https://mooseframework.inl.gov
Loading...
Searching...
No Matches
MassFreeConstraint.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 "MassFreeConstraint.h"
11#include "Assembly.h"
12#include "SystemBase.h"
13#include "MooseVariable.h"
14
15registerMooseObject("ThermalHydraulicsApp", MassFreeConstraint);
16
19{
21 params.addRequiredParam<std::vector<Real>>("normals", "node normals");
22 params.addRequiredParam<std::vector<dof_id_type>>("nodes", "node IDs");
23 params.addRequiredCoupledVar("rhouA", "Momentum");
25 "Constrains the momentum at the user-specified nodes along the user-specified normals");
26 return params;
27}
28
30 : NodalConstraint(parameters),
31 _normals(getParam<std::vector<Real>>("normals")),
32 _rhouA(coupledValue("rhouA")),
33 _rhouA_var_number(coupled("rhouA"))
34{
35 _primary_node_vector = getParam<std::vector<dof_id_type>>("nodes");
36 // just a dummy value that is never used
37 _connected_nodes.push_back(*_primary_node_vector.begin());
38}
39
40void
41MassFreeConstraint::computeResidual(const NumericVector<Number> & /*residual*/)
42{
43 const auto & dofs = _var.dofIndices();
44 std::vector<Number> re(dofs.size());
45
46 for (unsigned int i = 0; i < dofs.size(); i++)
47 re[i] = _rhouA[i] * _normals[i];
48
50}
51
52Real
57
58void
59MassFreeConstraint::computeJacobian(const SparseMatrix<Number> & /*jacobian*/)
60{
61 const auto & dofs = _var.dofIndices();
62
63 // off-diag
64 {
66 auto && dofs_rhouA = var_rhouA.dofIndices();
67 DenseMatrix<Number> Kee(dofs.size(), dofs_rhouA.size());
68
69 Kee.zero();
70 for (unsigned int i = 0; i < dofs.size(); i++)
71 Kee(i, i) = _normals[i];
72 addJacobian(_assembly, Kee, dofs, dofs_rhouA, _var.scalingFactor());
73 }
74}
75
76Real
registerMooseObject("ThermalHydraulicsApp", MassFreeConstraint)
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
Free BC for the mass equation.
virtual void computeResidual() override final
MassFreeConstraint(const InputParameters &parameters)
unsigned int _rhouA_var_number
virtual Real computeQpResidual(Moose::ConstraintType type) override
virtual Real computeQpJacobian(Moose::ConstraintJacobianType type) override
const VariableValue & _rhouA
virtual void computeJacobian() override final
static InputParameters validParams()
std::vector< Real > _normals
void scalingFactor(const std::vector< Real > &factor)
const std::vector< dof_id_type > & dofIndices() const final
std::vector< dof_id_type > _primary_node_vector
std::vector< dof_id_type > _connected_nodes
static InputParameters validParams()
MooseVariable & _var
THREAD_ID _tid
Assembly & _assembly
SystemBase & _sys
MooseVariableFE< T > & getFieldVariable(THREAD_ID tid, const std::string &var_name)
void addJacobian(Assembly &assembly, const Residuals &residuals, const Indices &dof_indices, Real scaling_factor)
void addResiduals(Assembly &assembly, const Residuals &residuals, const Indices &dof_indices, Real scaling_factor)
ConstraintType
ConstraintJacobianType