[P]arallel [Hi]gh-order [Li]brary for [P]DEs  Latest
Parallel High-Order Library for PDEs through hp-adaptive Discontinuous Galerkin methods
NNLS_solver.h
1 
33 /* Note: This solver is based on a modified version of the algorithm descrived in "SOLVING
34  * LEAST SQUARES PROBLEMS". This is because in the context of Energy Conserving Sampling
35  * and Weighting a modified exit condition was introduced. The details regarding the exit
36  * condition (EQUATION 13) are described in the following paper:
37  * https://onlinelibrary.wiley.com/doi/full/10.1002/nme.5332
38  * More details on the ECSW hyper-reduction technique can be found in:
39  * https://onlinelibrary.wiley.com/doi/full/10.1002/nme.4820
40  *
41  * Additionally Functionality added to the Eigen NNLS:
42  * -Option to use Gradient Exit Condition (used in Eigen/original textbook) or Residual Exit Condition (default - Introduced in ECSW work) (discussed further in NNLS_solver.cpp)
43  * -Option to use an iterative linear solver or direct solve (default) for LS problem in the algorithm
44  * -Option to input a transposed matrix
45 */
46 
47 #ifndef NNLS_H
48 #define NNLS_H
49 
50 #include <iostream>
51 #include <string>
52 #include <AztecOO_config.h>
53 #include <Epetra_MpiComm.h>
54 #include <Epetra_ConfigDefs.h>
55 #include <Epetra_Map.h>
56 #include <Epetra_CrsMatrix.h>
57 #include <Epetra_Vector.h>
58 #include <Epetra_MultiVector.h>
59 #include <Epetra_Import.h>
60 #include <Epetra_LinearProblem.h>
61 #include <EpetraExt_MatrixMatrix.h>
62 #include <AztecOO.h>
63 #include <Amesos.h>
64 #include <Amesos_BaseSolver.h>
65 #include <eigen/Eigen/Dense>
66 #include "parameters/all_parameters.h"
67 #include "reduced_order/multi_core_helper_functions.h"
68 
69 using Eigen::Matrix;
70 namespace PHiLiP {
78 {
79 public:
81  NNLSSolver(
82  const Parameters::AllParameters *const parameters_input,
83  const dealii::ParameterHandler &parameter_handler_input,
84  const Epetra_CrsMatrix &A,
85  Epetra_MpiComm &Comm,
86  Epetra_Vector &b);
87 
89  NNLSSolver(
90  const Parameters::AllParameters *const parameters_input,
91  const dealii::ParameterHandler &parameter_handler_input,
92  const Epetra_CrsMatrix &A,
93  const bool is_input_A_matrix_transposed,
94  Epetra_MpiComm &Comm,
95  Epetra_Vector &b);
96 
98  NNLSSolver(
99  const Parameters::AllParameters *const parameters_input,
100  const dealii::ParameterHandler &parameter_handler_input,
101  const Epetra_CrsMatrix &A,
102  Epetra_MpiComm &Comm,
103  Epetra_Vector &b,
104  bool grad_exit_crit);
105 
107  NNLSSolver(
108  const Parameters::AllParameters *const parameters_input,
109  const dealii::ParameterHandler &parameter_handler_input,
110  const Epetra_CrsMatrix &A,
111  const bool is_input_A_matrix_transposed,
112  Epetra_MpiComm &Comm,
113  Epetra_Vector &b,
114  bool grad_exit_crit);
115 
117  NNLSSolver(
118  const Parameters::AllParameters *const parameters_input,
119  const dealii::ParameterHandler &parameter_handler_input,
120  const Epetra_CrsMatrix &A,
121  Epetra_MpiComm &Comm,
122  Epetra_Vector &b,
123  bool iter_solver,
124  int LS_iter,
125  double LS_tol);
126 
128  NNLSSolver(
129  const Parameters::AllParameters *const parameters_input,
130  const dealii::ParameterHandler &parameter_handler_input,
131  const Epetra_CrsMatrix &A,
132  const bool is_input_A_matrix_transposed,
133  Epetra_MpiComm &Comm,
134  Epetra_Vector &b,
135  bool iter_solver,
136  int LS_iter,
137  double LS_tol);
138 
140  NNLSSolver(
141  const Parameters::AllParameters *const parameters_input,
142  const dealii::ParameterHandler &parameter_handler_input,
143  const Epetra_CrsMatrix &A,
144  const bool is_input_A_matrix_transposed,
145  Epetra_MpiComm &Comm,
146  Epetra_Vector &b,
147  bool grad_exit_crit,
148  bool iter_solver,
149  int LS_iter,
150  double LS_tol);
151 
154 
156  bool solve();
157 
159  Epetra_Vector & get_solution() {return multi_x_;}
160 
162  void starting_solution(Epetra_Vector &start) {
163  Epetra_Vector start_single_core = allocate_vector_to_single_core(start);
164  P.flip();
165  sub_into_x(start_single_core);
166  P.flip();}
167 
169 
171  const dealii::ParameterHandler &parameter_handler;
172 
173 protected:
175  Epetra_MpiComm Comm_;
177  const Epetra_CrsMatrix A_;
179  Epetra_Vector b_;
181  Epetra_Vector x_;
183  Epetra_Vector multi_x_;
185  int LS_iter_;
187  double LS_tol_;
191  std::vector<bool> Z;
193  std::vector<bool> P;
194 
195 public:
204  int iter_;
205 
206 protected:
208  Eigen::VectorXd index_set;
209 
210 private:
212  void epetra_permutation_matrix(Epetra_CrsMatrix &P_mat);
213 
215  void positive_set_matrix(Epetra_CrsMatrix &P_mat);
216 
218  void sub_into_x(Epetra_Vector &temp);
219 
221  void add_into_x(Epetra_Vector &temp, double alpha);
222 
224  void move_to_active_set(int idx);
225 
227  void move_to_inactive_set(int idx);
228 
229 };
230 } // PHiLiP namespace
231 #endif // NNLS_H
std::vector< bool > Z
Vector of booleans representing the columns in the active set.
Definition: NNLS_solver.h:191
const dealii::ParameterHandler & parameter_handler
Parameter handler for storing the .prm file being ran.
Definition: NNLS_solver.h:171
Epetra_Vector & get_solution()
Returns protected approximate solution.
Definition: NNLS_solver.h:159
void move_to_active_set(int idx)
Moves the column at idx into the active set (updating the index_set, Z, P, and numInactive_) ...
std::vector< bool > P
Vector of boolean representing the columns in the inactive set.
Definition: NNLS_solver.h:193
~NNLSSolver()
Destructor.
Definition: NNLS_solver.h:153
const bool is_input_A_matrix_transposed_
Definition: NNLS_solver.h:202
Files for the baseline physics.
Definition: ADTypes.hpp:10
Main parameter class that contains the various other sub-parameter classes.
const Epetra_CrsMatrix A_
Epetra Matrix A allocated to a single core.
Definition: NNLS_solver.h:177
bool iter_solver_
Boolean used for iterative solvers.
Definition: NNLS_solver.h:197
Epetra_MpiComm Comm_
Epetra Commuicator Object with MPI.
Definition: NNLS_solver.h:175
Eigen::VectorXd index_set
Eigen Vector of the index_set.
Definition: NNLS_solver.h:208
Epetra_Vector multi_x_
Epetra_Vector x, to be solved. Allocated to multiple cores.
Definition: NNLS_solver.h:183
void sub_into_x(Epetra_Vector &temp)
Replaces the entries with x with the values in temp.
int LS_iter_
Needed if the an iterative solver is used.
Definition: NNLS_solver.h:185
int iter_
Number of iterations in the NNLS solver.
Definition: NNLS_solver.h:204
void move_to_inactive_set(int idx)
Moves the column at idx into the inactive set (updating the index_set, Z, P, and numInactive_) ...
NNLSSolver(const Parameters::AllParameters *const parameters_input, const dealii::ParameterHandler &parameter_handler_input, const Epetra_CrsMatrix &A, Epetra_MpiComm &Comm, Epetra_Vector &b)
Default Constructor.
Definition: NNLS_solver.cpp:7
bool grad_exit_crit_
Boolean to use an exit Condition depending on maximum gradent.
Definition: NNLS_solver.h:199
int numInactive_
Number of inactive points.
Definition: NNLS_solver.h:189
double LS_tol_
Needed if the an iterative solver is used.
Definition: NNLS_solver.h:187
Epetra_Vector x_
Epetra Vector x, to be solved. Allocated to a single core.
Definition: NNLS_solver.h:181
bool solve()
Call to solve NNLS problem.
Epetra_Vector b_
Epetra Vector b allocated to a single core.
Definition: NNLS_solver.h:179
void starting_solution(Epetra_Vector &start)
Initiliazes the solution vector, must be used before .solve is called.
Definition: NNLS_solver.h:162
void positive_set_matrix(Epetra_CrsMatrix &P_mat)
Creates a matrix using the columns in A in the set P.
void epetra_permutation_matrix(Epetra_CrsMatrix &P_mat)
Creates square permutation matrix based off the active/inactive set, no longer in use...
void add_into_x(Epetra_Vector &temp, double alpha)
Adds the values of temp times alpha into the solution vector x.
const Parameters::AllParameters *const all_parameters
Pointer to all parameters.
Definition: NNLS_solver.h:168