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.
assign_rotation_field_about_an_axis_to_nodes_process.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: August 2017 $
6 // Revision: $Revision: 0.0 $
7 //
8 //
9 
10 #if !defined(KRATOS_ASSIGN_ROTATION_FIELD_ABOUT_AN_AXIS_TO_NODES_PROCESS_H_INCLUDED)
11 #define KRATOS_ASSIGN_ROTATION_FIELD_ABOUT_AN_AXIS_TO_NODES_PROCESS_H_INCLUDED
12 
13 
14 
15 // System includes
16 
17 // External includes
18 
19 // Project includes
21 
22 namespace Kratos
23 {
24 
27 
29 
32 {
33 public:
36 
39 
44  pybind11::object& rPyObject,
45  const std::string& rPyMethodName,
46  const bool SpatialFieldFunction,
47  Parameters rParameters
49  {
51 
52  Parameters default_parameters( R"(
53  {
54  "model_part_name":"MODEL_PART_NAME",
55  "variable_name": "VARIABLE_NAME",
56  "direction" : [],
57  "center" : []
58  } )" );
59 
60 
61  // Validate against defaults -- this ensures no type mismatch
62  rParameters.ValidateAndAssignDefaults(default_parameters);
63 
64  mvariable_name = rParameters["variable_name"].GetString();
65 
66  mPyObject = rPyObject;
67  mPyMethodName = rPyMethodName;
68 
69  mIsSpatialField = SpatialFieldFunction;
70 
71  for( unsigned int i=0; i<3; i++)
72  {
73  mdirection[i] = rParameters["direction"][i].GetDouble();
74  mcenter[i] = rParameters["center"][i].GetDouble();
75  }
76 
77  double norm = norm_2(mdirection);
78  if(norm!=0)
79  mdirection/=norm;
80 
81  KRATOS_CATCH("");
82  }
83 
84 
85 
88 
89 
93 
95  void operator()()
96  {
97  Execute();
98  }
99 
100 
104 
105 
107  void Execute() override
108  {
109 
110  KRATOS_TRY;
111 
112  if( ! mIsSpatialField ){
113 
114  const ProcessInfo& rCurrentProcessInfo = mrModelPart.GetProcessInfo();
115  const double& rCurrentTime = rCurrentProcessInfo[TIME];
116  const ProcessInfo& rPreviousProcessInfo = rCurrentProcessInfo.GetPreviousTimeStepInfo();
117  const double& rPreviousTime = rPreviousProcessInfo[TIME];
118 
119  this->CallTimeFunction(rPreviousTime, mprevious_value);
120  this->CallTimeFunction(rCurrentTime, mvalue);
121 
123 
124  }
125  else{
126 
127  AssignRotationAboutAnAxis();
128  }
129 
130  KRATOS_CATCH("");
131 
132  }
133 
136  void ExecuteInitialize() override
137  {
138  }
139 
143  {
144  }
145 
146 
149  {
150  }
151 
154  {
155  }
156 
157 
159  void ExecuteBeforeOutputStep() override
160  {
161  }
162 
163 
165  void ExecuteAfterOutputStep() override
166  {
167  }
168 
169 
172  void ExecuteFinalize() override
173  {
174  }
175 
176 
180 
181 
185 
186 
190 
192  std::string Info() const override
193  {
194  return "AssignRotationFieldAboutAnAxisToNodesProcess";
195  }
196 
198  void PrintInfo(std::ostream& rOStream) const override
199  {
200  rOStream << "AssignRotationFieldAboutAnAxisToNodesProcess";
201  }
202 
204  void PrintData(std::ostream& rOStream) const override
205  {
206  }
207 
208 
213 
214 protected:
215 
224 
227 
241 
242 private:
243 
249 
250  pybind11::object mPyObject;
251  std::string mPyMethodName;
252 
253  bool mIsSpatialField;
254 
258 
259  void CallFunction(const Node::Pointer& pNode, const double& time, double& rValue)
260  {
261  KRATOS_TRY
262 
263  if( mIsSpatialField ){
264 
265  double x = pNode->X(), y = pNode->Y(), z = pNode->Z();
266  rValue = mPyObject.attr(mPyMethodName.c_str())(x,y,z,time).cast<double>();
267 
268  }
269  else{
270 
271  rValue = mPyObject.attr(mPyMethodName.c_str())(0.0,0.0,0.0,time).cast<double>();
272 
273  }
274 
275  KRATOS_CATCH( "" )
276 
277  }
278 
279  void CallTimeFunction(const double& time, double& rValue)
280  {
281 
282  KRATOS_TRY
283 
284  rValue = mPyObject.attr(mPyMethodName.c_str())(0.0,0.0,0.0,time).cast<double>();
285 
286  KRATOS_CATCH( "" )
287 
288  }
289 
290 
291  void AssignRotationAboutAnAxis()
292  {
293  KRATOS_TRY
294 
295  const int nnodes = mrModelPart.GetMesh().Nodes().size();
296 
297  if(nnodes != 0)
298  {
299  ModelPart::NodesContainerType::iterator it_begin = mrModelPart.GetMesh().NodesBegin();
300 
301  Matrix rotation_matrix;
302  Quaternion<double> total_quaternion;
303  array_1d<double,3> radius;
304  array_1d<double,3> distance;
305  array_1d<double,3> rotation;
306  array_1d<double,3> delta_rotation;
307 
308 
309  //Possible prescribed variables: ROTATION / ANGULAR_VELOCITY / ANGULAR_ACCELERATION
310  double value = 0.0;
311  bool dynamic_angular_velocity = false;
312  bool dynamic_angular_acceleration = false;
313 
314  const ProcessInfo& rCurrentProcessInfo = mrModelPart.GetProcessInfo();
315  const double& rDeltaTime = rCurrentProcessInfo[DELTA_TIME];
316  const double& rCurrentTime = rCurrentProcessInfo[TIME];
317  const ProcessInfo& rPreviousProcessInfo = rCurrentProcessInfo.GetPreviousTimeStepInfo();
318  const double& rPreviousTime = rPreviousProcessInfo[TIME];
319 
320  array_1d<double,3> angular_velocity;
321  angular_velocity.clear();
322  array_1d<double,3> angular_acceleration;
323  angular_acceleration.clear();
324 
325  double time_factor = 0.0;
326  if(mvariable_name == "ROTATION"){
327 
328  time_factor = 1.0;
329 
330  }
331  else if(mvariable_name == "ANGULAR_VELOCITY"){
332 
333  dynamic_angular_velocity = true;
334  time_factor = rDeltaTime;
335 
336  }
337  else if(mvariable_name == "ANGULAR_ACCELERATION"){
338 
339  dynamic_angular_velocity = true;
340  dynamic_angular_acceleration = true;
341  time_factor = rDeltaTime * rDeltaTime;
342  }
343 
344  //#pragma omp parallel for //it does not work in parallel
345  for(int i = 0; i<nnodes; i++)
346  {
347  ModelPart::NodesContainerType::iterator it = it_begin + i;
348 
349  this->CallFunction(*(it.base()), rCurrentTime, value);
350 
351  rotation = value * mdirection;
352 
353  rotation *= time_factor;
354 
355  if( dynamic_angular_velocity ){
356 
357  this->CallFunction(*(it.base()), rPreviousTime, value);
358  delta_rotation = rotation - time_factor * value * mdirection;
359 
360  angular_velocity = delta_rotation / rDeltaTime;
361  if( dynamic_angular_acceleration ){
362  angular_acceleration = angular_velocity / rDeltaTime;
363  }
364  }
365 
366  //Get rotation matrix
367  total_quaternion = Quaternion<double>::FromRotationVector<array_1d<double,3> >(rotation);
368 
369  distance = it->GetInitialPosition() - mcenter;
370 
371  total_quaternion.ToRotationMatrix(rotation_matrix);
372 
373  noalias(radius) = prod(rotation_matrix, distance);
374 
375  array_1d<double,3>& displacement = it->FastGetSolutionStepValue(DISPLACEMENT);
376  displacement = radius - distance; //(mcenter + radius) - it->GetInitialPosition();
377 
378  if( dynamic_angular_velocity ){
379 
380  //compute the skewsymmmetric tensor of the angular velocity
381  BeamMathUtils<double>::VectorToSkewSymmetricTensor(angular_velocity, rotation_matrix);
382 
383  //compute the contribution of the angular velocity to the velocity v = Wxr
384  array_1d<double,3>& velocity = it->FastGetSolutionStepValue(VELOCITY);
385  velocity = prod(rotation_matrix,radius);
386 
387  if( dynamic_angular_acceleration ){
388  //compute the contribution of the centripetal acceleration ac = Wx(Wxr)
389  array_1d<double,3>& acceleration = it->FastGetSolutionStepValue(ACCELERATION);
390  acceleration = prod(rotation_matrix,velocity);
391 
392  //compute the contribution of the angular acceleration to the acceleration a = Axr
393  BeamMathUtils<double>::VectorToSkewSymmetricTensor(angular_acceleration, rotation_matrix);
394  acceleration += prod(rotation_matrix,radius);
395  }
396  }
397  }
398 
399  }
400 
401  KRATOS_CATCH( "" )
402  }
403 
404 
411 
414 
415 
425 
426 }; // Class AssignRotationFieldAboutAnAxisToNodesProcess
427 
428 
430 
433 
434 
438 
439 
441 inline std::istream& operator >> (std::istream& rIStream,
443 
445 inline std::ostream& operator << (std::ostream& rOStream,
447 {
448  rThis.PrintInfo(rOStream);
449  rOStream << std::endl;
450  rThis.PrintData(rOStream);
451 
452  return rOStream;
453 }
455 
456 
457 } // namespace Kratos.
458 
459 #endif // KRATOS_ASSIGN_ROTATION_FIELD_ABOUT_AN_AXIS_TO_NODES_PROCESS_H_INCLUDED defined
The base class for assigning a value to scalar variables or array_1d components processes in Kratos.
Definition: assign_rotation_about_an_axis_to_nodes_process.hpp:35
std::string mvariable_name
Definition: assign_rotation_about_an_axis_to_nodes_process.hpp:222
double mprevious_value
Definition: assign_rotation_about_an_axis_to_nodes_process.hpp:224
void Execute() override
Execute method is used to execute the AssignRotationAboutAnAxisToNodesProcess algorithms.
Definition: assign_rotation_about_an_axis_to_nodes_process.hpp:121
ModelPart & mrModelPart
Definition: assign_rotation_about_an_axis_to_nodes_process.hpp:221
double mvalue
Definition: assign_rotation_about_an_axis_to_nodes_process.hpp:223
array_1d< double, 3 > mdirection
Definition: assign_rotation_about_an_axis_to_nodes_process.hpp:225
array_1d< double, 3 > mcenter
Definition: assign_rotation_about_an_axis_to_nodes_process.hpp:226
The base class for assigning a value to scalar variables or array_1d components processes in Kratos.
Definition: assign_rotation_field_about_an_axis_to_nodes_process.hpp:32
void ExecuteInitializeSolutionStep() override
this function will be executed at every time step BEFORE performing the solve phase
Definition: assign_rotation_field_about_an_axis_to_nodes_process.hpp:148
void ExecuteFinalizeSolutionStep() override
this function will be executed at every time step AFTER performing the solve phase
Definition: assign_rotation_field_about_an_axis_to_nodes_process.hpp:153
void Execute() override
Execute method is used to execute the AssignRotationFieldAboutAnAxisToNodesProcess algorithms.
Definition: assign_rotation_field_about_an_axis_to_nodes_process.hpp:107
KRATOS_CLASS_POINTER_DEFINITION(AssignRotationFieldAboutAnAxisToNodesProcess)
Pointer definition of AssignRotationFieldAboutAnAxisToNodesProcess.
void ExecuteInitialize() override
Definition: assign_rotation_field_about_an_axis_to_nodes_process.hpp:136
AssignRotationFieldAboutAnAxisToNodesProcess(AssignRotationFieldAboutAnAxisToNodesProcess const &rOther)
Copy constructor.
~AssignRotationFieldAboutAnAxisToNodesProcess() override
Destructor.
Definition: assign_rotation_field_about_an_axis_to_nodes_process.hpp:87
void operator()()
This operator is provided to call the process as a function and simply calls the Execute method.
Definition: assign_rotation_field_about_an_axis_to_nodes_process.hpp:95
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: assign_rotation_field_about_an_axis_to_nodes_process.hpp:198
void ExecuteFinalize() override
Definition: assign_rotation_field_about_an_axis_to_nodes_process.hpp:172
void ExecuteBeforeOutputStep() override
this function will be executed at every time step BEFORE writing the output
Definition: assign_rotation_field_about_an_axis_to_nodes_process.hpp:159
void ExecuteAfterOutputStep() override
this function will be executed at every time step AFTER writing the output
Definition: assign_rotation_field_about_an_axis_to_nodes_process.hpp:165
AssignRotationFieldAboutAnAxisToNodesProcess(ModelPart &model_part, pybind11::object &rPyObject, const std::string &rPyMethodName, const bool SpatialFieldFunction, Parameters rParameters)
Definition: assign_rotation_field_about_an_axis_to_nodes_process.hpp:43
void ExecuteBeforeSolutionLoop() override
Definition: assign_rotation_field_about_an_axis_to_nodes_process.hpp:142
std::string Info() const override
Turn back information as a string.
Definition: assign_rotation_field_about_an_axis_to_nodes_process.hpp:192
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: assign_rotation_field_about_an_axis_to_nodes_process.hpp:204
static void VectorToSkewSymmetricTensor(const TVector3 &rVector, TMatrix3 &rSkewSymmetricTensor)
Definition: beam_math_utilities.hpp:231
NodesContainerType & Nodes()
Definition: mesh.h:346
NodeIterator NodesBegin()
Definition: mesh.h:326
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
MeshType & GetMesh(IndexType ThisIndex=0)
Definition: model_part.h:1791
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
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
std::string GetString() const
This method returns the string contained in the current Parameter.
Definition: kratos_parameters.cpp:684
size_type size() const
Returns the number of elements in the container.
Definition: pointer_vector_set.h:502
ProcessInfo holds the current value of different solution parameters.
Definition: process_info.h:59
ProcessInfo & GetPreviousTimeStepInfo(IndexType StepsBefore=1)
Definition: process_info.h:187
static Quaternion FromRotationVector(double rx, double ry, double rz)
Definition: quaternion.h:427
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
z
Definition: GenerateWind.py:163
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
TExpressionType::data_type norm_2(AMatrix::MatrixExpression< TExpressionType, TCategory > const &TheExpression)
Definition: amatrix_interface.h:625
Internals::Matrix< double, AMatrix::dynamic, AMatrix::dynamic > Matrix
Definition: amatrix_interface.h:470
AMatrix::MatrixProductExpression< TExpression1Type, TExpression2Type > prod(AMatrix::MatrixExpression< TExpression1Type, TCategory1 > const &First, AMatrix::MatrixExpression< TExpression2Type, TCategory2 > const &Second)
Definition: amatrix_interface.h:568
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
T & noalias(T &TheMatrix)
Definition: amatrix_interface.h:484
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
float velocity
Definition: PecletTest.py:54
ProcessInfo
Definition: edgebased_PureConvection.py:116
time
Definition: face_heat.py:85
model_part
Definition: face_heat.py:14
y
Other simbols definition.
Definition: generate_axisymmetric_navier_stokes_element.py:54
tuple acceleration
Definition: generate_droplet_dynamics.py:117
float radius
Definition: mesh_to_mdpa_converter.py:18
x
Definition: sensitivityMatrix.py:49
int nnodes
Definition: sensitivityMatrix.py:24
integer i
Definition: TensorModule.f:17