44 template<
class TMapperBackend>
59 template<
class TMapper>
66 rMapper.CreateMapperLocalSystems(rModelPartCommunicator, rLocalSystems);
69 template<
class TMapper>
72 return rMapper.GetMapperInterfaceInfo();
79 template<
class TSparseSpace,
class TDenseSpace,
class TMapperBackend>
116 : mrModelPartOrigin(rModelPartOrigin),
117 mrModelPartDestination(rModelPartDestination) {}
122 : mrModelPartOrigin(rModelPartOrigin),
123 mrModelPartDestination(rModelPartDestination),
124 mMapperSettings(JsonParameters)
126 mpInterfaceVectorContainerOrigin = Kratos::make_unique<InterfaceVectorContainerType>(rModelPartOrigin);
127 mpInterfaceVectorContainerDestination = Kratos::make_unique<InterfaceVectorContainerType>(rModelPartDestination);
139 double SearchRadius)
override
143 KRATOS_WARNING_IF(
"Mapper", mMapperSettings[
"use_initial_configuration"].GetBool()) <<
"Updating the interface while using the initial configuration for mapping!" << std::endl;
147 if (mpInverseMapper) {
148 mpInverseMapper->UpdateInterface(MappingOptions,
162 if (MappingOptions.
Is(MapperFlags::USE_TRANSPOSE)) {
163 GetInverseMapper().MapInternalTranspose(rDestinationVariable, rOriginVariable, MappingOptions);
165 MapInternal(rOriginVariable, rDestinationVariable, MappingOptions);
178 if (MappingOptions.
Is(MapperFlags::USE_TRANSPOSE)) {
179 GetInverseMapper().MapInternalTranspose(rDestinationVariable, rOriginVariable, MappingOptions);
181 MapInternal(rOriginVariable, rDestinationVariable, MappingOptions);
194 if (MappingOptions.
Is(MapperFlags::USE_TRANSPOSE)) {
195 MapInternalTranspose(rOriginVariable, rDestinationVariable, MappingOptions);
197 GetInverseMapper().Map(rDestinationVariable, rOriginVariable, MappingOptions);
210 if (MappingOptions.
Is(MapperFlags::USE_TRANSPOSE)) {
211 MapInternalTranspose(rOriginVariable, rDestinationVariable, MappingOptions);
213 GetInverseMapper().Map(rDestinationVariable, rOriginVariable, MappingOptions);
225 return *mpMappingMatrix;
233 std::string
Info()
const override
235 return "InterpolativeMapperBase";
241 rOStream <<
"InterpolativeMapperBase";
247 BaseType::PrintData(rOStream);
252 int mMeshesAreConforming =
false;
266 BuildMappingMatrix();
274 if (mMapperSettings.Has(
"search_radius")) {
275 KRATOS_WARNING(
"Mapper") <<
"DEPRECATION-WARNING: \"search_radius\" should be specified under \"search_settings\"!" << std::endl;
276 const double search_radius = mMapperSettings[
"search_radius"].GetDouble();
278 if (mMapperSettings.Has(
"search_settings")) {
279 KRATOS_ERROR_IF(mMapperSettings[
"search_settings"].
Has(
"search_radius")) <<
"\"search_radius\" specified twice, please only speficy it in \"search_settings\"!" << std::endl;
281 mMapperSettings.AddValue(
"search_settings",
Parameters());
284 mMapperSettings[
"search_settings"].AddEmptyValue(
"search_radius").SetDouble(search_radius);
285 mMapperSettings.RemoveValue(
"search_radius");
288 if (mMapperSettings.Has(
"search_iterations")) {
289 KRATOS_WARNING(
"Mapper") <<
"DEPRECATION-WARNING: \"search_iterations\" should be specified as \"max_num_search_iterations\" under \"search_settings\"!" << std::endl;
290 const int search_iterations = mMapperSettings[
"search_iterations"].GetInt();
292 if (mMapperSettings.Has(
"search_settings")) {
293 KRATOS_ERROR_IF(mMapperSettings[
"search_settings"].
Has(
"max_num_search_iterations")) <<
"\"search_iterations\" specified twice, please only speficy it in \"search_settings\" (as \"max_num_search_iterations\")!" << std::endl;
295 mMapperSettings.AddValue(
"search_settings",
Parameters());
298 mMapperSettings[
"search_settings"].AddEmptyValue(
"max_num_search_iterations").SetInt(search_iterations);
299 mMapperSettings.RemoveValue(
"search_iterations");
304 const Parameters mapper_default_settings(GetMapperDefaultSettings());
306 mMapperSettings.ValidateAndAssignDefaults(mapper_default_settings);
308 if (!mMapperSettings[
"search_settings"].
Has(
"echo_level")) {
310 mMapperSettings[
"search_settings"].AddEmptyValue(
"echo_level").SetInt(mMapperSettings[
"echo_level"].GetInt());
324 return mrModelPartOrigin;
333 return mrModelPartDestination;
347 MapperUniquePointerType mpInverseMapper =
nullptr;
351 InterfaceVectorContainerPointerType mpInterfaceVectorContainerOrigin;
352 InterfaceVectorContainerPointerType mpInterfaceVectorContainerDestination;
358 void BuildMappingMatrix()
363 mMapperLocalSystems);
365 const bool use_initial_configuration = mMapperSettings[
"use_initial_configuration"].
GetBool();
367 if (use_initial_configuration) {
377 auto p_interface_comm = Kratos::make_unique<InterfaceCommunicatorType>(
380 mMapperSettings[
"search_settings"]);
384 p_interface_comm->ExchangeInterfaceData(mrModelPartDestination.
GetCommunicator(),
385 p_ref_interface_info);
388 mMeshesAreConforming = p_interface_comm->AreMeshesConforming();
394 mpInterfaceVectorContainerOrigin->pGetVector(),
395 mpInterfaceVectorContainerDestination->pGetVector(),
396 mpInterfaceVectorContainerOrigin->GetModelPart(),
397 mpInterfaceVectorContainerDestination->GetModelPart(),
401 if (use_initial_configuration) {
409 mMapperLocalSystems.clear();
410 mMapperLocalSystems.shrink_to_fit();
421 void MapInternal(
const Variable<double>& rOriginVariable,
422 const Variable<double>& rDestinationVariable,
427 mpInterfaceVectorContainerOrigin->UpdateSystemVectorFromModelPart(rOriginVariable, MappingOptions);
431 mpInterfaceVectorContainerOrigin->GetVector(),
432 mpInterfaceVectorContainerDestination->GetVector());
434 mpInterfaceVectorContainerDestination->UpdateModelPartFromSystemVector(rDestinationVariable, MappingOptions);
439 void MapInternalTranspose(
const Variable<double>& rOriginVariable,
440 const Variable<double>& rDestinationVariable,
445 mpInterfaceVectorContainerDestination->UpdateSystemVectorFromModelPart(rDestinationVariable, MappingOptions);
449 mpInterfaceVectorContainerDestination->GetVector(),
450 mpInterfaceVectorContainerOrigin->GetVector());
452 mpInterfaceVectorContainerOrigin->UpdateModelPartFromSystemVector(rOriginVariable, MappingOptions);
457 void MapInternal(
const Variable<array_1d<double, 3>>& rOriginVariable,
458 const Variable<array_1d<double, 3>>& rDestinationVariable,
463 for (
const auto var_ext : {
"_X",
"_Y",
"_Z"}) {
467 MapInternal(var_origin, var_destination, MappingOptions);
473 void MapInternalTranspose(
const Variable<array_1d<double, 3>>& rOriginVariable,
474 const Variable<array_1d<double, 3>>& rDestinationVariable,
479 for (
const auto var_ext : {
"_X",
"_Y",
"_Z"}) {
483 MapInternalTranspose(var_origin, var_destination, MappingOptions);
495 if (r_data_comm.IsNullOnThisRank()) {
return;}
498 for (
const auto& rp_local_sys : mMapperLocalSystems) {
499 const auto pairing_status = rp_local_sys->GetPairingStatus();
502 std::stringstream warning_msg;
503 rp_local_sys->PairingInfo(warning_msg,
EchoLevel);
506 warning_msg <<
" is using an approximation";
508 warning_msg <<
" has not found a neighbor";
518 int approximations, no_neighbor;
519 std::tie(approximations, no_neighbor) = block_for_each<TwoReduction>(mMapperLocalSystems,
521 const auto pairing_status = rpLocalSys->GetPairingStatus();
523 return std::make_tuple(1,0);
525 return std::make_tuple(0,1);
527 return std::make_tuple(0,0);
529 approximations = r_data_comm.SumAll(approximations);
530 no_neighbor = r_data_comm.SumAll(no_neighbor);
533 KRATOS_WARNING_IF(
"Mapper", approximations > 0) << approximations <<
" / " << global_num_nodes <<
" (" << std::round((approximations/
static_cast<double>(global_num_nodes))*100) <<
" %) local systems are using an approximation" << std::endl;
535 KRATOS_WARNING_IF(
"Mapper", no_neighbor > 0) << no_neighbor <<
" / " << global_num_nodes <<
" (" << std::round((no_neighbor/
static_cast<double>(global_num_nodes))*100) <<
" %) local systems did not find a neighbor!" << std::endl;
538 if (mMapperSettings[
"print_pairing_status_to_file"].GetBool()) {
545 rpLocalSys->SetPairingStatusForPrinting();
550 KRATOS_INFO(
"Mapper") <<
"Printing file with PAIRING_STATUS: " <<
file_name <<
".vtk" << std::endl;
553 "file_format" : "binary",
554 "save_output_files_in_folder" : true,
555 "nodal_data_value_variables" : ["PAIRING_STATUS"]
558 vtk_params.AddValue("output_path", mMapperSettings[
"pairing_status_file_path"]);
563 rNode.GetData().Erase(PAIRING_STATUS);
573 virtual void CreateMapperLocalSystems(
579 virtual Parameters GetMapperDefaultSettings()
const = 0;
589 if (!mpInverseMapper) {
590 InitializeInverseMapper();
592 return *(
static_cast<InterpolativeMapperBase*
>(mpInverseMapper.get()));
597 void InitializeInverseMapper()
601 mpInverseMapper = this->Clone(mrModelPartDestination,
std::string Info() const override
Turn back information as a string.
Definition: periodic_interface_process.hpp:93
Definition of an accessor auxiliary class.
Definition: interpolative_mapper_base.h:46
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
InterfaceCommunicator::MapperInterfaceInfoUniquePointerType MapperInterfaceInfoUniquePointerType
Definition: interpolative_mapper_base.h:53
TMapperBackend::InterfaceCommunicatorType InterfaceCommunicatorType
Interface definitions.
Definition: interpolative_mapper_base.h:52
The Commmunicator class manages communication for distributed ModelPart instances.
Definition: communicator.h:67
virtual const DataCommunicator & GetDataCommunicator() const
Definition: communicator.cpp:340
SizeType GlobalNumberOfNodes() const
Definition: communicator.cpp:101
bool Is(Flags const &rOther) const
Definition: flags.h:274
Kratos::unique_ptr< MapperInterfaceInfo > MapperInterfaceInfoUniquePointerType
Definition: interface_communicator.h:53
Short class definition.
Definition: interface_vector_container.h:40
Definition: interpolative_mapper_base.h:81
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: interpolative_mapper_base.h:239
BaseType::TMappingMatrixType TMappingMatrixType
Definition: interpolative_mapper_base.h:104
std::size_t IndexType
Definition: interpolative_mapper_base.h:101
void InverseMap(const Variable< array_1d< double, 3 > > &rOriginVariable, const Variable< array_1d< double, 3 > > &rDestinationVariable, Kratos::Flags MappingOptions) override
Mapping from Destination to Origin, Vector Variable Same as InveseMap, but maps an array3-variable.
Definition: interpolative_mapper_base.h:203
ModelPart & GetDestinationModelPart()
This function destination model part.
Definition: interpolative_mapper_base.h:331
KRATOS_CLASS_POINTER_DEFINITION(InterpolativeMapperBase)
Pointer definition of InterpolativeMapperBase.
void Map(const Variable< array_1d< double, 3 > > &rOriginVariable, const Variable< array_1d< double, 3 > > &rDestinationVariable, Kratos::Flags MappingOptions) override
Mapping from Origin to Destination, Vector Variable Same as Map, but maps an array3-variable.
Definition: interpolative_mapper_base.h:171
TMapperBackend::InterfaceCommunicatorType InterfaceCommunicatorType
Definition: interpolative_mapper_base.h:91
ModelPart & GetOriginModelPart()
This function origin model part.
Definition: interpolative_mapper_base.h:322
void Map(const Variable< double > &rOriginVariable, const Variable< double > &rDestinationVariable, Kratos::Flags MappingOptions) override
Mapping from Origin to Destination, Scalar Variable Data is exchanged on the Interface,...
Definition: interpolative_mapper_base.h:155
void InverseMap(const Variable< double > &rOriginVariable, const Variable< double > &rDestinationVariable, Kratos::Flags MappingOptions) override
Mapping from Destination to Origin, Scalar Variable Data is exchanged on the Interface,...
Definition: interpolative_mapper_base.h:187
void Initialize()
Initializing the Mapper This has to be called in the constructor of the derived classes,...
Definition: interpolative_mapper_base.h:262
Kratos::unique_ptr< TMappingMatrixType > TMappingMatrixUniquePointerType
Definition: interpolative_mapper_base.h:105
BaseType::MapperUniquePointerType MapperUniquePointerType
Definition: interpolative_mapper_base.h:103
Kratos::unique_ptr< InterfaceVectorContainerType > InterfaceVectorContainerPointerType
Definition: interpolative_mapper_base.h:99
void ValidateInput()
Definition: interpolative_mapper_base.h:271
InterpolativeMapperBase(ModelPart &rModelPartOrigin, ModelPart &rModelPartDestination, Parameters JsonParameters)
Definition: interpolative_mapper_base.h:119
Kratos::unique_ptr< InterfaceCommunicator > InterfaceCommunicatorPointerType
Definition: interpolative_mapper_base.h:92
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: interpolative_mapper_base.h:245
Kratos::unique_ptr< MapperLocalSystem > MapperLocalSystemPointer
Definition: interpolative_mapper_base.h:95
Variable< double > ComponentVariableType
Definition: interpolative_mapper_base.h:107
TMappingMatrixUniquePointerType mpMappingMatrix
Definition: interpolative_mapper_base.h:254
std::string Info() const override
Turn back information as a string.
Definition: interpolative_mapper_base.h:233
InterpolativeMapperBase(ModelPart &rModelPartOrigin, ModelPart &rModelPartDestination)
Definition: interpolative_mapper_base.h:114
TMappingMatrixType & GetMappingMatrix() override
This method returns the mapping-matrix.
Definition: interpolative_mapper_base.h:223
~InterpolativeMapperBase() override=default
Destructor.
Mapper< TSparseSpace, TDenseSpace > BaseType
Definition: interpolative_mapper_base.h:89
InterfaceCommunicator::MapperInterfaceInfoUniquePointerType MapperInterfaceInfoUniquePointerType
Definition: interpolative_mapper_base.h:93
std::vector< MapperLocalSystemPointer > MapperLocalSystemPointerVector
Definition: interpolative_mapper_base.h:96
InterfaceVectorContainer< TSparseSpace, TDenseSpace > InterfaceVectorContainerType
Definition: interpolative_mapper_base.h:98
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
static const TComponentType & Get(const std::string &rName)
Retrieves a component with the specified name.
Definition: kratos_components.h:114
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
static void BuildMappingMatrix(Kratos::unique_ptr< typename TSparseSpace::MatrixType > &rpMappingMatrix, Kratos::unique_ptr< typename TSparseSpace::VectorType > &rpInterfaceVectorOrigin, Kratos::unique_ptr< typename TSparseSpace::VectorType > &rpInterfaceVectorDestination, const ModelPart &rModelPartOrigin, const ModelPart &rModelPartDestination, std::vector< Kratos::unique_ptr< MapperLocalSystem >> &rMapperLocalSystems, const int EchoLevel)
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
std::string FullName() const
This method returns the full name of the model part (including the parents model parts)
Definition: model_part.h:1850
Communicator & GetCommunicator()
Definition: model_part.h:1821
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
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
int GetInt() const
This method returns the integer contained in the current Parameter.
Definition: kratos_parameters.cpp:666
void AddValue(const std::string &rEntry, const Parameters &rOtherValue)
This method sets a non-existing parameter with a given parameter.
Definition: kratos_parameters.cpp:455
bool GetBool() const
This method returns the boolean contained in the current Parameter.
Definition: kratos_parameters.cpp:675
utility function to do a sum reduction
Definition: reduction_utilities.h:68
This class implements a set of auxiliar, already parallelized, methods to perform some common tasks r...
Definition: variable_utils.h:63
void SetNonHistoricalVariable(const TVarType &rVariable, const TType &Value, TContainerType &rContainer)
Sets the container value of any type of non historical variable.
Definition: variable_utils.h:790
void UpdateCurrentToInitialConfiguration(const ModelPart::NodesContainerType &rNodes)
This method updates the current nodal coordinates back to the initial coordinates.
Definition: variable_utils.cpp:245
VtkOutput A simple class that has functionality to write vtk output.
Definition: vtk_output.h:35
void PrintOutput(const std::string &rOutputFilename="")
Prints mrModelPart in VTK format together with the results.
Definition: vtk_output.cpp:167
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_ERROR_IF(conditional)
Definition: exception.h:162
#define KRATOS_INFO(label)
Definition: logger.h:250
#define KRATOS_WARNING_ALL_RANKS(label)
Definition: logger.h:275
#define KRATOS_WARNING_IF(label, conditional)
Definition: logger.h:266
#define KRATOS_WARNING(label)
Definition: logger.h:265
static int EchoLevel
Definition: co_sim_EMPIRE_API.h:42
void SaveCurrentConfiguration(ModelPart &rModelPart)
Definition: mapper_utilities.cpp:280
std::vector< MapperLocalSystemPointer > MapperLocalSystemPointerVector
Definition: mapper_utilities.h:46
void AssignInterfaceEquationIds(Communicator &rModelPartCommunicator)
Assigning INTERFACE_EQUATION_IDs to the nodes, with and without MPI This function assigns the INTERFA...
Definition: mapper_utilities.cpp:34
void RestoreCurrentConfiguration(ModelPart &rModelPart)
Definition: mapper_utilities.cpp:291
Kratos::unique_ptr< MapperInterfaceInfo > MapperInterfaceInfoUniquePointerType
Definition: mapper_utilities.h:40
void CheckInterfaceModelParts(const int CommRank)
Definition: mapper_utilities.cpp:120
bool Has(const std::string &ModelerName)
Checks if the modeler is registered.
Definition: modeler_factory.cpp:24
void TransposeMult(SparseSpaceType &dummy, SparseSpaceType::MatrixType &rA, SparseSpaceType::VectorType &rX, SparseSpaceType::VectorType &rY)
Definition: add_strategies_to_python.cpp:104
void Mult(TSpaceType &dummy, typename TSpaceType::MatrixType &rA, typename TSpaceType::VectorType &rX, typename TSpaceType::VectorType &rY)
Definition: add_strategies_to_python.cpp:98
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
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
echo_level
Definition: script.py:68
string file_name
Definition: sp_statistics.py:6
Definition: reduction_utilities.h:310