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 "SensitivityFilter.h" 11 : #include "MooseError.h" 12 : #include <algorithm> 13 : 14 : registerMooseObject("OptimizationApp", SensitivityFilter); 15 : 16 : InputParameters 17 246 : SensitivityFilter::validParams() 18 : { 19 246 : InputParameters params = ElementUserObject::validParams(); 20 246 : params.addClassDescription( 21 : "Computes the filtered sensitivity using a radial average user object."); 22 492 : params.addRequiredParam<UserObjectName>("filter_UO", "Radial Average user object"); 23 492 : params.addRequiredCoupledVar("density_sensitivity", "Name of the density_sensitivity variable."); 24 492 : params.addRequiredParam<VariableName>("design_density", "Design density variable name."); 25 : 26 246 : return params; 27 0 : } 28 : 29 132 : SensitivityFilter::SensitivityFilter(const InputParameters & parameters) 30 : : ElementUserObject(parameters), 31 132 : _filter(getUserObject<RadialAverage>("filter_UO").getAverage()), 32 132 : _density_sensitivity(writableVariable("density_sensitivity")), 33 132 : _design_density_name(getParam<VariableName>("design_density")), 34 264 : _design_density(_subproblem.getStandardVariable(_tid, _design_density_name)) 35 : { 36 132 : } 37 : 38 : void 39 118272 : SensitivityFilter::execute() 40 : { 41 : // Find the current element in the filter 42 118272 : auto filter_iter = _filter.find(_current_elem->id()); 43 : 44 : // Assert the element is found in the filter 45 : mooseAssert(filter_iter != _filter.end(), 46 : "An element could not be found in the filter. Check that a RadialAverage user object " 47 : "has run before this object."); 48 : 49 : // Get the quadrature point values from the filter 50 118272 : std::vector<Real> qp_vals = filter_iter->second; 51 : 52 : // Initialize the total elemental sensitivity value 53 118272 : Real den_sense_val = 0; 54 : 55 : // Compute the total elemental sensitivity value by summing over all quadrature points 56 591360 : for (unsigned int qp = 0; qp < _qrule->n_points(); qp++) 57 473088 : den_sense_val += qp_vals[qp] * _JxW[qp]; 58 : 59 118272 : den_sense_val /= _current_elem_volume; 60 : 61 : // Set the nodal value of the density sensitivity 62 118272 : _density_sensitivity.setNodalValue(den_sense_val); 63 118272 : }