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 11073 : PointVariableSamplerBase::validParams() 20 : { 21 11073 : InputParameters params = GeneralVectorPostprocessor::validParams(); 22 : 23 11073 : params += SamplerBase::validParams(); 24 : 25 44292 : params.addRequiredCoupledVar( 26 : "variable", "The names of the variables that this VectorPostprocessor operates on"); 27 33219 : params.addParam<PostprocessorName>( 28 22146 : "scaling", 1.0, "The postprocessor that the variables are multiplied with"); 29 22146 : params.addParam<bool>( 30 : "warn_discontinuous_face_values", 31 22146 : true, 32 : "Whether to return a warning if a discontinuous variable is sampled on a face"); 33 : 34 11073 : return params; 35 0 : } 36 : 37 905 : 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 : Moose::VarFieldType::VAR_FIELD_STANDARD), 45 3620 : _var_slns(_coupled_moose_vars.size(), nullptr) 46 : { 47 905 : addMooseVariableDependency(&mooseVariableField()); 48 : 49 905 : std::vector<std::string> var_names(_coupled_moose_vars.size()); 50 : 51 2191 : for (const auto i : index_range(_coupled_moose_vars)) 52 : { 53 1286 : const auto * const var = _coupled_moose_vars[i]; 54 1286 : var_names[i] = var->name(); 55 2572 : SamplerBase::checkForStandardFieldVariableType(var); 56 1286 : _var_slns[i] = &libMesh::cast_ptr<const MooseVariableField<Real> *>(var)->sln(); 57 : } 58 : 59 : // Initialize the data structures in SamplerBase 60 905 : SamplerBase::setupVariables(var_names); 61 905 : } 62 : 63 : void 64 4008 : PointVariableSamplerBase::initialize() 65 : { 66 4008 : PointSamplerBase::initialize(); 67 : 68 : // Check for elemental variables, which are ill-defined on faces for this object 69 8608 : for (const auto * const var : _coupled_moose_vars) 70 : { 71 4600 : const auto continuity = _assembly.getFE(var->feType(), _mesh.dimension())->get_continuity(); 72 4600 : if (continuity != libMesh::C_ZERO && continuity != libMesh::C_ONE) 73 595 : _discontinuous_at_faces = true; 74 : } 75 4008 : } 76 : 77 : void 78 4008 : PointVariableSamplerBase::execute() 79 : { 80 4008 : BoundingBox bbox = _mesh.getInflatedProcessorBoundingBox(); 81 : 82 : /// So we don't have to create and destroy this 83 4008 : std::vector<Point> point_vec(1); 84 : 85 76705 : for (MooseIndex(_points) i = 0; i < _points.size(); ++i) 86 : { 87 72697 : Point & p = _points[i]; 88 : 89 : // Do a bounding box check so we're not doing unnecessary PointLocator lookups 90 : // In the discontinuous case all ranks must proceed to get a global consensus 91 : // on who owns face points in getLocalElemContainingPoint() 92 72697 : if (bbox.contains_point(p) || _discontinuous_at_faces) 93 : { 94 58176 : auto & values = _point_values[i]; 95 : 96 58176 : if (values.empty()) 97 58176 : values.resize(_coupled_moose_vars.size()); 98 : 99 : // First find the element the hit lands in 100 58176 : const Elem * elem = getLocalElemContainingPoint(p); 101 : 102 58176 : if (elem) 103 : { 104 : // We have to pass a vector of points into reinitElemPhys 105 51471 : point_vec[0] = p; 106 : 107 51471 : _subproblem.setCurrentSubdomainID(elem, 0); 108 51471 : _subproblem.reinitElemPhys(elem, point_vec, 0); // Zero is for tid 109 : 110 107695 : for (const auto j : index_range(_coupled_moose_vars)) 111 56224 : values[j] = (*_var_slns[j])[0] * _pp_value; // The zero is for the "qp" 112 : 113 51471 : _found_points[i] = true; 114 : } 115 : } 116 : } 117 4008 : } 118 : 119 : void 120 89 : PointVariableSamplerBase::setPointsVector(const std::vector<Point> & points) 121 : { 122 89 : _points = points; 123 89 : } 124 : 125 : void 126 89 : PointVariableSamplerBase::transferPointsVector(std::vector<Point> && points) 127 : { 128 89 : _points = std::move(points); 129 89 : }