-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25349 from GiudGiud/PR_function_pos
Positions from functors
- Loading branch information
Showing
6 changed files
with
247 additions
and
0 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
framework/doc/content/source/positions/FunctorPositions.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,19 @@ | ||
# FunctorPositions | ||
|
||
!syntax description /Positions/FunctorPositions | ||
|
||
See the [Functor](syntax/Functors/index.md) for the list of available functors. | ||
The functors are evaluated at the origin of the mesh at the current time. | ||
|
||
## Example File Syntax | ||
|
||
In this example, the `FunctorPositions` is obtaining the positions from three time-dependent functions. | ||
The functions are evaluated at the origin of the mesh at the current time. | ||
|
||
!listing tests/positions/functor_positions.i block=Positions | ||
|
||
!syntax parameters /Positions/FunctorPositions | ||
|
||
!syntax inputs /Positions/FunctorPositions | ||
|
||
!syntax children /Positions/FunctorPositions |
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,31 @@ | ||
//* 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 "Positions.h" | ||
#include "FunctorInterface.h" | ||
|
||
/** | ||
* Positions from groups of three functors | ||
*/ | ||
class FunctorPositions : public Positions, public NonADFunctorInterface | ||
{ | ||
public: | ||
static InputParameters validParams(); | ||
FunctorPositions(const InputParameters & parameters); | ||
virtual ~FunctorPositions() = default; | ||
|
||
void initialize() override; | ||
|
||
private: | ||
/// Vector of pointers to the functors for each coordinate (inner-ordering is coordinates) | ||
std::vector<const Moose::Functor<Real> *> _pos_functors; | ||
}; |
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,76 @@ | ||
//* 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 "FunctorPositions.h" | ||
|
||
registerMooseObject("MooseApp", FunctorPositions); | ||
|
||
InputParameters | ||
FunctorPositions::validParams() | ||
{ | ||
InputParameters params = Positions::validParams(); | ||
params += NonADFunctorInterface::validParams(); | ||
|
||
params.addRequiredParam<std::vector<MooseFunctorName>>( | ||
"positions_functors", "Functors providing the XYZ coordinates of the positions"); | ||
// Use user-provided ordering | ||
params.set<bool>("auto_sort") = false; | ||
// All functors defined on all processes for now | ||
params.set<bool>("auto_broadcast") = false; | ||
// Keep as up-to-date as possible given the generality of functors | ||
params.set<ExecFlagEnum>("execute_on") = {EXEC_LINEAR, EXEC_TIMESTEP_BEGIN}; | ||
|
||
params.addClassDescription( | ||
"Import positions from one or more reporters, for example other Positions"); | ||
return params; | ||
} | ||
|
||
FunctorPositions::FunctorPositions(const InputParameters & parameters) | ||
: Positions(parameters), NonADFunctorInterface(this) | ||
|
||
{ | ||
const auto & functor_names = getParam<std::vector<MooseFunctorName>>("positions_functors"); | ||
|
||
// Check input sizes | ||
if (functor_names.size() % 3 != 0) | ||
paramError("position_functors", | ||
"The list of functors must be divisible by three, the number of coordinates"); | ||
|
||
for (const auto & name : functor_names) | ||
_pos_functors.push_back(&getFunctor<Real>(name)); | ||
|
||
// Obtain the positions by evaluating the functors | ||
initialize(); | ||
// Sort if needed (user-specified) | ||
finalize(); | ||
} | ||
|
||
void | ||
FunctorPositions::initialize() | ||
{ | ||
clearPositions(); | ||
const auto n_positions = _pos_functors.size() / 3; | ||
_positions.resize(n_positions); | ||
|
||
// Use the mesh center as a global argument for now | ||
_fe_problem.mesh().errorIfDistributedMesh(type()); | ||
// Locate the origin on the mesh | ||
const Point p(0, 0, 0); | ||
auto pl = _fe_problem.mesh().getMesh().sub_point_locator(); | ||
auto * const elem = (*pl)(p); | ||
if (!elem) | ||
mooseError("Origin point not in local mesh, cannot evaluate the functor there"); | ||
const Moose::ElemPointArg elem_origin = {elem, p, false}; | ||
const auto t = determineState(); | ||
|
||
for (auto i : make_range(n_positions)) | ||
_positions[i] = {(*_pos_functors[3 * i])(elem_origin, t), | ||
(*_pos_functors[3 * i + 1])(elem_origin, t), | ||
(*_pos_functors[3 * i + 2])(elem_origin, t)}; | ||
} |
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 @@ | ||
[Mesh] | ||
[cmg] | ||
type = CartesianMeshGenerator | ||
dx = 1 | ||
dim = 1 | ||
[] | ||
[] | ||
|
||
[Positions] | ||
[functors] | ||
type = FunctorPositions | ||
positions_functors = '0.1 0 0.3 | ||
f1 f2 f1' | ||
[] | ||
[] | ||
|
||
[Functions] | ||
[f1] | ||
type = PiecewiseConstant | ||
x = '0 0.5 1' | ||
y = '1 2 3' | ||
[] | ||
[f2] | ||
type = PiecewiseLinear | ||
x = '0 0.5 1' | ||
y = '1 2 3' | ||
[] | ||
[] | ||
|
||
[Problem] | ||
solve = false | ||
[] | ||
|
||
[Executioner] | ||
type = Transient | ||
# Test recover | ||
num_steps = 2 | ||
[] | ||
|
||
[Outputs] | ||
[out] | ||
type = JSON | ||
execute_system_information_on = none | ||
[] | ||
[] |
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,68 @@ | ||
{ | ||
"reporters": { | ||
"functors": { | ||
"type": "FunctorPositions", | ||
"values": { | ||
"positions_1d": { | ||
"type": "std::vector<libMesh::Point>" | ||
} | ||
} | ||
} | ||
}, | ||
"time_steps": [ | ||
{ | ||
"functors": { | ||
"positions_1d": [ | ||
{ | ||
"x": 0.1, | ||
"y": 0.0, | ||
"z": 0.3 | ||
}, | ||
{ | ||
"x": 1.0, | ||
"y": 1.0, | ||
"z": 1.0 | ||
} | ||
] | ||
}, | ||
"time": 0.0, | ||
"time_step": 0 | ||
}, | ||
{ | ||
"functors": { | ||
"positions_1d": [ | ||
{ | ||
"x": 0.1, | ||
"y": 0.0, | ||
"z": 0.3 | ||
}, | ||
{ | ||
"x": 2.0, | ||
"y": 3.0, | ||
"z": 2.0 | ||
} | ||
] | ||
}, | ||
"time": 1.0, | ||
"time_step": 1 | ||
}, | ||
{ | ||
"functors": { | ||
"positions_1d": [ | ||
{ | ||
"x": 0.1, | ||
"y": 0.0, | ||
"z": 0.3 | ||
}, | ||
{ | ||
"x": 3.0, | ||
"y": 3.0, | ||
"z": 3.0 | ||
} | ||
] | ||
}, | ||
"time": 2.0, | ||
"time_step": 2 | ||
} | ||
] | ||
} |
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