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 "UserObject.h" 14 : #include "BlockRestrictable.h" 15 : #include "ThreeMaterialPropertyInterface.h" 16 : #include "NeighborCoupleableMooseVariableDependencyIntermediateInterface.h" 17 : #include "TransientInterface.h" 18 : #include "RandomInterface.h" 19 : #include "ElementIDInterface.h" 20 : #include "MooseError.h" 21 : 22 : class MooseVariableFieldBase; 23 : 24 : namespace libMesh 25 : { 26 : class Elem; 27 : class QBase; 28 : } 29 : 30 : /** 31 : * This user object allows related evaluations on elements, boundaries, internal sides, 32 : * interfaces in one single place. DomainUserObject is still block restrictable. 33 : * While evaluations on elements, boundaries and internal sides always happen, 34 : * a parameter 'interface_boundaries' needs to be set to invoke evaluations on interfaces. 35 : * We require this parameter for interface evaluations because we want to enforce sanity 36 : * checks on coupling variables that are not defined on the domain this user object works on 37 : * but only are available on the other side of the interfaces. All sides of an interface must 38 : * connect with the subdomain of DomainUserObject. 39 : * With this user object, evaluations that would have to be put into ElementUserObject, 40 : * SideUserObject, InternalSideUserObject, and InterfaceUserObject separately may be combined. 41 : */ 42 : class DomainUserObject : public UserObject, 43 : public BlockRestrictable, 44 : public ThreeMaterialPropertyInterface, 45 : public NeighborCoupleableMooseVariableDependencyIntermediateInterface, 46 : public TransientInterface, 47 : public RandomInterface, 48 : public ElementIDInterface 49 : { 50 : public: 51 : static InputParameters validParams(); 52 : 53 : DomainUserObject(const InputParameters & parameters); 54 : 55 : void execute() override final; 56 : 57 : /** 58 : * execute method that is called during ComputeUserObjects::onElement 59 : */ 60 6016 : virtual void executeOnElement() {} 61 : 62 : /** 63 : * execute method that is called during ComputeUserObjects::onBoundary 64 : */ 65 7792 : virtual void executeOnBoundary() {} 66 : 67 : /** 68 : * execute method that is called during ComputeUserObjects::onInternalSide 69 : */ 70 3812 : virtual void executeOnInternalSide() {} 71 : 72 : /** 73 : * execute method that is called during ComputeUserObjects::onExternalSide 74 : */ 75 2124 : virtual void executeOnExternalSide(const Elem * /*elem*/, unsigned int /*side*/) {} 76 : 77 : /** 78 : * execute method that is called during ComputeUserObjects::onInterface 79 : */ 80 0 : virtual void executeOnInterface() {} 81 : 82 : /** 83 : * method that is called right before executeOnElement; sets the data to volumetric 84 : */ 85 : void preExecuteOnElement(); 86 : 87 : /** 88 : * method that is called right before executeOnBoundary; sets the data to face 89 : */ 90 : void preExecuteOnBoundary(); 91 : 92 : /** 93 : * method that is called right before executeOnInternalSide; sets the data to face 94 : */ 95 : void preExecuteOnInternalSide(); 96 : 97 : /** 98 : * method that is called right before executeOnInterface; sets the data to face 99 : */ 100 : void preExecuteOnInterface(); 101 : 102 : /** 103 : * Return whether this object should run \p executeOnInterface 104 : */ 105 : bool shouldExecuteOnInterface() const; 106 : 107 : void checkVariable(const MooseVariableFieldBase & variable) const override; 108 : 109 : protected: 110 209982 : const MooseArray<Point> & qPoints() const { return *_current_q_point; } 111 40912 : const QBase & qRule() const { return *_current_q_rule; } 112 261652 : const MooseArray<Real> & JxW() const { return *_current_JxW; } 113 261652 : const MooseArray<Real> & coord() const { return _coord; } 114 : const MooseArray<Point> & normals() const { return _normals; } 115 : 116 : /** 117 : * Routes through to \p Coupleable::getFieldVar, but also inserts the return variable into a set 118 : * of field variables to check on interface-connected blocks, as opposed to our blocks, when 119 : * performing our block-restriction integrity check. 120 : * The argument \p interfaces is optional specifying on what interfaces the variable is expected 121 : * to be available, i.e. the field variable is defined over elements out side of the domain but 122 : * connecting the subdomain with the interfaces. Default value means that the variable should be 123 : * available on all interfaces. 124 : * Note: a field variable on interfaces is not required to be defined on the subdomain of this 125 : * domain user object. 126 : */ 127 : const MooseVariableFieldBase * 128 : getInterfaceFieldVar(const std::string & var_name, 129 : unsigned int comp, 130 : const std::set<BoundaryID> * interfaces = nullptr); 131 : 132 : /// the Moose mesh 133 : MooseMesh & _mesh; 134 : 135 : /// The current element pointer (available during all execute functions) 136 : const Elem * const & _current_elem; 137 : 138 : /// The current element volume (available during all execute functions) 139 : const Real & _current_elem_volume; 140 : 141 : /// Current side of the current element (available during executeOnInternalSide() and 142 : /// executeOnBoundary() and executeOnInterface()) 143 : const unsigned int & _current_side; 144 : 145 : /// Current side of the current element (available during executeOnInternalSide() and 146 : /// executeOnBoundary() and executeOnInterface()) 147 : const Elem * const & _current_side_elem; 148 : 149 : /// Current side volume (available during executeOnInternalSide() and executeOnBoundary() and 150 : /// executeOnInterface()) 151 : const Real & _current_side_volume; 152 : 153 : /// The neighboring element (available during executeOnInternalSide() and executeOnInterface()) 154 : const Elem * const & _neighbor_elem; 155 : 156 : /// the neighboring element's volume (available during executeOnInternalSide() and 157 : /// executeOnInterface()) 158 : const Real & _current_neighbor_volume; 159 : 160 : /// The boundary ID (available during executeOnBoundary() and executeOnInterface()) 161 : const BoundaryID & _current_boundary_id; 162 : 163 : /// The unit norm at quadrature points on the element side/face from the current element 164 : /// perpendicular to the side 165 : const MooseArray<Point> & _normals; 166 : 167 : /// The set of boundary IDs on which this object should perform \p executeOnInterface 168 : std::set<BoundaryID> _interface_bnd_ids; 169 : 170 : /// The set of blocks connected to our blocks through boundaries of the \p _interface_bnd_ids data member 171 : std::map<BoundaryID, std::set<SubdomainID>> _interface_connected_blocks; 172 : 173 : private: 174 : void setVolumeData(); 175 : 176 : void setFaceData(); 177 : 178 : /// A pointer to the current volume/face quadrature points 179 : const MooseArray<Point> * _current_q_point; 180 : /// A pointer to the current volume/face quadrature rule 181 : const QBase * _current_q_rule; 182 : /// A pointer to the current JxW 183 : const MooseArray<Real> * _current_JxW; 184 : 185 : /// The quadrature points in physical space used in the element interior 186 : const MooseArray<Point> & _q_point; 187 : /// The quadrature rule used in the element interior 188 : const QBase * const & _qrule; 189 : /// The elemental Jacobian times quadrature weights in the element interior 190 : const MooseArray<Real> & _JxW; 191 : 192 : /// The quadrature points in physical space used on the element side/face 193 : const MooseArray<Point> & _q_point_face; 194 : /// The quadrature rule used on the element side/face 195 : const QBase * const & _qrule_face; 196 : /// The side element Jacobian times quadrature weights on the element side/face 197 : const MooseArray<Real> & _JxW_face; 198 : 199 : /// An array representing coordinate system volume modifications. Unity for Cartesian, 2piR for 200 : /// RZ, 4piR^2 for spherical 201 : const MooseArray<Real> & _coord; 202 : 203 : /// A map storing the set of boundaries where variables we wish to evaluate 204 : std::map<VariableName, std::set<BoundaryID>> _var_interfaces; 205 : }; 206 : 207 : inline void 208 0 : DomainUserObject::execute() 209 : { 210 0 : mooseError("Users of DomainUserObjects should call " 211 : "executeOnElement/executeOnBoundary/executeOnInternalSide"); 212 : } 213 : 214 : inline void 215 8726 : DomainUserObject::preExecuteOnElement() 216 : { 217 8726 : setVolumeData(); 218 8726 : } 219 : 220 : inline void 221 11324 : DomainUserObject::preExecuteOnBoundary() 222 : { 223 11324 : setFaceData(); 224 11324 : } 225 : 226 : inline void 227 13180 : DomainUserObject::preExecuteOnInternalSide() 228 : { 229 13180 : setFaceData(); 230 13180 : } 231 : 232 : inline void 233 1408 : DomainUserObject::preExecuteOnInterface() 234 : { 235 1408 : setFaceData(); 236 1408 : } 237 : 238 : inline void 239 8726 : DomainUserObject::setVolumeData() 240 : { 241 8726 : _current_q_point = &_q_point; 242 8726 : _current_q_rule = _qrule; 243 8726 : _current_JxW = &_JxW; 244 8726 : } 245 : 246 : inline void 247 25912 : DomainUserObject::setFaceData() 248 : { 249 25912 : _current_q_point = &_q_point_face; 250 25912 : _current_q_rule = _qrule_face; 251 25912 : _current_JxW = &_JxW_face; 252 25912 : } 253 : 254 : inline bool 255 2996 : DomainUserObject::shouldExecuteOnInterface() const 256 : { 257 2996 : return _interface_bnd_ids.count(_current_boundary_id); 258 : }