14 #if !defined(KRATOS_TRIGEN_PFEM_REFINE_SEGMENT_H_INCLUDED )
15 #define KRATOS_TRIGEN_PFEM_REFINE_SEGMENT_H_INCLUDED
35 void triangulate(
char *,
struct triangulateio *,
struct triangulateio *,
struct triangulateio *);
102 Element const& rReferenceElement,
103 Condition const& rReferenceBoundaryCondition,
105 double my_alpha = 1.4,
double h_factor=0.5)
109 if (ThisModelPart.
NodesBegin()->SolutionStepsDataHas(IS_FREE_SURFACE)==
false )
110 KRATOS_THROW_ERROR(std::logic_error,
"Add ----IS_FREE_SURFACE---- variable!!!!!! ERROR",
"");
111 if (ThisModelPart.
NodesBegin()->SolutionStepsDataHas(IS_STRUCTURE)==
false )
112 KRATOS_THROW_ERROR(std::logic_error,
"Add ----IS_STRUCTURE---- variable!!!!!! ERROR",
"");
113 if (ThisModelPart.
NodesBegin()->SolutionStepsDataHas(IS_BOUNDARY)==
false )
114 KRATOS_THROW_ERROR(std::logic_error,
"Add ----IS_BOUNDARY---- variable!!!!!! ERROR",
"");
115 if (ThisModelPart.
NodesBegin()->SolutionStepsDataHas(IS_FLUID)==
false )
117 if (ThisModelPart.
NodesBegin()->SolutionStepsDataHas(IS_WATER)==
false )
119 if (ThisModelPart.
NodesBegin()->SolutionStepsDataHas(IS_INTERFACE)==
false )
120 KRATOS_THROW_ERROR(std::logic_error,
"Add ----IS_INTERFACE---- variable!!!!!! ERROR",
"");
123 const auto inital_time = std::chrono::steady_clock::now();
132 std::vector <int> mid_seg_list;
134 int num_interface = 0;
135 SegmentDetecting(ThisModelPart, mid_seg_list, seg_num, num_interface, h_factor);
143 typedef Node::Pointer PointPointerType;
144 typedef std::vector<PointType::Pointer>
PointVector;
162 unsigned int bucket_size = 64;
165 unsigned int max_results = 500;
170 Node work_point(0,0.0,0.0,0.0);
260 list_of_nodes.reserve(ThisModelPart.
Nodes().size());
261 for(ModelPart::NodesContainerType::iterator i_node = ThisModelPart.
NodesBegin() ; i_node != ThisModelPart.
NodesEnd() ; i_node++)
263 (list_of_nodes).push_back(*(i_node.base()));
266 kd_tree nodes_tree1(list_of_nodes.begin(),list_of_nodes.end(), bucket_size);
268 unsigned int n_points_in_radius;
272 for(ModelPart::NodesContainerType::const_iterator in = ThisModelPart.
NodesBegin();
273 in != ThisModelPart.
NodesEnd(); in++)
275 radius=h_factor*in->FastGetSolutionStepValue(NODAL_H);
277 work_point[0]=in->
X();
278 work_point[1]=in->
Y();
279 work_point[2]=in->
Z();
281 n_points_in_radius = nodes_tree1.SearchInRadius(work_point,
radius,
res.begin(),res_distances.begin(), max_results);
282 if (n_points_in_radius>1)
284 if (in->FastGetSolutionStepValue(IS_BOUNDARY)==0.0 && in->FastGetSolutionStepValue(IS_STRUCTURE)==0.0 && in->FastGetSolutionStepValue(IS_INTERFACE)==0.0)
287 double erased_nodes = 0;
288 for(
auto i=
res.begin();
i!=
res.begin() + n_points_in_radius ;
i++)
289 erased_nodes += (*i)->Is(TO_ERASE);
301 if( erased_nodes < 1.0)
302 in->Set(TO_ERASE,
true);
306 else if ( (in)->FastGetSolutionStepValue(IS_STRUCTURE)!=1.0)
312 for(
auto i=
res.begin();
i!=
res.begin() + n_points_in_radius ;
i++)
314 if ( (*i)->FastGetSolutionStepValue(IS_BOUNDARY,1)==1.0 && res_distances[
k] < 0.2*
radius && res_distances[
k] > 0.0 )
322 in->Set(TO_ERASE,
true);
328 for(ModelPart::NodesContainerType::const_iterator in = ThisModelPart.
NodesBegin();
329 in != ThisModelPart.
NodesEnd(); in++)
331 if((in)->FastGetSolutionStepValue(IS_INTERFACE) == 1.0)
332 in->Set(TO_ERASE,
false);
347 struct triangulateio in_mid;
348 struct triangulateio out_mid;
349 struct triangulateio vorout_mid;
351 initialize_triangulateio(in_mid);
352 initialize_triangulateio(out_mid);
353 initialize_triangulateio(vorout_mid);
357 in_mid.numberofpoints = ThisModelPart.
Nodes().size();
358 in_mid.pointlist = (
REAL *) malloc(in_mid.numberofpoints * 2 *
sizeof(
REAL));
361 ModelPart::NodesContainerType::iterator nodes_begin = ThisModelPart.
NodesBegin();
362 std::vector <int> reorder_mid_seg_list;
364 reorder_mid_seg_list.resize(seg_num*2,
false);
366 for(
unsigned int i = 0;
i<ThisModelPart.
Nodes().size();
i++)
372 int pr_id = (nodes_begin +
i)->Id();
374 (nodes_begin +
i)->SetId(
i+1);
377 in_mid.pointlist[base] = (nodes_begin +
i)->
X();
378 in_mid.pointlist[base+1] = (nodes_begin +
i)->
Y();
380 auto& node_dofs = (nodes_begin +
i)->GetDofs();
381 for(
auto iii = node_dofs.begin(); iii != node_dofs.end(); iii++)
383 (**iii).SetEquationId(
i+1);
388 if( (nodes_begin +
i)->FastGetSolutionStepValue(IS_INTERFACE) == 1.0 )
390 for(
int jj = 0; jj < seg_num*2; ++jj)
391 if( mid_seg_list[jj] == pr_id)
392 reorder_mid_seg_list[jj] = (nodes_begin +
i)->Id();
408 in_mid.numberofsegments = seg_num;
409 in_mid.segmentlist = (
int*) malloc(in_mid.numberofsegments * 2 *
sizeof(
int));
410 in_mid.segmentmarkerlist = (
int*) malloc(in_mid.numberofsegments *
sizeof(
int));
412 for(
int ii = 0; ii < seg_num*2; ++ii)
413 in_mid.segmentlist[ii] = reorder_mid_seg_list[ii];
415 for(
int jj = 0; jj < seg_num ; ++jj)
416 in_mid.segmentmarkerlist[jj] = 5;
468 char options1[] =
"pcne";
471 triangulate(options1, &in_mid, &out_mid, &vorout_mid);
475 unsigned int el_number=out_mid.numberoftriangles;
481 std::vector<int> preserved_list1(el_number);
482 preserved_list1.resize(el_number);
502 int number_of_preserved_elems=0;
505 for(
unsigned int el = 0;
el< el_number;
el++)
510 point_base = (out_mid.trianglelist[base] - 1)*2;
511 x1[0] = out_mid.pointlist[point_base];
512 x1[1] = out_mid.pointlist[point_base+1];
514 point_base = (out_mid.trianglelist[base+1] - 1)*2;
515 x2[0] = out_mid.pointlist[point_base];
516 x2[1] = out_mid.pointlist[point_base+1];
518 point_base = (out_mid.trianglelist[base+2] - 1)*2;
519 x3[0] = out_mid.pointlist[point_base];
520 x3[1] = out_mid.pointlist[point_base+1];
525 temp.push_back( *((ThisModelPart.
Nodes()).find( out_mid.trianglelist[base]).base() ) );
526 temp.push_back( *((ThisModelPart.
Nodes()).find( out_mid.trianglelist[base+1]).base() ) );
527 temp.push_back( *((ThisModelPart.
Nodes()).find( out_mid.trianglelist[base+2]).base() ) );
529 int number_of_structure_nodes =
int(
temp[0].FastGetSolutionStepValue(IS_STRUCTURE) );
530 number_of_structure_nodes +=
int(
temp[1].FastGetSolutionStepValue(IS_STRUCTURE) );
531 number_of_structure_nodes +=
int(
temp[2].FastGetSolutionStepValue(IS_STRUCTURE) );
534 int nfs =
int(
temp[0].FastGetSolutionStepValue(IS_FREE_SURFACE) );
535 nfs +=
int(
temp[1].FastGetSolutionStepValue(IS_FREE_SURFACE) );
536 nfs +=
int(
temp[2].FastGetSolutionStepValue(IS_FREE_SURFACE) );
539 int nfluid =
int(
temp[0].FastGetSolutionStepValue(IS_FLUID) );
540 nfluid +=
int(
temp[1].FastGetSolutionStepValue(IS_FLUID) );
541 nfluid +=
int(
temp[2].FastGetSolutionStepValue(IS_FLUID) );
544 int num_interface = 0;
545 for(
int ii = 0; ii<3; ++ii)
546 if(
temp[ii].FastGetSolutionStepValue(IS_INTERFACE) == 1.0)
562 if(number_of_structure_nodes!=3)
564 if (nfs != 0 || nfluid != 3)
567 if( AlphaShape(my_alpha,
temp) && number_of_structure_nodes!=3)
569 preserved_list1[
el] =
true;
570 number_of_preserved_elems += 1;
576 double bigger_alpha = my_alpha*5.0;
577 if( AlphaShape(bigger_alpha,
temp) && number_of_structure_nodes!=3)
579 preserved_list1[
el] =
true;
580 number_of_preserved_elems += 1;
585 preserved_list1[
el] =
false;
592 struct triangulateio in2;
593 struct triangulateio out2;
594 struct triangulateio vorout2;
596 initialize_triangulateio(in2);
597 initialize_triangulateio(out2);
598 initialize_triangulateio(vorout2);
601 in2.numberofpoints = ThisModelPart.
Nodes().size();
602 in2.pointlist = (
REAL *) malloc(in2.numberofpoints * 2 *
sizeof(
REAL));
605 for(
unsigned int i = 0;
i<ThisModelPart.
Nodes().size();
i++)
608 in2.pointlist[base] = (nodes_begin +
i)->
X();
609 in2.pointlist[base+1] = (nodes_begin +
i)->
Y();
611 in2.numberoftriangles=number_of_preserved_elems;
613 in2.trianglelist = (
int *) malloc(in2.numberoftriangles * 3 *
sizeof(
int));
614 in2.trianglearealist = (
REAL *) malloc(in2.numberoftriangles *
sizeof(
REAL));
620 for (
unsigned int el=0;
el<el_number;
el++)
622 if( preserved_list1[
el] )
628 in2.trianglelist[new_base] = out_mid.trianglelist[old_base];
629 in2.trianglelist[new_base+1] = out_mid.trianglelist[old_base+1];
630 in2.trianglelist[new_base+2] = out_mid.trianglelist[old_base+2];
633 double prescribed_h = (nodes_begin + out_mid.trianglelist[old_base]-1)->FastGetSolutionStepValue(NODAL_H);
634 prescribed_h += (nodes_begin + out_mid.trianglelist[old_base+1]-1)->FastGetSolutionStepValue(NODAL_H);
635 prescribed_h += (nodes_begin + out_mid.trianglelist[old_base+2]-1)->FastGetSolutionStepValue(NODAL_H);
636 prescribed_h *= 0.3333;
638 in2.trianglearealist[
counter] = 0.5*(1.5*prescribed_h*1.5*prescribed_h);
683 in2.numberofsegments = seg_num;
684 in2.segmentlist = (
int*) malloc(in2.numberofsegments * 2 *
sizeof(
int));
685 in2.segmentmarkerlist = (
int*) malloc(in2.numberofsegments *
sizeof(
int));
687 for(
int ii = 0; ii < seg_num*2; ++ii)
689 in2.segmentlist[ii] = reorder_mid_seg_list[ii];
691 for(
int jj = 0; jj < seg_num ; ++jj)
692 in2.segmentmarkerlist[jj] = 5;
709 char mesh_regen_opts[] =
"Yjaqrpcn";
710 triangulate(mesh_regen_opts, &in2, &out2, &vorout2);
711 KRATOS_WATCH(
"Adaptive remeshing with segment executed")
715 char mesh_regen_opts[] =
"YJrn";
716 triangulate(mesh_regen_opts, &in2, &out2, &vorout2);
754 typedef Node::Pointer PointPointerType;
755 typedef std::vector<PointType::Pointer>
PointVector;
775 int n_points_before_refinement = in2.numberofpoints;
777 if (out2.numberofpoints > n_points_before_refinement )
779 for(
int i = n_points_before_refinement;
i<out2.numberofpoints;
i++)
783 double&
x= out2.pointlist[base];
784 double&
y= out2.pointlist[base+1];
788 pnode->SetBufferSize(ThisModelPart.
NodesBegin()->GetBufferSize() );
790 list_of_new_nodes.push_back( pnode );
794 if(out2.pointmarkerlist[
i] == 5)
796 pnode->FastGetSolutionStepValue(IS_INTERFACE) = 1.0;
801 pnode->FastGetSolutionStepValue(IS_INTERFACE) = 0.0;
806 for(Node::DofsContainerType::iterator iii = reference_dofs.begin(); iii != reference_dofs.end(); iii++)
811 (p_new_dof)->FreeDof();
819 std::cout <<
"During refinement we added " << out2.numberofpoints-n_points_before_refinement<<
" nodes " <<std::endl;
829 unsigned int MaximumNumberOfResults = list_of_new_nodes.size();
836 if(out2.numberofpoints-n_points_before_refinement > 0)
839 kd_tree nodes_tree2(list_of_new_nodes.begin(),list_of_new_nodes.end(),bucket_size);
842 for(
int el = 0;
el< in2.numberoftriangles;
el++)
846 point_base = (in2.trianglelist[base] - 1)*2;
847 x1[0] = in2.pointlist[point_base];
848 x1[1] = in2.pointlist[point_base+1];
850 point_base = (in2.trianglelist[base+1] - 1)*2;
851 x2[0] = in2.pointlist[point_base];
852 x2[1] = in2.pointlist[point_base+1];
854 point_base = (in2.trianglelist[base+2] - 1)*2;
855 x3[0] = in2.pointlist[point_base];
856 x3[1] = in2.pointlist[point_base+1];
861 CalculateCenterAndSearchRadius(
x1[0],
x1[1],
867 int number_of_points_in_radius;
870 work_point.
Z() = 0.0;
872 number_of_points_in_radius = nodes_tree2.SearchInRadius(work_point,
radius, Results.begin(),
873 ResultsDistances.begin(), MaximumNumberOfResults);
876 *( (nodes_begin + in2.trianglelist[base]-1).base() ),
877 *( (nodes_begin + in2.trianglelist[base+1]-1).base() ),
878 *( (nodes_begin + in2.trianglelist[base+2]-1).base() )
882 for(
auto it_found = Results.begin(); it_found != Results.begin() + number_of_points_in_radius; it_found++)
884 bool is_inside =
false;
888 (*it_found)->X(),(*it_found)->Y(),
N);
891 if(is_inside ==
true)
893 double regionflag = 0.0;
895 Interpolate( geom,
N, step_data_size, *(it_found ), regionflag);
905 for(
auto & list_of_new_node : list_of_new_nodes)
907 const array_1d<double,3>& disp = list_of_new_node->FastGetSolutionStepValue(DISPLACEMENT);
908 list_of_new_node->X0() = list_of_new_node->X() - disp[0];
909 list_of_new_node->Y0() = list_of_new_node->Y() - disp[1];
910 list_of_new_node->Z0() = 0.0;
920 (ThisModelPart.
Elements()).reserve(out2.numberoftriangles);
922 for(
int iii = 0; iii< out2.numberoftriangles; iii++)
927 *( (nodes_begin + out2.trianglelist[base]-1).base() ),
928 *( (nodes_begin + out2.trianglelist[base+1]-1).base() ),
929 *( (nodes_begin + out2.trianglelist[base+2]-1).base() )
935 if( *(ModelNodes).find( out2.trianglelist[base]).base() == *(ThisModelPart.
Nodes().end()).base() )
937 if( *(ModelNodes).find( out2.trianglelist[base+1]).base() == *(ThisModelPart.
Nodes().end()).base() )
939 if( *(ModelNodes).find( out2.trianglelist[base+2]).base() == *(ThisModelPart.
Nodes().end()).base() )
944 Element::Pointer p_element = rReferenceElement.
Create(
id, geom, properties);
945 (ThisModelPart.
Elements()).push_back(p_element);
951 ModelPart::ElementsContainerType::const_iterator el_begin = ThisModelPart.
ElementsBegin();
952 for(ModelPart::ElementsContainerType::const_iterator iii = ThisModelPart.
ElementsBegin();
956 int base = ( iii->Id() - 1 )*3;
958 (iii->GetValue(NEIGHBOUR_ELEMENTS)).resize(3);
960 for(
int i = 0;
i<3;
i++)
962 int index = out2.neighborlist[base+
i];
966 neighb(
i) = Element::WeakPointer();
971 for(ModelPart::NodesContainerType::const_iterator in = ThisModelPart.
NodesBegin(); in!=ThisModelPart.
NodesEnd(); in++)
973 in->FastGetSolutionStepValue(IS_BOUNDARY) = 0;
976 ModelPart::ElementsContainerType::iterator elements_end = ThisModelPart.
Elements().end();
981 for(ModelPart::ElementsContainerType::iterator iii = ThisModelPart.
ElementsBegin(); iii != ThisModelPart.
ElementsEnd(); iii++)
983 int base = ( iii->Id() - 1 )*3;
985 ModelPart::ElementsContainerType::iterator el_neighb;
996 el_neighb = (ThisModelPart.
Elements()).find( out2.neighborlist[base] );
997 if( el_neighb == elements_end )
1001 iii->GetGeometry()[1].FastGetSolutionStepValue(IS_BOUNDARY) = 1;
1002 iii->GetGeometry()[2].FastGetSolutionStepValue(IS_BOUNDARY) = 1;
1007 temp.push_back(iii->GetGeometry()(2));
1008 temp.push_back(iii->GetGeometry()(1));
1012 int id = (iii->Id()-1)*3;
1017 Condition::Pointer p_cond = rReferenceBoundaryCondition.
Create(
id,
temp, properties);
1018 (ThisModelPart.
Conditions()).push_back(p_cond);
1025 el_neighb = (ThisModelPart.
Elements()).find( out2.neighborlist[base+1] );
1027 if( el_neighb == elements_end )
1030 iii->GetGeometry()[2].FastGetSolutionStepValue(IS_BOUNDARY) = 1;
1031 iii->GetGeometry()[0].FastGetSolutionStepValue(IS_BOUNDARY) = 1;
1036 temp.push_back(iii->GetGeometry()(0));
1037 temp.push_back(iii->GetGeometry()(2));
1041 int id = (iii->Id()-1)*3+1;
1046 Condition::Pointer p_cond = rReferenceBoundaryCondition.
Create(
id,
temp, properties);
1047 (ThisModelPart.
Conditions()).push_back(p_cond);
1054 el_neighb = (ThisModelPart.
Elements()).find( out2.neighborlist[base+2] );
1055 if( el_neighb == elements_end )
1058 iii->GetGeometry()[0].FastGetSolutionStepValue(IS_BOUNDARY) = 1;
1059 iii->GetGeometry()[1].FastGetSolutionStepValue(IS_BOUNDARY) = 1;
1064 temp.push_back(iii->GetGeometry()(1));
1065 temp.push_back(iii->GetGeometry()(0));
1068 int id = (iii->Id()-1)*3+2;
1073 Condition::Pointer p_cond = rReferenceBoundaryCondition.
Create(
id,
temp, properties);
1074 (ThisModelPart.
Conditions()).push_back(p_cond);
1085 clean_triangulateio(in2);
1087 clean_triangulateio(out2);
1089 clean_triangulateio(vorout2);
1090 KRATOS_WATCH(
"Finished remeshing with Trigen_PFEM_Refine_segment")
1175 boost::numeric::ublas::bounded_matrix<double,2,2> mJ;
1176 boost::numeric::ublas::bounded_matrix<double,2,2> mJinv;
1192 double x0 = pgeom[0].X();
1193 double x1 = pgeom[1].X();
1194 double x2 = pgeom[2].X();
1196 double y0 = pgeom[0].Y();
1197 double y1 = pgeom[1].Y();
1198 double y2 = pgeom[2].Y();
1200 mJ(0,0)=2.0*(
x1-x0);
1201 mJ(0,1)=2.0*(y1-y0);
1202 mJ(1,0)=2.0*(
x2-x0);
1203 mJ(1,1)=2.0*(y2-y0);
1206 double detJ = mJ(0,0)*mJ(1,1)-mJ(0,1)*mJ(1,0);
1208 mJinv(0,0) = mJ(1,1);
1209 mJinv(0,1) = -mJ(0,1);
1210 mJinv(1,0) = -mJ(1,0);
1211 mJinv(1,1) = mJ(0,0);
1213 bounded_matrix<double,2,2> check;
1217 h = pgeom[0].FastGetSolutionStepValue(NODAL_H);
1218 h += pgeom[1].FastGetSolutionStepValue(NODAL_H);
1219 h += pgeom[2].FastGetSolutionStepValue(NODAL_H);
1227 pgeom[0].GetSolutionStepValue(IS_BOUNDARY) = 1;
1228 pgeom[1].GetSolutionStepValue(IS_BOUNDARY) = 1;
1229 pgeom[2].GetSolutionStepValue(IS_BOUNDARY) = 1;
1236 double x0_2 = x0*x0 + y0*y0;
1237 double x1_2 =
x1*
x1 + y1*y1;
1238 double x2_2 =
x2*
x2 + y2*y2;
1244 mRhs[0] = (x1_2 - x0_2);
1245 mRhs[1] = (x2_2 - x0_2);
1250 double radius = sqrt(pow(mC[0]-x0,2)+pow(mC[1]-y0,2));
1267 inline void CalculateCenterAndSearchRadius(
const double x0,
const double y0,
1268 const double x1,
const double y1,
1269 const double x2,
const double y2,
1270 double&
xc,
double&
yc,
double&
R
1273 xc = 0.3333333333333333333*(x0+
x1+
x2);
1274 yc = 0.3333333333333333333*(y0+y1+y2);
1276 double R1 = (
xc-x0)*(
xc-x0) + (
yc-y0)*(
yc-y0);
1287 inline double CalculateVol(
const double x0,
const double y0,
1288 const double x1,
const double y1,
1289 const double x2,
const double y2
1292 return 0.5*( (
x1-x0)*(y2-y0)- (y1-y0)*(
x2-x0) );
1296 const double x1,
const double y1,
1297 const double x2,
const double y2,
1298 const double xc,
const double yc,
1299 array_1d<double,3>&
N
1303 double inv_area = 0.0;
1304 if(area < 0.0000000000000001)
1310 inv_area = 1.0 / area;
1322 if(
N[0] >= 0.0 &&
N[1] >= 0.0 &&
N[2] >= 0.0 &&
N[0] <= 1.0 &&
N[1] <= 1.0 &&
N[2] <= 1.0)
1330 void Interpolate( Triangle2D3<Node >& geom,
const array_1d<double,3>&
N,
1331 unsigned int step_data_size,
1332 Node::Pointer pnode,
double region_flag)
1334 unsigned int buffer_size = pnode->GetBufferSize();
1339 double aux_interface = pnode->FastGetSolutionStepValue(IS_INTERFACE);
1345 double* step_data = (pnode)->SolutionStepData().Data(
step);
1348 double* node0_data = geom[0].SolutionStepData().Data(
step);
1349 double* node1_data = geom[1].SolutionStepData().Data(
step);
1350 double* node2_data = geom[2].SolutionStepData().Data(
step);
1353 for(
unsigned int j= 0;
j<step_data_size;
j++)
1356 step_data[
j] =
N[0]*node0_data[
j] +
N[1]*node1_data[
j] +
N[2]*node2_data[
j];
1361 if (
N[0]==0.0 &&
N[1]==0.0 &&
N[2]==0.0)
1362 KRATOS_THROW_ERROR(std::logic_error,
"SOMETHING's wrong with the added nodes!!!!!! ERROR",
"");
1373 pnode->FastGetSolutionStepValue(IS_BOUNDARY)=0.0;
1374 pnode->FastGetSolutionStepValue(IS_STRUCTURE)=0.0;
1375 pnode->Set(TO_ERASE,
false);
1376 pnode->FastGetSolutionStepValue(IS_FREE_SURFACE)=0.0;
1377 pnode->FastGetSolutionStepValue(IS_FLUID)=1.0;
1379 pnode->FastGetSolutionStepValue(IS_BOUNDARY,1)=0.0;
1380 pnode->FastGetSolutionStepValue(IS_STRUCTURE,1)=0.0;
1381 pnode->Set(TO_ERASE,
false);
1382 pnode->FastGetSolutionStepValue(IS_FREE_SURFACE,1)=0.0;
1383 pnode->FastGetSolutionStepValue(IS_FLUID,1)=1.0;
1387 pnode->FastGetSolutionStepValue(IS_INTERFACE) = aux_interface;
1388 pnode->FastGetSolutionStepValue(IS_INTERFACE,1) = aux_interface;
1390 double same_colour = 0.0;
1391 for(
int ii= 0; ii<= 2; ++ii)
1392 if(geom[ii].FastGetSolutionStepValue(IS_WATER) == 0.0)
1394 if(same_colour == 3.0)
1396 pnode->FastGetSolutionStepValue(IS_WATER) = 0.0;
1397 pnode->FastGetSolutionStepValue(IS_WATER,1) = 0.0;
1402 pnode->FastGetSolutionStepValue(IS_WATER) = 1.0;
1403 pnode->FastGetSolutionStepValue(IS_WATER) = 1.0;
1425 pnode->FastGetSolutionStepValue(IS_WATER) = 0.0;
1426 pnode->FastGetSolutionStepValue(IS_WATER,1) = 0.0;
1436 void SegmentDetecting(
ModelPart& ThisModelPart, std::vector <int>& seg_list,
int& seg_num,
int& num_interface,
double h_factor)
1442 std::vector <int> nodes_of_bad_segments;
1444 std::vector <int> raw_seg_list;
1451 ind->FastGetSolutionStepValue(IS_INTERFACE) = 0.0;
1455 for(ModelPart::ElementsContainerType::iterator elem = ThisModelPart.ElementsBegin();
1456 elem!=ThisModelPart.ElementsEnd(); elem++)
1459 if(elem->GetValue(IS_WATER_ELEMENT) == 0)
1463 Geometry< Node >& geom = elem->GetGeometry();
1465 for(
int ii=0; ii<(Tdim+1); ++ii)
1468 if(neighbor_els[ii].
GetValue(IS_WATER_ELEMENT) == 1 && neighbor_els[ii].Id() != elem->Id())
1473 if(geom[1].FastGetSolutionStepValue(IS_STRUCTURE) == 0.0 && geom[2].FastGetSolutionStepValue(IS_STRUCTURE) == 0.0)
1477 double length = 0.0;
1478 length = pow(geom[1].
X()-geom[2].
X(),2) + pow(geom[1].
Y()-geom[2].
Y(),2) +pow(geom[1].
Z()-geom[2].
Z(),2);
1479 length = sqrt(length);
1481 if(length < h_factor*geom[2].FastGetSolutionStepValue(NODAL_H))
1484 nodes_of_bad_segments.push_back(geom[2].Id());
1485 nodes_of_bad_segments.push_back(geom[1].Id());
1491 geom[2].FastGetSolutionStepValue(IS_INTERFACE) = 0.0;
1492 geom[2].Set(TO_ERASE,
true);
1498 raw_seg_list.push_back(geom[2].Id());
1499 raw_seg_list.push_back(geom[1].Id());
1500 geom[2].FastGetSolutionStepValue(IS_INTERFACE) = 1.0;
1501 geom[1].FastGetSolutionStepValue(IS_INTERFACE) = 1.0;
1507 if(geom[0].FastGetSolutionStepValue(IS_STRUCTURE) == 0.0 && geom[2].FastGetSolutionStepValue(IS_STRUCTURE) == 0.0)
1510 double length = 0.0;
1511 length = pow(geom[0].
X()-geom[2].
X(),2) + pow(geom[0].
Y()-geom[2].
Y(),2) +pow(geom[0].
Z()-geom[2].
Z(),2);
1512 length = sqrt(length);
1514 if(length < h_factor*geom[0].FastGetSolutionStepValue(NODAL_H))
1517 nodes_of_bad_segments.push_back(geom[0].Id());
1518 nodes_of_bad_segments.push_back(geom[2].Id());
1523 geom[0].FastGetSolutionStepValue(IS_INTERFACE) = 0.0;
1524 geom[0].Set(TO_ERASE,
true);
1530 raw_seg_list.push_back(geom[0].Id());
1531 raw_seg_list.push_back(geom[2].Id());
1532 geom[0].FastGetSolutionStepValue(IS_INTERFACE) = 1.0;
1533 geom[2].FastGetSolutionStepValue(IS_INTERFACE) = 1.0;
1539 if(geom[0].FastGetSolutionStepValue(IS_STRUCTURE) == 0.0 && geom[1].FastGetSolutionStepValue(IS_STRUCTURE) == 0.0)
1542 double length = 0.0;
1543 length = pow(geom[0].
X()-geom[1].
X(),2) + pow(geom[0].
Y()-geom[1].
Y(),2) +pow(geom[0].
Z()-geom[1].
Z(),2);
1544 length = sqrt(length);
1546 if(length < h_factor*geom[1].FastGetSolutionStepValue(NODAL_H))
1549 nodes_of_bad_segments.push_back(geom[1].Id());
1550 nodes_of_bad_segments.push_back(geom[0].Id());
1555 geom[1].FastGetSolutionStepValue(IS_INTERFACE) = 0.0;
1556 geom[1].Set(TO_ERASE,
true);
1562 raw_seg_list.push_back(geom[1].Id());
1563 raw_seg_list.push_back(geom[0].Id());
1564 geom[1].FastGetSolutionStepValue(IS_INTERFACE) = 1.0;
1565 geom[0].FastGetSolutionStepValue(IS_INTERFACE) = 1.0;
1578 if(ind->FastGetSolutionStepValue(IS_INTERFACE) == 1.0)
1593 for(
unsigned int ii=0; ii<nodes_of_bad_segments.size(); ii+=2)
1595 KRATOS_WATCH(
"!!!!!!!!!!!!!!!!!!! BAD NODES !!!!!!!!!!!!!!!!!!!!!!");
1597 int bad_node = nodes_of_bad_segments[ii];
1604 for(
int & jj : raw_seg_list)
1609 jj = nodes_of_bad_segments[ii + 1];
1610 KRATOS_WATCH(
"OOOOOOOOOOOOOOOOOO MERGE IS DONE OOOOOOOOOOOOOOOOOOOOOO");
1614 for(
unsigned int kk=0; kk<nodes_of_bad_segments.size(); kk+=2)
1616 if(nodes_of_bad_segments[kk + 1] == bad_node )
1618 nodes_of_bad_segments[kk + 1] = nodes_of_bad_segments[ii + 1];
1619 KRATOS_WATCH(
"HHHHHHHHHHHHHHHHHH BAD_SEGMENT LIST UPDATED HHHHHHHHHHHHHHHHHHHHHHHH");
1629 for(
unsigned int seg=0; seg < raw_seg_list.size(); seg+=2)
1631 if(raw_seg_list[seg] != raw_seg_list[seg + 1])
1633 seg_list.push_back(raw_seg_list[seg]);
1634 seg_list.push_back(raw_seg_list[seg + 1]);
1637 ModelPart::NodesContainerType::iterator inode = ThisModelPart.Nodes().find(raw_seg_list[seg]);
1638 inode->FastGetSolutionStepValue(IS_INTERFACE) = 1.0;
1639 inode->Set(TO_ERASE,
false);
1641 ModelPart::NodesContainerType::iterator iinode = ThisModelPart.Nodes().find(raw_seg_list[seg+1]);
1642 iinode->FastGetSolutionStepValue(IS_INTERFACE) = 1.0;
1643 iinode->Set(TO_ERASE,
false);
1657 void initialize_triangulateio( triangulateio& tr )
1659 tr.pointlist = (
REAL*)
nullptr;
1660 tr.pointattributelist = (
REAL*)
nullptr;
1661 tr.pointmarkerlist = (
int*)
nullptr;
1662 tr.numberofpoints = 0;
1663 tr.numberofpointattributes = 0;
1664 tr.trianglelist = (
int*)
nullptr;
1665 tr.triangleattributelist = (
REAL*)
nullptr;
1666 tr.trianglearealist = (
REAL*)
nullptr;
1667 tr.neighborlist = (
int*)
nullptr;
1668 tr.numberoftriangles = 0;
1669 tr.numberofcorners = 3;
1670 tr.numberoftriangleattributes = 0;
1671 tr.segmentlist = (
int*)
nullptr;
1672 tr.segmentmarkerlist = (
int*)
nullptr;
1673 tr.numberofsegments = 0;
1674 tr.holelist = (
REAL*)
nullptr;
1675 tr.numberofholes = 0;
1676 tr.regionlist = (
REAL*)
nullptr;
1677 tr.numberofregions = 0;
1678 tr.edgelist = (
int*)
nullptr;
1679 tr.edgemarkerlist = (
int*)
nullptr;
1680 tr.normlist = (
REAL*)
nullptr;
1681 tr.numberofedges = 0;
1684 void clean_triangulateio( triangulateio& tr )
1686 if(tr.pointlist !=
nullptr) free(tr.pointlist );
1687 if(tr.pointattributelist !=
nullptr) free(tr.pointattributelist );
1688 if(tr.pointmarkerlist !=
nullptr) free(tr.pointmarkerlist );
1689 if(tr.trianglelist !=
nullptr) free(tr.trianglelist );
1690 if(tr.triangleattributelist !=
nullptr) free(tr.triangleattributelist );
1691 if(tr.trianglearealist !=
nullptr) free(tr.trianglearealist );
1692 if(tr.neighborlist !=
nullptr) free(tr.neighborlist );
1693 if(tr.segmentlist !=
nullptr) free(tr.segmentlist );
1694 if(tr.segmentmarkerlist !=
nullptr) free(tr.segmentmarkerlist );
1695 if(tr.holelist !=
nullptr) free(tr.holelist );
1696 if(tr.regionlist !=
nullptr) free(tr.regionlist );
1697 if(tr.edgelist !=
nullptr) free(tr.edgelist );
1698 if(tr.edgemarkerlist !=
nullptr) free(tr.edgemarkerlist );
1699 if(tr.normlist !=
nullptr) free(tr.normlist );
1748 rOStream << std::endl;
PeriodicInterfaceProcess & operator=(const PeriodicInterfaceProcess &)=delete
Definition: bins_static.h:35
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
This class is a wrapper for a pointer to a data that is located in a different rank.
Definition: global_pointer.h:44
Definition: amatrix_interface.h:497
Definition: amatrix_interface.h:530
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
MeshType::NodeIterator NodeIterator
Definition: model_part.h:134
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
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
double Y() const
Definition: point.h:187
double Z() const
Definition: point.h:193
double X() const
Definition: point.h:181
PointerVector is a container like stl vector but using a vector to store pointers to its data.
Definition: pointer_vector.h:72
static double ElapsedSeconds(const std::chrono::steady_clock::time_point StartTime)
This method returns the resulting time.
Definition: timer.h:179
A generic tree data structure for spatial partitioning.
Definition: tree.h:190
Short class definition.
Definition: trigen_pfem_refine_segment.h:64
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: trigen_pfem_refine_segment.h:100
KRATOS_CLASS_POINTER_DEFINITION(TriGenPFEMRefineSegment)
Pointer definition of TriGenModeler.
virtual ~TriGenPFEMRefineSegment()=default
Destructor.
virtual void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: trigen_pfem_refine_segment.h:1117
virtual std::string Info() const
Turn back information as a string.
Definition: trigen_pfem_refine_segment.h:1111
TriGenPFEMRefineSegment()
Default constructor.
Definition: trigen_pfem_refine_segment.h:77
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: trigen_pfem_refine_segment.h:1120
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
#define REAL
Definition: delaunator_utilities.cpp:16
Kratos::ModelPart ModelPart
Definition: kratos_wrapper.h:31
z
Definition: GenerateWind.py:163
Parameters GetValue(Parameters &rParameters, const std::string &rEntry)
Definition: add_kratos_parameters_to_python.cpp:53
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
bool CalculatePosition(Geometry< Node > &geom, const double xc, const double yc, const double zc, array_1d< double, 3 > &N)
Definition: transfer_utility.h:343
double CalculateVol(const double x0, const double y0, const double x1, const double y1, const double x2, const double y2)
Definition: transfer_utility.h:424
AMatrix::MatrixProductExpression< TExpression1Type, TExpression2Type > prod(AMatrix::MatrixExpression< TExpression1Type, TCategory1 > const &First, AMatrix::MatrixExpression< TExpression2Type, TCategory2 > const &Second)
Definition: amatrix_interface.h:568
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
DistanceVector::iterator DistanceIterator
Definition: internal_variables_interpolation_process.h:56
std::vector< PointTypePointer > PointVector
Definition: internal_variables_interpolation_process.h:53
T & noalias(T &TheMatrix)
Definition: amatrix_interface.h:484
void triangulate(char *, struct triangulateio *, struct triangulateio *, struct triangulateio *)
REACTION_CHECK_STIFFNESS_FACTOR int
Definition: contact_structural_mechanics_application_variables.h:75
PointVector::iterator PointIterator
Definition: internal_variables_interpolation_process.h:54
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
Point PointType
Geometric definitions.
Definition: mortar_classes.h:36
int step
Definition: face_heat.py:88
y
Other simbols definition.
Definition: generate_axisymmetric_navier_stokes_element.py:54
res
Definition: generate_convection_diffusion_explicit_element.py:211
h
Definition: generate_droplet_dynamics.py:91
x2
Definition: generate_frictional_mortar_condition.py:122
x1
Definition: generate_frictional_mortar_condition.py:121
R
Definition: isotropic_damage_automatic_differentiation.py:172
float radius
Definition: mesh_to_mdpa_converter.py:18
def Interpolate(variable, entity, sf_values, historical_value)
Definition: point_output_process.py:231
int k
Definition: quadrature.py:595
int j
Definition: quadrature.py:648
el
Definition: read_stl.py:25
float temp
Definition: rotating_cone.py:85
float xc
Definition: rotating_cone.py:77
float yc
Definition: rotating_cone.py:78
int counter
Definition: script_THERMAL_CORRECT.py:218
add_nodes
Definition: script.py:96
N
Definition: sensitivityMatrix.py:29
x
Definition: sensitivityMatrix.py:49
integer i
Definition: TensorModule.f:17
e
Definition: run_cpp_mpi_tests.py:31