forked from idaholab/moose
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ElementValueSampler vector postprocessor
Closes idaholab#11594
- Loading branch information
1 parent
113d964
commit 1725e2f
Showing
13 changed files
with
304 additions
and
9 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
...k/doc/content/documentation/systems/VectorPostprocessors/ElementValueSampler.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
11 changes: 3 additions & 8 deletions
11
...ork/doc/content/documentation/systems/VectorPostprocessors/NodalValueSampler.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
framework/include/vectorpostprocessors/ElementValueSampler.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
29 changes: 29 additions & 0 deletions
29
framework/include/vectorpostprocessors/ElementVariableVectorPostprocessor.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
29 changes: 29 additions & 0 deletions
29
framework/src/vectorpostprocessors/ElementVariableVectorPostprocessor.C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
test/tests/vectorpostprocessors/element_value_sampler/element_value_sampler.i
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' | ||
[] |
5 changes: 5 additions & 0 deletions
5
...rocessors/element_value_sampler/gold/element_value_sampler_element_value_sampler_0000.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
15
test/tests/vectorpostprocessors/element_value_sampler/tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
[../] | ||
[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters