Skip to content

Commit

Permalink
Add extreme value pp test (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
dschwen committed Feb 3, 2025
1 parent 7ba0858 commit d9a5114
Show file tree
Hide file tree
Showing 10 changed files with 158 additions and 0 deletions.
16 changes: 16 additions & 0 deletions doc/content/source/postprocessors/ReciprocalIntegral.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# ReciprocalIntegral

!syntax description /Postprocessors/ReciprocalIntegral

This postprocesso should act on a reciprocal space tensor and will extract the magnitude of the zero k vector, the constant zero frequency contribution.
The result should be identical to an [integral](TensorIntegralPostprocessor.md) of the real space representatiopn of the tensor.

## Example Input File Syntax

!! Describe and include an example of how to use the ReciprocalIntegral object.

!syntax parameters /Postprocessors/ReciprocalIntegral

!syntax inputs /Postprocessors/ReciprocalIntegral

!syntax children /Postprocessors/ReciprocalIntegral
4 changes: 4 additions & 0 deletions include/actions/DomainAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class DomainAction : public Action
const std::array<int64_t, 3> & getReciprocalGridSize() const { return _n_reciprocal_global; }
const std::array<int64_t, 3> & getLocalGridSize() const { return _n_local; }
const std::array<int64_t, 3> & getLocalReciprocalGridSize() const { return _n_reciprocal_local; }
const Real & getVolume() const { return _volume_global; }
const std::array<Real, 3> & getDomainMin() const { return _min_global; }
const std::array<Real, 3> & getDomainMax() const { return _max_global; }
const std::array<Real, 3> & getGridSpacing() const { return _grid_spacing; }
Expand Down Expand Up @@ -106,6 +107,9 @@ class DomainAction : public Action
const std::array<Real, 3> _max_global;
///@}

/// Volume of teh simulation domain in real space
Real _volume_global;

const enum class MeshMode { SWIFT_DUMMY, SWIFT_DOMAIN, SWIFT_MANUAL } _mesh_mode;

/// grid spacing
Expand Down
4 changes: 4 additions & 0 deletions src/actions/DomainAction.C
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ DomainAction::gridChanged()
auto options = MooseTensor::floatTensorOptions();

// build real space axes
_volume_global = 1.0;
for (const unsigned int dim : {0, 1, 2})
{
// error check
Expand All @@ -151,12 +152,15 @@ DomainAction::gridChanged()

// real space axis
if (dim < _dim)
{
_global_axis[dim] =
align(torch::linspace(c10::Scalar(_min_global[dim] + _grid_spacing[dim] / 2.0),
c10::Scalar(_max_global[dim] - _grid_spacing[dim] / 2.0),
_n_global[dim],
options),
dim);
_volume_global *= _max_global[dim] - _min_global[dim];
}
else
_global_axis[dim] = torch::tensor({0.0}, options);
}
Expand Down
11 changes: 11 additions & 0 deletions src/postprocessors/ReciprocalIntegral.C
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/**********************************************************************/

#include "ReciprocalIntegral.h"
#include "DomainAction.h"

registerMooseObject("SwiftApp", ReciprocalIntegral);

Expand All @@ -20,6 +21,7 @@ ReciprocalIntegral::validParams()

ReciprocalIntegral::ReciprocalIntegral(const InputParameters & parameters)
: TensorPostprocessor(parameters)

{
}

Expand All @@ -34,6 +36,15 @@ ReciprocalIntegral::execute()
// Convert to std::complex<double> (TODO: or float!)
_integral = torch::real(zero_frequency_tensor).item<double>();

// divide by number of cells in real space
const auto & n = _domain.getGridSize();
_integral /= n[0] * n[1] * n[2];

// multiply by domain size
const auto & volume = _domain.getVolume();
mooseInfo(volume);
_integral *= volume;

// for parallelism only the proc owning the global 0 matters...
}

Expand Down
2 changes: 2 additions & 0 deletions test/tests/postprocessors/gold/average.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
time,avg_c
0,0.8
2 changes: 2 additions & 0 deletions test/tests/postprocessors/gold/extreme_value.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
time,max_c,min_c
0,3.2375,-1.6375
2 changes: 2 additions & 0 deletions test/tests/postprocessors/gold/integral.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
time,int_c
0,4.8
2 changes: 2 additions & 0 deletions test/tests/postprocessors/gold/reciprocal_integral.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
time,int_c_bar
0,4.8
75 changes: 75 additions & 0 deletions test/tests/postprocessors/postprocessors.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
[Domain]
dim = 2
nx = 40
ny = 40
xmax = 2
ymax = 3
mesh_mode = DUMMY
device_names = cpu
[]

[TensorBuffers]
[c]
[]
[c_bar]
[]
[]

[TensorComputes]
[Initialize]
[c]
type = ParsedCompute
buffer = c
extra_symbols = true
expression = -x+y+0.3
[]
[c_bar]
type = ForwardFFT
buffer = c_bar
input = c
[]
[]
[]

[Postprocessors]
[min_c]
type = TensorExtremeValuePostprocessor
buffer = c
value_type = MIN
execute_on = 'INITIAL TIMESTEP_END'
[]
[max_c]
type = TensorExtremeValuePostprocessor
buffer = c
value_type = MAX
execute_on = 'INITIAL TIMESTEP_END'
[]
[avg_c]
type = TensorAveragePostprocessor
buffer = c
execute_on = 'INITIAL TIMESTEP_END'
[]
[int_c]
type = TensorIntegralPostprocessor
buffer = c
execute_on = 'INITIAL TIMESTEP_END'
[]
[int_c_bar]
type = ReciprocalIntegral
buffer = c_bar
execute_on = 'INITIAL TIMESTEP_END'
[]
[]

[Problem]
type = TensorProblem
[]

[Executioner]
type = Transient
num_steps = 0
[]

[Outputs]
csv = true
[]
40 changes: 40 additions & 0 deletions test/tests/postprocessors/tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[Tests]
[extreme_value]
type = CSVDiff
input = postprocessors.i
csvdiff = extreme_value.csv
cli_args = 'Outputs/file_base=extreme_value Postprocessors/active="min_c max_c"'
requirement = 'The system shall be able to determine the minimum and maximum item value in a tensor.'
issues = '#6'
design = 'TensorExtremeValuePostprocessor.md'
[]

[average]
type = CSVDiff
input = postprocessors.i
csvdiff = average.csv
cli_args = 'Outputs/file_base=average Postprocessors/active="avg_c"'
requirement = 'The system shall be able to determine the average value in a tensor.'
issues = '#6'
design = 'TensorAveragePostprocessor.md'
[]

[integral]
type = CSVDiff
input = postprocessors.i
csvdiff = integral.csv
cli_args = 'Outputs/file_base=integral Postprocessors/active="int_c"'
requirement = 'The system shall be able to compute the integral over a simulation cell tensor.'
issues = '#6'
design = 'TensorIntegralPostprocessor.md'
[]
[reciprocal_integral]
type = CSVDiff
input = postprocessors.i
csvdiff = reciprocal_integral.csv
cli_args = 'Outputs/file_base=reciprocal_integral Postprocessors/active="int_c_bar"'
requirement = 'The system shall be able to compute the integral over a simulation cell tensor using the zero k vector in reciprocal space.'
issues = '#6'
design = 'ReciprocalIntegral.md'
[]
[]

0 comments on commit d9a5114

Please sign in to comment.