Smith  0.1
Smith is an implicit thermal structural mechanics simulation code.
system_base.cpp
1 // Copyright (c) Lawrence Livermore National Security, LLC and
2 // other Smith Project Developers. See the top-level LICENSE file for
3 // details.
4 //
5 // SPDX-License-Identifier: (BSD-3-Clause)
6 
10 
11 namespace smith {
12 
13 std::vector<FieldState> SystemBase::solve(const TimeInfo& time_info) const
14 {
15  std::vector<std::string> weak_form_names;
16  for (const auto& wf : weak_forms) {
17  weak_form_names.push_back(wf->name());
18  }
19  std::vector<std::vector<size_t>> index_map = field_store->indexMap(weak_form_names);
20 
21  std::vector<std::vector<FieldState>> inputs;
22  if (!solve_input_field_names.empty()) {
23  SLIC_ERROR_IF(solve_input_field_names.size() != weak_forms.size(),
24  "solve_input_field_names size must match weak_forms size");
25  }
26  for (size_t i = 0; i < weak_forms.size(); ++i) {
27  std::vector<FieldState> fields_for_wk;
28  if (solve_input_field_names.empty()) {
29  fields_for_wk = field_store->getStates(weak_forms[i]->name());
30  } else {
31  for (const auto& field_name : solve_input_field_names[i]) {
32  fields_for_wk.push_back(field_store->getField(field_name));
33  }
34  }
35  inputs.push_back(fields_for_wk);
36  }
37 
38  std::vector<std::string> bc_field_names;
39  if (!solve_result_field_names.empty()) {
40  SLIC_ERROR_IF(solve_result_field_names.size() != weak_forms.size(),
41  "solve_result_field_names size must match weak_forms size");
42  bc_field_names = solve_result_field_names;
43  for (size_t row = 0; row < weak_forms.size(); ++row) {
44  for (size_t col = 0; col < weak_forms.size(); ++col) {
45  index_map[row][col] = invalid_block_index;
46  for (size_t arg = 0; arg < inputs[row].size(); ++arg) {
47  if (inputs[row][arg].get()->name() == solve_result_field_names[col]) {
48  index_map[row][col] = arg;
49  break;
50  }
51  }
52  }
53  SLIC_ERROR_IF(index_map[row][row] == invalid_block_index, "Requested solve result field '"
55  << "' is not an argument of weak form '"
56  << weak_form_names[row] << "'");
57  }
58  }
59 
60  auto params = field_store->getParameterFields();
61  std::vector<std::vector<FieldState>> wk_params(weak_forms.size(), params);
62 
63  std::vector<WeakForm*> weak_form_ptrs;
64  for (auto& p : weak_forms) {
65  weak_form_ptrs.push_back(p.get());
66  }
67  auto bc_managers = solve_result_field_names.empty()
68  ? field_store->getBoundaryConditionManagers(weak_form_names)
69  : field_store->getBoundaryConditionManagersForFields(bc_field_names);
70  return solver->solve(weak_form_ptrs, index_map, field_store->getShapeDisp(), inputs, wk_params, time_info,
71  bc_managers);
72 }
73 
74 std::vector<ReactionState> SystemBase::computeReactions(const TimeInfo& time_info,
75  const std::vector<FieldState>& states_for_reactions) const
76 {
77  std::vector<ReactionState> reactions;
78  auto params = field_store->getParameterFields();
79  for (const auto& wf : weak_forms) {
80  std::vector<FieldState> wf_fields = field_store->getStatesFromVectors(wf->name(), states_for_reactions, params);
81  std::string test_field_name = field_store->getWeakFormReaction(wf->name());
82  size_t test_field_idx = field_store->getFieldIndex(test_field_name);
83  FieldState test_field = states_for_reactions[test_field_idx];
84  reactions.push_back(smith::evaluateWeakForm(wf, time_info, field_store->getShapeDisp(), wf_fields, test_field));
85  }
86  return reactions;
87 }
88 
89 } // namespace smith
Accelerator functionality.
Definition: smith.cpp:36
constexpr T & get(variant< T0, T1 > &v)
Returns the variant member of specified type.
Definition: variant.hpp:338
auto evaluateWeakForm(const std::shared_ptr< WeakForm > &weak_form, const TimeInfo &time_info, FieldState shape_disp, const std::vector< FieldState > &field_states, FieldState field_for_residual_space)
gretl-function implementation which evaluates the residual force (which is minus the mechanical force...
Definition: reaction.hpp:26
gretl::State< FEFieldPtr, FEDualPtr > FieldState
typedef
Definition: field_state.hpp:22
Methods for solving systems of equations as given by WeakForms. Tracks these operations on the gretl ...
Reaction class which is a names combination of a weak form and a set of dirichlet constrained nodes.
std::vector< std::shared_ptr< WeakForm > > weak_forms
Weak forms solved together by this system.
Definition: system_base.hpp:54
std::shared_ptr< FieldStore > field_store
Field store managing the system's fields.
Definition: system_base.hpp:57
virtual std::vector< ReactionState > computeReactions(const TimeInfo &time_info, const std::vector< FieldState > &states_for_reactions) const
Compute reactions after solving the main state.
Definition: system_base.cpp:74
virtual std::vector< FieldState > solve(const TimeInfo &time_info) const
Solve the system using the internal weak_forms and solver.
Definition: system_base.cpp:13
std::shared_ptr< SystemSolver > solver
The solver for the system.
Definition: system_base.hpp:58
std::vector< std::string > solve_result_field_names
Optional per-weak-form fields to solve/update instead of reaction fields.
Definition: system_base.hpp:64
std::vector< std::vector< std::string > > solve_input_field_names
Optional per-weak-form input field ordering used during solve.
Definition: system_base.hpp:66
struct storing time and timestep information
Definition: common.hpp:18
Defines the SystemBase struct for common system functionality.