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" 43 #include "libmesh/dof_map.h" 44 #include "libmesh/elem.h" 45 #include "libmesh/edge_edge2.h" 51 const unsigned int case_num,
52 const libMesh::ElemType e,
57 vec = RealVectorX::Zero(12);
87 std::vector<unsigned int>
91 if (e == libMesh::QUAD4) {
92 vec = RealVectorX::Zero(24);
93 mem_dofs = {2, 3, 6, 7};
94 bend_dofs = {10, 11, 14, 15, 18, 19};
96 else if (e == libMesh::TRI3) {
97 vec = RealVectorX::Zero(18);
98 mem_dofs = {1, 2, 4, 5};
99 bend_dofs = {7, 8, 10, 11, 13, 14};
107 vec(mem_dofs[0]) = 2.e-2;
108 vec(mem_dofs[1]) = 4.e-2;
110 vec(mem_dofs[2]) = -2.e-2;
111 vec(mem_dofs[3]) = +6.e-2;
116 vec(bend_dofs[0]) = 2.e-2;
117 vec(bend_dofs[1]) = 4.e-2;
119 vec(bend_dofs[2]) = -2.e-2;
120 vec(bend_dofs[3]) = +6.e-2;
122 vec(bend_dofs[4]) = -2.e-2;
123 vec(bend_dofs[5]) = +6.e-2;
128 vec(mem_dofs[0]) = 2.e-2;
129 vec(mem_dofs[1]) = 4.e-2;
131 vec(mem_dofs[2]) = -2.e-2;
132 vec(mem_dofs[3]) = +6.e-2;
134 vec(bend_dofs[0]) = 2.e-2;
135 vec(bend_dofs[1]) = 4.e-2;
137 vec(bend_dofs[2]) = -2.e-2;
138 vec(bend_dofs[3]) = +6.e-2;
140 vec(bend_dofs[4]) = -2.e-2;
141 vec(bend_dofs[5]) = +6.e-2;
146 vec(mem_dofs[0]) = 2.e-1;
147 vec(mem_dofs[1]) = 4.e-1;
149 vec(mem_dofs[2]) = -2.e-1;
150 vec(mem_dofs[3]) = +6.e-1;
152 vec(bend_dofs[0]) = 2.e-1;
153 vec(bend_dofs[1]) = 4.e-1;
155 vec(bend_dofs[2]) = -2.e-1;
156 vec(bend_dofs[3]) = +6.e-1;
158 vec(bend_dofs[4]) = -2.e-1;
159 vec(bend_dofs[5]) = +6.e-1;
164 libmesh_assert(
false);
170 template <
typename ValType>
179 std::vector<libMesh::Point> pts(1);
180 pts[0] = libMesh::Point(0., 1., 0.);
183 output.set_points_for_evaluation(pts);
184 std::multimap<libMesh::subdomain_id_type, MAST::OutputFunctionBase*> output_map;
185 output_map.insert(std::pair<libMesh::subdomain_id_type, MAST::OutputFunctionBase*>
190 const libMesh::Elem& elem = **(v._mesh->local_elements_begin());
193 std::unique_ptr<MAST::StructuralElementBase>
196 *v._p_card).release());
200 const libMesh::DofMap& dofmap = v._sys->get_dof_map();
201 std::vector<unsigned int> dof_ids;
202 dofmap.dof_indices(&elem, dof_ids);
204 const unsigned int ndofs = (
unsigned int)dof_ids.size();
207 libmesh_assert_equal_to(ndofs, x0.size());
211 xdot0 = RealVectorX::Zero(ndofs),
212 x = RealVectorX::Zero(ndofs),
213 xdot = RealVectorX::Zero(ndofs),
214 stress0 = RealVectorX::Zero(6),
215 stress = RealVectorX::Zero(6),
216 strain0 = RealVectorX::Zero(6),
217 strain = RealVectorX::Zero(6),
218 dvm_dX0 = RealVectorX::Zero(ndofs),
219 dvmf_dX0 = RealVectorX::Zero(ndofs),
220 dvm_dX_fd = RealVectorX::Zero(ndofs),
221 dvmf_dX_fd = RealVectorX::Zero(ndofs),
222 dstressdp = RealVectorX::Zero(6),
223 dstraindp = RealVectorX::Zero(6);
226 dstressdX0 = RealMatrixX::Zero(6, ndofs),
227 dstressdX_fd = RealMatrixX::Zero(6, ndofs),
228 dstraindX0 = RealMatrixX::Zero(6, ndofs),
229 dstraindX_fd = RealMatrixX::Zero(6, ndofs);
247 e->set_velocity(xdot0);
250 e->volume_output_quantity(
true,
false, output_map);
254 const std::vector<MAST::StressStrainOutputBase::Data*>&
257 libmesh_assert_equal_to(stress_data.size(), 1);
259 stress0 = stress_data[0]->stress();
260 strain0 = stress_data[0]->strain();
261 dstressdX0 = stress_data[0]->get_dstress_dX();
262 dstraindX0 = stress_data[0]->get_dstrain_dX();
263 vm0 = stress_data[0]->von_Mises_stress();
264 dvm_dX0 = stress_data[0]->dvon_Mises_stress_dX();
265 vmf0 = output.von_Mises_p_norm_functional_for_all_elems(pval);
266 dvmf_dX0 = output.von_Mises_p_norm_functional_state_derivartive_for_all_elems(pval);
272 for (
unsigned int i=0; i<ndofs; i++) {
276 e->set_velocity(xdot);
278 e->volume_output_quantity(
false,
false, output_map);
282 const std::vector<MAST::StressStrainOutputBase::Data*>&
285 libmesh_assert_equal_to(stress_data.size(), 1);
287 stress = stress_data[0]->stress();
288 strain = stress_data[0]->strain();
289 dstressdX_fd.col(i) = (stress-stress0)/delta;
290 dstraindX_fd.col(i) = (strain-strain0)/delta;
291 vm = stress_data[0]->von_Mises_stress();
292 dvm_dX_fd(i) = (vm-vm0)/delta;
293 dvmf_dX_fd(i) = (output.von_Mises_p_norm_functional_for_all_elems(pval)-vm0)/delta;
300 BOOST_TEST_MESSAGE(
" ** Stress Derivative wrt State **");
302 BOOST_TEST_MESSAGE(
" ** Strain Derivative wrt State **");
304 BOOST_TEST_MESSAGE(
" ** VM-Stress Derivative wrt State **");
306 BOOST_TEST_MESSAGE(
" ** VM_func-Stress Derivative wrt State **");
316 for (
unsigned int i=0; i<v._params_for_sensitivity.size(); i++) {
321 x = RealVectorX::Zero(ndofs);
322 e->sensitivity_param = &f;
324 e->set_solution(x,
true);
327 e->volume_output_quantity(
false,
true, output_map);
331 const std::vector<MAST::StressStrainOutputBase::Data*>&
334 libmesh_assert_equal_to(stress_data.size(), 1);
336 dstressdp = stress_data[0]->get_stress_sensitivity(&f);
337 dstraindp = stress_data[0]->get_strain_sensitivity(&f);
338 dvmdp = stress_data[0]->dvon_Mises_stress_dp (&f);
340 output.von_Mises_p_norm_functional_sensitivity_for_all_elems(pval, &f);
349 (fabs(p0) > 0)? dp=delta*p0 : dp=delta;
353 e->volume_output_quantity(
false,
false, output_map);
360 const std::vector<MAST::StressStrainOutputBase::Data*>&
363 libmesh_assert_equal_to(stress_data.size(), 1);
365 stress = (stress_data[0]->stress() - stress0)/dp;
366 strain = (stress_data[0]->strain() - strain0)/dp;
367 vm = (stress_data[0]->von_Mises_stress() - vm0)/dp;
369 (output.von_Mises_p_norm_functional_for_all_elems(pval)-vmf0)/dp;
375 BOOST_TEST_MESSAGE(
" ** dStress/dp (partial) wrt : " << f.
name() <<
" **");
377 BOOST_TEST_MESSAGE(
" ** dStrain/dp (partial) wrt : " << f.
name() <<
" **");
379 BOOST_TEST_MESSAGE(
" ** dVM-Stress/dp (partial) wrt : " << f.
name() <<
" **");
381 BOOST_TEST_MESSAGE(
" ** dVM_func-Stress/dp (partial) wrt : " << f.
name() <<
" **");
390 for (
unsigned int i=0; i<v._params_for_sensitivity.size(); i++) {
396 for (
unsigned int j=0; j<ndofs; j++) {
406 (fabs(p0) > 0)? dp=std::max(delta*p0, delta) : dp=delta;
408 x = RealVectorX::Zero(ndofs);
410 e->set_solution(x,
true);
411 e->sensitivity_param = &f;
414 e->volume_output_quantity(
false,
true, output_map);
418 const std::vector<MAST::StressStrainOutputBase::Data*>&
421 libmesh_assert_equal_to(stress_data.size(), 1);
423 dstressdp = stress_data[0]->get_stress_sensitivity(&f);
424 dstraindp = stress_data[0]->get_strain_sensitivity(&f);
425 dvmdp = stress_data[0]->dvon_Mises_stress_dp (&f);
427 output.von_Mises_p_norm_functional_sensitivity_for_all_elems(pval, &f);
437 e->sensitivity_param =
nullptr;
444 x = RealVectorX::Zero(ndofs);
445 e->set_solution(x,
true);
448 e->volume_output_quantity(
false,
false, output_map);
455 const std::vector<MAST::StressStrainOutputBase::Data*>&
458 libmesh_assert_equal_to(stress_data.size(), 1);
460 stress = (stress_data[0]->stress() - stress0)/dp;
461 strain = (stress_data[0]->strain() - strain0)/dp;
462 vm = (stress_data[0]->von_Mises_stress() - vm0)/dp;
464 (output.von_Mises_p_norm_functional_for_all_elems(pval)-vmf0)/dp;
470 BOOST_TEST_MESSAGE(
" ** dStress/dp (total: dof = " << j <<
") wrt : " << f.
name() <<
" **");
472 BOOST_TEST_MESSAGE(
" ** dStrain/dp (total: dof = " << j <<
") wrt : " << f.
name() <<
" **");
474 BOOST_TEST_MESSAGE(
" ** dVM-Stress/dp (total: dof = " << j <<
") wrt : " << f.
name() <<
" **");
476 BOOST_TEST_MESSAGE(
" ** dVM_func-Stress/dp (total: dof = " << j <<
") wrt : " << f.
name() <<
" **");
492 std::unique_ptr<libMesh::Elem> elem(
new libMesh::Edge2);
496 strain = RealVectorX::Zero(6),
497 stress = RealVectorX::Zero(6);
514 stress(0) = -stress1;
518 stress(0) = -stress2;
522 const std::vector<MAST::StressStrainOutputBase::Data*>&
526 stress(0) = dstress1;
527 data[0]->set_sensitivity(&f, stress, strain);
528 stress(0) = -dstress1;
529 data[1]->set_sensitivity(&f, stress, strain);
530 stress(0) = dstress2;
531 data[2]->set_sensitivity(&f, stress, strain);
532 stress(0) = -dstress2;
533 data[3]->set_sensitivity(&f, stress, strain);
536 BOOST_TEST_MESSAGE(
" ** von Mises Stress ** ");
538 data[0]->von_Mises_stress(),
541 data[1]->von_Mises_stress(),
544 data[2]->von_Mises_stress(),
547 data[3]->von_Mises_stress(),
550 BOOST_TEST_MESSAGE(
" ** dvm-stress/dp **");
552 data[0]->dvon_Mises_stress_dp(&f),
555 data[1]->dvon_Mises_stress_dp(&f),
558 data[2]->dvon_Mises_stress_dp(&f),
561 data[3]->dvon_Mises_stress_dp(&f),
564 BOOST_TEST_MESSAGE(
" ** vm-stress functional **");
565 func = stress2/pow(4.*JxW,0.5)*
566 pow(pow(fabs( stress1)/stress2,2)*JxW +
567 pow(fabs(-stress1)/stress2,2)*JxW +
568 pow(fabs( stress2)/stress2,2)*JxW +
569 pow(fabs(-stress2)/stress2,2)*JxW,0.5);
572 output.von_Mises_p_norm_functional_for_all_elems(2),
576 BOOST_TEST_MESSAGE(
" ** dvm-stress functional/dp **");
578 dfunc = stress2/pow(4.*JxW,0.5)*0.5*
579 pow(pow(fabs( stress1)/stress2,2)*JxW +
580 pow(fabs(-stress1)/stress2,2)*JxW +
581 pow(fabs( stress2)/stress2,2)*JxW +
582 pow(fabs(-stress2)/stress2,2)*JxW,-.5) *
583 2 *(fabs( stress1)/stress2*dstress1/stress2*JxW +
584 fabs(-stress1)/stress2*dstress1/stress2*JxW +
585 fabs( stress2)/stress2*dstress2/stress2*JxW +
586 fabs(-stress2)/stress2*dstress2/stress2*JxW);
590 output.von_Mises_p_norm_functional_sensitivity_for_all_elems(2, &f),
601 this->init(
false,
false);
606 BOOST_TEST_MESSAGE(
"**** Pure Extension Deformation **");
611 BOOST_TEST_MESSAGE(
"**** Pure Bending Deformation **");
616 BOOST_TEST_MESSAGE(
"**** Combined Extension-Bending Deformation **");
626 this->init(
false,
true);
631 BOOST_TEST_MESSAGE(
"**** Combined Extension-Bending Large Deformation **");
640 this->init(
true,
false);
645 BOOST_TEST_MESSAGE(
"**** Pure Extension Deformation **");
650 BOOST_TEST_MESSAGE(
"**** Pure Bending Deformation **");
655 BOOST_TEST_MESSAGE(
"**** Combined Extension-Bending Deformation **");
664 this->init(
true,
true);
669 BOOST_TEST_MESSAGE(
"**** Combined Extension-Bending Large Deformation **");
675 BOOST_AUTO_TEST_SUITE_END()
682 this->init(
false,
false, libMesh::QUAD4);
687 BOOST_TEST_MESSAGE(
"**** Pure Extension Deformation **");
691 BOOST_TEST_MESSAGE(
"**** Pure Bending Deformation **");
695 BOOST_TEST_MESSAGE(
"**** Combined Extension-Bending Deformation **");
704 this->init(
false,
true, libMesh::QUAD4);
708 BOOST_TEST_MESSAGE(
"**** Combined Extension-Bending Large Deformation **");
717 this->init(
false,
false, libMesh::TRI3);
722 BOOST_TEST_MESSAGE(
"**** Pure Extension Deformation **");
726 BOOST_TEST_MESSAGE(
"**** Pure Bending Deformation **");
730 BOOST_TEST_MESSAGE(
"**** Combined Extension-Bending Deformation **");
739 this->init(
false,
true, libMesh::TRI3);
743 BOOST_TEST_MESSAGE(
"**** Combined Extension-Bending Large Deformation **");
752 this->init(
true,
false, libMesh::QUAD4);
757 BOOST_TEST_MESSAGE(
"**** Pure Extension Deformation **");
761 BOOST_TEST_MESSAGE(
"**** Pure Bending Deformation **");
765 BOOST_TEST_MESSAGE(
"**** Combined Extension-Bending Deformation **");
774 this->init(
true,
true, libMesh::QUAD4);
778 BOOST_TEST_MESSAGE(
"**** Combined Extension-Bending Large Deformation **");
787 this->init(
true,
false, libMesh::TRI3);
792 BOOST_TEST_MESSAGE(
"**** Pure Extension Deformation **");
796 BOOST_TEST_MESSAGE(
"**** Pure Bending Deformation **");
800 BOOST_TEST_MESSAGE(
"**** Combined Extension-Bending Deformation **");
810 this->init(
true,
true, libMesh::TRI3);
814 BOOST_TEST_MESSAGE(
"**** Combined Extension-Bending Large Deformation **");
821 BOOST_AUTO_TEST_SUITE_END()
const std::string & name() const
returns the name of this function
Data structure provides the mechanism to store stress and strain output from a structural analysis...
void clear()
clears the data structure of any stored values so that it can be used for another element...
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_FIXTURE_TEST_SUITE(PanelSmallDisturbanceFrequencyDomain2D, MAST::PanelInviscidSmallDisturbanceFrequencyDomain2DAnalysis) BOOST_AUTO_TEST_CASE(FreqDomainSensitivityWrtOmega)
virtual const std::vector< MAST::StressStrainOutputBase::Data * > & get_stress_strain_data_for_elem(const MAST::GeomElem &e) const
bool compare_matrix(const RealMatrixX &m0, const RealMatrixX &m, const Real tol)
BOOST_AUTO_TEST_CASE(VonMisesStress)
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
bool compare_value(const Real v0, const Real v, const Real tol)
void check_stress(ValType &v, const RealVectorX &x0)
virtual MAST::StressStrainOutputBase::Data & add_stress_strain_at_qp_location(const MAST::GeomElem &e, const unsigned int qp, const libMesh::Point &quadrature_pt, const libMesh::Point &physical_pt, const RealVectorX &stress, const RealVectorX &strain, Real JxW)
add the stress tensor associated with the qp.
void set_deformation(const unsigned int dim, const unsigned int case_num, const libMesh::ElemType e, RealVectorX &vec)