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.
settle_model_structure_process.hpp
Go to the documentation of this file.
1 //
2 // Project Name: KratosDelaunayMeshingApplication $
3 // Created by: $Author: JMCarbonell $
4 // Last modified by: $Co-Author: $
5 // Date: $Date: April 2018 $
6 // Revision: $Revision: 0.0 $
7 //
8 //
9 
10 #if !defined(KRATOS_SETTLE_MODEL_STRUCTURE_PROCESS_H_INCLUDED )
11 #define KRATOS_SETTLE_MODEL_STRUCTURE_PROCESS_H_INCLUDED
12 
13 
14 // System includes
15 
16 // External includes
17 
18 // Project includes
22 
24 
26 //Data:
27 //StepData:
28 //Flags: (checked)
29 // (set)
30 // (modified)
31 // (reset)
32 
33 
34 namespace Kratos
35 {
36 
39 
49 
51 typedef ConditionsContainerType::iterator ConditionIterator;
52 typedef ConditionsContainerType::const_iterator ConditionConstantIterator;
53 
57 
61 
65 
67 
70  : public Process
71 {
72  public:
75 
78 
82 
84  SettleModelStructureProcess(ModelPart& rMainModelPart, Flags Options, int EchoLevel = 0)
85  : mrMainModelPart(rMainModelPart)
86  {
87  mOptions = Options;
89  }
90 
93  {
94  }
95 
99 
100  void operator()()
101  {
102  Execute();
103  }
104 
108 
111  void ExecuteInitialize() override
112  {
113  KRATOS_TRY
114 
115  //Clean Nodal and Conditional Flags
117 
118  //Sort Conditions
119  this->SortModelPartConditions();
120 
121  KRATOS_CATCH(" ")
122  }
123 
124 
127  void ExecuteFinalize() override
128  {
129  KRATOS_TRY
130 
131  // Restore meshes coherency
132  this->BuildModelPartStructure();
133 
134  // Perform searches for next processes (i.e. contact search)
135  this->PerformModelSearches();
136 
137  KRATOS_CATCH(" ")
138 
139  }
140 
144 
145 
149 
150 
154 
156  std::string Info() const override
157  {
158  return "SettleModelStructureProcess";
159  }
160 
162  void PrintInfo(std::ostream& rOStream) const override
163  {
164  rOStream << "SettleModelStructureProcess";
165  }
166 
168  void PrintData(std::ostream& rOStream) const override
169  {
170  }
171 
172 
176 
177 
179 
180  protected:
183 
184 
188 
190 
192 
194 
198 
202 
203 
204  //*******************************************************************************************
205  //*******************************************************************************************
206 
208  {
209 
210  KRATOS_TRY
211 
212  //Sort Conditions
213  unsigned int consecutive_index = 1;
214  for(ModelPart::ConditionsContainerType::iterator i_cond = mrMainModelPart.ConditionsBegin(); i_cond!=mrMainModelPart.ConditionsEnd(); ++i_cond)
215  (i_cond)->SetId(++consecutive_index);
216 
217  mrMainModelPart.Conditions().Sort();
218  // mrMainModelPart.Conditions().Unique();
219 
220  KRATOS_CATCH(" ")
221  }
222 
223 
224  //*******************************************************************************************
225  //*******************************************************************************************
226 
228  {
229 
230  KRATOS_TRY
231 
232  // Sort Elements
233  unsigned int consecutive_index = 1;
234  for(ModelPart::ElementsContainerType::iterator i_elem = mrMainModelPart.ElementsBegin(); i_elem!=mrMainModelPart.ElementsEnd(); ++i_elem)
235  i_elem->SetId(++consecutive_index);
236 
237  mrMainModelPart.Elements().Sort();
238  // mrMainModelPart.Elements().Unique();
239 
240  KRATOS_CATCH(" ")
241 
242  }
243 
244 
245  //*******************************************************************************************
246  //*******************************************************************************************
247 
249  {
250 
251  KRATOS_TRY
252 
253  //Sort Nodes, set STRUCTURE nodes at end
254  unsigned int consecutive_index = 1;
255  unsigned int reverse_index = mrMainModelPart.Nodes().size();
256  for(ModelPart::NodesContainerType::iterator i_node = mrMainModelPart.NodesBegin(); i_node!=mrMainModelPart.NodesEnd(); ++i_node)
257  {
258  if(i_node->IsNot(STRUCTURE) ){
259  i_node->SetId(++consecutive_index);
260  }
261  else{
262  i_node->SetId(reverse_index--);
263  }
264  }
265 
266  mrMainModelPart.Nodes().Sort();
267  // mrMainModelPart.Nodes().Unique();
268 
269  KRATOS_CATCH(" ")
270 
271  }
272 
273 
274  //*******************************************************************************************
275  //*******************************************************************************************
276 
278  {
279 
280  KRATOS_TRY
281 
282  //Once all model parts are build, the main model part must be reconstructed coherently
283  unsigned int NumberOfSubModelParts=mrMainModelPart.NumberOfSubModelParts();
284  if(NumberOfSubModelParts>0){
285  this->BuildTotalModelPart(mrMainModelPart, mEchoLevel);
286  }
287  else{
288  this->CleanMeshFlags(mrMainModelPart);
289  }
290 
291 
292  KRATOS_CATCH(" ")
293 
294  }
295 
296  //*******************************************************************************************
297  //*******************************************************************************************
298 
299  virtual void PerformModelSearches()
300  {
301  KRATOS_TRY
302 
303  //NODAL NEIGHBOURS SEARCH
305  FindNeighbours.Execute();
306 
307  //NODAL_H SEARCH
308  //FindNodalHProcess FindNodalH(mrMainModelPart);
309  //FindNodalH.Execute();
310 
311  //CONDITIONS MASTER_ELEMENTS and MASTER_NODES SEARCH
313  BuildBoundaryProcess.SearchConditionMasters();
314 
315  //BOUNDARY NORMALS SEARCH and SHRINKAGE FACTOR
316  BoundaryNormalsCalculationUtilities BoundaryComputation;
318 
319  KRATOS_CATCH(" ")
320  }
321 
322 
323  //*******************************************************************************************
324  //*******************************************************************************************
325 
326  virtual void BuildTotalModelPart(ModelPart& rModelPart, int EchoLevel)
327  {
328 
329  KRATOS_TRY
330 
331  //Mesh Id=0
332 
333  if( EchoLevel > 0 )
334  std::cout<<" [ START MODEL PART ["<<rModelPart.Name()<<"] [Elems=:"<<rModelPart.NumberOfElements()<<"|Nodes="<<rModelPart.NumberOfNodes()<<"|Conds="<<rModelPart.NumberOfConditions()<<"] ] "<<std::endl;
335 
336  rModelPart.Nodes().clear();
337  rModelPart.Elements().clear();
338 
339  //contact conditions are located on Mesh_0
340  ModelPart::ConditionsContainerType PreservedConditions;
341 
342  unsigned int nodeId=1;
343  unsigned int elemId=1;
344  unsigned int condId=1;
345 
346  this->BuildBodyModelParts(rModelPart, PreservedConditions, nodeId, elemId, condId);
347 
348  this->BuildBoundaryModelParts(rModelPart,PreservedConditions, nodeId, elemId, condId);
349 
350  this->BuildContactModelParts(rModelPart, PreservedConditions, nodeId, elemId, condId);
351 
352  //now set new conditions
353  rModelPart.Conditions().swap(PreservedConditions);
354 
355  //Unique (sort included)
356  rModelPart.Nodes().Unique();
357  rModelPart.Elements().Unique();
358  rModelPart.Conditions().Unique();
359 
360  //Sort Again to have coherent numeration for nodes (mesh with shared nodes)
361  unsigned int consecutive_index = 1;
362  for(ModelPart::NodesContainerType::iterator in = rModelPart.NodesBegin() ; in != rModelPart.NodesEnd() ; ++in)
363  in->SetId(++consecutive_index);
364 
365  this->BuildComputingDomain(rModelPart, EchoLevel);
366 
367  if( EchoLevel > 0 )
368  std::cout<<" [ END MODEL PART ["<<rModelPart.Name()<<"] [Elems=:"<<rModelPart.NumberOfElements()<<"|Nodes="<<rModelPart.NumberOfNodes()<<"|Conds="<<rModelPart.NumberOfConditions()<<"] ] "<<std::endl;
369 
370 
371  KRATOS_CATCH(" ")
372 
373  }
374 
375 
376  //*******************************************************************************************
377  //*******************************************************************************************
378 
379  void BuildBodyModelParts(ModelPart& rModelPart, ModelPart::ConditionsContainerType& rPreservedConditions, unsigned int& rNodeId, unsigned int& rElemId, unsigned int& rCondId)
380  {
381  KRATOS_TRY
382 
383  //Add Fluid Bodies modelparts to main modelpart flags: ( FLUID / NOT_ACTIVE / NOT_BOUNDARY )
384  //Add Solid Bodies modelparts to main modelpart flags: ( SOLID / NOT_ACTIVE / NOT_BOUNDARY )
385  //Add Rigid Bodies modelparts to main modelpart flags: ( RIGID / NOT_ACTIVE / NOT_BOUNDARY )
386 
387  const array_1d<double,3> ZeroNormal(3,0.0);
388 
389  for(ModelPart::SubModelPartIterator i_mp= rModelPart.SubModelPartsBegin() ; i_mp!=rModelPart.SubModelPartsEnd(); ++i_mp)
390  {
391 
392  bool add_to_main_model_part = false;
393 
394  if( i_mp->IsNot(ACTIVE) && i_mp->IsNot(BOUNDARY) ){ //only the domains (no computing, no boundary)
395 
396  if( i_mp->Is(SOLID) || i_mp->Is(FLUID) || i_mp->Is(RIGID) || i_mp->IsNot(CONTACT) )
397  add_to_main_model_part = true;
398  }
399 
400 
401  if( add_to_main_model_part ){
402 
403 
404  if( mEchoLevel > 0 )
405  std::cout<<" [ SUBMODEL PART ["<<i_mp->Name()<<"] [Elems="<<i_mp->NumberOfElements()<<"|Nodes="<<i_mp->NumberOfNodes()<<"|Conds="<<i_mp->NumberOfConditions()<<"] ";//Clean Nodes when redefining the main model part:
406  ModelPart::NodesContainerType temporal_nodes;
407  temporal_nodes.reserve(i_mp->Nodes().size());
408  temporal_nodes.swap(i_mp->Nodes());
409 
410 
411  if( !i_mp->NumberOfElements() ){ // usually rigid domains (however rigid domain have rigid surface elements)
412 
413  for(ModelPart::NodesContainerType::iterator i_node = temporal_nodes.begin() ; i_node != temporal_nodes.end() ; ++i_node)
414  {
415  if( i_node->IsNot(TO_ERASE) ){
416  (i_mp->Nodes()).push_back(*(i_node.base()));
417  (rModelPart.Nodes()).push_back(*(i_node.base()));
418  rModelPart.Nodes().back().SetId(rNodeId);
419  rNodeId+=1;
420  }
421  }
422  }
423  else{
424 
425  //reset domain flags in nodes before new assignment
426  if( i_mp->Is(FLUID) )
427  for(ModelPart::NodesContainerType::iterator i_node = temporal_nodes.begin() ; i_node != temporal_nodes.end() ; ++i_node)
428  i_node->Set(FLUID,false);
429 
430  if( i_mp->Is(SOLID) )
431  for(ModelPart::NodesContainerType::iterator i_node = temporal_nodes.begin() ; i_node != temporal_nodes.end() ; ++i_node)
432  i_node->Set(SOLID,false);
433 
434  //set new element and domain flags to nodes
435  for(ModelPart::ElementsContainerType::iterator i_elem = i_mp->ElementsBegin() ; i_elem != i_mp->ElementsEnd() ; ++i_elem)
436  {
437  if( i_elem->IsNot(TO_ERASE) ){ //at this point any element must be TO_ERASE
438 
439  PointsArrayType& vertices=i_elem->GetGeometry().Points();
440 
441  if(i_mp->Is(SOLID)){
442 
443  for(unsigned int i=0; i<vertices.size(); ++i)
444  {
445  //vertices[i].Set(BLOCKED,true);
446  vertices[i].Set(SOLID,true);
447  }
448  }
449  else if(i_mp->Is(FLUID)){
450 
451  for(unsigned int i=0; i<vertices.size(); ++i)
452  {
453  //vertices[i].Set(BLOCKED,true);
454  vertices[i].Set(FLUID,true);
455  }
456 
457  }
458 
459  (rModelPart.Elements()).push_back(*(i_elem.base()));
460  rModelPart.Elements().back().SetId(rElemId);
461  rElemId+=1;
462 
463  }
464  else{
465  std::cout<<" ELEMENT TO_ERASE must be RELEASED in a previous stage "<<std::endl;
466  }
467  }
468 
469  for(ModelPart::NodesContainerType::iterator i_node = temporal_nodes.begin() ; i_node != temporal_nodes.end() ; ++i_node)
470  {
471 
472  if( i_node->IsNot(TO_ERASE) ){
473  (i_mp->Nodes()).push_back(*(i_node.base()));
474  (rModelPart.Nodes()).push_back(*(i_node.base()));
475  rModelPart.Nodes().back().SetId(rNodeId);
476  ++rNodeId;
477  }
478 
479  i_node->Set(TO_REFINE,false);
480 
481  if ( i_node->IsNot(BOUNDARY)) {
482  i_node->Set(NEW_ENTITY,false);
483  }
484 
485  // if( (i_node->Is(BLOCKED) || i_node->Is(ISOLATED) ) && i_node->IsNot(TO_ERASE) ){
486  // (i_mp->Nodes()).push_back(*(i_node.base()));
487  // (rModelPart.Nodes()).push_back(*(i_node.base()));
488  // rModelPart.Nodes().back().SetId(rNodeId);
489  // ++rNodeId;
490  // }
491 
492  // if( i_node->Is(BLOCKED) || i_node->Is(RIGID) ){ //all nodes belonging to an element had been blocked previously
493 
494  // i_node->Set(ISOLATED,false); //reset isolated
495 
496  // if( i_node->IsNot(TO_ERASE) ){
497 
498  // (i_mp->Nodes()).push_back(*(i_node.base()));
499  // (rModelPart.Nodes()).push_back(*(i_node.base()));
500  // rModelPart.Nodes().back().SetId(rNodeId);
501  // rNodeId+=1;
502 
503  // }
504 
505  // }
506  // else{
507 
508  // if( i_node->IsNot(SOLID) )
509  // i_node->Set(ISOLATED,true);
510 
511  // if( mOptions.Is(MesherUtilities::KEEP_ISOLATED_NODES) && i_node->IsNot(TO_ERASE) ){
512 
513  // (i_mp->Nodes()).push_back(*(i_node.base()));
514  // (rModelPart.Nodes()).push_back(*(i_node.base()));
515  // rModelPart.Nodes().back().SetId(rNodeId);
516  // rNodeId+=1;
517 
518  // }
519 
520  // }
521 
522  // i_node->Set(TO_REFINE,false); //reset if was labeled to refine (to not duplicate boundary conditions)
523  // i_node->Set(BLOCKED,false);
524  // i_node->Set(NEW_ENTITY,false);
525 
526  if(i_node->IsNot(BOUNDARY)){
527 
528  if( i_node->SolutionStepsDataHas(CONTACT_FORCE) )
529  noalias(i_node->GetSolutionStepValue(CONTACT_FORCE)) = ZeroNormal;
530  }
531 
532  }
533 
534  }
535 
536  for(ModelPart::ConditionsContainerType::iterator i_cond = i_mp->ConditionsBegin() ; i_cond != i_mp->ConditionsEnd() ; ++i_cond)
537  {
538  if( i_cond->IsNot(TO_ERASE) ){
539  i_cond->Set(TO_REFINE,false); //reset if was labeled to refine (to not duplicate boundary conditions)
540  rPreservedConditions.push_back(*(i_cond.base()));
541  rPreservedConditions.back().SetId(rCondId);
542  rCondId+=1;
543  }
544  }
545 
546  if( mEchoLevel > 0 )
547  std::cout<<" / [Elems="<<i_mp->NumberOfElements()<<"|Nodes="<<i_mp->NumberOfNodes()<<"|Conds="<<i_mp->NumberOfConditions()<<"] ] "<<std::endl;
548 
549  }
550 
551  }
552 
553  KRATOS_CATCH(" ")
554  }
555 
556  //*******************************************************************************************
557  //*******************************************************************************************
558 
559  void BuildBoundaryModelParts(ModelPart& rModelPart, ModelPart::ConditionsContainerType& rPreservedConditions, unsigned int& rNodeId, unsigned int& rElemId, unsigned int& rCondId)
560  {
561 
562  KRATOS_TRY
563 
564  unsigned int body_model_part_conditions = rPreservedConditions.size();
565 
566  if(body_model_part_conditions > 0){
567 
568  //add new conditions: ( BOUNDARY model parts )
570  {
571  if( i_mp->Is(BOUNDARY) ){ //boundary model part
572 
573  if( mEchoLevel > 0 )
574  std::cout<<" [ SUBMODEL PART ["<<i_mp->Name()<<"] initial [Elems="<<i_mp->NumberOfElements()<<"|Nodes="<<i_mp->NumberOfNodes()<<"|Conds="<<i_mp->NumberOfConditions()<<"] ]"<<std::endl;
575 
576  this->CleanModelPartConditions(*i_mp);
577 
578  for(ModelPart::ConditionsContainerType::iterator i_cond = rPreservedConditions.begin(); i_cond!= rPreservedConditions.end(); ++i_cond)
579  {
580  ConditionsContainerType& ChildrenConditions = i_cond->GetValue(CHILDREN_CONDITIONS);
581 
582  //this conditions are cloned, then the id has no coherence, must be renumbered at the end of the assignation
583  for (ConditionConstantIterator cn = ChildrenConditions.begin() ; cn != ChildrenConditions.end(); ++cn)
584  {
585  if( cn->GetValue(MODEL_PART_NAME) == i_mp->Name() ){
586  i_mp->Conditions().push_back(*(cn.base()));
587 
588  if( i_cond->Is(NEW_ENTITY) ){
589  for(unsigned int i=0; i<i_cond->GetGeometry().size(); ++i)
590  {
591  if( i_cond->GetGeometry()[i].Is(NEW_ENTITY) ){
592  (i_mp->Nodes()).push_back(i_cond->GetGeometry()(i));
593  }
594  }
595  }
596  }
597  }
598  }
599  }
600  }
601  }
602 
603  // Set new nodes to the dirichlet sub model parts (works in 2D. not sure in 3D). Must be reviewed
604  for(ModelPart::SubModelPartIterator i_model_part = mrMainModelPart.SubModelPartsBegin() ; i_model_part != mrMainModelPart.SubModelPartsEnd(); ++i_model_part)
605  {
606  if( i_model_part->IsNot(BOUNDARY) && i_model_part->IsNot(ACTIVE) && i_model_part->IsNot(RIGID) ){
607 
608  for(ModelPart::NodesContainerType::iterator i_node = i_model_part->NodesBegin() ; i_node != i_model_part->NodesEnd(); ++i_node)
609  {
610 
611  if( i_node->Is(BOUNDARY) && i_node->Is(NEW_ENTITY) ){
612 
613  // Generate a list of neighbour nodes
614  unsigned int NodeId = i_node->Id();
615 
616  std::vector<int> list_of_neighbour_nodes;
617 
618  for( ModelPart::ConditionsContainerType::iterator j_cond = rPreservedConditions.begin(); j_cond != rPreservedConditions.end(); ++j_cond)
619  {
620 
621  bool node_belongs_to_condition = false;
622  Geometry< Node > & rjGeom = j_cond->GetGeometry();
623 
624  if ( j_cond->Is(NEW_ENTITY) ){
625  for ( unsigned int j = 0; j < rjGeom.size() ; ++j) {
626  if ( rjGeom[j].Id() == NodeId) {
627  node_belongs_to_condition = true;
628  break;
629  }
630  }
631 
632  if (node_belongs_to_condition){
633  for (unsigned int j = 0; j < rjGeom.size() ; ++j) {
634  list_of_neighbour_nodes.push_back( rjGeom[j].Id() );
635  }
636  }
637 
638  }
639  }
640 
641  if(list_of_neighbour_nodes.size() == 0){
642  //std::cout << "Warning: New Node["<<NodeId<<"] does not have any new neighbour" << std::endl;
643  continue;
644  }
645 
646  // unique and sort
647  std::sort(list_of_neighbour_nodes.begin(), list_of_neighbour_nodes.end() );
648  std::vector<int>::iterator new_end = std::unique( list_of_neighbour_nodes.begin(), list_of_neighbour_nodes.end() );
649  list_of_neighbour_nodes.resize( std::distance( list_of_neighbour_nodes.begin(), new_end) );
650 
652  {
653  if ( i_mp->Is(BOUNDARY) && i_mp->IsNot(CONTACT) && (i_mp->NumberOfConditions() == 0) )
654  {
655  unsigned int counter = 0;
656 
657  for (unsigned int ii = 0; ii < list_of_neighbour_nodes.size(); ++ii)
658  {
659  unsigned int target = list_of_neighbour_nodes[ii];
660 
661  for (ModelPart::NodesContainerType::iterator i_node = i_mp->NodesBegin(); i_node != i_mp->NodesEnd(); ++i_node)
662  {
663  if ( i_node->Id() == target) {
664  counter++;
665  }
666  }
667  }
668 
669  if ( counter == list_of_neighbour_nodes.size()-1)
670  i_mp->Nodes().push_back( *(i_node.base() ) );
671  }
672  }
673  }
674  }
675  }
676  }
677 
678  //reset NEW_ENTITIES in conditions
679  for( ModelPart::ConditionsContainerType::iterator j_cond = rPreservedConditions.begin(); j_cond != rPreservedConditions.end(); ++j_cond)
680  {
681  j_cond->Set(NEW_ENTITY,false);
682  for(unsigned int j=0; j<j_cond->GetGeometry().size(); ++j)
683  {
684  if( j_cond->GetGeometry()[j].Is(NEW_ENTITY) ){
685  j_cond->GetGeometry()[j].Set(NEW_ENTITY,false); //reset if was new
686  }
687  }
688  }
689 
690  //add new nodes: ( BOUNDARY model parts ) and remove erased nodes
692  {
693  if( i_mp->Is(BOUNDARY) ){ //boundary model part
694 
695  ModelPart::NodesContainerType temporal_nodes;
696  temporal_nodes.reserve(i_mp->Nodes().size());
697  temporal_nodes.swap(i_mp->Nodes());
698 
699  for(ModelPart::NodesContainerType::iterator i_node = temporal_nodes.begin() ; i_node != temporal_nodes.end() ; ++i_node)
700  {
701  if( i_node->IsNot(TO_ERASE) )
702  (i_mp->Nodes()).push_back(*(i_node.base()));
703  }
704 
705  if( mEchoLevel > 0 )
706  std::cout<<" [ SUBMODEL PART ["<<i_mp->Name()<<"] final [Elems="<<i_mp->NumberOfElements()<<"|Nodes="<<i_mp->NumberOfNodes()<<"|Conds="<<i_mp->NumberOfConditions()<<"] ] "<<std::endl;
707  }
708  }
709 
710  //add boundary domain conditions to preserved conditions
711  for(ModelPart::SubModelPartIterator i_mp= rModelPart.SubModelPartsBegin() ; i_mp!=rModelPart.SubModelPartsEnd(); ++i_mp)
712  {
713  if( i_mp->Is(BOUNDARY) ){ //boundary model part
714 
715  for(ModelPart::ConditionsContainerType::iterator i_cond = i_mp->ConditionsBegin() ; i_cond != i_mp->ConditionsEnd() ; ++i_cond)
716  {
717  if( i_cond->IsNot(TO_ERASE) ){
718  i_cond->Set(NEW_ENTITY,false); //reset here if the condition is inserted
719  rPreservedConditions.push_back(*(i_cond.base()));
720  rPreservedConditions.back().SetId(rCondId);
721  rCondId+=1;
722  }
723  }
724  }
725 
726  }
727 
728  KRATOS_CATCH( "" )
729  }
730 
731 
732 
733  //*******************************************************************************************
734  //*******************************************************************************************
735 
736  void BuildContactModelParts(ModelPart& rModelPart, ModelPart::ConditionsContainerType& rPreservedConditions, unsigned int& rNodeId, unsigned int& rElemId, unsigned int& rCondId)
737  {
738  KRATOS_TRY
739 
740  //Add Contact modelparts to main modelpart flags: ( CONTACT ) in contact model parts keep only nodes and contact conditions // after that a contact search will be needed
741 
742  //if contact condition has the same geometry size as an elements printing ids will coincide,
743  //renumber conditions with rElemId instead of rCondId :: in order to ensure it check maximun and apply it
744  unsigned int rContactId = rCondId;
745  if( rElemId > rCondId )
746  rContactId = rElemId;
747 
748 
749  for(ModelPart::SubModelPartIterator i_mp= rModelPart.SubModelPartsBegin() ; i_mp!=rModelPart.SubModelPartsEnd(); ++i_mp)
750  {
751 
752  if( i_mp->Is(CONTACT) ){ //keep only contact conditions
753 
754  if( mEchoLevel > 0 )
755  std::cout<<" [ SUBMODEL PART ["<<i_mp->Name()<<"] [Elems="<<i_mp->NumberOfElements()<<"|Nodes="<<i_mp->NumberOfNodes()<<"|Conds="<<i_mp->NumberOfConditions()<<"] ";
756 
757  i_mp->Elements().clear();
758 
759  //Clean Nodes when redefining the main model part:
760  ModelPart::NodesContainerType temporal_nodes;
761  temporal_nodes.reserve(i_mp->Nodes().size());
762  temporal_nodes.swap(i_mp->Nodes());
763 
764 
765  for(ModelPart::NodesContainerType::iterator i_node = temporal_nodes.begin() ; i_node != temporal_nodes.end() ; ++i_node)
766  {
767  if( i_node->IsNot(TO_ERASE) ){
768  (i_mp->Nodes()).push_back(*(i_node.base()));
769  }
770  }
771 
772  ModelPart::ConditionsContainerType temporal_conditions;
773  temporal_conditions.reserve(i_mp->Conditions().size());
774  temporal_conditions.swap(i_mp->Conditions());
775 
776  for(ModelPart::ConditionsContainerType::iterator i_cond = temporal_conditions.begin() ; i_cond != temporal_conditions.end() ; ++i_cond)
777  {
778 
779  if( i_cond->Is(CONTACT) ){ //keep only contact conditions
780 
781  if( i_cond->IsNot(TO_ERASE) ){ //it can not be to erase
782 
783  (i_mp->Conditions()).push_back(*(i_cond.base()));
784  rPreservedConditions.push_back(*(i_cond.base()));
785  rPreservedConditions.back().SetId(rContactId);
786  rContactId+=1;
787 
788  }
789 
790  }
791 
792  }
793 
794  if( mEchoLevel > 0 )
795  std::cout<<" / [Elems="<<i_mp->NumberOfElements()<<"|Nodes="<<i_mp->NumberOfNodes()<<"|Conds="<<i_mp->NumberOfConditions()<<"] ] "<<std::endl;
796 
797 
798  }
799 
800  }
801 
802 
803  if( rElemId > rCondId )
804  rElemId = rContactId;
805  else
806  rCondId = rContactId;
807 
808 
809  KRATOS_CATCH(" ")
810  }
811 
812 
813  //*******************************************************************************************
814  //*******************************************************************************************
815 
817  {
818 
819  KRATOS_TRY
820 
821  if( rModelPart.Is(BOUNDARY) )
822  rModelPart.Conditions().clear();
823 
824  //clean old conditions (TO_ERASE) and add new conditions (NEW_ENTITY)
825  // ModelPart::ConditionsContainerType PreservedConditions;
826  // PreservedConditions.reserve(rModelPart.Conditions().size());
827  // PreservedConditions.swap(rModelPart.Conditions());
828 
829  // for(ModelPart::ConditionsContainerType::iterator i_cond = PreservedConditions.begin(); i_cond!= PreservedConditions.end(); ++i_cond)
830  // {
831  // if(i_cond->IsNot(TO_ERASE))
832  // rModelPart.Conditions().push_back(*(i_cond.base()));
833  // }
834 
835 
836  KRATOS_CATCH( "" )
837  }
838 
839 
840  //*******************************************************************************************
841  //*******************************************************************************************
842 
843  virtual void BuildComputingDomain (ModelPart& rModelPart, int EchoLevel)
844  {
845  KRATOS_TRY
846 
847  std::string ComputingModelPartName;
848  for(ModelPart::SubModelPartIterator i_mp= rModelPart.SubModelPartsBegin() ; i_mp!=rModelPart.SubModelPartsEnd(); ++i_mp)
849  {
850  if( i_mp->Is(ACTIVE) && i_mp->IsNot(THERMAL) ){ //computing_domain
851  ComputingModelPartName = i_mp->Name();
852  }
853  }
854 
855 
856  ModelPart& rComputingModelPart = rModelPart.GetSubModelPart(ComputingModelPartName);
857 
858  rComputingModelPart.Nodes().clear();
859  rComputingModelPart.Elements().clear();
860  rComputingModelPart.Conditions().clear();
861 
862  //add all needed computing entities (elements, nodes, conditions)
863 
864  for(ModelPart::SubModelPartIterator i_mp= rModelPart.SubModelPartsBegin() ; i_mp!=rModelPart.SubModelPartsEnd(); ++i_mp)
865  {
866  if( (i_mp->IsNot(BOUNDARY) && i_mp->IsNot(ACTIVE)) || (i_mp->Is(RIGID)) ){
867 
868  if( i_mp->IsNot(CONTACT) ){
869 
870  for(ModelPart::NodesContainerType::iterator i_node = i_mp->NodesBegin() ; i_node != i_mp->NodesEnd() ; ++i_node)
871  {
872  (rComputingModelPart.Nodes()).push_back(*(i_node.base()));
873  }
874 
875  for(ModelPart::ConditionsContainerType::iterator i_cond = i_mp->ConditionsBegin() ; i_cond != i_mp->ConditionsEnd() ; ++i_cond)
876  {
877  (rComputingModelPart.Conditions()).push_back(*(i_cond.base()));
878  }
879 
880  if(i_mp->Is(RIGID)){
881 
882  for(ModelPart::ElementsContainerType::iterator i_elem = i_mp->ElementsBegin() ; i_elem != i_mp->ElementsEnd() ; ++i_elem)
883  {
884  if( this->CheckRigidElementSize(*i_elem) )
885  (rComputingModelPart.Elements()).push_back(*(i_elem.base()));
886  }
887  }
888  else{
889 
890  for(ModelPart::ElementsContainerType::iterator i_elem = i_mp->ElementsBegin() ; i_elem != i_mp->ElementsEnd() ; ++i_elem)
891  {
892  (rComputingModelPart.Elements()).push_back(*(i_elem.base()));
893  }
894  }
895 
896  }
897  }
898  }
899 
900  //add all contact conditions
901 
902  for(ModelPart::SubModelPartIterator i_mp= rModelPart.SubModelPartsBegin() ; i_mp!=rModelPart.SubModelPartsEnd(); ++i_mp)
903  {
904  if( i_mp->Is(CONTACT) ){
905 
906  for(ModelPart::ConditionsContainerType::iterator i_cond = i_mp->ConditionsBegin() ; i_cond != i_mp->ConditionsEnd() ; ++i_cond)
907  {
908  if( i_cond->Is(CONTACT) )
909  (rComputingModelPart.Conditions()).push_back(*(i_cond.base()));
910  }
911 
912  }
913 
914  }
915 
916  // Unique (sort included)
917  rComputingModelPart.Nodes().Unique();
918  // rComputingModelPart.Elements().Unique();
919  // rComputingModelPart.Conditions().Unique();
920 
921  if( EchoLevel > 0 )
922  std::cout<<" [ SUBMODEL PART ["<<rComputingModelPart.Name()<<"] [Elems="<<rComputingModelPart.NumberOfElements()<<"|Nodes="<<rComputingModelPart.NumberOfNodes()<<"|Conds="<<rComputingModelPart.NumberOfConditions()<<"] ] "<<std::endl;
923 
924 
925  KRATOS_CATCH(" ")
926  }
927 
928 
929  //*******************************************************************************************
930  //*******************************************************************************************
931 
932  void CleanMeshFlags(ModelPart& rModelPart)
933  {
934 
935  KRATOS_TRY
936 
937  for(ModelPart::NodesContainerType::const_iterator i_node = rModelPart.NodesBegin(); i_node != rModelPart.NodesEnd(); ++i_node)
938  {
939 
940  i_node->Set(NEW_ENTITY,false); //reset here if the node is labeled as insert
941  i_node->Set(TO_REFINE,false); //reset here if the node is labeled as refine (to not duplicate
942 
943  }
944 
945  for(ModelPart::ConditionsContainerType::iterator i_cond = rModelPart.ConditionsBegin() ; i_cond != rModelPart.ConditionsEnd() ; ++i_cond)
946  {
947  i_cond->Set(NEW_ENTITY,false); //reset here if the node is inserted
948  }
949 
950  KRATOS_CATCH(" ")
951  }
952 
953  //**************************************************************************
954  //**************************************************************************
955 
956  virtual bool CheckRigidElementSize(Element& rElement)
957  {
958  KRATOS_TRY
959 
960  GeometryType& rElementGeometry = rElement.GetGeometry();
961 
962  unsigned int rigid = 0;
963  unsigned int moving = 0;
964  for(unsigned int i=0; i<rElementGeometry.size(); ++i)
965  {
966  if(rElementGeometry[i].Is(RIGID)){
967  ++rigid;
968  array_1d<double,3>& movement = rElementGeometry[i].FastGetSolutionStepValue(DISPLACEMENT);
969  for(unsigned int j=0; j<3; ++j){
970  if( movement[j] != 0 )
971  ++moving;
972  }
973  }
974  }
975 
976  if( moving > 0 && rigid == rElementGeometry.size() ){
977  double CurrentSize = rElementGeometry.DomainSize();
978  std::vector<array_1d<double, 3> > CurrentCoordinates;
979  for(unsigned int i=0; i<rigid; ++i)
980  {
981  CurrentCoordinates.push_back(rElementGeometry[i].Coordinates());
982  rElementGeometry[i].Coordinates() = rElementGeometry[i].GetInitialPosition();
983  }
984 
985  double OriginalSize = rElementGeometry.DomainSize();
986  for(unsigned int i=0; i<rigid; ++i)
987  {
988  rElementGeometry[i].Coordinates() = CurrentCoordinates[i];
989  }
990 
991  if( (CurrentSize > OriginalSize + 1e-3*OriginalSize) || (CurrentSize < OriginalSize - 1e-3*OriginalSize) ){
992  //rElement.Set(TO_ERASE);
993  return false;
994  }
995  }
996 
997  return true;
998 
999  KRATOS_CATCH( "" )
1000  }
1001 
1002 
1003  //*******************************************************************************************
1004  //*******************************************************************************************
1005 
1006 
1010 
1011 
1015 
1016 
1020 
1021 
1023 
1024  private:
1027 
1028 
1032 
1033 
1037 
1038 
1042 
1043 
1047 
1048 
1052 
1053 
1057 
1059  SettleModelStructureProcess& operator=(SettleModelStructureProcess const& rOther);
1060 
1062  //SettleModelStructureProcess(SettleModelStructureProcess const& rOther);
1063 
1064 
1066 
1067 }; // Class SettleModelStructureProcess
1068 
1070 
1073 
1074 
1078 
1079 
1081 inline std::istream& operator >> (std::istream& rIStream,
1083 
1085 inline std::ostream& operator << (std::ostream& rOStream,
1086  const SettleModelStructureProcess& rThis)
1087 {
1088  rThis.PrintInfo(rOStream);
1089  rOStream << std::endl;
1090  rThis.PrintData(rOStream);
1091 
1092  return rOStream;
1093 }
1095 
1096 
1097 } // namespace Kratos.
1098 
1099 #endif // KRATOS_SETTLE_MODEL_STRUCTURE_PROCESS_H_INCLUDED defined
Definition: boundary_normals_calculation_utilities.hpp:48
void CalculateWeightedBoundaryNormals(ModelPart &rModelPart, int EchoLevel=0)
Calculates the area normal (unitary vector oriented as the normal) and weight the normal to shrink.
Definition: boundary_normals_calculation_utilities.hpp:123
Short class definition.
Definition: build_model_part_boundary_process.hpp:79
bool SearchConditionMasters()
Definition: build_model_part_boundary_process.hpp:240
Base class for all Elements.
Definition: element.h:60
Definition: flags.h:58
bool Is(Flags const &rOther) const
Definition: flags.h:274
GeometryType & GetGeometry()
Returns the reference of the geometry.
Definition: geometrical_object.h:158
Geometry base class.
Definition: geometry.h:71
void push_back(PointPointerType x)
Definition: geometry.h:548
SizeType size() const
Definition: geometry.h:518
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
ConditionIterator ConditionsBegin(IndexType ThisIndex=0)
Definition: model_part.h:1361
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
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
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
ElementIterator ElementsEnd(IndexType ThisIndex=0)
Definition: model_part.h:1179
ModelPart & GetSubModelPart(std::string const &SubModelPartName)
Definition: model_part.cpp:2029
SizeType NumberOfNodes(IndexType ThisIndex=0) const
Definition: model_part.h:341
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
ConditionIterator ConditionsEnd(IndexType ThisIndex=0)
Definition: model_part.h:1371
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
The base class for all processes in Kratos.
Definition: process.h:49
virtual void Execute()
Execute method is used to execute the Process algorithms.
Definition: process.h:101
Short class definition.
Definition: settle_model_structure_process.hpp:71
virtual ~SettleModelStructureProcess()
Destructor.
Definition: settle_model_structure_process.hpp:92
void ExecuteFinalize() override
Definition: settle_model_structure_process.hpp:127
SettleModelStructureProcess(ModelPart &rMainModelPart, Flags Options, int EchoLevel=0)
Default constructor.
Definition: settle_model_structure_process.hpp:84
KRATOS_CLASS_POINTER_DEFINITION(SettleModelStructureProcess)
Pointer definition of SettleModelStructureProcess.
void operator()()
Definition: settle_model_structure_process.hpp:100
void SortModelPartConditions()
Definition: settle_model_structure_process.hpp:207
Flags mOptions
Definition: settle_model_structure_process.hpp:191
void BuildBoundaryModelParts(ModelPart &rModelPart, ModelPart::ConditionsContainerType &rPreservedConditions, unsigned int &rNodeId, unsigned int &rElemId, unsigned int &rCondId)
Definition: settle_model_structure_process.hpp:559
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: settle_model_structure_process.hpp:168
void BuildBodyModelParts(ModelPart &rModelPart, ModelPart::ConditionsContainerType &rPreservedConditions, unsigned int &rNodeId, unsigned int &rElemId, unsigned int &rCondId)
Definition: settle_model_structure_process.hpp:379
void ExecuteInitialize() override
Definition: settle_model_structure_process.hpp:111
virtual void PerformModelSearches()
Definition: settle_model_structure_process.hpp:299
std::string Info() const override
Turn back information as a string.
Definition: settle_model_structure_process.hpp:156
virtual void BuildComputingDomain(ModelPart &rModelPart, int EchoLevel)
Definition: settle_model_structure_process.hpp:843
virtual bool CheckRigidElementSize(Element &rElement)
Definition: settle_model_structure_process.hpp:956
int mEchoLevel
Definition: settle_model_structure_process.hpp:193
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: settle_model_structure_process.hpp:162
virtual void BuildTotalModelPart(ModelPart &rModelPart, int EchoLevel)
Definition: settle_model_structure_process.hpp:326
void BuildContactModelParts(ModelPart &rModelPart, ModelPart::ConditionsContainerType &rPreservedConditions, unsigned int &rNodeId, unsigned int &rElemId, unsigned int &rCondId)
Definition: settle_model_structure_process.hpp:736
ModelPart & mrMainModelPart
Definition: settle_model_structure_process.hpp:189
void CleanMeshFlags(ModelPart &rModelPart)
Definition: settle_model_structure_process.hpp:932
void SortModelPartElements()
Definition: settle_model_structure_process.hpp:227
void CleanModelPartConditions(ModelPart &rModelPart)
Definition: settle_model_structure_process.hpp:816
void SortModelPartNodes()
Definition: settle_model_structure_process.hpp:248
void BuildModelPartStructure()
Definition: settle_model_structure_process.hpp:277
#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
Geometry< Node > GeometryType
The definition of the geometry.
Definition: mortar_classes.h:37
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
T & noalias(T &TheMatrix)
Definition: amatrix_interface.h:484
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
int j
Definition: quadrature.py:648
int counter
Definition: script_THERMAL_CORRECT.py:218
integer i
Definition: TensorModule.f:17
e
Definition: run_cpp_mpi_tests.py:31
def FindNeighbours(self)
FOR MEMBRANE print "00000" NormalCalculationUtils().CalculateOnSimplex(self.combined_model_part,...
Definition: ulf_PGLASS.py:386