14 #if !defined(KRATOS_AMGCL_NAVIERSTOKES_SOLVER )
15 #define KRATOS_AMGCL_NAVIERSTOKES_SOLVER
17 #ifndef AMGCL_PARAM_UNKNOWN
19 # define AMGCL_PARAM_UNKNOWN(name) \
20 Kratos::Logger("AMGCL") << KRATOS_CODE_LOCATION << Kratos::Logger::Severity::WARNING << "Unknown parameter " << name << std::endl
34 #include <boost/property_tree/json_parser.hpp>
36 #include <amgcl/adapter/crs_tuple.hpp>
37 #include <amgcl/adapter/ublas.hpp>
38 #include <amgcl/adapter/zero_copy.hpp>
39 #include <amgcl/backend/builtin.hpp>
40 #include <amgcl/value_type/static_matrix.hpp>
41 #include <amgcl/make_solver.hpp>
42 #include <amgcl/make_block_solver.hpp>
43 #include <amgcl/solver/runtime.hpp>
44 #include <amgcl/preconditioner/schur_pressure_correction.hpp>
45 #include <amgcl/preconditioner/runtime.hpp>
51 template<
class TSparseSpaceType,
class TDenseSpaceType,
52 class TReordererType = Reorderer<TSparseSpaceType, TDenseSpaceType> >
54 TDenseSpaceType, TReordererType>
74 "solver_type" : "amgcl_ns",
77 "schur_variable" : "PRESSURE",
99 "type": "aggregation",
120 mTol = rParameters[
"inner_settings"][
"solver"][
"tol"].
GetDouble();
121 mVerbosity=rParameters[
"verbosity"].
GetInt();
122 const std::string pressure_var_name = rParameters[
"schur_variable"].
GetString();
127 std::stringstream inner_settings;
130 boost::property_tree::read_json(inner_settings, mprm);
150 mprm.put(
"precond.pmask",
static_cast<void*
>(&mp[0]));
151 mprm.put(
"precond.pmask_size", mp.size());
152 mprm.put(
"solver.verbose", mVerbosity > 1);
155 write_json(std::cout, mprm);
160 std::stringstream matrix_market_name;
161 matrix_market_name <<
"A" <<
".mm";
164 std::stringstream matrix_market_vectname;
165 matrix_market_vectname <<
"b" <<
".mm.rhs";
177 std::tie(iters, resid) = block_solve<2>(rA, rX, rB);
180 std::tie(iters, resid) = block_solve<3>(rA, rX, rB);
187 <<
"Non converged linear solution. " << resid << std::endl;
191 std::cout <<
"Iterations: " << iters << std::endl
192 <<
"Error: " << resid << std::endl
196 bool is_solved =
true;
205 typedef amgcl::backend::builtin<double> sBackend;
206 typedef amgcl::backend::builtin<float> pBackend;
208 typedef amgcl::make_solver<
209 amgcl::runtime::preconditioner<pBackend>,
210 amgcl::runtime::solver::wrapper<pBackend>
213 typedef amgcl::make_solver<
214 amgcl::runtime::preconditioner<pBackend>,
215 amgcl::runtime::solver::wrapper<pBackend>
218 typedef amgcl::make_solver<
219 amgcl::preconditioner::schur_pressure_correction<USolver, PSolver>,
220 amgcl::runtime::solver::wrapper<sBackend>
223 auto pA = amgcl::adapter::zero_copy(
225 rA.index1_data().begin(),
226 rA.index2_data().begin(),
227 rA.value_data().begin()
230 Solver
solve(*pA, mprm);
231 KRATOS_INFO_IF(
"AMGCL NS Solver", mVerbosity > 1) <<
"AMGCL-NS Memory Occupation : " << amgcl::human_readable_memory(amgcl::backend::bytes(
solve)) << std::endl;
232 return solve(*pA, rB, rX);
235 template <
int UBlockSize>
238 typedef amgcl::static_matrix<float,UBlockSize,UBlockSize> fblock;
240 typedef amgcl::backend::builtin<double> sBackend;
241 typedef amgcl::backend::builtin<fblock> uBackend;
242 typedef amgcl::backend::builtin<float> pBackend;
244 typedef amgcl::make_block_solver<
245 amgcl::runtime::preconditioner<uBackend>,
246 amgcl::runtime::solver::wrapper<uBackend>
249 typedef amgcl::make_solver<
250 amgcl::runtime::preconditioner<pBackend>,
251 amgcl::runtime::solver::wrapper<pBackend>
254 typedef amgcl::make_solver<
255 amgcl::preconditioner::schur_pressure_correction<USolver, PSolver>,
256 amgcl::runtime::solver::wrapper<sBackend>
259 auto pA = amgcl::adapter::zero_copy(
261 rA.index1_data().begin(),
262 rA.index2_data().begin(),
263 rA.value_data().begin()
266 Solver
solve(*pA, mprm);
267 KRATOS_INFO_IF(
"AMGCL NS Solver", mVerbosity > 1) <<
"AMGCL-NS Memory Occupation : " << amgcl::human_readable_memory(amgcl::backend::bytes(
solve)) << std::endl;
268 return solve(*pA, rB, rX);
290 rOStream <<
"AMGCL NS Solver finished.";
331 unsigned int old_node_id = rDofSet.
size() ? rDofSet.
begin()->Id() : 0;
332 for (
auto it = rDofSet.
begin(); it!=rDofSet.
end(); it++) {
335 if(
id != old_node_id) {
337 if(old_ndof == -1) old_ndof = ndof;
338 else if(old_ndof != ndof) {
360 unsigned int old_node_id = rDofSet.
size() ? rDofSet.
begin()->Id() : 0;
361 for (
auto it = rDofSet.
begin(); it!=rDofSet.
end(); it++) {
362 if(it->EquationId() < system_size && it->GetSolutionStepValue(PARTITION_INDEX) == current_rank) {
364 if(
id != old_node_id) {
366 if(old_ndof == -1) old_ndof = ndof;
367 else if(old_ndof != ndof) {
384 if( old_ndof == -1) {
385 mndof = max_block_size;
388 KRATOS_ERROR_IF(mndof != max_block_size) <<
"Block size is not consistent. Local: " << mndof <<
" Max: " << max_block_size << std::endl;
391 KRATOS_INFO_IF(
"AMGCL NS Solver", mVerbosity > 1) <<
"mndof: " << mndof << std::endl;
408 if(mp.size() != rA.size1()) mp.resize( rA.size1() );
411 const unsigned int eq_id = it->EquationId();
412 if( eq_id < rA.size1() )
414 mp[eq_id] = (it->GetVariable().Key() == *mpPressureVar);
427 std::vector< char > mp;
429 boost::property_tree::ptree mprm;
447 template<
class TSparseSpaceType,
class TDenseSpaceType,
class TReordererType>
449 TDenseSpaceType, TReordererType>& rThis)
457 template<
class TSparseSpaceType,
class TDenseSpaceType,
class TReordererType>
460 TDenseSpaceType, TReordererType>& rThis)
462 rThis.PrintInfo(rOStream);
463 rOStream << std::endl;
464 rThis.PrintData(rOStream);
Definition: amgcl_ns_solver.h:55
TSparseSpaceType::MatrixType SparseMatrixType
Definition: amgcl_ns_solver.h:63
std::tuple< size_t, double > scalar_solve(SparseMatrixType &rA, VectorType &rX, VectorType &rB) const
Definition: amgcl_ns_solver.h:203
void PrintData(std::ostream &rOStream) const override
Definition: amgcl_ns_solver.h:296
TDenseSpaceType::MatrixType DenseMatrixType
Definition: amgcl_ns_solver.h:67
bool Solve(SparseMatrixType &rA, DenseMatrixType &rX, DenseMatrixType &rB) override
Definition: amgcl_ns_solver.h:279
std::tuple< size_t, double > block_solve(SparseMatrixType &rA, VectorType &rX, VectorType &rB) const
Definition: amgcl_ns_solver.h:236
TSparseSpaceType::VectorType VectorType
Definition: amgcl_ns_solver.h:65
void PrintInfo(std::ostream &rOStream) const override
Definition: amgcl_ns_solver.h:288
void ProvideAdditionalData(SparseMatrixType &rA, VectorType &rX, VectorType &rB, typename ModelPart::DofsArrayType &rDofSet, ModelPart &rModelPart) override
Definition: amgcl_ns_solver.h:317
~AMGCL_NS_Solver() override
Definition: amgcl_ns_solver.h:137
KRATOS_CLASS_POINTER_DEFINITION(AMGCL_NS_Solver)
bool Solve(SparseMatrixType &rA, VectorType &rX, VectorType &rB) override
Definition: amgcl_ns_solver.h:147
LinearSolver< TSparseSpaceType, TDenseSpaceType, TReordererType > BaseType
Definition: amgcl_ns_solver.h:61
AMGCL_NS_Solver(Parameters rParameters)
Definition: amgcl_ns_solver.h:69
bool AdditionalPhysicalDataIsNeeded() override
Definition: amgcl_ns_solver.h:306
virtual const DataCommunicator & GetDataCommunicator() const
Definition: communicator.cpp:340
virtual int Rank() const
Get the parallel rank for this DataCommunicator.
Definition: data_communicator.h:587
KratosComponents class encapsulates a lookup table for a family of classes in a generic way.
Definition: kratos_components.h:49
Base class for all the linear solvers in Kratos.
Definition: linear_solver.h:65
TSparseSpaceType::IndexType IndexType
The index type definition to be consistent.
Definition: linear_solver.h:88
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
Communicator & GetCommunicator()
Definition: model_part.h:1821
bool IsDistributed() const
Definition: model_part.h:1898
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
double GetDouble() const
This method returns the double contained in the current Parameter.
Definition: kratos_parameters.cpp:657
const std::string PrettyPrintJsonString() const
This method returns a string with the corresponding text to the equivalent *.json file (this version ...
Definition: kratos_parameters.cpp:415
int GetInt() const
This method returns the integer contained in the current Parameter.
Definition: kratos_parameters.cpp:666
void ValidateAndAssignDefaults(const Parameters &rDefaultParameters)
This function is designed to verify that the parameters under testing match the form prescribed by th...
Definition: kratos_parameters.cpp:1306
std::string GetString() const
This method returns the string contained in the current Parameter.
Definition: kratos_parameters.cpp:684
A sorted associative container similar to an STL set, but uses a vector to store pointers to its data...
Definition: pointer_vector_set.h:72
boost::indirect_iterator< typename TContainerType::iterator > iterator
Definition: pointer_vector_set.h:95
size_type size() const
Returns the number of elements in the container.
Definition: pointer_vector_set.h:502
iterator begin()
Returns an iterator pointing to the beginning of the container.
Definition: pointer_vector_set.h:278
iterator end()
Returns an iterator pointing to the end of the container.
Definition: pointer_vector_set.h:314
#define KRATOS_THROW_ERROR(ExceptionType, ErrorMessage, MoreInfo)
Definition: define.h:77
#define KRATOS_ERROR_IF(conditional)
Definition: exception.h:162
#define KRATOS_INFO_IF(label, conditional)
Definition: logger.h:251
#define KRATOS_WARNING_IF(label, conditional)
Definition: logger.h:266
TSpaceType::IndexType Size1(TSpaceType &dummy, typename TSpaceType::MatrixType const &rM)
Definition: add_strategies_to_python.cpp:117
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
bool WriteMatrixMarketVector(const char *FileName, VectorType &V)
Definition: matrix_market_interface.h:539
bool WriteMatrixMarketMatrix(const char *FileName, CompressedMatrixType &M, bool Symmetric)
Definition: matrix_market_interface.h:308
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
def solve(A, rhs)
Definition: ode_solve.py:303