MAST
Multidisciplinary-design Adaptation and Sensitivity Toolkit (MAST)
plate_thermally_stressed_modal_analysis.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/plate_thermally_stressed_modal_analysis/plate_thermally_stressed_modal_analysis.h"
27 #include "tests/base/test_comparisons.h"
29 #include "elasticity/structural_discipline.h"
31 #include "base/parameter.h"
35 #include "base/nonlinear_system.h"
36 
37 
38 BOOST_FIXTURE_TEST_SUITE (StructuralPlateThermallyStressedModalAnalysis,
39  MAST::PlateThermallyStressedModalAnalysis)
40 
41 
42 
43 BOOST_AUTO_TEST_CASE (PlateThermallyStressedModalSolutionSensitivity) {
44 
45  // initialize plate object. Initialize with nonlinear strain
46  this->init(libMesh::QUAD4, true);
47 
48  const Real
49  delta = 1.e-6,
50  tol = 1.e-3;
51 
52  std::vector<Real>
53  eig_vec,
54  deig_vec;
55 
56  this->solve(false, &eig_vec);
57 
58  unsigned int
59  nconv = std::min(_sys->get_n_converged_eigenvalues(),
60  _sys->get_n_requested_eigenvalues());
61 
62 
63  // verify the sensitivity solution of this system
65  eig = RealVectorX::Zero(nconv),
66  deig = RealVectorX::Zero(nconv),
67  deig_fd = RealVectorX::Zero(nconv);
68 
69  for (unsigned int i=0; i<nconv; i++) eig(i) = eig_vec[i];
70 
71 
72  // now iterate over all the parameters and calculate the analytical
73  // sensitivity and compare with the numerical sensitivity
74 
75  Real
76  p0 = 0.,
77  dp = 0.;
78 
80  // now evaluate the direct sensitivity
82 
83  for (unsigned int i=0; i<this->_params_for_sensitivity.size(); i++ ) {
84 
85  MAST::Parameter& f = *this->_params_for_sensitivity[i];
86 
87  // calculate the analytical sensitivity
88  // analysis is required at the baseline before sensitivity solution
89  // and the solution has changed after the previous perturbed solution
90  this->solve(false, &eig_vec);
91  std::vector<Real> deig_vec(nconv);
92  this->sensitivity_solve(f, deig_vec);
93  for (unsigned int i=0; i<nconv; i++) deig(i) = deig_vec[i];
94 
95  // now calculate the finite difference sensitivity
96 
97  // identify the perturbation in the parameter
98  p0 = f();
99  (fabs(p0) > 0)? dp=delta*p0 : dp=delta;
100  f() += dp;
101 
102  // solve at the perturbed parameter value
103  this->solve(false, &eig_vec);
104  for (unsigned int i=0; i<nconv; i++) deig_fd(i) = eig_vec[i];
105 
106  deig_fd -= eig;
107  deig_fd /= dp;
108 
109  // reset the parameter value
110  f() = p0;
111 
112  // now compare the eigenvalue sensitivity
113  BOOST_TEST_MESSAGE(" ** dlambda/dp (total) wrt : " << f.name() << " **");
114  for (unsigned int i=0; i<deig.size(); i++)
115  std::cout << deig_fd(i) << " " << deig(i) << std::endl;
116  BOOST_CHECK(MAST::compare_vector( deig_fd, deig, tol));
117  }
118 }
119 
120 BOOST_AUTO_TEST_SUITE_END()
121 
122 
123 
const std::string & name() const
returns the name of this function
Definition: function_base.h:60
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...
Definition: parameter.h:35
BOOST_FIXTURE_TEST_SUITE(StructuralPlateThermallyStressedModalAnalysis, MAST::PlateThermallyStressedModalAnalysis) BOOST_AUTO_TEST_CASE(PlateThermallyStressedModalSolutionSensitivity)
libMesh::Real Real
BOOST_AUTO_TEST_CASE(InternalForceJacobianZeroFreq)
Matrix< Real, Dynamic, 1 > RealVectorX