Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# CSVPointValueSampler

!syntax description /VectorPostprocessors/CSVPointValueSampler

!alert note
If the csv point value sampler is used with a discontinuous variable on the edge/face of a 2D/3D element, then the value from the element with the lowest ID will be returned.

The CSV output, with rows for each sampled point, contains the columns listed below. The vectors declared by `CSVPointValueSampler`
share the same names as the column headers.

- the id of the sampled points

- the values of the variable(s) requested

- the x, y and z coordinates of the requested sampled points

The sampled points and the values are written to a csv file at every time step. The sorting order of the points can be changed using the sort_by parameter which takes x, y, z or id (increasing distance from start point) as input.
Id can be supplied and/or sorted by the `point_id` from the csv file.

## Example input syntax

In this example, the variables `param1` and `param2` are sampled at the points read in from the csv file using a `CSVPointValueSampler`.

!listing test/tests/vectorpostprocessors/csv_point_value_sampler/csv_point_sampler.i block=VectorPostprocessors/point_sample

!syntax parameters /VectorPostprocessors/CSVPointValueSampler

!syntax inputs /VectorPostprocessors/CSVPointValueSampler

!syntax children /VectorPostprocessors/CSVPointValueSampler
23 changes: 23 additions & 0 deletions framework/include/vectorpostprocessors/CSVPointValueSampler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//* This file is part of the MOOSE framework
//* https://mooseframework.inl.gov
//*
//* 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

#pragma once

#include "PointVariableSamplerBase.h"

/**
* Class for sampling variable(s) at csv imported points
*/
class CSVPointValueSampler : public PointVariableSamplerBase
{
public:
static InputParameters validParams();

CSVPointValueSampler(const InputParameters & parameters);
};
87 changes: 87 additions & 0 deletions framework/src/vectorpostprocessors/CSVPointValueSampler.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#include "CSVPointValueSampler.h"
#include "DelimitedFileReader.h"

registerMooseObject("MooseApp", CSVPointValueSampler);

InputParameters
CSVPointValueSampler::validParams()
{
InputParameters params = PointVariableSamplerBase::validParams();
params.addClassDescription("Sample a variable at points specified in a csv file.");
params.addRequiredParam<FileName>("points_file", "CSV file with point coordinates (x, y, z).");
params.addRequiredParam<std::string>("point_xcoord",
"x coordinate column name from csv file being read in.");
params.addRequiredParam<std::string>("point_ycoord",
"y coordinate column name from csv file being read in.");
params.addRequiredParam<std::string>("point_zcoord",
"z coordinate column name from csv file being read in.");
params.addParam<std::string>("point_id", "id column name from csv file being read in.");

return params;
}

