MAST
Multidisciplinary-design Adaptation and Sensitivity Toolkit (MAST)
mast_3d_isotropic_element_property_card.cpp
Go to the documentation of this file.
1 // Catch2 includes
2 #include "catch.hpp"
3 
4 // libMesh includes
5 #include "libmesh/point.h"
6 
7 // MAST includes
8 #include "base/parameter.h"
12 
13 // Custom includes
14 #include "test_helpers.h"
15 
16 // TODO: Need to test with other types of materials.
17 // TODO: Need to test function that gets material.
18 
19 extern libMesh::LibMeshInit* p_global_init;
20 
21 TEST_CASE("element_property_card_constant_heat_transfer_isotropic_3d",
22  "[heat_transfer],[3D],[isotropic],[constant],[property]")
23 {
24  const uint dim = 3;
25 
26  // Define Material Properties as MAST Parameters
27  MAST::Parameter k("k_param", 237.0); // Thermal Conductivity
28 
29  // Create field functions to dsitribute these constant parameters throughout the model
30  MAST::ConstantFieldFunction k_f("k_th", k);
31 
32  // Initialize the material
34 
35  // Add the material property constant field functions to the material card
36  material.add(k_f);
37 
38  // Initialize the section
40 
41  // Add the material card to the section card
42  section.set_material(material);
43 
44  REQUIRE( section.dim() == dim);
45  REQUIRE( section.depends_on(k) );
46 
47  SECTION("3D section thermal conductance matrix")
48  {
59  std::unique_ptr<MAST::FieldFunction<RealMatrixX>> conduct_mat = section.thermal_conductance_matrix();
60 
61  const libMesh::Point point(2.3, 3.1, 5.2);
62  const Real time = 2.34;
63  RealMatrixX D_sec_conduc;
64  conduct_mat->operator()(point, time, D_sec_conduc);
65 
66  // Hard-coded value of the section's extension stiffness
67  RealMatrixX D_sec_conduc_true = RealMatrixX::Zero(3,3);
68  D_sec_conduc_true(0,0) = 237.0;
69  D_sec_conduc_true(1,1) = 237.0;
70  D_sec_conduc_true(2,2) = 237.0;
71 
72  // Convert the test and truth Eigen::Matrix objects to std::vector
73  // since Catch2 has built in methods to compare vectors
74  std::vector<double> test = TEST::eigen_matrix_to_std_vector(D_sec_conduc);
75  std::vector<double> truth = TEST::eigen_matrix_to_std_vector(D_sec_conduc_true);
76 
77  // Floating point approximations are diffcult to compare since the
78  // values typically aren't exactly equal due to numerical error.
79  // Therefore, we use the Approx comparison instead of Equals
80  CHECK_THAT( test, Catch::Approx<double>(truth) );
81  }
82 }
83 
84 
85 TEST_CASE("element_property_card_constant_transient_heat_transfer_isotropic_3d",
86  "[heat_transfer],[3D],[isotropic],[constant],[property],[transient]")
87 {
88  const uint dim = 3;
89 
90  // Define Material Properties as MAST Parameters
91  MAST::Parameter rho("rho_param", 1420.5); // Density
92  MAST::Parameter cp("cp_param", 908.0); // Specific Heat Capacity
93 
94  // Create field functions to dsitribute these constant parameters throughout the model
95  MAST::ConstantFieldFunction rho_f("rho", rho);
96  MAST::ConstantFieldFunction cp_f("cp", cp);
97 
98  // Initialize the material
100 
101  // Add the material property constant field functions to the material card
102  material.add(rho_f);
103  material.add(cp_f);
104 
105  // Initialize the section
107 
108  // Add the material card to the section card
109  section.set_material(material);
110 
111  REQUIRE( section.dim() == dim);
112  REQUIRE( section.depends_on(cp) );
113  REQUIRE( section.depends_on(rho) );
114 
115  SECTION("3D section thermal capacitance matrix")
116  {
127  std::unique_ptr<MAST::FieldFunction<RealMatrixX>> capaci_mat = section.thermal_capacitance_matrix();
128 
129  const libMesh::Point point(2.3, 3.1, 5.2);
130  const Real time = 2.34;
131  RealMatrixX D_sec_capac;
132  capaci_mat->operator()(point, time, D_sec_capac);
133 
134  // Hard-coded value of the section's extension stiffness
135  RealMatrixX D_sec_capac_true = RealMatrixX::Zero(1,1);
136  D_sec_capac_true(0,0) = 908.0*1420.5;
137 
138  // Convert the test and truth Eigen::Matrix objects to std::vector
139  // since Catch2 has built in methods to compare vectors
140  std::vector<double> test = TEST::eigen_matrix_to_std_vector(D_sec_capac);
141  std::vector<double> truth = TEST::eigen_matrix_to_std_vector(D_sec_capac_true);
142 
143  // Floating point approximations are diffcult to compare since the
144  // values typically aren't exactly equal due to numerical error.
145  // Therefore, we use the Approx comparison instead of Equals
146  CHECK_THAT( test, Catch::Approx<double>(truth) );
147  }
148 }
149 
150 
151 TEST_CASE("element_property_card_constant_thermoelastic_isotropic_3d",
152  "[thermoelastic],[3D],[isotropic],[constant],[property]")
153 {
154  const uint dim = 3;
155 
156  // Define Material Properties as MAST Parameters
157  MAST::Parameter E("E_param", 72.0e9); // Modulus of Elasticity
158  MAST::Parameter nu("nu_param", 0.33); // Poisson's ratio
159  MAST::Parameter alpha("alpha_param", 5.43e-05); // Coefficient of thermal expansion
160 
161  // Create field functions to dsitribute these constant parameters throughout the model
162  MAST::ConstantFieldFunction E_f("E", E);
163  MAST::ConstantFieldFunction nu_f("nu", nu);
164  MAST::ConstantFieldFunction alpha_f("alpha_expansion", alpha);
165 
166  // Initialize the material
168 
169  // Add the material property constant field functions to the material card
170  material.add(E_f);
171  material.add(nu_f);
172  material.add(alpha_f);
173 
174  // Initialize the section
176 
177  // Add the material card to the section card
178  section.set_material(material);
179 
180  REQUIRE( section.dim() == dim); // Ensure section is 2 dimensional
181  REQUIRE( section.depends_on(alpha) );
182 
183  SECTION("3D plane stress thermal expansion A matrix")
184  {
199  std::unique_ptr<MAST::FieldFunction<RealMatrixX>> texp_A_mat = section.thermal_expansion_A_matrix();
200 
201  const libMesh::Point point(2.3, 3.1, 5.2);
202  const Real time = 2.34;
203  RealMatrixX D_sec_texpA;
204  texp_A_mat->operator()(point, time, D_sec_texpA);
205 
206  // Hard-coded value of the section's extension stiffness
207  RealMatrixX D_sec_texpA_true = RealMatrixX::Zero(6,1);
208  D_sec_texpA_true(0,0) = 1.149882352941177e+07;
209  D_sec_texpA_true(1,0) = 1.149882352941177e+07;
210  D_sec_texpA_true(2,0) = 1.149882352941177e+07;
211 
212 
213  // Convert the test and truth Eigen::Matrix objects to std::vector
214  // since Catch2 has built in methods to compare vectors
215  std::vector<double> test = TEST::eigen_matrix_to_std_vector(D_sec_texpA);
216  std::vector<double> truth = TEST::eigen_matrix_to_std_vector(D_sec_texpA_true);
217 
218  // Floating point approximations are diffcult to compare since the
219  // values typically aren't exactly equal due to numerical error.
220  // Therefore, we use the Approx comparison instead of Equals
221  CHECK_THAT( test, Catch::Approx<double>(truth) );
222  }
223 
224 
225  SECTION("3D plane stress thermal expansion B matrix")
226  {
241  std::unique_ptr<MAST::FieldFunction<RealMatrixX>> texp_B_mat = section.thermal_expansion_B_matrix();
242 
243  const libMesh::Point point(2.3, 3.1, 5.2);
244  const Real time = 2.34;
245  RealMatrixX D_sec_texpB;
246  texp_B_mat->operator()(point, time, D_sec_texpB);
247 
248  // Hard-coded value of the section's extension stiffness
249  RealMatrixX D_sec_texpB_true = RealMatrixX::Zero(6,1);
250  D_sec_texpB_true(0,0) = 1.149882352941177e+07;
251  D_sec_texpB_true(1,0) = 1.149882352941177e+07;
252  D_sec_texpB_true(2,0) = 1.149882352941177e+07;
253 
254  // Convert the test and truth Eigen::Matrix objects to std::vector
255  // since Catch2 has built in methods to compare vectors
256  std::vector<double> test = TEST::eigen_matrix_to_std_vector(D_sec_texpB);
257  std::vector<double> truth = TEST::eigen_matrix_to_std_vector(D_sec_texpB_true);
258 
259  // Floating point approximations are diffcult to compare since the
260  // values typically aren't exactly equal due to numerical error.
261  // Therefore, we use the Approx comparison instead of Equals
262  CHECK_THAT( test, Catch::Approx<double>(truth) );
263  }
264 }
265 
266 
267 TEST_CASE("element_property_card_constant_dynamic_isotropic_3d",
268  "[dynamic],[3D],[isotropic],[constant],[property]")
269 {
270  const uint dim = 3;
271 
272  // Define Material Properties as MAST Parameters
273  MAST::Parameter rho("rho_param", 1420.5); // Density
274  MAST::Parameter E("E_param", 72.0e9); // Modulus of Elasticity
275  MAST::Parameter nu("nu_param", 0.33); // Poisson's ratio
276 
277  // Create field functions to dsitribute these constant parameters throughout the model
278  MAST::ConstantFieldFunction rho_f("rho", rho);
279  MAST::ConstantFieldFunction E_f("E", E);
280  MAST::ConstantFieldFunction nu_f("nu", nu);
281 
282  // Initialize the material
284 
285  // Add the material property constant field functions to the material card
286  material.add(rho_f);
287  material.add(E_f);
288  material.add(nu_f);
289 
290  // Initialize the section
292 
293  // Add the material card to the section card
294  section.set_material(material);
295 
296  REQUIRE( section.dim() == dim); // Ensure section is 2 dimensional
297  REQUIRE( section.depends_on(E) );
298  REQUIRE( section.depends_on(nu) );
299 
300  REQUIRE_FALSE( section.if_diagonal_mass_matrix() );
301 
302  section.set_diagonal_mass_matrix(true);
303  REQUIRE( section.if_diagonal_mass_matrix() );
304 
305  SECTION("3D section inertia matrix")
306  {
317  std::unique_ptr<MAST::FieldFunction<RealMatrixX>> inertia_mat = section.inertia_matrix();
318 
319  const libMesh::Point point(2.3, 3.1, 5.2);
320  const Real time = 2.34;
321  RealMatrixX D_sec_inertia;
322  inertia_mat->operator()(point, time, D_sec_inertia);
323 
324  // Hard-coded value of the section's extension stiffness
325  RealMatrixX D_sec_inertia_true = RealMatrixX::Identity(3,3);
326 
327  D_sec_inertia_true *= 1420.5;
328 
329  // Convert the test and truth Eigen::Matrix objects to std::vector
330  // since Catch2 has built in methods to compare vectors
331  std::vector<double> test = TEST::eigen_matrix_to_std_vector(D_sec_inertia);
332  std::vector<double> truth = TEST::eigen_matrix_to_std_vector(D_sec_inertia_true);
333 
334  // Floating point approximations are diffcult to compare since the
335  // values typically aren't exactly equal due to numerical error.
336  // Therefore, we use the Approx comparison instead of Equals
337  CHECK_THAT( test, Catch::Approx<double>(truth) );
338  }
339 }
340 
341 
342 
343 TEST_CASE("element_property_card_constant_structural_isotropic_3d",
344  "[structural],[3D],[isotropic],[constant],[property]")
345 {
346  const uint dim = 3;
347 
348  // Define Material Properties as MAST Parameters
349  MAST::Parameter E("E_param", 72.0e9); // Modulus of Elasticity
350  MAST::Parameter nu("nu_param", 0.33); // Poisson's ratio
351 
352 
353  // Create field functions to dsitribute these constant parameters throughout the model
354  MAST::ConstantFieldFunction E_f("E", E);
355  MAST::ConstantFieldFunction nu_f("nu", nu);
356 
357  // Initialize the material
359 
360  // Add the material property constant field functions to the material card
361  material.add(E_f);
362  material.add(nu_f);
363 
364  // Initialize the section
366 
367  // Add the material card to the section card
368  section.set_material(material);
369 
370  REQUIRE( section.dim() == dim); // Ensure section is 2 dimensional
371  REQUIRE( section.depends_on(E) );
372  REQUIRE( section.depends_on(nu) );
373 
374  SECTION("solid_2d_section is isotropic")
375  {
376  CHECK( section.if_isotropic() );
377  }
378 
379  SECTION("set_get_strain_type")
380  {
381  // Check that the default is linear strain
382  REQUIRE( section.strain_type() == MAST::LINEAR_STRAIN );
383 
385  REQUIRE( section.strain_type() == MAST::LINEAR_STRAIN );
386  REQUIRE_FALSE( section.strain_type() == MAST::NONLINEAR_STRAIN );
387 
389  REQUIRE( section.strain_type() == MAST::NONLINEAR_STRAIN );
390  REQUIRE_FALSE( section.strain_type() == MAST::LINEAR_STRAIN );
391  }
392 
393 // SECTION("quadrature_order")
394 // {
395 // section.set_bending_model(MAST::MINDLIN);
396 // REQUIRE( section.extra_quadrature_order(elem) == 0 );
397 //
398 // section.set_bending_model(MAST::DKT);
399 // REQUIRE( section.extra_quadrature_order(elem) == 2 );
400 // }
401 
402  SECTION("3D stiffness matrix")
403  {
414  std::unique_ptr<MAST::FieldFunction<RealMatrixX>> stiffness_mat = section.stiffness_A_matrix();
415 
416  const libMesh::Point point(2.3, 3.1, 5.2);
417  const Real time = 2.34;
418  RealMatrixX D_stiff;
419  stiffness_mat->operator()(point, time, D_stiff);
420 
421  // Hard-coded value of the section's extension stiffness
422  RealMatrixX D_stiff_true = RealMatrixX::Zero(6,6);
423  D_stiff_true(0,0) = 1.066784608580274e+11;
424  D_stiff_true(1,1) = 1.066784608580274e+11;
425  D_stiff_true(2,2) = 1.066784608580274e+11;
426  D_stiff_true(3,3) = 0.541353383458647e+11/2.0;
427  D_stiff_true(4,4) = 0.541353383458647e+11/2.0;
428  D_stiff_true(5,5) = 0.541353383458647e+11/2.0;
429 
430  D_stiff_true(0,1) = D_stiff_true(1,0) = 0.525431225121628e+11;
431  D_stiff_true(0,2) = D_stiff_true(2,0) = 0.525431225121628e+11;
432  D_stiff_true(1,2) = D_stiff_true(2,1) = 0.525431225121628e+11;
433 
434 
435  // Convert the test and truth Eigen::Matrix objects to std::vector
436  // since Catch2 has built in methods to compare vectors
437  std::vector<double> test = TEST::eigen_matrix_to_std_vector(D_stiff);
438  std::vector<double> truth = TEST::eigen_matrix_to_std_vector(D_stiff_true);
439 
440  // Floating point approximations are diffcult to compare since the
441  // values typically aren't exactly equal due to numerical error.
442  // Therefore, we use the Approx comparison instead of Equals
443  CHECK_THAT( test, Catch::Approx<double>(truth) );
444  }
445 
446 
447 
448 }
virtual bool if_isotropic() const
return true if the property is isotropic
virtual std::unique_ptr< MAST::FieldFunction< RealMatrixX > > thermal_expansion_A_matrix(const MAST::ElementBase &e) const
void set_diagonal_mass_matrix(bool m)
sets the mass matrix to be diagonal or consistent
virtual std::unique_ptr< MAST::FieldFunction< RealMatrixX > > thermal_expansion_B_matrix(const MAST::ElementBase &e) const
virtual bool depends_on(const MAST::FunctionBase &f) const
returns true if the property card depends on the function f
This is a scalar function whose value can be changed and one that can be used as a design variable in...
Definition: parameter.h:35
libMesh::Real Real
TEST_CASE("element_property_card_constant_heat_transfer_isotropic_3d", "[heat_transfer],[3D],[isotropic],[constant],[property]")
void set_strain(MAST::StrainType strain)
sets the type of strain to be used, which is LINEAR_STRAIN by default
virtual std::unique_ptr< MAST::FieldFunction< RealMatrixX > > inertia_matrix(const MAST::ElementBase &e) const
void add(MAST::FunctionBase &f)
adds the function to this card and returns a reference to it.
std::vector< double > eigen_matrix_to_std_vector(RealMatrixX M)
Converts an Eigen Matrix object to a std::vector.
libMesh::LibMeshInit * p_global_init
Definition: init_catch2.cpp:26
Matrix< Real, Dynamic, Dynamic > RealMatrixX
virtual std::unique_ptr< MAST::FieldFunction< RealMatrixX > > thermal_conductance_matrix(const MAST::ElementBase &e) const
virtual unsigned int dim() const
dimension of the element for which this property is defined
const MAST::StrainType strain_type() const
returns the type of strain to be used for this element
bool if_diagonal_mass_matrix() const
returns the type of strain to be used for this element
virtual std::unique_ptr< MAST::FieldFunction< RealMatrixX > > thermal_capacitance_matrix(const MAST::ElementBase &e) const
virtual void set_material(MAST::MaterialPropertyCardBase &mat)
sets the material card
virtual std::unique_ptr< MAST::FieldFunction< RealMatrixX > > stiffness_A_matrix(const MAST::ElementBase &e) const