Skip to content

Commit

Permalink
Improve VectorPostprocessorInterface
Browse files Browse the repository at this point in the history
- Use the object's mooseError() and paramError() where possible
- Improve function signatures
- Use error checking in overridden methods

refs idaholab#17512
  • Loading branch information
loganharbour authored and aeslaughter committed Jun 2, 2021
1 parent ff80c7d commit 9f492be
Show file tree
Hide file tree
Showing 19 changed files with 526 additions and 152 deletions.
8 changes: 4 additions & 4 deletions framework/include/auxkernels/AuxKernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,14 @@ class AuxKernelTempl : public MooseObject,
getPostprocessorValueByName(const PostprocessorName & name) const override;

const VectorPostprocessorValue &
getVectorPostprocessorValue(const std::string & name,
getVectorPostprocessorValue(const std::string & param_name,
const std::string & vector_name) const override final;
const VectorPostprocessorValue &
getVectorPostprocessorValueByName(const VectorPostprocessorName &,
const std::string & vector_name) const override final;

const VectorPostprocessorValue &
getVectorPostprocessorValue(const std::string & name,
getVectorPostprocessorValue(const std::string & param_name,
const std::string & vector_name,
bool needs_broadcast) const override final;
const VectorPostprocessorValue &
Expand All @@ -148,11 +148,11 @@ class AuxKernelTempl : public MooseObject,
bool needs_broadcast) const override final;

const ScatterVectorPostprocessorValue &
getScatterVectorPostprocessorValue(const std::string & name,
getScatterVectorPostprocessorValue(const std::string & param_name,
const std::string & vector_name) const override final;

const ScatterVectorPostprocessorValue &
getScatterVectorPostprocessorValueByName(const std::string & name,
getScatterVectorPostprocessorValueByName(const VectorPostprocessorName & name,
const std::string & vector_name) const override final;

protected:
Expand Down
1 change: 0 additions & 1 deletion framework/include/reporters/ReporterData.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ class ReporterData
friend class Reporter;
friend class ReporterInterface;
friend class VectorPostprocessor;
friend class VectorPostprocessorInterface;
friend class ReporterTransferInterface;
};

Expand Down
4 changes: 2 additions & 2 deletions framework/include/userobject/GeneralUserObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ class GeneralUserObject : public UserObject,
getPostprocessorValueByName(const PostprocessorName & name) const override final;

const VectorPostprocessorValue &
getVectorPostprocessorValue(const std::string & name,
getVectorPostprocessorValue(const std::string & param_name,
const std::string & vector_name) const override final;
const VectorPostprocessorValue &
getVectorPostprocessorValueByName(const VectorPostprocessorName & name,
const std::string & vector_name) const override final;

const VectorPostprocessorValue &
getVectorPostprocessorValue(const std::string & name,
getVectorPostprocessorValue(const std::string & param_name,
const std::string & vector_name,
bool use_broadcast) const override final;
const VectorPostprocessorValue &
Expand Down
8 changes: 4 additions & 4 deletions framework/include/userobject/UserObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,14 @@ class UserObject : public MooseObject,
getPostprocessorValueByName(const PostprocessorName & name) const override;

virtual const VectorPostprocessorValue &
getVectorPostprocessorValue(const std::string & name,
getVectorPostprocessorValue(const std::string & param_name,
const std::string & vector_name) const override;
virtual const VectorPostprocessorValue &
getVectorPostprocessorValueByName(const VectorPostprocessorName & name,
const std::string & vector_name) const override;

virtual const VectorPostprocessorValue &
getVectorPostprocessorValue(const std::string & name,
getVectorPostprocessorValue(const std::string & param_name,
const std::string & vector_name,
bool needs_broadcast) const override;
virtual const VectorPostprocessorValue &
Expand All @@ -187,10 +187,10 @@ class UserObject : public MooseObject,
bool needs_broadcast) const override;

const ScatterVectorPostprocessorValue &
getScatterVectorPostprocessorValue(const std::string & name,
getScatterVectorPostprocessorValue(const std::string & param_name,
const std::string & vector_name) const override final;
const ScatterVectorPostprocessorValue &
getScatterVectorPostprocessorValueByName(const std::string & name,
getScatterVectorPostprocessorValueByName(const VectorPostprocessorName & name,
const std::string & vector_name) const override final;

/**
Expand Down
6 changes: 4 additions & 2 deletions framework/include/vectorpostprocessors/LineValueSampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class LineValueSampler : public PointSamplerBase
* Gets the value of the variable at a point p.
* Returns zero if p does not lie along the line segment.
**/
Real getValue(Point p) const;
Real getValue(const Point & p) const;

protected:
const Point _start_point;
Expand All @@ -66,5 +66,7 @@ class LineValueSampler : public PointSamplerBase

/// Length of line segment
const Real _line_vector_norm;
};

private:
const VectorPostprocessorValue & _vpp_value;
};
10 changes: 5 additions & 5 deletions framework/include/vectorpostprocessors/VectorPostprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class VectorPostprocessor : public OutputInterface
/**
* Returns the name of the VectorPostprocessor.
*/
std::string PPName() { return _vpp_name; }
std::string PPName() const { return _vpp_name; }

/**
* Return whether or not this VectorPostprocessor contains complete history
Expand All @@ -70,18 +70,18 @@ class VectorPostprocessor : public OutputInterface
VectorPostprocessorValue & declareVector(const std::string & vector_name);

/// The name of the VectorPostprocessor
std::string _vpp_name;
const std::string _vpp_name;

/// Pointer to FEProblemBase
FEProblemBase * _vpp_fe_problem;
/// The FEProblemBase
FEProblemBase & _vpp_fe_problem;

/// DISTRIBUTED or REPLICATED
const MooseEnum & _parallel_type;

friend class SamplerBase;

private:
THREAD_ID _vpp_tid;
const THREAD_ID _vpp_tid;

const bool _contains_complete_history;

Expand Down
108 changes: 70 additions & 38 deletions framework/include/vectorpostprocessors/VectorPostprocessorInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class VectorPostprocessorInterface
* not the vector must be broadcast
*
* Retrieve the value of a VectorPostprocessor
* @param name The name of the VectorPostprocessor parameter (see below)
* @param param_name The name of the VectorPostprocessor parameter (see below)
* @param vector_name The name of the particular vector you want.
* @return A reference to the desired value
*
Expand All @@ -56,7 +56,8 @@ class VectorPostprocessorInterface
* getVectorPostprocessorValueOldByName
*/
virtual const VectorPostprocessorValue &
getVectorPostprocessorValue(const std::string & name, const std::string & vector_name) const;
getVectorPostprocessorValue(const std::string & param_name,
const std::string & vector_name) const;

/**
* DEPRECATED: Use the new version where you need to specify whether or
Expand Down Expand Up @@ -84,14 +85,15 @@ class VectorPostprocessorInterface
* not the vector must be broadcast
*
* Retrieve the old value of a VectorPostprocessor
* @param name The name of the VectorPostprocessor parameter
* @param param_name The name of the VectorPostprocessor parameter
* @param vector_name The name of the particular vector you want.
* @return The value of the VectorPostprocessor
*
* see getVectorPostprocessorValue
*/
const VectorPostprocessorValue &
getVectorPostprocessorValueOld(const std::string & name, const std::string & vector_name) const;
getVectorPostprocessorValueOld(const std::string & param_name,
const std::string & vector_name) const;

/**
* DEPRECATED: Use the new version where you need to specify whether or
Expand All @@ -115,7 +117,7 @@ class VectorPostprocessorInterface

/**
* Retrieve the value of a VectorPostprocessor
* @param name The name of the VectorPostprocessor parameter (see below)
* @param param_name The name of the VectorPostprocessor parameter (see below)
* @param vector_name The name of the particular vector you want.
* @param need_broadcast Whether or not this object requires the vector to
* be replicated in parallel
Expand All @@ -130,7 +132,7 @@ class VectorPostprocessorInterface
* getVectorPostprocessorValueOldByName
*/
virtual const VectorPostprocessorValue & getVectorPostprocessorValue(
const std::string & name, const std::string & vector_name, bool needs_broadcast) const;
const std::string & param_name, const std::string & vector_name, bool needs_broadcast) const;

/**
* Retrieve the value of the VectorPostprocessor
Expand All @@ -155,7 +157,7 @@ class VectorPostprocessorInterface

/**
* Retrieve the old value of a VectorPostprocessor
* @param name The name of the VectorPostprocessor parameter
* @param param_name The name of the VectorPostprocessor parameter
* @param vector_name The name of the particular vector you want.
* @param need_broadcast Whether or not this object requires the vector to
* be replicated in parallel
Expand All @@ -164,7 +166,7 @@ class VectorPostprocessorInterface
* see getVectorPostprocessorValue
*/
virtual const VectorPostprocessorValue & getVectorPostprocessorValueOld(
const std::string & name, const std::string & vector_name, bool needs_broadcast) const;
const std::string & param_name, const std::string & vector_name, bool needs_broadcast) const;

/**
* Retrieve the old value of a VectorPostprocessor
Expand Down Expand Up @@ -193,12 +195,12 @@ class VectorPostprocessorInterface
* In that case - this will return a reference to a value that will be _this_ processor's value
* from that vector
*
* @param name The name of the parameter holding the vpp name
* @param param_name The name of the parameter holding the vpp name
* @param vector_name The name of the vector
* @return The reference to the current scatter value
*/
virtual const ScatterVectorPostprocessorValue &
getScatterVectorPostprocessorValue(const std::string & name,
getScatterVectorPostprocessorValue(const std::string & param_name,
const std::string & vector_name) const;

/**
Expand All @@ -208,12 +210,12 @@ class VectorPostprocessorInterface
* In that case - this will return a reference to a value that will be _this_ processor's value
* from that vector
*
* @param vpp_name The name of the VectorPostprocessor
* @param name The name of the VectorPostprocessor
* @param vector_name The name of the vector
* @return The reference to the current scatter value
*/
virtual const ScatterVectorPostprocessorValue &
getScatterVectorPostprocessorValueByName(const std::string & name,
getScatterVectorPostprocessorValueByName(const VectorPostprocessorName & name,
const std::string & vector_name) const;

/**
Expand All @@ -223,12 +225,12 @@ class VectorPostprocessorInterface
* In that case - this will return a reference to a value that will be _this_ processor's
* value from that vector
*
* @param name The name of the parameter holding the vpp name
* @param param_name The name of the parameter holding the vpp name
* @param vector_name The name of the vector
* @return The reference to the old scatter value
*/
virtual const ScatterVectorPostprocessorValue &
getScatterVectorPostprocessorValueOld(const std::string & name,
getScatterVectorPostprocessorValueOld(const std::string & param_name,
const std::string & vector_name) const;

/**
Expand All @@ -238,85 +240,115 @@ class VectorPostprocessorInterface
* In that case - this will return a reference to a value that will be _this_ processor's
* value from that vector
*
* @param vpp_name The name of the VectorPostprocessor
* @param name The name of the VectorPostprocessor
* @param vector_name The name of the vector
* @return The reference to the old scatter value
*/
virtual const ScatterVectorPostprocessorValue &
getScatterVectorPostprocessorValueOldByName(const std::string & name,
getScatterVectorPostprocessorValueOldByName(const VectorPostprocessorName & name,
const std::string & vector_name) const;

/**
* Determine if the VectorPostprocessor data exists
* @param name The name of the VectorPostprocessor parameter
* @return True if the VectorPostprocessor exists
* Determine if the VectorPostprocessor data exists by parameter
* @param param_name The name of the VectorPostprocessor parameter
* @param vector_name The vector name within the VectorPostprocessor
* @return True if the VectorPostprocessor data exists
*
* @see hasVectorPostprocessorByName getVectorPostprocessorValue
*/
bool hasVectorPostprocessor(const std::string & name, const std::string & vector_name) const;
bool hasVectorPostprocessor(const std::string & param_name,
const std::string & vector_name) const;

/**
* Determine if the VectorPostprocessor data exists
* Determine if the VectorPostprocessor data exists by name
* @param name The name of the VectorPostprocessor
* @return True if the VectorPostprocessor exists
* @param vector_name The vector name within the VectorPostprocessor
* @return True if the VectorPostprocessor data exists
*
* @see hasVectorPostprocessor getVectorPostprocessorValueByName
*/
bool hasVectorPostprocessorByName(const VectorPostprocessorName & name,
const std::string & vector_name) const;

/**
* Determine if the VectorPostprocessor object exists
* Determine if the VectorPostprocessor exists by parameter
* @param name The name of the VectorPostprocessor parameter
* @return True if the VectorPostprocessor exists
* @return True if the C++ object exists
*/
bool hasVectorPostprocessorObject(const std::string & name) const;
bool hasVectorPostprocessor(const std::string & param_name) const;

/**
* Determine if the VectorPostprocessor object exists
* Determine if the VectorPostprocessor exists by name
* @param name The name of the VectorPostprocessor
* @return True if the C++ object exists
* @return True if the VectorPostprocessor exists
*/
bool hasVectorPostprocessorObjectByName(const VectorPostprocessorName & name) const;
bool hasVectorPostprocessorByName(const VectorPostprocessorName & name) const;

///@{
/**
* Return true if the VectorPostprocessor is marked with parallel_type as DISTRIBUTED
*/
bool isVectorPostprocessorDistributed(const std::string & name) const;
bool isVectorPostprocessorDistributed(const std::string & param_name) const;
bool isVectorPostprocessorDistributedByName(const VectorPostprocessorName & name) const;
///@}

/**
* Get the name of a VectorPostprocessor associated with a parameter.
* @param param_name The name of the VectorPostprocessor parameter
* @return The name of the given VectorPostprocessor
*/
const VectorPostprocessorName & getVectorPostprocessorName(const std::string & param_name) const;

private:
/**
* Helper function for extracting VPP data from ReporterData object
*/
const VectorPostprocessorValue &
getVectorPostprocessorByNameHelper(const std::string & object_name,
getVectorPostprocessorByNameHelper(const VectorPostprocessorName & name,
const std::string & vector_name,
bool broadcast,
std::size_t t_index) const;

/**
* Helper for getting the VPP context that handles scatter values
*/
const VectorPostprocessorContext<VectorPostprocessorValue> *
getVectorPostprocessorContextByNameHelper(const std::string & object_name,
const VectorPostprocessorContext<VectorPostprocessorValue> &
getVectorPostprocessorContextByNameHelper(const VectorPostprocessorName & name,
const std::string & vector_name) const;

///@{
/**
* Helpers for "possibly" checking if a vpp exists. This is only able to check for
* existance after all vpps have been added (after the task creating them has
* been called). If called before said task, this will do nothing, hence the
* "possibly". This allows us to have errors reported directly by the object
* requesting the vpp instead of through a system with less context.
*/
void possiblyCheckHasVectorPostprocessor(const std::string & param_name,
const std::string & vector_name) const;
/**
* Helper for checking if a VectorPostprocessor exists. This is only able to check
* for validity after all VectorPostprocessors have been added. If called before
* VectorPostprocessors have been added, this will do nothing, hence the "possibly".
*/
void possiblyCheckHasVectorPostprocessorByName(const VectorPostprocessorName & name,
const std::string & vector_name) const;
///@}

/**
* @returns True if all vpps have been added (the task associated with adding them is complete)
*/
bool vectorPostprocessorsAdded() const;

/// Whether or not to force broadcasting by default
const bool _broadcast_by_default;

/// VectorPostprocessorInterface Parameters
const InputParameters & _vpi_params;
/// The MooseObject that uses this interface
const MooseObject & _vpi_moose_object;

/// Reference the FEProblemBase class
FEProblemBase & _vpi_feproblem;
const FEProblemBase & _vpi_feproblem;

/// Thread ID
const THREAD_ID _vpi_tid;

/// Reference to the ReporterData that stores the vector
ReporterData & _vpi_reporter_data;
};

0 comments on commit 9f492be

Please sign in to comment.