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" 28 #include "tests/base/test_comparisons.h" 30 #include "elasticity/structural_discipline.h" 42 #include "libmesh/dof_map.h" 46 const unsigned int case_num,
47 const libMesh::ElemType e_type,
51 template <
typename ValType>
59 const libMesh::Elem& elem = **(v._mesh->local_elements_begin());
62 std::unique_ptr<MAST::StructuralElementBase>
65 *v._p_card).release());
69 const libMesh::DofMap& dofmap = v._sys->get_dof_map();
70 std::vector<unsigned int> dof_ids;
71 dofmap.dof_indices(&elem, dof_ids);
73 const unsigned int ndofs = (
unsigned int)dof_ids.size();
76 libmesh_assert(ndofs == x.size());
80 res0 = RealVectorX::Zero(ndofs),
81 dresdp = RealVectorX::Zero(ndofs),
82 dresdp_fd = RealVectorX::Zero(ndofs);
85 jac0 = RealMatrixX::Zero(ndofs, ndofs),
86 djacdp = RealMatrixX::Zero(ndofs, ndofs),
87 djacdp_fd = RealMatrixX::Zero(ndofs, ndofs),
97 e->internal_residual(
true, res0, jac0);
100 for (
unsigned int i=0; i<v._params_for_sensitivity.size(); i++) {
105 e->sensitivity_param = &f;
111 e->internal_residual_sensitivity(
true, dresdp, djacdp);
114 e->sensitivity_param =
nullptr;
120 (fabs(p0) > 0)? dp=delta*p0 : dp=delta;
125 e->internal_residual(
true, dresdp_fd, djacdp_fd);
137 BOOST_TEST_MESSAGE(
" ** dres/dp (partial) wrt : " << f.
name() <<
" **");
139 BOOST_TEST_MESSAGE(
" ** djac/dp (partial) wrt : " << f.
name() <<
" **");
151 this->init(
false,
false);
156 BOOST_TEST_MESSAGE(
"**** Pure Extension Deformation **");
158 check_internal_force_and_jacobian_sensitivity<MAST::BuildStructural1DElem>
162 BOOST_TEST_MESSAGE(
"**** Pure Bending Deformation **");
164 check_internal_force_and_jacobian_sensitivity<MAST::BuildStructural1DElem>
168 BOOST_TEST_MESSAGE(
"**** Combined Extension-Bending Deformation **");
170 check_internal_force_and_jacobian_sensitivity<MAST::BuildStructural1DElem>
179 this->init(
false,
true);
184 BOOST_TEST_MESSAGE(
"**** Combined Extension-Bending Large Deformation **");
186 check_internal_force_and_jacobian_sensitivity<MAST::BuildStructural1DElem>
195 this->init(
true,
false);
200 BOOST_TEST_MESSAGE(
"**** Pure Extension Deformation **");
202 check_internal_force_and_jacobian_sensitivity<MAST::BuildStructural1DElem>
206 BOOST_TEST_MESSAGE(
"**** Pure Bending Deformation **");
208 check_internal_force_and_jacobian_sensitivity<MAST::BuildStructural1DElem>
212 BOOST_TEST_MESSAGE(
"**** Combined Extension-Bending Deformation **");
214 check_internal_force_and_jacobian_sensitivity<MAST::BuildStructural1DElem>
222 this->init(
true,
true);
227 BOOST_TEST_MESSAGE(
"**** Combined Extension-Bending Large Deformation **");
229 check_internal_force_and_jacobian_sensitivity<MAST::BuildStructural1DElem>
234 BOOST_AUTO_TEST_SUITE_END()
239 MAST::BuildStructural2DElem)
243 this->init(
false,
true, libMesh::QUAD4);
248 BOOST_TEST_MESSAGE(
"**** Pure Extension Deformation **");
250 check_internal_force_and_jacobian_sensitivity<MAST::BuildStructural2DElem>
253 BOOST_TEST_MESSAGE(
"**** Pure Bending Deformation **");
255 check_internal_force_and_jacobian_sensitivity<MAST::BuildStructural2DElem>
258 BOOST_TEST_MESSAGE(
"**** Combined Extension-Bending Deformation **");
260 check_internal_force_and_jacobian_sensitivity<MAST::BuildStructural2DElem>
269 this->init(
false,
true, libMesh::QUAD4);
273 BOOST_TEST_MESSAGE(
"**** Combined Extension-Bending Large Deformation **");
275 check_internal_force_and_jacobian_sensitivity<MAST::BuildStructural2DElem>
283 this->init(
false,
false, libMesh::TRI3);
288 BOOST_TEST_MESSAGE(
"**** Pure Extension Deformation **");
290 check_internal_force_and_jacobian_sensitivity<MAST::BuildStructural2DElem>
293 BOOST_TEST_MESSAGE(
"**** Pure Bending Deformation **");
295 check_internal_force_and_jacobian_sensitivity<MAST::BuildStructural2DElem>
298 BOOST_TEST_MESSAGE(
"**** Combined Extension-Bending Deformation **");
300 check_internal_force_and_jacobian_sensitivity<MAST::BuildStructural2DElem>
308 this->init(
false,
true, libMesh::TRI3);
312 BOOST_TEST_MESSAGE(
"**** Combined Extension-Bending Large Deformation **");
314 check_internal_force_and_jacobian_sensitivity<MAST::BuildStructural2DElem>
323 this->init(
true,
false, libMesh::QUAD4);
328 BOOST_TEST_MESSAGE(
"**** Pure Extension Deformation **");
330 check_internal_force_and_jacobian_sensitivity<MAST::BuildStructural2DElem>
333 BOOST_TEST_MESSAGE(
"**** Pure Bending Deformation **");
335 check_internal_force_and_jacobian_sensitivity<MAST::BuildStructural2DElem>
338 BOOST_TEST_MESSAGE(
"**** Combined Extension-Bending Deformation **");
340 check_internal_force_and_jacobian_sensitivity<MAST::BuildStructural2DElem>
348 this->init(
true,
true, libMesh::QUAD4);
352 BOOST_TEST_MESSAGE(
"**** Combined Extension-Bending Large Deformation **");
354 check_internal_force_and_jacobian_sensitivity<MAST::BuildStructural2DElem>
362 this->init(
true,
false, libMesh::TRI3);
367 BOOST_TEST_MESSAGE(
"**** Pure Extension Deformation **");
369 check_internal_force_and_jacobian_sensitivity<MAST::BuildStructural2DElem>
372 BOOST_TEST_MESSAGE(
"**** Pure Bending Deformation **");
374 check_internal_force_and_jacobian_sensitivity<MAST::BuildStructural2DElem>
377 BOOST_TEST_MESSAGE(
"**** Combined Extension-Bending Deformation **");
379 check_internal_force_and_jacobian_sensitivity<MAST::BuildStructural2DElem>
388 this->init(
true,
true, libMesh::TRI3);
392 BOOST_TEST_MESSAGE(
"**** Combined Extension-Bending Large Deformation **");
394 check_internal_force_and_jacobian_sensitivity<MAST::BuildStructural2DElem>
400 BOOST_AUTO_TEST_SUITE_END()
void set_deformation(const unsigned int dim, const unsigned int case_num, const libMesh::ElemType e_type, RealVectorX &vec)
BOOST_FIXTURE_TEST_SUITE(Structural1DInternalForceSensitivity, MAST::BuildStructural1DElem) BOOST_AUTO_TEST_CASE(InternalForceJacobianLinearSensitivity1DIndependentOffset)
const std::string & name() const
returns the name of this function
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...
BOOST_AUTO_TEST_CASE(InternalForceJacobianNonlinearSensitivity1DIndependentOffset)
bool compare_matrix(const RealMatrixX &m0, const RealMatrixX &m, const Real tol)
Matrix< Real, Dynamic, Dynamic > RealMatrixX
void check_internal_force_and_jacobian_sensitivity(ValType &v, const RealVectorX &x)
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