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.
newmark_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_NEWMARK_STEP_METHOD_H_INCLUDED)
11 #define KRATOS_NEWMARK_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 NewmarkStepMethod : public NewmarkMethod<TVariableType,TValueType>
51  {
52  public:
53 
56 
59 
61  typedef typename BaseType::Pointer BasePointerType;
62 
64  typedef typename BaseType::NodeType NodeType;
65 
68 
71 
72 
74 
78 
79 
82  {
83  mpStepVariable = nullptr;
84  }
85 
87  NewmarkStepMethod(const TVariableType& rVariable) : DerivedType(rVariable)
88  {
89  mpStepVariable = nullptr;
90  }
91 
93  NewmarkStepMethod(const TVariableType& rVariable, const TVariableType& rFirstDerivative, const TVariableType& rSecondDerivative) : DerivedType(rVariable,rFirstDerivative,rSecondDerivative)
94  {
95  mpStepVariable = nullptr;
96  }
97 
99  NewmarkStepMethod(const TVariableType& rVariable, const TVariableType& rFirstDerivative, const TVariableType& rSecondDerivative, const TVariableType& rPrimaryVariable) : DerivedType(rVariable,rFirstDerivative,rSecondDerivative,rPrimaryVariable)
100  {
101  mpStepVariable = nullptr;
102  }
103 
106  :DerivedType(rOther)
108  {
109  }
110 
113  {
114  return BasePointerType( new NewmarkStepMethod(*this) );
115  }
116 
118  ~NewmarkStepMethod() override{}
119 
123 
127 
128  // has step variable
129  bool HasStepVariable() override
130  {
131  return true;
132  }
133 
134  // set step variable (step variable)
135  void SetStepVariable(const TVariableType& rStepVariable) override
136  {
137  mpStepVariable = &rStepVariable;
138  }
139 
140 
145  int Check( const ProcessInfo& rCurrentProcessInfo ) override
146  {
147  KRATOS_TRY
148 
149  // Perform base integration method checks
150  int ErrorCode = 0;
151  ErrorCode = BaseType::Check(rCurrentProcessInfo);
152 
153  if( this->mpStepVariable == nullptr ){
154  KRATOS_ERROR << " time integration method Step Variable not set " <<std::endl;
155  }
156 
157  return ErrorCode;
158 
159  KRATOS_CATCH("")
160  }
161 
165 
169 
173 
174 
176  std::string Info() const override
177  {
178  std::stringstream buffer;
179  buffer << "NewmarkStepMethod";
180  return buffer.str();
181  }
182 
184  void PrintInfo(std::ostream& rOStream) const override
185  {
186  rOStream << "NewmarkStepMethod";
187  }
188 
190  void PrintData(std::ostream& rOStream) const override
191  {
192  rOStream << "NewmarkStepMethod Data";
193  }
194 
195 
199 
200 
202 
203  protected:
204 
207 
211 
212  // method variables
214 
218 
219  void AssignFromFirstDerivative(NodeType& rNode) override
220  {
221  KRATOS_TRY
222 
223  // predict variable from first derivative
224  TValueType& CurrentVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 0);
225  TValueType& CurrentFirstDerivative = rNode.FastGetSolutionStepValue(*this->mpFirstDerivative, 0);
226 
227  const TValueType& PreviousVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 1);
228  const TValueType& PreviousFirstDerivative = rNode.FastGetSolutionStepValue(*this->mpFirstDerivative, 1);
229  const TValueType& PreviousSecondDerivative = rNode.FastGetSolutionStepValue(*this->mpSecondDerivative, 1);
230 
231  // newmark consistent
232  CurrentVariable = PreviousVariable + this->mNewmark.delta_time * ( ( 1.0 - (this->mNewmark.beta/this->mNewmark.gamma) ) * PreviousFirstDerivative + (this->mNewmark.beta/this->mNewmark.gamma) * CurrentFirstDerivative + this->mNewmark.delta_time * 0.5 * ( 1.0 - 2.0 * (this->mNewmark.beta/this->mNewmark.gamma) ) * PreviousSecondDerivative );
233  // uniform accelerated movement
234  //CurrentVariable = PreviousVariable + 0.5 * mNewmark.delta_time * (PreviousFirstDerivative + CurrentFirstDerivative) + 0.5 * mNewmark.delta_time * mNewmark.delta_time * PreviousSecondDerivative;
235 
236  TValueType& CurrentSecondDerivative = rNode.FastGetSolutionStepValue(*this->mpSecondDerivative, 0);
237 
238  // variable prediction :: uniform accelerated movement **
239  // CurrentVariable -= this->mNewmark.delta_time * PreviousFirstDerivative;
240 
241  //CurrentFirstDerivative = PreviousFirstDerivative;
242  CurrentSecondDerivative -= CurrentSecondDerivative;
243 
244  KRATOS_CATCH( "" )
245  }
246 
247  void AssignFromSecondDerivative(NodeType& rNode) override
248  {
249  KRATOS_TRY
250 
251  // predict variable from second derivative
252  TValueType& CurrentVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 0);
253  const TValueType& PreviousVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 1);
254 
255  TValueType& CurrentSecondDerivative = rNode.FastGetSolutionStepValue(*this->mpSecondDerivative, 0);
256 
257  const TValueType& PreviousFirstDerivative = rNode.FastGetSolutionStepValue(*this->mpFirstDerivative, 1);
258  const TValueType& PreviousSecondDerivative = rNode.FastGetSolutionStepValue(*this->mpSecondDerivative, 1);
259 
260  CurrentVariable = PreviousVariable + this->mNewmark.delta_time * PreviousFirstDerivative + this->mNewmark.delta_time * this->mNewmark.delta_time * ( 0.5 * ( 1.0 - 2.0 * this->mNewmark.beta ) * PreviousSecondDerivative + this->mNewmark.beta * CurrentSecondDerivative );
261 
262  // variable prediction :: uniform accelerated movement **
263  CurrentVariable -= this->mNewmark.delta_time * PreviousFirstDerivative + 0.5 * this->mNewmark.delta_time * this->mNewmark.delta_time * PreviousSecondDerivative;
264 
265  //CurrentSecondDerivative = PreviousSecondDerivative;
266 
267  KRATOS_CATCH( "" )
268  }
269 
273 
274 
275  void PredictFromVariable(NodeType& rNode) override
276  {
277  KRATOS_TRY
278 
279  this->PredictVariable(rNode);
280  this->PredictStepVariable(rNode);
281  this->PredictFirstDerivative(rNode);
282  this->PredictSecondDerivative(rNode);
283 
284 
285  // const TValueType& CurrentVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 0);
286  // const TValueType& CurrentStepVariable = rNode.FastGetSolutionStepValue(*this->mpStepVariable, 0);
287  // const TValueType& CurrentFirstDerivative = rNode.FastGetSolutionStepValue(*this->mpFirstDerivative, 0);
288  // const TValueType& CurrentSecondDerivative = rNode.FastGetSolutionStepValue(*this->mpSecondDerivative, 0);
289 
290  // std::cout<<*this->mpVariable<<" Predict Node["<<rNode.Id()<<"]"<<CurrentVariable<<" "<<CurrentStepVariable<<" "<<CurrentFirstDerivative<<" "<<CurrentSecondDerivative<<std::endl;
291 
292  KRATOS_CATCH( "" )
293  }
294 
295  virtual void PredictStepVariable(NodeType& rNode)
296  {
297  KRATOS_TRY
298 
299  // predict step variable from previous and current values
300  TValueType& CurrentStepVariable = rNode.FastGetSolutionStepValue(*this->mpStepVariable, 0);
301  const TValueType& CurrentVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 0);
302  TValueType& PreviousVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 1);
303 
304  CurrentStepVariable = CurrentVariable-PreviousVariable;
305 
306  // update variable previous iteration instead of previous step
307  PreviousVariable = CurrentVariable;
308 
309  KRATOS_CATCH( "" )
310  }
311 
312  void PredictVariable(NodeType& rNode) override
313  {
314  KRATOS_TRY
315 
316  TValueType& CurrentVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 0);
317  const TValueType& CurrentFirstDerivative = rNode.FastGetSolutionStepValue(*this->mpFirstDerivative, 0);
318  const TValueType& CurrentSecondDerivative = rNode.FastGetSolutionStepValue(*this->mpSecondDerivative, 0);
319 
320  // variable prediction :: uniform accelerated movement **
321  CurrentVariable += this->mNewmark.delta_time * CurrentFirstDerivative + 0.5 * this->mNewmark.delta_time * this->mNewmark.delta_time * CurrentSecondDerivative;
322 
323  KRATOS_CATCH( "" )
324  }
325 
326  void PredictFirstDerivative(NodeType& rNode) override
327  {
328  KRATOS_TRY
329 
330  const TValueType& CurrentStepVariable = rNode.FastGetSolutionStepValue(*this->mpStepVariable, 0);
331  TValueType& CurrentFirstDerivative = rNode.FastGetSolutionStepValue(*this->mpFirstDerivative, 0);
332  const TValueType& CurrentSecondDerivative = rNode.FastGetSolutionStepValue(*this->mpSecondDerivative, 0);
333 
334  CurrentFirstDerivative = this->mNewmark.c1 * CurrentStepVariable - this->mNewmark.c4 * CurrentFirstDerivative - this->mNewmark.c5 * CurrentSecondDerivative;
335 
336  KRATOS_CATCH( "" )
337  }
338 
339  void PredictSecondDerivative(NodeType& rNode) override
340  {
341  KRATOS_TRY
342 
343  const TValueType& CurrentFirstDerivative = rNode.FastGetSolutionStepValue(*this->mpFirstDerivative, 0);
344  TValueType& CurrentSecondDerivative = rNode.FastGetSolutionStepValue(*this->mpSecondDerivative, 0);
345  const TValueType& PreviousFirstDerivative = rNode.FastGetSolutionStepValue(*this->mpFirstDerivative, 1);
346 
347  CurrentSecondDerivative = ( 1.0 / (this->mNewmark.gamma * this->mNewmark.delta_time) ) * ( CurrentFirstDerivative - PreviousFirstDerivative - ( 1.0 - this->mNewmark.gamma ) * this->mNewmark.delta_time * CurrentSecondDerivative );
348 
349  KRATOS_CATCH( "" )
350  }
351 
352 
353  void UpdateFromVariable(NodeType& rNode) override
354  {
355  KRATOS_TRY
356 
357  this->UpdateStepVariable(rNode);
358  this->UpdateFirstDerivative(rNode);
359  this->UpdateSecondDerivative(rNode);
360  this->UpdateVariable(rNode);
361 
362  // const TValueType& CurrentVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 0);
363  // const TValueType& CurrentStepVariable = rNode.FastGetSolutionStepValue(*this->mpStepVariable, 0);
364  // const TValueType& CurrentFirstDerivative = rNode.FastGetSolutionStepValue(*this->mpFirstDerivative, 0);
365  // const TValueType& CurrentSecondDerivative = rNode.FastGetSolutionStepValue(*this->mpSecondDerivative, 0);
366 
367  // std::cout<<*this->mpVariable<<" Update Node["<<rNode.Id()<<"]"<<CurrentVariable<<" "<<CurrentStepVariable<<" "<<CurrentFirstDerivative<<" "<<CurrentSecondDerivative<<std::endl;
368 
369  KRATOS_CATCH( "" )
370  }
371 
372 
373  virtual void UpdateStepVariable(NodeType& rNode)
374  {
375  KRATOS_TRY
376 
377  // predict step variable from previous and current values
378  TValueType& CurrentStepVariable = rNode.FastGetSolutionStepValue(*this->mpStepVariable, 0);
379 
380  const TValueType& CurrentVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 0);
381  const TValueType& PreviousVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 1);
382 
383  CurrentStepVariable += CurrentVariable-PreviousVariable;
384 
385  KRATOS_CATCH( "" )
386  }
387 
388  void UpdateVariable(NodeType& rNode) override
389  {
390  KRATOS_TRY
391 
392  const TValueType& CurrentVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 0);
393  TValueType& PreviousVariable = rNode.FastGetSolutionStepValue(*this->mpVariable, 1);
394 
395  // update variable previous iteration instead of previous step
396  PreviousVariable = CurrentVariable;
397 
398  KRATOS_CATCH( "" )
399  }
400 
401  void UpdateFirstDerivative(NodeType& rNode) override
402  {
403  KRATOS_TRY
404 
405  const TValueType& CurrentStepVariable = rNode.FastGetSolutionStepValue(*this->mpStepVariable, 0);
406  TValueType& CurrentFirstDerivative = rNode.FastGetSolutionStepValue(*this->mpFirstDerivative, 0);
407  const TValueType& PreviousFirstDerivative = rNode.FastGetSolutionStepValue(*this->mpFirstDerivative, 1);
408  const TValueType& PreviousSecondDerivative = rNode.FastGetSolutionStepValue(*this->mpSecondDerivative, 1);
409 
410  CurrentFirstDerivative = (this->mNewmark.c1 * (CurrentStepVariable) - this->mNewmark.c4 * PreviousFirstDerivative - this->mNewmark.c5 * PreviousSecondDerivative);
411 
412  KRATOS_CATCH( "" )
413  }
414 
415  void UpdateSecondDerivative(NodeType& rNode) override
416  {
417  KRATOS_TRY
418 
419  const TValueType& CurrentStepVariable = rNode.FastGetSolutionStepValue(*this->mpStepVariable, 0);
420  TValueType& CurrentSecondDerivative = rNode.FastGetSolutionStepValue(*this->mpSecondDerivative, 0);
421  const TValueType& PreviousFirstDerivative = rNode.FastGetSolutionStepValue(*this->mpFirstDerivative, 1);
422  const TValueType& PreviousSecondDerivative = rNode.FastGetSolutionStepValue(*this->mpSecondDerivative, 1);
423 
424  CurrentSecondDerivative = (this->mNewmark.c0 * (CurrentStepVariable) - this->mNewmark.c2 * PreviousFirstDerivative - this->mNewmark.c3 * PreviousSecondDerivative);
425 
426  KRATOS_CATCH( "" )
427  }
428 
432 
436 
440 
442 
443  private:
444 
447 
451 
455 
459 
463 
467  friend class Serializer;
468 
469  void save(Serializer& rSerializer) const override
470  {
472  // rSerializer.save("StepVariable", mpStepVariable);
473  };
474 
475  void load(Serializer& rSerializer) override
476  {
478  // rSerializer.load("StepVariable", mpStepVariable);
479  };
480 
484 
488 
490 
491  }; // Class NewmarkStepMethod
492 
494 
497 
498 
502 
503  template<class TVariableType, class TValueType>
504  inline std::istream & operator >> (std::istream & rIStream, NewmarkStepMethod<TVariableType,TValueType>& rThis)
505  {
506  return rIStream;
507  }
508 
509  template<class TVariableType, class TValueType>
510  inline std::ostream & operator << (std::ostream & rOStream, const NewmarkStepMethod<TVariableType,TValueType>& rThis)
511  {
512  return rOStream << rThis.Info();
513  }
514 
516 
518 
519 } // namespace Kratos.
520 
521 #endif // KRATOS_NEWMARK_STEP_METHOD_H_INCLUDED defined
Short class definition.
Definition: newmark_method.hpp:51
BaseType::Pointer BasePointerType
BasePointerType.
Definition: newmark_method.hpp:128
NewmarkParameters mNewmark
Definition: newmark_method.hpp:320
BaseType::VariablePointer VariablePointer
KratosVariable or KratosVariableComponent.
Definition: newmark_method.hpp:134
Short class definition.
Definition: newmark_step_method.hpp:51
int Check(const ProcessInfo &rCurrentProcessInfo) override
This function is designed to be called once to perform all the checks needed.
Definition: newmark_step_method.hpp:145
void PredictVariable(NodeType &rNode) override
Definition: newmark_step_method.hpp:312
void UpdateVariable(NodeType &rNode) override
Definition: newmark_step_method.hpp:388
void UpdateSecondDerivative(NodeType &rNode) override
Definition: newmark_step_method.hpp:415
NewmarkStepMethod(const TVariableType &rVariable, const TVariableType &rFirstDerivative, const TVariableType &rSecondDerivative)
Constructor.
Definition: newmark_step_method.hpp:93
BasePointerType Clone() override
Clone.
Definition: newmark_step_method.hpp:112
void UpdateFromVariable(NodeType &rNode) override
Definition: newmark_step_method.hpp:353
VariablePointer mpStepVariable
Definition: newmark_step_method.hpp:213
BaseType::VariablePointer VariablePointer
KratosVariable or KratosVariableComponent.
Definition: newmark_step_method.hpp:67
virtual void UpdateStepVariable(NodeType &rNode)
Definition: newmark_step_method.hpp:373
void AssignFromFirstDerivative(NodeType &rNode) override
Definition: newmark_step_method.hpp:219
void UpdateFirstDerivative(NodeType &rNode) override
Definition: newmark_step_method.hpp:401
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: newmark_step_method.hpp:190
void PredictFromVariable(NodeType &rNode) override
Definition: newmark_step_method.hpp:275
BaseType::NodeType NodeType
NodeType.
Definition: newmark_step_method.hpp:64
BaseType::Pointer BasePointerType
BasePointerType.
Definition: newmark_step_method.hpp:61
KRATOS_CLASS_POINTER_DEFINITION(NewmarkStepMethod)
void PredictFirstDerivative(NodeType &rNode) override
Definition: newmark_step_method.hpp:326
TimeIntegrationMethod< TVariableType, TValueType > BaseType
BaseType.
Definition: newmark_step_method.hpp:58
std::string Info() const override
Turn back information as a string.
Definition: newmark_step_method.hpp:176
NewmarkStepMethod(NewmarkStepMethod &rOther)
Copy Constructor.
Definition: newmark_step_method.hpp:105
bool HasStepVariable() override
Definition: newmark_step_method.hpp:129
NewmarkStepMethod(const TVariableType &rVariable)
Constructor.
Definition: newmark_step_method.hpp:87
NewmarkMethod< TVariableType, TValueType > DerivedType
DerivedType.
Definition: newmark_step_method.hpp:70
void SetStepVariable(const TVariableType &rStepVariable) override
Definition: newmark_step_method.hpp:135
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: newmark_step_method.hpp:184
void AssignFromSecondDerivative(NodeType &rNode) override
Definition: newmark_step_method.hpp:247
void PredictSecondDerivative(NodeType &rNode) override
Definition: newmark_step_method.hpp:339
NewmarkStepMethod()
Default Constructor.
Definition: newmark_step_method.hpp:81
~NewmarkStepMethod() override
Destructor.
Definition: newmark_step_method.hpp:118
virtual void PredictStepVariable(NodeType &rNode)
Definition: newmark_step_method.hpp:295
NewmarkStepMethod(const TVariableType &rVariable, const TVariableType &rFirstDerivative, const TVariableType &rSecondDerivative, const TVariableType &rPrimaryVariable)
Constructor.
Definition: newmark_step_method.hpp:99
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
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
def load(f)
Definition: ode_solve.py:307
double c5
Definition: newmark_method.hpp:67
double c4
Definition: newmark_method.hpp:66
double c1
Definition: newmark_method.hpp:63
double delta_time
Definition: newmark_method.hpp:59
double beta
Definition: newmark_method.hpp:56
double gamma
Definition: newmark_method.hpp:57
double c0
Definition: newmark_method.hpp:62
double c2
Definition: newmark_method.hpp:64