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.
backward_euler_method.hpp
Go to the documentation of this file.
1 //
2 // Project Name: KratosSolidMechanicsApplication $
3 // Created by: $Author: JMCarbonell $
4 // Last modified by: $Co-Author: $
5 // Date: $Date: April 2018 $
6 // Revision: $Revision: 0.0 $
7 //
8 //
9 
10 #if !defined(KRATOS_BACKWARD_EULER_METHOD_H_INCLUDED)
11 #define KRATOS_BACKWARD_EULER_METHOD_H_INCLUDED
12 
13 // System includes
14 
15 // External includes
16 
17 // Project includes
19 
20 namespace Kratos
21 {
24 
27 
31 
35 
39 
43 
44 
46 
49  template<class TVariableType, class TValueType>
50  class BackwardEulerMethod : public TimeIntegrationMethod<TVariableType,TValueType>
51  {
52  public:
53 
56 
59 
61  typedef typename BaseType::Pointer BasePointerType;
62 
64  typedef typename BaseType::NodeType NodeType;
65 
68 
70 
74 
75 
78 
80  BackwardEulerMethod(const TVariableType& rVariable) : BaseType(rVariable) {}
81 
83  BackwardEulerMethod(const TVariableType& rVariable, const TVariableType& rFirstDerivative, const TVariableType& rSecondDerivative) : BaseType(rVariable,rFirstDerivative,rSecondDerivative) {}
84 
86  BackwardEulerMethod(const TVariableType& rVariable, const TVariableType& rFirstDerivative, const TVariableType& rSecondDerivative, const TVariableType& rPrimaryVariable) : BaseType(rVariable,rFirstDerivative,rSecondDerivative,rPrimaryVariable) {}
87 
90  :BaseType(rOther)
91  ,mDeltaTime(rOther.mDeltaTime)
92  {
93  }
94 
97  {
98  return BasePointerType( new BackwardEulerMethod(*this) );
99  }
100 
102  ~BackwardEulerMethod() override{}
103 
107 
111 
112  // set parameters (do not calculate parameters here, only read them)
113  void SetParameters(const ProcessInfo& rCurrentProcessInfo) override
114  {
115  KRATOS_TRY
116 
117  const double& delta_time = rCurrentProcessInfo[DELTA_TIME];
118 
119  if (delta_time < 1.0e-24)
120  {
121  KRATOS_ERROR << " ERROR: detected delta_time = 0 in the Solution Method DELTA_TIME. PLEASE : check if the time step is created correctly for the current model part " << std::endl;
122  }
123 
125 
126  KRATOS_CATCH( "" )
127  }
128 
129  // set parameters to process info
130  void SetProcessInfoParameters(ProcessInfo& rCurrentProcessInfo) override
131  {
132  KRATOS_TRY
133 
134 
135  KRATOS_CATCH( "" )
136  }
137 
142  int Check( const ProcessInfo& rCurrentProcessInfo ) override
143  {
144  KRATOS_TRY
145 
146  // Perform base integration method checks
147  int ErrorCode = 0;
148  ErrorCode = BaseType::Check(rCurrentProcessInfo);
149 
150  // Check that all required variables have been registered
151  if( this->mpFirstDerivative == nullptr ){
152  KRATOS_ERROR << " time integration method FirstDerivative not set " <<std::endl;
153  }
154 
155  if( this->mpSecondDerivative == nullptr ){
156  KRATOS_ERROR << " time integration method SecondDerivative not set " <<std::endl;
157  }
158 
159  return ErrorCode;
160 
161  KRATOS_CATCH("")
162  }
163 
167 
171 
175 
176 
178  std::string Info() const override
179  {
180  std::stringstream buffer;
181  buffer << "BackwardEulerMethod";
182  return buffer.str();
183  }
184 
186  void PrintInfo(std::ostream& rOStream) const override
187  {
188  rOStream << "BackwardEulerMethod";
189  }
190 
192  void PrintData(std::ostream& rOStream) const override
193  {
194  rOStream << "BackwardEulerMethod Data";
195  }
196 
197 
201 
202 
204 
205  protected:
206 
209 
213 
214  double mDeltaTime;
215 
219 
220  void AssignFromVariable(NodeType& rNode) override
221  {
222  KRATOS_TRY
223 
224  // predict variable from variable
225  TValueType& CurrentFirstDerivative = rNode.FastGetSolutionStepValue(*this->mpFirstDerivative, 0);
226  TValueType& CurrentSecondDerivative = rNode.FastGetSolutionStepValue(*this->mpSecondDerivative, 0);
227 
228  CurrentFirstDerivative -= CurrentFirstDerivative;
229  CurrentSecondDerivative -= CurrentSecondDerivative;
230 
231 
232  KRATOS_CATCH( "" )
233  }
234 
235  void AssignFromFirstDerivative(NodeType& rNode) override
236  {
237  KRATOS_TRY
238 
239  // predict variable from first derivative
240  TValueType& CurrentVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 0);
241  const TValueType& PreviousVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 1);
242  const TValueType& OldPreviousVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 2);
243 
244  TValueType& CurrentFirstDerivative = rNode.FastGetSolutionStepValue(*this->mpFirstDerivative, 0);
245  const TValueType& PreviousFirstDerivative = rNode.FastGetSolutionStepValue(*this->mpFirstDerivative, 1);
246 
247  // backward euler consistent
248  CurrentVariable = (1.0/3.0) * ( 4.0 * PreviousVariable - OldPreviousVariable + 2.0 * mDeltaTime * CurrentFirstDerivative);
249 
250  TValueType& CurrentSecondDerivative = rNode.FastGetSolutionStepValue(*this->mpSecondDerivative, 0);
251 
252  CurrentFirstDerivative = PreviousFirstDerivative;
253  CurrentSecondDerivative -= CurrentSecondDerivative;
254 
255  KRATOS_CATCH( "" )
256  }
257 
258  void AssignFromSecondDerivative(NodeType& rNode) override
259  {
260  KRATOS_TRY
261 
262  // predict variable from second derivative
263  TValueType& CurrentVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 0);
264  const TValueType& PreviousVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 1);
265 
266  const TValueType& CurrentSecondDerivative = rNode.FastGetSolutionStepValue(*this->mpSecondDerivative, 0);
267 
268  const TValueType& PreviousFirstDerivative = rNode.FastGetSolutionStepValue(*this->mpFirstDerivative, 1);
269 
270  // backward euler consistent
271  CurrentVariable = PreviousVariable + mDeltaTime * ( PreviousFirstDerivative + 0.5 * mDeltaTime * CurrentSecondDerivative );
272 
273  KRATOS_CATCH( "" )
274  }
275 
276  void PredictFromVariable(NodeType& rNode) override
277  {
278  KRATOS_TRY
279 
280  this->PredictVariable(rNode);
281  this->PredictFirstDerivative(rNode);
282  this->PredictSecondDerivative(rNode);
283 
284  KRATOS_CATCH( "" )
285  }
286 
287  void PredictFromFirstDerivative(NodeType& rNode) override
288  {
289  KRATOS_TRY
290 
291  this->PredictVariable(rNode);
292  this->PredictFirstDerivative(rNode);
293  this->PredictSecondDerivative(rNode);
294 
295  KRATOS_CATCH( "" )
296  }
297 
298  void PredictVariable(NodeType& rNode) override
299  {
300  KRATOS_TRY
301 
302  TValueType& CurrentVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 0);
303  const TValueType& PreviousVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 1);
304 
305  const TValueType& PreviousFirstDerivative = rNode.FastGetSolutionStepValue(*this->mpFirstDerivative, 1);
306 
307  // variable prediction
308  CurrentVariable = PreviousVariable + mDeltaTime * PreviousFirstDerivative;
309 
310 
311  KRATOS_CATCH( "" )
312  }
313 
314  void PredictFirstDerivative(NodeType& rNode) override
315  {
316  KRATOS_TRY
317 
318  // TValueType& CurrentFirstDerivative = rNode.FastGetSolutionStepValue(*this->mpFirstDerivative, 0);
319  // const TValueType& PreviousFirstDerivative = rNode.FastGetSolutionStepValue(*this->mpFirstDerivative, 1);
320 
321  // CurrentFirstDerivative = PreviousFirstDerivative;
322 
323  const TValueType& CurrentVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 0);
324  const TValueType& PreviousVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 1);
325  const TValueType& OldPreviousVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 2);
326 
327  TValueType& CurrentFirstDerivative = rNode.FastGetSolutionStepValue(*this->mpFirstDerivative, 0);
328 
329  CurrentFirstDerivative = (1.0/mDeltaTime) * ( 3.0 * 0.5 * CurrentVariable - 2.0 * PreviousVariable + 0.5 * OldPreviousVariable);
330 
331  KRATOS_CATCH( "" )
332  }
333 
334  void PredictSecondDerivative(NodeType& rNode) override
335  {
336  KRATOS_TRY
337 
338  // TValueType& CurrentSecondDerivative = rNode.FastGetSolutionStepValue(*this->mpSecondDerivative, 0);
339  // const TValueType& PreviousSecondDerivative = rNode.FastGetSolutionStepValue(*this->mpSecondDerivative, 1);
340 
341  // CurrentSecondDerivative = PreviousSecondDerivative;
342 
343  const TValueType& CurrentVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 0);
344  const TValueType& PreviousVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 1);
345  const TValueType& PreviousFirstDerivative = rNode.FastGetSolutionStepValue(*this->mpFirstDerivative, 1);
346 
347  TValueType& CurrentSecondDerivative = rNode.FastGetSolutionStepValue(*this->mpSecondDerivative, 0);
348 
349  CurrentSecondDerivative = (2.0/ (mDeltaTime*mDeltaTime)) * (CurrentVariable - PreviousVariable - mDeltaTime * PreviousFirstDerivative);
350 
351  KRATOS_CATCH( "" )
352  }
353 
354  void UpdateFromVariable(NodeType& rNode) override
355  {
356  KRATOS_TRY
357 
358  const TValueType& CurrentVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 0);
359  const TValueType& PreviousVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 1);
360  const TValueType& OldPreviousVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 2);
361 
362  TValueType& CurrentFirstDerivative = rNode.FastGetSolutionStepValue(*this->mpFirstDerivative, 0);
363  const TValueType& PreviousFirstDerivative = rNode.FastGetSolutionStepValue(*this->mpFirstDerivative, 1);
364 
365  TValueType& CurrentSecondDerivative = rNode.FastGetSolutionStepValue(*this->mpSecondDerivative, 0);
366 
367  CurrentSecondDerivative = (2.0/ (mDeltaTime*mDeltaTime)) * (CurrentVariable - PreviousVariable - mDeltaTime * PreviousFirstDerivative);
368 
369  CurrentFirstDerivative = (1.0/mDeltaTime) * ( (3.0/2.0) * CurrentVariable - 2.0 * PreviousVariable + 0.5 * OldPreviousVariable);
370 
371  KRATOS_CATCH( "" )
372  }
373 
374 
375  void UpdateFromFirstDerivative(NodeType& rNode) override
376  {
377  KRATOS_TRY
378 
379 
380  TValueType& CurrentVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 0);
381  const TValueType& PreviousVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 1);
382  const TValueType& OldPreviousVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 2);
383 
384  const TValueType& CurrentFirstDerivative = rNode.FastGetSolutionStepValue(*this->mpFirstDerivative, 0);
385  const TValueType& PreviousFirstDerivative = rNode.FastGetSolutionStepValue(*this->mpFirstDerivative, 1);
386 
387  TValueType& CurrentSecondDerivative = rNode.FastGetSolutionStepValue(*this->mpSecondDerivative, 0);
388 
389  CurrentVariable = (2.0 / 3.0) * ( mDeltaTime * CurrentFirstDerivative + 2.0 * PreviousVariable - 0.5 * OldPreviousVariable);
390  CurrentSecondDerivative = (2.0/ (mDeltaTime*mDeltaTime)) * (CurrentVariable - PreviousVariable - mDeltaTime * PreviousFirstDerivative);
391 
392 
393  KRATOS_CATCH( "" )
394  }
395 
396  void UpdateFromSecondDerivative(NodeType& rNode) override
397  {
398  KRATOS_TRY
399 
400  TValueType& CurrentVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 0);
401  const TValueType& PreviousVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 1);
402  const TValueType& OldPreviousVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 2);
403 
404  TValueType& CurrentFirstDerivative = rNode.FastGetSolutionStepValue(*this->mpFirstDerivative, 0);
405  const TValueType& PreviousFirstDerivative = rNode.FastGetSolutionStepValue(*this->mpFirstDerivative, 1);
406 
407  const TValueType& CurrentSecondDerivative = rNode.FastGetSolutionStepValue(*this->mpSecondDerivative, 0);
408 
409  CurrentVariable = PreviousVariable + mDeltaTime * PreviousFirstDerivative + 0.5 * mDeltaTime * mDeltaTime * CurrentSecondDerivative;
410  CurrentFirstDerivative = (1.0/mDeltaTime) * ( 3.0 * 0.5 * CurrentVariable - 2.0 * PreviousVariable + 0.5 * OldPreviousVariable);
411 
412  KRATOS_CATCH( "" )
413  }
414 
415  void UpdateVariable(NodeType& rNode) override
416  {
417  KRATOS_TRY
418 
419  KRATOS_CATCH( "" )
420  }
421 
422 
423  void UpdateFirstDerivative(NodeType& rNode) override
424  {
425  KRATOS_TRY
426 
427  const TValueType& CurrentVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 0);
428  const TValueType& PreviousVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 1);
429  const TValueType& OldPreviousVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 2);
430 
431  TValueType& CurrentFirstDerivative = rNode.FastGetSolutionStepValue(*this->mpFirstDerivative, 0);
432 
433  CurrentFirstDerivative = (1.0/mDeltaTime) * ( 3.0 * 0.5 * CurrentVariable - 2.0 * PreviousVariable + 0.5 * OldPreviousVariable);
434 
435  KRATOS_CATCH( "" )
436  }
437 
438  void UpdateSecondDerivative(NodeType& rNode) override
439  {
440  KRATOS_TRY
441 
442  const TValueType& CurrentVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 0);
443  const TValueType& PreviousVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 1);
444  const TValueType& PreviousFirstDerivative = rNode.FastGetSolutionStepValue(*this->mpFirstDerivative, 1);
445 
446  TValueType& CurrentSecondDerivative = rNode.FastGetSolutionStepValue(*this->mpSecondDerivative, 0);
447 
448  CurrentSecondDerivative = (2.0/ (mDeltaTime*mDeltaTime)) * (CurrentVariable - PreviousVariable - mDeltaTime * PreviousFirstDerivative);
449 
450  KRATOS_CATCH( "" )
451  }
452 
456 
460 
461  // get parameters
462  double& GetFirstDerivativeInertialParameter(double& rParameter) override
463  {
464  rParameter = 3.0 / (2.0 * mDeltaTime);
465  return rParameter;
466  }
467 
468  double& GetSecondDerivativeInertialParameter(double& rParameter) override
469  {
470  rParameter = 2.0 / (mDeltaTime*mDeltaTime);
471  return rParameter;
472  }
473 
477 
481 
483 
484  private:
485 
488 
492 
496 
500 
504 
508  friend class Serializer;
509 
510  void save(Serializer& rSerializer) const override
511  {
513  rSerializer.save("DeltaTime", mDeltaTime);
514  };
515 
516  void load(Serializer& rSerializer) override
517  {
519  rSerializer.load("DeltaTime", mDeltaTime);
520  };
521 
525 
529 
531 
532  }; // Class BackwardEulerMethod
533 
535 
538 
539 
543 
544  template<class TVariableType, class TValueType>
545  inline std::istream & operator >> (std::istream & rIStream, BackwardEulerMethod<TVariableType,TValueType>& rThis)
546  {
547  return rIStream;
548  }
549 
550  template<class TVariableType, class TValueType>
551  inline std::ostream & operator << (std::ostream & rOStream, const BackwardEulerMethod<TVariableType,TValueType>& rThis)
552  {
553  return rOStream << rThis.Info();
554  }
555 
557 
559 
560 } // namespace Kratos.
561 
562 #endif // KRATOS_BACKWARD_EULER_METHOD_H_INCLUDED defined
Short class definition.
Definition: backward_euler_method.hpp:51
void UpdateFromVariable(NodeType &rNode) override
Definition: backward_euler_method.hpp:354
int Check(const ProcessInfo &rCurrentProcessInfo) override
This function is designed to be called once to perform all the checks needed.
Definition: backward_euler_method.hpp:142
double mDeltaTime
Definition: backward_euler_method.hpp:214
double & GetSecondDerivativeInertialParameter(double &rParameter) override
Definition: backward_euler_method.hpp:468
void AssignFromSecondDerivative(NodeType &rNode) override
Definition: backward_euler_method.hpp:258
double & GetFirstDerivativeInertialParameter(double &rParameter) override
Definition: backward_euler_method.hpp:462
BackwardEulerMethod(const TVariableType &rVariable, const TVariableType &rFirstDerivative, const TVariableType &rSecondDerivative)
Constructor.
Definition: backward_euler_method.hpp:83
void PredictFromVariable(NodeType &rNode) override
Definition: backward_euler_method.hpp:276
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: backward_euler_method.hpp:192
void UpdateFirstDerivative(NodeType &rNode) override
Definition: backward_euler_method.hpp:423
BackwardEulerMethod(const TVariableType &rVariable)
Constructor.
Definition: backward_euler_method.hpp:80
void UpdateSecondDerivative(NodeType &rNode) override
Definition: backward_euler_method.hpp:438
void AssignFromVariable(NodeType &rNode) override
Definition: backward_euler_method.hpp:220
BasePointerType Clone() override
Clone.
Definition: backward_euler_method.hpp:96
void SetProcessInfoParameters(ProcessInfo &rCurrentProcessInfo) override
Definition: backward_euler_method.hpp:130
std::string Info() const override
Turn back information as a string.
Definition: backward_euler_method.hpp:178
void PredictFirstDerivative(NodeType &rNode) override
Definition: backward_euler_method.hpp:314
TimeIntegrationMethod< TVariableType, TValueType > BaseType
BaseType.
Definition: backward_euler_method.hpp:58
KRATOS_CLASS_POINTER_DEFINITION(BackwardEulerMethod)
void PredictFromFirstDerivative(NodeType &rNode) override
Definition: backward_euler_method.hpp:287
void UpdateVariable(NodeType &rNode) override
Definition: backward_euler_method.hpp:415
BaseType::Pointer BasePointerType
BasePointerType.
Definition: backward_euler_method.hpp:61
void UpdateFromSecondDerivative(NodeType &rNode) override
Definition: backward_euler_method.hpp:396
BaseType::VariablePointer VariablePointer
KratosVariable or KratosVariableComponent.
Definition: backward_euler_method.hpp:67
BaseType::NodeType NodeType
NodeType.
Definition: backward_euler_method.hpp:64
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: backward_euler_method.hpp:186
BackwardEulerMethod(BackwardEulerMethod &rOther)
Copy Constructor.
Definition: backward_euler_method.hpp:89
BackwardEulerMethod(const TVariableType &rVariable, const TVariableType &rFirstDerivative, const TVariableType &rSecondDerivative, const TVariableType &rPrimaryVariable)
Constructor.
Definition: backward_euler_method.hpp:86
void PredictVariable(NodeType &rNode) override
Definition: backward_euler_method.hpp:298
BackwardEulerMethod()
Default Constructor.
Definition: backward_euler_method.hpp:77
void PredictSecondDerivative(NodeType &rNode) override
Definition: backward_euler_method.hpp:334
void SetParameters(const ProcessInfo &rCurrentProcessInfo) override
Definition: backward_euler_method.hpp:113
void AssignFromFirstDerivative(NodeType &rNode) override
Definition: backward_euler_method.hpp:235
void UpdateFromFirstDerivative(NodeType &rNode) override
Definition: backward_euler_method.hpp:375
~BackwardEulerMethod() override
Destructor.
Definition: backward_euler_method.hpp:102
This class defines the node.
Definition: node.h:65
TVariableType::Type & FastGetSolutionStepValue(const TVariableType &rThisVariable)
Definition: node.h:435
ProcessInfo holds the current value of different solution parameters.
Definition: process_info.h:59
The serialization consists in storing the state of an object into a storage format like data file or ...
Definition: serializer.h:123
void load(std::string const &rTag, TDataType &rObject)
Definition: serializer.h:207
void save(std::string const &rTag, std::array< TDataType, TDataSize > const &rObject)
Definition: serializer.h:545
Short class definition.
Definition: time_integration_method.hpp:55
VariablePointer mpVariable
Definition: time_integration_method.hpp:405
virtual int Check(const ProcessInfo &rCurrentProcessInfo)
This function is designed to be called once to perform all the checks needed.
Definition: time_integration_method.hpp:272
const TVariableType * VariablePointer
KratosVariable or KratosVariableComponent.
Definition: time_integration_method.hpp:65
VariablePointer mpFirstDerivative
Definition: time_integration_method.hpp:407
VariablePointer mpSecondDerivative
Definition: time_integration_method.hpp:409
#define KRATOS_SERIALIZE_SAVE_BASE_CLASS(Serializer, BaseType)
Definition: define.h:812
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_SERIALIZE_LOAD_BASE_CLASS(Serializer, BaseType)
Definition: define.h:815
#define KRATOS_ERROR
Definition: exception.h:161
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
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
delta_time
Definition: generate_frictional_mortar_condition.py:130
def load(f)
Definition: ode_solve.py:307