MAST
Multidisciplinary-design Adaptation and Sensitivity Toolkit (MAST)
nonlinear_system.h
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 #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(const libMesh::NumericVector<Real>& X,
143  bool if_localize_sol,
145  MAST::AssemblyBase& assembly,
146  const MAST::FunctionBase& p,
147  bool if_assemble_jacobian = true);
148 
149 
155  virtual void adjoint_solve(const libMesh::NumericVector<Real>& X,
156  bool if_localize_sol,
159  MAST::AssemblyBase& assembly,
160  bool if_assemble_jacobian = true);
161 
162 
166  virtual void eigenproblem_solve(MAST::AssemblyElemOperations& elem_ops,
167  MAST::EigenproblemAssembly& assembly);
168 
177  virtual void
179  MAST::EigenproblemAssembly& assembly,
180  const MAST::FunctionBase& f,
181  std::vector<Real>& sens,
182  const std::vector<unsigned int>* indices=nullptr);
183 
184 
190  virtual void
191  get_eigenvalue (unsigned int i, Real& re, Real& im);
192 
193 
208  virtual void
209  get_eigenpair (unsigned int i,
210  Real& re,
211  Real& im,
212  libMesh::NumericVector<Real>& vec_re,
213  libMesh::NumericVector<Real>* vec_im = nullptr);
214 
220  void set_exchange_A_and_B (bool flag) {_exchange_A_and_B = flag;}
221 
225  void set_n_requested_eigenvalues (unsigned int n)
226  { _n_requested_eigenpairs = n; };
227 
228 
232  unsigned int
234 
238  unsigned int
240 
244  unsigned int get_n_iterations () const {return _n_iterations;}
245 
249  void set_eigenproblem_type (libMesh::EigenProblemType ept);
250 
254  libMesh::EigenProblemType
256 
261  bool generalized () const { return _is_generalized_eigenproblem; }
262 
263 
267  libMesh::SparseMatrix<Real> *matrix_A;
268 
272  libMesh::SparseMatrix<Real> *matrix_B;
273 
274 
279  std::unique_ptr<MAST::SlepcEigenSolver> eigen_solver;
280 
284  std::unique_ptr<libMesh::LinearSolver<Real>> linear_solver;
285 
292 
296  unsigned int n_global_non_condensed_dofs() const;
297 
298 
302  void write_out_vector(libMesh::NumericVector<Real>& vec,
303  const std::string & directory_name,
304  const std::string & data_name,
305  const bool write_binary_vectors);
306 
307 
311  void read_in_vector(libMesh::NumericVector<Real>& vec,
312  const std::string & directory_name,
313  const std::string & data_name,
314  const bool read_binary_vectors);
315 
316  void
317  project_vector_without_dirichlet (libMesh::NumericVector<Real> & new_vector,
318  libMesh::FunctionBase<Real>& f) const;
319 
320  protected:
321 
322 
327  virtual void init_data () libmesh_override;
328 
329 
334  void set_n_converged (unsigned int nconv)
335  { _n_converged_eigenpairs = nconv; }
336 
341  void set_n_iterations (unsigned int its)
342  { _n_iterations = its;}
343 
344 
350 
351 
357 
362 
367 
372 
376  unsigned int _n_iterations;
377 
383 
387  libMesh::EigenProblemType _eigen_problem_type;
388 
393 
399  std::vector<libMesh::dof_id_type> _local_non_condensed_dofs_vector;
400 
401  };
402 }
403 
404 
405 #endif // __mast__nonlinear_system_h__
unsigned int _n_iterations
The number of iterations of the eigen solver algorithm.
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...
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 .
unsigned int get_n_requested_eigenvalues() const
libMesh::SparseMatrix< Real > * matrix_A
The system matrix for standard eigenvalue problems.
unsigned int get_n_converged_eigenvalues() const
void project_vector_without_dirichlet(libMesh::NumericVector< Real > &new_vector, libMesh::FunctionBase< Real > &f) const
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.
libMesh::EigenProblemType get_eigenproblem_type() const
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
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
unsigned int get_n_iterations() const
void set_n_converged(unsigned int nconv)
Set the _n_converged_eigenpairs member, useful for subclasses of EigenSystem.
virtual void sensitivity_solve(const libMesh::NumericVector< Real > &X, bool if_localize_sol, MAST::AssemblyElemOperations &elem_ops, MAST::AssemblyBase &assembly, const MAST::FunctionBase &p, bool if_assemble_jacobian=true)
Solves the sensitivity problem for the provided parameter.
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 adjoint_solve(const libMesh::NumericVector< Real > &X, bool if_localize_sol, MAST::AssemblyElemOperations &elem_ops, MAST::OutputAssemblyElemOperations &output, MAST::AssemblyBase &assembly, bool if_assemble_jacobian=true)
solves the adjoint problem for the provided output function.
virtual void solve(MAST::AssemblyElemOperations &elem_ops, MAST::AssemblyBase &assembly)
solves the nonlinear problem with the specified assembly operation object