Serac  0.1
Serac is an implicit thermal strucural mechanics simulation code.
thermal_material_input.cpp
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 
8 
9 namespace serac {
10 
11 void ThermalMaterialInputOptions::defineInputFileSchema(axom::inlet::Container& container)
12 {
13  // Define schema with each thermal material parameter
14  container.addString("model", "The model of material").required(true);
15  container.addDouble("density", "Initial mass density");
16  container.addDouble("cp", "The specific heat capacity");
17 
18  // For LinearIsotropicConductor
19  container.addDouble("kappa", "The conductivity parameter");
20 
21  // For LinearConductor
22  container.addInt("dim", "Dimension of conductivity tensor parameter");
23  auto& kappa_tensor_container = container.addStruct("kappa_tensor", "The conductivity tensor parameter");
24  kappa_tensor_container.addDoubleArray("row1", "First row of the conductivity tensor parameter");
25  kappa_tensor_container.addDoubleArray("row2", "Second row of the conductivity tensor parameter");
26  kappa_tensor_container.addDoubleArray("row3", "Third row of the conductivity tensor parameter");
27 
28  // Verify
29  container.registerVerifier([](const axom::inlet::Container& c) -> bool {
30  axom::inlet::InletType double_type = axom::inlet::InletType::Double;
31  axom::inlet::InletType int_type = axom::inlet::InletType::Integer;
32  axom::inlet::InletType obj_type = axom::inlet::InletType::Object;
33  axom::inlet::InletType coll_type = axom::inlet::InletType::Collection;
34  std::string model = c["model"];
35  bool density_present = c.contains("density") && (c["density"].type() == double_type);
36  bool cp_present = c.contains("cp") && (c["cp"].type() == double_type);
37  bool kappa_present = c.contains("kappa") && (c["kappa"].type() == double_type);
38  bool dim_present = c.contains("dim") && (c["dim"].type() == int_type);
39  bool kappa_tensor_present = c.contains("kappa_tensor") && (c["kappa_tensor"].type() == obj_type);
40 
41  if (model == "LinearIsotropicConductor") {
42  return density_present && cp_present && kappa_present && !dim_present && !kappa_tensor_present;
43  } else if (model == "LinearConductor") {
44  if (density_present && cp_present && !kappa_present && dim_present && kappa_tensor_present) {
45  // Verify rows of kappa tensor struct is an array of doubles and is of proper size
46  int dim = c["dim"];
47  bool row1_present = c.contains("kappa_tensor/row1") && (c["kappa_tensor/row1"].type() == coll_type);
48  bool row2_present = c.contains("kappa_tensor/row2") && (c["kappa_tensor/row2"].type() == coll_type);
49  bool row3_present = c.contains("kappa_tensor/row3") && (c["kappa_tensor/row3"].type() == coll_type);
50  auto row1_size = c["kappa_tensor/row1"].get<std::vector<double>>().size();
51  auto row2_size = c["kappa_tensor/row2"].get<std::vector<double>>().size();
52  auto row3_size = c["kappa_tensor/row3"].get<std::vector<double>>().size();
53 
54  if (dim == 2) {
55  return row1_present && (row1_size == 2) && row2_present && (row2_size == 2) && !row3_present;
56  } else if (dim == 3) {
57  return row1_present && (row1_size == 3) && row2_present && (row2_size == 3) && row3_present &&
58  (row3_size == 3);
59  }
60  }
61  }
62 
63  return false;
64  });
65 }
66 
67 } // namespace serac
68 
69 std::vector<std::vector<double>> FromInlet<std::vector<std::vector<double>>>::operator()(
70  const axom::inlet::Container& base)
71 {
72  std::vector<std::vector<double>> result;
73 
74  result.push_back(base["row1"].get<std::vector<double>>());
75  result.push_back(base["row2"].get<std::vector<double>>());
76  result.push_back(base["row3"].get<std::vector<double>>());
77 
78  return result;
79 }
80 
82 {
84  std::string model = base["model"];
85 
86  if (model == "LinearIsotropicConductor") {
87  result = serac::heat_transfer::LinearIsotropicConductor(base["density"], base["cp"], base["kappa"]);
88  } else if (model == "LinearConductor") {
89  // Store tensor in a vector temporarily, then
90  // set the tensor values and material result based on the dimension
91  int dim = base["dim"];
92  if (dim == 2) {
93  std::vector<std::vector<double>> v = {base["kappa_tensor"]["row1"], base["kappa_tensor"]["row2"]};
94  serac::tensor<double, 2, 2> cond = {{{v[0][0], v[0][1]}, {v[1][0], v[1][1]}}};
95  result = serac::heat_transfer::LinearConductor<2>(base["density"], base["cp"], cond);
96  } else if (dim == 3) {
97  std::vector<std::vector<double>> v = {base["kappa_tensor"]["row1"], base["kappa_tensor"]["row2"],
98  base["kappa_tensor"]["row3"]};
100  {{v[0][0], v[0][1], v[0][2]}, {v[1][0], v[1][1], v[1][2]}, {v[2][0], v[2][1], v[2][2]}}};
101  result = serac::heat_transfer::LinearConductor<3>(base["density"], base["cp"], cond);
102  }
103  }
104 
105  return result;
106 }
constexpr auto get(std::integer_sequence< int, n... >)
return the Ith integer in {n...}
Accelerator functionality.
Definition: serac.cpp:38
std::variant< heat_transfer::LinearIsotropicConductor, heat_transfer::LinearConductor< 2 >, heat_transfer::LinearConductor< 3 > > var_thermal_material_t
Holds all possible heat transfer materials that can be utilized in our Input Deck.
constexpr SERAC_HOST_DEVICE int size(const tensor< T, n... > &)
returns the total number of stored values in a tensor
Definition: tensor.hpp:1851
constexpr SERAC_HOST_DEVICE auto type(const tuple< T... > &values)
a function intended to be used for extracting the ith type from a tuple.
Definition: tuple.hpp:274
serac::var_thermal_material_t operator()(const axom::inlet::Container &base)
Returns created object from Inlet container.
static void defineInputFileSchema(axom::inlet::Container &container)
Input file parameters specific to this class.
Linear anisotropic thermal material model.
Linear isotropic heat transfer material model.
Arbitrary-rank tensor class.
Definition: tensor.hpp:29
This file contains functions for reading a material from input files.