MAST
nonlinear_system.h
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 #ifndef __mast__nonlinear_system_h__
21 #define __mast__nonlinear_system_h__
22 
23 // C++ includes
24 #include <memory>
25 
26 // MAST includes
27 #include "base/mast_data_types.h"
28 
29 // libMesh includes
30 #include "libmesh/nonlinear_implicit_system.h"
31 #include "libmesh/enum_eigen_solver_type.h"
32 #include "libmesh/eigen_system.h"
33 
34 
35 namespace MAST {
36 
37 
38  // Forward declerations
39  class Parameter;
40  class SlepcEigenSolver;
41  class AssemblyBase;
42  class PhysicsDisciplineBase;
43  class AssemblyElemOperations;
44  class OutputAssemblyElemOperations;
45  class FunctionBase;
46  class EigenproblemAssembly;
47 
48 
57  public libMesh::NonlinearImplicitSystem {
58 
59  public:
60 
64  NonlinearSystem(libMesh::EquationSystems& es,
65  const std::string& name,
66  const unsigned int number);
67 
68 
69  virtual ~NonlinearSystem();
70 
71 
72  enum Operation {
78  };
79 
80 
85 
86  return _operation;
87  }
88 
89 
94 
95  _operation = op;
96  }
97 
103  _initialize_B_matrix = true;
104  }
105 
106 
111  virtual void clear () libmesh_override;
112 
113 
118  virtual void reinit () libmesh_override;
119 
120 
125  virtual std::pair<unsigned int, Real>
127 
128 
133  virtual void solve(MAST::AssemblyElemOperations& elem_ops,
134  MAST::AssemblyBase& assembly);
135 
136 
142  virtual void sensitivity_solve(MAST::AssemblyElemOperations& elem_ops,
143  MAST::AssemblyBase& assembly,
144  const MAST::FunctionBase& p,
145  bool if_assemble_jacobian = true);
146 
147 
153  virtual void adjoint_solve(MAST::AssemblyElemOperations& elem_ops,
155  MAST::AssemblyBase& assembly,
156  bool if_assemble_jacobian = true);
157 
158 
162  virtual void eigenproblem_solve(MAST::AssemblyElemOperations& elem_ops,
163  MAST::EigenproblemAssembly& assembly);
164 
173  virtual void
175  MAST::EigenproblemAssembly& assembly,
176  const MAST::FunctionBase& f,
177  std::vector<Real>& sens,
178  const std::vector<unsigned int>* indices=nullptr);
179 
180 
186  virtual void
187  get_eigenvalue (unsigned int i, Real& re, Real& im);
188 
189 
204  virtual void
205  get_eigenpair (unsigned int i,
206  Real& re,
207  Real& im,
208  libMesh::NumericVector<Real>& vec_re,
209  libMesh::NumericVector<Real>* vec_im = nullptr);
210 
216  void set_exchange_A_and_B (bool flag) {_exchange_A_and_B = flag;}
217 
221  void set_n_requested_eigenvalues (unsigned int n)
222  { _n_requested_eigenpairs = n; };
223 
224 
228  unsigned int
230 
234  unsigned int
236 
240  unsigned int get_n_iterations () const {return _n_iterations;}
241 
245  void set_eigenproblem_type (libMesh::EigenProblemType ept);
246 
250  libMesh::EigenProblemType
252 
257  bool generalized () const { return _is_generalized_eigenproblem; }
258 
259 
263  libMesh::SparseMatrix<Real> *matrix_A;
264 
268  libMesh::SparseMatrix<Real> *matrix_B;
269 
270 
275  std::unique_ptr<MAST::SlepcEigenSolver> eigen_solver;
276 
280  std::unique_ptr<libMesh::LinearSolver<Real>> linear_solver;
281 
288 
292  unsigned int n_global_non_condensed_dofs() const;
293 
294 
298  void write_out_vector(libMesh::NumericVector<Real>& vec,
299  const std::string & directory_name,
300  const std::string & data_name,
301  const bool write_binary_vectors);
302 
303 
307  void read_in_vector(libMesh::NumericVector<Real>& vec,
308  const std::string & directory_name,
309  const std::string & data_name,
310  const bool read_binary_vectors);
311 
312  void
313  project_vector_without_dirichlet (libMesh::NumericVector<Real> & new_vector,
314  libMesh::FunctionBase<Real>& f) const;
315 
316  protected:
317 
318 
323  virtual void init_data () libmesh_override;
324 
325 
330  void set_n_converged (unsigned int nconv)
331  { _n_converged_eigenpairs = nconv; }
332 
337  void set_n_iterations (unsigned int its)
338  { _n_iterations = its;}
339 
340 
346 
347 
353 
358 
363 
368 
372  unsigned int _n_iterations;
373 
379 
383  libMesh::EigenProblemType _eigen_problem_type;
384 
389 
395  std::vector<libMesh::dof_id_type> _local_non_condensed_dofs_vector;
396 
397  };
398 }
399 
400 
401 #endif // __mast__nonlinear_system_h__
unsigned int _n_iterations
The number of iterations of the eigen solver algorithm.
virtual void sensitivity_solve(MAST::AssemblyElemOperations &elem_ops, MAST::AssemblyBase &assembly, const MAST::FunctionBase &p, bool if_assemble_jacobian=true)
Solves the sensitivity problem for the provided parameter.
unsigned int get_n_converged_eigenvalues() const
unsigned int get_n_iterations() const
void initialize_condensed_dofs(MAST::PhysicsDisciplineBase &physics)
Loop over the dofs on each processor to initialize the list of non-condensed dofs.
void read_in_vector(libMesh::NumericVector< Real > &vec, const std::string &directory_name, const std::string &data_name, const bool read_binary_vectors)
reads the specified vector with the specified name in a directory.
This class implements a system for solution of nonlinear systems.
bool _is_generalized_eigenproblem
A boolean flag to indicate whether we are dealing with a generalized eigenvalue problem.
virtual void clear() libmesh_override
Clear all the data structures associated with the system.
void set_n_requested_eigenvalues(unsigned int n)
sets the number of eigenvalues requested
void write_out_vector(libMesh::NumericVector< Real > &vec, const std::string &directory_name, const std::string &data_name, const bool write_binary_vectors)
writes the specified vector with the specified name in a directory.
unsigned int _n_requested_eigenpairs
The number of requested eigenpairs.
This provides the base class for definitin of element level contribution of output quantity in an ana...
std::unique_ptr< MAST::SlepcEigenSolver > eigen_solver
The EigenSolver, definig which interface, i.e solver package to use.
bool _initialize_B_matrix
initialize the B matrix in addition to A, which might be needed for solution of complex system of equ...
unsigned int get_n_requested_eigenvalues() const
libMesh::Real Real
void set_eigenproblem_type(libMesh::EigenProblemType ept)
Sets the type of the current eigen problem.
virtual void reinit() libmesh_override
Reinitializes the member data fields associated with the system, so that, e.g., assemble() may be use...
MAST::NonlinearSystem::Operation _operation
current operation of the system
virtual void eigenproblem_sensitivity_solve(MAST::AssemblyElemOperations &elem_ops, MAST::EigenproblemAssembly &assembly, const MAST::FunctionBase &f, std::vector< Real > &sens, const std::vector< unsigned int > *indices=nullptr)
Solves the sensitivity system, for the provided parameters.
unsigned int n_global_non_condensed_dofs() const
Assembles the system of equations for an eigenproblem of type .
libMesh::SparseMatrix< Real > * matrix_A
The system matrix for standard eigenvalue problems.
bool _condensed_dofs_initialized
A private flag to indicate whether the condensed dofs have been initialized.
void set_n_iterations(unsigned int its)
Set the _n_iterations member, useful for subclasses of EigenSystem.
virtual void eigenproblem_solve(MAST::AssemblyElemOperations &elem_ops, MAST::EigenproblemAssembly &assembly)
Assembles & solves the eigen system.
virtual std::pair< unsigned int, Real > get_linear_solve_parameters()
calls NonlinearImplicitSystem::set_solver_parameters() before accessing the values.
virtual void init_data() libmesh_override
Initializes the member data fields associated with the system, so that, e.g., assemble() may be used...
libMesh::SparseMatrix< Real > * matrix_B
A second system matrix for generalized eigenvalue problems.
libMesh::EigenProblemType _eigen_problem_type
The type of the eigenvalue problem.
void set_init_B_matrix()
flag to also initialize the B matrix.
void set_operation(MAST::NonlinearSystem::Operation op)
sets the current operation of the system
libMesh::EigenProblemType get_eigenproblem_type() const
virtual void get_eigenvalue(unsigned int i, Real &re, Real &im)
gets the real and imaginary parts of the ith eigenvalue for the eigenproblem , and the associated eig...
std::unique_ptr< libMesh::LinearSolver< Real > > linear_solver
The LinearSolver for solution of the linear equations.
unsigned int _n_converged_eigenpairs
The number of converged eigenpairs.
std::vector< libMesh::dof_id_type > _local_non_condensed_dofs_vector
Vector storing the local dof indices that will not be condensed.
virtual void get_eigenpair(unsigned int i, Real &re, Real &im, libMesh::NumericVector< Real > &vec_re, libMesh::NumericVector< Real > *vec_im=nullptr)
gets the real and imaginary parts of the ith eigenvalue for the eigenproblem , and the associated eig...
MAST::NonlinearSystem::Operation operation()
bool _exchange_A_and_B
flag to exchange the A and B matrices in the eigenproblem solution
void project_vector_without_dirichlet(libMesh::NumericVector< Real > &new_vector, libMesh::FunctionBase< Real > &f) const
void set_n_converged(unsigned int nconv)
Set the _n_converged_eigenpairs member, useful for subclasses of EigenSystem.
virtual void adjoint_solve(MAST::AssemblyElemOperations &elem_ops, MAST::OutputAssemblyElemOperations &output, MAST::AssemblyBase &assembly, bool if_assemble_jacobian=true)
solves the adjoint problem for the provided output function.
void set_exchange_A_and_B(bool flag)
sets the flag to exchange the A and B matrices for a generalized eigenvalue problem.
NonlinearSystem(libMesh::EquationSystems &es, const std::string &name, const unsigned int number)
Default constructor.
virtual void solve(MAST::AssemblyElemOperations &elem_ops, MAST::AssemblyBase &assembly)
solves the nonlinear problem with the specified assembly operation object