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 : // Standard includes 13 : #include <string> 14 : 15 : // MOOSE includes 16 : #include "MooseTypes.h" 17 : 18 : // Forward Declarations 19 : class FEProblemBase; 20 : class InputParameters; 21 : class PostprocessorName; 22 : class MooseObject; 23 : 24 : #define usingPostprocessorInterfaceMembers \ 25 : using PostprocessorInterface::getPostprocessorValue; \ 26 : using PostprocessorInterface::getPostprocessorValueOld; \ 27 : using PostprocessorInterface::getPostprocessorValueOlder; \ 28 : using PostprocessorInterface::coupledPostprocessors 29 : 30 : /** 31 : * Interface class for classes which interact with Postprocessors. 32 : * Provides the getPostprocessorValueXYZ() and related interfaces. 33 : */ 34 : class PostprocessorInterface 35 : { 36 : public: 37 : PostprocessorInterface(const MooseObject * moose_object); 38 : 39 : PostprocessorInterface(const FEProblemBase * problem); 40 : 41 : #ifdef MOOSE_KOKKOS_ENABLED 42 : /** 43 : * Special constructor used for Kokkos functor copy during parallel dispatch 44 : */ 45 : PostprocessorInterface(const PostprocessorInterface & object, 46 : const Moose::Kokkos::FunctorCopy & key); 47 : #endif 48 : 49 : static InputParameters validParams(); 50 : 51 : ///@{ 52 : /** 53 : * doco-normal-methods-begin 54 : * Retrieve the value of a Postprocessor or one of it's old or older values 55 : * @param param_name The name of the Postprocessor parameter (see below) 56 : * @param index The index of the Postprocessor 57 : * @return A reference to the desired value 58 : * 59 : * The name required by this method is the name that is hard-coded into 60 : * your source code. For example, if you have a Kernel that requires 61 : * a Postprocessor you may have an input file with "pp = my_pp", this function 62 : * requires the "pp" name as input (see .../moose_test/functions/PostprocessorFunction.C) 63 : * 64 : * see getPostprocessorValueByName getPostprocessorValueOldByName getPostprocessorValueOlderByName 65 : */ 66 : const PostprocessorValue & getPostprocessorValue(const std::string & param_name, 67 : const unsigned int index = 0) const; 68 : const PostprocessorValue & getPostprocessorValueOld(const std::string & param_name, 69 : const unsigned int index = 0) const; 70 : const PostprocessorValue & getPostprocessorValueOlder(const std::string & param_name, 71 : const unsigned int index = 0) const; 72 : // doco-normal-methods-end 73 : 74 : ///@} 75 : 76 : ///@{ 77 : /** 78 : * Retrieve the value of the Postprocessor 79 : * @param name Postprocessor name (see below) 80 : * @return A reference to the desired value 81 : * 82 : * The name required by this method is the name defined in the input file. For example, 83 : * if you have a Kernel that requires a Postprocessor you may have an input file with 84 : * "pp = my_pp", this method requires the "my_pp" name as input 85 : * (see .../moose_test/functions/PostprocessorFunction.C) 86 : * 87 : * see getPostprocessorValue getPostprocessorValueOld getPostprocessorValueOlder 88 : */ 89 : virtual const PostprocessorValue & 90 : getPostprocessorValueByName(const PostprocessorName & name) const; 91 : const PostprocessorValue & getPostprocessorValueOldByName(const PostprocessorName & name) const; 92 : const PostprocessorValue & getPostprocessorValueOlderByName(const PostprocessorName & name) const; 93 : ///@} 94 : 95 : /** 96 : * Determine whether or not the Postprocessor is a default value. A default value is when 97 : * the value is either the value set by addParam, or is a user-set value in input instead of 98 : * a name to a postprocessor. 99 : * @param param_name The name of the Postprocessor parameter 100 : * @param index The index of the postprocessor 101 : * @return True if the Postprocessor is a default value, false if the Postprocessor 102 : * is the name of a Postprocessor 103 : */ 104 : bool isDefaultPostprocessorValue(const std::string & param_name, 105 : const unsigned int index = 0) const; 106 : 107 : /** 108 : * Determine if the Postprocessor data exists 109 : * @param param_name The name of the Postprocessor parameter 110 : * @param index The index of the Postprocessor 111 : * @return True if the Postprocessor exists 112 : * 113 : * @see hasPostprocessorByName getPostprocessorValue 114 : */ 115 : bool hasPostprocessor(const std::string & param_name, const unsigned int index = 0) const; 116 : 117 : /** 118 : * Determine if the Postprocessor data exists 119 : * @param name The name of the Postprocessor 120 : * @return True if the Postprocessor exists 121 : * 122 : * @see hasPostprocessor getPostprocessorValueByName 123 : */ 124 : bool hasPostprocessorByName(const PostprocessorName & name) const; 125 : 126 : /** 127 : * Returns number of Postprocessors coupled under parameter name 128 : * @param param_name The name of the Postprocessor parameter 129 : * @return Number of coupled post-processors, 1 if it's a single 130 : * 131 : */ 132 : std::size_t coupledPostprocessors(const std::string & param_name) const; 133 : 134 : /** 135 : * Get the name of a postprocessor. This can only be used if the postprocessor 136 : * parameter does _not_ have a default value set (see isDefaultPostprocessorValue()), 137 : * in which case the "name" is actually the default value. 138 : * @param param_name The name of the Postprocessor parameter 139 : * @param index The index of the Postprocessor 140 : * @return The name of the given Postprocessor 141 : */ 142 : const PostprocessorName & getPostprocessorName(const std::string & param_name, 143 : const unsigned int index = 0) const; 144 : 145 : protected: 146 : /** 147 : * Helper for deriving classes to override to add dependencies when a Postprocessor is requested. 148 : */ 149 43474 : virtual void addPostprocessorDependencyHelper(const PostprocessorName & /* name */) const {} 150 : 151 : private: 152 : /// The MooseObject that uses this interface 153 : const MooseObject & _ppi_moose_object; 154 : 155 : /// PostprocessorInterface Parameters 156 : const InputParameters & _ppi_params; 157 : 158 : /// Reference the the FEProblemBase class 159 : const FEProblemBase & _ppi_feproblem; 160 : 161 : /// Holds the default postprocessor values that are requested (key is PostprocessorName) 162 : mutable std::map<PostprocessorName, std::unique_ptr<PostprocessorValue>> _default_values; 163 : 164 : /** 165 : * Internal method for getting the PostprocessorName associated with a paremeter. 166 : * Needed in order to allow the return of a name that is a default value. 167 : */ 168 : const PostprocessorName & 169 : getPostprocessorNameInternal(const std::string & param_name, 170 : const unsigned int index, 171 : const bool allow_default_value = true) const; 172 : 173 : /** 174 : * Internal methods for getting Postprocessor values. 175 : */ 176 : ///@{ 177 : const PostprocessorValue & getPostprocessorValueInternal(const std::string & param_name, 178 : unsigned int index, 179 : std::size_t t_index) const; 180 : const PostprocessorValue & getPostprocessorValueByNameInternal(const PostprocessorName & name, 181 : std::size_t t_index) const; 182 : ///@} 183 : 184 : /** 185 : * @returns True if the PostprocessorName \p name repesents a default value: the name 186 : * converts to a value (set by addParam or set via input), and a Postprocessor does not 187 : * exist with the same name (we do allow Postprocessors with numbered names...) 188 : */ 189 : bool isDefaultPostprocessorValueByName(const PostprocessorName & name) const; 190 : 191 : /** 192 : * @returns The default value stored in the PostprocessorName \p name. 193 : */ 194 : PostprocessorValue getDefaultPostprocessorValueByName(const PostprocessorName & name) const; 195 : 196 : /** 197 : * Checks the parameters relating to a Postprocessor. If \p index is not set, index 198 : * checking is not performed. 199 : */ 200 : void checkParam(const std::string & param_name, 201 : const unsigned int index = std::numeric_limits<unsigned int>::max()) const; 202 : 203 : /** 204 : * @returns True if all pps have been added (the task associated with adding them is complete) 205 : */ 206 : bool postprocessorsAdded() const; 207 : };