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 "PointVariableSamplerBase.h" 11 : 12 : // MOOSE includes 13 : #include "MooseMesh.h" 14 : #include "Assembly.h" 15 : 16 : #include "libmesh/mesh_tools.h" 17 : 18 : InputParameters 19 44231 : PointVariableSamplerBase::validParams() 20 : { 21 44231 : InputParameters params = GeneralVectorPostprocessor::validParams(); 22 : 23 44231 : params += SamplerBase::validParams(); 24 : 25 44231 : params.addRequiredCoupledVar( 26 : "variable", "The names of the variables that this VectorPostprocessor operates on"); 27 132693 : params.addParam<PostprocessorName>( 28 88462 : "scaling", 1.0, "The postprocessor that the variables are multiplied with"); 29 132693 : params.addParam<bool>( 30 : "warn_discontinuous_face_values", 31 88462 : true, 32 : "Whether to return a warning if a discontinuous variable is sampled on a face"); 33 : 34 44231 : return params; 35 0 : } 36 : 37 719 : PointVariableSamplerBase::PointVariableSamplerBase(const InputParameters & parameters) 38 : : PointSamplerBase(parameters), 39 : CoupleableMooseVariableDependencyIntermediateInterface(this, false), 40 : MooseVariableInterface<Real>(this, 41 : false, 42 : "variable", 43 : Moose::VarKindType::VAR_ANY, 44 719 : Moose::VarFieldType::VAR_FIELD_STANDARD) 45 : { 46 719 : addMooseVariableDependency(&mooseVariableField()); 47 : 48 719 : std::vector<std::string> var_names(_coupled_moose_vars.size()); 49 : 50 1771 : for (unsigned int i = 0; i < _coupled_moose_vars.size(); i++) 51 : { 52 1052 : var_names[i] = _coupled_moose_vars[i]->name(); 53 1052 : SamplerBase::checkForStandardFieldVariableType(_coupled_moose_vars[i]); 54 : } 55 : 56 : // Initialize the data structures in SamplerBase 57 719 : SamplerBase::setupVariables(var_names); 58 719 : } 59 : 60 : void 61 3855 : PointVariableSamplerBase::initialize() 62 : { 63 3855 : SamplerBase::initialize(); 64 : 65 3855 : PointSamplerBase::initialize(); 66 : 67 : // Check for elemental variables, which are ill-defined on faces for this object 68 8258 : for (unsigned int i = 0; i < _coupled_moose_vars.size(); i++) 69 4403 : if (!_assembly.getFE(_coupled_moose_vars[i]->feType(), _mesh.dimension())->get_continuity()) 70 400 : _discontinuous_at_faces = true; 71 3855 : } 72 : 73 : void 74 3855 : PointVariableSamplerBase::execute() 75 : { 76 3855 : BoundingBox bbox = _mesh.getInflatedProcessorBoundingBox(); 77 : 78 : /// So we don't have to create and destroy this 79 3855 : std::vector<Point> point_vec(1); 80 : 81 61488 : for (MooseIndex(_points) i = 0; i < _points.size(); ++i) 82 : { 83 57633 : Point & p = _points[i]; 84 : 85 : // Do a bounding box check so we're not doing unnecessary PointLocator lookups 86 : // In the discontinuous case all ranks must proceed to get a global consensus 87 : // on who owns face points in getLocalElemContainingPoint() 88 57633 : if (bbox.contains_point(p) || _discontinuous_at_faces) 89 : { 90 42871 : auto & values = _point_values[i]; 91 : 92 42871 : if (values.empty()) 93 42871 : values.resize(_coupled_moose_vars.size()); 94 : 95 : // First find the element the hit lands in 96 42871 : const Elem * elem = getLocalElemContainingPoint(p); 97 : 98 42871 : if (elem) 99 : { 100 : // We have to pass a vector of points into reinitElemPhys 101 40812 : point_vec[0] = p; 102 : 103 40812 : _subproblem.setCurrentSubdomainID(elem, 0); 104 40812 : _subproblem.reinitElemPhys(elem, point_vec, 0); // Zero is for tid 105 : 106 85799 : for (MooseIndex(_coupled_moose_vars) j = 0; j < _coupled_moose_vars.size(); ++j) 107 89974 : values[j] = (dynamic_cast<MooseVariableField<Real> *>(_coupled_moose_vars[j]))->sln()[0] * 108 44987 : _pp_value; // The zero is for the "qp" 109 : 110 40812 : _found_points[i] = true; 111 : } 112 : } 113 : } 114 3855 : } 115 : 116 : void 117 88 : PointVariableSamplerBase::setPointsVector(const std::vector<Point> & points) 118 : { 119 88 : _points = points; 120 88 : } 121 : 122 : void 123 88 : PointVariableSamplerBase::transferPointsVector(std::vector<Point> && points) 124 : { 125 88 : _points = std::move(points); 126 88 : }