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.
local_refine_tetrahedra_mesh_parallel_to_boundaries.hpp
Go to the documentation of this file.
1 // KRATOS __ __ _____ ____ _ _ ___ _ _ ____
2 // | \/ | ____/ ___|| | | |_ _| \ | |/ ___|
3 // | |\/| | _| \___ \| |_| || || \| | | _
4 // | | | | |___ ___) | _ || || |\ | |_| |
5 // |_| |_|_____|____/|_| |_|___|_| \_|\____| APPLICATION
6 //
7 // License: BSD License
8 // Kratos default license: kratos/license.txt
9 //
10 // Main authors: Pablo Becker
11 //
12 
13 #pragma once
14 
15 // NOTE: Before compute the remeshing it is necessary to compute the neighbours
16 
17 // System includes
18 
19 // External includes
20 
21 // Project includes
24 
25 // Applicaion includes
27 
28 
29 namespace Kratos
30 {
46 {
47 public:
48 
54 
57  : LocalRefineTetrahedraMesh(rModelPart)
58  {
59  }
60 
63  = default;
64 
69  bool RefineOnReference,
70  bool InterpolateInternalVariables
71  ) override
72  {
73  KRATOS_TRY;
74 
75  //using the conditions to mark the boundary with the flag boundary
76  //note that we DO NOT add the conditions to the model part
77  block_for_each(mModelPart.Nodes(), [&](Node& rNode) {
78  rNode.Set(BOUNDARY,false);
79  });
80 
82  Geometry< Node >& geom = rCondition.GetGeometry();
83  for(unsigned int i=0; i<geom.size(); i++){
84  geom[i].SetLock();
85  geom[i].Set(BOUNDARY,true);
86  geom[i].UnSetLock();
87  }
88  });
89 
90  LocalRefineGeometryMesh::LocalRefineMesh(RefineOnReference,InterpolateInternalVariables);
91 
92 
93  KRATOS_CATCH("");
94  }
98 
99  /***********************************************************************************/
100  /***********************************************************************************/
101 
102  void ResetFatherNodes(ModelPart &rModelPart) override
103  {
104  block_for_each(mModelPart.Nodes(), [&](Node& rNode) {
105  if(rNode.GetValue(REFINEMENT_LEVEL)==0){
106  GlobalPointersVector<Node> empty_father_vector;
107  rNode.SetValue(FATHER_NODES, empty_father_vector);
108  }
109  });
110  }
111 
113  ModelPart& rThisModelPart,
114  compressed_matrix<int>& rCoord
115  ) override
116  {
117  KRATOS_TRY;
118  for (auto& r_elem: rThisModelPart.Elements()) {
119  if (r_elem.GetValue(SPLIT_ELEMENT)) {
120  Element::GeometryType& r_geom = r_elem.GetGeometry(); // Nodes of the element
121  for (unsigned int i = 0; i < r_geom.size(); i++) {
122  int index_i = mMapNodeIdToPos[r_geom[i].Id()];
123  bool is_boundary_i = r_geom[i].Is(BOUNDARY);
124  for (unsigned int j = 0; j < r_geom.size(); j++) {
125  int index_j = mMapNodeIdToPos[r_geom[j].Id()];
126  bool is_boundary_j = r_geom[j].Is(BOUNDARY);
127  if (index_j > index_i && (is_boundary_j||is_boundary_i)) {
128  rCoord(index_i, index_j) = -2;
129  }
130  }
131  }
132  }
133  }
134 
135  //unmarking edges belonging to the edges of conditions (skin) to avoid refining edges
136  for (auto& r_cond : rThisModelPart.Conditions()) {
137  auto& r_geom = r_cond.GetGeometry(); // Nodes of the condition
138  for (unsigned int i = 0; i < r_geom.size(); i++) {
139  int index_i = mMapNodeIdToPos[r_geom[i].Id()];
140  for (unsigned int j = 0; j < r_geom.size(); j++) {
141  int index_j = mMapNodeIdToPos[r_geom[j].Id()];
142  if (index_j > index_i) {
143  rCoord(index_i, index_j) = -1;
144  }
145  }
146  }
147  }
148 
149  KRATOS_CATCH("");
150  }
151 
152  //have to override because we need the refinement level in the ifs ( (*iNode)->GetValue(REFINEMENT_LEVEL)==mcurrent_refinement_level )
153  void UpdateSubModelPartNodes(ModelPart &rModelPart) override
154  {
155  bool added_nodes=false;
156 
157  for (auto it_submodel_part = rModelPart.SubModelPartsBegin();
158  it_submodel_part != rModelPart.SubModelPartsEnd(); it_submodel_part++) {
159  added_nodes=false;
160  for (auto it_node = rModelPart.Nodes().ptr_begin();
161  it_node != rModelPart.Nodes().ptr_end(); it_node++) {
162  auto &r_father_nodes = (*it_node)->GetValue(FATHER_NODES);
163  unsigned int parent_count = r_father_nodes.size();
164  if (parent_count > 0 && (*it_node)->GetValue(REFINEMENT_LEVEL)==mCurrentRefinementLevel) {
165  unsigned int parents_in_submodel_part = 0;
166 
167  for (auto it_parent = r_father_nodes.begin(); it_parent != r_father_nodes.end(); it_parent++) {
168  unsigned int parent_id = it_parent->Id();
169  ModelPart::NodeIterator iFound = it_submodel_part->Nodes().find( parent_id );
170  if ( iFound != it_submodel_part->NodesEnd() ) {
171  parents_in_submodel_part++;
172  }
173  }
174 
175  if ( parent_count == parents_in_submodel_part ) {
176  it_submodel_part->AddNode( *it_node );
177  added_nodes=true;
178  }
179  }
180  }
181  if(added_nodes) {
182  ModelPart &rSubModelPart = *it_submodel_part;
183  UpdateSubModelPartNodes(rSubModelPart);
184  }
185  }
186  }
187 
188 
189 protected:
195 
199 
203 
207 
211 
216 
217 private:
220 
224 
228 
232 
236 
240 
245 
246 };
247 
248 } // namespace Kratos.
Base class for all Conditions.
Definition: condition.h:59
Geometry base class.
Definition: geometry.h:71
SizeType size() const
Definition: geometry.h:518
IndexType const & Id() const
Id of this Geometry.
Definition: geometry.h:964
ModelPart & mModelPart
Definition: local_refine_geometry_mesh.hpp:238
virtual void LocalRefineMesh(bool refine_on_reference, bool interpolate_internal_variables)
Definition: local_refine_geometry_mesh.cpp:28
Definition: local_refine_tetrahedra_mesh.hpp:49
Definition: local_refine_tetrahedra_mesh_parallel_to_boundaries.hpp:46
void ResetFatherNodes(ModelPart &rModelPart) override
Definition: local_refine_tetrahedra_mesh_parallel_to_boundaries.hpp:102
LocalRefineTetrahedraMeshParallelToBoundaries(ModelPart &rModelPart)
Default constructors.
Definition: local_refine_tetrahedra_mesh_parallel_to_boundaries.hpp:56
void UpdateSubModelPartNodes(ModelPart &rModelPart) override
Definition: local_refine_tetrahedra_mesh_parallel_to_boundaries.hpp:153
void SearchEdgeToBeRefined(ModelPart &rThisModelPart, compressed_matrix< int > &rCoord) override
Definition: local_refine_tetrahedra_mesh_parallel_to_boundaries.hpp:112
void LocalRefineMesh(bool RefineOnReference, bool InterpolateInternalVariables) override
Definition: local_refine_tetrahedra_mesh_parallel_to_boundaries.hpp:68
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
SubModelPartIterator SubModelPartsEnd()
Definition: model_part.h:1708
SubModelPartIterator SubModelPartsBegin()
Definition: model_part.h:1698
ConditionsContainerType & Conditions(IndexType ThisIndex=0)
Definition: model_part.h:1381
MeshType::NodeIterator NodeIterator
Definition: model_part.h:134
ElementsContainerType & Elements(IndexType ThisIndex=0)
Definition: model_part.h:1189
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
This class defines the node.
Definition: node.h:65
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
void block_for_each(TIterator itBegin, TIterator itEnd, TFunction &&rFunction)
Execute a functor on all items of a range in parallel.
Definition: parallel_utilities.h:299
int j
Definition: quadrature.py:648
integer i
Definition: TensorModule.f:17