libMesh
transient_rb_construction.C
Go to the documentation of this file.
1 // rbOOmit: An implementation of the Certified Reduced Basis method.
2 // Copyright (C) 2009, 2010 David J. Knezevic
3 
4 // This file is part of rbOOmit.
5 
6 // rbOOmit is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 
11 // rbOOmit is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
15 
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 
20 // rbOOmit includes
21 #include "libmesh/transient_rb_construction.h"
22 #include "libmesh/transient_rb_evaluation.h"
23 #include "libmesh/transient_rb_theta_expansion.h"
24 #include "libmesh/transient_rb_assembly_expansion.h"
25 
26 // LibMesh includes
27 #include "libmesh/numeric_vector.h"
28 #include "libmesh/sparse_matrix.h"
29 #include "libmesh/dof_map.h"
30 #include "libmesh/libmesh_logging.h"
31 #include "libmesh/linear_solver.h"
32 #include "libmesh/equation_systems.h"
33 #include "libmesh/exodusII_io.h"
34 #include "libmesh/getpot.h"
35 #include "libmesh/dense_matrix.h"
36 #include "libmesh/dense_vector.h"
37 #include "libmesh/xdr_cxx.h"
38 #include "libmesh/timestamp.h"
39 
40 // TIMPI includes
41 #include "timpi/communicator.h"
42 
43 // For checking for the existence of files
44 #include <sys/stat.h>
45 
46 #include <fstream>
47 #include <sstream>
48 
49 // Need SLEPc to get the POD eigenvalues
50 #if defined(LIBMESH_HAVE_SLEPC)
51 // LAPACK include (via SLEPc)
52 #include "libmesh/ignore_warnings.h"
53 #include <petscsys.h>
54 #include <slepcblaslapack.h>
55 #include "libmesh/restore_warnings.h"
56 #endif // LIBMESH_HAVE_SLEPC
57 
58 namespace libMesh
59 {
60 
62  const std::string & name_in,
63  const unsigned int number_in)
64  : Parent(es, name_in, number_in),
65  L2_matrix(SparseMatrix<Number>::build(es.comm())),
66  non_dirichlet_L2_matrix(SparseMatrix<Number>::build(es.comm())),
67  nonzero_initialization(false),
68  compute_truth_projection_error(false),
69  init_filename(""),
70  POD_tol(-1.),
71  max_truth_solves(-1),
72  L2_assembly(nullptr)
73 {
74  // Indicate that we need to compute the RB
75  // inner product matrix in this case
77 
78  // We should not necessarily exit the greedy due to repeated parameters in
79  // the transient case
81 }
82 
83 
84 
86 {
87  this->clear();
88 }
89 
90 
92 {
93  Parent::clear();
94 
95  // clear the mass matrices
96  M_q_vector.clear();
97 
100 
101  // clear the temporal_data
102  temporal_data.clear();
103 }
104 
106  bool skip_vector_assembly)
107 {
108  // Check that the theta and assembly objects are consistently sized
109 #ifndef NDEBUG
110  TransientRBThetaExpansion & trans_theta_expansion =
111  cast_ref<TransientRBThetaExpansion &>(get_rb_theta_expansion());
112 
113  TransientRBAssemblyExpansion & trans_assembly_expansion =
114  cast_ref<TransientRBAssemblyExpansion &>(get_rb_assembly_expansion());
115 #endif
116  // This assert only gets called if DEBUG is on
117  libmesh_assert_equal_to (trans_theta_expansion.get_n_M_terms(), trans_assembly_expansion.get_n_M_terms());
118 
119  Parent::initialize_rb_construction(skip_matrix_assembly, skip_vector_assembly);
120 }
121 
122 void TransientRBConstruction::process_parameters_file (const std::string & parameters_filename)
123 {
124  Parent::process_parameters_file(parameters_filename);
125 
126  // Read in data from parameters_filename
127  GetPot infile(parameters_filename);
128 
129  // Read in the generic temporal discretization data
130  process_temporal_parameters_file(parameters_filename);
131 
132  // Read in the data specific to Construction
133  nonzero_initialization = infile("nonzero_initialization",nonzero_initialization);
134  init_filename = infile("init_filename",init_filename);
135 
136  const Real POD_tol_in = infile("POD_tol", POD_tol);
137  const int max_truth_solves_in = infile("max_truth_solves", max_truth_solves);
138  const unsigned int delta_N_in = infile("delta_N", delta_N);
139 
140  set_POD_tol(POD_tol_in);
141  set_max_truth_solves(max_truth_solves_in);
142  set_delta_N(delta_N_in);
143 
144  // Pass the temporal discretization data to the RBEvaluation
145  TransientRBEvaluation & trans_rb_eval = cast_ref<TransientRBEvaluation &>(get_rb_evaluation());
146  trans_rb_eval.pull_temporal_discretization_data( *this );
147 }
148 
150 {
152 
153  libMesh::out << std::endl << "TransientRBConstruction parameters:" << std::endl;
154 
156  {
157  // Print out info that describes the current setup
158  TransientRBThetaExpansion & trans_theta_expansion =
159  cast_ref<TransientRBThetaExpansion &>(get_rb_theta_expansion());
160  libMesh::out << "Q_m: " << trans_theta_expansion.get_n_M_terms() << std::endl;
161  }
162  else
163  {
164  libMesh::out << "RBThetaExpansion member is not set yet" << std::endl;
165  }
166  libMesh::out << "Number of time-steps: " << get_n_time_steps() << std::endl;
167  libMesh::out << "dt: " << get_delta_t() << std::endl;
168  libMesh::out << "euler_theta (time discretization parameter): " << get_euler_theta() << std::endl;
169  if (get_POD_tol() > 0.)
170  libMesh::out << "POD_tol: " << get_POD_tol() << std::endl;
171  if (max_truth_solves > 0)
172  libMesh::out << "Maximum number of truth solves: " << max_truth_solves << std::endl;
173  libMesh::out << "delta_N (number of basis functions to add each POD-Greedy step): " << get_delta_N() << std::endl;
175  {
176  libMesh::out << "Reading initial condition from " << init_filename << std::endl;
177  }
178  else
179  {
180  libMesh::out << "Using zero initial condition" << std::endl;
181  }
182  libMesh::out << std::endl;
183 }
184 
186 {
188 
189  TransientRBThetaExpansion & trans_theta_expansion =
190  cast_ref<TransientRBThetaExpansion &>(get_rb_theta_expansion());
191  const unsigned int Q_m = trans_theta_expansion.get_n_M_terms();
192  const unsigned int n_outputs = trans_theta_expansion.get_n_outputs();
193 
194  // Resize and allocate vectors for storing mesh-dependent data
195  const unsigned int n_time_levels = get_n_time_steps()+1;
196  temporal_data.resize(n_time_levels);
197 
198  // Resize vectors for storing mesh-dependent data but only
199  // initialize if initialize_mesh_dependent_data == true
200  M_q_vector.resize(Q_m);
201 
202  // Only initialize the mass matrices if we
203  // are not in single-matrix mode
204  {
205  DofMap & dof_map = this->get_dof_map();
206 
207  dof_map.attach_matrix(*L2_matrix);
208  L2_matrix->init();
209  L2_matrix->zero();
210 
211  for (unsigned int q=0; q<Q_m; q++)
212  {
213  // Initialize the memory for the matrices
215  dof_map.attach_matrix(*M_q_vector[q]);
216  M_q_vector[q]->init();
217  M_q_vector[q]->zero();
218  }
219 
220  // We also need to initialize a second set of non-Dirichlet operators
222  {
224  non_dirichlet_L2_matrix->init();
225  non_dirichlet_L2_matrix->zero();
226 
227  non_dirichlet_M_q_vector.resize(Q_m);
228  for (unsigned int q=0; q<Q_m; q++)
229  {
230  // Initialize the memory for the matrices
233  non_dirichlet_M_q_vector[q]->init();
234  non_dirichlet_M_q_vector[q]->zero();
235  }
236  }
237  }
238 
239  for (unsigned int i=0; i<n_time_levels; i++)
240  {
242  temporal_data[i]->init (this->n_dofs(), this->n_local_dofs(), false, PARALLEL);
243  }
244 
245  // and the truth output vectors
246  truth_outputs_all_k.resize(n_outputs);
247  for (unsigned int n=0; n<n_outputs; n++)
248  {
249  truth_outputs_all_k[n].resize(n_time_levels);
250  }
251 
252  // This vector is for storing rhs entries for
253  // computing the projection of the initial condition
254  // into the RB space
256 }
257 
259  bool skip_vector_assembly)
260 {
261  // Call parent's assembly functions
262  Parent::assemble_affine_expansion(skip_matrix_assembly, skip_vector_assembly);
263 
264  // Now update RB_ic_proj_rhs_all_N if necessary.
265  // This allows us to compute the L2 projection
266  // of the initial condition into the RB space
267  // so that we can continue to enrich a given RB
268  // space.
269  if (get_rb_evaluation().get_n_basis_functions() > 0)
270  {
271  // Load the initial condition into the solution vector
273 
274  std::unique_ptr<NumericVector<Number>> temp1 = NumericVector<Number>::build(this->comm());
275  temp1->init (this->n_dofs(), this->n_local_dofs(), false, PARALLEL);
276 
277  // First compute the right-hand side vector for the L2 projection
278  L2_matrix->vector_mult(*temp1, *solution);
279 
280  for (unsigned int i=0; i<get_rb_evaluation().get_n_basis_functions(); i++)
281  {
282  RB_ic_proj_rhs_all_N(i) = temp1->dot(get_rb_evaluation().get_basis_function(i));
283  }
284  }
285 }
286 
287 Real TransientRBConstruction::train_reduced_basis(const bool resize_rb_eval_data)
288 {
290  Real value = Parent::train_reduced_basis(resize_rb_eval_data);
292 
293  return value;
294 }
295 
297 {
298  TransientRBThetaExpansion & trans_theta_expansion =
299  cast_ref<TransientRBThetaExpansion &>(get_rb_theta_expansion());
300 
301  if (q >= trans_theta_expansion.get_n_M_terms())
302  libmesh_error_msg("Error: We must have q < Q_m in get_M_q.");
303 
304  return M_q_vector[q].get();
305 }
306 
308 {
310  libmesh_error_msg("Error: Must have store_non_dirichlet_operators==true to access non_dirichlet_M_q.");
311 
312  TransientRBThetaExpansion & trans_theta_expansion =
313  cast_ref<TransientRBThetaExpansion &>(get_rb_theta_expansion());
314 
315  if (q >= trans_theta_expansion.get_n_M_terms())
316  libmesh_error_msg("Error: We must have q < Q_m in get_M_q.");
317 
318  return non_dirichlet_M_q_vector[q].get();
319 }
320 
321 void TransientRBConstruction::get_all_matrices(std::map<std::string, SparseMatrix<Number> *> & all_matrices)
322 {
323  Parent::get_all_matrices(all_matrices);
324 
325  all_matrices["L2_matrix"] = L2_matrix.get();
326 
328  all_matrices["L2_matrix_non_dirichlet"] = non_dirichlet_L2_matrix.get();
329 
330  TransientRBThetaExpansion & trans_theta_expansion =
331  cast_ref<TransientRBThetaExpansion &>(get_rb_theta_expansion());
332  const unsigned int Q_m = trans_theta_expansion.get_n_M_terms();
333 
334  for (unsigned int q_m=0; q_m<Q_m; q_m++)
335  {
336  std::stringstream matrix_name;
337  matrix_name << "M" << q_m;
338  all_matrices[matrix_name.str()] = get_M_q(q_m);
339 
341  {
342  matrix_name << "_non_dirichlet";
343  all_matrices[matrix_name.str()] = get_non_dirichlet_M_q(q_m);
344  }
345  }
346 }
347 
348 void TransientRBConstruction::assemble_L2_matrix(SparseMatrix<Number> * input_matrix, bool apply_dirichlet_bc)
349 {
350  input_matrix->zero();
352  L2_assembly,
353  input_matrix,
354  nullptr,
355  false, /* symmetrize */
356  apply_dirichlet_bc);
357 }
358 
360 {
361  input_matrix->zero();
362  add_scaled_mass_matrix(1., input_matrix);
363 }
364 
366 {
367  const RBParameters & mu = get_parameters();
368 
369  TransientRBThetaExpansion & trans_theta_expansion =
370  cast_ref<TransientRBThetaExpansion &>(get_rb_theta_expansion());
371 
372  const unsigned int Q_m = trans_theta_expansion.get_n_M_terms();
373 
374  for (unsigned int q=0; q<Q_m; q++)
375  input_matrix->add(scalar * trans_theta_expansion.eval_M_theta(q,mu), *get_M_q(q));
376 }
377 
379  NumericVector<Number> & dest,
380  NumericVector<Number> & arg)
381 {
382  LOG_SCOPE("mass_matrix_scaled_matvec()", "TransientRBConstruction");
383 
384  dest.zero();
385 
386  const RBParameters & mu = get_parameters();
387 
388  TransientRBThetaExpansion & trans_theta_expansion =
389  cast_ref<TransientRBThetaExpansion &>(get_rb_theta_expansion());
390 
391  const unsigned int Q_m = trans_theta_expansion.get_n_M_terms();
392 
393  std::unique_ptr<NumericVector<Number>> temp_vec = NumericVector<Number>::build(this->comm());
394  temp_vec->init (this->n_dofs(), this->n_local_dofs(), false, PARALLEL);
395 
396  for (unsigned int q=0; q<Q_m; q++)
397  {
398  get_M_q(q)->vector_mult(*temp_vec, arg);
399  dest.add(scalar * trans_theta_expansion.eval_M_theta(q,mu), *temp_vec);
400  }
401 }
402 
404 {
405  LOG_SCOPE("truth_assembly()", "TransientRBConstruction");
406 
407  this->matrix->close();
408 
409  this->matrix->zero();
410  this->rhs->zero();
411 
412  const RBParameters & mu = get_parameters();
413 
414  TransientRBThetaExpansion & trans_theta_expansion =
415  cast_ref<TransientRBThetaExpansion &>(get_rb_theta_expansion());
416 
417  const unsigned int Q_a = trans_theta_expansion.get_n_A_terms();
418  const unsigned int Q_f = trans_theta_expansion.get_n_F_terms();
419 
420  const Real dt = get_delta_t();
421  const Real euler_theta = get_euler_theta();
422 
423  {
424  // We should have already assembled the matrices
425  // and vectors in the affine expansion, so
426  // just use them
427 
430 
431  std::unique_ptr<NumericVector<Number>> temp_vec = NumericVector<Number>::build(this->comm());
432  temp_vec->init (this->n_dofs(), this->n_local_dofs(), false, PARALLEL);
433 
434  for (unsigned int q_a=0; q_a<Q_a; q_a++)
435  {
436  matrix->add(euler_theta*trans_theta_expansion.eval_A_theta(q_a,mu), *get_Aq(q_a));
437 
438  get_Aq(q_a)->vector_mult(*temp_vec, *current_local_solution);
439  temp_vec->scale( -(1.-euler_theta)*trans_theta_expansion.eval_A_theta(q_a,mu) );
440  rhs->add(*temp_vec);
441  }
442 
443  for (unsigned int q_f=0; q_f<Q_f; q_f++)
444  {
445  *temp_vec = *get_Fq(q_f);
446  temp_vec->scale( get_control(get_time_step())*trans_theta_expansion.eval_F_theta(q_f,mu) );
447  rhs->add(*temp_vec);
448  }
449 
450  }
451 
452  this->matrix->close();
453  this->rhs->close();
454 }
455 
457 {
458  L2_assembly = &L2_assembly_in;
459 }
460 
462 {
463  if (!L2_assembly)
464  libmesh_error_msg("Error: L2_assembly hasn't been initialized yet");
465 
466  return *L2_assembly;
467 }
468 
469 void TransientRBConstruction::assemble_Mq_matrix(unsigned int q, SparseMatrix<Number> * input_matrix, bool apply_dirichlet_bc)
470 {
471  TransientRBThetaExpansion & trans_theta_expansion =
472  cast_ref<TransientRBThetaExpansion &>(get_rb_theta_expansion());
473 
474  TransientRBAssemblyExpansion & trans_assembly_expansion =
475  cast_ref<TransientRBAssemblyExpansion &>(get_rb_assembly_expansion());
476 
477  if (q >= trans_theta_expansion.get_n_M_terms())
478  libmesh_error_msg("Error: We must have q < Q_m in assemble_Mq_matrix.");
479 
480  input_matrix->zero();
482  &trans_assembly_expansion.get_M_assembly(q),
483  input_matrix,
484  nullptr,
485  false, /* symmetrize */
486  apply_dirichlet_bc);
487 }
488 
490 {
492 
493  TransientRBThetaExpansion & trans_theta_expansion =
494  cast_ref<TransientRBThetaExpansion &>(get_rb_theta_expansion());
495 
496  for (unsigned int q=0; q<trans_theta_expansion.get_n_M_terms(); q++)
498 
500  {
501  for (unsigned int q=0; q<trans_theta_expansion.get_n_M_terms(); q++)
503  }
504 }
505 
507 {
508  libMesh::out << "Assembling L2 matrix" << std::endl;
510 
512  {
513  libMesh::out << "Assembling non-Dirichlet L2 matrix" << std::endl;
514  assemble_L2_matrix(non_dirichlet_L2_matrix.get(), /* apply_dirichlet_bc = */ false);
515  }
516 
518 }
519 
521 {
522  LOG_SCOPE("truth_solve()", "TransientRBConstruction");
523 
524  const RBParameters & mu = get_parameters();
525  const unsigned int n_time_steps = get_n_time_steps();
526 
527  // // NumericVector for computing true L2 error
528  // std::unique_ptr<NumericVector<Number>> temp = NumericVector<Number>::build();
529  // temp->init (this->n_dofs(), this->n_local_dofs(), false, PARALLEL);
530 
531  // Apply initial condition again.
533  set_time_step(0);
534 
535  // Now compute the truth outputs
536  for (unsigned int n=0; n<get_rb_theta_expansion().get_n_outputs(); n++)
537  {
538  truth_outputs_all_k[n][0] = 0.;
539  for (unsigned int q_l=0; q_l<get_rb_theta_expansion().get_n_output_terms(n); q_l++)
540  {
542  get_output_vector(n,q_l)->dot(*solution);
543  }
544  }
545 
546  // Load initial projection error into temporal_data dense matrix
549 
550  for (unsigned int time_level=1; time_level<=n_time_steps; time_level++)
551  {
552  set_time_step(time_level);
553 
555 
556  // We assume that the truth assembly has been attached to the system
557  truth_assembly();
558 
559  // truth_assembly assembles into matrix and rhs, so use those for the solve
561 
562  // The matrix doesn't change at each timestep, so we
563  // can set reuse_preconditioner == true
564  linear_solver->reuse_preconditioner(true);
565 
566  if (assert_convergence)
567  {
569  }
570 
571  // Now compute the truth outputs
572  for (unsigned int n=0; n<get_rb_theta_expansion().get_n_outputs(); n++)
573  {
574  truth_outputs_all_k[n][time_level] = 0.;
575  for (unsigned int q_l=0; q_l<get_rb_theta_expansion().get_n_output_terms(n); q_l++)
576  {
577  truth_outputs_all_k[n][time_level] +=
579  }
580  }
581 
582  // load projection error into column _k of temporal_data matrix
585 
586  if ((write_interval > 0) && (time_level%write_interval == 0))
587  {
588  libMesh::out << std::endl << "Truth solve, plotting time step " << time_level << std::endl;
589 
590  std::ostringstream file_name;
591 
592  file_name << "truth.e.";
593  file_name << std::setw(3)
594  << std::setprecision(0)
595  << std::setfill('0')
596  << std::right
597  << time_level;
598 
599 #ifdef LIBMESH_HAVE_EXODUS_API
600  ExodusII_IO(get_mesh()).write_equation_systems (file_name.str(),
601  this->get_equation_systems());
602 #endif
603  }
604  }
605 
606  // Set reuse_preconditioner back to false for subsequent solves.
607  linear_solver->reuse_preconditioner(false);
608 
609  // Get the L2 norm of the truth solution at time-level _K
610  // Useful for normalizing our true error data
612  Real final_truth_L2_norm = libmesh_real(std::sqrt(inner_product_storage_vector->dot(*solution)));
613 
614 
615  return final_truth_L2_norm;
616 }
617 
618 bool
620  Real initial_greedy_error,
621  int count)
622 {
623  if ((get_max_truth_solves()>0) && (count >= get_max_truth_solves()))
624  {
625  libMesh::out << "Maximum number of truth solves reached: max = "
626  << count << std::endl;
627  return true;
628  }
629 
630  return Parent::greedy_termination_test(abs_greedy_error, initial_greedy_error, count);
631 }
632 
634 {
635  LOG_SCOPE("set_error_temporal_data()", "TransientRBConstruction");
636 
637  // first compute the projection of solution onto the current
638  // RB space
639 
640  const unsigned int time_step = get_time_step();
641 
642  if (get_rb_evaluation().get_n_basis_functions() == 0)
643  {
644  // If the basis is empty, then the error is the solution itself
645  temporal_data[time_step]->zero();
646  temporal_data[time_step]->add(1., *solution);
647  }
648  else
649  {
650  unsigned int RB_size = get_rb_evaluation().get_n_basis_functions();
651 
652  std::unique_ptr<NumericVector<Number>> temp = NumericVector<Number>::build(this->comm());
653  temp->init (this->n_dofs(), this->n_local_dofs(), false, PARALLEL);
654 
655  // First compute the right-hand side vector for the projection
657 
658  // zero_dirichlet_dofs_on_vector(*temp);
659 
660  // Do not assume that RB_stiffness matrix is diagonal,
661  // diagonality degrades as N increases
662 
663  // Get an appropriately sized copy of RB_inner_product_matrix
664  DenseMatrix<Number> RB_inner_product_matrix_N(RB_size,RB_size);
665  for (unsigned int i=0; i<RB_size; i++)
666  for (unsigned int j=0; j<RB_size; j++)
667  {
668  RB_inner_product_matrix_N(i,j) = get_rb_evaluation().RB_inner_product_matrix(i,j);
669  }
670 
671  // Compute the projection RHS
672  DenseVector<Number> RB_proj_rhs(RB_size);
673  for (unsigned int i=0; i<RB_size; i++)
674  {
675  RB_proj_rhs(i) = temp->dot(get_rb_evaluation().get_basis_function(i));
676  }
677 
678  DenseVector<Number> RB_proj(RB_size);
679 
680  // Now solve the linear system
681  RB_inner_product_matrix_N.lu_solve(RB_proj_rhs, RB_proj);
682 
683  // Load the RB projection into temp
684  temp->zero();
685  for (unsigned int i=0; i<RB_size; i++)
686  {
687  temp->add(RB_proj(i), get_rb_evaluation().get_basis_function(i));
688  }
689 
690  temp->add(-1., *solution);
691 
692  // Now temp holds the projection error, store in temporal_data
693  *(temporal_data[time_step]) = *temp;
694  }
695 
696  // return the square of the X norm of the truth solution
698 
700 }
701 
703 {
704  LOG_SCOPE("get_error_temporal_data()", "TransientRBConstruction");
705 
706  const unsigned int time_step = get_time_step();
707 
708  return *temporal_data[time_step];
709 }
710 
712 {
714  {
715  // Use System::read_serialized_data to read the initial condition
716  // into this->solution
717  Xdr IC_data(init_filename, READ);
718  read_serialized_data(IC_data, false);
719  }
720  else
721  {
722  // Otherwise zero out the solution as a default
723  this->solution->zero();
724  }
725  this->solution->close();
726  this->update();
727 }
728 
730 {
731  LOG_SCOPE("add_IC_to_RB_space()", "TransientRBConstruction");
732 
733  if (get_rb_evaluation().get_n_basis_functions() > 0)
734  libmesh_error_msg("Error: Should not call TransientRBConstruction::add_IC_to_RB_space() " \
735  << "on a system that already contains basis functions.");
736 
738  libmesh_error_msg("Error: Should not call TransientRBConstruction::add_IC_to_RB_space() " \
739  << "when nonzero_initialization==false.");
740 
742 
743  // load the new basis function into the basis_functions vector.
745  NumericVector<Number> & current_bf = get_rb_evaluation().get_basis_function(get_rb_evaluation().get_n_basis_functions()-1);
746  current_bf.init (this->n_dofs(), this->n_local_dofs(), false, PARALLEL);
747  current_bf = *solution;
748 
749  // We can just set the norm to 1.
751 
752  Real current_bf_norm = libmesh_real(std::sqrt( current_bf.dot(*inner_product_storage_vector) ));
753  current_bf.scale(1./current_bf_norm);
754 
755  unsigned int saved_delta_N = get_delta_N();
756  set_delta_N(1);
757  update_system();
758  set_delta_N(saved_delta_N);
759 }
760 
762 {
763  // Need SLEPc to get the POD eigenvalues
764 #if defined(LIBMESH_HAVE_SLEPC)
765  LOG_SCOPE("enrich_RB_space()", "TransientRBConstruction");
766 
767  // With the "method of snapshots", the size of
768  // the eigenproblem is determined by the number
769  // of time-steps (rather than the number of spatial dofs).
770  PetscBLASInt eigen_size = cast_int<PetscBLASInt>(temporal_data.size());
771  PetscBLASInt LDA = eigen_size; // The leading order of correlation_matrix
772  std::vector<Number> correlation_matrix(LDA*eigen_size);
773 
774  for (int i=0; i<eigen_size; i++)
775  {
777 
778  for (int j=i; j<eigen_size; j++)
779  {
780  // Scale the inner products by the number of time-steps to normalize the
781  // POD energy norm appropriately
782  Number inner_prod = (temporal_data[j]->dot(*inner_product_storage_vector)) /
783  (Real)(get_n_time_steps()+1);
784 
785  // Fill upper triangular part of correlation_matrix
786  correlation_matrix[j*eigen_size+i] = inner_prod;
787  }
788  }
789 
790  // Call the LAPACK eigensolver
791  char JOBZ = 'V'; // Compute eigenvectors and eigenvalues
792  char RANGE = 'A'; // Compute all eigenvalues
793  char UPLO = 'U'; // Upper triangular symmetric matrix
794 
795  Real VL = 0.; // Not used when RANGE = A
796  Real VU = 0.; // Not used when RANGE = A
797 
798  PetscBLASInt IL = 0; // Not used when RANGE = A
799  PetscBLASInt IU = 0; // Not used when RANGE = A
800 
801  Real ABSTOL = 1.e-14; // Absolute tolerance for eigensolver
802 
803  PetscBLASInt M = 0; // (output) The total number of evals found
804 
805  std::vector<Real> W(eigen_size); // (output) the eigenvalues
806 
807  PetscBLASInt LDZ = eigen_size; // The leading order of Z
808  std::vector<Number> Z(LDZ*eigen_size); // (output) the eigenvectors
809 
810  std::vector<PetscBLASInt> ISUPPZ(2*eigen_size); // Indicates which evecs in Z are nonzero
811 
812  // Work array, sized according to lapack documentation
813  PetscBLASInt LWORK = 26*eigen_size;
814  std::vector<Number> WORK(LWORK);
815 
816  // Work array, sized according to lapack documentation
817  PetscBLASInt LIWORK = 10*eigen_size;
818  std::vector<PetscBLASInt> IWORK(LIWORK);
819 
820  PetscBLASInt INFO = 0;
821 
822 #ifdef LIBMESH_USE_REAL_NUMBERS // Use real numbers
823  // Call the eigensolver for symmetric eigenvalue problems.
824  // NOTE: evals in W are in ascending order
825  LAPACKsyevr_(&JOBZ, &RANGE, &UPLO, &eigen_size, correlation_matrix.data(),
826  &LDA, &VL, &VU, &IL, &IU, &ABSTOL, &M, W.data(), Z.data(), &LDZ,
827  ISUPPZ.data(), WORK.data(), &LWORK, IWORK.data(), &LIWORK, &INFO );
828 #elif LIBMESH_USE_COMPLEX_NUMBERS // Use complex numbers
829  // Need some extra data in the complex case
830 
831  // Work array, sized according to lapack documentation
832  PetscBLASInt LRWORK = 24*eigen_size;
833  std::vector<Real> RWORK(LRWORK);
834 
835  // Call the eigensolver for symmetric eigenvalue problems.
836  // NOTE: evals in W are in ascending order
837  LAPACKsyevr_(&JOBZ, &RANGE, &UPLO, &eigen_size, correlation_matrix.data(),
838  &LDA, &VL, &VU, &IL, &IU, &ABSTOL, &M, W.data(), Z.data(), &LDZ,
839  ISUPPZ.data(), WORK.data(), &LWORK, RWORK.data(), &LRWORK, IWORK.data(),
840  &LIWORK, &INFO );
841 #else
842 #error libMesh does not yet support quaternions!
843 #endif
844 
845  if (INFO != 0)
846  libmesh_error_msg("Error in LAPACK syev eigensolver routine, INFO = " << INFO);
847 
848  // eval and evec now hold the sorted eigenvalues/eigenvectors
849  libMesh::out << std::endl << "POD Eigenvalues:" << std::endl;
850  for (unsigned int i=0; i<=1; i++)
851  {
852  libMesh::out << "eigenvalue " << i << " = " << W[eigen_size-1-i] << std::endl;
853  }
854  libMesh::out << "..." << std::endl;// << "." << std::endl << "." << std::endl;
855  libMesh::out << "last eigenvalue = " << W[0] << std::endl;
856  libMesh::out << std::endl;
857 
858  // Now load the new basis functions
859  unsigned int count = 0;
860  while (true)
861  {
862  // load the new basis function into the basis_functions vector.
864  NumericVector<Number> & current_bf = get_rb_evaluation().get_basis_function(get_rb_evaluation().get_n_basis_functions()-1);
865  current_bf.init (this->n_dofs(), this->n_local_dofs(), false, PARALLEL);
866  current_bf.zero();
867 
868  // Perform the matrix multiplication of temporal data with
869  // the next POD eigenvector
870  for (int j=0; j<eigen_size; j++)
871  {
872  int Z_row = j;
873  int Z_col = (eigen_size-1-count);
874  int Z_index = Z_col*eigen_size + Z_row;
875  current_bf.add(Z[Z_index], *temporal_data[j]);
876  }
877 
878  // We just set the norm to 1.
880 
881  Real current_bf_norm = std::abs( std::sqrt( current_bf.dot(*inner_product_storage_vector) ) );
882  current_bf.scale(1./current_bf_norm);
883 
884  // Increment count here since we use the incremented counter
885  // in the if clauses below
886  count++;
887 
888  // If positive POD_tol, we use it to determine the number of basis functions
889  // to add, and then break the loop when POD_tol is satisfied, or after Nmax
890  // basis functions have been added. Else we break the loop after delta_N
891  // (or Nmax) new basis functions.
892  if (POD_tol > 0.)
893  {
894  set_delta_N(1);
895 
896  // We need to define the updated RB system matrices before the RB solve
897  update_system();
898  Real error_bound = get_rb_evaluation().rb_solve(get_rb_evaluation().get_n_basis_functions());
899 
900  if ((error_bound <= POD_tol) || (get_rb_evaluation().get_n_basis_functions()==get_Nmax()))
901  {
902  set_delta_N(0);
903  break;
904  }
905  }
906  else
907  {
908  if (count == get_delta_N())
909  {
910  break;
911  }
912  else
913  if (get_rb_evaluation().get_n_basis_functions()==get_Nmax())
914  {
915  set_delta_N(count);
916  break;
917  }
918  }
919  }
920 
921 #else
922  libmesh_not_implemented();
923 #endif
924 }
925 
926 
928 {
929  // If delta_N is set to zero, there is nothing to update
930  if (get_delta_N() == 0)
931  return;
932 
934 
935  libMesh::out << "Updating RB initial conditions" << std::endl;
937 }
938 
940 {
941  return *L2_matrix;
942 }
943 
945 {
946  LOG_SCOPE("load_rb_solution()", "TransientRBConstruction");
947 
948  solution->zero();
949 
950  const unsigned int time_step = get_time_step();
951 
952  TransientRBEvaluation & trans_rb_eval = cast_ref<TransientRBEvaluation &>(get_rb_evaluation());
953  DenseVector<Number> RB_solution_vector_k = trans_rb_eval.RB_temporal_solution_data[time_step];
954 
955  if (RB_solution_vector_k.size() > get_rb_evaluation().get_n_basis_functions())
956  libmesh_error_msg("ERROR: rb_eval object contains " \
958  << " basis functions. RB_solution vector constains " \
959  << RB_solution_vector_k.size() \
960  << " entries. RB_solution in TransientRBConstruction::load_rb_solution is too long!");
961 
962  for (unsigned int i=0; i<RB_solution_vector_k.size(); i++)
963  solution->add(RB_solution_vector_k(i), get_rb_evaluation().get_basis_function(i));
964 
965  update();
966 }
967 
969 {
970  LOG_SCOPE("update_RB_system_matrices()", "TransientRBConstruction");
971 
973 
974  TransientRBEvaluation & trans_rb_eval = cast_ref<TransientRBEvaluation &>(get_rb_evaluation());
975 
976  TransientRBThetaExpansion & trans_theta_expansion =
977  cast_ref<TransientRBThetaExpansion &>(get_rb_theta_expansion());
978  const unsigned int Q_m = trans_theta_expansion.get_n_M_terms();
979 
980  unsigned int RB_size = get_rb_evaluation().get_n_basis_functions();
981 
982  std::unique_ptr<NumericVector<Number>> temp = NumericVector<Number>::build(this->comm());
983  temp->init (this->n_dofs(), this->n_local_dofs(), false, PARALLEL);
984 
985  for (unsigned int i=(RB_size-delta_N); i<RB_size; i++)
986  {
987  for (unsigned int j=0; j<RB_size; j++)
988  {
989  // Compute reduced L2 matrix
990  temp->zero();
991  L2_matrix->vector_mult(*temp, get_rb_evaluation().get_basis_function(j));
992 
994  trans_rb_eval.RB_L2_matrix(i,j) = value;
995  if (i!=j)
996  {
997  // The L2 matrix is assumed
998  // to be symmetric
999  trans_rb_eval.RB_L2_matrix(j,i) = value;
1000  }
1001 
1002  for (unsigned int q_m=0; q_m<Q_m; q_m++)
1003  {
1004  // Compute reduced M_q matrix
1005  temp->zero();
1006  get_M_q(q_m)->vector_mult(*temp, get_rb_evaluation().get_basis_function(j));
1007 
1008  value = (get_rb_evaluation().get_basis_function(i)).dot(*temp);
1009  trans_rb_eval.RB_M_q_vector[q_m](i,j) = value;
1010 
1011  if (i!=j)
1012  {
1013  // Each mass matrix term is assumed
1014  // to be symmetric
1015  trans_rb_eval.RB_M_q_vector[q_m](j,i) = value;
1016  }
1017  }
1018 
1019  }
1020  }
1021 }
1022 
1023 
1024 
1025 
1026 void TransientRBConstruction::update_residual_terms(bool compute_inner_products)
1027 {
1028  LOG_SCOPE("update_residual_terms()", "TransientRBConstruction");
1029 
1030  Parent::update_residual_terms(compute_inner_products);
1031 
1032  TransientRBEvaluation & trans_rb_eval = cast_ref<TransientRBEvaluation &>(get_rb_evaluation());
1033 
1034  TransientRBThetaExpansion & trans_theta_expansion =
1035  cast_ref<TransientRBThetaExpansion &>(get_rb_theta_expansion());
1036 
1037  const unsigned int Q_m = trans_theta_expansion.get_n_M_terms();
1038  const unsigned int Q_a = trans_theta_expansion.get_n_A_terms();
1039  const unsigned int Q_f = trans_theta_expansion.get_n_F_terms();
1040 
1041  unsigned int RB_size = get_rb_evaluation().get_n_basis_functions();
1042 
1043  for (unsigned int q_m=0; q_m<Q_m; q_m++)
1044  {
1045  for (unsigned int i=(RB_size-delta_N); i<RB_size; i++)
1046  {
1047  // Initialize the vectors when we need them
1048  if (!trans_rb_eval.M_q_representor[q_m][i])
1049  {
1050  trans_rb_eval.M_q_representor[q_m][i] = NumericVector<Number>::build(this->comm());
1051  trans_rb_eval.M_q_representor[q_m][i]->init (this->n_dofs(), this->n_local_dofs(), false, PARALLEL);
1052  }
1053 
1054  libmesh_assert(trans_rb_eval.M_q_representor[q_m][i]->size() == this->n_dofs() &&
1055  trans_rb_eval.M_q_representor[q_m][i]->local_size() == this->n_local_dofs() );
1056 
1057  rhs->zero();
1058  M_q_vector[q_m]->vector_mult(*rhs, get_rb_evaluation().get_basis_function(i));
1059 
1060  if (!is_quiet())
1061  libMesh::out << "Starting solve i="
1062  << i << " in TransientRBConstruction::update_residual_terms() at "
1063  << Utility::get_timestamp() << std::endl;
1064 
1066 
1067  if (assert_convergence)
1069 
1070  if (!is_quiet())
1071  {
1072  libMesh::out << "Finished solve i="
1073  << i << " in TransientRBConstruction::update_residual_terms() at "
1074  << Utility::get_timestamp() << std::endl;
1075 
1077  << " iterations, final residual "
1078  << this->final_linear_residual() << std::endl;
1079  }
1080 
1081  *trans_rb_eval.M_q_representor[q_m][i] = *solution;
1082  }
1083  }
1084 
1085  // Now compute and store the inner products if requested
1086  if (compute_inner_products)
1087  {
1088  for (unsigned int q_f=0; q_f<Q_f; q_f++)
1089  {
1091 
1092  for (unsigned int i=(RB_size-delta_N); i<RB_size; i++)
1093  {
1094  for (unsigned int q_m=0; q_m<Q_m; q_m++)
1095  {
1096  trans_rb_eval.Fq_Mq_representor_innerprods[q_f][q_m][i] =
1097  trans_rb_eval.M_q_representor[q_m][i]->dot(*inner_product_storage_vector);
1098  } // end for q_m
1099  } // end for i
1100  } // end for q_f
1101 
1102  unsigned int q=0;
1103  for (unsigned int q_m1=0; q_m1<Q_m; q_m1++)
1104  {
1105  for (unsigned int q_m2=q_m1; q_m2<Q_m; q_m2++)
1106  {
1107  for (unsigned int i=(RB_size-delta_N); i<RB_size; i++)
1108  {
1109  for (unsigned int j=0; j<RB_size; j++)
1110  {
1112 
1113  trans_rb_eval.Mq_Mq_representor_innerprods[q][i][j] =
1114  trans_rb_eval.M_q_representor[q_m1][i]->dot(*inner_product_storage_vector);
1115 
1116  if (i != j)
1117  {
1119  *trans_rb_eval.M_q_representor[q_m2][i]);
1120 
1121  trans_rb_eval.Mq_Mq_representor_innerprods[q][j][i] =
1122  trans_rb_eval.M_q_representor[q_m1][j]->dot(*inner_product_storage_vector);
1123  }
1124  } // end for j
1125  } // end for i
1126  q++;
1127  } // end for q_m2
1128  } // end for q_m1
1129 
1130 
1131  for (unsigned int i=(RB_size-delta_N); i<RB_size; i++)
1132  {
1133  for (unsigned int j=0; j<RB_size; j++)
1134  {
1135  for (unsigned int q_a=0; q_a<Q_a; q_a++)
1136  {
1137  for (unsigned int q_m=0; q_m<Q_m; q_m++)
1138  {
1140  *trans_rb_eval.M_q_representor[q_m][j]);
1141 
1142  trans_rb_eval.Aq_Mq_representor_innerprods[q_a][q_m][i][j] =
1143  trans_rb_eval.Aq_representor[q_a][i]->dot(*inner_product_storage_vector);
1144 
1145  if (i != j)
1146  {
1148  *trans_rb_eval.M_q_representor[q_m][i]);
1149 
1150  trans_rb_eval.Aq_Mq_representor_innerprods[q_a][q_m][j][i] =
1151  trans_rb_eval.Aq_representor[q_a][j]->dot(*inner_product_storage_vector);
1152  }
1153  } // end for q_m
1154  } // end for q_a
1155  } // end for j
1156  } // end for i
1157  } // end if (compute_inner_products)
1158 }
1159 
1160 
1162 {
1163  LOG_SCOPE("update_RB_initial_condition_all_N()", "TransientRBConstruction");
1164 
1165  TransientRBEvaluation & trans_rb_eval = cast_ref<TransientRBEvaluation &>(get_rb_evaluation());
1166 
1167  // Load the initial condition into the solution vector
1168  initialize_truth();
1169 
1170  std::unique_ptr<NumericVector<Number>> temp1 = NumericVector<Number>::build(this->comm());
1171  temp1->init (this->n_dofs(), this->n_local_dofs(), false, PARALLEL);
1172 
1173  std::unique_ptr<NumericVector<Number>> temp2 = NumericVector<Number>::build(this->comm());
1174  temp2->init (this->n_dofs(), this->n_local_dofs(), false, PARALLEL);
1175 
1176 
1177  unsigned int RB_size = get_rb_evaluation().get_n_basis_functions();
1178 
1179  // First compute the right-hand side vector for the L2 projection
1180  L2_matrix->vector_mult(*temp1, *solution);
1181 
1182  for (unsigned int i=(RB_size-delta_N); i<RB_size; i++)
1183  {
1184  RB_ic_proj_rhs_all_N(i) = temp1->dot(get_rb_evaluation().get_basis_function(i));
1185  }
1186 
1187 
1188  // Now compute the projection for each N
1189  DenseMatrix<Number> RB_L2_matrix_N;
1190  DenseVector<Number> RB_rhs_N;
1191  for (unsigned int N=(RB_size-delta_N); N<RB_size; N++)
1192  {
1193  // We have to index here by N+1 since the loop index is zero-based.
1194  trans_rb_eval.RB_L2_matrix.get_principal_submatrix(N+1, RB_L2_matrix_N);
1195 
1197 
1198  DenseVector<Number> RB_ic_N(N+1);
1199 
1200  // Now solve the linear system
1201  RB_L2_matrix_N.lu_solve(RB_rhs_N, RB_ic_N);
1202 
1203  // Load RB_ic_N into RB_initial_condition_all_N
1204  trans_rb_eval.RB_initial_condition_all_N[N] = RB_ic_N;
1205 
1206  // Compute the L2 error for the RB initial condition
1207  // This part is dependent on the truth space.
1208 
1209  // load the RB solution into temp1
1210  temp1->zero();
1211  for (unsigned int i=0; i<N+1; i++)
1212  {
1213  temp1->add(RB_ic_N(i), get_rb_evaluation().get_basis_function(i));
1214  }
1215 
1216  // subtract truth initial condition from RB_ic_N
1217  temp1->add(-1., *solution);
1218 
1219  // Compute L2 norm error, i.e. sqrt(M(solution,solution))
1220  temp2->zero();
1221  L2_matrix->vector_mult(*temp2, *temp1);
1222 
1223  trans_rb_eval.initial_L2_error_all_N[N] = libmesh_real(std::sqrt(temp2->dot(*temp1)));
1224  }
1225 }
1226 
1227 //Real TransientRBConstruction::uncached_compute_residual_dual_norm(const unsigned int N)
1228 //{
1229 // LOG_SCOPE("uncached_compute_residual_dual_norm()", "TransientRBConstruction");
1230 //
1231 // // This is the "slow" way of computing the residual, but it is useful
1232 // // for validating the "fast" way.
1233 // // Note that this only works in serial since otherwise each processor will
1234 // // have a different parameter value during the Greedy training.
1235 //
1236 // // Assemble the right-hand side to find the Reisz representor
1237 // // of the residual in the X norm
1238 // std::unique_ptr<NumericVector<Number>> RB_sol = NumericVector<Number>::build();
1239 // RB_sol->init (this->n_dofs(), this->n_local_dofs(), false, PARALLEL);
1240 // RB_sol->zero();
1241 //
1242 // std::unique_ptr<NumericVector<Number>> ghosted_temp = NumericVector<Number>::build();
1243 // ghosted_temp->init (this->n_dofs(), this->n_local_dofs(),
1244 // this->get_dof_map().get_send_list(), false,
1245 // GHOSTED);
1246 //
1247 // std::unique_ptr<NumericVector<Number>> parallel_temp = NumericVector<Number>::build();
1248 // parallel_temp->init (this->n_dofs(), this->n_local_dofs(), false, PARALLEL);
1249 //
1250 // // Store current_local_solution, since we don't want to corrupt it
1251 // *ghosted_temp = *current_local_solution;
1252 //
1253 // for (unsigned int i=0; i<N; i++)
1254 // {
1255 // RB_sol->add(RB_solution(i), rb_eval->get_basis_function(i));
1256 // parallel_temp->add(old_RB_solution(i), rb_eval->get_basis_function(i));
1257 // }
1258 //
1259 // // Load parallel_temp into current_local_solution in order to do assembly
1260 // const std::vector<unsigned int> & send_list = this->get_dof_map().get_send_list();
1261 // parallel_temp->localize (*current_local_solution, send_list);
1262 //
1263 // // Load the system_matrix
1264 // this->truth_assembly();
1265 //
1266 // // Restore current_local_solution
1267 // *current_local_solution = *ghosted_temp;
1268 //
1269 // matrix->vector_mult(*parallel_temp, *RB_sol);
1270 // rhs->add(-1., *parallel_temp);
1271 // rhs->close();
1272 //
1273 // zero_dirichlet_dofs_on_rhs();
1274 //
1275 // // Then solve the system to get the Reisz representor
1276 // matrix->zero();
1277 // {
1278 // matrix->add(1., *inner_product_matrix);
1279 // if (constrained_problem)
1280 // matrix->add(1., *constraint_matrix);
1281 // }
1282 //
1283 //
1284 // solution->zero();
1285 // solve();
1286 // // Make sure we didn't max out the number of iterations
1287 // if ((this->n_linear_iterations() >=
1288 // this->get_equation_systems().parameters.get<unsigned int>("linear solver maximum iterations")) &&
1289 // (this->final_linear_residual() >
1290 // this->get_equation_systems().parameters.get<Real>("linear solver tolerance")))
1291 // {
1292 // libmesh_error_msg("Warning: Linear solver may not have converged! Final linear residual = "
1293 // << this->final_linear_residual() << ", number of iterations = "
1294 // << this->n_linear_iterations());
1295 // }
1296 //
1297 // get_non_dirichlet_inner_product_matrix_if_avail()->vector_mult(*inner_product_storage_vector, *solution);
1298 //
1299 // Real slow_residual_norm_sq = solution->dot(*inner_product_storage_vector);
1300 //
1301 // return libmesh_real(std::sqrt( slow_residual_norm_sq ));
1302 //}
1303 
1304 void TransientRBConstruction::write_riesz_representors_to_files(const std::string & riesz_representors_dir,
1305  const bool write_binary_residual_representors)
1306 {
1307  LOG_SCOPE("write_riesz_representors_to_files()", "TransientRBConstruction");
1308 
1309  // Write out the M_q_representors. These are useful to have when restarting,
1310  // so you don't have to recompute them all over again. There should be
1311  // this->rb_eval->get_n_basis_functions() of these.
1312  libMesh::out << "Writing out the M_q_representors..." << std::endl;
1313 
1314  std::ostringstream file_name;
1315  const std::string riesz_representor_suffix = (write_binary_residual_representors ? ".xdr" : ".dat");
1316 
1317  TransientRBEvaluation & trans_rb_eval = cast_ref<TransientRBEvaluation &>(get_rb_evaluation());
1318 
1319  const unsigned int istop = trans_rb_eval.get_n_basis_functions();
1320  const unsigned int istart = istop-get_delta_N();
1321 
1322  for (std::size_t q=0; q<trans_rb_eval.M_q_representor.size(); ++q)
1323  for (unsigned int i=istart; i<istop; ++i)
1324  {
1325  libMesh::out << "Writing out M_q_representor[" << q << "][" << i << "]..." << std::endl;
1326  libmesh_assert(trans_rb_eval.M_q_representor[q][i]);
1327 
1328  file_name.str(""); // reset filename
1329  file_name << riesz_representors_dir << "/M_q_representor" << i << riesz_representor_suffix;
1330 
1331  {
1332  // No need to copy!
1333  //*solution = *(M_q_representor[q][i]);
1334  trans_rb_eval.M_q_representor[q][i]->swap(*solution);
1335 
1336  Xdr mr_data(file_name.str(),
1337  write_binary_residual_representors ? ENCODE : WRITE);
1338 
1339  write_serialized_data(mr_data, false);
1340 
1341  // Synchronize before moving on
1342  this->comm().barrier();
1343 
1344  // Swap back.
1345  trans_rb_eval.M_q_representor[q][i]->swap(*solution);
1346 
1347  // TODO: bzip the resulting file? See $LIBMESH_DIR/src/mesh/unstructured_mesh.C
1348  // for the system call, be sure to do it only on one processor, etc.
1349  }
1350  }
1351 }
1352 
1353 void TransientRBConstruction::read_riesz_representors_from_files(const std::string & riesz_representors_dir,
1354  const bool read_binary_residual_representors)
1355 {
1356  LOG_SCOPE("read_riesz_representors_from_files()", "TransientRBConstruction");
1357 
1358  const std::string riesz_representor_suffix =
1359  (read_binary_residual_representors ? ".xdr" : ".dat");
1360 
1361  std::ostringstream file_name;
1362  struct stat stat_info;
1363 
1364  TransientRBEvaluation & trans_rb_eval = cast_ref<TransientRBEvaluation &>(get_rb_evaluation());
1365 
1366  libMesh::out << "Reading in the M_q_representors..." << std::endl;
1367 
1368  // Read in the Aq representors. The class makes room for [Q_m][Nmax] of these. We are going to
1369  // read in [Q_m][this->rb_eval->get_n_basis_functions()]. FIXME:
1370  // should we be worried about leaks in the locations where we're about to fill entries?
1371  for (std::size_t i=0; i<trans_rb_eval.M_q_representor.size(); ++i)
1372  for (std::size_t j=0; j<trans_rb_eval.M_q_representor[i].size(); ++j)
1373  {
1374  if (trans_rb_eval.M_q_representor[i][j] != nullptr)
1375  libmesh_error_msg("Error, must delete existing M_q_representor before reading in from file.");
1376  }
1377 
1378  // Now ready to read them in from file!
1379  for (std::size_t i=0; i<trans_rb_eval.M_q_representor.size(); ++i)
1380  for (std::size_t j=0; j<trans_rb_eval.get_n_basis_functions(); ++j)
1381  {
1382  file_name.str(""); // reset filename
1383  file_name << riesz_representors_dir
1384  << "/M_q_representor" << i << "_" << j << riesz_representor_suffix;
1385 
1386  // On processor zero check to be sure the file exists
1387  if (this->processor_id() == 0)
1388  {
1389  int stat_result = stat(file_name.str().c_str(), &stat_info);
1390 
1391  if (stat_result != 0)
1392  libmesh_error_msg("File does not exist: " << file_name.str());
1393  }
1394 
1395  Xdr aqr_data(file_name.str(),
1396  read_binary_residual_representors ? DECODE : READ);
1397 
1398  read_serialized_data(aqr_data, false);
1399 
1400  trans_rb_eval.M_q_representor[i][j] = NumericVector<Number>::build(this->comm());
1401  trans_rb_eval.M_q_representor[i][j]->init (n_dofs(), n_local_dofs(),
1402  false, PARALLEL);
1403 
1404  // No need to copy, just swap
1405  //*M_q_representor[i][j] = *solution;
1406  trans_rb_eval.M_q_representor[i][j]->swap(*solution);
1407  }
1408 }
1409 
1410 } // namespace libMesh
libMesh::RBConstruction::inner_product_matrix
std::unique_ptr< SparseMatrix< Number > > inner_product_matrix
The inner product matrix.
Definition: rb_construction.h:484
libMesh::SparseMatrix::close
virtual void close()=0
Calls the SparseMatrix's internal assembly routines, ensuring that the values are consistent across p...
libMesh::RBEvaluation::get_n_basis_functions
virtual unsigned int get_n_basis_functions() const
Get the current number of basis functions.
Definition: rb_evaluation.h:145
libMesh::NumericVector::zero
virtual void zero()=0
Set all entries to zero.
libMesh::Number
Real Number
Definition: libmesh_common.h:195
libMesh::TransientRBConstruction::truth_solve
virtual Real truth_solve(int write_interval) override
Perform a truth solve at the current parameter.
Definition: transient_rb_construction.C:520
libMesh::RBThetaExpansion::get_n_output_terms
unsigned int get_n_output_terms(unsigned int output_index) const
Get the number of affine terms associated with the specified output.
Definition: rb_theta_expansion.C:53
libMesh::RBThetaExpansion::get_n_F_terms
unsigned int get_n_F_terms() const
Get Q_f, the number of terms in the affine expansion for the right-hand side.
Definition: rb_theta_expansion.C:41
libMesh::System::get_equation_systems
const EquationSystems & get_equation_systems() const
Definition: system.h:720
libMesh::TransientRBAssemblyExpansion::get_n_M_terms
unsigned int get_n_M_terms() const
Get Q_m, the number of terms in the affine expansion for the bilinear form.
Definition: transient_rb_assembly_expansion.C:56
libMesh::NumericVector::add
virtual void add(const numeric_index_type i, const T value)=0
Adds value to each entry of the vector.
libMesh::RBTemporalDiscretization::get_control
Real get_control(const unsigned int k) const
Get/set the RHS control.
Definition: rb_temporal_discretization.C:79
libMesh::TransientRBThetaExpansion
This class stores the set of RBTheta functor objects that define the "parameter-dependent expansion" ...
Definition: transient_rb_theta_expansion.h:41
libMesh::RBConstruction::get_Aq
SparseMatrix< Number > * get_Aq(unsigned int q)
Get a pointer to Aq.
Definition: rb_construction.C:1876
libMesh::ExplicitSystem::rhs
NumericVector< Number > * rhs
The system matrix.
Definition: explicit_system.h:114
libMesh::RBConstruction::Nmax
unsigned int Nmax
Maximum number of reduced basis functions we are willing to use.
Definition: rb_construction.h:762
libMesh::RBConstructionBase< LinearImplicitSystem >::inner_product_storage_vector
std::unique_ptr< NumericVector< Number > > inner_product_storage_vector
We keep an extra temporary vector that is useful for performing inner products (avoids unnecessary me...
Definition: rb_construction_base.h:254
libMesh::RBConstruction::process_parameters_file
virtual void process_parameters_file(const std::string &parameters_filename)
Read in from the file specified by parameters_filename and set the this system's member variables acc...
Definition: rb_construction.C:193
libMesh::PARALLEL
Definition: enum_parallel_type.h:36
libMesh::TransientRBConstruction::get_error_temporal_data
const NumericVector< Number > & get_error_temporal_data()
Get the column of temporal_data corresponding to the current time level.
Definition: transient_rb_construction.C:702
libMesh::TransientRBThetaExpansion::eval_M_theta
virtual Number eval_M_theta(unsigned int q, const RBParameters &mu)
Evaluate theta at the current parameter.
Definition: transient_rb_theta_expansion.C:33
libMesh::TransientRBEvaluation::M_q_representor
std::vector< std::vector< std::unique_ptr< NumericVector< Number > > > > M_q_representor
Vector storing the mass matrix representors.
Definition: transient_rb_evaluation.h:244
libMesh::TransientRBConstruction::greedy_termination_test
virtual bool greedy_termination_test(Real abs_greedy_error, Real initial_greedy_error, int count) override
Function that indicates when to terminate the Greedy basis training.
Definition: transient_rb_construction.C:619
libMesh::TransientRBConstruction::compute_truth_projection_error
bool compute_truth_projection_error
Boolean flag that indicates whether we will compute the projection error for the truth solution into ...
Definition: transient_rb_construction.h:301
libMesh::RBTemporalDiscretization::get_euler_theta
Real get_euler_theta() const
Get/set euler_theta, parameter that determines the temporal discretization.
Definition: rb_temporal_discretization.C:46
libMesh::libmesh_real
T libmesh_real(T a)
Definition: libmesh_common.h:166
libMesh::RBConstruction::initialize_rb_construction
virtual void initialize_rb_construction(bool skip_matrix_assembly=false, bool skip_vector_assembly=false)
Allocate all the data structures necessary for the construction stage of the RB method.
Definition: rb_construction.C:419
libMesh::TransientRBConstruction::set_delta_N
void set_delta_N(const unsigned int new_delta_N)
Set delta_N, the number of basis functions we add to the RB space from each POD.
Definition: transient_rb_construction.h:221
libMesh::TransientRBEvaluation::RB_initial_condition_all_N
std::vector< DenseVector< Number > > RB_initial_condition_all_N
The RB initial conditions (i.e.
Definition: transient_rb_evaluation.h:218
libMesh::RBEvaluation::rb_solve
virtual Real rb_solve(unsigned int N)
Perform online solve with the N RB basis functions, for the set of parameters in current_params,...
Definition: rb_evaluation.C:209
libMesh::SparseMatrix::vector_mult
void vector_mult(NumericVector< T > &dest, const NumericVector< T > &arg) const
Multiplies the matrix by the NumericVector arg and stores the result in NumericVector dest.
Definition: sparse_matrix.C:170
libMesh::TransientRBConstruction::L2_assembly
ElemAssembly * L2_assembly
Function pointer for assembling the L2 matrix.
Definition: transient_rb_construction.h:393
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::DenseVector::zero
virtual void zero() override
Set every element in the vector to 0.
Definition: dense_vector.h:379
libMesh::Xdr
This class implements a C++ interface to the XDR (eXternal Data Representation) format.
Definition: xdr_cxx.h:65
libMesh::TransientRBConstruction::M_q_vector
std::vector< std::unique_ptr< SparseMatrix< Number > > > M_q_vector
Vector storing the Q_m matrices from the mass operator.
Definition: transient_rb_construction.h:275
libMesh::TransientRBConstruction::get_all_matrices
virtual void get_all_matrices(std::map< std::string, SparseMatrix< Number > * > &all_matrices) override
Get a map that stores pointers to all of the matrices.
Definition: transient_rb_construction.C:321
libMesh::TransientRBConstruction::~TransientRBConstruction
virtual ~TransientRBConstruction()
Destructor.
Definition: transient_rb_construction.C:85
libMesh::TransientRBConstruction::print_info
virtual void print_info() override
Print out info that describes the current setup of this RBConstruction.
Definition: transient_rb_construction.C:149
libMesh::NumericVector::close
virtual void close()=0
Calls the NumericVector's internal assembly routines, ensuring that the values are consistent across ...
libMesh::TransientRBConstruction::update_residual_terms
virtual void update_residual_terms(bool compute_inner_products) override
Compute the terms that are combined ‘online’ to determine the dual norm of the residual.
Definition: transient_rb_construction.C:1026
libMesh::NumericVector::init
virtual void init(const numeric_index_type n, const numeric_index_type n_local, const bool fast=false, const ParallelType ptype=AUTOMATIC)=0
Change the dimension of the vector to n.
std::sqrt
MetaPhysicL::DualNumber< T, D > sqrt(const MetaPhysicL::DualNumber< T, D > &in)
libMesh::TransientRBConstruction::clear
virtual void clear() override
Clear all the data structures associated with the system.
Definition: transient_rb_construction.C:91
libMesh::RBConstruction::Fq_representor
std::vector< std::unique_ptr< NumericVector< Number > > > Fq_representor
Vector storing the residual representors associated with the right-hand side.
Definition: rb_construction.h:504
libMesh::ParallelObject::comm
const Parallel::Communicator & comm() const
Definition: parallel_object.h:94
libMesh::DenseMatrix< Number >
libMesh::TransientRBEvaluation::RB_L2_matrix
DenseMatrix< Number > RB_L2_matrix
Dense RB L2 matrix.
Definition: transient_rb_evaluation.h:166
libMesh::RBConstruction::assert_convergence
bool assert_convergence
A boolean flag to indicate whether to check for proper convergence after each solve.
Definition: rb_construction.h:781
libMesh::RBParameters
This class is part of the rbOOmit framework.
Definition: rb_parameters.h:42
libMesh::RBTemporalDiscretization::process_temporal_parameters_file
void process_temporal_parameters_file(const std::string &parameters_filename)
Read in and initialize parameters from parameters_filename.
Definition: rb_temporal_discretization.C:93
libMesh::WRITE
Definition: enum_xdr_mode.h:40
libMesh::RBThetaExpansion::eval_output_theta
virtual Number eval_output_theta(unsigned int output_index, unsigned int q_l, const RBParameters &mu)
Evaluate theta_q_l at the current parameter.
Definition: rb_theta_expansion.C:141
libMesh::ExodusII_IO
The ExodusII_IO class implements reading meshes in the ExodusII file format from Sandia National Labs...
Definition: exodusII_io.h:51
libMesh::TransientRBConstruction::get_non_dirichlet_M_q
SparseMatrix< Number > * get_non_dirichlet_M_q(unsigned int q)
Get a pointer to non_dirichlet_M_q.
Definition: transient_rb_construction.C:307
libMesh::RBTemporalDiscretization::get_delta_t
Real get_delta_t() const
Get/set delta_t, the time-step size.
Definition: rb_temporal_discretization.C:36
libMesh::RBTemporalDiscretization::pull_temporal_discretization_data
void pull_temporal_discretization_data(RBTemporalDiscretization &other)
Pull the temporal discretization data from other.
Definition: rb_temporal_discretization.C:110
libMesh::SparseMatrix
Generic sparse matrix.
Definition: vector_fe_ex5.C:45
libMesh::NumericVector::build
static std::unique_ptr< NumericVector< T > > build(const Parallel::Communicator &comm, const SolverPackage solver_package=libMesh::default_solver_package())
Builds a NumericVector on the processors in communicator comm using the linear solver package specifi...
Definition: numeric_vector.C:49
libMesh::RBParametrized::get_parameters
const RBParameters & get_parameters() const
Get the current parameters.
Definition: rb_parametrized.C:166
libMesh::RBConstruction::greedy_termination_test
virtual bool greedy_termination_test(Real abs_greedy_error, Real initial_greedy_error, int count)
Function that indicates when to terminate the Greedy basis training.
Definition: rb_construction.C:1192
libMesh::RBConstruction::assemble_misc_matrices
virtual void assemble_misc_matrices()
Assemble and store all the inner-product matrix, the constraint matrix (for constrained problems) and...
Definition: rb_construction.C:918
libMesh::TransientRBAssemblyExpansion::get_M_assembly
ElemAssembly & get_M_assembly(unsigned int q)
Return a reference to the specified M_assembly object.
Definition: transient_rb_assembly_expansion.C:66
libMesh::TransientRBConstruction::POD_tol
Real POD_tol
If positive, this tolerance determines the number of POD modes we add to the space on a call to enric...
Definition: transient_rb_construction.h:380
libMesh::TransientRBConstruction::write_riesz_representors_to_files
virtual void write_riesz_representors_to_files(const std::string &riesz_representors_dir, const bool write_binary_residual_representors) override
Write out all the Riesz representor data to files.
Definition: transient_rb_construction.C:1304
libMesh::RBTemporalDiscretization::set_time_step
void set_time_step(const unsigned int k)
Definition: rb_temporal_discretization.C:62
libMesh::NumericVector< Number >
libMesh::TransientRBEvaluation::Fq_Mq_representor_innerprods
std::vector< std::vector< std::vector< Number > > > Fq_Mq_representor_innerprods
Vectors storing the residual representor inner products to be used in computing the residuals online.
Definition: transient_rb_evaluation.h:224
libMesh::RBTemporalDiscretization::get_n_time_steps
unsigned int get_n_time_steps() const
Get/set the total number of time-steps.
Definition: rb_temporal_discretization.C:68
libMesh::TransientRBConstruction::set_max_truth_solves
void set_max_truth_solves(int max_truth_solves_in)
Definition: transient_rb_construction.h:209
libMesh::TransientRBConstruction::set_L2_assembly
void set_L2_assembly(ElemAssembly &L2_assembly_in)
Set the L2 object.
Definition: transient_rb_construction.C:456
libMesh::libmesh_assert
libmesh_assert(ctx)
libMesh::TransientRBConstruction::add_scaled_mass_matrix
void add_scaled_mass_matrix(Number scalar, SparseMatrix< Number > *input_matrix)
Add the scaled mass matrix (assembled for the current parameter) to input_matrix.
Definition: transient_rb_construction.C:365
libMesh::RBConstruction::update_residual_terms
virtual void update_residual_terms(bool compute_inner_products=true)
Compute the terms that are combined ‘online’ to determine the dual norm of the residual.
Definition: rb_construction.C:1535
libMesh::TransientRBConstruction::initialize_truth
virtual void initialize_truth()
This function imposes a truth initial condition, defaults to zero initial condition if the flag nonze...
Definition: transient_rb_construction.C:711
libMesh::TransientRBConstruction::init_filename
std::string init_filename
The filename of the file containing the initial condition projected onto the truth mesh.
Definition: transient_rb_construction.h:307
std::abs
MetaPhysicL::DualNumber< T, D > abs(const MetaPhysicL::DualNumber< T, D > &in)
libMesh::TransientRBThetaExpansion::get_n_M_terms
virtual unsigned int get_n_M_terms()
Get Q_m, the number of terms in the affine expansion for the mass operator.
Definition: transient_rb_theta_expansion.h:67
libMesh::RBConstruction::inner_product_solver
std::unique_ptr< LinearSolver< Number > > inner_product_solver
We store an extra linear solver object which we can optionally use for solving all systems in which t...
Definition: rb_construction.h:471
libMesh::RBConstruction::allocate_data_structures
virtual void allocate_data_structures()
Helper function that actually allocates all the data structures required by this class.
Definition: rb_construction.C:467
libMesh::RBTemporalDiscretization::get_time_step
unsigned int get_time_step() const
Get/set the current time-step.
Definition: rb_temporal_discretization.C:57
libMesh::LinearImplicitSystem::get_linear_solver
virtual LinearSolver< Number > * get_linear_solver() const override
Definition: linear_implicit_system.C:353
libMesh::TransientRBConstruction::train_reduced_basis
virtual Real train_reduced_basis(const bool resize_rb_eval_data=true) override
Train the reduced basis.
Definition: transient_rb_construction.C:287
libMesh::System::n_local_dofs
dof_id_type n_local_dofs() const
Definition: system.C:187
libMesh::DECODE
Definition: enum_xdr_mode.h:39
libMesh::RBConstruction::update_system
virtual void update_system()
Update the system after enriching the RB space; this calls a series of functions to update the system...
Definition: rb_construction.C:1350
libMesh::RBConstruction::is_rb_eval_initialized
bool is_rb_eval_initialized() const
Definition: rb_construction.C:183
libMesh::System::get_mesh
const MeshBase & get_mesh() const
Definition: system.h:2083
libMesh::ParallelObject::processor_id
processor_id_type processor_id() const
Definition: parallel_object.h:106
libMesh::RBConstruction::get_output_vector
NumericVector< Number > * get_output_vector(unsigned int n, unsigned int q_l)
Get a pointer to the n^th output.
Definition: rb_construction.C:1934
libMesh::System::current_local_solution
std::unique_ptr< NumericVector< Number > > current_local_solution
All the values I need to compute my contribution to the simulation at hand.
Definition: system.h:1551
libMesh::TransientRBEvaluation::RB_M_q_vector
std::vector< DenseMatrix< Number > > RB_M_q_vector
Dense matrices for the RB mass matrices.
Definition: transient_rb_evaluation.h:178
libMesh::TransientRBConstruction::get_matrix_for_output_dual_solves
virtual SparseMatrix< Number > & get_matrix_for_output_dual_solves() override
Override to return the L2 product matrix for output dual norm solves for transient state problems.
Definition: transient_rb_construction.C:939
libMesh::System::read_serialized_data
void read_serialized_data(Xdr &io, const bool read_additional_data=true)
Reads additional data, namely vectors, for this System.
Definition: system_io.C:724
libMesh::TransientRBConstruction::assemble_L2_matrix
void assemble_L2_matrix(SparseMatrix< Number > *input_matrix, bool apply_dirichlet_bc=true)
Assemble the L2 matrix.
Definition: transient_rb_construction.C:348
libMesh::ImplicitSystem::matrix
SparseMatrix< Number > * matrix
The system matrix.
Definition: implicit_system.h:393
libMesh::RBConstructionBase< LinearImplicitSystem >
libMesh::TransientRBEvaluation::Mq_Mq_representor_innerprods
std::vector< std::vector< std::vector< Number > > > Mq_Mq_representor_innerprods
Definition: transient_rb_evaluation.h:225
libMesh::RBConstruction::solve_for_matrix_and_rhs
virtual void solve_for_matrix_and_rhs(LinearSolver< Number > &input_solver, SparseMatrix< Number > &input_matrix, NumericVector< Number > &input_rhs)
Assembles & solves the linear system A*x=b for the specified matrix input_matrix and right-hand side ...
Definition: rb_construction.C:130
libMesh::RBConstruction::get_rb_evaluation
RBEvaluation & get_rb_evaluation()
Get a reference to the RBEvaluation object.
Definition: rb_construction.C:175
libMesh::DenseVector::dot
CompareTypes< T, T2 >::supertype dot(const DenseVector< T2 > &vec) const
Definition: dense_vector.h:451
libMesh::RBConstruction::get_rb_theta_expansion
RBThetaExpansion & get_rb_theta_expansion()
Get a reference to the RBThetaExpansion object that that belongs to rb_eval.
Definition: rb_construction.C:188
libMesh::RBThetaExpansion::eval_A_theta
virtual Number eval_A_theta(unsigned int q, const RBParameters &mu)
Evaluate theta_q_a at the current parameter.
Definition: rb_theta_expansion.C:119
libMesh::TransientRBConstruction::process_parameters_file
virtual void process_parameters_file(const std::string &parameters_filename) override
Read in the parameters from file and set up the system accordingly.
Definition: transient_rb_construction.C:122
libMesh::TransientRBEvaluation::RB_temporal_solution_data
std::vector< DenseVector< Number > > RB_temporal_solution_data
Array storing the solution data at each time level from the most recent solve.
Definition: transient_rb_evaluation.h:200
libMesh::TransientRBConstruction::update_system
virtual void update_system() override
Update the system after enriching the RB space.
Definition: transient_rb_construction.C:927
libMesh::RBConstructionBase< LinearImplicitSystem >::is_quiet
bool is_quiet() const
Is the system in quiet mode?
Definition: rb_construction_base.h:98
libMesh::TransientRBConstruction::non_dirichlet_M_q_vector
std::vector< std::unique_ptr< SparseMatrix< Number > > > non_dirichlet_M_q_vector
We sometimes also need a second set of M_q matrices that do not have the Dirichlet boundary condition...
Definition: transient_rb_construction.h:282
libMesh::TransientRBConstruction::read_riesz_representors_from_files
virtual void read_riesz_representors_from_files(const std::string &riesz_representors_dir, const bool write_binary_residual_representors) override
Write out all the Riesz representor data to files.
Definition: transient_rb_construction.C:1353
libMesh::RBConstruction::get_Nmax
unsigned int get_Nmax() const
Get/set Nmax, the maximum number of RB functions we are willing to compute.
Definition: rb_construction.h:206
libMesh::TransientRBConstruction::add_IC_to_RB_space
void add_IC_to_RB_space()
Initialize RB space by adding the truth initial condition as the first RB basis function.
Definition: transient_rb_construction.C:729
libMesh::TransientRBEvaluation
This class is part of the rbOOmit framework.
Definition: transient_rb_evaluation.h:50
libMesh::DenseVector::size
virtual unsigned int size() const override
Definition: dense_vector.h:92
libMesh::TransientRBConstruction::initialize_rb_construction
virtual void initialize_rb_construction(bool skip_matrix_assembly=false, bool skip_vector_assembly=false) override
Allocate all the data structures necessary for the construction stage of the RB method.
Definition: transient_rb_construction.C:105
libMesh::READ
Definition: enum_xdr_mode.h:41
libMesh::TransientRBConstruction::L2_matrix
std::unique_ptr< SparseMatrix< Number > > L2_matrix
The L2 matrix.
Definition: transient_rb_construction.h:264
libMesh::RBConstruction::check_convergence
void check_convergence(LinearSolver< Number > &input_solver)
Check if the linear solver reports convergence.
Definition: rb_construction.C:2231
libMesh::SparseMatrix::add
virtual void add(const numeric_index_type i, const numeric_index_type j, const T value)=0
Add value to the element (i,j).
libMesh::Utility::get_timestamp
std::string get_timestamp()
Definition: timestamp.C:37
libMesh::TransientRBConstruction::allocate_data_structures
virtual void allocate_data_structures() override
Helper function that actually allocates all the data structures required by this class.
Definition: transient_rb_construction.C:185
libMesh::EquationSystems
This is the EquationSystems class.
Definition: equation_systems.h:74
libMesh::LinearImplicitSystem::n_linear_iterations
unsigned int n_linear_iterations() const
Definition: linear_implicit_system.h:164
libMesh::MeshOutput::write_equation_systems
virtual void write_equation_systems(const std::string &, const EquationSystems &, const std::set< std::string > *system_names=nullptr)
This method implements writing a mesh with data to a specified file where the data is taken from the ...
Definition: mesh_output.C:31
libMesh::RBConstruction::print_info
virtual void print_info()
Print out info that describes the current setup of this RBConstruction.
Definition: rb_construction.C:312
libMesh::RBConstruction::get_non_dirichlet_inner_product_matrix_if_avail
SparseMatrix< Number > * get_non_dirichlet_inner_product_matrix_if_avail()
Get the non-Dirichlet inner-product matrix if it's available, otherwise get the inner-product matrix ...
Definition: rb_construction.C:1866
libMesh::RBThetaExpansion::get_n_outputs
unsigned int get_n_outputs() const
Get n_outputs, the number output functionals.
Definition: rb_theta_expansion.C:47
libMesh::RBConstruction::assemble_affine_expansion
virtual void assemble_affine_expansion(bool skip_matrix_assembly, bool skip_vector_assembly)
Assemble the matrices and vectors for this system.
Definition: rb_construction.C:449
libMesh::System::write_serialized_data
void write_serialized_data(Xdr &io, const bool write_additional_data=true) const
Writes additional data, namely vectors, for this System.
Definition: system_io.C:1703
libMesh::RBConstruction::update_RB_system_matrices
virtual void update_RB_system_matrices()
Compute the reduced basis matrices for the current basis.
Definition: rb_construction.C:1466
libMesh::TransientRBConstruction::truth_outputs_all_k
std::vector< std::vector< Number > > truth_outputs_all_k
The truth outputs for all time-levels from the most recent truth_solve.
Definition: transient_rb_construction.h:288
libMesh::ENCODE
Definition: enum_xdr_mode.h:38
libMesh::DenseVector::resize
void resize(const unsigned int n)
Resize the vector.
Definition: dense_vector.h:355
libMesh::DofMap::attach_matrix
void attach_matrix(SparseMatrix< Number > &matrix)
Additional matrices may be handled with this DofMap.
Definition: dof_map.C:274
libMesh::RBConstruction::compute_RB_inner_product
bool compute_RB_inner_product
Boolean flag to indicate whether we compute the RB_inner_product_matrix.
Definition: rb_construction.h:553
libMesh::RBConstruction::delta_N
unsigned int delta_N
The number of basis functions that we add at each greedy step.
Definition: rb_construction.h:768
libMesh::System::solution
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition: system.h:1539
libMesh::RBConstruction::get_delta_N
unsigned int get_delta_N() const
Get delta_N, the number of basis functions we add to the RB space per iteration of the greedy algorit...
Definition: rb_construction.h:417
libMesh::TransientRBConstruction::RB_ic_proj_rhs_all_N
DenseVector< Number > RB_ic_proj_rhs_all_N
The vector that stores the right-hand side for the initial condition projections.
Definition: transient_rb_construction.h:399
libMesh::ElemAssembly
ElemAssembly provides a per-element (interior and boundary) assembly functionality.
Definition: elem_assembly.h:38
libMesh::RBEvaluation::RB_inner_product_matrix
DenseMatrix< Number > RB_inner_product_matrix
The inner product matrix.
Definition: rb_evaluation.h:255
libMesh::SparseMatrix::build
static std::unique_ptr< SparseMatrix< T > > build(const Parallel::Communicator &comm, const SolverPackage solver_package=libMesh::default_solver_package())
Builds a SparseMatrix<T> using the linear solver package specified by solver_package.
Definition: sparse_matrix.C:130
libMesh::RBConstruction::add_scaled_matrix_and_vector
void add_scaled_matrix_and_vector(Number scalar, ElemAssembly *elem_assembly, SparseMatrix< Number > *input_matrix, NumericVector< Number > *input_vector, bool symmetrize=false, bool apply_dof_constraints=true)
This function loops over the mesh and applies the specified interior and/or boundary assembly routine...
Definition: rb_construction.C:588
libMesh::TransientRBConstruction::assemble_mass_matrix
void assemble_mass_matrix(SparseMatrix< Number > *input_matrix)
Assemble the mass matrix at the current parameter and store it in input_matrix.
Definition: transient_rb_construction.C:359
value
static const bool value
Definition: xdr_io.C:56
libMesh::DofMap
This class handles the numbering of degrees of freedom on a mesh.
Definition: dof_map.h:176
libMesh::TransientRBEvaluation::Aq_Mq_representor_innerprods
std::vector< std::vector< std::vector< std::vector< Number > > > > Aq_Mq_representor_innerprods
Definition: transient_rb_evaluation.h:226
libMesh::TransientSystem< RBConstruction >::clear
virtual void clear() override
Clear all the data structures associated with the system.
Definition: transient_system.C:65
libMesh::RBEvaluation::Aq_representor
std::vector< std::vector< std::unique_ptr< NumericVector< Number > > > > Aq_representor
Vector storing the residual representors associated with the left-hand side.
Definition: rb_evaluation.h:316
libMesh::DenseMatrix::get_principal_submatrix
void get_principal_submatrix(unsigned int sub_m, unsigned int sub_n, DenseMatrix< T > &dest) const
Put the sub_m x sub_n principal submatrix into dest.
Definition: dense_matrix_impl.h:574
libMesh::RBConstruction::exit_on_repeated_greedy_parameters
bool exit_on_repeated_greedy_parameters
Boolean flag to indicate whether we exit the greedy if we select the same parameters twice in a row.
Definition: rb_construction.h:530
libMesh::TransientRBConstruction::TransientRBConstruction
TransientRBConstruction(EquationSystems &es, const std::string &name, const unsigned int number)
Constructor.
Definition: transient_rb_construction.C:61
libMesh::TransientRBConstruction::update_RB_system_matrices
virtual void update_RB_system_matrices() override
Compute the reduced basis matrices for the current basis.
Definition: transient_rb_construction.C:968
libMesh::RBConstruction::get_all_matrices
virtual void get_all_matrices(std::map< std::string, SparseMatrix< Number > * > &all_matrices)
Get a map that stores pointers to all of the matrices.
Definition: rb_construction.C:1952
libMesh::TransientRBConstruction::update_RB_initial_condition_all_N
void update_RB_initial_condition_all_N()
Compute the L2 projection of the initial condition onto the RB space for 1 <= N <= RB_size and store ...
Definition: transient_rb_construction.C:1161
libMesh::TransientRBConstruction::enrich_RB_space
virtual void enrich_RB_space() override
Add a new basis functions to the RB space.
Definition: transient_rb_construction.C:761
libMesh::RBConstruction::get_Fq
NumericVector< Number > * get_Fq(unsigned int q)
Get a pointer to Fq.
Definition: rb_construction.C:1905
libMesh::TransientRBEvaluation::initial_L2_error_all_N
std::vector< Real > initial_L2_error_all_N
Vector storing initial L2 error for all 1 <= N <= RB_size.
Definition: transient_rb_evaluation.h:212
libMesh::TransientRBConstruction::get_max_truth_solves
int get_max_truth_solves() const
Get/set max_truth_solves, the maximum number of RB truth solves we are willing to compute in the tran...
Definition: transient_rb_construction.h:208
libMesh::NumericVector::scale
virtual void scale(const T factor)=0
Scale each element of the vector by the given factor.
libMesh::RBThetaExpansion::get_n_A_terms
unsigned int get_n_A_terms() const
Get Q_a, the number of terms in the affine expansion for the bilinear form.
Definition: rb_theta_expansion.C:35
libMesh::RBThetaExpansion::eval_F_theta
virtual Number eval_F_theta(unsigned int q, const RBParameters &mu)
Evaluate theta_q_f at the current parameter.
Definition: rb_theta_expansion.C:130
libMesh::TransientRBConstruction::assemble_all_affine_operators
virtual void assemble_all_affine_operators() override
Assemble and store all the affine operators.
Definition: transient_rb_construction.C:489
libMesh::RBConstruction::store_non_dirichlet_operators
bool store_non_dirichlet_operators
Boolean flag to indicate whether we store a second copy of each affine operator and vector which does...
Definition: rb_construction.h:560
libMesh::LinearImplicitSystem::final_linear_residual
Real final_linear_residual() const
Definition: linear_implicit_system.h:169
libMesh::TransientRBConstruction::non_dirichlet_L2_matrix
std::unique_ptr< SparseMatrix< Number > > non_dirichlet_L2_matrix
The L2 matrix without Dirichlet conditions enforced.
Definition: transient_rb_construction.h:270
libMesh::System::get_dof_map
const DofMap & get_dof_map() const
Definition: system.h:2099
libMesh::System::n_dofs
dof_id_type n_dofs() const
Definition: system.C:150
libMesh::TransientRBConstruction::max_truth_solves
int max_truth_solves
Maximum number of truth solves in the POD-Greedy.
Definition: transient_rb_construction.h:388
libMesh::DenseVector::get_principal_subvector
void get_principal_subvector(unsigned int sub_n, DenseVector< T > &dest) const
Puts the principal subvector of size sub_n (i.e.
Definition: dense_vector.h:672
libMesh::DenseMatrix::lu_solve
void lu_solve(const DenseVector< T > &b, DenseVector< T > &x)
Solve the system Ax=b given the input vector b.
Definition: dense_matrix_impl.h:625
libMesh::TransientRBConstruction::assemble_misc_matrices
virtual void assemble_misc_matrices() override
Override to assemble the L2 matrix as well.
Definition: transient_rb_construction.C:506
libMesh::TransientRBConstruction::nonzero_initialization
bool nonzero_initialization
Boolean flag to indicate whether we are using a non-zero initialization.
Definition: transient_rb_construction.h:294
libMesh::TransientRBConstruction::assemble_Mq_matrix
void assemble_Mq_matrix(unsigned int q, SparseMatrix< Number > *input_matrix, bool apply_dirichlet_bc=true)
Assemble the q^th affine term of the mass matrix and store it in input_matrix.
Definition: transient_rb_construction.C:469
libMesh::RBEvaluation::basis_functions
std::vector< std::unique_ptr< NumericVector< Number > > > basis_functions
The libMesh vectors storing the finite element coefficients of the RB basis functions.
Definition: rb_evaluation.h:241
libMesh::Real
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Definition: libmesh_common.h:121
libMesh::TransientSystem< RBConstruction >::old_local_solution
std::unique_ptr< NumericVector< Number > > old_local_solution
All the values I need to compute my contribution to the simulation at hand.
Definition: transient_system.h:119
libMesh::TransientRBConstruction::get_POD_tol
Real get_POD_tol() const
Get/set POD_tol.
Definition: transient_rb_construction.h:214
libMesh::TransientRBConstruction::set_POD_tol
void set_POD_tol(const Real POD_tol_in)
Definition: transient_rb_construction.h:215
communicator.h
libMesh::RBConstruction::assemble_all_affine_operators
virtual void assemble_all_affine_operators()
Assemble and store all Q_a affine operators as well as the inner-product matrix.
Definition: rb_construction.C:930
libMesh::TransientRBConstruction::assemble_affine_expansion
virtual void assemble_affine_expansion(bool skip_matrix_assembly, bool skip_vector_assembly) override
Override assemble_affine_expansion to also initialize RB_ic_proj_rhs_all_N, if necessary.
Definition: transient_rb_construction.C:258
libMesh::out
OStreamProxy out
libMesh::TransientRBAssemblyExpansion
This extends RBAssemblyExpansion to provide an assembly expansion for the case of time-dependent PDEs...
Definition: transient_rb_assembly_expansion.h:40
libMesh::TransientRBConstruction::set_error_temporal_data
Number set_error_temporal_data()
Set column k (i.e.
Definition: transient_rb_construction.C:633
libMesh::TransientRBConstruction::temporal_data
std::vector< std::unique_ptr< NumericVector< Number > > > temporal_data
Dense matrix to store the data that we use for the temporal POD.
Definition: transient_rb_construction.h:408
libMesh::TransientRBConstruction::load_rb_solution
virtual void load_rb_solution() override
Load the RB solution from the current time-level into the libMesh solution vector.
Definition: transient_rb_construction.C:944
libMesh::System::update
virtual void update()
Update the local values to reflect the solution on neighboring processors.
Definition: system.C:408
libMesh::SparseMatrix::zero
virtual void zero()=0
Set all entries to 0.
libMesh::LinearImplicitSystem::linear_solver
std::unique_ptr< LinearSolver< Number > > linear_solver
The LinearSolver defines the interface used to solve the linear_implicit system.
Definition: linear_implicit_system.h:158
libMesh::TransientRBConstruction::mass_matrix_scaled_matvec
void mass_matrix_scaled_matvec(Number scalar, NumericVector< Number > &dest, NumericVector< Number > &arg)
Perform a matrix-vector multiplication with the current mass matrix and store the result in dest.
Definition: transient_rb_construction.C:378
libMesh::TransientRBConstruction::get_M_q
SparseMatrix< Number > * get_M_q(unsigned int q)
Get a pointer to M_q.
Definition: transient_rb_construction.C:296
libMesh::RBEvaluation::get_basis_function
NumericVector< Number > & get_basis_function(unsigned int i)
Get a reference to the i^th basis function.
Definition: rb_evaluation.C:202
libMesh::NumericVector::dot
virtual T dot(const NumericVector< T > &v) const =0
libMesh::TransientRBConstruction::truth_assembly
virtual void truth_assembly() override
Assemble the truth system in the transient linear case.
Definition: transient_rb_construction.C:403
libMesh::DenseVector< Number >
libMesh::RBConstruction::train_reduced_basis
virtual Real train_reduced_basis(const bool resize_rb_eval_data=true)
Train the reduced basis.
Definition: rb_construction.C:1024
libMesh::RBConstruction::get_rb_assembly_expansion
RBAssemblyExpansion & get_rb_assembly_expansion()
Definition: rb_construction.C:371
libMesh::TransientRBConstruction::get_L2_assembly
ElemAssembly & get_L2_assembly()
Definition: transient_rb_construction.C:461