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.
constant_rotation_process.hpp
Go to the documentation of this file.
1 //
2 // Project Name: KratosDelaunayMeshingApplication $
3 // Created by: $Author: MACeligueta $
4 // Last modified by: $Co-Author: $
5 // Date: $Date: April 2018 $
6 // Revision: $Revision: 0.0 $
7 //
8 
9 #ifndef KRATOS_CONSTANT_ROTATION_PROCESS_H_INCLUDED
10 #define KRATOS_CONSTANT_ROTATION_PROCESS_H_INCLUDED
11 
12 // System includes
13 
14 // External includes
15 
16 // Project includes
17 #include "processes/process.h"
18 #include "utilities/math_utils.h"
20 
21 // Application includes
22 namespace Kratos
23 {
24 
26 {
27 public:
28 
31 
32  typedef Node NodeType;
34 
37  const double angular_velocity_x,
38  const double angular_velocity_y,
39  const double angular_velocity_z,
40  const double center_x,
41  const double center_y,
42  const double center_z): Process(), mrModelPart(rModelPart)
43  {
44  mW[0] = angular_velocity_x;
45  mW[1] = angular_velocity_y;
46  mW[2] = angular_velocity_z;
47  mCenter[0] = center_x;
48  mCenter[1] = center_y;
49  mCenter[2] = center_z;
50  }
51 
53  Parameters rParameters): Process(), mrModelPart(rModelPart)
54  {
55  Parameters default_parameters( R"(
56  {
57  "model_part_name":"rotating_part",
58  "angular_velocity_x":0.0,
59  "angular_velocity_y":0.0,
60  "angular_velocity_z":1.0,
61  "center_x":0.0,
62  "center_y":0.0,
63  "center_z":0.0,
64  "interval": [0,"End"]
65  } )" );
66 
67  rParameters.ValidateAndAssignDefaults(default_parameters);
68 
69  mW[0] = rParameters["angular_velocity_x"].GetDouble();
70  mW[1] = rParameters["angular_velocity_y"].GetDouble();
71  mW[2] = rParameters["angular_velocity_z"].GetDouble();
72  mCenter[0] = rParameters["center_x"].GetDouble();
73  mCenter[1] = rParameters["center_y"].GetDouble();
74  mCenter[2] = rParameters["center_z"].GetDouble();
75 
76  if(rParameters.Has("interval")) {
77  if(rParameters["interval"][1].IsString()) {
78  if(rParameters["interval"][1].GetString() == "End") rParameters["interval"][1].SetDouble(1e30);
79  else KRATOS_THROW_ERROR(std::runtime_error, "The second value of interval can be \"End\" or a number", 0);
80  }
81  mInitialTime = rParameters["interval"][0].GetDouble();
82  mFinalTime = rParameters["interval"][1].GetDouble();
83  }
84  }
85 
88 
89 
91  {
92  KRATOS_TRY;
93  ProcessInfo& rCurrentProcessInfo = mrModelPart.GetProcessInfo();
94  const double& rCurrentTime = rCurrentProcessInfo[TIME];
95 
96  if(rCurrentTime < mInitialTime || rCurrentTime > mFinalTime) {
97  SetAllNodesVelocityToZero();
98  return;
99  }
100 
101  array_1d<double,3> current_local_axis_1;
102  array_1d<double,3> current_local_axis_2;
103  array_1d<double,3> current_local_axis_3;
104 
105  const double modulus_omega = sqrt(mW[0]*mW[0] + mW[1]*mW[1] + mW[2]*mW[2]);
106  const double rotated_angle = modulus_omega * rCurrentTime;
107 
108  array_1d<double,3> unitary_omega;
109  noalias(unitary_omega) = mW / modulus_omega;
110 
111  array_1d<double,3> initial_local_axis_1; initial_local_axis_1[0] = 1.0; initial_local_axis_1[1] = 0.0; initial_local_axis_1[2] = 0.0; //(local axes are assumed oriented as global axes at the beginning)
112  array_1d<double,3> initial_local_axis_2; initial_local_axis_2[0] = 0.0; initial_local_axis_2[1] = 1.0; initial_local_axis_2[2] = 0.0; //(local axes are assumed oriented as global axes at the beginning)
113  array_1d<double,3> initial_local_axis_3; initial_local_axis_2[0] = 0.0; initial_local_axis_3[1] = 0.0; initial_local_axis_3[2] = 1.0; //(local axes are assumed oriented as global axes at the beginning)
114 
115  RotateAVectorAGivenAngleAroundAUnitaryVector(initial_local_axis_1, unitary_omega, rotated_angle, current_local_axis_1);
116  RotateAVectorAGivenAngleAroundAUnitaryVector(initial_local_axis_2, unitary_omega, rotated_angle, current_local_axis_2);
117  RotateAVectorAGivenAngleAroundAUnitaryVector(initial_local_axis_3, unitary_omega, rotated_angle, current_local_axis_3);
118 
119  //UPDATE POSITION AND VELOCITY OF ALL NODES
120  for (ModelPart::NodesContainerType::iterator node_i = mrModelPart.NodesBegin(); node_i != mrModelPart.NodesEnd(); ++node_i) {
121  //Get local coordinates at the beginning (local axes are assumed oriented as global axes at the beginning)
122  array_1d<double,3> local_coordinates;
123  local_coordinates[0] = node_i->X0() - mCenter[0];
124  local_coordinates[1] = node_i->Y0() - mCenter[1];
125  local_coordinates[2] = node_i->Z0() - mCenter[2];
126 
127  //Use local coordinates with the updated local axes
128  array_1d<double,3> new_from_center_to_node;
129  new_from_center_to_node = local_coordinates[0] * current_local_axis_1 + local_coordinates[1] * current_local_axis_2 + local_coordinates[2] * current_local_axis_3;
130 
131  array_1d<double,3>& current_node_position = node_i->Coordinates();
132  noalias(current_node_position) = mCenter + new_from_center_to_node;
133 
134  node_i->pGetDof(VELOCITY_X)->FixDof();
135  node_i->pGetDof(VELOCITY_Y)->FixDof();
136  node_i->pGetDof(VELOCITY_Z)->FixDof();
137  array_1d<double,3>& current_node_velocity = node_i->FastGetSolutionStepValue(VELOCITY);
138  //noalias(current_node_velocity) = MathUtils<double>::CrossProduct(new_from_center_to_node, mW);
139  MathUtils<double>::CrossProduct(current_node_velocity, mW, new_from_center_to_node);
140  }//end of loop over nodes
141  KRATOS_CATCH("");
142  }
143 
145  virtual std::string Info() const override
146  {
147  std::stringstream buffer;
148  buffer << "ConstantRotationProcess" ;
149  return buffer.str();
150  }
151 
153  virtual void PrintInfo(std::ostream& rOStream) const override {rOStream << "ConstantRotationProcess";}
154 
156  virtual void PrintData(std::ostream& rOStream) const override {}
157 
158 
159 protected:
162 
166 
170  double mInitialTime;
171  double mFinalTime;
172 
174  const double ang, array_1d<double, 3>& new_vec) {
175  double cang = cos(ang);
176  double sang = sin(ang);
177 
178  new_vec[0] = axis[0] * (axis[0] * old_vec[0] + axis[1] * old_vec[1] + axis[2] * old_vec[2]) * (1 - cang) + old_vec[0] * cang + (-axis[2] * old_vec[1] + axis[1] * old_vec[2]) * sang;
179  new_vec[1] = axis[1] * (axis[0] * old_vec[0] + axis[1] * old_vec[1] + axis[2] * old_vec[2]) * (1 - cang) + old_vec[1] * cang + ( axis[2] * old_vec[0] - axis[0] * old_vec[2]) * sang;
180  new_vec[2] = axis[2] * (axis[0] * old_vec[0] + axis[1] * old_vec[1] + axis[2] * old_vec[2]) * (1 - cang) + old_vec[2] * cang + (-axis[1] * old_vec[0] + axis[0] * old_vec[1]) * sang;
181  }
182 
183 
184 
185 private:
186 
188  ConstantRotationProcess& operator=(ConstantRotationProcess const& rOther){return *this;}
189 
190  void SetAllNodesVelocityToZero(){
191  KRATOS_TRY;
192  for (ModelPart::NodesContainerType::iterator node_i = mrModelPart.NodesBegin(); node_i != mrModelPart.NodesEnd(); ++node_i) {
193  node_i->pGetDof(VELOCITY_X)->FixDof();
194  node_i->pGetDof(VELOCITY_Y)->FixDof();
195  node_i->pGetDof(VELOCITY_Z)->FixDof();
196  array_1d<double,3>& current_node_velocity = node_i->FastGetSolutionStepValue(VELOCITY);
197  current_node_velocity[0] = 0.0;
198  current_node_velocity[1] = 0.0;
199  current_node_velocity[2] = 0.0;
200  }//end of loop over nodes
201  KRATOS_CATCH("");
202 
203  }
204 
205 }; // Class ConstantRotationProcess
206 
207 }; // namespace Kratos.
208 
209 #endif // KRATOS_CONSTANT_ROTATION_PROCESS_H_INCLUDED
Definition: constant_rotation_process.hpp:26
virtual std::string Info() const override
Turn back information as a string.
Definition: constant_rotation_process.hpp:145
KRATOS_CLASS_POINTER_DEFINITION(ConstantRotationProcess)
Pointer definition of ConstantRotationProcess.
array_1d< double, 3 > mW
Definition: constant_rotation_process.hpp:168
Geometry< NodeType > GeometryType
Definition: constant_rotation_process.hpp:33
virtual void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: constant_rotation_process.hpp:153
ConstantRotationProcess(ModelPart &rModelPart, Parameters rParameters)
Definition: constant_rotation_process.hpp:52
Node NodeType
Definition: constant_rotation_process.hpp:32
void ExecuteInitializeSolutionStep() override
This function will be executed at every time step BEFORE performing the solve phase.
Definition: constant_rotation_process.hpp:90
virtual void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: constant_rotation_process.hpp:156
double mFinalTime
Definition: constant_rotation_process.hpp:171
ConstantRotationProcess(ModelPart &rModelPart, const double angular_velocity_x, const double angular_velocity_y, const double angular_velocity_z, const double center_x, const double center_y, const double center_z)
Constructor.
Definition: constant_rotation_process.hpp:36
void RotateAVectorAGivenAngleAroundAUnitaryVector(const array_1d< double, 3 > &old_vec, const array_1d< double, 3 > &axis, const double ang, array_1d< double, 3 > &new_vec)
Definition: constant_rotation_process.hpp:173
array_1d< double, 3 > mCenter
Definition: constant_rotation_process.hpp:169
double mInitialTime
Definition: constant_rotation_process.hpp:170
virtual ~ConstantRotationProcess()
Destructor.
Definition: constant_rotation_process.hpp:87
ModelPart & mrModelPart
Definition: constant_rotation_process.hpp:167
Geometry base class.
Definition: geometry.h:71
static T CrossProduct(const T &a, const T &b)
Performs the vector product of the two input vectors a,b.
Definition: math_utils.h:762
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
NodeIterator NodesEnd(IndexType ThisIndex=0)
Definition: model_part.h:497
This class defines the node.
Definition: node.h:65
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 SetDouble(const double Value)
This method sets the double contained in the current Parameter.
Definition: kratos_parameters.cpp:787
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 Has(const std::string &rEntry) const
This method checks if the Parameter contains a certain entry.
Definition: kratos_parameters.cpp:520
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
#define KRATOS_THROW_ERROR(ExceptionType, ErrorMessage, MoreInfo)
Definition: define.h:77
#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
T & noalias(T &TheMatrix)
Definition: amatrix_interface.h:484
axis
Definition: all_t_win_vs_m_fixed_error.py:239