MAST
Multidisciplinary-design Adaptation and Sensitivity Toolkit (MAST)
beam_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/beam_modal_analysis/beam_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 (Structural1DBeamModalAnalysis,
39  MAST::BeamModalAnalysis)
40 
41 BOOST_AUTO_TEST_CASE (BeamModalSolution) {
42 
43  this->init(libMesh::EDGE2, false);
44 
45  const Real
46  tol = 1.e-2;
47 
48  std::vector<Real>
49  eig;
50 
51  this->solve(false, &eig);
52 
53  // check the solution
54  // iterate over each node, and compare the nodal solution with the
55  // expected anlaytical value
56  Real
57  th_y = (*_thy)(),
58  th_z = (*_thz)(),
59  Izz = pow(th_z,1)*pow(th_y,3)/12.,
60  A = th_z*th_y,
61  rho = (*_rho)(),
62  Eval = (*_E)(),
63  pi = acos(-1.),
64  analytical = 0.;
65 
66 
67  // analytical solution to the natural frequency of simply supported problem
68  // is
69  // lambda = omega^2 = (n pi/L)^4 EI/(rho A)
70  //
71  unsigned int
72  nconv = std::min(_sys->get_n_converged_eigenvalues(),
73  _sys->get_n_requested_eigenvalues());
74 
75  for (unsigned int i=0; i<nconv; i++) {
76 
77  analytical = Eval*Izz/(rho*A) * pow((i+1)*pi/_length, 4);
78 
79  // compare the eigenvalues
80  BOOST_CHECK(MAST::compare_value(analytical, eig[i], tol));
81  }
82 }
83 
84 
85 
86 BOOST_AUTO_TEST_CASE (BeamModalSolutionSensitivity) {
87 
88  const Real
89  delta = 1.e-5,
90  tol = 1.e-3;
91 
92  std::vector<Real>
93  eig_vec,
94  deig_vec;
95 
96  this->solve(false, &eig_vec);
97 
98  unsigned int
99  nconv = std::min(_sys->get_n_converged_eigenvalues(),
100  _sys->get_n_requested_eigenvalues());
101 
102 
103  // verify the sensitivity solution of this system
105  eig = RealVectorX::Zero(nconv),
106  deig = RealVectorX::Zero(nconv),
107  deig_fd = RealVectorX::Zero(nconv);
108 
109  for (unsigned int i=0; i<nconv; i++) eig(i) = eig_vec[i];
110 
111 
112  // now iterate over all the parameters and calculate the analytical
113  // sensitivity and compare with the numerical sensitivity
114 
115  Real
116  p0 = 0.,
117  dp = 0.;
118 
120  // now evaluate the direct sensitivity
122 
123  for (unsigned int i=0; i<this->_params_for_sensitivity.size(); i++ ) {
124 
125  MAST::Parameter& f = *this->_params_for_sensitivity[i];
126 
127  // calculate the analytical sensitivity
128  // analysis is required at the baseline before sensitivity solution
129  // and the solution has changed after the previous perturbed solution
130  this->solve(false, &eig_vec);
131  std::vector<Real> deig_vec(nconv);
132  this->sensitivity_solve(f, deig_vec);
133  for (unsigned int i=0; i<nconv; i++) deig(i) = deig_vec[i];
134 
135  // now calculate the finite difference sensitivity
136 
137  // identify the perturbation in the parameter
138  p0 = f();
139  (fabs(p0) > 0)? dp=delta*p0 : dp=delta;
140  f() += dp;
141 
142  // solve at the perturbed parameter value
143  this->solve(false, &eig_vec);
144  for (unsigned int i=0; i<nconv; i++) deig_fd(i) = eig_vec[i];
145 
146  deig_fd -= eig;
147  deig_fd /= dp;
148 
149  // reset the parameter value
150  f() = p0;
151 
152  // now compare the eigenvalue sensitivity
153  BOOST_TEST_MESSAGE(" ** dlambda/dp (total) wrt : " << f.name() << " **");
154  BOOST_CHECK(MAST::compare_vector( deig_fd, deig, tol));
155  }
156 }
157 
158 BOOST_AUTO_TEST_SUITE_END()
159 
160 
161 
const std::string & name() const
returns the name of this function
Definition: function_base.h:60
BOOST_AUTO_TEST_CASE(BeamModalSolutionSensitivity)
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
libMesh::Real Real
Matrix< Real, Dynamic, 1 > RealVectorX
BOOST_FIXTURE_TEST_SUITE(Structural1DBeamModalAnalysis, MAST::BeamModalAnalysis) BOOST_AUTO_TEST_CASE(BeamModalSolution)
bool compare_value(const Real v0, const Real v, const Real tol)
#define pi