Skip to content

Commit

Permalink
Added ElementValueSampler vector postprocessor
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuahansel committed May 29, 2018
1 parent 113d964 commit 1725e2f
Show file tree
Hide file tree
Showing 13 changed files with 304 additions and 9 deletions.
@@ -0,0 +1,16 @@
# ElementValueSampler

!syntax description /VectorPostprocessors/ElementValueSampler

This `VectorPostprocessor` is similar to [NodalValueSampler](NodalValueSampler.md),
but is used for sampling elemental variables instead of nodal variables. The
coordinate used for each sampling point is the centroid of the associated
element.

!syntax parameters /VectorPostprocessors/ElementValueSampler

!syntax inputs /VectorPostprocessors/ElementValueSampler

!syntax children /VectorPostprocessors/ElementValueSampler

!bibtex bibliography
@@ -1,15 +1,10 @@
<!-- MOOSE Documentation Stub: Remove this when content is added. -->

# NodalValueSampler

!alert construction title=Undocumented Class
The NodalValueSampler has not been documented, if you would like to contribute to MOOSE by
writing documentation, please see [/generate.md]. The content contained on this page explains
the typical documentation associated with a MooseObject; however, what is contained is ultimately
determined by what is necessary to make the documentation clear for users.

!syntax description /VectorPostprocessors/NodalValueSampler

This `VectorPostprocessor` is used for sampling nodal variables at each node
in the domain, selection of blocks, or selection of boundaries.

!syntax parameters /VectorPostprocessors/NodalValueSampler

!syntax inputs /VectorPostprocessors/NodalValueSampler
Expand Down
1 change: 0 additions & 1 deletion framework/doc/hidden.yml
Expand Up @@ -340,7 +340,6 @@
- /VectorPostprocessors/LineMaterialRealSampler
- /VectorPostprocessors/LineValueSampler
- /VectorPostprocessors/MaterialVectorPostprocessor
- /VectorPostprocessors/NodalValueSampler
- /VectorPostprocessors/PointValueSampler
- /VectorPostprocessors/SideValueSampler
- /VectorPostprocessors/SphericalAverage
Expand Down
45 changes: 45 additions & 0 deletions framework/include/vectorpostprocessors/ElementValueSampler.h
@@ -0,0 +1,45 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#ifndef ELEMENTVALUESAMPLER_H
#define ELEMENTVALUESAMPLER_H

#include "ElementVariableVectorPostprocessor.h"
#include "SamplerBase.h"

class ElementValueSampler;

template <>
InputParameters validParams<ElementValueSampler>();

/**
* Samples values of elemental variable(s).
*/
class ElementValueSampler : public ElementVariableVectorPostprocessor, protected SamplerBase
{
public:
ElementValueSampler(const InputParameters & parameters);

virtual void initialize() override;
virtual void execute() override;
virtual void finalize() override;

// Let the SamplerBase version of threadJoin() take part in the
// overload resolution process, otherwise we get warnings about
// overloaded virtual functions and "hiding" in debug mode.
using SamplerBase::threadJoin;

virtual void threadJoin(const UserObject & y) override;

protected:
/// So we don't have to create and destroy this vector over and over again
std::vector<Real> _values;
};

#endif
@@ -0,0 +1,29 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#ifndef ELEMENTALVARIABLEVECTORPOSTPROCESSOR_H
#define ELEMENTALVARIABLEVECTORPOSTPROCESSOR_H

#include "ElementVectorPostprocessor.h"

class ElementVariableVectorPostprocessor;

template <>
InputParameters validParams<ElementVariableVectorPostprocessor>();

/**
* Base class VectorPostprocessors operating on elemental variables.
*/
class ElementVariableVectorPostprocessor : public ElementVectorPostprocessor
{
public:
ElementVariableVectorPostprocessor(const InputParameters & parameters);
};

#endif
3 changes: 3 additions & 0 deletions framework/include/vectorpostprocessors/NodalValueSampler.h
Expand Up @@ -19,6 +19,9 @@ class NodalValueSampler;
template <>
InputParameters validParams<NodalValueSampler>();

