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_model_part_boundary_for_fluids_process.hpp
Go to the documentation of this file.
1 //
2 // Project Name: KratosDelaunayMeshingApplication $
3 // Created by: $Author: AFranci $
4 // Last modified by: $Co-Author: $
5 // Date: $Date: eptember 2018 $
6 // Revision: $Revision: 0.0 $
7 //
8 //
9 
10 #if !defined(KRATOS_BUILD_MODEL_PART_BOUNDARY_FOR_FLUIDS_PROCESS_H_INCLUDED)
11 #define KRATOS_BUILD_MODEL_PART_BOUNDARY_FOR_FLUIDS_PROCESS_H_INCLUDED
12 
13 // System includes
14 
15 // External includes
16 
17 // Project includes
18 #include "processes/process.h"
19 #include "includes/node.h"
20 #include "includes/element.h"
21 #include "includes/model_part.h"
22 
23 #include "geometries/line_2d_2.h"
24 #include "geometries/line_2d_3.h"
25 #include "geometries/line_3d_2.h"
28 
33 
35 
37 // Data: MASTER_ELEMENTS(set), MASTER_NODES(set), NEIGHBOUR_ELEMENTS
38 // Flags: (checked) CONTACT
39 // (set) BOUNDARY(set)
40 // (modified)
41 // (reset)
42 //(set):=(set in this process)
43 
44 namespace Kratos
45 {
46 
49 
56 
57  typedef GlobalPointersVector<Node> NodeWeakPtrVectorType;
58  typedef GlobalPointersVector<Element> ElementWeakPtrVectorType;
59 
63 
67 
71 
73 
76  : public MesherProcess
77  {
78  public:
81 
84 
88 
91  std::string const rModelPartName,
92  int EchoLevel = 0)
93  : mrModelPart(rModelPart)
94  {
95  mModelPartName = rModelPartName;
97  }
98 
101  {
102  }
103 
107 
108  void operator()()
109  {
110  Execute();
111  }
112 
116 
117  void Execute() override
118  {
119 
120  KRATOS_TRY
121 
122  bool success = false;
123 
124  // double begin_time = OpenMPUtils::GetCurrentTime();
125 
126  unsigned int NumberOfSubModelParts = mrModelPart.NumberOfSubModelParts();
127 
128  this->ResetNodesBoundaryFlag(mrModelPart);
129 
131  {
132 
134  {
135 
136  if (mEchoLevel >= 1)
137  std::cout << " [ Construct Boundary on ModelPart [" << i_mp->Name() << "] ]" << std::endl;
138 
139  success = UniqueSkinSearch(*i_mp);
140 
141  if (!success)
142  {
143  std::cout << " ERROR: BOUNDARY CONSTRUCTION FAILED ModelPart : [" << i_mp->Name() << "] " << std::endl;
144  }
145  // else
146  // {
147  // if (mEchoLevel >= 1)
148  // {
149  // double end_time = OpenMPUtils::GetCurrentTime();
150  // std::cout << " [ Performed in Time = " << end_time - begin_time << " ]" << std::endl;
151  // }
152  // //PrintSkin(*i_mp);
153  // }
154  }
155  }
156  else
157  {
158 
159  if (mEchoLevel >= 1)
160  std::cout << " [ Construct Boundary on ModelPart[" << mModelPartName << "] ]" << std::endl;
161 
163  success = UniqueSkinSearch(rModelPart);
164 
165  if (!success)
166  {
167  std::cout << " ERROR: BOUNDARY CONSTRUCTION FAILED on ModelPart : [" << rModelPart.Name() << "] " << std::endl;
168  }
169  // else
170  // {
171  // if (mEchoLevel >= 1)
172  // {
173  // double end_time = OpenMPUtils::GetCurrentTime();
174  // std::cout << " [ Performed in Time = " << end_time - begin_time << " ]" << std::endl;
175  // }
176  // //PrintSkin(rModelPart);
177  // }
178  }
179 
180  if (NumberOfSubModelParts > 1)
181  {
182  SetMainModelPartConditions();
183  SetComputingModelPart();
184  }
185 
186  // ComputeBoundaryNormals BoundUtils;
187  BoundaryNormalsCalculationUtilities BoundaryComputation;
189  {
191  }
192  else
193  {
195  BoundaryComputation.CalculateUnitBoundaryNormals(rModelPart, mEchoLevel);
196  }
197 
198  if (mEchoLevel >= 1)
199  std::cout << " Boundary Normals Computed and Assigned ] " << std::endl;
200 
201  KRATOS_CATCH("")
202  }
203 
204  //**************************************************************************
205  //**************************************************************************
206 
208  {
209 
210  KRATOS_TRY
211 
212  int composite_conditions = 0;
213  int total_conditions = 0;
214  int counter = 0;
215 
216  bool found = false;
217 
218  for (ModelPart::ConditionsContainerType::iterator i_cond = mrModelPart.ConditionsBegin(); i_cond != mrModelPart.ConditionsEnd(); ++i_cond)
219  {
220 
221  if (i_cond->Is(BOUNDARY)) // composite condition
222  composite_conditions++;
223 
224  // std::cout<<" BeforeSearch::Condition ("<<i_cond->Id()<<") ME="<<i_cond->GetValue(MASTER_ELEMENTS)[0]->Id()<<", MN= "<<i_cond->GetValue(MASTER_NODES)[0]->Id()<<std::endl;
225 
226  //********************************************************************
227 
228  DenseMatrix<unsigned int> lpofa; // connectivities of points defining faces
229  DenseVector<unsigned int> lnofa; // number of points defining faces
230 
231  Geometry<Node> &rConditionGeometry = i_cond->GetGeometry();
232  unsigned int size = rConditionGeometry.size();
233 
234  bool perform_search = true;
235  for (unsigned int i = 0; i < size; ++i)
236  {
237  if (rConditionGeometry[i].Is(RIGID)) // if is a rigid wall do not search else do search
238  perform_search = false;
239  }
240 
241  if (i_cond->Is(CONTACT))
242  perform_search = false;
243 
244  //********************************************************************
245  found = false;
246 
247  if (perform_search)
248  {
249 
250  if (size == 2)
251  {
252 
253  ElementWeakPtrVectorType &rE1 = rConditionGeometry[0].GetValue(NEIGHBOUR_ELEMENTS);
254  ElementWeakPtrVectorType &rE2 = rConditionGeometry[1].GetValue(NEIGHBOUR_ELEMENTS);
255 
256  if (rE1.size() == 0 || rE2.size() == 0)
257  std::cout << " NO SIZE in NEIGHBOUR_ELEMENTS " << std::endl;
258 
259  for (ElementWeakPtrVectorType::iterator ie = rE1.begin(); ie != rE1.end(); ++ie)
260  {
261  for (ElementWeakPtrVectorType::iterator ne = rE2.begin(); ne != rE2.end(); ++ne)
262  {
263 
264  if ((ne)->Id() == (ie)->Id() && !found)
265  {
266  ElementWeakPtrVectorType MasterElements;
267  MasterElements.push_back(*ie.base());
268  if (mEchoLevel >= 1)
269  {
270  // if(i_cond->GetValue(MASTER_ELEMENTS)[0]->Id() != MasterElements[0]->Id())
271  // std::cout<<"Condition "<<i_cond->Id()<<" WARNING: master elements ("<<i_cond->GetValue(MASTER_ELEMENTS)[0]->Id()<<" != "<<MasterElements[0]->Id()<<")"<<std::endl;
272  }
273  i_cond->SetValue(MASTER_ELEMENTS, MasterElements);
274 
275  Geometry<Node> &rElementGeometry = (ie)->GetGeometry();
276 
277  // get matrix nodes in faces
278  rElementGeometry.NodesInFaces(lpofa);
279  rElementGeometry.NumberNodesInFaces(lnofa);
280 
281  int node = 0;
282  for (unsigned int iface = 0; iface < rElementGeometry.size(); ++iface)
283  {
284  MesherUtilities MesherUtils;
285  found = MesherUtils.FindCondition(rConditionGeometry, rElementGeometry, lpofa, lnofa, iface);
286 
287  if (found)
288  {
289  node = iface;
290  break;
291  }
292  }
293 
294  if (found)
295  {
296  NodeWeakPtrVectorType MasterNodes;
297  MasterNodes.push_back(rElementGeometry(lpofa(0, node)));
298  if (mEchoLevel >= 1)
299  {
300  if (i_cond->GetValue(MASTER_NODES)[0].Id() != MasterNodes[0].Id())
301  std::cout << "Condition " << i_cond->Id() << " WARNING: master nodes (" << i_cond->GetValue(MASTER_NODES)[0].Id() << " != " << MasterNodes[0].Id() << ")" << std::endl;
302  i_cond->SetValue(MASTER_NODES, MasterNodes);
303  }
304  }
305  else
306  {
307  std::cout << " MASTER_NODE not FOUND : something is wrong " << std::endl;
308  }
309  }
310  }
311  }
312  }
313  if (size == 3)
314  {
315 
316  ElementWeakPtrVectorType &rE1 = rConditionGeometry[0].GetValue(NEIGHBOUR_ELEMENTS);
317  ElementWeakPtrVectorType &rE2 = rConditionGeometry[1].GetValue(NEIGHBOUR_ELEMENTS);
318  ElementWeakPtrVectorType &rE3 = rConditionGeometry[2].GetValue(NEIGHBOUR_ELEMENTS);
319 
320  if (rE1.size() == 0 || rE2.size() == 0 || rE3.size() == 0)
321  std::cout << " NO SIZE in NEIGHBOUR_ELEMENTS " << std::endl;
322 
323  for (ElementWeakPtrVectorType::iterator ie = rE1.begin(); ie != rE1.end(); ++ie)
324  {
325  for (ElementWeakPtrVectorType::iterator je = rE2.begin(); je != rE2.end(); ++je)
326  {
327 
328  if ((je)->Id() == (ie)->Id() && !found)
329  {
330 
331  for (ElementWeakPtrVectorType::iterator ke = rE3.begin(); ke != rE3.end(); ++ke)
332  {
333 
334  if ((ke)->Id() == (ie)->Id() && !found)
335  {
336 
337  ElementWeakPtrVectorType MasterElements;
338  MasterElements.push_back(*ie.base());
339  if (mEchoLevel >= 1)
340  {
341  if (i_cond->GetValue(MASTER_ELEMENTS)[0].Id() != MasterElements[0].Id())
342  std::cout << "Condition " << i_cond->Id() << " WARNING: master elements (" << i_cond->GetValue(MASTER_ELEMENTS)[0].Id() << " != " << MasterElements[0].Id() << ")" << std::endl;
343  }
344  i_cond->SetValue(MASTER_ELEMENTS, MasterElements);
345 
346  Geometry<Node> &rElementGeometry = (ie)->GetGeometry();
347 
348  // get matrix nodes in faces
349  rElementGeometry.NodesInFaces(lpofa);
350  rElementGeometry.NumberNodesInFaces(lnofa);
351 
352  int node = 0;
353  for (unsigned int iface = 0; iface < rElementGeometry.size(); ++iface)
354  {
355  MesherUtilities MesherUtils;
356  found = MesherUtils.FindCondition(rConditionGeometry, rElementGeometry, lpofa, lnofa, iface);
357 
358  if (found)
359  {
360  node = iface;
361  break;
362  }
363  }
364 
365  if (found)
366  {
367  NodeWeakPtrVectorType MasterNodes;
368  MasterNodes.push_back(rElementGeometry(lpofa(0, node)));
369  if (mEchoLevel >= 1)
370  {
371  if (i_cond->GetValue(MASTER_NODES)[0].Id() != MasterNodes[0].Id())
372  std::cout << "Condition " << i_cond->Id() << " WARNING: master nodes (" << i_cond->GetValue(MASTER_NODES)[0].Id() << " != " << MasterNodes[0].Id() << ")" << std::endl;
373  }
374  i_cond->SetValue(MASTER_NODES, MasterNodes);
375  }
376  else
377  {
378  std::cout << " MASTER_NODE not FOUND : something is wrong " << std::endl;
379  }
380  }
381  }
382  }
383  }
384  }
385  }
386 
387  total_conditions++;
388  }
389 
390  //********************************************************************
391 
392  // std::cout<<" AfterSearch::Condition ("<<i_cond->Id()<<") : ME="<<i_cond->GetValue(MASTER_ELEMENTS)[0].Id()<<", MN= "<<i_cond->GetValue(MASTER_NODES)[0].Id()<<std::endl;
393 
394  if (found)
395  counter++;
396  }
397 
398  if (counter == total_conditions)
399  {
400  if (mEchoLevel >= 1)
401  std::cout << " Condition Masters (ModelPart " << mrModelPart.Name() << "): LOCATED [" << counter << "]" << std::endl;
402  found = true;
403  }
404  else
405  {
406  if (mEchoLevel >= 1)
407  std::cout << " Condition Masters (ModelPart " << mrModelPart.Name() << "): not LOCATED [" << counter - total_conditions << "]" << std::endl;
408  found = false;
409  }
410 
411  if (counter != composite_conditions)
412  if (mEchoLevel >= 1)
413  std::cout << " Condition Masters (ModelPart " << mrModelPart.Name() << "): LOCATED [" << counter << "] COMPOSITE [" << composite_conditions << "] NO MATCH" << std::endl;
414 
415  return found;
416 
417  std::cout << " Condition Masters Found " << std::endl;
418 
419  KRATOS_CATCH("")
420  }
421 
425 
429 
433 
435  std::string Info() const override
436  {
437  return "BuildModelPartBoundaryForFluidsProcess";
438  }
439 
441  void PrintInfo(std::ostream &rOStream) const override
442  {
443  rOStream << "BuildModelPartBoundaryForFluidsProcess";
444  }
445 
447  void PrintData(std::ostream &rOStream) const override
448  {
449  }
450 
454 
456 
457  protected:
460 
464 
466 
467  std::string mModelPartName;
468 
470 
474 
478 
479  //**************************************************************************
480  //**************************************************************************
481 
482  bool ClearMasterEntities(ModelPart &rModelPart, ModelPart::ConditionsContainerType &rTemporaryConditions)
483  {
484  KRATOS_TRY
485 
486  for (ModelPart::ConditionsContainerType::iterator ic = rTemporaryConditions.begin(); ic != rTemporaryConditions.end(); ++ic)
487  {
488  ElementWeakPtrVectorType &MasterElements = ic->GetValue(MASTER_ELEMENTS);
489  MasterElements.erase(MasterElements.begin(), MasterElements.end());
490 
491  NodeWeakPtrVectorType &MasterNodes = ic->GetValue(MASTER_NODES);
492  MasterNodes.erase(MasterNodes.begin(), MasterNodes.end());
493  }
494 
495  return true;
496 
497  KRATOS_CATCH("")
498  }
499 
500  //**************************************************************************
501  //**************************************************************************
502 
503  bool UniqueSkinSearch(ModelPart &rModelPart)
504  {
505 
506  KRATOS_TRY
507 
508  if (mEchoLevel > 0)
509  {
510  std::cout << " [ Initial Conditions : " << rModelPart.Conditions().size() << std::endl;
511  }
512 
513  if (!rModelPart.Elements().size() || (rModelPart.Is(ACTIVE)))
514  {
515  if (mEchoLevel > 0)
516  {
517  std::cout << " [ Final Conditions : " << rModelPart.Conditions().size() << std::endl;
518  }
519  return true;
520  }
521 
522  // check if a remesh process has been performed and there is any node to erase
523  bool any_node_to_erase = false;
524  for (ModelPart::NodesContainerType::const_iterator in = rModelPart.NodesBegin(); in != rModelPart.NodesEnd(); ++in)
525  {
526  if (any_node_to_erase == false)
527  if (in->Is(TO_ERASE))
528  any_node_to_erase = true;
529  }
530 
531  this->SetBoundaryAndFreeSurface(rModelPart);
532  // //swap conditions for a temporary use
533  // unsigned int ConditionId=1;
534  // ModelPart::ConditionsContainerType TemporaryConditions;
535 
536  // //if there are no conditions check main modelpart mesh conditions
537  // if( !rModelPart.Conditions().size() ){
538 
539  // for(ModelPart::ConditionsContainerType::iterator i_cond = rModelPart.GetParentModelPart().ConditionsBegin(); i_cond!= rModelPart.GetParentModelPart().ConditionsEnd(); ++i_cond)
540  // {
541  // TemporaryConditions.push_back(*(i_cond.base()));
542  // i_cond->SetId(ConditionId);
543  // ConditionId++;
544  // }
545 
546  // }
547  // else{
548 
549  // TemporaryConditions.reserve(rModelPart.Conditions().size());
550  // TemporaryConditions.swap(rModelPart.Conditions());
551 
552  // //set consecutive ids in the mesh conditions
553  // if( any_node_to_erase ){
554  // for(ModelPart::ConditionsContainerType::iterator i_cond = TemporaryConditions.begin(); i_cond!= TemporaryConditions.end(); ++i_cond)
555  // {
556  // Geometry< Node >& rConditionGeometry = i_cond->GetGeometry();
557  // for( unsigned int i=0; i<rConditionGeometry.size(); i++ )
558  // {
559  // if( rConditionGeometry[i].Is(TO_ERASE)){
560  // i_cond->Set(TO_ERASE);
561  // break;
562  // }
563  // }
564 
565  // i_cond->SetId(ConditionId);
566  // ConditionId++;
567  // }
568  // }
569  // else{
570  // for(ModelPart::ConditionsContainerType::iterator i_cond = TemporaryConditions.begin(); i_cond!= TemporaryConditions.end(); ++i_cond)
571  // {
572 
573  // i_cond->SetId(ConditionId);
574  // ConditionId++;
575  // }
576  // }
577 
578  // }
579 
580  // //control the previous mesh conditions
581  // std::vector<int> PreservedConditions( TemporaryConditions.size() + 1 );
582  // std::fill( PreservedConditions.begin(), PreservedConditions.end(), 0 );
583 
584  // //build new skin for the Modelpart
585  // this->BuildCompositeConditions(rModelPart, TemporaryConditions, PreservedConditions, ConditionId);
586 
587  // //add other conditions out of the skin space dimension
588  // this->AddOtherConditions(rModelPart, TemporaryConditions, PreservedConditions, ConditionId);
589 
590  return true;
591 
592  KRATOS_CATCH("")
593  }
594 
595  //**************************************************************************
596  //**************************************************************************
597 
598  virtual bool SetBoundaryAndFreeSurface(ModelPart &rModelPart)
599  {
600 
601  KRATOS_TRY
602 
603  // properties to be used in the generation
604  int number_properties = rModelPart.GetParentModelPart().NumberOfProperties();
605  Properties::Pointer properties = rModelPart.GetParentModelPart().pGetProperties(number_properties - 1);
606 
607  ModelPart::ElementsContainerType::iterator elements_begin = rModelPart.ElementsBegin();
608  ModelPart::ElementsContainerType::iterator elements_end = rModelPart.ElementsEnd();
609 
610  for (ModelPart::ElementsContainerType::iterator ie = elements_begin; ie != elements_end; ie++)
611  {
612  Geometry<Node> &rElementGeometry = ie->GetGeometry();
613 
614  if (rElementGeometry.FacesNumber() >= 3)
615  { // 3 or 4
616 
617  //********************************************************************
618  /*each face is opposite to the corresponding node number so in 2D triangle
619  0 ----- 1 2
620  1 ----- 2 0
621  2 ----- 0 1
622  */
623 
624  /*each face is opposite to the corresponding node number so in 3D tetrahedron
625  0 ----- 1 2 3
626  1 ----- 2 0 3
627  2 ----- 0 1 3
628  3 ----- 0 2 1
629  */
630  //********************************************************************
631 
632  // finding boundaries and creating the "skin"
633  boost::numeric::ublas::matrix<unsigned int> lpofa; // connectivities of points defining faces
634  boost::numeric::ublas::vector<unsigned int> lnofa; // number of points defining faces
635 
636  ElementWeakPtrVectorType &rE = ie->GetValue(NEIGHBOUR_ELEMENTS);
637 
638  // get matrix nodes in faces
639  rElementGeometry.NodesInFaces(lpofa);
640  rElementGeometry.NumberNodesInFaces(lnofa);
641 
642  // loop on neighbour elements of an element
643  unsigned int iface = 0;
644  for (ElementWeakPtrVectorType::iterator ne = rE.begin(); ne != rE.end(); ne++)
645  {
646  unsigned int NumberNodesInFace = lnofa[iface];
647 
648  if ((ne)->Id() == ie->Id())
649  {
650  // if no neighbour is present => the face is free surface
651  bool freeSurfaceFace = false;
652  for (unsigned int j = 1; j <= NumberNodesInFace; j++)
653  {
654  rElementGeometry[lpofa(j, iface)].Set(BOUNDARY);
655  if (rElementGeometry[lpofa(j, iface)].IsNot(RIGID))
656  {
657  freeSurfaceFace = true;
658  }
659  }
660  if (freeSurfaceFace == true)
661  {
662  for (unsigned int j = 1; j <= NumberNodesInFace; j++)
663  {
664  rElementGeometry[lpofa(j, iface)].Set(FREE_SURFACE);
665  }
666  }
667 
668  } // end face condition
669 
670  iface += 1;
671  } // end loop neighbours
672  }
673  }
674 
675  return true;
676 
677  KRATOS_CATCH("")
678  }
679 
680  virtual bool BuildCompositeConditions(ModelPart &rModelPart, ModelPart::ConditionsContainerType &rTemporaryConditions, std::vector<int> &rPreservedConditions, unsigned int &rConditionId)
681  {
682 
683  KRATOS_TRY
684 
685  // master conditions must be deleted and set them again in the build
686  this->ClearMasterEntities(rModelPart, rTemporaryConditions);
687 
688  // properties to be used in the generation
689  int number_properties = rModelPart.GetParentModelPart().NumberOfProperties();
690  Properties::Pointer properties = rModelPart.GetParentModelPart().pGetProperties(number_properties - 1);
691 
692  ModelPart::ElementsContainerType::iterator elements_begin = rModelPart.ElementsBegin();
693  ModelPart::ElementsContainerType::iterator elements_end = rModelPart.ElementsEnd();
694 
695  // clear nodal boundary flag
696  for (ModelPart::ElementsContainerType::iterator ie = elements_begin; ie != elements_end; ++ie)
697  {
698  Geometry<Node> &rElementGeometry = ie->GetGeometry();
699 
700  for (unsigned int j = 0; j < rElementGeometry.size(); ++j)
701  {
702  rElementGeometry[j].Reset(BOUNDARY);
703  }
704  }
705 
706  rConditionId = 0;
707  for (ModelPart::ElementsContainerType::iterator ie = elements_begin; ie != elements_end; ++ie)
708  {
709  Geometry<Node> &rElementGeometry = ie->GetGeometry();
710 
711  const unsigned int dimension = rElementGeometry.WorkingSpaceDimension();
712 
713  if (rElementGeometry.FacesNumber() >= (dimension + 1))
714  { // 3 or 4
715 
716  //********************************************************************
717  /*each face is opposite to the corresponding node number so in 2D triangle
718  0 ----- 1 2
719  1 ----- 2 0
720  2 ----- 0 1
721  */
722 
723  /*each face is opposite to the corresponding node number so in 3D tetrahedron
724  0 ----- 1 2 3
725  1 ----- 2 0 3
726  2 ----- 0 1 3
727  3 ----- 0 2 1
728  */
729  //********************************************************************
730 
731  // finding boundaries and creating the "skin"
732  DenseMatrix<unsigned int> lpofa; // connectivities of points defining faces
733  DenseVector<unsigned int> lnofa; // number of points defining faces
734 
735  ElementWeakPtrVectorType &rE = ie->GetValue(NEIGHBOUR_ELEMENTS);
736 
737  // get matrix nodes in faces
738  rElementGeometry.NodesInFaces(lpofa);
739  rElementGeometry.NumberNodesInFaces(lnofa);
740 
741  // loop on neighbour elements of an element
742  unsigned int iface = 0;
743  for (ElementWeakPtrVectorType::iterator ne = rE.begin(); ne != rE.end(); ++ne)
744  {
745  unsigned int NumberNodesInFace = lnofa[iface];
746 
747  if ((ne)->Id() == ie->Id())
748  {
749  // if no neighbour is present => the face is free surface
750  for (unsigned int j = 1; j <= NumberNodesInFace; ++j)
751  {
752  rElementGeometry[lpofa(j, iface)].Set(BOUNDARY);
753  // std::cout<<" node ["<<j<<"]"<<rElementGeometry[lpofa(j,iface)].Id()<<std::endl;
754  }
755 
756  // 1.- create geometry: points array and geometry type
757  Condition::NodesArrayType FaceNodes;
758  Condition::GeometryType::Pointer ConditionVertices;
759 
760  FaceNodes.reserve(NumberNodesInFace);
761 
762  for (unsigned int j = 1; j <= NumberNodesInFace; ++j)
763  {
764  FaceNodes.push_back(rElementGeometry(lpofa(j, iface)));
765  }
766 
767  if (NumberNodesInFace == 2)
768  {
769  if (dimension == 2)
770  ConditionVertices = Kratos::make_shared<Line2D2<Node>>(FaceNodes);
771  else
772  ConditionVertices = Kratos::make_shared<Line3D2<Node>>(FaceNodes);
773  }
774  else if (NumberNodesInFace == 3)
775  {
776  if (dimension == 2)
777  ConditionVertices = Kratos::make_shared<Line2D3<Node>>(FaceNodes);
778  else
779  ConditionVertices = Kratos::make_shared<Triangle3D3<Node>>(FaceNodes);
780  }
781 
782  rConditionId += 1;
783 
784  // Create a composite condition
785  CompositeCondition::Pointer p_cond = Kratos::make_intrusive<CompositeCondition>(rConditionId, ConditionVertices, properties);
786 
787  bool condition_found = false;
788  bool point_condition = false;
789 
790  // Search for existing conditions: start
791  for (ModelPart::ConditionsContainerType::iterator i_cond = rTemporaryConditions.begin(); i_cond != rTemporaryConditions.end(); ++i_cond)
792  {
793  Geometry<Node> &rConditionGeometry = i_cond->GetGeometry();
794 
795  MesherUtilities MesherUtils;
796  condition_found = MesherUtils.FindCondition(rConditionGeometry, rElementGeometry, lpofa, lnofa, iface);
797 
798  if (condition_found)
799  {
800 
801  p_cond->AddChild(*(i_cond.base()));
802 
803  rPreservedConditions[i_cond->Id()] += 1;
804 
805  if (rConditionGeometry.PointsNumber() == 1)
806  point_condition = true;
807  }
808  }
809  // Search for existing conditions: end
810 
811  if (!point_condition)
812  {
813  // usually one MasterElement and one MasterNode for 2D and 3D simplex
814  // can be more than one in other geometries -> it has to be extended to that cases
815 
816  // std::cout<<" ID "<<p_cond->Id()<<" MASTER ELEMENT "<<ie->Id()<<std::endl;
817  // std::cout<<" MASTER NODE "<<rElementGeometry[lpofa(0,iface)].Id()<<" or "<<rElementGeometry[lpofa(NumberNodesInFace,iface)].Id()<<std::endl;
818 
819  ElementWeakPtrVectorType &MasterElements = p_cond->GetValue(MASTER_ELEMENTS);
820  MasterElements.push_back((*(ie.base())));
821  p_cond->SetValue(MASTER_ELEMENTS, MasterElements);
822 
823  NodeWeakPtrVectorType &MasterNodes = p_cond->GetValue(MASTER_NODES);
824  MasterNodes.push_back(rElementGeometry(lpofa(0, iface)));
825  p_cond->SetValue(MASTER_NODES, MasterNodes);
826  }
827 
828  rModelPart.Conditions().push_back(Condition::Pointer(p_cond));
829  // Set new conditions: end
830 
831  } // end face condition
832 
833  iface += 1;
834  } // end loop neighbours
835  }
836  else
837  {
838  // set nodes to BOUNDARY for elements outside of the working space dimension
839  for (unsigned int j = 0; j < rElementGeometry.size(); ++j)
840  {
841  rElementGeometry[j].Set(BOUNDARY);
842  }
843  }
844  }
845 
846  return true;
847 
848  KRATOS_CATCH("")
849  }
850 
851  //**************************************************************************
852  //**************************************************************************
853 
854  bool FindConditionID(ModelPart &rModelPart, Geometry<Node> &rConditionGeometry)
855  {
856  KRATOS_TRY
857 
858  // check if the condition exists and belongs to the modelpart checking node Ids
859  for (unsigned int i = 0; i < rConditionGeometry.size(); ++i)
860  {
861  for (ModelPart::NodesContainerType::const_iterator in = rModelPart.NodesBegin(); in != rModelPart.NodesEnd(); ++in)
862  {
863  if (rConditionGeometry[i].Id() == in->Id())
864  return true;
865  }
866  }
867 
868  return false;
869 
870  KRATOS_CATCH("")
871  }
872 
873  //**************************************************************************
874  //**************************************************************************
875 
876  void PrintSkin(ModelPart &rModelPart)
877  {
878 
879  KRATOS_TRY
880 
881  // PRINT SKIN:
882  std::cout << " CONDITIONS: geometry nodes (" << rModelPart.Conditions().size() << ")" << std::endl;
883 
884  ConditionsContainerType &rCond = rModelPart.Conditions();
885  for (ConditionsContainerType::iterator i_cond = rCond.begin(); i_cond != rCond.end(); ++i_cond)
886  {
887 
888  Geometry<Node> &rConditionGeometry = i_cond->GetGeometry();
889  std::cout << "[" << i_cond->Id() << "]:" << std::endl;
890  // i_cond->PrintInfo(std::cout);
891  std::cout << "( ";
892  for (unsigned int i = 0; i < rConditionGeometry.size(); ++i)
893  {
894  std::cout << rConditionGeometry[i].Id() << ", ";
895  }
896  std::cout << " ): ";
897 
898  i_cond->GetValue(MASTER_ELEMENTS)[0].PrintInfo(std::cout);
899 
900  std::cout << std::endl;
901  }
902  std::cout << std::endl;
903 
904  KRATOS_CATCH("")
905  }
906 
907  //**************************************************************************
908  //**************************************************************************
909 
910  bool AddOtherConditions(ModelPart &rModelPart, ModelPart::ConditionsContainerType &rTemporaryConditions, std::vector<int> &rPreservedConditions, unsigned int &rConditionId)
911  {
912 
913  KRATOS_TRY
914 
915  unsigned int counter = 0;
916 
917  // add all previous conditions not found in the skin search:
918  for (ModelPart::ConditionsContainerType::iterator i_cond = rTemporaryConditions.begin(); i_cond != rTemporaryConditions.end(); ++i_cond)
919  {
920 
921  if (rPreservedConditions[i_cond->Id()] == 0)
922  { // I have not used the condition and any node of the condition
923 
924  if (this->CheckAcceptedCondition(rModelPart, *i_cond))
925  {
926 
927  Geometry<Node> &rConditionGeometry = i_cond->GetGeometry();
928 
929  Condition::NodesArrayType FaceNodes;
930 
931  FaceNodes.reserve(rConditionGeometry.size());
932 
933  for (unsigned int j = 0; j < rConditionGeometry.size(); ++j)
934  {
935  FaceNodes.push_back(rConditionGeometry(j));
936  }
937 
938  rPreservedConditions[i_cond->Id()] += 1;
939 
940  rConditionId += 1;
941 
942  Condition::Pointer p_cond = i_cond->Clone(rConditionId, FaceNodes);
943  // p_cond->Data() = i_cond->Data();
944 
945  this->AddConditionToModelPart(rModelPart, p_cond);
946 
947  counter++;
948  }
949  }
950  }
951 
952  // std::cout<<" recovered conditions "<<counter<<std::endl;
953 
954  // control if all previous conditions have been added:
955  bool all_assigned = true;
956  unsigned int lost_conditions = 0;
957  for (unsigned int i = 1; i < rPreservedConditions.size(); ++i)
958  {
959  if (rPreservedConditions[i] == 0)
960  {
961  all_assigned = false;
962  lost_conditions++;
963  }
964  }
965 
966  if (mEchoLevel >= 1)
967  {
968 
969  std::cout << " Final Conditions : " << rModelPart.NumberOfConditions() << std::endl;
970 
971  if (all_assigned == true)
972  std::cout << " ALL_PREVIOUS_CONDITIONS_RELOCATED " << std::endl;
973  else
974  std::cout << " SOME_PREVIOUS_CONDITIONS_ARE_LOST [lost_conditions:" << lost_conditions << "]" << std::endl;
975  }
976 
977  return all_assigned;
978 
979  KRATOS_CATCH("")
980  }
981 
982  //**************************************************************************
983  //**************************************************************************
984 
985  virtual bool CheckAcceptedCondition(ModelPart &rModelPart, Condition &rCondition)
986  {
987  KRATOS_TRY
988 
989  Geometry<Node> &rConditionGeometry = rCondition.GetGeometry();
990 
991  return FindConditionID(rModelPart, rConditionGeometry);
992 
993  KRATOS_CATCH("")
994  }
995 
996  //**************************************************************************
997  //**************************************************************************
998 
999  virtual void AddConditionToModelPart(ModelPart &rModelPart, Condition::Pointer pCondition)
1000  {
1001  KRATOS_TRY
1002 
1003  rModelPart.AddCondition(pCondition);
1004  // rModelPart.Conditions().push_back(pCondition);
1005 
1006  KRATOS_CATCH("")
1007  }
1008 
1012 
1016 
1020 
1022 
1023  private:
1026 
1030 
1034 
1038 
1039  //**************************************************************************
1040  //**************************************************************************
1041 
1042  void SetComputingModelPart()
1043  {
1044 
1045  KRATOS_TRY
1046 
1047  std::string ComputingModelPartName;
1049  {
1050  if (i_mp->Is(ACTIVE))
1051  ComputingModelPartName = i_mp->Name();
1052  }
1053 
1054  ModelPart &rModelPart = mrModelPart.GetSubModelPart(ComputingModelPartName);
1055 
1056  if (mEchoLevel >= 1)
1057  {
1058  std::cout << " [" << ComputingModelPartName << " :: CONDITIONS [OLD:" << rModelPart.NumberOfConditions();
1059  }
1060 
1061  ModelPart::ConditionsContainerType KeepConditions;
1062 
1064  {
1065 
1066  if (i_mp->NumberOfElements() && ComputingModelPartName != i_mp->Name())
1067  { // conditions of model_parts with elements only
1068 
1069  for (ModelPart::ConditionsContainerType::iterator i_cond = i_mp->ConditionsBegin(); i_cond != i_mp->ConditionsEnd(); ++i_cond)
1070  {
1071  // i_cond->PrintInfo(std::cout);
1072  // std::cout<<" -- "<<std::endl;
1073 
1074  KeepConditions.push_back(*(i_cond.base()));
1075 
1076  // KeepConditions.back().PrintInfo(std::cout);
1077  // std::cout<<std::endl;
1078  }
1079  }
1080  }
1081 
1082  rModelPart.Conditions().swap(KeepConditions);
1083 
1084  if (mEchoLevel >= 1)
1085  {
1086  std::cout << " / NEW:" << rModelPart.NumberOfConditions() << "] " << std::endl;
1087  }
1088 
1089  KRATOS_CATCH("")
1090  }
1091 
1092  //**************************************************************************
1093  //**************************************************************************
1094 
1095  void SetMainModelPartConditions()
1096  {
1097 
1098  KRATOS_TRY
1099 
1100  if (mEchoLevel >= 1)
1101  {
1102  std::cout << " [" << mrModelPart.Name() << " :: CONDITIONS [OLD:" << mrModelPart.NumberOfConditions();
1103  }
1104 
1105  // contact conditions are located on Mesh_0
1106  ModelPart::ConditionsContainerType KeepConditions;
1107 
1108  unsigned int condId = 1;
1109  if (mModelPartName == mrModelPart.Name())
1110  {
1111 
1113  {
1114  if (!(i_mp->Is(ACTIVE)) && !(i_mp->Is(CONTACT)))
1115  {
1116  // std::cout<<" ModelPartName "<<i_mp->Name()<<" conditions "<<i_mp->NumberOfConditions()<<std::endl;
1117  for (ModelPart::ConditionsContainerType::iterator i_cond = i_mp->ConditionsBegin(); i_cond != i_mp->ConditionsEnd(); ++i_cond)
1118  {
1119  // i_cond->PrintInfo(std::cout);
1120  // std::cout<<" -- "<<std::endl;
1121 
1122  KeepConditions.push_back(*(i_cond.base()));
1123  KeepConditions.back().SetId(condId);
1124  condId += 1;
1125 
1126  // KeepConditions.back().PrintInfo(std::cout);
1127  // std::cout<<std::endl;
1128  }
1129  }
1130  }
1131  }
1132 
1133  for (ModelPart::ConditionsContainerType::iterator i_cond = mrModelPart.ConditionsBegin(); i_cond != mrModelPart.ConditionsEnd(); ++i_cond)
1134  {
1135  if (i_cond->Is(CONTACT))
1136  {
1137  KeepConditions.push_back(*(i_cond.base()));
1138  KeepConditions.back().SetId(condId);
1139  condId += 1;
1140 
1141  // std::cout<<" -- "<<std::endl;
1142  // KeepConditions.back().PrintInfo(std::cout);
1143  // std::cout<<std::endl;
1144  }
1145  }
1146 
1147  mrModelPart.Conditions().swap(KeepConditions);
1148 
1149  if (mEchoLevel >= 1)
1150  {
1151  std::cout << " / NEW:" << mrModelPart.NumberOfConditions() << "] " << std::endl;
1152  }
1153 
1154  KRATOS_CATCH("")
1155  }
1156 
1157  void ResetNodesBoundaryFlag(ModelPart &rModelPart)
1158  {
1159  // reset the boundary flag in all nodes
1160  for (ModelPart::NodesContainerType::const_iterator in = rModelPart.NodesBegin(); in != rModelPart.NodesEnd(); ++in)
1161  {
1162  in->Reset(BOUNDARY);
1163  }
1164  }
1165 
1169 
1173 
1177 
1180 
1182  // BuildModelPartBoundaryForFluidsProcess(BuildModelPartBoundaryForFluidsProcess const& rOther);
1183 
1185 
1186  }; // Class BuildModelPartBoundaryForFluidsProcess
1187 
1189 
1192 
1196 
1198  inline std::istream &operator>>(std::istream &rIStream,
1200 
1202  inline std::ostream &operator<<(std::ostream &rOStream,
1204  {
1205  rThis.PrintInfo(rOStream);
1206  rOStream << std::endl;
1207  rThis.PrintData(rOStream);
1208 
1209  return rOStream;
1210  }
1212 
1213 } // namespace Kratos.
1214 
1215 #endif // KRATOS_BUILD_MODEL_PART_BOUNDARY_FOR_FLUIDS_PROCESS_H_INCLUDED defined
Definition: boundary_normals_calculation_utilities.hpp:48
void CalculateUnitBoundaryNormals(ModelPart &rModelPart, int EchoLevel=0)
Calculates the area normal (vector oriented as the normal with a dimension proportional to the area).
Definition: boundary_normals_calculation_utilities.hpp:83
Short class definition.
Definition: build_model_part_boundary_for_fluids_process.hpp:77
std::string Info() const override
Turn back information as a string.
Definition: build_model_part_boundary_for_fluids_process.hpp:435
virtual bool BuildCompositeConditions(ModelPart &rModelPart, ModelPart::ConditionsContainerType &rTemporaryConditions, std::vector< int > &rPreservedConditions, unsigned int &rConditionId)
Definition: build_model_part_boundary_for_fluids_process.hpp:680
virtual ~BuildModelPartBoundaryForFluidsProcess()
Destructor.
Definition: build_model_part_boundary_for_fluids_process.hpp:100
ModelPart & mrModelPart
Definition: build_model_part_boundary_for_fluids_process.hpp:465
BuildModelPartBoundaryForFluidsProcess(ModelPart &rModelPart, std::string const rModelPartName, int EchoLevel=0)
Default constructor.
Definition: build_model_part_boundary_for_fluids_process.hpp:90
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: build_model_part_boundary_for_fluids_process.hpp:447
void PrintSkin(ModelPart &rModelPart)
Definition: build_model_part_boundary_for_fluids_process.hpp:876
virtual void AddConditionToModelPart(ModelPart &rModelPart, Condition::Pointer pCondition)
Definition: build_model_part_boundary_for_fluids_process.hpp:999
std::string mModelPartName
Definition: build_model_part_boundary_for_fluids_process.hpp:467
bool AddOtherConditions(ModelPart &rModelPart, ModelPart::ConditionsContainerType &rTemporaryConditions, std::vector< int > &rPreservedConditions, unsigned int &rConditionId)
Definition: build_model_part_boundary_for_fluids_process.hpp:910
bool SearchConditionMasters()
Definition: build_model_part_boundary_for_fluids_process.hpp:207
void operator()()
Definition: build_model_part_boundary_for_fluids_process.hpp:108
virtual bool SetBoundaryAndFreeSurface(ModelPart &rModelPart)
Definition: build_model_part_boundary_for_fluids_process.hpp:598
bool ClearMasterEntities(ModelPart &rModelPart, ModelPart::ConditionsContainerType &rTemporaryConditions)
Definition: build_model_part_boundary_for_fluids_process.hpp:482
virtual bool CheckAcceptedCondition(ModelPart &rModelPart, Condition &rCondition)
Definition: build_model_part_boundary_for_fluids_process.hpp:985
void Execute() override
Execute method is used to execute the MesherProcess algorithms.
Definition: build_model_part_boundary_for_fluids_process.hpp:117
bool FindConditionID(ModelPart &rModelPart, Geometry< Node > &rConditionGeometry)
Definition: build_model_part_boundary_for_fluids_process.hpp:854
bool UniqueSkinSearch(ModelPart &rModelPart)
Definition: build_model_part_boundary_for_fluids_process.hpp:503
int mEchoLevel
Definition: build_model_part_boundary_for_fluids_process.hpp:469
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: build_model_part_boundary_for_fluids_process.hpp:441
KRATOS_CLASS_POINTER_DEFINITION(BuildModelPartBoundaryForFluidsProcess)
Pointer definition of BuildModelPartBoundaryForFluidsProcess.
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 PointsNumber() const
Definition: geometry.h:528
SizeType size() const
Definition: geometry.h:518
IndexType const & Id() const
Id of this Geometry.
Definition: geometry.h:964
virtual void NodesInFaces(DenseMatrix< unsigned int > &rNodesInFaces) const
Definition: geometry.h:2195
virtual void NumberNodesInFaces(DenseVector< unsigned int > &rNumberNodesInFaces) const
Definition: geometry.h:2190
TVariableType::Type & GetValue(const TVariableType &rThisVariable)
Definition: geometry.h:627
virtual SizeType FacesNumber() const
Returns the number of faces of the current geometry.
Definition: geometry.h:2152
SizeType WorkingSpaceDimension() const
Definition: geometry.h:1287
boost::indirect_iterator< typename TContainerType::iterator > iterator
Definition: global_pointers_vector.h:79
iterator erase(iterator pos)
Definition: global_pointers_vector.h:351
void push_back(TPointerType x)
Definition: global_pointers_vector.h:322
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
Definition: amatrix_interface.h:41
The base class for processes passed to the solution scheme.
Definition: mesher_process.hpp:37
Short class definition.
Definition: mesher_utilities.hpp:49
bool FindCondition(Geometry< Node > &rConditionGeometry, Geometry< Node > &rGeometry, DenseMatrix< unsigned int > &lpofa, DenseVector< unsigned int > &lnofa, unsigned int &iface)
Definition: mesher_utilities.cpp:1971
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
SubModelPartIterator SubModelPartsEnd()
Definition: model_part.h:1708
PropertiesType::Pointer pGetProperties(IndexType PropertiesId, IndexType MeshIndex=0)
Returns the Properties::Pointer corresponding to it's identifier.
Definition: model_part.cpp:664
ConditionIterator ConditionsBegin(IndexType ThisIndex=0)
Definition: model_part.h:1361
SubModelPartIterator SubModelPartsBegin()
Definition: model_part.h:1698
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
SizeType NumberOfSubModelParts() const
Definition: model_part.h:1665
std::string & Name()
Definition: model_part.h:1811
NodeIterator NodesBegin(IndexType ThisIndex=0)
Definition: model_part.h:487
SubModelPartsContainerType::iterator SubModelPartIterator
Iterator over the sub model parts of this model part.
Definition: model_part.h:258
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
void AddCondition(ConditionType::Pointer pNewCondition, IndexType ThisIndex=0)
Definition: model_part.cpp:1436
SizeType NumberOfConditions(IndexType ThisIndex=0) const
Definition: model_part.h:1218
ElementIterator ElementsEnd(IndexType ThisIndex=0)
Definition: model_part.h:1179
ModelPart & GetSubModelPart(std::string const &SubModelPartName)
Definition: model_part.cpp:2029
NodeIterator NodesEnd(IndexType ThisIndex=0)
Definition: model_part.h:497
ModelPart & GetParentModelPart()
Definition: model_part.cpp:2124
ConditionIterator ConditionsEnd(IndexType ThisIndex=0)
Definition: model_part.h:1371
PointerVector is a container like stl vector but using a vector to store pointers to its data.
Definition: pointer_vector.h:72
void reserve(size_type dim)
Definition: pointer_vector.h:319
void push_back(const TPointerType &x)
Definition: pointer_vector.h:270
void push_back(TPointerType x)
Adds a pointer to the end of the set.
Definition: pointer_vector_set.h:544
#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
int counter
Definition: script_THERMAL_CORRECT.py:218
integer i
Definition: TensorModule.f:17
Definition: mesh_converter.cpp:38