Skip to content

Commit

Permalink
Make the base class of NearestPointBase as a template
Browse files Browse the repository at this point in the history
  • Loading branch information
fdkong committed May 16, 2019
1 parent c2e92dd commit 884a12a
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 32 deletions.
56 changes: 31 additions & 25 deletions framework/include/userobject/NearestPointBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ class UserObject;
* If you inherit from this class... then call this function
* to start your parameters for the new class
*/
template <typename UserObjectType>
template <typename UserObjectType, typename BaseType>
InputParameters
nearestPointBaseValidParams()
{
InputParameters params = validParams<ElementIntegralVariableUserObject>();
InputParameters params = validParams<BaseType>();

params.addParam<std::vector<Point>>("points",
"Computations will be lumped into values at these points.");
Expand All @@ -51,8 +51,8 @@ nearestPointBaseValidParams()
* Given a list of points this object computes the layered average
* closest to each one of those points.
*/
template <typename UserObjectType>
class NearestPointBase : public ElementIntegralVariableUserObject
template <typename UserObjectType, typename BaseType>
class NearestPointBase : public BaseType
{
public:
NearestPointBase(const InputParameters & parameters);
Expand Down Expand Up @@ -92,11 +92,17 @@ class NearestPointBase : public ElementIntegralVariableUserObject

// The list of InputParameter objects. This is a list because these cannot be copied (or moved).
std::list<InputParameters> _sub_params;

using BaseType::_communicator;
using BaseType::_current_elem;
using BaseType::isParamValid;
using BaseType::name;
using BaseType::processor_id;
};

template <typename UserObjectType>
NearestPointBase<UserObjectType>::NearestPointBase(const InputParameters & parameters)
: ElementIntegralVariableUserObject(parameters)
template <typename UserObjectType, typename BaseType>
NearestPointBase<UserObjectType, BaseType>::NearestPointBase(const InputParameters & parameters)
: BaseType(parameters)
{
fillPoints();

Expand All @@ -114,25 +120,25 @@ NearestPointBase<UserObjectType>::NearestPointBase(const InputParameters & param
}
}

template <typename UserObjectType>
NearestPointBase<UserObjectType>::~NearestPointBase()
template <typename UserObjectType, typename BaseType>
NearestPointBase<UserObjectType, BaseType>::~NearestPointBase()
{
}

template <typename UserObjectType>
template <typename UserObjectType, typename BaseType>
void
NearestPointBase<UserObjectType>::fillPoints()
NearestPointBase<UserObjectType, BaseType>::fillPoints()
{
if (isParamValid("points") && isParamValid("points_file"))
mooseError(name(), ": Both 'points' and 'points_file' cannot be specified simultaneously.");

if (isParamValid("points"))
{
_points = getParam<std::vector<Point>>("points");
_points = this->template getParam<std::vector<Point>>("points");
}
else if (isParamValid("points_file"))
{
const FileName & points_file = getParam<FileName>("points_file");
const FileName & points_file = this->template getParam<FileName>("points_file");
std::vector<Real> points_vec;

if (processor_id() == 0)
Expand Down Expand Up @@ -170,49 +176,49 @@ NearestPointBase<UserObjectType>::fillPoints()
mooseError(name(), ": You need to supply either 'points' or 'points_file' parameter.");
}

template <typename UserObjectType>
template <typename UserObjectType, typename BaseType>
void
NearestPointBase<UserObjectType>::initialize()
NearestPointBase<UserObjectType, BaseType>::initialize()
{
for (auto & user_object : _user_objects)
user_object->initialize();
}

template <typename UserObjectType>
template <typename UserObjectType, typename BaseType>
void
NearestPointBase<UserObjectType>::execute()
NearestPointBase<UserObjectType, BaseType>::execute()
{
nearestUserObject(_current_elem->centroid())->execute();
}

template <typename UserObjectType>
template <typename UserObjectType, typename BaseType>
void
NearestPointBase<UserObjectType>::finalize()
NearestPointBase<UserObjectType, BaseType>::finalize()
{
for (auto & user_object : _user_objects)
user_object->finalize();
}

template <typename UserObjectType>
template <typename UserObjectType, typename BaseType>
void
NearestPointBase<UserObjectType>::threadJoin(const UserObject & y)
NearestPointBase<UserObjectType, BaseType>::threadJoin(const UserObject & y)
{
auto & npla = static_cast<const NearestPointBase &>(y);

for (MooseIndex(_user_objects) i = 0; i < _user_objects.size(); ++i)
_user_objects[i]->threadJoin(*npla._user_objects[i]);
}

template <typename UserObjectType>
template <typename UserObjectType, typename BaseType>
Real
NearestPointBase<UserObjectType>::spatialValue(const Point & p) const
NearestPointBase<UserObjectType, BaseType>::spatialValue(const Point & p) const
{
return nearestUserObject(p)->spatialValue(p);
}

template <typename UserObjectType>
template <typename UserObjectType, typename BaseType>
std::shared_ptr<UserObjectType>
NearestPointBase<UserObjectType>::nearestUserObject(const Point & p) const
NearestPointBase<UserObjectType, BaseType>::nearestUserObject(const Point & p) const
{
unsigned int closest = 0;
Real closest_distance = std::numeric_limits<Real>::max();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// MOOSE includes
#include "NearestPointBase.h"
#include "ElementIntegralVariablePostprocessor.h"

#include "ElementIntegralVariableUserObject.h"
// Forward Declarations
class NearestPointIntegralVariablePostprocessor;

Expand All @@ -25,7 +25,7 @@ InputParameters validParams<NearestPointIntegralVariablePostprocessor>();
* closest to each one of those points.
*/
class NearestPointIntegralVariablePostprocessor
: public NearestPointBase<ElementIntegralVariablePostprocessor>
: public NearestPointBase<ElementIntegralVariablePostprocessor, ElementIntegralVariableUserObject>
{
public:
NearestPointIntegralVariablePostprocessor(const InputParameters & parameters);
Expand Down
3 changes: 2 additions & 1 deletion framework/include/userobject/NearestPointLayeredAverage.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ InputParameters validParams<NearestPointLayeredAverage>();
* Given a list of points this object computes the layered average
* closest to each one of those points.
*/
class NearestPointLayeredAverage : public NearestPointBase<LayeredAverage>
class NearestPointLayeredAverage
: public NearestPointBase<LayeredAverage, ElementIntegralVariableUserObject>
{
public:
NearestPointLayeredAverage(const InputParameters & parameters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ template <>
InputParameters
validParams<NearestPointIntegralVariablePostprocessor>()
{
InputParameters params = nearestPointBaseValidParams<ElementIntegralVariablePostprocessor>();
InputParameters params = nearestPointBaseValidParams<ElementIntegralVariablePostprocessor,
ElementIntegralVariableUserObject>();

return params;
}

NearestPointIntegralVariablePostprocessor::NearestPointIntegralVariablePostprocessor(
const InputParameters & parameters)
: NearestPointBase<ElementIntegralVariablePostprocessor>(parameters)
: NearestPointBase<ElementIntegralVariablePostprocessor, ElementIntegralVariableUserObject>(
parameters)
{
}

Expand Down
5 changes: 3 additions & 2 deletions framework/src/userobject/NearestPointLayeredAverage.C
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ template <>
InputParameters
validParams<NearestPointLayeredAverage>()
{
InputParameters params = nearestPointBaseValidParams<LayeredAverage>();
InputParameters params =
nearestPointBaseValidParams<LayeredAverage, ElementIntegralVariableUserObject>();

return params;
}

NearestPointLayeredAverage::NearestPointLayeredAverage(const InputParameters & parameters)
: NearestPointBase<LayeredAverage>(parameters)
: NearestPointBase<LayeredAverage, ElementIntegralVariableUserObject>(parameters)
{
}

0 comments on commit 884a12a

Please sign in to comment.