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.
trilinos_spalart_allmaras_turbulence_model.h
Go to the documentation of this file.
1 //
2 // Project Name: Kratos
3 // Last Modified by: $Author: jcotela $
4 // Date: $Date: 2011-07-22 17:06:00 $
5 // Revision: $Revision: 1.0 $
6 //
7 //
8 
9 #if !defined(KRATOS_TRILINOS_SPALART_ALLMARAS_H_INCLUDED )
10 #define KRATOS_TRILINOS_SPALART_ALLMARAS_H_INCLUDED
11 
12 // System includes
13 
14 // External includes
15 #include "Epetra_MpiComm.h"
16 
17 // Project includes
20 
21 // Application includes
26 
28 
29 namespace Kratos
30 {
33 
36 
40 
44 
48 
52 
54 
56 template<class TSparseSpace,
57  class TDenseSpace,
58  class TLinearSolver
59  >
60 class TrilinosSpalartAllmarasTurbulenceModel : public SpalartAllmarasTurbulenceModel<TSparseSpace,TDenseSpace,TLinearSolver>
61 {
62 public:
65 
68 
70 
74 
77  ModelPart& rModelPart,
78  typename TLinearSolver::Pointer pLinearSolver,
79  unsigned int DomainSize,
80  double NonLinearTol,
81  unsigned int MaxIter,
82  bool ReformDofSet,
83  unsigned int TimeOrder)
84  :
85  BaseSpAlType(rModelPart)
86  {
87  KRATOS_TRY;
88 
89  BaseSpAlType::mdomain_size = DomainSize;
90  BaseSpAlType::mtol = NonLinearTol;
91  BaseSpAlType::mmax_it = MaxIter;
92  BaseSpAlType::mtime_order = TimeOrder;
94 
95  //************************************************************************************************
96  //check that the variables needed are in the model part
97  if (!(BaseSpAlType::mr_model_part.NodesBegin()->SolutionStepsDataHas(DISTANCE)))
98  KRATOS_THROW_ERROR(std::logic_error, "Variable is not in the model part:", DISTANCE);
99  if (!(BaseSpAlType::mr_model_part.NodesBegin()->SolutionStepsDataHas(VELOCITY)))
100  KRATOS_THROW_ERROR(std::logic_error, "Variable is not in the model part:", VELOCITY);
101  if (!(BaseSpAlType::mr_model_part.NodesBegin()->SolutionStepsDataHas(MOLECULAR_VISCOSITY)))
102  KRATOS_THROW_ERROR(std::logic_error, "Variable is not in the model part:", MOLECULAR_VISCOSITY);
103  if (!(BaseSpAlType::mr_model_part.NodesBegin()->SolutionStepsDataHas(TURBULENT_VISCOSITY)))
104  KRATOS_THROW_ERROR(std::logic_error, "Variable is not in the model part:", TURBULENT_VISCOSITY);
105  if (!(BaseSpAlType::mr_model_part.NodesBegin()->SolutionStepsDataHas(MESH_VELOCITY)))
106  KRATOS_THROW_ERROR(std::logic_error, "Variable is not in the model part:", MESH_VELOCITY);
107  if (!(BaseSpAlType::mr_model_part.NodesBegin()->SolutionStepsDataHas(VISCOSITY)))
108  KRATOS_THROW_ERROR(std::logic_error, "Variable is not in the model part:", VISCOSITY);
109  if (!(BaseSpAlType::mr_model_part.NodesBegin()->SolutionStepsDataHas(NODAL_AREA)))
110  KRATOS_THROW_ERROR(std::logic_error, "Variable is not in the model part:", NODAL_AREA);
111  if (!(BaseSpAlType::mr_model_part.NodesBegin()->SolutionStepsDataHas(TEMP_CONV_PROJ)))
112  KRATOS_THROW_ERROR(std::logic_error, "Variable is not in the model part:", TEMP_CONV_PROJ);
113  if (!(BaseSpAlType::mr_model_part.NodesBegin()->SolutionStepsDataHas(PARTITION_INDEX)))
114  KRATOS_THROW_ERROR(std::logic_error, "Variable is not in the model part:", PARTITION_INDEX);
115 
116  if (BaseSpAlType::mr_model_part.GetBufferSize() < 3)
117  KRATOS_THROW_ERROR(std::logic_error, "insufficient buffer size for BDF2, currently buffer size is ", BaseSpAlType::mr_model_part.GetBufferSize());
118 
119  //************************************************************************************************
120  //construct a new auxiliary model part
127 
128  // Create a communicator for the new model part and copy the partition information about nodes.
130  typename Communicator::Pointer pSpalartMPIComm = typename Communicator::Pointer( new MPICommunicator(&(BaseSpAlType::mr_model_part.GetNodalSolutionStepVariablesList()), rReferenceComm.GetDataCommunicator()));
131  pSpalartMPIComm->SetNumberOfColors( rReferenceComm.GetNumberOfColors() ) ;
132  pSpalartMPIComm->NeighbourIndices() = rReferenceComm.NeighbourIndices();
133  pSpalartMPIComm->LocalMesh().SetNodes( rReferenceComm.LocalMesh().pNodes() );
134  pSpalartMPIComm->InterfaceMesh().SetNodes( rReferenceComm.InterfaceMesh().pNodes() );
135  pSpalartMPIComm->GhostMesh().SetNodes( rReferenceComm.GhostMesh().pNodes() );
136  for (unsigned int i = 0; i < rReferenceComm.GetNumberOfColors(); i++)
137  {
138  pSpalartMPIComm->pInterfaceMesh(i)->SetNodes( rReferenceComm.pInterfaceMesh(i)->pNodes() );
139  pSpalartMPIComm->pLocalMesh(i)->SetNodes( rReferenceComm.pLocalMesh(i)->pNodes() );
140  pSpalartMPIComm->pGhostMesh(i)->SetNodes( rReferenceComm.pGhostMesh(i)->pNodes() );
141  }
143 
144  std::string ElementName;
146  ElementName = std::string("SpalartAllmaras2D");
147  else
148  ElementName = std::string("SpalartAllmaras3D");
149 
150  const Element& rReferenceElement = KratosComponents<Element>::Get(ElementName);
151 
152  //generating the elements
153  for (ModelPart::ElementsContainerType::iterator iii = BaseSpAlType::mr_model_part.ElementsBegin(); iii != BaseSpAlType::mr_model_part.ElementsEnd(); iii++)
154  {
155  Properties::Pointer properties = iii->pGetProperties();
156  Element::Pointer p_element = rReferenceElement.Create(iii->Id(), iii->GetGeometry(), properties);
157  BaseSpAlType::mrSpalartModelPart.Elements().push_back(p_element);
158  }
159 
160  std::string ConditionName;
162  ConditionName = std::string("LineCondition2D2N");
163  else
164  ConditionName = std::string("SurfaceCondition3D3N");
165  const Condition& rReferenceCondition = KratosComponents<Condition>::Get(ConditionName);
166 
167  for (ModelPart::ConditionsContainerType::iterator iii = BaseSpAlType::mr_model_part.ConditionsBegin(); iii != BaseSpAlType::mr_model_part.ConditionsEnd(); iii++)
168  {
169  Properties::Pointer properties = iii->pGetProperties();
170  Condition::Pointer p_condition = rReferenceCondition.Create(iii->Id(), iii->GetGeometry(), properties);
171  BaseSpAlType::mrSpalartModelPart.Conditions().push_back(p_condition);
172  }
173 
174  // Create a communicator for the new model part
175  ParallelFillCommunicator CommunicatorGeneration(BaseSpAlType::mrSpalartModelPart, BaseSpAlType::mrSpalartModelPart.GetCommunicator().GetDataCommunicator());
176  CommunicatorGeneration.Execute();
177  //CommunicatorGeneration.PrintDebugInfo()
178 
179  // pointer types for the solution strategy construcion
180  typedef typename Scheme< TSparseSpace, TDenseSpace >::Pointer SchemePointerType;
181  typedef typename ConvergenceCriteria< TSparseSpace, TDenseSpace >::Pointer ConvergenceCriteriaPointerType;
182  typedef typename BuilderAndSolver<TSparseSpace, TDenseSpace, TLinearSolver>::Pointer BuilderSolverTypePointer;
184 
185  // Solution scheme: Aitken iterations
186  const double DefaultAitkenOmega = 1.0;
187  SchemePointerType pScheme = SchemePointerType( new TrilinosResidualBasedIncrementalAitkenStaticScheme< TSparseSpace, TDenseSpace > (DefaultAitkenOmega) );
188 
189  // Convergence criteria
190  const double NearlyZero = 1.0e-20;
191  ConvergenceCriteriaPointerType pConvCriteria = ConvergenceCriteriaPointerType( new ResidualCriteria<TSparseSpace,TDenseSpace>(NonLinearTol,NearlyZero) );
192 
193  //definitions for trilinos
194  int guess_row_size;
195  if(BaseSpAlType::mdomain_size == 2) guess_row_size = 15;
196  else guess_row_size = 40;
197 
198  // Builder and solver
199  BuilderSolverTypePointer pBuildAndSolver = BuilderSolverTypePointer(new TrilinosResidualBasedEliminationBuilderAndSolver<TSparseSpace,TDenseSpace,TLinearSolver> (rComm,guess_row_size,pLinearSolver));
200 
201  // Strategy
202  bool CalculateReactions = false;
203  bool MoveMesh = false;
204 
205  BaseSpAlType::mpSolutionStrategy = StrategyPointerType( new ResidualBasedNewtonRaphsonStrategy<TSparseSpace, TDenseSpace, TLinearSolver>(BaseSpAlType::mrSpalartModelPart,pScheme,pConvCriteria,pBuildAndSolver,MaxIter,CalculateReactions,ReformDofSet,MoveMesh));
206  BaseSpAlType::mpSolutionStrategy->SetEchoLevel(0);
208 
209  KRATOS_CATCH("");
210  }
211 
214  {}
215 
219 
220 
224 
225 
229 
230 
234 
235 
239 
241  std::string Info() const override
242  {
243  std::stringstream buffer;
244  buffer << "TrilinosSpalartAllmarasTurbulenceModel";
245  return buffer.str();
246  }
247 
249  void PrintInfo(std::ostream& rOStream) const override
250  {
251  rOStream << "TrilinosSpalartAllmarasTurbulenceModel";
252  }
253 
255  void PrintData(std::ostream& rOStream) const override
256  {
257  }
258 
259 
263 
264 
266 
267 protected:
270 
271 
275 
276 
280 
281 
285 
287  virtual void SolutionStrategyConfiguration(ModelPart& rSpalartModelPart,
288  typename TLinearSolver::Pointer pNewLinearSolver,
289  bool reform_dofset)
290  {
291 
292  }
293 
297 
298 
302 
303 
307 
308 
310 
311 private:
314 
315 
319 
320 
324 
328 
329 
333 
334 
338 
339 
343 
346  {
347  BaseSpAlType::operator=(rOther);
348  return *this;
349  }
350 
353  : BaseSpAlType(rOther)
354  {
355  }
356 
357 
359 
360 }; // Class SpalartAllmarasTurbulenceModel
361 
363 
366 
367 
371 
372 
374 template<class TSparseSpace,
375  class TDenseSpace,
376  class TLinearSolver
377  >
378 inline std::istream & operator >>(std::istream& rIStream,
380 {
381  return rIStream;
382 }
383 
385 template<class TSparseSpace,
386  class TDenseSpace,
387  class TLinearSolver
388  >
389 inline std::ostream & operator <<(std::ostream& rOStream,
391 {
392  rThis.PrintInfo(rOStream);
393  rOStream << std::endl;
394  rThis.PrintData(rOStream);
395 
396  return rOStream;
397 }
399 
401 
402 } // namespace Kratos.
403 
404 #endif // KRATOS_TRILINOS_SPALART_ALLMARAS_H_INCLUDED defined
405 
406 
Current class provides an implementation for the base builder and solving operations.
Definition: builder_and_solver.h:64
The Commmunicator class manages communication for distributed ModelPart instances.
Definition: communicator.h:67
NeighbourIndicesContainerType & NeighbourIndices()
Definition: communicator.cpp:162
MeshType & GhostMesh()
Returns the reference to the mesh storing all ghost entities.
Definition: communicator.cpp:251
MeshType::Pointer pInterfaceMesh()
Returns pointer to the mesh storing all interface entities.
Definition: communicator.cpp:191
SizeType GetNumberOfColors() const
Definition: communicator.cpp:121
MeshType::Pointer pLocalMesh()
Returns pointer to the mesh storing all local entities.
Definition: communicator.cpp:179
virtual const DataCommunicator & GetDataCommunicator() const
Definition: communicator.cpp:340
MeshType & InterfaceMesh()
Returns the reference to the mesh storing all interface entities.
Definition: communicator.cpp:257
MeshType & LocalMesh()
Returns the reference to the mesh storing all local entities.
Definition: communicator.cpp:245
MeshType::Pointer pGhostMesh()
Returns pointer to the mesh storing all ghost entities.
Definition: communicator.cpp:185
Base class for all Conditions.
Definition: condition.h:59
virtual Pointer Create(IndexType NewId, NodesArrayType const &ThisNodes, PropertiesType::Pointer pProperties) const
It creates a new condition pointer.
Definition: condition.h:205
This is the base class to define the different convergence criterion considered.
Definition: convergence_criteria.h:58
Base class for all Elements.
Definition: element.h:60
virtual Pointer Create(IndexType NewId, NodesArrayType const &ThisNodes, PropertiesType::Pointer pProperties) const
It creates a new element pointer.
Definition: element.h:202
Implicit solving strategy base class This is the base class from which we will derive all the implici...
Definition: implicit_solving_strategy.h:61
static const TComponentType & Get(const std::string &rName)
Retrieves a component with the specified name.
Definition: kratos_components.h:114
MPICommunicator manages the transfer of ModelPart data in MPI distributed memory environment.
Definition: mpi_communicator.h:569
NodesContainerType::Pointer pNodes()
Definition: mesh.h:356
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
void SetCommunicator(Communicator::Pointer pNewCommunicator)
Definition: model_part.h:1836
void SetNodes(NodesContainerType::Pointer pOtherNodes, IndexType ThisIndex=0)
Definition: model_part.h:522
void SetProcessInfo(ProcessInfo::Pointer pNewProcessInfo)
Definition: model_part.h:1766
void SetProperties(PropertiesContainerType::Pointer pOtherProperties, IndexType ThisIndex=0)
Definition: model_part.h:1013
Communicator & GetCommunicator()
Definition: model_part.h:1821
void SetBufferSize(IndexType NewBufferSize)
This method sets the suffer size of the model part database.
Definition: model_part.cpp:2171
ConditionsContainerType & Conditions(IndexType ThisIndex=0)
Definition: model_part.h:1381
ElementsContainerType & Elements(IndexType ThisIndex=0)
Definition: model_part.h:1189
ElementIterator ElementsEnd(IndexType ThisIndex=0)
Definition: model_part.h:1179
VariablesList & GetNodalSolutionStepVariablesList()
Definition: model_part.h:549
ConditionIterator ConditionsEnd(IndexType ThisIndex=0)
Definition: model_part.h:1371
This function recomputes the communication plan for MPI.
Definition: parallel_fill_communicator.h:56
void Execute() override
Execute the communicator fill.
Definition: parallel_fill_communicator.cpp:39
This is the base Newton Raphson strategy.
Definition: residualbased_newton_raphson_strategy.h:66
This is a convergence criteria that considers the residual as criteria.
Definition: residual_criteria.h:60
This class provides the implementation of the basic tasks that are needed by the solution strategy.
Definition: scheme.h:56
An impelementation of the Spalart-Allmaras turbulence model for incompressible flows.
Definition: spalart_allmaras_turbulence_model.h:77
unsigned int mdomain_size
Definition: spalart_allmaras_turbulence_model.h:366
double mtol
Definition: spalart_allmaras_turbulence_model.h:367
unsigned int mmax_it
Definition: spalart_allmaras_turbulence_model.h:368
bool madapt_for_fractional_step
Definition: spalart_allmaras_turbulence_model.h:370
ModelPart & mrSpalartModelPart
Definition: spalart_allmaras_turbulence_model.h:365
unsigned int mtime_order
Definition: spalart_allmaras_turbulence_model.h:369
ImplicitSolvingStrategy< TSparseSpace, TDenseSpace, TLinearSolver >::Pointer mpSolutionStrategy
Definition: spalart_allmaras_turbulence_model.h:371
ModelPart & mr_model_part
Definition: spalart_allmaras_turbulence_model.h:364
Definition: trilinos_elimination_builder_and_solver.h:117
A scheme for the solution of a problem using Aitken iterations.
Definition: trilinos_residualbased_incremental_aitken_static_scheme.h:54
Trilinos implementation of the Spalart-Allmaras turbulence model.
Definition: trilinos_spalart_allmaras_turbulence_model.h:61
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: trilinos_spalart_allmaras_turbulence_model.h:255
virtual ~TrilinosSpalartAllmarasTurbulenceModel()
Destructor.
Definition: trilinos_spalart_allmaras_turbulence_model.h:213
SpalartAllmarasTurbulenceModel< TSparseSpace, TDenseSpace, TLinearSolver > BaseSpAlType
Definition: trilinos_spalart_allmaras_turbulence_model.h:69
std::string Info() const override
Turn back information as a string.
Definition: trilinos_spalart_allmaras_turbulence_model.h:241
KRATOS_CLASS_POINTER_DEFINITION(TrilinosSpalartAllmarasTurbulenceModel)
Pointer definition of TrilinosSpalartAllmarasTurbulenceModel.
virtual void SolutionStrategyConfiguration(ModelPart &rSpalartModelPart, typename TLinearSolver::Pointer pNewLinearSolver, bool reform_dofset)
Initialize a Trilinos Solution Strategy for the Spalart Allmaras turbulence model.
Definition: trilinos_spalart_allmaras_turbulence_model.h:287
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: trilinos_spalart_allmaras_turbulence_model.h:249
TrilinosSpalartAllmarasTurbulenceModel(Epetra_MpiComm &rComm, ModelPart &rModelPart, typename TLinearSolver::Pointer pLinearSolver, unsigned int DomainSize, double NonLinearTol, unsigned int MaxIter, bool ReformDofSet, unsigned int TimeOrder)
Constructor.
Definition: trilinos_spalart_allmaras_turbulence_model.h:76
#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
void MoveMesh(Scheme< SparseSpaceType, LocalSpaceType > &dummy, ModelPart::NodesContainerType &rNodes)
Definition: add_strategies_to_python.cpp:175
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
integer i
Definition: TensorModule.f:17