Serac  0.1
Serac is an implicit thermal strucural mechanics simulation code.
material_verification_tools.hpp
Go to the documentation of this file.
1 // Copyright (c) 2019-2024, Lawrence Livermore National Security, LLC and
2 // other Serac 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 serac {
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 
47  auto state = initial_state;
48 
49  auto sigma_yy_and_zz = [&](auto x) {
50  auto epsilon_yy = x[0];
51  auto epsilon_zz = x[1];
52  using T = decltype(epsilon_yy);
53  tensor<T, 3, 3> du_dx{};
54  du_dx[0][0] = epsilon_xx(t);
55  du_dx[1][1] = epsilon_yy;
56  du_dx[2][2] = epsilon_zz;
57  auto state_copy = state;
58  auto stress = material(state_copy, du_dx, parameter_functions(t)...);
59  return tensor{{stress[1][1], stress[2][2]}};
60  };
61 
62  std::vector<tuple<double, tensor<double, 3, 3>, tensor<double, 3, 3>, StateType> > output_history;
63  output_history.reserve(num_steps);
64 
65  tensor<double, 3, 3> dudx{};
66  const double dt = t_max / double(num_steps - 1);
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 
102 template <typename MaterialType, typename StateType, typename... functions>
103 auto single_quadrature_point_test(double t_max, size_t num_steps, const MaterialType material,
104  const StateType initial_state, const functions... f)
105 {
106  double t = 0;
107  const double dt = t_max / double(num_steps - 1);
108  auto state = initial_state;
109 
110  using output_type = decltype(std::tuple{t, state, f(0.0)..., decltype(material(state, f(0.0)...)){}});
111  std::vector<output_type> history;
112  history.reserve(num_steps);
113 
114  for (size_t i = 0; i < num_steps; i++) {
115  auto material_output = material(state, f(t)...);
116  history.push_back(std::tuple{t, state, f(t)..., material_output});
117  t += dt;
118  }
119 
120  return history;
121 }
122 
123 } // namespace serac
Accelerator functionality.
Definition: serac.cpp:38
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 find_root(function &&f, tensor< double, n > x0)
Finds a root of a vector-valued nonlinear function.
tuple(T...) -> tuple< T... >
Class template argument deduction rule for tuples.
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...
Arbitrary-rank tensor class.
Definition: tensor.hpp:29
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.