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 : * Computes the off-diagonal Jacobian for variable jvar. 38 : */ 39 : virtual void computeOffDiagJacobian(unsigned int jvar) override = 0; 40 : 41 : /** 42 : * This is where the DiracKernel should call addPoint() for each point it needs to have a 43 : * value distributed at. 44 : */ 45 : virtual void addPoints() = 0; 46 : 47 : /** 48 : * Whether or not this DiracKernel has something to distribute on this element. 49 : */ 50 : bool hasPointsOnElem(const Elem * elem); 51 : 52 : /** 53 : * Whether or not this DiracKernel has something to distribute at this Point. 54 : */ 55 : bool isActiveAtPoint(const Elem * elem, const Point & p); 56 : 57 : /** 58 : * Remove all of the current points and elements. 59 : * NOTE: The points are still cached by id to find them fast 60 : */ 61 : void clearPoints(); 62 : 63 : /** 64 : * Clear the cache of points because the points may have moved 65 : */ 66 : void clearPointsCaches(); 67 : 68 : /** 69 : * Clear point cache when the mesh changes, so that element 70 : * coarsening, element deletion, and distributed mesh repartitioning 71 : * don't leave this with an invalid cache. 72 : */ 73 89 : virtual void meshChanged() override { clearPointsCaches(); }; 74 : 75 : protected: 76 : /** 77 : * Add the physical x,y,z point located in the element "elem" to the list of points 78 : * this DiracKernel will be asked to evaluate a value at. 79 : */ 80 : void addPoint(const Elem * elem, Point p, unsigned id = libMesh::invalid_uint); 81 : 82 : /** 83 : * This is a highly inefficient way to add a point where this DiracKernel needs to be 84 : * evaluated. 85 : * 86 : * This spawns a search for the element containing that point! 87 : */ 88 : const Elem * addPoint(Point p, unsigned id = libMesh::invalid_uint); 89 : 90 : /** 91 : * Returns the user-assigned ID of the current Dirac point if it 92 : * exits, and libMesh::invalid_uint otherwise. Can be used e.g. in 93 : * the computeQpResidual() function to determine the cached ID of 94 : * the current point, in case this information is relevant. 95 : */ 96 : unsigned currentPointCachedID(); 97 : 98 : ///< Current element 99 : const Elem * const & _current_elem; 100 : 101 : /// Coordinate system 102 : const Moose::CoordinateSystemType & _coord_sys; 103 : 104 : /// Place for storing Point/Elem information shared across all 105 : /// DiracKernel objects. 106 : DiracKernelInfo & _dirac_kernel_info; 107 : 108 : /// Place for storing Point/Elem information only for this DiracKernel 109 : DiracKernelInfo _local_dirac_kernel_info; 110 : 111 : /// The current point 112 : Point _current_point; 113 : 114 : /// Quadrature point index 115 : unsigned int _qp; 116 : /// Quadrature points 117 : const MooseArray<Point> & _q_point; 118 : /// Physical points 119 : const MooseArray<Point> & _physical_point; 120 : /// Quadrature rule 121 : const QBase * const & _qrule; 122 : /// Transformed Jacobian weights 123 : const MooseArray<Real> & _JxW; 124 : 125 : /// i-th, j-th index for enumerating shape and test functions 126 : unsigned int _i, _j; 127 : 128 : /// drop duplicate points or consider them in residual and Jacobian 129 : const bool _drop_duplicate_points; 130 : 131 : // @{ Point-not-found behavior 132 : enum class PointNotFoundBehavior 133 : { 134 : ERROR, 135 : WARNING, 136 : IGNORE 137 : }; 138 : const PointNotFoundBehavior _point_not_found_behavior; 139 : // @} 140 : 141 : /// Whether Dirac sources can move during the simulation 142 : const bool _allow_moving_sources; 143 : 144 : /// Data structure for caching user-defined IDs which can be mapped to 145 : /// specific std::pair<const Elem*, Point> and avoid the PointLocator Elem lookup. 146 : typedef std::map<unsigned, std::pair<const Elem *, Point>> point_cache_t; 147 : point_cache_t _point_cache; 148 : 149 : /// Map from Elem* to a list of (Dirac point, id) pairs which can be used 150 : /// in a user's computeQpResidual() routine to determine the user-defined ID for 151 : /// the current Dirac point, if one exists. 152 : typedef std::map<const Elem *, std::vector<std::pair<Point, unsigned>>> reverse_cache_t; 153 : reverse_cache_t _reverse_point_cache; 154 : 155 : private: 156 : /// This function is used internally when the Elem for a 157 : /// locally-cached point needs to be updated. You must pass in a 158 : /// pointer to the old_elem whose data is to be updated, the 159 : /// new_elem to which the Point belongs, and the Point and id 160 : /// information. 161 : void updateCaches(const Elem * old_elem, const Elem * new_elem, Point p, unsigned id); 162 : 163 : /// A helper function for addPoint(Point, id) for when 164 : /// id != invalid_uint. 165 : const Elem * addPointWithValidId(Point p, unsigned id); 166 : };