20 #ifndef __mast_check_sensitivity_h__ 21 #define __mast_check_sensitivity_h__ 24 #include "tests/base/test_comparisons.h" 26 #include "elasticity/structural_discipline.h" 36 #include "libmesh/numeric_vector.h" 41 template <
typename ValType>
55 const libMesh::NumericVector<Real>& sol_vec = v.solve();
58 for (
unsigned int i=0; i<v._outputs.size(); i++) {
59 BOOST_CHECK((v._outputs[i]->n_elem_in_storage() == 1));
63 n_dofs = sol_vec.size(),
64 n_elems = v._mesh->n_elem();
72 libmesh_assert(v._outputs.size() == n_elems);
74 stress0 = RealVectorX::Zero(n_elems),
75 dstressdp = RealVectorX::Zero(n_elems),
76 dstressdp_fd = RealVectorX::Zero(n_elems);
78 for (
unsigned int i=0; i<n_elems; i++) {
81 stress0(i) = v._outputs[i]->von_Mises_p_norm_functional_for_all_elems(p_val);
85 sol = RealVectorX::Zero(n_dofs);
86 dsol = RealVectorX::Zero(n_dofs);
89 for (
unsigned int i=0; i<n_dofs; i++) {
107 for (
unsigned int i=0; i<v._params_for_sensitivity.size(); i++ ) {
111 dsol = RealVectorX::Zero(n_dofs);
112 dsol_fd = RealVectorX::Zero(n_dofs);
113 dstressdp = RealVectorX::Zero(n_elems);
114 dstressdp_fd = RealVectorX::Zero(n_elems);
120 const libMesh::NumericVector<Real>& dsol_vec = v.sensitivity_solve(f);
123 for (
unsigned int i=0; i<v._outputs.size(); i++) {
124 BOOST_CHECK((v._outputs[i]->n_elem_in_storage() == 1));
128 for (
unsigned int j=0; j<n_dofs; j++) {
129 dsol(j) = dsol_vec(j);
133 for (
unsigned int j=0; j<n_elems; j++) {
135 v._outputs[j]->von_Mises_p_norm_functional_sensitivity_for_all_elems
146 (fabs(p0) > 0)? dp=delta*p0 : dp=delta;
150 const libMesh::NumericVector<Real>& sol_vec1 = v.solve();
153 for (
unsigned int i=0; i<v._outputs.size(); i++) {
154 BOOST_CHECK((v._outputs[i]->n_elem_in_storage() == 1));
158 for (
unsigned int i=0; i<n_dofs; i++) {
159 dsol_fd(i) = sol_vec1(i);
167 for (
unsigned int j=0; j<n_elems; j++) {
169 v._outputs[j]->von_Mises_p_norm_functional_for_all_elems(p_val);
173 dstressdp_fd -= stress0;
183 BOOST_TEST_MESSAGE(
" ** dX/dp (total) wrt : " << f.
name() <<
" **");
187 BOOST_TEST_MESSAGE(
" ** dvm-stress/dp (total) wrt : " << f.
name() <<
" **");
204 #endif // __mast_check_sensitivity_h__ 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...
void check_sensitivity(ValType &v)
Matrix< Real, Dynamic, 1 > RealVectorX