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 "FVPointValueConstraint.h" 11 : 12 : #include "MooseVariableScalar.h" 13 : #include "MooseVariableFV.h" 14 : #include "Assembly.h" 15 : 16 : registerMooseObject("MooseApp", FVPointValueConstraint); 17 : 18 : InputParameters 19 14290 : FVPointValueConstraint::validParams() 20 : { 21 14290 : InputParameters params = FVScalarLagrangeMultiplierConstraint::validParams(); 22 14290 : params.addClassDescription("This class is used to enforce integral of phi = volume * phi_0 " 23 : "with a Lagrange multiplier approach."); 24 14290 : params.setDocString("phi0", "What we want the point value of the primal variable to be."); 25 14290 : params.addRequiredParam<Point>( 26 : "point", "The XYZ coordinates of the points where the value shall be enforced."); 27 14290 : return params; 28 0 : } 29 : 30 13 : FVPointValueConstraint::FVPointValueConstraint(const InputParameters & parameters) 31 : : FVScalarLagrangeMultiplierConstraint(parameters), 32 13 : _point(getParam<Point>("point")), 33 26 : _my_elem(nullptr) 34 : { 35 13 : setMyElem(); 36 13 : } 37 : 38 : void 39 13 : FVPointValueConstraint::setMyElem() 40 : { 41 : // Find the element containing the point 42 13 : _point_locator = libMesh::PointLocatorBase::build(libMesh::TREE_LOCAL_ELEMENTS, _mesh); 43 13 : _point_locator->enable_out_of_mesh_mode(); 44 : 45 : // We only check in the restricted blocks, if needed 46 : const Elem * elem = 47 13 : blockRestricted() ? (*_point_locator)(_point, &blockIDs()) : (*_point_locator)(_point); 48 : 49 : // We communicate the results and if there is conflict between processes, 50 : // the minimum cell ID is chosen 51 13 : const dof_id_type elem_id = elem ? elem->id() : libMesh::DofObject::invalid_id; 52 13 : dof_id_type min_elem_id = elem_id; 53 13 : _mesh.comm().min(min_elem_id); 54 : 55 13 : if (min_elem_id == libMesh::DofObject::invalid_id) 56 0 : mooseError("The specified point for the FVPointValueConstraint is not in the " 57 : "domain! Try alleviating block restrictions or " 58 : "using another point!"); 59 : 60 13 : _my_elem = min_elem_id == elem_id ? elem : nullptr; 61 13 : } 62 : 63 : ADReal 64 308 : FVPointValueConstraint::computeQpResidual() 65 : { 66 308 : if (_current_elem == _my_elem) 67 154 : return _var(makeElemArg(_current_elem), determineState()) - _phi0; 68 : else 69 231 : return 0; 70 : }