diff --git a/framework/include/interfaces/PostprocessorInterface.h b/framework/include/interfaces/PostprocessorInterface.h index ac7b04745cfa..a5bdd9a6310f 100644 --- a/framework/include/interfaces/PostprocessorInterface.h +++ b/framework/include/interfaces/PostprocessorInterface.h @@ -94,6 +94,17 @@ class PostprocessorInterface bool isDefaultPostprocessorValue(const std::string & param_name, const unsigned int index = 0) const; + /** + * Get the default value associated with a Postprocessor parameter. + * You should check isDefaultPostprocessorValue to verify that the parameter + * is a default value before calling this method. + * @param param_name The name of the Postprocessor parameter + * @param index The index of the postprocessor + * @return The default value + */ + PostprocessorValue getDefaultPostprocessorValue(const std::string & param_name, + const unsigned int index = 0) const; + /** * Determine if the Postprocessor data exists * @param param_name The name of the Postprocessor parameter @@ -148,18 +159,40 @@ class PostprocessorInterface /// Reference the the FEProblemBase class const FEProblemBase & _ppi_feproblem; - /// Holds the default postprocessor values that are requested (key is param name, index) - mutable std::map, std::unique_ptr> - _default_values; + /// Holds the default postprocessor values that are requested (key is PostprocessorName) + mutable std::map> _default_values; - /// Extract the value using parameter name - const PostprocessorValue & getPostprocessorValueHelper(const std::string & name, - unsigned int index, - std::size_t t_index) const; + /** + * Internal method for getting the PostprocessorName associated with a paremeter. + * Needed in order to allow the return of a name that is a default value. + */ + const PostprocessorName & + getPostprocessorNameInternal(const std::string & param_name, + const unsigned int index, + const bool allow_default_value = true) const; - /// Extract the value using stored name - const PostprocessorValue & getPostprocessorValueByNameHelper(const PostprocessorName & name, - std::size_t t_index) const; + /** + * Internal methods for getting Postprocessor values. + */ + ///@{ + const PostprocessorValue & getPostprocessorValueInternal(const std::string & param_name, + unsigned int index, + std::size_t t_index) const; + const PostprocessorValue & getPostprocessorValueByNameInternal(const PostprocessorName & name, + std::size_t t_index) const; + ///@} + + /** + * @returns True if the PostprocessorName \p name repesents a default value: the name + * converts to a value (set by addParam or set via input), and a Postprocessor does not + * exist with the same name (we do allow Postprocessors with numbered names...) + */ + bool isDefaultPostprocessorValueByName(const PostprocessorName & name) const; + + /** + * @returns The default value stored in the PostprocessorName \p name. + */ + PostprocessorValue getDefaultPostprocessorValueByName(const PostprocessorName & name) const; /** * Checks the parameters relating to a Postprocessor. If \p index is not set, index diff --git a/framework/include/problems/FEProblemBase.h b/framework/include/problems/FEProblemBase.h index caeed9d6b29f..413b4a1ef332 100644 --- a/framework/include/problems/FEProblemBase.h +++ b/framework/include/problems/FEProblemBase.h @@ -904,10 +904,20 @@ class FEProblemBase : public SubProblem, public Restartable */ void initPostprocessorData(const std::string &) {} + /** + * Whether or not a Postprocessor value exists by a given name. + * @param name The name of the Postprocessor + * @return True if a Postprocessor value exists + * + * Note: You should prioritize the use of PostprocessorInterface::hasPostprocessor + * and PostprocessorInterface::hasPostprocessorByName over this method when possible. + */ + bool hasPostprocessorValueByName(const PostprocessorName & name) const; + /** * Get a read-only reference to the value associated with a Postprocessor that exists. * @param name The name of the post-processor - * @partm t_index Flag for getting current (0), old (1), or older (2) values + * @param t_index Flag for getting current (0), old (1), or older (2) values * @return The reference to the value at the given time index * * Note: This method is only for retrieving values that already exist, the Postprocessor and @@ -936,16 +946,6 @@ class FEProblemBase : public SubProblem, public Restartable std::size_t t_index = 0); ///@} - ///@{ - /** - * Deprecated - */ - bool hasPostprocessor(const std::string & name) const; - PostprocessorValue & getPostprocessorValue(const PostprocessorName & name); - PostprocessorValue & getPostprocessorValueOld(const std::string & name); - PostprocessorValue & getPostprocessorValueOlder(const std::string & name); - ///@} - /** * Get a read-only reference to the vector value associated with the VectorPostprocessor. * @param object_name The name of the VPP object. @@ -984,24 +984,6 @@ class FEProblemBase : public SubProblem, public Restartable const VectorPostprocessor & getVectorPostprocessorObjectByName(const std::string & object_name, THREAD_ID tid = 0) const; - ///@{ - /** - * DEPRECATED - */ - bool hasVectorPostprocessor(const std::string & name); - VectorPostprocessorValue & getVectorPostprocessorValue(const VectorPostprocessorName & name, - const std::string & vector_name); - VectorPostprocessorValue & getVectorPostprocessorValueOld(const std::string & name, - const std::string & vector_name); - VectorPostprocessorValue & getVectorPostprocessorValue(const VectorPostprocessorName & name, - const std::string & vector_name, - bool needs_broadcast); - VectorPostprocessorValue & getVectorPostprocessorValueOld(const std::string & name, - const std::string & vector_name, - bool needs_broadcast); - bool vectorPostprocessorHasVectors(const std::string & vpp_name); - ///@} - ///@{ /** * Returns whether or not the current simulation has any multiapps diff --git a/framework/include/reporters/ReporterData.h b/framework/include/reporters/ReporterData.h index 4abf14eb80ed..8aca8266cc13 100644 --- a/framework/include/reporters/ReporterData.h +++ b/framework/include/reporters/ReporterData.h @@ -18,6 +18,7 @@ #include "libmesh/auto_ptr.h" class MooseApp; +class Receiver; /** * This is a helper class for managing the storage of declared Reporter object values. This design @@ -60,6 +61,7 @@ class ReporterData WriteKey() {} // private constructor friend class Reporter; friend class Postprocessor; + friend class Receiver; friend class VectorPostprocessor; friend class ReporterTransferInterface; }; @@ -144,13 +146,23 @@ class ReporterData const T & value, const std::size_t time_index = 0); + /** + * Method for setting that a specific time index is requested for a Reporter value. + * @tparam T The Reporter value C++ type. + * @param reporter_name The name of the reporter value, which includes the object name and the + * data name. + * @param time_index The time index that is needed + */ + template + void needReporterTimeIndex(const ReporterName & reporter_name, const std::size_t time_index); + ///@{ /** * Method for returning a writable reference to the current Reporter value. This method is * used by the Reporter class to produce values. * @tparam T The Reporter value C++ type. - * @tparam S (optional) The ReporterContext for performing specialized actions after the values - * have been computed. For example, ReporterBroadcastContext automatically broadcasts + * @tparam S (optional) The ReporterContext for performing specialized actions after the + * values have been computed. For example, ReporterBroadcastContext automatically broadcasts * the computed value. See ReporterState.C/h for more information. * @param reporter_name The name of the reporter value, which includes the object name and the * data name. @@ -160,12 +172,13 @@ class ReporterData * by the S template parameter. If S = ReporterContext then the first argument * can be used as the default value (see ReporterContext.h). * - * The ReporterContext objects allow for custom handling of data (e.g., broadcasting the value). - * The get/declare methods can be called in any order thus an the underlying RestartableData - * object is often created by the get method before it is declared. Therefore the custom - * functionality cannot be handled by specializing the RestartableData/ReporterState object - * directly because the state is often created prior to the declaration that dictates how the - * produced value shall be computed. Thus, the reason for the separate ReporterContext objects. + * The ReporterContext objects allow for custom handling of data (e.g., broadcasting the + * value). The get/declare methods can be called in any order thus an the underlying + * RestartableData object is often created by the get method before it is declared. Therefore + * the custom functionality cannot be handled by specializing the + * RestartableData/ReporterState object directly because the state is often created prior to + * the declaration that dictates how the produced value shall be computed. Thus, the reason + * for the separate ReporterContext objects. */ template T & declareReporterValue(const ReporterName & reporter_name, @@ -258,7 +271,7 @@ class ReporterData template ReporterState & getReporterStateHelper(const ReporterName & reporter_name, bool declare, - const MooseObject & moose_object) const; + const MooseObject * moose_object = nullptr) const; /** * Helper for registering data with the MooseApp to avoid cyclic includes @@ -283,7 +296,7 @@ template ReporterState & ReporterData::getReporterStateHelper(const ReporterName & reporter_name, bool declare, - const MooseObject & moose_object) const + const MooseObject * moose_object /* = nullptr */) const { if (hasReporterState(reporter_name)) { @@ -298,7 +311,10 @@ ReporterData::getReporterStateHelper(const ReporterName & reporter_name, oss << ",\na Reporter with the same name " << suffix << ".\n\n"; oss << getReporterInfo(reporter_name); - moose_object.mooseError(oss.str()); + if (moose_object) + moose_object->mooseError(oss.str()); + else + mooseError(oss.str()); }; if (declare && hasReporterValue(reporter_name)) @@ -330,6 +346,12 @@ ReporterData::getReporterStateHelper(const ReporterName & reporter_name, // different special types are not unique so they'll be the same entry _states.emplace(reporter_name, state); + if (declare) + { + mooseAssert(moose_object, "Declaring a Reporter requires a MooseObject as a producer"); + state->setProducer(*moose_object); + } + return *state; } @@ -340,7 +362,7 @@ ReporterData::getReporterValue(const ReporterName & reporter_name, const ReporterMode & mode, const std::size_t time_index /* = 0 */) const { - auto & state = getReporterStateHelper(reporter_name, /* declare = */ false, consumer); + auto & state = getReporterStateHelper(reporter_name, /* declare = */ false, &consumer); state.addConsumer(mode, consumer); return state.value(time_index); } @@ -353,8 +375,7 @@ ReporterData::declareReporterValue(const ReporterName & reporter_name, Args &&... args) { // Get/create the ReporterState - auto & state = getReporterStateHelper(reporter_name, /* declare = */ true, producer); - state.setProducer(producer); + auto & state = getReporterStateHelper(reporter_name, /* declare = */ true, &producer); // They key in _states (ReporterName) is not unique. This is done on purpose // because we want to store reporter names a single name regardless of type. @@ -419,10 +440,11 @@ ReporterData::getReporterValue(const ReporterName & reporter_name, reporter_name, "\" with type \"", MooseUtils::prettyCppType(), - " is not declared."); + "\" is not declared."); - return static_cast *>(&getReporterContextBase(reporter_name)) - ->state() + // Force the const version of value, which does not allow for increasing time index + return static_cast &>( + getReporterStateHelper(reporter_name, /* declare = */ false)) .value(time_index); } @@ -437,6 +459,15 @@ ReporterData::setReporterValue(const ReporterName & reporter_name, const_cast(me.getReporterValue(reporter_name, time_index)) = value; } +template +void +ReporterData::needReporterTimeIndex(const ReporterName & reporter_name, + const std::size_t time_index) +{ + getReporterValue(reporter_name, 0); // for error checking that it is declared + getReporterStateHelper(reporter_name, /* declare = */ false).value(time_index); +} + // This is defined here to avoid cyclic includes, see ReporterContext.h template void diff --git a/framework/include/utils/InputParameters.h b/framework/include/utils/InputParameters.h index b1a981c74418..700941ec18a8 100644 --- a/framework/include/utils/InputParameters.h +++ b/framework/include/utils/InputParameters.h @@ -646,27 +646,6 @@ class InputParameters : public Parameters */ std::map> getAutoBuildVectors() const; - /** - * Whether or not a postprocessor parameter is a default value (not a name) - * @param param_name The name of the postprocessor parameter - * @param index The index in the default postprocessor vector - * @return True if the postprocessor is a default value - */ - bool isDefaultPostprocessorValue(const std::string & param_name, unsigned int index = 0) const; - - /** - * Get the default value for a postprocessor added with addPostprocessor - * - * This does _not_ return a reference. If you want to hand it out as a reference, you need - * to store it on your own. - * - * @param param_name The name of the postprocessor parameter - * @param index The index in the default postprocessor vector - * @return The default value for the postprocessor - */ - Real getDefaultPostprocessorValue(const std::string & param_name, - const unsigned int index = 0) const; - // BEGIN APPLY PARAMETER METHODS /** * Method for applying common parameters diff --git a/framework/src/interfaces/PostprocessorInterface.C b/framework/src/interfaces/PostprocessorInterface.C index 5c4f9249b439..ace453b8305c 100644 --- a/framework/src/interfaces/PostprocessorInterface.C +++ b/framework/src/interfaces/PostprocessorInterface.C @@ -8,11 +8,9 @@ //* https://www.gnu.org/licenses/lgpl-2.1.html #include "PostprocessorInterface.h" + #include "FEProblem.h" -#include "Postprocessor.h" -#include "MooseTypes.h" #include "MooseObject.h" -#include "UserObject.h" InputParameters PostprocessorInterface::validParams() @@ -31,48 +29,88 @@ const PostprocessorValue & PostprocessorInterface::getPostprocessorValue(const std::string & param_name, const unsigned int index /* = 0 */) const { - return getPostprocessorValueHelper(param_name, index, 0); + return getPostprocessorValueInternal(param_name, index, /* t_index = */ 0); } const PostprocessorValue & PostprocessorInterface::getPostprocessorValueOld(const std::string & param_name, const unsigned int index /* = 0 */) const { - return getPostprocessorValueHelper(param_name, index, 1); + return getPostprocessorValueInternal(param_name, index, /* t_index = */ 1); } const PostprocessorValue & PostprocessorInterface::getPostprocessorValueOlder(const std::string & param_name, const unsigned int index /* = 0 */) const { - return getPostprocessorValueHelper(param_name, index, 2); + return getPostprocessorValueInternal(param_name, index, /* t_index = */ 2); } const PostprocessorValue & PostprocessorInterface::getPostprocessorValueByName(const PostprocessorName & name) const { - return getPostprocessorValueByNameHelper(name, 0); + return getPostprocessorValueByNameInternal(name, /* t_index = */ 0); } const PostprocessorValue & PostprocessorInterface::getPostprocessorValueOldByName(const PostprocessorName & name) const { - return getPostprocessorValueByNameHelper(name, 1); + return getPostprocessorValueByNameInternal(name, /* t_index = */ 1); } const PostprocessorValue & PostprocessorInterface::getPostprocessorValueOlderByName(const PostprocessorName & name) const { - return getPostprocessorValueByNameHelper(name, 2); + return getPostprocessorValueByNameInternal(name, /* t_index = */ 2); } bool PostprocessorInterface::isDefaultPostprocessorValue(const std::string & param_name, const unsigned int index /* = 0 */) const { - checkParam(param_name, index); + return isDefaultPostprocessorValueByName(getPostprocessorNameInternal(param_name, index)); +} + +bool +PostprocessorInterface::isDefaultPostprocessorValueByName(const PostprocessorName & name) const +{ + // We do allow actual Postprocessor objects to have names that will succeed in being + // represented as a double... so if the name does actually exist as a PP, it's not a default + if (_ppi_feproblem.getReporterData().hasReporterValue( + PostprocessorReporterName(name))) + return false; - return _ppi_params.isDefaultPostprocessorValue(param_name, index); + std::istringstream ss(name); + Real real_value = -std::numeric_limits::max(); + return (ss >> real_value && ss.eof()); +} + +PostprocessorValue +PostprocessorInterface::getDefaultPostprocessorValue(const std::string & param_name, + const unsigned int index /* = 0 */) const +{ + const auto & name = getPostprocessorNameInternal(param_name, index); + + if (!isDefaultPostprocessorValueByName(name)) + _ppi_moose_object.mooseError( + "When getting the default Postprocessor value for parameter \"", + param_name, + "\" at index ", + index, + ",\nthe parameter does not represent a default Postprocessor value."); + + return getDefaultPostprocessorValueByName(name); +} + +PostprocessorValue +PostprocessorInterface::getDefaultPostprocessorValueByName(const PostprocessorName & name) const +{ + mooseAssert(isDefaultPostprocessorValueByName(name), "Not a default value"); + + Real real_value = -std::numeric_limits::max(); + std::istringstream ss(name); + ss >> real_value; + return real_value; } bool @@ -83,12 +121,7 @@ PostprocessorInterface::hasPostprocessor(const std::string & param_name, _ppi_moose_object.mooseError( "Cannot call hasPostprocessor() until all Postprocessors have been constructed."); - // If the parameter is a default value, we don't actually create a Postprocessor object - // for it, therefore this will be false - if (isDefaultPostprocessorValue(param_name, index)) - return false; - - return hasPostprocessorByName(getPostprocessorName(param_name, index)); + return hasPostprocessorByName(getPostprocessorNameInternal(param_name, index)); } bool @@ -162,55 +195,69 @@ const PostprocessorName & PostprocessorInterface::getPostprocessorName(const std::string & param_name, const unsigned int index /* = 0 */) const { - // If the Postprocessor is a default value, its name is actually the default value, - // therefore we shouldn't be getting a name associated with it - if (isDefaultPostprocessorValue(param_name, index)) - _ppi_moose_object.mooseError( - "While getting the name of the Postprocessor from parameter \"", - param_name, - "\" at index ", - index, - ":\nCannot get the name because the Postprocessor is a defualt value."); + return getPostprocessorNameInternal(param_name, index, /* allow_default_value = */ false); +} + +const PostprocessorName & +PostprocessorInterface::getPostprocessorNameInternal( + const std::string & param_name, + const unsigned int index, + const bool allow_default_value /* = true */) const +{ + checkParam(param_name, index); + + const auto & name = _ppi_params.isType(param_name) + ? _ppi_params.get(param_name) + : _ppi_params.get>(param_name)[index]; - return _ppi_params.isType(param_name) - ? _ppi_params.get(param_name) - : _ppi_params.get>(param_name)[index]; + if (!allow_default_value && isDefaultPostprocessorValueByName(name)) + { + std::stringstream oss; + oss << "Cannot get the name associated with PostprocessorName parameter \"" << param_name + << "\""; + if (index) + oss << " at index " << index; + oss << ",\nbecause said parameter is a default Postprocessor value."; + _ppi_moose_object.paramError(param_name, oss.str()); + } + + return name; } const PostprocessorValue & -PostprocessorInterface::getPostprocessorValueHelper(const std::string & param_name, - unsigned int index, - std::size_t t_index) const +PostprocessorInterface::getPostprocessorValueInternal(const std::string & param_name, + unsigned int index, + std::size_t t_index) const { + const auto & name = getPostprocessorNameInternal(param_name, index); + // If the Postprocessor is a default value (either set by addParam or set to a constant // value by the user in input/an action), we covert the name to a value, store said // value locally, and return it so that it fits in with the rest of the interface // (needing a reference to a value) - if (isDefaultPostprocessorValue(param_name, index)) + if (isDefaultPostprocessorValueByName(name)) { - const auto key = std::make_pair(param_name, index); - const auto value = _ppi_params.getDefaultPostprocessorValue(param_name, index); + const auto value = getDefaultPostprocessorValueByName(name); const auto & value_ref = - *_default_values.emplace(key, libmesh_make_unique(value)) + *_default_values.emplace(name, libmesh_make_unique(value)) .first->second; // first is inserted pair, second is value in pair mooseAssert(value == value_ref, "Inconsistent default value"); return value_ref; } // If not a default and all pps have been added, we check check for existance - else if (postprocessorsAdded() && !hasPostprocessor(param_name, index)) - _ppi_moose_object.paramError(param_name, - "A Postprocessor with the name \"", - getPostprocessorName(param_name, index), - "\" was not found."); + else if (postprocessorsAdded() && !hasPostprocessorByName(name)) + _ppi_moose_object.paramError( + param_name, "A Postprocessor with the name \"", name, "\" was not found."); - return getPostprocessorValueByNameHelper(getPostprocessorName(param_name, index), t_index); + return getPostprocessorValueByNameInternal(name, t_index); } const PostprocessorValue & -PostprocessorInterface::getPostprocessorValueByNameHelper(const PostprocessorName & name, - std::size_t t_index) const +PostprocessorInterface::getPostprocessorValueByNameInternal(const PostprocessorName & name, + std::size_t t_index) const { mooseAssert(t_index < 3, "Invalid time index"); + mooseAssert(!isDefaultPostprocessorValueByName(name), "Should not be default"); // If all pps have been added, we can check for existance if (postprocessorsAdded() && !hasPostprocessorByName(name)) diff --git a/framework/src/postprocessors/Receiver.C b/framework/src/postprocessors/Receiver.C index 0e7861855156..24d763627c3f 100644 --- a/framework/src/postprocessors/Receiver.C +++ b/framework/src/postprocessors/Receiver.C @@ -29,18 +29,22 @@ Receiver::validParams() Receiver::Receiver(const InputParameters & params) : GeneralPostprocessor(params), _initialize_old(getParam("initialize_old")), - _my_value(getPostprocessorValueByName(name())) // use FEProblem to avoid cyclic dependency + _my_value(_fe_problem.getReporterData().getReporterValue( + PostprocessorReporterName(name()))) { - // Initialize old/older data - getPostprocessorValueOldByName(name()); - getPostprocessorValueOlderByName(name()); + const PostprocessorReporterName r_name(name()); + auto & write_data = _fe_problem.getReporterData(ReporterData::WriteKey()); + // Request that we need the old and older time values for this Receiver + write_data.needReporterTimeIndex(r_name, 2); + + // Initialize values const Real & value = getParam("default"); - _fe_problem.setPostprocessorValueByName(_pp_name, value, 0); + write_data.setReporterValue(r_name, value, 0); if (_initialize_old) { - _fe_problem.setPostprocessorValueByName(_pp_name, value, 1); - _fe_problem.setPostprocessorValueByName(_pp_name, value, 2); + write_data.setReporterValue(r_name, value, 1); + write_data.setReporterValue(r_name, value, 2); } } diff --git a/framework/src/problems/FEProblemBase.C b/framework/src/problems/FEProblemBase.C index b34159b88650..3fda3c824c2d 100644 --- a/framework/src/problems/FEProblemBase.C +++ b/framework/src/problems/FEProblemBase.C @@ -3508,12 +3508,18 @@ FEProblemBase::hasUserObject(const std::string & name) const return !objs.empty(); } +bool +FEProblemBase::hasPostprocessorValueByName(const PostprocessorName & name) const +{ + return _reporter_data.hasReporterValue(PostprocessorReporterName(name)); +} + const PostprocessorValue & FEProblemBase::getPostprocessorValueByName(const PostprocessorName & name, std::size_t t_index) const { - ReporterName r_name(name, "value"); - return _reporter_data.getReporterValue(r_name, t_index); + return _reporter_data.getReporterValue(PostprocessorReporterName(name), + t_index); } void @@ -3521,44 +3527,8 @@ FEProblemBase::setPostprocessorValueByName(const PostprocessorName & name, const PostprocessorValue & value, std::size_t t_index) { - ReporterName r_name(name, "value"); - _reporter_data.setReporterValue(r_name, value, t_index); -} - -bool -FEProblemBase::hasPostprocessor(const std::string & name) const -{ - mooseDeprecated("The 'FEProblemBase::hasPostprocssor' is being removed, use the method in the " - "PostprocessorInterface"); - ReporterName r_name(name, "value"); - return _reporter_data.hasReporterValue(r_name); -} - -PostprocessorValue & -FEProblemBase::getPostprocessorValue(const PostprocessorName & name) -{ - mooseDeprecated("The 'FEProblemBase::getPostpostProcessorValue' is being removed to improve " - "'const' correctness, it has been replaced by getPostprocessorValueByName"); - const PostprocessorValue & value = getPostprocessorValueByName(name, 0); - return const_cast(value); -} - -PostprocessorValue & -FEProblemBase::getPostprocessorValueOld(const std::string & name) -{ - mooseDeprecated("The 'FEProblemBase::getPostpostProcessorValue' is being removed to improve " - "'const' correctness, it has been replaced by getPostprocessorValueByName"); - const PostprocessorValue & value = getPostprocessorValueByName(name, 1); - return const_cast(value); -} - -PostprocessorValue & -FEProblemBase::getPostprocessorValueOlder(const std::string & name) -{ - mooseDeprecated("The 'FEProblemBase::getPostpostProcessorValue' is being removed to improve " - "'const' correctness, it has been replaced by getPostprocessorValueByName"); - const PostprocessorValue & value = getPostprocessorValueByName(name, 2); - return const_cast(value); + _reporter_data.setReporterValue( + PostprocessorReporterName(name), value, t_index); } const VectorPostprocessorValue & @@ -3566,8 +3536,8 @@ FEProblemBase::getVectorPostprocessorValueByName(const std::string & object_name const std::string & vector_name, std::size_t t_index) const { - ReporterName r_name(object_name, vector_name); - return _reporter_data.getReporterValue(r_name, t_index); + return _reporter_data.getReporterValue( + VectorPostprocessorReporterName(object_name, vector_name), t_index); } void @@ -3576,8 +3546,8 @@ FEProblemBase::setVectorPostprocessorValueByName(const std::string & object_name const VectorPostprocessorValue & value, std::size_t t_index) { - ReporterName r_name(object_name, vector_name); - _reporter_data.setReporterValue(r_name, value, t_index); + _reporter_data.setReporterValue( + VectorPostprocessorReporterName(object_name, vector_name), value, t_index); } const VectorPostprocessor & @@ -3587,65 +3557,6 @@ FEProblemBase::getVectorPostprocessorObjectByName(const std::string & object_nam return getUserObject(object_name, tid); } -bool -FEProblemBase::hasVectorPostprocessor(const std::string & name) -{ - mooseDeprecated("The 'FEProblemBase::hasVectorPostprocessor() is being removed to improve " - "'const' correctness. It has been replace by hasVectorPostprocessorByName."); - return hasUserObject(name); -} - -VectorPostprocessorValue & -FEProblemBase::getVectorPostprocessorValue(const VectorPostprocessorName & name, - const std::string & vector_name) -{ - mooseDeprecated("The 'FEProblemBase::getVectorPostprocessorValue() is being removed, use the " - "methods in VectorPostprocessorInterface."); - return const_cast( - getVectorPostprocessorValueByName(name, vector_name, 0)); -} - -VectorPostprocessorValue & -FEProblemBase::getVectorPostprocessorValueOld(const std::string & name, - const std::string & vector_name) -{ - mooseDeprecated("The 'FEProblemBase::getVectorPostprocessorValueOld() is being removed, use the " - "methods in VectorPostprocessorInterface."); - return const_cast( - getVectorPostprocessorValueByName(name, vector_name, 1)); -} - -VectorPostprocessorValue & -FEProblemBase::getVectorPostprocessorValue(const VectorPostprocessorName & name, - const std::string & vector_name, - bool /*needs_broadcast*/) -{ - mooseDeprecated("The 'FEProblemBase::getVectorPostprocessor() is being removed, use the methods " - "in VectorPostprocessorInterface."); - return const_cast( - getVectorPostprocessorValueByName(name, vector_name, 0)); -} - -VectorPostprocessorValue & -FEProblemBase::getVectorPostprocessorValueOld(const std::string & name, - const std::string & vector_name, - bool /*needs_broadcast*/) -{ - mooseDeprecated("The 'FEProblemBase::getVectorPostprocessorOld() is being removed, use the " - "methods in VectorPostprocessorInterface."); - return const_cast( - getVectorPostprocessorValueByName(name, vector_name, 1)); -} - -bool -FEProblemBase::vectorPostprocessorHasVectors(const std::string & vpp_name) -{ - mooseDeprecated("The 'FEProblemBase::vectorPostprocessorHasVectors() is being removed, use the " - "method in VectorPostprocessor object."); - const VectorPostprocessor & vpp_obj = getVectorPostprocessorObjectByName(vpp_name); - return !vpp_obj.getVectorNames().empty(); -} - void FEProblemBase::parentOutputPositionChanged() { diff --git a/framework/src/transfers/MultiAppConservativeTransfer.C b/framework/src/transfers/MultiAppConservativeTransfer.C index a1bb4af30088..74dbb864ae35 100644 --- a/framework/src/transfers/MultiAppConservativeTransfer.C +++ b/framework/src/transfers/MultiAppConservativeTransfer.C @@ -411,7 +411,7 @@ MultiAppConservativeTransfer::adjustTransferedSolution(FEProblemBase * from_prob to_problem.computeUserObjectByName(EXEC_TRANSFER, Moose::POST_AUX, to_postprocessor); // Now we should have the right adjuster based on the transfered solution - PostprocessorValue & to_adjuster = to_problem.getPostprocessorValue(to_postprocessor); + const auto to_adjuster = to_problem.getPostprocessorValueByName(to_postprocessor); // decide if the adjustment should be performed if (!performAdjustment(from_adjuster, to_adjuster)) diff --git a/framework/src/utils/InputParameters.C b/framework/src/utils/InputParameters.C index 399ee17c7db0..ff7f28af46be 100644 --- a/framework/src/utils/InputParameters.C +++ b/framework/src/utils/InputParameters.C @@ -697,56 +697,6 @@ InputParameters::getGroupName(const std::string & param_name) const return std::string(); } -bool -InputParameters::isDefaultPostprocessorValue(const std::string & param_name, - unsigned int index) const -{ - if (!isParamValid(param_name)) - mooseError("\"", param_name, "\" is not a valid parameter"); - - PostprocessorName name; - if (isType(param_name)) - { - if (index > 0) - mooseError( - "Requested index ", index, " for a single postprocessor parameter \"", param_name, "\""); - name = get(param_name); - } - else if (isType>(param_name)) - { - const auto & names = get>(param_name); - if (names.size() <= index) - mooseError("Out of range postprocessor index ", index, " for parameter \"", param_name, "\""); - name = get>(param_name)[index]; - } - else - mooseError(type(param_name), " is not a postprocessor parameter type"); - - std::istringstream ss(name); - Real real_value = -std::numeric_limits::max(); - return (ss >> real_value && ss.eof()); -} - -PostprocessorValue -InputParameters::getDefaultPostprocessorValue(const std::string & param_name, - const unsigned int index) const -{ - if (!isDefaultPostprocessorValue(param_name, index)) - mooseError("Postprocessor with parameter name \"", - param_name, - "\" and index ", - index, - " is not a default value"); - - Real real_value = -std::numeric_limits::max(); - std::istringstream ss(isType(param_name) - ? get(param_name) - : get>(param_name)[index]); - - ss >> real_value; - return real_value; -} - void InputParameters::applyParameters(const InputParameters & common, const std::vector exclude) diff --git a/modules/stochastic_tools/src/transfers/SamplerPostprocessorTransfer.C b/modules/stochastic_tools/src/transfers/SamplerPostprocessorTransfer.C index daa6170db787..98a5ef747265 100644 --- a/modules/stochastic_tools/src/transfers/SamplerPostprocessorTransfer.C +++ b/modules/stochastic_tools/src/transfers/SamplerPostprocessorTransfer.C @@ -94,7 +94,7 @@ SamplerPostprocessorTransfer::initialSetup() { FEProblemBase & app_problem = _multi_app->appProblemBase(i); for (const auto & sub_pp_name : _sub_pp_names) - if (!app_problem.hasPostprocessor(sub_pp_name)) + if (!app_problem.hasPostprocessorValueByName(sub_pp_name)) mooseError("Unknown postprocesssor name '", sub_pp_name, "' on sub-application '", @@ -128,7 +128,7 @@ SamplerPostprocessorTransfer::executeFromMultiapp() FEProblemBase & app_problem = _multi_app->appProblemBase(i); if (app_problem.converged() || _keep_diverge) for (std::size_t j = 0; j < _sub_pp_names.size(); ++j) - _current_data[j].emplace_back(app_problem.getPostprocessorValue(_sub_pp_names[j])); + _current_data[j].emplace_back(app_problem.getPostprocessorValueByName(_sub_pp_names[j])); else for (std::size_t j = 0; j < _sub_pp_names.size(); ++j) _current_data[j].emplace_back(std::numeric_limits::quiet_NaN()); @@ -157,7 +157,7 @@ SamplerPostprocessorTransfer::execute() { FEProblemBase & app_problem = _multi_app->appProblemBase(i); if (app_problem.converged() || _keep_diverge) - current.emplace_back(app_problem.getPostprocessorValue(_sub_pp_names[j])); + current.emplace_back(app_problem.getPostprocessorValueByName(_sub_pp_names[j])); else current.emplace_back(std::numeric_limits::quiet_NaN()); } diff --git a/test/src/kernels/DefaultPostprocessorDiffusion.C b/test/src/kernels/DefaultPostprocessorDiffusion.C index 930f4931a7f9..a4ac664bfb64 100644 --- a/test/src/kernels/DefaultPostprocessorDiffusion.C +++ b/test/src/kernels/DefaultPostprocessorDiffusion.C @@ -22,7 +22,7 @@ DefaultPostprocessorDiffusion::validParams() "found a default value of 0.1 is utlized for the postprocessor value"); params.addParam("test_default_error", false, - "Set this to true to test the hasDefaultPostprocessorValue error message"); + "Set this to true to test the getDefaultPostprocessorValue error message"); return params; } @@ -31,7 +31,7 @@ DefaultPostprocessorDiffusion::DefaultPostprocessorDiffusion(const InputParamete { // Test the error message for defaultPostprocessorValue if (getParam("test_default_error")) - parameters.getDefaultPostprocessorValue("invalid_postprocessor_name"); + getDefaultPostprocessorValue("pps_name"); } Real diff --git a/test/tests/interfaces/postprocessorinterface/tests b/test/tests/interfaces/postprocessorinterface/tests index 72e342f416f5..89a9a7bbc232 100644 --- a/test/tests/interfaces/postprocessorinterface/tests +++ b/test/tests/interfaces/postprocessorinterface/tests @@ -43,7 +43,7 @@ type = RunException input = 'ppi_errors.i' cli_args = 'UserObjects/error_test/name_for_default=true' - expect_err = 'Cannot get the name because the Postprocessor is a defualt value.' + expect_err = 'Cannot get the name associated with PostprocessorName parameter "pps" at index 1,.*because said parameter is a default Postprocessor value.' requirement = 'The system shall report a reasonable error when requesting a Postprocessor name from a parameter in which the postprocessor is a default value and not a name.' [] diff --git a/test/tests/postprocessors/default_value/tests b/test/tests/postprocessors/default_value/tests index 0da2f77362e6..eb2fa5715edd 100644 --- a/test/tests/postprocessors/default_value/tests +++ b/test/tests/postprocessors/default_value/tests @@ -26,10 +26,12 @@ [default_error] type = 'RunException' input = 'default_value.i' - cli_args = 'Kernels/diff/test_default_error=true' - expect_err = '\"invalid_postprocessor_name\" is not a valid parameter' + cli_args = 'Kernels/diff/test_default_error=true + Kernels/diff/pps_name=constant + Postprocessors/constant/type=FunctionValuePostprocessor + Postprocessors/constant/function=0' + expect_err = 'When getting the default Postprocessor value for parameter "pps_name" at index 0,.*the parameter does not represent a default Postprocessor value.' - requirement = 'The system shall report an error when a request for a non-existant Postprocessor ' - 'value is made.' + requirement = 'The system shall report an error when a request for a non-existant default Postprocessor value is made.' [] []