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.
apply_rigid_rotation_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 // Guillermo Casas
12 //
13 
14 #if !defined(KRATOS_APPLY_RIGID_ROTATION_PROCESS )
15 #define KRATOS_APPLY_RIGID_ROTATION_PROCESS
16 
17 #include "includes/kratos_flags.h"
19 #include "processes/process.h"
20 #include "utilities/math_utils.h"
21 
23 
24 namespace Kratos
25 {
26 
28 
30 {
31 
32 public:
33 
35 
37 
40  Parameters& rParameters
42  {
44 
45  //only include validation with c++11 since raw_literals do not exist in c++03
46  Parameters default_parameters( R"(
47  {
48  "model_part_name":"PLEASE_CHOOSE_MODEL_PART_NAME",
49  "angular_velocity": 0.0,
50  "rotation_axis_initial_point": [0.0,0.0,0.0],
51  "rotation_axis_final_point": [0.0,0.0,1.0],
52  "initial_time": 0.0
53  } )" );
54 
55  // Some values need to be mandatorily prescribed since no meaningful default value exist. For this reason try accessing to them
56  // So that an error is thrown if they don't exist
57  rParameters["model_part_name"];
58 
59  // Now validate agains defaults -- this also ensures no type mismatch
60  rParameters.ValidateAndAssignDefaults(default_parameters);
61 
62  mangular_velocity = rParameters["angular_velocity"].GetDouble();
63  maxis_initial_point = rParameters["rotation_axis_initial_point"].GetVector();
64  maxis_final_point = rParameters["rotation_axis_final_point"].GetVector();
65  minitial_time = rParameters["initial_time"].GetDouble();
66 
67  KRATOS_CATCH("");
68  }
69 
71 
74 
76 
78  void Execute() override
79  {
80  }
81 
84  void ExecuteInitialize() override
85  {
86  KRATOS_TRY;
87 
88  // Initializing auxiliary Rodrigues matrices
89  array_1d<double,3> rotation_axis;
91  const double axis_norm = norm_2(rotation_axis);
92  if (axis_norm > 1.0e-15){
93  rotation_axis[0] *= 1.0/axis_norm;
94  rotation_axis[1] *= 1.0/axis_norm;
95  rotation_axis[2] *= 1.0/axis_norm;
96  }
97 
99  midentity_matrix(0,0) = 1.0;
100  midentity_matrix(1,1) = 1.0;
101  midentity_matrix(2,2) = 1.0;
102 
103  for (int i = 0; i < 3; ++i) {
104  for (int j = 0; j < 3; ++j) {
105  maxis_matrix(i,j) = rotation_axis[i] * rotation_axis[j];
106  }
107  }
108 
110  mantisym_axis_matrix(0, 1) = - rotation_axis[2];
111  mantisym_axis_matrix(0, 2) = rotation_axis[1];
112  mantisym_axis_matrix(1, 0) = rotation_axis[2];
113  mantisym_axis_matrix(1, 2) = - rotation_axis[0];
114  mantisym_axis_matrix(2, 0) = - rotation_axis[1];
115  mantisym_axis_matrix(2, 1) = rotation_axis[0];
116 
117  KRATOS_CATCH("");
118  }
119 
122  {
123  KRATOS_TRY;
124 
125  // Fixing DOFs and perform rotation if necessary
126  const int nnodes = static_cast<int>(mr_model_part.Nodes().size());
127 
128  if(nnodes != 0)
129  {
130  const double current_time = mr_model_part.GetProcessInfo()[TIME];
131 
132  if(current_time >= minitial_time)
133  {
134  this->CalculateRodriguesMatrices(current_time);
135 
136  ModelPart::NodesContainerType::iterator it_begin = mr_model_part.NodesBegin();
137 
138  #pragma omp parallel for
139  for(int i = 0; i<nnodes; i++)
140  {
141  ModelPart::NodesContainerType::iterator it = it_begin + i;
142 
143  // Rotate mesh node
144  noalias(it->Coordinates()) = maxis_initial_point + prod(mrotation_matrix, it->GetInitialPosition().Coordinates() - maxis_initial_point);
145 
146  // Update mesh_displacement ?
147  // array_1d<double, 3>& mesh_displacement = it->FastGetSolutionStepValue(MESH_DISPLACEMENT);
148  // noalias(mesh_displacement) = it->Coordinates() - it->GetInitialPosition().Coordinates();
149 
150  // Update mesh_velocity
151  array_1d<double, 3>& mesh_velocity = it->FastGetSolutionStepValue(MESH_VELOCITY);
152  noalias(mesh_velocity) = prod(mrotation_dt_matrix, it->GetInitialPosition().Coordinates() - maxis_initial_point);
153 
154  // Update mesh_acceleration ? We would need second order time derivative of rotation matrix
155  // array_1d<double, 3>& mesh_acceleration = it->FastGetSolutionStepValue(MESH_ACCELERATION);
156  // noalias(mesh_acceleration) = prod(mrotation_dt2_matrix, it->GetInitialPosition().Coordinates() - maxis_initial_point);
157  }
158  }
159  }
160 
161  KRATOS_CATCH("");
162  }
163 
165  std::string Info() const override
166  {
167  return "ApplyRigidRotationProcess";
168  }
169 
171  void PrintInfo(std::ostream& rOStream) const override
172  {
173  rOStream << "ApplyRigidRotationProcess";
174  }
175 
177  void PrintData(std::ostream& rOStream) const override
178  {
179  }
180 
182 
183 protected:
184 
186 
188 
198  // BoundedMatrix<double, 3, 3> mrotation_dt2_matrix;
199 
201 
202 private:
203 
204  void CalculateRodriguesMatrices(const double current_time)
205  {
206  const double delta_time = current_time - minitial_time;
207  const double sin_theta = std::sin(delta_time * mangular_velocity);
208  const double cos_theta = std::cos(delta_time * mangular_velocity);
209 
210  // Rotation matrix
212  + sin_theta * mantisym_axis_matrix
213  + (1.0 - cos_theta) * maxis_matrix;
214 
215  // Rotation matrix derivative (derivative of R with respect to time)
218  + mangular_velocity * sin_theta * maxis_matrix;
219  }
220 
222  ApplyRigidRotationProcess& operator=(ApplyRigidRotationProcess const& rOther);
223 
225  //ApplyRigidRotationProcess(ApplyRigidRotationProcess const& rOther);
226 
227 }; // Class ApplyRigidRotationProcess
228 
230 inline std::istream& operator >> (std::istream& rIStream,
232 
234 inline std::ostream& operator << (std::ostream& rOStream,
235  const ApplyRigidRotationProcess& rThis)
236 {
237  rThis.PrintInfo(rOStream);
238  rOStream << std::endl;
239  rThis.PrintData(rOStream);
240 
241  return rOStream;
242 }
243 
244 } // namespace Kratos.
245 
246 #endif /* KRATOS_APPLY_RIGID_ROTATION_PROCESS defined */
Process used to rotate eulerian model parts using Rodrigues' rotation formula.
Definition: apply_rigid_rotation_process.hpp:30
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: apply_rigid_rotation_process.hpp:171
ModelPart & mr_model_part
Member Variables.
Definition: apply_rigid_rotation_process.hpp:187
ApplyRigidRotationProcess(ModelPart &model_part, Parameters &rParameters)
Constructor.
Definition: apply_rigid_rotation_process.hpp:39
void ExecuteInitialize() override
Definition: apply_rigid_rotation_process.hpp:84
KRATOS_CLASS_POINTER_DEFINITION(ApplyRigidRotationProcess)
BoundedMatrix< double, 3, 3 > midentity_matrix
Definition: apply_rigid_rotation_process.hpp:193
BoundedMatrix< double, 3, 3 > mantisym_axis_matrix
Definition: apply_rigid_rotation_process.hpp:195
array_1d< double, 3 > maxis_initial_point
Definition: apply_rigid_rotation_process.hpp:191
double minitial_time
Definition: apply_rigid_rotation_process.hpp:190
array_1d< double, 3 > maxis_final_point
Definition: apply_rigid_rotation_process.hpp:192
double mangular_velocity
Definition: apply_rigid_rotation_process.hpp:189
BoundedMatrix< double, 3, 3 > mrotation_matrix
Definition: apply_rigid_rotation_process.hpp:196
BoundedMatrix< double, 3, 3 > maxis_matrix
Definition: apply_rigid_rotation_process.hpp:194
void Execute() override
Execute method is used to execute the ApplyComponentTableProcess algorithms.
Definition: apply_rigid_rotation_process.hpp:78
std::string Info() const override
Turn back information as a string.
Definition: apply_rigid_rotation_process.hpp:165
void ExecuteInitializeSolutionStep() override
this function will be executed at every time step BEFORE performing the solve phase
Definition: apply_rigid_rotation_process.hpp:121
~ApplyRigidRotationProcess() override
Destructor.
Definition: apply_rigid_rotation_process.hpp:73
BoundedMatrix< double, 3, 3 > mrotation_dt_matrix
Definition: apply_rigid_rotation_process.hpp:197
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: apply_rigid_rotation_process.hpp:177
Definition: flags.h:58
Definition: amatrix_interface.h:41
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
NodeIterator NodesBegin(IndexType ThisIndex=0)
Definition: model_part.h:487
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
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
Vector GetVector() const
This method returns the vector contained in the current Parameter.
Definition: kratos_parameters.cpp:707
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
The base class for all processes in Kratos.
Definition: process.h:49
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
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
KratosZeroMatrix< double > ZeroMatrix
Definition: amatrix_interface.h:559
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
model_part
Definition: face_heat.py:14
delta_time
Definition: generate_frictional_mortar_condition.py:130
int j
Definition: quadrature.py:648
int nnodes
Definition: sensitivityMatrix.py:24
integer i
Definition: TensorModule.f:17