16 #include <unordered_map>
70 template< const SizeType TDim, const SizeType TNumNodes,
class TVarType, const SizeType TNumNodesMaster = TNumNodes>
130 using IntMap = std::unordered_map<IndexType, IndexType>;
172 LinearSolverType::Pointer pThisLinearSolver = nullptr
186 TVarType& rThisVariable,
188 LinearSolverType::Pointer pThisLinearSolver = nullptr
203 TVarType& rOriginVariable,
204 TVarType& rDestinationVariable,
206 LinearSolverType::Pointer pThisLinearSolver = nullptr
244 void Execute()
override;
249 void ExecuteInitializeSolutionStep()
override;
258 TVarType& rOriginVariable,
259 TVarType& rDestinationVariable,
264 mpOriginVariable = &rOriginVariable;
265 mpDestinationVariable = &rDestinationVariable;
274 const Parameters GetDefaultParameters()
const override;
289 std::string
Info()
const override
291 return "SimpleMortarMapperProcess";
297 rOStream <<
"SimpleMortarMapperProcess";
319 const TVarType* mpOriginVariable;
320 const TVarType* mpDestinationVariable;
322 double mMappingCoefficient = 1.0;
325 unsigned int mEchoLevel = 0;
328 LinearSolverType::Pointer mpThisLinearSolver;
341 void CheckAndPerformSearch();
346 void ResetNodalArea();
351 double GetReferenceArea();
364 void AssemblyMortarOperators(
369 MortarKinematicVariablesType& rThisKinematicVariables,
370 MortarOperatorType& rThisMortarOperators,
383 static inline BoundedMatrixType CalculateAe(
385 MortarKinematicVariablesType& rThisKinematicVariables,
395 static inline BoundedMatrixType InvertDiagonalMatrix(
const BoundedMatrixType& rInputMatrix);
402 static inline void InvertDiagonalMatrix(
403 const BoundedMatrixType& rInputMatrix,
404 BoundedMatrixType& rInvertedMatrix
411 void LumpMatrix(BoundedMatrixType& rInputMatrix);
417 void GetSystemSize(
SizeType& rSizeSystem);
425 void CreateSlaveConectivityDatabase(
427 IntMap& rConectivityDatabase,
428 IntMap& rInverseConectivityDatabase
442 bool CheckWholeVector(std::vector<bool>& rVectorToCheck);
451 void ComputeResidualMatrix(
455 const MortarOperatorType& rThisMortarOperators
468 void AssembleRHSAndLHS(
470 std::vector<VectorType>& rb,
472 const Matrix& rResidualMatrix,
474 IntMap& rInverseConectivityDatabase,
475 const MortarOperatorType& rThisMortarOperators
487 std::vector<VectorType>& rb,
489 const Matrix& rResidualMatrix,
491 IntMap& rInverseConectivityDatabase
497 void ExecuteExplicitMapping();
502 void ExecuteImplicitMapping();
518 template<
class TClassType,
bool TImplicit = false>
519 void PerformMortarOperations(
521 std::vector<VectorType>& rb,
522 IntMap& rInverseConectivityDatabase,
523 typename TClassType::Pointer pIndexesPairs,
525 ExactMortarIntegrationUtilityType& rIntegrationUtility,
526 MortarKinematicVariablesType& rThisKineticVariables,
527 MortarOperatorType& rThisMortarOperators,
538 std::vector<IndexType> indexes_to_remove, geometrical_objects_to_erase;
541 const double discontinous_interface_factor = mOptions.
Is(DISCONTINOUS_INTERFACE) ? mThisParameters[
"discontinous_interface_factor"].
GetDouble() : 1.0;
547 auto& r_slave_geometry = rGeometricalObject.
GetGeometry();
552 const auto& r_const_origin_model_part = mOriginModelPart;
553 const auto& r_const_destination_model_part = mDestinationModelPart;
555 for (
auto it_pair = pIndexesPairs->begin(); it_pair != pIndexesPairs->end(); ++it_pair ) {
556 const IndexType master_id = pIndexesPairs->GetId(it_pair);
558 const auto& r_master_geometry = mOptions.
Is(ORIGIN_SKIN_IS_CONDITION_BASED) ? r_const_origin_model_part.GetCondition(master_id).GetGeometry() : r_const_origin_model_part.GetElement(master_id).GetGeometry();
559 r_master_geometry.PointLocalCoordinates(aux_coords, r_master_geometry.Center());
565 std::vector<array_1d<PointType,TDim>> geometrical_objects_points_slave;
566 const bool is_inside = rIntegrationUtility.GetExactIntegration(r_slave_geometry, slave_normal, r_master_geometry, master_normal, geometrical_objects_points_slave);
570 rThisKineticVariables.Initialize();
573 rThisMortarOperators.Initialize();
575 const BoundedMatrixType Ae = CalculateAe(r_slave_geometry, rThisKineticVariables, geometrical_objects_points_slave, r_integration_method);
577 AssemblyMortarOperators( geometrical_objects_points_slave, r_slave_geometry, r_master_geometry,master_normal, rThisKineticVariables, rThisMortarOperators, r_integration_method, Ae);
580 const IndexType size_to_compute = MortarUtilities::SizeToCompute<TDim, TVarType>();
581 Matrix residual_matrix(TNumNodes, size_to_compute);
582 ComputeResidualMatrix(residual_matrix, r_slave_geometry, r_master_geometry, rThisMortarOperators);
585 MortarUtilities::AddValue<TVarType, MortarUtilitiesSettings::SaveAsNonHistoricalVariable>(r_slave_geometry, r_aux_variable, residual_matrix);
589 if (mEchoLevel > 1) {
590 BoundedMatrixType aux_copy_D = rThisMortarOperators.DOperator;
591 LumpMatrix(aux_copy_D);
592 const BoundedMatrixType aux_diff = aux_copy_D - rThisMortarOperators.DOperator;
594 if (norm_diff > 1.0e-4)
595 KRATOS_WARNING(
"D OPERATOR") <<
" THE MORTAR OPERATOR D IS NOT DIAGONAL" << std::endl;
596 if (mEchoLevel == 3) {
602 if (Iteration == 0) {
603 if constexpr (TImplicit) {
605 const SizeType variable_size = MortarUtilities::SizeToCompute<TDim, TVarType>();
606 AssembleRHSAndLHS(rA, rb, variable_size, residual_matrix, r_slave_geometry, rInverseConectivityDatabase, rThisMortarOperators);
608 for (
IndexType i_node = 0; i_node < TNumNodes; ++i_node) {
609 double& r_nodal_area = r_slave_geometry[i_node].GetValue(NODAL_AREA);
610 AtomicAdd(r_nodal_area, rThisMortarOperators.DOperator(i_node, i_node));
613 if (mOptions.
Is(DISCONTINOUS_INTERFACE)) {
614 const double element_length = r_slave_geometry.Length();
617 for (
IndexType i_node = 0; i_node < TNumNodes; ++i_node) {
618 const double nodal_area_contribution = rThisMortarOperators.DOperator(i_node, i_node);
621 const auto& r_slave_node = r_slave_geometry[i_node];
624 const auto& r_index_masp_master = mOptions.
Is(ORIGIN_SKIN_IS_CONDITION_BASED) ? r_const_origin_model_part.GetCondition(master_id).GetValue(INDEX_SET) : r_const_origin_model_part.GetElement(master_id).GetValue(INDEX_SET);
625 for (
auto it_master_pair = r_index_masp_master->begin(); it_master_pair != r_index_masp_master->end(); ++it_master_pair ) {
627 const IndexType auxiliar_slave_id = r_index_masp_master->GetId(it_master_pair);
628 if (rGeometricalObject.
Id() != auxiliar_slave_id) {
629 GeometryType& r_auxiliar_slave_geometry =
const_cast<GeometryType&
>(mOptions.
Is(DESTINATION_SKIN_IS_CONDITION_BASED) ? r_const_destination_model_part.GetCondition(auxiliar_slave_id).GetGeometry() : r_const_destination_model_part.GetElement(auxiliar_slave_id).GetGeometry());
631 for (
IndexType j_node = 0; j_node < TNumNodes; ++j_node) {
633 auto& r_auxiliary_slave_node = r_auxiliar_slave_geometry[j_node];
634 const double distance = r_auxiliary_slave_node.Distance(r_slave_node);
635 const double contribution_coeff = 1.0/std::pow((1.0 + distance/(discontinous_interface_factor * element_length)), 2);
637 double& r_nodal_area = r_auxiliary_slave_node.GetValue(NODAL_AREA);
638 AtomicAdd(r_nodal_area, contribution_coeff * nodal_area_contribution);
645 }
else if constexpr (TImplicit) {
646 const SizeType variable_size = MortarUtilities::SizeToCompute<TDim, TVarType>();
647 AssembleRHS(rb, variable_size, residual_matrix, r_slave_geometry, rInverseConectivityDatabase);
650 indexes_to_remove.push_back(master_id);
651 const IndexType other_id = pIndexesPairs->GetOtherId(it_pair);
652 if (std::is_same<TClassType, IndexMap>::value && other_id != 0) {
653 geometrical_objects_to_erase.push_back(other_id);
659 for (
IndexType i_to_remove = 0; i_to_remove < indexes_to_remove.size(); ++i_to_remove) {
660 if (mOptions.
Is(ORIGIN_SKIN_IS_CONDITION_BASED)) {
661 for (
auto&
id : geometrical_objects_to_erase ) {
663 r_cond.
Set(TO_ERASE,
true);
666 for (
auto&
id : geometrical_objects_to_erase ) {
667 auto& r_elem = r_root_model_part.
GetElement(
id);
668 r_elem.
Set(TO_ERASE,
true);
671 pIndexesPairs->RemoveId(indexes_to_remove[i_to_remove]);
682 template<
class TClassType>
684 typename TClassType::Pointer pIndexesPairs,
685 GeometricalObject& rGeometricalObject,
686 ExactMortarIntegrationUtilityType& rIntegrationUtility
693 std::vector<IndexType> indexes_to_remove, geometrical_objects_to_erase;
699 auto& r_slave_geometry = rGeometricalObject.GetGeometry();
700 r_slave_geometry.PointLocalCoordinates(aux_coords, r_slave_geometry.Center());
701 const array_1d<double, 3> slave_normal = r_slave_geometry.UnitNormal(aux_coords);
704 const auto& r_const_origin_model_part = mOriginModelPart;
706 for (
auto it_pair = pIndexesPairs->begin(); it_pair != pIndexesPairs->end(); ++it_pair ) {
707 const IndexType master_id = pIndexesPairs->GetId(it_pair);
709 const auto& r_master_geometry = mOptions.
Is(ORIGIN_SKIN_IS_CONDITION_BASED) ? r_const_origin_model_part.GetCondition(master_id).GetGeometry() : r_const_origin_model_part.GetElement(master_id).GetGeometry();
710 r_master_geometry.PointLocalCoordinates(aux_coords, r_master_geometry.Center());
711 const array_1d<double, 3> master_normal = r_master_geometry.UnitNormal(aux_coords);
714 std::vector<array_1d<PointType,TDim>> geometrical_objects_points_slave;
715 const bool is_inside = rIntegrationUtility.GetExactIntegration(r_slave_geometry, slave_normal, r_master_geometry, master_normal, geometrical_objects_points_slave);
718 indexes_to_remove.push_back(master_id);
719 const IndexType other_id = pIndexesPairs->GetOtherId(it_pair);
720 if (std::is_same<TClassType, IndexMap>::value && other_id != 0) {
721 geometrical_objects_to_erase.push_back(other_id);
727 for (
IndexType i_to_remove = 0; i_to_remove < indexes_to_remove.size(); ++i_to_remove) {
728 if (mOptions.
Is(ORIGIN_SKIN_IS_CONDITION_BASED)) {
729 for (
auto&
id : geometrical_objects_to_erase ) {
730 auto& r_cond = r_root_model_part.GetCondition(
id);
731 r_cond.Set(TO_ERASE,
true);
734 for (
auto&
id : geometrical_objects_to_erase ) {
735 auto& r_elem = r_root_model_part.GetElement(
id);
736 r_elem.Set(TO_ERASE,
true);
739 pIndexesPairs->RemoveId(indexes_to_remove[i_to_remove]);
750 template<
class TEntity>
752 TEntity& rGeometricalObject,
753 KDTreeType& rTreePoints,
755 const double SearchFactor
761 GeometryType& r_geometry = rGeometricalObject.GetGeometry();
762 const Point center = r_geometry.Center();
765 for(
IndexType i_node = 0; i_node < r_geometry.PointsNumber(); ++i_node) {
766 const array_1d<double, 3> aux_vector = center.Coordinates() - r_geometry[i_node].Coordinates();
767 const double aux_value =
inner_prod(aux_vector, aux_vector);
771 const double search_radius = SearchFactor * std::sqrt(
radius);
773 const SizeType number_points_found = rTreePoints.SearchInRadius(center, search_radius, points_found.begin(), AllocationSize);
775 if (number_points_found > 0) {
777 if (!rGeometricalObject.Has(INDEX_SET))
778 rGeometricalObject.SetValue(INDEX_SET, Kratos::make_shared<IndexSet>());
781 IndexSet::Pointer indexes_set = rGeometricalObject.GetValue(INDEX_SET);
783 for (
IndexType i_point = 0; i_point < number_points_found; ++i_point ) {
784 auto p_geometrical_object_master = points_found[i_point]->pGetObject();
785 indexes_set->AddId(p_geometrical_object_master->Id());
793 void CreateInverseDatabase();
800 void UpdateInterface();
819 SimpleMortarMapperProcess&
operator=(SimpleMortarMapperProcess
const& rOther) =
delete;
PeriodicInterfaceProcess & operator=(const PeriodicInterfaceProcess &)=delete
Short class definition.
Definition: bucket.h:57
This is the definition dual lagrange multiplier operators according to the work of Alexander Popp: ht...
Definition: mortar_classes.h:1513
std::size_t IndexType
Definition: flags.h:74
void Set(const Flags ThisFlag)
Definition: flags.cpp:33
bool Is(Flags const &rOther) const
Definition: flags.h:274
This defines the geometrical object, base definition of the element and condition entities.
Definition: geometrical_object.h:58
GeometryType & GetGeometry()
Returns the reference of the geometry.
Definition: geometrical_object.h:158
IntegrationMethod
Definition: geometry_data.h:76
Geometry base class.
Definition: geometry.h:71
virtual CoordinatesArrayType & PointLocalCoordinates(CoordinatesArrayType &rResult, const CoordinatesArrayType &rPoint) const
Returns the local coordinates of a given arbitrary point.
Definition: geometry.h:1854
PointType::CoordinatesArrayType CoordinatesArrayType
Definition: geometry.h:147
IndexType Id() const
Definition: indexed_object.h:107
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
An two node 2D line geometry with linear shape functions.
Definition: line_2d_2.h:65
Base class for all the linear solvers in Kratos.
Definition: linear_solver.h:65
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
ConditionType & GetCondition(IndexType ConditionId, IndexType ThisIndex=0)
Definition: model_part.h:1313
ElementType & GetElement(IndexType ElementId, IndexType ThisIndex=0)
Definition: model_part.h:1121
ModelPart & GetRootModelPart()
Definition: model_part.cpp:510
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
double GetDouble() const
This method returns the double contained in the current Parameter.
Definition: kratos_parameters.cpp:657
Point class.
Definition: point.h:59
Custom Point container to be used by the search.
Definition: point_object.h:56
The base class for all processes in Kratos.
Definition: process.h:49
This is basic mapper of values between domains using mortar formulation.
Definition: simple_mortar_mapper_process.h:73
typename SparseSpaceType::VectorType VectorType
Type definition for vector.
Definition: simple_mortar_mapper_process.h:121
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: simple_mortar_mapper_process.h:295
KRATOS_DEFINE_LOCAL_FLAG(CONSIDER_TESELLATION)
If the entities to take into account on the destination model part are the conditions,...
typename std::conditional< TDim==2, LineType, TriangleType >::type DecompositionType
Type definition for DecompositionType based on TDim value.
Definition: simple_mortar_mapper_process.h:109
KRATOS_DEFINE_LOCAL_FLAG(ORIGIN_IS_HISTORICAL)
If interface is discontinous.
KRATOS_DEFINE_LOCAL_FLAG(ORIGIN_SKIN_IS_CONDITION_BASED)
If the destination variables is historical.
KRATOS_DEFINE_LOCAL_FLAG(DESTINATION_IS_HISTORICAL)
If the origin variables is historical.
void operator()()
Definition: simple_mortar_mapper_process.h:232
typename SparseSpaceType::MatrixType MatrixType
Type definition for matrix.
Definition: simple_mortar_mapper_process.h:118
std::vector< PointTypePointer > PointVector
Definition: simple_mortar_mapper_process.h:138
KRATOS_DEFINE_LOCAL_FLAG(AVERAGE_NORMAL)
KRATOS_CLASS_POINTER_DEFINITION(SimpleMortarMapperProcess)
If we consider the tesellation in the mortar integration.
typename PointMapperType::Pointer PointTypePointer
Definition: simple_mortar_mapper_process.h:137
void Map(TVarType &rOriginVariable, TVarType &rDestinationVariable, const Flags Flag=Flags())
This method is a direct map between the origin and destination modelpart with custom variables.
Definition: simple_mortar_mapper_process.h:257
KRATOS_DEFINE_LOCAL_FLAG(DESTINATION_SKIN_IS_CONDITION_BASED)
If the entities to take into account on the origin model part are the conditions, otherwise we will t...
std::string Info() const override
Turn back information as a string.
Definition: simple_mortar_mapper_process.h:289
std::unordered_map< IndexType, IndexType > IntMap
A map for integers.
Definition: simple_mortar_mapper_process.h:130
~SimpleMortarMapperProcess() override=default
Destructor.
KRATOS_DEFINE_LOCAL_FLAG(DISCONTINOUS_INTERFACE)
If using average normal.
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: simple_mortar_mapper_process.h:301
A generic tree data structure for spatial partitioning.
Definition: tree.h:190
A three node 3D triangle geometry with linear shape functions.
Definition: triangle_3d_3.h:77
A class template for handling data types, matrices, and vectors in a Ublas space.
Definition: ublas_space.h:121
TMatrixType MatrixType
The matrix type considered.
Definition: ublas_space.h:133
TVectorType VectorType
The vector type considered.
Definition: ublas_space.h:136
Short class definition.
Definition: array_1d.h:61
#define KRATOS_WATCH(variable)
Definition: define.h:806
std::size_t IndexType
The definition of the index type.
Definition: key_hash.h:35
#define KRATOS_WARNING(label)
Definition: logger.h:265
Kratos::ModelPart ModelPart
Definition: kratos_wrapper.h:31
std::unordered_map< IndexType, IndexType > IntMap
A map for integers.
Definition: mortar_utilities.h:91
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
AMatrix::IdentityMatrix< double > IdentityMatrix
Definition: amatrix_interface.h:564
void AtomicAdd(TDataType &target, const TDataType &value)
Definition: atomic_utilities.h:55
TExpression1Type::data_type inner_prod(AMatrix::MatrixExpression< TExpression1Type, TCategory1 > const &First, AMatrix::MatrixExpression< TExpression2Type, TCategory2 > const &Second)
Definition: amatrix_interface.h:592
Geometry< Node > GeometryType
The definition of the geometry.
Definition: mortar_classes.h:37
std::size_t SizeType
The definition of the size type.
Definition: mortar_classes.h:43
std::vector< PointTypePointer > PointVector
Definition: internal_variables_interpolation_process.h:53
TExpressionType::data_type norm_frobenius(AMatrix::MatrixExpression< TExpressionType, TCategory > const &TheExpression)
Definition: amatrix_interface.h:687
type
Definition: generate_gid_list_file.py:35
float radius
Definition: mesh_to_mdpa_converter.py:18
Auxiliar struct for mapping.
Definition: simple_mortar_mapper_process.h:151
ExactMortarIntegrationUtilityType integration_utility
Definition: simple_mortar_mapper_process.h:154
MortarOperatorType this_mortar_operators
Definition: simple_mortar_mapper_process.h:153
MortarKinematicVariablesType this_kinematic_variables
Definition: simple_mortar_mapper_process.h:152