forked from idaholab/moose
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add nearest point average userobject. Refs idaholab#18536
- Loading branch information
1 parent
cbe2ad2
commit f49fefb
Showing
7 changed files
with
255 additions
and
0 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
framework/doc/content/source/userobject/NearestPointAverage.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,17 @@ | ||
# NearestPointAverage | ||
|
||
The domain is virtually divided into a number of subdomains according to | ||
the nearest points provided by the users. For each provided point, a virtual | ||
subdomain is created around that point and consists of all regions of space | ||
that are closer to that point than any of the other provided points. Then, | ||
the variable average is computed over each individual subdomain separately. | ||
|
||
!syntax description /UserObjects/NearestPointAverage | ||
|
||
!syntax parameters /UserObjects/NearestPointAverage | ||
|
||
!syntax inputs /UserObjects/NearestPointAverage | ||
|
||
!syntax children /UserObjects/NearestPointAverage | ||
|
||
!bibtex bibliography |
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,43 @@ | ||
//* 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 | ||
|
||
#pragma once | ||
|
||
// MOOSE includes | ||
#include "NearestPointBase.h" | ||
#include "ElementAverageValue.h" | ||
#include "ElementVariableVectorPostprocessor.h" | ||
|
||
// Forward Declarations | ||
class NearestPointAverage; | ||
|
||
/** | ||
* Given a list of points this object computes the average of a variable | ||
* over the points closest to each provided point. | ||
*/ | ||
class NearestPointAverage | ||
: public NearestPointBase<ElementAverageValue, ElementVariableVectorPostprocessor> | ||
{ | ||
public: | ||
static InputParameters validParams(); | ||
|
||
NearestPointAverage(const InputParameters & parameters); | ||
|
||
virtual Real spatialValue(const Point & point) const override; | ||
|
||
Real userObjectValue(unsigned int i) const; | ||
|
||
unsigned int nearestPointIndex(const Point & point) const; | ||
|
||
virtual void finalize() override; | ||
|
||
protected: | ||
/// Postprocessor values for each point | ||
VectorPostprocessorValue & _np_post_processor_values; | ||
}; |
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,97 @@ | ||
//* 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 | ||
|
||
// MOOSE includes | ||
#include "NearestPointAverage.h" | ||
|
||
registerMooseObject("MooseApp", NearestPointAverage); | ||
|
||
InputParameters | ||
NearestPointAverage::validParams() | ||
{ | ||
InputParameters params = | ||
nearestPointBaseValidParams<ElementAverageValue, ElementVariableVectorPostprocessor>(); | ||
|
||
params.addClassDescription( | ||
"Compute element variable averages for nearest-point based subdomains"); | ||
|
||
return params; | ||
} | ||
|
||
NearestPointAverage::NearestPointAverage(const InputParameters & parameters) | ||
: NearestPointBase<ElementAverageValue, ElementVariableVectorPostprocessor>(parameters), | ||
_np_post_processor_values(declareVector("np_post_processor_values")) | ||
{ | ||
_np_post_processor_values.resize(_user_objects.size()); | ||
} | ||
|
||
Real | ||
NearestPointAverage::spatialValue(const Point & point) const | ||
{ | ||
unsigned int i = nearestPointIndex(point); | ||
|
||
if (i >= _np_post_processor_values.size()) | ||
mooseError("The vector length of vector post processor is ", | ||
_np_post_processor_values.size(), | ||
" but nearestPointIndex() return ", | ||
i); | ||
|
||
return _np_post_processor_values[i]; | ||
} | ||
|
||
Real | ||
NearestPointAverage::userObjectValue(unsigned int i) const | ||
{ | ||
if (i >= _np_post_processor_values.size()) | ||
mooseError("The vector length of vector post processor is ", | ||
_np_post_processor_values.size(), | ||
" but you pass in ", | ||
i); | ||
|
||
return _np_post_processor_values[i]; | ||
} | ||
|
||
void | ||
NearestPointAverage::finalize() | ||
{ | ||
if (_user_objects.size() != _np_post_processor_values.size()) | ||
mooseError("The vector length of the vector postprocessor ", | ||
_np_post_processor_values.size(), | ||
" is different from the number of user objects ", | ||
_user_objects.size()); | ||
|
||
unsigned int i = 0; | ||
for (auto & user_object : _user_objects) | ||
{ | ||
user_object->finalize(); | ||
_np_post_processor_values[i++] = user_object->getValue(); | ||
} | ||
} | ||
|
||
unsigned int | ||
NearestPointAverage::nearestPointIndex(const Point & p) const | ||
{ | ||
unsigned int closest = 0; | ||
Real closest_distance = std::numeric_limits<Real>::max(); | ||
|
||
for (auto it : Moose::enumerate(_points)) | ||
{ | ||
const auto & current_point = it.value(); | ||
|
||
Real current_distance = (p - current_point).norm(); | ||
|
||
if (current_distance < closest_distance) | ||
{ | ||
closest_distance = current_distance; | ||
closest = it.index(); | ||
} | ||
} | ||
|
||
return closest; | ||
} |
Binary file added
BIN
+95.8 KB
test/tests/userobjects/nearest_point_average/gold/nearest_point_average_out.e
Binary file not shown.
80 changes: 80 additions & 0 deletions
80
test/tests/userobjects/nearest_point_average/nearest_point_average.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,80 @@ | ||
[Mesh] | ||
type = GeneratedMesh | ||
dim = 3 | ||
nx = 8 | ||
ny = 8 | ||
nz = 8 | ||
[] | ||
|
||
[Variables] | ||
[u] | ||
[] | ||
[] | ||
|
||
[AuxVariables] | ||
[v] | ||
[] | ||
[np_average] | ||
order = CONSTANT | ||
family = MONOMIAL | ||
[] | ||
[] | ||
|
||
[ICs] | ||
[v] | ||
type = FunctionIC | ||
variable = v | ||
function = v | ||
[] | ||
[] | ||
|
||
[Functions] | ||
[v] | ||
type = ParsedFunction | ||
value = x+y-sin(z) | ||
[] | ||
[] | ||
|
||
[Kernels] | ||
[diff] | ||
type = Diffusion | ||
variable = u | ||
[] | ||
[] | ||
|
||
[AuxKernels] | ||
[np_average] | ||
type = SpatialUserObjectAux | ||
variable = np_average | ||
execute_on = timestep_end | ||
user_object = npa | ||
[] | ||
[] | ||
|
||
[BCs] | ||
[left] | ||
type = DirichletBC | ||
variable = u | ||
boundary = left | ||
value = 0 | ||
[] | ||
[] | ||
|
||
[UserObjects] | ||
[npa] | ||
type = NearestPointAverage | ||
points_file = points.txt | ||
variable = v | ||
[] | ||
[] | ||
|
||
[Executioner] | ||
type = Steady | ||
petsc_options_iname = '-pc_type -pc_hypre_type' | ||
petsc_options_value = 'hypre boomeramg' | ||
[] | ||
|
||
[Outputs] | ||
exodus = true | ||
hide = 'u' | ||
[] |
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,8 @@ | ||
0.25 0.25 0.25 | ||
0.75 0.25 0.25 | ||
0.25 0.75 0.25 | ||
0.75 0.75 0.25 | ||
0.25 0.25 0.75 | ||
0.75 0.25 0.75 | ||
0.25 0.75 0.75 | ||
0.75 0.75 0.75 |
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,10 @@ | ||
[Tests] | ||
[./test] | ||
type = Exodiff | ||
input = nearest_point_average.i | ||
exodiff = nearest_point_average_out.e | ||
requirement = 'The system shall compute averages computed from the closest values for a list of points' | ||
design = 'NearestPointAverage.md' | ||
issues = '#18536' | ||
[../] | ||
[] |