13 #if !defined(KRATOS_MSUITE_PFEM_MODELER_H_INCLUDED )
14 #define KRATOS_MSUITE_PFEM_MODELER_H_INCLUDED
24 #include <boost/timer.hpp>
119 Element const& rReferenceElement,
120 Condition const& rReferenceBoundaryCondition,
122 double my_alpha = 1.4,
double h_factor = 0.5)
126 if (ThisModelPart.
NodesBegin()->SolutionStepsDataHas(IS_FREE_SURFACE) ==
false)
127 KRATOS_THROW_ERROR(std::logic_error,
"Add ----IS_FREE_SURFACE---- variable!!!!!! ERROR",
"");
128 if (ThisModelPart.
NodesBegin()->SolutionStepsDataHas(IS_STRUCTURE) ==
false)
129 KRATOS_THROW_ERROR(std::logic_error,
"Add ----IS_STRUCTURE---- variable!!!!!! ERROR",
"");
130 if (ThisModelPart.
NodesBegin()->SolutionStepsDataHas(IS_BOUNDARY) ==
false)
131 KRATOS_THROW_ERROR(std::logic_error,
"Add ----IS_BOUNDARY---- variable!!!!!! ERROR",
"");
132 if (ThisModelPart.
NodesBegin()->SolutionStepsDataHas(IS_FLUID) ==
false)
133 KRATOS_THROW_ERROR(std::logic_error,
"Add ----IS_FLUID---- variable!!!!!! ERROR",
"");
136 boost::timer auxiliary;
139 CleanCloudOfNodes(ThisModelPart,node_erase,h_factor);
153 unsigned int index_I = 1;
154 for (ModelPart::NodesContainerType::iterator in = ThisModelPart.
NodesBegin(); in != ThisModelPart.
NodesEnd(); in++)
156 in->SetId(index_I++);
159 for(Node::DofsContainerType::iterator iii = node_dofs.begin(); iii != node_dofs.end(); iii++)
161 iii->SetId(in->Id());
166 array1<double> new_h( ThisModelPart.
Nodes().size() );
170 int nlen =
int(ThisModelPart.
Nodes().size());
175 new_h[0] = (ThisModelPart.
NodesBegin())->FastGetSolutionStepValue(NODAL_H);
178 m.hmin =
p.h = ThisModelPart.
NodesBegin()->FastGetSolutionStepValue(NODAL_H,1);
180 for (
i = 1;
i < nlen;
i++)
182 new_h[
i] = (ThisModelPart.
NodesBegin() +
i)->FastGetSolutionStepValue(NODAL_H);
183 p.setpos(punto(&((ThisModelPart.
NodesBegin() +
i)->X())));
184 p.set_min_max(
m.pmin,
m.pmax);
187 double hi = (ThisModelPart.
NodesBegin() +
i)->FastGetSolutionStepValue(NODAL_H,1);
195 bool es3D =
m.pmax[2] -
m.pmin[2] > ERRADM;
196 if (!es3D)
m.tipo.set(m_planaxy);
200 m.epsilon =
m.hmin / 1000;
204 m.o =
new octree(
m.n,
m.pmin,
m.pmax, es3D ? 3 : 2);
205 for (
i = 0;
i < nlen;
i++)
m.o->add(
i);
208 bool pasa_elementos =
false;
212 elemento ei((nv == 2) ? e_segmento : ((nv == 3) ? e_triangulo : e_tetraedro));
215 for (
i = 0;
i < elen;
i++)
218 for (
j = 0;
j < nv;
j++)
220 int ix =
int(geom[
j].Id());
226 m.tipo.set((nv == 2) ? m_lin : ((nv == 3) ? m_sup : m_vol));
228 else m.tipo.set(m_nodos);
241 array1<double> shape_functions;
242 m.delaunay_refinado(my_alpha, new_h, nodes_from, shape_functions );
244 int added_nodes =
m.n.len - ThisModelPart.
Nodes().size();
250 int old_size = ThisModelPart.
Nodes().size();
251 for(
int iii=old_size; iii<
m.n.len; iii++)
253 unsigned int id=iii+1;
254 Node::Pointer pnode = ThisModelPart.
CreateNewNode(
id,
m.n[iii][0],
m.n[iii][1],
m.n[iii][2]);
255 pnode->SetBufferSize(ThisModelPart.
NodesBegin()->GetBufferSize() );
256 for(Node::DofsContainerType::iterator iii = reference_dofs.begin(); iii != reference_dofs.end(); iii++)
260 (p_new_dof)->FreeDof();
266 unsigned int buffer_size = ThisModelPart.
NodesBegin()->GetBufferSize();
267 unsigned int dim = 2;
268 for(
int iii=0; iii<added_nodes; iii++)
270 int base = iii * (
dim+1);
272 Node::Pointer pnode = *(ThisModelPart.
NodesBegin() + old_size + iii).base();
276 double* step_data = (pnode)->SolutionStepData().Data(
step);
280 double* node0_data = (ThisModelPart.
NodesBegin() + nodes_from[base + 0] )->SolutionStepData().Data(
step);
281 double* node1_data = (ThisModelPart.
NodesBegin() + nodes_from[base + 1] )->SolutionStepData().Data(
step);
282 double* node2_data = (ThisModelPart.
NodesBegin() + nodes_from[base + 2] )->SolutionStepData().Data(
step);
292 for (
int j = 0;
j < step_data_size;
j++)
293 step_data[
j] = shape_functions[base + 0] * node0_data[
j]
294 + shape_functions[base + 1] * node1_data[
j]
295 + shape_functions[base + 2] * node2_data[
j];
315 ModelPart::NodesContainerType::iterator nodes_begin = ThisModelPart.
NodesBegin();
316 array1< elemento >& el_list =
m.e;
317 (ThisModelPart.
Elements()).reserve(el_list.len);
318 for (
int i = 0;
i < el_list.len;
i++)
321 const elemento& ei = el_list[
i];
324 *((nodes_begin + ei[0]).base()),
325 *((nodes_begin + ei[1]).base()),
326 *((nodes_begin + ei[2]).base())
329 Element::Pointer p_element = rReferenceElement.
Create(
id, geom, properties);
330 (ThisModelPart.
Elements()).push_back(p_element);
336 for (
int k = 0;
k <
m.frontera.len;
k++)
338 const array1< elemento >& el_list_fk =
m.frontera[
k].e;
339 for (
int i = 0;
i < el_list_fk.len;
i++)
342 const elemento& ei = el_list_fk[
i];
349 *((nodes_begin + ei[1]).base()),
350 *((nodes_begin + ei[0]).base())
352 Condition::Pointer p_cond = rReferenceBoundaryCondition.
Create(
id, geom, properties);
353 (ThisModelPart.
Conditions()).push_back(p_cond);
361 for (ModelPart::NodesContainerType::iterator in = ThisModelPart.
NodesBegin(); in != ThisModelPart.
NodesEnd(); in++)
362 in->FastGetSolutionStepValue(IS_BOUNDARY) = 0;
363 for (
int k = 0;
k <
m.frontera.len;
k++)
365 const pline& n_list_fk =
m.frontera[
k].n;
366 for (
int i = 0;
i < n_list_fk.len;
i++)
367 (nodes_begin + n_list_fk[
i])->FastGetSolutionStepValue(IS_BOUNDARY) = 1;
410 KRATOS_WATCH(
"Finished remeshing with Msuite_PFEM_Refine")
432 virtual std::string
Info()
const
508 void CleanCloudOfNodes(
517 unsigned int bucket_size = 20;
518 unsigned int max_results = 100;
523 list_of_nodes.reserve(ThisModelPart.
Nodes().size());
524 for (ModelPart::NodesContainerType::iterator i_node = ThisModelPart.
NodesBegin(); i_node != ThisModelPart.
NodesEnd(); i_node++)
526 (list_of_nodes).push_back(*(i_node.base()));
529 kd_tree nodes_tree1(list_of_nodes.begin(), list_of_nodes.end(), bucket_size);
531 unsigned int n_points_in_radius;
533 Node work_point(0,0.0,0.0,0.0);
534 for (ModelPart::NodesContainerType::iterator in = ThisModelPart.
NodesBegin();
535 in != ThisModelPart.
NodesEnd(); in++)
537 radius = h_factor * in->FastGetSolutionStepValue(NODAL_H,1);
539 work_point[0] = in->X();
540 work_point[1] = in->Y();
541 work_point[2] = in->Z();
543 n_points_in_radius = nodes_tree1.SearchInRadius(work_point,
radius,
res.begin(), res_distances.begin(), max_results);
544 if (n_points_in_radius > 1)
546 if (in->FastGetSolutionStepValue(IS_BOUNDARY,1) == 0.0 && in->FastGetSolutionStepValue(IS_STRUCTURE) == 0.0)
549 unsigned int erased_nodes = 0;
551 erased_nodes += (*i)->Is(TO_ERASE);
553 if (erased_nodes < 1)
554 in->Set(TO_ERASE,
true);
557 else if ((in)->FastGetSolutionStepValue(IS_STRUCTURE) != 1.0)
565 if ((*i)->FastGetSolutionStepValue(IS_BOUNDARY,1) == 1.0 && res_distances[
k] < 0.2 *
radius && res_distances[
k] > 0.0)
572 in->Set(TO_ERASE,
true);
580 boost::numeric::ublas::bounded_matrix<double,3,2> DN_DX;
581 array_1d<double,3>
N;
593 for (ModelPart::ElementsContainerType::iterator ie = ThisModelPart.
ElementsBegin();
596 Geometry<Node >& geom = ie->GetGeometry();
598 unsigned int nstructure = 0;
599 for(
unsigned int i=0;
i<geom.size();
i++)
600 nstructure +=
int(geom[
i].FastGetSolutionStepValue(IS_STRUCTURE) );
609 double havg = geom[0].FastGetSolutionStepValue(NODAL_H) +
610 geom[1].FastGetSolutionStepValue(NODAL_H) +
611 geom[2].FastGetSolutionStepValue(NODAL_H);
612 havg *= 0.333333333333333;
614 for(
unsigned int iii=0; iii<geom.size(); iii++)
616 if(geom[iii].FastGetSolutionStepValue(IS_STRUCTURE) != 1.0)
618 double DNnorm = sqrt( DN_DX(iii,0)*DN_DX(iii,0) + DN_DX(iii,1)*DN_DX(iii,1) );
619 double h = 1.0 / DNnorm;
624 geom[iii].Set(TO_ERASE,
true);
719 rOStream << std::endl;
Short class definition.
Definition: bucket.h:57
Base class for all Conditions.
Definition: condition.h:59
virtual Pointer Create(IndexType NewId, NodesArrayType const &ThisNodes, PropertiesType::Pointer pProperties) const
It creates a new condition pointer.
Definition: condition.h:205
Dof represents a degree of freedom (DoF).
Definition: dof.h:86
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
This process removes the entities from a model part with the flag TO_ERASE.
Definition: entity_erase_process.h:70
void Execute() override
Execute method is used to execute the Process algorithms.
Geometry base class.
Definition: geometry.h:71
static void CalculateGeometryData(const GeometryType &rGeometry, BoundedMatrix< double, 4, 3 > &rDN_DX, array_1d< double, 4 > &rN, double &rVolume)
This function is designed to compute the shape function derivatives, shape functions and volume in 3D...
Definition: geometry_utilities.h:176
An two node 2D line geometry with linear shape functions.
Definition: line_2d_2.h:65
Short class definition.
Definition: msuite_pfem_refine.h:69
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: msuite_pfem_refine.h:445
std::vector< PointType::Pointer > PointVector
Definition: msuite_pfem_refine.h:75
PointVector::iterator PointIterator
Definition: msuite_pfem_refine.h:76
Tree< KDTreePartition< BucketType > > kd_tree
Definition: msuite_pfem_refine.h:80
std::vector< double > DistanceVector
Definition: msuite_pfem_refine.h:77
virtual std::string Info() const
Turn back information as a string.
Definition: msuite_pfem_refine.h:432
virtual void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: msuite_pfem_refine.h:439
Node PointType
Definition: msuite_pfem_refine.h:73
MSuitePFEMModeler()
Default constructor.
Definition: msuite_pfem_refine.h:92
virtual ~MSuitePFEMModeler()
Destructor.
Definition: msuite_pfem_refine.h:99
KRATOS_CLASS_POINTER_DEFINITION(MSuitePFEMModeler)
Pointer definition of TriGenModeler.
std::vector< double >::iterator DistanceIterator
Definition: msuite_pfem_refine.h:78
Node ::Pointer PointPointerType
Definition: msuite_pfem_refine.h:74
Bucket< 3, PointType, PointVector, PointPointerType, PointIterator, DistanceIterator > BucketType
Definition: msuite_pfem_refine.h:79
void ReGenerateMesh(ModelPart &ThisModelPart, Element const &rReferenceElement, Condition const &rReferenceBoundaryCondition, EntitiesEraseProcess< Node > &node_erase, bool rem_nodes=true, bool add_nodes=true, double my_alpha=1.4, double h_factor=0.5)
Definition: msuite_pfem_refine.h:117
PropertiesType::Pointer pGetProperties(IndexType PropertiesId)
Definition: mesh.h:394
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
NodeType::Pointer CreateNewNode(int Id, double x, double y, double z, VariablesList::Pointer pNewVariablesList, IndexType ThisIndex=0)
Definition: model_part.cpp:270
SizeType GetNodalSolutionStepDataSize()
Definition: model_part.h:571
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
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
This class defines the node.
Definition: node.h:65
std::vector< std::unique_ptr< Dof< double > >> DofsContainerType
The DoF container type definition.
Definition: node.h:92
A generic tree data structure for spatial partitioning.
Definition: tree.h:190
A three node 2D triangle geometry with linear shape functions.
Definition: triangle_2d_3.h:74
#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
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
std::vector< PointTypePointer > PointVector
Definition: internal_variables_interpolation_process.h:53
REACTION_CHECK_STIFFNESS_FACTOR int
Definition: contact_structural_mechanics_application_variables.h:75
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
std::vector< double > DistanceVector
Definition: internal_variables_interpolation_process.h:55
int step
Definition: face_heat.py:88
res
Definition: generate_convection_diffusion_explicit_element.py:211
h
Definition: generate_droplet_dynamics.py:91
float radius
Definition: mesh_to_mdpa_converter.py:18
int k
Definition: quadrature.py:595
int j
Definition: quadrature.py:648
int m
Definition: run_marine_rain_substepping.py:8
int counter
Definition: script_THERMAL_CORRECT.py:218
add_nodes
Definition: script.py:96
p
Definition: sensitivityMatrix.py:52
N
Definition: sensitivityMatrix.py:29
int dim
Definition: sensitivityMatrix.py:25
integer i
Definition: TensorModule.f:17