LCOV - code coverage report
Current view: top level - src/postprocessors - SolutionChangeNormFixedPoint.C (source / functions) Hit Total Coverage
Test: coverage.info Lines: 31 31 100.0 %
Date: 2026-04-22 20:21:53 Functions: 6 6 100.0 %

          Line data    Source code
       1             : //* This file is part of the RACCOON application
       2             : //* being developed at Dolbow lab at Duke University
       3             : //* http://dolbow.pratt.duke.edu
       4             : 
       5             : #include "SolutionChangeNormFixedPoint.h"
       6             : #include "Moose.h"
       7             : #include "MooseVariableFE.h"
       8             : 
       9             : registerMooseObject("raccoonApp", SolutionChangeNormFixedPoint);
      10             : 
      11             : InputParameters
      12         138 : SolutionChangeNormFixedPoint::validParams()
      13             : {
      14         138 :   InputParameters params = ElementIntegralPostprocessor::validParams();
      15         138 :   params.addClassDescription(
      16             :       "Computes the L2 norm of the change in a variable between consecutive fixed-point "
      17             :       "(Picard) iterations: ||d^(k+1) - d^(k)||_2. Intended for use as a staggered-scheme "
      18             :       "convergence criterion via PostprocessorConvergence.");
      19         276 :   params.addRequiredCoupledVar("variable", "The variable to monitor for fixed-point convergence");
      20             :   // Default to running at the fixed-point convergence check, after each sub-app solve and
      21             :   // damage transfer, but before the convergence decision is made.
      22         414 :   params.set<ExecFlagEnum>("execute_on") = {EXEC_MULTIAPP_FIXED_POINT_CONVERGENCE};
      23         138 :   return params;
      24         138 : }
      25             : 
      26           1 : SolutionChangeNormFixedPoint::SolutionChangeNormFixedPoint(const InputParameters & parameters)
      27             :   : ElementIntegralPostprocessor(parameters),
      28             :     MooseVariableInterface<Real>(this,
      29             :                                  false,
      30             :                                  "variable",
      31             :                                  Moose::VarKindType::VAR_ANY,
      32             :                                  Moose::VarFieldType::VAR_FIELD_STANDARD),
      33           2 :     _fp_var(mooseVariable())
      34             : {
      35           1 : }
      36             : 
      37             : void
      38           4 : SolutionChangeNormFixedPoint::initialize()
      39             : {
      40           4 :   ElementIntegralPostprocessor::initialize();
      41             : 
      42           4 :   auto & sys = _fp_var->sys();
      43             : 
      44             :   // solutionState(0) is the current solution, updated by the MultiAppCopyTransfer to d^(k).
      45           4 :   sys.solutionState(0).localize(_current_local);
      46             : 
      47             :   // solutionState(1, FixedPoint) is the PREVIOUS_FP_SOLUTION_TAG vector — d^(k-1), copied
      48             :   // there by SystemBase::copyPreviousFixedPointSolutions() before the current solve began.
      49           4 :   sys.solutionState(1, Moose::SolutionIterationType::FixedPoint).localize(_fp_old_local);
      50           4 : }
      51             : 
      52             : Real // Compute (d^k-d^(k-1))^2
      53          64 : SolutionChangeNormFixedPoint::computeQpIntegral()
      54             : {
      55             :   // Interpolate the previous fixed-point solution at the current quadrature point.
      56             :   // dofIndices() and phi() are populated for the current element during reinit().
      57          64 :   const auto & dof_indices = _fp_var->dofIndices();
      58          64 :   const auto & phi = _fp_var->phi();
      59             : 
      60             :   Real u_curr = 0.0, u_fp_old = 0.0;
      61         320 :   for (unsigned int i = 0; i < dof_indices.size(); ++i)
      62             :   {
      63         256 :     u_curr += _current_local[dof_indices[i]] * phi[i][_qp];
      64         256 :     u_fp_old += _fp_old_local[dof_indices[i]] * phi[i][_qp];
      65             :   }
      66             : 
      67          64 :   const Real diff = u_curr - u_fp_old;
      68          64 :   return diff * diff;
      69             : }
      70             : 
      71             : Real // Integrate
      72           4 : SolutionChangeNormFixedPoint::getValue() const
      73             : {
      74           4 :   return std::sqrt(ElementIntegralPostprocessor::getValue());
      75             : }
      76             : 
      77             : void
      78           4 : SolutionChangeNormFixedPoint::finalize()
      79             : {
      80           4 :   ElementIntegralPostprocessor::finalize();
      81           4 :   if (processor_id() == 0)
      82           4 :     Moose::out << "  " << name() << " = " << std::sqrt(_integral_value) << "\n";
      83           4 : }

Generated by: LCOV version 1.16