libMesh
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/rb_construction.h"
22 #include "libmesh/rb_assembly_expansion.h"
23 #include "libmesh/rb_evaluation.h"
24 #include "libmesh/elem_assembly.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/equation_systems.h"
32 #include "libmesh/exodusII_io.h"
33 #include "libmesh/gmv_io.h"
34 #include "libmesh/linear_solver.h"
35 #include "libmesh/getpot.h"
36 #include "libmesh/int_range.h"
37 #include "libmesh/mesh_base.h"
38 #include "libmesh/parallel.h"
39 #include "libmesh/xdr_cxx.h"
40 #include "libmesh/timestamp.h"
41 #include "libmesh/petsc_linear_solver.h"
42 #include "libmesh/dg_fem_context.h"
43 #include "libmesh/dirichlet_boundaries.h"
44 #include "libmesh/zero_function.h"
45 #include "libmesh/coupling_matrix.h"
46 #include "libmesh/face_tri3_subdivision.h"
47 #include "libmesh/quadrature.h"
48 #include "libmesh/utility.h"
49 #include "libmesh/int_range.h"
50 
51 // C++ includes
52 #include <sys/types.h>
53 #include <sys/stat.h>
54 #include <errno.h>
55 #include <fstream>
56 #include <sstream>
57 #include <limits>
58 
59 namespace libMesh
60 {
61 
63  const std::string & name_in,
64  const unsigned int number_in)
65  : Parent(es, name_in, number_in),
66  inner_product_solver(LinearSolver<Number>::build(es.comm())),
67  extra_linear_solver(nullptr),
68  inner_product_matrix(SparseMatrix<Number>::build(es.comm())),
69  skip_residual_in_train_reduced_basis(false),
70  exit_on_repeated_greedy_parameters(true),
71  impose_internal_fluxes(false),
72  skip_degenerate_sides(true),
73  compute_RB_inner_product(false),
74  store_non_dirichlet_operators(false),
75  use_empty_rb_solve_in_greedy(true),
76  Fq_representor_innerprods_computed(false),
77  Nmax(0),
78  delta_N(1),
79  output_dual_innerprods_computed(false),
80  assert_convergence(true),
81  rb_eval(nullptr),
82  inner_product_assembly(nullptr),
83  use_energy_inner_product(false),
84  rel_training_tolerance(1.e-4),
85  abs_training_tolerance(1.e-12),
86  normalize_rb_bound_in_greedy(false)
87 {
88  // set assemble_before_solve flag to false
89  // so that we control matrix assembly.
90  assemble_before_solve = false;
91 }
92 
93 
95 {
96  this->clear();
97 }
98 
99 
101 {
102  LOG_SCOPE("clear()", "RBConstruction");
103 
104  Parent::clear();
105 
106  Aq_vector.clear();
107  Fq_vector.clear();
108  outputs_vector.clear();
109 
111  {
112  non_dirichlet_Aq_vector.clear();
113  non_dirichlet_Fq_vector.clear();
115  }
116 
117  // Also delete the Fq representors
118  Fq_representor.clear();
119 
120  // Set Fq_representor_innerprods_computed flag to false now
121  // that we've cleared the Fq representors
123 }
124 
125 std::string RBConstruction::system_type () const
126 {
127  return "RBConstruction";
128 }
129 
131  SparseMatrix<Number> & input_matrix,
132  NumericVector<Number> & input_rhs)
133 {
134  // This is similar to LinearImplicitSysmte::solve()
135 
136  // Get a reference to the EquationSystems
137  const EquationSystems & es =
138  this->get_equation_systems();
139 
140  // If the linear solver hasn't been initialized, we do so here.
141  input_solver.init();
142 
143  // Get the user-specifiied linear solver tolerance
144  const double tol =
145  double(es.parameters.get<Real>("linear solver tolerance"));
146 
147  // Get the user-specified maximum # of linear solver iterations
148  const unsigned int maxits =
149  es.parameters.get<unsigned int>("linear solver maximum iterations");
150 
151  // Solve the linear system. Several cases:
152  std::pair<unsigned int, Real> rval = std::make_pair(0,0.0);
153 
154  // It's good practice to clear the solution vector first since it can
155  // affect convergence of iterative solvers
156  solution->zero();
157  rval = input_solver.solve (input_matrix, *solution, input_rhs, tol, maxits);
158 
159  // Store the number of linear iterations required to
160  // solve and the final residual.
161  _n_linear_iterations = rval.first;
162  _final_linear_residual = rval.second;
163 
165 
166  // Update the system after the solve
167  this->update();
168 }
169 
171 {
172  rb_eval = &rb_eval_in;
173 }
174 
176 {
177  if (!rb_eval)
178  libmesh_error_msg("Error: RBEvaluation object hasn't been initialized yet");
179 
180  return *rb_eval;
181 }
182 
184 {
185  return (rb_eval != nullptr);
186 }
187 
189 {
191 }
192 
193 void RBConstruction::process_parameters_file (const std::string & parameters_filename)
194 {
195  // First read in data from input_filename
196  GetPot infile(parameters_filename);
197 
198  const unsigned int n_training_samples = infile("n_training_samples",0);
199  const bool deterministic_training = infile("deterministic_training",false);
200  unsigned int training_parameters_random_seed_in =
201  static_cast<unsigned int>(-1);
202  training_parameters_random_seed_in = infile("training_parameters_random_seed",
203  training_parameters_random_seed_in);
204  const bool quiet_mode_in = infile("quiet_mode", quiet_mode);
205  const unsigned int Nmax_in = infile("Nmax", Nmax);
206  const Real rel_training_tolerance_in = infile("rel_training_tolerance",
208  const Real abs_training_tolerance_in = infile("abs_training_tolerance",
210 
211  // Initialize value to false, let the input file value override.
212  const bool normalize_rb_bound_in_greedy_in = infile("normalize_rb_bound_in_greedy",
213  false);
214 
215  // Read in the parameters from the input file too
216  unsigned int n_continuous_parameters = infile.vector_variable_size("parameter_names");
217  RBParameters mu_min_in;
218  RBParameters mu_max_in;
219  for (unsigned int i=0; i<n_continuous_parameters; i++)
220  {
221  // Read in the parameter names
222  std::string param_name = infile("parameter_names", "NONE", i);
223 
224  {
225  Real min_val = infile(param_name, 0., 0);
226  mu_min_in.set_value(param_name, min_val);
227  }
228 
229  {
230  Real max_val = infile(param_name, 0., 1);
231  mu_max_in.set_value(param_name, max_val);
232  }
233  }
234 
235  std::map<std::string, std::vector<Real>> discrete_parameter_values_in;
236 
237  unsigned int n_discrete_parameters = infile.vector_variable_size("discrete_parameter_names");
238  for (unsigned int i=0; i<n_discrete_parameters; i++)
239  {
240  std::string param_name = infile("discrete_parameter_names", "NONE", i);
241 
242  unsigned int n_vals_for_param = infile.vector_variable_size(param_name);
243  std::vector<Real> vals_for_param(n_vals_for_param);
244  for (auto j : IntRange<unsigned int>(0, vals_for_param.size()))
245  vals_for_param[j] = infile(param_name, 0., j);
246 
247  discrete_parameter_values_in[param_name] = vals_for_param;
248  }
249 
250  std::map<std::string,bool> log_scaling_in;
251  // For now, just set all entries to false.
252  // TODO: Implement a decent way to specify log-scaling true/false
253  // in the input text file
254  for (const auto & pr : mu_min_in)
255  log_scaling_in[pr.first] = false;
256 
257  // Set the parameters that have been read in
258  set_rb_construction_parameters(n_training_samples,
259  deterministic_training,
260  training_parameters_random_seed_in,
261  quiet_mode_in,
262  Nmax_in,
263  rel_training_tolerance_in,
264  abs_training_tolerance_in,
265  normalize_rb_bound_in_greedy_in,
266  mu_min_in,
267  mu_max_in,
268  discrete_parameter_values_in,
269  log_scaling_in);
270 }
271 
273  unsigned int n_training_samples_in,
274  bool deterministic_training_in,
275  unsigned int training_parameters_random_seed_in,
276  bool quiet_mode_in,
277  unsigned int Nmax_in,
278  Real rel_training_tolerance_in,
279  Real abs_training_tolerance_in,
280  bool normalize_rb_bound_in_greedy_in,
281  RBParameters mu_min_in,
282  RBParameters mu_max_in,
283  std::map<std::string, std::vector<Real>> discrete_parameter_values_in,
284  std::map<std::string,bool> log_scaling_in)
285 {
286  // Read in training_parameters_random_seed value. This is used to
287  // seed the RNG when picking the training parameters. By default the
288  // value is -1, which means use std::time to seed the RNG.
289  set_training_random_seed(training_parameters_random_seed_in);
290 
291  // Set quiet mode
292  set_quiet_mode(quiet_mode_in);
293 
294  // Initialize RB parameters
295  set_Nmax(Nmax_in);
296 
297  set_rel_training_tolerance(rel_training_tolerance_in);
298  set_abs_training_tolerance(abs_training_tolerance_in);
299 
300  set_normalize_rb_bound_in_greedy(normalize_rb_bound_in_greedy_in);
301 
302  // Initialize the parameter ranges and the parameters themselves
303  initialize_parameters(mu_min_in, mu_max_in, discrete_parameter_values_in);
304 
306  this->get_parameters_max(),
307  n_training_samples_in,
308  log_scaling_in,
309  deterministic_training_in); // use deterministic parameters
310 }
311 
313 {
314  // Print out info that describes the current setup
315  libMesh::out << std::endl << "RBConstruction parameters:" << std::endl;
316  libMesh::out << "system name: " << this->name() << std::endl;
317  libMesh::out << "Nmax: " << Nmax << std::endl;
318  libMesh::out << "Greedy relative error tolerance: " << get_rel_training_tolerance() << std::endl;
319  libMesh::out << "Greedy absolute error tolerance: " << get_abs_training_tolerance() << std::endl;
320  libMesh::out << "Do we normalize RB error bound in greedy? " << get_normalize_rb_bound_in_greedy() << std::endl;
322  {
323  libMesh::out << "Aq operators attached: " << get_rb_theta_expansion().get_n_A_terms() << std::endl;
324  libMesh::out << "Fq functions attached: " << get_rb_theta_expansion().get_n_F_terms() << std::endl;
325  libMesh::out << "n_outputs: " << get_rb_theta_expansion().get_n_outputs() << std::endl;
326  for (unsigned int n=0; n<get_rb_theta_expansion().get_n_outputs(); n++)
327  libMesh::out << "output " << n << ", Q_l = " << get_rb_theta_expansion().get_n_output_terms(n) << std::endl;
328  }
329  else
330  {
331  libMesh::out << "RBThetaExpansion member is not set yet" << std::endl;
332  }
333  libMesh::out << "Number of parameters: " << get_n_params() << std::endl;
334  for (const auto & pr : get_parameters())
335  if (!is_discrete_parameter(pr.first))
336  {
337  libMesh::out << "Parameter " << pr.first
338  << ": Min = " << get_parameter_min(pr.first)
339  << ", Max = " << get_parameter_max(pr.first) << std::endl;
340  }
341 
343  libMesh::out << "n_training_samples: " << get_n_training_samples() << std::endl;
344  libMesh::out << "quiet mode? " << is_quiet() << std::endl;
345  libMesh::out << std::endl;
346 }
347 
349 {
350  std::unique_ptr<NumericVector<Number>> temp = solution->clone();
351 
352  for (unsigned int i=0; i<get_rb_evaluation().get_n_basis_functions(); i++)
353  {
354  for (unsigned int j=0; j<get_rb_evaluation().get_n_basis_functions(); j++)
355  {
357  Number value = temp->dot( get_rb_evaluation().get_basis_function(i) );
358 
359  libMesh::out << value << " ";
360  }
361  libMesh::out << std::endl;
362  }
363  libMesh::out << std::endl;
364 }
365 
367 {
368  rb_assembly_expansion = &rb_assembly_expansion_in;
369 }
370 
372 {
374  libmesh_error_msg("Error: RBAssemblyExpansion object hasn't been initialized yet");
375 
376  return *rb_assembly_expansion;
377 }
378 
380 {
381  use_energy_inner_product = false;
382  inner_product_assembly = &inner_product_assembly_in;
383 }
384 
386 {
388  libmesh_error_msg("Error: inner_product_assembly not available since we're using energy inner-product");
389 
391  libmesh_error_msg("Error: inner_product_assembly hasn't been initialized yet");
392 
393  return *inner_product_assembly;
394 }
395 
396 void RBConstruction::set_energy_inner_product(const std::vector<Number> & energy_inner_product_coeffs_in)
397 {
399  energy_inner_product_coeffs = energy_inner_product_coeffs_in;
400 }
401 
403 {
404 #ifdef LIBMESH_ENABLE_CONSTRAINTS
405  const DofMap & dof_map = get_dof_map();
406 
407  for (dof_id_type i=dof_map.first_dof(); i<dof_map.end_dof(); i++)
408  {
410  {
411  vector.set(i, 0.);
412  }
413  }
414 #endif
415 
416  vector.close();
417 }
418 
419 void RBConstruction::initialize_rb_construction(bool skip_matrix_assembly,
420  bool skip_vector_assembly)
421 {
422  if (!skip_matrix_assembly && !skip_vector_assembly)
423  {
424  // Check that the theta and assembly objects are consistently sized
425  libmesh_assert_equal_to (get_rb_theta_expansion().get_n_A_terms(), get_rb_assembly_expansion().get_n_A_terms());
426  libmesh_assert_equal_to (get_rb_theta_expansion().get_n_F_terms(), get_rb_assembly_expansion().get_n_F_terms());
427  libmesh_assert_equal_to (get_rb_theta_expansion().get_n_outputs(), get_rb_assembly_expansion().get_n_outputs());
428  for (unsigned int i=0; i<get_rb_theta_expansion().get_n_outputs(); i++)
429  {
430  libmesh_assert_equal_to (get_rb_theta_expansion().get_n_output_terms(i),
431  get_rb_assembly_expansion().get_n_output_terms(i));
432  }
433  }
434 
435  // Perform the initialization
437  assemble_affine_expansion(skip_matrix_assembly, skip_vector_assembly);
438 
439  // inner_product_solver performs solves with the same matrix every time
440  // hence we can set reuse_preconditioner(true).
441  inner_product_solver->reuse_preconditioner(true);
442 
443  // The primary solver is used for truth solves and other solves that
444  // require different matrices, so set reuse_preconditioner(false).
446 
447 }
448 
449 void RBConstruction::assemble_affine_expansion(bool skip_matrix_assembly,
450  bool skip_vector_assembly)
451 {
452  if (!skip_matrix_assembly)
453  {
454  // Assemble and store all of the matrices
455  this->assemble_misc_matrices();
457  }
458 
459  if (!skip_vector_assembly)
460  {
461  // Assemble and store all of the vectors
464  }
465 }
466 
468 {
469  // Resize vectors for storing mesh-dependent data
470  Aq_vector.resize(get_rb_theta_expansion().get_n_A_terms());
471  Fq_vector.resize(get_rb_theta_expansion().get_n_F_terms());
472 
473  // Resize the Fq_representors and initialize each to nullptr.
474  // These are basis independent and hence stored here, whereas
475  // the Aq_representors are stored in RBEvaluation
476  Fq_representor.resize(get_rb_theta_expansion().get_n_F_terms());
477 
478  // Initialize vectors for the inner products of the Fq representors
479  // These are basis independent and therefore stored here.
480  unsigned int Q_f_hat = get_rb_theta_expansion().get_n_F_terms()*(get_rb_theta_expansion().get_n_F_terms()+1)/2;
481  Fq_representor_innerprods.resize(Q_f_hat);
482 
483  // Resize the output vectors
484  outputs_vector.resize(get_rb_theta_expansion().get_n_outputs());
485  for (unsigned int n=0; n<get_rb_theta_expansion().get_n_outputs(); n++)
487 
488  // Resize the output dual norm vectors
489  output_dual_innerprods.resize(get_rb_theta_expansion().get_n_outputs());
490  for (unsigned int n=0; n<get_rb_theta_expansion().get_n_outputs(); n++)
491  {
493  output_dual_innerprods[n].resize(Q_l_hat);
494  }
495 
496  {
497  DofMap & dof_map = this->get_dof_map();
498 
500  inner_product_matrix->init();
501  inner_product_matrix->zero();
502 
504  {
505  // We also need a non-Dirichlet inner-product matrix
510  }
511 
512  for (unsigned int q=0; q<get_rb_theta_expansion().get_n_A_terms(); q++)
513  {
514  // Initialize the memory for the matrices
516  dof_map.attach_matrix(*Aq_vector[q]);
517  Aq_vector[q]->init();
518  Aq_vector[q]->zero();
519  }
520 
521  // We also need to initialize a second set of non-Dirichlet operators
523  {
524  non_dirichlet_Aq_vector.resize(get_rb_theta_expansion().get_n_A_terms());
525  for (unsigned int q=0; q<get_rb_theta_expansion().get_n_A_terms(); q++)
526  {
527  // Initialize the memory for the matrices
530  non_dirichlet_Aq_vector[q]->init();
531  non_dirichlet_Aq_vector[q]->zero();
532  }
533  }
534  }
535 
536  // Initialize the vectors
537  for (unsigned int q=0; q<get_rb_theta_expansion().get_n_F_terms(); q++)
538  {
539  // Initialize the memory for the vectors
541  Fq_vector[q]->init (this->n_dofs(), this->n_local_dofs(), false, PARALLEL);
542  }
543 
544  // We also need to initialize a second set of non-Dirichlet operators
546  {
547  non_dirichlet_Fq_vector.resize(get_rb_theta_expansion().get_n_F_terms());
548  for (unsigned int q=0; q<get_rb_theta_expansion().get_n_F_terms(); q++)
549  {
550  // Initialize the memory for the vectors
552  non_dirichlet_Fq_vector[q]->init (this->n_dofs(), this->n_local_dofs(), false, PARALLEL);
553  }
554  }
555 
556  for (unsigned int n=0; n<get_rb_theta_expansion().get_n_outputs(); n++)
557  for (unsigned int q_l=0; q_l<get_rb_theta_expansion().get_n_output_terms(n); q_l++)
558  {
559  // Initialize the memory for the truth output vectors
561  outputs_vector[n][q_l]->init (this->n_dofs(), this->n_local_dofs(), false, PARALLEL);
562  }
563 
565  {
566  non_dirichlet_outputs_vector.resize(get_rb_theta_expansion().get_n_outputs());
567  for (unsigned int n=0; n<get_rb_theta_expansion().get_n_outputs(); n++)
568  {
569  non_dirichlet_outputs_vector[n].resize( get_rb_theta_expansion().get_n_output_terms(n) );
570  for (unsigned int q_l=0; q_l<get_rb_theta_expansion().get_n_output_terms(n); q_l++)
571  {
572  // Initialize the memory for the truth output vectors
574  non_dirichlet_outputs_vector[n][q_l]->init (this->n_dofs(), this->n_local_dofs(), false, PARALLEL);
575  }
576  }
577  }
578 
579  // Resize truth_outputs vector
580  truth_outputs.resize(this->get_rb_theta_expansion().get_n_outputs());
581 }
582 
583 std::unique_ptr<DGFEMContext> RBConstruction::build_context ()
584 {
585  return libmesh_make_unique<DGFEMContext>(*this);
586 }
587 
589  ElemAssembly * elem_assembly,
590  SparseMatrix<Number> * input_matrix,
591  NumericVector<Number> * input_vector,
592  bool symmetrize,
593  bool apply_dof_constraints)
594 {
595  LOG_SCOPE("add_scaled_matrix_and_vector()", "RBConstruction");
596 
597  bool assemble_matrix = (input_matrix != nullptr);
598  bool assemble_vector = (input_vector != nullptr);
599 
600  if (!assemble_matrix && !assemble_vector)
601  return;
602 
603  const MeshBase & mesh = this->get_mesh();
604 
605  // First add any node-based terms (e.g. point loads)
606  // We only enter this loop if we have at least one
607  // nodeset, since we use nodesets to indicate
608  // where to impose the node-based terms.
609  if (mesh.get_boundary_info().n_nodeset_conds() > 0)
610  {
611  // build_node_list() returns a vector of (node-id, bc-id) tuples.
612  for (const auto & t : mesh.get_boundary_info().build_node_list())
613  {
614  const Node & node = mesh.node_ref(std::get<0>(t));
615 
616  // If node is on this processor, then all dofs on node are too
617  // so we can do the add below safely
618  if (node.processor_id() == this->comm().rank())
619  {
620  // Get the values to add to the rhs vector
621  std::vector<dof_id_type> nodal_dof_indices;
622  DenseMatrix<Number> nodal_matrix;
623  DenseVector<Number> nodal_rhs;
624  elem_assembly->get_nodal_values(nodal_dof_indices,
625  nodal_matrix,
626  nodal_rhs,
627  *this,
628  node);
629 
630  // Perform any required user-defined postprocessing on
631  // the matrix and rhs.
632  //
633  // TODO: We need to postprocess node matrices and vectors
634  // in some cases (e.g. when rotations are applied to
635  // nodes), but since we don't have a FEMContext at this
636  // point we would need to have a different interface
637  // taking the DenseMatrix, DenseVector, and probably the
638  // current node that we are on...
639  // this->post_process_elem_matrix_and_vector(nodal_matrix, nodal_rhs);
640 
641  if (!nodal_dof_indices.empty())
642  {
643  if (assemble_vector)
644  input_vector->add_vector(nodal_rhs, nodal_dof_indices);
645 
646  if (assemble_matrix)
647  input_matrix->add_matrix(nodal_matrix, nodal_dof_indices);
648  }
649  }
650  }
651  }
652 
653  std::unique_ptr<DGFEMContext> c = this->build_context();
654  DGFEMContext & context = cast_ref<DGFEMContext &>(*c);
655 
656  this->init_context(context);
657 
658  for (const auto & elem : mesh.active_local_element_ptr_range())
659  {
660  // Subdivision elements need special care:
661  // - skip ghost elements
662  // - init special quadrature rule
663  std::unique_ptr<QBase> qrule;
664  if (elem->type() == TRI3SUBDIVISION)
665  {
666  const Tri3Subdivision * gh_elem = static_cast<const Tri3Subdivision *> (elem);
667  if (gh_elem->is_ghost())
668  continue ;
669  // A Gauss quadrature rule for numerical integration.
670  // For subdivision shell elements, a single Gauss point per
671  // element is sufficient, hence we use extraorder = 0.
672  const int extraorder = 0;
673  FEBase * elem_fe = nullptr;
674  context.get_element_fe( 0, elem_fe );
675 
676  qrule = elem_fe->get_fe_type().default_quadrature_rule (2, extraorder);
677 
678  // Tell the finite element object to use our quadrature rule.
679  elem_fe->attach_quadrature_rule (qrule.get());
680  }
681 
682  context.pre_fe_reinit(*this, elem);
683  context.elem_fe_reinit();
684  elem_assembly->interior_assembly(context);
685 
686  const unsigned char n_sides = context.get_elem().n_sides();
687  for (context.side = 0; context.side != n_sides; ++context.side)
688  {
689  // May not need to apply fluxes on non-boundary elements
690  if ((context.get_elem().neighbor_ptr(context.get_side()) != nullptr) && !impose_internal_fluxes)
691  continue;
692 
693  // skip degenerate sides with zero area
694  if( (context.get_elem().side_ptr(context.get_side())->volume() <= 0.) && skip_degenerate_sides)
695  continue;
696 
697  context.side_fe_reinit();
698  elem_assembly->boundary_assembly(context);
699 
700  if (context.dg_terms_are_active())
701  {
702  input_matrix->add_matrix (context.get_elem_elem_jacobian(),
703  context.get_dof_indices(),
704  context.get_dof_indices());
705 
706  input_matrix->add_matrix (context.get_elem_neighbor_jacobian(),
707  context.get_dof_indices(),
708  context.get_neighbor_dof_indices());
709 
710  input_matrix->add_matrix (context.get_neighbor_elem_jacobian(),
711  context.get_neighbor_dof_indices(),
712  context.get_dof_indices());
713 
714  input_matrix->add_matrix (context.get_neighbor_neighbor_jacobian(),
715  context.get_neighbor_dof_indices(),
716  context.get_neighbor_dof_indices());
717  }
718  }
719 
720  // Do any required user post-processing before symmetrizing
721  // and/or applying constraints. Only do the post processing
722  // if we are applying the dof constraints.
723  if (apply_dof_constraints)
725 
726  // Need to symmetrize before imposing
727  // periodic constraints
728  if (assemble_matrix && symmetrize)
729  {
730  DenseMatrix<Number> Ke_transpose;
731  context.get_elem_jacobian().get_transpose(Ke_transpose);
732  context.get_elem_jacobian() += Ke_transpose;
733  context.get_elem_jacobian() *= 0.5;
734  }
735 
736  if (apply_dof_constraints)
737  {
738  // Apply constraints, e.g. Dirichlet and periodic constraints
740  (context.get_elem_jacobian(),
741  context.get_elem_residual(),
742  context.get_dof_indices(),
743  /*asymmetric_constraint_rows*/ false );
744  }
745 
746  // Scale and add to global matrix and/or vector
747  context.get_elem_jacobian() *= scalar;
748  context.get_elem_residual() *= scalar;
749 
750  if (assemble_matrix)
751  {
752 
753  CouplingMatrix * coupling_matrix = get_dof_map()._dof_coupling;
754  if (!coupling_matrix)
755  {
756  // If we haven't defined a _dof_coupling matrix then just add
757  // the whole matrix
758  input_matrix->add_matrix (context.get_elem_jacobian(),
759  context.get_dof_indices() );
760  }
761  else
762  {
763  // Otherwise we should only add the relevant submatrices
764  for (unsigned int var1=0; var1<n_vars(); var1++)
765  {
766  ConstCouplingRow ccr(var1, *coupling_matrix);
767  for (const auto & var2 : ccr)
768  {
769  unsigned int sub_m = context.get_elem_jacobian( var1, var2 ).m();
770  unsigned int sub_n = context.get_elem_jacobian( var1, var2 ).n();
771  DenseMatrix<Number> sub_jac(sub_m, sub_n);
772  for (unsigned int row=0; row<sub_m; row++)
773  for (unsigned int col=0; col<sub_n; col++)
774  {
775  sub_jac(row,col) = context.get_elem_jacobian( var1, var2 ).el(row,col);
776  }
777  input_matrix->add_matrix (sub_jac,
778  context.get_dof_indices(var1),
779  context.get_dof_indices(var2) );
780  }
781  }
782  }
783 
784  }
785 
786  if (assemble_vector)
787  input_vector->add_vector (context.get_elem_residual(),
788  context.get_dof_indices() );
789  }
790 
791  if (assemble_matrix)
792  input_matrix->close();
793  if (assemble_vector)
794  input_vector->close();
795 }
796 
798 {
799  // Set current_local_solution = vec so that we can access
800  // vec from DGFEMContext during assembly
801  vec.localize
802  (*current_local_solution, this->get_dof_map().get_send_list());
803 }
804 
806 {
807  LOG_SCOPE("truth_assembly()", "RBConstruction");
808 
809  const RBParameters & mu = get_parameters();
810 
811  this->matrix->zero();
812  this->rhs->zero();
813 
814  this->matrix->close();
815  this->rhs->close();
816 
817  {
818  // We should have already assembled the matrices
819  // and vectors in the affine expansion, so
820  // just use them
821 
822  for (unsigned int q_a=0; q_a<get_rb_theta_expansion().get_n_A_terms(); q_a++)
823  {
824  matrix->add(get_rb_theta_expansion().eval_A_theta(q_a, mu), *get_Aq(q_a));
825  }
826 
827  std::unique_ptr<NumericVector<Number>> temp_vec = NumericVector<Number>::build(this->comm());
828  temp_vec->init (this->n_dofs(), this->n_local_dofs(), false, PARALLEL);
829  for (unsigned int q_f=0; q_f<get_rb_theta_expansion().get_n_F_terms(); q_f++)
830  {
831  *temp_vec = *get_Fq(q_f);
832  temp_vec->scale( get_rb_theta_expansion().eval_F_theta(q_f, mu) );
833  rhs->add(*temp_vec);
834  }
835  }
836 
837  this->matrix->close();
838  this->rhs->close();
839 }
840 
842  bool apply_dof_constraints)
843 {
844  input_matrix->zero();
845 
847  {
850  input_matrix,
851  nullptr,
852  false, /* symmetrize */
853  apply_dof_constraints);
854  }
855  else
856  {
858  {
859  libmesh_error_msg("Error: invalid number of entries in energy_inner_product_coeffs.");
860  }
861 
862  // We symmetrize below so that we may use the energy inner-product even in cases
863  // where the A_q are not symmetric.
864  for (unsigned int q_a=0; q_a<get_rb_theta_expansion().get_n_A_terms(); q_a++)
865  {
868  input_matrix,
869  nullptr,
870  true, /* symmetrize */
871  apply_dof_constraints);
872  }
873  }
874 }
875 
877  SparseMatrix<Number> * input_matrix,
878  bool apply_dof_constraints)
879 {
880  if (q >= get_rb_theta_expansion().get_n_A_terms())
881  libmesh_error_msg("Error: We must have q < Q_a in assemble_Aq_matrix.");
882 
883  input_matrix->zero();
884 
887  input_matrix,
888  nullptr,
889  false, /* symmetrize */
890  apply_dof_constraints);
891 }
892 
894  unsigned int q_a,
895  SparseMatrix<Number> * input_matrix,
896  bool symmetrize)
897 {
898  LOG_SCOPE("add_scaled_Aq()", "RBConstruction");
899 
900  if (q_a >= get_rb_theta_expansion().get_n_A_terms())
901  libmesh_error_msg("Error: We must have q < Q_a in add_scaled_Aq.");
902 
903  if (!symmetrize)
904  {
905  input_matrix->add(scalar, *get_Aq(q_a));
906  input_matrix->close();
907  }
908  else
909  {
912  input_matrix,
913  nullptr,
914  symmetrize);
915  }
916 }
917 
919 {
920  libMesh::out << "Assembling inner product matrix" << std::endl;
922 
924  {
925  libMesh::out << "Assembling non-Dirichlet inner product matrix" << std::endl;
927  }
928 }
929 
931 {
932  for (unsigned int q_a=0; q_a<get_rb_theta_expansion().get_n_A_terms(); q_a++)
933  {
934  libMesh::out << "Assembling affine operator " << (q_a+1) << " of "
935  << get_rb_theta_expansion().get_n_A_terms() << std::endl;
936  assemble_Aq_matrix(q_a, get_Aq(q_a));
937  }
938 
940  {
941  for (unsigned int q_a=0; q_a<get_rb_theta_expansion().get_n_A_terms(); q_a++)
942  {
943  libMesh::out << "Assembling non-Dirichlet affine operator " << (q_a+1) << " of "
944  << get_rb_theta_expansion().get_n_A_terms() << std::endl;
945  assemble_Aq_matrix(q_a, get_non_dirichlet_Aq(q_a), false);
946  }
947  }
948 }
949 
951 {
952  for (unsigned int q_f=0; q_f<get_rb_theta_expansion().get_n_F_terms(); q_f++)
953  {
954  libMesh::out << "Assembling affine vector " << (q_f+1) << " of "
955  << get_rb_theta_expansion().get_n_F_terms() << std::endl;
956  assemble_Fq_vector(q_f, get_Fq(q_f));
957  }
958 
960  {
961  for (unsigned int q_f=0; q_f<get_rb_theta_expansion().get_n_F_terms(); q_f++)
962  {
963  libMesh::out << "Assembling non-Dirichlet affine vector " << (q_f+1) << " of "
964  << get_rb_theta_expansion().get_n_F_terms() << std::endl;
965  assemble_Fq_vector(q_f, get_non_dirichlet_Fq(q_f), false);
966  }
967  }
968 
969 }
970 
972  NumericVector<Number> * input_vector,
973  bool apply_dof_constraints)
974 {
975  if (q >= get_rb_theta_expansion().get_n_F_terms())
976  libmesh_error_msg("Error: We must have q < Q_f in assemble_Fq_vector.");
977 
978  input_vector->zero();
979 
982  nullptr,
983  input_vector,
984  false, /* symmetrize */
985  apply_dof_constraints /* apply_dof_constraints */);
986 }
987 
989 {
990  for (unsigned int n=0; n<get_rb_theta_expansion().get_n_outputs(); n++)
991  for (unsigned int q_l=0; q_l<get_rb_theta_expansion().get_n_output_terms(n); q_l++)
992  {
993  libMesh::out << "Assembling output vector, (" << (n+1) << "," << (q_l+1)
994  << ") of (" << get_rb_theta_expansion().get_n_outputs()
995  << "," << get_rb_theta_expansion().get_n_output_terms(n) << ")"
996  << std::endl;
997  get_output_vector(n, q_l)->zero();
999  nullptr,
1000  get_output_vector(n,q_l),
1001  false, /* symmetrize */
1002  true /* apply_dof_constraints */);
1003  }
1004 
1006  {
1007  for (unsigned int n=0; n<get_rb_theta_expansion().get_n_outputs(); n++)
1008  for (unsigned int q_l=0; q_l<get_rb_theta_expansion().get_n_output_terms(n); q_l++)
1009  {
1010  libMesh::out << "Assembling non-Dirichlet output vector, (" << (n+1) << "," << (q_l+1)
1011  << ") of (" << get_rb_theta_expansion().get_n_outputs()
1012  << "," << get_rb_theta_expansion().get_n_output_terms(n) << ")"
1013  << std::endl;
1016  nullptr,
1018  false, /* symmetrize */
1019  false /* apply_dof_constraints */);
1020  }
1021  }
1022 }
1023 
1024 Real RBConstruction::train_reduced_basis(const bool resize_rb_eval_data)
1025 {
1026  LOG_SCOPE("train_reduced_basis()", "RBConstruction");
1027 
1028  int count = 0;
1029 
1030  RBEvaluation & rbe = get_rb_evaluation();
1031 
1032  // initialize rbe's parameters
1033  rbe.initialize_parameters(*this);
1034 
1035  // possibly resize data structures according to Nmax
1036  if (resize_rb_eval_data)
1038 
1039  // Clear the Greedy param list
1040  for (auto & plist : rbe.greedy_param_list)
1041  plist.clear();
1042 
1043  rbe.greedy_param_list.clear();
1044 
1045  Real training_greedy_error = 0.;
1046 
1047 
1048  // If we are continuing from a previous training run,
1049  // we might already be at the max number of basis functions.
1050  // If so, we can just return.
1051  if (rbe.get_n_basis_functions() >= get_Nmax())
1052  {
1053  libMesh::out << "Maximum number of basis functions reached: Nmax = "
1054  << get_Nmax() << std::endl;
1055  return 0.;
1056  }
1057 
1058 
1060  {
1061  // Compute the dual norms of the outputs if we haven't already done so.
1063 
1064  // Compute the Fq Riesz representor dual norms if we haven't already done so.
1066  }
1067 
1068  libMesh::out << std::endl << "---- Performing Greedy basis enrichment ----" << std::endl;
1069  Real initial_greedy_error = 0.;
1070  bool initial_greedy_error_initialized = false;
1071  while (true)
1072  {
1073  libMesh::out << std::endl << "---- Basis dimension: "
1074  << rbe.get_n_basis_functions() << " ----" << std::endl;
1075 
1076  if (count > 0 || (count==0 && use_empty_rb_solve_in_greedy))
1077  {
1078  libMesh::out << "Performing RB solves on training set" << std::endl;
1079  training_greedy_error = compute_max_error_bound();
1080 
1081  libMesh::out << "Maximum error bound is " << training_greedy_error << std::endl << std::endl;
1082 
1083  // record the initial error
1084  if (!initial_greedy_error_initialized)
1085  {
1086  initial_greedy_error = training_greedy_error;
1087  initial_greedy_error_initialized = true;
1088  }
1089 
1090  // Break out of training phase if we have reached Nmax
1091  // or if the training_tolerance is satisfied.
1092  if (greedy_termination_test(training_greedy_error, initial_greedy_error, count))
1093  break;
1094  }
1095 
1096  libMesh::out << "Performing truth solve at parameter:" << std::endl;
1097  print_parameters();
1098 
1099  // Update the list of Greedily selected parameters
1100  this->update_greedy_param_list();
1101 
1102  // Perform an Offline truth solve for the current parameter
1103  truth_solve(-1);
1104 
1105  // Add orthogonal part of the snapshot to the RB space
1106  libMesh::out << "Enriching the RB space" << std::endl;
1107  enrich_RB_space();
1108 
1109  update_system();
1110 
1111  // Check if we've reached Nmax now. We do this before calling
1112  // update_residual_terms() since we can skip that step if we've
1113  // already reached Nmax.
1114  if (rbe.get_n_basis_functions() >= this->get_Nmax())
1115  {
1116  libMesh::out << "Maximum number of basis functions reached: Nmax = "
1117  << get_Nmax() << std::endl;
1118  break;
1119  }
1120 
1122  {
1124  }
1125 
1126  // Increment counter
1127  count++;
1128  }
1129  this->update_greedy_param_list();
1130 
1131  return training_greedy_error;
1132 }
1133 
1134 void RBConstruction::enrich_basis_from_rhs_terms(const bool resize_rb_eval_data)
1135 {
1136  LOG_SCOPE("enrich_basis_from_rhs_terms()", "RBConstruction");
1137 
1138  // initialize rb_eval's parameters
1140 
1141  // possibly resize data structures according to Nmax
1142  if (resize_rb_eval_data)
1143  {
1145  }
1146 
1147  libMesh::out << std::endl << "---- Enriching basis from rhs terms ----" << std::endl;
1148 
1149  truth_assembly();
1150 
1151  for (unsigned int q_f=0; q_f<get_rb_theta_expansion().get_n_F_terms(); q_f++)
1152  {
1153  libMesh::out << std::endl << "Performing truth solve with rhs from rhs term " << q_f << std::endl;
1154 
1155  *rhs = *get_Fq(q_f);
1156 
1157  if (rhs->l2_norm() == 0)
1158  {
1159  // Skip enrichment if the rhs is zero
1160  continue;
1161  }
1162 
1163  // truth_assembly assembles into matrix and rhs, so use those for the solve
1164  if (extra_linear_solver)
1165  {
1166  // If extra_linear_solver has been initialized, then we use it for the
1167  // truth solves.
1169 
1170  if (assert_convergence)
1172  }
1173  else
1174  {
1176 
1177  if (assert_convergence)
1179  }
1180 
1181  // Call user-defined post-processing routines on the truth solution.
1183 
1184  // Add orthogonal part of the snapshot to the RB space
1185  libMesh::out << "Enriching the RB space" << std::endl;
1186  enrich_RB_space();
1187 
1188  update_system();
1189  }
1190 }
1191 
1193  Real initial_error,
1194  int)
1195 {
1196  if (abs_greedy_error < this->abs_training_tolerance)
1197  {
1198  libMesh::out << "Absolute error tolerance reached." << std::endl;
1199  return true;
1200  }
1201 
1202  Real rel_greedy_error = abs_greedy_error/initial_error;
1203  if (rel_greedy_error < this->rel_training_tolerance)
1204  {
1205  libMesh::out << "Relative error tolerance reached." << std::endl;
1206  return true;
1207  }
1208 
1209  RBEvaluation & rbe = get_rb_evaluation();
1210 
1211  if (rbe.get_n_basis_functions() >= this->get_Nmax())
1212  {
1213  libMesh::out << "Maximum number of basis functions reached: Nmax = "
1214  << get_Nmax() << std::endl;
1215  return true;
1216  }
1217 
1219  for (auto & plist : rbe.greedy_param_list)
1220  if (plist == get_parameters())
1221  {
1222  libMesh::out << "Exiting greedy because the same parameters were selected twice" << std::endl;
1223  return true;
1224  }
1225 
1226  return false;
1227 }
1228 
1230 {
1232 }
1233 
1235 {
1236  if (i >= get_rb_evaluation().greedy_param_list.size())
1237  libmesh_error_msg("Error: Argument in RBConstruction::get_greedy_parameter is too large.");
1238 
1240 }
1241 
1243 {
1244  LOG_SCOPE("truth_solve()", "RBConstruction");
1245 
1246  truth_assembly();
1247 
1248  // truth_assembly assembles into matrix and rhs, so use those for the solve
1249  if (extra_linear_solver)
1250  {
1251  // If extra_linear_solver has been initialized, then we use it for the
1252  // truth solves.
1254 
1255  if (assert_convergence)
1257  }
1258  else
1259  {
1261 
1262  if (assert_convergence)
1264  }
1265 
1266  // Call user-defined post-processing routines on the truth solution.
1268 
1269  const RBParameters & mu = get_parameters();
1270 
1271  for (unsigned int n=0; n<get_rb_theta_expansion().get_n_outputs(); n++)
1272  {
1273  truth_outputs[n] = 0.;
1274  for (unsigned int q_l=0; q_l<get_rb_theta_expansion().get_n_output_terms(n); q_l++)
1276  get_output_vector(n,q_l)->dot(*solution);
1277  }
1278 
1279  if (plot_solution > 0)
1280  {
1281 #if defined(LIBMESH_USE_COMPLEX_NUMBERS)
1282  GMVIO(get_mesh()).write_equation_systems ("truth.gmv",
1283  this->get_equation_systems());
1284 #else
1285 #ifdef LIBMESH_HAVE_EXODUS_API
1287  this->get_equation_systems());
1288 #endif
1289 #endif
1290  }
1291 
1292  // Get the X norm of the truth solution
1293  // Useful for normalizing our true error data
1295  Number truth_X_norm = std::sqrt(inner_product_storage_vector->dot(*solution));
1296 
1297  return libmesh_real(truth_X_norm);
1298 }
1299 
1300 void RBConstruction::set_Nmax(unsigned int Nmax_in)
1301 {
1302  this->Nmax = Nmax_in;
1303 }
1304 
1306 {
1307  LOG_SCOPE("load_basis_function()", "RBConstruction");
1308 
1309  libmesh_assert_less (i, get_rb_evaluation().get_n_basis_functions());
1310 
1312 
1313  this->update();
1314 }
1315 
1317 {
1318  LOG_SCOPE("enrich_RB_space()", "RBConstruction");
1319 
1320  auto new_bf = NumericVector<Number>::build(this->comm());
1321  new_bf->init (this->n_dofs(), this->n_local_dofs(), false, PARALLEL);
1322  *new_bf = *solution;
1323 
1324  for (unsigned int index=0; index<get_rb_evaluation().get_n_basis_functions(); index++)
1325  {
1327 
1328  Number scalar =
1329  inner_product_storage_vector->dot(get_rb_evaluation().get_basis_function(index));
1330  new_bf->add(-scalar, get_rb_evaluation().get_basis_function(index));
1331  }
1332 
1333  // Normalize new_bf
1335  Number new_bf_norm = std::sqrt( inner_product_storage_vector->dot(*new_bf) );
1336 
1337  if (new_bf_norm == 0.)
1338  {
1339  new_bf->zero(); // avoid potential nan's
1340  }
1341  else
1342  {
1343  new_bf->scale(1./new_bf_norm);
1344  }
1345 
1346  // load the new basis function into the basis_functions vector.
1347  get_rb_evaluation().basis_functions.emplace_back( std::move(new_bf) );
1348 }
1349 
1351 {
1352  libMesh::out << "Updating RB matrices" << std::endl;
1354 }
1355 
1357 {
1359 
1360  Real error_bound = get_rb_evaluation().rb_solve(get_rb_evaluation().get_n_basis_functions());
1361 
1363  {
1364  Real error_bound_normalization = get_rb_evaluation().get_error_bound_normalization();
1365 
1366  if ((error_bound < abs_training_tolerance) ||
1367  (error_bound_normalization < abs_training_tolerance))
1368  {
1369  // We don't want to normalize this error bound if the bound or the
1370  // normalization value are below the absolute tolerance. Hence do nothing
1371  // in this case.
1372  }
1373  else
1374  error_bound /= error_bound_normalization;
1375  }
1376 
1377  return error_bound;
1378 }
1379 
1380 void RBConstruction::recompute_all_residual_terms(bool compute_inner_products)
1381 {
1382  // Compute the basis independent terms
1384  compute_Fq_representor_innerprods(compute_inner_products);
1385 
1386  // and all the basis dependent terms
1387  unsigned int saved_delta_N = delta_N;
1389 
1390  update_residual_terms(compute_inner_products);
1391 
1392  delta_N = saved_delta_N;
1393 }
1394 
1396 {
1397  LOG_SCOPE("compute_max_error_bound()", "RBConstruction");
1398 
1399  // Treat the case with no parameters in a special way
1400  if (get_n_params() == 0)
1401  {
1402  Real max_val;
1403  if (std::numeric_limits<Real>::has_infinity)
1404  {
1405  max_val = std::numeric_limits<Real>::infinity();
1406  }
1407  else
1408  {
1409  max_val = std::numeric_limits<Real>::max();
1410  }
1411 
1412  // Make sure we do at least one solve, but otherwise return a zero error bound
1413  // when we have no parameters
1414  return (get_rb_evaluation().get_n_basis_functions() == 0) ? max_val : 0.;
1415  }
1416 
1418 
1419  // keep track of the maximum error
1420  unsigned int max_err_index = 0;
1421  Real max_err = 0.;
1422 
1424  for (unsigned int i=0; i<get_local_n_training_samples(); i++)
1425  {
1426  // Load training parameter i, this is only loaded
1427  // locally since the RB solves are local.
1428  set_params_from_training_set( first_index+i );
1429 
1431 
1432  if (training_error_bounds[i] > max_err)
1433  {
1434  max_err_index = i;
1435  max_err = training_error_bounds[i];
1436  }
1437  }
1438 
1439  std::pair<numeric_index_type, Real> error_pair(first_index+max_err_index, max_err);
1440  get_global_max_error_pair(this->comm(),error_pair);
1441 
1442  // If we have a serial training set (i.e. a training set that is the same on all processors)
1443  // just set the parameters on all processors
1444  if (serial_training_set)
1445  {
1446  set_params_from_training_set( error_pair.first );
1447  }
1448  // otherwise, broadcast the parameter that produced the maximum error
1449  else
1450  {
1451  unsigned int root_id=0;
1452  if ((get_first_local_training_index() <= error_pair.first) &&
1453  (error_pair.first < get_last_local_training_index()))
1454  {
1455  set_params_from_training_set( error_pair.first );
1456  root_id = this->processor_id();
1457  }
1458 
1459  this->comm().sum(root_id); // root_id is only non-zero on one processor
1460  broadcast_parameters(root_id);
1461  }
1462 
1463  return error_pair.second;
1464 }
1465 
1467 {
1468  LOG_SCOPE("update_RB_system_matrices()", "RBConstruction");
1469 
1470  unsigned int RB_size = get_rb_evaluation().get_n_basis_functions();
1471 
1472  std::unique_ptr<NumericVector<Number>> temp = NumericVector<Number>::build(this->comm());
1473  temp->init (this->n_dofs(), this->n_local_dofs(), false, PARALLEL);
1474 
1475  for (unsigned int q_f=0; q_f<get_rb_theta_expansion().get_n_F_terms(); q_f++)
1476  {
1477  for (unsigned int i=(RB_size-delta_N); i<RB_size; i++)
1478  {
1479  get_rb_evaluation().RB_Fq_vector[q_f](i) = get_non_dirichlet_Fq_if_avail(q_f)->dot(get_rb_evaluation().get_basis_function(i));
1480  }
1481  }
1482 
1483  for (unsigned int i=(RB_size-delta_N); i<RB_size; i++)
1484  {
1485  for (unsigned int n=0; n<get_rb_theta_expansion().get_n_outputs(); n++)
1486  for (unsigned int q_l=0; q_l<get_rb_theta_expansion().get_n_output_terms(n); q_l++)
1487  {
1488  get_rb_evaluation().RB_output_vectors[n][q_l](i) =
1489  get_output_vector(n,q_l)->dot(get_rb_evaluation().get_basis_function(i));
1490  }
1491 
1492  for (unsigned int j=0; j<RB_size; j++)
1493  {
1494  Number value = 0.;
1495 
1497  {
1498  // Compute reduced inner_product_matrix
1499  temp->zero();
1501 
1502  value = temp->dot( get_rb_evaluation().get_basis_function(i) );
1504  if (i!=j)
1505  {
1506  // The inner product matrix is assumed
1507  // to be hermitian
1509  }
1510  }
1511 
1512  for (unsigned int q_a=0; q_a<get_rb_theta_expansion().get_n_A_terms(); q_a++)
1513  {
1514  // Compute reduced Aq matrix
1515  temp->zero();
1516  get_non_dirichlet_Aq_if_avail(q_a)->vector_mult(*temp, get_rb_evaluation().get_basis_function(j));
1517 
1518  value = (*temp).dot(get_rb_evaluation().get_basis_function(i));
1519  get_rb_evaluation().RB_Aq_vector[q_a](i,j) = value;
1520 
1521  if (i!=j)
1522  {
1523  temp->zero();
1524  get_non_dirichlet_Aq_if_avail(q_a)->vector_mult(*temp, get_rb_evaluation().get_basis_function(i));
1525 
1526  value = (*temp).dot(get_rb_evaluation().get_basis_function(j));
1527  get_rb_evaluation().RB_Aq_vector[q_a](j,i) = value;
1528  }
1529  }
1530  }
1531  }
1532 }
1533 
1534 
1535 void RBConstruction::update_residual_terms(bool compute_inner_products)
1536 {
1537  LOG_SCOPE("update_residual_terms()", "RBConstruction");
1538 
1539  libMesh::out << "Updating RB residual terms" << std::endl;
1540 
1541  unsigned int RB_size = get_rb_evaluation().get_n_basis_functions();
1542 
1543  for (unsigned int q_a=0; q_a<get_rb_theta_expansion().get_n_A_terms(); q_a++)
1544  {
1545  for (unsigned int i=(RB_size-delta_N); i<RB_size; i++)
1546  {
1547  // Initialize the vector in which we'll store the representor
1548  if (!get_rb_evaluation().Aq_representor[q_a][i])
1549  {
1551  get_rb_evaluation().Aq_representor[q_a][i]->init(this->n_dofs(), this->n_local_dofs(), false, PARALLEL);
1552  }
1553 
1554  libmesh_assert(get_rb_evaluation().Aq_representor[q_a][i]->size() == this->n_dofs() &&
1555  get_rb_evaluation().Aq_representor[q_a][i]->local_size() == this->n_local_dofs() );
1556 
1557  rhs->zero();
1558  get_Aq(q_a)->vector_mult(*rhs, get_rb_evaluation().get_basis_function(i));
1559  rhs->scale(-1.);
1560 
1561  if (!is_quiet())
1562  {
1563  libMesh::out << "Starting solve [q_a][i]=[" << q_a <<"]["<< i << "] in RBConstruction::update_residual_terms() at "
1564  << Utility::get_timestamp() << std::endl;
1565  }
1566 
1568 
1569  if (assert_convergence)
1571 
1572  if (!is_quiet())
1573  {
1574  libMesh::out << "Finished solve [q_a][i]=[" << q_a <<"]["<< i << "] in RBConstruction::update_residual_terms() at "
1575  << Utility::get_timestamp() << std::endl;
1576  libMesh::out << this->n_linear_iterations() << " iterations, final residual "
1577  << this->final_linear_residual() << std::endl;
1578  }
1579 
1580  // Store the representor
1582  }
1583  }
1584 
1585  // Now compute and store the inner products (if requested)
1586  if (compute_inner_products)
1587  {
1588 
1589  for (unsigned int q_f=0; q_f<get_rb_theta_expansion().get_n_F_terms(); q_f++)
1590  {
1592 
1593  for (unsigned int q_a=0; q_a<get_rb_theta_expansion().get_n_A_terms(); q_a++)
1594  {
1595  for (unsigned int i=(RB_size-delta_N); i<RB_size; i++)
1596  {
1598  inner_product_storage_vector->dot(*get_rb_evaluation().Aq_representor[q_a][i]);
1599  }
1600  }
1601  }
1602 
1603  unsigned int q=0;
1604  for (unsigned int q_a1=0; q_a1<get_rb_theta_expansion().get_n_A_terms(); q_a1++)
1605  {
1606  for (unsigned int q_a2=q_a1; q_a2<get_rb_theta_expansion().get_n_A_terms(); q_a2++)
1607  {
1608  for (unsigned int i=(RB_size-delta_N); i<RB_size; i++)
1609  {
1610  for (unsigned int j=0; j<RB_size; j++)
1611  {
1614  inner_product_storage_vector->dot(*get_rb_evaluation().Aq_representor[q_a1][i]);
1615 
1616  if (i != j)
1617  {
1620  inner_product_storage_vector->dot(*get_rb_evaluation().Aq_representor[q_a1][j]);
1621  }
1622  }
1623  }
1624  q++;
1625  }
1626  }
1627  } // end if (compute_inner_products)
1628 }
1629 
1631 {
1632  return *inner_product_matrix;
1633 }
1634 
1636 {
1637  // Skip calculations if we've already computed the output dual norms
1639  {
1640  // Short circuit if we don't have any outputs
1641  if (get_rb_theta_expansion().get_n_outputs() == 0)
1642  {
1644  return;
1645  }
1646 
1647  // Only log if we get to here
1648  LOG_SCOPE("compute_output_dual_innerprods()", "RBConstruction");
1649 
1650  libMesh::out << "Compute output dual inner products" << std::endl;
1651 
1652  // Find out the largest value of Q_l
1653  unsigned int max_Q_l = 0;
1654  for (unsigned int n=0; n<get_rb_theta_expansion().get_n_outputs(); n++)
1655  max_Q_l = (get_rb_theta_expansion().get_n_output_terms(n) > max_Q_l) ? get_rb_theta_expansion().get_n_output_terms(n) : max_Q_l;
1656 
1657  std::vector<std::unique_ptr<NumericVector<Number>>> L_q_representor(max_Q_l);
1658  for (unsigned int q=0; q<max_Q_l; q++)
1659  {
1660  L_q_representor[q] = NumericVector<Number>::build(this->comm());
1661  L_q_representor[q]->init (this->n_dofs(), this->n_local_dofs(), false, PARALLEL);
1662  }
1663 
1664  for (unsigned int n=0; n<get_rb_theta_expansion().get_n_outputs(); n++)
1665  {
1666  for (unsigned int q_l=0; q_l<get_rb_theta_expansion().get_n_output_terms(n); q_l++)
1667  {
1668  rhs->zero();
1669  rhs->add(1., *get_output_vector(n,q_l));
1670 
1671  if (!is_quiet())
1672  libMesh::out << "Starting solve n=" << n << ", q_l=" << q_l
1673  << " in RBConstruction::compute_output_dual_innerprods() at "
1674  << Utility::get_timestamp() << std::endl;
1675 
1676  // Use the main linear solver here instead of the inner_product solver, since
1677  // get_matrix_for_output_dual_solves() may not return the inner product matrix.
1679 
1680  // We possibly perform multiple solves here with the same matrix, hence
1681  // set reuse_preconditioner(true) (and set it back to false again below
1682  // at the end of this function).
1683  linear_solver->reuse_preconditioner(true);
1684 
1685  if (assert_convergence)
1687 
1688  if (!is_quiet())
1689  {
1690  libMesh::out << "Finished solve n=" << n << ", q_l=" << q_l
1691  << " in RBConstruction::compute_output_dual_innerprods() at "
1692  << Utility::get_timestamp() << std::endl;
1693 
1695  << " iterations, final residual "
1696  << this->final_linear_residual() << std::endl;
1697  }
1698 
1699  *L_q_representor[q_l] = *solution;
1700  }
1701 
1702  unsigned int q=0;
1703  for (unsigned int q_l1=0; q_l1<get_rb_theta_expansion().get_n_output_terms(n); q_l1++)
1704  {
1706 
1707  for (unsigned int q_l2=q_l1; q_l2<get_rb_theta_expansion().get_n_output_terms(n); q_l2++)
1708  {
1709  output_dual_innerprods[n][q] = L_q_representor[q_l2]->dot(*inner_product_storage_vector);
1710  libMesh::out << "output_dual_innerprods[" << n << "][" << q << "] = " << output_dual_innerprods[n][q] << std::endl;
1711 
1712  q++;
1713  }
1714  }
1715  }
1716 
1717  // We may not need to use linear_solver again (e.g. this would happen if we use
1718  // extra_linear_solver for the truth_solves). As a result, let's clear linear_solver
1719  // to release any memory it may be taking up. If we do need it again, it will
1720  // be initialized when necessary.
1721  linear_solver->clear();
1722  linear_solver->reuse_preconditioner(false);
1723 
1725  }
1726 
1728 }
1729 
1730 void RBConstruction::compute_Fq_representor_innerprods(bool compute_inner_products)
1731 {
1732 
1733  // Skip calculations if we've already computed the Fq_representors
1735  {
1736  // Only log if we get to here
1737  LOG_SCOPE("compute_Fq_representor_innerprods()", "RBConstruction");
1738 
1739  for (unsigned int q_f=0; q_f<get_rb_theta_expansion().get_n_F_terms(); q_f++)
1740  {
1741  if (!Fq_representor[q_f])
1742  {
1744  Fq_representor[q_f]->init (this->n_dofs(), this->n_local_dofs(), false, PARALLEL);
1745  }
1746 
1747  libmesh_assert(Fq_representor[q_f]->size() == this->n_dofs() &&
1748  Fq_representor[q_f]->local_size() == this->n_local_dofs() );
1749 
1750  rhs->zero();
1751  rhs->add(1., *get_Fq(q_f));
1752 
1753  if (!is_quiet())
1754  libMesh::out << "Starting solve q_f=" << q_f
1755  << " in RBConstruction::update_residual_terms() at "
1756  << Utility::get_timestamp() << std::endl;
1757 
1759 
1760  if (assert_convergence)
1762 
1763  if (!is_quiet())
1764  {
1765  libMesh::out << "Finished solve q_f=" << q_f
1766  << " in RBConstruction::update_residual_terms() at "
1767  << Utility::get_timestamp() << std::endl;
1768 
1770  << " iterations, final residual "
1771  << this->final_linear_residual() << std::endl;
1772  }
1773 
1774  *Fq_representor[q_f] = *solution;
1775  }
1776 
1777  if (compute_inner_products)
1778  {
1779  unsigned int q=0;
1780 
1781  for (unsigned int q_f1=0; q_f1<get_rb_theta_expansion().get_n_F_terms(); q_f1++)
1782  {
1784 
1785  for (unsigned int q_f2=q_f1; q_f2<get_rb_theta_expansion().get_n_F_terms(); q_f2++)
1786  {
1788 
1789  q++;
1790  }
1791  }
1792  } // end if (compute_inner_products)
1793 
1795  }
1796 
1798 }
1799 
1801 {
1802  LOG_SCOPE("load_rb_solution()", "RBConstruction");
1803 
1804  solution->zero();
1805 
1806  if (get_rb_evaluation().RB_solution.size() > get_rb_evaluation().get_n_basis_functions())
1807  libmesh_error_msg("ERROR: System contains " << get_rb_evaluation().get_n_basis_functions() << " basis functions." \
1808  << " RB_solution vector constains " << get_rb_evaluation().RB_solution.size() << " entries." \
1809  << " RB_solution in RBConstruction::load_rb_solution is too long!");
1810 
1811  for (auto i : IntRange<unsigned int>(0, get_rb_evaluation().RB_solution.size()))
1812  solution->add(get_rb_evaluation().RB_solution(i), get_rb_evaluation().get_basis_function(i));
1813 
1814  update();
1815 }
1816 
1817 // The slow (but simple, non-error prone) way to compute the residual dual norm
1818 // Useful for error checking
1820 {
1821  LOG_SCOPE("compute_residual_dual_norm_slow()", "RBConstruction");
1822 
1823  // Put the residual in rhs in order to compute the norm of the Riesz representor
1824  // Note that this only works in serial since otherwise each processor will
1825  // have a different parameter value during the Greedy training.
1826 
1827  std::unique_ptr<NumericVector<Number>> RB_sol = NumericVector<Number>::build(comm());
1828  RB_sol->init (this->n_dofs(), this->n_local_dofs(), false, PARALLEL);
1829 
1830  std::unique_ptr<NumericVector<Number>> temp = NumericVector<Number>::build(comm());
1831  temp->init (this->n_dofs(), this->n_local_dofs(), false, PARALLEL);
1832 
1833  for (unsigned int i=0; i<N; i++)
1834  {
1835  RB_sol->add(get_rb_evaluation().RB_solution(i), get_rb_evaluation().get_basis_function(i));
1836  }
1837 
1838  this->truth_assembly();
1839  matrix->vector_mult(*temp, *RB_sol);
1840  rhs->add(-1., *temp);
1841 
1842  // Then solve to get the Reisz representor
1843  matrix->zero();
1845 
1848  Number slow_residual_norm_sq = solution->dot(*inner_product_storage_vector);
1849 
1850  return std::sqrt( libmesh_real(slow_residual_norm_sq) );
1851 }
1852 
1854 {
1855  return inner_product_matrix.get();
1856 }
1857 
1859 {
1861  libmesh_error_msg("Error: Must have store_non_dirichlet_operators==true to access non_dirichlet_inner_product_matrix.");
1862 
1864 }
1865 
1867 {
1869  {
1871  }
1872 
1873  return get_inner_product_matrix();
1874 }
1875 
1877 {
1878  if (q >= get_rb_theta_expansion().get_n_A_terms())
1879  libmesh_error_msg("Error: We must have q < Q_a in get_Aq.");
1880 
1881  return Aq_vector[q].get();
1882 }
1883 
1885 {
1887  libmesh_error_msg("Error: Must have store_non_dirichlet_operators==true to access non_dirichlet_Aq.");
1888 
1889  if (q >= get_rb_theta_expansion().get_n_A_terms())
1890  libmesh_error_msg("Error: We must have q < Q_a in get_Aq.");
1891 
1892  return non_dirichlet_Aq_vector[q].get();
1893 }
1894 
1896 {
1898  {
1899  return get_non_dirichlet_Aq(q);
1900  }
1901 
1902  return get_Aq(q);
1903 }
1904 
1906 {
1907  if (q >= get_rb_theta_expansion().get_n_F_terms())
1908  libmesh_error_msg("Error: We must have q < Q_f in get_Fq.");
1909 
1910  return Fq_vector[q].get();
1911 }
1912 
1914 {
1916  libmesh_error_msg("Error: Must have store_non_dirichlet_operators==true to access non_dirichlet_Fq.");
1917 
1918  if (q >= get_rb_theta_expansion().get_n_F_terms())
1919  libmesh_error_msg("Error: We must have q < Q_f in get_Fq.");
1920 
1921  return non_dirichlet_Fq_vector[q].get();
1922 }
1923 
1925 {
1927  {
1928  return get_non_dirichlet_Fq(q);
1929  }
1930 
1931  return get_Fq(q);
1932 }
1933 
1935 {
1936  if ((n >= get_rb_theta_expansion().get_n_outputs()) || (q_l >= get_rb_theta_expansion().get_n_output_terms(n)))
1937  libmesh_error_msg("Error: We must have n < n_outputs and " \
1938  << "q_l < get_rb_theta_expansion().get_n_output_terms(n) in get_output_vector.");
1939 
1940  return outputs_vector[n][q_l].get();
1941 }
1942 
1944 {
1945  if ((n >= get_rb_theta_expansion().get_n_outputs()) || (q_l >= get_rb_theta_expansion().get_n_output_terms(n)))
1946  libmesh_error_msg("Error: We must have n < n_outputs and " \
1947  << "q_l < get_rb_theta_expansion().get_n_output_terms(n) in get_non_dirichlet_output_vector.");
1948 
1949  return non_dirichlet_outputs_vector[n][q_l].get();
1950 }
1951 
1952 void RBConstruction::get_all_matrices(std::map<std::string, SparseMatrix<Number> *> & all_matrices)
1953 {
1954  all_matrices.clear();
1955 
1956  all_matrices["inner_product"] = get_inner_product_matrix();
1957 
1959  {
1960  all_matrices["non_dirichlet_inner_product"] = get_non_dirichlet_inner_product_matrix();
1961  }
1962 
1963  for (unsigned int q_a=0; q_a<get_rb_theta_expansion().get_n_A_terms(); q_a++)
1964  {
1965  std::stringstream matrix_name;
1966  matrix_name << "A" << q_a;
1967  all_matrices[matrix_name.str()] = get_Aq(q_a);
1968 
1970  {
1971  matrix_name << "_non_dirichlet";
1972  all_matrices[matrix_name.str()] = get_non_dirichlet_Aq(q_a);
1973  }
1974  }
1975 }
1976 
1977 void RBConstruction::get_all_vectors(std::map<std::string, NumericVector<Number> *> & all_vectors)
1978 {
1979  all_vectors.clear();
1980 
1981  get_output_vectors(all_vectors);
1982 
1983  for (unsigned int q_f=0; q_f<get_rb_theta_expansion().get_n_F_terms(); q_f++)
1984  {
1985  std::stringstream F_vector_name;
1986  F_vector_name << "F" << q_f;
1987  all_vectors[F_vector_name.str()] = get_Fq(q_f);
1988 
1990  {
1991  F_vector_name << "_non_dirichlet";
1992  all_vectors[F_vector_name.str()] = get_non_dirichlet_Fq(q_f);
1993  }
1994  }
1995 }
1996 
1997 void RBConstruction::get_output_vectors(std::map<std::string, NumericVector<Number> *> & output_vectors)
1998 {
1999  output_vectors.clear();
2000 
2001  for (unsigned int n=0; n<get_rb_theta_expansion().get_n_outputs(); n++)
2002  for (unsigned int q_l=0; q_l<get_rb_theta_expansion().get_n_output_terms(n); q_l++)
2003  {
2004  std::stringstream output_name;
2005  output_name << "output_" << n << "_"<< q_l;
2006  output_vectors[output_name.str()] = get_output_vector(n,q_l);
2007 
2009  {
2010  output_name << "_non_dirichlet";
2011  output_vectors[output_name.str()] = get_non_dirichlet_output_vector(n,q_l);
2012  }
2013  }
2014 }
2015 
2016 #ifdef LIBMESH_ENABLE_DIRICHLET
2017 
2018 std::unique_ptr<DirichletBoundary> RBConstruction::build_zero_dirichlet_boundary_object()
2019 {
2020  ZeroFunction<> zf;
2021 
2022  std::set<boundary_id_type> dirichlet_ids;
2023  std::vector<unsigned int> variables;
2024 
2025  // The DirichletBoundary constructor clones zf, so it's OK that zf is only in local scope
2026  return libmesh_make_unique<DirichletBoundary>(dirichlet_ids, variables, &zf);
2027 }
2028 
2029 #endif
2030 
2031 void RBConstruction::write_riesz_representors_to_files(const std::string & riesz_representors_dir,
2032  const bool write_binary_residual_representors)
2033 {
2034  LOG_SCOPE("write_riesz_representors_to_files()", "RBConstruction");
2035 
2036  // Write out Riesz representors. These are useful to have when restarting,
2037  // so you don't have to recompute them all over again.
2038 
2039  // First we write out the Fq representors, these are independent of an RBEvaluation object.
2040  libMesh::out << "Writing out the Fq_representors..." << std::endl;
2041 
2042  std::ostringstream file_name;
2043  const std::string riesz_representor_suffix = (write_binary_residual_representors ? ".xdr" : ".dat");
2044  struct stat stat_info;
2045 
2046  // Residual representors written out to their own separate directory
2047  if ( this->processor_id() == 0)
2048  if ( Utility::mkdir(riesz_representors_dir.c_str()) != 0)
2049  libMesh::out << "Skipping creating residual_representors directory: " << strerror(errno) << std::endl;
2050 
2051  for (auto i : index_range(Fq_representor))
2052  {
2053  if (Fq_representor[i])
2054  {
2055  file_name.str(""); // reset filename
2056  file_name << riesz_representors_dir << "/Fq_representor" << i << riesz_representor_suffix;
2057 
2058  // Check to see if file exists, if so, don't overwrite it, we assume it was
2059  // there from a previous call to this function. Note: if stat returns zero
2060  // it means it successfully got the file attributes (and therefore the file
2061  // exists). Because of the following factors:
2062  // 1.) write_serialized_data takes longer for proc 0 than it does for others,
2063  // so processors can get out of sync.
2064  // 2.) The constructor for Xdr opens a (0 length) file on *all* processors,
2065  // there are typically hundreds of 0-length files created during this loop,
2066  // and that screws up checking for the existence of files. One way to stay
2067  // in sync is to but a barrier at each iteration of the loop -- not sure how
2068  // bad this will affect performance, but it can't be much worse than serialized
2069  // I/O already is :)
2070  int stat_result = stat(file_name.str().c_str(), &stat_info);
2071 
2072  if ( (stat_result != 0) || // file definitely doesn't already exist
2073  (stat_info.st_size == 0)) // file exists, but has zero length (can happen if another proc already opened it!)
2074  {
2075  // No need to copy!
2076  // *solution = *(Fq_representor[i]);
2077  // std::swap doesn't work on pointers
2078  //std::swap(solution.get(), Fq_representor[i]);
2079  Fq_representor[i]->swap(*solution);
2080 
2081  Xdr fqr_data(file_name.str(),
2082  write_binary_residual_representors ? ENCODE : WRITE);
2083 
2084  write_serialized_data(fqr_data, false);
2085 
2086  // Synchronize before moving on
2087  this->comm().barrier();
2088 
2089  // Swap back.
2090  Fq_representor[i]->swap(*solution);
2091 
2092  // TODO: bzip the resulting file? See $LIBMESH_DIR/src/mesh/unstructured_mesh.C
2093  // for the system call, be sure to do it only on one processor, etc.
2094  }
2095  }
2096  }
2097 
2098 
2099  // Next, write out the Aq representors associated with rb_eval.
2100  libMesh::out << "Writing out the Aq_representors..." << std::endl;
2101 
2102  const unsigned int jstop = get_rb_evaluation().get_n_basis_functions();
2103  const unsigned int jstart = jstop-get_delta_N();
2104 
2105  RBEvaluation & rbe = get_rb_evaluation();
2106  for (auto i : index_range(rbe.Aq_representor))
2107  for (unsigned int j=jstart; j<jstop; ++j)
2108  {
2109  libMesh::out << "Writing out Aq_representor[" << i << "][" << j << "]..." << std::endl;
2110  libmesh_assert(get_rb_evaluation().Aq_representor[i][j]);
2111 
2112  file_name.str(""); // reset filename
2113  file_name << riesz_representors_dir
2114  << "/Aq_representor" << i << "_" << j << riesz_representor_suffix;
2115 
2116  {
2117  // No need to copy! Use swap instead.
2118  // *solution = *(Aq_representor[i][j]);
2119  rbe.Aq_representor[i][j]->swap(*solution);
2120 
2121  Xdr aqr_data(file_name.str(),
2122  write_binary_residual_representors ? ENCODE : WRITE);
2123 
2124  write_serialized_data(aqr_data, false);
2125 
2126  // Synchronize before moving on
2127  this->comm().barrier();
2128 
2129  // Swap back.
2130  rbe.Aq_representor[i][j]->swap(*solution);
2131 
2132  // TODO: bzip the resulting file? See $LIBMESH_DIR/src/mesh/unstructured_mesh.C
2133  // for the system call, be sure to do it only on one processor, etc.
2134  }
2135  }
2136 }
2137 
2138 
2139 
2140 void RBConstruction::read_riesz_representors_from_files(const std::string & riesz_representors_dir,
2141  const bool read_binary_residual_representors)
2142 {
2143  LOG_SCOPE("read_riesz_representors_from_files()", "RBConstruction");
2144 
2145  libMesh::out << "Reading in the Fq_representors..." << std::endl;
2146 
2147  const std::string riesz_representor_suffix = (read_binary_residual_representors ? ".xdr" : ".dat");
2148  std::ostringstream file_name;
2149  struct stat stat_info;
2150 
2151  // Read in the Fq_representors. There should be Q_f of these. FIXME:
2152  // should we be worried about leaks here?
2153  for (const auto & rep : Fq_representor)
2154  if (rep)
2155  libmesh_error_msg("Error, must delete existing Fq_representor before reading in from file.");
2156 
2157  for (auto i : index_range(Fq_representor))
2158  {
2159  file_name.str(""); // reset filename
2160  file_name << riesz_representors_dir
2161  << "/Fq_representor" << i << riesz_representor_suffix;
2162 
2163  // On processor zero check to be sure the file exists
2164  if (this->processor_id() == 0)
2165  {
2166  int stat_result = stat(file_name.str().c_str(), &stat_info);
2167 
2168  if (stat_result != 0)
2169  libmesh_error_msg("File does not exist: " << file_name.str());
2170  }
2171 
2172  Xdr fqr_data(file_name.str(),
2173  read_binary_residual_representors ? DECODE : READ);
2174 
2175  read_serialized_data(fqr_data, false);
2176 
2178  Fq_representor[i]->init (this->n_dofs(), this->n_local_dofs(), false, PARALLEL);
2179 
2180  // No need to copy, just swap
2181  // *Fq_representor[i] = *solution;
2182  Fq_representor[i]->swap(*solution);
2183  }
2184 
2185  // Alert the update_residual_terms() function that we don't need to recompute
2186  // the Fq_representors as we have already read them in from file!
2188 
2189 
2190  libMesh::out << "Reading in the Aq_representors..." << std::endl;
2191 
2192  // Read in the Aq representors. The class makes room for [Q_a][Nmax] of these. We are going to
2193  // read in [Q_a][get_rb_evaluation().get_n_basis_functions()]. FIXME:
2194  // should we be worried about leaks in the locations where we're about to fill entries?
2195  RBEvaluation & rbe = get_rb_evaluation();
2196  for (const auto & row : rbe.Aq_representor)
2197  for (const auto & rep : row)
2198  if (rep)
2199  libmesh_error_msg("Error, must delete existing Aq_representor before reading in from file.");
2200 
2201  // Now ready to read them in from file!
2202  for (auto i : index_range(rbe.Aq_representor))
2203  for (unsigned int j=0; j<rbe.get_n_basis_functions(); ++j)
2204  {
2205  file_name.str(""); // reset filename
2206  file_name << riesz_representors_dir
2207  << "/Aq_representor" << i << "_" << j << riesz_representor_suffix;
2208 
2209  // On processor zero check to be sure the file exists
2210  if (this->processor_id() == 0)
2211  {
2212  int stat_result = stat(file_name.str().c_str(), &stat_info);
2213 
2214  if (stat_result != 0)
2215  libmesh_error_msg("File does not exist: " << file_name.str());
2216  }
2217 
2218  Xdr aqr_data(file_name.str(), read_binary_residual_representors ? DECODE : READ);
2219 
2220  read_serialized_data(aqr_data, false);
2221 
2222  rbe.Aq_representor[i][j] = NumericVector<Number>::build(this->comm());
2223  rbe.Aq_representor[i][j]->init (n_dofs(), n_local_dofs(),
2224  false, PARALLEL);
2225 
2226  // No need to copy, just swap
2227  rbe.Aq_representor[i][j]->swap(*solution);
2228  }
2229 }
2230 
2232 {
2234 
2235  conv_flag = input_solver.get_converged_reason();
2236 
2237  if (conv_flag < 0)
2238  {
2239  std::stringstream err_msg;
2240  err_msg << "Convergence error. Error id: " << conv_flag;
2241  libmesh_error_msg(err_msg.str());
2242  }
2243 }
2244 
2246 {
2247  return assert_convergence;
2248 }
2249 
2251 {
2252  assert_convergence = flag;
2253 }
2254 
2255 } // namespace libMesh
libMesh::LinearSolver::reuse_preconditioner
virtual void reuse_preconditioner(bool)
Set the same_preconditioner flag, which indicates if we reuse the same preconditioner for subsequent ...
Definition: linear_solver.C:129
libMesh::RBConstruction::inner_product_matrix
std::unique_ptr< SparseMatrix< Number > > inner_product_matrix
The inner product matrix.
Definition: rb_construction.h:484
libMesh::LinearImplicitSystem::_final_linear_residual
Real _final_linear_residual
The final residual for the linear system Ax=b.
Definition: linear_implicit_system.h:204
libMesh::SparseMatrix::close
virtual void close()=0
Calls the SparseMatrix's internal assembly routines, ensuring that the values are consistent across p...
libMesh::RBConstruction::enrich_RB_space
virtual void enrich_RB_space()
Add a new basis function to the RB space.
Definition: rb_construction.C:1316
libMesh::RBConstruction::post_process_truth_solution
virtual void post_process_truth_solution()
Similarly, provide an opportunity to post-process the truth solution after the solve is complete.
Definition: rb_construction.h:651
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::RBParametrized::print_discrete_parameter_values
void print_discrete_parameter_values() const
Print out all the discrete parameter values.
Definition: rb_parametrized.C:389
libMesh::NumericVector::zero
virtual void zero()=0
Set all entries to zero.
libMesh::RBParametrized::get_parameters_min
const RBParameters & get_parameters_min() const
Get an RBParameters object that specifies the minimum allowable value for each parameter.
Definition: rb_parametrized.C:174
libMesh::RBConstructionBase< LinearImplicitSystem >::clear
virtual void clear()
Clear all the data structures associated with the system.
Definition: rb_construction_base.C:65
libMesh::dof_id_type
uint8_t dof_id_type
Definition: id_types.h:67
libMesh::Number
Real Number
Definition: libmesh_common.h:195
libMesh::DiffContext::get_elem_residual
const DenseVector< Number > & get_elem_residual() const
Const accessor for element residual.
Definition: diff_context.h:249
libMesh::DenseMatrix::get_transpose
void get_transpose(DenseMatrix< T > &dest) const
Put the tranposed matrix into dest.
Definition: dense_matrix_impl.h:612
libMesh::System::n_vars
unsigned int n_vars() const
Definition: system.h:2155
libMesh::RBEvaluation::RB_Aq_vector
std::vector< DenseMatrix< Number > > RB_Aq_vector
Dense matrices for the RB computations.
Definition: rb_evaluation.h:260
libMesh::LinearSolver::get_converged_reason
virtual LinearConvergenceReason get_converged_reason() const =0
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::FEMContext::side
unsigned char side
Current side for side_* to examine.
Definition: fem_context.h:1010
libMesh::System::get_equation_systems
const EquationSystems & get_equation_systems() const
Definition: system.h:720
libMesh::NumericVector::add
virtual void add(const numeric_index_type i, const T value)=0
Adds value to each entry of the vector.
libMesh::RBConstruction::get_RB_error_bound
virtual Real get_RB_error_bound()
Definition: rb_construction.C:1356
libMesh::RBConstruction::get_non_dirichlet_Fq
NumericVector< Number > * get_non_dirichlet_Fq(unsigned int q)
Get a pointer to non-Dirichlet Fq.
Definition: rb_construction.C:1913
libMesh::DGFEMContext::get_neighbor_dof_indices
const std::vector< dof_id_type > & get_neighbor_dof_indices() const
Accessor for neighbor dof indices.
Definition: dg_fem_context.h:71
libMesh::RBConstruction::get_Aq
SparseMatrix< Number > * get_Aq(unsigned int q)
Get a pointer to Aq.
Definition: rb_construction.C:1876
libMesh::MeshBase::get_boundary_info
const BoundaryInfo & get_boundary_info() const
The information about boundary ids on the mesh.
Definition: mesh_base.h:132
libMesh::ExplicitSystem::rhs
NumericVector< Number > * rhs
The system matrix.
Definition: explicit_system.h:114
libMesh::RBConstructionBase< LinearImplicitSystem >::get_first_local_training_index
numeric_index_type get_first_local_training_index() const
Get the first local index of the training parameters.
Definition: rb_construction_base.C:116
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::DiffContext::get_dof_indices
const std::vector< dof_id_type > & get_dof_indices() const
Accessor for element dof indices.
Definition: diff_context.h:367
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::DGFEMContext::side_fe_reinit
virtual void side_fe_reinit() override
Override side_fe_reinit to set a boolean flag so that by default DG terms are assumed to be inactive.
Definition: dg_fem_context.C:77
libMesh::LinearSolver::solve
virtual std::pair< unsigned int, Real > solve(SparseMatrix< T > &, NumericVector< T > &, NumericVector< T > &, const double, const unsigned int)=0
This function calls the solver _solver_type preconditioned with the _preconditioner_type precondition...
libMesh::RBAssemblyExpansion::get_output_assembly
ElemAssembly & get_output_assembly(unsigned int output_index, unsigned int q_l)
Return a reference to the specified output assembly object.
Definition: rb_assembly_expansion.C:190
libMesh::RBConstruction::get_all_vectors
virtual void get_all_vectors(std::map< std::string, NumericVector< Number > * > &all_vectors)
Get a map that stores pointers to all of the vectors.
Definition: rb_construction.C:1977
libMesh::libmesh_real
T libmesh_real(T a)
Definition: libmesh_common.h:166
libMesh::RBConstruction::get_non_dirichlet_Fq_if_avail
NumericVector< Number > * get_non_dirichlet_Fq_if_avail(unsigned int q)
Get a pointer to non_dirichlet_Fq if it's available, otherwise get Fq.
Definition: rb_construction.C:1924
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::RBConstruction::set_rb_evaluation
void set_rb_evaluation(RBEvaluation &rb_eval_in)
Set the RBEvaluation object.
Definition: rb_construction.C:170
libMesh::DGFEMContext
This class extends FEMContext in order to provide extra data required to perform local element residu...
Definition: dg_fem_context.h:39
libMesh::RBConstruction::abs_training_tolerance
Real abs_training_tolerance
Definition: rb_construction.h:855
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::RBConstructionBase< LinearImplicitSystem >::set_training_random_seed
void set_training_random_seed(unsigned int seed)
Set the seed that is used to randomly generate training parameters.
Definition: rb_construction_base.C:630
libMesh::RBConstruction::get_non_dirichlet_inner_product_matrix
SparseMatrix< Number > * get_non_dirichlet_inner_product_matrix()
Get the non-Dirichlet (or more generally no-constraints) version of the inner-product matrix.
Definition: rb_construction.C:1858
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::RBConstruction::rel_training_tolerance
Real rel_training_tolerance
Relative and absolute tolerances for training reduced basis using the Greedy scheme.
Definition: rb_construction.h:854
libMesh::index_range
IntRange< std::size_t > index_range(const std::vector< T > &vec)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
Definition: int_range.h:106
libMesh::RBParametrized::get_n_params
unsigned int get_n_params() const
Get the number of parameters.
Definition: rb_parametrized.C:115
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::Xdr
This class implements a C++ interface to the XDR (eXternal Data Representation) format.
Definition: xdr_cxx.h:65
libMesh::RBConstruction::Fq_representor_innerprods
std::vector< Number > Fq_representor_innerprods
Vectors storing the residual representor inner products to be used in computing the residuals online.
Definition: rb_construction.h:513
libMesh::FEMContext::get_side
unsigned char get_side() const
Accessor for current side of Elem object.
Definition: fem_context.h:910
libMesh::FEMContext::pre_fe_reinit
virtual void pre_fe_reinit(const System &, const Elem *e)
Reinitializes local data vectors/matrices on the current geometric element.
Definition: fem_context.C:1642
libMesh::RBConstruction::compute_output_dual_innerprods
virtual void compute_output_dual_innerprods()
Compute and store the dual norm of each output functional.
Definition: rb_construction.C:1635
libMesh::RBAssemblyExpansion::get_F_assembly
ElemAssembly & get_F_assembly(unsigned int q)
Return a reference to the specified F_assembly object.
Definition: rb_assembly_expansion.C:182
libMesh::NumericVector::close
virtual void close()=0
Calls the NumericVector's internal assembly routines, ensuring that the values are consistent across ...
libMesh::RBEvaluation::output_dual_innerprods
std::vector< std::vector< Number > > output_dual_innerprods
The vector storing the dual norm inner product terms for each output.
Definition: rb_evaluation.h:308
libMesh::FEGenericBase
This class forms the foundation from which generic finite elements may be derived.
Definition: exact_error_estimator.h:39
libMesh::DGFEMContext::get_neighbor_elem_jacobian
const DenseMatrix< Number > & get_neighbor_elem_jacobian() const
Const accessor for element-neighbor Jacobian.
Definition: dg_fem_context.h:162
libMesh::RBConstruction::~RBConstruction
virtual ~RBConstruction()
Destructor.
Definition: rb_construction.C:94
libMesh::RBConstruction::post_process_elem_matrix_and_vector
virtual void post_process_elem_matrix_and_vector(DGFEMContext &)
This function is called from add_scaled_matrix_and_vector() before each element matrix and vector are...
Definition: rb_construction.h:641
libMesh::DGFEMContext::get_elem_elem_jacobian
const DenseMatrix< Number > & get_elem_elem_jacobian() const
Const accessor for element-element Jacobian.
Definition: dg_fem_context.h:110
std::sqrt
MetaPhysicL::DualNumber< T, D > sqrt(const MetaPhysicL::DualNumber< T, D > &in)
libMesh::FEMContext::get_elem
const Elem & get_elem() const
Accessor for current Elem object.
Definition: fem_context.h:896
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::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::RBConstruction::get_matrix_for_output_dual_solves
virtual SparseMatrix< Number > & get_matrix_for_output_dual_solves()
Return the matrix for the output residual dual norm solves.
Definition: rb_construction.C:1630
libMesh::RBConstruction::build_zero_dirichlet_boundary_object
static std::unique_ptr< DirichletBoundary > build_zero_dirichlet_boundary_object()
It's helpful to be able to generate a DirichletBoundary that stores a ZeroFunction in order to impose...
Definition: rb_construction.C:2018
libMesh::libmesh_conj
T libmesh_conj(T a)
Definition: libmesh_common.h:167
libMesh::ElemAssembly::get_nodal_values
virtual void get_nodal_values(std::vector< dof_id_type > &, DenseMatrix< Number > &, DenseVector< Number > &, const System &, const Node &)
Get values to add to the matrix or rhs vector based on node.
Definition: elem_assembly.h:69
libMesh::DenseMatrixBase::n
unsigned int n() const
Definition: dense_matrix_base.h:109
libMesh::RBConstruction::Aq_vector
std::vector< std::unique_ptr< SparseMatrix< Number > > > Aq_vector
Vector storing the Q_a matrices from the affine expansion.
Definition: rb_construction.h:826
libMesh::WRITE
Definition: enum_xdr_mode.h:40
mesh
MeshBase & mesh
Definition: mesh_communication.C:1257
libMesh::ElemAssembly::interior_assembly
virtual void interior_assembly(FEMContext &)
Perform the element interior assembly.
Definition: elem_assembly.h:57
libMesh::RBConstruction::non_dirichlet_Fq_vector
std::vector< std::unique_ptr< NumericVector< Number > > > non_dirichlet_Fq_vector
Definition: rb_construction.h:846
libMesh::RBConstruction::init_context
virtual void init_context(FEMContext &)
Initialize the FEMContext prior to performing an element loop.
Definition: rb_construction.h:742
libMesh::DofMap::first_dof
dof_id_type first_dof(const processor_id_type proc) const
Definition: dof_map.h:650
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::RBConstruction::outputs_vector
std::vector< std::vector< std::unique_ptr< NumericVector< Number > > > > outputs_vector
The libMesh vectors that define the output functionals.
Definition: rb_construction.h:838
libMesh::RBConstruction::rb_eval
RBEvaluation * rb_eval
The current RBEvaluation object we are using to perform the Evaluation stage of the reduced basis met...
Definition: rb_construction.h:792
libMesh::GMVIO
This class implements writing meshes in the GMV format.
Definition: gmv_io.h:54
libMesh::RBConstruction::set_inner_product_assembly
void set_inner_product_assembly(ElemAssembly &inner_product_assembly_in)
Set the rb_assembly_expansion object.
Definition: rb_construction.C:379
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::RBConstruction::use_empty_rb_solve_in_greedy
bool use_empty_rb_solve_in_greedy
A boolean flag to indicate whether or not we initialize the Greedy algorithm by performing rb_solves ...
Definition: rb_construction.h:567
libMesh::DofMap::is_constrained_dof
bool is_constrained_dof(const dof_id_type dof) const
Definition: dof_map.h:1962
libMesh::RBConstruction::recompute_all_residual_terms
virtual void recompute_all_residual_terms(const bool compute_inner_products=true)
This function computes all of the residual representors, can be useful when restarting a basis traini...
Definition: rb_construction.C:1380
libMesh::RBParametrized::set_parameters
void set_parameters(const RBParameters &params)
Set the current parameters to params.
Definition: rb_parametrized.C:155
libMesh::DofObject::processor_id
processor_id_type processor_id() const
Definition: dof_object.h:829
libMesh::LinearSolver::init
virtual void init(const char *name=nullptr)=0
Initialize data structures if not done so already.
libMesh::RBConstruction::zero_constrained_dofs_on_vector
void zero_constrained_dofs_on_vector(NumericVector< Number > &vector)
It is sometimes useful to be able to zero vector entries that correspond to constrained dofs.
Definition: rb_construction.C:402
libMesh::RBConstructionBase< LinearImplicitSystem >::get_global_max_error_pair
static void get_global_max_error_pair(const Parallel::Communicator &communicator, std::pair< numeric_index_type, Real > &error_pair)
Static function to return the error pair (index,error) that is corresponds to the largest error on al...
Definition: rb_construction_base.C:85
libMesh::SparseMatrix
Generic sparse matrix.
Definition: vector_fe_ex5.C:45
libMesh::RBParametrized::get_parameters_max
const RBParameters & get_parameters_max() const
Get an RBParameters object that specifies the maximum allowable value for each parameter.
Definition: rb_parametrized.C:182
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::RBConstruction::update_greedy_param_list
void update_greedy_param_list()
Update the list of Greedily chosen parameters with current_parameters.
Definition: rb_construction.C:1229
libMesh::NumericVector< Number >
libMesh::DenseMatrixBase::m
unsigned int m() const
Definition: dense_matrix_base.h:104
libMesh::RBConstruction::print_basis_function_orthogonality
void print_basis_function_orthogonality()
Print out a matrix that shows the orthogonality of the RB basis functions.
Definition: rb_construction.C:348
libMesh::System::assemble_before_solve
bool assemble_before_solve
Flag which tells the system to whether or not to call the user assembly function during each call to ...
Definition: system.h:1493
libMesh::RBAssemblyExpansion
This class stores the set of ElemAssembly functor objects that define the "parameter-independent expa...
Definition: rb_assembly_expansion.h:44
libMesh::libmesh_assert
libmesh_assert(ctx)
libMesh::RBConstruction::get_convergence_assertion_flag
bool get_convergence_assertion_flag() const
Getter for the flag determining if convergence should be checked after each solve.
Definition: rb_construction.C:2245
libMesh::RBConstruction::get_inner_product_matrix
SparseMatrix< Number > * get_inner_product_matrix()
Get a pointer to inner_product_matrix.
Definition: rb_construction.C:1853
libMesh::IntRange
The IntRange templated class is intended to make it easy to loop over integers which are indices of a...
Definition: int_range.h:53
libMesh::RBConstruction::inner_product_assembly
ElemAssembly * inner_product_assembly
Pointer to inner product assembly.
Definition: rb_construction.h:803
libMesh::RBConstruction::skip_degenerate_sides
bool skip_degenerate_sides
In some cases meshes are intentionally created with degenerate sides as a way to represent,...
Definition: rb_construction.h:545
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::NumericVector::add_vector
virtual void add_vector(const T *v, const std::vector< numeric_index_type > &dof_indices)
Computes , where v is a pointer and each dof_indices[i] specifies where to add value v[i].
Definition: numeric_vector.C:363
libMesh::LinearConvergenceReason
LinearConvergenceReason
Linear solver convergence flags (taken from the PETSc flags).
Definition: enum_convergence_flags.h:33
libMesh::MeshBase
This is the MeshBase class.
Definition: mesh_base.h:78
libMesh::RBParametrized::get_parameter_max
Real get_parameter_max(const std::string &param_name) const
Get maximum allowable value of parameter param_name.
Definition: rb_parametrized.C:198
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::clear
virtual void clear() override
Clear all the data structures associated with the system.
Definition: rb_construction.C:100
libMesh::NumericVector::localize
virtual void localize(std::vector< T > &v_local) const =0
Creates a copy of the global vector in the local vector v_local.
libMesh::RBConstructionBase< LinearImplicitSystem >::broadcast_parameters
void broadcast_parameters(unsigned int proc_id)
Broadcasts parameters on processor proc_id to all processors.
Definition: rb_construction_base.C:600
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::RBConstructionBase< LinearImplicitSystem >::get_n_training_samples
numeric_index_type get_n_training_samples() const
Get the total number of training samples.
Definition: rb_construction_base.C:98
libMesh::LinearImplicitSystem::get_linear_solver
virtual LinearSolver< Number > * get_linear_solver() const override
Definition: linear_implicit_system.C:353
libMesh::System::n_local_dofs
dof_id_type n_local_dofs() const
Definition: system.C:187
libMesh::RBConstruction::assemble_Fq_vector
void assemble_Fq_vector(unsigned int q, NumericVector< Number > *input_vector, bool apply_dof_constraints=true)
Assemble the q^th affine vector and store it in input_matrix.
Definition: rb_construction.C:971
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::Tri3Subdivision::is_ghost
bool is_ghost() const
Definition: face_tri3_subdivision.h:116
libMesh::RBConstruction::set_convergence_assertion_flag
void set_convergence_assertion_flag(bool flag)
Setter for the flag determining if convergence should be checked after each solve.
Definition: rb_construction.C:2250
libMesh::RBConstruction::RBConstruction
RBConstruction(EquationSystems &es, const std::string &name, const unsigned int number)
Constructor.
Definition: rb_construction.C:62
libMesh::RBConstruction::set_rel_training_tolerance
void set_rel_training_tolerance(Real new_training_tolerance)
Get/set the relative tolerance for the basis training.
Definition: rb_construction.h:184
libMesh::RBConstruction::get_non_dirichlet_Aq_if_avail
SparseMatrix< Number > * get_non_dirichlet_Aq_if_avail(unsigned int q)
Get a pointer to non_dirichlet_Aq if it's available, otherwise get Aq.
Definition: rb_construction.C:1895
libMesh::RBEvaluation::RB_solution
DenseVector< Number > RB_solution
The RB solution vector.
Definition: rb_evaluation.h:270
libMesh::RBConstruction::is_rb_eval_initialized
bool is_rb_eval_initialized() const
Definition: rb_construction.C:183
libMesh::RBConstruction::write_riesz_representors_to_files
virtual void write_riesz_representors_to_files(const std::string &riesz_representors_dir, const bool write_binary_residual_representors)
Write out all the Riesz representor data to files.
Definition: rb_construction.C:2031
libMesh::RBConstruction::get_output_vectors
virtual void get_output_vectors(std::map< std::string, NumericVector< Number > * > &all_vectors)
Get a map that stores pointers to all of the vectors.
Definition: rb_construction.C:1997
libMesh::RBConstruction::energy_inner_product_coeffs
std::vector< Number > energy_inner_product_coeffs
We may optionally want to use the "energy inner-product" rather than the inner-product assembly speci...
Definition: rb_construction.h:821
libMesh::RBEvaluation::Fq_representor_innerprods
std::vector< Number > Fq_representor_innerprods
Vectors storing the residual representor inner products to be used in computing the residuals online.
Definition: rb_evaluation.h:290
libMesh::RBConstructionBase< LinearImplicitSystem >::set_params_from_training_set
void set_params_from_training_set(unsigned int index)
Set parameters to the RBParameters stored in index index of the training set.
Definition: rb_construction_base.C:130
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::DofMap::enforce_constraints_exactly
void enforce_constraints_exactly(const System &system, NumericVector< Number > *v=nullptr, bool homogeneous=false) const
Constrains the numeric vector v, which represents a solution defined on the mesh.
Definition: dof_map.h:2054
libMesh::RBConstruction::non_dirichlet_outputs_vector
std::vector< std::vector< std::unique_ptr< NumericVector< Number > > > > non_dirichlet_outputs_vector
Definition: rb_construction.h:847
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::RBConstruction::compute_max_error_bound
virtual Real compute_max_error_bound()
(i) Compute the a posteriori error bound for each set of parameters in the training set,...
Definition: rb_construction.C:1395
libMesh::RBEvaluation::Fq_Aq_representor_innerprods
std::vector< std::vector< std::vector< Number > > > Fq_Aq_representor_innerprods
Vectors storing the residual representor inner products to be used in computing the residuals online.
Definition: rb_evaluation.h:299
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::BoundaryInfo::n_nodeset_conds
std::size_t n_nodeset_conds() const
Definition: boundary_info.C:1680
libMesh::RBConstruction::extra_linear_solver
LinearSolver< Number > * extra_linear_solver
Also, we store a pointer to an extra linear solver.
Definition: rb_construction.h:479
libMesh::Elem::side_ptr
virtual std::unique_ptr< Elem > side_ptr(unsigned int i)=0
libMesh::RBConstruction::assemble_Aq_matrix
void assemble_Aq_matrix(unsigned int q, SparseMatrix< Number > *input_matrix, bool apply_dof_constraints=true)
Assemble the q^th affine matrix and store it in input_matrix.
Definition: rb_construction.C:876
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::ImplicitSystem::matrix
SparseMatrix< Number > * matrix
The system matrix.
Definition: implicit_system.h:393
libMesh::RBConstructionBase< LinearImplicitSystem >
libMesh::RBParametrized::print_parameters
void print_parameters() const
Print the current parameters.
Definition: rb_parametrized.C:206
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::RBParameters::set_value
void set_value(const std::string &param_name, Real value)
Set the value of the specified parameter.
Definition: rb_parameters.C:47
libMesh::Node
A Node is like a Point, but with more information.
Definition: node.h:52
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::RBConstruction::enrich_basis_from_rhs_terms
void enrich_basis_from_rhs_terms(const bool resize_rb_eval_data=true)
This function computes one basis function for each rhs term.
Definition: rb_construction.C:1134
libMesh::RBAssemblyExpansion::get_A_assembly
ElemAssembly & get_A_assembly(unsigned int q)
Return a reference to the specified A_assembly object.
Definition: rb_assembly_expansion.C:174
libMesh::FEType::default_quadrature_rule
std::unique_ptr< QBase > default_quadrature_rule(const unsigned int dim, const int extraorder=0) const
Definition: fe_type.C:31
libMesh::RBConstructionBase< LinearImplicitSystem >::is_quiet
bool is_quiet() const
Is the system in quiet mode?
Definition: rb_construction_base.h:98
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::RBConstruction::set_rb_assembly_expansion
void set_rb_assembly_expansion(RBAssemblyExpansion &rb_assembly_expansion_in)
Set the rb_assembly_expansion object.
Definition: rb_construction.C:366
libMesh::RBConstruction::add_scaled_Aq
void add_scaled_Aq(Number scalar, unsigned int q_a, SparseMatrix< Number > *input_matrix, bool symmetrize)
Add the scaled q^th affine matrix to input_matrix.
Definition: rb_construction.C:893
libMesh::DenseVector::size
virtual unsigned int size() const override
Definition: dense_vector.h:92
libMesh::ZeroFunction
ConstFunction that simply returns 0.
Definition: zero_function.h:36
libMesh::DGFEMContext::get_elem_neighbor_jacobian
const DenseMatrix< Number > & get_elem_neighbor_jacobian() const
Const accessor for element-neighbor Jacobian.
Definition: dg_fem_context.h:136
libMesh::READ
Definition: enum_xdr_mode.h:41
libMesh::FEAbstract::get_fe_type
FEType get_fe_type() const
Definition: fe_abstract.h:427
libMesh::RBConstruction::get_greedy_parameter
const RBParameters & get_greedy_parameter(unsigned int i)
Return the parameters chosen during the i^th step of the Greedy algorithm.
Definition: rb_construction.C:1234
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::numeric_index_type
dof_id_type numeric_index_type
Definition: id_types.h:99
libMesh::EquationSystems
This is the EquationSystems class.
Definition: equation_systems.h:74
libMesh::DofMap::constrain_element_matrix_and_vector
void constrain_element_matrix_and_vector(DenseMatrix< Number > &matrix, DenseVector< Number > &rhs, std::vector< dof_id_type > &elem_dofs, bool asymmetric_constraint_rows=true) const
Constrains the element matrix and vector.
Definition: dof_map.h:2034
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::Utility::mkdir
int mkdir(const char *pathname)
Create a directory.
Definition: utility.C:140
libMesh::RBEvaluation::Aq_Aq_representor_innerprods
std::vector< std::vector< std::vector< Number > > > Aq_Aq_representor_innerprods
Definition: rb_evaluation.h:300
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::RBConstruction::get_normalize_rb_bound_in_greedy
bool get_normalize_rb_bound_in_greedy()
Definition: rb_construction.h:200
libMesh::RBConstruction::set_normalize_rb_bound_in_greedy
void set_normalize_rb_bound_in_greedy(bool normalize_rb_bound_in_greedy_in)
Get/set the boolean to indicate if we normalize the RB error in the greedy.
Definition: rb_construction.h:198
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::RBConstruction::Fq_vector
std::vector< std::unique_ptr< NumericVector< Number > > > Fq_vector
Vector storing the Q_f vectors in the affine decomposition of the right-hand side.
Definition: rb_construction.h:832
libMesh::RBEvaluation::RB_output_vectors
std::vector< std::vector< DenseVector< Number > > > RB_output_vectors
The vectors storing the RB output vectors.
Definition: rb_evaluation.h:275
libMesh::ENCODE
Definition: enum_xdr_mode.h:38
libMesh::RBConstruction::read_riesz_representors_from_files
virtual void read_riesz_representors_from_files(const std::string &riesz_representors_dir, const bool write_binary_residual_representors)
Read in all the Riesz representor data from files.
Definition: rb_construction.C:2140
libMesh::FEMContext::elem_fe_reinit
virtual void elem_fe_reinit(const std::vector< Point > *const pts=nullptr)
Reinitializes interior FE objects on the current geometric element.
Definition: fem_context.C:1436
libMesh::RBConstruction::truth_outputs
std::vector< Number > truth_outputs
Vector storing the truth output values from the most recent truth solve.
Definition: rb_construction.h:490
libMesh::RBConstruction::compute_residual_dual_norm_slow
Real compute_residual_dual_norm_slow(const unsigned int N)
The slow (but simple, non-error prone) way to compute the residual dual norm.
Definition: rb_construction.C:1819
libMesh::DofMap::attach_matrix
void attach_matrix(SparseMatrix< Number > &matrix)
Additional matrices may be handled with this DofMap.
Definition: dof_map.C:274
libMesh::RBParametrized::initialize_parameters
void initialize_parameters(const RBParameters &mu_min_in, const RBParameters &mu_max_in, const std::map< std::string, std::vector< Real >> &discrete_parameter_values)
Initialize the parameter ranges and set current_parameters.
Definition: rb_parametrized.C:60
libMesh::RBConstructionBase< LinearImplicitSystem >::get_last_local_training_index
numeric_index_type get_last_local_training_index() const
Get the last local index of the training parameters.
Definition: rb_construction_base.C:123
libMesh::RBConstruction::skip_residual_in_train_reduced_basis
bool skip_residual_in_train_reduced_basis
Boolean flag to indicate if we skip residual calculations in train_reduced_basis.
Definition: rb_construction.h:522
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::get_non_dirichlet_Aq
SparseMatrix< Number > * get_non_dirichlet_Aq(unsigned int q)
Get a pointer to non_dirichlet_Aq.
Definition: rb_construction.C:1884
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::FEMContext::get_element_fe
void get_element_fe(unsigned int var, FEGenericBase< OutputShape > *&fe) const
Accessor for interior finite element object for variable var for the largest dimension in the mesh.
Definition: fem_context.h:275
libMesh::System::solution
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition: system.h:1539
libMesh::SparseMatrix::add_matrix
virtual void add_matrix(const DenseMatrix< T > &dm, const std::vector< numeric_index_type > &rows, const std::vector< numeric_index_type > &cols)=0
Add the full matrix dm to the SparseMatrix.
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::ElemAssembly
ElemAssembly provides a per-element (interior and boundary) assembly functionality.
Definition: elem_assembly.h:38
libMesh::RBConstruction::non_dirichlet_Aq_vector
std::vector< std::unique_ptr< SparseMatrix< Number > > > non_dirichlet_Aq_vector
We may also need a second set of matrices/vectors that do not have the Dirichlet boundary conditions ...
Definition: rb_construction.h:845
libMesh::RBConstruction::normalize_rb_bound_in_greedy
bool normalize_rb_bound_in_greedy
This boolean indicates if we normalize the RB error in the greedy using RBEvaluation::get_error_bound...
Definition: rb_construction.h:861
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::RBConstruction::rb_assembly_expansion
RBAssemblyExpansion * rb_assembly_expansion
This member holds the (parameter independent) assembly functors that define the "affine expansion" of...
Definition: rb_construction.h:798
libMesh::RBConstructionBase< LinearImplicitSystem >::set_quiet_mode
void set_quiet_mode(bool quiet_mode_in)
Set the quiet_mode flag.
Definition: rb_construction_base.h:92
libMesh::NumericVector::set
virtual void set(const numeric_index_type i, const T value)=0
Sets v(i) = value.
value
static const bool value
Definition: xdr_io.C:56
libMesh::RBConstruction::load_basis_function
virtual void load_basis_function(unsigned int i)
Load the i^th RB function into the RBConstruction solution vector.
Definition: rb_construction.C:1305
libMesh::DofMap
This class handles the numbering of degrees of freedom on a mesh.
Definition: dof_map.h:176
libMesh::RBConstruction::output_dual_innerprods
std::vector< std::vector< Number > > output_dual_innerprods
The vector storing the dual norm inner product terms for each output.
Definition: rb_construction.h:496
libMesh::System::name
const std::string & name() const
Definition: system.h:2067
libMesh::RBConstruction::impose_internal_fluxes
bool impose_internal_fluxes
Boolean flag to indicate whether we impose "fluxes" (i.e.
Definition: rb_construction.h:537
libMesh::RBEvaluation::get_error_bound_normalization
virtual Real get_error_bound_normalization()
Definition: rb_evaluation.C:291
libMesh::DGFEMContext::dg_terms_are_active
bool dg_terms_are_active() const
Are the DG terms active, i.e.
Definition: dg_fem_context.h:232
libMesh::RBEvaluation
This class is part of the rbOOmit framework.
Definition: rb_evaluation.h:50
libMesh::RBConstruction::get_abs_training_tolerance
Real get_abs_training_tolerance()
Definition: rb_construction.h:193
libMesh::RBConstructionBase< LinearImplicitSystem >::serial_training_set
bool serial_training_set
This boolean flag indicates whether or not the training set should be the same on all processors.
Definition: rb_construction_base.h:247
libMesh::LinearSolver
This base class can be inherited from to provide interfaces to linear solvers from different packages...
Definition: linear_solver.h:69
libMesh::RBConstruction::load_rb_solution
virtual void load_rb_solution()
Load the RB solution from the most recent solve with rb_eval into this system's solution vector.
Definition: rb_construction.C:1800
libMesh::DiffContext::get_elem_jacobian
const DenseMatrix< Number > & get_elem_jacobian() const
Const accessor for element Jacobian.
Definition: diff_context.h:283
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::RBConstruction::get_rel_training_tolerance
Real get_rel_training_tolerance()
Definition: rb_construction.h:186
libMesh::RBConstruction::use_energy_inner_product
bool use_energy_inner_product
Boolean to indicate whether we're using the energy inner-product.
Definition: rb_construction.h:809
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::RBConstruction::training_error_bounds
std::vector< Real > training_error_bounds
Vector storing the values of the error bound for each parameter in the training set — the parameter g...
Definition: rb_construction.h:464
libMesh::RBConstruction::truth_assembly
virtual void truth_assembly()
Assemble the truth matrix and right-hand side for current_parameters.
Definition: rb_construction.C:805
libMesh::DGFEMContext::get_neighbor_neighbor_jacobian
const DenseMatrix< Number > & get_neighbor_neighbor_jacobian() const
Const accessor for element-neighbor Jacobian.
Definition: dg_fem_context.h:188
libMesh::RBConstruction::set_abs_training_tolerance
void set_abs_training_tolerance(Real new_training_tolerance)
Get/set the absolute tolerance for the basis training.
Definition: rb_construction.h:191
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::RBConstruction::get_Fq
NumericVector< Number > * get_Fq(unsigned int q)
Get a pointer to Fq.
Definition: rb_construction.C:1905
libMesh::NumericVector::l2_norm
virtual Real l2_norm() const =0
libMesh::RBConstruction::output_dual_innerprods_computed
bool output_dual_innerprods_computed
A boolean flag to indicate whether or not the output dual norms have already been computed — used to ...
Definition: rb_construction.h:775
libMesh::RBConstruction::non_dirichlet_inner_product_matrix
std::unique_ptr< SparseMatrix< Number > > non_dirichlet_inner_product_matrix
Definition: rb_construction.h:848
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::RBConstruction::assemble_all_affine_vectors
virtual void assemble_all_affine_vectors()
Assemble and store the affine RHS vectors.
Definition: rb_construction.C:950
libMesh::RBConstructionBase< LinearImplicitSystem >::quiet_mode
bool quiet_mode
Flag to indicate whether we print out extra information during the Offline stage.
Definition: rb_construction_base.h:239
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::RBConstruction::truth_solve
virtual Real truth_solve(int plot_solution)
Perform a "truth" solve, i.e.
Definition: rb_construction.C:1242
libMesh::LinearImplicitSystem::final_linear_residual
Real final_linear_residual() const
Definition: linear_implicit_system.h:169
libMesh::RBConstruction::get_non_dirichlet_output_vector
NumericVector< Number > * get_non_dirichlet_output_vector(unsigned int n, unsigned int q_l)
Get a pointer to non-Dirichlet output vector.
Definition: rb_construction.C:1943
libMesh::RBConstruction::system_type
virtual std::string system_type() const override
Definition: rb_construction.C:125
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::ConstCouplingRow
This proxy class acts like a container of indices from a single coupling row.
Definition: coupling_matrix.h:337
libMesh::DofMap::_dof_coupling
CouplingMatrix * _dof_coupling
Degree of freedom coupling.
Definition: dof_map.h:1434
libMesh::LinearImplicitSystem::_n_linear_iterations
unsigned int _n_linear_iterations
The number of linear iterations required to solve the linear system Ax=b.
Definition: linear_implicit_system.h:199
libMesh::RBEvaluation::resize_data_structures
virtual void resize_data_structures(const unsigned int Nmax, bool resize_error_bound_data=true)
Resize and clear the data vectors corresponding to the value of Nmax.
Definition: rb_evaluation.C:108
libMesh::DenseMatrix::el
virtual T el(const unsigned int i, const unsigned int j) const override
Definition: dense_matrix.h:118
libMesh::CouplingMatrix
This class defines a coupling matrix.
Definition: coupling_matrix.h:54
libMesh::Elem::neighbor_ptr
const Elem * neighbor_ptr(unsigned int i) const
Definition: elem.h:2085
libMesh::RBConstructionBase< LinearImplicitSystem >::get_local_n_training_samples
numeric_index_type get_local_n_training_samples() const
Get the total number of training samples local to this processor.
Definition: rb_construction_base.C:109
libMesh::TRI3SUBDIVISION
Definition: enum_elem_type.h:69
libMesh::RBEvaluation::get_rb_theta_expansion
RBThetaExpansion & get_rb_theta_expansion()
Get a reference to the rb_theta_expansion.
Definition: rb_evaluation.C:88
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::RBConstruction::assemble_inner_product_matrix
void assemble_inner_product_matrix(SparseMatrix< Number > *input_matrix, bool apply_dof_constraints=true)
Assemble the inner product matrix and store it in input_matrix.
Definition: rb_construction.C:841
libMesh::RBConstruction::compute_Fq_representor_innerprods
virtual void compute_Fq_representor_innerprods(bool compute_inner_products=true)
Compute the terms that are combined ‘online’ to determine the dual norm of the residual.
Definition: rb_construction.C:1730
libMesh::RBConstruction::set_context_solution_vec
virtual void set_context_solution_vec(NumericVector< Number > &vec)
Set current_local_solution = vec so that we can access vec from FEMContext during assembly.
Definition: rb_construction.C:797
libMesh::RBConstruction::assemble_all_output_vectors
virtual void assemble_all_output_vectors()
Assemble and store the output vectors.
Definition: rb_construction.C:988
libMesh::FEAbstract::attach_quadrature_rule
virtual void attach_quadrature_rule(QBase *q)=0
Provides the class with the quadrature rule.
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::Elem::n_sides
virtual unsigned int n_sides() const =0
libMesh::RBEvaluation::RB_Fq_vector
std::vector< DenseVector< Number > > RB_Fq_vector
Dense vector for the RHS.
Definition: rb_evaluation.h:265
libMesh::Tri3Subdivision
The Tri3Subdivision element is a three-noded subdivision surface shell element used in mechanics calc...
Definition: face_tri3_subdivision.h:40
libMesh::RBThetaExpansion
This class stores the set of RBTheta functor objects that define the "parameter-dependent expansion" ...
Definition: rb_theta_expansion.h:44
libMesh::Parameters::get
const T & get(const std::string &) const
Definition: parameters.h:421
libMesh::RBConstruction::Fq_representor_innerprods_computed
bool Fq_representor_innerprods_computed
A boolean flag to indicate whether or not the Fq representor norms have already been computed — used ...
Definition: rb_construction.h:574
libMesh::RBConstruction::set_Nmax
virtual void set_Nmax(unsigned int Nmax)
Definition: rb_construction.C:1300
libMesh::out
OStreamProxy out
libMesh::RBConstruction::get_inner_product_assembly
ElemAssembly & get_inner_product_assembly()
Definition: rb_construction.C:385
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::RBConstructionBase< LinearImplicitSystem >::initialize_training_parameters
virtual void initialize_training_parameters(const RBParameters &mu_min, const RBParameters &mu_max, unsigned int n_training_parameters, std::map< std::string, bool > log_param_scale, bool deterministic=true)
Initialize the parameter ranges and indicate whether deterministic or random training parameters shou...
Definition: rb_construction_base.C:181
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::RBConstruction::set_energy_inner_product
void set_energy_inner_product(const std::vector< Number > &energy_inner_product_coeffs_in)
Specify the coefficients of the A_q operators to be used in the energy inner-product.
Definition: rb_construction.C:396
libMesh::RBParametrized::is_discrete_parameter
bool is_discrete_parameter(const std::string &mu_name) const
Is parameter mu_name discrete?
Definition: rb_parametrized.C:373
libMesh::NumericVector::dot
virtual T dot(const NumericVector< T > &v) const =0
libMesh::ElemAssembly::boundary_assembly
virtual void boundary_assembly(FEMContext &)
Perform the element boundary assembly.
Definition: elem_assembly.h:62
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::DofMap::end_dof
dof_id_type end_dof(const processor_id_type proc) const
Definition: dof_map.h:692
libMesh::RBConstruction::get_rb_assembly_expansion
RBAssemblyExpansion & get_rb_assembly_expansion()
Definition: rb_construction.C:371
libMesh::RBEvaluation::greedy_param_list
std::vector< RBParameters > greedy_param_list
The list of parameters selected by the Greedy algorithm in generating the Reduced Basis associated wi...
Definition: rb_evaluation.h:247
libMesh::RBParametrized::get_parameter_min
Real get_parameter_min(const std::string &param_name) const
Get minimum allowable value of parameter param_name.
Definition: rb_parametrized.C:190
libMesh::RBConstruction::set_rb_construction_parameters
void set_rb_construction_parameters(unsigned int n_training_samples_in, bool deterministic_training_in, unsigned int training_parameters_random_seed_in, bool quiet_mode_in, unsigned int Nmax_in, Real rel_training_tolerance_in, Real abs_training_tolerance_in, bool normalize_rb_error_bound_in_greedy_in, RBParameters mu_min_in, RBParameters mu_max_in, std::map< std::string, std::vector< Real >> discrete_parameter_values_in, std::map< std::string, bool > log_scaling)
Set the state of this RBConstruction object based on the arguments to this function.
Definition: rb_construction.C:272
libMesh::EquationSystems::parameters
Parameters parameters
Data structure holding arbitrary parameters.
Definition: equation_systems.h:557
libMesh::RBConstruction::build_context
virtual std::unique_ptr< DGFEMContext > build_context()
Builds a DGFEMContext object with enough information to do evaluations on each element.
Definition: rb_construction.C:583