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_triangle_mesh_generic.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 Agustin 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
26 
27 namespace Kratos
28 {
43 
44 template<class TGeometricalObjectType, typename TArrayType>
47 {
48 public:
49 
55 
58  {
59 
60  }
61 
64  = default;
65 
69 
73 
82  ModelPart& rThisModelPart,
83  TArrayType& rObjects,
84  const compressed_matrix<int>& rCoord,
86  bool InterpolateInternalVariables
87  )
88  {
89  typename TArrayType::iterator GeometricalObjectsBegin = rObjects.ptr_begin();
90  typename TArrayType::iterator GeometricalObjectsEnd = rObjects.ptr_end();
91 
92  unsigned int to_be_deleted = 0;
93  unsigned int large_id = (GeometricalObjectsEnd - 1)->Id() * 10;
94  bool create_object = false;
95  int EdgeIds[3];
96  int t[12];
97  int number_object = 0;
98  int splitted_edges = 0;
99  int nint = 0;
100  std::vector<int> rAux;
101 
102  const ProcessInfo& rCurrentProcessInfo = rThisModelPart.GetProcessInfo();
103 
104  KRATOS_INFO("LocalRefineTriangleMeshGeneric") << "****************** REFINING MESH ******************" << std::endl;
105  KRATOS_INFO("LocalRefineTriangleMeshGeneric") << "OLD NUMBER OBJECTS: " << GeometricalObjectsEnd - GeometricalObjectsBegin << std::endl;
106 
108 
109  unsigned int current_id = (GeometricalObjectsEnd - 1)->Id() + 1;
110  for (typename TArrayType::iterator it = GeometricalObjectsBegin; it != GeometricalObjectsEnd; ++it) {
111  for (int & i : t) {
112  i = -1;
113  }
114  typename TGeometricalObjectType::GeometryType& rGeom = it->GetGeometry();
115  CalculateEdges(rGeom, rCoord, EdgeIds, rAux);
116 
117  const unsigned int dimension = rGeom.WorkingSpaceDimension();
118 
119  // It creates the new conectivities
120  create_object = TriangleSplit::Split_Triangle(EdgeIds, t, &number_object, &splitted_edges, &nint);
121 
122  // It creates the new objects
123  if (create_object) {
124  to_be_deleted++;
125  auto& r_child_objects = GetNeighbour(it);
126  r_child_objects.resize(0);
127  for (int i = 0; i < number_object; i++) {
128  const unsigned int base = i * 3;
129  const unsigned int i0 = rAux[t[base]];
130  const unsigned int i1 = rAux[t[base + 1]];
131  const unsigned int i2 = rAux[t[base + 2]];
132 
133  if (dimension == 2) {
134  Triangle2D3<Node > rGeom(
135  rThisModelPart.Nodes()(i0),
136  rThisModelPart.Nodes()(i1),
137  rThisModelPart.Nodes()(i2)
138  );
139 
140  typename TGeometricalObjectType::Pointer p_object;
141  p_object = it->Create(current_id, rGeom, it->pGetProperties());
142  p_object->Initialize(rCurrentProcessInfo);
143  p_object->InitializeSolutionStep(rCurrentProcessInfo);
144  p_object->FinalizeSolutionStep(rCurrentProcessInfo);
145 
146  // Setting the internal variables in the child elem
147  if (InterpolateInternalVariables) {
148  InterpolateInteralVariables(number_object, *it.base(), p_object, rCurrentProcessInfo);
149  }
150 
151  // Transfer elemental variables
152  p_object->GetData() = it->GetData();
153  //const unsigned int& level = it->GetValue(REFINEMENT_LEVEL);
154  p_object->GetValue(SPLIT_ELEMENT) = false;
155  //p_element->SetValue(REFINEMENT_LEVEL, 1);
156  rNewObjects.push_back(p_object);
157  r_child_objects.push_back(typename TGeometricalObjectType::WeakPointer(p_object) );
158  } else {
159  Triangle3D3<Node > rGeom(
160  rThisModelPart.Nodes()(i0),
161  rThisModelPart.Nodes()(i1),
162  rThisModelPart.Nodes()(i2)
163  );
164 
165  typename TGeometricalObjectType::Pointer p_object;
166  p_object = it->Create(current_id, rGeom, it->pGetProperties());
167  p_object->Initialize(rCurrentProcessInfo);
168  p_object->InitializeSolutionStep(rCurrentProcessInfo);
169  p_object->FinalizeSolutionStep(rCurrentProcessInfo);
170 
171  // Setting the internal variables in the child elem
172  if (InterpolateInternalVariables == true)
173  InterpolateInteralVariables(number_object, *it.base(), p_object, rCurrentProcessInfo);
174 
175  // Transfer elemental variables
176  p_object->GetData() = it->GetData();
177  p_object->GetValue(SPLIT_ELEMENT) = false;
178  rNewObjects.push_back(p_object);
179  r_child_objects.push_back(typename TGeometricalObjectType::WeakPointer(p_object) );
180  }
181 
182  current_id++;
183  }
184  it->SetId(large_id);
185  large_id++;
186  }
187 
188  }
189 
190  /* Adding news elements to the model part */
191  for (auto it_new = rNewObjects.begin(); it_new != rNewObjects.end(); it_new++) {
192  rObjects.push_back(*(it_new.base()));
193  }
194 
195  /* All of the elements to be erased are at the end */
196  rObjects.Sort();
197 
198  /* Now remove all of the "old" elements */
199  rObjects.erase(rObjects.end() - to_be_deleted, rObjects.end());
200 
201  KRATOS_INFO("LocalRefineTriangleMeshGeneric") << "NEW NUMBER OBJECTS: " << rObjects.size() << std::endl;
202  }
203 
213  Geometry<Node>& rGeom,
214  const compressed_matrix<int>& rCoord,
215  int* EdgeIds,
216  std::vector<int>& rAux
217  ) override
218  {
219  rAux.resize(6, false);
220 
221  const std::size_t index_0 = mMapNodeIdToPos[rGeom[0].Id()];
222  const std::size_t index_1 = mMapNodeIdToPos[rGeom[1].Id()];
223  const std::size_t index_2 = mMapNodeIdToPos[rGeom[2].Id()];
224 
225  rAux[0] = rGeom[0].Id();
226  rAux[1] = rGeom[1].Id();
227  rAux[2] = rGeom[2].Id();
228 
229  if (index_0 > index_1) {
230  rAux[3] = rCoord(index_1, index_0);
231  } else {
232  rAux[3] = rCoord(index_0, index_1);
233  }
234 
235  if (index_1 > index_2) {
236  rAux[4] = rCoord(index_2, index_1);
237  } else {
238  rAux[4] = rCoord(index_1, index_2);
239  }
240 
241  if (index_2 > index_0){
242  rAux[5] = rCoord(index_0, index_2);
243  } else {
244  rAux[5] = rCoord(index_2, index_0);
245  }
246 
247  // Edge 01
248  if (rAux[3] < 0) {
249  if (index_0 > index_1){
250  EdgeIds[0] = 0;
251  } else {
252  EdgeIds[0] = 1;
253  }
254  } else {
255  EdgeIds[0] = 3;
256  }
257 
258  // Edge 12
259  if (rAux[4] < 0){
260  if (index_1 > index_2) {
261  EdgeIds[1] = 1;
262  } else {
263  EdgeIds[1] = 2;
264  }
265  } else {
266  EdgeIds[1] = 4;
267  }
268 
269  // Edge 20
270  if (rAux[5] < 0) {
271  if (index_2 > index_0) {
272  EdgeIds[2] = 2;
273  } else {
274  EdgeIds[2] = 0;
275  }
276  } else {
277  EdgeIds[2] = 5;
278  }
279  }
280 
281  GlobalPointersVector<Element>& GetNeighbour(ElementsArrayType::iterator it_elem)
282  {
283  return it_elem->GetValue(NEIGHBOUR_ELEMENTS);
284  }
285 
286  GlobalPointersVector<Condition>& GetNeighbour(ConditionsArrayType::iterator it_cond)
287  {
288  return it_cond->GetValue(NEIGHBOUR_CONDITIONS);
289  }
290 
291 };
292 
293 } // namespace Kratos.
Geometry base class.
Definition: geometry.h:71
IndexType const & Id() const
Id of this Geometry.
Definition: geometry.h:964
Definition: local_refine_geometry_mesh.hpp:49
std::unordered_map< std::size_t, unsigned int > mMapNodeIdToPos
The current refinement level.
Definition: local_refine_geometry_mesh.hpp:240
void InterpolateInteralVariables(const int &number_elem, const TGeometricalObjectPointerType father_elem, TGeometricalObjectPointerType child_elem, const ProcessInfo &rCurrentProcessInfo)
Definition: local_refine_geometry_mesh.hpp:213
Definition: local_refine_triangle_mesh_generic.hpp:47
GlobalPointersVector< Element > & GetNeighbour(ElementsArrayType::iterator it_elem)
Definition: local_refine_triangle_mesh_generic.hpp:281
~LocalRefineTriangleMeshGeneric() override=default
Destructor.
void EraseOldObjetcsAndCreateNewObjects(ModelPart &rThisModelPart, TArrayType &rObjects, const compressed_matrix< int > &rCoord, PointerVector< TGeometricalObjectType > &rNewObjects, bool InterpolateInternalVariables)
Definition: local_refine_triangle_mesh_generic.hpp:81
GlobalPointersVector< Condition > & GetNeighbour(ConditionsArrayType::iterator it_cond)
Definition: local_refine_triangle_mesh_generic.hpp:286
void CalculateEdges(Geometry< Node > &rGeom, const compressed_matrix< int > &rCoord, int *EdgeIds, std::vector< int > &rAux) override
Definition: local_refine_triangle_mesh_generic.hpp:212
LocalRefineTriangleMeshGeneric(ModelPart &model_part)
Default constructors.
Definition: local_refine_triangle_mesh_generic.hpp:57
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
PointerVector is a container like stl vector but using a vector to store pointers to its data.
Definition: pointer_vector.h:72
iterator end()
Definition: pointer_vector.h:177
iterator begin()
Definition: pointer_vector.h:169
void push_back(const TPointerType &x)
Definition: pointer_vector.h:270
ProcessInfo holds the current value of different solution parameters.
Definition: process_info.h:59
A three node 2D triangle geometry with linear shape functions.
Definition: triangle_2d_3.h:74
A three node 3D triangle geometry with linear shape functions.
Definition: triangle_3d_3.h:77
static int Split_Triangle(const int edges[3], int t[12], int *nel, int *splitted_edges, int *nint)
Utility to split triangles.
Definition: split_triangle.h:117
#define KRATOS_INFO(label)
Definition: logger.h:250
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
Geometry< Node > GeometryType
The definition of the geometry.
Definition: mortar_classes.h:37
model_part
Definition: face_heat.py:14
int dimension
Definition: isotropic_damage_automatic_differentiation.py:123
int t
Definition: ode_solve.py:392
int current_id
Output settings end ####.
Definition: script.py:194
integer i
Definition: TensorModule.f:17