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 "NearestPointIntegralVariablePostprocessor.h" 12 : 13 : registerMooseObject("MooseApp", NearestPointIntegralVariablePostprocessor); 14 : 15 : InputParameters 16 14508 : NearestPointIntegralVariablePostprocessor::validParams() 17 : { 18 : InputParameters params = NearestPointBase<ElementIntegralVariablePostprocessor, 19 14508 : ElementVariableVectorPostprocessor>::validParams(); 20 : 21 14508 : params.addClassDescription( 22 : "Compute element variable integrals for nearest-point based subdomains"); 23 : 24 14508 : params.registerBase("VectorPostprocessor"); 25 : 26 14508 : return params; 27 0 : } 28 : 29 127 : NearestPointIntegralVariablePostprocessor::NearestPointIntegralVariablePostprocessor( 30 127 : const InputParameters & parameters) 31 : : NearestPointBase<ElementIntegralVariablePostprocessor, ElementVariableVectorPostprocessor>( 32 : parameters), 33 127 : _np_post_processor_values(declareVector("np_post_processor_values")) 34 : { 35 127 : _np_post_processor_values.resize(_user_objects.size()); 36 127 : } 37 : 38 : Real 39 64088 : NearestPointIntegralVariablePostprocessor::spatialValue(const Point & point) const 40 : { 41 64088 : unsigned int i = nearestPointIndex(point); 42 : 43 64088 : 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 64088 : return _np_post_processor_values[i]; 50 : } 51 : 52 : Real 53 557568 : NearestPointIntegralVariablePostprocessor::userObjectValue(unsigned int i) const 54 : { 55 557568 : 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 557568 : return _np_post_processor_values[i]; 62 : } 63 : 64 : void 65 165 : NearestPointIntegralVariablePostprocessor::finalize() 66 : { 67 165 : 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 165 : unsigned int i = 0; 74 517 : for (auto & user_object : _user_objects) 75 : { 76 352 : user_object->finalize(); 77 352 : const auto & const_user_object = *user_object; 78 352 : _np_post_processor_values[i++] = const_user_object.getValue(); 79 : } 80 165 : } 81 : 82 : unsigned int 83 620312 : NearestPointIntegralVariablePostprocessor::nearestPointIndex(const Point & p) const 84 : { 85 620312 : unsigned int closest = 0; 86 620312 : Real closest_distance = std::numeric_limits<Real>::max(); 87 : 88 1989112 : for (auto it : Moose::enumerate(_points)) 89 : { 90 1368800 : const auto & current_point = it.value(); 91 : 92 1368800 : Real current_distance = (p - current_point).norm(); 93 : 94 1368800 : if (current_distance < closest_distance) 95 : { 96 969222 : closest_distance = current_distance; 97 969222 : closest = it.index(); 98 : } 99 : } 100 : 101 620312 : return closest; 102 : }