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_periodic.h
Go to the documentation of this file.
1 // | / |
2 // ' / __| _` | __| _ \ __|
3 // . \ | ( | | ( |\__ `
4 // _|\_\_| \__,_|\__|\___/ ____/
5 // Multi-Physics
6 //
7 // License: BSD License
8 // Kratos default license: kratos/license.txt
9 //
10 // Main authors: Jordi Cotela
11 //
12 
13 
14 #ifndef KRATOS_RESIDUALBASED_BLOCK_BUILDER_AND_SOLVER_PERIODIC_H
15 #define KRATOS_RESIDUALBASED_BLOCK_BUILDER_AND_SOLVER_PERIODIC_H
16 
17 /* System includes */
18 #include <set>
19 
20 #ifdef _OPENMP
21 #include <omp.h>
22 #endif
23 
24 /* External includes */
25 #include "boost/smart_ptr.hpp"
26 #include "utilities/timer.h"
27 
28 /* Project includes */
30 #include "includes/model_part.h"
31 
32 namespace Kratos
33 {
34 
63 template<class TSparseSpace,
64  class TDenseSpace, //= DenseSpace<double>,
65  class TLinearSolver //= LinearSolver<TSparseSpace,TDenseSpace>
66  >
68  : public ResidualBasedBlockBuilderAndSolver< TSparseSpace, TDenseSpace, TLinearSolver >
69 {
70 public:
75 
76 
78 
80 
81  typedef typename BaseType::TDataType TDataType;
82 
84 
86 
88 
90 
92 
95 
99 
101 
109  ResidualBasedBlockBuilderAndSolverPeriodic(typename TLinearSolver::Pointer pNewLinearSystemSolver,
110  const Variable<int>& PeriodicVariable ):
111  ResidualBasedBlockBuilderAndSolver< TSparseSpace, TDenseSpace, TLinearSolver >(pNewLinearSystemSolver),
112  mPeriodicIdVar(PeriodicVariable)
113  {}
114 
118  {
119  }
120 
121 
132  void SetUpSystem(ModelPart &r_model_part) override
133  {
134  // Assign an Equation Id to all non-duplicate nodes
135  unsigned int EqId = 0;
136 
137  // Modify edge/corner periodic condtions so that one of the nodes gets EquationId
138  for (ModelPart::ConditionIterator itCond = r_model_part.ConditionsBegin(); itCond != r_model_part.ConditionsEnd(); itCond++) {
139  auto& r_geometry = itCond->GetGeometry();
140  if (itCond->Is(PERIODIC) && (r_geometry.PointsNumber() == 4 || r_geometry.PointsNumber() == 8)) {
141  r_geometry[0].GetSolutionStepValue(mPeriodicIdVar) = 0;
142  }
143  }
144 
145  for (typename DofsArrayType::iterator itDof = BaseType::mDofSet.begin(); itDof != BaseType::mDofSet.end(); ++itDof)
146  {
147  if ( itDof->GetSolutionStepValue(mPeriodicIdVar) < static_cast<int>(itDof->Id()) )
148  itDof->SetEquationId(EqId++);
149  }
150 
151  // Reset edge/corner periodic condtions
152  for (ModelPart::ConditionIterator itCond = r_model_part.ConditionsBegin(); itCond != r_model_part.ConditionsEnd(); itCond++) {
153  auto& r_geometry = itCond->GetGeometry();
154  if (itCond->Is(PERIODIC) && (r_geometry.PointsNumber() == 4 || r_geometry.PointsNumber() == 8)) {
155  r_geometry[0].GetSolutionStepValue(mPeriodicIdVar) = r_geometry[1].GetSolutionStepValue(mPeriodicIdVar);
156  }
157  }
158 
159  // Copy Equation Id to duplicate nodes.
160  for (ModelPart::ConditionIterator itCond = r_model_part.ConditionsBegin(); itCond != r_model_part.ConditionsEnd(); itCond++)
161  {
162  // PeriodicCondition always have exactly 2 nodes
163  ModelPart::ConditionType::GeometryType& rGeom = itCond->GetGeometry();
164  if (itCond->Is(PERIODIC)) {
165  if (rGeom.PointsNumber() == 2) {
166  int Node0 = rGeom[0].Id();
167  int Node0Pair = rGeom[0].FastGetSolutionStepValue(mPeriodicIdVar);
168 
169  int Node1 = rGeom[1].Id();
170  int Node1Pair = rGeom[1].FastGetSolutionStepValue(mPeriodicIdVar);
171 
172  // If the nodes are marked as a periodic pair (this is to avoid acting on two-noded conditions that are not PeriodicCondition)
173  if ( ( Node0 == Node1Pair ) && ( Node1 == Node0Pair ) ) {
174  if ( Node0 < Node0Pair ) // If Node0 is the one with lower Id (the one that does not have an EquationId yet)
175  CopyEquationId(rGeom[1],rGeom[0]);
176  else
177  CopyEquationId(rGeom[0],rGeom[1]);
178  }
179  }
180  else {
181  for (unsigned int i = 1; i < rGeom.PointsNumber(); i++) {
182  CopyEquationId(rGeom[0],rGeom[i]);
183  }
184  }
185  }
186  }
187 
189  }
190 
191  void ApplyDirichletConditions(typename TSchemeType::Pointer pScheme,
192  ModelPart &r_model_part,
194  TSystemVectorType &Dx,
195  TSystemVectorType &b) override
196  {
197  double* Avalues = A.value_data().begin();
198  std::size_t* Arow_indices = A.index1_data().begin();
199  std::size_t* Acol_indices = A.index2_data().begin();
200 
201  for (typename DofsArrayType::iterator itDof = BaseType::mDofSet.begin(); itDof != BaseType::mDofSet.end(); ++itDof)
202  {
203  if (itDof->IsFixed())
204  {
205  std::size_t RowId = itDof->EquationId();
206  std::size_t RowBegin = Arow_indices[RowId];
207  std::size_t RowEnd = Arow_indices[RowId+1];
208 
209  for (std::size_t k = RowBegin; k != RowEnd; k++)
210  {
211  if ( Acol_indices[k] == RowId )
212  Avalues[k] = 1.0;
213  else
214  Avalues[k] = 0.0;
215  }
216 
217  b[RowId] = 0.0;
218  }
219  }
220  }
221 
239 protected:
277 private:
286  const Variable<int>& mPeriodicIdVar;
287 
298  void CopyEquationId(ModelPart::NodeType& rOrigin,
299  ModelPart::NodeType& rDest)
300  {
301  for (auto itDof = rOrigin.GetDofs().begin(); itDof != rOrigin.GetDofs().end(); itDof++)
302  rDest.pGetDof( (*itDof)->GetVariable() )->SetEquationId( (*itDof)->EquationId() );
303  }
304 
322 }; /* Class ResidualBasedBlockBuilderAndSolverPeriodic */
323 
332 } /* namespace Kratos.*/
333 
334 #endif // KRATOS_RESIDUALBASED_BLOCK_BUILDER_AND_SOLVER_PERIODIC_H
TSparseSpace::VectorType TSystemVectorType
Definition of the vector size.
Definition: builder_and_solver.h:85
ModelPart::NodesContainerType NodesArrayType
The containers of the entities.
Definition: builder_and_solver.h:109
TSparseSpace::MatrixType TSystemMatrixType
Definition of the sparse matrix.
Definition: builder_and_solver.h:82
ModelPart::ConditionsContainerType ConditionsArrayType
Definition: builder_and_solver.h:111
TDenseSpace::MatrixType LocalSystemMatrixType
The local matrix definition.
Definition: builder_and_solver.h:94
TSparseSpace::VectorPointerType TSystemVectorPointerType
Definition of the pointer to the vector.
Definition: builder_and_solver.h:91
TSparseSpace::DataType TDataType
Definition of the data type.
Definition: builder_and_solver.h:79
DofsArrayType mDofSet
Pointer to the linear solver.
Definition: builder_and_solver.h:739
TDenseSpace::VectorType LocalSystemVectorType
The local vector definition.
Definition: builder_and_solver.h:97
TSparseSpace::MatrixPointerType TSystemMatrixPointerType
Definition of the pointer to the sparse matrix.
Definition: builder_and_solver.h:88
unsigned int mEquationSystemSize
Flag taking in account if it is needed or not to calculate the reactions.
Definition: builder_and_solver.h:747
ModelPart::ElementsContainerType ElementsArrayType
Definition: builder_and_solver.h:110
void SetEquationId(EquationIdType NewEquationId)
Definition: dof.h:331
Geometry base class.
Definition: geometry.h:71
SizeType PointsNumber() const
Definition: geometry.h:528
IndexType const & Id() const
Id of this Geometry.
Definition: geometry.h:964
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
ConditionIterator ConditionsBegin(IndexType ThisIndex=0)
Definition: model_part.h:1361
MeshType::ConditionIterator ConditionIterator
Definition: model_part.h:189
ConditionIterator ConditionsEnd(IndexType ThisIndex=0)
Definition: model_part.h:1371
This class defines the node.
Definition: node.h:65
DofsContainerType & GetDofs()
Definition: node.h:694
DofType::Pointer pGetDof(TVariableType const &rDofVariable) const
Get DoF counted pointer for a given variable.
Definition: node.h:711
A sorted associative container similar to an STL set, but uses a vector to store pointers to its data...
Definition: pointer_vector_set.h:72
boost::indirect_iterator< typename TContainerType::iterator > iterator
Definition: pointer_vector_set.h:95
iterator end()
Returns an iterator pointing to the end of the container.
Definition: pointer_vector_set.h:314
Current class provides an implementation for standard builder and solving operations.
Definition: residualbased_block_builder_and_solver.h:82
Definition: residualbased_block_builder_and_solver_periodic.h:69
BaseType::ConditionsArrayType ConditionsArrayType
Definition: residualbased_block_builder_and_solver_periodic.h:98
BaseType::ElementsArrayType ElementsArrayType
Definition: residualbased_block_builder_and_solver_periodic.h:97
BaseType::TSystemVectorPointerType TSystemVectorPointerType
Definition: residualbased_block_builder_and_solver_periodic.h:94
ResidualBasedBlockBuilderAndSolverPeriodic(typename TLinearSolver::Pointer pNewLinearSystemSolver, const Variable< int > &PeriodicVariable)
Definition: residualbased_block_builder_and_solver_periodic.h:109
BaseType::TSystemMatrixType TSystemMatrixType
Definition: residualbased_block_builder_and_solver_periodic.h:85
KRATOS_CLASS_POINTER_DEFINITION(ResidualBasedBlockBuilderAndSolverPeriodic)
BaseType::TSystemMatrixPointerType TSystemMatrixPointerType
Definition: residualbased_block_builder_and_solver_periodic.h:93
BaseType::DofsArrayType DofsArrayType
Definition: residualbased_block_builder_and_solver_periodic.h:83
BaseType::TDataType TDataType
Definition: residualbased_block_builder_and_solver_periodic.h:81
~ResidualBasedBlockBuilderAndSolverPeriodic() override
Definition: residualbased_block_builder_and_solver_periodic.h:117
BaseType::LocalSystemVectorType LocalSystemVectorType
Definition: residualbased_block_builder_and_solver_periodic.h:89
void SetUpSystem(ModelPart &r_model_part) override
Organises the dofset in order to speed up the building phase.
Definition: residualbased_block_builder_and_solver_periodic.h:132
BaseType::LocalSystemMatrixType LocalSystemMatrixType
Definition: residualbased_block_builder_and_solver_periodic.h:91
BaseType::TSystemVectorType TSystemVectorType
Definition: residualbased_block_builder_and_solver_periodic.h:87
BaseType::TSchemeType TSchemeType
Definition: residualbased_block_builder_and_solver_periodic.h:79
BaseType::ElementsContainerType ElementsContainerType
Definition: residualbased_block_builder_and_solver_periodic.h:100
ResidualBasedBlockBuilderAndSolver< TSparseSpace, TDenseSpace, TLinearSolver > BaseType
Definition: residualbased_block_builder_and_solver_periodic.h:77
void ApplyDirichletConditions(typename TSchemeType::Pointer pScheme, ModelPart &r_model_part, TSystemMatrixType &A, TSystemVectorType &Dx, TSystemVectorType &b) override
Applies the dirichlet conditions. This operation may be very heavy or completely unexpensive dependin...
Definition: residualbased_block_builder_and_solver_periodic.h:191
BaseType::NodesArrayType NodesArrayType
Definition: residualbased_block_builder_and_solver_periodic.h:96
This class provides the implementation of the basic tasks that are needed by the solution strategy.
Definition: scheme.h:56
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
b
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:31
int k
Definition: quadrature.py:595
A
Definition: sensitivityMatrix.py:70
integer i
Definition: TensorModule.f:17