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 : #pragma once 11 : 12 : #include "SystemBase.h" 13 : #include "MooseVariableFieldBase.h" 14 : #include "libmesh/system.h" 15 : #include "libmesh/enum_norm_type.h" 16 : #include "libmesh/petsc_vector.h" 17 : 18 : /** 19 : * Provide a simple RAII interface for linear lagrange solution variables. 20 : */ 21 : class SolutionHandle 22 : { 23 : public: 24 4004 : SolutionHandle(const MooseVariableFieldBase & variable) 25 4004 : : _var(const_cast<MooseVariableFieldBase &>(variable)), 26 4004 : _soln(_var.sys().solution()), 27 4004 : _soln_old(_var.sys().solutionOld()) 28 : { 29 4004 : } 30 : 31 : /** 32 : * Get a value from the solution vector. 33 : */ 34 2450889776 : Number operator()(const Node * node) const 35 : { 36 : // The 0 assumes linear Lagrange (I think) 37 2450889776 : dof_id_type dof = node->dof_number(_var.sys().number(), _var.number(), 0); 38 2450889776 : return _soln(dof); 39 : } 40 : /** 41 : * Get a value from the old solution vector. 42 : */ 43 78219984 : Number old(const Node * node) const 44 : { 45 : // The 0 assumes linear Lagrange (I think) 46 78219984 : dof_id_type dof = node->dof_number(_var.sys().number(), _var.number(), 0); 47 78219984 : return _soln_old(dof); 48 : } 49 : /** 50 : * Set a value in the solution vector. 51 : */ 52 95927106 : void set(const Node * node, Number val) 53 : { 54 95927106 : dof_id_type dof = node->dof_number(_var.sys().number(), _var.number(), 0); 55 95927106 : _soln.set(dof, val); 56 95927106 : } 57 : 58 10752 : Real L2norm() const 59 : { 60 10752 : return _var.sys().system().calculate_norm(_soln, _var.number(), DISCRETE_L2); 61 : } 62 : 63 54 : void close() { _soln.close(); } 64 : 65 : private: 66 : MooseVariableFieldBase & _var; 67 : NumericVector<Number> & _soln; 68 : const NumericVector<Number> & _soln_old; 69 : };