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 "SideValueSampler.h" 11 : 12 : // MOOSE includes 13 : #include "MooseVariableFE.h" 14 : 15 : #include "libmesh/quadrature.h" 16 : 17 : registerMooseObject("MooseApp", SideValueSampler); 18 : 19 : InputParameters 20 14479 : SideValueSampler::validParams() 21 : { 22 14479 : InputParameters params = SideVectorPostprocessor::validParams(); 23 14479 : params += SamplerBase::validParams(); 24 28958 : params.addClassDescription("Sample variable(s) along a sideset, internal or external."); 25 43437 : params.addRequiredCoupledVar( 26 : "variable", "The names of the variables that this VectorPostprocessor operates on"); 27 : 28 14479 : return params; 29 0 : } 30 : 31 110 : SideValueSampler::SideValueSampler(const InputParameters & parameters) 32 : : SideVectorPostprocessor(parameters), 33 : SamplerBase(parameters, this, _communicator), 34 110 : _qp_sampling(true) 35 : { 36 110 : std::vector<std::string> var_names(_coupled_moose_vars.size()); 37 110 : _values.resize(_coupled_moose_vars.size()); 38 : 39 274 : for (unsigned int i = 0; i < _coupled_moose_vars.size(); i++) 40 : { 41 164 : var_names[i] = _coupled_moose_vars[i]->name(); 42 492 : SamplerBase::checkForStandardFieldVariableType(_coupled_moose_vars[i]); 43 : } 44 : 45 110 : if (!_coupled_fv_moose_vars.empty()) 46 : { 47 26 : const auto num_fv_vars = _coupled_fv_moose_vars.size(); 48 26 : if (num_fv_vars != _coupled_moose_vars.size()) 49 0 : paramError( 50 : "variable", 51 : "This object cannot accept mixed FE and FV variables, please make " 52 : "sure all the provided variables are either FE or FV by separating this vector " 53 : "postprocessor " 54 : "into two blocks, one for finite element and another for finite volume variables!"); 55 : 56 26 : _qp_sampling = false; 57 : } 58 : 59 : // Initialize the data structures in SamplerBase 60 110 : SamplerBase::setupVariables(var_names); 61 110 : } 62 : 63 : void 64 102 : SideValueSampler::initialize() 65 : { 66 102 : SamplerBase::initialize(); 67 102 : } 68 : 69 : void 70 29016 : SideValueSampler::execute() 71 : { 72 29016 : if (_qp_sampling) 73 57924 : for (unsigned int _qp = 0; _qp < _qrule->n_points(); _qp++) 74 : { 75 58248 : for (unsigned int i = 0; i < _coupled_moose_vars.size(); i++) 76 29232 : _values[i] = (dynamic_cast<MooseVariable *>(_coupled_moose_vars[i]))->sln()[_qp]; 77 : 78 29016 : SamplerBase::addSample(_q_point[_qp], _current_elem->id(), _values); 79 : } 80 : else 81 : { 82 108 : getFaceInfos(); 83 : 84 108 : const auto state = determineState(); 85 : 86 216 : for (const auto & fi : _face_infos) 87 : { 88 324 : for (unsigned int i = 0; i < _coupled_fv_moose_vars.size(); i++) 89 : { 90 : mooseAssert(_coupled_fv_moose_vars[i]->hasFaceSide(*fi, true) || 91 : _coupled_fv_moose_vars[i]->hasFaceSide(*fi, false), 92 : "Variable " + _coupled_fv_moose_vars[i]->name() + 93 : " should be defined on one side of the face!"); 94 : 95 : const auto * elem = 96 216 : _coupled_fv_moose_vars[i]->hasFaceSide(*fi, true) ? fi->elemPtr() : fi->neighborPtr(); 97 : 98 216 : const auto face_arg = Moose::FaceArg( 99 216 : {fi, Moose::FV::LimiterType::CentralDifference, true, false, elem, nullptr}); 100 216 : _values[i] = MetaPhysicL::raw_value((*_coupled_fv_moose_vars[i])(face_arg, state)); 101 : } 102 : 103 108 : SamplerBase::addSample(fi->faceCentroid(), _current_elem->id(), _values); 104 : } 105 : } 106 29016 : } 107 : 108 : void 109 96 : SideValueSampler::finalize() 110 : { 111 96 : SamplerBase::finalize(); 112 96 : } 113 : 114 : void 115 6 : SideValueSampler::threadJoin(const UserObject & y) 116 : { 117 6 : const auto & vpp = static_cast<const SideValueSampler &>(y); 118 : 119 6 : SamplerBase::threadJoin(vpp); 120 6 : }