/**
* Samples values of nodal variable(s).
*/
class NodalValueSampler : public NodalVariableVectorPostprocessor, protected SamplerBase
{
public:
Expand Down
78 changes: 78 additions & 0 deletions framework/src/vectorpostprocessors/ElementValueSampler.C
@@ -0,0 +1,78 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#include "ElementValueSampler.h"

// MOOSE includes
#include "MooseVariableFE.h"

// C++ includes
#include <numeric>

registerMooseObject("MooseApp", ElementValueSampler);

template <>
InputParameters
validParams<ElementValueSampler>()
{
InputParameters params = validParams<ElementVariableVectorPostprocessor>();

params.addClassDescription("Samples values of elemental variable(s).");

params += validParams<SamplerBase>();

return params;
}

ElementValueSampler::ElementValueSampler(const InputParameters & parameters)
: ElementVariableVectorPostprocessor(parameters), SamplerBase(parameters, this, _communicator)
{
// ensure that variables are elemental, i.e., not scalar and and not nodal
for (unsigned int i = 0; i < _coupled_moose_vars.size(); i++)
if (_coupled_moose_vars[i]->feType().family == SCALAR || _coupled_moose_vars[i]->isNodal())
paramError("variable", "The variable '", _coupled_moose_vars[i]->name(), "' is not elemental.");

std::vector<std::string> var_names(_coupled_moose_vars.size());
_values.resize(_coupled_moose_vars.size());

for (unsigned int i = 0; i < _coupled_moose_vars.size(); i++)
var_names[i] = _coupled_moose_vars[i]->name();

// Initialize the data structures in SamplerBase
SamplerBase::setupVariables(var_names);
}

void
ElementValueSampler::initialize()
{
SamplerBase::initialize();
}

void
ElementValueSampler::execute()
{
for (unsigned int i = 0; i < _coupled_moose_vars.size(); i++)
_values[i] = _coupled_moose_vars[i]->getElementalValue(_current_elem);

SamplerBase::addSample(_current_elem->centroid(), _current_elem->id(), _values);
}

void
ElementValueSampler::finalize()
{
SamplerBase::finalize();
}

void
ElementValueSampler::threadJoin(const UserObject & y)
{
const ElementValueSampler & vpp = static_cast<const ElementValueSampler &>(y);

SamplerBase::threadJoin(vpp);
}
@@ -0,0 +1,29 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#include "ElementVariableVectorPostprocessor.h"
#include "MooseVariable.h"
#include "SubProblem.h"
#include "MooseTypes.h"

template <>
InputParameters
validParams<ElementVariableVectorPostprocessor>()
{
InputParameters params = validParams<ElementVectorPostprocessor>();
params.addRequiredCoupledVar(
"variable", "The names of the variables that this VectorPostprocessor operates on");
return params;
}

ElementVariableVectorPostprocessor::ElementVariableVectorPostprocessor(
const InputParameters & parameters)
: ElementVectorPostprocessor(parameters)
{
}
7 changes: 7 additions & 0 deletions framework/src/vectorpostprocessors/NodalValueSampler.C
Expand Up @@ -23,6 +23,8 @@ validParams<NodalValueSampler>()
{
InputParameters params = validParams<NodalVariableVectorPostprocessor>();

params.addClassDescription("Samples values of nodal variable(s).");

params += validParams<SamplerBase>();

return params;
Expand All @@ -31,6 +33,11 @@ validParams<NodalValueSampler>()
NodalValueSampler::NodalValueSampler(const InputParameters & parameters)
: NodalVariableVectorPostprocessor(parameters), SamplerBase(parameters, this, _communicator)
{
// ensure that variables are nodal, i.e., not scalar and and not elemental
for (unsigned int i = 0; i < _coupled_moose_vars.size(); i++)
if (_coupled_moose_vars[i]->feType().family == SCALAR || !_coupled_moose_vars[i]->isNodal())
paramError("variable", "The variable '", _coupled_moose_vars[i]->name(), "' is not nodal.");

std::vector<std::string> var_names(_coupled_moose_vars.size());
_values.resize(_coupled_moose_vars.size());
_has_values.resize(_coupled_moose_vars.size());
Expand Down
@@ -0,0 +1,67 @@
# Tests the ElementValueSampler vector post-processor. In this test, 2 constant
# monomial variables are given distributions by a function and are output to a CSV file.

[Mesh]
type = GeneratedMesh
dim = 2
nx = 2
ny = 2
[]

[Functions]
[./u_fn]
type = ParsedFunction
value = '2 * x + 3 * y'
[../]
[./v_fn]
type = ParsedFunction
value = 'x + y'
[../]
[]

[AuxVariables]
[./u]
family = MONOMIAL
order = CONSTANT
[../]
[./v]
family = MONOMIAL
order = CONSTANT
[../]
[]

[ICs]
[./u_ic]
type = FunctionIC
variable = u
function = u_fn
[../]
[./v_ic]
type = FunctionIC
variable = v
function = v_fn
[../]
[]

[VectorPostprocessors]
[./element_value_sampler]
type = ElementValueSampler
variable = 'u v'
sort_by = x
execute_on = 'initial'
[../]
[]

[Problem]
solve = false
[]

[Executioner]
type = Steady
[]

[Outputs]
file_base = 'element_value_sampler'
csv = true
execute_on = 'initial'
[]
@@ -0,0 +1,5 @@
x,y,z,id,u,v
0.25,0.25,0,0,1.25,0.5
0.25,0.75,0,2,2.75,1
0.75,0.25,0,1,2.25,1
0.75,0.75,0,3,3.75,1.5
15 changes: 15 additions & 0 deletions test/tests/vectorpostprocessors/element_value_sampler/tests
@@ -0,0 +1,15 @@
[Tests]
[./element_value_sampler]
type = 'CSVDiff'
input = 'element_value_sampler.i'
csvdiff = 'element_value_sampler_element_value_sampler_0000.csv'
mesh_mode = REPLICATED
[../]
[./not_elemental]
type = 'RunException'
input = 'element_value_sampler.i'
cli_args = 'AuxVariables/u/family=LAGRANGE AuxVariables/u/order=FIRST'
expect_err = "The variable 'u' is not elemental"
mesh_mode = REPLICATED
[../]
[]
7 changes: 7 additions & 0 deletions test/tests/vectorpostprocessors/nodal_value_sampler/tests
Expand Up @@ -5,4 +5,11 @@
csvdiff = 'nodal_value_sampler_out_nodal_sample_0001.csv'
mesh_mode = REPLICATED
[../]
[./not_nodal]
type = 'RunException'
input = 'nodal_value_sampler.i'
cli_args = 'Variables/u/family=MONOMIAL Variables/u/order=CONSTANT'
expect_err = "The variable 'u' is not nodal"
mesh_mode = REPLICATED
[../]
[]

0 comments on commit 1725e2f

Please sign in to comment.