OGS
SolidMaterialInternalToSecondaryVariables.h
Go to the documentation of this file.
1 
11 #pragma once
12 
13 #include <map>
14 #include <memory>
15 
17 
19 {
20 template <typename LocalAssemblerInterface,
21  typename AddSecondaryVariableCallback, int DisplacementDim>
23  std::map<int, std::unique_ptr<MaterialLib::Solids::MechanicsBase<
24  DisplacementDim>>> const& solid_materials,
25  AddSecondaryVariableCallback const& add_secondary_variable)
26 {
27  // Collect the internal variables for all solid materials.
28  std::vector<typename MaterialLib::Solids::MechanicsBase<
29  DisplacementDim>::InternalVariable>
30  internal_variables;
31  for (auto const& material_id__solid_material : solid_materials)
32  {
33  auto const variables =
34  material_id__solid_material.second->getInternalVariables();
35  copy(begin(variables), end(variables),
36  back_inserter(internal_variables));
37  }
38 
39  // Register the internal variables.
40  for (auto const& internal_variable : internal_variables)
41  {
42  auto const& name = internal_variable.name;
43  auto const& fct = internal_variable.getter;
44  auto const num_components = internal_variable.num_components;
45  DBUG("Registering internal variable {:s}.", name);
46 
47  auto getIntPtValues =
48  [fct, num_components](
49  LocalAssemblerInterface const& loc_asm,
50  const double /*t*/,
51  std::vector<GlobalVector*> const& /*x*/,
52  std::vector<
53  NumLib::LocalToGlobalIndexMap const*> const& /*dof_table*/,
54  std::vector<double>& cache) -> std::vector<double> const& {
55  const unsigned num_int_pts = loc_asm.getNumberOfIntegrationPoints();
56 
57  cache.clear();
58  auto cache_mat = MathLib::createZeroedMatrix<Eigen::Matrix<
59  double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>>(
60  cache, num_components, num_int_pts);
61 
62  // TODO avoid the heap allocation (one per finite element)
63  std::vector<double> cache_column(num_int_pts);
64 
65  for (unsigned i = 0; i < num_int_pts; ++i)
66  {
67  auto const& state = loc_asm.getMaterialStateVariablesAt(i);
68 
69  auto const& int_pt_values = fct(state, cache_column);
70  assert(int_pt_values.size() ==
71  static_cast<std::size_t>(num_components));
72  auto const int_pt_values_vec = MathLib::toVector(int_pt_values);
73 
74  cache_mat.col(i).noalias() = int_pt_values_vec;
75  }
76 
77  return cache;
78  };
79 
80  add_secondary_variable(name, num_components, std::move(getIntPtValues));
81  }
82 }
83 
84 template <typename LocalAssemblerInterface, typename IntegrationPointWriter,
85  int DisplacementDim>
87  std::map<int, std::unique_ptr<MaterialLib::Solids::MechanicsBase<
88  DisplacementDim>>> const& solid_materials,
89  std::vector<std::unique_ptr<LocalAssemblerInterface>> const&
90  local_assemblers,
91  std::vector<std::unique_ptr<IntegrationPointWriter>>&
92  integration_point_writer,
93  int const integration_order)
94 {
95  // Collect the internal variables for all solid materials.
96  std::vector<typename MaterialLib::Solids::MechanicsBase<
97  DisplacementDim>::InternalVariable>
98  internal_variables;
99  for (auto const& solid_material : solid_materials)
100  {
101  auto const ivs = solid_material.second->getInternalVariables();
102  copy(begin(ivs), end(ivs), back_inserter(internal_variables));
103  }
104 
105  // Create integration point writers for each of the internal variables.
106  for (auto const& iv : internal_variables)
107  {
108  DBUG("Creating integration point writer for internal variable {:s}.",
109  iv.name);
110 
111  integration_point_writer.emplace_back(
112  std::make_unique<IntegrationPointWriter>(
113  "material_state_variable_" + iv.name + "_ip", iv.num_components,
114  integration_order, local_assemblers,
115  &LocalAssemblerInterface::getMaterialStateVariableInternalState,
116  iv.reference, iv.num_components));
117  }
118 }
119 } // namespace ProcessLib::Deformation
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition: Logging.h:29
void copy(PETScVector const &x, PETScVector &y)
Definition: LinAlg.cpp:37
Eigen::Map< const Vector > toVector(std::vector< double > const &data, Eigen::VectorXd::Index size)
Creates an Eigen mapped vector from the given data vector.
Eigen::Map< Matrix > createZeroedMatrix(std::vector< double > &data, Eigen::MatrixXd::Index rows, Eigen::MatrixXd::Index cols)
Definition: EigenMapTools.h:32
void solidMaterialInternalToSecondaryVariables(std::map< int, std::unique_ptr< MaterialLib::Solids::MechanicsBase< DisplacementDim >>> const &solid_materials, AddSecondaryVariableCallback const &add_secondary_variable)
void solidMaterialInternalVariablesToIntegrationPointWriter(std::map< int, std::unique_ptr< MaterialLib::Solids::MechanicsBase< DisplacementDim >>> const &solid_materials, std::vector< std::unique_ptr< LocalAssemblerInterface >> const &local_assemblers, std::vector< std::unique_ptr< IntegrationPointWriter >> &integration_point_writer, int const integration_order)
virtual std::vector< InternalVariable > getInternalVariables() const