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_stokes_initialization_process.h
Go to the documentation of this file.
1 #ifndef KRATOS_TRILINOS_STOKES_INITIALIZATION_PROCESS_H
2 #define KRATOS_TRILINOS_STOKES_INITIALIZATION_PROCESS_H
3 
4 // System includes
5 
6 // External includes
7 #include "Epetra_MpiComm.h"
8 
9 // Project includes
10 
11 // Application includes
12 #include "containers/model.h"
17 
18 #include "../FluidDynamicsApplication/custom_processes/stokes_initialization_process.h"
19 
20 namespace Kratos
21 {
24 
27 
31 
35 
39 
43 
45 
50 template<class TSparseSpace,
51  class TDenseSpace,
52  class TLinearSolver
53  >
54 class TrilinosStokesInitializationProcess : public StokesInitializationProcess<TSparseSpace,TDenseSpace,TLinearSolver>
55 {
56 public:
59 
62 
64 
68 
69  TrilinosStokesInitializationProcess(Epetra_MpiComm& rComm,
70  ModelPart& rModelPart,
71  typename TLinearSolver::Pointer pLinearSolver,
72  unsigned int DomainSize,
73  const Variable<int>& PeriodicPairIndicesVar):
74  BaseType(rModelPart,pLinearSolver,DomainSize,this),
75  mrComm(rComm),
76  mrPeriodicVar(PeriodicPairIndicesVar)
77  {
78  KRATOS_TRY;
79 
80  ModelPart& rReferenceModelPart = BaseType::mrReferenceModelPart;
81  typename TLinearSolver::Pointer& pBaseLinearSolver = BaseType::mpLinearSolver;
82  unsigned int BaseDomainSize = BaseType::mDomainSize;
84 
85  // Initialize new model part (same nodes, new elements, no conditions)
86  if(rModelPart.GetModel().HasModelPart("StokesModelPart"))
87  rModelPart.GetModel().DeleteModelPart("StokesModelPart");
88  ModelPart& rStokesModelPart = rModelPart.GetModel().CreateModelPart("StokesModelPart");
89  rStokesModelPart.GetNodalSolutionStepVariablesList() = rReferenceModelPart.GetNodalSolutionStepVariablesList();
90  rStokesModelPart.SetBufferSize(1);
91  rStokesModelPart.SetNodes( rReferenceModelPart.pNodes() );
92  rStokesModelPart.SetProcessInfo( rReferenceModelPart.pGetProcessInfo() );
93  rStokesModelPart.SetProperties( rReferenceModelPart.pProperties() );
94 
95  // Create a communicator for the new model part and copy the partition information about nodes.
96  Communicator& rReferenceComm = rReferenceModelPart.GetCommunicator();
97  typename Communicator::Pointer pStokesMPIComm = Kratos::make_shared<MPICommunicator>( &(rReferenceModelPart.GetNodalSolutionStepVariablesList()) );
98  pStokesMPIComm->SetNumberOfColors( rReferenceComm.GetNumberOfColors() ) ;
99  pStokesMPIComm->NeighbourIndices() = rReferenceComm.NeighbourIndices();
100  pStokesMPIComm->LocalMesh().SetNodes( rReferenceComm.LocalMesh().pNodes() );
101  pStokesMPIComm->InterfaceMesh().SetNodes( rReferenceComm.InterfaceMesh().pNodes() );
102  pStokesMPIComm->GhostMesh().SetNodes( rReferenceComm.GhostMesh().pNodes() );
103  for (unsigned int i = 0; i < rReferenceComm.GetNumberOfColors(); i++)
104  {
105  pStokesMPIComm->pInterfaceMesh(i)->SetNodes( rReferenceComm.pInterfaceMesh(i)->pNodes() );
106  pStokesMPIComm->pLocalMesh(i)->SetNodes( rReferenceComm.pLocalMesh(i)->pNodes() );
107  pStokesMPIComm->pGhostMesh(i)->SetNodes( rReferenceComm.pGhostMesh(i)->pNodes() );
108  }
109  rStokesModelPart.SetCommunicator( pStokesMPIComm );
110 
111  // Retrieve Stokes element model
112  std::string ElementName;
113  if (BaseDomainSize == 2)
114  ElementName = std::string("StationaryStokes2D");
115  else
116  ElementName = std::string("StationaryStokes3D");
117 
118  const Element& rReferenceElement = KratosComponents<Element>::Get(ElementName);
119 
120  // Generate Stokes elements
121  for (ModelPart::ElementsContainerType::iterator itElem = rReferenceModelPart.ElementsBegin(); itElem != rReferenceModelPart.ElementsEnd(); itElem++)
122  {
123  Element::Pointer pElem = rReferenceElement.Create(itElem->Id(), itElem->GetGeometry(), itElem->pGetProperties() );
124  rStokesModelPart.Elements().push_back(pElem);
125  rStokesModelPart.GetCommunicator().LocalMesh().Elements().push_back(pElem);
126  }
127 
128  // Solution scheme: Linear static scheme
129  auto pScheme = Kratos::make_shared< ResidualBasedIncrementalUpdateStaticScheme< TSparseSpace, TDenseSpace > >();
130 
131  // Builder and solver
132  int guess_row_size;
133  if(BaseDomainSize == 2)
134  guess_row_size = 15;
135  else
136  guess_row_size = 40;
137 
138  auto pBuildAndSolver = Kratos::make_shared<TrilinosBlockBuilderAndSolverPeriodic<TSparseSpace,TDenseSpace,TLinearSolver> >(
139  mrComm,
140  guess_row_size,
141  pBaseLinearSolver,
143  );
144 
145  // Strategy
146  bool ReactionFlag = false;
147  bool ReformDofSetFlag = false;
148  bool CalculateNormDxFlag = false;
149  bool MoveMeshFlag = false;
150 
151  pSolutionStrategy = Kratos::make_shared< ResidualBasedLinearStrategy<TSparseSpace, TDenseSpace, TLinearSolver> >(
152  rStokesModelPart,
153  pScheme,
154  pBuildAndSolver,
155  ReactionFlag,
156  ReformDofSetFlag,
157  CalculateNormDxFlag,
158  MoveMeshFlag
159  );
160 
161  pSolutionStrategy->SetEchoLevel(0);
162  pSolutionStrategy->Check();
163 
164  BaseType::mIsCleared = false;
165 
166  KRATOS_CATCH("");
167  }
168 
170 
172  {
174  }
175 
176 
180 
181 
185 
186 
190 
191 
195 
196 
200 
202 
203  std::string Info() const override
204  {
205  std::stringstream buffer;
206  buffer << " TrilinosStokesInitializationProcess";
207  return buffer.str();
208  }
209 
211 
212  void PrintInfo(std::ostream& rOStream) const override
213  {
214  rOStream << " TrilinosStokesInitializationProcess";
215  }
216 
218 
219  void PrintData(std::ostream& rOStream) const override
220  {
221  }
222 
223 
227 
228 
230 
231 protected:
234 
235 
239 
240  Epetra_MpiComm& mrComm;
241 
243 
247 
248 
252 
253 
257 
258 
262 
263 
267 
269 
270 private:
273 
274 
278 
279 
283 
284 
288 
289 
293 
294 
298 
299 
303 
305 
307  {
308  return *this;
309  }
310 
312 
314  { }
315 
316 
318 
319 }; // Class TrilinosStokesInitializationProcess
320 
322 
325 
326 
330 
331 
333 
334 template<class TSparseSpace,
335  class TDenseSpace,
336  class TLinearSolver
337  >
338 inline std::istream & operator >>(std::istream& rIStream,
340 {
341  return rIStream;
342 }
343 
345 
346 template<class TSparseSpace,
347  class TDenseSpace,
348  class TLinearSolver
349  >
350 inline std::ostream & operator <<(std::ostream& rOStream,
352 {
353  rThis.PrintInfo(rOStream);
354  rOStream << std::endl;
355  rThis.PrintData(rOStream);
356 
357  return rOStream;
358 }
360 
362 
363 } // namespace Kratos.
364 
365 #endif // KRATOS_TRILINOS_STOKES_INITIALIZATION_PROCESS_H
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
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 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
NodesContainerType::Pointer pNodes()
Definition: mesh.h:356
ElementsContainerType & Elements()
Definition: mesh.h:568
ModelPart & CreateModelPart(const std::string &ModelPartName, IndexType NewBufferSize=1)
This method creates a new model part contained in the current Model with a given name and buffer size...
Definition: model.cpp:37
void DeleteModelPart(const std::string &ModelPartName)
This method deletes a modelpart with a given name.
Definition: model.cpp:64
bool HasModelPart(const std::string &rFullModelPartName) const
This method checks if a certain a model part exists given a certain name.
Definition: model.cpp:178
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
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
ProcessInfo::Pointer pGetProcessInfo()
Definition: model_part.h:1756
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
NodesContainerType::Pointer pNodes(IndexType ThisIndex=0)
Definition: model_part.h:517
ElementsContainerType & Elements(IndexType ThisIndex=0)
Definition: model_part.h:1189
PropertiesContainerType::Pointer pProperties(IndexType ThisIndex=0)
Definition: model_part.h:1008
ElementIterator ElementsEnd(IndexType ThisIndex=0)
Definition: model_part.h:1179
Model & GetModel()
Definition: model_part.h:323
VariablesList & GetNodalSolutionStepVariablesList()
Definition: model_part.h:549
void push_back(TPointerType x)
Adds a pointer to the end of the set.
Definition: pointer_vector_set.h:544
virtual void SetEchoLevel(const int Level)
This sets the level of echo for the solving strategy.
Definition: solving_strategy.h:255
virtual int Check()
Function to perform expensive checks.
Definition: solving_strategy.h:377
A process to provide initial values for Navier-Stokes problems.
Definition: stokes_initialization_process.h:58
ImplicitSolvingStrategy< TSparseSpace, TDenseSpace, TLinearSolver >::Pointer mpSolutionStrategy
Definition: stokes_initialization_process.h:248
TLinearSolver::Pointer mpLinearSolver
Definition: stokes_initialization_process.h:244
ModelPart & mrReferenceModelPart
Definition: stokes_initialization_process.h:242
bool mIsCleared
Definition: stokes_initialization_process.h:250
unsigned int mDomainSize
Definition: stokes_initialization_process.h:246
A process to provide initial values for Navier-Stokes problems.
Definition: trilinos_stokes_initialization_process.h:55
std::string Info() const override
Turn back information as a string.
Definition: trilinos_stokes_initialization_process.h:203
TrilinosStokesInitializationProcess(Epetra_MpiComm &rComm, ModelPart &rModelPart, typename TLinearSolver::Pointer pLinearSolver, unsigned int DomainSize, const Variable< int > &PeriodicPairIndicesVar)
Definition: trilinos_stokes_initialization_process.h:69
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: trilinos_stokes_initialization_process.h:219
StokesInitializationProcess< TSparseSpace, TDenseSpace, TLinearSolver > BaseType
Definition: trilinos_stokes_initialization_process.h:63
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: trilinos_stokes_initialization_process.h:212
Epetra_MpiComm & mrComm
Definition: trilinos_stokes_initialization_process.h:240
const Variable< int > & mrPeriodicVar
Definition: trilinos_stokes_initialization_process.h:242
virtual ~TrilinosStokesInitializationProcess()
Destructor.
Definition: trilinos_stokes_initialization_process.h:171
KRATOS_CLASS_POINTER_DEFINITION(TrilinosStokesInitializationProcess)
Pointer definition of TrilinosStokesInitializationProcess.
#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
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