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.
transfer_solving_model_part_entities_process.hpp
Go to the documentation of this file.
1 //
2 // Project Name: KratosSolidMechanicsApplication $
3 // Created by: $Author: JMCarbonell $
4 // Last modified by: $Co-Author: $
5 // Date: $Date: July 2018 $
6 // Revision: $Revision: 0.0 $
7 //
8 //
9 
10 #if !defined(KRATOS_TRANSFER_SOLVING_MODEL_PART_ENTITIES_PROCESS_H_INCLUDED)
11 #define KRATOS_TRANSFER_SOLVING_MODEL_PART_ENTITIES_PROCESS_H_INCLUDED
12 
13 // System includes
14 
15 // External includes
16 
17 // Project includes
18 #include "custom_processes/transfer_entities_between_model_parts_process.hpp"
20 
21 namespace Kratos
22 {
23 
26 
28 
30 {
31 public:
34 
35  typedef Node NodeType;
38 
41 
46  Parameters rParameters
47  ) : Process(), mrModelPart(rModelPart)
48  {
50 
51  Parameters default_parameters( R"(
52  {
53  "model_part_name": "new_computing_domain",
54  "assign_flags": [],
55  "composite_conditions": false,
56  "transfer_entities": [],
57  "generate_entities": []
58  } )" );
59 
60 
61  // Validate against defaults -- this ensures no type mismatch
62  rParameters.ValidateAndAssignDefaults(default_parameters);
63 
64  mSolvingModelPartName = rParameters["model_part_name"].GetString();
65  if(!mrModelPart.HasSubModelPart(mSolvingModelPartName))
66  mrModelPart.CreateSubModelPart(mSolvingModelPartName);
67 
68 
69  for(unsigned int i = 0; i<rParameters["assign_flags"].size(); i++)
70  mrModelPart.GetSubModelPart(mSolvingModelPartName).Set(KratosComponents<Flags>::Get(rParameters["assign_flags"][i].GetString()));
71 
72  mCompositeConditions = rParameters["composite_conditions"].GetBool();
73 
74  for(unsigned int i=0; i<rParameters["transfer_entities"].size(); ++i)
75  {
76  Parameters EntitiesTransfer = rParameters["transfer_entities"][i];
77  this->AddToEntitiesTransferList(EntitiesTransfer);
78  }
79 
80  for(unsigned int i=0; i<rParameters["generate_entities"].size(); ++i)
81  {
82  Parameters EntitiesGeneration = rParameters["generate_entities"][i];
83  this->AddToEntitiesGenerationList(EntitiesGeneration);
84  }
85 
86  KRATOS_CATCH("")
87  }
88 
89 
92 
93 
97 
99  void operator()()
100  {
101  Execute();
102  }
103 
104 
108 
109 
111  void Execute() override
112  {
113  KRATOS_TRY
114 
115  ModelPart& SolvingModelPart = mrModelPart.GetSubModelPart(mSolvingModelPartName);
116 
117  //clear previous nodes
118  SolvingModelPart.Nodes().clear();
119  //clear previous elements
120  SolvingModelPart.Elements().clear();
121  //clear previous conditions
122  SolvingModelPart.Conditions().clear();
123 
124  if( mElementGenerationList.size() != 0 || mConditionGenerationList.size() != 0 ){
125  this->GenerateAndTransferEntities(SolvingModelPart, mElementGenerationList, mConditionGenerationList);
126  }
127 
128  if( mNodeTransferList.size()!=0 || mElementTransferList.size() != 0 || mConditionTransferList.size() != 0 ){
129  this->TransferEntities(SolvingModelPart, mNodeTransferList, mElementTransferList, mConditionTransferList);
130  }
131 
132  if( mCompositeConditions ){
133  this->TransferBoundaryConditions(SolvingModelPart,mrModelPart);
134  }
135 
136  //assigning Properties
137  SolvingModelPart.SetProperties( mrModelPart.pProperties() );
138 
139  //assigning Tables
140  SolvingModelPart.Tables() = mrModelPart.Tables();
141 
142  Communicator::Pointer pComm = mrModelPart.GetCommunicator().Create();
143  SolvingModelPart.SetCommunicator(pComm);
144 
145  KRATOS_CATCH("")
146  }
147 
148 
152 
153 
157 
158 
162 
164  std::string Info() const override
165  {
166  return "TransferSolvingModelPartEntitiesProcess";
167  }
168 
170  void PrintInfo(std::ostream& rOStream) const override
171  {
172  rOStream << "TransferSolvingModelPartEntitiesProcess";
173  }
174 
176  void PrintData(std::ostream& rOStream) const override
177  {
178  }
179 
180 
185 
186 protected:
187 
196 
199 
213 
214 private:
215 
216  template<class EntityType>
217  class EntityTransfer
218  {
219  private:
220  // member variables
221  const EntityType* mpEntityType;
222 
223  public:
224 
225  //variables
226  std::vector<ModelPart*> OriginModelParts;
227  std::vector<Flags> TransferFlags;
228  std::vector<Flags> AssignFlags;
229 
230  // set methods
231  void SetEntityType(const std::string& rName) {mpEntityType = &(KratosComponents<EntityType>::Get(rName));};
232 
233  void SetEntityType(const EntityType& rEntityType) {mpEntityType = &rEntityType;};
234 
235  // get methods
236  const EntityType& GetEntityType() const {return *mpEntityType;};
237  };
238 
239 
245 
246  ModelPart& mrModelPart;
247 
248  std::string mSolvingModelPartName;
249 
250  bool mCompositeConditions;
251 
252  std::vector<EntityTransfer<NodeType> > mNodeTransferList;
253 
254  std::vector<EntityTransfer<ElementType> > mElementTransferList;
255 
256  std::vector<EntityTransfer<ConditionType> > mConditionTransferList;
257 
258  std::vector<EntityTransfer<ElementType> > mElementGenerationList;
259 
260  std::vector<EntityTransfer<ConditionType> > mConditionGenerationList;
261 
268 
269 
270  //**********************************************************************************************
271  //**********************************************************************************************
272 
273  void AddToEntitiesTransferList(Parameters& rParameters)
274  {
275  Parameters default_parameters( R"(
276  {
277  "origin_model_parts_list": [],
278  "entity_type": "Element",
279  "transfer_flags" : [],
280  "assign_flags" : []
281  } )" );
282 
283  // Validate against defaults -- this ensures no type mismatch
284  rParameters.ValidateAndAssignDefaults(default_parameters);
285 
286  if( rParameters["entity_type"].GetString() == "Node" ){
287  EntityTransfer<NodeType> Entity;
288  for( unsigned int i=0; i<rParameters["origin_model_parts_list"].size(); ++i)
289  {
290  Entity.OriginModelParts.push_back(&mrModelPart.GetSubModelPart(rParameters["origin_model_parts_list"][i].GetString()));
291  }
292  for(unsigned int i=0; i<rParameters["transfer_flags"].size(); ++i)
293  {
294  Entity.TransferFlags.push_back(KratosComponents<Flags>::Get(rParameters["transfer_flags"][i].GetString()));
295  }
296  for(unsigned int i=0; i<rParameters["assign_flags"].size(); ++i)
297  {
298  Entity.AssignFlags.push_back(KratosComponents<Flags>::Get(rParameters["assign_flags"][i].GetString()));
299  }
300  mNodeTransferList.push_back( Entity );
301  }
302  else if( rParameters["entity_type"].GetString() == "Element" ){
303  EntityTransfer<ElementType> Entity;
304  for( unsigned int i=0; i<rParameters["origin_model_parts_list"].size(); ++i)
305  {
306  Entity.OriginModelParts.push_back(&mrModelPart.GetSubModelPart(rParameters["origin_model_parts_list"][i].GetString()));
307  }
308  for(unsigned int i=0; i<rParameters["transfer_flags"].size(); ++i)
309  {
310  Entity.TransferFlags.push_back(KratosComponents<Flags>::Get(rParameters["transfer_flags"][i].GetString()));
311  }
312  for(unsigned int i=0; i<rParameters["assign_flags"].size(); ++i)
313  {
314  Entity.AssignFlags.push_back(KratosComponents<Flags>::Get(rParameters["assign_flags"][i].GetString()));
315  }
316  mElementTransferList.push_back( Entity );
317  }
318  else if( rParameters["entity_type"].GetString() == "Condition" )
319  {
320  EntityTransfer<ConditionType> Entity;
321  for( unsigned int i=0; i<rParameters["origin_model_parts_list"].size(); ++i)
322  {
323  Entity.OriginModelParts.push_back(&mrModelPart.GetSubModelPart(rParameters["origin_model_parts_list"][i].GetString()));
324  }
325  for(unsigned int i=0; i<rParameters["transfer_flags"].size(); ++i)
326  {
327  Entity.TransferFlags.push_back(KratosComponents<Flags>::Get(rParameters["transfer_flags"][i].GetString()));
328  }
329  for(unsigned int i=0; i<rParameters["assign_flags"].size(); ++i)
330  {
331  Entity.AssignFlags.push_back(KratosComponents<Flags>::Get(rParameters["assign_flags"][i].GetString()));
332  }
333  mConditionTransferList.push_back( Entity );
334  }
335 
336  }
337 
338 
339  //**********************************************************************************************
340  //**********************************************************************************************
341 
342  void AddToEntitiesGenerationList(Parameters& rParameters)
343  {
344  Parameters default_parameters( R"(
345  {
346  "origin_model_parts_list": [],
347  "entity_type": "Element",
348  "transfer_flags": [],
349  "assign_flags": [],
350  "entity_kratos_type": "ElementType"
351  } )" );
352 
353  // Validate against defaults -- this ensures no type mismatch
354  rParameters.ValidateAndAssignDefaults(default_parameters);
355 
356  if( rParameters["entity_type"].GetString() == "Element" ){
357  EntityTransfer<ElementType> Entity;
358  for( unsigned int i=0; i<rParameters["origin_model_parts_list"].size(); ++i)
359  {
360  Entity.OriginModelParts.push_back(&mrModelPart.GetSubModelPart(rParameters["origin_model_parts_list"][i].GetString()));
361  }
362  for(unsigned int i=0; i<rParameters["transfer_flags"].size(); ++i)
363  {
364  Entity.TransferFlags.push_back(KratosComponents<Flags>::Get(rParameters["transfer_flags"][i].GetString()));
365  }
366  for(unsigned int i=0; i<rParameters["assign_flags"].size(); ++i)
367  {
368  Entity.AssignFlags.push_back(KratosComponents<Flags>::Get(rParameters["assign_flags"][i].GetString()));
369  }
370  Entity.SetEntityType(rParameters["entity_kratos_type"].GetString());
371  mElementGenerationList.push_back( Entity );
372  }
373  else if( rParameters["entity_type"].GetString() == "Condition" )
374  {
375  EntityTransfer<ConditionType> Entity;
376  for( unsigned int i=0; i<rParameters["origin_model_parts_list"].size(); ++i)
377  {
378  Entity.OriginModelParts.push_back(&mrModelPart.GetSubModelPart(rParameters["origin_model_parts_list"][i].GetString()));
379  }
380  for(unsigned int i=0; i<rParameters["transfer_flags"].size(); ++i)
381  {
382  Entity.TransferFlags.push_back(KratosComponents<Flags>::Get(rParameters["transfer_flags"][i].GetString()));
383  }
384  for(unsigned int i=0; i<rParameters["assign_flags"].size(); ++i)
385  {
386  Entity.AssignFlags.push_back(KratosComponents<Flags>::Get(rParameters["assign_flags"][i].GetString()));
387  }
388  Entity.SetEntityType(rParameters["entity_kratos_type"].GetString());
389  mConditionGenerationList.push_back( Entity );
390  }
391  }
392 
393  //**********************************************************************************************
394  //**********************************************************************************************
395 
399 
400  void GenerateAndTransferEntities(ModelPart& rDestinationModelPart,
401  std::vector<EntityTransfer<ElementType> >& rElementGenerationList,
402  std::vector<EntityTransfer<ConditionType> >& rConditionGenerationList)
403  {
404  KRATOS_TRY
405 
406  //generate elements
407  for(std::vector<EntityTransfer<Element> >::iterator i_entity = rElementGenerationList.begin(); i_entity != rElementGenerationList.end(); ++i_entity)
408  {
409  for(std::vector<ModelPart*>::iterator i_part = i_entity->OriginModelParts.begin(); i_part != i_entity->OriginModelParts.end(); ++i_part)
410  {
411  for(ModelPart::ElementsContainerType::iterator i_elem = (*i_part)->ElementsBegin(); i_elem != (*i_part)->ElementsEnd(); ++i_elem)
412  {
413  if (this->MatchFlags(*(i_elem.base()),i_entity->TransferFlags))
414  {
415  Properties::Pointer pProperties = i_elem->pGetProperties();
416  Element::Pointer pElement = i_entity->GetEntityType().Create(i_elem->Id(), i_elem->GetGeometry(), pProperties);
417 
418  //set origin element as pointer
419  pElement->SetValue(MASTER_ELEMENT,Element::WeakPointer(*i_elem.base()));
420 
421  rDestinationModelPart.Elements().push_back(pElement);
422  }
423  }
424  }
425  }
426 
427  //generate conditions
428  for(std::vector<EntityTransfer<Condition> >::iterator i_entity = rConditionGenerationList.begin(); i_entity != rConditionGenerationList.end(); ++i_entity)
429  {
430  for(std::vector<ModelPart*>::iterator i_part = i_entity->OriginModelParts.begin(); i_part != i_entity->OriginModelParts.end(); ++i_part)
431  {
432  //generate contact conditions
433  for (ModelPart::ConditionsContainerType::iterator i_cond = (*i_part)->ConditionsBegin(); i_cond != (*i_part)->ConditionsEnd(); ++i_cond)
434  {
435  if (this->MatchFlags(*(i_cond.base()),i_entity->TransferFlags))
436  {
437  Properties::Pointer pProperties = i_cond->pGetProperties();
438  Condition::Pointer pCondition = i_entity->GetEntityType().Create(i_cond->Id(), i_cond->GetGeometry(), pProperties);
439 
440  //set mechanical variables to contact conditions:
441  pCondition->GetData() = i_cond->GetData();
442 
443  rDestinationModelPart.Conditions().push_back(pCondition);
444  }
445  }
446  }
447  }
448 
449  KRATOS_CATCH("")
450  }
451 
452 
453  void TransferEntities(ModelPart& rDestinationModelPart,
454  std::vector<EntityTransfer<NodeType> >& rNodeTransferList,
455  std::vector<EntityTransfer<ElementType> >& rElementTransferList,
456  std::vector<EntityTransfer<ConditionType> >& rConditionTransferList)
457  {
458  KRATOS_TRY
459 
460 
461  std::string Nodes = "Nodes";
462 
463  //transfer nodes
464  for(std::vector<EntityTransfer<NodeType> >::iterator i_entity = rNodeTransferList.begin(); i_entity != rNodeTransferList.end(); ++i_entity)
465  {
466  for(std::vector<ModelPart*>::iterator i_part = i_entity->OriginModelParts.begin(); i_part != i_entity->OriginModelParts.end(); ++i_part)
467  {
468  TransferEntitiesBetweenModelPartsProcess NodesTransferProcess(rDestinationModelPart, *(*i_part), Nodes, i_entity->TransferFlags, i_entity->AssignFlags);
469  NodesTransferProcess.Execute();
470  }
471  }
472 
473  std::string Elements = "Elements";
474 
475  //transfer elements
476  for(std::vector<EntityTransfer<ElementType> >::iterator i_entity = rElementTransferList.begin(); i_entity != rElementTransferList.end(); ++i_entity)
477  {
478  for(std::vector<ModelPart*>::iterator i_part = i_entity->OriginModelParts.begin(); i_part != i_entity->OriginModelParts.end(); ++i_part)
479  {
480  TransferEntitiesBetweenModelPartsProcess ElementsTransferProcess(rDestinationModelPart, *(*i_part), Elements, i_entity->TransferFlags, i_entity->AssignFlags);
481  ElementsTransferProcess.Execute();
482  }
483  }
484 
485  std::string Conditions = "Conditions";
486 
487  //transfer conditions
488  for(std::vector<EntityTransfer<ConditionType> >::iterator i_entity = rConditionTransferList.begin(); i_entity != rConditionTransferList.end(); ++i_entity)
489  {
490  for(std::vector<ModelPart*>::iterator i_part = i_entity->OriginModelParts.begin(); i_part != i_entity->OriginModelParts.end(); ++i_part)
491  {
492  TransferEntitiesBetweenModelPartsProcess ConditionsTransferProcess(rDestinationModelPart, *(*i_part), Conditions, i_entity->TransferFlags, i_entity->AssignFlags);
493  ConditionsTransferProcess.Execute();
494  }
495  }
496 
497  KRATOS_CATCH("")
498  }
499 
500 
501  void TransferBoundaryConditions(ModelPart& rDestinationModelPart,
502  ModelPart& rOriginModelPart)
503  {
504  KRATOS_TRY
505 
506  std::vector<Flags> BoundaryFlags;
507  BoundaryFlags.push_back(BOUNDARY);
508  std::string Conditions = "Conditions";
509  TransferEntitiesBetweenModelPartsProcess ConditionsTransferProcess(rDestinationModelPart, rOriginModelPart, Conditions, BoundaryFlags);
510  ConditionsTransferProcess.Execute();
511 
512  KRATOS_CATCH("")
513  }
514 
515 
516  bool MatchFlags(const Element::Pointer& pElement, const std::vector<Flags>& rFlags)
517  {
518 
519  for(unsigned int i = 0; i<rFlags.size(); i++)
520  {
521  if( pElement->IsNot(rFlags[i]) )
522  return false;
523  }
524 
525  return true;
526  }
527 
528 
529  bool MatchFlags(const Condition::Pointer& pCondition, const std::vector<Flags>& rFlags)
530  {
531 
532  for(unsigned int i = 0; i<rFlags.size(); i++)
533  {
534  if( pCondition->IsNot(rFlags[i]) )
535  return false;
536  }
537 
538  return true;
539  }
540 
544 
547 
548 
558 
559 }; // Class TransferSolvingModelPartEntitiesProcess
560 
562 
565 
566 
570 
571 
573 inline std::istream& operator >> (std::istream& rIStream,
575 
577 inline std::ostream& operator << (std::ostream& rOStream,
579 {
580  rThis.PrintInfo(rOStream);
581  rOStream << std::endl;
582  rThis.PrintData(rOStream);
583 
584  return rOStream;
585 }
587 
588 
589 } // namespace Kratos.
590 
591 #endif // KRATOS_TRANSFER_SOLVING_MODEL_PART_ENTITIES_PROCESS_H_INCLUDED defined
virtual Communicator::Pointer Create(const DataCommunicator &rDataCommunicator) const
Definition: communicator.cpp:70
Base class for all Conditions.
Definition: condition.h:59
Base class for all Elements.
Definition: element.h:60
void Set(const Flags ThisFlag)
Definition: flags.cpp:33
void AssignFlags(Flags const &rOther)
Definition: flags.h:179
KratosComponents class encapsulates a lookup table for a family of classes in a generic way.
Definition: kratos_components.h:49
static const TComponentType & Get(const std::string &rName)
Retrieves a component with the specified name.
Definition: kratos_components.h:114
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
Communicator & GetCommunicator()
Definition: model_part.h:1821
bool HasSubModelPart(std::string const &ThisSubModelPartName) const
Definition: model_part.cpp:2142
ModelPart & CreateSubModelPart(std::string const &NewSubModelPartName)
Definition: model_part.cpp:2000
PropertiesContainerType::Pointer pProperties(IndexType ThisIndex=0)
Definition: model_part.h:1008
ModelPart & GetSubModelPart(std::string const &SubModelPartName)
Definition: model_part.cpp:2029
TablesContainerType & Tables()
Definition: model_part.h:635
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
This class defines the node.
Definition: node.h:65
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
void ValidateAndAssignDefaults(const Parameters &rDefaultParameters)
This function is designed to verify that the parameters under testing match the form prescribed by th...
Definition: kratos_parameters.cpp:1306
SizeType size() const
This method returns the total size of the current array parameter.
Definition: kratos_parameters.cpp:993
std::string GetString() const
This method returns the string contained in the current Parameter.
Definition: kratos_parameters.cpp:684
bool GetBool() const
This method returns the boolean contained in the current Parameter.
Definition: kratos_parameters.cpp:675
The base class for all processes in Kratos.
Definition: process.h:49
Process to transfer model part entities to a solving submodelpart.
Definition: transfer_solving_model_part_entities_process.hpp:30
std::string Info() const override
Turn back information as a string.
Definition: transfer_solving_model_part_entities_process.hpp:164
~TransferSolvingModelPartEntitiesProcess() override
Destructor.
Definition: transfer_solving_model_part_entities_process.hpp:91
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: transfer_solving_model_part_entities_process.hpp:176
Condition ConditionType
Definition: transfer_solving_model_part_entities_process.hpp:36
KRATOS_CLASS_POINTER_DEFINITION(TransferSolvingModelPartEntitiesProcess)
Pointer definition of TransferSolvingModelPartEntitiesProcess.
void operator()()
This operator is provided to call the process as a function and simply calls the Execute method.
Definition: transfer_solving_model_part_entities_process.hpp:99
TransferSolvingModelPartEntitiesProcess(ModelPart &rModelPart, Parameters rParameters)
Definition: transfer_solving_model_part_entities_process.hpp:45
Element ElementType
Definition: transfer_solving_model_part_entities_process.hpp:37
void Execute() override
Execute method is used to execute the TransferSolvingModelPartEntitiesProcess algorithms.
Definition: transfer_solving_model_part_entities_process.hpp:111
TransferSolvingModelPartEntitiesProcess(TransferSolvingModelPartEntitiesProcess const &rOther)
Copy constructor.
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: transfer_solving_model_part_entities_process.hpp:170
Node NodeType
Definition: transfer_solving_model_part_entities_process.hpp:35
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
Kratos::ModelPart ModelPart
Definition: kratos_wrapper.h:31
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
integer i
Definition: TensorModule.f:17