Smith  0.1
Smith is an implicit thermal structural mechanics simulation code.
system_base.hpp
Go to the documentation of this file.
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 
12 #pragma once
13 
14 #include <string>
15 #include <vector>
16 #include <memory>
17 #include <utility>
18 #include "field_state.hpp"
19 #include "field_store.hpp"
20 #include "system_solver.hpp"
21 #include "state_advancer.hpp"
22 #include "smith/physics/common.hpp"
23 #include "mfem.hpp"
24 
25 namespace smith {
26 
27 template <typename... Args>
28 struct Parameters;
29 
30 namespace detail {
31 
34 template <std::size_t, typename T>
35 using always_t = T;
36 
38 template <typename Space, typename... Tail, std::size_t... Is>
39 auto time_rule_params_impl(std::index_sequence<Is...>) -> Parameters<always_t<Is, Space>..., Tail...>;
40 
41 } // namespace detail
42 
45 template <typename Rule, typename Space, typename... Tail>
47  decltype(detail::time_rule_params_impl<Space, Tail...>(std::make_index_sequence<Rule::num_states>{}));
48 
52 struct SystemBase {
53  // --- equations ---
54  std::vector<std::shared_ptr<WeakForm>> weak_forms;
55 
56  // --- infrastructure ---
57  std::shared_ptr<FieldStore> field_store;
58  std::shared_ptr<SystemSolver> solver;
59  std::vector<std::shared_ptr<SystemBase>>
62  std::vector<std::shared_ptr<SystemBase>> post_solve_systems;
63  std::vector<std::string>
65  std::vector<std::vector<std::string>>
67 
69  SystemBase() = default;
76  explicit SystemBase(std::shared_ptr<FieldStore> fs, std::shared_ptr<SystemSolver> sol = nullptr,
77  std::vector<std::shared_ptr<WeakForm>> wfs = {})
78  : weak_forms(std::move(wfs)), field_store(std::move(fs)), solver(std::move(sol))
79  {
80  }
81  virtual ~SystemBase() = default;
82 
88  virtual std::vector<FieldState> solve(const TimeInfo& time_info) const;
89 
96  virtual std::vector<ReactionState> computeReactions(const TimeInfo& time_info,
97  const std::vector<FieldState>& states_for_reactions) const;
98 };
99 
103 inline std::shared_ptr<SystemBase> makeSystem(std::shared_ptr<FieldStore> field_store,
104  std::shared_ptr<SystemSolver> solver,
105  std::vector<std::shared_ptr<WeakForm>> weak_forms)
106 {
107  return std::make_shared<SystemBase>(std::move(field_store), std::move(solver), std::move(weak_forms));
108 }
109 
110 } // namespace smith
111 
112 namespace smith {
113 namespace detail {
114 
116 template <typename WeakFormT, typename FieldStorePtr, typename... Args, std::size_t... Is>
117 auto buildWeakFormWithCouplingImpl(const FieldStorePtr& field_store, const std::string& weak_form_name,
118  const std::string& unknown_field_name, const std::tuple<Args...>& args_tuple,
119  std::index_sequence<Is...>)
120 {
121  auto coupling_fields_tuple = std::get<sizeof...(Args) - 1>(args_tuple);
122  return std::apply(
123  [&](const auto&... coupling_fields) {
124  return std::make_shared<WeakFormT>(weak_form_name, field_store->getMesh(),
125  field_store->getField(unknown_field_name).get()->space(),
126  field_store->createSpaces(weak_form_name, unknown_field_name,
127  std::get<Is>(args_tuple)..., coupling_fields...));
128  },
129  coupling_fields_tuple);
130 }
131 
133 template <typename WeakFormT, typename FieldStorePtr, typename... Args>
134 auto buildWeakFormWithCoupling(const FieldStorePtr& field_store, const std::string& weak_form_name,
135  const std::string& unknown_field_name, const Args&... args)
136 {
137  return buildWeakFormWithCouplingImpl<WeakFormT>(field_store, weak_form_name, unknown_field_name, std::tie(args...),
138  std::make_index_sequence<sizeof...(Args) - 1>{});
139 }
140 
141 } // namespace detail
142 } // namespace smith
A file defining some enums and structs that are used by the different physics modules.
constexpr auto get(std::integer_sequence< int, n... >)
return the Ith integer in {n...}
T always_t
Helper: given an index and a type, always produces the type (used to repeat a type N times via pack e...
Definition: system_base.hpp:35
auto time_rule_params_impl(std::index_sequence< Is... >) -> Parameters< always_t< Is, Space >..., Tail... >
Implementation for TimeRuleParams: repeat Space N times, then append Tail...
auto buildWeakFormWithCouplingImpl(const FieldStorePtr &field_store, const std::string &weak_form_name, const std::string &unknown_field_name, const std::tuple< Args... > &args_tuple, std::index_sequence< Is... >)
Expands coupling tuple into trailing weak-form space arguments.
auto buildWeakFormWithCoupling(const FieldStorePtr &field_store, const std::string &weak_form_name, const std::string &unknown_field_name, const Args &... args)
Builds weak form using regular args plus final coupling pack argument.
Accelerator functionality.
Definition: smith.cpp:36
std::shared_ptr< SystemBase > makeSystem(std::shared_ptr< FieldStore > field_store, std::shared_ptr< SystemSolver > solver, std::vector< std::shared_ptr< WeakForm >> weak_forms)
Convenience factory for a plain SystemBase.
decltype(detail::time_rule_params_impl< Space, Tail... >(std::make_index_sequence< Rule::num_states >{})) TimeRuleParams
Generate a Parameters<...> type with Rule::num_states copies of Space followed by additional Tail typ...
Definition: system_base.hpp:47
Interface and implementations for advancing from one step to the next. Typically these are time integ...
a struct that is used in the physics modules to clarify which template arguments are user-controlled ...
Definition: common.hpp:59
Base struct for physics systems containing common members and helper functions.
Definition: system_base.hpp:52
std::vector< std::shared_ptr< SystemBase > > cycle_zero_systems
Definition: system_base.hpp:60
std::vector< std::shared_ptr< WeakForm > > weak_forms
Weak forms solved together by this system.
Definition: system_base.hpp:54
std::vector< std::shared_ptr< SystemBase > > post_solve_systems
Optional systems solved after main state update.
Definition: system_base.hpp:62
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
SystemBase()=default
Construct an empty system shell.
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
SystemBase(std::shared_ptr< FieldStore > fs, std::shared_ptr< SystemSolver > sol=nullptr, std::vector< std::shared_ptr< WeakForm >> wfs={})
Construct a system from a field store, solver, and weak forms.
Definition: system_base.hpp:76
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