MAST
Multidisciplinary-design Adaptation and Sensitivity Toolkit (MAST)
membrane_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/membrane_extension_uniaxial_stress/membrane_extension_uniaxial.h"
27 #include "examples/structural/membrane_extension_biaxial_stress/membrane_extension_biaxial.h"
28 #include "tests/base/check_sensitivity.h"
29 #include "base/nonlinear_system.h"
30 
31 
32 
33 void
34 uniaxial_membrane_sensitivity(MAST::MembraneExtensionUniaxial& mem) {
35 
36  const Real
37  tol = 1.e-2;
38 
39  // verify the sensitivity solution of this system
41  sol,
42  dsol,
43  dsol_fd;
44 
45  mem.solve();
46 
47  // make sure that each stress object has a single stored value
48  for (unsigned int i=0; i<mem._outputs.size(); i++)
49  BOOST_CHECK((mem._outputs[i]->n_elem_in_storage() == 1));
50 
51  const Real
52  press = (*mem._press)(),
53  Eval = (*mem._E)(),
54  nuval = (*mem._nu)(),
55  p_val = 2.;
56 
57  Real
58  analytical = 0.,
59  numerical = 0.;
60 
61  unsigned int
62  dof_num = 0;
63  libMesh::MeshBase::const_node_iterator
64  it = mem._mesh->local_nodes_begin(),
65  end = mem._mesh->local_nodes_end();
66 
67  // now clear the stress data structures
68  mem.clear_stresss();
69 
70  // now iterate over all the parameters and calculate the analytical
71  // sensitivity and compare with the numerical sensitivity
72 
74  // now evaluate the direct sensitivity
76 
77  for (unsigned int i=0; i<mem._params_for_sensitivity.size(); i++ ) {
78 
79  MAST::Parameter& f = *mem._params_for_sensitivity[i];
80 
81  // calculate the analytical sensitivity
82  // analysis is required at the baseline before sensitivity solution
83  // and the solution has changed after the previous perturbed solution
84  mem.solve();
85  const libMesh::NumericVector<Real>& dsol_vec = mem.sensitivity_solve(f);
86 
87  // make sure that each stress object has a single stored value
88  for (unsigned int i=0; i<mem._outputs.size(); i++)
89  BOOST_CHECK((mem._outputs[i]->n_elem_in_storage() == 1));
90 
91  BOOST_TEST_MESSAGE(" ** dX/dp (total) wrt : " << f.name() << " **");
92  it = mem._mesh->local_nodes_begin();
93  for ( ; it!=end; it++) {
94  const libMesh::Node* node = *it;
95 
96  // the x-displacement
97  dof_num = node->dof_number(mem._sys->number(),
98  mem._structural_sys->vars()[0],
99  0);
100  analytical = 0.;
101  if (f.name() == "E")
102  analytical = -(*node)(0) * press/pow(Eval,2);
103  else if (f.name() == "nu")
104  analytical = 0.;
105  else if (f.name() == "th")
106  analytical = 0.;
107  else
108  libmesh_error(); // should not get here
109  numerical = dsol_vec.el(dof_num);
110  BOOST_CHECK(MAST::compare_value(analytical, numerical, tol));
111 
112  // the y-displacement
113  dof_num = node->dof_number(mem._sys->number(),
114  mem._structural_sys->vars()[1],
115  0);
116  analytical = 0.;
117  if (f.name() == "E")
118  analytical = +nuval * (*node)(1) * press/pow(Eval,2);
119  else if (f.name() == "nu")
120  analytical = - (*node)(1) * press/Eval;
121  else if (f.name() == "th")
122  analytical = 0.;
123  else
124  libmesh_error(); // should not get here
125  numerical = dsol_vec.el(dof_num);
126  BOOST_CHECK(MAST::compare_value(analytical, numerical, tol));
127  }
128 
129 
130  // now check the stress value in each element, which should be the same as
131  // the pressure value specified for the problem
132  BOOST_TEST_MESSAGE(" ** dvm-stress/dp (total) wrt : " << f.name() << " **");
133  for (unsigned int i=0; i<mem._outputs.size(); i++) {
134  // the call to all elements should actually include a single element only
135  // the p-norm used is for p=2.
136  numerical =
137  mem._outputs[i]->von_Mises_p_norm_functional_sensitivity_for_all_elems(p_val, &f);
138  BOOST_CHECK(MAST::compare_value(0., numerical, tol));
139  }
140 
141 
142  // now clear the stress data structures
143  mem.clear_stresss();
144  }
145 
146 
148  // now evaluate the adjoint sensitivity
150 
151 
152 
153 }
154 
155 
156 
157 BOOST_FIXTURE_TEST_SUITE (Structural2DMembraneExtensionUniaxial,
158  MAST::MembraneExtensionUniaxial)
159 
160 
161 
162 BOOST_AUTO_TEST_CASE (MembraneExtensionUniaxialSolution) {
163 
164  const Real
165  tol = 1.e-2;
166 
167  this->init(libMesh::QUAD4, false);
168  this->solve();
169 
170  // check the solution
171  // this is a constant stress extension problem with the
172  // stress = pressure
173  // strain = pressure/E
174  // displacement = strain * length
175  //
176  // iterate over each node, and compare the nodal solution with the
177  // expected anlaytical value
178  unsigned int
179  dof_num = 0;
180  libMesh::MeshBase::const_node_iterator
181  it = _mesh->local_nodes_begin(),
182  end = _mesh->local_nodes_end();
183 
184  Real
185  press = (*_press)(),
186  Eval = (*_E)(),
187  nuval = (*_nu)(),
188  analytical = 0.,
189  numerical = 0.;
190 
191  for ( ; it!=end; it++) {
192  const libMesh::Node* node = *it;
193 
194  // the x-displacement
195  dof_num = node->dof_number(_sys->number(), _structural_sys->vars()[0], 0);
196  analytical = (*node)(0) * press/Eval;
197  numerical = _sys->solution->el(dof_num);
198  BOOST_CHECK(MAST::compare_value(analytical, numerical, tol));
199 
200  // the y-displacement
201  dof_num = node->dof_number(_sys->number(), _structural_sys->vars()[1], 0);
202  analytical = -nuval * (*node)(1) * press/Eval;
203  numerical = _sys->solution->el(dof_num);
204  BOOST_CHECK(MAST::compare_value(analytical, numerical, tol));
205  }
206 
207  // make sure that each stress object has a single stored value
208  for (unsigned int i=0; i<_outputs.size(); i++) {
209  BOOST_CHECK(_outputs[i]->n_elem_in_storage() == 1);
210  }
211 
212  // now check the stress value in each element, which should be the same as
213  // the pressure value specified for the problem
214  for (unsigned int i=0; i<_outputs.size(); i++) {
215  // the call to all elements should actually include a single element only
216  // the p-norm used is for p=2.
217  numerical = _outputs[i]->von_Mises_p_norm_functional_for_all_elems(2);
218  BOOST_CHECK(MAST::compare_value(press, numerical, tol));
219  }
220 }
221 
222 
223 BOOST_AUTO_TEST_CASE (MembraneExtensionUniaxialSensitivity) {
224 
226 }
227 
228 
229 BOOST_AUTO_TEST_SUITE_END()
230 
231 
232 
233 BOOST_FIXTURE_TEST_SUITE (Structural2DMembraneExtensionBiaxial,
234  MAST::MembraneExtensionBiaxial)
235 
236 BOOST_AUTO_TEST_CASE (MembraneExtensionBiaxialSensitivity) {
237 
239 }
240 
241 
242 BOOST_AUTO_TEST_SUITE_END()
243 
const std::string & name() const
returns the name of this function
Definition: function_base.h:60
This is a scalar function whose value can be changed and one that can be used as a design variable in...
Definition: parameter.h:35
void check_sensitivity(ValType &v)
BOOST_FIXTURE_TEST_SUITE(Structural2DMembraneExtensionUniaxial, MAST::MembraneExtensionUniaxial) BOOST_AUTO_TEST_CASE(MembraneExtensionUniaxialSolution)
void uniaxial_membrane_sensitivity(MAST::MembraneExtensionUniaxial &mem)
libMesh::Real Real
Matrix< Real, Dynamic, 1 > RealVectorX
bool compare_value(const Real v0, const Real v, const Real tol)
BOOST_AUTO_TEST_CASE(MembraneExtensionUniaxialSensitivity)