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