www.mooseframework.org
ComputeUserObjectsThread.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 "ThreadedElementLoop.h"
14 
15 #include "libmesh/elem_range.h"
16 
18 class ElementUserObject;
21 
22 // libMesh forward declarations
23 namespace libMesh
24 {
25 template <typename T>
26 class NumericVector;
27 }
28 
32 class ComputeUserObjectsThread : public ThreadedElementLoop<ConstElemRange>
33 {
34 public:
36  SystemBase & sys,
37  const TheWarehouse::Query & query);
38  // Splitting Constructor
40 
41  virtual ~ComputeUserObjectsThread();
42 
43  virtual void onElement(const Elem * elem) override;
44  virtual void onBoundary(const Elem * elem, unsigned int side, BoundaryID bnd_id) override;
45  virtual void onInternalSide(const Elem * elem, unsigned int side) override;
46  virtual void onInterface(const Elem * elem, unsigned int side, BoundaryID bnd_id) override;
47  virtual void post() override;
48  virtual void subdomainChanged() override;
49 
50  void join(const ComputeUserObjectsThread & /*y*/);
51 
52 protected:
53  const NumericVector<Number> & _soln;
54 
55 private:
56  template <typename T>
57  void querySubdomain(Interfaces iface, std::vector<T> & results)
58  {
59  _query.clone()
61  .condition<AttribSubdomains>(_subdomain)
62  .condition<AttribInterfaces>(iface)
63  .queryInto(results);
64  }
65  template <typename T>
66  void queryBoundary(Interfaces iface, BoundaryID bnd, std::vector<T> & results)
67  {
68  _query.clone()
70  .condition<AttribBoundaries>(bnd)
71  .condition<AttribInterfaces>(iface)
72  .queryInto(results);
73  }
74 
76  std::vector<InternalSideUserObject *> _internal_side_objs;
77  std::vector<InterfaceUserObject *> _interface_user_objects;
78  std::vector<ElementUserObject *> _element_objs;
79  std::vector<ShapeElementUserObject *> _shape_element_objs;
80 };
81 
82 // determine when we need to run user objects based on whether any initial conditions or aux
83 // kernels depend on the user objects. If so we need to run them either before ics, before aux
84 // kernels, or after aux kernels (if nothing depends on them). Mark/store this information as
85 // attributes in the warehouse for later reference.
86 template <typename T>
87 void
89  const std::vector<T *> & objs,
90  const std::set<std::string> & ic_deps,
91  const std::set<std::string> & aux_deps)
92 {
93  // Notes about how this information is used later during the simulation:
94  // We only need to run pre-ic objects for their "initial" exec flag time (not the others).
95  //
96  // For pre/post aux objects:
97  //
98  // If an object was not run as a pre-ic object or it is a pre-ic object and
99  // shouldDuplicateInitialExecution returns true:
100  // * run the object at all its exec flag times.
101  // Else
102  // * run the object at all its exec flag times *except* "initial"
103  //
104  for (const auto obj : objs)
105  {
106  if (ic_deps.count(obj->name()) > 0)
107  w.update(obj, AttribPreIC(w, true));
108 
109  if ((obj->isParamValid("force_preaux") && obj->template getParam<bool>("force_preaux")) ||
110  aux_deps.count(obj->name()) > 0 || ic_deps.count(obj->name()) > 0)
111  w.update(obj, AttribPreAux(w, true));
112  else
113  w.update(obj, AttribPreAux(w, false));
114  }
115 }
116 
Base class for assembly-like calculations.
virtual void post() override
Called after the element range loop.
std::vector< ElementUserObject * > _element_objs
std::vector< ShapeElementUserObject * > _shape_element_objs
void querySubdomain(Interfaces iface, std::vector< T > &results)
virtual void onBoundary(const Elem *elem, unsigned int side, BoundaryID bnd_id) override
Called when doing boundary assembling.
virtual void onElement(const Elem *elem) override
Assembly of the element (not including surface assembly)
void groupUserObjects(TheWarehouse &w, const std::vector< T *> &objs, const std::set< std::string > &ic_deps, const std::set< std::string > &aux_deps)
virtual void onInterface(const Elem *elem, unsigned int side, BoundaryID bnd_id) override
Called when doing interface assembling.
TODO: delete this later - it is a temporary hack for dealing with inter-system dependencies.
Definition: Attributes.h:168
void queryBoundary(Interfaces iface, BoundaryID bnd, std::vector< T > &results)
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
virtual void subdomainChanged() override
Called every time the current subdomain changes (i.e.
static PetscErrorCode Vec x
Base class for a system (of equations)
Definition: SystemBase.h:92
Interfaces
Definition: Attributes.h:15
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
Query & condition(Args &&... args)
Adds a new condition to the query.
Definition: TheWarehouse.h:157
std::vector< std::string > split(const std::string &str, const std::string &delimiter)
Python like split function for strings.
Definition: MooseUtils.C:736
TODO: delete this later - it is a temporary hack for dealing with inter-system dependencies.
Definition: Attributes.h:153
ElementUserObject class in which the _phi and _grad_phi shape function data is available and correctl...
boundary_id_type BoundaryID
const TheWarehouse::Query _query
std::vector< InterfaceUserObject * > _interface_user_objects
TheWarehouse is a container for MooseObjects that allows querying/filtering over various customizeabl...
Definition: TheWarehouse.h:119
void join(const ComputeUserObjectsThread &)
const NumericVector< Number > & _soln
ComputeUserObjectsThread(FEProblemBase &problem, SystemBase &sys, const TheWarehouse::Query &query)
void update(MooseObject *obj)
update updates the metadata/attribute-info stored for the given object obj that must already exists i...
Definition: TheWarehouse.C:129
Class for threaded computation of UserObjects.
Query clone() const
clone creates and returns an independent copy of the query in its current state.
Definition: TheWarehouse.h:164
virtual void onInternalSide(const Elem *elem, unsigned int side) override
Called when doing internal edge assembling.
std::vector< InternalSideUserObject * > _internal_side_objs
SubdomainID _subdomain
The subdomain for the current element.
Base class for implementing interface user objects.
Query is a convenient way to construct and pass around (possible partially constructed) warehouse que...
Definition: TheWarehouse.h:128