LCOV - code coverage report
Current view: top level - include/error_estimation - hp_coarsentest.h (source / functions) Hit Total Coverage
Test: libMesh/libmesh: #4229 (6a9aeb) with base 727f46 Lines: 0 1 0.0 %
Date: 2025-08-19 19:27:09 Functions: 0 2 0.0 %
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_HP_COARSENTEST_H
      21             : #define LIBMESH_HP_COARSENTEST_H
      22             : 
      23             : // Local Includes
      24             : #include "libmesh/dense_matrix.h"
      25             : #include "libmesh/dense_vector.h"
      26             : #include "libmesh/hp_selector.h"
      27             : #include "libmesh/id_types.h"
      28             : #include "libmesh/libmesh_common.h"
      29             : #include "libmesh/fe.h"         // MipsPro requires fe.h and quadrature.h
      30             : #include "libmesh/quadrature.h" // Required for inline deletion std::unique_ptrs<> in destructor
      31             : 
      32             : // C++ includes
      33             : #include <vector>
      34             : #include <memory>
      35             : 
      36             : #ifdef LIBMESH_ENABLE_AMR
      37             : 
      38             : namespace libMesh
      39             : {
      40             : 
      41             : // Forward Declarations
      42             : class Elem;
      43             : class Point;
      44             : class System;
      45             : template <typename T> class TensorValue;
      46             : template <typename T> class VectorValue;
      47             : typedef VectorValue<Real> RealVectorValue;
      48             : typedef TensorValue<Real> RealTensorValue;
      49             : typedef RealVectorValue RealGradient;
      50             : typedef RealTensorValue RealTensor;
      51             : 
      52             : 
      53             : /**
      54             :  * This class uses the error estimate given by different types of
      55             :  * derefinement (h coarsening or p reduction) to choose between h
      56             :  * refining and p elevation.
      57             :  * Currently we assume that a set of elements has already been flagged
      58             :  * for h refinement, and we may want to change some of those elements
      59             :  * to be flagged for p refinement.
      60             :  *
      61             :  * This code is currently experimental and will not produce optimal
      62             :  * hp meshes without significant improvement.
      63             :  *
      64             :  * \author Roy H. Stogner
      65             :  * \date 2006
      66             :  */
      67             : class HPCoarsenTest : public HPSelector
      68             : {
      69             : public:
      70             : 
      71             :   /**
      72             :    * Constructor.
      73             :    */
      74             :   HPCoarsenTest() : p_weight(1.0), _extra_order(1)
      75             :   {
      76             :     libmesh_experimental();
      77             :   }
      78             : 
      79             :   /**
      80             :    * This class cannot be (default) copy constructed/assigned because
      81             :    * it has unique_ptr members. Explicitly deleting these functions is
      82             :    * the best way to document this fact.
      83             :    */
      84             :   HPCoarsenTest (const HPCoarsenTest &) = delete;
      85             :   HPCoarsenTest & operator= (const HPCoarsenTest &) = delete;
      86             : 
      87             :   /**
      88             :    * Defaulted move ctor, move assignment operator, and destructor.
      89             :    */
      90             :   HPCoarsenTest (HPCoarsenTest &&) = default;
      91             :   HPCoarsenTest & operator= (HPCoarsenTest &&) = default;
      92           0 :   virtual ~HPCoarsenTest() = default;
      93             : 
      94             :   /**
      95             :    * This pure virtual function must be redefined
      96             :    * in derived classes to take a mesh flagged for h
      97             :    * refinement and potentially change the desired
      98             :    * refinement type.
      99             :    */
     100             :   virtual void select_refinement (System & system) override;
     101             : 
     102             :   /**
     103             :    * Because the coarsening test seems to always choose p refinement, we're
     104             :    * providing an option to make h refinement more likely
     105             :    */
     106             :   Real p_weight;
     107             : 
     108             :   /**
     109             :    * Increases or decreases the order of the quadrature rule used for numerical
     110             :    * integration.  The default \p extraorder is 1, because properly
     111             :    * integrating L2 error requires integrating the squares of terms
     112             :    * with order p+1, and 2p+2 is 1 higher than what we default to
     113             :    * using for reasonable mass matrix integration.
     114             :    */
     115             :   void extra_quadrature_order (const int extraorder)
     116             :   { _extra_order = extraorder; }
     117             : 
     118             : protected:
     119             :   /**
     120             :    * The helper function which adds individual fine element data to
     121             :    * the coarse element projection
     122             :    */
     123             :   void add_projection(const System &, const Elem *, unsigned int var);
     124             : 
     125             :   /**
     126             :    * The coarse element on which a solution projection is cached
     127             :    */
     128             :   Elem * coarse;
     129             : 
     130             :   /**
     131             :    * Global DOF indices for fine elements
     132             :    */
     133             :   std::vector<dof_id_type> dof_indices;
     134             : 
     135             :   /**
     136             :    * The finite element objects for fine and coarse elements
     137             :    */
     138             :   std::unique_ptr<FEBase> fe, fe_coarse;
     139             : 
     140             :   /**
     141             :    * The shape functions and their derivatives
     142             :    */
     143             :   const std::vector<std::vector<Real>> * phi, * phi_coarse;
     144             :   const std::vector<std::vector<RealGradient>> * dphi, * dphi_coarse;
     145             :   const std::vector<std::vector<RealTensor>> * d2phi, * d2phi_coarse;
     146             : 
     147             :   /**
     148             :    * Mapping jacobians
     149             :    */
     150             :   const std::vector<Real> * JxW;
     151             : 
     152             :   /**
     153             :    * Quadrature locations
     154             :    */
     155             :   const std::vector<Point> * xyz_values;
     156             :   std::vector<Point> coarse_qpoints;
     157             : 
     158             :   /**
     159             :    * The quadrature rule for the fine element
     160             :    */
     161             :   std::unique_ptr<QBase> qrule;
     162             : 
     163             :   /**
     164             :    * Linear system for projections
     165             :    */
     166             :   DenseMatrix<Number> Ke;
     167             :   DenseVector<Number> Fe;
     168             :   /**
     169             :    * Coefficients for projected coarse and projected
     170             :    * p-derefined solutions
     171             :    */
     172             :   DenseVector<Number> Uc;
     173             :   DenseVector<Number> Up;
     174             : 
     175             :   /**
     176             :    * Extra order to use for quadrature rule
     177             :    */
     178             :   int _extra_order;
     179             : };
     180             : 
     181             : } // namespace libMesh
     182             : 
     183             : #endif // #ifdef LIBMESH_ENABLE_AMR
     184             : 
     185             : #endif // LIBMESH_HP_COARSENTEST_H

Generated by: LCOV version 1.14