84 unsigned int new_id = (
model_part.NodesEnd() - 1)->Id() + 1;
88 KRATOS_THROW_ERROR(std::logic_error,
"adding a center node with an already existing id",
"");
92 double X = (geom[0].X() + geom[1].X() + geom[2].X() + geom[3].X()) / 4.0;
93 double Y = (geom[0].Y() + geom[1].Y() + geom[2].Y() + geom[3].Y()) / 4.0;
94 double Z = (geom[0].Z() + geom[1].Z() + geom[2].Z() + geom[3].Z()) / 4.0;
96 double X0 = (geom[0].X0() + geom[1].X0() + geom[2].X0() + geom[3].X0()) / 4.0;
97 double Y0 = (geom[0].Y0() + geom[1].Y0() + geom[2].Y0() + geom[3].Y0()) / 4.0;
98 double Z0 = (geom[0].Z0() + geom[1].Z0() + geom[2].Z0() + geom[3].Z0()) / 4.0;
101 Node ::Pointer pnode =
model_part.CreateNewNode(new_id,
X,
Y,
Z);
103 unsigned int buffer_size =
model_part.NodesBegin()->GetBufferSize();
104 pnode->SetBufferSize(buffer_size);
112 unsigned int step_data_size =
model_part.GetNodalSolutionStepDataSize();
114 for (Node::DofsContainerType::iterator iii = reference_dofs.begin(); iii != reference_dofs.end(); ++iii)
120 (p_new_dof)->FreeDof();
126 double* new_step_data = pnode->SolutionStepData().Data(
step);
127 double* step_data1 = geom[0].SolutionStepData().Data(
step);
128 double* step_data2 = geom[1].SolutionStepData().Data(
step);
129 double* step_data3 = geom[2].SolutionStepData().Data(
step);
130 double* step_data4 = geom[3].SolutionStepData().Data(
step);
133 for (
unsigned int j = 0;
j < step_data_size;
j++)
135 new_step_data[
j] = 0.25 * (step_data1[
j] + step_data2[
j] + step_data3[
j] + step_data4[
j]);
139 pnode->
GetValue(FATHER_NODES).resize(0);
140 pnode->GetValue(FATHER_NODES).push_back( Node::WeakPointer( geom(0) ) );
141 pnode->GetValue(FATHER_NODES).push_back( Node::WeakPointer( geom(1) ) );
142 pnode->GetValue(FATHER_NODES).push_back( Node::WeakPointer( geom(2) ) );
143 pnode->GetValue(FATHER_NODES).push_back( Node::WeakPointer( geom(3) ) );
161 const compressed_matrix<int>& Coord,
163 bool interpolate_internal_variables
167 ElementsArrayType::iterator it_begin = rElements.ptr_begin();
168 ElementsArrayType::iterator it_end = rElements.ptr_end();
169 unsigned int to_be_deleted = 0;
170 unsigned int large_id = (rElements.end() - 1)->Id() * 15;
171 unsigned int current_id = (rElements.end() - 1)->Id() + 1;
172 bool create_element =
false;
174 int splitted_edges = 0;
175 int internal_node = 0;
180 std::vector<int> aux;
182 std::cout <<
"****************** REFINING MESH ******************" << std::endl;
183 std::cout <<
"OLD NUMBER ELEMENTS: " << rElements.size() << std::endl;
190 for (ElementsArrayType::iterator it = it_begin; it != it_end; ++it)
197 if (internal_node == 1)
202 bool verified =
false;
203 for(
int iii = 0; iii < number_elem*4; iii++)
211 if(verified ==
false)
214 for(
int iii = 0; iii < number_elem * 4; iii++)
216 std::cout <<
t[iii] << std::endl;
226 it->SetValue(SPLIT_ELEMENT,
false);
236 it->SetValue(SPLIT_ELEMENT,
true);
240 for (
int i = 0;
i < number_elem;
i++)
242 unsigned int base =
i * 4;
243 unsigned int i0 = aux[
t[base]];
244 unsigned int i1 = aux[
t[base + 1]];
245 unsigned int i2 = aux[
t[base + 2]];
246 unsigned int i3 = aux[
t[base + 3]];
249 this_model_part.
Nodes()(i0),
250 this_model_part.
Nodes()(i1),
251 this_model_part.
Nodes()(i2),
252 this_model_part.
Nodes()(i3)
256 Element::Pointer p_element;
257 p_element = it->Create(
current_id, geom, it->pGetProperties());
258 p_element->Initialize(rCurrentProcessInfo);
259 p_element->InitializeSolutionStep(rCurrentProcessInfo);
260 p_element->FinalizeSolutionStep(rCurrentProcessInfo);
263 if (interpolate_internal_variables ==
true)
269 p_element->GetData() = it->GetData();
270 p_element->GetValue(SPLIT_ELEMENT) =
false;
273 rChildElements.
push_back( Element::WeakPointer(p_element) );
281 for (
unsigned int i = 0;
i < 32;
i++)
290 rElements.push_back(*(it_new.base()));
297 rElements.erase(this_model_part.
Elements().end() - to_be_deleted, this_model_part.
Elements().end());
299 std::cout <<
"NEW NUMBER ELEMENTS: " << rElements.size() << std::endl;
303 if (NewElements.
size() > 0)
320 unsigned int to_be_deleted = 0;
326 iElem != iSubModelPart->ElementsEnd(); iElem++)
328 if( iElem->GetValue(SPLIT_ELEMENT) )
333 for (
auto iChild = rChildElements.
ptr_begin();
334 iChild != rChildElements.
ptr_end(); iChild++ )
336 NewElements.
push_back((*iChild)->shared_from_this());
342 iSubModelPart->Elements().reserve( iSubModelPart->Elements().size() + NewElements.
size() );
344 it_new != NewElements.
end(); it_new++)
346 iSubModelPart->Elements().push_back(*(it_new.base()));
350 iSubModelPart->Elements().Sort();
351 iSubModelPart->Elements().erase(iSubModelPart->Elements().end() - to_be_deleted, iSubModelPart->Elements().end());
360 if (NewElements.
size() > 0)
362 ModelPart &rSubModelPart = *iSubModelPart;
380 const compressed_matrix<int>& Coord
389 if(rConditions.size() > 0)
391 ConditionsArrayType::iterator it_begin = rConditions.ptr_begin();
392 ConditionsArrayType::iterator it_end = rConditions.ptr_end();
393 unsigned int to_be_deleted = 0;
394 unsigned int large_id = (rConditions.end() - 1)->Id() * 7;
398 int splitted_edges = 0;
404 unsigned int current_id = (rConditions.end() - 1)->Id() + 1;
405 for (ConditionsArrayType::iterator it = it_begin; it != it_end; ++it)
409 if (geom.
size() == 3)
416 if(create_condition==
true)
421 it->SetValue(SPLIT_ELEMENT,
true);
422 rChildConditions.
resize(0);
425 for(
int i = 0;
i < number_elem;
i++)
427 unsigned int base =
i * 3;
428 unsigned int i0 = aux[
t[base]];
429 unsigned int i1 = aux[
t[base+1]];
430 unsigned int i2 = aux[
t[base+2]];
433 this_model_part.
Nodes()(i0),
434 this_model_part.
Nodes()(i1),
435 this_model_part.
Nodes()(i2)
439 Condition::Pointer pcond;
440 pcond = it->Create(
current_id, newgeom, it->pGetProperties());
441 pcond ->Initialize(rCurrentProcessInfo);
442 pcond ->InitializeSolutionStep(rCurrentProcessInfo);
443 pcond ->FinalizeSolutionStep(rCurrentProcessInfo);
446 pcond->GetData() = it->GetData();
447 pcond->GetValue(SPLIT_ELEMENT) =
false;
450 rChildConditions.
push_back( Condition::WeakPointer( pcond ) );
466 unsigned int total_size = this_model_part.
Conditions().size()+ NewConditions.
size();
467 this_model_part.
Conditions().reserve(total_size);
470 for (
auto iCond = NewConditions.
ptr_begin();
471 iCond != NewConditions.
ptr_end(); iCond++)
473 this_model_part.
Conditions().push_back( *iCond );
479 if (NewConditions.
size() > 0)
495 unsigned int to_be_deleted = 0;
496 rNewConditions.
clear();
500 for (
auto it_cond = it_sub_model_part->ConditionsBegin(); it_cond != it_sub_model_part->ConditionsEnd(); it_cond++) {
501 if( it_cond->GetValue(SPLIT_ELEMENT) ) {
503 auto& rChildConditions = it_cond->GetValue(NEIGHBOUR_CONDITIONS);
504 for (
auto iChild = rChildConditions.ptr_begin(); iChild != rChildConditions.ptr_end(); iChild++ ) {
505 rNewConditions.
push_back((*iChild)->shared_from_this());
511 it_sub_model_part->Conditions().reserve( it_sub_model_part->Conditions().size() + rNewConditions.
size() );
512 for (
auto it_new = rNewConditions.
begin(); it_new != rNewConditions.
end(); it_new++) {
513 it_sub_model_part->Conditions().push_back(*(it_new.base()));
517 it_sub_model_part->Conditions().Sort();
518 it_sub_model_part->Conditions().erase(it_sub_model_part->Conditions().end() - to_be_deleted, it_sub_model_part->Conditions().end());
519 if (rNewConditions.
size() > 0) {
520 ModelPart &rSubModelPart = *it_sub_model_part;
540 const compressed_matrix<int>& Coord,
542 std::vector<int> & aux
545 aux.resize(11,
false);
553 aux[0] = geom[0].
Id();
554 aux[1] = geom[1].
Id();
555 aux[2] = geom[2].
Id();
556 aux[3] = geom[3].
Id();
558 if (index_0 > index_1)
560 aux[4] = Coord(index_1, index_0);
564 aux[4] = Coord(index_0, index_1);
567 if (index_0 > index_2)
569 aux[5] = Coord(index_2, index_0);
573 aux[5] = Coord(index_0, index_2);
576 if (index_0 > index_3)
578 aux[6] = Coord(index_3, index_0);
582 aux[6] = Coord(index_0, index_3);
585 if (index_1 > index_2)
587 aux[7] = Coord(index_2, index_1);
591 aux[7] = Coord(index_1, index_2);
594 if (index_1 > index_3)
596 aux[8] = Coord(index_3, index_1);
600 aux[8] = Coord(index_1, index_3);
603 if (index_2 > index_3)
605 aux[9] = Coord(index_3, index_2);
609 aux[9] = Coord(index_2, index_3);
630 const compressed_matrix<int>& Coord,
639 aux[0] = geom[0].
Id();
640 aux[1] = geom[1].
Id();
641 aux[2] = geom[2].
Id();
643 if (index_0 > index_1)
645 aux[3] = Coord(index_1, index_0);
649 aux[3] = Coord(index_0, index_1);
653 if (index_1 > index_2)
655 aux[4] = Coord(index_2, index_1);
659 aux[4] = Coord(index_1, index_2);
663 if (index_2 > index_0)
665 aux[5] = Coord(index_0, index_2);
669 aux[5] = Coord(index_2, index_0);
675 if (index_0 > index_1)
692 if (index_1 > index_2)
709 if (index_2 > index_0)
Dof represents a degree of freedom (DoF).
Definition: dof.h:86
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
TVariableType::Type & GetValue(const TVariableType &rThisVariable)
Definition: geometry.h:627
ptr_iterator ptr_begin()
Definition: global_pointers_vector.h:253
void push_back(TPointerType x)
Definition: global_pointers_vector.h:322
void resize(size_type new_dim) const
Definition: global_pointers_vector.h:366
ptr_iterator ptr_end()
Definition: global_pointers_vector.h:261
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
ModelPart::ElementsContainerType ElementsArrayType
Definition: local_refine_geometry_mesh.hpp:55
ModelPart::ConditionsContainerType ConditionsArrayType
Definition: local_refine_geometry_mesh.hpp:56
Definition: local_refine_tetrahedra_mesh.hpp:49
void CalculateEdges(Element::GeometryType &geom, const compressed_matrix< int > &Coord, int *edge_ids, std::vector< int > &aux) override
Definition: local_refine_tetrahedra_mesh.hpp:538
void UpdateSubModelPartConditions(ModelPart &rModelPart, PointerVector< Condition > &rNewConditions)
Definition: local_refine_tetrahedra_mesh.hpp:493
LocalRefineTetrahedraMesh(ModelPart &rModelPart)
Default constructors.
Definition: local_refine_tetrahedra_mesh.hpp:59
void EraseOldElementAndCreateNewElement(ModelPart &this_model_part, const compressed_matrix< int > &Coord, PointerVector< Element > &NewElements, bool interpolate_internal_variables) override
Definition: local_refine_tetrahedra_mesh.hpp:159
void CalculateEdgesFaces(Element::GeometryType &geom, const compressed_matrix< int > &Coord, int *edge_ids, array_1d< int, 6 > &aux)
Definition: local_refine_tetrahedra_mesh.hpp:629
unsigned int CreateCenterNode(Geometry< Node > &geom, ModelPart &model_part)
Definition: local_refine_tetrahedra_mesh.hpp:81
void EraseOldConditionsAndCreateNew(ModelPart &this_model_part, const compressed_matrix< int > &Coord) override
Definition: local_refine_tetrahedra_mesh.hpp:378
~LocalRefineTetrahedraMesh()=default
Destructor.
void UpdateSubModelPartElements(ModelPart &this_model_part, PointerVector< Element > &NewElements)
Definition: local_refine_tetrahedra_mesh.hpp:315
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
SubModelPartsContainerType::iterator SubModelPartIterator
Iterator over the sub model parts of this model part.
Definition: model_part.h:258
ConditionsContainerType & Conditions(IndexType ThisIndex=0)
Definition: model_part.h:1381
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
ElementsContainerType & Elements(IndexType ThisIndex=0)
Definition: model_part.h:1189
MeshType::ElementIterator ElementIterator
Definition: model_part.h:174
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
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
void clear()
Definition: pointer_vector.h:309
size_type size() const
Definition: pointer_vector.h:255
ptr_iterator ptr_end()
Definition: pointer_vector.h:209
iterator end()
Definition: pointer_vector.h:177
boost::indirect_iterator< typename TContainerType::iterator > iterator
Definition: pointer_vector.h:89
iterator begin()
Definition: pointer_vector.h:169
void push_back(const TPointerType &x)
Definition: pointer_vector.h:270
ptr_iterator ptr_begin()
Definition: pointer_vector.h:201
ProcessInfo holds the current value of different solution parameters.
Definition: process_info.h:59
A four node tetrahedra geometry with linear shape functions.
Definition: tetrahedra_3d_4.h:59
static int Split_Tetrahedra(const int edges[6], int t[56], int *nel, int *splitted_edges, int *nint)
Function to split a tetrahedron For a given edges splitting pattern, this function computes the inter...
Definition: split_tetrahedra.h:177
static void TetrahedraSplitMode(int aux_ids[11], int edge_ids[6])
Returns the edges vector filled with the splitting pattern. Provided the array of nodal ids,...
Definition: split_tetrahedra.h:91
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
Short class definition.
Definition: array_1d.h:61
#define KRATOS_THROW_ERROR(ExceptionType, ErrorMessage, MoreInfo)
Definition: define.h:77
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_WATCH(variable)
Definition: define.h:806
#define KRATOS_TRY
Definition: define.h:109
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
int step
Definition: face_heat.py:88
model_part
Definition: face_heat.py:14
int t
Definition: ode_solve.py:392
int j
Definition: quadrature.py:648
int current_id
Output settings end ####.
Definition: script.py:194
integer i
Definition: TensorModule.f:17