CSVPointValueSampler::CSVPointValueSampler(const InputParameters & parameters)
: PointVariableSamplerBase(parameters)
{
std::string idName;
if (isParamValid("point_id"))
idName = getParam<std::string>("point_id");

std::string xName = getParam<std::string>("point_xcoord");
std::string yName = getParam<std::string>("point_ycoord");
std::string zName = getParam<std::string>("point_zcoord");

bool found_x = false;
bool found_y = false;
bool found_z = false;

std::vector<Real> point_xcoord;
std::vector<Real> point_ycoord;
std::vector<Real> point_zcoord;

MooseUtils::DelimitedFileReader reader(getParam<FileName>("points_file"));
reader.read();

auto const & names = reader.getNames();
auto const & data = reader.getData();

for (std::size_t i = 0; i < names.size(); ++i)
{
if (names[i] == xName)
{
point_xcoord = data[i];
found_x = true;
}
else if (names[i] == yName)
{
point_ycoord = data[i];
found_y = true;
}
else if (names[i] == zName)
{
point_zcoord = data[i];
found_z = true;
}
else if (names[i] == idName)
{
_ids = data[i];
}
}
if (!found_x || !found_y || !found_z)
paramError("points_file",
"Column with name '",
xName,
" or ",
yName,
" or ",
zName,
"' missing from measurement file");

const std::size_t nvals = point_xcoord.size();
_points.resize(nvals);
for (const auto & i : make_range(nvals))
{
const Point point(point_xcoord[i], point_ycoord[i], point_zcoord[i]);
_points[i] = point;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
[Mesh]
[gmg]
type = GeneratedMeshGenerator
dim = 2
nx = 10
xmin = 0
xmax = 1
ny = 10
ymin = 0
ymax = 1
[]
parallel_type = REPLICATED
[]

[AuxVariables]
[params1]
order = FIRST
family = LAGRANGE
[]
[params2]
order = CONSTANT
family = MONOMIAL
[]
[]

[AuxKernels]
[params1]
type = ParsedAux
variable = params1
expression = 'x*y*t'
use_xyzt = true
[]
[params2]
type = ParsedAux
variable = params2
expression = 'x*x*t'
use_xyzt = true
[]
[]

[VectorPostprocessors]
[point_sample]
type=CSVPointValueSampler
point_xcoord = x
point_ycoord = y
point_zcoord = z
point_id = id
points_file = 'gold/csv_point_sampler_out_point_sample_0001.csv'
sort_by = id
variable = 'params1 params2'
[]
[point_sample_x]
type=CSVPointValueSampler
point_xcoord = x
point_ycoord = y
point_zcoord = z
point_id = id
points_file = 'gold/csv_point_sampler_out_point_sample_0001.csv'
sort_by = x
variable = 'params1 params2'
[]
[]

[Outputs]
csv = true
execute_on = timestep_end
[]

[Executioner]
type = Transient
dt = 1.0
num_steps = 2
solve_type = NEWTON
[]

[Problem]
solve = false
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
id,params1,params2,x,y,z
0,0,0.9025,1,0,0
0.070710678118655,0.0475,0.9025,0.95,0.05,0
0.14142135623731,0.09,0.7225,0.9,0.1,0
0.21213203435596,0.1275,0.7225,0.85,0.15,0
0.28284271247462,0.16,0.5625,0.8,0.2,0
0.35355339059327,0.1875,0.5625,0.75,0.25,0
0.42426406871193,0.21,0.4225,0.7,0.3,0
0.49497474683058,0.2275,0.4225,0.65,0.35,0
0.56568542494924,0.24,0.3025,0.6,0.4,0
0.63639610306789,0.2475,0.3025,0.55,0.45,0
0.70710678118655,0.25,0.2025,0.5,0.5,0
0.7778174593052,0.2475,0.2025,0.45,0.55,0
0.84852813742386,0.24,0.1225,0.4,0.6,0
0.91923881554251,0.2275,0.1225,0.35,0.65,0
0.98994949366117,0.21,0.0625,0.3,0.7,0
1.0606601717798,0.1875,0.0625,0.25,0.75,0
1.1313708498985,0.16,0.0225,0.2,0.8,0
1.2020815280171,0.1275,0.0225,0.15,0.85,0
1.2727922061358,0.09,0.0025,0.1,0.9,0
1.3435028842544,0.0475,0.0025,0.05,0.95,0
1.4142135623731,0,0.0025,0,1,0
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
id,params1,params2,x,y,z
0,0,1.805,1,0,0
0.070710678118655,0.095,1.805,0.95,0.05,0
0.14142135623731,0.18,1.445,0.9,0.1,0
0.21213203435596,0.255,1.445,0.85,0.15,0
0.28284271247462,0.32,1.125,0.8,0.2,0
0.35355339059327,0.375,1.125,0.75,0.25,0
0.42426406871193,0.42,0.845,0.7,0.3,0
0.49497474683058,0.455,0.845,0.65,0.35,0
0.56568542494924,0.48,0.605,0.6,0.4,0
0.63639610306789,0.495,0.605,0.55,0.45,0
0.70710678118655,0.5,0.405,0.5,0.5,0
0.7778174593052,0.495,0.405,0.45,0.55,0
0.84852813742386,0.48,0.245,0.4,0.6,0
0.91923881554251,0.455,0.245,0.35,0.65,0
0.98994949366117,0.42,0.125,0.3,0.7,0
1.0606601717798,0.375,0.125,0.25,0.75,0
1.1313708498985,0.32,0.045,0.2,0.8,0
1.2020815280171,0.255,0.045,0.15,0.85,0
1.2727922061358,0.18,0.005,0.1,0.9,0
1.3435028842544,0.095,0.005,0.05,0.95,0
1.4142135623731,0,0.005,0,1,0
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
id,params1,params2,x,y,z
1.4142135623731,0,0.005,0,1,0
1.3435028842544,0.095,0.005,0.05,0.95,0
1.2727922061358,0.18,0.005,0.1,0.9,0
1.2020815280171,0.255,0.045,0.15,0.85,0
1.1313708498985,0.32,0.045,0.2,0.8,0
1.0606601717798,0.375,0.125,0.25,0.75,0
0.98994949366117,0.42,0.125,0.3,0.7,0
0.91923881554251,0.455,0.245,0.35,0.65,0
0.84852813742386,0.48,0.245,0.4,0.6,0
0.7778174593052,0.495,0.405,0.45,0.55,0
0.70710678118655,0.5,0.405,0.5,0.5,0
0.63639610306789,0.495,0.605,0.55,0.45,0
0.56568542494924,0.48,0.605,0.6,0.4,0
0.49497474683058,0.455,0.845,0.65,0.35,0
0.42426406871193,0.42,0.845,0.7,0.3,0
0.35355339059327,0.375,1.125,0.75,0.25,0
0.28284271247462,0.32,1.125,0.8,0.2,0
0.21213203435596,0.255,1.445,0.85,0.15,0
0.14142135623731,0.18,1.445,0.9,0.1,0
0.070710678118655,0.095,1.805,0.95,0.05,0
0,0,1.805,1,0,0
19 changes: 19 additions & 0 deletions test/tests/vectorpostprocessors/csv_point_value_sampler/tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[Tests]
issues = '#31810'
design = 'CSVPointValueSampler.md'
[test]
type = 'CSVDiff'
allow_warnings = true
input = 'csv_point_sampler.i'
csvdiff = 'csv_point_sampler_out_point_sample_0001.csv csv_point_sampler_out_point_sample_0002.csv csv_point_sampler_out_point_sample_x_0002.csv'
requirement = 'The system shall support the ability to sample field variables at user specified points imported via csv file.'
[]
[error]
type = 'RunException'
allow_warnings = true
input = 'csv_point_sampler.i'
cli_args = "VectorPostprocessors/point_sample/point_xcoord=dummy"
expect_err = "Column with name 'dummy or y or z' missing from measurement file"
requirement = 'The system shall report error when column requested is not named in csv file.'
[]
[]