20 params.
addClassDescription(
"Optimization function with parameters represented by a mesh and "
21 "finite-element shape functions.");
23 params.
addRequiredParam<FileName>(
"exodus_mesh",
"File containing parameter mesh.");
26 "Family of FE shape functions for parameter.");
29 "Order of FE shape functions for parameter.");
32 "parameter_name",
"Reporter or VectorPostprocessor vector containing parameter values.");
34 "Name of vector-postprocessor or reporter vector containing time, "
35 "default assumes time independence.");
37 "project_points",
false,
"Whether to find the closest point on parameter mesh.");
41 "Number of nearest node candidates to consider when projecting points to parameter mesh.");
50 getParam<FileName>(
"exodus_mesh"),
51 getParam<bool>(
"project_points"),
52 getParam<unsigned
int>(
"kdtree_candidates")),
53 _values(getReporterValue<
std::vector<Real>>(
"parameter_name")),
54 _coordt(isParamValid(
"time_name") ? getReporterValue<
std::vector<Real>>(
"time_name")
68 std::vector<dof_id_type> dof_indices;
69 std::vector<Real> weights;
74 for (
const auto & i : index_range(dof_indices))
75 val += (
_values[dof_indices[i] + offset0] * ti[0].second +
76 _values[dof_indices[i] + offset1] * ti[1].second) *
90 std::vector<dof_id_type> dof_indices;
91 std::vector<RealGradient> weights;
94 RealGradient val(0, 0, 0);
95 for (
const auto & i : index_range(dof_indices))
96 val += (
_values[dof_indices[i] + offset0] * ti[0].second +
97 _values[dof_indices[i] + offset1] * ti[1].second) *
108 if (ti[0].first == ti[1].first)
113 std::vector<dof_id_type> dof_indices;
114 std::vector<Real> weights;
118 for (
const auto & i : index_range(dof_indices))
119 val += (
_values[dof_indices[i] + offset0] * ti[0].second +
120 _values[dof_indices[i] + offset1] * ti[1].second) *
132 std::vector<dof_id_type> dof_indices;
133 std::vector<Real> weights;
139 std::vector<Real> pg(sz, 0.0);
140 for (
const auto & i : index_range(dof_indices))
142 pg[dof_indices[i] + offset0] += weights[i] * ti[0].second;
143 pg[dof_indices[i] + offset1] += weights[i] * ti[1].second;
148std::array<std::pair<std::size_t, Real>, 2>
151 std::array<std::pair<std::size_t, Real>, 2> ti;
152 if (
_coordt.size() <= 1 || MooseUtils::absoluteFuzzyLessEqual(t,
_coordt[0]))
157 else if (MooseUtils::absoluteFuzzyGreaterEqual(t,
_coordt.back()))
159 ti[0] = {
_coordt.size() - 1, 0.5};
160 ti[1] = {
_coordt.size() - 1, 0.5};
163 for (std::size_t i = 1; i <
_coordt.size(); ++i)
164 if (MooseUtils::absoluteFuzzyGreaterEqual(
_coordt[i], t))
169 ti[0] = {i - 1, -1.0 / dt};
170 ti[1] = {i, 1.0 / dt};
174 ti[0] = {i - 1, (
_coordt[i] - t) / dt};
175 ti[1] = {i, (t -
_coordt[i - 1]) / dt};
191 "Size of parameter vector (",
193 ") does not match number of degrees of freedom in mesh (",
registerMooseObject("OptimizationApp", ParameterMeshFunction)
void ErrorVector unsigned int
static MooseEnum getNonlinearVariableFamilies()
static MooseEnum getNonlinearVariableOrders()
void paramError(const std::string ¶m, Args... args) const
Base class for functions used in inverse optimization The parameterDerivative function is used in adj...
static InputParameters validParams()
const std::vector< Real > & _coordt
Time coordinates from reporter.
ParameterMeshFunction(const InputParameters ¶meters)
virtual Real timeDerivative(Real t, const Point &p) const override
virtual RealGradient gradient(Real t, const Point &p) const override
virtual Real value(Real t, const Point &p) const override
const ParameterMesh _parameter_mesh
Parameter mesh.
virtual std::vector< Real > parameterGradient(Real t, const Point &p) const override
std::array< std::pair< std::size_t, Real >, 2 > interpolateTime(Real t, bool derivative=false) const
This function is used to compute the weights for time interpolation.
void checkSize() const
Used to make sure DoFs in '_parameter_mesh' matches number of values in '_values'.
static InputParameters validParams()
const std::vector< Real > & _values
values from reporter
void getIndexAndWeight(const Point &pt, std::vector< dof_id_type > &dof_indices, std::vector< Real > &weights) const
Interpolate parameters onto the computational mesh getIndexAndWeight is only used by ParameterMeshFun...