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.
build_mesh_boundary_for_fluids_process.hpp
Go to the documentation of this file.
1 //
2 // Project Name: KratosPfemApplication $
3 // Created by: $Author: AFranci $
4 // Last modified by: $Co-Author: $
5 // Date: $Date: September 2018 $
6 // Revision: $Revision: 0.0 $
7 //
8 //
9 
10 #if !defined(KRATOS_BUILD_MESH_BOUNDARY_FOR_FLUIDS_PROCESS_H_INCLUDED)
11 #define KRATOS_BUILD_MESH_BOUNDARY_FOR_FLUIDS_PROCESS_H_INCLUDED
12 
13 // System includes
14 
15 // External includes
16 
17 // Project includes
19 // #include <boost/timer.hpp>
20 
22 // Data: MASTER_ELEMENTS(set), MASTER_NODES(set)
23 // StepData:
24 // Flags: (checked) TO_ERASE, TO_REFINE, CONTACT, NEW_ENTITY
25 // (set) BOUNDARY(set), [TO_REFINE(nodes), TO_ERASE(condition)]->locally to not preserve condition
26 // (modified)
27 // (reset)
28 // (set):=(set in this process)
29 
30 namespace Kratos
31 {
32 
35 
42 
43  typedef GlobalPointersVector<Node> NodeWeakPtrVectorType;
44  typedef GlobalPointersVector<Element> ElementWeakPtrVectorType;
48 
52 
56 
58 
62  {
63  public:
66 
69 
73 
76  MesherUtilities::MeshingParameters &rRemeshingParameters,
77  int EchoLevel)
78  : BuildModelPartBoundaryProcess(rModelPart, rModelPart.Name(), EchoLevel),
79  mrRemesh(rRemeshingParameters)
80  {
81  }
82 
85  {
86  }
87 
91 
92  void operator()()
93  {
94  Execute();
95  }
96 
100 
101  void Execute() override
102  {
103  KRATOS_TRY
104 
105  bool success = false;
106 
107  if (mEchoLevel > 0)
108  std::cout << " [ Build Boundary on ModelPart [" << mrModelPart.Name() << "] ]" << std::endl;
109 
110  success = UniqueSkinSearch(mrModelPart);
111 
112  if (!success)
113  {
114  std::cout << " ERROR: BOUNDARY BUILD FAILED ModelPart : [" << mrModelPart << "] " << std::endl;
115  }
116 
117  KRATOS_CATCH(" ")
118  }
119 
123 
127 
131 
133  std::string Info() const override
134  {
135  return "BuildMeshBoundaryForFluidsProcess";
136  }
137 
139  void PrintInfo(std::ostream &rOStream) const override
140  {
141  rOStream << "BuildMeshBoundaryForFluidsProcess";
142  }
143 
145  void PrintData(std::ostream &rOStream) const override
146  {
147  }
148 
152 
154 
155  protected:
158 
162 
166 
167  //**************************************************************************
168  //**************************************************************************
169 
170  bool UniqueSkinSearch(ModelPart &rModelPart)
171  {
172 
173  KRATOS_TRY
174 
175  if (mEchoLevel > 0)
176  {
177  std::cout << " [ Initial Conditions : " << rModelPart.Conditions().size() << std::endl;
178  }
179 
180  if (!rModelPart.Elements().size() || (rModelPart.Is(ACTIVE)))
181  {
182  if (mEchoLevel > 0)
183  {
184  std::cout << " [ Final Conditions : " << rModelPart.Conditions().size() << std::endl;
185  }
186  return true;
187  }
188  const unsigned int dimension = mrModelPart.ElementsBegin()->GetGeometry().WorkingSpaceDimension();
189 
190  // reset the boundary flag in all nodes and check if a remesh process has been performed
191  bool any_node_to_erase = false;
192  for (ModelPart::NodesContainerType::const_iterator in = rModelPart.NodesBegin(); in != rModelPart.NodesEnd(); in++)
193  {
194 
195  NodeWeakPtrVectorType &nNodes = in->GetValue(NEIGHBOUR_NODES);
196  unsigned int neighNodes = nNodes.size();
197  if (neighNodes < (dimension + 1))
198  {
199  in->FastGetSolutionStepValue(ISOLATED_NODE) = 1;
200  }
201  else
202  {
203  in->FastGetSolutionStepValue(ISOLATED_NODE) = 0;
204  }
205 
206  if (in->Is(ISOLATED)) // to record the information of the previous step
207  {
208  in->Set(PFEMFlags::PREVIOUS_ISOLATED, true);
209  }
210  else
211  {
212  in->Reset(PFEMFlags::PREVIOUS_ISOLATED);
213  }
214 
215  if (in->Is(FREE_SURFACE)) // to record the information of the previous step
216  {
217  in->Set(PFEMFlags::PREVIOUS_FREESURFACE, true);
218  }
219  else
220  {
221  in->Reset(PFEMFlags::PREVIOUS_FREESURFACE);
222  }
223 
224  in->Reset(BOUNDARY);
225  in->Reset(FREE_SURFACE);
226 
227  if (any_node_to_erase == false)
228  if (in->Is(TO_ERASE))
229  any_node_to_erase = true;
230  }
231  SetBoundaryAndFreeSurface(rModelPart);
232 
233  return true;
234 
235  KRATOS_CATCH("")
236  }
237 
238  // bool SetBoundaryAndFreeSurface( ModelPart& rModelPart, ModelPart::ConditionsContainerType& rTemporaryConditions, std::vector<int>& rPreservedConditions, unsigned int& rConditionId )
240  {
241 
242  KRATOS_TRY
243 
244  // properties to be used in the generation
245  int number_properties = rModelPart.GetParentModelPart().NumberOfProperties();
246  Properties::Pointer properties = rModelPart.GetParentModelPart().pGetProperties(number_properties - 1);
247 
248  ModelPart::ElementsContainerType::iterator elements_begin = mrModelPart.ElementsBegin();
249  ModelPart::ElementsContainerType::iterator elements_end = mrModelPart.ElementsEnd();
250 
251  for (ModelPart::ElementsContainerType::iterator ie = elements_begin; ie != elements_end; ie++)
252  {
253 
254  Geometry<Node> &rElementGeometry = ie->GetGeometry();
255 
256  if (rElementGeometry.FacesNumber() >= 3)
257  { // 3 or 4
258 
259  /*each face is opposite to the corresponding node number so in 2D triangle
260  0 ----- 1 2
261  1 ----- 2 0
262  2 ----- 0 1
263  */
264 
265  /*each face is opposite to the corresponding node number so in 3D tetrahedron
266  0 ----- 1 2 3
267  1 ----- 2 0 3
268  2 ----- 0 1 3
269  3 ----- 0 2 1
270  */
271 
272  // finding boundaries and creating the "skin"
273  //
274  //********************************************************************
275 
276  boost::numeric::ublas::matrix<unsigned int> lpofa; // connectivities of points defining faces
277  boost::numeric::ublas::vector<unsigned int> lnofa; // number of points defining faces
278 
279  ElementWeakPtrVectorType &rE = ie->GetValue(NEIGHBOUR_ELEMENTS);
280 
281  // get matrix nodes in faces
282  rElementGeometry.NodesInFaces(lpofa);
283  rElementGeometry.NumberNodesInFaces(lnofa);
284 
285  // loop on neighbour elements of an element
286  unsigned int iface = 0;
287  for (ElementWeakPtrVectorType::iterator ne = rE.begin(); ne != rE.end(); ne++)
288  {
289 
290  unsigned int NumberNodesInFace = lnofa[iface];
291 
292  if ((ne)->Id() == ie->Id())
293  {
294 
295  // if no neighbour is present => the face is free surface
296  bool freeSurfaceFace = false;
297  for (unsigned int j = 1; j <= NumberNodesInFace; j++)
298  {
299  rElementGeometry[lpofa(j, iface)].Set(BOUNDARY);
300  if (rElementGeometry[lpofa(j, iface)].IsNot(RIGID))
301  {
302  freeSurfaceFace = true;
303  }
304  }
305  if (freeSurfaceFace == true)
306  {
307  for (unsigned int j = 1; j <= NumberNodesInFace; j++)
308  {
309  rElementGeometry[lpofa(j, iface)].Set(FREE_SURFACE);
310  }
311  }
312 
313  } // end face condition
314 
315  iface += 1;
316 
317  } // end loop neighbours
318  }
319  }
320 
321  return true;
322 
323  KRATOS_CATCH("")
324  }
325 
326  //**************************************************************************
327  //**************************************************************************
328 
329  bool CheckAcceptedCondition(ModelPart &rModelPart, Condition &rCondition) override
330  {
331  KRATOS_TRY
332 
333  bool node_not_preserved = false;
334  bool condition_not_preserved = false;
335 
336  Geometry<Node> &rConditionGeometry = rCondition.GetGeometry();
337 
338  for (unsigned int j = 0; j < rConditionGeometry.size(); j++)
339  {
340  if (rConditionGeometry[j].Is(TO_ERASE) || rConditionGeometry[j].Is(TO_REFINE))
341  node_not_preserved = true;
342 
343  if (rConditionGeometry[j].Is(ISOLATED) || rConditionGeometry[j].IsNot(BOUNDARY))
344  condition_not_preserved = true;
345  }
346 
347  if (rCondition.Is(TO_ERASE))
348  condition_not_preserved = true;
349 
350  if (rCondition.Is(BOUNDARY)) // flag for composite condition
351  condition_not_preserved = true;
352 
353  if (node_not_preserved == true || condition_not_preserved == true)
354  return false;
355  else
356  return true;
357 
358  KRATOS_CATCH("")
359  }
360 
361  //**************************************************************************
362  //**************************************************************************
363 
364  void AddConditionToModelPart(ModelPart &rModelPart, Condition::Pointer pCondition) override
365  {
366  KRATOS_TRY
367 
368  rModelPart.Conditions().push_back(pCondition);
369 
370  KRATOS_CATCH("")
371  }
372 
376 
380 
384 
388 
390 
391  private:
394 
398 
400 
404 
408 
409  //**************************************************************************
410  //**************************************************************************
411 
412  bool FindNodeInCondition(Geometry<Node> &rConditionGeometry, Geometry<Node> &rElementGeometry, boost::numeric::ublas::matrix<unsigned int> &lpofa, boost::numeric::ublas::vector<unsigned int> &lnofa, unsigned int &iface)
413  {
414  KRATOS_TRY
415 
416  // not equivalent geometry sizes for boundary conditions:
417  if (rConditionGeometry.size() != lnofa[iface])
418  return false;
419 
420  // line boundary condition:
421  if (lnofa[iface] == 2)
422  {
423  if (rConditionGeometry[0].Id() == rElementGeometry[lpofa(1, iface)].Id() ||
424  rConditionGeometry[1].Id() == rElementGeometry[lpofa(2, iface)].Id() ||
425  rConditionGeometry[0].Id() == rElementGeometry[lpofa(2, iface)].Id() ||
426  rConditionGeometry[1].Id() == rElementGeometry[lpofa(1, iface)].Id())
427  {
428  return true;
429  }
430  else
431  {
432  return false;
433  }
434  }
435 
436  // 3D faces:
437  if (lnofa[iface] == 3)
438  {
439  if (rConditionGeometry[0].Id() == rElementGeometry[lpofa(1, iface)].Id() ||
440  rConditionGeometry[1].Id() == rElementGeometry[lpofa(2, iface)].Id() ||
441  rConditionGeometry[2].Id() == rElementGeometry[lpofa(3, iface)].Id() ||
442  rConditionGeometry[0].Id() == rElementGeometry[lpofa(3, iface)].Id() ||
443  rConditionGeometry[1].Id() == rElementGeometry[lpofa(1, iface)].Id() ||
444  rConditionGeometry[2].Id() == rElementGeometry[lpofa(2, iface)].Id() ||
445  rConditionGeometry[0].Id() == rElementGeometry[lpofa(2, iface)].Id() ||
446  rConditionGeometry[1].Id() == rElementGeometry[lpofa(3, iface)].Id() ||
447  rConditionGeometry[2].Id() == rElementGeometry[lpofa(1, iface)].Id())
448  {
449  return true;
450  }
451  else
452  {
453  return false;
454  }
455  }
456 
457  if (lnofa[iface] > 3)
458  {
459  KRATOS_THROW_ERROR(std::logic_error, "Wrong Condition Number of Face Nodes", *this);
460  }
461 
462  return false;
463 
464  KRATOS_CATCH(" ")
465  }
466 
470 
474 
478 
481 
483 
484  }; // Class BuildMeshBoundaryForFluidsProcess
485 
487 
490 
494 
496  inline std::istream &operator>>(std::istream &rIStream,
498 
500  inline std::ostream &operator<<(std::ostream &rOStream,
502  {
503  rThis.PrintInfo(rOStream);
504  rOStream << std::endl;
505  rThis.PrintData(rOStream);
506 
507  return rOStream;
508  }
510 
511 } // namespace Kratos.
512 
513 #endif // KRATOS_BUILD_MESH_BOUNDARY_FOR_FLUIDS_PROCESS_H_INCLUDED defined
Short class definition.
Definition: build_mesh_boundary_for_fluids_process.hpp:62
BuildMeshBoundaryForFluidsProcess(ModelPart &rModelPart, MesherUtilities::MeshingParameters &rRemeshingParameters, int EchoLevel)
Default constructor.
Definition: build_mesh_boundary_for_fluids_process.hpp:75
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: build_mesh_boundary_for_fluids_process.hpp:145
void Execute() override
Execute method is used to execute the Process algorithms.
Definition: build_mesh_boundary_for_fluids_process.hpp:101
bool UniqueSkinSearch(ModelPart &rModelPart)
Definition: build_mesh_boundary_for_fluids_process.hpp:170
virtual ~BuildMeshBoundaryForFluidsProcess()
Destructor.
Definition: build_mesh_boundary_for_fluids_process.hpp:84
std::string Info() const override
Turn back information as a string.
Definition: build_mesh_boundary_for_fluids_process.hpp:133
void AddConditionToModelPart(ModelPart &rModelPart, Condition::Pointer pCondition) override
Definition: build_mesh_boundary_for_fluids_process.hpp:364
void operator()()
Definition: build_mesh_boundary_for_fluids_process.hpp:92
KRATOS_CLASS_POINTER_DEFINITION(BuildMeshBoundaryForFluidsProcess)
Pointer definition of BuildMeshBoundaryForFluidsProcess.
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: build_mesh_boundary_for_fluids_process.hpp:139
bool SetBoundaryAndFreeSurface(ModelPart &rModelPart)
Definition: build_mesh_boundary_for_fluids_process.hpp:239
bool CheckAcceptedCondition(ModelPart &rModelPart, Condition &rCondition) override
Definition: build_mesh_boundary_for_fluids_process.hpp:329
Short class definition.
Definition: build_model_part_boundary_process.hpp:79
int mEchoLevel
Definition: build_model_part_boundary_process.hpp:571
ModelPart & mrModelPart
Definition: build_model_part_boundary_process.hpp:567
Base class for all Conditions.
Definition: condition.h:59
bool Is(Flags const &rOther) const
Definition: flags.h:274
bool IsNot(Flags const &rOther) const
Definition: flags.h:291
GeometryType & GetGeometry()
Returns the reference of the geometry.
Definition: geometrical_object.h:158
Geometry base class.
Definition: geometry.h:71
SizeType size() const
Definition: geometry.h:518
virtual void NodesInFaces(DenseMatrix< unsigned int > &rNodesInFaces) const
Definition: geometry.h:2195
virtual void NumberNodesInFaces(DenseVector< unsigned int > &rNumberNodesInFaces) const
Definition: geometry.h:2190
virtual SizeType FacesNumber() const
Returns the number of faces of the current geometry.
Definition: geometry.h:2152
This class is a vector which stores global pointers.
Definition: global_pointers_vector.h:61
boost::indirect_iterator< typename TContainerType::iterator > iterator
Definition: global_pointers_vector.h:79
iterator begin()
Definition: global_pointers_vector.h:221
size_type size() const
Definition: global_pointers_vector.h:307
iterator end()
Definition: global_pointers_vector.h:229
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
MeshType::ConditionsContainerType ConditionsContainerType
Condintions container. A vector set of Conditions with their Id's as key.
Definition: model_part.h:183
PropertiesType::Pointer pGetProperties(IndexType PropertiesId, IndexType MeshIndex=0)
Returns the Properties::Pointer corresponding to it's identifier.
Definition: model_part.cpp:664
SizeType NumberOfProperties(IndexType ThisIndex=0) const
Returns the number of properties of the mesh.
Definition: model_part.cpp:575
MeshType::ElementsContainerType ElementsContainerType
Element container. A vector set of Elements with their Id's as key.
Definition: model_part.h:168
std::string & Name()
Definition: model_part.h:1811
NodeIterator NodesBegin(IndexType ThisIndex=0)
Definition: model_part.h:487
ConditionsContainerType & Conditions(IndexType ThisIndex=0)
Definition: model_part.h:1381
ElementsContainerType & Elements(IndexType ThisIndex=0)
Definition: model_part.h:1189
MeshType::NodesContainerType NodesContainerType
Nodes container. Which is a vector set of nodes with their Id's as key.
Definition: model_part.h:128
ElementIterator ElementsEnd(IndexType ThisIndex=0)
Definition: model_part.h:1179
NodeIterator NodesEnd(IndexType ThisIndex=0)
Definition: model_part.h:497
ModelPart & GetParentModelPart()
Definition: model_part.cpp:2124
#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
GlobalPointersVector< Element > ElementWeakPtrVectorType
Definition: build_model_part_boundary_process.hpp:60
static int EchoLevel
Definition: co_sim_EMPIRE_API.h:42
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
ModelPart::NodesContainerType NodesContainerType
Definition: find_conditions_neighbours_process.h:44
ModelPart::ConditionsContainerType ConditionsContainerType
Definition: find_conditions_neighbours_process.h:45
GlobalPointersVector< Node > NodeWeakPtrVectorType
Definition: build_model_part_boundary_process.hpp:59
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
ModelPart::ElementsContainerType ElementsContainerType
Definition: clear_contact_conditions_mesher_process.hpp:43
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
int j
Definition: quadrature.py:648
Definition: mesher_utilities.hpp:631