LCOV - code coverage report
Current view: top level - src/actions - CopyNodalVarsAction.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 22 23 95.7 %
Date: 2025-07-17 01:28:37 Functions: 3 3 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             : // MOOSE includes
      11             : #include "CopyNodalVarsAction.h"
      12             : 
      13             : #include "ActionWarehouse.h"
      14             : #include "AuxiliarySystem.h"
      15             : #include "FEProblem.h"
      16             : #include "MooseApp.h"
      17             : #include "NonlinearSystemBase.h"
      18             : 
      19             : #include <map>
      20             : 
      21             : registerMooseAction("MooseApp", CopyNodalVarsAction, "check_copy_nodal_vars");
      22             : 
      23             : registerMooseAction("MooseApp", CopyNodalVarsAction, "copy_nodal_vars");
      24             : 
      25             : registerMooseAction("MooseApp", CopyNodalVarsAction, "copy_nodal_aux_vars");
      26             : 
      27             : InputParameters
      28     1341750 : CopyNodalVarsAction::validParams()
      29             : {
      30     1341750 :   InputParameters params = Action::validParams();
      31     1341750 :   params.addClassDescription("Copies variable information from a file.");
      32     1341750 :   params.addParam<std::string>(
      33             :       "initial_from_file_timestep",
      34             :       "LATEST",
      35             :       "Gives the timestep (or \"LATEST\") for which to read a solution from a file "
      36             :       "for a given variable. (Default: LATEST)");
      37     1341750 :   params.addParam<std::string>(
      38             :       "initial_from_file_var",
      39             :       "Gives the name of a variable for which to read an initial condition from a mesh file");
      40             : 
      41     1341750 :   params.addParamNamesToGroup("initial_from_file_timestep initial_from_file_var",
      42             :                               "Initial From File");
      43             : 
      44     1341750 :   return params;
      45           0 : }
      46             : 
      47      272210 : CopyNodalVarsAction::CopyNodalVarsAction(const InputParameters & params) : Action(params) {}
      48             : 
      49             : void
      50      353797 : CopyNodalVarsAction::act()
      51             : {
      52             : 
      53      353797 :   if (isParamValid("initial_from_file_var"))
      54             :   {
      55         802 :     if (_current_task == "check_copy_nodal_vars")
      56         407 :       _app.setExodusFileRestart(true);
      57             :     else
      58             :     {
      59             :       SystemBase * system;
      60             :       // Is this a NonlinearSystem variable or an AuxiliarySystem variable?
      61         395 :       if (_current_task == "copy_nodal_vars")
      62             :       {
      63             :         // This iterates through each nonlinear system and finds which one the current variable
      64             :         // needs to be copied to
      65         211 :         system = &_problem->getSolverSystem(/*sys_num=*/0);
      66         446 :         for (unsigned int i = 0; i < _problem->numSolverSystems(); i++)
      67         235 :           if (_problem->getSolverSystem(i).hasVariable(name()))
      68         175 :             system = &_problem->getSolverSystem(i);
      69             :       }
      70             :       else
      71         184 :         system = &_problem->getAuxiliarySystem();
      72             : 
      73         395 :       system->addVariableToCopy(name(),
      74         790 :                                 getParam<std::string>("initial_from_file_var"),
      75         790 :                                 getParam<std::string>("initial_from_file_timestep"));
      76             :     }
      77             :   }
      78      353797 : }

Generated by: LCOV version 1.14