LCOV - code coverage report
Current view: top level - include/base - SolutionHandle.h (source / functions) Hit Total Coverage
Test: idaholab/moose subchannel: #31730 (e8b711) with base e0c998 Lines: 17 17 100.0 %
Date: 2025-10-29 16:55:46 Functions: 5 5 100.0 %
Legend: Lines: hit not hit

          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        5604 :   SolutionHandle(const MooseVariableFieldBase & variable)
      25        5604 :     : _var(const_cast<MooseVariableFieldBase &>(variable)),
      26        5604 :       _soln(_var.sys().solution()),
      27        5604 :       _soln_old(_var.sys().solutionOld())
      28             :   {
      29        5604 :   }
      30             : 
      31             :   /**
      32             :    * Get a value from the solution vector.
      33             :    */
      34  2308886198 :   Number operator()(const Node * node) const
      35             :   {
      36             :     // The 0 assumes linear Lagrange (I think)
      37  2308886198 :     dof_id_type dof = node->dof_number(_var.sys().number(), _var.number(), 0);
      38  2308886198 :     return _soln(dof);
      39             :   }
      40             :   /**
      41             :    * Get a value from the old solution vector.
      42             :    */
      43    72524388 :   Number old(const Node * node) const
      44             :   {
      45             :     // The 0 assumes linear Lagrange (I think)
      46    72524388 :     dof_id_type dof = node->dof_number(_var.sys().number(), _var.number(), 0);
      47    72524388 :     return _soln_old(dof);
      48             :   }
      49             :   /**
      50             :    * Set a value in the solution vector.
      51             :    */
      52    88239540 :   void set(const Node * node, Number val)
      53             :   {
      54    88239540 :     dof_id_type dof = node->dof_number(_var.sys().number(), _var.number(), 0);
      55    88239540 :     _soln.set(dof, val);
      56    88239540 :   }
      57             : 
      58       13478 :   Real L2norm() const
      59             :   {
      60       13478 :     return _var.sys().system().calculate_norm(_soln, _var.number(), DISCRETE_L2);
      61             :   }
      62             : 
      63             :   void close() { _soln.close(); }
      64             : 
      65             : private:
      66             :   MooseVariableFieldBase & _var;
      67             :   NumericVector<Number> & _soln;
      68             :   const NumericVector<Number> & _soln_old;
      69             : };

Generated by: LCOV version 1.14