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 : #include "GeneralUserObject.h" 13 : #include "Coupleable.h" 14 : #include "ScalarCoupleable.h" 15 : #include "MooseVariableDependencyInterface.h" 16 : #include "MooseVariable.h" 17 : #include "SubProblem.h" 18 : #include "NonlinearSystem.h" 19 : #include "Assembly.h" 20 : #include "FEProblem.h" 21 : #include "MooseMesh.h" 22 : 23 : #include "libmesh/elem.h" 24 : #include "libmesh/parallel_algebra.h" 25 : 26 : // Forward Declarations 27 : 28 : namespace libMesh 29 : { 30 : class Elem; 31 : class QBase; 32 : } 33 : 34 : /** 35 : * A base class that loops over elements and do things 36 : * 37 : * Notes: 38 : * 39 : * 1. this class is designed to enable more than one element-loop in the execution of user 40 : * objects. 41 : * It is necessary because in many numerical schemes, the data required in one element-loop 42 : * should be pre-computed from another element-loop. 43 : * 44 : * For example, in the workflow of a cell-centered finite volume method, 45 : * two element-loops are required in a specific sequence in user objects: 46 : * 47 : * First, an element-loop is requried to calculate the in-cell gradients of variables 48 : * using a piecewise linear reconstruction scheme. 49 : * 50 : * Second, another element-loop is required to calculate the limited in-cell gradients of 51 : * variables 52 : * based on the reconstructed gradients from the element and its face-neighboring elements. 53 : */ 54 : class ElementLoopUserObject : public GeneralUserObject, 55 : public BlockRestrictable, 56 : public Coupleable, 57 : public MooseVariableDependencyInterface 58 : { 59 : public: 60 : static InputParameters validParams(); 61 : 62 : ElementLoopUserObject(const InputParameters & parameters); 63 : ElementLoopUserObject(ElementLoopUserObject & x, Threads::split split); 64 : virtual ~ElementLoopUserObject(); 65 : 66 : virtual void initialize(); 67 : virtual void execute(); 68 : virtual void finalize(); 69 : 70 : virtual void pre(); 71 : virtual void preElement(const Elem * elem); 72 : virtual void onElement(const Elem * elem); 73 : virtual void onBoundary(const Elem * elem, unsigned int side, BoundaryID bnd_id); 74 : virtual void onInternalSide(const Elem * elem, unsigned int side); 75 : virtual void onInterface(const Elem * elem, unsigned int side, BoundaryID bnd_id); 76 : virtual void post(); 77 : virtual void subdomainChanged(); 78 47400 : virtual bool keepGoing() { return true; } 79 : 80 : virtual void meshChanged(); 81 : 82 : void join(const ElementLoopUserObject & /*y*/); 83 : 84 : protected: 85 : virtual void caughtMooseException(MooseException & e); 86 : 87 : MooseMesh & _mesh; 88 : 89 : const Elem * _current_elem; 90 : const Real & _current_elem_volume; 91 : unsigned int _current_side; 92 : const Elem * _current_neighbor; 93 : 94 : const MooseArray<Point> & _q_point; 95 : const QBase * const & _qrule; 96 : const MooseArray<Real> & _JxW; 97 : const MooseArray<Real> & _coord; 98 : 99 : /// true if we have cached interface elements, false if they need to be cached. We want to (re)cache only when mesh changed 100 : bool _have_interface_elems; 101 : /// List of element IDs that are on the processor boundary and need to be send to other processors 102 : std::set<dof_id_type> _interface_elem_ids; 103 : 104 : /// The subdomain for the current element 105 : SubdomainID _subdomain; 106 : 107 : /// The subdomain for the last element 108 : SubdomainID _old_subdomain; 109 : 110 : virtual void computeElement(); 111 : virtual void computeBoundary(); 112 : virtual void computeInternalSide(); 113 : virtual void computeInterface(); 114 : };