Skip to content

Commit

Permalink
Add in base class for helping to create AuxKernels that use group sol…
Browse files Browse the repository at this point in the history
…ution values. Add example objects and tests. closes idaholab#10
  • Loading branch information
friedmud committed Oct 14, 2017
1 parent be288b9 commit ead5cc3
Show file tree
Hide file tree
Showing 13 changed files with 411 additions and 2 deletions.
40 changes: 40 additions & 0 deletions modules/ray_tracing/include/auxkernels/AverageGroupValueAux.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/****************************************************************/
/* DO NOT MODIFY THIS HEADER */
/* MOOSE - Multiphysics Object Oriented Simulation Environment */
/* */
/* (c) 2010 Battelle Energy Alliance, LLC */
/* ALL RIGHTS RESERVED */
/* */
/* Prepared by Battelle Energy Alliance, LLC */
/* Under Contract No. DE-AC07-05ID14517 */
/* With the U. S. Department of Energy */
/* */
/* See COPYRIGHT for full restrictions */
/****************************************************************/

#ifndef AVERAGEGROUPVALUEAUX_H
#define AVERAGEGROUPVALUEAUX_H

#include "AuxKernel.h"

// Local Includes
#include "GroupValueAuxBase.h"

// Forward Declarations
class AverageGroupValueAux;

template <>
InputParameters validParams<AverageGroupValueAux>();

class AverageGroupValueAux : public GroupValueAuxBase
{
public:
AverageGroupValueAux(const InputParameters & parameters);

virtual ~AverageGroupValueAux() {}

protected:
virtual Real computeValue();
};

#endif // AVERAGEGROUPVALUEAUX_H
53 changes: 53 additions & 0 deletions modules/ray_tracing/include/auxkernels/GroupValueAuxBase.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/****************************************************************/
/* DO NOT MODIFY THIS HEADER */
/* MOOSE - Multiphysics Object Oriented Simulation Environment */
/* */
/* (c) 2010 Battelle Energy Alliance, LLC */
/* ALL RIGHTS RESERVED */
/* */
/* Prepared by Battelle Energy Alliance, LLC */
/* Under Contract No. DE-AC07-05ID14517 */
/* With the U. S. Department of Energy */
/* */
/* See COPYRIGHT for full restrictions */
/****************************************************************/

#ifndef GROUPVALUEAUXBASE_H
#define GROUPVALUEAUXBASE_H

#include "AuxKernel.h"

// Local Includes
#include "RayProblem.h"

// Forward Declarations
class GroupValueAuxBase;

template <>
InputParameters validParams<GroupValueAuxBase>();

class GroupValueAuxBase : public AuxKernel
{
public:
GroupValueAuxBase(const InputParameters & parameters);

virtual ~GroupValueAuxBase() {}

protected:
/// The RAY Problem
RayProblem & _ray_problem;

/// The RAY System
RaySystem & _ray_sys;

/// Number of energy groups in the problem
unsigned int _num_groups;

/// Offest into the vectors
dof_id_type & _current_offset;

/// READ only! The current group values
PetscScalar *& _group_values;
};

#endif // GROUPVALUEAUXBASE_H
72 changes: 72 additions & 0 deletions modules/ray_tracing/include/ray_kernels/ConstantGroupValues.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/****************************************************************/
/* DO NOT MODIFY THIS HEADER */
/* MOOSE - Multiphysics Object Oriented Simulation Environment */
/* */
/* (c) 2010 Battelle Energy Alliance, LLC */
/* ALL RIGHTS RESERVED */
/* */
/* Prepared by Battelle Energy Alliance, LLC */
/* Under Contract No. DE-AC07-05ID14517 */
/* With the U. S. Department of Energy */
/* */
/* See COPYRIGHT for full restrictions */
/****************************************************************/

#ifndef CONSTANTGROUPVALUES_H
#define CONSTANTGROUPVALUES_H

// Local Includes
#include "Ray.h"
#include "RayKernel.h"

class ConstantGroupValues;

