Smith  0.1
Smith is an implicit thermal structural mechanics simulation code.
lumped_mass_explicit_newmark_state_advancer.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 
13 
14 namespace smith {
15 
18 {
19  auto s_bc = s.clone({s});
20 
21  s_bc.set_eval([=](const gretl::UpstreamStates& inputs, gretl::DownstreamState& output) {
22  auto s_new = std::make_shared<FiniteElementState>(*inputs[0].get<FEFieldPtr>());
23  s_new->SetSubVector(bc_manager->allEssentialTrueDofs(), 0.0);
24  output.set<FEFieldPtr, FEDualPtr>(s_new);
25  });
26 
27  s_bc.set_vjp([=](gretl::UpstreamStates& inputs, const gretl::DownstreamState& output) {
28  FiniteElementDual tmp(*output.get_dual<FEDualPtr, FEFieldPtr>());
29  tmp.SetSubVector(bc_manager->allEssentialTrueDofs(), 0.0);
30  inputs[0].get_dual<FEDualPtr, FEFieldPtr>()->Add(1.0, tmp);
31  });
32 
33  return s_bc.finalize();
34 }
35 
37  const TimeInfo& time_info, const FieldState& shape_disp, const std::vector<FieldState>& states_in,
38  const std::vector<FieldState>& params) const
39 {
41  SLIC_ERROR_IF(states_in.size() != 3, "ExplicitNewmark is a 2nd order time integrator requiring 3 states.");
42 
43  enum STATES
44  {
45  DISP,
46  VELO,
47  ACCEL
48  };
49 
50  enum PARAMS
51  {
52  DENSITY
53  };
54 
55  std::vector<FieldState> states = states_in;
56 
57  if (time_info.cycle() == 0 || !m_diag_inv) {
58  // Calculate a_pred, lumped mass version
59  auto lumped_mass = computeLumpedMass(mass_residual_eval_.get(), shape_disp, states[DISP], params[DENSITY]);
60  auto diag_inv = diagInverse(lumped_mass); // should return inverse of diagonal matrix as a field state
61  m_diag_inv = std::make_unique<FieldState>(diag_inv);
62  auto zero_mass_res = evalResidual(residual_eval_.get(), shape_disp, states, params, time_info, ACCEL);
63  auto a_initial = negativeComponentWiseMult(*m_diag_inv, zero_mass_res, bc_manager_.get());
64  states[ACCEL] = a_initial;
65  }
66 
67  double start_time = time_info.time();
68  double end_time = time_info.time() + time_info.dt();
69 
70  DoubleState stable_dt = ts_estimator_->dt(shape_disp, states, params);
71  DoubleState time =
72  gretl::clone_state([=](double) { return start_time; }, [](double, double, double&, double) {}, stable_dt);
73 
74  while (time.get() < end_time) {
75  if (time.get() + stable_dt.get() > end_time) {
76  stable_dt = end_time - time;
77  }
78 
79  time = time + stable_dt;
80 
81  // grabs initial states
82  const FieldState& u = states[DISP];
83  const FieldState& v = states[VELO];
84  const FieldState& a = states[ACCEL];
85 
86  // first pass of setting u and v predictors
87  FieldState v_half_step = v + 0.5 * (stable_dt * a);
88  FieldState u_pred = u + stable_dt * v_half_step;
89 
90  // zeroing out u predictor dofs associated with zero BCs
91  u_pred = applyZeroBoundaryConditions(u_pred, bc_manager_.get());
92  // create a vector of type FieldState called state_pred and put the u and v predictors into it
93  std::vector<FieldState> state_pred{u_pred, v_half_step, zeroCopy(a)};
94 
95  // should return the evaluation of the residual for the current state variables
96  auto zero_mass_res = evalResidual(residual_eval_.get(), shape_disp, state_pred, params,
97  TimeInfo(time.get(), time_info.dt(), time_info.cycle()), ACCEL);
98 
99  // m_diag_inv*zero_mass_res; // calculate the acceleration
100  auto a_pred = negativeComponentWiseMult(*m_diag_inv, zero_mass_res, bc_manager_.get());
101 
102  // update the v predictor after a predictor solves
103  FieldState v_pred = v_half_step + 0.5 * (stable_dt * a_pred);
104 
105  states = std::vector<FieldState>{u_pred, v_pred, a_pred};
106 
107  if (time.get() < end_time) {
108  stable_dt = ts_estimator_->dt(shape_disp, states, params);
109  }
110  }
111 
112  // place all solved updated states into the output
113  return states;
114 }
115 
116 } // namespace smith
This file contains the declaration of the boundary condition manager class.
A container for the boundary condition information relating to a specific physics module.
const mfem::Array< int > & allEssentialTrueDofs() const
Returns all the true degrees of freedom associated with all the essential BCs.
Class for encapsulating the dual vector space of a finite element space (i.e. the space of linear for...
std::vector< FieldState > advanceState(const TimeInfo &time_info, const FieldState &shape_disp, const std::vector< FieldState > &states, const std::vector< FieldState > &params) const override
This is an overloaded member function, provided for convenience. It differs from the above function o...
Implementation of explicit Newmark.
Accelerator functionality.
Definition: smith.cpp:36
FieldState diagInverse(const FieldState &x)
gretl-function implementation to compute invert the values for every entry in a FieldState.
FieldState evalResidual(const WeakForm *residual_eval, FieldState shape_disp, const std::vector< FieldState > &states, const std::vector< FieldState > &params, TimeInfo time_info, size_t inertial_index)
gretl-function implementation which evaluates the residual force (which is minus the mechanical force...
gretl::State< double, double > DoubleState
typedef
Definition: field_state.hpp:25
std::shared_ptr< FiniteElementState > FEFieldPtr
typedef
Definition: field_state.hpp:20
gretl::State< FEFieldPtr, FEDualPtr > FieldState
typedef
Definition: field_state.hpp:22
FieldState computeLumpedMass(const WeakForm *mass_residual_eval, const FieldState &shape_u, const FieldState &lumped_field, const FieldState &rho)
gretl-function implementation to compute lumped mass vectors from shape_displacements FieldState and ...
std::shared_ptr< FiniteElementDual > FEDualPtr
typedef
Definition: field_state.hpp:21
FieldState negativeComponentWiseMult(const FieldState &x, const FieldState &y, const BoundaryConditionManager *bc_manager)
gretl-function implementation which multiplies and then negates x and y component-wise to create a ne...
FieldState applyZeroBoundaryConditions(const FieldState &s, const BoundaryConditionManager *bc_manager)
uses the constrained dofs on the bc_manager to zero the corresponding dofs in FieldState s.
FieldState zeroCopy(const FieldState &x)
gretl-function to make a deep-copy of a FieldState and initialize it to 0.
Definition: field_state.cpp:76
#define SMITH_MARK_FUNCTION
Definition: profiling.hpp:90
struct storing time and timestep information
Definition: common.hpp:18
double dt() const
accessor for dt
Definition: common.hpp:29
size_t cycle() const
accessor for cycle
Definition: common.hpp:32
double time() const
accessor for the current time
Definition: common.hpp:26
Base class and implementations of an interface to estimate stable timesteps.
Specifies interface for evaluating weak form residuals and their gradients.