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.
compute_average_pfem_mesh_parameters_process.hpp
Go to the documentation of this file.
1 //
2 // Project Name: KratosPfemFluidDynamicsApplication $
3 // Created by: $Author: AFranci $
4 // Last modified by: $Co-Author: $
5 // Date: $Date: October 2019 $
6 // Revision: $Revision: 0.0 $
7 //
8 //
9 
10 #if !defined(KRATOS_COMPUTE_AVERAGE_PFEM_MESH_PARAMETERS_PROCESS_H_INCLUDED)
11 #define KRATOS_COMPUTE_AVERAGE_PFEM_MESH_PARAMETERS_PROCESS_H_INCLUDED
12 
13 // External includes
14 
15 // System includes
16 
17 // Project includes
20 
21 #include "includes/model_part.h"
24 
27 
29 // Data:
30 // Flags: (checked)
31 // (set)
32 // (modified)
33 // (reset)
34 //(set):=(set in this process)
35 
36 namespace Kratos
37 {
38 
41 
43 
48  : public MesherProcess
49  {
50  public:
53 
56 
61 
65 
68  MesherUtilities::MeshingParameters &rRemeshingParameters,
69  int EchoLevel)
70  : mrModelPart(rModelPart),
71  mrRemesh(rRemeshingParameters)
72  {
73  KRATOS_INFO("ComputeAveragePfemMeshParametersProcess") << " activated " << std::endl;
74 
75  mEchoLevel = EchoLevel;
76  }
77 
80 
84 
86  void operator()()
87  {
88  Execute();
89  }
90 
94 
96  void Execute() override
97  {
99 
100  if (mEchoLevel > 1)
101  std::cout << " COMPUTE AVERAGE PFEM MESH PARAMETERS PROCESS ]; " << std::endl;
102 
103  const unsigned int dimension = mrModelPart.ElementsBegin()->GetGeometry().WorkingSpaceDimension();
104  const unsigned int numberOfRefiningBoxes = mrRemesh.UseRefiningBox.size();
105  Vector inBoxesNodes(numberOfRefiningBoxes);
106  noalias(inBoxesNodes) = ZeroVector(numberOfRefiningBoxes);
107  Vector inBoxesMeanNodalSize(numberOfRefiningBoxes);
108  noalias(inBoxesMeanNodalSize) = ZeroVector(numberOfRefiningBoxes);
109  double preliminaryOutOfBoxesFluidNodes = 0;
110  double preliminaryOutOfBoxesMeanNodalSize = 0;
111  bool homogeneousMesh = true;
112  for (ModelPart::NodesContainerType::iterator i_node = mrModelPart.NodesBegin(); i_node != mrModelPart.NodesEnd(); i_node++)
113  {
114  if (i_node->Is(FLUID))
115  {
116  if (numberOfRefiningBoxes == 0 || (numberOfRefiningBoxes == 1 && mrRemesh.UseRefiningBox[0] == false))
117  {
118  preliminaryOutOfBoxesFluidNodes += 1.0;
119  preliminaryOutOfBoxesMeanNodalSize += i_node->FastGetSolutionStepValue(NODAL_H);
120  }
121  else
122  {
123  unsigned outOfRefiningBoxes = true;
124  for (unsigned int index = 0; index < numberOfRefiningBoxes; index++)
125  {
126  array_1d<double, 3> RefiningBoxMinimumPoint = mrRemesh.RefiningBoxMinimumPoint[index];
127  array_1d<double, 3> RefiningBoxMaximumPoint = mrRemesh.RefiningBoxMaximumPoint[index];
128  if (mrRemesh.UseRefiningBox[index] == true)
129  {
130  homogeneousMesh = false;
131  if (dimension == 2)
132  {
133  if (i_node->X() > RefiningBoxMinimumPoint[0] && i_node->Y() > RefiningBoxMinimumPoint[1] &&
134  i_node->X() < RefiningBoxMaximumPoint[0] && i_node->Y() < RefiningBoxMaximumPoint[1])
135  {
136  outOfRefiningBoxes = false;
137  inBoxesNodes[index] += 1.0;
138  inBoxesMeanNodalSize[index] += i_node->FastGetSolutionStepValue(NODAL_H); // this is a preliminary evaluation of the local mesh size
139  }
140  }
141  else if (dimension == 3)
142  {
143  if (i_node->X() > RefiningBoxMinimumPoint[0] && i_node->Y() > RefiningBoxMinimumPoint[1] && i_node->Z() > RefiningBoxMinimumPoint[2] &&
144  i_node->X() < RefiningBoxMaximumPoint[0] && i_node->Y() < RefiningBoxMaximumPoint[1] && i_node->Z() < RefiningBoxMaximumPoint[2])
145  {
146  outOfRefiningBoxes = false;
147  inBoxesNodes[index] += 1.0;
148  inBoxesMeanNodalSize[index] += i_node->FastGetSolutionStepValue(NODAL_H); // this is a preliminary evaluation of the local mesh size
149  }
150  }
151  }
152  }
153  // CONSIDER ONLY THE NODES OUT FROM THE REFINEMENT AREAS
154  if (outOfRefiningBoxes == true)
155  {
156  preliminaryOutOfBoxesFluidNodes += 1.0;
157  preliminaryOutOfBoxesMeanNodalSize += i_node->FastGetSolutionStepValue(NODAL_H); // this is a preliminary evaluation of the local mesh size
158  }
159  }
160  }
161  }
162  preliminaryOutOfBoxesMeanNodalSize *= 1.0 / preliminaryOutOfBoxesFluidNodes;
163 
164  mrRemesh.Refine->CriticalRadius = preliminaryOutOfBoxesMeanNodalSize;
165  mrRemesh.Refine->InitialRadius = preliminaryOutOfBoxesMeanNodalSize;
166 
167  if (homogeneousMesh == false)
168  {
169  double outOfBoxesFluidNodes = 0;
170  double outOfBoxesMeanNodalSize = 0;
171  for (ModelPart::NodesContainerType::iterator i_node = mrModelPart.NodesBegin(); i_node != mrModelPart.NodesEnd(); i_node++)
172  {
173  if (i_node->Is(FLUID))
174  {
175  unsigned outOfRefiningBoxes = true;
176  for (unsigned int index = 0; index < numberOfRefiningBoxes; index++)
177  {
178  const double transitionDistanceInInputMesh = mrRemesh.RefiningBoxElementsInTransitionZone[index] * mrRemesh.Refine->CriticalRadius;
179  array_1d<double, 3> RefiningBoxMinimumPoint = mrRemesh.RefiningBoxMinimumPoint[index];
180  array_1d<double, 3> RefiningBoxMaximumPoint = mrRemesh.RefiningBoxMaximumPoint[index];
181  if (mrRemesh.UseRefiningBox[index] == true)
182  {
183  if (dimension == 2)
184  {
185  if (i_node->X() > (RefiningBoxMinimumPoint[0] - transitionDistanceInInputMesh) && i_node->Y() > (RefiningBoxMinimumPoint[1] - transitionDistanceInInputMesh) &&
186  i_node->X() < (RefiningBoxMaximumPoint[0] + transitionDistanceInInputMesh) && i_node->Y() < (RefiningBoxMaximumPoint[1] + transitionDistanceInInputMesh))
187  {
188  outOfRefiningBoxes = false;
189  }
190  }
191  else if (dimension == 3)
192  {
193  if (i_node->X() > (RefiningBoxMinimumPoint[0] - transitionDistanceInInputMesh) && i_node->Y() > (RefiningBoxMinimumPoint[1] - transitionDistanceInInputMesh) && i_node->Z() > (RefiningBoxMinimumPoint[2] - transitionDistanceInInputMesh) &&
194  i_node->X() < (RefiningBoxMaximumPoint[0] + transitionDistanceInInputMesh) && i_node->Y() < (RefiningBoxMaximumPoint[1] + transitionDistanceInInputMesh) && i_node->Z() < (RefiningBoxMaximumPoint[2] + transitionDistanceInInputMesh))
195  {
196  outOfRefiningBoxes = false;
197  }
198  }
199  }
200  }
201  // CONSIDER ONLY THE NODES OUT FROM THE REFINEMENT AREAS
202  if (outOfRefiningBoxes == true)
203  {
204  outOfBoxesFluidNodes += 1.0;
205  outOfBoxesMeanNodalSize += i_node->FastGetSolutionStepValue(NODAL_H);
206  }
207  }
208  }
209  if (outOfBoxesFluidNodes == 0)
210  {
211  mrRemesh.Refine->CriticalRadius = preliminaryOutOfBoxesMeanNodalSize;
212  mrRemesh.Refine->InitialRadius = preliminaryOutOfBoxesMeanNodalSize;
213  std::cout << "the coarse zone is too thin, I'll take the preliminary mesh size estimation: " << preliminaryOutOfBoxesMeanNodalSize << std::endl;
214  }
215  else
216  {
217  outOfBoxesMeanNodalSize *= 1.0 / outOfBoxesFluidNodes;
218  mrRemesh.Refine->CriticalRadius = outOfBoxesMeanNodalSize;
219  mrRemesh.Refine->InitialRadius = outOfBoxesMeanNodalSize;
220  }
221 
222  std::cout << "Mesh size outside the refining boxes is: " << outOfBoxesMeanNodalSize << std::endl;
223  for (unsigned int index = 0; index < numberOfRefiningBoxes; index++)
224  {
225  double localMeshSize = inBoxesMeanNodalSize[index] / inBoxesNodes[index];
226  std::cout << "Mesh size inside refining box n." << index << " is: " << localMeshSize << std::endl;
227 
228  mrRemesh.SetRefiningBoxMeshSize(index, localMeshSize);
229  const double tolerance = mrRemesh.RefiningBoxMeshSize[index] * 0.01;
230  const double differenceOfSize = outOfBoxesMeanNodalSize - mrRemesh.RefiningBoxMeshSize[index];
231 
232  mrRemesh.RefiningBoxMinimumPoint[index][0] += -tolerance; // the finest nodes at the frontier should not be erased
233  mrRemesh.RefiningBoxMinimumPoint[index][1] += -tolerance;
234  mrRemesh.RefiningBoxMinimumPoint[index][2] += -tolerance;
235 
236  mrRemesh.RefiningBoxMaximumPoint[index][0] += tolerance;
237  mrRemesh.RefiningBoxMaximumPoint[index][1] += tolerance;
238  mrRemesh.RefiningBoxMaximumPoint[index][2] += tolerance;
239 
240  const double transitionDistance = mrRemesh.RefiningBoxElementsInTransitionZone[index] * std::abs(differenceOfSize);
241 
242  mrRemesh.RefiningBoxShiftedMinimumPoint[index][0] = mrRemesh.RefiningBoxMinimumPoint[index][0] - transitionDistance;
243  mrRemesh.RefiningBoxShiftedMinimumPoint[index][1] = mrRemesh.RefiningBoxMinimumPoint[index][1] - transitionDistance;
244  mrRemesh.RefiningBoxShiftedMinimumPoint[index][2] = mrRemesh.RefiningBoxMinimumPoint[index][2] - transitionDistance;
245 
246  mrRemesh.RefiningBoxShiftedMaximumPoint[index][0] = mrRemesh.RefiningBoxMaximumPoint[index][0] + transitionDistance;
247  mrRemesh.RefiningBoxShiftedMaximumPoint[index][1] = mrRemesh.RefiningBoxMaximumPoint[index][1] + transitionDistance;
248  mrRemesh.RefiningBoxShiftedMaximumPoint[index][2] = mrRemesh.RefiningBoxMaximumPoint[index][2] + transitionDistance;
249  }
250  }
251 
252  KRATOS_CATCH(" ")
253  }
254 
258 
262 
266 
268  std::string Info() const override
269  {
270  return "ComputeAveragePfemMeshParametersProcess";
271  }
272 
274  void PrintInfo(std::ostream &rOStream) const override
275  {
276  rOStream << "ComputeAveragePfemMeshParametersProcess";
277  }
278 
282 
284 
285  private:
288 
292  ModelPart &mrModelPart;
293 
295 
296  MesherUtilities mMesherUtilities;
297 
298  int mEchoLevel;
299 
303 
307 
311 
315 
319 
322 
324 
326  // Process(Process const& rOther);
327 
329 
330  }; // Class Process
331 
333 
336 
340 
342  inline std::istream &operator>>(std::istream &rIStream,
344 
346  inline std::ostream &operator<<(std::ostream &rOStream,
348  {
349  rThis.PrintInfo(rOStream);
350  rOStream << std::endl;
351  rThis.PrintData(rOStream);
352 
353  return rOStream;
354  }
356 
357 } // namespace Kratos.
358 
359 #endif // KRATOS_SET_INLET_PROCESS_H_INCLUDED defined
Refine Mesh Elements Process 2D and 3D.
Definition: compute_average_pfem_mesh_parameters_process.hpp:49
ModelPart::ConditionType ConditionType
Definition: compute_average_pfem_mesh_parameters_process.hpp:58
ModelPart::NodeType NodeType
Definition: compute_average_pfem_mesh_parameters_process.hpp:57
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: compute_average_pfem_mesh_parameters_process.hpp:274
void operator()()
This operator is provided to call the process as a function and simply calls the Execute method.
Definition: compute_average_pfem_mesh_parameters_process.hpp:86
ModelPart::PropertiesType PropertiesType
Definition: compute_average_pfem_mesh_parameters_process.hpp:59
ComputeAveragePfemMeshParametersProcess(ModelPart &rModelPart, MesherUtilities::MeshingParameters &rRemeshingParameters, int EchoLevel)
Default constructor.
Definition: compute_average_pfem_mesh_parameters_process.hpp:67
std::string Info() const override
Turn back information as a string.
Definition: compute_average_pfem_mesh_parameters_process.hpp:268
ConditionType::GeometryType GeometryType
Definition: compute_average_pfem_mesh_parameters_process.hpp:60
KRATOS_CLASS_POINTER_DEFINITION(ComputeAveragePfemMeshParametersProcess)
Pointer definition of Process.
void Execute() override
Execute method is used to execute the Process algorithms.
Definition: compute_average_pfem_mesh_parameters_process.hpp:96
virtual ~ComputeAveragePfemMeshParametersProcess()
Destructor.
Definition: compute_average_pfem_mesh_parameters_process.hpp:79
Base class for all Conditions.
Definition: condition.h:59
Geometry base class.
Definition: geometry.h:71
The base class for processes passed to the solution scheme.
Definition: mesher_process.hpp:37
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: mesher_process.hpp:157
Short class definition.
Definition: mesher_utilities.hpp:49
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
NodeIterator NodesEnd(IndexType ThisIndex=0)
Definition: model_part.h:497
This class defines the node.
Definition: node.h:65
Properties encapsulates data shared by different Elements or Conditions. It can store any type of dat...
Definition: properties.h:69
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_INFO(label)
Definition: logger.h:250
static int EchoLevel
Definition: co_sim_EMPIRE_API.h:42
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
KratosZeroVector< double > ZeroVector
Definition: amatrix_interface.h:561
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
int dimension
Definition: isotropic_damage_automatic_differentiation.py:123
Definition: mesher_utilities.hpp:631
RefiningParameters::Pointer Refine
Definition: mesher_utilities.hpp:684
std::vector< unsigned int > RefiningBoxElementsInTransitionZone
Definition: mesher_utilities.hpp:708
std::vector< array_1d< double, 3 > > RefiningBoxShiftedMaximumPoint
Definition: mesher_utilities.hpp:713
std::vector< double > RefiningBoxMeshSize
Definition: mesher_utilities.hpp:707
void SetRefiningBoxMeshSize(unsigned int index, double rRefiningBoxMeshSize)
Definition: mesher_utilities.hpp:969
std::vector< bool > UseRefiningBox
Definition: mesher_utilities.hpp:704
std::vector< array_1d< double, 3 > > RefiningBoxMinimumPoint
Definition: mesher_utilities.hpp:709
std::vector< array_1d< double, 3 > > RefiningBoxMaximumPoint
Definition: mesher_utilities.hpp:710
std::vector< array_1d< double, 3 > > RefiningBoxShiftedMinimumPoint
Definition: mesher_utilities.hpp:712