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.
explicit_strategy.hpp
Go to the documentation of this file.
1 //
2 // Project Name: KratosSolidMechanicsApplication $
3 // Created by: $Author: MSantasusana $
4 // Last modified by: $Co-Author: JMCarbonell $
5 // Date: $Date: April 2014 $
6 // Revision: $Revision: March 2018 $
7 //
8 //
9 
10 #if !defined(KRATOS_EXPLICIT_STRATEGY_H_INCLUDED)
11 #define KRATOS_EXPLICIT_STRATEGY_H_INCLUDED
12 
13 // System includes
14 
15 // External includes
16 
17 // Project includes
20 
21 //default builder and solver
23 
24 
25 namespace Kratos
26 {
27 
30 
34 
38 
42 
46 
47 template<class TSparseSpace,
48  class TDenseSpace, // = DenseSpace<double>,
49  class TLinearSolver //= LinearSolver<TSparseSpace,TDenseSpace>
50  >
51 class ExplicitSolutionStrategy : public SolutionStrategy<TSparseSpace, TDenseSpace, TLinearSolver>
52 {
53  public:
54 
57 
58  // Counted pointer of ClassName
59 
61 
63 
65 
67 
69 
70  typedef typename BaseType::SchemeType SchemeType;
71 
72  typedef TSparseSpace SparseSpaceType;
73 
75 
77 
79 
81 
83 
86 
88 
89 
92  typename SchemeType::Pointer pScheme,
93  Flags& rOptions)
94  : SolutionStrategy<TSparseSpace, TDenseSpace, TLinearSolver>(rModelPart, rOptions)
95  {
97 
98 
99  //saving the scheme
100  mpScheme = pScheme;
101 
102  //create explicit builder
103  mpBuilderAndSolver = Kratos::make_shared<ExplicitBuilderAndSolver<TSparseSpace, TDenseSpace, TLinearSolver> >();
104 
105  //set lumped mass matrix by default
106  if( this->GetModelPart().GetProcessInfo().Has(COMPUTE_LUMPED_MASS_MATRIX) )
107  this->GetModelPart().GetProcessInfo()[COMPUTE_LUMPED_MASS_MATRIX] = true;
108  KRATOS_CATCH( "" )
109  }
110 
113 
116 
118 
122 
126  void InitializeSolutionStep() override
127  {
128  KRATOS_TRY
129 
130 
131  //initialize system elements, conditions..
132  if(this->IsNot(LocalFlagType::INITIALIZED))
133  this->Initialize();
134 
135  //initial operations ... things that are constant over the Solution Step
136  mpBuilderAndSolver->InitializeSolutionStep(mpScheme, this->GetModelPart(), mpA, mpDx, mpb);
137 
138  //initial operations ... things that are constant over the Solution Step
139  mpScheme->InitializeSolutionStep(this->GetModelPart());
140 
141 
142  KRATOS_CATCH( "" )
143  }
144 
145 
149  void FinalizeSolutionStep() override
150  {
151  KRATOS_TRY
152 
153  //Finalization of the solution step
154 
155  //calculate reactions if required
156  // if(mOptions.Is(LocalFlagType::COMPUTE_REACTIONS))
157  // mpBuilderAndSolver->CalculateReactions(pScheme, this->GetModelPart(), (*mpA), (*mpDx), (*mpb));
158 
159  //finalize scheme anb builder and solver
160  mpScheme->FinalizeSolutionStep(this->GetModelPart());
161  mpBuilderAndSolver->FinalizeSolutionStep(mpScheme, this->GetModelPart(), mpA, mpDx, mpb);
162 
163  if(this->mOptions.Is(LocalFlagType::REFORM_DOFS)){
164  //deallocate the systemvectors
168 
169  this->Clear();
170  }
171 
172  //this->Finalize();
173 
174  KRATOS_CATCH("")
175  }
176 
177 
181  bool SolveSolutionStep() override
182  {
183  KRATOS_TRY
184 
185  //compute nodal mass and inertia
186  if(this->mOptions.IsNot(LocalFlagType::CONSTANT_SYSTEM_MATRIX))
187  mpBuilderAndSolver->BuildLHS(mpScheme, this->GetModelPart(), (*mpA));
188 
189 
190  mpBuilderAndSolver->BuildRHS(mpScheme, this->GetModelPart(), (*mpb));
191 
192  //update explicitly integrates the equation of motion
193  this->Update();
194 
195  return true;
196 
197  KRATOS_CATCH( "" )
198  }
199 
200  //**********************************************************************
201  //**********************************************************************
202 
203  void Clear() override
204  {
205  KRATOS_TRY
206 
207  mpBuilderAndSolver->Clear();
208  mpScheme->Clear();
209 
210  KRATOS_CATCH( "" )
211  }
212 
213 
217 
222  void SetScheme(typename SchemeType::Pointer pScheme)
223  {
224  mpScheme = pScheme;
225  };
226 
231  typename SchemeType::Pointer GetScheme()
232  {
233  return mpScheme;
234  };
235 
239 
243 
245 
246  protected:
249 
253 
254  typename SchemeType::Pointer mpScheme;
255  typename BuilderAndSolverType::Pointer mpBuilderAndSolver;
256 
260 
261 
265 
269 
273  void Initialize() override
274  {
275  KRATOS_TRY
276 
277  //Initialize The Scheme - OPERATIONS TO BE DONE ONCE
278  if (mpScheme->IsNot(LocalFlagType::INITIALIZED))
279  mpScheme->Initialize(this->GetModelPart());
280 
281  // //Initialize The Elements - OPERATIONS TO BE DONE ONCE
282  // if (mpScheme->ElementsAreInitialized() == false)
283  // mpScheme->InitializeElements(this->GetModelPart());
284 
285  // //Initialize The Conditions- OPERATIONS TO BE DONE ONCE
286  // if (mpScheme->ConditionsAreInitialized() == false)
287  // mpScheme->InitializeConditions(this->GetModelPart());
288 
289  //compute nodal mass and inertia
290  if(this->mOptions.Is(LocalFlagType::CONSTANT_SYSTEM_MATRIX))
291  mpBuilderAndSolver->BuildLHS(mpScheme, this->GetModelPart(), (*mpA));
292 
293  this->Set(LocalFlagType::INITIALIZED,true);
294 
295 
296  KRATOS_CATCH( "" )
297  }
298 
306  void Update() override
307  {
308  KRATOS_TRY
309 
310  mpScheme->Update(this->GetModelPart(), mpBuilderAndSolver->GetDofSet(), (*mpDx));
311 
312  KRATOS_CATCH("")
313  }
314 
319  int Check() override
320  {
321  KRATOS_TRY
322 
323  //check the model part
324  BaseType::Check();
325 
326  //check the scheme
327  mpScheme->Check(this->GetModelPart());
328 
329  //check the builder and solver
330  mpBuilderAndSolver->Check(this->GetModelPart());
331 
332  return 0;
333 
334  KRATOS_CATCH( "" )
335  }
336 
347 
348  private:
369 
372 
374 
375 };
376 
378 
385 
387 
388 } // namespace Kratos.
389 #endif // KRATOS_EXPLICIT_STRATEGY_H_INCLUDED defined
Convergence Criterion base class.
Definition: convergence_criterion.hpp:52
bool Has(const Variable< TDataType > &rThisVariable) const
Checks if the data container has a value associated with a given variable.
Definition: data_value_container.h:382
Definition: explicit_strategy.hpp:52
bool SolveSolutionStep() override
Solves the current step. This function returns true if a solution has been found, false otherwise.
Definition: explicit_strategy.hpp:181
void Clear() override
Clears the internal storage.
Definition: explicit_strategy.hpp:203
BaseType::SchemeType SchemeType
Definition: explicit_strategy.hpp:70
SchemeType::Pointer GetScheme()
Get method for the time scheme.
Definition: explicit_strategy.hpp:231
ConvergenceCriterion< TSparseSpace, TDenseSpace > ConvergenceCriterionType
Definition: explicit_strategy.hpp:66
ExplicitSolutionStrategy(ModelPart &rModelPart, typename SchemeType::Pointer pScheme, Flags &rOptions)
Constructor.
Definition: explicit_strategy.hpp:91
~ExplicitSolutionStrategy() override
Destructor.
Definition: explicit_strategy.hpp:112
void InitializeSolutionStep() override
Performs all the required operations that should be done (for each step) before solving the solution ...
Definition: explicit_strategy.hpp:126
TSparseSpace SparseSpaceType
Definition: explicit_strategy.hpp:72
SystemVectorPointerType mpb
The incremement in the solution.
Definition: explicit_strategy.hpp:258
BaseType::SystemVectorType SystemVectorType
Definition: explicit_strategy.hpp:78
SchemeType::Pointer mpScheme
Definition: explicit_strategy.hpp:254
BaseType::LocalFlagType LocalFlagType
Definition: explicit_strategy.hpp:64
SystemMatrixPointerType mpA
The RHS vector of the system of equations.
Definition: explicit_strategy.hpp:259
SystemVectorPointerType mpDx
The pointer to the builder and solver employed.
Definition: explicit_strategy.hpp:257
int Check() override
Definition: explicit_strategy.hpp:319
void Initialize() override
Initialization of member variables and prior operations.
Definition: explicit_strategy.hpp:273
KRATOS_CLASS_POINTER_DEFINITION(ExplicitSolutionStrategy)
BaseType::BuilderAndSolverType BuilderAndSolverType
Definition: explicit_strategy.hpp:68
BuilderAndSolverType::Pointer mpBuilderAndSolver
The pointer to the time scheme employed.
Definition: explicit_strategy.hpp:255
void Update() override
Here the database is updated.
Definition: explicit_strategy.hpp:306
void FinalizeSolutionStep() override
Performs all the required operations that should be done (for each step) after solving the solution s...
Definition: explicit_strategy.hpp:149
BaseType::DofsArrayType DofsArrayType
Definition: explicit_strategy.hpp:74
BaseType::SystemMatrixPointerType SystemMatrixPointerType
Definition: explicit_strategy.hpp:80
void SetScheme(typename SchemeType::Pointer pScheme)
Set method for the time scheme.
Definition: explicit_strategy.hpp:222
SolutionStrategy< TSparseSpace, TDenseSpace, TLinearSolver > BaseType
Definition: explicit_strategy.hpp:62
BaseType::SystemMatrixType SystemMatrixType
Definition: explicit_strategy.hpp:76
BaseType::SystemVectorPointerType SystemVectorPointerType
Definition: explicit_strategy.hpp:82
Definition: flags.h:58
void Set(const Flags ThisFlag)
Definition: flags.cpp:33
bool Is(Flags const &rOther) const
Definition: flags.h:274
bool IsNot(Flags const &rOther) const
Definition: flags.h:291
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
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
Solution Buider and Solver base class.
Definition: solution_builder_and_solver.hpp:63
Solution scheme base class.
Definition: solution_scheme.hpp:54
Solution strategy base class.
Definition: solution_strategy.hpp:52
TSparseSpace::VectorPointerType SystemVectorPointerType
Definition: solution_strategy.hpp:63
ModelPart & GetModelPart()
Operations to get the pointer to the model.
Definition: solution_strategy.hpp:243
Flags mOptions
Definition: solution_strategy.hpp:267
TSparseSpace::MatrixPointerType SystemMatrixPointerType
Definition: solution_strategy.hpp:62
TSparseSpace::MatrixType SystemMatrixType
Definition: solution_strategy.hpp:60
virtual int Check()
Function to perform expensive checks.
Definition: solution_strategy.hpp:154
TSparseSpace::VectorType SystemVectorType
Definition: solution_strategy.hpp:61
Solver local flags class definition.
Definition: solution_local_flags.hpp:48
static void Clear(MatrixPointerType &pA)
Definition: ublas_space.h:578
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21