19 "This Function finds the nearest point in the specified vectors of coordinates and returns " 20 "the values specified in the vector of values at the index of the nearest point. All the " 21 "vectors must be specified using either vector postprocessors or reporter vectors. This " 22 "function interpolates linearly in time with transient data.");
24 "Name of vector-postprocessor or reporter vector containing " 25 "x-coordinate of points, default is assumed to be all 0s.");
27 "Name of vector-postprocessor or reporter vector containing " 28 "y-coordinate of points, default is assumed to be all 0s.");
30 "Name of vector-postprocessor or reporter vector containing " 31 "z-coordinate of points, default is assumed to be all 0s.");
33 "Name of vector-postprocessor or reporter vector containing time, " 34 "default is assumed to be all 0s.");
36 "value_name",
"Name of vector-postprocessor or reporter vector containing value data.");
44 _coordx(isParamValid(
"x_coord_name") ? getReporterValue<
std::vector<
Real>>(
"x_coord_name")
46 _coordy(isParamValid(
"y_coord_name") ? getReporterValue<
std::vector<
Real>>(
"y_coord_name")
48 _coordz(isParamValid(
"z_coord_name") ? getReporterValue<
std::vector<
Real>>(
"z_coord_name")
50 _coordt(isParamValid(
"time_name") ? getReporterValue<
std::vector<
Real>>(
"time_name")
52 _values(getReporterValue<
std::vector<
Real>>(
"value_name"))
59 const std::array<std::pair<Real, std::size_t>, 2> tv =
findNearestPoint(t, p);
64 if (tv[0].second == tv[1].second)
67 const Real told = tv[0].first;
68 const Real tnew = tv[1].first;
71 return vold + (vnew - vold) * (t - told) / (tnew - told);
83 const std::array<std::pair<Real, std::size_t>, 2> tv =
findNearestPoint(t, p);
85 if (tv[0].second == tv[1].second)
88 const Real told = tv[0].first;
89 const Real tnew = tv[1].first;
92 return (vnew - vold) / (tnew - told);
98 const std::array<std::pair<Real, std::size_t>, 2> tv =
findNearestPoint(t, p);
99 std::vector<Real> param_grad(
_nval, 0.0);
101 if (tv[0].second == tv[1].second)
102 param_grad[tv[0].second] = 1;
105 const Real told = tv[0].first;
106 const Real tnew = tv[1].first;
107 param_grad[tv[0].second] = (tnew - t) / (tnew - told);
108 param_grad[tv[1].second] = (t - told) / (tnew - told);
119 paramError(
"value",
"At least one coordinate vector must not be empty.");
122 "Number of x coordinates (",
124 ") does not match number of values (",
129 "Number of y coordinates (",
131 ") does not match number of values (",
136 "Number of z coordinates (",
138 ") does not match number of values (",
145 ") does not match number of values (",
159 std::vector<std::pair<Real, std::size_t>> * vec =
nullptr;
161 if (pt.absolute_fuzzy_equals(it.first))
169 vec->emplace_back(time, i);
170 std::sort(vec->begin(),
172 [](
const std::pair<Real, Real> &
a,
const std::pair<Real, Real> &
b)
173 {
return a.first <
b.first; });
177 std::array<std::pair<Real, std::size_t>, 2>
186 "Size of value vector (",
188 ") does not match number of coordinates specified (",
195 [&p](
const std::pair<Point, std::vector<std::pair<Real, std::size_t>>> & p1,
196 const std::pair<Point, std::vector<std::pair<Real, std::size_t>>> & p2)
197 {
return (p - p1.first).norm_sq() < (p - p2.first).
norm_sq(); })
201 return {tval[0], tval[0]};
203 return {tval.back(), tval.back()};
205 for (std::size_t ti = 1; ti < tval.size(); ++ti)
207 return {tval[ti - 1], tval[ti]};
209 mooseError(
"Internal error: unable to find nearest point.");
210 return std::array<std::pair<Real, std::size_t>, 2>();
void buildCoordinateMapping() const
Builds _coord_mapping object with coordinates from input vectors.
const std::vector< Real > & _coordy
y-coordinates from reporter
const std::vector< Real > & _coordt
time-coordinates from reporter
const std::vector< Real > & _coordx
x-coordinates from reporter
NearestReporterCoordinatesFunction(const InputParameters ¶meters)
std::array< std::pair< Real, std::size_t >, 2 > findNearestPoint(Real t, const Point &p) const
With an input time and point, gets the closest point and two closest times in _coord_mapping.
virtual Real timeDerivative(Real t, const Point &p) const override
const std::vector< Real > & _values
values from reporter
std::size_t _nval
Number of values from coordinate vectors.
Function based on the nearest point to coordinates and values defined by a vector of values...
void paramError(const std::string ¶m, Args... args) const
virtual RealGradient gradient(Real t, const Point &p) const override
registerMooseObject("OptimizationApp", NearestReporterCoordinatesFunction)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Base class for functions used in inverse optimization The parameterDerivative function is used in adj...
const std::vector< Real > & _coordz
z-coordinates from reporter
static InputParameters validParams()
virtual std::vector< Real > parameterGradient(Real t, const Point &p) const override
bool absoluteFuzzyLessEqual(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
IntRange< T > make_range(T beg, T end)
bool absoluteFuzzyGreaterEqual(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
void mooseError(Args &&... args) const
std::map< Point, std::vector< std::pair< Real, std::size_t > > > _coord_mapping
Data structure for all current data.
static InputParameters validParams()
virtual Real value(Real t, const Point &p) const override