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_torque_about_an_axis_to_conditions_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: January 2018 $
6 // Revision: $Revision: 0.0 $
7 //
8 //
9 
10 #if !defined(KRATOS_ASSIGN_TORQUE_ABOUT_AN_AXIS_TO_CONDITIONS_PROCESS_H_INCLUDED)
11 #define KRATOS_ASSIGN_TORQUE_ABOUT_AN_AXIS_TO_CONDITIONS_PROCESS_H_INCLUDED
12 
13 
14 // System includes
15 
16 // External includes
17 
18 // Project includes
19 #include "includes/model_part.h"
21 #include "processes/process.h"
23 
24 namespace Kratos
25 {
26 
29 
31 
34 {
35 public:
38 
41 
45 
46 
48 
49 
50 
52  Parameters rParameters
54  {
56 
57  Parameters default_parameters( R"(
58  {
59  "model_part_name":"MODEL_PART_NAME",
60  "variable_name": "VARIABLE_NAME",
61  "modulus" : 1.0,
62  "direction" : [],
63  "center" : []
64  } )" );
65 
66 
67  // Validate against defaults -- this ensures no type mismatch
68  rParameters.ValidateAndAssignDefaults(default_parameters);
69 
70  mvariable_name = rParameters["variable_name"].GetString();
71 
72 
73  if( KratosComponents< Variable<array_1d<double, 3> > >::Has( mvariable_name ) ) //case of array_1d variable
74  {
75 
76  mvalue = rParameters["modulus"].GetDouble();
77 
78  for( unsigned int i=0; i<3; i++)
79  {
80  mdirection[i] = rParameters["direction"][i].GetDouble();
81  mcenter[i] = rParameters["center"][i].GetDouble();
82  }
83 
84  double norm = norm_2(mdirection);
85  if(norm!=0)
86  mdirection/=norm;
87 
88  }
89  else //case of other variable type
90  {
91  KRATOS_ERROR << "trying to set a variable that is not in the model_part - variable name is " << mvariable_name <<std::endl;
92  }
93 
94  KRATOS_CATCH("");
95  }
96 
97 
100 
101 
105 
107  void operator()()
108  {
109  Execute();
110  }
111 
112 
116 
117 
119  void Execute() override
120  {
121 
122  KRATOS_TRY;
123 
124  this->AssignTorqueAboutAnAxis(KratosComponents< Variable<array_1d<double,3> > >::Get(mvariable_name));
125 
126  KRATOS_CATCH("");
127 
128  }
129 
132  void ExecuteInitialize() override
133  {
134  }
135 
139  {
140  }
141 
142 
145  {
146  }
147 
150  {
151  }
152 
153 
155  void ExecuteBeforeOutputStep() override
156  {
157  }
158 
159 
161  void ExecuteAfterOutputStep() override
162  {
163  }
164 
165 
168  void ExecuteFinalize() override
169  {
170  array_1d<double,3> vector_value;
171  vector_value.clear();
172  InternalAssignValue(KratosComponents< Variable<array_1d<double,3> > >::Get(mvariable_name), vector_value);
173  }
174 
175 
179 
180 
184 
185 
189 
191  std::string Info() const override
192  {
193  return "AssignTorqueAboutAnAxisToConditionsProcess";
194  }
195 
197  void PrintInfo(std::ostream& rOStream) const override
198  {
199  rOStream << "AssignTorqueAboutAnAxisToConditionsProcess";
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;
226 
230 
233 
247 
248 private:
249 
258 
259 
260  void InternalAssignValue(const Variable<array_1d<double,3> >& rVariable,
261  const array_1d<double,3>& rvector_value)
262  {
263  const int nconditions = mrModelPart.GetMesh().Conditions().size();
264 
265  if(nconditions != 0)
266  {
267  ModelPart::ConditionsContainerType::iterator it_begin = mrModelPart.GetMesh().ConditionsBegin();
268 
269  #pragma omp parallel for
270  for(int i = 0; i<nconditions; i++)
271  {
272  ModelPart::ConditionsContainerType::iterator it = it_begin + i;
273 
274  it->SetValue(rVariable, rvector_value);
275  }
276  }
277  }
278 
279  void AssignTorqueAboutAnAxis(const Variable<array_1d<double,3> >& rVariable)
280  {
281  KRATOS_TRY
282 
283  const int nconditions = mrModelPart.GetMesh().Conditions().size();
284 
285  if(nconditions != 0)
286  {
287  ModelPart::ConditionsContainerType::iterator it_begin = mrModelPart.GetMesh().ConditionsBegin();
288 
289  std::vector<array_1d<double,3> > Couples(nconditions);
290  std::vector<array_1d<double,3> > Forces(nconditions);
291 
292  Matrix rotation_matrix;
293  array_1d<double,3> radius;
294  array_1d<double,3> distance;
295  array_1d<double,3> force;
296 
297  #pragma omp parallel for private(rotation_matrix,radius,distance,force)
298  for(int i = 0; i<nconditions; i++)
299  {
300  ModelPart::ConditionsContainerType::iterator it = it_begin + i;
301 
302  Geometry< Node >& rGeometry = it->GetGeometry();
303 
304  //Get geometry size
305  unsigned int size = rGeometry.size();
306  array_1d<double,3> couple;
307  couple.clear();
308  array_1d<double,3> moment;
309  moment.clear();
310  for ( unsigned int j = 0; j < size; j++ )
311  {
312 
313  noalias(distance) = rGeometry[j].GetInitialPosition() - mcenter;
314 
315  noalias(radius) = distance-inner_prod(distance,mdirection) * mdirection,
316 
317  //compute the skewsymmmetric tensor for the torque axis
319 
320  double norm_radius = norm_2(radius);
321  if(norm_radius!=0)
322  radius/=norm_radius;
323 
324  noalias(force) = prod(rotation_matrix, radius);
325 
326  noalias(couple) += force*norm_radius;
327 
328  double norm = norm_2(force);
329  if(norm!=0)
330  force/=norm;
331 
332  //compute the skewsymmmetric tensor for the radius
334 
335  noalias(moment) += norm_radius * prod(rotation_matrix, force);
336  }
337 
338  const unsigned int dimension = rGeometry.WorkingSpaceDimension();
339  double domain_size = 1.0;
340  if(dimension==3)
341  domain_size = rGeometry.Area();
342  if(dimension==2)
343  domain_size = rGeometry.Length();
344 
345  Couples[i] = moment * domain_size * (1.0/double(size));
346  Forces[i] = couple * (1.0/double(size));
347 
348  }
349 
350  double total_size = 1.0;
351  array_1d<double,3> torque;
352  for(int i = 0; i<nconditions; i++)
353  {
354  ModelPart::ConditionsContainerType::iterator it = it_begin + i;
355  Geometry< Node >& rGeometry = it->GetGeometry();
356  const unsigned int dimension = rGeometry.WorkingSpaceDimension();
357  double domain_size = 0.0;
358  if(dimension==3)
359  domain_size = rGeometry.Area();
360  if(dimension==2)
361  domain_size = rGeometry.Length();
362 
363  total_size += domain_size;
364  torque += Couples[i];
365  }
366 
367  torque /=total_size;
368 
369  //solve distributed couple
370  double value = 0;
371  for(int i = 0; i<3; i++)
372  {
373  if( torque[i] != 0 )
374  value = mdirection[i]*mvalue/torque[i];
375  if( value != 0 )
376  break;
377  }
378 
379  array_1d<double,3> load;
380  #pragma omp parallel for private(torque)
381  for(int i = 0; i<nconditions; i++)
382  {
383  ModelPart::ConditionsContainerType::iterator it = it_begin + i;
384  load = value * Forces[i];
385  it->SetValue(rVariable, load);
386  }
387 
388  }
389 
390  KRATOS_CATCH( "" )
391 
392  }
393 
394 
401 
404 
405 
415 
416 }; // Class AssignTorqueAboutAnAxisToConditionsProcess
417 
418 
420 
423 
424 
428 
429 
431 inline std::istream& operator >> (std::istream& rIStream,
433 
435 inline std::ostream& operator << (std::ostream& rOStream,
437 {
438  rThis.PrintInfo(rOStream);
439  rOStream << std::endl;
440  rThis.PrintData(rOStream);
441 
442  return rOStream;
443 }
445 
446 
447 } // namespace Kratos.
448 
449 #endif // KRATOS_ASSIGN_TORQUE_ABOUT_AN_AXIS_TO_CONDITIONS_PROCESS_H_INCLUDED defined
The base class for assigning a value to scalar variables or array_1d components processes in Kratos.
Definition: assign_torque_about_an_axis_to_conditions_process.hpp:34
ModelPart & mrModelPart
Definition: assign_torque_about_an_axis_to_conditions_process.hpp:221
AssignTorqueAboutAnAxisToConditionsProcess(ModelPart &model_part)
Definition: assign_torque_about_an_axis_to_conditions_process.hpp:47
double mvalue
Definition: assign_torque_about_an_axis_to_conditions_process.hpp:223
~AssignTorqueAboutAnAxisToConditionsProcess() override
Destructor.
Definition: assign_torque_about_an_axis_to_conditions_process.hpp:99
AssignTorqueAboutAnAxisToConditionsProcess(ModelPart &model_part, Parameters rParameters)
Definition: assign_torque_about_an_axis_to_conditions_process.hpp:51
void operator()()
This operator is provided to call the process as a function and simply calls the Execute method.
Definition: assign_torque_about_an_axis_to_conditions_process.hpp:107
void ExecuteFinalizeSolutionStep() override
this function will be executed at every time step AFTER performing the solve phase
Definition: assign_torque_about_an_axis_to_conditions_process.hpp:149
array_1d< double, 3 > mcenter
Definition: assign_torque_about_an_axis_to_conditions_process.hpp:225
void ExecuteInitializeSolutionStep() override
this function will be executed at every time step BEFORE performing the solve phase
Definition: assign_torque_about_an_axis_to_conditions_process.hpp:144
void Execute() override
Execute method is used to execute the AssignTorqueAboutAnAxisToConditionsProcess algorithms.
Definition: assign_torque_about_an_axis_to_conditions_process.hpp:119
AssignTorqueAboutAnAxisToConditionsProcess(AssignTorqueAboutAnAxisToConditionsProcess const &rOther)
Copy constructor.
array_1d< double, 3 > mdirection
Definition: assign_torque_about_an_axis_to_conditions_process.hpp:224
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: assign_torque_about_an_axis_to_conditions_process.hpp:203
void ExecuteBeforeSolutionLoop() override
Definition: assign_torque_about_an_axis_to_conditions_process.hpp:138
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: assign_torque_about_an_axis_to_conditions_process.hpp:197
void ExecuteAfterOutputStep() override
this function will be executed at every time step AFTER writing the output
Definition: assign_torque_about_an_axis_to_conditions_process.hpp:161
void ExecuteBeforeOutputStep() override
this function will be executed at every time step BEFORE writing the output
Definition: assign_torque_about_an_axis_to_conditions_process.hpp:155
std::string Info() const override
Turn back information as a string.
Definition: assign_torque_about_an_axis_to_conditions_process.hpp:191
void ExecuteInitialize() override
Definition: assign_torque_about_an_axis_to_conditions_process.hpp:132
void ExecuteFinalize() override
Definition: assign_torque_about_an_axis_to_conditions_process.hpp:168
std::string mvariable_name
Definition: assign_torque_about_an_axis_to_conditions_process.hpp:222
KRATOS_CLASS_POINTER_DEFINITION(AssignTorqueAboutAnAxisToConditionsProcess)
Pointer definition of AssignTorqueAboutAnAxisToConditionsProcess.
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
ConditionsContainerType & Conditions()
Definition: mesh.h:691
ConditionIterator ConditionsBegin()
Definition: mesh.h:671
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
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
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
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
TExpression1Type::data_type inner_prod(AMatrix::MatrixExpression< TExpression1Type, TCategory1 > const &First, AMatrix::MatrixExpression< TExpression2Type, TCategory2 > const &Second)
Definition: amatrix_interface.h:592
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
T & noalias(T &TheMatrix)
Definition: amatrix_interface.h:484
TABLE_NUMBER_ANGULAR_VELOCITY TABLE_NUMBER_MOMENT I33 BEAM_INERTIA_ROT_UNIT_LENGHT_Y KRATOS_DEFINE_APPLICATION_VARIABLE(DEM_APPLICATION, double, BEAM_INERTIA_ROT_UNIT_LENGHT_Z) typedef std double
Definition: DEM_application_variables.h:182
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
int domain_size
Definition: face_heat.py:4
model_part
Definition: face_heat.py:14
int dimension
Definition: isotropic_damage_automatic_differentiation.py:123
float radius
Definition: mesh_to_mdpa_converter.py:18
def load(f)
Definition: ode_solve.py:307
int j
Definition: quadrature.py:648
integer i
Definition: TensorModule.f:17