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.
refine_elements_in_edges_mesher_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_REFINE_ELEMENTS_IN_EDGES_MESHER_PROCESS_H_INCLUDED )
11 #define KRATOS_REFINE_ELEMENTS_IN_EDGES_MESHER_PROCESS_H_INCLUDED
12 
13 
14 // External includes
15 
16 // System includes
17 
18 // Project includes
21 
22 #include "includes/model_part.h"
26 
27 namespace Kratos
28 {
29 
32 
34 
38  : public MesherProcess
39 {
40  public:
43 
46 
50 
55 
58  MesherUtilities::MeshingParameters& rRemeshingParameters,
59  int EchoLevel)
60  : mrModelPart(rModelPart),
61  mrRemesh(rRemeshingParameters)
62  {
64  }
65 
66 
69 
70 
74 
76  void operator()()
77  {
78  Execute();
79  }
80 
81 
85 
86 
88  void Execute() override
89  {
91 
92  if( ( mrRemesh.Refine->RefiningOptions.Is(MesherUtilities::REFINE_ADD_NODES) ||
93  mrRemesh.Refine->RefiningOptions.Is(MesherUtilities::REFINE_INSERT_NODES) ) )
94  {
95 
96  //1.- Select Elements to split (edge elements with all nodes as boundary-free surface)
97  ModelPart::ElementsContainerType BoundaryEdgedElements;
98  ModelPart::ConditionsContainerType BoundaryEdgedConditions;
99  this->SelectFullBoundaryEdgedElements(mrModelPart, BoundaryEdgedElements);
100 
101  //2.- Select Inside Faces to refine
102  std::vector<Geometry< Node > > ListOfFacesToSplit;
103  this->SelectFacesToSplit(BoundaryEdgedElements,ListOfFacesToSplit);
104 
105 
106  //3.- Create and insert new nodes
107  std::vector<Node::Pointer> ListOfNewNodes;
108  this->GenerateNewNodes(mrModelPart,ListOfNewNodes,ListOfFacesToSplit);
109 
110  //4.- Insert new nodes to model part
111  this->SetNodesToModelPart(mrModelPart, ListOfNewNodes);
112  }
113 
114  KRATOS_CATCH(" ")
115  }
116 
117 
121 
122 
126 
127 
131 
133  std::string Info() const override
134  {
135  return "RefineElementsInEdgesMesherProcess";
136  }
137 
139  void PrintInfo(std::ostream& rOStream) const override
140  {
141  rOStream << "RefineElementsInEdgesMesherProcess";
142  }
143 
145  void PrintData(std::ostream& rOStream) const override
146  {
147  }
148 
149 
153 
155 
156  protected:
157 
163 
165 
167 
169 
171 
179 
180  virtual void SelectFullBoundaryEdgedElements(ModelPart& rModelPart,
181  ModelPart::ElementsContainerType& rBoundaryEdgedElements)
182  {
183  KRATOS_TRY
184 
185  bool is_full_boundary = false;
186  ModelPart::ElementsContainerType& rElements = rModelPart.Elements();
187  for(auto i_elem(rElements.begin()); i_elem != rElements.end(); ++i_elem)
188  {
189  Geometry< Node >& rGeometry = i_elem->GetGeometry();
190 
191  is_full_boundary = true;
192  for(unsigned int i=0; i<rGeometry.size(); ++i)
193  {
194  if( rGeometry[i].IsNot(BOUNDARY) ){
195  is_full_boundary = false;
196  break;
197  }
198  }
199 
200  if( is_full_boundary ){
201  rBoundaryEdgedElements.push_back(*i_elem.base());
202  }
203 
204  }
205 
206  KRATOS_CATCH( "" )
207  }
208 
210  std::vector<Geometry< Node > >& rListOfFacesToSplit)
211  {
212  KRATOS_TRY
213 
214  DenseMatrix<unsigned int> lpofa; //connectivities of points defining faces
215  DenseVector<unsigned int> lnofa; //number of points defining faces
216 
217  for(auto& i_elem : rBoundaryEdgedElements)
218  {
219  ElementWeakPtrVectorType& nElements = i_elem.GetValue(NEIGHBOUR_ELEMENTS);
220 
221  unsigned int face=0;
222  bool accepted_face = false;
223  for(auto& i_nelem : nElements)
224  {
225  if(i_nelem.Id() != i_elem.Id()) // If there is a shared element in face nf
226  {
227  accepted_face = true;
228 
229  Geometry< Node >& rGeometry = i_elem.GetGeometry();
230 
231  rGeometry.NodesInFaces(lpofa);
232  rGeometry.NumberNodesInFaces(lnofa);
233 
234  unsigned int NumberNodesInFace = lnofa[face];
235  Condition::NodesArrayType FaceNodes;
236  FaceNodes.reserve(NumberNodesInFace);
237 
238  unsigned int split_counter=0;
239  unsigned int counter=0;
240  for(unsigned int j=1; j<=NumberNodesInFace; ++j)
241  {
242  if(rGeometry[lpofa(j,face)].Is(TO_SPLIT))
243  ++split_counter;
244  FaceNodes.push_back(rGeometry(lpofa(j,face)));
245 
246  //do not SPLIT small edges only big edges, else a lot of volume is added
247  if(mrModelPart.Is(FLUID) && counter>0){
248  if( 4.5 * this->mrRemesh.Refine->CriticalRadius > norm_2(FaceNodes[counter].Coordinates()-FaceNodes[counter-1].Coordinates()) ){
249  accepted_face = false;
250  }
251  }
252  ++counter;
253  }
254 
255  if(split_counter==NumberNodesInFace)
256  accepted_face = false;
257 
258  unsigned int free_surface = 0;
259  if(accepted_face){
260 
261  if(mrModelPart.Is(FLUID) ){
262  //set FLUID flag in RIGID nodes to false
263  //and to not refine the edge in order to erase blocked edge elements
264  for(unsigned int i=0; i<FaceNodes.size(); ++i)
265  {
266  if(FaceNodes[i].Is(RIGID) && FaceNodes[i].Is(FREE_SURFACE)){
267  ++free_surface;
268  }
269  }
270 
271  if(free_surface != 0){
272  accepted_face = false;
273  }
274  }
275 
276  }
277 
278  if( accepted_face ){
279  Geometry<Node > InsideFace(FaceNodes);
280  rListOfFacesToSplit.push_back(InsideFace);
281 
282  //set TO_SPLIT to make the insertion unique
283  for(unsigned int i=0; i<FaceNodes.size(); ++i)
284  FaceNodes[i].Set(TO_SPLIT);
285  break;
286  }
287 
288  }
289  ++face;
290  }
291  }
292 
293  // reset TO_SPLIT
294  for(auto& i_face : rListOfFacesToSplit)
295  {
296  for(unsigned int i=0; i<i_face.size(); ++i)
297  {
298  i_face[i].Set(TO_SPLIT,false);
299  }
300  }
301 
302  // std::cout<<" rEdgeElements "<< rBoundaryEdgedElements.size()<<std::endl;
303  // std::cout<<" FacesToSplit "<<rListOfFacesToSplit.size()<<std::endl;
304 
305  KRATOS_CATCH( "" )
306  }
307 
308  void GenerateNewNodes(ModelPart& rModelPart,
309  std::vector<Node::Pointer>& rListOfNewNodes,
310  std::vector<Geometry<Node > >& rListOfFacesToSplit)
311  {
312  KRATOS_TRY
313 
314  //ProcessInfo& rCurrentProcessInfo = rModelPart.GetProcessInfo();
315 
316  MeshDataTransferUtilities DataTransferUtilities;
317 
318  Node::Pointer pNode;
319 
320  //center
321  double xc = 0;
322  double yc = 0;
323  double zc = 0;
324 
325  //radius
326  double radius = 0;
327 
328  //assign data to dofs
329  Node::DofsContainerType& ReferenceDofs = rModelPart.Nodes().front().GetDofs();
330 
332 
333 
334  std::vector<double> ShapeFunctionsN;
335 
336  unsigned int id = MesherUtilities::GetMaxNodeId(rModelPart.GetParentModelPart()) + 1;
337 
338  unsigned int size = 0;
339  //unsigned int count = 0;
340 
341  for(auto& i_face : rListOfFacesToSplit)
342  {
343  size = i_face.size();
344 
345  ShapeFunctionsN.resize(size);
346 
347  if( size == 2 )
348  DataTransferUtilities.CalculateCenterAndSearchRadius( i_face[0].X(), i_face[0].Y(),
349  i_face[1].X(), i_face[1].Y(),
350  xc,yc,radius);
351 
352  if( size == 3 )
353  DataTransferUtilities.CalculateCenterAndSearchRadius( i_face[0].X(), i_face[0].Y(), i_face[0].Z(),
354  i_face[1].X(), i_face[1].Y(), i_face[1].Z(),
355  i_face[2].X(), i_face[2].Y(), i_face[2].Z(),
356  xc,yc,zc,radius);
357 
358 
359  //create a new node
360  pNode = Kratos::make_intrusive< Node >( id, xc, yc, zc );
361 
362  //giving model part variables list to the node
363  pNode->SetSolutionStepVariablesList(&VariablesList);
364 
365  //set buffer size
366  pNode->SetBufferSize(rModelPart.GetBufferSize());
367 
368  //generating the dofs
369  for(auto& i_dof : ReferenceDofs)
370  {
371  Node::DofType& rDof = *i_dof;
372  Node::DofType::Pointer pNewDof = pNode->pAddDof( rDof );
373 
374  // in rigid edges set it fix has no sense:
375  (pNewDof)->FreeDof();
376 
377  // count = 0;
378  // for( unsigned int i = 0; i<size; ++i )
379  // {
380  // if(i_face[i].IsFixed(rDof.GetVariable()))
381  // count++;
382  // }
383 
384  // if( count == size )
385  // (pNewDof)->FixDof();
386  // else
387  // (pNewDof)->FreeDof();
388  }
389 
390  std::fill(ShapeFunctionsN.begin(), ShapeFunctionsN.end(), 1.0/double(size));
391 
392  double alpha = 1;
393  DataTransferUtilities.Interpolate( i_face, ShapeFunctionsN, VariablesList, pNode, alpha );
394 
395  //set flags from one of the nodes
396  pNode->AssignFlags(i_face[0]);
397 
398  if( rModelPart.Is(FLUID) )
399  pNode->Set(FLUID);
400 
401  if( rModelPart.Is(SOLID) )
402  pNode->Set(SOLID);
403 
404  pNode->Set(NEW_ENTITY,true);
405  pNode->Set(ACTIVE,true);
406 
407  //unset boundary flags
408  pNode->Set(BOUNDARY,false);
409  pNode->Set(FREE_SURFACE,false);
410  pNode->Set(RIGID,false);
411  pNode->Set(INLET,false);
412 
413  //set variables
414  this->SetNewNodeVariables(rModelPart, pNode);
415 
416  rListOfNewNodes.push_back(pNode);
417 
418  id++;
419  }
420 
421  KRATOS_CATCH( "" )
422  }
423 
424  void SetNewNodeVariables(ModelPart& rModelPart, Node::Pointer& pNode)
425  {
426  KRATOS_TRY
427 
428  //set model part
429  pNode->SetValue(MODEL_PART_NAME,rModelPart.Name());
430 
431  //set nodal_h
432  pNode->FastGetSolutionStepValue(NODAL_H) = mrRemesh.Refine->CriticalSide*2.0;
433 
434  //set original position
435  const array_1d<double,3>& Displacement = pNode->FastGetSolutionStepValue(DISPLACEMENT);
436  pNode->X0() = pNode->X() - Displacement[0];
437  pNode->Y0() = pNode->Y() - Displacement[1];
438  pNode->Z0() = pNode->Z() - Displacement[2];
439 
440  //reset contact force
441  if( pNode->SolutionStepsDataHas(CONTACT_FORCE) )
442  pNode->FastGetSolutionStepValue(CONTACT_FORCE).clear();
443 
444 
445  KRATOS_CATCH( "" )
446  }
447 
448  void SetNodesToModelPart(ModelPart& rModelPart, std::vector<Node::Pointer>& rListOfNewNodes)
449  {
450  KRATOS_TRY
451 
452  if(rListOfNewNodes.size())
453  {
454  //add new conditions: ( SOLID body model part )
455  for(auto& i_node : rListOfNewNodes)
456  {
457  rModelPart.Nodes().push_back(i_node);
458  }
459 
460  }
461 
462  KRATOS_CATCH( "" )
463  }
464 
475 
476  private:
497 
500 
501 
503 
504 
506  //Process(Process const& rOther);
507 
508 
510 
511 }; // Class Process
512 
514 
517 
518 
522 
523 
525 inline std::istream& operator >> (std::istream& rIStream,
527 
529 inline std::ostream& operator << (std::ostream& rOStream,
531 {
532  rThis.PrintInfo(rOStream);
533  rOStream << std::endl;
534  rThis.PrintData(rOStream);
535 
536  return rOStream;
537 }
539 
540 
541 } // namespace Kratos.
542 
543 #endif // KRATOS_REFINE_ELEMENTS_IN_EDGES_MESHER_PROCESS_H_INCLUDED defined
Base class for all Conditions.
Definition: condition.h:59
Dof represents a degree of freedom (DoF).
Definition: dof.h:86
void Set(const Flags ThisFlag)
Definition: flags.cpp:33
bool Is(Flags const &rOther) const
Definition: flags.h:274
bool IsNot(Flags const &rOther) const
Definition: flags.h:291
Geometry base class.
Definition: geometry.h:71
void push_back(PointPointerType x)
Definition: geometry.h:548
SizeType size() const
Definition: geometry.h:518
virtual void NodesInFaces(DenseMatrix< unsigned int > &rNodesInFaces) const
Definition: geometry.h:2195
virtual void NumberNodesInFaces(DenseVector< unsigned int > &rNumberNodesInFaces) const
Definition: geometry.h:2190
Definition: amatrix_interface.h:41
Short class definition.
Definition: mesh_data_transfer_utilities.hpp:46
The base class for processes passed to the solution scheme.
Definition: mesher_process.hpp:37
Short class definition.
Definition: mesher_utilities.hpp:49
static unsigned int GetMaxNodeId(ModelPart &rModelPart)
Definition: mesher_utilities.hpp:1408
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
MeshType::ElementsContainerType ElementsContainerType
Element container. A vector set of Elements with their Id's as key.
Definition: model_part.h:168
std::string & Name()
Definition: model_part.h:1811
IndexType GetBufferSize() const
This method gets the suffer size of the model part database.
Definition: model_part.h:1876
ElementsContainerType & Elements(IndexType ThisIndex=0)
Definition: model_part.h:1189
ModelPart & GetParentModelPart()
Definition: model_part.cpp:2124
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
VariablesList & GetNodalSolutionStepVariablesList()
Definition: model_part.h:549
std::vector< std::unique_ptr< Dof< double > >> DofsContainerType
The DoF container type definition.
Definition: node.h:92
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
void reserve(size_type dim)
Definition: pointer_vector.h:319
void push_back(const TPointerType &x)
Definition: pointer_vector.h:270
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: refine_elements_in_edges_mesher_process.hpp:39
ModelPart & mrModelPart
Definition: refine_elements_in_edges_mesher_process.hpp:164
virtual ~RefineElementsInEdgesMesherProcess()
Destructor.
Definition: refine_elements_in_edges_mesher_process.hpp:68
int mEchoLevel
Definition: refine_elements_in_edges_mesher_process.hpp:170
std::string Info() const override
Turn back information as a string.
Definition: refine_elements_in_edges_mesher_process.hpp:133
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: refine_elements_in_edges_mesher_process.hpp:139
MesherUtilities::MeshingParameters & mrRemesh
Definition: refine_elements_in_edges_mesher_process.hpp:166
void SelectFacesToSplit(ModelPart::ElementsContainerType &rBoundaryEdgedElements, std::vector< Geometry< Node > > &rListOfFacesToSplit)
Definition: refine_elements_in_edges_mesher_process.hpp:209
RefineElementsInEdgesMesherProcess(ModelPart &rModelPart, MesherUtilities::MeshingParameters &rRemeshingParameters, int EchoLevel)
Default constructor.
Definition: refine_elements_in_edges_mesher_process.hpp:57
virtual void SelectFullBoundaryEdgedElements(ModelPart &rModelPart, ModelPart::ElementsContainerType &rBoundaryEdgedElements)
Definition: refine_elements_in_edges_mesher_process.hpp:180
KRATOS_CLASS_POINTER_DEFINITION(RefineElementsInEdgesMesherProcess)
Pointer definition of Process.
void SetNewNodeVariables(ModelPart &rModelPart, Node::Pointer &pNode)
Definition: refine_elements_in_edges_mesher_process.hpp:424
ConditionType::GeometryType GeometryType
Definition: refine_elements_in_edges_mesher_process.hpp:49
MesherUtilities mMesherUtilities
Definition: refine_elements_in_edges_mesher_process.hpp:168
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: refine_elements_in_edges_mesher_process.hpp:145
void Execute() override
Execute method is used to execute the Process algorithms.
Definition: refine_elements_in_edges_mesher_process.hpp:88
ModelPart::ConditionType ConditionType
Definition: refine_elements_in_edges_mesher_process.hpp:47
void GenerateNewNodes(ModelPart &rModelPart, std::vector< Node::Pointer > &rListOfNewNodes, std::vector< Geometry< Node > > &rListOfFacesToSplit)
Definition: refine_elements_in_edges_mesher_process.hpp:308
void SetNodesToModelPart(ModelPart &rModelPart, std::vector< Node::Pointer > &rListOfNewNodes)
Definition: refine_elements_in_edges_mesher_process.hpp:448
void operator()()
This operator is provided to call the process as a function and simply calls the Execute method.
Definition: refine_elements_in_edges_mesher_process.hpp:76
GlobalPointersVector< Element > ElementWeakPtrVectorType
Definition: refine_elements_in_edges_mesher_process.hpp:51
ModelPart::PropertiesType PropertiesType
Definition: refine_elements_in_edges_mesher_process.hpp:48
Holds a list of variables and their position in VariablesListDataValueContainer.
Definition: variables_list.h:50
BOOST_UBLAS_INLINE void clear()
Definition: array_1d.h:325
#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
TExpressionType::data_type norm_2(AMatrix::MatrixExpression< TExpressionType, TCategory > const &TheExpression)
Definition: amatrix_interface.h:625
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
alpha
Definition: generate_convection_diffusion_explicit_element.py:113
float radius
Definition: mesh_to_mdpa_converter.py:18
int j
Definition: quadrature.py:648
float xc
Definition: rotating_cone.py:77
float yc
Definition: rotating_cone.py:78
int counter
Definition: script_THERMAL_CORRECT.py:218
integer i
Definition: TensorModule.f:17
Definition: mesher_utilities.hpp:631
RefiningParameters::Pointer Refine
Definition: mesher_utilities.hpp:684