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