KratosMultiphysics
KRATOS Multiphysics (Kratos) is a framework for building parallel, multi-disciplinary simulation software, aiming at modularity, extensibility, and high performance. Kratos is written in C++, and counts with an extensive Python interface.
helmholtz_strategy.h
Go to the documentation of this file.
1 // | / |
2 // ' / __| _` | __| _ \ __|
3 // . \ | ( | | ( |\__ `
4 // _|\_\_| \__,_|\__|\___/ ____/
5 // Multi-Physics
6 //
7 // License: BSD License
8 // Kratos default license:
9 // kratos/license.txt
10 //
11 // Main authors: Reza Najian Asl
12 //
13 
14 #if !defined(KRATOS_HELMHOLTZ_VEC_STRATEGY)
15 #define KRATOS_HELMHOLTZ_VEC_STRATEGY
16 
17 /* System includes */
18 
19 /* External includes */
20 
21 /* Project includes */
22 #include "containers/model.h"
28 
29 namespace Kratos {
30 
52 
54 template <class TSparseSpace, class TDenseSpace, class TLinearSolver>
56  : public ImplicitSolvingStrategy<TSparseSpace, TDenseSpace, TLinearSolver> {
57 public:
63 
69 
78  typename TLinearSolver::Pointer pNewLinearSolver,
79  bool ReformDofSetAtEachStep = false,
80  bool ComputeReactions = false,
81  int EchoLevel = 0,
82  const double PoissonRatio = 0.3)
83  : ImplicitSolvingStrategy<TSparseSpace, TDenseSpace, TLinearSolver>(model_part) {
85 
86  mreform_dof_set_at_each_step = ReformDofSetAtEachStep;
87  mcompute_reactions = ComputeReactions;
88  mecho_level = EchoLevel;
89  bool calculate_norm_dx_flag = false;
90 
91  mpscheme = typename SchemeType::Pointer(
93  TDenseSpace>());
94 
95  mpbulider_and_solver = typename TBuilderAndSolverType::Pointer(
96  new ResidualBasedBlockBuilderAndSolver<TSparseSpace, TDenseSpace,
97  TLinearSolver>(
98  pNewLinearSolver));
99 
100  mpstrategy = typename BaseType::Pointer(new ResidualBasedLinearStrategy<TSparseSpace, TDenseSpace,TLinearSolver>(
102  mpscheme,
103  mpbulider_and_solver,
104  mcompute_reactions,
105  mreform_dof_set_at_each_step,
106  calculate_norm_dx_flag));
107 
108  mpstrategy->SetEchoLevel(mecho_level);
109 
110  KRATOS_CATCH("")
111  }
112 
114  {
115 
116  }
117 
118  void Initialize() override {}
119 
120  double Solve() override {
121  KRATOS_TRY;
122 
124  BaseType::GetModelPart().GetCommunicator().LocalMesh().Nodes());
125 
126  // Solve for the mesh movement
127  mpstrategy->Solve();
128 
129  // Clearing the system if needed
130  if (mreform_dof_set_at_each_step == true)
131  mpstrategy->Clear();
132 
133  return 0.0;
134 
135  KRATOS_CATCH("");
136  }
137 
155  {
156  return mpstrategy->GetSystemMatrix();
157  }
158 
160  {
161  return mpstrategy->GetSystemVector();
162  }
163 
165  {
166  return mpstrategy->GetSolutionVector();
167  }
168 
169  void ExportSystem()
170  {
171  mpstrategy->Clear();
172  mpstrategy->Initialize();
173  mpstrategy->InitializeSolutionStep();
174  mpstrategy->Predict();
175  mpbulider_and_solver->Build(mpscheme,BaseType::GetModelPart(),mpstrategy->GetSystemMatrix(),mpstrategy->GetSystemVector());
176 
177  std::stringstream matrix_market_name;
178  matrix_market_name << "A_wo_D_BC.mm";
179  TSparseSpace::WriteMatrixMarketMatrix((char *)(matrix_market_name.str()).c_str(), mpstrategy->GetSystemMatrix(), false);
180 
181  std::stringstream matrix_market_vectname;
182  matrix_market_vectname << "b_wo_D_BC.mm";
183  TSparseSpace::WriteMatrixMarketVector((char *)(matrix_market_vectname.str()).c_str(), mpstrategy->GetSystemVector());
184 
185  mpstrategy->SolveSolutionStep();
186 
187  matrix_market_name.str("");
188  matrix_market_name << "A_wi_D_BC.mm";
189  TSparseSpace::WriteMatrixMarketMatrix((char *)(matrix_market_name.str()).c_str(), mpstrategy->GetSystemMatrix(), false);
190 
191  matrix_market_vectname.str("");
192  matrix_market_vectname << "b_wi_D_BC.mm";
193  TSparseSpace::WriteMatrixMarketVector((char *)(matrix_market_vectname.str()).c_str(), mpstrategy->GetSystemVector());
194 
195  mpstrategy->FinalizeSolutionStep();
196 
197  mpstrategy->Clear();
198 
199  }
200 
201  typename BaseType::Pointer GetStrategy()
202  {
203  return mpstrategy;
204  }
205 
212 protected:
242 private:
250  typename SchemeType::Pointer mpscheme;
251  typename BaseType::Pointer mpstrategy;
252  typename TBuilderAndSolverType::Pointer mpbulider_and_solver;
253 
254  int mecho_level;
255  bool mreform_dof_set_at_each_step;
256  bool mcompute_reactions;
257 
279  HelmholtzStrategy(const HelmholtzStrategy &Other);
280 
283 }; /* Class HelmholtzStrategy */
284 
291 }
292 /* namespace Kratos.*/
293 
294 #endif /* KRATOS_HELMHOLTZ_VEC_STRATEGY defined */
Short class definition.
Definition: helmholtz_strategy.h:56
ImplicitSolvingStrategy< TSparseSpace, TDenseSpace, TLinearSolver > BaseType
Definition: helmholtz_strategy.h:64
TSystemMatrixType & GetSystemMatrix() override
This method returns the LHS matrix.
Definition: helmholtz_strategy.h:154
virtual ~HelmholtzStrategy()
Definition: helmholtz_strategy.h:113
BaseType::TSystemVectorType TSystemVectorType
Definition: helmholtz_strategy.h:67
void ExportSystem()
Definition: helmholtz_strategy.h:169
double Solve() override
The problem of interest is solved.
Definition: helmholtz_strategy.h:120
TSystemVectorType & GetSystemVector() override
This method returns the RHS vector.
Definition: helmholtz_strategy.h:159
BaseType::TSystemMatrixType TSystemMatrixType
Definition: helmholtz_strategy.h:66
BaseType::TBuilderAndSolverType TBuilderAndSolverType
Definition: helmholtz_strategy.h:65
HelmholtzStrategy(ModelPart &model_part, typename TLinearSolver::Pointer pNewLinearSolver, bool ReformDofSetAtEachStep=false, bool ComputeReactions=false, int EchoLevel=0, const double PoissonRatio=0.3)
Definition: helmholtz_strategy.h:77
KRATOS_CLASS_POINTER_DEFINITION(HelmholtzStrategy)
BaseType::Pointer GetStrategy()
Definition: helmholtz_strategy.h:201
void Initialize() override
Initialization of member variables and prior operations.
Definition: helmholtz_strategy.h:118
TSystemVectorType & GetSolutionVector() override
This method returns the solution vector.
Definition: helmholtz_strategy.h:164
Scheme< TSparseSpace, TDenseSpace > SchemeType
Definition: helmholtz_strategy.h:68
Implicit solving strategy base class This is the base class from which we will derive all the implici...
Definition: implicit_solving_strategy.h:61
BaseType::TSystemVectorType TSystemVectorType
Definition: implicit_solving_strategy.h:72
BuilderAndSolver< TSparseSpace, TDenseSpace, TLinearSolver > TBuilderAndSolverType
Definition: implicit_solving_strategy.h:84
BaseType::TSystemMatrixType TSystemMatrixType
Definition: implicit_solving_strategy.h:70
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
Current class provides an implementation for standard builder and solving operations.
Definition: residualbased_block_builder_and_solver.h:82
This class provides the implementation of a static scheme.
Definition: residualbased_incrementalupdate_static_scheme.h:57
This is a very simple strategy to solve linearly the problem.
Definition: residualbased_linear_strategy.h:64
This class provides the implementation of the basic tasks that are needed by the solution strategy.
Definition: scheme.h:56
ModelPart & GetModelPart()
Operations to get the pointer to the model.
Definition: solving_strategy.h:350
TSparseSpace::MatrixType TSystemMatrixType
Definition: solving_strategy.h:71
TSparseSpace::VectorType TSystemVectorType
Definition: solving_strategy.h:73
This class implements a set of auxiliar, already parallelized, methods to perform some common tasks r...
Definition: variable_utils.h:63
void UpdateCurrentToInitialConfiguration(const ModelPart::NodesContainerType &rNodes)
This method updates the current nodal coordinates back to the initial coordinates.
Definition: variable_utils.cpp:245
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
static int EchoLevel
Definition: co_sim_EMPIRE_API.h:42
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
model_part
Definition: face_heat.py:14