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.
generate_new_contact_conditions_mesher_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_GENERATE_NEW_CONTACT_CONDITIONS_MESHER_PROCESS_H_INCLUDED )
11 #define KRATOS_GENERATE_NEW_CONTACT_CONDITIONS_MESHER_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"
25 
27 //Data: MASTER_ELEMENTS(set), MASTER_CONDITION(set)
28 //StepData:
29 //Flags: (checked)
30 // (set) CONTACT(set)
31 // (modified)
32 // (reset)
33 // (set):=(set in this process)
34 
35 namespace Kratos
36 {
37 
40 
44 
48 
52 
56 
58 
61  : public MesherProcess
62  {
63  public:
66 
69 
73 
77 
80  MesherUtilities::MeshingParameters& rRemeshingParameters,
81  int EchoLevel)
82  : mrModelPart(rModelPart),
83  mrRemesh(rRemeshingParameters)
84  {
85  mEchoLevel = EchoLevel;
86  }
87 
90  {
91  }
92 
93 
97 
98  void operator()()
99  {
100  Execute();
101  }
102 
103 
107 
108  void Execute() override
109  {
110  KRATOS_TRY
111 
112  if( mEchoLevel > 0 ){
113  std::cout<<" [ GENERATE NEW CONTACT ELEMENTS: "<<std::endl;
114  std::cout<<" Total Conditions BEFORE: ["<<mrModelPart.Conditions().size()<<"] ];"<<std::endl;
115  }
116 
117  if( mrModelPart.Name() != mrRemesh.SubModelPartName )
118  std::cout<<" ModelPart Supplied do not corresponds to the Meshing Domain: ("<<mrModelPart.Name()<<" != "<<mrRemesh.SubModelPartName<<")"<<std::endl;
119 
120  //*******************************************************************
121  //selecting elements
122  if( !mrRemesh.MeshElementsSelectedFlag ) //Select Mesh Elements not performed ... is needed to be done before building new elements
123  {
124  std::cout<<" ERROR : no selection of elements performed before building the elements "<<std::endl;
125  SelectElementsMesherProcess SelectElements(mrModelPart,mrRemesh,mEchoLevel);
126  SelectElements.Execute();
127  }
128 
129 
130  //*******************************************************************
131  //set consecutive ids for global conditions
132  int id=1;
133  for(ModelPart::ConditionsContainerType::iterator i_cond = mrModelPart.GetParentModelPart().ConditionsBegin() ; i_cond != mrModelPart.GetParentModelPart().ConditionsEnd(); ++i_cond)
134  {
135  i_cond->SetId(id);
136  id++;
137  }
138 
139  //*******************************************************************
140  //properties to be used in the generation
141  Properties::Pointer pProperties = mrRemesh.GetProperties();
142 
143  Condition const & rReferenceCondition=mrRemesh.GetReferenceCondition(); //contact element
144 
145  const unsigned int nds = rReferenceCondition.GetGeometry().size();
146 
147  if( mEchoLevel > 0 )
148  std::cout<<" [START contact Element Generation "<<std::endl;
149 
150  int& OutNumberOfElements = mrRemesh.OutMesh.GetNumberOfElements();
151  int* OutElementList = mrRemesh.OutMesh.GetElementList();
152 
153  int previous_id = mrModelPart.GetParentModelPart().Conditions().back().Id();
154  id = previous_id;
155 
156  ModelPart::NodesContainerType::iterator nodes_begin = mrModelPart.NodesBegin();
157 
158  for(int el = 0; el<OutNumberOfElements; ++el)
159  {
160  if(mrRemesh.PreservedElements[el])
161  {
162  Geometry<Node > Vertices;
163  for(unsigned int i=0; i<nds; ++i)
164  {
165  //note that OutElementList, starts from node 1, not from node 0, it can be directly assigned to mrRemesh.NodalPreIds.
166 
167  // detected problems in find() method for mesh nodes
168  // bool node_exists = mrModelPart.GetMesh().HasNode(OutElementList[el*nds+i]);
169  // if(!node_exists){
170 
171  // std::cout<<" ERROR node "<<mrRemesh.NodalPreIds[OutElementList[el*nds+i]]<<" is not in the modelpart "<<std::endl;
172  // std::cout<<" Element["<<el<<"] lnode["<<i<<"]: ["<<el*nds+i<<"] ElList["<<OutElementList[el*nds+i]<<"]: NODE "<<mrRemesh.NodalPreIds[OutElementList[el*nds+i]]<<std::endl;
173  // for(ModelPart::NodesContainerType::iterator i_node = mrModelPart.NodesBegin() ; i_node != mrModelPart.NodesEnd() ; ++i_node)
174  // {
175  // if( i_node->Id() == (unsigned int)mrRemesh.NodalPreIds[OutElementList[el*nds+i]] )
176  // std::cout<<" Node "<<i_node->Id()<<" is in Model PART !!!! "<<std::endl;
177  // }
178  // }
179 
180  Vertices.push_back(*(nodes_begin + OutElementList[el*nds+i]-1).base());
181  //Vertices.push_back(mrModelPart.pGetNode(mrRemesh.NodalPreIds[OutElementList[el*nds+i]]));
182  Vertices.back().Set(CONTACT);
183  }
184 
185  id += 1;
186 
187  Condition::Pointer pContactCondition = rReferenceCondition.Create(id, Vertices, pProperties);
188 
189 
190  //search the model part condition associated to this contact element MASTER CONDITION
191  //assign the MASTER ELEMENT and the MASTER NODE
192 
193  bool condition_found=false;
194  MesherUtilities MesherUtils;
195  Condition::Pointer pMasterCondition = MesherUtils.FindMasterCondition(pContactCondition,mrModelPart.Conditions(),condition_found);
196 
197  if(!condition_found){
198 
199  std::cout<<" MASTER CONDITION NOT FOUND: Contact Element Release "<<std::endl;
200  id -= 1;
201  }
202  else{
203 
204  // std::cout<<" contact master "<<std::endl;
205  // pMasterCondition->GetValue(MASTER_ELEMENTS)[0].PrintInfo(std::cout);
206  // pMasterCondition->GetValue(MASTER_ELEMENTS)[0].PrintData(std::cout);
207  // pMasterCondition->GetValue(MASTER_ELEMENTS)[0].GetProperties().PrintData(std::cout);
208  // std::cout<<std::endl;
209 
210  pContactCondition->SetValue(MASTER_CONDITION, pMasterCondition);
211  pContactCondition->SetValue(MASTER_ELEMENTS, pMasterCondition->GetValue(MASTER_ELEMENTS) );
212  pContactCondition->SetValue(MASTER_NODES, pMasterCondition->GetValue(MASTER_NODES) );
213 
214  if( pContactCondition->Is(SELECTED) ){ //two master nodes needed
215 
216  Element::ElementType& rMasterElement = pMasterCondition->GetValue(MASTER_ELEMENTS).back();
217  Geometry< Node >& rMasterGeometry = rMasterElement.GetGeometry();
218  Element::NodeType& rMasterNode = pContactCondition->GetValue(MASTER_NODES).back();
219  Geometry< Node >& rGeometry = pContactCondition->GetGeometry();
220 
221  std::vector<bool> edge_nodes(4);
222  std::fill(edge_nodes.begin(), edge_nodes.end(), false);
223 
224  for(unsigned int i=0; i<rMasterGeometry.PointsNumber(); ++i)
225  {
226  for(unsigned int j=0; j<rGeometry.PointsNumber(); ++j)
227  {
228  if(rGeometry[j].Id()==rMasterGeometry[i].Id()){
229  edge_nodes[i] = true;
230  break;
231  }
232  }
233  }
234 
235  for(unsigned int i=0; i<4; ++i)
236  {
237  if(!edge_nodes[i] && rMasterGeometry[i].Id() != rMasterNode.Id())
238  pContactCondition->GetValue(MASTER_NODES).push_back( rMasterGeometry(i) );
239  }
240  }
241 
242 
243  pContactCondition->SetValue(NORMAL, pMasterCondition->GetValue(NORMAL) );
244  pContactCondition->Set(CONTACT);
245 
246  //set ACTIVE if it is going to be considered in computation:
247  //here one can check the geometrical gap to dismiss some contact elements here
248  //it will be done later in the contact element calculation
249  pContactCondition->Set(ACTIVE);
250 
251  //setting new elements
252  mrModelPart.AddCondition(pContactCondition);
253 
254  }
255  }
256  }
257 
258 
259  //Restore global ID's
260  for(ModelPart::NodesContainerType::iterator in = mrModelPart.NodesBegin() ; in != mrModelPart.NodesEnd(); ++in)
261  {
262  in->SetId( mrRemesh.NodalPreIds[ in->Id() ] );
263  }
264 
265  if( mEchoLevel > 0 ){
266  std::cout<<" [END contact Elements Generation ["<<id-previous_id<<"] ]"<<std::endl;
267 
268  std::cout<<" Total Conditions AFTER: ["<<mrModelPart.Conditions().size()<<"] ];"<<std::endl;
269  }
270 
271 
272  std::cout<<" [Contact Candidates:"<<id-previous_id<<"]"<<std::endl;
273 
274 
275  KRATOS_CATCH(" ")
276  }
277 
278 
282 
283 
287 
288 
292 
294  std::string Info() const override
295  {
296  return "GenerateNewContactConditionsMesherProcess";
297  }
298 
300  void PrintInfo(std::ostream& rOStream) const override
301  {
302  rOStream << "GenerateNewContactConditionsMesherProcess";
303  }
304 
306  void PrintData(std::ostream& rOStream) const override
307  {
308  }
309 
310 
314 
315 
317 
318  protected:
321 
322 
326 
327 
331 
332 
336 
337 
341 
342 
346 
347 
351 
352 
354 
355  private:
358 
359 
363  ModelPart& mrModelPart;
364 
366 
367  int mEchoLevel;
368 
372 
373 
377 
378 
382 
383 
387 
388 
392 
395 
397  //GenerateNewContactConditionsMesherProcess(GenerateNewContactConditionsMesherProcess const& rOther);
398 
399 
401 
402  }; // Class GenerateNewContactConditionsMesherProcess
403 
405 
408 
409 
413 
414 
416  inline std::istream& operator >> (std::istream& rIStream,
418 
420  inline std::ostream& operator << (std::ostream& rOStream,
422  {
423  rThis.PrintInfo(rOStream);
424  rOStream << std::endl;
425  rThis.PrintData(rOStream);
426 
427  return rOStream;
428  }
430 
431 
432 } // namespace Kratos.
433 
434 #endif // KRATOS_GENERATE_NEW_CONTACT_CONDITIONS_MESHER_PROCESS_H_INCLUDED defined
Base class for all Conditions.
Definition: condition.h:59
virtual Pointer Create(IndexType NewId, NodesArrayType const &ThisNodes, PropertiesType::Pointer pProperties) const
It creates a new condition pointer.
Definition: condition.h:205
Base class for all Elements.
Definition: element.h:60
Short class definition.
Definition: generate_new_contact_conditions_mesher_process.hpp:62
ModelPart::ConditionType ConditionType
Definition: generate_new_contact_conditions_mesher_process.hpp:70
ModelPart::PropertiesType PropertiesType
Definition: generate_new_contact_conditions_mesher_process.hpp:71
GenerateNewContactConditionsMesherProcess(ModelPart &rModelPart, MesherUtilities::MeshingParameters &rRemeshingParameters, int EchoLevel)
Default constructor.
Definition: generate_new_contact_conditions_mesher_process.hpp:79
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: generate_new_contact_conditions_mesher_process.hpp:306
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: generate_new_contact_conditions_mesher_process.hpp:300
std::string Info() const override
Turn back information as a string.
Definition: generate_new_contact_conditions_mesher_process.hpp:294
void operator()()
Definition: generate_new_contact_conditions_mesher_process.hpp:98
ConditionType::GeometryType GeometryType
Definition: generate_new_contact_conditions_mesher_process.hpp:72
void Execute() override
Execute method is used to execute the Process algorithms.
Definition: generate_new_contact_conditions_mesher_process.hpp:108
KRATOS_CLASS_POINTER_DEFINITION(GenerateNewContactConditionsMesherProcess)
Pointer definition of GenerateNewContactConditionsMesherProcess.
virtual ~GenerateNewContactConditionsMesherProcess()
Destructor.
Definition: generate_new_contact_conditions_mesher_process.hpp:89
TVariableType::Type & GetValue(const TVariableType &rThisVariable)
Definition: geometrical_object.h:248
GeometryType & GetGeometry()
Returns the reference of the geometry.
Definition: geometrical_object.h:158
Geometry base class.
Definition: geometry.h:71
SizeType PointsNumber() const
Definition: geometry.h:528
void push_back(PointPointerType x)
Definition: geometry.h:548
SizeType size() const
Definition: geometry.h:518
PointReferenceType back()
Definition: geometry.h:507
The base class for processes passed to the solution scheme.
Definition: mesher_process.hpp:37
Short class definition.
Definition: mesher_utilities.hpp:49
Condition::Pointer FindMasterCondition(Condition::Pointer &pCondition, ModelPart::ConditionsContainerType &rModelConditions, bool &condition_found)
Definition: mesher_utilities.cpp:1642
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
ConditionIterator ConditionsBegin(IndexType ThisIndex=0)
Definition: model_part.h:1361
std::string & Name()
Definition: model_part.h:1811
NodeIterator NodesBegin(IndexType ThisIndex=0)
Definition: model_part.h:487
ConditionsContainerType & Conditions(IndexType ThisIndex=0)
Definition: model_part.h:1381
void AddCondition(ConditionType::Pointer pNewCondition, IndexType ThisIndex=0)
Definition: model_part.cpp:1436
NodeIterator NodesEnd(IndexType ThisIndex=0)
Definition: model_part.h:497
ModelPart & GetParentModelPart()
Definition: model_part.cpp:2124
ConditionIterator ConditionsEnd(IndexType ThisIndex=0)
Definition: model_part.h:1371
This class defines the node.
Definition: node.h:65
IndexType Id() const
Definition: node.h:262
TVariableType::Type & GetValue(const TVariableType &rThisVariable)
Definition: node.h:466
Properties encapsulates data shared by different Elements or Conditions. It can store any type of dat...
Definition: properties.h:69
Refine Mesh Elements Process 2D and 3D.
Definition: select_elements_mesher_process.hpp:47
void Execute() override
Execute method is used to execute the Process algorithms.
Definition: select_elements_mesher_process.hpp:95
#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
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
int j
Definition: quadrature.py:648
el
Definition: read_stl.py:25
integer i
Definition: TensorModule.f:17
int * GetElementList()
Definition: mesher_utilities.hpp:178
int & GetNumberOfElements()
Definition: mesher_utilities.hpp:183
Definition: mesher_utilities.hpp:631
Condition const & GetReferenceCondition()
Definition: mesher_utilities.hpp:847
std::vector< int > PreservedElements
Definition: mesher_utilities.hpp:669
bool MeshElementsSelectedFlag
Definition: mesher_utilities.hpp:662
MeshContainer OutMesh
Definition: mesher_utilities.hpp:675
PropertiesType::Pointer GetProperties()
Definition: mesher_utilities.hpp:838
std::string SubModelPartName
Definition: mesher_utilities.hpp:642
std::vector< int > NodalPreIds
Definition: mesher_utilities.hpp:668