22 #include <boost/test/unit_test.hpp> 26 #include "tests/structural/build_structural_elem_1D.h" 27 #include "tests/structural/build_structural_elem_2D.h" 30 #include "tests/base/test_comparisons.h" 32 #include "elasticity/structural_discipline.h" 42 #include "libmesh/dof_map.h" 47 const unsigned int case_num,
48 const libMesh::ElemType e_type,
53 template <
typename ValType>
64 v._discipline->add_volume_load(0, *v._thermal_load);
68 const libMesh::Elem& elem = **(v._mesh->local_elements_begin());
71 std::unique_ptr<MAST::StructuralElementBase>
74 *v._p_card).release());
78 const libMesh::DofMap& dofmap = v._sys->get_dof_map();
79 std::vector<unsigned int> dof_ids;
80 dofmap.dof_indices(&elem, dof_ids);
82 const unsigned int ndofs = (
unsigned int)dof_ids.size();
85 libmesh_assert_equal_to(sol.size(), ndofs);
89 x0 = RealVectorX::Zero(ndofs),
90 xdot0 = RealVectorX::Zero(ndofs),
91 x = RealVectorX::Zero(ndofs),
92 xdot = RealVectorX::Zero(ndofs),
93 res0 = RealVectorX::Zero(ndofs),
94 res = RealVectorX::Zero(ndofs);
97 jac_x = RealMatrixX::Zero(ndofs, ndofs),
98 jac_xdot = RealMatrixX::Zero(ndofs, ndofs),
99 jac_x_fd = RealMatrixX::Zero(ndofs, ndofs),
100 jac_xdot_fd = RealMatrixX::Zero(ndofs, ndofs),
111 e->set_velocity(xdot);
115 e->volume_external_residual(
true,
119 v._discipline->volume_loads());
121 for (
unsigned int i=0; i<ndofs; i++) {
129 e->set_velocity(xdot);
133 e->volume_external_residual(
false,
137 v._discipline->volume_loads());
140 jac_x_fd.col(i) = (res-res0)/delta;
150 e->set_velocity(xdot);
154 e->volume_external_residual(
false,
158 v._discipline->volume_loads());
161 jac_xdot_fd.col(i) = (res-res0)/delta;
170 v._discipline->clear_volume_load(0, *v._thermal_load);
176 template <
typename ValType>
186 v._discipline->add_volume_load(0, *v._thermal_load);
189 const libMesh::Elem& elem = **(v._mesh->local_elements_begin());
192 std::unique_ptr<MAST::StructuralElementBase>
195 *v._p_card).release());
199 const libMesh::DofMap& dofmap = v._sys->get_dof_map();
200 std::vector<unsigned int> dof_ids;
201 dofmap.dof_indices(&elem, dof_ids);
203 const unsigned int ndofs = (
unsigned int)dof_ids.size();
206 libmesh_assert_equal_to(x.size(), ndofs);
210 res0 = RealVectorX::Zero(ndofs),
211 dresdp = RealVectorX::Zero(ndofs),
212 dresdp_fd = RealVectorX::Zero(ndofs);
215 jac0 = RealMatrixX::Zero(ndofs, ndofs),
216 djacdp = RealMatrixX::Zero(ndofs, ndofs),
217 djacdp_fd = RealMatrixX::Zero(ndofs, ndofs),
229 e->volume_external_residual(
true,
233 v._discipline->volume_loads());
236 for (
unsigned int i=0; i<v._params_for_sensitivity.size(); i++) {
241 e->sensitivity_param = &f;
247 e->volume_external_residual_sensitivity(
true,
251 v._discipline->volume_loads());
254 e->sensitivity_param =
nullptr;
260 (fabs(p0) > 0)? dp=delta*p0 : dp=delta;
265 e->volume_external_residual(
true,
269 v._discipline->volume_loads());
280 BOOST_TEST_MESSAGE(
" ** dres/dp (partial) wrt : " << f.
name() <<
" **");
282 BOOST_TEST_MESSAGE(
" ** djac/dp (partial) wrt : " << f.
name() <<
" **");
287 v._discipline->clear_volume_load(0, *v._thermal_load);
300 this->init(
false,
false);
302 check_thermal_residual_force_jacobian<MAST::BuildStructural1DElem>(*
this, v);
311 this->init(
false,
true);
313 check_thermal_residual_force_jacobian<MAST::BuildStructural1DElem>(*
this, v);
322 this->init(
true,
false);
324 check_thermal_residual_force_jacobian<MAST::BuildStructural1DElem>(*
this, v);
333 this->init(
true,
true);
335 check_thermal_residual_force_jacobian<MAST::BuildStructural1DElem>(*
this, v);
339 BOOST_AUTO_TEST_SUITE_END()
344 MAST::BuildStructural1DElem)
348 this->init(
false,
false);
353 BOOST_TEST_MESSAGE(
"**** Pure Extension Deformation **");
355 check_thermal_force_and_jacobian_sensitivity<MAST::BuildStructural1DElem>
359 BOOST_TEST_MESSAGE(
"**** Pure Bending Deformation **");
361 check_thermal_force_and_jacobian_sensitivity<MAST::BuildStructural1DElem>
365 BOOST_TEST_MESSAGE(
"**** Combined Extension-Bending Deformation **");
367 check_thermal_force_and_jacobian_sensitivity<MAST::BuildStructural1DElem>
376 this->init(
false,
true);
381 BOOST_TEST_MESSAGE(
"**** Combined Extension-Bending Large Deformation **");
383 check_thermal_force_and_jacobian_sensitivity<MAST::BuildStructural1DElem>
391 this->init(
true,
false);
396 BOOST_TEST_MESSAGE(
"**** Pure Extension Deformation **");
398 check_thermal_force_and_jacobian_sensitivity<MAST::BuildStructural1DElem>
402 BOOST_TEST_MESSAGE(
"**** Pure Bending Deformation **");
404 check_thermal_force_and_jacobian_sensitivity<MAST::BuildStructural1DElem>
408 BOOST_TEST_MESSAGE(
"**** Combined Extension-Bending Deformation **");
410 check_thermal_force_and_jacobian_sensitivity<MAST::BuildStructural1DElem>
420 this->init(
true,
true);
425 BOOST_TEST_MESSAGE(
"**** Combined Extension-Bending Large Deformation **");
427 check_thermal_force_and_jacobian_sensitivity<MAST::BuildStructural1DElem>
434 BOOST_AUTO_TEST_SUITE_END()
439 MAST::BuildStructural2DElem)
446 this->init(
false,
false, libMesh::QUAD4);
448 check_thermal_residual_force_jacobian<MAST::BuildStructural2DElem>(*
this, v);
457 this->init(
false,
false, libMesh::TRI3);
459 check_thermal_residual_force_jacobian<MAST::BuildStructural2DElem>(*
this, v);
468 this->init(
false,
true, libMesh::QUAD4);
470 check_thermal_residual_force_jacobian<MAST::BuildStructural2DElem>(*
this, v);
479 this->init(
false,
true, libMesh::TRI3);
481 check_thermal_residual_force_jacobian<MAST::BuildStructural2DElem>(*
this, v);
490 this->init(
true,
false, libMesh::QUAD4);
492 check_thermal_residual_force_jacobian<MAST::BuildStructural2DElem>(*
this, v);
501 this->init(
true,
false, libMesh::TRI3);
503 check_thermal_residual_force_jacobian<MAST::BuildStructural2DElem>(*
this, v);
512 this->init(
true,
true, libMesh::QUAD4);
514 check_thermal_residual_force_jacobian<MAST::BuildStructural2DElem>(*
this, v);
523 this->init(
true,
true, libMesh::TRI3);
525 check_thermal_residual_force_jacobian<MAST::BuildStructural2DElem>(*
this, v);
529 BOOST_AUTO_TEST_SUITE_END()
535 MAST::BuildStructural2DElem)
539 this->init(
false,
false, libMesh::QUAD4);
544 BOOST_TEST_MESSAGE(
"**** Pure Extension Deformation **");
546 check_thermal_force_and_jacobian_sensitivity<MAST::BuildStructural2DElem>
550 BOOST_TEST_MESSAGE(
"**** Pure Bending Deformation **");
552 check_thermal_force_and_jacobian_sensitivity<MAST::BuildStructural2DElem>
556 BOOST_TEST_MESSAGE(
"**** Combined Extension-Bending Deformation **");
558 check_thermal_force_and_jacobian_sensitivity<MAST::BuildStructural2DElem>
567 this->init(
false,
false, libMesh::TRI3);
572 BOOST_TEST_MESSAGE(
"**** Pure Extension Deformation **");
574 check_thermal_force_and_jacobian_sensitivity<MAST::BuildStructural2DElem>
578 BOOST_TEST_MESSAGE(
"**** Pure Bending Deformation **");
580 check_thermal_force_and_jacobian_sensitivity<MAST::BuildStructural2DElem>
584 BOOST_TEST_MESSAGE(
"**** Combined Extension-Bending Deformation **");
586 check_thermal_force_and_jacobian_sensitivity<MAST::BuildStructural2DElem>
596 this->init(
false,
true, libMesh::QUAD4);
601 BOOST_TEST_MESSAGE(
"**** Combined Extension-Bending Large Deformation **");
603 check_thermal_force_and_jacobian_sensitivity<MAST::BuildStructural2DElem>
612 this->init(
false,
true, libMesh::TRI3);
617 BOOST_TEST_MESSAGE(
"**** Combined Extension-Bending Large Deformation **");
619 check_thermal_force_and_jacobian_sensitivity<MAST::BuildStructural2DElem>
629 this->init(
true,
false, libMesh::QUAD4);
634 BOOST_TEST_MESSAGE(
"**** Pure Extension Deformation **");
636 check_thermal_force_and_jacobian_sensitivity<MAST::BuildStructural2DElem>
640 BOOST_TEST_MESSAGE(
"**** Pure Bending Deformation **");
642 check_thermal_force_and_jacobian_sensitivity<MAST::BuildStructural2DElem>
646 BOOST_TEST_MESSAGE(
"**** Combined Extension-Bending Deformation **");
648 check_thermal_force_and_jacobian_sensitivity<MAST::BuildStructural2DElem>
657 this->init(
true,
false, libMesh::TRI3);
662 BOOST_TEST_MESSAGE(
"**** Pure Extension Deformation **");
664 check_thermal_force_and_jacobian_sensitivity<MAST::BuildStructural2DElem>
668 BOOST_TEST_MESSAGE(
"**** Pure Bending Deformation **");
670 check_thermal_force_and_jacobian_sensitivity<MAST::BuildStructural2DElem>
674 BOOST_TEST_MESSAGE(
"**** Combined Extension-Bending Deformation **");
676 check_thermal_force_and_jacobian_sensitivity<MAST::BuildStructural2DElem>
686 this->init(
true,
true, libMesh::QUAD4);
691 BOOST_TEST_MESSAGE(
"**** Combined Extension-Bending Large Deformation **");
693 check_thermal_force_and_jacobian_sensitivity<MAST::BuildStructural2DElem>
702 this->init(
true,
true, libMesh::TRI3);
707 BOOST_TEST_MESSAGE(
"**** Combined Extension-Bending Large Deformation **");
709 check_thermal_force_and_jacobian_sensitivity<MAST::BuildStructural2DElem>
716 BOOST_AUTO_TEST_SUITE_END()
void set_deformation(const unsigned int dim, const unsigned int case_num, const libMesh::ElemType e_type, RealVectorX &vec)
const std::string & name() const
returns the name of this function
void check_thermal_residual_force_jacobian(ValType &v, const RealVectorX &sol)
BOOST_AUTO_TEST_CASE(ThermalResidualNonlinear1DIndependentOffset)
BOOST_FIXTURE_TEST_SUITE(Structural1DJacobianEvaluation, MAST::BuildStructural1DElem) BOOST_AUTO_TEST_CASE(ThermalResidualLinear1DIndependentOffset)
bool compare_vector(const RealVectorX &v0, const RealVectorX &v, const Real tol)
This is a scalar function whose value can be changed and one that can be used as a design variable in...
bool compare_matrix(const RealMatrixX &m0, const RealMatrixX &m, const Real tol)
Matrix< Real, Dynamic, Dynamic > RealMatrixX
Matrix< Real, Dynamic, 1 > RealVectorX
std::unique_ptr< MAST::StructuralElementBase > build_structural_element(MAST::SystemInitialization &sys, const MAST::GeomElem &elem, const MAST::ElementPropertyCardBase &p)
builds the structural element for the specified element type
void check_thermal_force_and_jacobian_sensitivity(ValType &v, const RealVectorX &x)