LCOV - code coverage report
Current view: top level - include/reduced_basis - rb_scm_construction.h (source / functions) Hit Total Coverage
Test: libMesh/libmesh: #4229 (6a9aeb) with base 727f46 Lines: 5 6 83.3 %
Date: 2025-08-19 19:27:09 Functions: 3 7 42.9 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : #ifndef LIBMESH_RB_SCM_CONSTRUCTION_H
      21             : #define LIBMESH_RB_SCM_CONSTRUCTION_H
      22             : 
      23             : // Configuration data
      24             : #include "libmesh/libmesh_config.h"
      25             : 
      26             : // Currently, the RBSCMConstruction is only usable
      27             : // if SLEPc is enabled.
      28             : #if defined(LIBMESH_HAVE_SLEPC) && (LIBMESH_HAVE_GLPK)
      29             : 
      30             : // rbOOmit includes
      31             : #include "libmesh/rb_construction_base.h"
      32             : 
      33             : // libMesh includes
      34             : #include "libmesh/condensed_eigen_system.h"
      35             : 
      36             : // C++ includes
      37             : 
      38             : namespace libMesh
      39             : {
      40             : 
      41             : // Forward declarations
      42             : class RBSCMEvaluation;
      43             : 
      44             : /**
      45             :  * This class is part of the rbOOmit framework.
      46             :  *
      47             :  * RBSCMConstruction implements the the Successive Constraint Method (SCM)
      48             :  * for computing rigorous lower bounds for stability constants.
      49             :  *
      50             :  * \author David J. Knezevic
      51             :  * \date 2009
      52             :  */
      53           0 : class RBSCMConstruction : public RBConstructionBase<CondensedEigenSystem>
      54             : {
      55             : public:
      56             : 
      57             :   /**
      58             :    * Constructor.  Optionally initializes required
      59             :    * data structures.
      60             :    */
      61             :   RBSCMConstruction (EquationSystems & es,
      62             :                      const std::string & name_in,
      63             :                      const unsigned int number_in);
      64             : 
      65             :   /**
      66             :    * Special functions.
      67             :    * - This class has the same restrictions/defaults as its base class.
      68             :    * - Destructor is defaulted out-of-line
      69             :    */
      70             :   RBSCMConstruction (RBSCMConstruction &&) = default;
      71             :   RBSCMConstruction (const RBSCMConstruction &) = delete;
      72             :   RBSCMConstruction & operator= (const RBSCMConstruction &) = delete;
      73             :   RBSCMConstruction & operator= (RBSCMConstruction &&) = delete;
      74             :   virtual ~RBSCMConstruction ();
      75             : 
      76             :   /**
      77             :    * The type of system.
      78             :    */
      79             :   typedef RBSCMConstruction sys_type;
      80             : 
      81             :   /**
      82             :    * The type of the parent.
      83             :    */
      84             :   typedef RBConstructionBase<CondensedEigenSystem> Parent;
      85             : 
      86             :   /**
      87             :    * Clear all the data structures associated with
      88             :    * the system.
      89             :    */
      90             :   virtual void clear () override;
      91             : 
      92             :   /**
      93             :    * Set the RBSCMEvaluation object.
      94             :    */
      95             :   void set_rb_scm_evaluation(RBSCMEvaluation & rb_scm_eval_in);
      96             : 
      97             :   /**
      98             :    * Get a reference to the RBSCMEvaluation object.
      99             :    */
     100             :   RBSCMEvaluation & get_rb_scm_evaluation();
     101             : 
     102             :   /**
     103             :    * Get a reference to the RBThetaExpansion object.
     104             :    */
     105             :   RBThetaExpansion & get_rb_theta_expansion();
     106             : 
     107             :   /**
     108             :    * Clear and resize the SCM data vectors. Override
     109             :    * in subclass as necessary.
     110             :    */
     111             :   virtual void resize_SCM_vectors ();
     112             : 
     113             :   /**
     114             :    * Read in the parameters from file specified by \p parameters_filename
     115             :    * and set the this system's member variables accordingly.
     116             :    */
     117             :   virtual void process_parameters_file(const std::string & parameters_filename);
     118             : 
     119             :   /**
     120             :    * Print out info that describes the current setup of this RBSCMConstruction.
     121             :    */
     122             :   virtual void print_info();
     123             : 
     124             :   /**
     125             :    * This function is called before truth eigensolves in
     126             :    * compute_SCM_bounding_box and evaluate_stability_constant.
     127             :    * Override it to set specific properties to optimize
     128             :    * eigensolver performance. The argument refers to
     129             :    * the operator index in compute_SCM_bounding_box;
     130             :    * a negative value of the argument indicates we are
     131             :    * not performing a bounding box solve.
     132             :    */
     133          13 :   virtual void set_eigensolver_properties(int) {}
     134             : 
     135             :   /**
     136             :    * Set the name of the associated RB system --- we need
     137             :    * this to load the (symmetrized) affine operators.
     138             :    */
     139             :   void set_RB_system_name(const std::string & new_name)
     140             :   { RB_system_name = new_name; }
     141             : 
     142             :   /**
     143             :    * Get/set SCM_training_tolerance: tolerance for SCM greedy.
     144             :    */
     145           1 :   Real get_SCM_training_tolerance() const                         { return SCM_training_tolerance; }
     146           1 :   void set_SCM_training_tolerance(Real SCM_training_tolerance_in) { this->SCM_training_tolerance = SCM_training_tolerance_in; }
     147             : 
     148             :   /**
     149             :    * Perform the SCM greedy algorithm to develop a lower bound
     150             :    * over the training set.
     151             :    */
     152             :   virtual void perform_SCM_greedy();
     153             : 
     154             :   /**
     155             :    * Attach the deflation space defined by the specified vector, can
     156             :    * be useful in solving constrained eigenvalue problems.
     157             :    *
     158             :    * This function is called at the start of perform_SCM_greedy and by
     159             :    * default is does nothing. Override in subclass to attach a specific
     160             :    * vector.
     161             :    */
     162           1 :   virtual void attach_deflation_space() {}
     163             : 
     164             : protected:
     165             : 
     166             :   /**
     167             :    * Add the scaled symmetrized affine matrix from the
     168             :    * associated RBSystem to matrix_A.
     169             :    */
     170             :   virtual void add_scaled_symm_Aq(unsigned int q_a, Number scalar);
     171             : 
     172             :   /**
     173             :    * Copy over the matrix to store in matrix_B,
     174             :    * usually this is the mass or inner-product
     175             :    * matrix, but needs to be implemented in subclass.
     176             :    */
     177             :   virtual void load_matrix_B();
     178             : 
     179             :   /**
     180             :    * Compute the SCM bounding box.
     181             :    */
     182             :   virtual void compute_SCM_bounding_box();
     183             : 
     184             :   /**
     185             :    * Compute the stability constant for current_parameters
     186             :    * by solving a generalized eigenvalue problem over the
     187             :    * truth space.
     188             :    */
     189             :   virtual void evaluate_stability_constant();
     190             : 
     191             :   /**
     192             :    * Enrich C_J by adding the element of SCM_training_samples
     193             :    * that has the largest gap between alpha_LB and alpha_LB.
     194             :    */
     195             :   virtual void enrich_C_J(unsigned int new_C_J_index);
     196             : 
     197             :   /**
     198             :    * Compute upper and lower bounds for each SCM training point.
     199             :    * Return a pair containing the maximum SCM error, and the
     200             :    * index of the parameter in the training set at which the max
     201             :    * error is achieved.
     202             :    */
     203             :   virtual std::pair<unsigned int,Real> compute_SCM_bounds_on_training_set();
     204             : 
     205             :   /**
     206             :    * Compute the inner product between two vectors using the system's
     207             :    * matrix_B.
     208             :    */
     209             :   Number B_inner_product(const NumericVector<Number> & v, const NumericVector<Number> & w) const;
     210             : 
     211             :   /**
     212             :    * Compute the inner product between two vectors using
     213             :    * matrix Aq.
     214             :    */
     215             :   Number Aq_inner_product(unsigned int q,
     216             :                           const NumericVector<Number> & v,
     217             :                           const NumericVector<Number> & w);
     218             : 
     219             :   /**
     220             :    * Helper function which provides an error
     221             :    * indicator to be used in the SCM greedy.
     222             :    * Override in subclasses to specialize behavior.
     223             :    */
     224         700 :   virtual Real SCM_greedy_error_indicator(Real LB, Real UB) { return fabs(UB-LB)/fabs(UB); }
     225             : 
     226             :   //----------- PROTECTED DATA MEMBERS -----------//
     227             : 
     228             :   /**
     229             :    * Tolerance which controls when to terminate the SCM Greedy.
     230             :    */
     231             :   Real SCM_training_tolerance;
     232             : 
     233             :   /**
     234             :    * The name of the associated RB system.
     235             :    */
     236             :   std::string RB_system_name;
     237             : 
     238             : private:
     239             : 
     240             :   /**
     241             :    * The current RBSCMEvaluation object we are using to
     242             :    * perform the Evaluation stage of the SCM.
     243             :    */
     244             :   RBSCMEvaluation * rb_scm_eval;
     245             : };
     246             : 
     247             : } // namespace libMesh
     248             : 
     249             : #endif // LIBMESH_HAVE_SLEPC && LIBMESH_HAVE_GLPK
     250             : 
     251             : #endif // LIBMESH_RB_SCM_CONSTRUCTION_H

Generated by: LCOV version 1.14