Line data Source code
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 : #include "MisfitReporterOffsetFunctionMaterial.h" 11 : 12 : #include "libmesh/libmesh_common.h" 13 : 14 : registerMooseObject("OptimizationApp", MisfitReporterOffsetFunctionMaterial); 15 : registerMooseObject("OptimizationApp", ADMisfitReporterOffsetFunctionMaterial); 16 : 17 : template <bool is_ad> 18 : InputParameters 19 72 : MisfitReporterOffsetFunctionMaterialTempl<is_ad>::validParams() 20 : { 21 72 : InputParameters params = ReporterOffsetFunctionMaterial::validParams(); 22 72 : params.addClassDescription( 23 : "Computes the misfit and misfit gradient materials for inverse optimizations problems."); 24 : 25 144 : params.addRequiredCoupledVar("forward_variable", 26 : "Variable that is being used for the forward simulation."); 27 144 : params.addRequiredParam<ReporterName>("measurement_value_name", 28 : "Reporter with measurement data."); 29 72 : return params; 30 0 : } 31 : 32 : template <bool is_ad> 33 54 : MisfitReporterOffsetFunctionMaterialTempl<is_ad>::MisfitReporterOffsetFunctionMaterialTempl( 34 : const InputParameters & parameters) 35 : : ReporterOffsetFunctionMaterialTempl<is_ad>(parameters), 36 54 : _sim_var(this->template coupledGenericValue<is_ad>("forward_variable")), 37 54 : _mat_prop_gradient( 38 54 : this->template declareGenericProperty<Real, is_ad>(_prop_name + "_gradient")), 39 54 : _measurement_values(this->template getReporterValue<std::vector<Real>>( 40 54 : "measurement_value_name", REPORTER_MODE_REPLICATED)) 41 : { 42 54 : } 43 : 44 : template <bool is_ad> 45 : void 46 1501920 : MisfitReporterOffsetFunctionMaterialTempl<is_ad>::computeQpProperties() 47 : { 48 1501920 : _material[_qp] = 0.0; 49 1501920 : _mat_prop_gradient[_qp] = 0.0; 50 1501920 : 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 6395760 : for (const auto idx : make_range(num_pts)) 59 : { 60 4893840 : const Point offset = 61 4893840 : _read_in_points ? _points[idx] : Point(_coordx[idx], _coordy[idx], _coordz[idx]); 62 : 63 4893840 : const Real measurement_value = _measurement_values[idx]; 64 4893840 : const auto simulation_value = _sim_var[_qp]; 65 : 66 : // Compute weighting function 67 4893840 : const Real weighting = computeOffsetFunction(offset); 68 : 69 : // Computed weighted misfit and gradient materials 70 4893840 : _material[_qp] += 71 4893840 : Utility::pow<2>(weighting) * Utility::pow<2>(measurement_value - simulation_value); 72 4893840 : _mat_prop_gradient[_qp] -= 73 4893840 : 2.0 * Utility::pow<2>(weighting) * (measurement_value - simulation_value); 74 : } 75 1501920 : } 76 : 77 : template class MisfitReporterOffsetFunctionMaterialTempl<true>; 78 : template class MisfitReporterOffsetFunctionMaterialTempl<false>;