26#include "libmesh/threads.h"
27#include "libmesh/elem.h"
28#include "libmesh/fe_map.h"
32 _nl(fe_problem.currentNonlinearSystem()),
34 _integrated_bcs(_nl.getIntegratedBCWarehouse()),
35 _dg_kernels(_nl.getDGKernelWarehouse()),
36 _interface_kernels(_nl.getInterfaceKernelWarehouse()),
37 _kernels(_nl.getKernelWarehouse()),
38 _hdg_kernels(_nl.getHDGKernelWarehouse()),
39 _has_active_objects(_integrated_bcs.hasActiveObjects() || _dg_kernels.hasActiveObjects() ||
40 _interface_kernels.hasActiveObjects() || _kernels.hasActiveObjects() ||
41 _fe_problem.haveFV()),
42 _should_execute_dg(false)
50 _num_cached(x._num_cached),
51 _integrated_bcs(x._integrated_bcs),
52 _dg_kernels(x._dg_kernels),
53 _interface_kernels(x._interface_kernels),
55 _tag_kernels(x._tag_kernels),
56 _hdg_kernels(x._hdg_kernels),
57 _has_active_objects(x._has_active_objects),
58 _should_execute_dg(x._should_execute_dg)
81 std::set<MooseVariableFEBase *> needed_moose_vars;
88 std::set<TagID> needed_fe_var_vector_tags;
97 std::unordered_set<unsigned int> needed_mat_props;
109 .template condition<AttribSysNum>(
_nl.
number())
110 .template condition<AttribSystem>(
"FVElementalKernel")
111 .template condition<AttribSubdomains>(
_subdomain)
112 .template condition<AttribThread>(
_tid)
116 const auto & fv_mv_deps = fv_kernel->getMooseVariableDependencies();
117 needed_moose_vars.insert(fv_mv_deps.begin(), fv_mv_deps.end());
118 const auto & fv_mp_deps = fv_kernel->getMatPropDependencies();
119 needed_mat_props.insert(fv_mp_deps.begin(), fv_mp_deps.end());
154 for (
const auto & kernel : kernels)
165 const unsigned int side,
167 const Elem *
const lower_d_elem )
189 for (
const auto & bc : bcs)
190 if (bc->shouldApply())
201 const Elem * neighbor = elem->neighbor_ptr(side);
203 if (neighbor->active())
233 std::vector<const Elem *> fine_neighbors;
234 neighbor->active_family_tree_by_neighbor(fine_neighbors, elem);
235 for (
const Elem * fine_neighbor : fine_neighbors)
245 const Elem * fine_neighbor)
250 "' is defined on boundary ",
252 ", whose primary (boundary-tagged) side is coarser than its paired side. This "
253 "case is not supported with a displaced mesh problem: the displaced problem's "
254 "assembly is not reinitialized on these faces, and the borrowed integration "
255 "weight used to handle the mismatched refinement is not AD-differentiable with "
256 "respect to mesh displacement.");
258 const unsigned int fine_side = fine_neighbor->which_neighbor_am_i(elem);
265 current_assembly.
reinitElemFaceRef(fine_neighbor, fine_side, TOLERANCE,
nullptr,
nullptr);
271 std::vector<Point> elem_side_ref_points;
273 elem_side_elem.dim(), &elem_side_elem, fine_phys_points, elem_side_ref_points);
278 current_assembly.
reinitElemFaceRef(elem, side, TOLERANCE, &elem_side_ref_points,
nullptr);
280 std::vector<Real> elem_ref_weights(fine_phys_JxW.size());
281 for (
const auto qp : index_range(elem_ref_weights))
282 elem_ref_weights[qp] = fine_phys_JxW[qp] / elem_dummy_JxW[qp];
300 .
reinitElemFaceRef(elem, side, TOLERANCE, &elem_side_ref_points, &elem_ref_weights);
328 for (
const auto & interface_kernel : int_ks)
338 const Elem * neighbor = elem->neighbor_ptr(side);
373 bool has_interface_kernels =
false;
374 for (
const auto bid : boundary_ids)
376 has_interface_kernels =
true;
378 if (has_interface_kernels)
383 " is missing a neighbor (hence identified as an external side) but "
384 "has interface kernel(s) defined on the boundary.");
391 for (
const auto & dg_kernel : dgks)
392 if (dg_kernel->hasBlocks(neighbor->subdomain_id()))
399 compute(cast_ref<ResidualObject &>(kernel));
405 compute(cast_ref<ResidualObject &>(kernel));
411 compute(cast_ref<ResidualObject &>(bc));
417 compute(cast_ref<ResidualObject &>(dg));
423 compute(cast_ref<ResidualObject &>(ik));
445 console <<
"[DBG] Beginning elemental loop to compute " +
objectType() +
" on " << execute_on
448 console <<
"[DBG] Execution order on each element:" << std::endl;
449 console <<
"[DBG] - kernels on element quadrature points" << std::endl;
450 console <<
"[DBG] - finite volume elemental kernels on element" << std::endl;
451 console <<
"[DBG] - integrated boundary conditions on element side quadrature points"
453 console <<
"[DBG] - DG kernels on element side quadrature points" << std::endl;
454 console <<
"[DBG] - interface kernels on element side quadrature points" << std::endl;);
471 console <<
"[DBG] Ordering of " +
objectType() +
" Objects on block " << block_name <<
" ("
475 console <<
"[DBG] Ordering of kernels:" << std::endl;
480 console <<
"[DBG] Ordering of FV elemental kernels:" << std::endl;
481 std::string fvkernels =
486 { return str_out +
" " + kernel->name(); });
491 console <<
"[DBG] Ordering of DG kernels:" << std::endl;
497 console <<
"[DBG] No Active " +
objectType() +
" Objects on block " << block_name <<
" ("
513 console <<
"[DBG] Ordering of " +
objectType() +
" Objects on boundary " << b_name <<
" (" << bid
518 console <<
"[DBG] Ordering of integrated boundary conditions:" << std::endl;
527 console <<
"[DBG] Ordering of interface kernels:" << std::endl;
536 const unsigned int side,
538 const Elem *
const lower_d_elem)
boundary_id_type BoundaryID
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Keeps track of stuff related to assembling.
void reinitElemFaceRef(const Elem *elem, unsigned int elem_side, Real tolerance, const std::vector< Point > *const pts=nullptr, const std::vector< Real > *const weights=nullptr)
Reinitialize FE data for the given element on the given side, optionally with a given set of referenc...
const MooseArray< Point > & qPointsFace() const
Returns the reference to the current quadrature being used.
const MooseArray< Real > & JxWFace() const
Returns the reference to the transformed jacobian weights on a current face.
virtual void reinitElemFace(const Elem *elem, unsigned int side, THREAD_ID tid) override
Reinit assembly info for a side of an element.
Serves as a base class for DGKernel and ADDGKernel.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
virtual void reinitNeighborPhys(const Elem *neighbor, unsigned int neighbor_side, const std::vector< Point > &physical_points, const THREAD_ID tid) override
virtual bool haveFV() const override
returns true if this problem includes/needs finite volume functionality.
void reinitMaterialsFace(SubdomainID blk_id, const THREAD_ID tid, bool swap_stateful=true, const std::deque< MaterialBase * > *reinit_mats=nullptr)
reinit materials on element faces
AuxiliarySystem & getAuxiliarySystem()
virtual void reinitOffDiagScalars(const THREAD_ID tid) override
virtual std::size_t numNonlinearSystems() const override
virtual void swapBackMaterialsFace(const THREAD_ID tid)
virtual std::shared_ptr< const DisplacedProblem > getDisplacedProblem() const
const MaterialWarehouse & getMaterialWarehouse() const
virtual void reinitElemNeighborAndLowerD(const Elem *elem, unsigned int side, const THREAD_ID tid) override
void reinitMaterialsNeighbor(SubdomainID blk_id, const THREAD_ID tid, bool swap_stateful=true, const std::deque< MaterialBase * > *reinit_mats=nullptr)
reinit materials on the neighboring element face
virtual void swapBackMaterialsNeighbor(const THREAD_ID tid)
void prepareMaterials(const std::unordered_set< unsigned int > &consumer_needed_mat_props, const SubdomainID blk_id, const THREAD_ID tid)
Add the MooseVariables and the material properties that the current materials depend on to the depend...
void reinitElemFace(const Elem *elem, unsigned int side, BoundaryID, const THREAD_ID tid)
virtual void reinitLowerDElem(const Elem *lower_d_elem, const THREAD_ID tid, const std::vector< Point > *const pts=nullptr, const std::vector< Real > *const weights=nullptr) override
const ExecFlagType & getCurrentExecuteOnFlag() const
Return/set the current execution flag.
virtual unsigned int currentNlSysNum() const override
void reinitMaterialsFaceOnBoundary(const BoundaryID boundary_id, const SubdomainID blk_id, const THREAD_ID tid, const bool swap_stateful=true, const std::deque< MaterialBase * > *const reinit_mats=nullptr)
reinit materials on element faces on a boundary (internal or external) This specific routine helps us...
void reinitMaterialsBoundary(BoundaryID boundary_id, const THREAD_ID tid, bool swap_stateful=true, const std::deque< MaterialBase * > *reinit_mats=nullptr)
reinit materials on a boundary
virtual void setActiveElementalMooseVariables(const std::set< MooseVariableFEBase * > &moose_vars, const THREAD_ID tid) override
Set the MOOSE variables to be reinited on each element.
virtual void swapBackMaterials(const THREAD_ID tid)
virtual void setActiveFEVariableCoupleableVectorTags(std::set< TagID > &vtags, const THREAD_ID tid) override
bool shouldPrintExecution(const THREAD_ID tid) const
Check whether the problem should output execution orders at this time.
virtual Assembly & assembly(const THREAD_ID tid, const unsigned int sys_num) override
TheWarehouse & theWarehouse() const
NonlinearSystemBase & getNonlinearSystemBase(const unsigned int sys_num)
virtual void subdomainSetup(SubdomainID subdomain, const THREAD_ID tid)
void reinitMaterialsNeighborOnBoundary(const BoundaryID boundary_id, const SubdomainID blk_id, const THREAD_ID tid, const bool swap_stateful=true, const std::deque< MaterialBase * > *const reinit_mats=nullptr)
reinit materials on neighbor element (usually faces) on a boundary (internal or external) This specif...
void reinitMaterialsInterface(BoundaryID boundary_id, const THREAD_ID tid, bool swap_stateful=true)
virtual void reinitNeighbor(const Elem *elem, unsigned int side, const THREAD_ID tid) override
virtual void setNeighborSubdomainID(const Elem *elem, unsigned int side, const THREAD_ID tid) override
FVElemental is used for calculating residual contributions from volume integral terms of a PDE where ...
Base class for deriving any boundary condition of a integrated type.
InterfaceKernelBase is the base class for all InterfaceKernel type classes.
This is the common base class for the three main kernel types implemented in MOOSE,...
std::vector< T > stdVector() const
Extremely inefficient way to produce a std::vector from a MooseArray!
const std::string & getBoundaryName(const BoundaryID boundary_id) const
Return the name of the boundary given the id.
const std::string & getSubdomainName(SubdomainID subdomain_id) const
Return the name of a block given an id.
std::vector< BoundaryID > getBoundaryIDs(const Elem *const elem, const unsigned short int side) const
Returns a vector of boundary IDs for the requested element on the requested side.
unsigned int size(THREAD_ID tid=0) const
Return how many kernels we store in the current warehouse.
std::string activeObjectsToFormattedString(THREAD_ID tid=0, const std::string &prefix="[DBG]") const
Output the active content of the warehouse to a string, meant to be output to the console.
const std::map< SubdomainID, std::vector< std::shared_ptr< T > > > & getActiveBlockObjects(THREAD_ID tid=0) const
void updateBlockMatPropDependency(SubdomainID id, std::unordered_set< unsigned int > &needed_mat_props, THREAD_ID tid=0, const bool producer_only=false) const
void updateBlockFEVariableCoupledVectorTagDependency(SubdomainID id, std::set< TagID > &needed_fe_var_vector_tags, THREAD_ID tid=0) const
void updateBoundaryVariableDependency(std::set< MooseVariableFieldBase * > &needed_moose_vars, THREAD_ID tid=0) const
void updateBlockVariableDependency(SubdomainID id, std::set< MooseVariableFieldBase * > &needed_moose_vars, THREAD_ID tid=0) const
const std::map< BoundaryID, std::vector< std::shared_ptr< T > > > & getActiveBoundaryObjects(THREAD_ID tid=0) const
bool hasActiveBlockObjects(THREAD_ID tid=0) const
void updateBoundaryMatPropDependency(std::unordered_set< unsigned int > &needed_mat_props, THREAD_ID tid=0, const bool producer_only=false) const
bool hasActiveBoundaryObjects(THREAD_ID tid=0) const
MooseObjectTagWarehouse< KernelBase > & _kernels
virtual std::string objectType() const
Return what the loops is meant to compute.
virtual void onBoundary(const Elem *elem, unsigned int side, BoundaryID bnd_id, const Elem *lower_d_elem=nullptr) override
Called when doing boundary assembling.
bool shouldComputeInternalSide(const Elem &elem, const Elem &neighbor) const override
Whether to compute the internal side for the provided element-neighbor pair.
virtual void onInternalSide(const Elem *elem, unsigned int side) override
Called when doing internal edge assembling.
NonlinearThread(FEProblemBase &fe_problem)
void onInterfaceWithHRefinementMismatch(const Elem *elem, unsigned int side, BoundaryID bnd_id, const Elem *fine_neighbor)
Compute and accumulate the interface kernel contribution from a single active fine neighbor when elem...
MooseObjectTagWarehouse< IntegratedBCBase > & _integrated_bcs
Reference to BC storage structures.
virtual void accumulateNeighbor()=0
Add neighbor residual/Jacobian into assembly global data.
virtual void operator()(const ConstElemRange &range, bool bypass_threading=false) override
virtual void determineObjectWarehouses()=0
Determine the objects we will actually compute based on vector/matrix tag information.
virtual void computeOnInterface(BoundaryID bnd_id)
void prepareFace(const Elem *elem, unsigned int side, BoundaryID bnd_id=Moose::INVALID_BOUNDARY_ID, const Elem *lower_d_elem=nullptr)
Reinitialize variables and materials on a face.
MooseObjectWarehouse< InterfaceKernelBase > * _ik_warehouse
bool _subdomain_has_dg
Whether the subdomain has DGKernels.
virtual void computeOnBoundary(BoundaryID bnd_id, const Elem *lower_d_elem)
MooseObjectTagWarehouse< DGKernelBase > & _dg_kernels
Reference to DGKernel storage structure.
virtual void post() override
Called after the element range loop.
virtual void accumulateNeighborLower()=0
Add neighbor and lower residual/Jacobian into assembly global data.
void printBlockExecutionInformation() const override
Print list of specific objects executed on each block and in which order.
virtual void accumulate()=0
Add element residual/Jacobian into assembly global data.
virtual void onExternalSide(const Elem *elem, unsigned int side) override
Called when iterating over external sides (no side neighbor)
virtual void compute(ResidualObject &ro)=0
Will dispatch to computeResidual/computeJacobian/computeResidualAndJacobian based on the derived clas...
virtual void computeOnElement()
virtual void computeOnInternalFace()=0
std::vector< FVElementalKernel * > _fv_kernels
Current subdomain FVElementalKernels.
bool _subdomain_has_hdg
Whether the subdomain has HDGKernels.
NonlinearSystemBase & _nl
Reference to the underlying NonlinearSystemBase.
void printBoundaryExecutionInformation(const unsigned int bid) const override
Print list of specific objects executed on each boundary and in which order.
virtual void subdomainChanged() override
Called every time the current subdomain changes (i.e.
libMesh::ElemSideBuilder _elem_side_builder
Builds (and caches) the side element for elem/side pairs in onInterfaceWithHRefinementMismatch.
const bool _has_active_objects
Whether there are any active residual objects; otherwise we will do an early return.
MooseObjectWarehouse< DGKernelBase > * _dg_warehouse
MooseObjectWarehouse< HDGKernel > * _hdg_warehouse
MooseObjectWarehouse< KernelBase > * _tag_kernels
void printGeneralExecutionInformation() const override
Print information about the loop, mostly order of execution of objects.
virtual ~NonlinearThread()
MooseObjectTagWarehouse< InterfaceKernelBase > & _interface_kernels
Reference to interface kernel storage structure.
virtual void accumulateLower()=0
Add lower-d residual/Jacobian into assembly global data.
virtual void onInterface(const Elem *elem, unsigned int side, BoundaryID bnd_id) override
Called when doing interface assembling.
virtual void postElement(const Elem *) override
Called after the element assembly is done (including surface assembling)
MooseObjectWarehouse< IntegratedBCBase > * _ibc_warehouse
bool _should_execute_dg
Whether DG kernels should be executed for a given elem-neighbor pairing.
virtual void onElement(const Elem *elem) override
Assembly of the element (not including surface assembly)
const ConsoleStream & console() const
Return console handle.
The "SwapBackSentinel" class's destructor guarantees that FEProblemBase::swapBackMaterials{Face,...
unsigned int number() const
Gets the number of this system.
virtual void reinitElemFace(const Elem *elem, unsigned int side, THREAD_ID tid)
Reinit assembly info for a side of an element.
const std::vector< MooseVariableScalar * > & getScalarVariables(THREAD_ID tid)
std::vector< T * > & queryInto(std::vector< T * > &results, Args &&... args)
queryInto executes the query and stores the results in the given vector.
Query query()
query creates and returns an initialized a query object for querying objects from the warehouse.
virtual void operator()(const RangeType &range, bool bypass_threading=false)
SubdomainID _subdomain
The subdomain for the current element.
std::set< BoundaryID > _boundaries_exec_printed
Keep track of which boundaries were visited.
virtual bool shouldComputeInternalSide(const Elem &elem, const Elem &neighbor) const
Whether to compute the internal side for the provided element-neighbor pair.
std::set< SubdomainID > _blocks_exec_printed
Keep track of which blocks were visited.
Base class for assembly-like calculations.
void clearVarsAndMaterials()
void prepareElement(const Elem *elem)
FEProblemBase & _fe_problem
static Point inverse_map(const unsigned int dim, const Elem *elem, const Point &p, const Real tolerance=TOLERANCE, const bool secure=true, const bool extra_checks=true)
std::string formatString(std::string message, const std::string &prefix)
Add new lines and prefixes to a string for pretty display in output NOTE: This makes a copy of the st...
const BoundaryID INVALID_BOUNDARY_ID