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 : // MOOSE includes 13 : #include "MooseTypes.h" 14 : 15 : // Forward Declarations 16 : class FEProblemBase; 17 : class InputParameters; 18 : class MooseObject; 19 : template <typename T> 20 : class VectorPostprocessorContext; 21 : 22 : class VectorPostprocessorInterface 23 : { 24 : public: 25 : static InputParameters validParams(); 26 : 27 : /** 28 : * Constructor 29 : * 30 : * @param broadcast_by_default Set to true if the system inheriting from this interface always 31 : * needs the VPPs to be broadcast 32 : */ 33 : VectorPostprocessorInterface(const MooseObject * moose_object, bool broadcast_by_default = false); 34 : 35 : #ifdef MOOSE_KOKKOS_ENABLED 36 : /** 37 : * Special constructor used for Kokkos functor copy during parallel dispatch 38 : */ 39 : VectorPostprocessorInterface(const VectorPostprocessorInterface & object, 40 : const Moose::Kokkos::FunctorCopy & key); 41 : #endif 42 : 43 : /** 44 : * This class has virtual methods, so it needs a virtual dtor. 45 : */ 46 875377 : virtual ~VectorPostprocessorInterface() = default; 47 : 48 : /** 49 : * DEPRECATED: Use the new version where you need to specify whether or 50 : * not the vector must be broadcast 51 : * 52 : * Retrieve the value of a VectorPostprocessor 53 : * @param param_name The name of the VectorPostprocessor parameter (see below) 54 : * @param vector_name The name of the particular vector you want. 55 : * @return A reference to the desired value 56 : * 57 : * The name required by this method is the name that is hard-coded into 58 : * your source code. For example, if you have a Kernel that requires 59 : * a VectorPostprocessor you may have an input file with "pp = my_pp", this function 60 : * requires the "pp" name as input (see .../moose_test/functions/VectorPostprocessorFunction.C) 61 : * 62 : * see getVectorPostprocessorValueOld getVectorPostprocessorValueByName 63 : * getVectorPostprocessorValueOldByName 64 : */ 65 : const VectorPostprocessorValue & 66 : getVectorPostprocessorValue(const std::string & param_name, 67 : const std::string & vector_name) const; 68 : 69 : /** 70 : * DEPRECATED: Use the new version where you need to specify whether or 71 : * not the vector must be broadcast 72 : * 73 : * Retrieve the value of the VectorPostprocessor 74 : * @param name VectorPostprocessor name (see below) 75 : * @param vector_name The name of the particular vector you want. 76 : * @return A reference to the desired value 77 : * 78 : * The name required by this method is the name defined in the input file. For example, 79 : * if you have a Kernel that requires a VectorPostprocessor you may have an input file with 80 : * "pp = my_pp", this method requires the "my_pp" name as input 81 : * (see .../moose_test/functions/VectorPostprocessorFunction.C) 82 : * 83 : * see getVectorPostprocessorValue getVectorPostprocessorValueOldByName 84 : * getVectorPostprocessorValueByName 85 : */ 86 : const VectorPostprocessorValue & 87 : getVectorPostprocessorValueByName(const VectorPostprocessorName & name, 88 : const std::string & vector_name) const; 89 : 90 : /** 91 : * DEPRECATED: Use the new version where you need to specify whether or 92 : * not the vector must be broadcast 93 : * 94 : * Retrieve the old value of a VectorPostprocessor 95 : * @param param_name The name of the VectorPostprocessor parameter 96 : * @param vector_name The name of the particular vector you want. 97 : * @return The value of the VectorPostprocessor 98 : * 99 : * see getVectorPostprocessorValue 100 : */ 101 : const VectorPostprocessorValue & 102 : getVectorPostprocessorValueOld(const std::string & param_name, 103 : const std::string & vector_name) const; 104 : 105 : /** 106 : * DEPRECATED: Use the new version where you need to specify whether or 107 : * not the vector must be broadcast 108 : * 109 : * Retrieve the old value of a VectorPostprocessor 110 : * @param name The name of the VectorPostprocessor 111 : * @param vector_name The name of the particular vector you want. 112 : * @return The value of the VectorPostprocessor 113 : * 114 : * If within the validParams for the object the addVectorPostprocessorParam was called this method 115 : * will retun a reference to the default value specified in the call to the 116 : * addVectorPostprocessorParam 117 : * function if the postVectorPostprocessor does not exist. 118 : * 119 : * see getVectorPostprocessorValueByName 120 : */ 121 : const VectorPostprocessorValue & 122 : getVectorPostprocessorValueOldByName(const VectorPostprocessorName & name, 123 : const std::string & vector_name) const; 124 : 125 : // doco-normal-methods-begin 126 : /** 127 : * Retrieve the value of a VectorPostprocessor 128 : * @param param_name The name of the VectorPostprocessor parameter (see below) 129 : * @param vector_name The name of the particular vector you want. 130 : * @param need_broadcast Whether or not this object requires the vector to 131 : * be replicated in parallel 132 : * @return A reference to the desired value 133 : * 134 : * The name required by this method is the name that is hard-coded into 135 : * your source code. For example, if you have a Kernel that requires 136 : * a VectorPostprocessor you may have an input file with "pp = my_pp", this function 137 : * requires the "pp" name as input (see .../moose_test/functions/VectorPostprocessorFunction.C) 138 : * 139 : * see getVectorPostprocessorValueOld getVectorPostprocessorValueByName 140 : * getVectorPostprocessorValueOldByName 141 : */ 142 : const VectorPostprocessorValue & getVectorPostprocessorValue(const std::string & param_name, 143 : const std::string & vector_name, 144 : bool needs_broadcast) const; 145 : // doco-normal-methods-end 146 : 147 : /** 148 : * Retrieve the value of the VectorPostprocessor 149 : * @param name VectorPostprocessor name (see below) 150 : * @param vector_name The name of the particular vector you want. 151 : * @param need_broadcast Whether or not this object requires the vector to 152 : * be replicated in parallel 153 : * @return A reference to the desired value 154 : * 155 : * The name required by this method is the name defined in the input file. For example, 156 : * if you have a Kernel that requires a VectorPostprocessor you may have an input file with 157 : * "pp = my_pp", this method requires the "my_pp" name as input 158 : * (see .../moose_test/functions/VectorPostprocessorFunction.C) 159 : * 160 : * see getVectorPostprocessorValue getVectorPostprocessorValueOldByName 161 : * getVectorPostprocessorValueByName 162 : */ 163 : const VectorPostprocessorValue & 164 : getVectorPostprocessorValueByName(const VectorPostprocessorName & name, 165 : const std::string & vector_name, 166 : bool needs_broadcast) const; 167 : 168 : /** 169 : * Retrieve the old value of a VectorPostprocessor 170 : * @param param_name The name of the VectorPostprocessor parameter 171 : * @param vector_name The name of the particular vector you want. 172 : * @param need_broadcast Whether or not this object requires the vector to 173 : * be replicated in parallel 174 : * @return The value of the VectorPostprocessor 175 : * 176 : * see getVectorPostprocessorValue 177 : */ 178 : const VectorPostprocessorValue & getVectorPostprocessorValueOld(const std::string & param_name, 179 : const std::string & vector_name, 180 : bool needs_broadcast) const; 181 : 182 : /** 183 : * Retrieve the old value of a VectorPostprocessor 184 : * @param name The name of the VectorPostprocessor 185 : * @param vector_name The name of the particular vector you want. 186 : * @param need_broadcast Whether or not this object requires the vector to 187 : * be replicated in parallel 188 : * @return The value of the VectorPostprocessor 189 : * 190 : * If within the validParams for the object the addVectorPostprocessorParam was called this method 191 : * will retun a reference to the default value specified in the call to the 192 : * addVectorPostprocessorParam 193 : * function if the postVectorPostprocessor does not exist. 194 : * 195 : * see getVectorPostprocessorValueByName 196 : */ 197 : const VectorPostprocessorValue & 198 : getVectorPostprocessorValueOldByName(const VectorPostprocessorName & name, 199 : const std::string & vector_name, 200 : bool needs_broadcast) const; 201 : 202 : /** 203 : * Return the scatter value for the post processor 204 : * 205 : * This is only valid when you expec the vector to be of lenghth "num_procs" 206 : * In that case - this will return a reference to a value that will be _this_ processor's value 207 : * from that vector 208 : * 209 : * @param param_name The name of the parameter holding the vpp name 210 : * @param vector_name The name of the vector 211 : * @return The reference to the current scatter value 212 : */ 213 : const ScatterVectorPostprocessorValue & 214 : getScatterVectorPostprocessorValue(const std::string & param_name, 215 : const std::string & vector_name) const; 216 : 217 : /** 218 : * Return the scatter value for the post processor 219 : * 220 : * This is only valid when you expec the vector to be of lenghth "num_procs" 221 : * In that case - this will return a reference to a value that will be _this_ processor's value 222 : * from that vector 223 : * 224 : * @param name The name of the VectorPostprocessor 225 : * @param vector_name The name of the vector 226 : * @return The reference to the current scatter value 227 : */ 228 : const ScatterVectorPostprocessorValue & 229 : getScatterVectorPostprocessorValueByName(const VectorPostprocessorName & name, 230 : const std::string & vector_name) const; 231 : 232 : /** 233 : * Return the old scatter value for the post processor 234 : * 235 : * This is only valid when you expec the vector to be of lenghth "num_procs" 236 : * In that case - this will return a reference to a value that will be _this_ processor's 237 : * value from that vector 238 : * 239 : * @param param_name The name of the parameter holding the vpp name 240 : * @param vector_name The name of the vector 241 : * @return The reference to the old scatter value 242 : */ 243 : const ScatterVectorPostprocessorValue & 244 : getScatterVectorPostprocessorValueOld(const std::string & param_name, 245 : const std::string & vector_name) const; 246 : 247 : /** 248 : * Return the old scatter value for the post processor 249 : * 250 : * This is only valid when you expect the vector to be of length "num_procs" 251 : * In that case - this will return a reference to a value that will be _this_ processor's 252 : * value from that vector 253 : * 254 : * @param name The name of the VectorPostprocessor 255 : * @param vector_name The name of the vector 256 : * @return The reference to the old scatter value 257 : */ 258 : const ScatterVectorPostprocessorValue & 259 : getScatterVectorPostprocessorValueOldByName(const VectorPostprocessorName & name, 260 : const std::string & vector_name) const; 261 : 262 : /** 263 : * Determine if the VectorPostprocessor data exists by parameter 264 : * @param param_name The name of the VectorPostprocessor parameter 265 : * @param vector_name The vector name within the VectorPostprocessor 266 : * @return True if the VectorPostprocessor data exists 267 : * 268 : * @see hasVectorPostprocessorByName getVectorPostprocessorValue 269 : */ 270 : bool hasVectorPostprocessor(const std::string & param_name, 271 : const std::string & vector_name) const; 272 : 273 : /** 274 : * Determine if the VectorPostprocessor data exists by name 275 : * @param name The name of the VectorPostprocessor 276 : * @param vector_name The vector name within the VectorPostprocessor 277 : * @return True if the VectorPostprocessor data exists 278 : * 279 : * @see hasVectorPostprocessor getVectorPostprocessorValueByName 280 : */ 281 : bool hasVectorPostprocessorByName(const VectorPostprocessorName & name, 282 : const std::string & vector_name) const; 283 : 284 : /** 285 : * Determine if the VectorPostprocessor exists by parameter 286 : * @param name The name of the VectorPostprocessor parameter 287 : * @return True if the VectorPostprocessor exists 288 : */ 289 : bool hasVectorPostprocessor(const std::string & param_name) const; 290 : 291 : /** 292 : * Determine if the VectorPostprocessor exists by name 293 : * @param name The name of the VectorPostprocessor 294 : * @return True if the VectorPostprocessor exists 295 : */ 296 : bool hasVectorPostprocessorByName(const VectorPostprocessorName & name) const; 297 : 298 : ///@{ 299 : /** 300 : * Return true if the VectorPostprocessor is marked with parallel_type as DISTRIBUTED 301 : */ 302 : bool isVectorPostprocessorDistributed(const std::string & param_name) const; 303 : bool isVectorPostprocessorDistributedByName(const VectorPostprocessorName & name) const; 304 : ///@} 305 : 306 : /** 307 : * Get the name of a VectorPostprocessor associated with a parameter. 308 : * @param param_name The name of the VectorPostprocessor parameter 309 : * @return The name of the given VectorPostprocessor 310 : */ 311 : const VectorPostprocessorName & getVectorPostprocessorName(const std::string & param_name) const; 312 : 313 : protected: 314 : /** 315 : * Helper for deriving classes to override to add dependencies when a VectorPostprocessor is 316 : * requested. 317 : */ 318 : virtual void 319 153 : addVectorPostprocessorDependencyHelper(const VectorPostprocessorName & /* name */) const 320 : { 321 153 : } 322 : 323 : private: 324 : /** 325 : * Helper function for extracting VPP data from ReporterData object 326 : */ 327 : const VectorPostprocessorValue & 328 : getVectorPostprocessorByNameHelper(const VectorPostprocessorName & name, 329 : const std::string & vector_name, 330 : bool broadcast, 331 : std::size_t t_index) const; 332 : 333 : /** 334 : * Helper for getting the VPP context that handles scatter values 335 : */ 336 : const VectorPostprocessorContext<VectorPostprocessorValue> & 337 : getVectorPostprocessorContextByNameHelper(const VectorPostprocessorName & name, 338 : const std::string & vector_name) const; 339 : 340 : ///@{ 341 : /** 342 : * Helpers for "possibly" checking if a vpp exists. This is only able to check for 343 : * existance after all vpps have been added (after the task creating them has 344 : * been called). If called before said task, this will do nothing, hence the 345 : * "possibly". This allows us to have errors reported directly by the object 346 : * requesting the vpp instead of through a system with less context. 347 : */ 348 : void possiblyCheckHasVectorPostprocessor(const std::string & param_name, 349 : const std::string & vector_name) const; 350 : void possiblyCheckHasVectorPostprocessorByName(const VectorPostprocessorName & name, 351 : const std::string & vector_name) const; 352 : ///@} 353 : 354 : /** 355 : * @returns True if all vpps have been added (the task associated with adding them is complete) 356 : */ 357 : bool vectorPostprocessorsAdded() const; 358 : 359 : /// Whether or not to force broadcasting by default 360 : const bool _broadcast_by_default; 361 : 362 : /// The MooseObject that uses this interface 363 : const MooseObject & _vpi_moose_object; 364 : 365 : /// Reference the FEProblemBase class 366 : const FEProblemBase & _vpi_feproblem; 367 : 368 : /// Thread ID 369 : const THREAD_ID _vpi_tid; 370 : };