LCOV - code coverage report
Current view: top level - include/dirackernels - DiracKernelBase.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 1 1 100.0 %
Date: 2025-07-17 01:28:37 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //* This file is part of the MOOSE framework
       2             : //* https://mooseframework.inl.gov
       3             : //*
       4             : //* All rights reserved, see COPYRIGHT for full restrictions
       5             : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
       6             : //*
       7             : //* Licensed under LGPL 2.1, please see LICENSE for details
       8             : //* https://www.gnu.org/licenses/lgpl-2.1.html
       9             : 
      10             : #pragma once
      11             : 
      12             : // MOOSE includes
      13             : #include "DiracKernelInfo.h"
      14             : #include "ResidualObject.h"
      15             : #include "CoupleableMooseVariableDependencyIntermediateInterface.h"
      16             : #include "MaterialPropertyInterface.h"
      17             : #include "GeometricSearchInterface.h"
      18             : #include "MooseVariableField.h"
      19             : #include "MooseVariableInterface.h"
      20             : #include "BlockRestrictable.h"
      21             : 
      22             : /**
      23             :  * DiracKernelBase is the base class for all DiracKernel type classes.
      24             :  */
      25             : class DiracKernelBase : public ResidualObject,
      26             :                         public CoupleableMooseVariableDependencyIntermediateInterface,
      27             :                         public MaterialPropertyInterface,
      28             :                         protected GeometricSearchInterface,
      29             :                         public BlockRestrictable
      30             : {
      31             : public:
      32             :   static InputParameters validParams();
      33             : 
      34             :   DiracKernelBase(const InputParameters & parameters);
      35             : 
      36             :   /**
      37             :    * This gets called by computeOffDiagJacobian() at each quadrature point.
      38             :    */
      39             :   virtual Real computeQpOffDiagJacobian(unsigned int jvar);
      40             : 
      41             :   /**
      42             :    * Computes the off-diagonal Jacobian for variable jvar.
      43             :    */
      44             :   virtual void computeOffDiagJacobian(unsigned int jvar) override = 0;
      45             : 
      46             :   /**
      47             :    * This is where the DiracKernel should call addPoint() for each point it needs to have a
      48             :    * value distributed at.
      49             :    */
      50             :   virtual void addPoints() = 0;
      51             : 
      52             :   /**
      53             :    * Whether or not this DiracKernel has something to distribute on this element.
      54             :    */
      55             :   bool hasPointsOnElem(const Elem * elem);
      56             : 
      57             :   /**
      58             :    * Whether or not this DiracKernel has something to distribute at this Point.
      59             :    */
      60             :   bool isActiveAtPoint(const Elem * elem, const Point & p);
      61             : 
      62             :   /**
      63             :    * Remove all of the current points and elements.
      64             :    * NOTE: The points are still cached by id to find them fast
      65             :    */
      66             :   void clearPoints();
      67             : 
      68             :   /**
      69             :    * Clear the cache of points because the points may have moved
      70             :    */
      71             :   void clearPointsCaches();
      72             : 
      73             :   /**
      74             :    * Clear point cache when the mesh changes, so that element
      75             :    * coarsening, element deletion, and distributed mesh repartitioning
      76             :    * don't leave this with an invalid cache.
      77             :    */
      78          82 :   virtual void meshChanged() override { clearPointsCaches(); };
      79             : 
      80             : protected:
      81             :   /**
      82             :    * Add the physical x,y,z point located in the element "elem" to the list of points
      83             :    * this DiracKernel will be asked to evaluate a value at.
      84             :    */
      85             :   void addPoint(const Elem * elem, Point p, unsigned id = libMesh::invalid_uint);
      86             : 
      87             :   /**
      88             :    * This is a highly inefficient way to add a point where this DiracKernel needs to be
      89             :    * evaluated.
      90             :    *
      91             :    * This spawns a search for the element containing that point!
      92             :    */
      93             :   const Elem * addPoint(Point p, unsigned id = libMesh::invalid_uint);
      94             : 
      95             :   /**
      96             :    * Returns the user-assigned ID of the current Dirac point if it
      97             :    * exits, and libMesh::invalid_uint otherwise.  Can be used e.g. in
      98             :    * the computeQpResidual() function to determine the cached ID of
      99             :    * the current point, in case this information is relevant.
     100             :    */
     101             :   unsigned currentPointCachedID();
     102             : 
     103             :   ///< Current element
     104             :   const Elem * const & _current_elem;
     105             : 
     106             :   /// Coordinate system
     107             :   const Moose::CoordinateSystemType & _coord_sys;
     108             : 
     109             :   /// Place for storing Point/Elem information shared across all
     110             :   /// DiracKernel objects.
     111             :   DiracKernelInfo & _dirac_kernel_info;
     112             : 
     113             :   /// Place for storing Point/Elem information only for this DiracKernel
     114             :   DiracKernelInfo _local_dirac_kernel_info;
     115             : 
     116             :   /// The current point
     117             :   Point _current_point;
     118             : 
     119             :   /// Quadrature point index
     120             :   unsigned int _qp;
     121             :   /// Quadrature points
     122             :   const MooseArray<Point> & _q_point;
     123             :   /// Physical points
     124             :   const MooseArray<Point> & _physical_point;
     125             :   /// Quadrature rule
     126             :   const QBase * const & _qrule;
     127             :   /// Transformed Jacobian weights
     128             :   const MooseArray<Real> & _JxW;
     129             : 
     130             :   /// i-th, j-th index for enumerating shape and test functions
     131             :   unsigned int _i, _j;
     132             : 
     133             :   /// drop duplicate points or consider them in residual and Jacobian
     134             :   const bool _drop_duplicate_points;
     135             : 
     136             :   // @{ Point-not-found behavior
     137             :   enum class PointNotFoundBehavior
     138             :   {
     139             :     ERROR,
     140             :     WARNING,
     141             :     IGNORE
     142             :   };
     143             :   const PointNotFoundBehavior _point_not_found_behavior;
     144             :   // @}
     145             : 
     146             :   /// Whether Dirac sources can move during the simulation
     147             :   const bool _allow_moving_sources;
     148             : 
     149             :   /// Data structure for caching user-defined IDs which can be mapped to
     150             :   /// specific std::pair<const Elem*, Point> and avoid the PointLocator Elem lookup.
     151             :   typedef std::map<unsigned, std::pair<const Elem *, Point>> point_cache_t;
     152             :   point_cache_t _point_cache;
     153             : 
     154             :   /// Map from Elem* to a list of (Dirac point, id) pairs which can be used
     155             :   /// in a user's computeQpResidual() routine to determine the user-defined ID for
     156             :   /// the current Dirac point, if one exists.
     157             :   typedef std::map<const Elem *, std::vector<std::pair<Point, unsigned>>> reverse_cache_t;
     158             :   reverse_cache_t _reverse_point_cache;
     159             : 
     160             : private:
     161             :   /// This function is used internally when the Elem for a
     162             :   /// locally-cached point needs to be updated.  You must pass in a
     163             :   /// pointer to the old_elem whose data is to be updated, the
     164             :   /// new_elem to which the Point belongs, and the Point and id
     165             :   /// information.
     166             :   void updateCaches(const Elem * old_elem, const Elem * new_elem, Point p, unsigned id);
     167             : 
     168             :   /// A helper function for addPoint(Point, id) for when
     169             :   /// id != invalid_uint.
     170             :   const Elem * addPointWithValidId(Point p, unsigned id);
     171             : };

Generated by: LCOV version 1.14