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 : #ifdef MOOSE_MFEM_ENABLED 11 : 12 : #pragma once 13 : 14 : #include "MFEMObject.h" 15 : #include "SetupInterface.h" 16 : #include "DependencyResolverInterface.h" 17 : 18 : #include <optional> 19 : #include <set> 20 : 21 : /** 22 : * Base class for MFEM objects that participate in execution ordering but are not UserObjects. 23 : */ 24 : class MFEMExecutedObject : public MFEMObject, 25 : public SetupInterface, 26 : public DependencyResolverInterface 27 : { 28 : public: 29 : /** 30 : * Declare the common parameters used by MFEM executed objects. 31 : */ 32 : static InputParameters validParams(); 33 : 34 : /** 35 : * Construct an executed MFEM object and materialize its dependency metadata. 36 : */ 37 : MFEMExecutedObject(const InputParameters & parameters); 38 : 39 : /** 40 : * Perform any pre-execution setup for this object. 41 : */ 42 2547 : virtual void initialize() {} 43 : /** 44 : * Perform the main work for this object. 45 : */ 46 0 : virtual void execute() {} 47 : /** 48 : * Perform any post-execution finalization for this object. 49 : */ 50 1867 : virtual void finalize() {} 51 : 52 : /** 53 : * Return the variable name supplied by this object, or std::nullopt if none. 54 : */ 55 : virtual std::optional<std::string> suppliedVariableName() const; 56 : /** 57 : * Return the postprocessor name supplied by this object, or std::nullopt if none. 58 : */ 59 : virtual std::optional<std::string> suppliedPostprocessorName() const; 60 : /** 61 : * Return the vector postprocessor name supplied by this object, or std::nullopt if none. 62 : */ 63 : virtual std::optional<std::string> suppliedVectorPostprocessorName() const; 64 : 65 : virtual const std::set<std::string> & getRequestedItems() override; 66 : virtual const std::set<std::string> & getSuppliedItems() override; 67 : 68 : /** 69 : * Add an optional dependency-bearing parameter and register it with the MFEM scheduler. 70 : */ 71 : template <typename T> 72 : static void addDependencyParam(InputParameters & params, 73 : const std::string & param_name, 74 : const std::string & doc_string); 75 : 76 : /** 77 : * Add a required dependency-bearing parameter and register it with the MFEM scheduler. 78 : */ 79 : template <typename T> 80 : static void addRequiredDependencyParam(InputParameters & params, 81 : const std::string & param_name, 82 : const std::string & doc_string); 83 : 84 : protected: 85 : /** 86 : * Build the dependency key used for a supplied/requested variable. 87 : */ 88 : static std::string variableDependencyKey(const std::string & name); 89 : /** 90 : * Build the dependency key used for a supplied/requested postprocessor. 91 : */ 92 : static std::string postprocessorDependencyKey(const std::string & name); 93 : /** 94 : * Build the dependency key used for a supplied/requested vector postprocessor. 95 : */ 96 : static std::string vectorPostprocessorDependencyKey(const std::string & name); 97 : 98 : /** 99 : * Record one dependency-bearing parameter in the private parameter metadata. 100 : */ 101 : static void appendDependencyParam(InputParameters & params, const std::string & param_name); 102 : 103 : private: 104 : /// Lazily constructed requested dependency keys for this object's registered dependencies. 105 : std::optional<std::set<std::string>> _requested_items; 106 : /// Lazily constructed supplied dependency keys for this object's supplied resources. 107 : std::optional<std::set<std::string>> _supplied_items; 108 : }; 109 : 110 : template <typename T> 111 : void 112 20 : MFEMExecutedObject::addDependencyParam(InputParameters & params, 113 : const std::string & param_name, 114 : const std::string & doc_string) 115 : { 116 20 : params.addParam<T>(param_name, doc_string); 117 20 : appendDependencyParam(params, param_name); 118 20 : } 119 : 120 : template <typename T> 121 : void 122 49154 : MFEMExecutedObject::addRequiredDependencyParam(InputParameters & params, 123 : const std::string & param_name, 124 : const std::string & doc_string) 125 : { 126 49154 : params.addRequiredParam<T>(param_name, doc_string); 127 49154 : appendDependencyParam(params, param_name); 128 49154 : } 129 : 130 : #endif