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) 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  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  auto mat_with_dt = [&material, dt](auto& state, auto du_dx, parameter_types... parameters) {
98  return material(state, dt, du_dx, parameters...);
99  };
100  return uniaxial_stress_test(t_max, num_steps, mat_with_dt, initial_state, epsilon_xx, parameter_functions...);
101 }
102 
122 template <typename MaterialType, typename StateType, typename... functions>
123 auto single_quadrature_point_test(double t_max, size_t num_steps, const MaterialType material,
124  const StateType initial_state, const functions... f)
125 {
126  double t = 0;
127  const double dt = t_max / double(num_steps - 1);
128  auto state = initial_state;
129 
130  using output_type = decltype(std::tuple{t, state, f(0.0)..., decltype(material(state, dt, f(0.0)...)){}});
131  std::vector<output_type> history;
132  history.reserve(num_steps);
133 
134  for (size_t i = 0; i < num_steps; i++) {
135  auto material_output = material(state, dt, f(t)...);
136  history.push_back(std::tuple{t, state, f(t)..., material_output});
137  t += dt;
138  }
139 
140  return history;
141 }
142 
143 } // namespace serac
Accelerator functionality.
Definition: serac.cpp:36
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(const function &f, tensor< double, n > x0)
Finds a root of a vector-valued nonlinear function.
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.
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: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.