MAST
structural_near_null_vector_space.cpp
Go to the documentation of this file.
1 /*
2  * MAST: Multidisciplinary-design Adaptation and Sensitivity Toolkit
3  * Copyright (C) 2013-2019 Manav Bhatia
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 // MAST includes
22 #include "base/nonlinear_system.h"
23 
24 // libMesh includes
25 #include "libmesh/function_base.h"
26 #include "libmesh/numeric_vector.h"
27 #include "libmesh/exodusII_io.h"
28 
29 namespace MAST {
30 
32  public libMesh::FunctionBase<Real> {
33  public:
34  StructuralModes(const unsigned int mode_num):
35  libMesh::FunctionBase<Real>(),
36  _mode(mode_num) {
37 
38  // make sure the mode number makes sense
39  libmesh_assert_less_equal(mode_num, 5);
40  }
41 
42 
43  virtual std::unique_ptr<libMesh::FunctionBase<Real> > clone () const {
44 
45  libMesh::FunctionBase<Real> *rval = new MAST::StructuralModes(_mode);
46  return std::unique_ptr<libMesh::FunctionBase<Real> >(rval);
47  }
48 
49  // this should not get called
50  virtual Real operator()
51  (const libMesh::Point& p, const Real time) {libmesh_assert(false);}
52 
53  virtual void
54  operator() (const libMesh::Point& p,
55  const Real time,
56  libMesh::DenseVector<Real>& output) {
57 
58  output.resize(6);
59 
60  switch (_mode) {
61  case 0:
62  case 1:
63  case 2: {
64  output(_mode) = 1.;
65  }
66  break;
67 
68  case 3: {
69 
70  Real th = 1.e-5;
71  // rigid-body rotation
72  output(_mode) = th;
73  // also set deformation assuming rotation about (x,y,z)=0
74  // theta-x is only going to lead to changes in y,z
75  output(1) = (cos(th) * p(1) - sin(th) * p(2)) - p(1);
76  output(2) = (sin(th) * p(1) + cos(th) * p(2)) - p(2);
77  }
78  break;
79 
80  case 4: {
81 
82  Real th = 1.e-5;
83  // rigid-body rotation
84  output(_mode) = th;
85  // also set deformation assuming rotation about (x,y,z)=0
86  // theta-y is only going to lead to changes in x,z
87  output(0) = ( cos(th) * p(0) + sin(th) * p(2)) - p(0);
88  output(2) = (-sin(th) * p(0) + cos(th) * p(2)) - p(2);
89  }
90  break;
91 
92  case 5: {
93 
94  Real th = 1.e-5;
95  // rigid-body rotation
96  output(_mode) = th;
97  // also set deformation assuming rotation about (x,y,z)=0
98  // theta-z is only going to lead to changes in x,y
99  output(0) = (cos(th) * p(0) - sin(th) * p(1)) - p(0);
100  output(1) = (sin(th) * p(0) + cos(th) * p(1)) - p(1);
101  }
102  break;
103 
104  default:
105  libmesh_error(); // should not get here
106  }
107  }
108  protected:
109 
120  const unsigned int _mode;
121  };
122 }
123 
124 
125 
127 libMesh::NonlinearImplicitSystem::ComputeVectorSubspace() {
128 
129  _nm.resize(6);
130  _nm[0] = "x_translation_mode";
131  _nm[1] = "y_translation_mode";
132  _nm[2] = "z_translation_mode";
133  _nm[3] = "tx_rotation_mode";
134  _nm[4] = "ty_rotation_mode";
135  _nm[5] = "tz_rotation_mode";
136 
137 }
138 
139 
140 void
142 operator()(std::vector<libMesh::NumericVector<Real>*>&sp,
143  libMesh::NonlinearImplicitSystem& s) {
144 
145 
146  MAST::NonlinearSystem& sys = dynamic_cast<MAST::NonlinearSystem&>(s);
147 
148  // make sure that the vector coming in is of zero-size
149  libmesh_assert_equal_to(sp.size(), 0);
150 
151  // now initialize six vectors and add them to the system and sp
152  sp.resize(6);
153 
154  // the names of these six vectors, for storage
155  std::vector<std::string> nm(6);
156  nm[0] = "x_translation_mode";
157  nm[1] = "y_translation_mode";
158  nm[2] = "z_translation_mode";
159  nm[3] = "tx_rotation_mode";
160  nm[4] = "ty_rotation_mode";
161  nm[5] = "tz_rotation_mode";
162 
163 
164  // first, the three translation modes
165  for (unsigned int i=0; i<nm.size(); i++) {
166 
167  sp[i] = &s.add_vector(nm[i]);
168  sp[i]->zero();
169 
170  MAST::StructuralModes sol(i);
171  sys.project_vector_without_dirichlet(*sp[i], sol);
172 
173  //libMesh::ExodusII_IO(s.get_mesh()).write_equation_systems("output.exo",
174  // s.get_equation_systems());
175 
176  }
177 }
178 
179 
This class implements a system for solution of nonlinear systems.
virtual Real operator()(const libMesh::Point &p, const Real time)
libMesh::Real Real
StructuralModes(const unsigned int mode_num)
virtual std::unique_ptr< libMesh::FunctionBase< Real > > clone() const
const unsigned int _mode
mode number: 0 = rigid-body translation in x 1 = rigid-body translation in y 2 = rigid-body translati...
void project_vector_without_dirichlet(libMesh::NumericVector< Real > &new_vector, libMesh::FunctionBase< Real > &f) const
virtual void operator()(std::vector< libMesh::NumericVector< Real > * > &sp, libMesh::NonlinearImplicitSystem &s)
This function will be called to compute the subspace basis (e.g., nullspace or nearnullspace).