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_simple_steady_scheme.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: Michael Andre, https://github.com/msandre
11 //
12 
13 
14 #if !defined(KRATOS_RESIDUALBASED_SIMPLE_STEADY_SCHEME )
15 #define KRATOS_RESIDUALBASED_SIMPLE_STEADY_SCHEME
16 
17 // Project includes
18 #include "includes/define.h"
19 #include "includes/model_part.h"
21 #include "includes/variables.h"
22 #include "includes/cfd_variables.h"
23 #include "containers/array_1d.h"
24 #include "utilities/openmp_utils.h"
26 #include "processes/process.h"
27 
28 namespace Kratos {
29 
32 
33 template<class TSparseSpace, class TDenseSpace >
34 class ResidualBasedSimpleSteadyScheme : public Scheme<TSparseSpace, TDenseSpace> {
35 public:
38 
40 
42 
44 
46 
48 
50 
52 
54 
58 
59  ResidualBasedSimpleSteadyScheme(double VelocityRelaxationFactor,
60  double PressureRelaxationFactor,
61  unsigned int DomainSize)
62  : Scheme<TSparseSpace, TDenseSpace>(),
63  mVelocityRelaxationFactor(VelocityRelaxationFactor),
64  mPressureRelaxationFactor(PressureRelaxationFactor),
65  mRotationTool(DomainSize,DomainSize+1,SLIP)
66  {}
67 
69  double VelocityRelaxationFactor,
70  double PressureRelaxationFactor,
71  unsigned int DomainSize,
72  Process::Pointer pTurbulenceModel)
73  : Scheme<TSparseSpace, TDenseSpace>(),
74  mVelocityRelaxationFactor(VelocityRelaxationFactor),
75  mPressureRelaxationFactor(PressureRelaxationFactor),
76  mRotationTool(DomainSize,DomainSize+1,SLIP),
77  mpTurbulenceModel(pTurbulenceModel)
78 
79  {}
80 
82 
83 
88  {
89  return mVelocityRelaxationFactor;
90  }
91 
93  {
94  mVelocityRelaxationFactor = factor;
95  }
96 
98  {
99  return mPressureRelaxationFactor;
100  }
101 
103  {
104  mPressureRelaxationFactor = factor;
105  }
106 
107  void Update(ModelPart& rModelPart,
108  DofsArrayType& rDofSet,
109  TSystemMatrixType& rA,
110  TSystemVectorType& rDx,
111  TSystemVectorType& rb) override
112  {
113  KRATOS_TRY;
114 
115  mRotationTool.RotateVelocities(rModelPart);
116 
117  TSparseSpace::InplaceMult(rDx, mVelocityRelaxationFactor);
118 
119  mpDofUpdater->UpdateDofs(rDofSet,rDx);
120 
121  mRotationTool.RecoverVelocities(rModelPart);
122 
123  KRATOS_CATCH("");
124  }
125 
127  Element& rCurrentElement,
128  LocalSystemMatrixType& LHS_Contribution,
129  LocalSystemVectorType& RHS_Contribution,
131  const ProcessInfo& CurrentProcessInfo) override
132  {
133  KRATOS_TRY;
134 
135  rCurrentElement.CalculateLocalSystem(LHS_Contribution, RHS_Contribution, CurrentProcessInfo);
136 
137  Matrix SteadyLHS;
138  rCurrentElement.CalculateLocalVelocityContribution(SteadyLHS, RHS_Contribution, CurrentProcessInfo);
139  rCurrentElement.EquationIdVector(EquationId, CurrentProcessInfo);
140 
141  if (SteadyLHS.size1() != 0)
142  noalias(LHS_Contribution) += SteadyLHS;
143 
144  // apply slip condition
145  mRotationTool.Rotate(LHS_Contribution,RHS_Contribution,rCurrentElement.GetGeometry());
146  mRotationTool.ApplySlipCondition(LHS_Contribution,RHS_Contribution,rCurrentElement.GetGeometry());
147 
148  KRATOS_CATCH("");
149  }
150 
152  Condition& rCurrentCondition,
153  LocalSystemMatrixType& LHS_Contribution,
154  LocalSystemVectorType& RHS_Contribution,
156  const ProcessInfo& CurrentProcessInfo) override
157  {
158  KRATOS_TRY;
159 
160  rCurrentCondition.CalculateLocalSystem(LHS_Contribution, RHS_Contribution, CurrentProcessInfo);
161 
162  Matrix SteadyLHS;
163  rCurrentCondition.CalculateLocalVelocityContribution(SteadyLHS, RHS_Contribution, CurrentProcessInfo);
164  rCurrentCondition.EquationIdVector(EquationId, CurrentProcessInfo);
165 
166  if (SteadyLHS.size1() != 0)
167  noalias(LHS_Contribution) += SteadyLHS;
168 
169  // apply slip condition
170  mRotationTool.Rotate(LHS_Contribution,RHS_Contribution,rCurrentCondition.GetGeometry());
171  mRotationTool.ApplySlipCondition(LHS_Contribution,RHS_Contribution,rCurrentCondition.GetGeometry());
172 
173  KRATOS_CATCH("");
174  }
175 
177  Element& rCurrentElement,
178  LocalSystemVectorType& rRHS_Contribution,
179  Element::EquationIdVectorType& rEquationId,
180  const ProcessInfo& rCurrentProcessInfo) override
181  {
182  KRATOS_TRY;
183 
184  //TODO: This is very inefficient. Check why the RHS-only methods are not called.
185  Matrix LHS_Contribution;
187  rCurrentElement,
188  LHS_Contribution,
189  rRHS_Contribution,
190  rEquationId,
191  rCurrentProcessInfo);
192 
193  KRATOS_CATCH("");
194  }
195 
197  Condition& rCurrentCondition,
198  LocalSystemVectorType& rRHS_Contribution,
199  Element::EquationIdVectorType& rEquationId,
200  const ProcessInfo& rCurrentProcessInfo) override
201  {
202  KRATOS_TRY;
203 
204  //TODO: This is very inefficient. Check why the RHS-only methods are not called.
205  Matrix LHS_Contribution;
207  rCurrentCondition,
208  LHS_Contribution,
209  rRHS_Contribution,
210  rEquationId,
211  rCurrentProcessInfo);
212 
213  KRATOS_CATCH("");
214  }
215 
217  TSystemMatrixType& rA,
218  TSystemVectorType& rDx,
219  TSystemVectorType& rb) override
220  {
221  if (mpTurbulenceModel) // If not null
222  {
223  mpTurbulenceModel->Execute();
224  }
225 
226  ProcessInfo& CurrentProcessInfo = rModelPart.GetProcessInfo();
227 
228  //if orthogonal subscales are computed
229  if (CurrentProcessInfo[OSS_SWITCH] == 1.0) {
230 
231  KRATOS_INFO_IF("ResidualBasedSimpleSteadyScheme", rModelPart.GetCommunicator().MyPID() == 0)
232  << "Computing OSS projections" << std::endl;
233 
234  const int number_of_nodes = rModelPart.NumberOfNodes();
235 
236  #pragma omp parallel for
237  for (int i = 0; i < number_of_nodes; i++) {
238  ModelPart::NodeIterator it_node = rModelPart.NodesBegin() + i;
239  noalias(it_node->FastGetSolutionStepValue(ADVPROJ)) = ZeroVector(3);
240  it_node->FastGetSolutionStepValue(DIVPROJ) = 0.0;
241  it_node->FastGetSolutionStepValue(NODAL_AREA) = 0.0;
242  }
243 
244  const int number_of_elements = rModelPart.NumberOfElements();
246 
247  #pragma omp parallel for private(output)
248  for (int i = 0; i < number_of_elements; i++) {
249  ModelPart::ElementIterator it_elem = rModelPart.ElementsBegin() + i;
250  it_elem->Calculate(ADVPROJ,output,CurrentProcessInfo);
251  }
252 
253  rModelPart.GetCommunicator().AssembleCurrentData(NODAL_AREA);
254  rModelPart.GetCommunicator().AssembleCurrentData(DIVPROJ);
255  rModelPart.GetCommunicator().AssembleCurrentData(ADVPROJ);
256 
257  #pragma omp parallel for
258  for (int i = 0; i < number_of_nodes; i++) {
259  ModelPart::NodeIterator it_node = rModelPart.NodesBegin() + i;
260  if (it_node->FastGetSolutionStepValue(NODAL_AREA) == 0.0)
261  it_node->FastGetSolutionStepValue(NODAL_AREA) = 1.0;
262  const double area_inverse = 1.0 / it_node->FastGetSolutionStepValue(NODAL_AREA);
263  it_node->FastGetSolutionStepValue(ADVPROJ) *= area_inverse;
264  it_node->FastGetSolutionStepValue(DIVPROJ) *= area_inverse;
265  }
266  }
267  }
268 
269  void FinalizeSolutionStep(ModelPart& rModelPart,
270  TSystemMatrixType& rA,
271  TSystemVectorType& rDx,
272  TSystemVectorType& rb) override
273  {
274  LocalSystemVectorType RHS_Contribution;
275  LocalSystemMatrixType LHS_Contribution;
276  const ProcessInfo& rCurrentProcessInfo = rModelPart.GetProcessInfo();
277 
278  for (ModelPart::NodeIterator itNode = rModelPart.NodesBegin();
279  itNode != rModelPart.NodesEnd(); ++itNode)
280  {
281  itNode->FastGetSolutionStepValue(REACTION_X,0) = 0.0;
282  itNode->FastGetSolutionStepValue(REACTION_Y,0) = 0.0;
283  itNode->FastGetSolutionStepValue(REACTION_Z,0) = 0.0;
284  }
285 
286  for (ModelPart::ElementsContainerType::ptr_iterator itElem = rModelPart.Elements().ptr_begin();
287  itElem != rModelPart.Elements().ptr_end(); ++itElem)
288  {
289  (*itElem)->CalculateLocalSystem(LHS_Contribution,RHS_Contribution,rCurrentProcessInfo);
290  Matrix SteadyLHS;
291  (*itElem)->CalculateLocalVelocityContribution(SteadyLHS,RHS_Contribution,rCurrentProcessInfo);
292 
293  GeometryType& rGeom = (*itElem)->GetGeometry();
294  unsigned int NumNodes = rGeom.PointsNumber();
295  unsigned int Dimension = rGeom.WorkingSpaceDimension();
296  unsigned int index = 0;
297 
298  for (unsigned int i = 0; i < NumNodes; i++)
299  {
300  rGeom[i].FastGetSolutionStepValue(REACTION_X,0) -= RHS_Contribution[index++];
301  rGeom[i].FastGetSolutionStepValue(REACTION_Y,0) -= RHS_Contribution[index++];
302  if (Dimension == 3) rGeom[i].FastGetSolutionStepValue(REACTION_Z,0) -= RHS_Contribution[index++];
303  index++; // skip pressure dof
304  }
305  }
306 
307  rModelPart.GetCommunicator().AssembleCurrentData(REACTION);
309  }
310 
312 
313 protected:
314 
317 
319 
320 private:
323 
324  double mVelocityRelaxationFactor;
325  double mPressureRelaxationFactor;
327  Process::Pointer mpTurbulenceModel;
328  typename TSparseSpace::DofUpdaterPointerType mpDofUpdater = TSparseSpace::CreateDofUpdater();
329 
331 };
332 
334 
335 } // namespace Kratos
336 
337 #endif /* KRATOS_RESIDUALBASED_SIMPLE_STEADY_SCHEME defined */
virtual bool AssembleCurrentData(Variable< int > const &ThisVariable)
Definition: communicator.cpp:502
virtual int MyPID() const
Definition: communicator.cpp:91
Base class for all Conditions.
Definition: condition.h:59
virtual void CalculateLocalVelocityContribution(MatrixType &rDampingMatrix, VectorType &rRightHandSideVector, const ProcessInfo &rCurrentProcessInfo)
Definition: condition.h:922
std::vector< std::size_t > EquationIdVectorType
Definition: condition.h:98
virtual void EquationIdVector(EquationIdVectorType &rResult, const ProcessInfo &rCurrentProcessInfo) const
Definition: condition.h:260
virtual void CalculateLocalSystem(MatrixType &rLeftHandSideMatrix, VectorType &rRightHandSideVector, const ProcessInfo &rCurrentProcessInfo)
Definition: condition.h:408
virtual void RotateVelocities(ModelPart &rModelPart) const
Transform nodal velocities to the rotated coordinates (aligned with each node's normal)
Definition: coordinate_transformation_utilities.h:631
virtual void RecoverVelocities(ModelPart &rModelPart) const
Transform nodal velocities from the rotated system to the original one.
Definition: coordinate_transformation_utilities.h:669
virtual void ApplySlipCondition(TLocalMatrixType &rLocalMatrix, TLocalVectorType &rLocalVector, GeometryType &rGeometry) const
Apply slip boundary conditions to the rotated local contributions.
Definition: coordinate_transformation_utilities.h:565
virtual void Rotate(TLocalMatrixType &rLocalMatrix, TLocalVectorType &rLocalVector, GeometryType &rGeometry) const
Rotate the local system contributions so that they are oriented with each node's normal.
Definition: coordinate_transformation_utilities.h:447
Base class for all Elements.
Definition: element.h:60
virtual void EquationIdVector(EquationIdVectorType &rResult, const ProcessInfo &rCurrentProcessInfo) const
Definition: element.h:258
virtual void CalculateLocalVelocityContribution(MatrixType &rDampingMatrix, VectorType &rRightHandSideVector, const ProcessInfo &rCurrentProcessInfo)
Definition: element.h:972
virtual void CalculateLocalSystem(MatrixType &rLeftHandSideMatrix, VectorType &rRightHandSideVector, const ProcessInfo &rCurrentProcessInfo)
Definition: element.h:405
std::vector< std::size_t > EquationIdVectorType
Definition: element.h:98
GeometryType & GetGeometry()
Returns the reference of the geometry.
Definition: geometrical_object.h:158
Geometry base class.
Definition: geometry.h:71
SizeType PointsNumber() const
Definition: geometry.h:528
SizeType WorkingSpaceDimension() const
Definition: geometry.h:1287
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
Communicator & GetCommunicator()
Definition: model_part.h:1821
NodeIterator NodesBegin(IndexType ThisIndex=0)
Definition: model_part.h:487
SizeType NumberOfElements(IndexType ThisIndex=0) const
Definition: model_part.h:1027
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
MeshType::NodeIterator NodeIterator
Definition: model_part.h:134
ElementsContainerType & Elements(IndexType ThisIndex=0)
Definition: model_part.h:1189
MeshType::ElementIterator ElementIterator
Definition: model_part.h:174
SizeType NumberOfNodes(IndexType ThisIndex=0) const
Definition: model_part.h:341
NodeIterator NodesEnd(IndexType ThisIndex=0)
Definition: model_part.h:497
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
ProcessInfo holds the current value of different solution parameters.
Definition: process_info.h:59
Definition: residualbased_simple_steady_scheme.h:34
void CalculateRHSContribution(Element &rCurrentElement, LocalSystemVectorType &rRHS_Contribution, Element::EquationIdVectorType &rEquationId, const ProcessInfo &rCurrentProcessInfo) override
This function is designed to calculate just the RHS contribution.
Definition: residualbased_simple_steady_scheme.h:176
BaseType::TSystemVectorType TSystemVectorType
Definition: residualbased_simple_steady_scheme.h:47
void SetVelocityRelaxationFactor(double factor)
Definition: residualbased_simple_steady_scheme.h:92
void CalculateSystemContributions(Element &rCurrentElement, LocalSystemMatrixType &LHS_Contribution, LocalSystemVectorType &RHS_Contribution, Element::EquationIdVectorType &EquationId, const ProcessInfo &CurrentProcessInfo) override
This function is designed to be called in the builder and solver to introduce the selected time integ...
Definition: residualbased_simple_steady_scheme.h:126
void CalculateSystemContributions(Condition &rCurrentCondition, LocalSystemMatrixType &LHS_Contribution, LocalSystemVectorType &RHS_Contribution, Condition::EquationIdVectorType &EquationId, const ProcessInfo &CurrentProcessInfo) override
Functions totally analogous to the precedent but applied to the "condition" objects.
Definition: residualbased_simple_steady_scheme.h:151
BaseType::DofsArrayType DofsArrayType
Definition: residualbased_simple_steady_scheme.h:43
~ResidualBasedSimpleSteadyScheme() override
Definition: residualbased_simple_steady_scheme.h:81
BaseType::TSystemMatrixType TSystemMatrixType
Definition: residualbased_simple_steady_scheme.h:45
BaseType::LocalSystemVectorType LocalSystemVectorType
Definition: residualbased_simple_steady_scheme.h:49
void SetPressureRelaxationFactor(double factor)
Definition: residualbased_simple_steady_scheme.h:102
double GetVelocityRelaxationFactor() const
Definition: residualbased_simple_steady_scheme.h:87
KRATOS_CLASS_POINTER_DEFINITION(ResidualBasedSimpleSteadyScheme)
void FinalizeNonLinIteration(ModelPart &rModelPart, TSystemMatrixType &rA, TSystemVectorType &rDx, TSystemVectorType &rb) override
Function to be called when it is needed to finalize an iteration. It is designed to be called at the ...
Definition: residualbased_simple_steady_scheme.h:216
void FinalizeSolutionStep(ModelPart &rModelPart, TSystemMatrixType &rA, TSystemVectorType &rDx, TSystemVectorType &rb) override
Function called once at the end of a solution step, after convergence is reached if an iterative proc...
Definition: residualbased_simple_steady_scheme.h:269
void CalculateRHSContribution(Condition &rCurrentCondition, LocalSystemVectorType &rRHS_Contribution, Element::EquationIdVectorType &rEquationId, const ProcessInfo &rCurrentProcessInfo) override
Functions totally analogous to the precedent but applied to the "condition" objects.
Definition: residualbased_simple_steady_scheme.h:196
void Update(ModelPart &rModelPart, DofsArrayType &rDofSet, TSystemMatrixType &rA, TSystemVectorType &rDx, TSystemVectorType &rb) override
Performing the update of the solution.
Definition: residualbased_simple_steady_scheme.h:107
ResidualBasedSimpleSteadyScheme(double VelocityRelaxationFactor, double PressureRelaxationFactor, unsigned int DomainSize, Process::Pointer pTurbulenceModel)
Definition: residualbased_simple_steady_scheme.h:68
Scheme< TSparseSpace, TDenseSpace > BaseType
Definition: residualbased_simple_steady_scheme.h:41
Element::GeometryType GeometryType
Definition: residualbased_simple_steady_scheme.h:53
ResidualBasedSimpleSteadyScheme(double VelocityRelaxationFactor, double PressureRelaxationFactor, unsigned int DomainSize)
Definition: residualbased_simple_steady_scheme.h:59
BaseType::LocalSystemMatrixType LocalSystemMatrixType
Definition: residualbased_simple_steady_scheme.h:51
double GetPressureRelaxationFactor() const
Definition: residualbased_simple_steady_scheme.h:97
This class provides the implementation of the basic tasks that are needed by the solution strategy.
Definition: scheme.h:56
typename TSparseSpace::MatrixType TSystemMatrixType
Matrix type definition.
Definition: scheme.h:71
virtual void EquationId(const Element &rElement, Element::EquationIdVectorType &rEquationId, const ProcessInfo &rCurrentProcessInfo)
This method gets the eqaution id corresponding to the current element.
Definition: scheme.h:636
typename TSparseSpace::VectorType TSystemVectorType
Vector type definition.
Definition: scheme.h:74
typename TDenseSpace::VectorType LocalSystemVectorType
Local system vector type definition.
Definition: scheme.h:80
virtual void FinalizeSolutionStep(ModelPart &rModelPart, TSystemMatrixType &A, TSystemVectorType &Dx, TSystemVectorType &b)
Function called once at the end of a solution step, after convergence is reached if an iterative proc...
Definition: scheme.h:294
typename TDenseSpace::MatrixType LocalSystemMatrixType
Local system matrix type definition.
Definition: scheme.h:77
#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
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
KratosZeroVector< double > ZeroVector
Definition: amatrix_interface.h:561
T & noalias(T &TheMatrix)
Definition: amatrix_interface.h:484
output
Definition: generate_frictional_mortar_condition.py:444
integer i
Definition: TensorModule.f:17
float factor
for node in (self.combined_model_part).Nodes: pold = node.GetSolutionStepValue(PRESSURE,...
Definition: ulf_PGLASS.py:254