https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
SolutionHandle Class Reference

Provide a simple RAII interface for linear lagrange solution variables. More...

#include <SolutionHandle.h>

Public Member Functions

 SolutionHandle (const MooseVariableFieldBase &variable)
 
Number operator() (const Node *node) const
 Get a value from the solution vector.
 
Number interpolate (const Node *node_in, const Node *node_out, Real weight) const
 Get the value at the fraction weight of the way from node_in to node_out, two nodes of the same axial element, by linear interpolation between the values of the variable at the two nodes on that element.
 
Number old (const Node *node) const
 Get a value from the old solution vector.
 
void set (const Node *node, Number val)
 Set a value in the solution vector.
 
Real L2norm () const
 
void close ()
 

Private Attributes

MooseVariableFieldBase & _var
 
NumericVector< Number > & _soln
 
const NumericVector< Number > & _soln_old
 

Detailed Description

Provide a simple RAII interface for linear lagrange solution variables.

Definition at line 22 of file SolutionHandle.h.

Constructor & Destructor Documentation

◆ SolutionHandle()

SolutionHandle::SolutionHandle ( const MooseVariableFieldBase &  variable)
inline

Definition at line 25 of file SolutionHandle.h.

26 : _var(const_cast<MooseVariableFieldBase &>(variable)),
29 {
30 }
SystemBase & sys()
MooseVariableFieldBase & _var
NumericVector< Number > & _soln
const NumericVector< Number > & _soln_old
NumericVector< Number > & solutionOld()
NumericVector< Number > & solution()

Member Function Documentation

◆ close()

void SolutionHandle::close ( )
inline

Definition at line 71 of file SolutionHandle.h.

71{ _soln.close(); }
virtual void close()=0

◆ interpolate()

Number SolutionHandle::interpolate ( const Node *  node_in,
const Node *  node_out,
Real  weight 
) const
inline

Get the value at the fraction weight of the way from node_in to node_out, two nodes of the same axial element, by linear interpolation between the values of the variable at the two nodes on that element.

This works for any variable type: an elemental variable has the same value at both nodes. Only valid on the processor that holds the solution.

Definition at line 80 of file SolutionHandle.h.

81{
82 auto & mesh = _var.sys().mesh();
83 for (const auto elem_id : libmesh_map_find(mesh.nodeToElemMap(), node_in->id()))
84 {
85 const auto & elem = *mesh.elemPtr(elem_id);
86 if (elem.get_node_index(node_out) == libMesh::invalid_uint)
87 continue;
88 const auto & system = _var.sys().system();
89 const auto value_in = system.point_value(_var.number(), *node_in, elem, &_soln);
90 const auto value_out = system.point_value(_var.number(), *node_out, elem, &_soln);
91 // This form returns the nodal value exactly at weight 0 and 1
92 return (1 - weight) * value_in + weight * value_out;
93 }
94 mooseError("Nodes ", node_in->id(), " and ", node_out->id(), " do not share an element.");
95}
void mooseError(Args &&... args)
unsigned int number() const
MooseMesh & mesh()
virtual libMesh::System & system()=0
Number point_value(unsigned int var, const Point &p, const bool insist_on_success=true, const NumericVector< Number > *sol=nullptr) const
MeshBase & mesh
dof_id_type weight(const MeshBase &mesh, const processor_id_type pid)
const unsigned int invalid_uint

◆ L2norm()

Real SolutionHandle::L2norm ( ) const
inline

Definition at line 66 of file SolutionHandle.h.

67 {
68 return _var.sys().system().calculate_norm(_soln, _var.number(), DISCRETE_L2);
69 }
Real calculate_norm(const NumericVector< Number > &v, unsigned int var, FEMNormType norm_type, std::set< unsigned int > *skip_dimensions=nullptr) const

◆ old()

Number SolutionHandle::old ( const Node *  node) const
inline

Get a value from the old solution vector.

Definition at line 51 of file SolutionHandle.h.

52 {
53 // The 0 assumes linear Lagrange (I think)
54 dof_id_type dof = node->dof_number(_var.sys().number(), _var.number(), 0);
55 return _soln_old(dof);
56 }
unsigned int number() const
uint8_t dof_id_type

◆ operator()()

Number SolutionHandle::operator() ( const Node *  node) const
inline

Get a value from the solution vector.

Definition at line 35 of file SolutionHandle.h.

36 {
37 // The 0 assumes linear Lagrange (I think)
38 dof_id_type dof = node->dof_number(_var.sys().number(), _var.number(), 0);
39 return _soln(dof);
40 }

◆ set()

void SolutionHandle::set ( const Node *  node,
Number  val 
)
inline

Set a value in the solution vector.

Definition at line 60 of file SolutionHandle.h.

61 {
62 dof_id_type dof = node->dof_number(_var.sys().number(), _var.number(), 0);
63 _soln.set(dof, val);
64 }
virtual void set(const numeric_index_type i, const T value)=0

Member Data Documentation

◆ _soln

NumericVector<Number>& SolutionHandle::_soln
private

Definition at line 75 of file SolutionHandle.h.

Referenced by close(), interpolate(), L2norm(), operator()(), and set().

◆ _soln_old

const NumericVector<Number>& SolutionHandle::_soln_old
private

Definition at line 76 of file SolutionHandle.h.

Referenced by old().

◆ _var

MooseVariableFieldBase& SolutionHandle::_var
private

Definition at line 74 of file SolutionHandle.h.

Referenced by interpolate(), L2norm(), old(), operator()(), and set().


The documentation for this class was generated from the following file: