15 #if !defined(KRATOS_MAPPING_VARIABLES_2D_UTILITIES )
16 #define KRATOS_MAPPING_VARIABLES_2D_UTILITIES
93 this->ComputeCellMatrixDimensions(rAuxVariables,rModelPartNew);
102 bool add_temperature,
103 bool add_reference_temperature)
106 std::vector< std::vector< std::vector<Element::Pointer> > > ElementOldCellMatrix;
107 ElementOldCellMatrix.resize(AuxVariables.
NRows);
108 for(
int i = 0;
i < AuxVariables.
NRows;
i++) ElementOldCellMatrix[
i].resize(AuxVariables.
NColumns);
115 int NElems =
static_cast<int>(rModelPartOld.
Elements().size());
116 ModelPart::ElementsContainerType::iterator el_begin = rModelPartOld.
ElementsBegin();
118 #pragma omp parallel for private(X_me,Y_me,PointsNumber)
119 for(
int i = 0;
i < NElems;
i++)
121 ModelPart::ElementsContainerType::iterator itElemOld = el_begin +
i;
123 double X_left = itElemOld->GetGeometry().GetPoint(0).X0();
124 double X_right = X_left;
125 double Y_top = itElemOld->GetGeometry().GetPoint(0).Y0();
126 double Y_bot = Y_top;
127 PointsNumber = itElemOld->GetGeometry().PointsNumber();
129 for(
int j = 1;
j < PointsNumber;
j++)
131 X_me = itElemOld->GetGeometry().GetPoint(
j).X0();
132 Y_me = itElemOld->GetGeometry().GetPoint(
j).Y0();
134 if(X_me > X_right) X_right = X_me;
135 else if(X_me < X_left) X_left = X_me;
136 if(Y_me > Y_top) Y_top = Y_me;
137 else if(Y_me < Y_bot) Y_bot = Y_me;
145 if(Column_left < 0) Column_left = 0;
146 else if(Column_left >= AuxVariables.
NColumns) Column_left = AuxVariables.
NColumns-1;
147 if(Column_right >= AuxVariables.
NColumns) Column_right = AuxVariables.
NColumns-1;
148 else if(Column_right < 0) Column_right = 0;
150 if(Row_top < 0) Row_top = 0;
151 else if(Row_top >= AuxVariables.
NRows) Row_top = AuxVariables.
NRows-1;
152 if(Row_bot >= AuxVariables.
NRows) Row_bot = AuxVariables.
NRows-1;
153 else if(Row_bot < 0) Row_bot = 0;
155 for(
int k = Row_top;
k <= Row_bot;
k++)
157 for(
int l = Column_left;
l <= Column_right;
l++)
161 ElementOldCellMatrix[
k][
l].push_back((*(itElemOld.base())));
166 for(
int k = Row_top;
k <= Row_bot;
k++)
168 for(
int l = Column_left;
l <= Column_right;
l++)
172 ElementOldCellMatrix[
k][
l].push_back((*(itElemOld.base())));
179 const int NNodes =
static_cast<int>(rModelPartNew.
Nodes().size());
180 ModelPart::NodesContainerType::iterator node_begin = rModelPartNew.
NodesBegin();
185 #pragma omp parallel for private(X_me,Y_me,PointsNumber,GlobalCoordinates,LocalCoordinates)
186 for(
int i = 0;
i < NNodes;
i++)
188 ModelPart::NodesContainerType::iterator itNodeNew = node_begin +
i;
190 X_me = itNodeNew->X0();
191 Y_me = itNodeNew->Y0();
197 else if(Column < 0) Column = 0;
198 if(Row >= AuxVariables.
NRows) Row = AuxVariables.
NRows-1;
199 else if(Row < 0) Row = 0;
201 noalias(GlobalCoordinates) = itNodeNew->Coordinates();
202 bool IsInside =
false;
203 Element::Pointer pElementOld;
205 for(
unsigned int m = 0;
m < (ElementOldCellMatrix[Row][Column]).size();
m++)
207 pElementOld = ElementOldCellMatrix[Row][Column][
m];
208 IsInside = pElementOld->GetGeometry().IsInside(GlobalCoordinates,LocalCoordinates);
214 for(
int i = 0;
i < 12;
i++)
216 for(
int j = 1;
j<10;
j++)
218 for(
unsigned int m = 0;
m < (ElementOldCellMatrix[Row][Column]).size();
m++)
220 pElementOld = ElementOldCellMatrix[Row][Column][
m];
221 double tol =
j * pow(10.0, (
i-12));
222 IsInside = pElementOld->GetGeometry().IsInside(GlobalCoordinates,LocalCoordinates,
tol);
231 if(IsInside ==
false)
233 std::cout <<
"None of the old elements contains node " << itNodeNew->Id() << std::endl;
237 PointsNumber = pElementOld->GetGeometry().PointsNumber();
238 Vector ShapeFunctionsValuesVector(PointsNumber);
239 Vector NodalVariableVector(PointsNumber);
241 pElementOld->GetGeometry().ShapeFunctionsValues(ShapeFunctionsValuesVector,LocalCoordinates);
246 double max_temperature = -10e12;
247 double min_temperature = 10e12;
249 for(
int j = 0;
j < PointsNumber;
j++)
251 NodalVariableVector[
j] = pElementOld->GetGeometry().GetPoint(
j).FastGetSolutionStepValue(TEMPERATURE);
252 if (NodalVariableVector[
j] > max_temperature) max_temperature = NodalVariableVector[
j];
253 if (NodalVariableVector[
j] < min_temperature) min_temperature = NodalVariableVector[
j];
255 itNodeNew->FastGetSolutionStepValue(TEMPERATURE) =
inner_prod(ShapeFunctionsValuesVector,NodalVariableVector);
256 if (itNodeNew->FastGetSolutionStepValue(TEMPERATURE) > max_temperature) itNodeNew->FastGetSolutionStepValue(TEMPERATURE) = max_temperature;
257 if (itNodeNew->FastGetSolutionStepValue(TEMPERATURE) < min_temperature) itNodeNew->FastGetSolutionStepValue(TEMPERATURE) = min_temperature;
260 if (add_reference_temperature)
262 double max_reference_temperature = -10e12;
263 double min_reference_temperature = 10e12;
265 for(
int j = 0;
j < PointsNumber;
j++)
267 NodalVariableVector[
j] = pElementOld->GetGeometry().GetPoint(
j).FastGetSolutionStepValue(NODAL_REFERENCE_TEMPERATURE);
268 if (NodalVariableVector[
j] > max_reference_temperature) max_reference_temperature = NodalVariableVector[
j];
269 if (NodalVariableVector[
j] < min_reference_temperature) min_reference_temperature = NodalVariableVector[
j];
271 itNodeNew->FastGetSolutionStepValue(NODAL_REFERENCE_TEMPERATURE) =
inner_prod(ShapeFunctionsValuesVector,NodalVariableVector);
272 if (itNodeNew->FastGetSolutionStepValue(NODAL_REFERENCE_TEMPERATURE) > max_reference_temperature) itNodeNew->FastGetSolutionStepValue(NODAL_REFERENCE_TEMPERATURE) = max_reference_temperature;
273 if (itNodeNew->FastGetSolutionStepValue(NODAL_REFERENCE_TEMPERATURE) < min_reference_temperature) itNodeNew->FastGetSolutionStepValue(NODAL_REFERENCE_TEMPERATURE) = min_reference_temperature;
282 bool add_displacement,
286 std::vector< std::vector< std::vector<Element::Pointer> > > ElementOldCellMatrix;
287 ElementOldCellMatrix.resize(AuxVariables.
NRows);
288 for(
int i = 0;
i < AuxVariables.
NRows;
i++) ElementOldCellMatrix[
i].resize(AuxVariables.
NColumns);
295 int NElems =
static_cast<int>(rModelPartOld.
Elements().size());
296 ModelPart::ElementsContainerType::iterator el_begin = rModelPartOld.
ElementsBegin();
298 #pragma omp parallel for private(X_me,Y_me,PointsNumber)
299 for(
int i = 0;
i < NElems;
i++)
301 ModelPart::ElementsContainerType::iterator itElemOld = el_begin +
i;
303 double X_left = itElemOld->GetGeometry().GetPoint(0).X0();
304 double X_right = X_left;
305 double Y_top = itElemOld->GetGeometry().GetPoint(0).Y0();
306 double Y_bot = Y_top;
307 PointsNumber = itElemOld->GetGeometry().PointsNumber();
309 for(
int j = 1;
j < PointsNumber;
j++)
311 X_me = itElemOld->GetGeometry().GetPoint(
j).X0();
312 Y_me = itElemOld->GetGeometry().GetPoint(
j).Y0();
314 if(X_me > X_right) X_right = X_me;
315 else if(X_me < X_left) X_left = X_me;
316 if(Y_me > Y_top) Y_top = Y_me;
317 else if(Y_me < Y_bot) Y_bot = Y_me;
325 if(Column_left < 0) Column_left = 0;
326 else if(Column_left >= AuxVariables.
NColumns) Column_left = AuxVariables.
NColumns-1;
327 if(Column_right >= AuxVariables.
NColumns) Column_right = AuxVariables.
NColumns-1;
328 else if(Column_right < 0) Column_right = 0;
330 if(Row_top < 0) Row_top = 0;
331 else if(Row_top >= AuxVariables.
NRows) Row_top = AuxVariables.
NRows-1;
332 if(Row_bot >= AuxVariables.
NRows) Row_bot = AuxVariables.
NRows-1;
333 else if(Row_bot < 0) Row_bot = 0;
335 for(
int k = Row_top;
k <= Row_bot;
k++)
337 for(
int l = Column_left;
l <= Column_right;
l++)
341 ElementOldCellMatrix[
k][
l].push_back((*(itElemOld.base())));
348 const int NNodes =
static_cast<int>(rModelPartNew.
Nodes().size());
349 ModelPart::NodesContainerType::iterator node_begin = rModelPartNew.
NodesBegin();
354 #pragma omp parallel for private(X_me,Y_me,PointsNumber,GlobalCoordinates,LocalCoordinates)
355 for(
int i = 0;
i < NNodes;
i++)
357 ModelPart::NodesContainerType::iterator itNodeNew = node_begin +
i;
359 X_me = itNodeNew->X0();
360 Y_me = itNodeNew->Y0();
366 else if(Column < 0) Column = 0;
367 if(Row >= AuxVariables.
NRows) Row = AuxVariables.
NRows-1;
368 else if(Row < 0) Row = 0;
370 noalias(GlobalCoordinates) = itNodeNew->Coordinates();
371 bool IsInside =
false;
372 Element::Pointer pElementOld;
374 for(
unsigned int m = 0;
m < (ElementOldCellMatrix[Row][Column]).size();
m++)
376 pElementOld = ElementOldCellMatrix[Row][Column][
m];
377 IsInside = pElementOld->GetGeometry().IsInside(GlobalCoordinates,LocalCoordinates);
383 for(
int i = 0;
i < 12;
i++)
385 for(
int j = 1;
j<10;
j++)
387 for(
unsigned int m = 0;
m < (ElementOldCellMatrix[Row][Column]).size();
m++)
389 pElementOld = ElementOldCellMatrix[Row][Column][
m];
390 double tol =
j * pow(10.0, (
i-12));
391 IsInside = pElementOld->GetGeometry().IsInside(GlobalCoordinates,LocalCoordinates,
tol);
400 if(IsInside ==
false)
402 std::cout <<
"None of the old elements contains node " << itNodeNew->Id() << std::endl;
405 itNodeNew->FastGetSolutionStepValue(NODAL_CAUCHY_STRESS_TENSOR) =
ZeroMatrix(2,2);
406 itNodeNew->FastGetSolutionStepValue(INITIAL_NODAL_CAUCHY_STRESS_TENSOR) =
ZeroMatrix(2,2);
411 PointsNumber = pElementOld->GetGeometry().PointsNumber();
412 Vector ShapeFunctionsValuesVector(PointsNumber);
413 Vector NodalVariableVector(PointsNumber);
415 pElementOld->GetGeometry().ShapeFunctionsValues(ShapeFunctionsValuesVector,LocalCoordinates);
418 if (add_displacement)
420 double max_displacement_x = -10e12;
421 double min_displacement_x = 10e12;
422 for(
int j = 0;
j < PointsNumber;
j++)
424 NodalVariableVector[
j] = pElementOld->GetGeometry().GetPoint(
j).FastGetSolutionStepValue(DISPLACEMENT_X);
425 if (NodalVariableVector[
j] > max_displacement_x) max_displacement_x = NodalVariableVector[
j];
426 if (NodalVariableVector[
j] < min_displacement_x) min_displacement_x = NodalVariableVector[
j];
428 itNodeNew->FastGetSolutionStepValue(DISPLACEMENT_X) =
inner_prod(ShapeFunctionsValuesVector,NodalVariableVector);
429 if (itNodeNew->FastGetSolutionStepValue(DISPLACEMENT_X) > max_displacement_x) itNodeNew->FastGetSolutionStepValue(DISPLACEMENT_X) = max_displacement_x;
430 if (itNodeNew->FastGetSolutionStepValue(DISPLACEMENT_X) < min_displacement_x) itNodeNew->FastGetSolutionStepValue(DISPLACEMENT_X) = min_displacement_x;
432 double max_displacement_y = -10e12;
433 double min_displacement_y = 10e12;
434 for(
int j = 0;
j < PointsNumber;
j++)
436 NodalVariableVector[
j] = pElementOld->GetGeometry().GetPoint(
j).FastGetSolutionStepValue(DISPLACEMENT_Y);
437 if (NodalVariableVector[
j] > max_displacement_y) max_displacement_y = NodalVariableVector[
j];
438 if (NodalVariableVector[
j] < min_displacement_y) min_displacement_y = NodalVariableVector[
j];
440 itNodeNew->FastGetSolutionStepValue(DISPLACEMENT_Y) =
inner_prod(ShapeFunctionsValuesVector,NodalVariableVector);
441 if (itNodeNew->FastGetSolutionStepValue(DISPLACEMENT_Y) > max_displacement_y) itNodeNew->FastGetSolutionStepValue(DISPLACEMENT_Y) = max_displacement_y;
442 if (itNodeNew->FastGetSolutionStepValue(DISPLACEMENT_Y) < min_displacement_y) itNodeNew->FastGetSolutionStepValue(DISPLACEMENT_Y) = min_displacement_y;
452 for(
int k = 0;
k < 2;
k++)
454 for(
int l = 0;
l < 2;
l++)
456 MaxNodalStress(
k,
l) = -10e12;
457 MinNodalStress(
k,
l) = 10e12;
458 for(
int j = 0;
j < PointsNumber;
j++)
460 NodalVariableVector[
j] = pElementOld->GetGeometry().GetPoint(
j).FastGetSolutionStepValue(NODAL_CAUCHY_STRESS_TENSOR)(
k,
l);
461 if (NodalVariableVector[
j] > MaxNodalStress(
k,
l)) MaxNodalStress(
k,
l) = NodalVariableVector[
j];
462 if (NodalVariableVector[
j] < MinNodalStress(
k,
l)) MinNodalStress(
k,
l) = NodalVariableVector[
j];
464 NodalStress(
k,
l) =
inner_prod(ShapeFunctionsValuesVector,NodalVariableVector);
465 if (NodalStress(
k,
l) > MaxNodalStress(
k,
l)) NodalStress(
k,
l) = MaxNodalStress(
k,
l);
466 if (NodalStress(
k,
l) < MinNodalStress(
k,
l)) NodalStress(
k,
l) = MinNodalStress(
k,
l);
470 itNodeNew->FastGetSolutionStepValue(INITIAL_NODAL_CAUCHY_STRESS_TENSOR) = NodalStress;
471 itNodeNew->FastGetSolutionStepValue(NODAL_CAUCHY_STRESS_TENSOR) = NodalStress;
480 void ComputeCellMatrixDimensions(
481 UtilityVariables& rAuxVariables,
486 std::vector<double> X_max_partition(NumThreads);
487 std::vector<double> X_min_partition(NumThreads);
488 std::vector<double> Y_max_partition(NumThreads);
489 std::vector<double> Y_min_partition(NumThreads);
491 const int NNodes =
static_cast<int>(rModelPart.
Nodes().size());
492 ModelPart::NodesContainerType::iterator node_begin = rModelPart.
NodesBegin();
497 X_max_partition[
k] = node_begin->X();
498 X_min_partition[
k] = X_max_partition[
k];
499 Y_max_partition[
k] = node_begin->Y();
500 Y_min_partition[
k] = Y_max_partition[
k];
503 for(
int i = 0;
i < NNodes;
i++)
505 ModelPart::NodesContainerType::iterator itNode = node_begin +
i;
507 double X_me = itNode->X();
508 double Y_me = itNode->Y();
510 if( X_me > X_max_partition[
k] ) X_max_partition[
k] = X_me;
511 else if( X_me < X_min_partition[
k] ) X_min_partition[
k] = X_me;
513 if( Y_me > Y_max_partition[
k] ) Y_max_partition[
k] = Y_me;
514 else if( Y_me < Y_min_partition[
k] ) Y_min_partition[
k] = Y_me;
518 rAuxVariables.X_max = X_max_partition[0];
519 rAuxVariables.X_min = X_min_partition[0];
520 rAuxVariables.Y_max = Y_max_partition[0];
521 rAuxVariables.Y_min = Y_min_partition[0];
523 for(
unsigned int i=1;
i < NumThreads;
i++)
525 if(X_max_partition[
i] > rAuxVariables.X_max) rAuxVariables.X_max = X_max_partition[
i];
526 if(X_min_partition[
i] < rAuxVariables.X_min) rAuxVariables.X_min = X_min_partition[
i];
527 if(Y_max_partition[
i] > rAuxVariables.Y_max) rAuxVariables.Y_max = Y_max_partition[
i];
528 if(Y_min_partition[
i] < rAuxVariables.Y_min) rAuxVariables.Y_min = Y_min_partition[
i];
532 double AverageElementLength = 0.0;
534 int NElems =
static_cast<int>(rModelPart.
Elements().size());
535 ModelPart::ElementsContainerType::iterator el_begin = rModelPart.
ElementsBegin();
537 #pragma omp parallel for reduction(+:AverageElementLength)
538 for(
int i = 0;
i < NElems;
i++)
540 ModelPart::ElementsContainerType::iterator itElem = el_begin +
i;
542 AverageElementLength += itElem->GetGeometry().Length();
545 AverageElementLength = AverageElementLength/NElems;
548 rAuxVariables.NRows =
int((rAuxVariables.Y_max-rAuxVariables.Y_min)/(AverageElementLength));
549 rAuxVariables.NColumns =
int((rAuxVariables.X_max-rAuxVariables.X_min)/(AverageElementLength));
550 if(rAuxVariables.NRows <= 0) rAuxVariables.NRows = 1;
551 if(rAuxVariables.NColumns <= 0) rAuxVariables.NColumns = 1;
552 rAuxVariables.RowSize = (rAuxVariables.Y_max-rAuxVariables.Y_min)/rAuxVariables.NRows;
553 rAuxVariables.ColumnSize = (rAuxVariables.X_max-rAuxVariables.X_min)/rAuxVariables.NColumns;
Definition: mapping_variables_2D_utilities.hpp:37
void InitializeMapping(UtilityVariables &rAuxVariables, ModelPart &rModelPartNew)
Member Variables.
Definition: mapping_variables_2D_utilities.hpp:89
void NodalMechanicalVariablesMapping(const UtilityVariables &AuxVariables, ModelPart &rModelPartOld, ModelPart &rModelPartNew, bool add_displacement, bool add_stress)
Definition: mapping_variables_2D_utilities.hpp:278
KRATOS_CLASS_POINTER_DEFINITION(MappingVariables2DUtilities)
void NodalThermalVariablesMapping(const UtilityVariables &AuxVariables, ModelPart &rModelPartOld, ModelPart &rModelPartNew, bool add_temperature, bool add_reference_temperature)
Definition: mapping_variables_2D_utilities.hpp:98
MappingVariables2DUtilities()
Constructor.
Definition: mapping_variables_2D_utilities.hpp:56
virtual ~MappingVariables2DUtilities()
Destructor.
Definition: mapping_variables_2D_utilities.hpp:61
void MappingThermalModelParts(ModelPart &rModelPartOld, ModelPart &rModelPartNew, bool add_temperature, bool add_reference_temperature)
Definition: mapping_variables_2D_utilities.hpp:65
void MappingMechanicalModelParts(ModelPart &rModelPartOld, ModelPart &rModelPartNew, bool add_displacement, bool add_stress)
Definition: mapping_variables_2D_utilities.hpp:73
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
ElementIterator ElementsBegin(IndexType ThisIndex=0)
Definition: model_part.h:1169
NodeIterator NodesBegin(IndexType ThisIndex=0)
Definition: model_part.h:487
ElementsContainerType & Elements(IndexType ThisIndex=0)
Definition: model_part.h:1189
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
static int ThisThread()
Wrapper for omp_get_thread_num().
Definition: openmp_utils.h:108
static int GetNumThreads()
Returns the current number of threads.
Definition: parallel_utilities.cpp:34
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
KratosZeroMatrix< double > ZeroMatrix
Definition: amatrix_interface.h:559
TExpression1Type::data_type inner_prod(AMatrix::MatrixExpression< TExpression1Type, TCategory1 > const &First, AMatrix::MatrixExpression< TExpression2Type, TCategory2 > const &Second)
Definition: amatrix_interface.h:592
T & noalias(T &TheMatrix)
Definition: amatrix_interface.h:484
REACTION_CHECK_STIFFNESS_FACTOR int
Definition: contact_structural_mechanics_application_variables.h:75
int tol
Definition: hinsberg_optimization.py:138
int k
Definition: quadrature.py:595
int j
Definition: quadrature.py:648
int m
Definition: run_marine_rain_substepping.py:8
integer i
Definition: TensorModule.f:17
integer l
Definition: TensorModule.f:17
Basic Structs for the utility -----------------------------------------------------------------------...
Definition: mapping_variables_2D_utilities.hpp:44
int NColumns
Definition: mapping_variables_2D_utilities.hpp:46
double Y_max
Definition: mapping_variables_2D_utilities.hpp:45
double X_max
Definition: mapping_variables_2D_utilities.hpp:45
double X_min
Definition: mapping_variables_2D_utilities.hpp:45
double ColumnSize
Definition: mapping_variables_2D_utilities.hpp:47
double Y_min
Definition: mapping_variables_2D_utilities.hpp:45
double RowSize
Definition: mapping_variables_2D_utilities.hpp:47
int NRows
Definition: mapping_variables_2D_utilities.hpp:46