1 #include "assemble_ECSW_residual.h" 4 #include "flow_solver/flow_solver.h" 5 #include "flow_solver/flow_solver_factory.h" 8 namespace HyperReduction {
11 template <
int dim,
int nstate>
14 const dealii::ParameterHandler ¶meter_handler_input,
17 MatrixXd snapshot_parameters_input,
20 :
AssembleECSWBase<dim, nstate>(parameters_input, parameter_handler_input, dg_input, pod, snapshot_parameters_input, ode_solver_type, Comm)
24 template <
int dim,
int nstate>
26 this->
pcout <<
"Solve for A and b for the NNLS Problem from POD Snapshots"<< std::endl;
27 MatrixXd snapshotMatrix = this->
pod->getSnapshotMatrix();
28 const Epetra_CrsMatrix epetra_pod_basis = this->
pod->getPODBasis()->trilinos_matrix();
29 Epetra_CrsMatrix epetra_system_matrix = this->
dg->system_matrix.trilinos_matrix();
32 int num_snaps_POD = snapshotMatrix.cols();
33 int n_reduced_dim_POD = epetra_pod_basis.NumGlobalCols();
34 int N_FOM_dim = epetra_pod_basis.NumGlobalRows();
35 int num_elements_N_e = this->
dg->triangulation->n_active_cells();
41 this->
pcout <<
"LIMITED NUMBER OF SNAPSHOTS"<< std::endl;
45 training_snaps = num_snaps_POD;
47 const int rank = this->
Comm_.MyPID();
49 const int length = epetra_system_matrix.NumMyRows()/(nstate*n_quad_pts);
50 int *local_elements =
new int[length];
52 for (
const auto &cell : this->
dg->dof_handler.active_cell_iterators())
54 if (cell->is_locally_owned()){
55 local_elements[ctr] = cell->active_cell_index();
59 Epetra_Map RowMap((n_reduced_dim_POD*training_snaps), (n_reduced_dim_POD*training_snaps), 0, this->
Comm_);
60 Epetra_Map ColMap(num_elements_N_e, length, local_elements, 0, this->
Comm_);
61 Epetra_Map dMap((n_reduced_dim_POD*training_snaps), (rank == 0) ? (n_reduced_dim_POD*training_snaps) : 0, 0, this->
Comm_);
63 delete[] local_elements;
65 Epetra_CrsMatrix C_T(Epetra_DataAccess::Copy, ColMap, RowMap, num_elements_N_e);
66 Epetra_Vector d(dMap);
69 const unsigned int max_dofs_per_cell = this->
dg->dof_handler.get_fe_collection().max_dofs_per_cell();
70 std::vector<dealii::types::global_dof_index> current_dofs_indices(max_dofs_per_cell);
74 this->
pcout <<
"Snapshot Parameter Values" << std::endl;
75 this->
pcout << snap_param << std::endl;
80 this->
dg = flow_solver->dg;
84 const bool compute_dRdW =
true;
85 this->
dg->assemble_residual(compute_dRdW);
86 Epetra_Vector epetra_right_hand_side(Epetra_DataAccess::Copy, epetra_system_matrix.RowMap(), this->
dg->right_hand_side.begin());
87 Epetra_Vector local_rhs = copy_vector_to_all_cores(epetra_right_hand_side);
90 epetra_system_matrix = this->
dg->system_matrix.trilinos_matrix();
91 std::shared_ptr<Epetra_CrsMatrix> epetra_test_basis = this->
local_generate_test_basis(epetra_system_matrix, epetra_pod_basis);
92 Epetra_CrsMatrix local_test_basis = copy_matrix_to_all_cores(*epetra_test_basis);
95 for (
const auto &cell : this->
dg->dof_handler.active_cell_iterators())
97 if (cell->is_locally_owned()){
98 int cell_num = cell->active_cell_index();
99 const int fe_index_curr_cell = cell->active_fe_index();
100 const dealii::FESystem<dim,dim> ¤t_fe_ref = this->
dg->fe_collection[fe_index_curr_cell];
101 const int n_dofs_curr_cell = current_fe_ref.n_dofs_per_cell();
103 current_dofs_indices.resize(n_dofs_curr_cell);
104 cell->get_dof_indices(current_dofs_indices);
107 const Epetra_SerialComm sComm;
108 Epetra_Map LeRowMap(n_dofs_curr_cell, 0, sComm);
109 Epetra_Map LeColMap(N_FOM_dim, 0, sComm);
110 Epetra_CrsMatrix L_e(Epetra_DataAccess::Copy, LeRowMap, LeColMap, 1);
113 for(
int i = 0; i < n_dofs_curr_cell; i++){
114 const int col = current_dofs_indices[i];
115 L_e.InsertGlobalValues(i, 1, &posOne , &col);
117 L_e.FillComplete(LeColMap, LeRowMap);
120 Epetra_Vector local_r(LeRowMap);
121 Epetra_Vector global_r_e(LeColMap);
122 L_e.Multiply(
false, local_rhs, local_r);
123 L_e.Multiply(
true, local_r, global_r_e);
126 Epetra_Map cseRowMap(n_reduced_dim_POD, 0, sComm);
127 Epetra_Vector c_se(cseRowMap);
129 local_test_basis.Multiply(
true, global_r_e, c_se);
130 double *c_se_array =
new double[n_reduced_dim_POD];
132 c_se.ExtractCopy(c_se_array);
135 for (
int k = 0; k < n_reduced_dim_POD; ++k){
136 int place = row_num+k;
137 C_T.InsertGlobalValues(cell_num, 1, &c_se_array[k], &place);
142 row_num+=n_reduced_dim_POD;
147 this->
pcout <<
"LIMITED NUMBER OF SNAPSHOTS"<< std::endl;
154 C_T.FillComplete(RowMap, ColMap);
156 Epetra_CrsMatrix C_single = copy_matrix_to_all_cores(C_T);
157 for (
int p = 0; p < num_elements_N_e; p++){
158 double *row =
new double[C_single.NumGlobalCols()];
159 int *global_cols =
new int[C_single.NumGlobalCols()];
161 C_single.ExtractGlobalRowCopy(p, C_single.NumGlobalCols(), numE , row, global_cols);
162 for (
int o = 0; o < dMap.NumMyElements(); o++){
163 int col = dMap.GID(o);
164 d.SumIntoMyValues(1, &row[col], &o);
167 delete[] global_cols;
171 this->
A_T->reinit(C_T);
172 this->
b.reinit(dMap.NumMyElements());
173 for(
int z = 0 ; z < dMap.NumMyElements() ; z++){
const dealii::ParameterHandler & parameter_handler
Parameter handler for storing the .prm file being ran.
std::vector< dealii::LinearAlgebra::distributed::Vector< double > > fom_locations
Vector of parameter-ROMTestLocation pairs.
FlowSolverParam flow_solver_param
Contains the parameters for simulation cases (flow solver test)
MatrixXd snapshot_parameters
Matrix of snapshot parameters.
std::shared_ptr< dealii::TrilinosWrappers::SparseMatrix > A_T
Matrix for the NNLS Problem.
Files for the baseline physics.
int num_training_snaps
Maximum number of snapshots in the ECSW training.
ODESolverEnum
Types of ODE solver.
unsigned int poly_degree
Polynomial order (P) of the basis functions for DG.
Main parameter class that contains the various other sub-parameter classes.
static std::unique_ptr< FlowSolver< dim, nstate > > select_flow_case(const Parameters::AllParameters *const parameters_input, const dealii::ParameterHandler ¶meter_handler_input)
Factory to return the correct flow solver given input file.
dealii::LinearAlgebra::ReadWriteVector< double > b
RHS Vector for the NNLS Problem.
std::shared_ptr< ProperOrthogonalDecomposition::PODBase< dim > > pod
POD.
Epetra_MpiComm Comm_
Epetra Communicator Object with MPI.
std::shared_ptr< Epetra_CrsMatrix > local_generate_test_basis(Epetra_CrsMatrix &system_matrix, const Epetra_CrsMatrix &pod_basis)
Generate Test Basis from the pod and snapshot info depending on the ode_solve_type (copied from the O...
const Parameters::AllParameters *const all_parameters
Pointer to all parameters.
std::shared_ptr< DGBase< dim, double > > dg
dg
dealii::ConditionalOStream pcout
ConditionalOStream.
DGBase is independent of the number of state variables.
HyperReductionParam hyper_reduction_param
Contains parameters for Hyperreduction.
Parameters::AllParameters reinit_params(const RowVectorXd ¶meter) const
Reinitialize parameters.
void build_problem() override
Fill entries of A and b.
AssembleECSWRes(const PHiLiP::Parameters::AllParameters *const parameters_input, const dealii::ParameterHandler ¶meter_handler_input, std::shared_ptr< DGBase< dim, double >> &dg_input, std::shared_ptr< ProperOrthogonalDecomposition::PODBase< dim >> pod, MatrixXd snapshot_parameters_input, Parameters::ODESolverParam::ODESolverEnum ode_solver_type, Epetra_MpiComm &Comm)
Constructor.