OGS 6.1.0-1699-ge946d4c5f
ThermoMechanicsProcess.cpp
Go to the documentation of this file.
1 
10 #include "ThermoMechanicsProcess.h"
11 
12 #include <cassert>
13 
14 #include "BaseLib/Functional.h"
16 
17 #include "ThermoMechanicsFEM.h"
18 
19 namespace ProcessLib
20 {
21 namespace ThermoMechanics
22 {
23 template <int DisplacementDim>
25  MeshLib::Mesh& mesh,
26  std::unique_ptr<ProcessLib::AbstractJacobianAssembler>&& jacobian_assembler,
27  std::vector<std::unique_ptr<ParameterBase>> const& parameters,
28  unsigned const integration_order,
29  std::vector<std::vector<std::reference_wrapper<ProcessVariable>>>&&
30  process_variables,
32  SecondaryVariableCollection&& secondary_variables,
33  NumLib::NamedFunctionCaller&& named_function_caller,
34  bool const use_monolithic_scheme)
35  : Process(mesh, std::move(jacobian_assembler), parameters,
36  integration_order, std::move(process_variables),
37  std::move(secondary_variables), std::move(named_function_caller),
38  use_monolithic_scheme),
39  _process_data(std::move(process_data))
40 {
41  _integration_point_writer.emplace_back(
42  std::make_unique<KelvinVectorIntegrationPointWriter>(
43  "sigma_ip",
44  static_cast<int>(mesh.getDimension() == 2 ? 4 : 6) /*n components*/,
45  2 /*integration order*/, [this]() {
46  // Result containing integration point data for each local
47  // assembler.
48  std::vector<std::vector<double>> result;
49  result.resize(_local_assemblers.size());
50 
51  for (std::size_t i = 0; i < _local_assemblers.size(); ++i)
52  {
53  auto const& local_asm = *_local_assemblers[i];
54 
55  result[i] = local_asm.getSigma();
56  }
57 
58  return result;
59  }));
60 
61  _integration_point_writer.emplace_back(
62  std::make_unique<KelvinVectorIntegrationPointWriter>(
63  "epsilon_ip",
64  static_cast<int>(mesh.getDimension() == 2 ? 4 : 6) /*n components*/,
65  2 /*integration order*/, [this]() {
66  // Result containing integration point data for each local
67  // assembler.
68  std::vector<std::vector<double>> result;
69  result.resize(_local_assemblers.size());
70 
71  for (std::size_t i = 0; i < _local_assemblers.size(); ++i)
72  {
73  auto const& local_asm = *_local_assemblers[i];
74 
75  result[i] = local_asm.getEpsilon();
76  }
77 
78  return result;
79  }));
80 
81  _integration_point_writer.emplace_back(
82  std::make_unique<KelvinVectorIntegrationPointWriter>(
83  "epsilon_m_ip",
84  static_cast<int>(mesh.getDimension() == 2 ? 4 : 6) /*n components*/,
85  2 /*integration order*/, [this]() {
86  // Result containing integration point data for each local
87  // assembler.
88  std::vector<std::vector<double>> result;
89  result.resize(_local_assemblers.size());
90 
91  for (std::size_t i = 0; i < _local_assemblers.size(); ++i)
92  {
93  auto const& local_asm = *_local_assemblers[i];
94 
95  result[i] = local_asm.getEpsilonMechanical();
96  }
97 
98  return result;
99  }));
100 }
101 
102 template <int DisplacementDim>
104 {
105  return false;
106 }
107 
108 template <int DisplacementDim>
110  NumLib::LocalToGlobalIndexMap const& dof_table,
111  MeshLib::Mesh const& mesh,
112  unsigned const integration_order)
113 {
115  DisplacementDim, ThermoMechanicsLocalAssembler>(
116  mesh.getElements(), dof_table, _local_assemblers,
117  mesh.isAxiallySymmetric(), integration_order, _process_data);
118 
119  // TODO move the two data members somewhere else.
120  // for extrapolation of secondary variables
121  std::vector<MeshLib::MeshSubset> all_mesh_subsets_single_component{
125  std::move(all_mesh_subsets_single_component),
126  // by location order is needed for output
128 
130  "sigma",
133  DisplacementDim>::RowsAtCompileTime,
134  getExtrapolator(), _local_assemblers,
136 
138  "epsilon",
141  DisplacementDim>::RowsAtCompileTime,
142  getExtrapolator(), _local_assemblers,
144 
145  // Set initial conditions for integration point data.
146  for (auto const& ip_writer : _integration_point_writer)
147  {
148  // Find the mesh property with integration point writer's name.
149  auto const& name = ip_writer->name();
150  if (!mesh.getProperties().existsPropertyVector<double>(name))
151  {
152  continue;
153  }
154  auto const& mesh_property =
155  *mesh.getProperties().template getPropertyVector<double>(name);
156 
157  // The mesh property must be defined on integration points.
158  if (mesh_property.getMeshItemType() !=
160  {
161  continue;
162  }
163 
164  auto const ip_meta_data = getIntegrationPointMetaData(mesh, name);
165 
166  // Check the number of components.
167  if (ip_meta_data.n_components != mesh_property.getNumberOfComponents())
168  {
169  OGS_FATAL(
170  "Different number of components in meta data (%d) than in "
171  "the integration point field data for '%s': %d.",
172  ip_meta_data.n_components, name.c_str(),
173  mesh_property.getNumberOfComponents());
174  }
175 
176  // Now we have a properly named vtk's field data array and the
177  // corresponding meta data.
178  std::size_t position = 0;
179  for (auto& local_asm : _local_assemblers)
180  {
181  std::size_t const integration_points_read =
182  local_asm->setIPDataInitialConditions(
183  name, &mesh_property[position],
184  ip_meta_data.integration_order);
185  if (integration_points_read == 0)
186  {
187  OGS_FATAL(
188  "No integration points read in the integration point "
189  "initial conditions set function.");
190  }
191  position += integration_points_read * ip_meta_data.n_components;
192  }
193  }
194 }
195 
196 template <int DisplacementDim>
198  const double t, GlobalVector const& x, GlobalMatrix& M, GlobalMatrix& K,
199  GlobalVector& b)
200 {
201  DBUG("Assemble ThermoMechanicsProcess.");
202 
203  std::vector<std::reference_wrapper<NumLib::LocalToGlobalIndexMap>>
204  dof_table = {std::ref(*_local_to_global_index_map)};
205  const int process_id =
207  ProcessLib::ProcessVariable const& pv = getProcessVariables(process_id)[0];
208 
209  // Call global assembler for each local assembly item.
212  pv.getActiveElementIDs(), dof_table, t, x, M, K, b,
214 }
215 
216 template <int DisplacementDim>
218  assembleWithJacobianConcreteProcess(const double t, GlobalVector const& x,
219  GlobalVector const& xdot,
220  const double dxdot_dx,
221  const double dx_dx, GlobalMatrix& M,
222  GlobalMatrix& K, GlobalVector& b,
223  GlobalMatrix& Jac)
224 {
225  DBUG("AssembleJacobian ThermoMechanicsProcess.");
226 
227  std::vector<std::reference_wrapper<NumLib::LocalToGlobalIndexMap>>
228  dof_table = {std::ref(*_local_to_global_index_map)};
229  const int process_id =
231  ProcessLib::ProcessVariable const& pv = getProcessVariables(process_id)[0];
232 
233  // Call global assembler for each local assembly item.
236  _local_assemblers, pv.getActiveElementIDs(), dof_table, t, x,
237  xdot, dxdot_dx, dx_dx, M, K, b, Jac, _coupled_solutions);
238 }
239 
240 template <int DisplacementDim>
242  GlobalVector const& x, double const t, double const dt,
243  const int process_id)
244 {
245  DBUG("PreTimestep ThermoMechanicsProcess.");
246 
247  _process_data.dt = dt;
248  _process_data.t = t;
249 
250  ProcessLib::ProcessVariable const& pv = getProcessVariables(process_id)[0];
251 
255  dt);
256 }
257 
258 template <int DisplacementDim>
260  GlobalVector const& x, const double /*t*/, const double /*delta_t*/,
261  int const process_id)
262 {
263  DBUG("PostTimestep ThermoMechanicsProcess.");
264 
265  ProcessLib::ProcessVariable const& pv = getProcessVariables(process_id)[0];
266 
271 }
272 
273 template class ThermoMechanicsProcess<2>;
274 template class ThermoMechanicsProcess<3>;
275 
276 } // namespace ThermoMechanics
277 } // namespace ProcessLib
IntegrationPointMetaData getIntegrationPointMetaData(MeshLib::Mesh const &mesh, std::string const &name)
void assembleWithJacobianConcreteProcess(const double t, GlobalVector const &x, GlobalVector const &xdot, const double dxdot_dx, const double dx_dx, GlobalMatrix &M, GlobalMatrix &K, GlobalVector &b, GlobalMatrix &Jac) override
std::unique_ptr< MeshLib::MeshSubset const > _mesh_subset_all_nodes
Definition: Process.h:262
static void executeSelectedMemberOnDereferenced(Method method, Container const &container, std::vector< std::size_t > const &active_container_ids, Args &&... args)
virtual std::vector< double > const & getIntPtSigma(const double, GlobalVector const &, NumLib::LocalToGlobalIndexMap const &, std::vector< double > &cache) const =0
std::vector< std::reference_wrapper< ProcessVariable > > const & getProcessVariables(const int process_id) const
Definition: Process.h:123
SecondaryVariableFunctions makeExtrapolator(const unsigned num_components, NumLib::Extrapolator &extrapolator, LocalAssemblerCollection const &local_assemblers, typename NumLib::ExtrapolatableLocalAssemblerCollection< LocalAssemblerCollection >::IntegrationPointValuesMethod integration_point_values_method)
void assembleConcreteProcess(const double t, GlobalVector const &x, GlobalMatrix &M, GlobalMatrix &K, GlobalVector &b) override
std::vector< std::unique_ptr< ThermoMechanicsLocalAssemblerInterface > > _local_assemblers
std::unique_ptr< NumLib::LocalToGlobalIndexMap > _local_to_global_index_map_single_component
void assemble(std::size_t const mesh_item_id, LocalAssemblerInterface &local_assembler, std::vector< std::reference_wrapper< NumLib::LocalToGlobalIndexMap >> const &dof_tables, double const t, GlobalVector const &x, GlobalMatrix &M, GlobalMatrix &K, GlobalVector &b, CoupledSolutionsForStaggeredScheme const *const cpl_xs)
MeshLib::Properties & getProperties()
Definition: Mesh.h:131
void createLocalAssemblers(std::vector< MeshLib::Element *> const &mesh_elements, NumLib::LocalToGlobalIndexMap const &dof_table, std::vector< std::unique_ptr< LocalAssemblerInterface >> &local_assemblers, ExtraCtorArgs &&... extra_ctor_args)
NumLib::Extrapolator & getExtrapolator() const
Definition: Process.h:150
void assembleWithJacobian(std::size_t const mesh_item_id, LocalAssemblerInterface &local_assembler, std::vector< std::reference_wrapper< NumLib::LocalToGlobalIndexMap >> const &dof_tables, const double t, GlobalVector const &x, GlobalVector const &xdot, const double dxdot_dx, const double dx_dx, GlobalMatrix &M, GlobalMatrix &K, GlobalVector &b, GlobalMatrix &Jac, CoupledSolutionsForStaggeredScheme const *const cpl_xs)
bool isAxiallySymmetric() const
Definition: Mesh.h:134
std::unique_ptr< NumLib::LocalToGlobalIndexMap > _local_to_global_index_map
Definition: Process.h:264
Builds expression trees of named functions dynamically at runtime.
virtual void preTimestep(std::size_t const mesh_item_id, NumLib::LocalToGlobalIndexMap const &dof_table, GlobalVector const &x, double const t, double const delta_t)
static void executeSelectedMemberDereferenced(Object &object, Method method, Container const &container, std::vector< std::size_t > const &active_container_ids, Args &&... args)
SecondaryVariableCollection _secondary_variables
Definition: Process.h:266
void postTimestepConcreteProcess(GlobalVector const &x, const double t, const double delta_t, int const process_id) override
ThermoMechanicsProcessData< DisplacementDim > _process_data
void preTimestepConcreteProcess(GlobalVector const &x, double const t, double const dt, const int process_id) override
virtual std::vector< double > const & getIntPtEpsilon(const double, GlobalVector const &, NumLib::LocalToGlobalIndexMap const &, std::vector< double > &cache) const =0
ThermoMechanicsProcess(MeshLib::Mesh &mesh, std::unique_ptr< ProcessLib::AbstractJacobianAssembler > &&jacobian_assembler, std::vector< std::unique_ptr< ParameterBase >> const &parameters, unsigned const integration_order, std::vector< std::vector< std::reference_wrapper< ProcessVariable >>> &&process_variables, ThermoMechanicsProcessData< DisplacementDim > &&process_data, SecondaryVariableCollection &&secondary_variables, NumLib::NamedFunctionCaller &&named_function_caller, bool const use_monolithic_scheme)
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Definition: Mesh.h:108
bool existsPropertyVector(std::string const &name) const
Definition: Properties.h:79
virtual void postTimestep(std::size_t const mesh_item_id, NumLib::LocalToGlobalIndexMap const &dof_table, GlobalVector const &x)
CoupledSolutionsForStaggeredScheme * _coupled_solutions
Definition: Process.h:279
Handles configuration of several secondary variables from the project file.
void initializeConcreteProcess(NumLib::LocalToGlobalIndexMap const &dof_table, MeshLib::Mesh const &mesh, unsigned const integration_order) override
Process specific initialization called by initialize().
unsigned getDimension() const
Returns the dimension of the mesh (determined by the maximum dimension over all elements).
Definition: Mesh.h:81
Ordering data by spatial location.
#define OGS_FATAL(fmt,...)
Definition: Error.h:71
void addSecondaryVariable(std::string const &internal_name, SecondaryVariableFunctions &&fcts)
std::vector< std::unique_ptr< IntegrationPointWriter > > _integration_point_writer
Definition: Process.h:290
const bool _use_monolithic_scheme
Definition: Process.h:275
VectorMatrixAssembler _global_assembler
Definition: Process.h:273
Eigen::Matrix< double, KelvinVectorDimensions< DisplacementDim >::value, 1, Eigen::ColMajor > KelvinVectorType
Definition: KelvinVector.h:49
std::vector< std::size_t > & getActiveElementIDs() const