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.
model_start_end_meshing_for_fluids_process.hpp
Go to the documentation of this file.
1 //
2 // Project Name: KratosPfemFluidApplication $
3 // Created by: $Author: JMCarbonell $
4 // Last modified by: $Co-Author: $
5 // Date: $Date: February 2016 $
6 // Revision: $Revision: 0.0 $
7 //
8 //
9 
10 #if !defined(KRATOS_MODEL_START_END_MESHING_FOR_FLUIDS_PROCESS_H_INCLUDED)
11 #define KRATOS_MODEL_START_END_MESHING_FOR_FLUIDS_PROCESS_H_INCLUDED
12 
13 // System includes
14 
15 // External includes
16 
17 // Project includes
19 
21 //Data:
22 //StepData:
23 //Flags: (checked)
24 // (set)
25 // (modified)
26 // (reset)
27 
28 namespace Kratos
29 {
30 
33 
42 
43  typedef PointerVectorSet<ConditionType, IndexedObject> ConditionsContainerType;
44  typedef ConditionsContainerType::iterator ConditionIterator;
45  typedef ConditionsContainerType::const_iterator ConditionConstantIterator;
46 
50 
54 
58 
60 
64  {
65  public:
68 
71 
75 
78  Flags Options,
79  int EchoLevel = 0)
80  : SettleModelStructureProcess(rMainModelPart, Options, EchoLevel)
81  {
82  }
83 
86  {
87  }
88 
89  void operator()()
90  {
91  Execute();
92  }
93 
97 
98  void Execute() override{
99 
100  };
101 
105 
109 
113 
117 
119  std::string Info() const override
120  {
121  return "ModelStartEndMeshingForFluidsProcess";
122  }
123 
125  void PrintInfo(std::ostream &rOStream) const override
126  {
127  rOStream << "ModelStartEndMeshingForFluidsProcess";
128  }
129 
130  protected:
133 
137 
138  //*******************************************************************************************
139  //*******************************************************************************************
140 
141  void BuildTotalModelPart(ModelPart &rModelPart, int EchoLevel) override
142  {
143 
144  KRATOS_TRY
145 
146  //Mesh Id=0
147 
148  if (EchoLevel > 1)
149  std::cout << " [ START MODEL PART [" << rModelPart.Name() << "] [Elems=:" << rModelPart.NumberOfElements() << "|Nodes=" << rModelPart.NumberOfNodes() << "|Conds=" << rModelPart.NumberOfConditions() << "] ] " << std::endl;
150 
151  rModelPart.Nodes().clear();
152  rModelPart.Elements().clear();
153 
154  //contact conditions are located on Mesh_0
155  // ModelPart::ConditionsContainerType PreservedConditions;
156 
157  unsigned int nodeId = 1;
158  unsigned int elemId = 1;
159  // unsigned int condId=1;
160 
161  for (ModelPart::SubModelPartIterator i_mp = rModelPart.SubModelPartsBegin(); i_mp != rModelPart.SubModelPartsEnd(); i_mp++)
162  {
163  // if( (i_mp->Is(SOLID) && i_mp->IsNot(ACTIVE)) || (i_mp->Is(BOUNDARY) && i_mp->Is(RIGID)) ){ //only the solid domains (no computing) and the rigid body domains (rigid)
164  if ((i_mp->Is(SOLID) && i_mp->IsNot(ACTIVE)) || (i_mp->Is(FLUID) && i_mp->IsNot(ACTIVE)) || (i_mp->Is(BOUNDARY) && i_mp->Is(RIGID)))
165  { //only the solid domains (no computing) and the rigid body domains (rigid)
166 
167  if (EchoLevel > 1)
168  std::cout << " [ SUBMODEL PART [" << i_mp->Name() << "] [Elems=" << i_mp->NumberOfElements() << "|Nodes=" << i_mp->NumberOfNodes() << "|Conds=" << i_mp->NumberOfConditions() << "] ] " << std::endl;
169 
170  //Clean Nodes when redefining the main model part:
171  const array_1d<double, 3> ZeroNormal(3, 0.0);
172  ModelPart::NodesContainerType temporal_nodes;
173  temporal_nodes.reserve(i_mp->Nodes().size());
174  temporal_nodes.swap(i_mp->Nodes());
175 
176  if (!i_mp->NumberOfElements())
177  {
178  for (ModelPart::NodesContainerType::iterator i_node = temporal_nodes.begin(); i_node != temporal_nodes.end(); i_node++)
179  {
180  if (i_node->IsNot(TO_ERASE))
181  {
182  (i_mp->Nodes()).push_back(*(i_node.base()));
183  (rModelPart.Nodes()).push_back(*(i_node.base()));
184  rModelPart.Nodes().back().SetId(nodeId);
185  nodeId += 1;
186  }
187  }
188  }
189  else
190  {
191 
192  for (ModelPart::ElementsContainerType::iterator i_elem = i_mp->ElementsBegin(); i_elem != i_mp->ElementsEnd(); i_elem++)
193  {
194  if (i_elem->IsNot(TO_ERASE))
195  {
196 
197  PointsArrayType &vertices = i_elem->GetGeometry().Points();
198  for (unsigned int i = 0; i < vertices.size(); i++)
199  {
200  vertices[i].Set(BLOCKED);
201  if (i_mp->Is(FLUID))
202  {
203  vertices[i].Set(FLUID);
204  }
205  }
206  i_elem->SetId(elemId);
207  (rModelPart.Elements()).push_back(*(i_elem.base()));
208  rModelPart.Elements().back().SetId(elemId);
209  elemId += 1;
210  }
211  }
212 
213  for (ModelPart::NodesContainerType::iterator i_node = temporal_nodes.begin(); i_node != temporal_nodes.end(); i_node++)
214  {
215  //i_node->PrintInfo(std::cout);
216  //std::cout<<std::endl;
217 
218  if (i_node->Is(BLOCKED) || i_node->Is(RIGID))
219  {
220  if (i_node->Is(RIGID) && i_node->IsNot(BLOCKED))
221  {
222  // double pressureRigid=i_node->FastGetSolutionStepValue(PRESSURE);
223  i_node->FastGetSolutionStepValue(PRESSURE) = 0;
224  if (i_mp->Is(FLUID))
225  {
226  i_node->Reset(FLUID); //reset isolated
227  }
228  // std::cout<<" fluid 1. SET PRESSURE 0 TO ISOLATED NODE ("<<nodeId<<") its pressure was "<<pressureRigid<<std::endl;
229  }
230  i_node->Reset(ISOLATED); //reset isolated
231  i_node->Reset(NEW_ENTITY); //reset if was new
232  i_node->Reset(TO_REFINE); //reset if was labeled to refine (to not duplicate boundary conditions)
233  i_node->Reset(BLOCKED);
234 
235  if (i_node->IsNot(TO_ERASE))
236  {
237 
238  (i_mp->Nodes()).push_back(*(i_node.base()));
239  (rModelPart.Nodes()).push_back(*(i_node.base()));
240  rModelPart.Nodes().back().SetId(nodeId);
241  nodeId += 1;
242  }
243  }
244  else
245  {
246 
247  i_node->Set(ISOLATED);
248  i_node->Reset(BOUNDARY);
249  i_node->Reset(NEW_ENTITY); //reset if was new
250  i_node->Reset(TO_REFINE); //reset if was labeled to refine (to not duplicate boundary conditions)
251  i_node->Reset(BLOCKED);
252 
253  if (mOptions.Is(MesherUtilities::KEEP_ISOLATED_NODES) && i_node->IsNot(TO_ERASE))
254  {
255  i_node->FastGetSolutionStepValue(PRESSURE) = 0;
256  (i_mp->Nodes()).push_back(*(i_node.base()));
257  (rModelPart.Nodes()).push_back(*(i_node.base()));
258  rModelPart.Nodes().back().SetId(nodeId);
259  nodeId += 1;
260  }
261  }
262 
263  }
264  }
265 
266  // for(ModelPart::ConditionsContainerType::iterator i_cond = i_mp->ConditionsBegin() ; i_cond != i_mp->ConditionsEnd() ; i_cond++)
267  // {
268  // if( i_cond->IsNot(TO_ERASE) ){
269  // i_cond->Reset(NEW_ENTITY); //reset here if the condition is inserted
270  // PreservedConditions.push_back(*(i_cond.base()));
271  // PreservedConditions.back().SetId(condId);
272  // condId+=1;
273 
274  // Geometry< Node >& rGeometry = i_cond->GetGeometry();
275  // unsigned int NumNodes=rGeometry.size();
276  // unsigned int freeSurfaceNodes=0;
277  // unsigned int rigidNodes=0;
278  // for (unsigned int n = 0; n < NumNodes; ++n)
279  // {
280 
281  // if(rGeometry[n].Is(RIGID) || rGeometry[n].Is(SOLID)){
282  // // std::cout<<"rigid node! "<<rGeometry[n].X()<<" "<<rGeometry[n].Y()<<std::endl;
283  // rigidNodes++;
284  // }else {
285  // freeSurfaceNodes++;
286  // }
287  // }
288  // if((freeSurfaceNodes>0 && rigidNodes>0) || rigidNodes==0){
289  // for (unsigned int n = 0; n < NumNodes; ++n)
290  // {
291  // rGeometry[n].Set(FREE_SURFACE);
292  // }
293  // }
294 
295  // }
296  // }
297  }
298 
299  else
300  {
301  // Skipping the Computing Model Part
302  if (!((i_mp->Is(ACTIVE) && i_mp->Is(SOLID)) || (i_mp->Is(ACTIVE) && i_mp->Is(FLUID))))
303  {
304  if (i_mp->NumberOfElements())
305  {
306  // Adding the remaining elements to the Main Mode Part
307  for (ModelPart::ElementsContainerType::iterator i_elem = i_mp->ElementsBegin(); i_elem != i_mp->ElementsEnd(); i_elem++)
308  {
309  i_elem->SetId(elemId);
310  (rModelPart.Elements()).push_back(*(i_elem.base()));
311  rModelPart.Elements().back().SetId(elemId);
312  elemId += 1;
313  }
314  }
315  }
316  }
317  }
318 
319  // this->BuildBoundaryModelParts(rModelPart,PreservedConditions, nodeId, elemId, condId);
320 
321  // for(ModelPart::SubModelPartIterator i_mp= rModelPart.SubModelPartsBegin() ; i_mp!=rModelPart.SubModelPartsEnd(); i_mp++)
322  // {
323  // if( i_mp->Is(BOUNDARY) ){ //boundary model part
324 
325  // for(ModelPart::ConditionsContainerType::iterator i_cond = i_mp->ConditionsBegin() ; i_cond != i_mp->ConditionsEnd() ; i_cond++)
326  // {
327  // if( i_cond->IsNot(TO_ERASE) ){
328  // i_cond->Reset(NEW_ENTITY); //reset here if the condition is inserted
329  // PreservedConditions.push_back(*(i_cond.base()));
330  // PreservedConditions.back().SetId(condId);
331  // condId+=1;
332  // }
333  // }
334  // }
335 
336  // }
337 
338  // for(ModelPart::ConditionsContainerType::iterator i_cond = rModelPart.ConditionsBegin(); i_cond!= rModelPart.ConditionsEnd(); i_cond++)
339  // {
340  // if(i_cond->Is(CONTACT)){
341  // PreservedConditions.push_back(*(i_cond.base()));
342  // PreservedConditions.back().SetId(condId);
343  // condId+=1;
344  // }
345  // }
346 
347  // rModelPart.Conditions().swap(PreservedConditions);
348 
349  // Unique (it includes sort())
350  rModelPart.Nodes().Unique();
351  rModelPart.Elements().Unique();
352  // rModelPart.Conditions().Unique();
353 
354  // Sort Again to have coherent numeration for nodes (mesh with shared nodes)
355  unsigned int consecutive_index = 1;
356  for (ModelPart::NodesContainerType::iterator in = rModelPart.NodesBegin(); in != rModelPart.NodesEnd(); in++)
357  in->SetId(consecutive_index++);
358 
359  this->BuildComputingDomain(rModelPart, EchoLevel);
360 
361  if (EchoLevel > 1)
362  std::cout << " [ END MODEL PART [" << rModelPart.Name() << "] [Elems=:" << rModelPart.NumberOfElements() << "|Nodes=" << rModelPart.NumberOfNodes() << "|Conds=" << rModelPart.NumberOfConditions() << "] ] " << std::endl;
363 
364  KRATOS_CATCH(" ")
365  }
366 
367  //*******************************************************************************************
368  //*******************************************************************************************
369 
370  void BuildComputingDomain(ModelPart &rModelPart, int EchoLevel) override
371  {
372  KRATOS_TRY
373 
374  std::string ComputingModelPartName;
375  for (ModelPart::SubModelPartIterator i_mp = rModelPart.SubModelPartsBegin(); i_mp != rModelPart.SubModelPartsEnd(); i_mp++)
376  {
377  // if( (i_mp->Is(ACTIVE) && i_mp->Is(SOLID)) ){ //solid_computing_domain
378  if ((i_mp->Is(ACTIVE) && i_mp->Is(SOLID)) || (i_mp->Is(ACTIVE) && i_mp->Is(FLUID)))
379  { // solid_computing_domain and fluid_computing_domain
380  ComputingModelPartName = i_mp->Name();
381  }
382  }
383 
384  ModelPart &rComputingModelPart = rModelPart.GetSubModelPart(ComputingModelPartName);
385 
386  rComputingModelPart.Nodes().clear();
387  rComputingModelPart.Elements().clear();
388  // rComputingModelPart.Conditions().clear();
389 
390  for (ModelPart::SubModelPartIterator i_mp = rModelPart.SubModelPartsBegin(); i_mp != rModelPart.SubModelPartsEnd(); i_mp++)
391  {
392  // if( (i_mp->Is(SOLID) && i_mp->IsNot(ACTIVE)) || (i_mp->Is(BOUNDARY) && i_mp->Is(RIGID)) ){
393  if (((i_mp->Is(ACTIVE) && i_mp->Is(SOLID)) || (i_mp->Is(BOUNDARY) && i_mp->Is(RIGID))) || (i_mp->Is(FLUID) && i_mp->IsNot(ACTIVE)))
394  {
395 
396  for (ModelPart::NodesContainerType::iterator i_node = i_mp->NodesBegin(); i_node != i_mp->NodesEnd(); i_node++)
397  {
398  rComputingModelPart.Nodes().push_back(*(i_node.base()));
399  // rComputingModelPart.AddNode(*(i_node.base())); // very slow!
400  }
401 
402  // for(ModelPart::ConditionsContainerType::iterator i_cond = i_mp->ConditionsBegin() ; i_cond != i_mp->ConditionsEnd() ; i_cond++)
403  // {
404  // rComputingModelPart.AddCondition(*(i_cond.base()));
405  // }
406 
407  for (ModelPart::ElementsContainerType::iterator i_elem = i_mp->ElementsBegin(); i_elem != i_mp->ElementsEnd(); i_elem++)
408  {
409  rComputingModelPart.AddElement(*(i_elem.base()));
410  }
411  }
412  }
413 
414  // // // Sort
415  // // rComputingModelPart.Nodes().Sort();
416  // // rComputingModelPart.Elements().Sort();
417  // // // rComputingModelPart.Conditions().Sort();
418 
419  // Unique (Sort is included)
420  rComputingModelPart.Nodes().Unique();
421  rComputingModelPart.Elements().Unique();
422  // rComputingModelPart.Conditions().Unique();
423 
424  if (EchoLevel > 1)
425  std::cout << " [ SUBMODEL PART [" << rComputingModelPart.Name() << "] [Elems=" << rComputingModelPart.NumberOfElements() << "|Nodes=" << rComputingModelPart.NumberOfNodes() << "|Conds=" << rComputingModelPart.NumberOfConditions() << "] ] " << std::endl;
426 
427  KRATOS_CATCH(" ")
428  }
429 
430  void PerformModelSearches() override
431  {
432 
433  KRATOS_TRY
434 
435  //NODAL NEIGHBOURS SEARCH
437  FindNeighbours.Execute();
438 
439  //BOUNDARY NORMALS SEARCH and SHRINKAGE FACTOR
440  BoundaryNormalsCalculationUtilities BoundaryComputation;
442 
443  KRATOS_CATCH(" ")
444  }
445 
446  //*******************************************************************************************
447  //*******************************************************************************************
448 
452 
456 
460 
462 
463  private:
466 
470 
474 
478 
482 
486 
490 
493 
495  //ModelStartEndMeshingForFluidsProcess(ModelStartEndMeshingForFluidsProcess const& rOther);
496 
498 
499  }; // Class ModelStartEndMeshingForFluidsProcess
500 
502 
505 
509 
511  inline std::istream &operator>>(std::istream &rIStream,
513 
515  inline std::ostream &operator<<(std::ostream &rOStream,
517  {
518  rThis.PrintInfo(rOStream);
519  rOStream << std::endl;
520  rThis.PrintData(rOStream);
521 
522  return rOStream;
523  }
525 
526 } // namespace Kratos.
527 
528 #endif // KRATOS_MODEL_START_END_MESHING_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
Definition: flags.h:58
bool Is(Flags const &rOther) const
Definition: flags.h:274
PointerVector< TPointType > PointsArrayType
Definition: geometry.h:118
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
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
SubModelPartIterator SubModelPartsBegin()
Definition: model_part.h:1698
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
SubModelPartsContainerType::iterator SubModelPartIterator
Iterator over the sub model parts of this model part.
Definition: model_part.h:258
SizeType NumberOfElements(IndexType ThisIndex=0) const
Definition: model_part.h:1027
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
SizeType NumberOfConditions(IndexType ThisIndex=0) const
Definition: model_part.h:1218
ModelPart & GetSubModelPart(std::string const &SubModelPartName)
Definition: model_part.cpp:2029
SizeType NumberOfNodes(IndexType ThisIndex=0) const
Definition: model_part.h:341
void AddElement(ElementType::Pointer pNewElement, IndexType ThisIndex=0)
Definition: model_part.cpp:917
NodeIterator NodesEnd(IndexType ThisIndex=0)
Definition: model_part.h:497
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
Condition ConditionType
Definition: model_part.h:121
Short class definition.
Definition: model_start_end_meshing_for_fluids_process.hpp:64
KRATOS_CLASS_POINTER_DEFINITION(ModelStartEndMeshingForFluidsProcess)
Pointer definition of ModelStartEndMeshingForFluidsProcess.
void Execute() override
Execute method is used to execute the Process algorithms.
Definition: model_start_end_meshing_for_fluids_process.hpp:98
std::string Info() const override
Turn back information as a string.
Definition: model_start_end_meshing_for_fluids_process.hpp:119
void PerformModelSearches() override
Definition: model_start_end_meshing_for_fluids_process.hpp:430
void BuildComputingDomain(ModelPart &rModelPart, int EchoLevel) override
Definition: model_start_end_meshing_for_fluids_process.hpp:370
ModelStartEndMeshingForFluidsProcess(ModelPart &rMainModelPart, Flags Options, int EchoLevel=0)
Default constructor.
Definition: model_start_end_meshing_for_fluids_process.hpp:77
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: model_start_end_meshing_for_fluids_process.hpp:125
void BuildTotalModelPart(ModelPart &rModelPart, int EchoLevel) override
Definition: model_start_end_meshing_for_fluids_process.hpp:141
virtual ~ModelStartEndMeshingForFluidsProcess()
Destructor.
Definition: model_start_end_meshing_for_fluids_process.hpp:85
void operator()()
Definition: model_start_end_meshing_for_fluids_process.hpp:89
Short class definition.
Definition: nodal_neighbours_search_process.hpp:50
PointerVector is a container like stl vector but using a vector to store pointers to its data.
Definition: pointer_vector.h:72
size_type size() const
Definition: pointer_vector.h:255
Short class definition.
Definition: settle_model_structure_process.hpp:71
Flags mOptions
Definition: settle_model_structure_process.hpp:191
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: settle_model_structure_process.hpp:168
int mEchoLevel
Definition: settle_model_structure_process.hpp:193
ModelPart & mrMainModelPart
Definition: settle_model_structure_process.hpp:189
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
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
ConditionsContainerType::iterator ConditionIterator
Definition: settle_model_structure_process.hpp:51
ConditionsContainerType::const_iterator ConditionConstantIterator
Definition: settle_model_structure_process.hpp:52
ModelPart::ConditionsContainerType ConditionsContainerType
Definition: find_conditions_neighbours_process.h:45
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
GeometryType::PointsArrayType PointsArrayType
Definition: settle_model_structure_process.hpp:48
Condition ConditionType
Definition: assign_unique_model_part_collection_tag_utility.h:43
integer i
Definition: TensorModule.f:17
def FindNeighbours(self)
FOR MEMBRANE print "00000" NormalCalculationUtils().CalculateOnSimplex(self.combined_model_part,...
Definition: ulf_PGLASS.py:386