template <>
InputParameters validParams<ConstantGroupValues>();

class ConstantGroupValues : public RayKernel
{
public:
ConstantGroupValues(const InputParameters & params);
virtual ~ConstantGroupValues();

virtual void initialSetup() {}
virtual void timestepSetup() {}

/**
* Called at the beginning of a new Ray trace
*
* Useful for caching data!
*/
virtual void rayStart() {}

/**
* Called on each Segment
* @param start The beginning of the segment
* @param end The end of the segment
* @param ends_in_elem Whether or not the Ray ends _within_ the current element. Note: this is
* NOT true if the Ray hits a physical boundary on one side of the element. It is _only_ true if
* the Ray truly ends _within_ the element.
*/
virtual void onSegment(const Elem * /*elem*/,
const Point & /*start*/,
const Point & /*end*/,
bool /*ends_in_elem*/);

/**
* Set the current Ray that's being worked on
*/
virtual void setRay(const std::shared_ptr<Ray> & ray);

protected:
/// Number of groups in the problem
unsigned int _num_groups;

/// Values to use for each group
const std::vector<Real> & _input_group_values;

/// Pointer to the beginning of the Ray's data
Real * _ray_data;
};

#endif /* CONSTANTGROUPVALUES_H */
6 changes: 6 additions & 0 deletions modules/ray_tracing/include/systems/RaySystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ class RaySystem : public SystemBase, public ConsoleStreamInterface
return _threaded_data[tid]._group_solution_values;
}

/**
* Get the raw PETSc vector that holds group values
* This is for _read only_ access _after_ a sweep has been done!
*/
PetscScalar *& currentGroupSolutionValues() { return _current_group_solution_values; }

/**
* Get the ray tracing results
*/
Expand Down
39 changes: 39 additions & 0 deletions modules/ray_tracing/src/auxkernels/AverageGroupValueAux.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/****************************************************************/
/* DO NOT MODIFY THIS HEADER */
/* MOOSE - Multiphysics Object Oriented Simulation Environment */
/* */
/* (c) 2010 Battelle Energy Alliance, LLC */
/* ALL RIGHTS RESERVED */
/* */
/* Prepared by Battelle Energy Alliance, LLC */
/* Under Contract No. DE-AC07-05ID14517 */
/* With the U. S. Department of Energy */
/* */
/* See COPYRIGHT for full restrictions */
/****************************************************************/

#include "AverageGroupValueAux.h"

template <>
InputParameters
validParams<AverageGroupValueAux>()
{
InputParameters params = validParams<GroupValueAuxBase>();
return params;
}

AverageGroupValueAux::AverageGroupValueAux(const InputParameters & parameters)
: GroupValueAuxBase(parameters)
{
}

Real
AverageGroupValueAux::computeValue()
{
Real total = 0;

for (unsigned int g = 0; g < _num_groups; g++)
total += _group_values[_current_offset + g];

return total / static_cast<Real>(_num_groups);
}
33 changes: 33 additions & 0 deletions modules/ray_tracing/src/auxkernels/GroupValueAuxBase.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/****************************************************************/
/* DO NOT MODIFY THIS HEADER */
/* MOOSE - Multiphysics Object Oriented Simulation Environment */
/* */
/* (c) 2010 Battelle Energy Alliance, LLC */
/* ALL RIGHTS RESERVED */
/* */
/* Prepared by Battelle Energy Alliance, LLC */
/* Under Contract No. DE-AC07-05ID14517 */
/* With the U. S. Department of Energy */
/* */
/* See COPYRIGHT for full restrictions */
/****************************************************************/

#include "GroupValueAuxBase.h"

template <>
InputParameters
validParams<GroupValueAuxBase>()
{
InputParameters params = validParams<AuxKernel>();
return params;
}

