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

          Line data    Source code
       1             : // The libMesh Finite Element Library.
       2             : // Copyright (C) 2002-2025 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
       3             : 
       4             : // This library is free software; you can redistribute it and/or
       5             : // modify it under the terms of the GNU Lesser General Public
       6             : // License as published by the Free Software Foundation; either
       7             : // version 2.1 of the License, or (at your option) any later version.
       8             : 
       9             : // This library is distributed in the hope that it will be useful,
      10             : // but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      12             : // Lesser General Public License for more details.
      13             : 
      14             : // You should have received a copy of the GNU Lesser General Public
      15             : // License along with this library; if not, write to the Free Software
      16             : // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
      17             : 
      18             : 
      19             : 
      20             : #ifndef LIBMESH_SMOOTHNESS_ESTIMATOR_H
      21             : #define LIBMESH_SMOOTHNESS_ESTIMATOR_H
      22             : 
      23             : // Local Includes
      24             : #include "libmesh/point.h"
      25             : #include "libmesh/elem_range.h"
      26             : 
      27             : // C++ includes
      28             : #include <cstddef>
      29             : #include <vector>
      30             : 
      31             : namespace libMesh
      32             : {
      33             : 
      34             : // Forward Declarations
      35             : class ErrorVector;
      36             : class System;
      37             : class Elem;
      38             : enum Order : int;
      39             : 
      40             : /**
      41             :  * This class implements the Smoothness estimate.
      42             :  *
      43             :  * \author Arjun Kulathuvayal
      44             :  * \author Varis Carey
      45             :  * \author Benjamin S. Kirk
      46             :  * \date 2025
      47             :  */
      48             : class SmoothnessEstimator
      49             : {
      50             : public:
      51             : 
      52             :   /**
      53             :    * Constructor.
      54             :    */
      55             :   SmoothnessEstimator();
      56             : 
      57             :   /**
      58             :    * Copy/move ctor, copy/move assignment operator, and destructor are
      59             :    * all explicitly defaulted for this class.
      60             :    */
      61             :   SmoothnessEstimator (const SmoothnessEstimator &) = default;
      62             :   SmoothnessEstimator (SmoothnessEstimator &&) = default;
      63             :   SmoothnessEstimator & operator= (const SmoothnessEstimator &) = default;
      64             :   SmoothnessEstimator & operator= (SmoothnessEstimator &&) = default;
      65        1173 :   virtual ~SmoothnessEstimator() = default;
      66             : 
      67             :   /**
      68             :    * This function uses the Legendre expansion of solution to estimate coefficient
      69             :    * decay to quantify the solution smoothness on each cell. The estimated smoothness
      70             :    * is output in the vector (for time being, we use ErrorVector)
      71             :    * For element order 1, the least square fit of log|order| vs log |coefficients|
      72             :    * fails. This leads to pure h refinement.
      73             :    * \p smoothness_per_cell
      74             :    */
      75             :   virtual void estimate_smoothness (const System & system,
      76             :                                ErrorVector & smoothness_per_cell,
      77             :                                const NumericVector<Number> * solution_vector = nullptr);
      78             : 
      79             :   /**
      80             :    * Increases or decreases the order of the quadrature rule used for numerical
      81             :    * integration.  The default \p extraorder is 1, because properly
      82             :    * integrating L2 error requires integrating the squares of terms
      83             :    * with order p+1, and 2p+2 is 1 higher than what we default to
      84             :    * using for reasonable mass matrix integration.
      85             :    */
      86             :   void extra_quadrature_order (const int extraorder)
      87             :   { _extra_order = extraorder; }
      88             : 
      89             : protected:
      90             : 
      91             :   /**
      92             :    * \returns The Legendre polynomial basis function values at a point (x,y,z).
      93             :    */
      94             :   static std::vector<Real> legepoly(const unsigned int dim,
      95             :                                     const Order order,
      96             :                                     const Point p,
      97             :                                     const unsigned int matsize);
      98             : 
      99             :   /**
     100             :    * Extra order to use for quadrature rule
     101             :    */
     102             :   int _extra_order;
     103             : 
     104             :   /**
     105             :    * Computes slop in a linear regression
     106             :    */
     107             :   static Real compute_slope(int N, Real Sx, Real Sy, Real Sxx, Real Sxy);
     108             : 
     109             :   void reduce_smoothness (std::vector<ErrorVectorReal> & error_per_cell,
     110             :                           const Parallel::Communicator & comm);
     111             : 
     112             : private:
     113             : 
     114             :   /**
     115             :    * Class to compute the error contribution for a range
     116             :    * of elements. May be executed in parallel on separate threads.
     117             :    */
     118             :   class EstimateSmoothness
     119             :   {
     120             :   public:
     121          68 :     EstimateSmoothness (const System & sys,
     122             :                    const SmoothnessEstimator & ee,
     123        2414 :                    ErrorVector & epc) :
     124        2278 :       system(sys),
     125        2278 :       smoothness_estimator(ee),
     126        2414 :       smoothness_per_cell(epc)
     127          68 :     {}
     128             : 
     129             :     void operator()(const ConstElemRange & range) const;
     130             : 
     131             :   private:
     132             :     const System & system;
     133             :     const SmoothnessEstimator & smoothness_estimator;
     134             :     ErrorVector & smoothness_per_cell;
     135             :   };
     136             : 
     137             :   friend class EstimateSmoothness;
     138             : };
     139             : 
     140             : 
     141             : } // namespace libMesh
     142             : 
     143             : 
     144             : #endif // LIBMESH_SMOOTHNESS_ESTIMATOR_H

Generated by: LCOV version 1.14