LCOV - code coverage report
Current view: top level - src/ics - SolutionIC.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 419b9d Lines: 34 38 89.5 %
Date: 2025-08-08 20:01:16 Functions: 4 4 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 "SolutionIC.h"
      11             : #include "SolutionUserObjectBase.h"
      12             : #include "MooseMesh.h"
      13             : #include "SystemBase.h"
      14             : 
      15             : registerMooseObject("MooseApp", SolutionIC);
      16             : registerMooseObjectRenamed("MooseApp", SolutionInitialCondition, "06/30/2024 24:00", SolutionIC);
      17             : 
      18             : InputParameters
      19       28782 : SolutionIC::validParams()
      20             : {
      21       28782 :   InputParameters params = InitialCondition::validParams();
      22       28782 :   params.addRequiredParam<UserObjectName>("solution_uo",
      23             :                                           "The SolutionUserObject to extract data from.");
      24       28782 :   params.addRequiredParam<VariableName>(
      25             :       "from_variable", "The name of the variable in the file that is to be extracted");
      26       28782 :   params.addParam<std::vector<SubdomainName>>(
      27             :       "from_subdomains",
      28             :       "The name(s) of the subdomain(s) in the solution file providing the data. If not specified, "
      29             :       "will default to the block restriction specified by the 'block' parameter.");
      30       28782 :   params.addClassDescription(
      31             :       "Sets the initial condition from a field variable stored in an Exodus file, "
      32             :       "retrieved by a SolutionUserObject");
      33       28782 :   return params;
      34           0 : }
      35             : 
      36         132 : SolutionIC::SolutionIC(const InputParameters & parameters)
      37             :   : InitialCondition(parameters),
      38         132 :     _solution_object(getUserObject<SolutionUserObjectBase>("solution_uo")),
      39         264 :     _solution_object_var_name(getParam<VariableName>("from_variable"))
      40             : {
      41         132 : }
      42             : 
      43             : void
      44         108 : SolutionIC::initialSetup()
      45             : {
      46             :   // can only check blocks when the solution UO uses Exodus
      47         108 :   if (_solution_object.getSolutionFileType() == "exodusII")
      48             :   {
      49             :     // remap block names this IC is defined on into the ExodusII file block IDs
      50         108 :     const auto & block_names_to_ids_from = _solution_object.getBlockNamesToIds();
      51             : 
      52         108 :     const std::vector<SubdomainID> all_block_ids(meshBlockIDs().begin(), meshBlockIDs().end());
      53             :     const auto blocks_to_check =
      54         216 :         isParamValid("from_subdomains")
      55         108 :             ? getParam<std::vector<SubdomainName>>("from_subdomains")
      56         108 :             : (blockRestricted() ? blocks() : _sys.mesh().getSubdomainNames(all_block_ids));
      57             : 
      58         212 :     for (auto & blk_name : blocks_to_check)
      59             :     {
      60         108 :       auto it = block_names_to_ids_from.find(blk_name);
      61         108 :       if (it != block_names_to_ids_from.end())
      62          39 :         _exo_block_ids.insert(it->second);
      63             :       else
      64             :       {
      65          69 :         auto blk_id = _sys.mesh().getSubdomainID(blk_name);
      66             :         // use the ids, it may be that the source file does not have block names
      67             :         // and that we are using the id as the block name (block = 0 for example)
      68          69 :         const auto & block_ids_to_names_from = _solution_object.getBlockIdsToNames();
      69         134 :         if (block_ids_to_names_from.find(blk_id) != block_ids_to_names_from.end() &&
      70         134 :             block_ids_to_names_from.find(blk_id)->second.empty())
      71          65 :           _exo_block_ids.insert(blk_id);
      72             :         else
      73           4 :           mooseError("Block '",
      74             :                      blk_name,
      75             :                      "' does not exist in the file '",
      76           4 :                      _solution_object.getMeshFileName(),
      77             :                      "'.");
      78             :       }
      79             :     }
      80         104 :   }
      81             : 
      82         104 :   if (_solution_object.getSolutionFileType() != "exodusII" && isParamValid("from_subdomains"))
      83           0 :     paramError("from_subdomains",
      84             :                "Source subdomain block restriction is not supported if the solution file type is "
      85           0 :                "not Exodus. Current file type: " +
      86           0 :                    std::string(_solution_object.getSolutionFileType()));
      87         104 : }
      88             : 
      89             : Real
      90         774 : SolutionIC::value(const Point & p)
      91             : {
      92         774 :   return _solution_object.pointValue(0., p, _solution_object_var_name, &_exo_block_ids);
      93             : }

Generated by: LCOV version 1.14