10 #if !defined(KRATOS_TRANSFER_SOLVING_MODEL_PART_ENTITIES_PROCESS_H_INCLUDED)
11 #define KRATOS_TRANSFER_SOLVING_MODEL_PART_ENTITIES_PROCESS_H_INCLUDED
18 #include "custom_processes/transfer_entities_between_model_parts_process.hpp"
47 ) :
Process(), mrModelPart(rModelPart)
53 "model_part_name": "new_computing_domain",
55 "composite_conditions": false,
56 "transfer_entities": [],
57 "generate_entities": []
64 mSolvingModelPartName = rParameters[
"model_part_name"].
GetString();
69 for(
unsigned int i = 0;
i<rParameters[
"assign_flags"].
size();
i++)
72 mCompositeConditions = rParameters[
"composite_conditions"].
GetBool();
74 for(
unsigned int i=0;
i<rParameters[
"transfer_entities"].
size(); ++
i)
76 Parameters EntitiesTransfer = rParameters[
"transfer_entities"][
i];
77 this->AddToEntitiesTransferList(EntitiesTransfer);
80 for(
unsigned int i=0;
i<rParameters[
"generate_entities"].
size(); ++
i)
82 Parameters EntitiesGeneration = rParameters[
"generate_entities"][
i];
83 this->AddToEntitiesGenerationList(EntitiesGeneration);
118 SolvingModelPart.
Nodes().clear();
120 SolvingModelPart.Elements().clear();
122 SolvingModelPart.Conditions().clear();
124 if( mElementGenerationList.size() != 0 || mConditionGenerationList.size() != 0 ){
125 this->GenerateAndTransferEntities(SolvingModelPart, mElementGenerationList, mConditionGenerationList);
128 if( mNodeTransferList.size()!=0 || mElementTransferList.size() != 0 || mConditionTransferList.size() != 0 ){
129 this->TransferEntities(SolvingModelPart, mNodeTransferList, mElementTransferList, mConditionTransferList);
132 if( mCompositeConditions ){
133 this->TransferBoundaryConditions(SolvingModelPart,mrModelPart);
137 SolvingModelPart.SetProperties( mrModelPart.
pProperties() );
140 SolvingModelPart.Tables() = mrModelPart.
Tables();
143 SolvingModelPart.SetCommunicator(pComm);
164 std::string
Info()
const override
166 return "TransferSolvingModelPartEntitiesProcess";
172 rOStream <<
"TransferSolvingModelPartEntitiesProcess";
216 template<
class EntityType>
221 const EntityType* mpEntityType;
226 std::vector<ModelPart*> OriginModelParts;
227 std::vector<Flags> TransferFlags;
233 void SetEntityType(
const EntityType& rEntityType) {mpEntityType = &rEntityType;};
236 const EntityType& GetEntityType()
const {
return *mpEntityType;};
248 std::string mSolvingModelPartName;
250 bool mCompositeConditions;
252 std::vector<EntityTransfer<NodeType> > mNodeTransferList;
254 std::vector<EntityTransfer<ElementType> > mElementTransferList;
256 std::vector<EntityTransfer<ConditionType> > mConditionTransferList;
258 std::vector<EntityTransfer<ElementType> > mElementGenerationList;
260 std::vector<EntityTransfer<ConditionType> > mConditionGenerationList;
273 void AddToEntitiesTransferList(Parameters& rParameters)
275 Parameters default_parameters( R
"(
277 "origin_model_parts_list": [],
278 "entity_type": "Element",
279 "transfer_flags" : [],
284 rParameters.ValidateAndAssignDefaults(default_parameters);
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)
290 Entity.OriginModelParts.push_back(&mrModelPart.GetSubModelPart(rParameters[
"origin_model_parts_list"][
i].GetString()));
292 for(
unsigned int i=0;
i<rParameters[
"transfer_flags"].size(); ++
i)
296 for(
unsigned int i=0;
i<rParameters[
"assign_flags"].size(); ++
i)
300 mNodeTransferList.push_back( Entity );
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)
306 Entity.OriginModelParts.push_back(&mrModelPart.GetSubModelPart(rParameters[
"origin_model_parts_list"][
i].GetString()));
308 for(
unsigned int i=0;
i<rParameters[
"transfer_flags"].size(); ++
i)
312 for(
unsigned int i=0;
i<rParameters[
"assign_flags"].size(); ++
i)
316 mElementTransferList.push_back( Entity );
318 else if( rParameters[
"entity_type"].GetString() ==
"Condition" )
320 EntityTransfer<ConditionType> Entity;
321 for(
unsigned int i=0;
i<rParameters[
"origin_model_parts_list"].size(); ++
i)
323 Entity.OriginModelParts.push_back(&mrModelPart.GetSubModelPart(rParameters[
"origin_model_parts_list"][
i].GetString()));
325 for(
unsigned int i=0;
i<rParameters[
"transfer_flags"].size(); ++
i)
329 for(
unsigned int i=0;
i<rParameters[
"assign_flags"].size(); ++
i)
333 mConditionTransferList.push_back( Entity );
342 void AddToEntitiesGenerationList(Parameters& rParameters)
344 Parameters default_parameters( R
"(
346 "origin_model_parts_list": [],
347 "entity_type": "Element",
348 "transfer_flags": [],
350 "entity_kratos_type": "ElementType"
354 rParameters.ValidateAndAssignDefaults(default_parameters);
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)
360 Entity.OriginModelParts.push_back(&mrModelPart.GetSubModelPart(rParameters[
"origin_model_parts_list"][
i].GetString()));
362 for(
unsigned int i=0;
i<rParameters[
"transfer_flags"].size(); ++
i)
366 for(
unsigned int i=0;
i<rParameters[
"assign_flags"].size(); ++
i)
370 Entity.SetEntityType(rParameters[
"entity_kratos_type"].GetString());
371 mElementGenerationList.push_back( Entity );
373 else if( rParameters[
"entity_type"].GetString() ==
"Condition" )
375 EntityTransfer<ConditionType> Entity;
376 for(
unsigned int i=0;
i<rParameters[
"origin_model_parts_list"].size(); ++
i)
378 Entity.OriginModelParts.push_back(&mrModelPart.GetSubModelPart(rParameters[
"origin_model_parts_list"][
i].GetString()));
380 for(
unsigned int i=0;
i<rParameters[
"transfer_flags"].size(); ++
i)
384 for(
unsigned int i=0;
i<rParameters[
"assign_flags"].size(); ++
i)
388 Entity.SetEntityType(rParameters[
"entity_kratos_type"].GetString());
389 mConditionGenerationList.push_back( Entity );
400 void GenerateAndTransferEntities(ModelPart& rDestinationModelPart,
401 std::vector<EntityTransfer<ElementType> >& rElementGenerationList,
402 std::vector<EntityTransfer<ConditionType> >& rConditionGenerationList)
407 for(std::vector<EntityTransfer<Element> >::iterator i_entity = rElementGenerationList.begin(); i_entity != rElementGenerationList.end(); ++i_entity)
409 for(std::vector<ModelPart*>::iterator i_part = i_entity->OriginModelParts.begin(); i_part != i_entity->OriginModelParts.end(); ++i_part)
411 for(ModelPart::ElementsContainerType::iterator i_elem = (*i_part)->ElementsBegin(); i_elem != (*i_part)->ElementsEnd(); ++i_elem)
413 if (this->MatchFlags(*(i_elem.base()),i_entity->TransferFlags))
415 Properties::Pointer pProperties = i_elem->pGetProperties();
416 Element::Pointer pElement = i_entity->GetEntityType().Create(i_elem->Id(), i_elem->GetGeometry(), pProperties);
419 pElement->SetValue(MASTER_ELEMENT,Element::WeakPointer(*i_elem.base()));
421 rDestinationModelPart.Elements().push_back(pElement);
428 for(std::vector<EntityTransfer<Condition> >::iterator i_entity = rConditionGenerationList.begin(); i_entity != rConditionGenerationList.end(); ++i_entity)
430 for(std::vector<ModelPart*>::iterator i_part = i_entity->OriginModelParts.begin(); i_part != i_entity->OriginModelParts.end(); ++i_part)
433 for (ModelPart::ConditionsContainerType::iterator i_cond = (*i_part)->ConditionsBegin(); i_cond != (*i_part)->ConditionsEnd(); ++i_cond)
435 if (this->MatchFlags(*(i_cond.base()),i_entity->TransferFlags))
437 Properties::Pointer pProperties = i_cond->pGetProperties();
438 Condition::Pointer pCondition = i_entity->GetEntityType().Create(i_cond->Id(), i_cond->GetGeometry(), pProperties);
441 pCondition->GetData() = i_cond->GetData();
443 rDestinationModelPart.Conditions().push_back(pCondition);
453 void TransferEntities(ModelPart& rDestinationModelPart,
454 std::vector<EntityTransfer<NodeType> >& rNodeTransferList,
455 std::vector<EntityTransfer<ElementType> >& rElementTransferList,
456 std::vector<EntityTransfer<ConditionType> >& rConditionTransferList)
461 std::string Nodes =
"Nodes";
464 for(std::vector<EntityTransfer<NodeType> >::iterator i_entity = rNodeTransferList.begin(); i_entity != rNodeTransferList.end(); ++i_entity)
466 for(std::vector<ModelPart*>::iterator i_part = i_entity->OriginModelParts.begin(); i_part != i_entity->OriginModelParts.end(); ++i_part)
468 TransferEntitiesBetweenModelPartsProcess NodesTransferProcess(rDestinationModelPart, *(*i_part), Nodes, i_entity->TransferFlags, i_entity->AssignFlags);
469 NodesTransferProcess.Execute();
473 std::string Elements =
"Elements";
476 for(std::vector<EntityTransfer<ElementType> >::iterator i_entity = rElementTransferList.begin(); i_entity != rElementTransferList.end(); ++i_entity)
478 for(std::vector<ModelPart*>::iterator i_part = i_entity->OriginModelParts.begin(); i_part != i_entity->OriginModelParts.end(); ++i_part)
480 TransferEntitiesBetweenModelPartsProcess ElementsTransferProcess(rDestinationModelPart, *(*i_part), Elements, i_entity->TransferFlags, i_entity->AssignFlags);
481 ElementsTransferProcess.Execute();
485 std::string Conditions =
"Conditions";
488 for(std::vector<EntityTransfer<ConditionType> >::iterator i_entity = rConditionTransferList.begin(); i_entity != rConditionTransferList.end(); ++i_entity)
490 for(std::vector<ModelPart*>::iterator i_part = i_entity->OriginModelParts.begin(); i_part != i_entity->OriginModelParts.end(); ++i_part)
492 TransferEntitiesBetweenModelPartsProcess ConditionsTransferProcess(rDestinationModelPart, *(*i_part), Conditions, i_entity->TransferFlags, i_entity->AssignFlags);
493 ConditionsTransferProcess.Execute();
501 void TransferBoundaryConditions(ModelPart& rDestinationModelPart,
502 ModelPart& rOriginModelPart)
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();
516 bool MatchFlags(
const Element::Pointer& pElement,
const std::vector<Flags>& rFlags)
519 for(
unsigned int i = 0;
i<rFlags.size();
i++)
521 if( pElement->IsNot(rFlags[
i]) )
529 bool MatchFlags(
const Condition::Pointer& pCondition,
const std::vector<Flags>& rFlags)
532 for(
unsigned int i = 0;
i<rFlags.size();
i++)
534 if( pCondition->IsNot(rFlags[
i]) )
581 rOStream << std::endl;
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