GroupValueAuxBase::GroupValueAuxBase(const InputParameters & parameters)
: AuxKernel(parameters),
_ray_problem(dynamic_cast<RayProblem &>(*parameters.get<FEProblem *>("_fe_problem"))),
_ray_sys(_ray_problem.raySystem()),
_num_groups(_ray_problem.numGroups()),
_current_offset(_ray_sys.currentOffset(_tid)),
_group_values(_ray_sys.currentGroupSolutionValues())
{
}
8 changes: 8 additions & 0 deletions modules/ray_tracing/src/base/RayTracingApp.C
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

// Ray Kernels
#include "AccumulateDistance.h"
#include "ConstantGroupValues.h"

// Ray Materials
#include "ConstantRayMaterial.h"
Expand All @@ -20,6 +21,9 @@
#include "AddRayKernelAction.h"
#include "AddRayBCAction.h"

// AuxKernels
#include "AverageGroupValueAux.h"

template <>
InputParameters
validParams<RayTracingApp>()
Expand Down Expand Up @@ -69,9 +73,13 @@ RayTracingApp::registerObjects(Factory & factory)

// Ray Kernels
registerUserObject(AccumulateDistance);
registerUserObject(ConstantGroupValues);

// Ray Materials
registerUserObject(ConstantRayMaterial);

// AuxKernels
registerAux(AverageGroupValueAux);
}

// External entry point for dynamic syntax association
Expand Down
2 changes: 0 additions & 2 deletions modules/ray_tracing/src/problems/RayProblem.C
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ RayProblem::RaySubdomainSetup(SubdomainID subdomain, THREAD_ID tid)
void
RayProblem::reinitElem(const Elem * elem, THREAD_ID tid)
{
// std::cout << "RayProblem::reinitElem()" << std::endl;

_ray_system->reinitElem(elem, tid);

FEProblem::reinitElem(elem, tid);
Expand Down
60 changes: 60 additions & 0 deletions modules/ray_tracing/src/ray_kernels/ConstantGroupValues.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/****************************************************************/
/* DO NOT MODIFY THIS HEADER */
/* MOOSE - Multiphysics Object Oriented Simulation Environment */
/* */
/* (c) 2010 Battelle Energy Alliance, LLC */
/* ALL RIGHTS RESERVED */
/* */
/* Prepared by Battelle Energy Alliance, LLC */
/* Under Contract No. DE-AC07-05ID14517 */
/* With the U. S. Department of Energy */
/* */
/* See COPYRIGHT for full restrictions */
/****************************************************************/

#include "ConstantGroupValues.h"

// Local Includes
#include "RayProblem.h"
#include "RaySystem.h"

// MOOSE Includes
#include "MooseMesh.h"

template <>
InputParameters
validParams<ConstantGroupValues>()
{
InputParameters params = validParams<RayKernel>();

params.addRequiredParam<std::vector<Real>>("group_values", "The value for each group");

return params;
}

ConstantGroupValues::ConstantGroupValues(const InputParameters & params)
: RayKernel(params),
_num_groups(_ray_problem.numGroups()),
_input_group_values(getParam<std::vector<Real>>("group_values"))
{
if (_num_groups != _input_group_values.size())
mooseError("group_values size does not match num_groups! In ", name());
}

ConstantGroupValues::~ConstantGroupValues() {}

void
ConstantGroupValues::onSegment(const Elem * /*elem*/,
const Point & /* start */,
const Point & /* end */,
bool /* ends_in_elem */)
{
for (unsigned int g = 0; g < _num_groups; g++)
_group_solution_values[_current_offset + g] = _input_group_values[g];
}

void
ConstantGroupValues::setRay(const std::shared_ptr<Ray> & ray)
{
RayKernel::setRay(ray);
}
3 changes: 3 additions & 0 deletions modules/ray_tracing/src/systems/RaySystem.C
Original file line number Diff line number Diff line change
Expand Up @@ -309,4 +309,7 @@ RaySystem::postSweep()
_current_group_solution += (*_threaded_data[tid]._group_solution);

_current_group_solution.close();

// Before exiting... update this in case anyone wants it
VecGetArray(_current_group_solution.vec(), &_current_group_solution_values);
}
Loading

0 comments on commit ead5cc3

Please sign in to comment.