LCOV - code coverage report
Current view: top level - src/actions - THMCreateMeshAction.C (source / functions) Hit Total Coverage
Test: idaholab/moose thermal_hydraulics: #32971 (54bef8) with base c6cf66 Lines: 32 33 97.0 %
Date: 2026-05-29 20:41:18 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 "THMCreateMeshAction.h"
      11             : #include "THMMesh.h"
      12             : #include "FEProblemBase.h"
      13             : #include "CreateProblemAction.h"
      14             : #include "Factory.h"
      15             : #include "MooseApp.h"
      16             : #include "ActionWarehouse.h"
      17             : 
      18             : registerMooseAction("ThermalHydraulicsApp", THMCreateMeshAction, "setup_mesh");
      19             : registerMooseAction("ThermalHydraulicsApp", THMCreateMeshAction, "uniform_refine_mesh");
      20             : 
      21             : InputParameters
      22        2117 : THMCreateMeshAction::validParams()
      23             : {
      24        2117 :   InputParameters params = Action::validParams();
      25        2117 :   params.addClassDescription("Action that creates an empty mesh (in case one was not already "
      26             :                              "created) and also builds THMProblem (same).");
      27        2117 :   return params;
      28           0 : }
      29             : 
      30        2117 : THMCreateMeshAction::THMCreateMeshAction(const InputParameters & params) : Action(params) {}
      31             : 
      32             : void
      33        4230 : THMCreateMeshAction::act()
      34             : {
      35        4230 :   if (_current_task == "setup_mesh")
      36             :   {
      37        2117 :     if (!_mesh)
      38             :     {
      39        2043 :       const std::string class_name = "THMMesh";
      40        2043 :       InputParameters params = _factory.getValidParams(class_name);
      41        4086 :       params.set<MooseEnum>("dim") = "3";
      42        2043 :       params.set<unsigned int>("patch_size") = 1;
      43             :       // We need to go through the Factory to create the THMMesh so
      44             :       // that its params object is properly added to the Warehouse.
      45        2043 :       _mesh = _factory.create<THMMesh>(class_name, "THM:mesh", params);
      46        2043 :     }
      47             : 
      48        2117 :     if (!_mesh->hasMeshBase())
      49        2117 :       _mesh->setMeshBase(_mesh->buildMeshBaseObject());
      50             : 
      51        2117 :     if (!_problem)
      52             :     {
      53        2117 :       const std::string class_name = "THMProblem";
      54        2117 :       InputParameters params = _factory.getValidParams(class_name);
      55        2117 :       _app.builder().extractParams("", params); // extract global params
      56             :       // apply common parameters of the object held by CreateProblemAction to honor user inputs in
      57             :       // [Problem]
      58        2117 :       auto p = _awh.getActionByTask<CreateProblemAction>("create_problem");
      59        2117 :       if (p)
      60         197 :         params.applyParameters(p->getObjectParams());
      61        2117 :       params.set<MooseMesh *>("mesh") = _mesh.get();
      62        2117 :       params.set<bool>("use_nonlinear") = _app.useNonlinear();
      63        2117 :       _problem = _factory.create<FEProblemBase>(class_name, "THM:problem", params);
      64        2117 :     }
      65             :   }
      66        2113 :   else if (_current_task == "uniform_refine_mesh")
      67             :   {
      68        4226 :     if (_app.isParamSetByUser("refinements"))
      69             :     {
      70          12 :       auto level = _app.getParam<unsigned int>("refinements");
      71           6 :       _mesh->setUniformRefineLevel(level, false);
      72             :     }
      73             :   }
      74        4230 : }

Generated by: LCOV version 1.14