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_contact_model_part_process.hpp
Go to the documentation of this file.
1 //
2 // Project Name: KratosContactMechanicsApplication $
3 // Created by: $Author: JMCarbonell $
4 // Last modified by: $Co-Author: $
5 // Date: $Date: August 2016 $
6 // Revision: $Revision: 0.0 $
7 //
8 //
9 
10 #if !defined(KRATOS_BUILD_CONTACT_MODEL_PART_PROCESS_H_INCLUDED )
11 #define KRATOS_BUILD_CONTACT_MODEL_PART_PROCESS_H_INCLUDED
12 
13 
14 // System includes
15 #include <string>
16 #include <iostream>
17 
18 // External includes
19 #include <boost/timer.hpp>
20 
21 // Project includes
22 #include "includes/model_part.h"
24 
26 //Data:
27 //StepData:
28 //Flags: (checked)
29 // (set)
30 // (modified)
31 // (reset)
32 // (set):=(set in this process)
33 
34 namespace Kratos
35 {
36 
39 
43 
47 
51 
55 
57 
60  : public Process
61  {
62  public:
65 
68 
72 
76 
79  MesherUtilities::MeshingParameters& rRemeshingParameters,
80  std::vector<std::string>& rContactModelParts,
81  int EchoLevel)
82  : mrModelPart(rModelPart)
83  ,mrRemesh(rRemeshingParameters)
84  ,mrContactModelParts(rContactModelParts)
85  {
86  mEchoLevel = EchoLevel;
87  mMasterConditionsInitialized = false;
88  }
89 
90 
93  :mrModelPart(rOther.mrModelPart)
94  ,mrRemesh(rOther.mrRemesh)
95  ,mrContactModelParts(rOther.mrContactModelParts)
96  ,mEchoLevel(rOther.mEchoLevel)
97  ,mMasterConditionsInitialized(rOther.mMasterConditionsInitialized)
98  {
99  }
100 
103  {
104  }
105 
106 
110 
111  void operator()()
112  {
113  Execute();
114  }
115 
116 
120 
121  void Execute() override
122  {
123  KRATOS_TRY
124 
125  if( mEchoLevel > 0 )
126  std::cout<<" [ CONSTRUCT CONTACT MODEL_PART: "<<std::endl;
127 
128  ModelPart& rModelPart = mrModelPart.GetSubModelPart(mrRemesh.SubModelPartName);
129 
130  //set CONTACT label
131  rModelPart.Set(CONTACT);
132 
133  this->Execute(rModelPart);
134 
135  //this->Transfer(rModelPart);
136 
137  this->SetHoles();
138 
139  if( mEchoLevel > 0 )
140  std::cout<<" CONSTRUCT CONTACT MODEL_PART ]; "<<std::endl;
141 
142 
143  KRATOS_CATCH(" ")
144  }
145 
146 
150 
151 
155 
156 
160 
162  std::string Info() const override
163  {
164  return "BuildContactModelPartProcess";
165  }
166 
168  void PrintInfo(std::ostream& rOStream) const override
169  {
170  rOStream << "BuildContactModelPartProcess";
171  }
172 
174  void PrintData(std::ostream& rOStream) const override
175  {
176  }
177 
178 
182 
183 
185 
186  protected:
189 
190 
194 
195 
199 
200 
204 
205 
209 
210 
214 
215 
219 
220 
222 
223  private:
226 
227 
231  ModelPart& mrModelPart;
232 
234 
235  std::vector<std::string> mrContactModelParts;
236 
237  int mEchoLevel;
238 
239  bool mMasterConditionsInitialized;
240 
244 
245  //**************************************************************************
246  //**************************************************************************
247  void Execute(ModelPart& rModelPart)
248  {
249 
250  KRATOS_TRY
251 
252  //check if the construction is needed
253  unsigned int count_nodes = 0;
254  unsigned int count_conditions = 0;
255 
256  for(std::vector<std::string>::const_iterator n_mp = mrContactModelParts.begin(); n_mp!=mrContactModelParts.end(); ++n_mp)
257  {
258  //std::cout<<" ModelParts "<<*n_mp<<std::endl;
259  ModelPart& i_mp = mrModelPart.GetSubModelPart(*n_mp);
260 
261  for(ModelPart::NodesContainerType::iterator i_node = i_mp.NodesBegin() ; i_node != i_mp.NodesEnd() ; i_node++)
262  {
263  if( i_node->Is(BOUNDARY) )
264  ++count_nodes;
265  }
266 
267  for(ModelPart::ConditionsContainerType::iterator i_cond = i_mp.ConditionsBegin() ; i_cond != i_mp.ConditionsEnd() ; i_cond++)
268  {
269  if( i_cond->Is(BOUNDARY) && i_cond->IsNot(CONTACT) )
270  ++count_conditions;
271  }
272  }
273 
274 
275  bool build_is_needed = false;
276  if( count_nodes != rModelPart.Nodes().size() || count_conditions != rModelPart.Conditions().size() )
277  build_is_needed = true;
278 
279  const ProcessInfo& rProcessInfo = rModelPart.GetProcessInfo();
280  if( rProcessInfo[MESHING_STEP_TIME] == rProcessInfo[TIME] )
281  build_is_needed = true;
282 
283  if( build_is_needed ){
284 
285  //*******************************************************************
286  //set boundary conditions and nodes:
287 
288  rModelPart.Nodes().clear();
289  rModelPart.Elements().clear();
290 
291  ModelPart::ConditionsContainerType PreservedConditions;
292  PreservedConditions.swap(rModelPart.Conditions());
293 
294 
295  for(std::vector<std::string>::const_iterator n_mp = mrContactModelParts.begin(); n_mp!=mrContactModelParts.end(); ++n_mp)
296  {
297  //std::cout<<" ModelParts "<<*n_mp<<std::endl;
298  ModelPart& i_mp = mrModelPart.GetSubModelPart(*n_mp);
299 
300  for(ModelPart::NodesContainerType::iterator i_node = i_mp.NodesBegin() ; i_node != i_mp.NodesEnd() ; i_node++)
301  {
302  if( i_node->Is(BOUNDARY) )
303  rModelPart.AddNode(*(i_node.base()));
304  }
305 
306  for(ModelPart::ConditionsContainerType::iterator i_cond = i_mp.ConditionsBegin() ; i_cond != i_mp.ConditionsEnd() ; i_cond++)
307  {
308  if( i_cond->Is(BOUNDARY) && i_cond->IsNot(CONTACT) )
309  rModelPart.AddCondition(*(i_cond.base()));
310  }
311  }
312 
313  //add previous contact conditions
314  for(ModelPart::ConditionsContainerType::iterator i_cond = PreservedConditions.begin(); i_cond!= PreservedConditions.end(); i_cond++)
315  {
316  if(i_cond->Is(CONTACT)){
317  rModelPart.Conditions().push_back(*(i_cond.base()));
318  }
319  }
320 
321 
322  //Sort
323  //rModelPart.Nodes().Sort();
324  //rModelPart.Conditions().Sort();
325 
326  //Unique
327  //rModelPart.Nodes().Unique();
328  //rModelPart.Conditions().Unique();
329 
330  }
331 
332  if( mEchoLevel > 0 )
333  std::cout<<" CONTACT MODEL_PART: (NODES:"<<rModelPart.NumberOfNodes()<<" CONDITIONS:"<<rModelPart.NumberOfConditions()<<") ]; "<<std::endl;
334 
335  KRATOS_CATCH(" ")
336 
337  }
338 
339  //**************************************************************************
340  //**************************************************************************
341  void Transfer(ModelPart& rModelPart)
342  {
343 
344  KRATOS_TRY
345 
346  //*******************************************************************
347  //set transfer parameters
348  MeshDataTransferUtilities DataTransferUtilities;
349 
350  MeshDataTransferUtilities::TransferParameters::Pointer rParameters = mrRemesh.GetTransferParameters();
351 
352  //be careful: it must be done once only after the step solution:
353  if(!mMasterConditionsInitialized){
354  rParameters->Options.Set(MeshDataTransferUtilities::INITIALIZE_MASTER_CONDITION, true);
355  DataTransferUtilities.TransferBoundaryData(*rParameters, rModelPart);
356  mMasterConditionsInitialized = true;
357  }
358  else{
359  rParameters->Options.Set(MeshDataTransferUtilities::MASTER_ELEMENT_TO_MASTER_CONDITION, true);
360  DataTransferUtilities.TransferBoundaryData(*rParameters, mrModelPart);
361  }
362 
363  KRATOS_CATCH( "" )
364  }
365 
366 
367  //**************************************************************************
368  //**************************************************************************
369 
370  void SetHoles()
371  {
372 
373  KRATOS_TRY
374 
375  //*******************************************************************
376  //set holes (inside point of the contact domains):
377  std::vector<BoundedVector<double, 3> > Holes;
378  BoundedVector<double, 3> Point;
379 
380  for(std::vector<std::string>::const_iterator n_mp = mrContactModelParts.begin(); n_mp!=mrContactModelParts.end(); ++n_mp)
381  {
382  //std::cout<<" ModelParts "<<*n_mp<<std::endl;
383  ModelPart& i_mp = mrModelPart.GetSubModelPart(*n_mp);
384 
385  //Get inside point of the subdomains
386  unsigned int dimension = i_mp.GetProcessInfo()[SPACE_DIMENSION];
387  if(i_mp.NumberOfConditions()){
388  ModelPart::ConditionsContainerType::iterator element_begin = i_mp.ConditionsBegin();
389  dimension = element_begin->GetGeometry().WorkingSpaceDimension();
390  }
391 
392  bool hole_found = false;
393  for(ModelPart::NodesContainerType::iterator i_node = i_mp.NodesBegin() ; i_node != i_mp.NodesEnd() ; i_node++)
394  {
395  if( i_node->IsNot(BOUNDARY) ){
396  Point[0] = i_node->X();
397  Point[1] = i_node->Y();
398 
399  if(dimension>2)
400  Point[2] = i_node->Z();
401 
402  //std::cout<<" SetPoint "<<Point<<std::endl;
403  Holes.push_back(Point);
404  hole_found = true;
405  break;
406  }
407  }
408 
409  if( !hole_found ){
410  for(ModelPart::NodesContainerType::iterator i_node = i_mp.NodesBegin() ; i_node != i_mp.NodesEnd() ; i_node++)
411  {
412  if( i_node->Is(BOUNDARY) ){
413 
414  array_1d<double, 3>& Normal = i_node->FastGetSolutionStepValue(NORMAL);
415  double Nodal_H = i_node->FastGetSolutionStepValue(NODAL_H);
416  double tolerance = 0.5 * Nodal_H;
417 
418  //std::cout<<" Normal "<<Normal<<" Nodal_h "<<Nodal_H<<std::endl;
419 
420  Point[0] = i_node->X() - Normal[0] * tolerance;
421  Point[1] = i_node->Y() - Normal[1] * tolerance;
422  if(dimension>2)
423  Point[2] = i_node->Z() - Normal[2] * tolerance;
424 
425  Holes.push_back(Point);
426  hole_found = true;
427  break;
428  }
429  }
430  }
431  }
432 
433 
434  mrRemesh.SetHoles(Holes);
435 
436 
437  KRATOS_CATCH(" ")
438 
439  }
440 
444 
445 
449 
450 
454 
455 
459 
462 
464  //BuildContactModelPartProcess(BuildContactModelPartProcess const& rOther);
465 
466 
468 
469  }; // Class BuildContactModelPartProcess
470 
472 
475 
476 
480 
481 
483  inline std::istream& operator >> (std::istream& rIStream,
485 
487  inline std::ostream& operator << (std::ostream& rOStream,
488  const BuildContactModelPartProcess& rThis)
489  {
490  rThis.PrintInfo(rOStream);
491  rOStream << std::endl;
492  rThis.PrintData(rOStream);
493 
494  return rOStream;
495  }
497 
498 
499 } // namespace Kratos.
500 
501 #endif // KRATOS_BUILD_CONTACT_MODEL_PART_PROCESS_H_INCLUDED defined
Short class definition.
Definition: build_contact_model_part_process.hpp:61
ModelPart::ConditionType ConditionType
Definition: build_contact_model_part_process.hpp:69
BuildContactModelPartProcess(BuildContactModelPartProcess const &rOther)
Copy constructor.
Definition: build_contact_model_part_process.hpp:92
BuildContactModelPartProcess(ModelPart &rModelPart, MesherUtilities::MeshingParameters &rRemeshingParameters, std::vector< std::string > &rContactModelParts, int EchoLevel)
Default constructor.
Definition: build_contact_model_part_process.hpp:78
std::string Info() const override
Turn back information as a string.
Definition: build_contact_model_part_process.hpp:162
ConditionType::GeometryType GeometryType
Definition: build_contact_model_part_process.hpp:71
void operator()()
Definition: build_contact_model_part_process.hpp:111
void Execute() override
Execute method is used to execute the Process algorithms.
Definition: build_contact_model_part_process.hpp:121
ModelPart::PropertiesType PropertiesType
Definition: build_contact_model_part_process.hpp:70
KRATOS_CLASS_POINTER_DEFINITION(BuildContactModelPartProcess)
Pointer definition of BuildContactModelPartProcess.
virtual ~BuildContactModelPartProcess()
Destructor.
Definition: build_contact_model_part_process.hpp:102
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: build_contact_model_part_process.hpp:174
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: build_contact_model_part_process.hpp:168
Base class for all Conditions.
Definition: condition.h:59
void Set(const Flags ThisFlag)
Definition: flags.cpp:33
Geometry base class.
Definition: geometry.h:71
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
ConditionIterator ConditionsBegin(IndexType ThisIndex=0)
Definition: model_part.h:1361
void AddNode(NodeType::Pointer pNewNode, IndexType ThisIndex=0)
Definition: model_part.cpp:211
NodeIterator NodesBegin(IndexType ThisIndex=0)
Definition: model_part.h:487
ConditionsContainerType & Conditions(IndexType ThisIndex=0)
Definition: model_part.h:1381
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
ElementsContainerType & Elements(IndexType ThisIndex=0)
Definition: model_part.h:1189
void AddCondition(ConditionType::Pointer pNewCondition, IndexType ThisIndex=0)
Definition: model_part.cpp:1436
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
NodeIterator NodesEnd(IndexType ThisIndex=0)
Definition: model_part.h:497
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
ConditionIterator ConditionsEnd(IndexType ThisIndex=0)
Definition: model_part.h:1371
void swap(PointerVectorSet &rOther)
Swaps the contents of this PointerVectorSet with another.
Definition: pointer_vector_set.h:532
The base class for all processes in Kratos.
Definition: process.h:49
Properties encapsulates data shared by different Elements or Conditions. It can store any type of dat...
Definition: properties.h:69
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
Kratos::ModelPart ModelPart
Definition: kratos_wrapper.h:31
static int EchoLevel
Definition: co_sim_EMPIRE_API.h:42
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
ProcessInfo
Definition: edgebased_PureConvection.py:116
int dimension
Definition: isotropic_damage_automatic_differentiation.py:123
Definition: mesher_utilities.hpp:631
TransferParametersType::Pointer GetTransferParameters()
Definition: mesher_utilities.hpp:828
std::string SubModelPartName
Definition: mesher_utilities.hpp:642
void SetHoles(std::vector< BoundedVector< double, 3 >> &rHoles)
Definition: mesher_utilities.hpp:803