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_structural_meshmoving_strategy.h
Go to the documentation of this file.
1 // | / |
2 // ' / __| _` | __| _ \ __|
3 // . \ | ( | | ( |\__ `
4 // _|\_\_| \__,_|\__|\___/ ____/
5 // Multi-Physics
6 //
7 // License: BSD License
8 // Kratos default license:
9 //kratos/license.txt
10 //
11 // Main authors: Andreas Winterstein (a.winterstein@tum.de)
12 //
13 
14 #if !defined(KRATOS_TRILINOS_STRUCTURAL_MESHMOVING_STRATEGY)
15 #define KRATOS_TRILINOS_STRUCTURAL_MESHMOVING_STRATEGY
16 
17 /* System includes */
18 
19 /* External includes */
20 
21 /* Project includes */
22 #include "includes/model_part.h"
23 #include "containers/model.h"
29 
30 /* Trilinos includes */
32 
33 namespace Kratos
34 {
56 
59 template <class TSparseSpace,
60  class TDenseSpace, //= DenseSpace<double>,
61  class TLinearSolver //= LinearSolver<TSparseSpace,TDenseSpace>
62  >
64  : public ImplicitSolvingStrategy<TSparseSpace, TDenseSpace, TLinearSolver>
65 {
66 public:
72 
74 
76 
86  typename TLinearSolver::Pointer pNewLinearSolver,
87  int TimeOrder = 2,
88  bool ReformDofSetAtEachStep = false,
89  bool ComputeReactions = false,
90  bool CalculateMeshVelocities = true,
91  int EchoLevel = 0)
92  :
93  ImplicitSolvingStrategy<TSparseSpace, TDenseSpace, TLinearSolver>(model_part),
94  mrReferenceModelPart(model_part)
95  {
97 
98  if(mrReferenceModelPart.GetModel().HasModelPart(mrReferenceModelPart.Name()+"_StructuralMeshMovingPart"))
99  KRATOS_ERROR << "StructuralMeshMovingPart already existing when constructing TrilinosLaplacianMeshMovingStrategy";
100 
101  // Passed variables
102  m_reform_dof_set_at_each_step = ReformDofSetAtEachStep;
103  m_compute_reactions = ComputeReactions;
104  m_calculate_mesh_velocities = CalculateMeshVelocities;
105  m_echo_level = EchoLevel;
106  m_time_order = TimeOrder;
107  bool calculate_norm_dx_flag = false;
108 
109  // Definitions for trilinos
110  int guess_row_size;
111  guess_row_size = 15;
112 
113  // Generating Mesh Part
114  GenerateMeshPart();
115 
116  typename SchemeType::Pointer pscheme = typename SchemeType::Pointer(
118 
119  typedef typename BuilderAndSolver<TSparseSpace, TDenseSpace, TLinearSolver>::Pointer BuilderSolverTypePointer;
120  BuilderSolverTypePointer builderSolver = BuilderSolverTypePointer(
122  Communicator, guess_row_size, pNewLinearSolver));
123 
124  mstrategy = typename BaseType::Pointer(
126  *mpmesh_model_part,
127  pscheme,
128  builderSolver,
129  m_compute_reactions,
130  m_reform_dof_set_at_each_step,
131  calculate_norm_dx_flag));
132 
133  mstrategy->SetEchoLevel(m_echo_level);
134 
135  KRATOS_CATCH("")
136  }
137 
141  {
142  mrReferenceModelPart.GetModel().DeleteModelPart(mrReferenceModelPart.Name()+"_StructuralMeshMovingPart");
143  }
144 
148  void Initialize() override
149  {}
150 
151  double Solve() override
152  {
153  KRATOS_TRY;
154 
155  // Setting mesh to initial configuration
156  for (ModelPart::NodeIterator i = (*mpmesh_model_part).NodesBegin();
157  i != (*mpmesh_model_part).NodesEnd();
158  ++i)
159  {
160  (i)->X() = (i)->X0();
161  (i)->Y() = (i)->Y0();
162  (i)->Z() = (i)->Z0();
163  }
164 
165  // Solve for mesh movement
166  mstrategy->Solve();
167 
168  // Clearing the system if needed
169  if (m_reform_dof_set_at_each_step == true)
170  mstrategy->Clear();
171 
172  return 0.0;
173 
174  KRATOS_CATCH("")
175  }
176 
200 protected:
230 private:
237  ModelPart& mrReferenceModelPart;
238  ModelPart* mpmesh_model_part;
239 
240  typename BaseType::Pointer mstrategy;
241 
242  int m_echo_level;
243  int m_time_order;
244  bool m_reform_dof_set_at_each_step;
245  bool m_compute_reactions;
246  bool m_calculate_mesh_velocities;
247 
256  void GenerateMeshPart()
257  {
258  if(!mrReferenceModelPart.GetModel().HasModelPart(mrReferenceModelPart.Name()+"_StructuralMeshMovingPart"))
259  mrReferenceModelPart.GetModel().DeleteModelPart(mrReferenceModelPart.Name()+"_StructuralMeshMovingPart");
260 
261  mpmesh_model_part = &mrReferenceModelPart.GetModel().CreateModelPart(mrReferenceModelPart.Name()+"_StructuralMeshMovingPart");
262 
263  // Initializing mesh nodes
264  mpmesh_model_part->Nodes() = BaseType::GetModelPart().Nodes();
265 
266  // Creating mesh elements
267  ModelPart::ElementsContainerType& MeshElems = mpmesh_model_part->Elements();
268  // this works for multiple geometries because we use the
269  // element's Create() member function that accepts a geometry
270  // pointer
271  const Element& rElem =
272  KratosComponents<Element>::Get("StructuralMeshMovingElement3D4N");
273 
274  for (auto it = BaseType::GetModelPart().ElementsBegin();
276  ++it)
277  MeshElems.push_back(rElem.Create(
278  it->Id(), it->pGetGeometry(), it->pGetProperties()));
279 
280  // Optimize communicaton plan
281  ParallelFillCommunicator CommunicatorGeneration(*mpmesh_model_part, mrReferenceModelPart.GetCommunicator().GetDataCommunicator());
282  CommunicatorGeneration.Execute();
283  }
284 
300 
303 }; /* Class TrilinosStructuralMeshMovingStrategy */
304 
311 }
312 /* namespace Kratos.*/
313 
314 #endif /* KRATOS_STRUCTURAL_MESHMOVING_STRATEGY defined */
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
virtual const DataCommunicator & GetDataCommunicator() const
Definition: communicator.cpp:340
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
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
MeshType::ElementsContainerType ElementsContainerType
Element container. A vector set of Elements with their Id's as key.
Definition: model_part.h:168
Communicator & GetCommunicator()
Definition: model_part.h:1821
std::string & Name()
Definition: model_part.h:1811
MeshType::NodeIterator NodeIterator
Definition: model_part.h:134
ElementsContainerType & Elements(IndexType ThisIndex=0)
Definition: model_part.h:1189
ElementIterator ElementsEnd(IndexType ThisIndex=0)
Definition: model_part.h:1179
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
Model & GetModel()
Definition: model_part.h:323
This function recomputes the communication plan for MPI.
Definition: parallel_fill_communicator.h:56
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
ModelPart & GetModelPart()
Operations to get the pointer to the model.
Definition: solving_strategy.h:350
Current class provides an implementation for trilinos builder and solving operations.
Definition: trilinos_block_builder_and_solver.h:85
Short class definition.
Definition: trilinos_structural_meshmoving_strategy.h:65
double Solve() override
The problem of interest is solved.
Definition: trilinos_structural_meshmoving_strategy.h:151
KRATOS_CLASS_POINTER_DEFINITION(TrilinosStructuralMeshMovingStrategy)
ImplicitSolvingStrategy< TSparseSpace, TDenseSpace, TLinearSolver > BaseType
Definition: trilinos_structural_meshmoving_strategy.h:75
void Initialize() override
Definition: trilinos_structural_meshmoving_strategy.h:148
Scheme< TSparseSpace, TDenseSpace > SchemeType
Definition: trilinos_structural_meshmoving_strategy.h:73
TrilinosStructuralMeshMovingStrategy(Epetra_MpiComm &Communicator, ModelPart &model_part, typename TLinearSolver::Pointer pNewLinearSolver, int TimeOrder=2, bool ReformDofSetAtEachStep=false, bool ComputeReactions=false, bool CalculateMeshVelocities=true, int EchoLevel=0)
Definition: trilinos_structural_meshmoving_strategy.h:84
virtual ~TrilinosStructuralMeshMovingStrategy()
Definition: trilinos_structural_meshmoving_strategy.h:140
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_ERROR
Definition: exception.h:161
static int EchoLevel
Definition: co_sim_EMPIRE_API.h:42
void CalculateMeshVelocities(ModelPart &rModelPart, const TimeDiscretization::BDF1 &rBDF)
Definition: mesh_velocity_calculation.cpp:56
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
model_part
Definition: face_heat.py:14
integer i
Definition: TensorModule.f:17