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_convdiff_strategy.h
Go to the documentation of this file.
1 // KRATOS ___ ___ _ ___ __ ___ ___ ___ ___
2 // / __/ _ \| \| \ \ / /__| \_ _| __| __|
3 // | (_| (_) | .` |\ V /___| |) | || _|| _|
4 // \___\___/|_|\_| \_/ |___/___|_| |_| APPLICATION
5 //
6 // License: BSD License
7 // Kratos default license: kratos/license.txt
8 //
9 // Main authors: Riccardo Rossi
10 //
11 
12 #if !defined(KRATOS_RESIDUALBASED_CONVECTION_DIFFUSION_STRATEGY )
13 #define KRATOS_RESIDUALBASED_CONVECTION_DIFFUSION_STRATEGY
14 
15 /* System includes */
16 
17 /* External includes */
18 
19 /* Project includes */
20 #include "includes/define.h"
21 #include "includes/model_part.h"
28 //#include "custom_utilities/convection_diffusion_settings.h"
29 
30 
31 
32 namespace Kratos
33 {
34 
61 
83 template<class TSparseSpace,
84  class TDenseSpace,
85  class TLinearSolver
86  >
88  : public ImplicitSolvingStrategy<TSparseSpace,TDenseSpace,TLinearSolver>
89 {
90 public:
96 
98 
99  typedef typename BaseType::TDataType TDataType;
100 
101  //typedef typename BaseType::DofSetType DofSetType;
102 
104 
106 
108 
110 
112 
113 
114 
131  typename TLinearSolver::Pointer pNewLinearSolver,
132  bool ReformDofAtEachIteration = true,
133  int time_order = 2,
134  int prediction_order = 2
135  )
136  : ImplicitSolvingStrategy<TSparseSpace,TDenseSpace,TLinearSolver>(model_part,false)
137  {
138  KRATOS_TRY
139 
140  mtime_order = time_order;
141  mOldDt = 0.00;
142  mprediction_order = prediction_order;
143 
144  ProcessInfo& rCurrentProcessInfo = BaseType::GetModelPart().GetProcessInfo();
145  ConvectionDiffusionSettings::Pointer my_settings = rCurrentProcessInfo.GetValue(CONVECTION_DIFFUSION_SETTINGS);
146  const Variable<double>& rUnknownVar= my_settings->GetUnknownVariable();
147 
148 
149 
150 
151  //initializing fractional velocity solution step
152  typedef Scheme< TSparseSpace, TDenseSpace > SchemeType;
153  typename SchemeType::Pointer pscheme = typename SchemeType::Pointer
155 
156  bool CalculateReactions = false;
157  bool CalculateNormDxFlag = true;
158 
159  //choosing the solving strategy
160 // mstep1 = typename BaseType::Pointer(
161 // new ResidualBasedLinearStrategy<TSparseSpace, TDenseSpace, TLinearSolver >
162 // (model_part,pscheme,pNewLinearSolver,CalculateReactions,ReformDofAtEachIteration,CalculateNormDxFlag) );
163 // mstep1->SetEchoLevel(2);
164 
165 
166  typedef typename BuilderAndSolver<TSparseSpace,TDenseSpace,TLinearSolver>::Pointer BuilderSolverTypePointer;
167 
168  BuilderSolverTypePointer componentwise_build = BuilderSolverTypePointer(new ResidualBasedEliminationBuilderAndSolverComponentwise<TSparseSpace,TDenseSpace,TLinearSolver,Variable<double> > (pNewLinearSolver,rUnknownVar) );
169  mstep1 = typename BaseType::Pointer(new ResidualBasedLinearStrategy<TSparseSpace, TDenseSpace, TLinearSolver >(
170  model_part,
171  pscheme,
172  componentwise_build,
173  CalculateReactions,
175  CalculateNormDxFlag));
176  mstep1->SetEchoLevel(2);
177  Check();
178  KRATOS_CATCH("")
179  }
180 
181 
182 
186 
190  //*********************************************************************************
191  //**********************************************************************
192  double Solve() override
193  {
194  KRATOS_TRY
195 
196  //calculate the BDF coefficients
197  ProcessInfo& rCurrentProcessInfo = BaseType::GetModelPart().GetProcessInfo();
198  double Dt = rCurrentProcessInfo[DELTA_TIME];
199  int stationary= rCurrentProcessInfo[STATIONARY];
200 
201  double Dp_norm;
202  if(stationary==1)
203  {
205  rCurrentProcessInfo[FRACTIONAL_STEP] = 1;
206  Dp_norm = mstep1->Solve();
207  }
208  else
209  {
210  if(mtime_order == 2)
211  {
212  if(BaseType::GetModelPart().GetBufferSize() < 3)
213  KRATOS_THROW_ERROR(std::logic_error,"insufficient buffer size for BDF2","")
214  double dt_old = rCurrentProcessInfo.GetPreviousTimeStepInfo(1)[DELTA_TIME];
215 
216  double rho = dt_old/Dt;
217  double coeff = 1.0/(Dt*rho*rho+Dt*rho);
218 
219  rCurrentProcessInfo[BDF_COEFFICIENTS].resize(3);
220  Vector& BDFcoeffs = rCurrentProcessInfo[BDF_COEFFICIENTS];
221  BDFcoeffs[0] = coeff*(rho*rho+2.0*rho); //coefficient for step n+1
222  BDFcoeffs[1] = -coeff*(rho*rho+2.0*rho+1.0);//coefficient for step n
223  BDFcoeffs[2] = coeff;
224  }
225  else
226  {
227  rCurrentProcessInfo[BDF_COEFFICIENTS].resize(2);
228  Vector& BDFcoeffs = rCurrentProcessInfo[BDF_COEFFICIENTS];
229  BDFcoeffs[0] = 1.0 / Dt; //coefficient for step n+1
230  BDFcoeffs[1] = -1.0 / Dt;//coefficient for step n
231  }
232 
233  //second order prediction for the velocity
234  if(mprediction_order == 2)
235  {
237  KRATOS_THROW_ERROR(std::logic_error,"insufficient buffer size for second order prediction","")
238 
239  ConvectionDiffusionSettings::Pointer my_settings = rCurrentProcessInfo.GetValue(CONVECTION_DIFFUSION_SETTINGS);
240  const Variable<double>& rUnknownVar= my_settings->GetUnknownVariable();
241 
243  i != BaseType::GetModelPart().NodesEnd() ; ++i)
244  {
245  i->FastGetSolutionStepValue(rUnknownVar) = 2.00*i->FastGetSolutionStepValue(rUnknownVar,1) - i->FastGetSolutionStepValue(rUnknownVar,2);
246  }
248  }
249 
250  //SOLVING THE PROBLEM
251  rCurrentProcessInfo[FRACTIONAL_STEP] = 1;
252 
253  Dp_norm = mstep1->Solve();
255 
256  }
257  return Dp_norm;
258  KRATOS_CATCH("")
259  }
260 
261 
262 
263  //******************************************************************************************************
264  //******************************************************************************************************
265  //calculation of projection
267  {
268  KRATOS_TRY;
269 
270  ProcessInfo& rCurrentProcessInfo = BaseType::GetModelPart().GetProcessInfo();
271  const ProcessInfo& rConstCurrentProcessInfo = BaseType::GetModelPart().GetProcessInfo();
272 
273  ConvectionDiffusionSettings::Pointer my_settings = rCurrentProcessInfo.GetValue(CONVECTION_DIFFUSION_SETTINGS);
274 
275  const Variable<double>& rProjectionVariable = my_settings->GetProjectionVariable();
276 
277  //first of all set to zero the nodal variables to be updated nodally
278  for(ModelPart::NodeIterator i = BaseType::GetModelPart().NodesBegin() ;
279  i != BaseType::GetModelPart().NodesEnd() ; ++i)
280  {
281  (i)->GetSolutionStepValue(rProjectionVariable) = 0.00;
282  (i)->GetSolutionStepValue(NODAL_AREA) = 0.00;
283  }
284 
285  //add the elemental contributions for the calculation of the velocity
286  //and the determination of the nodal area
287  rCurrentProcessInfo[FRACTIONAL_STEP] = 2;
290  {
291  (i)->InitializeSolutionStep(rConstCurrentProcessInfo);
292  }
293 
296 
297  //solve nodally for the velocity
298  for(ModelPart::NodeIterator i = BaseType::GetModelPart().NodesBegin() ;
299  i != BaseType::GetModelPart().NodesEnd() ; ++i)
300  {
301  double& conv_proj = (i)->GetSolutionStepValue(rProjectionVariable);
302  double temp = 1.00 / (i)->GetSolutionStepValue(NODAL_AREA);
303  conv_proj *= temp;
304  }
305 
306  KRATOS_CATCH("")
307  }
308 
309  void SetEchoLevel(int Level) override
310  {
311  mstep1->SetEchoLevel(Level);
312  }
313 
314  void Clear() override
315  {
316  mstep1->Clear();
317  }
318 
319  int Check() override
320  {
321  KRATOS_TRY
322 
323  ProcessInfo& rCurrentProcessInfo = BaseType::GetModelPart().GetProcessInfo();
324  ConvectionDiffusionSettings::Pointer my_settings = rCurrentProcessInfo.GetValue(CONVECTION_DIFFUSION_SETTINGS);
325  const Variable<double>& rUnknownVar = my_settings->GetUnknownVariable();
326  const Variable<double>& rDensityVar = my_settings->GetDensityVariable();
327  const Variable<double>& rDiffusionVar = my_settings->GetDiffusionVariable();
328  const Variable<double>& rSourceVar = my_settings->GetVolumeSourceVariable();
329  const Variable<array_1d<double, 3 > >& rMeshVelocityVar = my_settings->GetMeshVelocityVariable();
330  const Variable<double>& rProjectionVariable = my_settings->GetProjectionVariable();
331 
332  //const Variable<double>& rSpecificHeatVar = my_settings->GetSpecificHeatVariable();
333  //const Variable<array_1d<double, 3 > >& rVelocityVar = my_settings->GetVelocityVariable();
334 
335  if (BaseType::GetModelPart().NodesBegin()->SolutionStepsDataHas(rUnknownVar) == false)
336  KRATOS_THROW_ERROR(std::logic_error, "Add ----UnknownVar---- variable!!!!!! ERROR", "");
337  if (BaseType::GetModelPart().NodesBegin()->SolutionStepsDataHas(rDensityVar) == false)
338  KRATOS_THROW_ERROR(std::logic_error, "Add ----rDensityVar---- variable!!!!!! ERROR", "");
339  if (BaseType::GetModelPart().NodesBegin()->SolutionStepsDataHas(rDiffusionVar) == false)
340  KRATOS_THROW_ERROR(std::logic_error, "Add ----rDiffusionVar---- variable!!!!!! ERROR", "");
341  if (BaseType::GetModelPart().NodesBegin()->SolutionStepsDataHas(rSourceVar) == false)
342  KRATOS_THROW_ERROR(std::logic_error, "Add ----rSourceVar---- variable!!!!!! ERROR", "");
343  if (BaseType::GetModelPart().NodesBegin()->SolutionStepsDataHas(rMeshVelocityVar) == false)
344  KRATOS_THROW_ERROR(std::logic_error, "Add ----rMeshVelocityVar---- variable!!!!!! ERROR", "");
345  if (BaseType::GetModelPart().NodesBegin()->SolutionStepsDataHas(rProjectionVariable) == false)
346  KRATOS_THROW_ERROR(std::logic_error, "Add ----rProjectionVariable---- variable!!!!!! ERROR", "");
347 
348 
349  /* if(BaseType::GetModelPart().GetMesh().GetProperties(0)[EMISSIVITY] == false)
350  KRATOS_THROW_ERROR(std::logic_error, "Add ----EMISSIVITY---- variable!!!!!! ERROR", "");
351  if(BaseType::GetModelPart().GetMesh().GetProperties(0)[CONVECTION_COEFFICIENT] == false)
352  KRATOS_THROW_ERROR(std::logic_error, "Add ----CONVECTION_COEFFICIENT---- variable!!!!!! ERROR", "");
353  if(BaseType::GetModelPart().GetMesh().GetProperties(0)[AMBIENT_TEMPERATURE] == false)
354  KRATOS_THROW_ERROR(std::logic_error, "Add ----AMBIENT_TEMPERATURE---- variable!!!!!! ERROR", "");*/
355 
356 
357  return 0;
358 
359  KRATOS_CATCH("")
360 
361  }
362 
390 protected:
429 private:
437  typename BaseType::Pointer mstep1;
438  double mOldDt;
439  int mtime_order;
440  int mprediction_order;
441 
442 
443 
444 
445 
472 
473 
476 }; /* Class ResidualBasedConvectionDiffusionStrategy */
477 
486 } /* namespace Kratos.*/
487 
488 #endif /* KRATOS_RESIDUALBASED_CONVECTION_DIFFUSION_STRATEGY defined */
Current class provides an implementation for the base builder and solving operations.
Definition: builder_and_solver.h:64
virtual bool AssembleCurrentData(Variable< int > const &ThisVariable)
Definition: communicator.cpp:502
TDataType & GetValue(const Variable< TDataType > &rThisVariable)
Gets the value associated with a given variable.
Definition: data_value_container.h:268
Implicit solving strategy base class This is the base class from which we will derive all the implici...
Definition: implicit_solving_strategy.h:61
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
IndexType GetBufferSize() const
This method gets the suffer size of the model part database.
Definition: model_part.h:1876
NodeIterator NodesBegin(IndexType ThisIndex=0)
Definition: model_part.h:487
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
MeshType::NodeIterator NodeIterator
Definition: model_part.h:134
ElementIterator ElementsEnd(IndexType ThisIndex=0)
Definition: model_part.h:1179
MeshType::ElementIterator ElementIterator
Definition: model_part.h:174
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
This strategy is used to solve convection-diffusion problem.
Definition: residualbased_convdiff_strategy.h:89
BaseType::LocalSystemVectorType LocalSystemVectorType
Definition: residualbased_convdiff_strategy.h:109
void CalculateProjection()
Definition: residualbased_convdiff_strategy.h:266
void SetEchoLevel(int Level) override
This sets the level of echo for the solving strategy.
Definition: residualbased_convdiff_strategy.h:309
BaseType::TSystemVectorType TSystemVectorType
Definition: residualbased_convdiff_strategy.h:107
virtual ~ResidualBasedConvectionDiffusionStrategy()
Definition: residualbased_convdiff_strategy.h:185
BaseType::LocalSystemMatrixType LocalSystemMatrixType
Definition: residualbased_convdiff_strategy.h:111
ResidualBasedConvectionDiffusionStrategy(ModelPart &model_part, typename TLinearSolver::Pointer pNewLinearSolver, bool ReformDofAtEachIteration=true, int time_order=2, int prediction_order=2)
Definition: residualbased_convdiff_strategy.h:129
int Check() override
Function to perform expensive checks.
Definition: residualbased_convdiff_strategy.h:319
ImplicitSolvingStrategy< TSparseSpace, TDenseSpace, TLinearSolver > BaseType
Definition: residualbased_convdiff_strategy.h:97
double Solve() override
Definition: residualbased_convdiff_strategy.h:192
void Clear() override
Clears the internal storage.
Definition: residualbased_convdiff_strategy.h:314
BaseType::TSystemMatrixType TSystemMatrixType
Definition: residualbased_convdiff_strategy.h:105
BaseType::TDataType TDataType
Definition: residualbased_convdiff_strategy.h:99
BaseType::DofsArrayType DofsArrayType
Definition: residualbased_convdiff_strategy.h:103
KRATOS_CLASS_POINTER_DEFINITION(ResidualBasedConvectionDiffusionStrategy)
Definition: residualbased_elimination_builder_and_solver_componentwise.h:95
This class provides the implementation of a static scheme.
Definition: residualbased_incrementalupdate_static_scheme.h:57
This is a very simple strategy to solve linearly the problem.
Definition: residualbased_linear_strategy.h:64
This class provides the implementation of the basic tasks that are needed by the solution strategy.
Definition: scheme.h:56
TDenseSpace::MatrixType LocalSystemMatrixType
Definition: solving_strategy.h:79
virtual void InitializeSolutionStep()
Performs all the required operations that should be done (for each step) before solving the solution ...
Definition: solving_strategy.h:224
TSparseSpace::DataType TDataType
Definition: solving_strategy.h:69
ModelPart & GetModelPart()
Operations to get the pointer to the model.
Definition: solving_strategy.h:350
TSparseSpace::MatrixType TSystemMatrixType
Definition: solving_strategy.h:71
TSparseSpace::VectorType TSystemVectorType
Definition: solving_strategy.h:73
TDenseSpace::VectorType LocalSystemVectorType
Definition: solving_strategy.h:81
#define KRATOS_THROW_ERROR(ExceptionType, ErrorMessage, MoreInfo)
Definition: define.h:77
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
int time_order
Definition: ProjectParameters.py:51
list coeff
Definition: bombardelli_test.py:41
def GetSolutionStepValue(entity, variable, solution_step_index)
Definition: coupling_interface_data.py:253
model_part
Definition: face_heat.py:14
Dt
Definition: face_heat.py:78
rho
Definition: generate_droplet_dynamics.py:86
float temp
Definition: rotating_cone.py:85
integer i
Definition: TensorModule.f:17
ReformDofAtEachIteration
Definition: test_pureconvectionsolver_benchmarking.py:131