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_nonlinear.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_NONLINEAR )
13 #define KRATOS_RESIDUALBASED_CONVECTION_DIFFUSION_STRATEGY_NONLINEAR
14 
15 /* System includes */
16 
17 /* External includes */
18 
19 /* Project includes */
20 #include "includes/define.h"
21 #include "includes/model_part.h"
30 
31 
32 namespace Kratos
33 {
34 
61 
86 template<class TSparseSpace,
87  class TDenseSpace,
88  class TLinearSolver
89  >
91  : public ImplicitSolvingStrategy<TSparseSpace, TDenseSpace, TLinearSolver>
92 {
93 public:
99 
101 
102  typedef typename BaseType::TDataType TDataType;
103 
104  //typedef typename BaseType::DofSetType DofSetType;
105 
107 
109 
111 
113 
115 
116 
117 
124 
138  typename TLinearSolver::Pointer pNewLinearSolver,
139  bool ReformDofAtEachIteration = true,
140  int time_order = 2,
141  int max_iter = 30,
142  double toll = 1e-6
143  )
144  : ImplicitSolvingStrategy<TSparseSpace, TDenseSpace, TLinearSolver>(model_part, false)
145  {
146  KRATOS_TRY
147 
148  mtime_order = time_order;
149  mOldDt = 0.00;
150  mtoll = toll;
151  mmax_iter = max_iter;
152 
153  ProcessInfo& rCurrentProcessInfo = BaseType::GetModelPart().GetProcessInfo();
154  ConvectionDiffusionSettings::Pointer my_settings = rCurrentProcessInfo.GetValue(CONVECTION_DIFFUSION_SETTINGS);
155  const Variable<double>& rUnknownVar = my_settings->GetUnknownVariable();
156 
157  //initializing fractional velocity solution step
158  typedef Scheme< TSparseSpace, TDenseSpace > SchemeType;
159  typename SchemeType::Pointer pscheme = typename SchemeType::Pointer
161 
162  bool CalculateReactions = false;
163  bool CalculateNormDxFlag = true;
164 
165 
166 
167  typedef typename BuilderAndSolver<TSparseSpace, TDenseSpace, TLinearSolver>::Pointer BuilderSolverTypePointer;
168 
169  BuilderSolverTypePointer componentwise_build = BuilderSolverTypePointer(new ResidualBasedEliminationBuilderAndSolverComponentwise<TSparseSpace, TDenseSpace, TLinearSolver, Variable<double> > (pNewLinearSolver, rUnknownVar));
170  mstep1 = typename BaseType::Pointer(new ResidualBasedLinearStrategy<TSparseSpace, TDenseSpace, TLinearSolver > (
171  model_part,
172  pscheme,
173  componentwise_build,
174  CalculateReactions,
176  CalculateNormDxFlag));
177  mstep1->SetEchoLevel(2);
178 
179  Check();
180  KRATOS_CATCH("")
181  }
182 
186  {
187  }
188 
192  //*********************************************************************************
193  //**********************************************************************
194 
195  double Solve() override
196  {
197  KRATOS_TRY
198 
199  //calculate the BDF coefficients
200  ProcessInfo& rCurrentProcessInfo = BaseType::GetModelPart().GetProcessInfo();
201  double Dt = rCurrentProcessInfo[DELTA_TIME];
202  int stationary= rCurrentProcessInfo[STATIONARY];
203 
204  unsigned int iter = 0;
205  double ratio;
206  bool is_converged = false;
207  double dT_norm = 0.0;
208  double T_norm = 0.0;
209 
210  if(stationary==1){
211  iter = 0;
212  //ratio;
213  is_converged = false;
214  dT_norm = 0.0;
215  T_norm = 0.0;
216  while (iter++ < mmax_iter && is_converged == false)
217  {
218  rCurrentProcessInfo[FRACTIONAL_STEP] = 1;
219  dT_norm = mstep1->Solve();
220  T_norm = CalculateTemperatureNorm();
222 
223  ratio = 1.00;
224  if (T_norm != 0.00)
225  ratio = dT_norm / T_norm;
226  else
227  {
228  std::cout << "T_norm = " << T_norm << " dT_norm = " << dT_norm << std::endl;
229  }
230 
231  if (dT_norm < 1e-11)
232  ratio = 0; //converged
233 
234  if (ratio < mtoll)
235  is_converged = true;
236 
237  std::cout << " iter = " << iter << " ratio = " << ratio << std::endl;
238  }
239  }
240  else{
241 
242  if (mOldDt == 0.00) //needed for the first step
243  mOldDt = Dt;
244  if (mtime_order == 2)
245  {
246  if (BaseType::GetModelPart().GetBufferSize() < 3)
247  KRATOS_THROW_ERROR(std::logic_error, "insufficient buffer size for BDF2", "")
248 
249  double dt_old = rCurrentProcessInfo.GetPreviousTimeStepInfo(1)[DELTA_TIME];
250 
251  double rho = dt_old / Dt;
252  double coeff = 1.0 / (Dt * rho * rho + Dt * rho);
253 
254  rCurrentProcessInfo[BDF_COEFFICIENTS].resize(3);
255  Vector& BDFcoeffs = rCurrentProcessInfo[BDF_COEFFICIENTS];
256  BDFcoeffs[0] = coeff * (rho * rho + 2.0 * rho); //coefficient for step n+1
257  BDFcoeffs[1] = -coeff * (rho * rho + 2.0 * rho + 1.0); //coefficient for step n
258  BDFcoeffs[2] = coeff;
259  }
260  else
261  {
262  rCurrentProcessInfo[BDF_COEFFICIENTS].resize(2);
263  Vector& BDFcoeffs = rCurrentProcessInfo[BDF_COEFFICIENTS];
264  BDFcoeffs[0] = 1.0 / Dt; //coefficient for step n+1
265  BDFcoeffs[1] = -1.0 / Dt; //coefficient for step n
266  }
267 
268  iter = 0;
269  //ratio;
270  is_converged = false;
271  dT_norm = 0.0;
272  T_norm = 0.0;
273 
274  while (iter++ < mmax_iter && is_converged == false)
275  {
276  rCurrentProcessInfo[FRACTIONAL_STEP] = 1;
277  dT_norm = mstep1->Solve();
278  T_norm = CalculateTemperatureNorm();
280 
281  ratio = 1.00;
282  if (T_norm != 0.00)
283  ratio = dT_norm / T_norm;
284  else
285  {
286  std::cout << "T_norm = " << T_norm << " dT_norm = " << dT_norm << std::endl;
287  }
288 
289  if (dT_norm < 1e-11)
290  ratio = 0; //converged
291 
292  if (ratio < mtoll)
293  is_converged = true;
294 
295  std::cout << " iter = " << iter << " ratio = " << ratio << std::endl;
296  }
297  }
298 
299  return dT_norm;
300  KRATOS_CATCH("")
301  }
302  //******************************************************************************************************
303  //******************************************************************************************************
305 
307  {
308  KRATOS_TRY;
309 
310  double norm = 0.00;
311 
312  ProcessInfo& rCurrentProcessInfo = BaseType::GetModelPart().GetProcessInfo();
313  ConvectionDiffusionSettings::Pointer my_settings = rCurrentProcessInfo.GetValue(CONVECTION_DIFFUSION_SETTINGS);
314  const Variable<double>& rUnknownVar = my_settings->GetUnknownVariable();
315 
316 
317  for (ModelPart::NodeIterator i = BaseType::GetModelPart().NodesBegin();
319  {
320  norm += pow(i->FastGetSolutionStepValue(rUnknownVar), 2);
321  }
322 
323  return sqrt(norm);
324 
325  KRATOS_CATCH("")
326  }
327 
328  //******************************************************************************************************
329  //******************************************************************************************************
331 
333  {
334  KRATOS_TRY;
335 
336  ProcessInfo& rCurrentProcessInfo = BaseType::GetModelPart().GetProcessInfo();
337  const ProcessInfo& rConstCurrentProcessInfo = BaseType::GetModelPart().GetProcessInfo();
338 
339  ConvectionDiffusionSettings::Pointer my_settings = rCurrentProcessInfo.GetValue(CONVECTION_DIFFUSION_SETTINGS);
340 
341  const Variable<double>& rProjectionVariable = my_settings->GetProjectionVariable();
342 
343  //first of all set to zero the nodal variables to be updated nodally
344  for (ModelPart::NodeIterator i = BaseType::GetModelPart().NodesBegin();
346  {
347  if ((i->GetValue(NEIGHBOUR_ELEMENTS)).size() != 0)
348  {
349 
350 
351  (i)->FastGetSolutionStepValue(rProjectionVariable) = 0.00;
352  (i)->FastGetSolutionStepValue(NODAL_AREA) = 0.00;
353  }
354  else
355  {
356  (i)->FastGetSolutionStepValue(NODAL_AREA) = 1.00;
357  }
358  }
359 
360  //add the elemental contributions for the calculation of the velocity
361  //and the determination of the nodal area
362  rCurrentProcessInfo[FRACTIONAL_STEP] = 2;
365  {
366  (i)->InitializeSolutionStep(rConstCurrentProcessInfo);
367  }
368 
369  //solve nodally for the velocity
372  {
373  double& conv_proj = (i)->FastGetSolutionStepValue(rProjectionVariable);
374  double temp = 1.00 / (i)->FastGetSolutionStepValue(NODAL_AREA);
375  conv_proj *= temp;
376  }
377 
378  KRATOS_CATCH("")
379  }
380 
381  void SetEchoLevel(int Level) override
382  {
383  mstep1->SetEchoLevel(Level);
384  }
385 
386  void Clear() override
387  {
388  mstep1->Clear();
389  }
390 
391  int Check() override
392  {
393  KRATOS_TRY
394 
395  ProcessInfo& rCurrentProcessInfo = BaseType::GetModelPart().GetProcessInfo();
396  ConvectionDiffusionSettings::Pointer my_settings = rCurrentProcessInfo.GetValue(CONVECTION_DIFFUSION_SETTINGS);
397  const Variable<double>& rUnknownVar = my_settings->GetUnknownVariable();
398  const Variable<double>& rDensityVar = my_settings->GetDensityVariable();
399  const Variable<double>& rDiffusionVar = my_settings->GetDiffusionVariable();
400  const Variable<double>& rSourceVar = my_settings->GetVolumeSourceVariable();
401  const Variable<array_1d<double, 3 > >& rMeshVelocityVar = my_settings->GetMeshVelocityVariable();
402  const Variable<double>& rProjectionVariable = my_settings->GetProjectionVariable();
403 
404 
405  if (BaseType::GetModelPart().NodesBegin()->SolutionStepsDataHas(rUnknownVar) == false)
406  KRATOS_THROW_ERROR(std::logic_error, "Add ----UnknownVar---- variable!!!!!! ERROR", "");
407  if (BaseType::GetModelPart().NodesBegin()->SolutionStepsDataHas(rDensityVar) == false)
408  KRATOS_THROW_ERROR(std::logic_error, "Add ----rDensityVar---- variable!!!!!! ERROR", "");
409  if (BaseType::GetModelPart().NodesBegin()->SolutionStepsDataHas(rDiffusionVar) == false)
410  KRATOS_THROW_ERROR(std::logic_error, "Add ----rDiffusionVar---- variable!!!!!! ERROR", "");
411  if (BaseType::GetModelPart().NodesBegin()->SolutionStepsDataHas(rSourceVar) == false)
412  KRATOS_THROW_ERROR(std::logic_error, "Add ----rSourceVar---- variable!!!!!! ERROR", "");
413  if (BaseType::GetModelPart().NodesBegin()->SolutionStepsDataHas(rMeshVelocityVar) == false)
414  KRATOS_THROW_ERROR(std::logic_error, "Add ----rMeshVelocityVar---- variable!!!!!! ERROR", "");
415  if (BaseType::GetModelPart().NodesBegin()->SolutionStepsDataHas(rProjectionVariable) == false)
416  KRATOS_THROW_ERROR(std::logic_error, "Add ----rProjectionVariable---- variable!!!!!! ERROR", "");
417 
418 
419  //if(BaseType::GetModelPart().GetMesh().GetProperties(0)[EMISSIVITY] == false)
420  // KRATOS_THROW_ERROR(std::logic_error, "Add ----EMISSIVITY---- variable!!!!!! ERROR", "");
421  //if(BaseType::GetModelPart().GetMesh().GetProperties(0)[CONVECTION_COEFFICIENT] == false)
422  // KRATOS_THROW_ERROR(std::logic_error, "Add ----CONVECTION_COEFFICIENT---- variable!!!!!! ERROR", "");
423  //if(BaseType::GetModelPart().GetMesh().GetProperties(0)[AMBIENT_TEMPERATURE] == false)
424  // KRATOS_THROW_ERROR(std::logic_error, "Add ----AMBIENT_TEMPERATURE---- variable!!!!!! ERROR", "");
425 
426 
427  return 0;
428 
429  KRATOS_CATCH("")
430 
431  }
459 protected:
498 private:
506  typename BaseType::Pointer mstep1;
507  double mOldDt;
508  int mtime_order;
509  unsigned int mmax_iter;
510  double mtoll;
511 
512 
513 
514 
515 
542 
543 
546 }; /* Class ResidualBasedConvectionDiffusionStrategyNonLinear */
547 
556 } /* namespace Kratos.*/
557 
558 #endif /* KRATOS_RESIDUALBASED_CONVECTION_DIFFUSION_STRATEGY_NONLINEAR defined */
Current class provides an implementation for the base builder and solving operations.
Definition: builder_and_solver.h:64
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
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_nonlinear.h:92
double CalculateTemperatureNorm()
calculation of temperature norm
Definition: residualbased_convdiff_strategy_nonlinear.h:306
BaseType::LocalSystemMatrixType LocalSystemMatrixType
Definition: residualbased_convdiff_strategy_nonlinear.h:114
BaseType::TDataType TDataType
Definition: residualbased_convdiff_strategy_nonlinear.h:102
BaseType::TSystemVectorType TSystemVectorType
Definition: residualbased_convdiff_strategy_nonlinear.h:110
BaseType::DofsArrayType DofsArrayType
Definition: residualbased_convdiff_strategy_nonlinear.h:106
virtual ~ResidualBasedConvectionDiffusionStrategyNonLinear()
Definition: residualbased_convdiff_strategy_nonlinear.h:185
ResidualBasedConvectionDiffusionStrategyNonLinear(ModelPart &model_part, typename TLinearSolver::Pointer pNewLinearSolver, bool ReformDofAtEachIteration=true, int time_order=2, int max_iter=30, double toll=1e-6)
Constructor.
Definition: residualbased_convdiff_strategy_nonlinear.h:136
int Check() override
Function to perform expensive checks.
Definition: residualbased_convdiff_strategy_nonlinear.h:391
BaseType::LocalSystemVectorType LocalSystemVectorType
Definition: residualbased_convdiff_strategy_nonlinear.h:112
void SetEchoLevel(int Level) override
This sets the level of echo for the solving strategy.
Definition: residualbased_convdiff_strategy_nonlinear.h:381
void Clear() override
Clears the internal storage.
Definition: residualbased_convdiff_strategy_nonlinear.h:386
KRATOS_CLASS_POINTER_DEFINITION(ResidualBasedConvectionDiffusionStrategyNonLinear)
ImplicitSolvingStrategy< TSparseSpace, TDenseSpace, TLinearSolver > BaseType
Definition: residualbased_convdiff_strategy_nonlinear.h:100
void CalculateProjection()
calculation of projection
Definition: residualbased_convdiff_strategy_nonlinear.h:332
double Solve() override
Definition: residualbased_convdiff_strategy_nonlinear.h:195
BaseType::TSystemMatrixType TSystemMatrixType
Definition: residualbased_convdiff_strategy_nonlinear.h:108
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
model_part
Definition: face_heat.py:14
Dt
Definition: face_heat.py:78
rho
Definition: generate_droplet_dynamics.py:86
int max_iter
Definition: hinsberg_optimization.py:139
float temp
Definition: rotating_cone.py:85
integer i
Definition: TensorModule.f:17
ReformDofAtEachIteration
Definition: test_pureconvectionsolver_benchmarking.py:131
e
Definition: run_cpp_mpi_tests.py:31