13 #if !defined(KRATOS_INITIAL_STRESS_3D_UTILITIES )
14 #define KRATOS_INITIAL_STRESS_3D_UTILITIES
69 this->ComputeCellMatrixDimensions(AuxVariables,rCurrentModelPart);
78 std::fstream initial_stresses_mdpa;
79 std::string initial_stress_mdpa_path = rParameters[
"initial_input_filename"].
GetString() +
".mdpa";
81 initial_stresses_mdpa.open(initial_stress_mdpa_path.c_str(),
std::fstream::out | std::fstream::trunc);
82 initial_stresses_mdpa.precision(15);
84 initial_stresses_mdpa <<
"Begin Properties 0" << std::endl;
85 initial_stresses_mdpa <<
"End Properties" << std::endl << std::endl;
87 const int NNodes =
static_cast<int>(rCurrentModelPart.
Nodes().size());
88 ModelPart::NodesContainerType::iterator node_begin = rCurrentModelPart.
NodesBegin();
89 initial_stresses_mdpa <<
"Begin Nodes" << std::endl;
91 for(
int i = 0;
i < NNodes;
i++) {
92 ModelPart::NodesContainerType::iterator it_node = node_begin +
i;
93 initial_stresses_mdpa << it_node->Id() <<
" " <<
94 it_node->X0() <<
" " <<
95 it_node->Y0() <<
" " <<
96 it_node->Z0() << std::endl;
98 initial_stresses_mdpa <<
"End Nodes" << std::endl << std::endl;
100 this->WriteLinearElements(initial_stresses_mdpa,rCurrentModelPart);
102 this->CalculateNodalStresses(rCurrentModelPart);
103 Matrix InitialStressTensor(3,3);
104 initial_stresses_mdpa <<
"Begin NodalData INITIAL_STRESS_TENSOR" << std::endl;
106 for(
int i = 0;
i < NNodes;
i++) {
107 ModelPart::NodesContainerType::iterator it_node = node_begin +
i;
108 noalias(InitialStressTensor) = it_node->FastGetSolutionStepValue(NODAL_EFFECTIVE_STRESS_TENSOR);
109 initial_stresses_mdpa << it_node->Id() <<
" 0 [3,3] ((" <<
110 InitialStressTensor(0,0) <<
"," << InitialStressTensor(0,1) <<
"," << InitialStressTensor(0,2) <<
"),(" <<
111 InitialStressTensor(1,0) <<
"," << InitialStressTensor(1,1) <<
"," << InitialStressTensor(1,2) <<
"),(" <<
112 InitialStressTensor(2,0) <<
"," << InitialStressTensor(2,1) <<
"," << InitialStressTensor(2,2) <<
"))" << std::endl;
114 initial_stresses_mdpa <<
"End NodalData" << std::endl;
116 initial_stresses_mdpa.close();
131 std::vector< std::vector< std::vector< std::vector<Element::Pointer> > > > ElementOldCellMatrix;
132 ElementOldCellMatrix.resize(AuxVariables.
NRows);
133 for(
int i = 0;
i < AuxVariables.
NRows;
i++)
134 ElementOldCellMatrix[
i].resize(AuxVariables.
NColumns);
135 for(
int i = 0;
i < AuxVariables.
NRows;
i++)
139 ElementOldCellMatrix[
i][
j].resize(AuxVariables.
NSections);
149 int NElems =
static_cast<int>(rInitialModelPart.
Elements().size());
150 ModelPart::ElementsContainerType::iterator el_begin = rInitialModelPart.
ElementsBegin();
152 #pragma omp parallel for private(X_me,Y_me,Z_me,PointsNumber)
153 for(
int i = 0;
i < NElems;
i++)
155 ModelPart::ElementsContainerType::iterator itElemOld = el_begin +
i;
157 double X_left = itElemOld->GetGeometry().GetPoint(0).X0();
158 double X_right = X_left;
159 double Y_top = itElemOld->GetGeometry().GetPoint(0).Y0();
160 double Y_bot = Y_top;
161 double Z_back = itElemOld->GetGeometry().GetPoint(0).Z0();
162 double Z_front = Z_back;
163 PointsNumber = itElemOld->GetGeometry().PointsNumber();
165 for(
int j = 1;
j < PointsNumber;
j++)
167 X_me = itElemOld->GetGeometry().GetPoint(
j).X0();
168 Y_me = itElemOld->GetGeometry().GetPoint(
j).Y0();
169 Z_me = itElemOld->GetGeometry().GetPoint(
j).Z0();
171 if(X_me > X_right) X_right = X_me;
172 else if(X_me < X_left) X_left = X_me;
173 if(Y_me > Y_top) Y_top = Y_me;
174 else if(Y_me < Y_bot) Y_bot = Y_me;
175 if(Z_me > Z_front) Z_front = Z_me;
176 else if(Z_me < Z_back) Z_back = Z_me;
186 if(Column_left < 0) Column_left = 0;
187 else if(Column_left >= AuxVariables.
NColumns) Column_left = AuxVariables.
NColumns-1;
188 if(Column_right >= AuxVariables.
NColumns) Column_right = AuxVariables.
NColumns-1;
189 else if(Column_right < 0) Column_right = 0;
190 if(Row_top < 0) Row_top = 0;
191 else if(Row_top >= AuxVariables.
NRows) Row_top = AuxVariables.
NRows-1;
192 if(Row_bot >= AuxVariables.
NRows) Row_bot = AuxVariables.
NRows-1;
193 else if(Row_bot < 0) Row_bot = 0;
194 if(Section_back < 0) Section_back = 0;
195 else if(Section_back >= AuxVariables.
NSections) Section_back = AuxVariables.
NSections-1;
197 else if(Section_front < 0) Section_front = 0;
199 for(
int s = Section_back; s <= Section_front; s++)
201 for(
int k = Row_top;
k <= Row_bot;
k++)
203 for(
int l = Column_left;
l <= Column_right;
l++)
207 ElementOldCellMatrix[
k][
l][s].push_back((*(itElemOld.base())));
215 const int NNodes =
static_cast<int>(rCurrentModelPart.
Nodes().size());
216 ModelPart::NodesContainerType::iterator node_begin = rCurrentModelPart.
NodesBegin();
221 #pragma omp parallel for private(X_me,Y_me,Z_me,PointsNumber,GlobalCoordinates,LocalCoordinates)
222 for(
int i = 0;
i < NNodes;
i++)
224 ModelPart::NodesContainerType::iterator itNodeNew = node_begin +
i;
226 X_me = itNodeNew->X0();
227 Y_me = itNodeNew->Y0();
228 Z_me = itNodeNew->Z0();
235 else if(Column < 0) Column = 0;
236 if(Row >= AuxVariables.
NRows) Row = AuxVariables.
NRows-1;
237 else if(Row < 0) Row = 0;
239 else if(Section < 0) Section = 0;
241 noalias(GlobalCoordinates) = itNodeNew->Coordinates();
242 bool IsInside =
false;
243 Element::Pointer pElementOld;
245 for(
unsigned int m = 0;
m < (ElementOldCellMatrix[Row][Column][Section]).size();
m++)
247 pElementOld = ElementOldCellMatrix[Row][Column][Section][
m];
248 IsInside = pElementOld->GetGeometry().IsInside(GlobalCoordinates,LocalCoordinates);
262 for(
int j = 0;
j < 12;
j++)
264 for(
int k = 1;
k<10;
k++)
266 for(
unsigned int m = 0;
m < (ElementOldCellMatrix[Row][Column][Section]).size();
m++)
268 pElementOld = ElementOldCellMatrix[Row][Column][Section][
m];
269 double tol =
k * pow(10.0, (
j-12));
270 IsInside = pElementOld->GetGeometry().IsInside(GlobalCoordinates,LocalCoordinates,
tol);
279 if(IsInside ==
false)
280 std::cout <<
"ERROR!!, NONE OF THE OLD ELEMENTS CONTAINS NODE: " << itNodeNew->Id() << std::endl;
282 PointsNumber = pElementOld->GetGeometry().PointsNumber();
284 Vector ShapeFunctionsValuesVector(PointsNumber);
285 pElementOld->GetGeometry().ShapeFunctionsValues(ShapeFunctionsValuesVector,LocalCoordinates);
288 std::vector<Vector> ComponentsNodalVariableVector(6);
289 for(
int j = 0;
j < 6;
j++) {
290 ComponentsNodalVariableVector[
j].resize(PointsNumber);
292 Vector nodal_initial_stress_vector(6);
293 Matrix nodal_initial_stress_tensor(3,3);
294 for(
int j = 0;
j < PointsNumber;
j++) {
295 noalias(nodal_initial_stress_tensor) = pElementOld->GetGeometry().GetPoint(
j).FastGetSolutionStepValue(INITIAL_STRESS_TENSOR);
297 for (
int k= 0;
k < 6;
k++) {
298 ComponentsNodalVariableVector[
k][
j] = nodal_initial_stress_vector[
k];
301 for (
int k= 0;
k < 6;
k++) {
302 nodal_initial_stress_vector[
k] =
inner_prod(ShapeFunctionsValuesVector,ComponentsNodalVariableVector[
k]);
305 Matrix& rNodalStress = itNodeNew->FastGetSolutionStepValue(INITIAL_STRESS_TENSOR);
306 if(rNodalStress.size1() != 3)
307 rNodalStress.
resize(3,3,
false);
308 noalias(rNodalStress) = nodal_initial_stress_tensor;
318 void ComputeCellMatrixDimensions(
319 UtilityVariables& rAuxVariables,
324 std::vector<double> X_max_partition(NumThreads);
325 std::vector<double> X_min_partition(NumThreads);
326 std::vector<double> Y_max_partition(NumThreads);
327 std::vector<double> Y_min_partition(NumThreads);
328 std::vector<double> Z_max_partition(NumThreads);
329 std::vector<double> Z_min_partition(NumThreads);
331 const int NNodes =
static_cast<int>(rModelPart.
Nodes().size());
332 ModelPart::NodesContainerType::iterator node_begin = rModelPart.
NodesBegin();
338 X_max_partition[
k] = node_begin->X();
339 X_min_partition[
k] = X_max_partition[
k];
340 Y_max_partition[
k] = node_begin->Y();
341 Y_min_partition[
k] = Y_max_partition[
k];
342 Z_max_partition[
k] = node_begin->Z();
343 Z_min_partition[
k] = Z_max_partition[
k];
345 double X_me, Y_me, Z_me;
348 for(
int i = 0;
i < NNodes;
i++)
350 ModelPart::NodesContainerType::iterator itNode = node_begin +
i;
356 if( X_me > X_max_partition[
k] ) X_max_partition[
k] = X_me;
357 else if( X_me < X_min_partition[
k] ) X_min_partition[
k] = X_me;
359 if( Y_me > Y_max_partition[
k] ) Y_max_partition[
k] = Y_me;
360 else if( Y_me < Y_min_partition[
k] ) Y_min_partition[
k] = Y_me;
362 if( Z_me > Z_max_partition[
k] ) Z_max_partition[
k] = Z_me;
363 else if( Z_me < Z_min_partition[
k] ) Z_min_partition[
k] = Z_me;
367 rAuxVariables.X_max = X_max_partition[0];
368 rAuxVariables.X_min = X_min_partition[0];
369 rAuxVariables.Y_max = Y_max_partition[0];
370 rAuxVariables.Y_min = Y_min_partition[0];
371 rAuxVariables.Z_max = Z_max_partition[0];
372 rAuxVariables.Z_min = Z_min_partition[0];
374 for(
unsigned int i=1;
i < NumThreads;
i++)
376 if(X_max_partition[
i] > rAuxVariables.X_max) rAuxVariables.X_max = X_max_partition[
i];
377 if(X_min_partition[
i] < rAuxVariables.X_min) rAuxVariables.X_min = X_min_partition[
i];
378 if(Y_max_partition[
i] > rAuxVariables.Y_max) rAuxVariables.Y_max = Y_max_partition[
i];
379 if(Y_min_partition[
i] < rAuxVariables.Y_min) rAuxVariables.Y_min = Y_min_partition[
i];
380 if(Z_max_partition[
i] > rAuxVariables.Z_max) rAuxVariables.Z_max = Z_max_partition[
i];
381 if(Z_min_partition[
i] < rAuxVariables.Z_min) rAuxVariables.Z_min = Z_min_partition[
i];
385 double AverageElementLength = 0.0;
387 int NElems =
static_cast<int>(rModelPart.
Elements().size());
388 ModelPart::ElementsContainerType::iterator el_begin = rModelPart.
ElementsBegin();
390 #pragma omp parallel for reduction(+:AverageElementLength)
391 for(
int i = 0;
i < NElems;
i++)
393 ModelPart::ElementsContainerType::iterator itElem = el_begin +
i;
395 AverageElementLength += itElem->GetGeometry().Length();
398 AverageElementLength = AverageElementLength/NElems;
401 rAuxVariables.NRows =
int((rAuxVariables.Y_max-rAuxVariables.Y_min)/AverageElementLength);
402 rAuxVariables.NColumns =
int((rAuxVariables.X_max-rAuxVariables.X_min)/AverageElementLength);
403 rAuxVariables.NSections =
int((rAuxVariables.Z_max-rAuxVariables.Z_min)/AverageElementLength);
404 if(rAuxVariables.NRows <= 0) rAuxVariables.NRows = 1;
405 if(rAuxVariables.NColumns <= 0) rAuxVariables.NColumns = 1;
406 if(rAuxVariables.NSections <= 0) rAuxVariables.NSections = 1;
407 rAuxVariables.RowSize = (rAuxVariables.Y_max-rAuxVariables.Y_min)/rAuxVariables.NRows;
408 rAuxVariables.ColumnSize = (rAuxVariables.X_max-rAuxVariables.X_min)/rAuxVariables.NColumns;
409 rAuxVariables.SectionSize = (rAuxVariables.Z_max-rAuxVariables.Z_min)/rAuxVariables.NSections;
414 void CalculateNodalStresses(ModelPart& rCurrentModelPart) {
417 const int NNodes =
static_cast<int>(rCurrentModelPart.Nodes().size());
418 ModelPart::NodesContainerType::iterator node_begin = rCurrentModelPart.NodesBegin();
420 #pragma omp parallel for
421 for(
int i = 0;
i < NNodes;
i++)
423 ModelPart::NodesContainerType::iterator it_node = node_begin +
i;
424 it_node->FastGetSolutionStepValue(NODAL_AREA) = 0.0;
425 Matrix& rNodalStress = it_node->FastGetSolutionStepValue(NODAL_EFFECTIVE_STRESS_TENSOR);
426 if(rNodalStress.size1() != 3)
427 rNodalStress.
resize(3,3,
false);
432 const ProcessInfo& r_current_process_info = rCurrentModelPart.GetProcessInfo();
433 const auto it_elem_begin = rCurrentModelPart.ElementsBegin();
434 #pragma omp parallel for
435 for(
int i=0; i<static_cast<int>(rCurrentModelPart.Elements().size()); ++
i) {
436 auto it_elem = it_elem_begin +
i;
437 it_elem->FinalizeSolutionStep(r_current_process_info);
441 #pragma omp parallel for
442 for(
int n = 0;
n < NNodes;
n++)
444 ModelPart::NodesContainerType::iterator it_node = node_begin +
n;
445 const double& NodalArea = it_node->FastGetSolutionStepValue(NODAL_AREA);
446 if (NodalArea>1.0e-20)
448 const double InvNodalArea = 1.0/NodalArea;
449 Matrix& rNodalStress = it_node->FastGetSolutionStepValue(NODAL_EFFECTIVE_STRESS_TENSOR);
450 for(
unsigned int i = 0;
i<3;
i++)
452 for(
unsigned int j = 0;
j<3;
j++)
454 rNodalStress(
i,
j) *= InvNodalArea;
463 void WriteLinearElements(std::fstream& rInitialStressesMdpa, ModelPart& rCurrentModelPart) {
465 int NElems =
static_cast<int>(rCurrentModelPart.Elements().size());
466 ModelPart::ElementsContainerType::iterator el_begin = rCurrentModelPart.ElementsBegin();
468 int PointsNumber = el_begin->GetGeometry().PointsNumber();
469 if(PointsNumber == 4){
470 rInitialStressesMdpa <<
"Begin Elements Element3D4N" << std::endl;
472 for(
int i = 0;
i < NElems;
i++)
474 ModelPart::ElementsContainerType::iterator it_elem = el_begin +
i;
475 rInitialStressesMdpa << it_elem->Id() <<
" 0 " <<
476 it_elem->GetGeometry().GetPoint(0).Id() <<
" " <<
477 it_elem->GetGeometry().GetPoint(1).Id() <<
" " <<
478 it_elem->GetGeometry().GetPoint(2).Id() <<
" " <<
479 it_elem->GetGeometry().GetPoint(3).Id() << std::endl;
482 rInitialStressesMdpa <<
"Begin Elements Element3D8N" << std::endl;
484 for(
int i = 0;
i < NElems;
i++)
486 ModelPart::ElementsContainerType::iterator it_elem = el_begin +
i;
487 rInitialStressesMdpa << it_elem->Id() <<
" 0 " <<
488 it_elem->GetGeometry().GetPoint(0).Id() <<
" " <<
489 it_elem->GetGeometry().GetPoint(1).Id() <<
" " <<
490 it_elem->GetGeometry().GetPoint(2).Id() <<
" " <<
491 it_elem->GetGeometry().GetPoint(3).Id() <<
" " <<
492 it_elem->GetGeometry().GetPoint(4).Id() <<
" " <<
493 it_elem->GetGeometry().GetPoint(5).Id() <<
" " <<
494 it_elem->GetGeometry().GetPoint(6).Id() <<
" " <<
495 it_elem->GetGeometry().GetPoint(7).Id() << std::endl;
498 rInitialStressesMdpa <<
"End Elements" << std::endl << std::endl;
Definition: initial_stress_3D_utilities.hpp:37
void NodalVariablesMapping(const UtilityVariables &AuxVariables, ModelPart &rInitialModelPart, ModelPart &rCurrentModelPart)
Member Variables.
Definition: initial_stress_3D_utilities.hpp:125
void SaveInitialStresses(Parameters &rParameters, ModelPart &rCurrentModelPart)
Definition: initial_stress_3D_utilities.hpp:76
void TransferInitialStresses(ModelPart &rInitialModelPart, ModelPart &rCurrentModelPart)
Definition: initial_stress_3D_utilities.hpp:64
InitialStress3DUtilities()
Constructor.
Definition: initial_stress_3D_utilities.hpp:55
KRATOS_CLASS_POINTER_DEFINITION(InitialStress3DUtilities)
virtual ~InitialStress3DUtilities()
Destructor.
Definition: initial_stress_3D_utilities.hpp:60
void resize(std::size_t NewSize1, std::size_t NewSize2, bool preserve=0)
Definition: amatrix_interface.h:224
static TMatrixType StressVectorToTensor(const TVector &rStressVector)
Transforms a stess vector into a matrix. Stresses are assumed to be stored in the following way: for...
Definition: math_utils.h:1174
static TVector StressTensorToVector(const TMatrixType &rStressTensor, SizeType rSize=0)
Transforms a given symmetric Stress Tensor to Voigt Notation:
Definition: math_utils.h:1399
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
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
std::string GetString() const
This method returns the string contained in the current Parameter.
Definition: kratos_parameters.cpp:684
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
KratosZeroMatrix< double > ZeroMatrix
Definition: amatrix_interface.h:559
Internals::Matrix< double, AMatrix::dynamic, AMatrix::dynamic > Matrix
Definition: amatrix_interface.h:470
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
ProcessInfo
Definition: edgebased_PureConvection.py:116
int tol
Definition: hinsberg_optimization.py:138
out
Definition: isotropic_damage_automatic_differentiation.py:200
int n
manufactured solution and derivatives (u=0 at z=0 dudz=0 at z=domain_height)
Definition: ode_solve.py:402
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: initial_stress_3D_utilities.hpp:44
double X_min
Definition: initial_stress_3D_utilities.hpp:45
double X_max
Definition: initial_stress_3D_utilities.hpp:45
double Z_max
Definition: initial_stress_3D_utilities.hpp:45
int NSections
Definition: initial_stress_3D_utilities.hpp:46
int NColumns
Definition: initial_stress_3D_utilities.hpp:46
double Y_max
Definition: initial_stress_3D_utilities.hpp:45
double ColumnSize
Definition: initial_stress_3D_utilities.hpp:47
double Z_min
Definition: initial_stress_3D_utilities.hpp:45
double SectionSize
Definition: initial_stress_3D_utilities.hpp:47
double Y_min
Definition: initial_stress_3D_utilities.hpp:45
int NRows
Definition: initial_stress_3D_utilities.hpp:46
double RowSize
Definition: initial_stress_3D_utilities.hpp:47