https://mooseframework.inl.gov
Loading...
Searching...
No Matches
NSPressurePin.C
Go to the documentation of this file.
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 "NSPressurePin.h"
11#include "SubProblem.h"
12#include "SystemBase.h"
13#include "NS.h"
14
15#include "libmesh/mesh_base.h"
16#include "libmesh/elem_range.h"
17#include "libmesh/numeric_vector.h"
18#include "libmesh/mesh_tools.h"
19
21registerMooseObjectRenamed("NavierStokesApp", NSFVPressurePin, "01/19/2025 00:00", NSPressurePin);
22
25{
26 auto params = GeneralUserObject::validParams();
28
29 // Not much flexibility there, applying the pin at the wrong time prevents convergence
30 ExecFlagEnum & exec_enum = params.set<ExecFlagEnum>("execute_on", true);
31 // all bad choices
33 exec_enum = {EXEC_TIMESTEP_END};
34
35 // Avoid uninitialized residual objects
36 params.suppressParameter<bool>("force_preic");
37
38 params.addParam<NonlinearVariableName>("variable", NS::pressure, "Pressure variable");
39 params.addParam<PostprocessorName>("phi0", "0", "Pressure pin value");
40 MooseEnum pin_types("point-value average");
41 params.addRequiredParam<MooseEnum>("pin_type", pin_types, "How to pin the pressure");
42 params.addParam<Point>(
43 "point",
44 "The XYZ coordinates of a point inside an element where the pinned value shall be enforced.");
45 params.addParam<PostprocessorName>(
46 "pressure_average", "A postprocessor that computes the average of the pressure variable");
47
48 params.addClassDescription("Pins the pressure after a solve");
49 params.registerBase("Corrector");
50
51 return params;
52}
53
55 : GeneralUserObject(params),
58 _mesh(UserObject::_subproblem.mesh().getMesh()),
59 _p(UserObject::_subproblem.getVariable(0, getParam<NonlinearVariableName>("variable"))),
60 _p0(getPostprocessorValue("phi0")),
61 _pressure_pin_type(getParam<MooseEnum>("pin_type")),
62 _pressure_pin_point(_pressure_pin_type == "point-value" ? getParam<Point>("point")
63 : Point(0, 0, 0)),
64 _current_pressure_average(
65 _pressure_pin_type == "average" ? &getPostprocessorValue("pressure_average") : nullptr)
66{
67}
68
69void
71{
72 mooseAssert(!Threads::in_threads, "paramError is not safe in threaded mode");
73
74 // Check execute_on of the postprocessor
75 if (_pressure_pin_type == "average" &&
76 !_fe_problem.getUserObjectBase(getParam<PostprocessorName>("pressure_average"))
79 paramError("pressure_average",
80 "Pressure average postprocessor must include the pin execute_on flags");
81}
82
83void
85{
86 // Get the value of the pin
87 Real pin_value = 0;
88 if (_pressure_pin_type == "point-value")
89 {
90 Real point_value = _sys.system().point_value(_p.number(), _pressure_pin_point, false);
91
96 if (MooseUtils::absoluteFuzzyEqual(point_value, 0.0))
97 {
98 auto pl = _mesh.sub_point_locator();
99 pl->enable_out_of_mesh_mode();
100
101 auto * elem = (*pl)(_pressure_pin_point);
102 auto elem_id = elem ? elem->id() : DofObject::invalid_id;
103 gatherMin(elem_id);
104
105 if (elem_id == DofObject::invalid_id)
106 mooseError("No element to gather point pressure from located at ", _pressure_pin_point);
107 // Default at construction
108 pl->disable_out_of_mesh_mode();
109 }
110
111 pin_value = _p0 - point_value;
112 }
113 else
114 pin_value = _p0 - *_current_pressure_average;
115
116 // Offset the entire pressure vector by the value of the pin
117 NumericVector<Number> & sln = _sys.solution();
118 std::set<dof_id_type> local_dofs;
119 _sys.system().local_dof_indices(_p.number(), local_dofs);
120 for (const auto dof : local_dofs)
121 sln.add(dof, pin_value);
122 sln.close();
123 _sys.system().update();
124}
const ExecFlagType EXEC_TIMESTEP_END
const ExecFlagType EXEC_TIMESTEP_BEGIN
const ExecFlagType EXEC_LINEAR
const ExecFlagType EXEC_NONE
registerMooseObject("NavierStokesApp", NSPressurePin)
registerMooseObjectRenamed("NavierStokesApp", NSFVPressurePin, "01/19/2025 00:00", NSPressurePin)
static InputParameters validParams()
void removeAvailableFlags(const ExecFlagType &flag, Args... flags)
const UserObject & getUserObjectBase(const std::string &name, const THREAD_ID tid=0) const
static InputParameters validParams()
void paramError(const std::string &param, Args... args) const
void mooseError(Args &&... args) const
unsigned int number() const
bool isValueSet(const std::string &value) const
This user-object corrects the pressure.
NSPressurePin(const InputParameters &params)
const PostprocessorValue & _p0
Value of the pressure pin.
const Point _pressure_pin_point
If using point-value pressure pin, the point at which to apply the pin.
const PostprocessorValue *const _current_pressure_average
If using average pressure pin, provides the average pressure value.
MeshBase & _mesh
LibMesh mesh class for the current simulation mesh.
const MooseVariableFieldBase & _p
The thread 0 copy of the pressure variable.
const MooseEnum _pressure_pin_type
Pressure pin type.
virtual void initialSetup() override
static InputParameters validParams()
virtual void execute() override
const ExecFlagEnum & getExecuteOnEnum() const
NumericVector< Number > & solution()
virtual libMesh::System & system()=0
void gatherMin(T &value)
FEProblemBase & _fe_problem
SystemBase & _sys
Number point_value(unsigned int var, const Point &p, const bool insist_on_success=true, const NumericVector< Number > *sol=nullptr) const
void local_dof_indices(const unsigned int var, std::set< dof_id_type > &var_indices) const
virtual void update()
MeshBase & mesh
static const std::string pressure
Definition NS.h:57