LCOV - code coverage report
Current view: top level - include/reduced_basis - rb_parametrized.h (source / functions) Hit Total Coverage
Test: libMesh/libmesh: #4308 (b969c4) with base 7aa2c3 Lines: 1 1 100.0 %
Date: 2025-11-07 13:38:09 Functions: 1 2 50.0 %
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_PARAMETRIZED_H
      21             : #define LIBMESH_RB_PARAMETRIZED_H
      22             : 
      23             : // rbOOmit includes
      24             : #include "libmesh/rb_parameters.h"
      25             : 
      26             : // libMesh includes
      27             : #include "libmesh/reference_counted_object.h"
      28             : 
      29             : // C++ includes
      30             : #include <cstddef>
      31             : #include <vector>
      32             : 
      33             : namespace libMesh
      34             : {
      35             : 
      36             : /**
      37             :  * This class is part of the rbOOmit framework.
      38             :  *
      39             :  * This class defines basic functionality of
      40             :  * a parametrized object.
      41             :  *
      42             :  * \author David J. Knezevic
      43             :  * \date 2011
      44             :  */
      45          68 : class RBParametrized : public ReferenceCountedObject<RBParametrized>
      46             : {
      47             : public:
      48             : 
      49             :   /**
      50             :    * Constructor.
      51             :    */
      52             :   RBParametrized ();
      53             : 
      54             :   /**
      55             :    * Special functions.
      56             :    * - This simple class can be default copy/move constructed/assigned.
      57             :    * - Destructor is defaulted out-of-line.
      58             :    */
      59             :   RBParametrized (RBParametrized &&) = default;
      60             :   RBParametrized & operator= (RBParametrized &&) = default;
      61             :   RBParametrized (const RBParametrized &) = default;
      62             :   RBParametrized & operator= (const RBParametrized &) = default;
      63             :   virtual ~RBParametrized ();
      64             : 
      65             :   /**
      66             :    * Clear all the data structures associated with
      67             :    * the system.
      68             :    */
      69             :   virtual void clear ();
      70             : 
      71             :   /**
      72             :    * Initialize the parameter ranges and set current_parameters.
      73             :    * Parameter ranges are inclusive.
      74             :    * The input min/max RBParameters should have exactly 1 sample each.
      75             :    * Vector-valued samples are not currently supported for the min/max
      76             :    * parameters or for discrete parameters.
      77             :    */
      78             :   void initialize_parameters(const RBParameters & mu_min_in,
      79             :                              const RBParameters & mu_max_in,
      80             :                              const std::map<std::string, std::vector<Real>> & discrete_parameter_values);
      81             : 
      82             :   /**
      83             :    * Initialize the parameter ranges and set current_parameters.
      84             :    */
      85             :   void initialize_parameters(const RBParametrized & rb_parametrized);
      86             : 
      87             :   /**
      88             :    * Get the number of parameters.
      89             :    */
      90             :   unsigned int get_n_params() const;
      91             : 
      92             :   /**
      93             :    * Get the number of continuous parameters.
      94             :    */
      95             :   unsigned int get_n_continuous_params() const;
      96             : 
      97             :   /**
      98             :    * Get the number of discrete parameters.
      99             :    */
     100             :   unsigned int get_n_discrete_params() const;
     101             : 
     102             :   /**
     103             :    * Get the current parameters.
     104             :    */
     105             :   const RBParameters & get_parameters() const;
     106             : 
     107             :   /**
     108             :    * Set the current parameters to \p params
     109             :    * The parameters are checked for validity; an error is thrown if
     110             :    * the number of parameters or samples is different than expected.
     111             :    * We \return a boolean true if the new parameters are within the min/max
     112             :    * range, and false otherwise (but the parameters are set regardless).
     113             :    * Enabling the "verbose_mode" flag will also print more details.
     114             :    */
     115             :   bool set_parameters(const RBParameters & params);
     116             : 
     117             :   /**
     118             :    * Get an RBParameters object that specifies the minimum allowable value
     119             :    * for each parameter.
     120             :    */
     121             :   const RBParameters & get_parameters_min() const;
     122             : 
     123             :   /**
     124             :    * Get an RBParameters object that specifies the maximum allowable value
     125             :    * for each parameter.
     126             :    */
     127             :   const RBParameters & get_parameters_max() const;
     128             : 
     129             :   /**
     130             :    * Get minimum allowable value of parameter \p param_name.
     131             :    */
     132             :   Real get_parameter_min(const std::string & param_name) const;
     133             : 
     134             :   /**
     135             :    * Get maximum allowable value of parameter \p param_name.
     136             :    */
     137             :   Real get_parameter_max(const std::string & param_name) const;
     138             : 
     139             :   /**
     140             :    * Print the current parameters.
     141             :    */
     142             :   void print_parameters() const;
     143             : 
     144             :   /**
     145             :    * Write out the parameter ranges to files.
     146             :    */
     147             :   void write_parameter_data_to_files(const std::string & continuous_param_file_name,
     148             :                                      const std::string & discrete_param_file_name,
     149             :                                      const bool write_binary_data);
     150             : 
     151             :   /**
     152             :    * Read in the parameter ranges from files.
     153             :    */
     154             :   void read_parameter_data_from_files(const std::string & continuous_param_file_name,
     155             :                                       const std::string & discrete_param_file_name,
     156             :                                       const bool read_binary_data);
     157             : 
     158             :   /**
     159             :    * Is parameter \p mu_name discrete?
     160             :    */
     161             :   bool is_discrete_parameter(const std::string & mu_name) const;
     162             : 
     163             :   /**
     164             :    * Get a const reference to the discrete parameter values.
     165             :    */
     166             :   const std::map<std::string, std::vector<Real>> & get_discrete_parameter_values() const;
     167             : 
     168             :   /**
     169             :    * Print out all the discrete parameter values.
     170             :    */
     171             :   void print_discrete_parameter_values() const;
     172             : 
     173             :   /**
     174             :    * \returns The closest entry to \p value from \p list_of_values.
     175             :    */
     176             :   static Real get_closest_value(Real value, const std::vector<Real> & list_of_values);
     177             : 
     178             :   /**
     179             :    * Public boolean to toggle verbose mode.
     180             :    */
     181             :   bool verbose_mode;
     182             : 
     183             : private:
     184             : 
     185             :   /**
     186             :    * Write out the parameter ranges to file.
     187             :    */
     188             :   void write_parameter_ranges_to_file(const std::string & file_name,
     189             :                                       const bool write_binary);
     190             : 
     191             :   /**
     192             :    * Write out the discrete parameter values to file.
     193             :    */
     194             :   void write_discrete_parameter_values_to_file(const std::string & file_name,
     195             :                                                const bool write_binary_data);
     196             : 
     197             :   /**
     198             :    * Read in the parameter ranges from file. Initialize parameters
     199             :    * to the "minimum" parameter values.
     200             :    */
     201             :   void read_parameter_ranges_from_file(const std::string & file_name,
     202             :                                        const bool read_binary,
     203             :                                        RBParameters & param_min,
     204             :                                        RBParameters & param_max);
     205             : 
     206             :   /**
     207             :    * Read in the discrete parameter values from file, if we have any.
     208             :    */
     209             :   void read_discrete_parameter_values_from_file(const std::string & file_name,
     210             :                                                 const bool read_binary_data,
     211             :                                                 std::map<std::string, std::vector<Real>> & discrete_parameter_values_in);
     212             : 
     213             :   /**
     214             :    * Helper function to check that \p params is valid:
     215             :    *  - same number of parameters (error)
     216             :    *  - parameter values are within the min/max range (warning)
     217             :    *  - discrete values are correctly discrete within tolerance (warning)
     218             :    * Warnings are only printed if "verbose_mode" is true.
     219             :    */
     220             :   bool check_if_valid_params(const RBParameters & params) const;
     221             : 
     222             :   /**
     223             :    * Helper function to check if the specified value
     224             :    * is in the list of values (within a tolerance given
     225             :    * by \p tol).
     226             :    */
     227             :   static bool is_value_in_list(Real value, const std::vector<Real> & list_of_values, Real tol);
     228             : 
     229             :   //--------------- PRIVATE DATA MEMBERS ---------------//
     230             : 
     231             :   /**
     232             :    * Flag indicating whether the parameters have been initialized.
     233             :    */
     234             :   bool parameters_initialized;
     235             : 
     236             :   /**
     237             :    * Vector storing the current parameters.
     238             :    */
     239             :   RBParameters parameters;
     240             : 
     241             :   /**
     242             :    * Vectors that define the ranges (min and max) for the parameters.
     243             :    */
     244             :   RBParameters parameters_min;
     245             :   RBParameters parameters_max;
     246             : 
     247             :   /**
     248             :    * Map that defines the allowable values of any discrete parameters.
     249             :    */
     250             :   std::map<std::string, std::vector<Real>> _discrete_parameter_values;
     251             : };
     252             : 
     253             : } // namespace libMesh
     254             : 
     255             : 
     256             : #endif // LIBMESH_RB_PARAMETRIZED_H

Generated by: LCOV version 1.14