LCOV - code coverage report
Current view: top level - src/actions - AddTimeIndependentReactionSolverAction.C (source / functions) Hit Total Coverage
Test: idaholab/moose geochemistry: 2bf808 Lines: 84 89 94.4 %
Date: 2025-07-17 01:29:12 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             : #include "AddTimeIndependentReactionSolverAction.h"
      11             : #include "Executioner.h"
      12             : #include "FEProblem.h"
      13             : 
      14             : registerMooseAction("GeochemistryApp", AddTimeIndependentReactionSolverAction, "setup_mesh");
      15             : registerMooseAction("GeochemistryApp", AddTimeIndependentReactionSolverAction, "init_mesh");
      16             : registerMooseAction("GeochemistryApp", AddTimeIndependentReactionSolverAction, "create_problem");
      17             : registerMooseAction("GeochemistryApp", AddTimeIndependentReactionSolverAction, "setup_executioner");
      18             : registerMooseAction("GeochemistryApp", AddTimeIndependentReactionSolverAction, "add_output");
      19             : registerMooseAction("GeochemistryApp", AddTimeIndependentReactionSolverAction, "add_user_object");
      20             : registerMooseAction("GeochemistryApp",
      21             :                     AddTimeIndependentReactionSolverAction,
      22             :                     "add_geochemistry_molality_aux");
      23             : registerMooseAction("GeochemistryApp",
      24             :                     AddTimeIndependentReactionSolverAction,
      25             :                     "add_geochemistry_reactor");
      26             : 
      27             : InputParameters
      28         278 : AddTimeIndependentReactionSolverAction::validParams()
      29             : {
      30         278 :   InputParameters params = AddGeochemistrySolverAction::validParams();
      31         278 :   params.set<ExecFlagEnum>("execute_console_output_on") = EXEC_FINAL;
      32         278 :   params.set<bool>("solver_info") = true;
      33         556 :   params.addParam<Real>("temperature", 25.0, "The temperature (degC) of the aqueous solution");
      34         278 :   params.addClassDescription(
      35             :       "Action that sets up a time-dependent equilibrium reaction solver.  This creates creates a "
      36             :       "time-dependent geochemistry solver, and adds AuxVariables corresonding to the molalities, "
      37             :       "etc");
      38             : 
      39         278 :   return params;
      40           0 : }
      41             : 
      42         278 : AddTimeIndependentReactionSolverAction::AddTimeIndependentReactionSolverAction(
      43         278 :     const InputParameters & params)
      44         278 :   : AddGeochemistrySolverAction(params)
      45             : {
      46         278 : }
      47             : 
      48             : void
      49        2224 : AddTimeIndependentReactionSolverAction::act()
      50             : {
      51             :   // create Output and Aux objects
      52        2224 :   AddGeochemistrySolverAction::act();
      53             : 
      54             :   // Set up an arbitrary mesh
      55        2224 :   if (_current_task == "setup_mesh")
      56             :   {
      57         278 :     const std::string class_name = "GeneratedMesh";
      58         278 :     InputParameters params = _factory.getValidParams(class_name);
      59         556 :     params.set<MooseEnum>("dim") = "1";
      60         278 :     _mesh = _factory.create<MooseMesh>(class_name, "mesh", params);
      61         278 :   }
      62             :   // Initialize the arbitrary mesh
      63        1946 :   else if (_current_task == "init_mesh")
      64             :   {
      65         278 :     _mesh->init();
      66             :   }
      67             :   // Create a "solve=false" FEProblem, if appropriate
      68        1668 :   else if (_current_task == "create_problem")
      69             :   {
      70         278 :     const std::string class_name = "FEProblem";
      71         278 :     InputParameters params = _factory.getValidParams(class_name);
      72         278 :     params.set<MooseMesh *>("mesh") = _mesh.get();
      73         278 :     params.set<bool>("use_nonlinear") = true;
      74         556 :     params.set<bool>("solve") = getParam<bool>("include_moose_solve");
      75         278 :     _problem = _factory.create<FEProblemBase>(class_name, "Problem", params);
      76         556 :     _problem->setKernelCoverageCheck(getParam<bool>("include_moose_solve")
      77             :                                          ? FEProblemBase::CoverageCheckMode::TRUE
      78             :                                          : FEProblemBase::CoverageCheckMode::FALSE);
      79         278 :   }
      80             :   // Set up an arbitrary steady executioner
      81        1390 :   else if (_current_task == "setup_executioner")
      82             :   {
      83         278 :     const std::string class_name = "Steady";
      84         278 :     InputParameters params = _factory.getValidParams(class_name);
      85         278 :     params.set<FEProblemBase *>("_fe_problem_base") = _problem.get();
      86         278 :     params.set<FEProblem *>("_fe_problem") = (std::dynamic_pointer_cast<FEProblem>(_problem)).get();
      87             :     std::shared_ptr<Executioner> executioner =
      88         278 :         _factory.create<Executioner>(class_name, "Executioner", params);
      89         278 :     _app.setExecutioner(std::move(executioner));
      90         278 :   }
      91        1112 :   else if (_current_task == "add_geochemistry_reactor")
      92             :   {
      93         278 :     const std::string class_name = "GeochemistryTimeIndependentReactor";
      94         278 :     auto params = _factory.getValidParams(class_name);
      95             :     // Only pass parameters that were supplied to this action
      96         556 :     if (isParamValid("block"))
      97           0 :       params.set<std::vector<SubdomainName>>("block") =
      98           0 :           getParam<std::vector<SubdomainName>>("block");
      99         556 :     if (isParamValid("boundary"))
     100           0 :       params.set<std::vector<BoundaryName>>("boundary") =
     101           0 :           getParam<std::vector<BoundaryName>>("boundary");
     102         834 :     params.set<UserObjectName>("model_definition") = getParam<UserObjectName>("model_definition");
     103         556 :     if (isParamValid("swap_out_of_basis"))
     104         556 :       params.set<std::vector<std::string>>("swap_out_of_basis") =
     105         834 :           getParam<std::vector<std::string>>("swap_out_of_basis");
     106         556 :     if (isParamValid("swap_into_basis"))
     107         556 :       params.set<std::vector<std::string>>("swap_into_basis") =
     108         834 :           getParam<std::vector<std::string>>("swap_into_basis");
     109         556 :     params.set<MultiMooseEnum>("constraint_meaning") =
     110         556 :         getParam<MultiMooseEnum>("constraint_meaning");
     111         556 :     params.set<std::vector<std::string>>("constraint_species") =
     112         556 :         getParam<std::vector<std::string>>("constraint_species");
     113         556 :     params.set<std::vector<Real>>("constraint_value") =
     114         556 :         getParam<std::vector<Real>>("constraint_value");
     115         834 :     params.set<MultiMooseEnum>("constraint_unit") = getParam<MultiMooseEnum>("constraint_unit");
     116         556 :     params.set<Real>("max_ionic_strength") = getParam<Real>("max_ionic_strength");
     117         278 :     params.set<unsigned>("extra_iterations_to_make_consistent") =
     118         556 :         getParam<unsigned>("extra_iterations_to_make_consistent");
     119         556 :     params.set<Real>("stoichiometry_tolerance") = getParam<Real>("stoichiometry_tolerance");
     120         556 :     params.set<std::string>("charge_balance_species") =
     121         278 :         getParam<std::string>("charge_balance_species");
     122         556 :     if (isParamValid("prevent_precipitation"))
     123         556 :       params.set<std::vector<std::string>>("prevent_precipitation") =
     124         834 :           getParam<std::vector<std::string>>("prevent_precipitation");
     125         556 :     params.set<Real>("abs_tol") = getParam<Real>("abs_tol");
     126         556 :     params.set<Real>("rel_tol") = getParam<Real>("rel_tol");
     127         556 :     params.set<Real>("min_initial_molality") = getParam<Real>("min_initial_molality");
     128         556 :     params.set<unsigned>("max_iter") = getParam<unsigned>("max_iter");
     129         556 :     params.set<Real>("max_initial_residual") = getParam<Real>("max_initial_residual");
     130         556 :     params.set<Real>("swap_threshold") = getParam<Real>("swap_threshold");
     131         556 :     params.set<unsigned>("max_swaps_allowed") = getParam<unsigned>("max_swaps_allowed");
     132         278 :     params.set<unsigned>("ramp_max_ionic_strength_initial") =
     133         556 :         getParam<unsigned>("ramp_max_ionic_strength_initial");
     134         556 :     params.set<bool>("ionic_str_using_basis_only") = getParam<bool>("ionic_str_using_basis_only");
     135         278 :     params.set<bool>("stoichiometric_ionic_str_using_Cl_only") =
     136         556 :         getParam<bool>("stoichiometric_ionic_str_using_Cl_only");
     137         556 :     params.set<Real>("temperature") = getParam<Real>("temperature");
     138         834 :     params.set<ExecFlagEnum>("execute_on") = {EXEC_FINAL};
     139         556 :     _problem->addUserObject(
     140         278 :         class_name, getParam<UserObjectName>("geochemistry_reactor_name"), params);
     141         278 :   }
     142        2502 : }

Generated by: LCOV version 1.14