OGS
SmallDeformationProcess.cpp
Go to the documentation of this file.
1 
12 
13 #include <cassert>
14 #include <nlohmann/json.hpp>
15 
18 #include "ProcessLib/Process.h"
21 #include "SmallDeformationFEM.h"
22 
23 namespace ProcessLib
24 {
25 namespace SmallDeformation
26 {
27 template <int DisplacementDim>
29  std::string name,
30  MeshLib::Mesh& mesh,
31  std::unique_ptr<ProcessLib::AbstractJacobianAssembler>&& jacobian_assembler,
32  std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters,
33  unsigned const integration_order,
34  std::vector<std::vector<std::reference_wrapper<ProcessVariable>>>&&
35  process_variables,
37  SecondaryVariableCollection&& secondary_variables)
38  : Process(std::move(name), mesh, std::move(jacobian_assembler), parameters,
39  integration_order, std::move(process_variables),
40  std::move(secondary_variables)),
41  _process_data(std::move(process_data))
42 {
43  _nodal_forces = MeshLib::getOrCreateMeshProperty<double>(
44  mesh, "NodalForces", MeshLib::MeshItemType::Node, DisplacementDim);
45 
46  _material_forces = MeshLib::getOrCreateMeshProperty<double>(
47  mesh, "MaterialForces", MeshLib::MeshItemType::Node, DisplacementDim);
48 
49  _process_data.principal_stress_vector[0] =
50  MeshLib::getOrCreateMeshProperty<double>(
51  const_cast<MeshLib::Mesh&>(mesh), "principal_stress_vector_1",
53 
54  _process_data.principal_stress_vector[1] =
55  MeshLib::getOrCreateMeshProperty<double>(
56  const_cast<MeshLib::Mesh&>(mesh), "principal_stress_vector_2",
58 
59  _process_data.principal_stress_vector[2] =
60  MeshLib::getOrCreateMeshProperty<double>(
61  const_cast<MeshLib::Mesh&>(mesh), "principal_stress_vector_3",
63 
64  _process_data.principal_stress_values =
65  MeshLib::getOrCreateMeshProperty<double>(
66  const_cast<MeshLib::Mesh&>(mesh), "principal_stress_values",
68 
69  // TODO (naumov) remove ip suffix. Probably needs modification of the mesh
70  // properties, s.t. there is no "overlapping" with cell/point data.
71  // See getOrCreateMeshProperty.
72  _integration_point_writer.emplace_back(
73  std::make_unique<IntegrationPointWriter>(
74  "sigma_ip",
75  static_cast<int>(mesh.getDimension() == 2 ? 4 : 6) /*n components*/,
76  integration_order, _local_assemblers,
78 }
79 
80 template <int DisplacementDim>
82 {
83  return false;
84 }
85 
86 template <int DisplacementDim>
88  NumLib::LocalToGlobalIndexMap const& dof_table,
89  MeshLib::Mesh const& mesh,
90  unsigned const integration_order)
91 {
92  using nlohmann::json;
93 
95  DisplacementDim, SmallDeformationLocalAssembler>(
96  mesh.getElements(), dof_table, _local_assemblers,
97  NumLib::IntegrationOrder{integration_order}, mesh.isAxiallySymmetric(),
98  _process_data);
99 
100  auto add_secondary_variable = [&](std::string const& name,
101  int const num_components,
102  auto get_ip_values_function)
103  {
104  _secondary_variables.addSecondaryVariable(
105  name,
106  makeExtrapolator(num_components, getExtrapolator(),
107  _local_assemblers,
108  std::move(get_ip_values_function)));
109  };
110 
111  add_secondary_variable("free_energy_density",
112  1,
113  &LocalAssemblerInterface::getIntPtFreeEnergyDensity);
114 
115  add_secondary_variable("sigma",
117  DisplacementDim>::RowsAtCompileTime,
118  &LocalAssemblerInterface::getIntPtSigma);
119 
120  add_secondary_variable("epsilon",
122  DisplacementDim>::RowsAtCompileTime,
123  &LocalAssemblerInterface::getIntPtEpsilon);
124 
125  //
126  // enable output of internal variables defined by material models
127  //
129  LocalAssemblerInterface>(_process_data.solid_materials,
130  add_secondary_variable);
131 
132  setIPDataInitialConditions(_integration_point_writer, mesh.getProperties(),
133  _local_assemblers);
134 
135  // Initialize local assemblers after all variables have been set.
137  &LocalAssemblerInterface::initialize, _local_assemblers,
138  *_local_to_global_index_map);
139 }
140 
141 template <int DisplacementDim>
143  const double t, double const dt, std::vector<GlobalVector*> const& x,
144  std::vector<GlobalVector*> const& xdot, int const process_id,
146 {
147  DBUG("Assemble SmallDeformationProcess.");
148 
149  ProcessLib::ProcessVariable const& pv = getProcessVariables(process_id)[0];
150 
151  std::vector<std::reference_wrapper<NumLib::LocalToGlobalIndexMap>>
152  dof_table = {std::ref(*_local_to_global_index_map)};
153  // Call global assembler for each local assembly item.
155  _global_assembler, &VectorMatrixAssembler::assemble, _local_assemblers,
156  pv.getActiveElementIDs(), dof_table, t, dt, x, xdot, process_id, M, K,
157  b);
158 }
159 
160 template <int DisplacementDim>
162  assembleWithJacobianConcreteProcess(const double t, double const dt,
163  std::vector<GlobalVector*> const& x,
164  std::vector<GlobalVector*> const& xdot,
165  int const process_id, GlobalMatrix& M,
166  GlobalMatrix& K, GlobalVector& b,
167  GlobalMatrix& Jac)
168 {
169  DBUG("AssembleWithJacobian SmallDeformationProcess.");
170 
171  ProcessLib::ProcessVariable const& pv = getProcessVariables(process_id)[0];
172 
173  std::vector<std::reference_wrapper<NumLib::LocalToGlobalIndexMap>>
174  dof_table = {std::ref(*_local_to_global_index_map)};
175  // Call global assembler for each local assembly item.
178  _local_assemblers, pv.getActiveElementIDs(), dof_table, t, dt, x, xdot,
179  process_id, M, K, b, Jac);
180 
181  transformVariableFromGlobalVector(b, 0, *_local_to_global_index_map,
182  *_nodal_forces, std::negate<double>());
183 }
184 
185 template <int DisplacementDim>
187  std::vector<GlobalVector*> const& x, const double t, const double dt,
188  int const process_id)
189 {
190  DBUG("PostTimestep SmallDeformationProcess.");
191  std::vector<NumLib::LocalToGlobalIndexMap const*> dof_tables;
192  dof_tables.reserve(x.size());
193  std::generate_n(std::back_inserter(dof_tables), x.size(),
194  [&]() { return _local_to_global_index_map.get(); });
195 
196  ProcessLib::ProcessVariable const& pv = getProcessVariables(process_id)[0];
198  &LocalAssemblerInterface::postTimestep, _local_assemblers,
199  pv.getActiveElementIDs(), dof_tables, x, t, dt);
200 
201  std::unique_ptr<GlobalVector> material_forces;
203  material_forces, _local_assemblers, *_local_to_global_index_map,
204  *x[process_id]);
205 
206  material_forces->copyValues(*_material_forces);
207 }
208 
209 template <int DisplacementDim>
211  double const t, double const dt, std::vector<GlobalVector*> const& x,
212  GlobalVector const& x_dot, const int process_id)
213 {
214  DBUG("Compute the secondary variables for SmallDeformationProcess.");
215  std::vector<NumLib::LocalToGlobalIndexMap const*> dof_tables;
216  dof_tables.reserve(x.size());
217  std::generate_n(std::back_inserter(dof_tables), x.size(),
218  [&]() { return _local_to_global_index_map.get(); });
219 
220  ProcessLib::ProcessVariable const& pv = getProcessVariables(process_id)[0];
223  pv.getActiveElementIDs(), dof_tables, t, dt, x, x_dot, process_id);
224 }
225 template class SmallDeformationProcess<2>;
226 template class SmallDeformationProcess<3>;
227 
228 } // namespace SmallDeformation
229 } // namespace ProcessLib
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition: Logging.h:29
Global vector based on Eigen vector.
Definition: EigenVector.h:28
bool isAxiallySymmetric() const
Definition: Mesh.h:131
unsigned getDimension() const
Returns the dimension of the mesh (determined by the maximum dimension over all elements).
Definition: Mesh.h:76
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Definition: Mesh.h:103
Properties & getProperties()
Definition: Mesh.h:128
virtual void postTimestep(std::size_t const mesh_item_id, std::vector< NumLib::LocalToGlobalIndexMap const * > const &dof_tables, std::vector< GlobalVector * > const &x, double const t, double const dt)
virtual void initialize(std::size_t const mesh_item_id, NumLib::LocalToGlobalIndexMap const &dof_table)
virtual void computeSecondaryVariable(std::size_t const mesh_item_id, std::vector< NumLib::LocalToGlobalIndexMap const * > const &dof_tables, double const t, double const dt, std::vector< GlobalVector * > const &x, GlobalVector const &x_dot, int const process_id)
std::vector< std::size_t > const & getActiveElementIDs() const
std::vector< std::unique_ptr< IntegrationPointWriter > > _integration_point_writer
Definition: Process.h:354
Handles configuration of several secondary variables from the project file.
void postTimestepConcreteProcess(std::vector< GlobalVector * > const &x, const double t, const double dt, int const process_id) override
void assembleWithJacobianConcreteProcess(const double t, double const dt, std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &xdot, int const process_id, GlobalMatrix &M, GlobalMatrix &K, GlobalVector &b, GlobalMatrix &Jac) override
SmallDeformationProcess(std::string name, MeshLib::Mesh &mesh, std::unique_ptr< ProcessLib::AbstractJacobianAssembler > &&jacobian_assembler, std::vector< std::unique_ptr< ParameterLib::ParameterBase >> const &parameters, unsigned const integration_order, std::vector< std::vector< std::reference_wrapper< ProcessVariable >>> &&process_variables, SmallDeformationProcessData< DisplacementDim > &&process_data, SecondaryVariableCollection &&secondary_variables)
SmallDeformationProcessData< DisplacementDim > _process_data
void computeSecondaryVariableConcrete(double const t, double const dt, std::vector< GlobalVector * > const &x, GlobalVector const &x_dot, const int process_id) override
std::vector< std::unique_ptr< LocalAssemblerInterface > > _local_assemblers
void initializeConcreteProcess(NumLib::LocalToGlobalIndexMap const &dof_table, MeshLib::Mesh const &mesh, unsigned const integration_order) override
Process specific initialization called by initialize().
void assembleConcreteProcess(const double t, double const dt, std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &xdot, int const process_id, GlobalMatrix &M, GlobalMatrix &K, GlobalVector &b) override
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, double const dt, std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &xdot, int const process_id, GlobalMatrix &M, GlobalMatrix &K, GlobalVector &b, GlobalMatrix &Jac)
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, double const dt, std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &xdot, int const process_id, GlobalMatrix &M, GlobalMatrix &K, GlobalVector &b)
Eigen::Matrix< double, kelvin_vector_dimensions(DisplacementDim), 1, Eigen::ColMajor > KelvinVectorType
Definition: KelvinVector.h:48
static const double t
void transformVariableFromGlobalVector(GlobalVector const &input_vector, int const variable_id, NumLib::LocalToGlobalIndexMap const &local_to_global_index_map, MeshLib::PropertyVector< double > &output_vector, Functor mapFunction)
Definition: DOFTableUtil.h:59
void solidMaterialInternalToSecondaryVariables(std::map< int, std::unique_ptr< MaterialLib::Solids::MechanicsBase< DisplacementDim >>> const &solid_materials, AddSecondaryVariableCallback const &add_secondary_variable)
void writeMaterialForces(std::unique_ptr< GlobalVector > &material_forces, std::vector< std::unique_ptr< LocalAssemblerInterface >> const &local_assemblers, NumLib::LocalToGlobalIndexMap const &local_to_global_index_map, GlobalVector const &x)
void createLocalAssemblers(std::vector< MeshLib::Element * > const &mesh_elements, NumLib::LocalToGlobalIndexMap const &dof_table, std::vector< std::unique_ptr< LocalAssemblerInterface >> &local_assemblers, NumLib::IntegrationOrder const integration_order, ExtraCtorArgs &&... extra_ctor_args)
void setIPDataInitialConditions(std::vector< std::unique_ptr< IntegrationPointWriter >> const &_integration_point_writer, MeshLib::Properties const &mesh_properties, LocalAssemblersVector &local_assemblers)
SecondaryVariableFunctions makeExtrapolator(const unsigned num_components, NumLib::Extrapolator &extrapolator, LocalAssemblerCollection const &local_assemblers, typename NumLib::ExtrapolatableLocalAssemblerCollection< LocalAssemblerCollection >::IntegrationPointValuesMethod integration_point_values_method)
static void executeSelectedMemberOnDereferenced(Method method, Container const &container, std::vector< std::size_t > const &active_container_ids, Args &&... args)
static void executeSelectedMemberDereferenced(Object &object, Method method, Container const &container, std::vector< std::size_t > const &active_container_ids, Args &&... args)
static void executeMemberOnDereferenced(Method method, Container const &container, Args &&... args)