OGS 6.2.0-97-g4a610c866
SmallDeformationNonlocalProcess.cpp
Go to the documentation of this file.
1 
13 
14 #include <nlohmann/json.hpp>
15 #include <iostream>
16 
17 // Reusing local assembler creation code.
19 
20 namespace ProcessLib
21 {
22 namespace SmallDeformationNonlocal
23 {
24 template <int DisplacementDim>
27  MeshLib::Mesh& mesh,
28  std::unique_ptr<ProcessLib::AbstractJacobianAssembler>&&
29  jacobian_assembler,
30  std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const&
31  parameters,
32  unsigned const integration_order,
33  std::vector<std::vector<std::reference_wrapper<ProcessVariable>>>&&
34  process_variables,
36  SecondaryVariableCollection&& secondary_variables,
37  NumLib::NamedFunctionCaller&& named_function_caller)
38  : Process(mesh, std::move(jacobian_assembler), parameters,
39  integration_order, std::move(process_variables),
40  std::move(secondary_variables), std::move(named_function_caller)),
41  _process_data(std::move(process_data))
42 {
43  _nodal_forces = MeshLib::getOrCreateMeshProperty<double>(
44  mesh, "NodalForces", MeshLib::MeshItemType::Node, DisplacementDim);
45 
46  _integration_point_writer.emplace_back(
47  std::make_unique<SigmaIntegrationPointWriter>(
48  static_cast<int>(mesh.getDimension() == 2 ? 4 : 6) /*n components*/,
49  integration_order, [this]() {
50  // Result containing integration point data for each local
51  // assembler.
52  std::vector<std::vector<double>> result;
53  result.resize(_local_assemblers.size());
54 
55  for (std::size_t i = 0; i < _local_assemblers.size(); ++i)
56  {
57  auto const& local_asm = *_local_assemblers[i];
58 
59  result[i] = local_asm.getSigma();
60  }
61 
62  return result;
63  }));
64 
65  _integration_point_writer.emplace_back(
66  std::make_unique<KappaDIntegrationPointWriter>(
67  integration_order, [this]() {
68  // Result containing integration point data for each local
69  // assembler.
70  std::vector<std::vector<double>> result;
71  result.resize(_local_assemblers.size());
72 
73  for (std::size_t i = 0; i < _local_assemblers.size(); ++i)
74  {
75  auto const& local_asm = *_local_assemblers[i];
76 
77  result[i] = local_asm.getKappaD();
78  }
79 
80  return result;
81  }));
82 }
83 
84 template <int DisplacementDim>
86 {
87  return false;
88 }
89 
90 template <int DisplacementDim>
93  MeshLib::Mesh const& mesh,
94  unsigned const integration_order)
95 {
96  // Reusing local assembler creation code.
99  mesh.getElements(), dof_table, _local_assemblers,
100  mesh.isAxiallySymmetric(), integration_order, _process_data);
101 
102  // TODO move the two data members somewhere else.
103  // for extrapolation of secondary variables
104  std::vector<MeshLib::MeshSubset> all_mesh_subsets_single_component{
107  std::make_unique<NumLib::LocalToGlobalIndexMap>(
108  std::move(all_mesh_subsets_single_component),
109  // by location order is needed for output
111 
113  "sigma",
115  DisplacementDim>::RowsAtCompileTime,
116  getExtrapolator(), _local_assemblers,
118 
120  "epsilon",
122  DisplacementDim>::RowsAtCompileTime,
123  getExtrapolator(), _local_assemblers,
125 
127  "eps_p_V",
128  makeExtrapolator(1, getExtrapolator(), _local_assemblers,
131  "eps_p_D_xx",
132  makeExtrapolator(1, getExtrapolator(), _local_assemblers,
134 
136  "damage",
137  makeExtrapolator(1, getExtrapolator(), _local_assemblers,
139 
141  &LocalAssemblerInterface::nonlocal, _local_assemblers,
142  _local_assemblers);
143 
144  // Set initial conditions for integration point data.
145  for (auto const& ip_writer : _integration_point_writer)
146  {
147  auto const& name = ip_writer->name();
148  // First check the field data, which is used for restart.
149  if (mesh.getProperties().existsPropertyVector<double>(name))
150  {
151  auto const& mesh_property =
152  *mesh.getProperties().template getPropertyVector<double>(name);
153 
154  // The mesh property must be defined on integration points.
155  if (mesh_property.getMeshItemType() !=
157  {
158  continue;
159  }
160 
161  auto const ip_meta_data = getIntegrationPointMetaData(mesh, name);
162 
163  // Check the number of components.
164  if (ip_meta_data.n_components !=
165  mesh_property.getNumberOfComponents())
166  {
167  OGS_FATAL(
168  "Different number of components in meta data (%d) than in "
169  "the integration point field data for '%s': %d.",
170  ip_meta_data.n_components, name.c_str(),
171  mesh_property.getNumberOfComponents());
172  }
173 
174  // Now we have a properly named vtk's field data array and the
175  // corresponding meta data.
176  std::size_t position = 0;
177  for (auto& local_asm : _local_assemblers)
178  {
179  std::size_t const integration_points_read =
180  local_asm->setIPDataInitialConditions(
181  name, &mesh_property[position],
182  ip_meta_data.integration_order);
183  if (integration_points_read == 0)
184  {
185  OGS_FATAL(
186  "No integration points read in the integration point "
187  "initial conditions set function.");
188  }
189  position += integration_points_read * ip_meta_data.n_components;
190  }
191  }
192  else if (mesh.getProperties().existsPropertyVector<double>(name +
193  "_ic"))
194  { // Try to find cell data with '_ic' suffix
195  auto const& mesh_property =
196  *mesh.getProperties().template getPropertyVector<double>(name +
197  "_ic");
198  if (mesh_property.getMeshItemType() != MeshLib::MeshItemType::Cell)
199  {
200  continue;
201  }
202 
203  // Now we have a vtk's cell data array containing the initial
204  // conditions for the corresponding integration point writer.
205 
206  // For each assembler use the single cell value for all
207  // integration points.
208  for (std::size_t i = 0; i < _local_assemblers.size(); ++i)
209  {
210  auto& local_asm = _local_assemblers[i];
211 
212  std::vector<double> value(
213  &mesh_property[i],
214  &mesh_property[i] + mesh_property.getNumberOfComponents());
215  // TODO (naumov) Check sizes / read size / etc.
216  // OR reconstruct dimensions from size / component =
217  // ip_points
218  local_asm->setIPDataInitialConditionsFromCellData(name, value);
219  }
220  }
221  }
222 }
223 
224 template <int DisplacementDim>
226  const double t, GlobalVector const& x, GlobalMatrix& M, GlobalMatrix& K,
227  GlobalVector& b)
228 {
229  DBUG("Assemble SmallDeformationNonlocalProcess.");
230 
231  std::vector<std::reference_wrapper<NumLib::LocalToGlobalIndexMap>>
232  dof_table = {std::ref(*_local_to_global_index_map)};
233 
234  const int process_id = 0;
235  ProcessLib::ProcessVariable const& pv = getProcessVariables(process_id)[0];
236 
237  // Call global assembler for each local assembly item.
240  pv.getActiveElementIDs(), dof_table, t, x, M, K, b, _coupled_solutions);
241 }
242 
243 template <int DisplacementDim>
245  DisplacementDim>::preAssembleConcreteProcess(const double t,
246  GlobalVector const& x)
247 {
248  DBUG("preAssemble SmallDeformationNonlocalProcess.");
249 
250  const int process_id = 0;
251  ProcessLib::ProcessVariable const& pv = getProcessVariables(process_id)[0];
252 
253  // Call global assembler for each local assembly item.
258 }
259 
260 template <int DisplacementDim>
262  assembleWithJacobianConcreteProcess(const double t, GlobalVector const& x,
263  GlobalVector const& xdot,
264  const double dxdot_dx,
265  const double dx_dx, GlobalMatrix& M,
266  GlobalMatrix& K, GlobalVector& b,
267  GlobalMatrix& Jac)
268 {
269  DBUG("AssembleWithJacobian SmallDeformationNonlocalProcess.");
270 
271  std::vector<std::reference_wrapper<NumLib::LocalToGlobalIndexMap>>
272  dof_table = {std::ref(*_local_to_global_index_map)};
273 
274  const int process_id = 0;
275  ProcessLib::ProcessVariable const& pv = getProcessVariables(process_id)[0];
276 
277  // Call global assembler for each local assembly item.
280  _local_assemblers, pv.getActiveElementIDs(), dof_table, t, x, xdot,
281  dxdot_dx, dx_dx, M, K, b, Jac, _coupled_solutions);
282 
283  b.copyValues(*_nodal_forces);
284  std::transform(_nodal_forces->begin(), _nodal_forces->end(),
285  _nodal_forces->begin(), [](double val) { return -val; });
286 }
287 
288 template <int DisplacementDim>
290  DisplacementDim>::preTimestepConcreteProcess(GlobalVector const& x,
291  double const t,
292  double const dt,
293  int const /*process_id*/)
294 {
295  DBUG("PreTimestep SmallDeformationNonlocalProcess.");
296 
297  _process_data.dt = dt;
298  _process_data.t = t;
299 
300  const int process_id = 0;
301  ProcessLib::ProcessVariable const& pv = getProcessVariables(process_id)[0];
302 
306 }
307 
308 template <int DisplacementDim>
311  GlobalVector const& x)
312 {
313  _process_data.crack_volume_old = _process_data.crack_volume;
314  _process_data.crack_volume = 0.0;
315 
316  DBUG("PostNonLinearSolver crack volume computation.");
317 
318  const int process_id = 0;
319  ProcessLib::ProcessVariable const& pv = getProcessVariables(process_id)[0];
320 
324  _process_data.crack_volume);
325 
326  INFO("Integral of crack: %g", _process_data.crack_volume);
327 
329 }
330 
333 
334 } // namespace SmallDeformationNonlocal
335 } // namespace ProcessLib
void initializeConcreteProcess(NumLib::LocalToGlobalIndexMap const &dof_table, MeshLib::Mesh const &mesh, unsigned const integration_order) override
Process specific initialization called by initialize().
IntegrationPointMetaData getIntegrationPointMetaData(MeshLib::Mesh const &mesh, std::string const &name)
SmallDeformationNonlocalProcessData< DisplacementDim > _process_data
virtual std::vector< double > const & getIntPtEpsPDXX(const double, GlobalVector const &, NumLib::LocalToGlobalIndexMap const &, std::vector< double > &cache) const =0
std::unique_ptr< MeshLib::MeshSubset const > _mesh_subset_all_nodes
Definition: Process.h:263
static void executeSelectedMemberOnDereferenced(Method method, Container const &container, std::vector< std::size_t > const &active_container_ids, Args &&... args)
std::vector< std::reference_wrapper< ProcessVariable > > const & getProcessVariables(const int process_id) const
Definition: Process.h:124
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
void preAssemble(const std::size_t mesh_item_id, LocalAssemblerInterface &local_assembler, const NumLib::LocalToGlobalIndexMap &dof_table, const double t, const GlobalVector &x)
std::unique_ptr< NumLib::LocalToGlobalIndexMap > _local_to_global_index_map_single_component
NumLib::IterationResult postIterationConcreteProcess(GlobalVector const &x) override
virtual std::vector< double > const & getIntPtEpsilon(const double, GlobalVector const &, NumLib::LocalToGlobalIndexMap const &, std::vector< double > &cache) const =0
static void executeMemberOnDereferenced(Method method, Container const &container, Args &&... args)
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)
void preTimestepConcreteProcess(GlobalVector const &x, double const t, double const dt, int const) override
MeshLib::Properties & getProperties()
Definition: Mesh.h:134
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:151
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:137
std::unique_ptr< NumLib::LocalToGlobalIndexMap > _local_to_global_index_map
Definition: Process.h:265
IterationResult
Status flags telling the NonlinearSolver if an iteration succeeded.
virtual std::vector< double > const & getIntPtDamage(const double, GlobalVector const &, NumLib::LocalToGlobalIndexMap const &, std::vector< double > &cache) const =0
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)
virtual void computeCrackIntegral(std::size_t mesh_item_id, NumLib::LocalToGlobalIndexMap const &dof_table, GlobalVector const &x, double &crack_volume)=0
void preAssembleConcreteProcess(const double t, GlobalVector const &x) override
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:267
std::vector< std::unique_ptr< LocalAssemblerInterface > > _local_assemblers
virtual std::vector< double > const & getIntPtSigma(const double, GlobalVector const &, NumLib::LocalToGlobalIndexMap const &, std::vector< double > &cache) const =0
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 std::vector< double > const & getIntPtEpsPV(const double, GlobalVector const &, NumLib::LocalToGlobalIndexMap const &, std::vector< double > &cache) const =0
CoupledSolutionsForStaggeredScheme * _coupled_solutions
Definition: Process.h:280
virtual void nonlocal(std::size_t const mesh_item_id, std::vector< std::unique_ptr< SmallDeformationNonlocalLocalAssemblerInterface >> const &local_assemblers)=0
Handles configuration of several secondary variables from the project file.
Ordering data by spatial location.
#define OGS_FATAL(fmt,...)
Definition: Error.h:63
void addSecondaryVariable(std::string const &internal_name, SecondaryVariableFunctions &&fcts)
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
SmallDeformationNonlocalProcess(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, SmallDeformationNonlocalProcessData< DisplacementDim > &&process_data, SecondaryVariableCollection &&secondary_variables, NumLib::NamedFunctionCaller &&named_function_caller)
std::vector< std::unique_ptr< IntegrationPointWriter > > _integration_point_writer
Definition: Process.h:291
VectorMatrixAssembler _global_assembler
Definition: Process.h:274
Eigen::Matrix< double, KelvinVectorDimensions< DisplacementDim >::value, 1, Eigen::ColMajor > KelvinVectorType
Definition: KelvinVector.h:49
std::vector< std::size_t > & getActiveElementIDs() const