Skip to content

Commit 3240424

Browse files
Merge pull request #31250 from k-collie/k-collie/mfem-point-and-line-sampler
Add MFEM point and line sampler
2 parents 4f13ca8 + dd56f76 commit 3240424

23 files changed

Lines changed: 1132 additions & 1 deletion

framework/doc/content/source/mfem/auxkernels/MFEMCurlAux.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ where $\vec u \in H(\mathrm{curl})$, $\vec v \in H(\mathrm{div})$ and $\lambda$
1616

1717
## Example Input File Syntax
1818

19-
!listing curlcurl.i block=AuxKernels
19+
!listing mfem/kernels/curlcurl.i block=AuxKernels
2020

2121
!syntax parameters /AuxKernels/MFEMCurlAux
2222

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# MFEMLineValueSampler
2+
3+
!if! function=hasCapability('mfem')
4+
5+
## Overview
6+
7+
This class performs accurate interpolation of scalar and vector quantities
8+
along a specified line using MFEM's
9+
[`FindPointsGSLIB`](https://mfem.org/howto/findpts/) `gslib` interpolation.
10+
11+
## Example Input File Syntax
12+
13+
!listing mfem/vectorpostprocessors/point_value_sampler/point_value_sampler_diffusion.i block=VectorPostprocessors
14+
15+
!syntax parameters /VectorPostprocessors/MFEMLineValueSampler
16+
17+
!syntax inputs /VectorPostprocessors/MFEMLineValueSampler
18+
19+
!syntax children /VectorPostprocessors/MFEMLineValueSampler
20+
21+
!if-end!
22+
23+
!else
24+
!include mfem/mfem_warning.md
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# MFEMPointValueSampler
2+
3+
!if! function=hasCapability('mfem')
4+
5+
## Overview
6+
7+
This class performs accurate interpolation of scalar and vector quantities at a
8+
set of specified points using MFEM's
9+
[`FindPointsGSLIB`](https://mfem.org/howto/findpts/) `gslib` interpolation.
10+
11+
## Example Input File Syntax
12+
13+
!listing mfem/vectorpostprocessors/point_value_sampler/point_value_sampler_diffusion.i block=VectorPostprocessors
14+
15+
!syntax parameters /VectorPostprocessors/MFEMPointValueSampler
16+
17+
!syntax inputs /VectorPostprocessors/MFEMPointValueSampler
18+
19+
!syntax children /VectorPostprocessors/MFEMPointValueSampler
20+
21+
!if-end!
22+
23+
!else
24+
!include mfem/mfem_warning.md
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# MFEMValueSamplerBase
2+
3+
!if! function=hasCapability('mfem')
4+
5+
## Summary
6+
7+
Base class which can interpolate scalar and vector quantities at a set of
8+
points. Derived classes control where those points come from, for example a
9+
list of points or a line.
10+
11+
## Overview
12+
13+
This class performs accurate interpolation using MFEM's `FindPointsGSLIB`
14+
`gslib` integration.
15+
16+
!if-end!
17+
18+
!else
19+
!include mfem/mfem_warning.md
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# MFEMVectorPostprocessor
2+
3+
!if! function=hasCapability('mfem')
4+
5+
## Summary
6+
7+
Base class for MFEM vectorpostprocessors used to evaluate an array of values.
8+
9+
## Overview
10+
11+
MFEM vectorpostprocessors calculate an array of values from the (aux)variables,
12+
typically after each timestep.
13+
14+
An `MFEMVectorPostprocessor` is derived from `MFEMGeneralUserObject`.
15+
Therefore, the order of their execution can be controlled similar to other
16+
MOOSE UserObjects using the `execution_order_group` input parameter, e.g., to
17+
require the execution of a vectorpostprocessor computing on an [AuxVariable.md]
18+
strictly after the execution of the [MFEMAuxKernel.md] computing the variable
19+
field itself.
20+
21+
`MFEMVectorPostprocessor` is a virtual base class. Derived classes should use
22+
the `VectorPostprocessor::declareVector` method to get a reference to a vector
23+
which will be output.
24+
25+
!if-end!
26+
27+
!else
28+
!include mfem/mfem_warning.md
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//* This file is part of the MOOSE framework
2+
//* https://mooseframework.inl.gov
3+
//*
4+
//* All rights reserved, see COPYRIGHT for full restrictions
5+
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6+
//*
7+
//* Licensed under LGPL 2.1, please see LICENSE for details
8+
//* https://www.gnu.org/licenses/lgpl-2.1.html
9+
10+
#ifdef MOOSE_MFEM_ENABLED
11+
12+
#pragma once
13+
14+
#include "MFEMValueSamplerBase.h"
15+
16+
#include "mfem.hpp"
17+
18+
/*
19+
* MFEM Postprocessor which samples values at a set of points evenly
20+
* distributed along a line.
21+
*/
22+
class MFEMLineValueSampler : public MFEMValueSamplerBase
23+
{
24+
public:
25+
static InputParameters validParams();
26+
27+
MFEMLineValueSampler(const InputParameters & parameters);
28+
};
29+
30+
#endif // MOOSE_MFEM_ENABLED
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//* This file is part of the MOOSE framework
2+
//* https://mooseframework.inl.gov
3+
//*
4+
//* All rights reserved, see COPYRIGHT for full restrictions
5+
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6+
//*
7+
//* Licensed under LGPL 2.1, please see LICENSE for details
8+
//* https://www.gnu.org/licenses/lgpl-2.1.html
9+
10+
#ifdef MOOSE_MFEM_ENABLED
11+
12+
#pragma once
13+
14+
#include "MFEMValueSamplerBase.h"
15+
16+
#include "mfem.hpp"
17+
18+
/*
19+
* MFEM Postprocessor which samples values at points.
20+
*/
21+
class MFEMPointValueSampler : public MFEMValueSamplerBase
22+
{
23+
public:
24+
static InputParameters validParams();
25+
26+
MFEMPointValueSampler(const InputParameters & parameters);
27+
};
28+
29+
#endif // MOOSE_MFEM_ENABLED
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//* This file is part of the MOOSE framework
2+
//* https://mooseframework.inl.gov
3+
//*
4+
//* All rights reserved, see COPYRIGHT for full restrictions
5+
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6+
//*
7+
//* Licensed under LGPL 2.1, please see LICENSE for details
8+
//* https://www.gnu.org/licenses/lgpl-2.1.html
9+
10+
#ifdef MOOSE_MFEM_ENABLED
11+
12+
#pragma once
13+
14+
#include "MFEMVectorPostprocessor.h"
15+
16+
#include "MooseTypes.h"
17+
#include "libmesh/point.h"
18+
#include "mfem.hpp"
19+
20+
/*
21+
* MFEM Postprocessor which samples values at points.
22+
*
23+
* Subclasses should override validParams and provide and use the constructor.
24+
*/
25+
class MFEMValueSamplerBase : public MFEMVectorPostprocessor
26+
{
27+
public:
28+
static InputParameters validParams();
29+
30+
MFEMValueSamplerBase(const InputParameters & parameters, const std::vector<Point> & points);
31+
32+
/** Perform the interpolation in FindPointsGSLIB.
33+
*/
34+
virtual void execute() override;
35+
36+
/** Store the result of the interpolation.
37+
*/
38+
virtual void finalize() override;
39+
40+
private:
41+
mfem::FindPointsGSLIB _finder;
42+
mfem::Ordering::Type _points_ordering;
43+
mfem::Vector _points;
44+
mfem::Vector _interp_vals;
45+
46+
const VariableName & _var_name;
47+
const mfem::GridFunction & _var;
48+
49+
// VectorPostprocessor declared values - the values written to these are output
50+
std::vector<std::reference_wrapper<VectorPostprocessorValue>> _declared_points;
51+
std::vector<std::reference_wrapper<VectorPostprocessorValue>> _declared_vals;
52+
};
53+
54+
#endif // MOOSE_MFEM_ENABLED
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//* This file is part of the MOOSE framework
2+
//* https://mooseframework.inl.gov
3+
//*
4+
//* All rights reserved, see COPYRIGHT for full restrictions
5+
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6+
//*
7+
//* Licensed under LGPL 2.1, please see LICENSE for details
8+
//* https://www.gnu.org/licenses/lgpl-2.1.html
9+
10+
#ifdef MOOSE_MFEM_ENABLED
11+
12+
#pragma once
13+
14+
#include "MFEMGeneralUserObject.h"
15+
#include "VectorPostprocessor.h"
16+
17+
/*
18+
* Vector postprocessor for MFEM results. Must inherit from VectorPostprocessor
19+
* in order for MOOSE to call it.
20+
*/
21+
class MFEMVectorPostprocessor : public MFEMGeneralUserObject, public VectorPostprocessor
22+
{
23+
public:
24+
static InputParameters validParams();
25+
26+
MFEMVectorPostprocessor(const InputParameters & parameters);
27+
};
28+
29+
#endif // MOOSE_MFEM_ENABLED
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
//* This file is part of the MOOSE framework
2+
//* https://mooseframework.inl.gov
3+
//*
4+
//* All rights reserved, see COPYRIGHT for full restrictions
5+
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6+
//*
7+
//* Licensed under LGPL 2.1, please see LICENSE for details
8+
//* https://www.gnu.org/licenses/lgpl-2.1.html
9+
10+
#ifdef MOOSE_MFEM_ENABLED
11+
12+
#include "MFEMLineValueSampler.h"
13+
14+
#include "libmesh/point.h"
15+
#include "MooseError.h"
16+
#include "MFEMProblem.h"
17+
18+
#include <vector>
19+
20+
registerMooseObject("MooseApp", MFEMLineValueSampler);
21+
22+
namespace
23+
{
24+
std::vector<Point>
25+
generateLinePoints(const Point & start_point, const Point & end_point, unsigned int num_points)
26+
{
27+
if (num_points < 2)
28+
{
29+
mooseError("In MFEMLineValueSampler: line must have at least 2 points,"
30+
"for single points use MFEMPointValueSampler.");
31+
}
32+
33+
// initialize and populate vector with linearly-spaced points along line
34+
std::vector<Point> points;
35+
points.reserve(num_points);
36+
for (unsigned int i_point = 0; i_point < num_points; i_point++)
37+
{
38+
// fractional distance along line [0, 1]
39+
Real t = static_cast<Real>(i_point) / static_cast<Real>(num_points - 1);
40+
points.push_back(t * end_point + (1 - t) * start_point);
41+
}
42+
43+
return points;
44+
}
45+
}
46+
47+
InputParameters
48+
MFEMLineValueSampler::validParams()
49+
{
50+
InputParameters params = MFEMValueSamplerBase::validParams();
51+
52+
params.addClassDescription("Sample an MFEM variable along a specified line.");
53+
54+
// these should not be of type libmesh::Point - need mfem::Point parsing
55+
params.addRequiredParam<Point>("start_point", "The beginning of the line");
56+
params.addRequiredParam<Point>("end_point", "The ending of the line");
57+
58+
params.addRequiredParam<unsigned int>("num_points",
59+
"The number of points to sample along the line");
60+
61+
return params;
62+
}
63+
64+
MFEMLineValueSampler::MFEMLineValueSampler(const InputParameters & parameters)
65+
: MFEMValueSamplerBase(parameters,
66+
// can't call getParam as that requires initialized base class
67+
// so calling parameters.get directly
68+
generateLinePoints(parameters.get<Point>("start_point"),
69+
parameters.get<Point>("end_point"),
70+
parameters.get<unsigned int>("num_points")))
71+
{
72+
}
73+
74+
#endif // MOOSE_MFEM_ENABLED

0 commit comments

Comments
 (0)