KratosMultiphysics
KRATOS Multiphysics (Kratos) is a framework for building parallel, multi-disciplinary simulation software, aiming at modularity, extensibility, and high performance. Kratos is written in C++, and counts with an extensive Python interface.
residualbased_block_builder_and_solver_with_constraints_for_chimera.h
Go to the documentation of this file.
1 // | / |
2 // ' / __| _` | __| _ \ __|
3 // . \ | ( | | ( |\__ `
4 // _|\_\_| \__,_|\__|\___/ ____/
5 // Multi-Physics
6 //
7 //
8 // License: BSD License
9 // Kratos default license: kratos/license.txt
10 //
11 // Authors: Aditya Ghantasala, https://github.com/adityaghantasala
12 // Navaneeth K Narayanan
13 // Rishith Ellath Meethal
14 //
15 #if !defined(RESIDUAL_BASED_BLOCK_BUILDER_AND_SOLVER_WITH_CONSTRAINTS_FOR_CHIMERA)
16 #define RESIDUAL_BASED_BLOCK_BUILDER_AND_SOLVER_WITH_CONSTRAINTS_FOR_CHIMERA
17 
18 /* System includes */
19 #include <unordered_set>
20 #include <unordered_map>
21 
22 /* External includes */
23 
24 /* Project includes */
27 
28 namespace Kratos
29 {
30 
33 
37 
41 
45 
49 
68 template <class TSparseSpace,
69  class TDenseSpace,
70  class TLinearSolver>
72  : public ResidualBasedBlockBuilderAndSolver<TSparseSpace, TDenseSpace, TLinearSolver>
73 {
74 public:
77 
80 
81  // The size_t types
82  typedef typename BaseType::IndexType IndexType;
83 
88 
89 
91 
95 
99  typename TLinearSolver::Pointer pNewLinearSystemSolver)
100  : ResidualBasedBlockBuilderAndSolver<TSparseSpace, TDenseSpace, TLinearSolver>(pNewLinearSystemSolver)
101  {
102  }
103 
107 
111 
115 
116 
120  void Clear() override
121  {
122  BaseType::Clear();
123  mL.resize(0,0,false);
124  }
125 
129 
133 
137 
139  std::string Info() const override
140  {
141  return "ResidualBasedBlockBuilderAndSolverWithConstraintsForChimera";
142  }
143 
147 
149 
150 protected:
160 
164 
166  {
168  if (rModelPart.MasterSlaveConstraints().size() > 0)
169  {
170  mL = BaseType::mT;
171  }
172  }
173 
174  void BuildMasterSlaveConstraints(ModelPart &rModelPart) override
175  {
176 
177  KRATOS_TRY
178 
180 
181  // Setting the master dofs into the T and C system
182  for (auto eq_id : BaseType::mMasterIds)
183  {
184  mL(eq_id, eq_id) = 1.0;
185  }
186 
187  // Setting inactive slave dofs in the T and C system
188  for (auto eq_id : BaseType::mInactiveSlaveDofs)
189  {
190  mL(eq_id, eq_id) = 1.0;
191  }
192 
193  KRATOS_CATCH("")
194  }
195 
197  typename TSchemeType::Pointer pScheme,
198  ModelPart& rModelPart,
199  TSystemMatrixType& rA,
200  TSystemVectorType& rb) override
201  {
202  KRATOS_TRY
203 
204  if (rModelPart.MasterSlaveConstraints().size() != 0)
205  {
206  double start_constraints = OpenMPUtils::GetCurrentTime();
207  BuildMasterSlaveConstraints(rModelPart);
208  // We compute the transposed matrix of the global relation matrix
209  TSystemMatrixType L_transpose_matrix(mL.size2(), mL.size1());
210  SparseMatrixMultiplicationUtility::TransposeMatrix<TSystemMatrixType, TSystemMatrixType>(L_transpose_matrix, mL, 1.0);
211 
212  TSystemVectorType b_modified(rb.size());
213  TSparseSpace::Mult(L_transpose_matrix, rb, b_modified);
214  TSparseSpace::Copy(b_modified, rb);
215  b_modified.resize(0, false); //free memory
216 
217  TSystemMatrixType auxiliar_A_matrix(BaseType::mT.size2(), rA.size2());
218  SparseMatrixMultiplicationUtility::MatrixMultiplication(L_transpose_matrix, rA, auxiliar_A_matrix); //auxiliar = T_transpose * rA
219  L_transpose_matrix.resize(0, 0, false); //free memory
220 
221  SparseMatrixMultiplicationUtility::MatrixMultiplication(auxiliar_A_matrix, BaseType::mT, rA); //A = auxilar * T NOTE: here we are overwriting the old A matrix!
222  auxiliar_A_matrix.resize(0, 0, false); //free memory
223 
224  double max_diag = 0.0;
225  for (IndexType i = 0; i < rA.size1(); ++i)
226  {
227  max_diag = std::max(std::abs(rA(i, i)), max_diag);
228  }
229 // Apply diagonal values on slaves BaseType::mDofSet.size()
230 #pragma omp parallel for
231  for (int i = 0; i < static_cast<int>(BaseType::mSlaveIds.size()); ++i)
232  {
233  const IndexType slave_equation_id = BaseType::mSlaveIds[i];
234  if (BaseType::mInactiveSlaveDofs.find(slave_equation_id) == BaseType::mInactiveSlaveDofs.end())
235  {
236  rA(slave_equation_id, slave_equation_id) = max_diag;
237  rb[slave_equation_id] = 0.0;
238  }
239  }
240  const double stop_constraints = OpenMPUtils::GetCurrentTime();
241  KRATOS_INFO_IF("ResidualBasedBlockBuilderAndSolverWithConstraintsForChimera", this->GetEchoLevel() >= 1 )<< "Applying constraints time: " << stop_constraints - start_constraints << std::endl;
242  }
243 
244  KRATOS_CATCH("")
245  }
246 
250 
254 
258 
260 
261 }; /* Class ResidualBasedBlockBuilderAndSolverWithConstraintsForChimera */
262 
264 
267 
269 
270 } /* namespace Kratos.*/
271 
272 #endif /* KRATOS_RESIDUAL_BASED_BLOCK_BUILDER_AND_SOLVER defined */
std::size_t IndexType
Definition of the index type.
Definition: builder_and_solver.h:76
TSparseSpace::VectorType TSystemVectorType
Definition of the vector size.
Definition: builder_and_solver.h:85
TSparseSpace::MatrixType TSystemMatrixType
Definition of the sparse matrix.
Definition: builder_and_solver.h:82
int GetEchoLevel() const
It returns the echo level.
Definition: builder_and_solver.h:674
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
MasterSlaveConstraintContainerType & MasterSlaveConstraints(IndexType ThisIndex=0)
Definition: model_part.h:654
Current class provides an implementation for standard builder and solving operations.
Definition: residualbased_block_builder_and_solver.h:82
void Clear() override
This function is intended to be called at the end of the solution step to clean up memory storage not...
Definition: residualbased_block_builder_and_solver.h:1081
std::vector< IndexType > mSlaveIds
This is vector containing the rigid movement of the constraint.
Definition: residualbased_block_builder_and_solver.h:1220
std::unordered_set< IndexType > mInactiveSlaveDofs
The equation ids of the master.
Definition: residualbased_block_builder_and_solver.h:1222
virtual void BuildMasterSlaveConstraints(ModelPart &rModelPart)
Definition: residualbased_block_builder_and_solver.h:1384
TSystemMatrixType mT
Definition: residualbased_block_builder_and_solver.h:1218
virtual void ConstructMasterSlaveConstraintsStructure(ModelPart &rModelPart)
Definition: residualbased_block_builder_and_solver.h:1301
BaseType::TSystemMatrixType TSystemMatrixType
Definition: residualbased_block_builder_and_solver.h:107
std::vector< IndexType > mMasterIds
The equation ids of the slaves.
Definition: residualbased_block_builder_and_solver.h:1221
Current class provides an implementation for applying the chimera constraints that is enforcing conti...
Definition: residualbased_block_builder_and_solver_with_constraints_for_chimera.h:73
TSystemMatrixType mL
Definition: residualbased_block_builder_and_solver_with_constraints_for_chimera.h:156
void BuildMasterSlaveConstraints(ModelPart &rModelPart) override
Definition: residualbased_block_builder_and_solver_with_constraints_for_chimera.h:174
BaseType::TSchemeType TSchemeType
Definition of the classes from the base class.
Definition: residualbased_block_builder_and_solver_with_constraints_for_chimera.h:85
ResidualBasedBlockBuilderAndSolver< TSparseSpace, TDenseSpace, TLinearSolver > BaseType
Definition of the base class.
Definition: residualbased_block_builder_and_solver_with_constraints_for_chimera.h:79
BaseType::TSystemMatrixType TSystemMatrixType
Definition: residualbased_block_builder_and_solver_with_constraints_for_chimera.h:86
void Clear() override
This function is intended to be called at the end of the solution step to clean up memory storage not...
Definition: residualbased_block_builder_and_solver_with_constraints_for_chimera.h:120
BaseType::TSystemVectorType TSystemVectorType
Definition: residualbased_block_builder_and_solver_with_constraints_for_chimera.h:87
KRATOS_CLASS_POINTER_DEFINITION(ResidualBasedBlockBuilderAndSolverWithConstraintsForChimera)
void ApplyConstraints(typename TSchemeType::Pointer pScheme, ModelPart &rModelPart, TSystemMatrixType &rA, TSystemVectorType &rb) override
Applies the constraints with master-slave relation matrix.
Definition: residualbased_block_builder_and_solver_with_constraints_for_chimera.h:196
BaseType::IndexType IndexType
Definition: residualbased_block_builder_and_solver_with_constraints_for_chimera.h:82
std::string Info() const override
Turn back information as a string.
Definition: residualbased_block_builder_and_solver_with_constraints_for_chimera.h:139
ResidualBasedBlockBuilderAndSolverWithConstraintsForChimera(typename TLinearSolver::Pointer pNewLinearSystemSolver)
Definition: residualbased_block_builder_and_solver_with_constraints_for_chimera.h:98
void ConstructMasterSlaveConstraintsStructure(ModelPart &rModelPart) override
Definition: residualbased_block_builder_and_solver_with_constraints_for_chimera.h:165
This class provides the implementation of the basic tasks that are needed by the solution strategy.
Definition: scheme.h:56
static void MatrixMultiplication(const AMatrix &rA, const BMatrix &rB, CMatrix &rC)
Matrix-matrix product C = A·B @detail This method uses a template for each matrix.
Definition: sparse_matrix_multiplication_utility.h:117
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_INFO_IF(label, conditional)
Definition: logger.h:251
static double max(double a, double b)
Definition: GeometryFunctions.h:79
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
integer i
Definition: TensorModule.f:17