11 #if !defined(KRATOS_TETGEN_CDT_H_INCLUDED )
12 #define KRATOS_TETGEN_CDT_H_INCLUDED
20 #include <boost/timer.hpp>
28 #include "utilities/geometry_utilities.h"
121 boost::timer mesh_recreation_time;
123 out.tetrahedronvolumelist =
new double[
out.numberoftetrahedra];
125 int el_number =
out.numberoftetrahedra;
128 for (
int el = 0;
el< el_number;
el++)
134 ModelPart::NodesContainerType::iterator it1 = (rNodes).find(
out.tetrahedronlist[old_base]);
135 ModelPart::NodesContainerType::iterator it2 = (rNodes).find(
out.tetrahedronlist[old_base+1]);
136 ModelPart::NodesContainerType::iterator it3 = (rNodes).find(
out.tetrahedronlist[old_base+2]);
137 ModelPart::NodesContainerType::iterator it4 = (rNodes).find(
out.tetrahedronlist[old_base+3]);
139 if ( it1 == ThisModelPart.
Nodes().end() )
140 KRATOS_THROW_ERROR(std::logic_error,
"trying to use an inexisting node with id ",it1->Id());
141 if ( it2 == ThisModelPart.
Nodes().end() )
142 KRATOS_THROW_ERROR(std::logic_error,
"trying to use an inexisting node with id ",it2->Id());
143 if ( it3 == ThisModelPart.
Nodes().end() )
144 KRATOS_THROW_ERROR(std::logic_error,
"trying to use an inexisting node with id ",it3->Id());
145 if ( it4 == ThisModelPart.
Nodes().end() )
146 KRATOS_THROW_ERROR(std::logic_error,
"trying to use an inexisting node with id ",it4->Id());
148 Node::Pointer pn1 = *it1.base();
149 Node::Pointer pn2 = *it2.base();
150 Node::Pointer pn3 = *it3.base();
151 Node::Pointer pn4 = *it4.base();
153 double prescribed_h = (pn1)->FastGetSolutionStepValue(NODAL_H);
154 prescribed_h += (pn2)->FastGetSolutionStepValue(NODAL_H);
155 prescribed_h += (pn3)->FastGetSolutionStepValue(NODAL_H);
156 prescribed_h += (pn4)->FastGetSolutionStepValue(NODAL_H);
157 prescribed_h *= 0.25;
163 out.tetrahedronvolumelist[
counter] = 0.217*prescribed_h*prescribed_h*prescribed_h;
169 char mesh_regen_opts[] =
"u0MrqYYnSJQ";
170 tetrahedralize(mesh_regen_opts, &
out, &
outnew);
177 std::cout <<
"mesh recreation time" << mesh_recreation_time.elapsed() << std::endl;
187 int n_points_before_refinement = ThisModelPart.
Nodes().size();
193 InterpolateAndAddNewNodes(ThisModelPart,
outnew,element_finder);
196 if (ThisModelPart.
NodesBegin()->SolutionStepsDataHas(DISPLACEMENT)==
true )
198 for ( ModelPart::NodesContainerType::iterator it = list_of_new_nodes.begin(); it!=list_of_new_nodes.end(); it++)
201 (it)->X0() = (it)->
X() - disp[0];
202 (it)->Y0() = (it)->
Y() - disp[1];
203 (it)->Z0() = (it)->
Z() - disp[2];
208 AddElementsToModelPart(ThisModelPart,
outnew,property_id,rReferenceElement);
215 Element const& rReferenceElement,
216 bool apply_volume_constraints,
217 unsigned int property_id)
222 if (apply_volume_constraints==
true && ThisModelPart.
NodesBegin()->SolutionStepsDataHas(NODAL_H)==
false )
224 if (ThisModelPart.
NodesBegin()->SolutionStepsDataHas(IS_BOUNDARY)==
false )
225 KRATOS_THROW_ERROR(std::logic_error,
"Add ----IS_BOUNDARY---- variable!!!!!! ERROR",
"");
228 for (ModelPart::NodesContainerType::iterator inode = ThisModelPart.
NodesBegin(); inode!=ThisModelPart.
NodesEnd(); inode++)
229 inode->FastGetSolutionStepValue(IS_BOUNDARY) = 1.0;
230 for (ModelPart::ConditionsContainerType::iterator icond = ThisModelPart.
ConditionsBegin(); icond!=ThisModelPart.
ConditionsEnd(); icond++)
233 for (
unsigned int i=0;
i<geom.
size();
i++)
234 geom[
i].FastGetSolutionStepValue(IS_BOUNDARY) = 1.0;
243 for (ModelPart::ElementsContainerType::iterator i_el = ThisModelPart.
ElementsBegin() ; i_el != ThisModelPart.
ElementsEnd() ; i_el++)
244 (AuxModelPart.
Elements()).push_back(*(i_el.base()));
253 temp_nodes_container.reserve(ThisModelPart.
Nodes().size());
254 temp_nodes_container.swap(ThisModelPart.
Nodes());
255 for (ModelPart::NodesContainerType::iterator i_node = temp_nodes_container.begin() ; i_node != temp_nodes_container.end() ; i_node++)
257 if (
static_cast<bool>(i_node->FastGetSolutionStepValue(IS_BOUNDARY)) ==
true)
258 i_node->Set(TO_ERASE,
false);
259 if (
static_cast<bool>(i_node->Is(TO_ERASE)) ==
false)
260 (ThisModelPart.
Nodes()).push_back(*(i_node.base()));
265 for (ModelPart::NodesContainerType::iterator i_node = temp_nodes_container.begin() ; i_node != temp_nodes_container.end() ; i_node++)
284 in.numberofpoints = ThisModelPart.
Nodes().size();
285 in.pointlist =
new REAL[in.numberofpoints * 3];
288 ModelPart::NodesContainerType::iterator nodes_begin = ThisModelPart.
NodesBegin();
289 for (
unsigned int i = 0;
i<ThisModelPart.
Nodes().size();
i++)
292 in.pointlist[base] = (nodes_begin +
i)->
X();
293 in.pointlist[base+1] = (nodes_begin +
i)->
Y();
294 in.pointlist[base+2] = (nodes_begin +
i)->
Z();
298 in.numberoffacets = ThisModelPart.
Conditions().size();;
299 in.facetmarkerlist =
new int[in.numberoffacets];
300 in.facetlist =
new tetgenio::facet[in.numberoffacets];
301 ModelPart::ConditionsContainerType::iterator it = ThisModelPart.
ConditionsBegin();
303 tetgenio::polygon *
p;
304 for (
int ii=0; ii<in.numberoffacets ; ++ii)
306 f = &in.facetlist[ii];
307 f->numberofpolygons = 1;
308 f->polygonlist =
new tetgenio::polygon[
f->numberofpolygons];
309 f->numberofholes = 0;
310 f->holelist =
nullptr;
314 p = &
f->polygonlist[0];
315 p->numberofvertices = 3;
316 p->vertexlist =
new int[
p->numberofvertices];
317 p->vertexlist[0] = geom[0].
Id();
318 p->vertexlist[1] = geom[1].
Id();
319 p->vertexlist[2] = geom[2].
Id();
326 char tetgen_options[] =
"pqYYfnJu0MQ";
327 tetrahedralize(tetgen_options, &in, &
out);
332 InterpolateAndAddNewNodes(ThisModelPart,
out,element_finder);
342 if (apply_volume_constraints==
true)
344 addNodes(ThisModelPart, rReferenceElement,
true,property_id, element_finder);
349 AddElementsToModelPart(ThisModelPart,
out,property_id,rReferenceElement);
353 std::vector<unsigned int> el_per_node(
outnew.numberofpoints, 0 );
354 for (
int iii = 0; iii<
outnew.numberoftetrahedra*4; iii++)
355 el_per_node[
outnew.tetrahedronlist[iii]-1 ] += 1;
358 for(
unsigned int i=0;
i<
static_cast<unsigned int>(
outnew.numberofpoints);
i++)
360 if(el_per_node[
i] == 0)
361 ThisModelPart.
Nodes().find(
i+1 )->Set(TO_ERASE,
true);
366 aux_nodes_container.reserve(ThisModelPart.
Nodes().size());
367 aux_nodes_container.swap(ThisModelPart.
Nodes());
368 for (ModelPart::NodesContainerType::iterator i_node = aux_nodes_container.begin() ; i_node != aux_nodes_container.end() ; i_node++)
370 if (
static_cast<bool>(i_node->Is(TO_ERASE)) ==
false)
371 (ThisModelPart.
Nodes()).push_back(*(i_node.base()));
395 virtual std::string
Info()
const
459 void AddElementsToModelPart(
ModelPart& rModelPart, tetgenio& tet,
unsigned int property_id,
Element const& rReferenceElement)
465 boost::timer adding_elems;
469 (rModelPart.
Elements()).reserve(tet.numberoftetrahedra);
471 for (
int iii = 0; iii< tet.numberoftetrahedra; iii++)
477 ModelPart::NodesContainerType::iterator it1 = (ModelNodes).find( tet.tetrahedronlist[base]);
478 ModelPart::NodesContainerType::iterator it2 = (ModelNodes).find( tet.tetrahedronlist[base+1]);
479 ModelPart::NodesContainerType::iterator it3 = (ModelNodes).find( tet.tetrahedronlist[base+2]);
480 ModelPart::NodesContainerType::iterator it4 = (ModelNodes).find( tet.tetrahedronlist[base+3]);
482 if ( it1 == rModelPart.
Nodes().end() )
483 KRATOS_THROW_ERROR(std::logic_error,
"trying to use an inexisting node with id ",it1->Id());
484 if ( it2 == rModelPart.
Nodes().end() )
485 KRATOS_THROW_ERROR(std::logic_error,
"trying to use an inexisting node with id ",it2->Id());
486 if ( it3 == rModelPart.
Nodes().end() )
487 KRATOS_THROW_ERROR(std::logic_error,
"trying to use an inexisting node with id ",it3->Id());
488 if ( it4 == rModelPart.
Nodes().end() )
489 KRATOS_THROW_ERROR(std::logic_error,
"trying to use an inexisting node with id ",it4->Id());
491 Node::Pointer pn1 = *it1.base();
492 Node::Pointer pn2 = *it2.base();
493 Node::Pointer pn3 = *it3.base();
494 Node::Pointer pn4 = *it4.base();
498 Element::Pointer p_element = rReferenceElement.
Create(
id, geom, properties);
499 (rModelPart.
Elements()).push_back(p_element);
502 std::cout <<
"time for adding elems" << adding_elems.elapsed() << std::endl;;
508 void InterpolateAndAddNewNodes(ModelPart& rModelPart, tetgenio& tet, BinBasedFastPointLocator<3>& element_finder)
510 unsigned int n_points_before_refinement = rModelPart.Nodes().size();
513 if (
static_cast<unsigned int>(tet.numberofpoints)>n_points_before_refinement)
518 array_1d<double, 4 >
N;
519 const int max_results = 10000;
524 int step_data_size = rModelPart.GetNodalSolutionStepDataSize();
527 for (
int i = n_points_before_refinement;
i<tet.numberofpoints;
i++)
531 double&
x= tet.pointlist[base];
532 double&
y= tet.pointlist[base+1];
533 double&
z= tet.pointlist[base+2];
535 Node::Pointer pnode = rModelPart.CreateNewNode(
id,
x,
y,
z);
543 for (Node::DofsContainerType::iterator iii = reference_dofs.begin(); iii != reference_dofs.end(); iii++)
548 (p_new_dof)->FreeDof();
552 auto result_begin = results.begin();
553 Element::Pointer pelement;
555 bool is_found = element_finder.FindPointOnMesh(pnode->Coordinates(),
N, pelement, result_begin, max_results);
558 if (is_found ==
true)
560 Geometry<Node >& geom = pelement->GetGeometry();
562 Interpolate( geom,
N, step_data_size, pnode);
568 std::cout <<
"During refinement we added " << tet.numberofpoints-n_points_before_refinement<<
"nodes " <<std::endl;
574 void Interpolate( Geometry<Node >& geom,
const array_1d<double,4>&
N,
575 unsigned int step_data_size,
578 unsigned int buffer_size = pnode->GetBufferSize();
585 double* step_data = (pnode)->SolutionStepData().Data(
step);
588 double* node0_data = geom[0].SolutionStepData().Data(
step);
589 double* node1_data = geom[1].SolutionStepData().Data(
step);
590 double* node2_data = geom[2].SolutionStepData().Data(
step);
591 double* node3_data = geom[3].SolutionStepData().Data(
step);
594 for (
unsigned int j= 0;
j<step_data_size;
j++)
597 step_data[
j] =
N[0]*node0_data[
j] +
N[1]*node1_data[
j] +
N[2]*node2_data[
j] +
N[3]*node3_data[
j];
602 pnode->FastGetSolutionStepValue(IS_BOUNDARY)=0.0;
607 template<
class T, std::
size_t dim >
611 double operator()( T
const& p1, T
const& p2 )
614 for ( std::size_t
i = 0 ;
i <
dim ;
i++)
616 double tmp = p1[
i] - p2[
i];
623 template<
class T, std::
size_t dim >
624 class DistanceCalculator
627 double operator()( T
const& p1, T
const& p2 )
630 for ( std::size_t
i = 0 ;
i <
dim ;
i++)
632 double tmp = p1[
i] - p2[
i];
690 rOStream << std::endl;
This class is designed to allow the fast location of MANY points on the top of a 3D mesh.
Definition: binbased_fast_point_locator.h:68
void UpdateSearchDatabase()
Function to construct or update the search database.
Definition: binbased_fast_point_locator.h:139
ConfigureType::ResultContainerType ResultContainerType
Definition: binbased_fast_point_locator.h:81
Dof * Pointer
Pointer definition of Dof.
Definition: dof.h:93
Base class for all Elements.
Definition: element.h:60
virtual Pointer Create(IndexType NewId, NodesArrayType const &ThisNodes, PropertiesType::Pointer pProperties) const
It creates a new element pointer.
Definition: element.h:202
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
PropertiesType::Pointer pGetProperties(IndexType PropertiesId)
Definition: mesh.h:394
ModelPart & CreateModelPart(const std::string &ModelPartName, IndexType NewBufferSize=1)
This method creates a new model part contained in the current Model with a given name and buffer size...
Definition: model.cpp:37
void DeleteModelPart(const std::string &ModelPartName)
This method deletes a modelpart with a given name.
Definition: model.cpp:64
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
ElementIterator ElementsBegin(IndexType ThisIndex=0)
Definition: model_part.h:1169
ConditionIterator ConditionsBegin(IndexType ThisIndex=0)
Definition: model_part.h:1361
NodeIterator NodesBegin(IndexType ThisIndex=0)
Definition: model_part.h:487
ConditionsContainerType & Conditions(IndexType ThisIndex=0)
Definition: model_part.h:1381
ElementsContainerType & Elements(IndexType ThisIndex=0)
Definition: model_part.h:1189
MeshType::NodesContainerType NodesContainerType
Nodes container. Which is a vector set of nodes with their Id's as key.
Definition: model_part.h:128
ElementIterator ElementsEnd(IndexType ThisIndex=0)
Definition: model_part.h:1179
NodeIterator NodesEnd(IndexType ThisIndex=0)
Definition: model_part.h:497
MeshType & GetMesh(IndexType ThisIndex=0)
Definition: model_part.h:1791
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
Model & GetModel()
Definition: model_part.h:323
ConditionIterator ConditionsEnd(IndexType ThisIndex=0)
Definition: model_part.h:1371
Dof< double > DofType
Dof type.
Definition: node.h:83
std::vector< std::unique_ptr< Dof< double > >> DofsContainerType
The DoF container type definition.
Definition: node.h:92
Short class definition.
Definition: tetgen_cdt.h:66
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: tetgen_cdt.h:404
void addNodes(ModelPart &ThisModelPart, Element const &rReferenceElement, bool apply_volume_constraints, unsigned int property_id, BinBasedFastPointLocator< 3 > element_finder)
Definition: tetgen_cdt.h:117
KRATOS_CLASS_POINTER_DEFINITION(TetGenCDT)
Pointer definition of TetGenCDT.
virtual void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: tetgen_cdt.h:401
tetgenio outnew
Definition: tetgen_cdt.h:116
void GenerateCDT(ModelPart &ThisModelPart, Element const &rReferenceElement, bool apply_volume_constraints, unsigned int property_id)
Definition: tetgen_cdt.h:213
virtual ~TetGenCDT()=default
Destructor.
TetGenCDT()
Default constructor.
Definition: tetgen_cdt.h:80
tetgenio out
Definition: tetgen_cdt.h:116
virtual std::string Info() const
Turn back information as a string.
Definition: tetgen_cdt.h:395
A four node tetrahedra geometry with linear shape functions.
Definition: tetrahedra_3d_4.h:59
#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
#define REAL
Definition: delaunator_utilities.cpp:16
z
Definition: GenerateWind.py:163
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
float dist
Definition: edgebased_PureConvection.py:89
int step
Definition: face_heat.py:88
y
Other simbols definition.
Definition: generate_axisymmetric_navier_stokes_element.py:54
f
Definition: generate_convection_diffusion_explicit_element.py:112
tuple tmp
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:98
int j
Definition: quadrature.py:648
el
Definition: read_stl.py:25
int counter
Definition: script_THERMAL_CORRECT.py:218
p
Definition: sensitivityMatrix.py:52
N
Definition: sensitivityMatrix.py:29
x
Definition: sensitivityMatrix.py:49
int dim
Definition: sensitivityMatrix.py:25
integer i
Definition: TensorModule.f:17