MAST
Multidisciplinary-design Adaptation and Sensitivity Toolkit (MAST)
bar_extension_evaluation.cpp
Go to the documentation of this file.
1 /*
2  * MAST: Multidisciplinary-design Adaptation and Sensitivity Toolkit
3  * Copyright (C) 2013-2020 Manav Bhatia and MAST authors
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 
21 // BOOST includes
22 #include <boost/test/unit_test.hpp>
23 
24 
25 // MAST includes
26 #include "examples/structural/bar_extension/bar_extension.h"
27 #include "tests/base/check_sensitivity.h"
28 #include "base/nonlinear_system.h"
29 
30 
31 
32 // libMesh includes
33 #include "libmesh/numeric_vector.h"
34 
35 
36 BOOST_FIXTURE_TEST_SUITE (Structural1DBarExtension,
37  MAST::BarExtension)
38 
39 BOOST_AUTO_TEST_CASE (BarExtensionSolution) {
40 
41  const Real
42  tol = 1.e-2;
43 
44  this->init(libMesh::EDGE2, false);
45  this->solve();
46 
47  // check the solution
48  // this is a constant stress extension problem with the
49  // stress = pressure
50  // strain = pressure/E
51  // displacement = strain * length
52  //
53  // iterate over each node, and compare the nodal solution with the
54  // expected anlaytical value
55  unsigned int
56  dof_num = 0;
57  libMesh::MeshBase::const_node_iterator
58  it = _mesh->local_nodes_begin(),
59  end = _mesh->local_nodes_end();
60 
61  Real
62  press = (*_press)(),
63  Eval = (*_E)(),
64  analytical = 0.,
65  numerical = 0.;
66 
67  for ( ; it!=end; it++) {
68  const libMesh::Node* node = *it;
69  dof_num = node->dof_number(_sys->number(), _structural_sys->vars()[0], 0);
70  analytical = (*node)(0) * press/Eval;
71  numerical = _sys->solution->el(dof_num);
72  BOOST_CHECK(MAST::compare_value(analytical, numerical, tol));
73  }
74 
75  // make sure that each stress object has a single stored value
76  for (unsigned int i=0; i<_outputs.size(); i++) {
77  BOOST_CHECK(_outputs[i]->n_elem_in_storage() == 1);
78  }
79 
80  // now check the stress value in each element, which should be the same as
81  // the pressure value specified for the problem
82  for (unsigned int i=0; i<_outputs.size(); i++) {
83  // the call to all elements should actually include a single element only
84  // the p-norm used is for p=2.
85  numerical = _outputs[i]->von_Mises_p_norm_functional_for_all_elems(2);
86  BOOST_CHECK(MAST::compare_value(press, numerical, tol));
87  }
88 }
89 
90 
91 BOOST_AUTO_TEST_CASE (BarExtensionSensitivity) {
92 
93  this->init(libMesh::EDGE2, false);
95 }
96 
97 
98 BOOST_AUTO_TEST_SUITE_END()
99 
100 
101 
void check_sensitivity(ValType &v)
libMesh::Real Real
BOOST_FIXTURE_TEST_SUITE(Structural1DBarExtension, MAST::BarExtension) BOOST_AUTO_TEST_CASE(BarExtensionSolution)
bool compare_value(const Real v0, const Real v, const Real tol)
BOOST_AUTO_TEST_CASE(BarExtensionSensitivity)