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.
lagrangian_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 //
12 
13 #if !defined(KRATOS_LAGRANGIAN_ROTATION_PROCESS)
14 #define KRATOS_LAGRANGIAN_ROTATION_PROCESS
15 
16 #include "includes/kratos_flags.h"
18 #include "processes/process.h"
19 #include "utilities/math_utils.h"
20 
22 
23 namespace Kratos
24 {
25 
27 
29 {
30 
31 public:
33 
35 
38  Parameters rParameters) : Process(Flags()), mr_model_part(model_part)
39  {
41 
42  //only include validation with c++11 since raw_literals do not exist in c++03
43  Parameters default_parameters(R"(
44  {
45  "model_part_name":"PLEASE_CHOOSE_MODEL_PART_NAME",
46  "angular_velocity": 0.0,
47  "rotation_axis_initial_point": [0.0,0.0,0.0],
48  "rotation_axis_final_point": [0.0,0.0,1.0],
49  "initial_time": 0.0,
50  "final_time": 10.0
51  } )");
52 
53  // Some values need to be mandatorily prescribed since no meaningful default value exist. For this reason try accessing to them
54  // So that an error is thrown if they don't exist
55  rParameters["model_part_name"];
56 
57  // Now validate agains defaults -- this also ensures no type mismatch
58  rParameters.ValidateAndAssignDefaults(default_parameters);
59 
60  mangular_velocity = rParameters["angular_velocity"].GetDouble();
61  maxis_initial_point = rParameters["rotation_axis_initial_point"].GetVector();
62  maxis_final_point = rParameters["rotation_axis_final_point"].GetVector();
63  minitial_time = rParameters["initial_time"].GetDouble();
64  mfinal_time = rParameters["final_time"].GetDouble();
65 
66  KRATOS_CATCH("");
67  }
68 
70 
73 
75 
77  void Execute() override
78  {
79  }
80 
83  void ExecuteInitialize() override
84  {
85  KRATOS_TRY;
86 
87  // Initializing auxiliary Rodrigues matrices
88  array_1d<double, 3> rotation_axis;
90  const double axis_norm = norm_2(rotation_axis);
91  if (axis_norm > 1.0e-15)
92  {
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  {
105  for (int j = 0; j < 3; ++j)
106  {
107  maxis_matrix(i, j) = rotation_axis[i] * rotation_axis[j];
108  }
109  }
110 
112  mantisym_axis_matrix(0, 1) = -rotation_axis[2];
113  mantisym_axis_matrix(0, 2) = rotation_axis[1];
114  mantisym_axis_matrix(1, 0) = rotation_axis[2];
115  mantisym_axis_matrix(1, 2) = -rotation_axis[0];
116  mantisym_axis_matrix(2, 0) = -rotation_axis[1];
117  mantisym_axis_matrix(2, 1) = rotation_axis[0];
118 
119  KRATOS_CATCH("");
120  }
121 
122  // /// this function will be executed at every time step BEFORE performing the solve phase
123  // void ExecuteInitializeSolutionStep() override
124  // {
125  // KRATOS_TRY;
126 
127  // // Fixing DOFs and perform rotation if necessary
128  // const int nnodes = static_cast<int>(mr_model_part.Nodes().size());
129 
130  // if(nnodes != 0)
131  // {
132  // const double current_time = mr_model_part.GetProcessInfo()[TIME];
133 
134  // //if(current_time >= minitial_time)
135  // //{
136  // const double delta_time = current_time - minitial_time;
137  // double sin_theta = std::sin(delta_time * mangular_velocity);
138  // double cos_theta = std::cos(delta_time * mangular_velocity);
139  // noalias(mrotation_dt_matrix) = - mangular_velocity * sin_theta * midentity_matrix
140  // + mangular_velocity * cos_theta * mantisym_axis_matrix
141  // + mangular_velocity * sin_theta * maxis_matrix;
142  // if(current_time < minitial_time)
143  // {
144  // sin_theta = std::sin(delta_time * mangular_velocity*current_time/minitial_time);
145  // cos_theta = std::cos(delta_time * mangular_velocity*current_time/minitial_time);
146 
147  // noalias(mrotation_dt_matrix) = - mangular_velocity *current_time/minitial_time * sin_theta * midentity_matrix
148  // + mangular_velocity *current_time/minitial_time * cos_theta * mantisym_axis_matrix
149  // + mangular_velocity *current_time/minitial_time * sin_theta * maxis_matrix;
150  // }
151 
152  // ModelPart::NodesContainerType::iterator it_begin = mr_model_part.NodesBegin();
153  // array_1d<double, 3> point_initial_position;
154 
155  // #pragma omp parallel for private(point_initial_position)
156  // for(int i = 0; i<nnodes; i++)
157  // {
158  // ModelPart::NodesContainerType::iterator it = it_begin + i;
159 
160  // noalias(point_initial_position) = it->GetInitialPosition().Coordinates();
161 
162  // it->Fix(VELOCITY_X);
163  // it->Fix(VELOCITY_Y);
164  // it->Fix(VELOCITY_Z);
165 
166  // array_1d<double, 3>& velocity = it->FastGetSolutionStepValue(VELOCITY);
167  // noalias(velocity) = prod(mrotation_dt_matrix, point_initial_position - maxis_initial_point);
168  // }
169 
170  // }
171 
172  // KRATOS_CATCH("");
173  // }
174 
177  {
178  KRATOS_TRY;
179 
180  // Fixing DOFs and perform rotation if necessary
181  const int nnodes = static_cast<int>(mr_model_part.Nodes().size());
182 
183  if (nnodes != 0)
184  {
185  const double current_time = mr_model_part.GetProcessInfo()[TIME];
186 
187  // if(current_time >= minitial_time)
188  // {
189  this->CalculateRodriguesMatrices(current_time);
190 
191  ModelPart::NodesContainerType::iterator it_begin = mr_model_part.NodesBegin();
192  array_1d<double, 3> point_initial_position;
193 
194 #pragma omp parallel for private(point_initial_position)
195  for (int i = 0; i < nnodes; i++)
196  {
197  ModelPart::NodesContainerType::iterator it = it_begin + i;
198 
199  // noalias(point_initial_position) = it->GetInitialPosition().Coordinates();
200  noalias(point_initial_position) = it->Coordinates();
201 
202  it->Fix(VELOCITY_X);
203  it->Fix(VELOCITY_Y);
204  it->Fix(VELOCITY_Z);
205 
206  array_1d<double, 3> &velocity = it->FastGetSolutionStepValue(VELOCITY);
207  noalias(velocity) = prod(mrotation_dt_matrix, point_initial_position - maxis_initial_point);
208  }
209  // }
210  // else
211  // {
212  // ModelPart::NodesContainerType::iterator it_begin = mr_model_part.NodesBegin();
213 
214  // #pragma omp parallel for
215  // for(int i = 0; i<nnodes; i++)
216  // {
217  // ModelPart::NodesContainerType::iterator it = it_begin + i;
218 
219  // it->Fix(VELOCITY_X);
220  // it->Fix(VELOCITY_Y);
221  // it->Fix(VELOCITY_Z);
222 
223  // array_1d<double, 3>& velocity = it->FastGetSolutionStepValue(VELOCITY);
224  // noalias(velocity) = ZeroVector(3);
225  // }
226  // }
227  }
228 
229  KRATOS_CATCH("");
230  }
231 
233  std::string Info() const override
234  {
235  return "LagrangianRotationProcess";
236  }
237 
239  void PrintInfo(std::ostream &rOStream) const override
240  {
241  rOStream << "LagrangianRotationProcess";
242  }
243 
245  void PrintData(std::ostream &rOStream) const override
246  {
247  }
248 
250 
251 protected:
253 
255 
258  double mfinal_time;
265  // BoundedMatrix<double, 3, 3> mrotation_matrix;
266 
268 
269 private:
270  void CalculateRodriguesMatrices(const double current_time)
271  {
272  const double delta_time = mr_model_part.GetProcessInfo()[DELTA_TIME];
273  double current_angular_velocity = mangular_velocity * current_time / minitial_time; // before the initial time, a linear law is used
274 
275  if (current_time >= minitial_time)
276  {
277  current_angular_velocity = mangular_velocity;
278  }
279 
280  if (current_time > mfinal_time)
281  {
282  current_angular_velocity = 0;
283  }
284 
285  double sin_theta = std::sin(delta_time * current_angular_velocity);
286  double cos_theta = std::cos(delta_time * current_angular_velocity);
287 
288  // Rotation matrix derivative (derivative of R with respect to time)
289  noalias(mrotation_dt_matrix) = -current_angular_velocity * sin_theta * midentity_matrix + current_angular_velocity * cos_theta * mantisym_axis_matrix + current_angular_velocity * sin_theta * maxis_matrix;
290  }
291 
293  LagrangianRotationProcess &operator=(LagrangianRotationProcess const &rOther);
294 
296  //LagrangianRotationProcess(LagrangianRotationProcess const& rOther);
297 
298 }; // Class LagrangianRotationProcess
299 
301 inline std::istream &operator>>(std::istream &rIStream,
303 
305 inline std::ostream &operator<<(std::ostream &rOStream,
306  const LagrangianRotationProcess &rThis)
307 {
308  rThis.PrintInfo(rOStream);
309  rOStream << std::endl;
310  rThis.PrintData(rOStream);
311 
312  return rOStream;
313 }
314 
315 } // namespace Kratos.
316 
317 #endif /* KRATOS_LAGRANGIAN_ROTATION_PROCESS defined */
Definition: flags.h:58
Definition: amatrix_interface.h:41
Process used to rotate lagrangian model parts using Rodrigues' rotation formula.
Definition: lagrangian_rotation_process.hpp:29
BoundedMatrix< double, 3, 3 > mrotation_dt_matrix
Definition: lagrangian_rotation_process.hpp:264
double minitial_time
Definition: lagrangian_rotation_process.hpp:257
void ExecuteInitializeSolutionStep() override
this function will be executed at every time step BEFORE performing the solve phase
Definition: lagrangian_rotation_process.hpp:176
std::string Info() const override
Turn back information as a string.
Definition: lagrangian_rotation_process.hpp:233
array_1d< double, 3 > maxis_final_point
Definition: lagrangian_rotation_process.hpp:260
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: lagrangian_rotation_process.hpp:239
KRATOS_CLASS_POINTER_DEFINITION(LagrangianRotationProcess)
~LagrangianRotationProcess() override
Destructor.
Definition: lagrangian_rotation_process.hpp:72
array_1d< double, 3 > maxis_initial_point
Definition: lagrangian_rotation_process.hpp:259
LagrangianRotationProcess(ModelPart &model_part, Parameters rParameters)
Constructor.
Definition: lagrangian_rotation_process.hpp:37
BoundedMatrix< double, 3, 3 > mantisym_axis_matrix
Definition: lagrangian_rotation_process.hpp:263
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: lagrangian_rotation_process.hpp:245
void ExecuteInitialize() override
Definition: lagrangian_rotation_process.hpp:83
void Execute() override
Execute method is used to execute the ApplyComponentTableProcess algorithms.
Definition: lagrangian_rotation_process.hpp:77
double mfinal_time
Definition: lagrangian_rotation_process.hpp:258
double mangular_velocity
Definition: lagrangian_rotation_process.hpp:256
BoundedMatrix< double, 3, 3 > midentity_matrix
Definition: lagrangian_rotation_process.hpp:261
BoundedMatrix< double, 3, 3 > maxis_matrix
Definition: lagrangian_rotation_process.hpp:262
ModelPart & mr_model_part
Member Variables.
Definition: lagrangian_rotation_process.hpp:254
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
float velocity
Definition: PecletTest.py:54
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