9 #if !defined(KRATOS_TRILINOS_LOCAL_CUTTING_ISO_APP)
10 #define KRATOS_TRILINOS_LOCAL_CUTTING_ISO_APP
16 #include "utilities/geometry_utilities.h"
19 #include "Epetra_Vector.h"
20 #include "Epetra_Map.h"
21 #include "Epetra_SerialDenseMatrix.h"
22 #include "Epetra_MpiComm.h"
23 #include "Epetra_FECrsGraph.h"
24 #include "Epetra_FECrsMatrix.h"
26 #include "Epetra_FEVector.h"
28 #include "Epetra_Import.h"
29 #include "Epetra_MpiComm.h"
86 ModelPart& this_model_part = mr_model_part;
87 ModelPart& new_model_part = mr_new_model_part;
90 KRATOS_WATCH(
"Adding Skin Conditions to the new model part, added in layer:")
97 NodesArrayType::iterator it_begin_node_old = rNodes_old.ptr_begin();
103 int *local_ids =
new int[nlocal_nodes];
107 local_ids[
k++] = it->Id() - 1;
114 int *ids =
new int[
nnodes];
116 for (ModelPart::NodesContainerType::iterator it = this_model_part.
NodesBegin(); it != this_model_part.
NodesEnd(); it++)
118 ids[
k++] = it->Id() - 1;
128 aux_non_overlapping_graph->PutScalar(-1.0);
134 bool* used_nodes =
new bool [
nnodes];
135 for (
int index = 0; index!=
nnodes; ++index) used_nodes[index]=
false;
139 int number_of_local_conditions=0;
146 ++number_of_local_conditions;
147 for (
unsigned int i = 0;
i < geom.
size();
i++)
149 aux_ids = geom[
i].
Id() - 1;
150 int node_position = this_model_part.
Nodes().find(geom[
i].Id()) - it_begin_node_old;
151 used_nodes[node_position]=
true;
152 int ierr = aux_non_overlapping_graph->ReplaceGlobalValues( 1 , &aux_ids, &this_partition_index,0);
160 ierr = aux_non_overlapping_graph->GlobalAssemble(Insert,
true);
165 double* local_non_ov =
new double [nlocal_nodes];
166 ierr = aux_non_overlapping_graph->ExtractCopy(local_non_ov,nlocal_nodes);
170 int n_owned_nonzeros = 0;
172 for (
int index=0; index!=nlocal_nodes; ++index)
174 if (local_non_ov[index]>(-0.5))
183 mrComm.ScanSum(&n_owned_nonzeros, &nodes_before, 1);
184 nodes_before -= n_owned_nonzeros;
186 int conditions_before = -1;
187 mrComm.ScanSum(&number_of_local_conditions, &conditions_before, 1);
188 conditions_before -=number_of_local_conditions;
192 int number_of_local_nodes = new_model_part.
Nodes().size();
193 int number_of_old_nodes = -1;
194 mrComm.SumAll(&number_of_local_nodes, &number_of_old_nodes, 1);
195 if (number_of_old_nodes < 0) number_of_old_nodes = 0;
197 int number_of_local_old_conditions = new_model_part.
Conditions().size();
198 int number_of_old_conditions = -1;
199 mrComm.SumAll(&number_of_local_old_conditions, &number_of_old_conditions, 1);
201 if (number_of_old_conditions < 0) number_of_old_conditions = 0;
226 int node_id=number_of_old_nodes+nodes_before;
227 for (
int index=0; index!=nlocal_nodes; ++index)
229 if (local_non_ov[index]>(-0.5))
233 ierr = IDs_non_overlapping_graph->ReplaceMyValue ( index , 0 , node_id_double );
234 KRATOS_ERROR_IF(ierr < 0) <<
"epetra failure in line" << __LINE__ << std::endl;
239 ierr = IDs_non_overlapping_graph->GlobalAssemble(Insert,
true);
247 Epetra_Import importer(*pmy_ov_map, *pmy_map);
250 ierr = IDs_overlap->Import(*IDs_non_overlapping_graph, importer, Insert);
251 KRATOS_ERROR_IF(ierr < 0) <<
"epetra failure in line" << __LINE__ << std::endl;
253 double* local_IDs_ov =
new double [
nnodes];
254 ierr = IDs_overlap->ExtractCopy(local_IDs_ov,
nnodes);
255 KRATOS_ERROR_IF(ierr < 0) <<
"epetra failure in line" << __LINE__ << std::endl;
260 ierr = Partition_overlap->Import(*aux_non_overlapping_graph, importer, Insert);
261 KRATOS_ERROR_IF(ierr < 0) <<
"epetra failure in line" << __LINE__ << std::endl;
263 double* local_Partition_ov =
new double [
nnodes];
264 ierr = Partition_overlap->ExtractCopy(local_Partition_ov,
nnodes);
265 KRATOS_ERROR_IF(ierr < 0) <<
"epetra failure in line" << __LINE__ << std::endl;
269 for (
int index=0; index!=
nnodes; ++index)
272 if (used_nodes[index]==
true)
275 int node_number=
int(local_IDs_ov[index]);
277 ModelPart::NodesContainerType::iterator it_node = this_model_part.
Nodes().begin()+index;
280 Node::Pointer pnode = Node ::Pointer (
new Node(node_number, it_node->X(), it_node->Y(), it_node->Z()));
283 pnode->SetBufferSize(this_model_part.
NodesBegin()->GetBufferSize());
284 pnode->GetValue(FATHER_NODES).resize(0);
285 pnode->GetValue(FATHER_NODES).push_back( Node::WeakPointer( *it_node.base() ) );
286 pnode->GetValue(FATHER_NODES).push_back( Node::WeakPointer( *it_node.base() ) );
287 pnode->
GetValue(WEIGHT_FATHER_NODES) = 1.0;
288 pnode->X0() = it_node->X0();
289 pnode->Y0() = it_node->Y0();
290 pnode->Z0() = it_node->Z0();
291 pnode->FastGetSolutionStepValue(PARTITION_INDEX)=local_Partition_ov[index];
292 new_model_part.
Nodes().push_back(pnode);
296 new_model_part.
Nodes().Sort();
298 new_model_part.
Nodes().Unique();
303 int triangle_ID = number_of_old_conditions + conditions_before;
304 vector<int> triangle_nodes(3);
308 for(ModelPart::ConditionsContainerType::iterator i_condition = rConditions.begin() ; i_condition != rConditions.end() ; i_condition++)
313 for(
unsigned int i = 0;
i < i_condition->GetGeometry().size() ;
i++)
315 int position = (geom[
i].
Id()) - 1;
316 int local_position = (*pmy_ov_map).LID(position);
317 triangle_nodes[
i]=local_IDs_ov[local_position] ;
320 new_model_part.
Nodes()(triangle_nodes[0]),
321 new_model_part.
Nodes()(triangle_nodes[1]),
322 new_model_part.
Nodes()(triangle_nodes[2])
325 Condition::Pointer p_condition = rReferenceCondition.
Create(triangle_ID, geometry, properties);
326 new_model_part.
Conditions().push_back(p_condition);
332 if (
mrComm.MyPID() == 0) std::cout <<
"copyng conditions and recalculation plan have been completed" << std::endl;
340 template <
class TDataType>
347 std::cout <<
"Generating Isosurface with the following data:"<<std::endl;
352 ModelPart& this_model_part = mr_model_part;
355 vector<int> Elems_In_Plane(this_model_part.
Elements().size());
356 int number_of_triangles = 0;
360 vector<int> List_New_Nodes;
361 vector<int> partition_new_nodes;
362 vector<array_1d<int, 2 > > father_node_ids;
363 vector< array_1d<double, 3 > > Coordinate_New_Node;
370 MPI_Barrier(MPI_COMM_WORLD);
371 if (
mrComm.MyPID() == 0) std::cout <<
"index matrix constructed" << std::endl;
373 FirstLoop(mr_model_part, p_edge_ids, p_partition_ids, variable, isovalue , number_of_triangles, Elems_In_Plane, tolerance, used_nodes_matrix);
374 MPI_Barrier(MPI_COMM_WORLD);
375 if (
mrComm.MyPID() == 0) std::cout <<
"Search_Edge_To_Be_Refined completed" << std::endl;
377 Create_List_Of_New_Nodes(mr_model_part, mr_new_model_part, p_edge_ids, p_partition_ids, List_New_Nodes, partition_new_nodes, father_node_ids, used_nodes_matrix);
378 MPI_Barrier(MPI_COMM_WORLD);
379 if (
mrComm.MyPID() == 0) std::cout <<
"Create_List_Of_New_Nodes completed" << std::endl;
382 MPI_Barrier(MPI_COMM_WORLD);
383 if (
mrComm.MyPID() == 0) std::cout <<
"Calculate_Coordinate_And_Insert_New_Nodes completed" << std::endl;
385 GenerateElements(mr_model_part, mr_new_model_part, Elems_In_Plane, p_edge_ids, plane_number, number_of_triangles, variable);
386 MPI_Barrier(MPI_COMM_WORLD);
387 if (
mrComm.MyPID() == 0) std::cout <<
"finished generating elements" << std::endl;
391 if (
mrComm.MyPID() == 0) std::cout <<
"recalculation of communication plan completed" << std::endl;
430 int *local_ids =
new int[nlocal_nodes];
434 local_ids[
k++] = it->Id() - 1;
444 int *ids =
new int[
nnodes];
446 for (ModelPart::NodesContainerType::iterator it = this_model_part.
NodesBegin(); it != this_model_part.
NodesEnd(); it++)
448 ids[
k++] = it->Id() - 1;
456 int guess_row_size = 20;
461 for (ModelPart::ElementsContainerType::iterator it = this_model_part.
ElementsBegin(); it != this_model_part.
ElementsEnd(); it++)
464 for (
unsigned int i = 0;
i < geom.
size();
i++)
465 aux_ids[
i] = geom[
i].Id() - 1;
468 KRATOS_ERROR_IF(ierr < 0) <<
"epetra failure in line" << __LINE__ << std::endl;
473 for (
unsigned int i = 0;
i < geom.
size();
i++)
474 aux_ids[
i] = geom[
i].Id() - 1;
477 KRATOS_ERROR_IF(ierr < 0) <<
"epetra failure in line" << __LINE__ << std::endl;
492 pB.swap(used_nodes_matrix);
502 double isovalue,
int& number_of_triangles, vector<int>& Elems_In_Plane,
double tolerance,
511 p_nonoverlapping_partitions->PutScalar(-1.0);
516 ElementsArrayType::iterator it_begin = rElements.ptr_begin();
517 ElementsArrayType::iterator it_end = rElements.ptr_end();
521 double diff_node_value;
522 double diff_neigh_value;;
528 unsigned int exact_nodes = 0;
529 unsigned int outside_nodes = 0;
530 number_of_triangles = 0;
531 int current_element = 0;
532 int number_of_cuts = 0;
534 for (ElementsArrayType::iterator it = it_begin; it != it_end; ++it)
541 for (
unsigned int i = 0;
i < it->GetGeometry().size();
i++)
544 node_value= geom[
i].FastGetSolutionStepValue(variable);
545 diff_node_value = isovalue - node_value;
546 for (
unsigned int j = 0;
j < it->GetGeometry().size();
j++)
551 neigh_value= geom[
j].FastGetSolutionStepValue(variable);
552 diff_neigh_value = isovalue - neigh_value;
557 if (fabs(diff_node_value) < (tolerance) )
559 int index_i = geom[
i].
Id() - 1;
561 double true_value = -1.0;
562 int ierr = p_edge_ids->SumIntoGlobalValues(1, &index_i, 1, &index_i, &value);
564 ierr = p_nonoverlapping_partitions->ReplaceGlobalValues(1, &index_i, 1, &index_i, &this_partition_index);
566 ierr = used_nodes_matrix->ReplaceGlobalValues(1, &index_i, 1, &index_i, &true_value);
571 list_matching_nodes[
i] = geom[
i].
Id();
572 if ((diff_node_value * diff_neigh_value) > 0.0)
576 if ((diff_node_value * diff_neigh_value) < 0.0 && (fabs(diff_neigh_value)>(tolerance)))
578 int index_i = geom[
i].
Id() - 1;
579 int index_j = geom[
j].
Id() - 1;
581 double true_value = -1.0;
583 if (index_j > index_i)
585 int ierr = p_edge_ids->SumIntoGlobalValues(1, &index_i, 1, &index_j, &value);
587 ierr = p_nonoverlapping_partitions->ReplaceGlobalValues(1, &index_i, 1, &index_j, &this_partition_index);
589 ierr = used_nodes_matrix->ReplaceGlobalValues(1, &index_i, 1, &index_j, &true_value);
599 Elems_In_Plane[current_element - 1] = 0;
600 if (exact_nodes < 3 || outside_nodes<2 )
602 if (number_of_cuts == 6)
604 number_of_triangles += 1;
605 Elems_In_Plane[current_element - 1] = 1;
607 else if (number_of_cuts == 8)
609 number_of_triangles += 2;
610 Elems_In_Plane[ current_element - 1] = 2;
618 ierr = p_edge_ids->GlobalAssemble(
true, Add);
619 KRATOS_ERROR_IF(ierr < 0) <<
"epetra failure in line" << __LINE__ << std::endl;
621 ierr = p_nonoverlapping_partitions->GlobalAssemble(
true, Insert);
622 KRATOS_ERROR_IF(ierr < 0) <<
"epetra failure in line" << __LINE__ << std::endl;
625 int MaxNumEntries = p_edge_ids->MaxNumEntries() + 5;
631 ierr = pAoverlap->Import(*p_edge_ids, importer, Insert);
632 KRATOS_ERROR_IF(ierr < 0) <<
"epetra failure in line" << __LINE__ << std::endl;
633 ierr = pAoverlap->FillComplete();
634 KRATOS_ERROR_IF(ierr < 0) <<
"epetra failure in line" << __LINE__ << std::endl;
636 ierr = paux->Import(*p_nonoverlapping_partitions, importer, Insert);
637 KRATOS_ERROR_IF(ierr < 0) <<
"epetra failure in line" << __LINE__ << std::endl;
638 ierr = paux->FillComplete();
639 KRATOS_ERROR_IF(ierr < 0) <<
"epetra failure in line" << __LINE__ << std::endl;
642 pAoverlap.swap(p_edge_ids);
643 paux.swap(p_partition_ids);
660 vector<int> &List_New_Nodes,
661 vector<int> &partition_new_nodes,
667 int NumMyRows = p_edge_ids->NumMyRows();
670 int MaxNumEntries = p_edge_ids->MaxNumEntries();
671 double * id_values =
new double[MaxNumEntries];
672 double * partition_values =
new double[MaxNumEntries];
673 int * Indices =
new int[MaxNumEntries];
678 int * Indices_aux =
new int[MaxNumEntries];
679 double * id_values_aux =
new double[MaxNumEntries];
681 int n_owned_nonzeros = 0;
682 int n_new_nonzeros = 0;
683 double this_partition_index =
mrComm.MyPID();
685 for (Row = 0; Row < NumMyRows; ++Row)
687 GlobalRow = p_edge_ids->GRID(Row);
688 int ierr = p_edge_ids->ExtractGlobalRowCopy(GlobalRow, MaxNumEntries, NumEntries, id_values, Indices);
691 ierr = p_partition_ids->ExtractGlobalRowCopy(GlobalRow, MaxNumEntries, NumEntries, partition_values, Indices);
694 for (Col = 0; Col != NumEntries; Col++)
696 if (Indices[Col] >= Row)
699 n_new_nonzeros = n_new_nonzeros + 1;
700 if (partition_values[Col] == this_partition_index)
701 n_owned_nonzeros = n_owned_nonzeros + 1;
707 int nodes_before = -1;
708 mrComm.ScanSum(&n_owned_nonzeros, &nodes_before, 1);
709 nodes_before = nodes_before - n_owned_nonzeros;
710 if (nodes_before < 0)
711 KRATOS_THROW_ERROR(std::logic_error,
"problem with scan sum ... giving a negative number of nodes before",
"")
714 int number_of_local_nodes = new_model_part.
Nodes().size();
715 int total_number_of_nodes = -1;
716 mrComm.SumAll(&number_of_local_nodes, &total_number_of_nodes, 1);
718 if (total_number_of_nodes < 0) total_number_of_nodes = 0;
723 int start_id = total_number_of_nodes + nodes_before + 1;
724 int end_id = start_id + n_owned_nonzeros;
728 plocal_ids->PutScalar(-1);
732 for (Row = 0; Row < NumMyRows; ++Row)
734 GlobalRow = p_edge_ids->GRID(Row);
736 int ierr = p_edge_ids->ExtractGlobalRowCopy(GlobalRow, MaxNumEntries, NumEntries, id_values, Indices);
737 KRATOS_ERROR_IF(ierr < 0) <<
"epetra failure in line" << __LINE__ << std::endl;
739 ierr = p_partition_ids->ExtractGlobalRowCopy(GlobalRow, MaxNumEntries, NumEntries, partition_values, Indices);
740 KRATOS_ERROR_IF(ierr < 0) <<
"epetra failure in line" << __LINE__ << std::endl;
742 for (Col = 0; Col < NumEntries; ++Col)
744 if (Indices[Col] >= Row)
745 if (id_values[Col] < -1.5 &&
746 partition_values[Col] == this_partition_index &&
750 plocal_ids->ReplaceGlobalValues(1, &GlobalRow, 1, &(Indices[Col]), &did);
755 plocal_ids->GlobalAssemble(
true, Insert);
757 KRATOS_ERROR_IF(
id != end_id) <<
"the own node count is not verified...some error occurred" << std::endl;
762 int ierr = p_edge_ids->Import(*plocal_ids, importer, Insert);
763 KRATOS_ERROR_IF(ierr < 0) <<
"epetra failure in line" << __LINE__ << std::endl;
764 p_edge_ids->FillComplete();
765 KRATOS_ERROR_IF(ierr < 0) <<
"epetra failure in line" << __LINE__ << std::endl;
769 List_New_Nodes.resize(n_new_nonzeros);
770 partition_new_nodes.resize(n_new_nonzeros);
771 father_node_ids.resize(n_new_nonzeros);
774 for (Row = 0; Row < NumMyRows; ++Row)
776 GlobalRow = p_edge_ids->GRID(Row);
777 int num_id_entries = -1;
778 int ierr = p_edge_ids->ExtractGlobalRowCopy(GlobalRow, MaxNumEntries, num_id_entries, id_values, Indices);
781 ierr = p_partition_ids->ExtractGlobalRowCopy(GlobalRow, MaxNumEntries, NumEntries, partition_values, Indices);
787 if (NumEntries != num_id_entries)
KRATOS_THROW_ERROR(std::logic_error,
"we should have the same number of new_ids and of partition_values",
"");
788 for (Col = 0; Col < NumEntries; ++Col)
790 if (Indices[Col] >= Row)
795 List_New_Nodes[
k] = id_values[Col];
796 partition_new_nodes[
k] = partition_values[Col];
798 father_node_ids[
k][0] = GlobalRow + 1;
799 father_node_ids[
k][1] = Indices[Col] + 1;
800 int IsNeeded =
GetUpperTriangularMatrixValue(used_nodes_matrix, GlobalRow , (Indices[Col]), MaxNumEntries, NumEntries_aux, Indices_aux, id_values_aux);
803 father_node_ids[
k][0] = -1;
804 father_node_ids[
k][1] = -1;
808 if (id_values[Col] < -1.5)
813 if (
k !=
int(n_new_nonzeros))
KRATOS_THROW_ERROR(std::logic_error,
"number of new nodes check failed",
"")
818 delete [] partition_values;
831 const vector<int> &List_New_Nodes,
832 const vector<int> &partition_new_nodes,
844 double diff_node_value;
845 double diff_neigh_value;
846 double diff_node_neigh;
851 vector< array_1d<double, 3 > > Coordinate_New_Node;
852 Coordinate_New_Node.
resize(father_node_ids.size());
860 MPI_Barrier(MPI_COMM_WORLD);
861 if ((father_node_ids.size())!=0)
863 for (
unsigned int i = 0;
i < father_node_ids.size();
i++)
867 const int& node_i = father_node_ids[
i][0];
868 const int& node_j = father_node_ids[
i][1];
871 ModelPart::NodesContainerType::iterator it_node1 = this_model_part.
Nodes().find(node_i);
872 if (it_node1 == this_model_part.
NodesEnd())
874 std::cout <<
"- father node 1 - looking for Id " << node_i <<
" " << node_j << std::endl;
877 noalias(Coord_Node_1) = it_node1->Coordinates();
880 ModelPart::NodesContainerType::iterator it_node2 = this_model_part.
Nodes().find(node_j);
881 if (it_node2 == this_model_part.
NodesEnd())
883 std::cout <<
"- father node 2 - looking for Id " << node_i <<
" " << node_j << std::endl;
886 noalias(Coord_Node_2) = it_node2->Coordinates();
892 node_value = it_node1->FastGetSolutionStepValue(variable);
893 diff_node_value = isovalue - node_value;
895 neigh_value = it_node2->FastGetSolutionStepValue(variable);
896 diff_neigh_value = isovalue - neigh_value;
898 diff_node_neigh= node_value - neigh_value;
900 vector_distance = Coord_Node_2 - Coord_Node_1;
903 if (fabs(diff_node_value) < tolerance) weight = 0.0;
904 else if (fabs(diff_neigh_value) < tolerance) weight = 1.0;
905 else weight = fabs(diff_node_value / diff_node_neigh);
907 if (weight > 1.05) weight=1.0;
909 for (
unsigned int index = 0; index != 3; ++index)
910 if (father_node_ids[
i][0] != father_node_ids[
i][1])
911 Coordinate_New_Node[
i][index] = Coord_Node_1[index] + vector_distance[index] * weight;
913 Coordinate_New_Node[
i][index] = Coord_Node_1[index];
916 Node::Pointer pnode = Node ::Pointer (
new Node(List_New_Nodes[
i], Coordinate_New_Node[
i][0], Coordinate_New_Node[
i][1], Coordinate_New_Node[
i][2]));
918 pnode->SetBufferSize(this_model_part.
NodesBegin()->GetBufferSize());
919 pnode->GetValue(FATHER_NODES).resize(0);
920 pnode->GetValue(FATHER_NODES).push_back(Node ::WeakPointer(*it_node1.base()));
921 pnode->GetValue(FATHER_NODES).push_back(Node ::WeakPointer(*it_node2.base()));
922 pnode->
GetValue(WEIGHT_FATHER_NODES) = weight;
924 pnode->X0() = weight * (it_node2->X0()) + (1.0 - weight) * it_node1->X0();
925 pnode->Y0() = weight * (it_node2->Y0()) + (1.0 - weight) * it_node1->Y0();
926 pnode->Z0() = weight * (it_node2->Z0()) + (1.0 - weight) * it_node1->Z0();
927 pnode->FastGetSolutionStepValue(PARTITION_INDEX) =
double(partition_new_nodes[
i]) ;
928 new_model_part.
Nodes().push_back(pnode);
932 new_model_part.
Nodes().Sort();
933 unsigned int current_size = new_model_part.
Nodes().size();
934 new_model_part.
Nodes().Unique();
936 if(current_size != new_model_part.
Nodes().size())
954 int plane_number,
int& number_of_triangles,
969 unsigned int temp_int;
973 int total_existing_elements = -1;
974 int local_existing_elements = new_model_part.
Conditions().size();
975 mrComm.SumAll(&local_existing_elements, &total_existing_elements, 1);
977 if (total_existing_elements < 0) total_existing_elements = 0;
979 Element const rReferenceElement;
982 int MaxNumEntries = p_edge_ids->MaxNumEntries();
983 double * id_values =
new double[MaxNumEntries];
984 int * Indices =
new int[MaxNumEntries];
990 ElementsArrayType::iterator it_begin_old = rElements_old.ptr_begin();
991 ElementsArrayType::iterator it_end_old = rElements_old.ptr_end();
996 int triangle_id_int = 0;
997 int current_element = 0;
998 unsigned int triangle_nodes = 0;
999 bool new_node =
false;
1002 for (
unsigned int k = 0;
k != 4; ++
k)
1004 TriangleNodesArray[
k] = 0;
1007 int elements_before = -1;
1008 mrComm.ScanSum(&number_of_triangles, &elements_before, 1);
1009 if (elements_before < 0) elements_before = 0;
1010 else elements_before-=number_of_triangles;
1013 for (
int j = 0;
j < 3;
j++)
1016 for (ElementsArrayType::iterator it = it_begin_old; it != it_end_old; ++it)
1019 if (Elems_In_Plane[current_element - 1] != 0)
1021 for (
int j = 0;
j < 3;
j++)
1028 for (
int I = 0; I < 4; I++)
1030 double node_value = geom[I].FastGetSolutionStepValue(variable);
1031 for (
int j = 0;
j < 3;
j++)
1032 gradient(
j) += DN_DX(I,
j) * node_value;
1040 if (Elems_In_Plane[current_element - 1] == 1)
1044 for (
unsigned int i = 0;
i < it->GetGeometry().size();
i++)
1047 for (
unsigned int j = 0;
j < it->GetGeometry().size();
j++)
1050 int index_i = geom[
i].
Id() - 1;
1051 int index_j = geom[
j].
Id() - 1;
1054 for (
unsigned int l = 0;
l != 3; ++
l)
1056 if (TriangleNodesArray[
l] == NodeId
1061 if (new_node && index_i <= index_j)
1063 TriangleNodesArray[triangle_nodes] = NodeId;
1066 if (triangle_nodes == 3)
break;
1068 if (triangle_nodes == 3)
break;
1071 ModelPart::NodesContainerType::iterator it_node1 = new_model_part.
Nodes().find(TriangleNodesArray[0]);
1072 noalias(temp_vector1) = it_node1->Coordinates();
1074 it_node1 = new_model_part.
Nodes().find(TriangleNodesArray[1]);
1075 noalias(temp_vector2) = it_node1->Coordinates();
1077 it_node1 = new_model_part.
Nodes().find(TriangleNodesArray[2]);
1078 noalias(temp_vector3) = it_node1->Coordinates();
1080 temp_vector3 -= temp_vector1;
1081 temp_vector2 -= temp_vector1;
1086 if (
inner_prod(temp_vector4, gradient) < 0.0)
1088 temp_int = TriangleNodesArray[2];
1089 TriangleNodesArray[2] = TriangleNodesArray[1];
1090 TriangleNodesArray[1] = temp_int;
1095 new_model_part.
Nodes()(TriangleNodesArray[0]),
1096 new_model_part.
Nodes()(TriangleNodesArray[1]),
1097 new_model_part.
Nodes()(TriangleNodesArray[2])
1100 Condition::Pointer p_condition = rReferenceCondition.
Create(triangle_id_int + 1 + elements_before + total_existing_elements, geom, properties);
1101 new_model_part.
Conditions().push_back(p_condition);
1107 if (Elems_In_Plane[current_element - 1] == 2)
1112 for (
unsigned int i = 0;
i < it->GetGeometry().size();
i++)
1115 for (
unsigned int j = 0;
j < it->GetGeometry().size();
j++)
1118 int index_i = geom[
i].
Id() - 1;
1119 int index_j = geom[
j].
Id() - 1;
1122 for (
unsigned int l = 0;
l != 3; ++
l)
1124 if (TriangleNodesArray[
l] == NodeId
1130 if (new_node && index_i < index_j)
1132 TriangleNodesArray[triangle_nodes] = NodeId;
1135 if (triangle_nodes == 4)
break;
1137 if (triangle_nodes == 4)
break;
1139 if (triangle_nodes!=4)
1150 ModelPart::NodesContainerType::iterator it_node1 = new_model_part.
Nodes().find(TriangleNodesArray[0]);
1151 noalias(temp_vector1) = it_node1->Coordinates();
1154 bool error_bool=
true;
1156 for (
int iii = 1; iii != 4; ++iii)
1158 it_node1 = new_model_part.
Nodes().find(TriangleNodesArray[iii]);
1159 noalias(temp_vector2) = (it_node1->Coordinates());
1160 noalias(temp_vector3) = temp_vector2 - temp_vector1;
1181 it_node1 = new_model_part.
Nodes().find(TriangleNodesArray[jjj]);
1182 noalias(temp_vector2) = it_node1->Coordinates();
1184 it_node1 = new_model_part.
Nodes().find(TriangleNodesArray[kkk]);
1185 noalias(temp_vector3) = it_node1->Coordinates();
1187 noalias(temp_vector2) -= temp_vector1;
1188 noalias(temp_vector3) -= temp_vector1;
1191 dist2 =
inner_prod(temp_vector2, temp_vector4);
1192 dist3 =
inner_prod(temp_vector3, temp_vector4);
1197 nodes_for_2triang[0] = TriangleNodesArray[0];
1198 nodes_for_2triang[1] = TriangleNodesArray[jjj];
1199 nodes_for_2triang[2] = TriangleNodesArray[iii];
1200 nodes_for_2triang[3] = TriangleNodesArray[iii];
1201 nodes_for_2triang[4] = TriangleNodesArray[kkk];
1202 nodes_for_2triang[5] = TriangleNodesArray[0];
1212 nodes_for_2triang[0] = TriangleNodesArray[0];
1213 nodes_for_2triang[1] = TriangleNodesArray[1];
1214 nodes_for_2triang[2] = TriangleNodesArray[2];
1215 nodes_for_2triang[3] = TriangleNodesArray[3];
1216 nodes_for_2triang[4] = TriangleNodesArray[2];
1217 nodes_for_2triang[5] = TriangleNodesArray[0];
1221 for (
int index = 0; index != 2; ++index)
1227 it_node1 = new_model_part.
Nodes().find(nodes_for_2triang[index * 3 + 0]);
1228 noalias(temp_vector1) = it_node1->Coordinates();
1230 it_node1 = new_model_part.
Nodes().find(nodes_for_2triang[index * 3 + 1]);
1231 noalias(temp_vector2) = it_node1->Coordinates();
1233 it_node1 = new_model_part.
Nodes().find(nodes_for_2triang[index * 3 + 2]);
1234 noalias(temp_vector3) = it_node1->Coordinates();
1236 temp_vector3 -= temp_vector1;
1237 temp_vector2 -= temp_vector1;
1240 if (
inner_prod(temp_vector4, gradient) < 0.0)
1242 temp_int = nodes_for_2triang[index * 3 + 2];
1243 nodes_for_2triang[index * 3 + 2] = nodes_for_2triang[index * 3 + 1];
1244 nodes_for_2triang[index * 3 + 1] = temp_int;
1248 new_model_part.
Nodes()(nodes_for_2triang[index * 3 + 0]),
1249 new_model_part.
Nodes()(nodes_for_2triang[index * 3 + 1]),
1250 new_model_part.
Nodes()(nodes_for_2triang[index * 3 + 2])
1253 Condition::Pointer p_condition = rReferenceCondition.
Create(triangle_id_int + 1 + elements_before + total_existing_elements, geom, properties);
1255 new_model_part.
Conditions().push_back(p_condition);
1277 if (
mrComm.MyPID() == 0) std::cout <<
"Updating cut data:"<<std::endl;
1281 for (ModelPart::NodesContainerType::iterator it = new_model_part.
NodesBegin(); it != new_model_part.
NodesEnd(); it++)
1283 double* node0_data = it->GetValue(FATHER_NODES)[0].SolutionStepData().Data(0);
1284 double* node1_data = it->GetValue(FATHER_NODES)[1].SolutionStepData().Data(0);
1285 double weight = it->GetValue(WEIGHT_FATHER_NODES);
1286 double* step_data = (it)->SolutionStepData().Data(0);
1287 int partition_index= it->FastGetSolutionStepValue(PARTITION_INDEX);
1290 for (
int j = 0;
j < step_data_size;
j++)
1292 step_data[
j] = (1.0-weight) * node0_data[
j] + ( weight) * node1_data[
j];
1294 it->FastGetSolutionStepValue(PARTITION_INDEX)=partition_index;
1301 if (
mrComm.MyPID() == 0) std::cout <<
"Deleting cut data:"<<std::endl;
1302 new_model_part.
Nodes().clear();
1327 for (
int i = 0;
i < row_size;
i++)
1329 if (indices[
i] ==
j)
1341 if (index_0 > index_1)
1343 p_edge_ids->ExtractGlobalRowCopy(index_1, MaxNumEntries, NumEntries,
values, Indices);
1348 p_edge_ids->ExtractGlobalRowCopy(index_0, MaxNumEntries, NumEntries,
values, Indices);
virtual const DataCommunicator & GetDataCommunicator() const
Definition: communicator.cpp:340
MeshType & LocalMesh()
Returns the reference to the mesh storing all local entities.
Definition: communicator.cpp:245
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
Base class for all Elements.
Definition: element.h:60
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
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
Definition: amatrix_interface.h:41
static const TComponentType & Get(const std::string &rName)
Retrieves a component with the specified name.
Definition: kratos_components.h:114
static T CrossProduct(const T &a, const T &b)
Performs the vector product of the two input vectors a,b.
Definition: math_utils.h:762
NodesContainerType & Nodes()
Definition: mesh.h:346
NodeIterator NodesEnd()
Definition: mesh.h:336
NodeIterator NodesBegin()
Definition: mesh.h:326
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
MeshType::ConditionsContainerType ConditionsContainerType
Condintions container. A vector set of Conditions with their Id's as key.
Definition: model_part.h:183
ConditionIterator ConditionsBegin(IndexType ThisIndex=0)
Definition: model_part.h:1361
SizeType GetNodalSolutionStepDataSize()
Definition: model_part.h:571
MeshType::ElementsContainerType ElementsContainerType
Element container. A vector set of Elements with their Id's as key.
Definition: model_part.h:168
Communicator & GetCommunicator()
Definition: model_part.h:1821
NodeIterator NodesBegin(IndexType ThisIndex=0)
Definition: model_part.h:487
ConditionsContainerType & Conditions(IndexType ThisIndex=0)
Definition: model_part.h:1381
void AddNodalSolutionStepVariable(VariableData const &ThisVariable)
Definition: model_part.h:532
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
VariablesList & GetNodalSolutionStepVariablesList()
Definition: model_part.h:549
ConditionIterator ConditionsEnd(IndexType ThisIndex=0)
Definition: model_part.h:1371
This class defines the node.
Definition: node.h:65
This function recomputes the communication plan for MPI.
Definition: parallel_fill_communicator.h:56
void Execute() override
Execute the communicator fill.
Definition: parallel_fill_communicator.cpp:39
PointerVector is a container like stl vector but using a vector to store pointers to its data.
Definition: pointer_vector.h:72
size_type size() const
Returns the number of elements in the container.
Definition: pointer_vector_set.h:502
A three node 3D triangle geometry with linear shape functions.
Definition: triangle_3d_3.h:77
Definition: trilinos_cutting_iso_app.h:41
vector< Matrix > Matrix_Order_Tensor
Definition: trilinos_cutting_iso_app.h:47
void Create_List_Of_New_Nodes(ModelPart &this_model_part, ModelPart &new_model_part, Kratos::shared_ptr< Epetra_FECrsMatrix > &p_edge_ids, Kratos::shared_ptr< Epetra_FECrsMatrix > &p_partition_ids, vector< int > &List_New_Nodes, vector< int > &partition_new_nodes, vector< array_1d< int, 2 > > &father_node_ids, Kratos::shared_ptr< Epetra_FECrsMatrix > &used_nodes_matrix)
Definition: trilinos_cutting_iso_app.h:657
void CSR_Row_Matrix(ModelPart &this_model_part, Kratos::shared_ptr< Epetra_FECrsMatrix > &p_edge_ids, Kratos::shared_ptr< Epetra_FECrsMatrix > &used_nodes_matrix)
Definition: trilinos_cutting_iso_app.h:421
vector< Vector > Vector_Order_Tensor
Definition: trilinos_cutting_iso_app.h:48
Kratos::shared_ptr< Epetra_FECrsGraph > mp_non_overlapping_graph
Definition: trilinos_cutting_iso_app.h:1317
Node PointType
Definition: trilinos_cutting_iso_app.h:50
PointVector::iterator PointIterator
Definition: trilinos_cutting_iso_app.h:53
int mtotal_number_of_existing_nodes
Definition: trilinos_cutting_iso_app.h:1315
vector< Vector_Order_Tensor > Node_Vector_Order_Tensor
Definition: trilinos_cutting_iso_app.h:49
double smallest_edge
Definition: trilinos_cutting_iso_app.h:1310
void Clear()
Definition: trilinos_cutting_iso_app.h:401
~TrilinosCuttingIsosurfaceApplication()
Definition: trilinos_cutting_iso_app.h:65
double GetValueFromRow(int row, int j, int row_size, int *indices, double *values)
Definition: trilinos_cutting_iso_app.h:1325
ModelPart::ConditionsContainerType ConditionsArrayType
Definition: trilinos_cutting_iso_app.h:46
ModelPart::ElementsContainerType ElementsArrayType
Definition: trilinos_cutting_iso_app.h:45
void GenerateVariableCut(ModelPart &mr_model_part, ModelPart &mr_new_model_part, Variable< TDataType > &variable, double isovalue, int plane_number, float tolerance)
Definition: trilinos_cutting_iso_app.h:342
Kratos::shared_ptr< Epetra_Map > mp_overlapping_map
Definition: trilinos_cutting_iso_app.h:1313
void AddSkinConditions(ModelPart &mr_model_part, ModelPart &mr_new_model_part, int plane_number)
ADDSKINCONDITIONS: THIS FUNCTION ADDS TO THE NEW MODEL PART THE DATA OF THE CONDITIONS BELONGING TO T...
Definition: trilinos_cutting_iso_app.h:84
std::vector< PointType::Pointer > PointVector
Definition: trilinos_cutting_iso_app.h:52
void UpdateCutData(ModelPart &new_model_part, ModelPart &old_model_part)
Definition: trilinos_cutting_iso_app.h:1275
TrilinosCuttingIsosurfaceApplication(Epetra_MpiComm &Comm)
Definition: trilinos_cutting_iso_app.h:60
double GetUpperTriangularMatrixValue(const Kratos::shared_ptr< Epetra_FECrsMatrix > &p_edge_ids, int index_0, int index_1, int &MaxNumEntries, int &NumEntries, int *Indices, double *values)
Definition: trilinos_cutting_iso_app.h:1338
ModelPart::NodesContainerType NodesArrayType
Definition: trilinos_cutting_iso_app.h:44
Kratos::shared_ptr< Epetra_Map > mp_non_overlapping_map
Definition: trilinos_cutting_iso_app.h:1314
void GenerateElements(ModelPart &this_model_part, ModelPart &new_model_part, vector< int > Elems_In_Plane, const Kratos::shared_ptr< Epetra_FECrsMatrix > p_edge_ids, int plane_number, int &number_of_triangles, Variable< double > &variable)
Definition: trilinos_cutting_iso_app.h:951
Node ::Pointer PointPointerType
Definition: trilinos_cutting_iso_app.h:51
void DeleteCutData(ModelPart &new_model_part)
Definition: trilinos_cutting_iso_app.h:1299
void Calculate_Coordinate_And_Insert_New_Nodes(ModelPart &this_model_part, ModelPart &new_model_part, const vector< array_1d< int, 2 > > &father_node_ids, const vector< int > &List_New_Nodes, const vector< int > &partition_new_nodes, Variable< double > &variable, double isovalue, float tolerance)
Definition: trilinos_cutting_iso_app.h:829
Epetra_MpiComm & mrComm
Definition: trilinos_cutting_iso_app.h:1312
Kratos::shared_ptr< Epetra_CrsGraph > mp_overlapping_graph
Definition: trilinos_cutting_iso_app.h:1318
void FirstLoop(ModelPart &this_model_part, Kratos::shared_ptr< Epetra_FECrsMatrix > &p_edge_ids, Kratos::shared_ptr< Epetra_FECrsMatrix > &p_partition_ids, Variable< double > &variable, double isovalue, int &number_of_triangles, vector< int > &Elems_In_Plane, double tolerance, Kratos::shared_ptr< Epetra_FECrsMatrix > &used_nodes_matrix)
Definition: trilinos_cutting_iso_app.h:500
Variable class contains all information needed to store and retrive data from a data container.
Definition: variable.h:63
Short class definition.
Definition: array_1d.h:61
BOOST_UBLAS_INLINE void resize(size_type array_size, bool preserve=true)
Definition: array_1d.h:242
#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 KRATOS_ERROR_IF(conditional)
Definition: exception.h:162
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
std::shared_ptr< T > shared_ptr
Definition: smart_pointers.h:27
TExpression1Type::data_type inner_prod(AMatrix::MatrixExpression< TExpression1Type, TCategory1 > const &First, AMatrix::MatrixExpression< TExpression2Type, TCategory2 > const &Second)
Definition: amatrix_interface.h:592
T & noalias(T &TheMatrix)
Definition: amatrix_interface.h:484
AMatrix::MatrixRow< const TExpressionType > row(AMatrix::MatrixExpression< TExpressionType, TCategory > const &TheExpression, std::size_t RowIndex)
Definition: amatrix_interface.h:649
REACTION_CHECK_STIFFNESS_FACTOR int
Definition: contact_structural_mechanics_application_variables.h:75
TABLE_NUMBER_ANGULAR_VELOCITY TABLE_NUMBER_MOMENT I33 BEAM_INERTIA_ROT_UNIT_LENGHT_Y KRATOS_DEFINE_APPLICATION_VARIABLE(DEM_APPLICATION, double, BEAM_INERTIA_ROT_UNIT_LENGHT_Z) typedef std double
Definition: DEM_application_variables.h:182
list values
Definition: bombardelli_test.py:42
int k
Definition: quadrature.py:595
int j
Definition: quadrature.py:648
int node_id
Definition: read_stl.py:12
int counter
Definition: script_THERMAL_CORRECT.py:218
N
Definition: sensitivityMatrix.py:29
int nnodes
Definition: sensitivityMatrix.py:24
integer i
Definition: TensorModule.f:17
integer l
Definition: TensorModule.f:17