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.
poromechanics_face_load_control_module_process.hpp
Go to the documentation of this file.
1 // | / |
2 // ' / __| _` | __| _ \ __|
3 // . \ | ( | | ( |\__ `
4 // _|\_\_| \__,_|\__|\___/ ____/
5 // Multi-Physics
6 //
7 // License: BSD License
8 // Kratos default license: kratos/license.txt
9 //
10 // Main authors: Ignasi de Pouplana
11 //
12 
13 
14 #if !defined(KRATOS_POROMECHANICS_FACE_LOAD_CONTROL_MODULE_PROCESS )
15 #define KRATOS_POROMECHANICS_FACE_LOAD_CONTROL_MODULE_PROCESS
16 
17 #include "includes/table.h"
18 #include "includes/kratos_flags.h"
20 #include "processes/process.h"
21 
23 
24 namespace Kratos
25 {
26 
28 
30 {
31 
32 public:
33 
35 
38 
40 
43  ModelPart& rModelPart,
44  Parameters rParameters
45  ) : Process(Flags()) , mrModelPart(rModelPart)
46  {
48 
49  Parameters default_parameters( R"(
50  {
51  "model_part_name":"MODEL_PART_NAME",
52  "imposed_direction" : 0,
53  "face_load_table_id" : 0,
54  "initial_velocity" : 0.0,
55  "limit_velocity" : 1.0,
56  "velocity_factor" : 1.0,
57  "initial_stiffness" : 1.0e7,
58  "force_increment_tolerance": 100.0,
59  "update_stiffness": true,
60  "force_averaging_time": 1.0e-5
61  } )" );
62 
63  rParameters.ValidateAndAssignDefaults(default_parameters);
64 
65  double ImposedDirection = rParameters["imposed_direction"].GetInt();
66 
67  if(ImposedDirection == 2)
68  {
69  mDisplacementName = "DISPLACEMENT" + std::string("_Z");
70  mReactionName = "REACTION" + std::string("_Z");
71  mAverageReactionName = "AVERAGE_REACTION" + std::string("_Z");
72  mTargetReactionName = "TARGET_REACTION" + std::string("_Z");
73  mLoadingVelocityName = "LOADING_VELOCITY" + std::string("_Z");
74  }
75  else if(ImposedDirection == 1)
76  {
77  mDisplacementName = "DISPLACEMENT" + std::string("_Y");
78  mReactionName = "REACTION" + std::string("_Y");
79  mAverageReactionName = "AVERAGE_REACTION" + std::string("_Y");
80  mTargetReactionName = "TARGET_REACTION" + std::string("_Y");
81  mLoadingVelocityName = "LOADING_VELOCITY" + std::string("_Y");
82  }
83  else
84  {
85  mDisplacementName = "DISPLACEMENT" + std::string("_X");
86  mReactionName = "REACTION" + std::string("_X");
87  mAverageReactionName = "AVERAGE_REACTION" + std::string("_X");
88  mTargetReactionName = "TARGET_REACTION" + std::string("_X");
89  mLoadingVelocityName = "LOADING_VELOCITY" + std::string("_X");
90  }
91 
92  mFaceLoadTableId = rParameters["face_load_table_id"].GetInt();
93  mVelocity = rParameters["initial_velocity"].GetDouble();
94  mLimitVelocity = rParameters["limit_velocity"].GetDouble();
95  mVelocityFactor = rParameters["velocity_factor"].GetDouble();
96  mForceIncrementTolerance = rParameters["force_increment_tolerance"].GetDouble();
97  mUpdateStiffness = rParameters["update_stiffness"].GetBool();
98  mReactionForceOld = 0.0;
99  mStiffness = rParameters["initial_stiffness"].GetDouble();
100  mForceAveragingTime = rParameters["force_averaging_time"].GetDouble(); // If set equal to the time step, no average is performed
101  mVectorOfLastForces.resize(0);
102 
103  // Initialize Variables
104  const int NNodes = static_cast<int>(mrModelPart.Nodes().size());
105  ModelPart::NodesContainerType::iterator it_begin = mrModelPart.NodesBegin();
106  array_1d<double,3> zero_vector = ZeroVector(3);
107  #pragma omp parallel for
108  for(int i = 0; i<NNodes; i++) {
109  ModelPart::NodesContainerType::iterator it = it_begin + i;
110  it->SetValue(AVERAGE_REACTION,zero_vector);
111  it->SetValue(TARGET_REACTION,zero_vector);
112  it->SetValue(LOADING_VELOCITY,zero_vector);
113  }
114 
115  KRATOS_CATCH("");
116  }
117 
119 
122 
124 
126  void Execute() override
127  {
128  }
129 
132  void ExecuteInitialize() override
133  {
134  KRATOS_TRY;
135 
136  typedef Variable<double> component_type;
137  const component_type& disp_component = KratosComponents< component_type >::Get(mDisplacementName);
138  const component_type& loading_vel_component = KratosComponents< component_type >::Get(mLoadingVelocityName);
139 
140  const int NNodes = static_cast<int>(mrModelPart.Nodes().size());
141  ModelPart::NodesContainerType::iterator it_begin = mrModelPart.NodesBegin();
142 
143  #pragma omp parallel for
144  for(int i = 0; i<NNodes; i++) {
145  ModelPart::NodesContainerType::iterator it = it_begin + i;
146  it->Fix(disp_component);
147  it->FastGetSolutionStepValue(disp_component) = 0.0;
148  it->GetValue(loading_vel_component) = mVelocity;
149  }
150 
151  KRATOS_CATCH("");
152  }
153 
156  {
157  KRATOS_TRY;
158 
159  const double CurrentTime = mrModelPart.GetProcessInfo()[TIME];
160 
161  const int NNodes = static_cast<int>(mrModelPart.Nodes().size());
162  ModelPart::NodesContainerType::iterator it_begin = mrModelPart.NodesBegin();
163 
164  double ReactionForce = CalculateReactionForce();
165  ReactionForce = UpdateVectorOfHistoricalForcesAndComputeNewAverage(ReactionForce);
166 
167  // Update K if required
168  const double DeltaTime = mrModelPart.GetProcessInfo()[DELTA_TIME];
169  if(mUpdateStiffness == true) {
170  mStiffness = EstimateStiffness(ReactionForce,DeltaTime);
171  }
172  mReactionForceOld = ReactionForce;
173 
174  // Update velocity
175  const double NextTargetReaction = this->GetTargetReaction(CurrentTime+DeltaTime);
176  const double df_target = NextTargetReaction - ReactionForce;
177  double delta_velocity = df_target/(mStiffness * DeltaTime) - mVelocity;
178 
179  if(std::abs(df_target) < mForceIncrementTolerance) {
180  delta_velocity = -mVelocity;
181  }
182 
183  mVelocity += mVelocityFactor * delta_velocity;
184 
185  if(std::abs(mVelocity) > std::abs(mLimitVelocity)) {
186  if(mVelocity >= 0.0) {
187  mVelocity = std::abs(mLimitVelocity);
188  } else {
189  mVelocity = - std::abs(mLimitVelocity);
190  }
191  }
192 
193  typedef Variable<double> component_type;
194  const component_type& disp_component = KratosComponents< component_type >::Get(mDisplacementName);
195 
196  // Update Imposed displacement
197  #pragma omp parallel for
198  for(int i = 0; i<NNodes; i++) {
199  ModelPart::NodesContainerType::iterator it = it_begin + i;
200  it->FastGetSolutionStepValue(disp_component) += mVelocity * DeltaTime;
201  }
202 
203  KRATOS_CATCH("");
204  }
205 
206 
211  {
212  const double CurrentTime = mrModelPart.GetProcessInfo()[TIME];
213 
214  const int NNodes = static_cast<int>(mrModelPart.Nodes().size());
215  ModelPart::NodesContainerType::iterator it_begin = mrModelPart.NodesBegin();
216 
217  double ReactionForce = CalculateReactionForce();
218 
219  typedef Variable<double> component_type;
220  const component_type& target_reaction_component = KratosComponents< component_type >::Get(mTargetReactionName);
221  const component_type& average_reaction_component = KratosComponents< component_type >::Get(mAverageReactionName);
222  const component_type& loading_vel_component = KratosComponents< component_type >::Get(mLoadingVelocityName);
223 
224  // Update Imposed displacement
225  #pragma omp parallel for
226  for(int i = 0; i<NNodes; i++) {
227  ModelPart::NodesContainerType::iterator it = it_begin + i;
228  // Save calculated velocity and reaction for print
229  it->GetValue(target_reaction_component) = this->GetTargetReaction(CurrentTime);
230  it->GetValue(average_reaction_component) = ReactionForce;
231  it->GetValue(loading_vel_component) = mVelocity;
232  }
233  }
234 
236  std::string Info() const override
237  {
238  return "PoromechanicsFaceLoadControlModuleProcess";
239  }
240 
242  void PrintInfo(std::ostream& rOStream) const override
243  {
244  rOStream << "PoromechanicsFaceLoadControlModuleProcess";
245  }
246 
248  void PrintData(std::ostream& rOStream) const override
249  {
250  }
251 
253 
254 protected:
255 
257 
259  // unsigned int mImposedDirection;
260  std::string mDisplacementName;
261  std::string mReactionName;
262  std::string mAverageReactionName;
263  std::string mTargetReactionName;
264  std::string mLoadingVelocityName;
265  unsigned int mFaceLoadTableId;
266  double mVelocity;
271  double mStiffness;
273  std::vector<double> mVectorOfLastForces;
275 
277 
278  virtual double GetTargetReaction(const double& time) {
279 
280  // Calculate face_area
281  const int NCons = static_cast<int>(mrModelPart.Conditions().size());
282  ModelPart::ConditionsContainerType::iterator con_begin = mrModelPart.ConditionsBegin();
283  double FaceArea = 0.0;
284  #pragma omp parallel for reduction(+:FaceArea)
285  for(int i = 0; i < NCons; i++)
286  {
287  ModelPart::ConditionsContainerType::iterator itCond = con_begin + i;
288  FaceArea += itCond->GetGeometry().Area();
289  }
290 
291  // Get Target Face Load from table
292  TableType::Pointer pFaceLoadTable = mrModelPart.pGetTable(mFaceLoadTableId);
293  const double face_load = pFaceLoadTable->GetValue(time);
294 
295  return face_load*FaceArea;
296  }
297 
298  virtual double UpdateVectorOfHistoricalForcesAndComputeNewAverage(const double& last_reaction) {
299  KRATOS_TRY;
300  int length_of_vector = mVectorOfLastForces.size();
301  if (length_of_vector == 0) { //only the first time
302  int number_of_steps_for_force_averaging = (int) (mForceAveragingTime / mrModelPart.GetProcessInfo()[DELTA_TIME]);
303  if(number_of_steps_for_force_averaging < 1) number_of_steps_for_force_averaging = 1;
304  mVectorOfLastForces.resize(number_of_steps_for_force_averaging);
305  KRATOS_INFO("Poro control module") << " 'number_of_steps_for_force_averaging' is "<< number_of_steps_for_force_averaging << std::endl;
306  }
307 
308  length_of_vector = mVectorOfLastForces.size();
309 
310  if(length_of_vector > 1) {
311  for(int i=1; i<length_of_vector; i++) {
313  }
314  }
315  mVectorOfLastForces[length_of_vector-1] = last_reaction;
316 
317  double average = 0.0;
318  for(int i=0; i<length_of_vector; i++) {
319  average += mVectorOfLastForces[i];
320  }
321  average /= (double) length_of_vector;
322  return average;
323 
324  KRATOS_CATCH("");
325  }
326 
327  virtual double CalculateReactionForce() {
328 
329  typedef Variable<double> component_type;
330  const component_type& reaction_component = KratosComponents< component_type >::Get(mReactionName);
331 
332  const int NNodes = static_cast<int>(mrModelPart.Nodes().size());
333  ModelPart::NodesContainerType::iterator it_begin = mrModelPart.NodesBegin();
334 
335  // Calculate Average ReactionForce
336  double FaceReaction = 0.0;
337  #pragma omp parallel for reduction(+:FaceReaction)
338  for(int i = 0; i<NNodes; i++){
339  ModelPart::NodesContainerType::iterator it = it_begin + i;
340  FaceReaction += it->FastGetSolutionStepValue(reaction_component);
341  }
342 
343  return FaceReaction/NNodes;
344  }
345 
346  virtual double EstimateStiffness(const double& rReactionForce, const double& rDeltaTime) {
347  double K_estimated = mStiffness;
348  if(std::abs(mVelocity) > 1.0e-12 && std::abs(rReactionForce-mReactionForceOld) > mForceIncrementTolerance) {
349  K_estimated = std::abs((rReactionForce-mReactionForceOld)/(mVelocity * rDeltaTime));
350  }
351  return K_estimated;
352  }
353 
355 
356 private:
357 
360 
362  //PoromechanicsFaceLoadControlModuleProcess(PoromechanicsFaceLoadControlModuleProcess const& rOther);
363 
364 
365 
366 }; // Class PoromechanicsFaceLoadControlModuleProcess
367 
369 inline std::istream& operator >> (std::istream& rIStream,
371 
373 inline std::ostream& operator << (std::ostream& rOStream,
375 {
376  rThis.PrintInfo(rOStream);
377  rOStream << std::endl;
378  rThis.PrintData(rOStream);
379 
380  return rOStream;
381 }
382 
383 } // namespace Kratos.
384 
385 #endif /* KRATOS_POROMECHANICS_FACE_LOAD_CONTROL_MODULE_PROCESS defined */
Definition: flags.h:58
static const TComponentType & Get(const std::string &rName)
Retrieves a component with the specified name.
Definition: kratos_components.h:114
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
ConditionIterator ConditionsBegin(IndexType ThisIndex=0)
Definition: model_part.h:1361
NodeIterator NodesBegin(IndexType ThisIndex=0)
Definition: model_part.h:487
ConditionsContainerType & Conditions(IndexType ThisIndex=0)
Definition: model_part.h:1381
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
TableType::Pointer pGetTable(IndexType TableId)
Definition: model_part.h:595
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
double GetDouble() const
This method returns the double contained in the current Parameter.
Definition: kratos_parameters.cpp:657
int GetInt() const
This method returns the integer contained in the current Parameter.
Definition: kratos_parameters.cpp:666
void ValidateAndAssignDefaults(const Parameters &rDefaultParameters)
This function is designed to verify that the parameters under testing match the form prescribed by th...
Definition: kratos_parameters.cpp:1306
bool GetBool() const
This method returns the boolean contained in the current Parameter.
Definition: kratos_parameters.cpp:675
FaceLoad control module for displacements.
Definition: poromechanics_face_load_control_module_process.hpp:30
std::string mDisplacementName
Definition: poromechanics_face_load_control_module_process.hpp:260
Table< double, double > TableType
Defining a table with double argument and result type as table type.
Definition: poromechanics_face_load_control_module_process.hpp:37
unsigned int mFaceLoadTableId
Definition: poromechanics_face_load_control_module_process.hpp:265
void ExecuteInitialize() override
Definition: poromechanics_face_load_control_module_process.hpp:132
std::string mReactionName
Definition: poromechanics_face_load_control_module_process.hpp:261
std::string mLoadingVelocityName
Definition: poromechanics_face_load_control_module_process.hpp:264
std::string mAverageReactionName
Definition: poromechanics_face_load_control_module_process.hpp:262
void ExecuteFinalizeSolutionStep() override
This function will be executed at every time step AFTER performing the solve phase.
Definition: poromechanics_face_load_control_module_process.hpp:210
virtual double EstimateStiffness(const double &rReactionForce, const double &rDeltaTime)
Definition: poromechanics_face_load_control_module_process.hpp:346
virtual double CalculateReactionForce()
Definition: poromechanics_face_load_control_module_process.hpp:327
double mReactionForceOld
Definition: poromechanics_face_load_control_module_process.hpp:269
void Execute() override
Execute method is used to execute the PoromechanicsFaceLoadControlModuleProcess algorithms.
Definition: poromechanics_face_load_control_module_process.hpp:126
double mForceAveragingTime
Definition: poromechanics_face_load_control_module_process.hpp:274
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: poromechanics_face_load_control_module_process.hpp:248
KRATOS_CLASS_POINTER_DEFINITION(PoromechanicsFaceLoadControlModuleProcess)
std::string mTargetReactionName
Definition: poromechanics_face_load_control_module_process.hpp:263
ModelPart & mrModelPart
Member Variables.
Definition: poromechanics_face_load_control_module_process.hpp:258
bool mUpdateStiffness
Definition: poromechanics_face_load_control_module_process.hpp:272
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: poromechanics_face_load_control_module_process.hpp:242
void ExecuteInitializeSolutionStep() override
this function will be executed at every time step BEFORE performing the solve phase
Definition: poromechanics_face_load_control_module_process.hpp:155
double mStiffness
Definition: poromechanics_face_load_control_module_process.hpp:271
double mForceIncrementTolerance
Definition: poromechanics_face_load_control_module_process.hpp:270
double mVelocity
Definition: poromechanics_face_load_control_module_process.hpp:266
virtual double UpdateVectorOfHistoricalForcesAndComputeNewAverage(const double &last_reaction)
Definition: poromechanics_face_load_control_module_process.hpp:298
double mVelocityFactor
Definition: poromechanics_face_load_control_module_process.hpp:268
~PoromechanicsFaceLoadControlModuleProcess() override
Destructor.
Definition: poromechanics_face_load_control_module_process.hpp:121
double mLimitVelocity
Definition: poromechanics_face_load_control_module_process.hpp:267
std::vector< double > mVectorOfLastForces
Definition: poromechanics_face_load_control_module_process.hpp:273
PoromechanicsFaceLoadControlModuleProcess(ModelPart &rModelPart, Parameters rParameters)
Constructor.
Definition: poromechanics_face_load_control_module_process.hpp:42
std::string Info() const override
Turn back information as a string.
Definition: poromechanics_face_load_control_module_process.hpp:236
virtual double GetTargetReaction(const double &time)
Definition: poromechanics_face_load_control_module_process.hpp:278
The base class for all processes in Kratos.
Definition: process.h:49
Definition: table.h:435
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_INFO(label)
Definition: logger.h:250
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
KratosZeroVector< double > ZeroVector
Definition: amatrix_interface.h:561
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
REACTION_CHECK_STIFFNESS_FACTOR int
Definition: contact_structural_mechanics_application_variables.h:75
TABLE_NUMBER_ANGULAR_VELOCITY TABLE_NUMBER_MOMENT I33 BEAM_INERTIA_ROT_UNIT_LENGHT_Y KRATOS_DEFINE_APPLICATION_VARIABLE(DEM_APPLICATION, double, BEAM_INERTIA_ROT_UNIT_LENGHT_Z) typedef std double
Definition: DEM_application_variables.h:182
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
time
Definition: face_heat.py:85
integer i
Definition: TensorModule.f:17