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_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 2016 $
6 // Revision: $Revision: 0.0 $
7 //
8 //
9 
10 #if !defined(KRATOS_ASSIGN_ROTATION_ABOUT_AN_AXIS_TO_NODES_PROCESS_H_INCLUDED)
11 #define KRATOS_ASSIGN_ROTATION_ABOUT_AN_AXIS_TO_NODES_PROCESS_H_INCLUDED
12 
13 
14 
15 // System includes
16 
17 // External includes
18 
19 // Project includes
20 #include "includes/model_part.h"
22 #include "processes/process.h"
24 
25 namespace Kratos
26 {
27 
30 
32 
35 {
36 public:
39 
42 
46 
47 
49 
50 
51 
53  Parameters rParameters
55  {
57 
58  Parameters default_parameters( R"(
59  {
60  "model_part_name":"MODEL_PART_NAME",
61  "variable_name": "VARIABLE_NAME",
62  "modulus" : 1.0,
63  "direction" : [],
64  "center" : []
65  } )" );
66 
67 
68  // Validate against defaults -- this ensures no type mismatch
69  rParameters.ValidateAndAssignDefaults(default_parameters);
70 
71  mvariable_name = rParameters["variable_name"].GetString();
72 
73 
74  if( KratosComponents< Variable<array_1d<double, 3> > >::Has( mvariable_name ) ) //case of array_1d variable
75  {
76 
77  mvalue = rParameters["modulus"].GetDouble();
78 
79  for( unsigned int i=0; i<3; i++)
80  {
81  mdirection[i] = rParameters["direction"][i].GetDouble();
82  mcenter[i] = rParameters["center"][i].GetDouble();
83  }
84 
85  double norm = norm_2(mdirection);
86  if(norm!=0)
87  mdirection/=norm;
88 
89  }
90  else //case of bool variable
91  {
92  KRATOS_ERROR << "trying to set a variable that is not in the model_part - variable name is " << mvariable_name <<std::endl;
93 
94  }
95 
96  KRATOS_CATCH("");
97  }
98 
99 
102 
103 
107 
109  void operator()()
110  {
111  Execute();
112  }
113 
114 
118 
119 
121  void Execute() override
122  {
123 
124  KRATOS_TRY;
125 
126  this->AssignRotationAboutAnAxis();
127 
128  KRATOS_CATCH("");
129 
130  }
131 
134  void ExecuteInitialize() override
135  {
136  }
137 
141  {
142  }
143 
144 
147  {
148  }
149 
152  {
154  }
155 
156 
158  void ExecuteBeforeOutputStep() override
159  {
160  }
161 
162 
164  void ExecuteAfterOutputStep() override
165  {
166  }
167 
168 
171  void ExecuteFinalize() override
172  {
173  }
174 
175 
179 
180 
184 
185 
189 
191  std::string Info() const override
192  {
193  return "AssignRotationAboutAnAxisToNodesProcess";
194  }
195 
197  void PrintInfo(std::ostream& rOStream) const override
198  {
199  rOStream << "AssignRotationAboutAnAxisToNodesProcess";
200  }
201 
203  void PrintData(std::ostream& rOStream) const override
204  {
205  }
206 
207 
212 
213 protected:
214 
220 
222  std::string mvariable_name;
223  double mvalue;
227 
231 
234 
248 
249 private:
250 
256 
257 
261 
262 
263  void AssignRotationAboutAnAxis()
264  {
265  KRATOS_TRY
266 
267  const int nnodes = mrModelPart.GetMesh().Nodes().size();
268 
269  //std::cout<<" Apply rigid body rotation "<<std::endl;
270 
271  if(nnodes != 0)
272  {
273  ModelPart::NodesContainerType::iterator it_begin = mrModelPart.GetMesh().NodesBegin();
274 
275  Matrix rotation_matrix;
277  array_1d<double,3> distance;
278 
279  //Possible prescribed variables: ROTATION / ANGULAR_VELOCITY / ANGULAR_ACCELERATION
280  bool dynamic_angular_velocity = false;
281  bool dynamic_angular_acceleration = false;
282 
283  const ProcessInfo& rCurrentProcessInfo = mrModelPart.GetProcessInfo();
284  const double& rDeltaTime = rCurrentProcessInfo[DELTA_TIME];
285 
286  array_1d<double,3> angular_velocity;
287  angular_velocity.clear();
288  array_1d<double,3> angular_acceleration;
289  angular_acceleration.clear();
290 
291  double time_factor = 0.0;
292  if(mvariable_name == "ROTATION"){
293 
294  time_factor = 1.0;
295 
296  }
297  else if(mvariable_name == "ANGULAR_VELOCITY"){
298 
299  dynamic_angular_velocity = true;
300  time_factor = rDeltaTime;
301 
302  }
303  else if(mvariable_name == "ANGULAR_ACCELERATION"){
304 
305  dynamic_angular_velocity = true;
306  dynamic_angular_acceleration = true;
307  time_factor = rDeltaTime * rDeltaTime;
308 
309  }
310 
311  array_1d<double,3> delta_rotation = time_factor * (mvalue - mprevious_value) * mdirection;
312 
313  array_1d<double,3> rotation = time_factor * mvalue * mdirection;
314 
315  if( dynamic_angular_velocity ){
316  angular_velocity = delta_rotation / rDeltaTime;
317  if( dynamic_angular_acceleration ){
318  angular_acceleration = angular_velocity / rDeltaTime;
319  }
320  }
321 
322  //Get rotation matrix
323  Quaternion<double> total_quaternion = Quaternion<double>::FromRotationVector<array_1d<double,3> >(rotation);
324 
325  #pragma omp parallel for private(distance,radius,rotation_matrix)
326  for(int i = 0; i<nnodes; i++)
327  {
328 
329  ModelPart::NodesContainerType::iterator it = it_begin + i;
330 
331  distance = it->GetInitialPosition() - mcenter;
332 
333  total_quaternion.ToRotationMatrix(rotation_matrix);
334 
335  noalias(radius) = prod(rotation_matrix, distance);
336 
337  array_1d<double,3>& displacement = it->FastGetSolutionStepValue(DISPLACEMENT);
338  displacement = radius - distance; //(mcenter + radius) - it->GetInitialPosition();
339 
340  if( dynamic_angular_velocity ){
341 
342  //compute the skewsymmmetric tensor of the angular velocity
343  BeamMathUtils<double>::VectorToSkewSymmetricTensor(angular_velocity, rotation_matrix);
344 
345  //compute the contribution of the angular velocity to the velocity v = Wxr
346  array_1d<double,3>& velocity = it->FastGetSolutionStepValue(VELOCITY);
347  velocity = prod(rotation_matrix,radius);
348 
349 
350  if( dynamic_angular_acceleration ){
351  //compute the contribution of the centripetal acceleration ac = Wx(Wxr)
352  array_1d<double,3>& acceleration = it->FastGetSolutionStepValue(ACCELERATION);
353  acceleration = prod(rotation_matrix,velocity);
354 
355  //compute the contribution of the angular acceleration to the acceleration a = Axr
356  BeamMathUtils<double>::VectorToSkewSymmetricTensor(angular_acceleration, rotation_matrix);
357  acceleration += prod(rotation_matrix,radius);
358 
359  }
360 
361  }
362  }
363 
364  }
365 
366  KRATOS_CATCH( "" )
367  }
368 
369 
376 
379 
380 
390 
391 }; // Class AssignRotationAboutAnAxisToNodesProcess
392 
393 
395 
398 
399 
403 
404 
406 inline std::istream& operator >> (std::istream& rIStream,
408 
410 inline std::ostream& operator << (std::ostream& rOStream,
412 {
413  rThis.PrintInfo(rOStream);
414  rOStream << std::endl;
415  rThis.PrintData(rOStream);
416 
417  return rOStream;
418 }
420 
421 
422 } // namespace Kratos.
423 
424 #endif // KRATOS_ASSIGN_ROTATION_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
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: assign_rotation_about_an_axis_to_nodes_process.hpp:197
std::string mvariable_name
Definition: assign_rotation_about_an_axis_to_nodes_process.hpp:222
AssignRotationAboutAnAxisToNodesProcess(ModelPart &model_part, Parameters rParameters)
Definition: assign_rotation_about_an_axis_to_nodes_process.hpp:52
void operator()()
This operator is provided to call the process as a function and simply calls the Execute method.
Definition: assign_rotation_about_an_axis_to_nodes_process.hpp:109
~AssignRotationAboutAnAxisToNodesProcess() override
Destructor.
Definition: assign_rotation_about_an_axis_to_nodes_process.hpp:101
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
void ExecuteBeforeOutputStep() override
this function will be executed at every time step BEFORE writing the output
Definition: assign_rotation_about_an_axis_to_nodes_process.hpp:158
double mvalue
Definition: assign_rotation_about_an_axis_to_nodes_process.hpp:223
AssignRotationAboutAnAxisToNodesProcess(AssignRotationAboutAnAxisToNodesProcess const &rOther)
Copy constructor.
KRATOS_CLASS_POINTER_DEFINITION(AssignRotationAboutAnAxisToNodesProcess)
Pointer definition of AssignRotationAboutAnAxisToNodesProcess.
void ExecuteFinalize() override
Definition: assign_rotation_about_an_axis_to_nodes_process.hpp:171
array_1d< double, 3 > mdirection
Definition: assign_rotation_about_an_axis_to_nodes_process.hpp:225
void ExecuteBeforeSolutionLoop() override
Definition: assign_rotation_about_an_axis_to_nodes_process.hpp:140
void ExecuteInitialize() override
Definition: assign_rotation_about_an_axis_to_nodes_process.hpp:134
AssignRotationAboutAnAxisToNodesProcess(ModelPart &model_part)
Definition: assign_rotation_about_an_axis_to_nodes_process.hpp:48
void ExecuteInitializeSolutionStep() override
this function will be executed at every time step BEFORE performing the solve phase
Definition: assign_rotation_about_an_axis_to_nodes_process.hpp:146
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: assign_rotation_about_an_axis_to_nodes_process.hpp:203
array_1d< double, 3 > mcenter
Definition: assign_rotation_about_an_axis_to_nodes_process.hpp:226
std::string Info() const override
Turn back information as a string.
Definition: assign_rotation_about_an_axis_to_nodes_process.hpp:191
void ExecuteAfterOutputStep() override
this function will be executed at every time step AFTER writing the output
Definition: assign_rotation_about_an_axis_to_nodes_process.hpp:164
void ExecuteFinalizeSolutionStep() override
this function will be executed at every time step AFTER performing the solve phase
Definition: assign_rotation_about_an_axis_to_nodes_process.hpp:151
static void VectorToSkewSymmetricTensor(const TVector3 &rVector, TMatrix3 &rSkewSymmetricTensor)
Definition: beam_math_utilities.hpp:231
Definition: flags.h:58
KratosComponents class encapsulates a lookup table for a family of classes in a generic way.
Definition: kratos_components.h:49
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
The base class for all processes in Kratos.
Definition: process.h:49
ProcessInfo holds the current value of different solution parameters.
Definition: process_info.h:59
static Quaternion FromRotationVector(double rx, double ry, double rz)
Definition: quaternion.h:427
Variable class contains all information needed to store and retrive data from a data container.
Definition: variable.h:63
BOOST_UBLAS_INLINE void clear()
Definition: array_1d.h:325
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_ERROR
Definition: exception.h:161
bool Has(const std::string &ModelerName)
Checks if the modeler is registered.
Definition: modeler_factory.cpp:24
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
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
model_part
Definition: face_heat.py:14
tuple acceleration
Definition: generate_droplet_dynamics.py:117
float radius
Definition: mesh_to_mdpa_converter.py:18
int nnodes
Definition: sensitivityMatrix.py:24
integer i
Definition: TensorModule.f:17