LCOV - code coverage report
Current view: top level - src/ics - SolutionIC.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 34 38 89.5 %
Date: 2025-07-17 01:28:37 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       28766 : SolutionIC::validParams()
      20             : {
      21       28766 :   InputParameters params = InitialCondition::validParams();
      22       28766 :   params.addRequiredParam<UserObjectName>("solution_uo",
      23             :                                           "The SolutionUserObject to extract data from.");
      24       28766 :   params.addRequiredParam<VariableName>(
      25             :       "from_variable", "The name of the variable in the file that is to be extracted");
      26       28766 :   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       28766 :   params.addClassDescription(
      31             :       "Sets the initial condition from a field variable stored in an Exodus file, "
      32             :       "retrieved by a SolutionUserObject");
      33       28766 :   return params;
      34           0 : }
      35             : 
      36         124 : SolutionIC::SolutionIC(const InputParameters & parameters)
      37             :   : InitialCondition(parameters),
      38         124 :     _solution_object(getUserObject<SolutionUserObjectBase>("solution_uo")),
      39         248 :     _solution_object_var_name(getParam<VariableName>("from_variable"))
      40             : {
      41         124 : }
      42             : 
      43             : void
      44         100 : SolutionIC::initialSetup()
      45             : {
      46             :   // can only check blocks when the solution UO uses Exodus
      47         100 :   if (_solution_object.getSolutionFileType() == "exodusII")
      48             :   {
      49             :     // remap block names this IC is defined on into the ExodusII file block IDs
      50         100 :     const auto & block_names_to_ids_from = _solution_object.getBlockNamesToIds();
      51             : 
      52         100 :     const std::vector<SubdomainID> all_block_ids(meshBlockIDs().begin(), meshBlockIDs().end());
      53             :     const auto blocks_to_check =
      54         200 :         isParamValid("from_subdomains")
      55         100 :             ? getParam<std::vector<SubdomainName>>("from_subdomains")
      56         100 :             : (blockRestricted() ? blocks() : _sys.mesh().getSubdomainNames(all_block_ids));
      57             : 
      58         196 :     for (auto & blk_name : blocks_to_check)
      59             :     {
      60         100 :       auto it = block_names_to_ids_from.find(blk_name);
      61         100 :       if (it != block_names_to_ids_from.end())
      62          36 :         _exo_block_ids.insert(it->second);
      63             :       else
      64             :       {
      65          64 :         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          64 :         const auto & block_ids_to_names_from = _solution_object.getBlockIdsToNames();
      69         124 :         if (block_ids_to_names_from.find(blk_id) != block_ids_to_names_from.end() &&
      70         124 :             block_ids_to_names_from.find(blk_id)->second.empty())
      71          60 :           _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          96 :   }
      81             : 
      82          96 :   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          96 : }
      88             : 
      89             : Real
      90         688 : SolutionIC::value(const Point & p)
      91             : {
      92         688 :   return _solution_object.pointValue(0., p, _solution_object_var_name, &_exo_block_ids);
      93             : }

Generated by: LCOV version 1.14