13 #if !defined(KRATOS_BINBASED_PROJECTION )
14 #define KRATOS_BINBASED_PROJECTION
71 template<std::
size_t TDim >
138 template<
class TDataType>
149 KRATOS_INFO(
"BinBasedMeshTransfer") <<
"Interpolate From Fixed Mesh*************************************" << std::endl;
152 for(
auto node_it = rMoving_ModelPart.
NodesBegin(); node_it != rMoving_ModelPart.
NodesEnd(); ++node_it) {
153 ClearVariables(node_it, rMovingDomainVariable);
157 const int max_results = 10000;
159 const int nparticles = rMoving_ModelPart.
Nodes().size();
161 #pragma omp parallel for firstprivate(results,N)
162 for (
int i = 0;
i < nparticles;
i++) {
163 ModelPart::NodesContainerType::iterator iparticle = rMoving_ModelPart.
NodesBegin() +
i;
164 NodeType::Pointer pparticle = *(iparticle.base());
165 auto result_begin = results.begin();
166 Element::Pointer pelement;
168 bool is_found = node_locator.FindPointOnMesh(pparticle->Coordinates(),
N, pelement, result_begin, max_results);
170 if (is_found ==
true) {
172 Interpolate( pelement,
N, pparticle, rFixedDomainVariable , rMovingDomainVariable );
189 template<
class TDataType>
200 KRATOS_INFO(
"BinBasedMeshTransfer") <<
"Transfer From Moving Mesh*************************************" << std::endl;
202 if (rMoving_ModelPart.
NodesBegin()->SolutionStepsDataHas(rMovingDomainVariable) ==
false)
204 if (rFixed_ModelPart.
NodesBegin()->SolutionStepsDataHas(rFixedDomainVariable) ==
false)
209 for(ModelPart::NodesContainerType::iterator node_it = rFixed_ModelPart.
NodesBegin();
210 node_it != rFixed_ModelPart.
NodesEnd(); ++node_it)
213 ClearVariables(node_it, rFixedDomainVariable);
217 for (ModelPart::NodesContainerType::iterator node_it = rFixed_ModelPart.
NodesBegin();
218 node_it != rFixed_ModelPart.
NodesEnd(); node_it++)
224 (node_it)->
GetValue(YOUNG_MODULUS) = 0.0;
232 const int max_results = 10000;
234 const int nparticles = rMoving_ModelPart.
Nodes().size();
236 #pragma omp parallel for firstprivate(results,N)
237 for (
int i = 0;
i < nparticles;
i++)
239 ModelPart::NodesContainerType::iterator iparticle = rMoving_ModelPart.
NodesBegin() +
i;
241 NodeType::Pointer pparticle = *(iparticle.base());
242 auto result_begin = results.begin();
244 Element::Pointer pelement;
246 bool is_found = node_locator.FindPointOnMesh(pparticle->Coordinates(),
N, pelement, result_begin, max_results);
248 if (is_found ==
true)
253 const TDataType& value = (iparticle)->FastGetSolutionStepValue(rMovingDomainVariable);
255 for (std::size_t
k = 0;
k < geom.
size();
k++)
258 geom[
k].FastGetSolutionStepValue(rFixedDomainVariable) +=
N[
k] * value;
269 for (ModelPart::NodesContainerType::iterator node_it = rFixed_ModelPart.
NodesBegin();
270 node_it != rFixed_ModelPart.
NodesEnd(); node_it++)
272 const double NN = (node_it)->
GetValue(YOUNG_MODULUS);
275 (node_it)->FastGetSolutionStepValue(rFixedDomainVariable) /= NN;
291 template<
class TDataType>
302 KRATOS_WATCH(
"Transfer From Moving Mesh*************************************")
303 if (rMoving_ModelPart.
NodesBegin()->SolutionStepsDataHas(rMovingDomainVariable) ==
false)
305 if (rFixed_ModelPart.
NodesBegin()->SolutionStepsDataHas(rFixedDomainVariable) ==
false)
310 for(ModelPart::NodesContainerType::iterator node_it = rFixed_ModelPart.
NodesBegin();
311 node_it != rFixed_ModelPart.
NodesEnd(); ++node_it)
313 ClearVariables(node_it, rFixedDomainVariable);
319 const std::size_t max_results = 5000;
320 Matrix Nmat(max_results,TDim+1);
321 boost::numeric::ublas::vector<int> positions(max_results);
324 Node work_point(0,0.0,0.0,0.0);
325 for(ModelPart::ElementsContainerType::iterator elem_it = rMoving_ModelPart.
ElementsBegin(); elem_it != rMoving_ModelPart.
ElementsEnd(); ++elem_it)
327 std::size_t nfound = node_locator.
FindNodesInElement(*(elem_it.base()), positions, Nmat, max_results, work_results.
begin(), work_distances.begin(), work_point);
328 for(std::size_t
k=0;
k<nfound;
k++)
330 auto it = work_results.begin() + positions[
k];
334 Interpolate( *(elem_it.base()),
N, *it, rMovingDomainVariable , rFixedDomainVariable);
358 virtual std::string
Info()
const
424 inline void CalculateCenterAndSearchRadius(
GeometryType&geom,
428 double x0 = geom[0].X();
429 double y0 = geom[0].Y();
430 double x1 = geom[1].X();
431 double y1 = geom[1].Y();
432 double x2 = geom[2].X();
433 double y2 = geom[2].Y();
436 xc = 0.3333333333333333333*(x0+
x1+
x2);
437 yc = 0.3333333333333333333*(y0+y1+y2);
440 double R1 = (
xc-x0)*(
xc-x0) + (
yc-y0)*(
yc-y0);
452 inline void CalculateCenterAndSearchRadius(
GeometryType&geom,
453 double&
xc,
double&
yc,
double& zc,
double&
R, array_1d<double,4>&
N
457 double x0 = geom[0].X();
458 double y0 = geom[0].Y();
459 double z0 = geom[0].Z();
460 double x1 = geom[1].X();
461 double y1 = geom[1].Y();
462 double z1 = geom[1].Z();
463 double x2 = geom[2].X();
464 double y2 = geom[2].Y();
465 double z2 = geom[2].Z();
466 double x3 = geom[3].X();
467 double y3 = geom[3].Y();
468 double z3 = geom[3].Z();
472 yc = 0.25*(y0+y1+y2+y3);
473 zc = 0.25*(z0+z1+z2+z3);
475 double R1 = (
xc-x0)*(
xc-x0) + (
yc-y0)*(
yc-y0) + (zc-z0)*(zc-z0);
476 double R2 = (
xc-
x1)*(
xc-
x1) + (
yc-y1)*(
yc-y1) + (zc-z1)*(zc-z1);
477 double R3 = (
xc-
x2)*(
xc-
x2) + (
yc-y2)*(
yc-y2) + (zc-z2)*(zc-z2);
478 double R4 = (
xc-x3)*(
xc-x3) + (
yc-y3)*(
yc-y3) + (zc-z3)*(zc-z3);
489 inline double CalculateVol(
const double x0,
const double y0,
490 const double x1,
const double y1,
491 const double x2,
const double y2
494 return 0.5*( (
x1-x0)*(y2-y0)- (y1-y0)*(
x2-x0) );
498 inline double CalculateVol(
const double x0,
const double y0,
const double z0,
499 const double x1,
const double y1,
const double z1,
500 const double x2,
const double y2,
const double z2,
501 const double x3,
const double y3,
const double z3
504 double x10 =
x1 - x0;
505 double y10 = y1 - y0;
506 double z10 = z1 - z0;
508 double x20 =
x2 - x0;
509 double y20 = y2 - y0;
510 double z20 = z2 - z0;
512 double x30 = x3 - x0;
513 double y30 = y3 - y0;
514 double z30 = z3 - z0;
516 double detJ = x10 * y20 * z30 - x10 * y30 * z20 + y10 * z20 * x30 - y10 * x20 * z30 + z10 * x20 * y30 - z10 * y20 * x30;
517 return detJ*0.1666666666666666666667;
524 const double xc,
const double yc,
const double zc,
525 array_1d<double,3>&
N
528 double x0 = geom[0].X();
529 double y0 = geom[0].Y();
530 double x1 = geom[1].X();
531 double y1 = geom[1].Y();
532 double x2 = geom[2].X();
533 double y2 = geom[2].Y();
535 double area = CalculateVol(x0,y0,
x1,y1,
x2,y2);
536 double inv_area = 0.0;
547 inv_area = 1.0 / area;
551 N[0] = CalculateVol(
x1,y1,
x2,y2,
xc,
yc) * inv_area;
552 N[1] = CalculateVol(
x2,y2,x0,y0,
xc,
yc) * inv_area;
553 N[2] = CalculateVol(x0,y0,
x1,y1,
xc,
yc) * inv_area;
556 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)
566 const double xc,
const double yc,
const double zc,
567 array_1d<double,4>&
N
571 double x0 = geom[0].X();
572 double y0 = geom[0].Y();
573 double z0 = geom[0].Z();
574 double x1 = geom[1].X();
575 double y1 = geom[1].Y();
576 double z1 = geom[1].Z();
577 double x2 = geom[2].X();
578 double y2 = geom[2].Y();
579 double z2 = geom[2].Z();
580 double x3 = geom[3].X();
581 double y3 = geom[3].Y();
582 double z3 = geom[3].Z();
584 double vol = CalculateVol(x0,y0,z0,
x1,y1,z1,
x2,y2,z2,x3,y3,z3);
586 double inv_vol = 0.0;
587 if(vol < 0.0000000000001)
600 N[0] = CalculateVol(
x1,y1,z1,x3,y3,z3,
x2,y2,z2,
xc,
yc,zc) * inv_vol;
601 N[1] = CalculateVol(x3,y3,z3,x0,y0,z0,
x2,y2,z2,
xc,
yc,zc) * inv_vol;
602 N[2] = CalculateVol(x3,y3,z3,
x1,y1,z1,x0,y0,z0,
xc,
yc,zc) * inv_vol;
603 N[3] = CalculateVol(x0,y0,z0,
x1,y1,z1,
x2,y2,z2,
xc,
yc,zc) * inv_vol;
606 if(
N[0] >= 0.0 &&
N[1] >= 0.0 &&
N[2] >= 0.0 &&
N[3] >=0.0 &&
607 N[0] <= 1.0 &&
N[1] <= 1.0 &&
N[2] <= 1.0 &&
N[3] <=1.0)
620 Element::Pointer ElemIt,
623 NodeType::Pointer pnode)
628 const std::size_t buffer_size = pnode->GetBufferSize();
630 const std::size_t vector_size =
N.size();
634 double* step_data = (pnode)->SolutionStepData().Data(
step);
636 double* node0_data = geom[0].SolutionStepData().Data(
step);
639 for(
int j= 0;
j< step_data_size;
j++) {
640 step_data[
j] =
N[0]*node0_data[
j];
642 for(std::size_t
k= 1;
k< vector_size;
k++) {
643 double* node1_data = geom[
k].SolutionStepData().Data(
step);
644 for(
int j= 0;
j< step_data_size;
j++) {
645 step_data[
j] +=
N[
k]*node1_data[
j];
655 Element::Pointer ElemIt,
657 NodeType::Pointer pnode,
658 Variable<array_1d<double,3> >& rOriginVariable,
659 Variable<array_1d<double,3> >& rDestinationVariable)
664 const std::size_t buffer_size = pnode->GetBufferSize();
666 const std::size_t vector_size =
N.size();
670 array_1d<double,3>& step_data = (pnode)->FastGetSolutionStepValue(rDestinationVariable ,
step);
672 step_data =
N[0] * geom[0].FastGetSolutionStepValue(rOriginVariable ,
step);
675 for(std::size_t
j= 1;
j< vector_size;
j++) {
676 const array_1d<double,3>& node_data = geom[
j].FastGetSolutionStepValue(rOriginVariable ,
step);
677 step_data +=
N[
j] * node_data;
685 Element::Pointer ElemIt,
687 NodeType::Pointer pnode,
688 Variable<double>& rOriginVariable,
689 Variable<double>& rDestinationVariable)
694 const std::size_t buffer_size = pnode->GetBufferSize();
696 const std::size_t vector_size =
N.size();
701 double& step_data = (pnode)->FastGetSolutionStepValue(rDestinationVariable ,
step);
705 step_data =
N[0] * geom[0].FastGetSolutionStepValue(rOriginVariable ,
step);
708 for(std::size_t
j= 1;
j< vector_size;
j++) {
709 const double node_data = geom[
j].FastGetSolutionStepValue(rOriginVariable ,
step);
710 step_data +=
N[
j] * node_data;
718 inline void Clear(ModelPart::NodesContainerType::iterator node_it,
int step_data_size )
720 std::size_t buffer_size = node_it->GetBufferSize();
725 double* step_data = (node_it)->SolutionStepData().Data(
step);
728 for(
int j= 0;
j< step_data_size;
j++)
736 inline void ClearVariables(ModelPart::NodesContainerType::iterator node_it , Variable<array_1d<double,3> >& rVariable)
738 array_1d<double, 3>& Aux_var = node_it->FastGetSolutionStepValue(rVariable, 0);
744 inline void ClearVariables(ModelPart::NodesContainerType::iterator node_it, Variable<double>& rVariable)
746 double& Aux_var = node_it->FastGetSolutionStepValue(rVariable, 0);
797 template<std::
size_t TDim>
802 rOStream << std::endl;
This class is designed to allow the fast location of MANY points on the top of a 3D mesh.
Definition: binbased_fast_point_locator.h:68
ConfigureType::ResultContainerType ResultContainerType
Definition: binbased_fast_point_locator.h:81
This class allows the interpolation between non-matching meshes in 2D and 3D.
Definition: binbased_projection.h:73
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: binbased_projection.h:367
BinBasedMeshTransfer()=default
Default constructor.
KRATOS_CLASS_POINTER_DEFINITION(BinBasedMeshTransfer< TDim >)
Pointer definition of BinBasedMeshTransfer.
void DirectInterpolation(ModelPart &rOrigin_ModelPart, ModelPart &rDestination_ModelPart)
Interpolate the whole problem type.
Definition: binbased_projection.h:113
void MappingFromMovingMesh_VariableMeshes(ModelPart &rMoving_ModelPart, ModelPart &rFixed_ModelPart, Variable< TDataType > &rMovingDomainVariable, Variable< TDataType > &rFixedDomainVariable, BinBasedNodesInElementLocator< TDim > &node_locator)
Interpolate one variable from the moving mesh to the fixed one.
Definition: binbased_projection.h:292
Geometry< NodeType > GeometryType
Definition: binbased_projection.h:83
virtual std::string Info() const
Turn back information as a stemplate<class T, std::size_t dim> tring.
Definition: binbased_projection.h:358
virtual void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: binbased_projection.h:364
void DirectVariableInterpolation(ModelPart &rFixed_ModelPart, ModelPart &rMoving_ModelPart, Variable< TDataType > &rFixedDomainVariable, Variable< TDataType > &rMovingDomainVariable, BinBasedFastPointLocator< TDim > &node_locator)
Interpolate one variable from the fixed mesh to the moving one.
Definition: binbased_projection.h:139
virtual ~BinBasedMeshTransfer()=default
Destructor.
void MappingFromMovingMesh(ModelPart &rMoving_ModelPart, ModelPart &rFixed_ModelPart, Variable< TDataType > &rMovingDomainVariable, Variable< TDataType > &rFixedDomainVariable, BinBasedFastPointLocator< TDim > &node_locator)
Definition: binbased_projection.h:190
Node NodeType
Node type definition.
Definition: binbased_projection.h:82
REMARK: the location function is threadsafe, and can be used in OpenMP loops.
Definition: binbased_nodes_in_element_locator.h:44
std::vector< PointType::Pointer > PointVector
Definition: binbased_nodes_in_element_locator.h:49
unsigned int FindNodesInElement(Element::Pointer &pelement, DenseVector< int > &positions, Matrix &Nmat, const unsigned int max_results, PointIterator work_results, DistanceIterator work_distances, Node &work_point)
function to find all teh nodes of a fixed mesh contained in the elements of a moving mesh
Definition: binbased_nodes_in_element_locator.h:133
std::vector< double > DistanceVector
Definition: binbased_nodes_in_element_locator.h:51
Geometry base class.
Definition: geometry.h:71
SizeType size() const
Definition: geometry.h:518
TVariableType::Type & GetValue(const TVariableType &rThisVariable)
Definition: geometry.h:627
iterator begin()
Definition: amatrix_interface.h:241
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
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
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
This class defines the node.
Definition: node.h:65
Variable class contains all information needed to store and retrive data from a data container.
Definition: variable.h:63
#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
Definition: exception.h:161
#define KRATOS_INFO(label)
Definition: logger.h:250
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
KratosZeroVector< double > ZeroVector
Definition: amatrix_interface.h:561
Internals::Matrix< double, AMatrix::dynamic, 1 > Vector
Definition: amatrix_interface.h:472
std::vector< PointTypePointer > PointVector
Definition: internal_variables_interpolation_process.h:53
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
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
x2
Definition: generate_frictional_mortar_condition.py:122
x1
Definition: generate_frictional_mortar_condition.py:121
R
Definition: isotropic_damage_automatic_differentiation.py:172
int k
Definition: quadrature.py:595
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
integer i
Definition: TensorModule.f:17