https://mooseframework.inl.gov
Loading...
Searching...
No Matches
SolutionHandle.h
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#pragma once
11
12#include "SystemBase.h"
14#include "MooseMesh.h"
15#include "libmesh/system.h"
16#include "libmesh/enum_norm_type.h"
17#include "libmesh/petsc_vector.h"
18
23{
24public:
26 : _var(const_cast<MooseVariableFieldBase &>(variable)),
27 _soln(_var.sys().solution()),
28 _soln_old(_var.sys().solutionOld())
29 {
30 }
31
35 Number operator()(const Node * node) const
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 }
47 Number interpolate(const Node * node_in, const Node * node_out, Real weight) const;
51 Number old(const Node * node) const
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 }
60 void set(const Node * node, Number val)
61 {
62 dof_id_type dof = node->dof_number(_var.sys().number(), _var.number(), 0);
63 _soln.set(dof, val);
64 }
65
66 Real L2norm() const
67 {
68 return _var.sys().system().calculate_norm(_soln, _var.number(), DISCRETE_L2);
69 }
70
71 void close() { _soln.close(); }
72
73private:
75 NumericVector<Number> & _soln;
76 const NumericVector<Number> & _soln_old;
77};
78
79inline Number
80SolutionHandle::interpolate(const Node * node_in, const Node * node_out, Real weight) const
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)
SystemBase & sys()
unsigned int number() const
Provide a simple RAII interface for linear lagrange solution variables.
MooseVariableFieldBase & _var
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...
Real L2norm() const
Number old(const Node *node) const
Get a value from the old solution vector.
Number operator()(const Node *node) const
Get a value from the solution vector.
SolutionHandle(const MooseVariableFieldBase &variable)
NumericVector< Number > & _soln
void set(const Node *node, Number val)
Set a value in the solution vector.
const NumericVector< Number > & _soln_old
unsigned int number() const
MooseMesh & mesh()
virtual libMesh::System & system()=0
virtual void set(const numeric_index_type i, const T value)=0
virtual void close()=0
Number point_value(unsigned int var, const Point &p, const bool insist_on_success=true, const NumericVector< Number > *sol=nullptr) const
Real calculate_norm(const NumericVector< Number > &v, unsigned int var, FEMNormType norm_type, std::set< unsigned int > *skip_dimensions=nullptr) const
MeshBase & mesh
const unsigned int invalid_uint