diff --git a/framework/doc/content/source/vectorpostprocessors/ElementValueSampler.md b/framework/doc/content/source/vectorpostprocessors/ElementValueSampler.md index b73aa6fbc032..fdd6c65e7f2a 100644 --- a/framework/doc/content/source/vectorpostprocessors/ElementValueSampler.md +++ b/framework/doc/content/source/vectorpostprocessors/ElementValueSampler.md @@ -4,13 +4,17 @@ 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 +coordinate used for each sampling point is the centroid (vertex-average approximation) of the associated element. !alert note title=Vector names / CSV output column names `ElementValueSampler` declares a vector for each spatial coordinate, (`x`, `y`, `z`), of the centroid of the element along with its ID as well as a vector named after each variable sampled, containing the variable values. +!alert note title=General sampling +The `ElementValueSampler` samples elemental variables at the element centroids. For more flexible sampling, +use the [PositionsFunctorValueSampler.md]. + !syntax parameters /VectorPostprocessors/ElementValueSampler !syntax inputs /VectorPostprocessors/ElementValueSampler diff --git a/framework/doc/content/source/vectorpostprocessors/LineValueSampler.md b/framework/doc/content/source/vectorpostprocessors/LineValueSampler.md index e2365a1dad41..8e8539821b2c 100644 --- a/framework/doc/content/source/vectorpostprocessors/LineValueSampler.md +++ b/framework/doc/content/source/vectorpostprocessors/LineValueSampler.md @@ -18,6 +18,10 @@ If the line value sampler is used with a discontinuous variable on the edge/face the distance along the sampled line in a vector called `id`, and a vector named after each value sampled, containing the variable values at each point. +!alert note title=General sampling +The `LineValueSampler` samples variables on the specified line. For more flexible sampling, +use the [PositionsFunctorValueSampler.md]. + !syntax parameters /VectorPostprocessors/LineValueSampler !syntax inputs /VectorPostprocessors/LineValueSampler diff --git a/framework/doc/content/source/vectorpostprocessors/NodalValueSampler.md b/framework/doc/content/source/vectorpostprocessors/NodalValueSampler.md index 8db1ebb000a6..7a0eae2de7b8 100644 --- a/framework/doc/content/source/vectorpostprocessors/NodalValueSampler.md +++ b/framework/doc/content/source/vectorpostprocessors/NodalValueSampler.md @@ -10,6 +10,10 @@ in the domain, selection of blocks, or selection of boundaries. the IDs of the nodes in a vector named `id`, and a vector named after each variable sampled, containing the variable values at each point. +!alert note title=General sampling +The `NodalValueSampler` samples nodal variables at the mesh nodes. For more flexible sampling, +use the [PositionsFunctorValueSampler.md]. + !syntax parameters /VectorPostprocessors/NodalValueSampler !syntax inputs /VectorPostprocessors/NodalValueSampler diff --git a/framework/doc/content/source/vectorpostprocessors/PointValueSampler.md b/framework/doc/content/source/vectorpostprocessors/PointValueSampler.md index 058023ad0ff8..5d244f1bfb00 100644 --- a/framework/doc/content/source/vectorpostprocessors/PointValueSampler.md +++ b/framework/doc/content/source/vectorpostprocessors/PointValueSampler.md @@ -14,6 +14,9 @@ share the same names as the column headers. - the x, y and z coordinates of the requested sampled points +!alert note title=General sampling +The `PointValueSampler` samples variables at the specified points. For more flexible sampling, +use the [PositionsFunctorValueSampler.md]. ## Example input syntax diff --git a/framework/doc/content/source/vectorpostprocessors/SideValueSampler.md b/framework/doc/content/source/vectorpostprocessors/SideValueSampler.md index 0c5ebffa6cac..6b21fad89821 100644 --- a/framework/doc/content/source/vectorpostprocessors/SideValueSampler.md +++ b/framework/doc/content/source/vectorpostprocessors/SideValueSampler.md @@ -11,6 +11,10 @@ names. - the X, Y, Z coordinates of the quadrature points on the side +!alert note title=General sampling +The `SideValueSampler` samples variables on the specified boundary on element side quadrature points. For more flexible sampling, +use the [PositionsFunctorValueSampler.md]. + ## Example input syntax In this example, variable `u` and `v` are the solutions of two boundary value diffusion problems. Their value along the `top` boundary and along the `center` internal sidesets are reported using two `SideValueSampler`. The rows in the CSV output are sorted according the `x` coordinate along the boundary for the former, and the element `id` for the latter. diff --git a/framework/include/vectorpostprocessors/SamplerBase.h b/framework/include/vectorpostprocessors/SamplerBase.h index 424123ec30dc..ec32f633bd4a 100644 --- a/framework/include/vectorpostprocessors/SamplerBase.h +++ b/framework/include/vectorpostprocessors/SamplerBase.h @@ -58,6 +58,15 @@ class SamplerBase */ void setupVariables(const std::vector & variable_names); + /** + * Checks whether the passed variable pointer corresponds to a regular single-valued field + * variable + * @param var_param_name name of the variable parameter in which the variables were passed + * @param var_ptr pointer to the field variable + */ + void checkForStandardFieldVariableType(const MooseVariableFieldBase * const var_ptr, + const std::string & var_param_name = "variable") const; + /** * Call this with the value of every variable at each point you want to sample at. * @param p The point where you took the sample diff --git a/framework/src/vectorpostprocessors/ElementValueSampler.C b/framework/src/vectorpostprocessors/ElementValueSampler.C index 8ee428ea78b8..5a4483369fef 100644 --- a/framework/src/vectorpostprocessors/ElementValueSampler.C +++ b/framework/src/vectorpostprocessors/ElementValueSampler.C @@ -22,7 +22,7 @@ ElementValueSampler::validParams() { InputParameters params = ElementVariableVectorPostprocessor::validParams(); - params.addClassDescription("Samples values of elemental variable(s)."); + params.addClassDescription("Samples values of variables on elements."); params += SamplerBase::validParams(); @@ -32,12 +32,17 @@ ElementValueSampler::validParams() ElementValueSampler::ElementValueSampler(const InputParameters & parameters) : ElementVariableVectorPostprocessor(parameters), SamplerBase(parameters, this, _communicator) { - // ensure that variables are elemental, i.e., not scalar and and not nodal + // ensure that variables are '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 elemental."); - + { + if (_coupled_moose_vars[i]->isNodal()) + paramError("variable", + "The variable '", + _coupled_moose_vars[i]->name(), + "' is a nodal variable. Nodal variables can be sampled using a " + "'NodalValueSampler'."); + SamplerBase::checkForStandardFieldVariableType(_coupled_moose_vars[i]); + } std::vector var_names(_coupled_moose_vars.size()); _values.resize(_coupled_moose_vars.size()); diff --git a/framework/src/vectorpostprocessors/NodalValueSampler.C b/framework/src/vectorpostprocessors/NodalValueSampler.C index b29af699008b..4d3211f4d99c 100644 --- a/framework/src/vectorpostprocessors/NodalValueSampler.C +++ b/framework/src/vectorpostprocessors/NodalValueSampler.C @@ -32,10 +32,13 @@ NodalValueSampler::validParams() NodalValueSampler::NodalValueSampler(const InputParameters & parameters) : NodalVariableVectorPostprocessor(parameters), SamplerBase(parameters, this, _communicator) { - // ensure that variables are nodal, i.e., not scalar and and not elemental + // ensure that variables are 'nodal' (they have DoFs at nodes) for (unsigned int i = 0; i < _coupled_moose_vars.size(); i++) - if (_coupled_moose_vars[i]->feType().family == SCALAR || !_coupled_moose_vars[i]->isNodal()) + { + if (!_coupled_moose_vars[i]->isNodal()) paramError("variable", "The variable '", _coupled_moose_vars[i]->name(), "' is not nodal."); + SamplerBase::checkForStandardFieldVariableType(_coupled_moose_vars[i]); + } std::vector var_names(_coupled_moose_vars.size()); _values.resize(_coupled_moose_vars.size()); diff --git a/framework/src/vectorpostprocessors/PointVariableSamplerBase.C b/framework/src/vectorpostprocessors/PointVariableSamplerBase.C index e50d627c4d7e..f37185de8aa9 100644 --- a/framework/src/vectorpostprocessors/PointVariableSamplerBase.C +++ b/framework/src/vectorpostprocessors/PointVariableSamplerBase.C @@ -48,7 +48,10 @@ PointVariableSamplerBase::PointVariableSamplerBase(const InputParameters & param std::vector var_names(_coupled_moose_vars.size()); for (unsigned int i = 0; i < _coupled_moose_vars.size(); i++) + { var_names[i] = _coupled_moose_vars[i]->name(); + SamplerBase::checkForStandardFieldVariableType(_coupled_moose_vars[i]); + } // Initialize the data structures in SamplerBase SamplerBase::setupVariables(var_names); diff --git a/framework/src/vectorpostprocessors/SamplerBase.C b/framework/src/vectorpostprocessors/SamplerBase.C index 2c3e47b2d21b..37b7f2d48b14 100644 --- a/framework/src/vectorpostprocessors/SamplerBase.C +++ b/framework/src/vectorpostprocessors/SamplerBase.C @@ -15,6 +15,8 @@ #include "MooseEnum.h" #include "MooseError.h" #include "VectorPostprocessor.h" +#include "MooseVariableFieldBase.h" +#include "MooseBaseParameterInterface.h" #include "libmesh/point.h" @@ -87,6 +89,33 @@ SamplerBase::initialize() _values.begin(), _values.end(), [](VectorPostprocessorValue * vec) { vec->clear(); }); } +void +SamplerBase::checkForStandardFieldVariableType(const MooseVariableFieldBase * const var_ptr, + const std::string & var_param_name) const +{ + // A pointer to a MooseVariableFieldBase should never be SCALAR + mooseAssert(var_ptr->feType().family != SCALAR, + "Scalar variable '" + var_ptr->name() + "' cannot be sampled."); + mooseAssert(dynamic_cast(_vpp), "Should have succeeded"); + if (var_ptr->isVector()) + dynamic_cast(_vpp)->paramError( + var_param_name, + "The variable '", + var_ptr->name(), + "' is a vector variable. Sampling those is not currently supported in the " + "framework. It may be supported using a dedicated object in your application. Use " + "'VectorVariableComponentAux' auxkernel to copy those values into a regular field " + "variable"); + if (var_ptr->isArray()) + dynamic_cast(_vpp)->paramError( + var_param_name, + "The variable '", + var_ptr->name(), + "' is an array variable. Sampling those is not currently supported in the " + "framework. It may be supported using a dedicated object in your application. Use " + "'ArrayVariableComponent' auxkernel to copy those values into a regular field variable"); +} + void SamplerBase::finalize() { diff --git a/framework/src/vectorpostprocessors/SideValueSampler.C b/framework/src/vectorpostprocessors/SideValueSampler.C index 21d2021bb7cb..57eedfd97549 100644 --- a/framework/src/vectorpostprocessors/SideValueSampler.C +++ b/framework/src/vectorpostprocessors/SideValueSampler.C @@ -35,9 +35,12 @@ SideValueSampler::SideValueSampler(const InputParameters & parameters) _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(); + SamplerBase::checkForStandardFieldVariableType(_coupled_moose_vars[i]); + } - // Initialize the datastructions in SamplerBase + // Initialize the data structures in SamplerBase SamplerBase::setupVariables(var_names); } diff --git a/test/tests/vectorpostprocessors/element_value_sampler/element_value_sampler.i b/test/tests/vectorpostprocessors/element_value_sampler/element_value_sampler.i index c3e0065a356a..8a5e1ac23d7b 100644 --- a/test/tests/vectorpostprocessors/element_value_sampler/element_value_sampler.i +++ b/test/tests/vectorpostprocessors/element_value_sampler/element_value_sampler.i @@ -9,47 +9,47 @@ [] [Functions] - [./u_fn] + [u_fn] type = ParsedFunction expression = '2 * x + 3 * y' - [../] - [./v_fn] + [] + [v_fn] type = ParsedFunction expression = 'x + y' - [../] + [] [] [AuxVariables] - [./u] + [u] family = MONOMIAL order = CONSTANT - [../] - [./v] + [] + [v] family = MONOMIAL order = CONSTANT - [../] + [] [] [ICs] - [./u_ic] + [u_ic] type = FunctionIC variable = u function = u_fn - [../] - [./v_ic] + [] + [v_ic] type = FunctionIC variable = v function = v_fn - [../] + [] [] [VectorPostprocessors] - [./element_value_sampler] + [element_value_sampler] type = ElementValueSampler variable = 'u v' sort_by = id execute_on = 'initial' - [../] + [] [] [Problem] diff --git a/test/tests/vectorpostprocessors/element_value_sampler/tests b/test/tests/vectorpostprocessors/element_value_sampler/tests index a19ed4e0614d..8753c97a4822 100644 --- a/test/tests/vectorpostprocessors/element_value_sampler/tests +++ b/test/tests/vectorpostprocessors/element_value_sampler/tests @@ -29,14 +29,32 @@ detail = 'for finite volume variables mixed with finite element variables,' [] - [lagrange] + [] + [exceptions] + requirement = 'The system shall throw an error if the variables specified for elemental sampling are' + [nodal] 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" + expect_err = "The variable 'u' is a nodal variable. Nodal variables can be sampled using a 'NodalValueSampler'" mesh_mode = REPLICATED - - detail = 'but not for nodal variables.' + detail = 'nodal variables,' + [] + [vector] + type = 'RunException' + input = 'element_value_sampler.i' + cli_args = 'AuxVariables/u/family=MONOMIAL_VEC ICs/active=' + expect_err = "The variable 'u' is a vector variable. Sampling those is not currently supported" + mesh_mode = REPLICATED + detail = 'vector variables,' + [] + [array] + type = 'RunException' + input = 'element_value_sampler.i' + cli_args = 'AuxVariables/u/components=8 ICs/active=' + expect_err = "The variable 'u' is an array variable. Sampling those is not currently supported" + mesh_mode = REPLICATED + detail = 'and array variables.' [] [] [] diff --git a/test/tests/vectorpostprocessors/nodal_value_sampler/nodal_value_sampler.i b/test/tests/vectorpostprocessors/nodal_value_sampler/nodal_value_sampler.i index 989f04868f42..b87d428792ef 100644 --- a/test/tests/vectorpostprocessors/nodal_value_sampler/nodal_value_sampler.i +++ b/test/tests/vectorpostprocessors/nodal_value_sampler/nodal_value_sampler.i @@ -6,57 +6,57 @@ [] [Variables] - [./u] - [../] - [./v] - [../] + [u] + [] + [v] + [] [] [Kernels] - [./diff] + [diff] type = Diffusion variable = u - [../] - [./diff_v] + [] + [diff_v] type = Diffusion variable = v - [../] + [] [] [BCs] - [./left] + [left] type = DirichletBC variable = u boundary = left value = 0 - [../] - [./right] + [] + [right] type = DirichletBC variable = u boundary = right value = 1 - [../] - [./left_v] + [] + [left_v] type = DirichletBC variable = v boundary = left value = 1 - [../] - [./right_v] + [] + [right_v] type = DirichletBC variable = v boundary = right value = 0 - [../] + [] [] [VectorPostprocessors] - [./nodal_sample] + [nodal_sample] type = NodalValueSampler variable = 'u v' boundary = top sort_by = x - [../] + [] [] [Executioner] diff --git a/test/tests/vectorpostprocessors/nodal_value_sampler/tests b/test/tests/vectorpostprocessors/nodal_value_sampler/tests index a60326c5372f..113b70dc074f 100644 --- a/test/tests/vectorpostprocessors/nodal_value_sampler/tests +++ b/test/tests/vectorpostprocessors/nodal_value_sampler/tests @@ -2,21 +2,38 @@ design = 'NodalValueSampler.md' issues = '#3087' - [./test] + [test] type = 'CSVDiff' input = 'nodal_value_sampler.i' csvdiff = 'nodal_value_sampler_out_nodal_sample_0001.csv' mesh_mode = REPLICATED - requirement = 'The system shall support sampling of a field variable at every node in the domain.' - [../] - [./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 - - requirement = 'The system shall issue an error when a nodal sampler is used on a field that does not have values defined at the nodes.' - [../] + [] + [exceptions] + requirement = 'The system shall throw an error if the variables specified for nodal sampling are' + [not_nodal] + type = 'RunException' + input = 'nodal_value_sampler.i' + cli_args = 'Variables/u/family=MONOMIAL' + expect_err = "The variable 'u' is not nodal" + mesh_mode = REPLICATED + detail = 'clearly not nodal variables with degrees of freedom in the element volumes,' + [] + [vector] + type = 'RunException' + input = 'nodal_value_sampler.i' + cli_args = 'Variables/u/family=LAGRANGE_VEC' + expect_err = "The variable \'u\' is a vector variable. Sampling those is not currently supported" + mesh_mode = REPLICATED + detail = 'vector variables,' + [] + [array] + type = 'RunException' + input = 'nodal_value_sampler.i' + cli_args = 'Variables/u/components=8' + expect_err = "The variable \'u\' is an array variable. Sampling those is not currently supported" + mesh_mode = REPLICATED + detail = 'and array variables.' + [] + [] []