https://mooseframework.inl.gov
Loading...
Searching...
No Matches
MisfitReporterOffsetFunctionMaterial.C
Go to the documentation of this file.
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
11
12#include "libmesh/libmesh_common.h"
13
16
17template <bool is_ad>
20{
23 "Computes the misfit and misfit gradient materials for inverse optimizations problems.");
24
25 params.addRequiredCoupledVar("forward_variable",
26 "Variable that is being used for the forward simulation.");
27 params.addRequiredParam<ReporterName>("measurement_value_name",
28 "Reporter with measurement data.");
29 return params;
30}
31
32template <bool is_ad>
34 const InputParameters & parameters)
35 : ReporterOffsetFunctionMaterialTempl<is_ad>(parameters),
36 _sim_var(this->template coupledGenericValue<is_ad>("forward_variable")),
37 _mat_prop_gradient(
38 this->template declareGenericProperty<Real, is_ad>(_prop_name + "_gradient")),
39 _measurement_values(this->template getReporterValue<std::vector<Real>>(
40 "measurement_value_name", REPORTER_MODE_REPLICATED))
41{
42}
43
44template <bool is_ad>
45void
47{
48 _material[_qp] = 0.0;
49 _mat_prop_gradient[_qp] = 0.0;
50 auto num_pts = _read_in_points ? _points.size() : _coordx.size();
51 if (!_read_in_points)
52 mooseAssert((_coordx.size() == _coordy.size()) && (_coordx.size() == _coordz.size()),
53 "Size of the coordinate offsets don't match.");
54
55 mooseAssert(num_pts == _measurement_values.size(),
56 "Number of offsets doesn't match the number of measurements.");
57
58 for (const auto idx : make_range(num_pts))
59 {
60 const Point offset =
61 _read_in_points ? _points[idx] : Point(_coordx[idx], _coordy[idx], _coordz[idx]);
62
63 const Real measurement_value = _measurement_values[idx];
64 const auto simulation_value = _sim_var[_qp];
65
66 // Compute weighting function
67 const Real weighting = computeOffsetFunction(offset);
68
69 // Computed weighted misfit and gradient materials
70 _material[_qp] +=
71 Utility::pow<2>(weighting) * Utility::pow<2>(measurement_value - simulation_value);
72 _mat_prop_gradient[_qp] -=
73 2.0 * Utility::pow<2>(weighting) * (measurement_value - simulation_value);
74 }
75}
76
registerMooseObject("OptimizationApp", MisfitReporterOffsetFunctionMaterial)
const ReporterMode REPORTER_MODE_REPLICATED
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
This class creates a misfit and misfit gradient material that can be used for optimizing measurements...
MisfitReporterOffsetFunctionMaterialTempl(const InputParameters &parameters)
This class defines a material with an associated offset function.