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 std::unique_ptr local_elements(std::make_unique<
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.get(), 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_);
64 Epetra_CrsMatrix C_T(Epetra_DataAccess::Copy, ColMap, RowMap, num_elements_N_e);
65 Epetra_Vector d(dMap);
68 const unsigned int max_dofs_per_cell = this->
dg->dof_handler.get_fe_collection().max_dofs_per_cell();
69 std::vector<dealii::types::global_dof_index> current_dofs_indices(max_dofs_per_cell);
73 this->
pcout <<
"Snapshot Parameter Values" << std::endl;
74 this->
pcout << snap_param << std::endl;
79 this->
dg = flow_solver->dg;
83 const bool compute_dRdW =
true;
84 this->
dg->assemble_residual(compute_dRdW);
85 Epetra_Vector epetra_right_hand_side(Epetra_DataAccess::Copy, epetra_system_matrix.RowMap(), this->
dg->right_hand_side.begin());
86 Epetra_Vector local_rhs = copy_vector_to_all_cores(epetra_right_hand_side);
89 epetra_system_matrix = this->
dg->system_matrix.trilinos_matrix();
90 std::shared_ptr<Epetra_CrsMatrix> epetra_test_basis = this->
local_generate_test_basis(epetra_system_matrix, epetra_pod_basis);
91 Epetra_CrsMatrix local_test_basis = copy_matrix_to_all_cores(*epetra_test_basis);
94 for (
const auto &cell : this->
dg->dof_handler.active_cell_iterators())
96 if (cell->is_locally_owned()){
97 int cell_num = cell->active_cell_index();
98 const int fe_index_curr_cell = cell->active_fe_index();
99 const dealii::FESystem<dim,dim> ¤t_fe_ref = this->
dg->fe_collection[fe_index_curr_cell];
100 const int n_dofs_curr_cell = current_fe_ref.n_dofs_per_cell();
102 current_dofs_indices.resize(n_dofs_curr_cell);
103 cell->get_dof_indices(current_dofs_indices);
106 const Epetra_SerialComm sComm;
107 Epetra_Map LeRowMap(n_dofs_curr_cell, 0, sComm);
108 Epetra_Map LeColMap(N_FOM_dim, 0, sComm);
109 Epetra_CrsMatrix L_e(Epetra_DataAccess::Copy, LeRowMap, LeColMap, 1);
112 for(
int i = 0; i < n_dofs_curr_cell; i++){
113 const int col = current_dofs_indices[i];
114 L_e.InsertGlobalValues(i, 1, &posOne , &col);
116 L_e.FillComplete(LeColMap, LeRowMap);
119 Epetra_Vector local_r(LeRowMap);
120 Epetra_Vector global_r_e(LeColMap);
121 L_e.Multiply(
false, local_rhs, local_r);
122 L_e.Multiply(
true, local_r, global_r_e);
125 Epetra_Map cseRowMap(n_reduced_dim_POD, 0, sComm);
126 Epetra_Vector c_se(cseRowMap);
128 local_test_basis.Multiply(
true, global_r_e, c_se);
129 std::unique_ptr c_se_array(std::make_unique<
double[]>(n_reduced_dim_POD));
131 c_se.ExtractCopy(c_se_array.get());
134 for (
int k = 0; k < n_reduced_dim_POD; ++k){
135 int place = row_num+k;
136 C_T.InsertGlobalValues(cell_num, 1, &c_se_array[k], &place);
140 row_num+=n_reduced_dim_POD;
145 this->
pcout <<
"LIMITED NUMBER OF SNAPSHOTS"<< std::endl;
152 C_T.FillComplete(RowMap, ColMap);
154 Epetra_CrsMatrix C_single = copy_matrix_to_all_cores(C_T);
155 for (
int p = 0; p < num_elements_N_e; p++){
156 std::unique_ptr row(std::make_unique<
double[]>(C_single.NumGlobalCols()));
157 std::unique_ptr global_cols(std::make_unique<
int[]>(C_single.NumGlobalCols()));
159 C_single.ExtractGlobalRowCopy(p, C_single.NumGlobalCols(), numE , row.get(), global_cols.get());
160 for (
int o = 0; o < dMap.NumMyElements(); o++){
161 int col = dMap.GID(o);
162 d.SumIntoMyValues(1, &row[col], &o);
167 this->
A_T->reinit(C_T);
168 this->
b.reinit(dMap.NumMyElements());
169 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.