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 : // MOOSE includes 11 : #include "NearestPointAverage.h" 12 : 13 : registerMooseObject("MooseApp", NearestPointAverage); 14 : 15 : InputParameters 16 14290 : NearestPointAverage::validParams() 17 : { 18 : InputParameters params = 19 14290 : NearestPointBase<ElementAverageValue, ElementVariableVectorPostprocessor>::validParams(); 20 : 21 : // The base type (ElementAverageValue) and the user object type (ElementVariableVPP) are 22 : // postprocessor and VPP respectively and this object is meant to be a UO 23 14290 : params.set<std::string>("_moose_base") = "UserObject"; 24 : 25 14290 : params.addClassDescription( 26 : "Compute element variable averages for nearest-point based subdomains"); 27 : 28 14290 : return params; 29 0 : } 30 : 31 13 : NearestPointAverage::NearestPointAverage(const InputParameters & parameters) 32 : : NearestPointBase<ElementAverageValue, ElementVariableVectorPostprocessor>(parameters), 33 13 : _np_post_processor_values(declareVector("np_post_processor_values")) 34 : { 35 13 : _np_post_processor_values.resize(_user_objects.size()); 36 13 : } 37 : 38 : Real 39 32768 : NearestPointAverage::spatialValue(const Point & point) const 40 : { 41 32768 : unsigned int i = nearestPointIndex(point); 42 : 43 32768 : if (i >= _np_post_processor_values.size()) 44 0 : mooseError("The vector length of vector post processor is ", 45 0 : _np_post_processor_values.size(), 46 : " but nearestPointIndex() return ", 47 : i); 48 : 49 32768 : return _np_post_processor_values[i]; 50 : } 51 : 52 : Real 53 0 : NearestPointAverage::userObjectValue(unsigned int i) const 54 : { 55 0 : if (i >= _np_post_processor_values.size()) 56 0 : mooseError("The vector length of vector post processor is ", 57 0 : _np_post_processor_values.size(), 58 : " but you pass in ", 59 : i); 60 : 61 0 : return _np_post_processor_values[i]; 62 : } 63 : 64 : void 65 11 : NearestPointAverage::finalize() 66 : { 67 11 : if (_user_objects.size() != _np_post_processor_values.size()) 68 0 : mooseError("The vector length of the vector postprocessor ", 69 0 : _np_post_processor_values.size(), 70 : " is different from the number of user objects ", 71 0 : _user_objects.size()); 72 : 73 11 : unsigned int i = 0; 74 99 : for (auto & user_object : _user_objects) 75 : { 76 88 : user_object->finalize(); 77 88 : const auto & const_user_object = *user_object; 78 88 : _np_post_processor_values[i++] = const_user_object.getValue(); 79 : } 80 11 : } 81 : 82 : unsigned int 83 32768 : NearestPointAverage::nearestPointIndex(const Point & p) const 84 : { 85 32768 : unsigned int closest = 0; 86 32768 : Real closest_distance = std::numeric_limits<Real>::max(); 87 : 88 294912 : for (auto it : Moose::enumerate(_points)) 89 : { 90 262144 : const auto & current_point = it.value(); 91 : 92 262144 : Real current_distance = (p - current_point).norm(); 93 : 94 262144 : if (current_distance < closest_distance) 95 : { 96 91136 : closest_distance = current_distance; 97 91136 : closest = it.index(); 98 : } 99 : } 100 : 101 32768 : return closest; 102 : }