Smith  0.1
Smith is an implicit thermal structural mechanics simulation code.
material_verification_tools.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 
13 #pragma once
14 
15 #include <functional>
16 
19 
20 namespace smith {
21 
41 template <typename MaterialType, typename StateType, typename... parameter_types>
42 auto uniaxial_stress_test(double t_max, size_t num_steps, const MaterialType material, const StateType initial_state,
43  std::function<double(double)> epsilon_xx, const parameter_types... parameter_functions)
44 {
45  double t = 0;
46  const double dt = t_max / double(num_steps - 1);
47 
48  auto state = initial_state;
49 
50  auto sigma_yy_and_zz = [&](auto x) {
51  auto epsilon_yy = x[0];
52  auto epsilon_zz = x[1];
53  using T = decltype(epsilon_yy);
54  tensor<T, 3, 3> du_dx{};
55  du_dx[0][0] = epsilon_xx(t);
56  du_dx[1][1] = epsilon_yy;
57  du_dx[2][2] = epsilon_zz;
58  auto state_copy = state;
59  auto stress = material(state_copy, du_dx, parameter_functions(t)...);
60  return tensor{{stress[1][1], stress[2][2]}};
61  };
62 
63  std::vector<tuple<double, tensor<double, 3, 3>, tensor<double, 3, 3>, StateType> > output_history;
64  output_history.reserve(num_steps);
65 
66  tensor<double, 3, 3> dudx{};
67  for (size_t i = 0; i < num_steps; i++) {
68  auto initial_guess = tensor<double, 2>{dudx[1][1], dudx[2][2]};
69  auto epsilon_yy_and_zz = find_root(sigma_yy_and_zz, initial_guess);
70  dudx[0][0] = epsilon_xx(t);
71  dudx[1][1] = epsilon_yy_and_zz[0];
72  dudx[2][2] = epsilon_yy_and_zz[1];
73 
74  auto stress = material(state, dudx, parameter_functions(t)...);
75  output_history.push_back(tuple{t, dudx, stress, state});
76 
77  t += dt;
78  }
79 
80  return output_history;
81 }
82 
91 template <typename MaterialType, typename StateType, typename... parameter_types>
92 auto uniaxial_stress_test_rate_dependent(double t_max, size_t num_steps, const MaterialType material,
93  const StateType initial_state, std::function<double(double)> epsilon_xx,
94  const parameter_types... parameter_functions)
95 {
96  const double dt = t_max / double(num_steps - 1);
97  // Make the lambda a generic callable that forwards all extra parameters
98  auto mat_with_dt = [&material, dt](auto& state, auto du_dx, auto&&... params) {
99  return material(state, dt, du_dx, std::forward<decltype(params)>(params)...);
100  };
101  return uniaxial_stress_test(t_max, num_steps, mat_with_dt, initial_state, epsilon_xx, parameter_functions...);
102 }
103 
123 template <typename MaterialType, typename StateType, typename... functions>
124 auto single_quadrature_point_test(double t_max, size_t num_steps, const MaterialType material,
125  const StateType initial_state, const functions... f)
126 {
127  double t = 0;
128  const double dt = t_max / double(num_steps - 1);
129  auto state = initial_state;
130 
131  using output_type = decltype(std::tuple{t, state, f(0.0)..., decltype(material(state, dt, f(0.0)...)){}});
132  std::vector<output_type> history;
133  history.reserve(num_steps);
134 
135  for (size_t i = 0; i < num_steps; i++) {
136  auto material_output = material(state, dt, f(t)...);
137  history.push_back(std::tuple{t, state, f(t)..., material_output});
138  t += dt;
139  }
140 
141  return history;
142 }
143 
144 } // namespace smith
Accelerator functionality.
Definition: smith.cpp:36
tuple(T...) -> tuple< T... >
Class template argument deduction rule for tuples.
auto uniaxial_stress_test_rate_dependent(double t_max, size_t num_steps, const MaterialType material, const StateType initial_state, std::function< double(double)> epsilon_xx, const parameter_types... parameter_functions)
Drive a rate-dependent material model thorugh a uniaxial tension experiment.
auto uniaxial_stress_test(double t_max, size_t num_steps, const MaterialType material, const StateType initial_state, std::function< double(double)> epsilon_xx, const parameter_types... parameter_functions)
Drive the material model thorugh a uniaxial tension experiment.
auto single_quadrature_point_test(double t_max, size_t num_steps, const MaterialType material, const StateType initial_state, const functions... f)
This function takes a material model (and associate state variables), subjects it to a time history o...
auto find_root(const function &f, tensor< double, n > x0)
Finds a root of a vector-valued nonlinear function.
Arbitrary-rank tensor class.
Definition: tensor.hpp:28
This is a class that mimics most of std::tuple's interface, except that it is usable in CUDA kernels ...
Definition: tuple.hpp:28
Implementation of the tensor class used by Functional.
Implements a std::tuple-like object that works in CUDA kernels.