80 const unsigned int local_space_dimension = (p_geometry ==
nullptr) ? 0 : p_geometry->LocalSpaceDimension();
95 KRATOS_ERROR_IF(max_local_space_dimension_1 == 3 && max_local_space_dimension_2 == 3) <<
"Both model parts are 3D" << std::endl;
96 KRATOS_ERROR_IF(max_local_space_dimension_1 == 1 || max_local_space_dimension_2 == 1) <<
"One model part is 1D, not compatible" << std::endl;
97 KRATOS_ERROR_IF(max_local_space_dimension_1 == 0 || max_local_space_dimension_2 == 0) <<
"Impossible to determine local space dimension in at least one model part" << std::endl;
98 if (max_local_space_dimension_1 == 2) {
99 return rFirstModelPart;
100 }
else if (max_local_space_dimension_2 == 2) {
101 return rSecondModelPart;
103 KRATOS_ERROR <<
"Impossible to detect 2D model part" << std::endl;
105 return rFirstModelPart;
120 KRATOS_ERROR_IF(max_local_space_dimension_1 == 3 && max_local_space_dimension_2 == 3) <<
"Both model parts are 3D" << std::endl;
121 KRATOS_ERROR_IF(max_local_space_dimension_1 == 1 || max_local_space_dimension_2 == 1) <<
"One model part is 1D, not compatible" << std::endl;
122 KRATOS_ERROR_IF(max_local_space_dimension_1 == 0 || max_local_space_dimension_2 == 0) <<
"Impossible to determine local space dimension in at least one model part" << std::endl;
123 if (max_local_space_dimension_1 == 3) {
124 return rFirstModelPart;
125 }
else if (max_local_space_dimension_2 == 3) {
126 return rSecondModelPart;
128 KRATOS_ERROR <<
"Impossible to detect 3D model part" << std::endl;
130 return rFirstModelPart;
143 template<
class TSparseSpace,
class TDenseSpace,
class TMapperBackend>
191 ) :
BaseType(rModelPartOrigin, rModelPartDestination),
193 mr2DModelPart(rModelPartOrigin),
194 mr3DModelPart(rModelPartDestination)
203 ) :
BaseType(rModelPartOrigin, rModelPartDestination, JsonParameters),
213 mCopiedParameters = JsonParameters.
Clone();
219 mMetaMapperType = mCopiedParameters[
"base_mapper"].
GetString();
227 GetNormalAndReferencePlane();
291 mpBaseMapper->UpdateInterface(MappingOptions, SearchRadius);
323 return Kratos::make_unique<Projection3D2DMapper<TSparseSpace, TDenseSpace, TMapperBackend>>(rModelPartOrigin, rModelPartDestination, JsonParameters);
338 return mr2DModelPart;
347 return mr3DModelPart;
364 std::string
Info()
const override
366 return "Projection3D2DMapper";
372 rOStream <<
"Projection3D2DMapper";
395 std::string mMetaMapperType;
406 void CheckOriginIs2D()
412 mOriginIs2D = p_origin_model_part == p_2d_model_part ? true :
false;
420 void GetEntityMeshType()
426 if (r_2d_model_part.NumberOfConditions() > 0) {
428 }
else if (r_2d_model_part.NumberOfElements() > 0) {
440 void GetNormalAndReferencePlane()
450 const auto& r_communicator = r_2d_model_part.GetCommunicator();
451 const auto& r_data_communicator = r_communicator.GetDataCommunicator();
452 const int mpi_rank = r_data_communicator.Rank();
453 const int mpi_size = r_data_communicator.Size();
459 const int tag_send_normal = 1;
460 const int tag_send_point = 2;
463 if (partition_entity != mpi_rank) {
467 r_data_communicator.Recv(mNormalPlane, partition_entity, tag_send_normal);
468 r_data_communicator.Recv(mPointPlane.
Coordinates(), partition_entity, tag_send_point);
473 p_geometry->PointLocalCoordinates(aux_coords, mPointPlane);
474 noalias(mNormalPlane) = p_geometry->UnitNormal(aux_coords);
477 std::size_t check_normal;
478 const double numerical_limit = std::numeric_limits<double>::epsilon() * 1.0e4;
479 struct normal_check {
480 normal_check(array_1d<double, 3>& rNormal) : reference_normal(rNormal) {};
481 array_1d<double, 3> reference_normal;
485 check_normal = block_for_each<SumReduction<std::size_t>>(r_2d_model_part.Conditions(), normal_check(mNormalPlane), [&numerical_limit](
auto& r_cond, normal_check& nc) {
486 auto& r_geom = r_cond.GetGeometry();
487 r_geom.PointLocalCoordinates(nc.aux_coords, r_geom.Center());
488 const auto normal = r_geom.UnitNormal(nc.aux_coords);
489 return (
norm_2(normal - nc.reference_normal) > numerical_limit);
492 check_normal = block_for_each<SumReduction<std::size_t>>(r_2d_model_part.Elements(), normal_check(mNormalPlane), [&numerical_limit](
auto& r_elem, normal_check& nc) {
493 auto& r_geom = r_elem.GetGeometry();
494 r_geom.PointLocalCoordinates(nc.aux_coords, r_geom.Center());
495 const auto normal = r_geom.UnitNormal(nc.aux_coords);
496 return (
norm_2(normal - nc.reference_normal) > numerical_limit);
499 KRATOS_ERROR_IF_NOT(check_normal == 0) <<
"The 2D reference model part has not consistent normals. Please check that is properly aligned" << std::endl;
503 const auto& r_point_coordinates = mPointPlane.
Coordinates();
504 for (
int i_rank = 0; i_rank < mpi_size; ++i_rank) {
505 if (i_rank != partition_entity) {
506 r_data_communicator.Send(mNormalPlane, i_rank, tag_send_normal);
507 r_data_communicator.Send(r_point_coordinates, i_rank, tag_send_point);
519 void CreateBaseMapper()
528 if (mMetaMapperType ==
"nearest_neighbor") {
529 if (mCopiedParameters.
Has(
"interpolation_type")) mCopiedParameters.
RemoveValue(
"interpolation_type");
530 if (mCopiedParameters.
Has(
"local_coord_tolerance")) mCopiedParameters.
RemoveValue(
"local_coord_tolerance");
531 mpBaseMapper = Kratos::make_unique<NearestNeighborMapperType>(r_origin_model_part, r_destination_model_part, mCopiedParameters);
532 }
else if (mMetaMapperType ==
"nearest_element") {
533 if (mCopiedParameters.
Has(
"interpolation_type")) mCopiedParameters.
RemoveValue(
"interpolation_type");
534 mpBaseMapper = Kratos::make_unique<NearestElementMapperType>(r_origin_model_part, r_destination_model_part, mCopiedParameters);
535 }
else if (mMetaMapperType ==
"barycentric") {
536 mpBaseMapper = Kratos::make_unique<BarycentricMapperType>(r_origin_model_part, r_destination_model_part, mCopiedParameters);
538 KRATOS_ERROR <<
"Mapper " << mCopiedParameters[
"base_mapper"].
GetString() <<
" is not available as base mapper for projection" << std::endl;
548 void MoveModelParts()
559 struct ProjectionVariables
561 ProjectionVariables(array_1d<double, 3>& rNormal, Point& rPoint) : reference_normal(rNormal), reference_point(rPoint) {};
562 array_1d<double, 3> reference_normal;
563 Point reference_point;
565 array_1d<double, 3> projected_point_coordinates;
569 block_for_each(r_3d_model_part.Nodes(), ProjectionVariables(mNormalPlane, mPointPlane), [&](
auto& r_node, ProjectionVariables&
p) {
571 noalias(r_node.Coordinates()) =
p.projected_point_coordinates;
580 void UnMoveModelParts()
594 void CreateMapperLocalSystems(
595 const Communicator& rModelPartCommunicator,
608 Parameters GetMapperDefaultSettings()
const override
610 return Parameters( R
"({
611 "search_settings" : {},
613 "interpolation_type" : "unspecified",
614 "local_coord_tolerance" : 0.25,
615 "use_initial_configuration" : false,
616 "print_pairing_status_to_file" : false,
617 "pairing_status_file_path" : "",
618 "base_mapper" : "nearest_neighbor"
static MapperInterfaceInfoUniquePointerType GetMapperInterfaceInfo(const TMapper &rMapper)
Definition: interpolative_mapper_base.h:70
static void CreateMapperLocalSystems(TMapper &rMapper, const Communicator &rModelPartCommunicator, std::vector< Kratos::unique_ptr< MapperLocalSystem >> &rLocalSystems)
Definition: interpolative_mapper_base.h:60
Barycentric Mapper.
Definition: barycentric_mapper.h:111
virtual const DataCommunicator & GetDataCommunicator() const
Definition: communicator.cpp:340
virtual int Rank() const
Get the parallel rank for this DataCommunicator.
Definition: data_communicator.h:587
static TPointClass3 FastProject(const TPointClass1 &rPointOrigin, const TPointClass2 &rPointToProject, const array_1d< double, 3 > &rNormal, double &rDistance)
Project a point over a plane (avoiding some steps)
Definition: geometrical_projection_utilities.h:135
PointType::CoordinatesArrayType CoordinatesArrayType
Definition: geometry.h:147
Kratos::unique_ptr< MapperInterfaceInfo > MapperInterfaceInfoUniquePointerType
Definition: interface_communicator.h:53
Definition: interpolative_mapper_base.h:81
ModelPart & GetDestinationModelPart()
This function destination model part.
Definition: interpolative_mapper_base.h:331
ModelPart & GetOriginModelPart()
This function origin model part.
Definition: interpolative_mapper_base.h:322
void Initialize()
Initializing the Mapper This has to be called in the constructor of the derived classes,...
Definition: interpolative_mapper_base.h:262
void ValidateInput()
Definition: interpolative_mapper_base.h:271
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: interpolative_mapper_base.h:245
TMappingMatrixUniquePointerType mpMappingMatrix
Definition: interpolative_mapper_base.h:254
void UpdateInterface(Kratos::Flags MappingOptions, double SearchRadius) override
Updates the mapping-system after the geometry/mesh has changed After changes in the topology (e....
Definition: interpolative_mapper_base.h:137
Base Class for all Mappers.
Definition: mapper.h:43
TSparseSpace::MatrixType TMappingMatrixType
Definition: mapper.h:55
Kratos::unique_ptr< Mapper > MapperUniquePointerType
Definition: mapper.h:53
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
ConditionIterator ConditionsBegin(IndexType ThisIndex=0)
Definition: model_part.h:1361
Communicator & GetCommunicator()
Definition: model_part.h:1821
SizeType NumberOfElements(IndexType ThisIndex=0) const
Definition: model_part.h:1027
SizeType NumberOfConditions(IndexType ThisIndex=0) const
Definition: model_part.h:1218
Interpolative Mapper.
Definition: nearest_element_mapper.h:186
Nearest Neighbor Mapper.
Definition: nearest_neighbor_mapper.h:139
This class defines the node.
Definition: node.h:65
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
bool RemoveValue(const std::string &rEntry)
This method removes an entry of the Parameters given a certain key.
Definition: kratos_parameters.cpp:482
Parameters Clone() const
Generates a clone of the current document.
Definition: kratos_parameters.cpp:397
std::string GetString() const
This method returns the string contained in the current Parameter.
Definition: kratos_parameters.cpp:684
bool Has(const std::string &rEntry) const
This method checks if the Parameter contains a certain entry.
Definition: kratos_parameters.cpp:520
Point class.
Definition: point.h:59
CoordinatesArrayType const & Coordinates() const
Definition: point.h:215
This mapper simplifies the mapping between two model parts thanks to the projection over a reference ...
Definition: projection_3D_2D_mapper.h:146
KRATOS_CLASS_POINTER_DEFINITION(Projection3D2DMapper)
Pointer definition of Projection3D2DMapper.
InterfaceCommunicator::MapperInterfaceInfoUniquePointerType MapperInterfaceInfoUniquePointerType
Definition: projection_3D_2D_mapper.h:162
Projection3D2DMapper(ModelPart &rModelPartOrigin, ModelPart &rModelPartDestination, Parameters JsonParameters)
Definition: projection_3D_2D_mapper.h:199
ModelPart & Get2DModelPart()
This method returns the 2D model part.
Definition: projection_3D_2D_mapper.h:336
InterpolativeMapperBase< TSparseSpace, TDenseSpace, TMapperBackend > BaseType
BaseType definitions.
Definition: projection_3D_2D_mapper.h:155
ModelPart & Get3DModelPart()
This method returns the 3D model part.
Definition: projection_3D_2D_mapper.h:345
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: projection_3D_2D_mapper.h:376
~Projection3D2DMapper() override=default
Destructor.
NearestNeighborMapper< TSparseSpace, TDenseSpace, TMapperBackend > NearestNeighborMapperType
Other mappers definition.
Definition: projection_3D_2D_mapper.h:165
std::string Info() const override
Turn back information as a string.
Definition: projection_3D_2D_mapper.h:364
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: projection_3D_2D_mapper.h:370
BaseType::MapperUniquePointerType MapperUniquePointerType
Definition: projection_3D_2D_mapper.h:158
BaseType::TMappingMatrixType TMappingMatrixType
Definition: projection_3D_2D_mapper.h:157
Kratos::unique_ptr< BaseType > BaseMapperUniquePointerType
Definition: projection_3D_2D_mapper.h:156
BarycentricMapper< TSparseSpace, TDenseSpace, TMapperBackend > BarycentricMapperType
Definition: projection_3D_2D_mapper.h:167
void UpdateInterface(Kratos::Flags MappingOptions, double SearchRadius) override
Updates the mapping-system after the geometry/mesh has changed After changes in the topology (e....
Definition: projection_3D_2D_mapper.h:274
TMapperBackend::InterfaceCommunicatorType InterfaceCommunicatorType
Interface definitions.
Definition: projection_3D_2D_mapper.h:161
EntityTypeMesh
Entity type mesh considered.
Definition: projection_3D_2D_mapper.h:177
Projection3D2DMapper(ModelPart &rModelPartOrigin, ModelPart &rModelPartDestination)
Definition: projection_3D_2D_mapper.h:188
MapperUniquePointerType Clone(ModelPart &rModelPartOrigin, ModelPart &rModelPartDestination, Parameters JsonParameters) const override
Cloning the Mapper returns a clone of the current Mapper pure virtual, has to be implemented in every...
Definition: projection_3D_2D_mapper.h:315
NearestElementMapper< TSparseSpace, TDenseSpace, TMapperBackend > NearestElementMapperType
Definition: projection_3D_2D_mapper.h:166
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_ERROR
Definition: exception.h:161
#define KRATOS_ERROR_IF_NOT(conditional)
Definition: exception.h:163
#define KRATOS_ERROR_IF(conditional)
Definition: exception.h:162
void SaveCurrentConfiguration(ModelPart &rModelPart)
Definition: mapper_utilities.cpp:280
void RestoreCurrentConfiguration(ModelPart &rModelPart)
Definition: mapper_utilities.cpp:291
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
GeometryType::Pointer GetGeometryFromModelPart(const ModelPart &rModelPart)
This method retrieves the first geometry from a model part.
Definition: projection_3D_2D_mapper.h:53
TExpressionType::data_type norm_2(AMatrix::MatrixExpression< TExpressionType, TCategory > const &TheExpression)
Definition: amatrix_interface.h:625
ModelPart & Determine2DModelPart(ModelPart &rFirstModelPart, ModelPart &rSecondModelPart)
This method determines the 2D model part.
Definition: projection_3D_2D_mapper.h:90
void block_for_each(TIterator itBegin, TIterator itEnd, TFunction &&rFunction)
Execute a functor on all items of a range in parallel.
Definition: parallel_utilities.h:299
std::unique_ptr< T > unique_ptr
Definition: smart_pointers.h:33
ModelPart & Determine3DModelPart(ModelPart &rFirstModelPart, ModelPart &rSecondModelPart)
This method determines the 3D model part.
Definition: projection_3D_2D_mapper.h:115
Geometry< Node > GeometryType
The definition of the geometry.
Definition: mortar_classes.h:37
T & noalias(T &TheMatrix)
Definition: amatrix_interface.h:484
int DeterminePartitionWithEntities(const ModelPart &rModelPart)
This method determines the partition where the model part has at least one entity.
Definition: projection_3D_2D_mapper.h:63
unsigned int DetermineModelPartMaximumLocalDimension(ModelPart &rModelPart)
This method determines maximum local space dimension of a ModelPart.
Definition: projection_3D_2D_mapper.h:76
is_distributed
Definition: convergence_accelerator_factory.py:10
p
Definition: sensitivityMatrix.py:52