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.
emc_step_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: November 2017 $
6 // Revision: $Revision: 0.0 $
7 //
8 //
9 
10 #if !defined(KRATOS_EMC_STEP_METHOD_H_INCLUDED)
11 #define KRATOS_EMC_STEP_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 EmcStepMethod : public TimeIntegrationMethod<TVariableType,TValueType>
51  {
52  protected:
53 
55  {
56  double alpha;
57  double delta_time;
58 
59  //system constants
60  double c0;
61  double c1;
62 
63  void SetParameters(const double& ralpha,
64  const double& rdelta_time)
65  {
66  alpha = ralpha;
67 
68  delta_time = rdelta_time;
69 
70  c0 = ( 2.0 / delta_time );
71  c1 = ( 1.0 / delta_time );
72  }
73 
74 
75  private:
76 
77  friend class Serializer;
78 
79  void save(Serializer& rSerializer) const
80  {
81  rSerializer.save("alpha", alpha);
82  rSerializer.save("delta_time", delta_time);
83  rSerializer.save("c0", c0);
84  rSerializer.save("c1", c1);
85  };
86 
87  void load(Serializer& rSerializer)
88  {
89  rSerializer.load("alpha", alpha);
90  rSerializer.load("delta_time", delta_time);
91  rSerializer.load("c0", c0);
92  rSerializer.load("c1", c1);
93  };
94 
95  };
96 
97  public:
98 
101 
104 
106  typedef typename BaseType::Pointer BasePointerType;
107 
109  typedef typename BaseType::NodeType NodeType;
110 
113 
115 
119 
120 
123  {
124  mpStepVariable = nullptr;
125  }
126 
128  EmcStepMethod(const TVariableType& rVariable) : BaseType(rVariable)
129  {
130  mpStepVariable = nullptr;
131  }
132 
134  EmcStepMethod(const TVariableType& rVariable, const TVariableType& rFirstDerivative, const TVariableType& rSecondDerivative) : BaseType(rVariable,rFirstDerivative,rSecondDerivative)
135  {
136  mpStepVariable = nullptr;
137  }
138 
140  EmcStepMethod(const TVariableType& rVariable, const TVariableType& rFirstDerivative, const TVariableType& rSecondDerivative, const TVariableType& rPrimaryVariable) : BaseType(rVariable,rFirstDerivative,rSecondDerivative,rPrimaryVariable)
141  {
142  mpStepVariable = nullptr;
143  }
144 
147  :BaseType(rOther)
148  ,mEmc(rOther.mEmc)
150  {
151  }
152 
155  {
156  return BasePointerType( new EmcStepMethod(*this) );
157  }
158 
160  ~EmcStepMethod() override{}
161 
165 
169 
170  //calculate parameters (to call it once with the original input parameters)
171  void CalculateParameters(ProcessInfo& rCurrentProcessInfo) override
172  {
173  KRATOS_TRY
174 
175 
176  double alpha = 0.5;
177  if (rCurrentProcessInfo.Has(EQUILIBRIUM_POINT))
178  {
179  alpha = rCurrentProcessInfo[EQUILIBRIUM_POINT];
180  }
181 
182  rCurrentProcessInfo[EQUILIBRIUM_POINT] = alpha;
183 
184  this->SetParameters(rCurrentProcessInfo);
185 
186  KRATOS_CATCH( "" )
187  }
188 
189 
190  // set parameters (do not calculate parameters here, only read them)
191  void SetParameters(const ProcessInfo& rCurrentProcessInfo) override
192  {
193  KRATOS_TRY
194 
195  double delta_time = rCurrentProcessInfo[DELTA_TIME];
196 
197  if (delta_time < 1.0e-24)
198  {
199  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;
200  }
201 
202  double alpha = 0.5;
203  if (rCurrentProcessInfo.Has(EQUILIBRIUM_POINT))
204  {
205  alpha = rCurrentProcessInfo[EQUILIBRIUM_POINT];
206  }
207 
209 
210  KRATOS_CATCH( "" )
211  }
212 
213  // set parameters to process info
214  void SetProcessInfoParameters(ProcessInfo& rCurrentProcessInfo) override
215  {
216  KRATOS_TRY
217 
218  rCurrentProcessInfo[EQUILIBRIUM_POINT] = this->mEmc.alpha;
219 
220  KRATOS_CATCH( "" )
221  }
222 
223  // has step variable
224  bool HasStepVariable() override
225  {
226  return true;
227  }
228 
229  // set step variable (step variable)
230  void SetStepVariable(const TVariableType& rStepVariable) override
231  {
232  mpStepVariable = &rStepVariable;
233  }
234 
239  int Check( const ProcessInfo& rCurrentProcessInfo ) override
240  {
241  KRATOS_TRY
242 
243  // Perform base integration method checks
244  int ErrorCode = 0;
245  ErrorCode = BaseType::Check(rCurrentProcessInfo);
246 
247  if( this->mpStepVariable == nullptr ){
248  KRATOS_ERROR << " time integration method Step Variable not set " <<std::endl;
249  }
250 
251  return ErrorCode;
252 
253  KRATOS_CATCH("")
254  }
255 
259 
263 
267 
268 
270  std::string Info() const override
271  {
272  std::stringstream buffer;
273  buffer << "EmcStepMethod";
274  return buffer.str();
275  }
276 
278  void PrintInfo(std::ostream& rOStream) const override
279  {
280  rOStream << "EmcStepMethod";
281  }
282 
284  void PrintData(std::ostream& rOStream) const override
285  {
286  rOStream << "EmcStepMethod Data";
287  }
288 
289 
293 
294 
296 
297  protected:
298 
301 
305 
306  // method parameters
308 
309  // method variables
311 
315 
319 
320 
321  void AssignFromVariable(NodeType& rNode) override
322  {
323  KRATOS_TRY
324 
325  // predict variable from variable
326 
327 
328  KRATOS_CATCH( "" )
329  }
330 
331 
332  void AssignFromFirstDerivative(NodeType& rNode) override
333  {
334  KRATOS_TRY
335 
336  // predict variable from first derivative
337  TValueType& CurrentVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 0);
338  const TValueType& PreviousVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 1);
339 
340  const TValueType& CurrentFirstDerivative = rNode.FastGetSolutionStepValue(*this->mpFirstDerivative, 0);
341  TValueType& PreviousFirstDerivative = rNode.FastGetSolutionStepValue(*this->mpFirstDerivative, 1);
342 
343  PreviousFirstDerivative = CurrentFirstDerivative;
344 
345  CurrentVariable = PreviousVariable + (CurrentFirstDerivative+PreviousFirstDerivative) * (1.0/this->mEmc.c0);
346 
347  KRATOS_CATCH( "" )
348  }
349 
350  void AssignFromSecondDerivative(NodeType& rNode) override
351  {
352  KRATOS_TRY
353 
354  // predict variable from second derivative
355  TValueType& CurrentVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 0);
356  const TValueType& PreviousVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 1);
357 
358  const TValueType& CurrentSecondDerivative = rNode.FastGetSolutionStepValue(*this->mpSecondDerivative, 0);
359 
360  CurrentVariable = PreviousVariable + CurrentSecondDerivative * (1.0/(this->mEmc.c0*this->mEmc.c1));
361 
362  KRATOS_CATCH( "" )
363  }
364 
365  void PredictFromVariable(NodeType& rNode) override
366  {
367  KRATOS_TRY
368 
369  this->PredictStepVariable(rNode);
370  this->PredictFirstDerivative(rNode);
371  this->PredictSecondDerivative(rNode);
372  this->PredictVariable(rNode);
373 
374  // const TValueType& CurrentVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 0);
375  // const TValueType& CurrentStepVariable = rNode.FastGetSolutionStepValue(*this->mpStepVariable, 0);
376  // const TValueType& CurrentFirstDerivative = rNode.FastGetSolutionStepValue(*this->mpFirstDerivative, 0);
377  // const TValueType& CurrentSecondDerivative = rNode.FastGetSolutionStepValue(*this->mpSecondDerivative, 0);
378 
379  // std::cout<<*this->mpVariable<<" Predict Node["<<rNode.Id()<<"]"<<CurrentVariable<<" "<<CurrentStepVariable<<" "<<CurrentFirstDerivative<<" "<<CurrentSecondDerivative<<std::endl;
380 
381  KRATOS_CATCH( "" )
382  }
383 
384  virtual void PredictStepVariable(NodeType& rNode)
385  {
386  KRATOS_TRY
387 
388  // predict step variable from previous and current values
389  TValueType& CurrentStepVariable = rNode.FastGetSolutionStepValue(*this->mpStepVariable, 0);
390 
391  const TValueType& CurrentVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 0);
392  const TValueType& PreviousVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 1);
393 
394  CurrentStepVariable = CurrentVariable-PreviousVariable;
395 
396  KRATOS_CATCH( "" )
397  }
398 
399  void PredictVariable(NodeType& rNode) override
400  {
401  KRATOS_TRY
402 
403  const TValueType& CurrentVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 0);
404  TValueType& PreviousVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 1);
405 
406  // update variable previous iteration instead of previous step
407  PreviousVariable = CurrentVariable;
408 
409  KRATOS_CATCH( "" )
410  }
411 
412  void PredictFirstDerivative(NodeType& rNode) override
413  {
414  KRATOS_TRY
415 
416  const TValueType& CurrentVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 0);
417  TValueType& CurrentFirstDerivative = rNode.FastGetSolutionStepValue(*this->mpFirstDerivative, 0);
418 
419  const TValueType& PreviousVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 1);
420  const TValueType& PreviousFirstDerivative = rNode.FastGetSolutionStepValue(*this->mpFirstDerivative, 1);
421 
422  CurrentFirstDerivative = this->mEmc.c0 * (CurrentVariable-PreviousVariable) - PreviousFirstDerivative;
423 
424  KRATOS_CATCH( "" )
425  }
426 
427  void PredictSecondDerivative(NodeType& rNode) override
428  {
429  KRATOS_TRY
430 
431 
432  const TValueType& CurrentFirstDerivative = rNode.FastGetSolutionStepValue(*this->mpFirstDerivative, 0);
433 
434  TValueType& CurrentSecondDerivative = rNode.FastGetSolutionStepValue(*this->mpSecondDerivative, 0);
435 
436  const TValueType& PreviousFirstDerivative = rNode.FastGetSolutionStepValue(*this->mpSecondDerivative, 1);
437 
438  CurrentSecondDerivative = this->mEmc.c1 * (CurrentFirstDerivative-PreviousFirstDerivative);
439 
440 
441  KRATOS_CATCH( "" )
442  }
443 
444 
445  void UpdateFromVariable(NodeType& rNode) override
446  {
447  KRATOS_TRY
448 
449  this->UpdateStepVariable(rNode);
450  this->UpdateFirstDerivative(rNode);
451  this->UpdateSecondDerivative(rNode);
452  this->UpdateVariable(rNode);
453 
454  // const TValueType& CurrentVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 0);
455  // const TValueType& CurrentStepVariable = rNode.FastGetSolutionStepValue(*this->mpStepVariable, 0);
456  // const TValueType& CurrentFirstDerivative = rNode.FastGetSolutionStepValue(*this->mpFirstDerivative, 0);
457  // const TValueType& CurrentSecondDerivative = rNode.FastGetSolutionStepValue(*this->mpSecondDerivative, 0);
458 
459  // std::cout<<*this->mpVariable<<" Update Node["<<rNode.Id()<<"]"<<CurrentVariable<<" "<<CurrentStepVariable<<" "<<CurrentFirstDerivative<<" "<<CurrentSecondDerivative<<std::endl;
460 
461  KRATOS_CATCH( "" )
462  }
463 
464 
465  virtual void UpdateStepVariable(NodeType& rNode)
466  {
467  KRATOS_TRY
468 
469  // predict step variable from previous and current values
470  TValueType& CurrentStepVariable = rNode.FastGetSolutionStepValue(*this->mpStepVariable, 0);
471 
472  const TValueType& CurrentVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 0);
473  const TValueType& PreviousVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 1);
474 
475  CurrentStepVariable += CurrentVariable-PreviousVariable;
476 
477  KRATOS_CATCH( "" )
478  }
479 
480  void UpdateVariable(NodeType& rNode) override
481  {
482  KRATOS_TRY
483 
484  const TValueType& CurrentVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 0);
485  TValueType& PreviousVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 1);
486 
487  // update variable previous iteration instead of previous step
488  PreviousVariable = CurrentVariable;
489 
490  KRATOS_CATCH( "" )
491  }
492 
493  void UpdateFirstDerivative(NodeType& rNode) override
494  {
495  KRATOS_TRY
496 
497  TValueType& CurrentFirstDerivative = rNode.FastGetSolutionStepValue(*this->mpFirstDerivative, 0);
498  const TValueType& PreviousFirstDerivative = rNode.FastGetSolutionStepValue(*this->mpFirstDerivative, 1);
499 
500  const TValueType& CurrentStepVariable = rNode.FastGetSolutionStepValue(*this->mpStepVariable, 0);
501 
502  CurrentFirstDerivative = this->mEmc.c0 * (CurrentStepVariable) - PreviousFirstDerivative;
503 
504 
505  KRATOS_CATCH( "" )
506  }
507 
508  void UpdateSecondDerivative(NodeType& rNode) override
509  {
510  KRATOS_TRY
511 
512  TValueType& CurrentSecondDerivative = rNode.FastGetSolutionStepValue(*this->mpSecondDerivative, 0);
513 
514  const TValueType& CurrentFirstDerivative = rNode.FastGetSolutionStepValue(*this->mpFirstDerivative, 0);
515  const TValueType& PreviousFirstDerivative = rNode.FastGetSolutionStepValue(*this->mpFirstDerivative, 1);
516 
517  CurrentSecondDerivative = this->mEmc.c1 * (CurrentFirstDerivative - PreviousFirstDerivative);
518 
519  KRATOS_CATCH( "" )
520  }
521 
522 
526 
530 
534 
536 
537  private:
538 
541 
545 
549 
553 
557 
561  friend class Serializer;
562 
563  void save(Serializer& rSerializer) const override
564  {
566  rSerializer.save("EmcParameters", mEmc);
567  // rSerializer.save("StepVariable", mpStepVariable);
568  };
569 
570  void load(Serializer& rSerializer) override
571  {
573  rSerializer.load("EmcParameters", mEmc);
574  // rSerializer.load("StepVariable", mpStepVariable);
575  };
576 
580 
584 
586 
587  }; // Class EmcStepMethod
588 
590 
593 
594 
598 
599  template<class TVariableType, class TValueType>
600  inline std::istream & operator >> (std::istream & rIStream, EmcStepMethod<TVariableType,TValueType>& rThis)
601  {
602  return rIStream;
603  }
604 
605  template<class TVariableType, class TValueType>
606  inline std::ostream & operator << (std::ostream & rOStream, const EmcStepMethod<TVariableType,TValueType>& rThis)
607  {
608  return rOStream << rThis.Info();
609  }
610 
612 
614 
615 } // namespace Kratos.
616 
617 #endif // KRATOS_EMC_STEP_METHOD_H_INCLUDED defined
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
Short class definition.
Definition: emc_step_method.hpp:51
BasePointerType Clone() override
Clone.
Definition: emc_step_method.hpp:154
virtual void PredictStepVariable(NodeType &rNode)
Definition: emc_step_method.hpp:384
void PredictSecondDerivative(NodeType &rNode) override
Definition: emc_step_method.hpp:427
void PredictFirstDerivative(NodeType &rNode) override
Definition: emc_step_method.hpp:412
BaseType::NodeType NodeType
NodeType.
Definition: emc_step_method.hpp:109
EmcStepMethod(const TVariableType &rVariable, const TVariableType &rFirstDerivative, const TVariableType &rSecondDerivative)
Constructor.
Definition: emc_step_method.hpp:134
EmcParameters mEmc
Definition: emc_step_method.hpp:307
BaseType::Pointer BasePointerType
BasePointerType.
Definition: emc_step_method.hpp:106
int Check(const ProcessInfo &rCurrentProcessInfo) override
This function is designed to be called once to perform all the checks needed.
Definition: emc_step_method.hpp:239
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: emc_step_method.hpp:284
void UpdateSecondDerivative(NodeType &rNode) override
Definition: emc_step_method.hpp:508
virtual void UpdateStepVariable(NodeType &rNode)
Definition: emc_step_method.hpp:465
void AssignFromSecondDerivative(NodeType &rNode) override
Definition: emc_step_method.hpp:350
void UpdateVariable(NodeType &rNode) override
Definition: emc_step_method.hpp:480
void SetProcessInfoParameters(ProcessInfo &rCurrentProcessInfo) override
Definition: emc_step_method.hpp:214
EmcStepMethod(const TVariableType &rVariable, const TVariableType &rFirstDerivative, const TVariableType &rSecondDerivative, const TVariableType &rPrimaryVariable)
Constructor.
Definition: emc_step_method.hpp:140
void UpdateFirstDerivative(NodeType &rNode) override
Definition: emc_step_method.hpp:493
void UpdateFromVariable(NodeType &rNode) override
Definition: emc_step_method.hpp:445
void SetParameters(const ProcessInfo &rCurrentProcessInfo) override
Definition: emc_step_method.hpp:191
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: emc_step_method.hpp:278
EmcStepMethod(EmcStepMethod &rOther)
Copy Constructor.
Definition: emc_step_method.hpp:146
~EmcStepMethod() override
Destructor.
Definition: emc_step_method.hpp:160
TimeIntegrationMethod< TVariableType, TValueType > BaseType
BaseType.
Definition: emc_step_method.hpp:103
void PredictFromVariable(NodeType &rNode) override
Definition: emc_step_method.hpp:365
EmcStepMethod(const TVariableType &rVariable)
Constructor.
Definition: emc_step_method.hpp:128
VariablePointer mpStepVariable
Definition: emc_step_method.hpp:310
BaseType::VariablePointer VariablePointer
KratosVariable or KratosVariableComponent.
Definition: emc_step_method.hpp:112
bool HasStepVariable() override
Definition: emc_step_method.hpp:224
void SetStepVariable(const TVariableType &rStepVariable) override
Definition: emc_step_method.hpp:230
void AssignFromFirstDerivative(NodeType &rNode) override
Definition: emc_step_method.hpp:332
void AssignFromVariable(NodeType &rNode) override
Definition: emc_step_method.hpp:321
KRATOS_CLASS_POINTER_DEFINITION(EmcStepMethod)
EmcStepMethod()
Default Constructor.
Definition: emc_step_method.hpp:122
void CalculateParameters(ProcessInfo &rCurrentProcessInfo) override
Definition: emc_step_method.hpp:171
void PredictVariable(NodeType &rNode) override
Definition: emc_step_method.hpp:399
std::string Info() const override
Turn back information as a string.
Definition: emc_step_method.hpp:270
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
alpha
Definition: generate_convection_diffusion_explicit_element.py:113
delta_time
Definition: generate_frictional_mortar_condition.py:130
def load(f)
Definition: ode_solve.py:307
Definition: emc_step_method.hpp:55
double c0
Definition: emc_step_method.hpp:60
void SetParameters(const double &ralpha, const double &rdelta_time)
Definition: emc_step_method.hpp:63
double c1
Definition: emc_step_method.hpp:61
double alpha
Definition: emc_step_method.hpp:56
double delta_time
Definition: emc_step_method.hpp:57