13 #if !defined(KRATOS_PROJECTION )
14 #define KRATOS_PROJECTION
35 template<
class T, std::
size_t dim >
42 for( std::size_t
i = 0 ;
i <
dim ;
i++)
44 double tmp = p1[
i] - p2[
i];
86 template<std::
size_t TDim >
142 typedef std::vector<PointType::Pointer>
PointVector;
143 typedef std::vector<PointType::Pointer>::iterator
PointIterator;
153 auto inital_time = std::chrono::steady_clock::now();
174 for(ModelPart::NodesContainerType::iterator node_it = rDestination_ModelPart.
NodesBegin();
175 node_it != rDestination_ModelPart.
NodesEnd(); ++node_it)
178 Node::Pointer pnode = *(node_it.base());
181 list_of_new_nodes.push_back( pnode );
189 unsigned int bucket_size = 20;
190 tree nodes_tree(list_of_new_nodes.begin(),list_of_new_nodes.end(),bucket_size);
194 Node work_point(0,0.0,0.0,0.0);
195 unsigned int MaximumNumberOfResults = 10000;
201 for(ModelPart::NodesContainerType::iterator node_it = rDestination_ModelPart.
NodesBegin();
202 node_it != rDestination_ModelPart.
NodesEnd(); ++node_it)
205 Clear(node_it, step_data_size );
207 inital_time = std::chrono::steady_clock::now();
209 for( ModelPart::ElementsContainerType::iterator el_it = rOrigin_ModelPart.
ElementsBegin();
237 CalculateCenterAndSearchRadius( geom,
xc,
yc,zc,
radius,
N);
243 int number_of_points_in_radius;
246 number_of_points_in_radius = nodes_tree.SearchInRadius(work_point,
radius, Results.begin(),
247 ResultsDistances.begin(), MaximumNumberOfResults);
251 for(
auto it_found = Results.begin(); it_found != Results.begin() + number_of_points_in_radius; it_found++)
254 bool is_inside =
false;
273 double is_visited = (*it_found)->GetValue(IS_VISITED);
274 is_inside = CalculatePosition(geom, (*it_found)->X(),(*it_found)->Y(),(*it_found)->Z(),
N);
277 if(is_inside ==
true && is_visited != 1.0)
280 Interpolate( el_it,
N, step_data_size, *it_found );
301 template<
class TDataType>
319 typedef std::vector<PointType::Pointer>
PointVector;
320 typedef std::vector<PointType::Pointer>::iterator
PointIterator;
330 auto inital_time = std::chrono::steady_clock::now();
350 for(ModelPart::NodesContainerType::iterator node_it = rDestination_ModelPart.
NodesBegin();
351 node_it != rDestination_ModelPart.
NodesEnd(); ++node_it)
353 node_it->GetValue(IS_VISITED) = 0.0;
357 for(ModelPart::NodesContainerType::iterator node_it = rDestination_ModelPart.
NodesBegin();
358 node_it != rDestination_ModelPart.
NodesEnd(); ++node_it)
361 ClearVariables(node_it, rDestinationVariable);
365 Node::Pointer pnode = *(node_it.base());
368 list_of_new_nodes.push_back( pnode );
378 unsigned int bucket_size = 20;
379 tree nodes_tree(list_of_new_nodes.begin(),list_of_new_nodes.end(),bucket_size);
382 Node work_point(0,0.0,0.0,0.0);
383 unsigned int MaximumNumberOfResults = 10000;
390 inital_time = std::chrono::steady_clock::now();
392 for( ModelPart::ElementsContainerType::iterator el_it = rOrigin_ModelPart.
ElementsBegin();
420 CalculateCenterAndSearchRadius( geom,
xc,
yc,zc,
radius,
N);
426 int number_of_points_in_radius;
429 number_of_points_in_radius = nodes_tree.SearchInRadius(work_point,
radius, Results.begin(),
430 ResultsDistances.begin(), MaximumNumberOfResults);
434 for(
auto it_found = Results.begin(); it_found != Results.begin() + number_of_points_in_radius; it_found++)
437 bool is_inside =
false;
457 double is_visited = (*it_found)->GetValue(IS_VISITED);
458 is_inside = CalculatePosition(geom, (*it_found)->X(),(*it_found)->Y(),(*it_found)->Z(),
N);
463 if(is_inside ==
true && is_visited != 1.0)
467 Interpolate( el_it,
N, *it_found , rOriginVariable , rDestinationVariable );
496 virtual std::string
Info()
const
566 double x0 = geom[0].X();
567 double y0 = geom[0].Y();
568 double x1 = geom[1].X();
569 double y1 = geom[1].Y();
570 double x2 = geom[2].X();
571 double y2 = geom[2].Y();
574 xc = 0.3333333333333333333*(x0+
x1+
x2);
575 yc = 0.3333333333333333333*(y0+y1+y2);
578 double R1 = (
xc-x0)*(
xc-x0) + (
yc-y0)*(
yc-y0);
590 inline void CalculateCenterAndSearchRadius(Geometry<Node >&geom,
591 double&
xc,
double&
yc,
double& zc,
double&
R, array_1d<double,4>&
N
595 double x0 = geom[0].X();
596 double y0 = geom[0].Y();
597 double z0 = geom[0].Z();
598 double x1 = geom[1].X();
599 double y1 = geom[1].Y();
600 double z1 = geom[1].Z();
601 double x2 = geom[2].X();
602 double y2 = geom[2].Y();
603 double z2 = geom[2].Z();
604 double x3 = geom[3].X();
605 double y3 = geom[3].Y();
606 double z3 = geom[3].Z();
610 yc = 0.25*(y0+y1+y2+y3);
611 zc = 0.25*(z0+z1+z2+z3);
613 double R1 = (
xc-x0)*(
xc-x0) + (
yc-y0)*(
yc-y0) + (zc-z0)*(zc-z0);
614 double R2 = (
xc-
x1)*(
xc-
x1) + (
yc-y1)*(
yc-y1) + (zc-z1)*(zc-z1);
615 double R3 = (
xc-
x2)*(
xc-
x2) + (
yc-y2)*(
yc-y2) + (zc-z2)*(zc-z2);
616 double R4 = (
xc-x3)*(
xc-x3) + (
yc-y3)*(
yc-y3) + (zc-z3)*(zc-z3);
627 inline double CalculateVol(
const double x0,
const double y0,
628 const double x1,
const double y1,
629 const double x2,
const double y2
632 return 0.5*( (
x1-x0)*(y2-y0)- (y1-y0)*(
x2-x0) );
636 inline double CalculateVol(
const double x0,
const double y0,
const double z0,
637 const double x1,
const double y1,
const double z1,
638 const double x2,
const double y2,
const double z2,
639 const double x3,
const double y3,
const double z3
642 double x10 =
x1 - x0;
643 double y10 = y1 - y0;
644 double z10 = z1 - z0;
646 double x20 =
x2 - x0;
647 double y20 = y2 - y0;
648 double z20 = z2 - z0;
650 double x30 = x3 - x0;
651 double y30 = y3 - y0;
652 double z30 = z3 - z0;
654 double detJ = x10 * y20 * z30 - x10 * y30 * z20 + y10 * z20 * x30 - y10 * x20 * z30 + z10 * x20 * y30 - z10 * y20 * x30;
655 return detJ*0.1666666666666666666667;
661 inline bool CalculatePosition( Geometry<Node >&geom,
662 const double xc,
const double yc,
const double zc,
663 array_1d<double,3>&
N
666 double x0 = geom[0].X();
667 double y0 = geom[0].Y();
668 double x1 = geom[1].X();
669 double y1 = geom[1].Y();
670 double x2 = geom[2].X();
671 double y2 = geom[2].Y();
673 double area = CalculateVol(x0,y0,
x1,y1,
x2,y2);
674 double inv_area = 0.0;
685 inv_area = 1.0 / area;
689 N[0] = CalculateVol(
x1,y1,
x2,y2,
xc,
yc) * inv_area;
690 N[1] = CalculateVol(
x2,y2,x0,y0,
xc,
yc) * inv_area;
691 N[2] = CalculateVol(x0,y0,
x1,y1,
xc,
yc) * inv_area;
694 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)
703 inline bool CalculatePosition( Geometry<Node >&geom,
704 const double xc,
const double yc,
const double zc,
705 array_1d<double,4>&
N
709 double x0 = geom[0].X();
710 double y0 = geom[0].Y();
711 double z0 = geom[0].Z();
712 double x1 = geom[1].X();
713 double y1 = geom[1].Y();
714 double z1 = geom[1].Z();
715 double x2 = geom[2].X();
716 double y2 = geom[2].Y();
717 double z2 = geom[2].Z();
718 double x3 = geom[3].X();
719 double y3 = geom[3].Y();
720 double z3 = geom[3].Z();
722 double vol = CalculateVol(x0,y0,z0,
x1,y1,z1,
x2,y2,z2,x3,y3,z3);
724 double inv_vol = 0.0;
725 if(vol < 0.0000000000001)
731 KRATOS_WATCH(
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
738 N[0] = CalculateVol(
x1,y1,z1,x3,y3,z3,
x2,y2,z2,
xc,
yc,zc) * inv_vol;
739 N[1] = CalculateVol(x3,y3,z3,x0,y0,z0,
x2,y2,z2,
xc,
yc,zc) * inv_vol;
740 N[2] = CalculateVol(x3,y3,z3,
x1,y1,z1,x0,y0,z0,
xc,
yc,zc) * inv_vol;
741 N[3] = CalculateVol(x0,y0,z0,
x1,y1,z1,
x2,y2,z2,
xc,
yc,zc) * inv_vol;
744 if(
N[0] >= 0.0 &&
N[1] >= 0.0 &&
N[2] >= 0.0 &&
N[3] >=0.0 &&
745 N[0] <= 1.0 &&
N[1] <= 1.0 &&
N[2] <= 1.0 &&
N[3] <=1.0)
758 ModelPart::ElementsContainerType::iterator el_it,
759 const array_1d<double,3>&
N,
764 Geometry< Node >& geom = el_it->GetGeometry();
766 unsigned int buffer_size = pnode->GetBufferSize();
771 double* step_data = (pnode)->SolutionStepData().Data(
step);
773 double* node0_data = geom[0].SolutionStepData().Data(
step);
774 double* node1_data = geom[1].SolutionStepData().Data(
step);
775 double* node2_data = geom[2].SolutionStepData().Data(
step);
778 for(
int j= 0;
j< step_data_size;
j++)
780 step_data[
j] =
N[0]*node0_data[
j] +
N[1]*node1_data[
j] +
N[2]*node2_data[
j];
783 pnode->GetValue(IS_VISITED) = 1.0;
788 ModelPart::ElementsContainerType::iterator el_it,
789 const array_1d<double,4>&
N,
794 Geometry< Node >& geom = el_it->GetGeometry();
796 unsigned int buffer_size = pnode->GetBufferSize();
801 double* step_data = (pnode)->SolutionStepData().Data(
step);
803 double* node0_data = geom[0].SolutionStepData().Data(
step);
804 double* node1_data = geom[1].SolutionStepData().Data(
step);
805 double* node2_data = geom[2].SolutionStepData().Data(
step);
806 double* node3_data = geom[3].SolutionStepData().Data(
step);
809 for(
int j= 0;
j< step_data_size;
j++)
811 step_data[
j] =
N[0]*node0_data[
j] +
N[1]*node1_data[
j] +
N[2]*node2_data[
j] +
N[3]*node3_data[
j];
814 pnode->GetValue(IS_VISITED) = 1.0;
821 ModelPart::ElementsContainerType::iterator el_it,
822 const array_1d<double,3>&
N,
824 Variable<array_1d<double,3> >& rOriginVariable,
825 Variable<array_1d<double,3> >& rDestinationVariable)
828 Geometry< Node >& geom = el_it->GetGeometry();
830 unsigned int buffer_size = pnode->GetBufferSize();
835 array_1d<double,3>& step_data = (pnode)->FastGetSolutionStepValue(rDestinationVariable ,
step);
837 const array_1d<double,3>& node0_data = geom[0].FastGetSolutionStepValue(rOriginVariable ,
step);
838 const array_1d<double,3>& node1_data = geom[1].FastGetSolutionStepValue(rOriginVariable ,
step);
839 const array_1d<double,3>& node2_data = geom[2].FastGetSolutionStepValue(rOriginVariable ,
step);
842 for(
unsigned int j= 0;
j< TDim;
j++)
844 step_data[
j] =
N[0]*node0_data[
j] +
N[1]*node1_data[
j] +
N[2]*node2_data[
j];
847 pnode->GetValue(IS_VISITED) = 1.0;
853 ModelPart::ElementsContainerType::iterator el_it,
854 const array_1d<double,4>&
N,
856 Variable<array_1d<double,3> >& rOriginVariable,
857 Variable<array_1d<double,3> >& rDestinationVariable)
861 Geometry< Node >& geom = el_it->GetGeometry();
863 unsigned int buffer_size = pnode->GetBufferSize();
868 array_1d<double,3>& step_data = (pnode)->FastGetSolutionStepValue(rDestinationVariable ,
step);
870 const array_1d<double,3>& node0_data = geom[0].FastGetSolutionStepValue(rOriginVariable ,
step);
871 const array_1d<double,3>& node1_data = geom[1].FastGetSolutionStepValue(rOriginVariable ,
step);
872 const array_1d<double,3>& node2_data = geom[2].FastGetSolutionStepValue(rOriginVariable ,
step);
873 const array_1d<double,3>& node3_data = geom[3].FastGetSolutionStepValue(rOriginVariable ,
step);
876 for(
unsigned int j= 0;
j< TDim;
j++)
878 step_data[
j] =
N[0]*node0_data[
j] +
N[1]*node1_data[
j] +
N[2]*node2_data[
j] +
N[3]*node3_data[
j];
881 pnode->GetValue(IS_VISITED) = 1.0;
886 ModelPart::ElementsContainerType::iterator el_it,
887 const array_1d<double,3>&
N,
889 Variable<double>& rOriginVariable,
890 Variable<double>& rDestinationVariable)
893 Geometry< Node >& geom = el_it->GetGeometry();
895 unsigned int buffer_size = pnode->GetBufferSize();
900 double& step_data = (pnode)->FastGetSolutionStepValue(rDestinationVariable ,
step);
902 const double node0_data = geom[0].FastGetSolutionStepValue(rOriginVariable ,
step);
903 const double node1_data = geom[1].FastGetSolutionStepValue(rOriginVariable ,
step);
904 const double node2_data = geom[2].FastGetSolutionStepValue(rOriginVariable ,
step);
908 step_data =
N[0]*node0_data +
N[1]*node1_data +
N[2]*node2_data;
911 pnode->GetValue(IS_VISITED) = 1.0;
916 ModelPart::ElementsContainerType::iterator el_it,
917 const array_1d<double,4>&
N,
919 Variable<double>& rOriginVariable,
920 Variable<double>& rDestinationVariable)
923 Geometry< Node >& geom = el_it->GetGeometry();
925 unsigned int buffer_size = pnode->GetBufferSize();
930 double& step_data = (pnode)->FastGetSolutionStepValue(rDestinationVariable ,
step);
932 const double node0_data = geom[0].FastGetSolutionStepValue(rOriginVariable ,
step);
933 const double node1_data = geom[1].FastGetSolutionStepValue(rOriginVariable ,
step);
934 const double node2_data = geom[2].FastGetSolutionStepValue(rOriginVariable ,
step);
935 const double node3_data = geom[3].FastGetSolutionStepValue(rOriginVariable ,
step);
939 step_data =
N[0]*node0_data +
N[1]*node1_data +
N[2]*node2_data +
N[3]*node3_data;
942 pnode->GetValue(IS_VISITED) = 1.0;
945 inline void Clear(ModelPart::NodesContainerType::iterator node_it,
int step_data_size )
947 unsigned int buffer_size = node_it->GetBufferSize();
952 double* step_data = (node_it)->SolutionStepData().Data(
step);
955 for(
int j= 0;
j< step_data_size;
j++)
963 inline void ClearVariables(ModelPart::NodesContainerType::iterator node_it , Variable<array_1d<double,3> >& rVariable)
965 array_1d<double, 3>& Aux_var = node_it->FastGetSolutionStepValue(rVariable, 0);
972 inline void ClearVariables(ModelPart::NodesContainerType::iterator node_it, Variable<double>& rVariable)
974 double& Aux_var = node_it->FastGetSolutionStepValue(rVariable, 0);
1028 template<std::
size_t TDim>
1033 rOStream << std::endl;
Short class definition.
Definition: bucket.h:57
Definition: projection.h:37
double operator()(T const &p1, T const &p2)
Definition: projection.h:39
Geometry base class.
Definition: geometry.h:71
PropertiesType::Pointer pGetProperties(IndexType PropertiesId)
Definition: mesh.h:394
This class allows the interpolation between non-matching meshes in 2D and 3D.
Definition: projection.h:88
virtual void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: projection.h:502
void DirectVariableInterpolation(ModelPart &rOrigin_ModelPart, ModelPart &rDestination_ModelPart, Variable< TDataType > &rOriginVariable, Variable< TDataType > &rDestinationVariable)
Interpolate one variable.
Definition: projection.h:302
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: projection.h:505
virtual std::string Info() const
Turn back information as a stemplate<class T, std::size_t dim> tring.
Definition: projection.h:496
void DirectInterpolation(ModelPart &rOrigin_ModelPart, ModelPart &rDestination_ModelPart)
Interpolate the whole problem type.
Definition: projection.h:124
KRATOS_CLASS_POINTER_DEFINITION(MeshTransfer< TDim >)
Pointer definition of MeshTransfer.
MeshTransfer()=default
Default constructor.
virtual ~MeshTransfer()=default
Destructor.
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
SizeType GetNodalSolutionStepDataSize()
Definition: model_part.h:571
NodeIterator NodesBegin(IndexType ThisIndex=0)
Definition: model_part.h:487
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
This class defines the node.
Definition: node.h:65
double Y() const
Definition: point.h:187
double Z() const
Definition: point.h:193
double X() const
Definition: point.h:181
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
Variable class contains all information needed to store and retrive data from a data container.
Definition: variable.h:63
#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
KratosZeroVector< double > ZeroVector
Definition: amatrix_interface.h:561
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
PointType::Pointer PointTypePointer
Definition: internal_variables_interpolation_process.h:52
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
float dist
Definition: edgebased_PureConvection.py:89
int step
Definition: face_heat.py:88
x2
Definition: generate_frictional_mortar_condition.py:122
x1
Definition: generate_frictional_mortar_condition.py:121
tuple tmp
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:98
R
Definition: isotropic_damage_automatic_differentiation.py:172
float radius
Definition: mesh_to_mdpa_converter.py:18
int j
Definition: quadrature.py:648
float xc
Definition: rotating_cone.py:77
float yc
Definition: rotating_cone.py:78
N
Definition: sensitivityMatrix.py:29
int dim
Definition: sensitivityMatrix.py:25
integer i
Definition: TensorModule.f:17