https://mooseframework.inl.gov
SolutionIC.C
Go to the documentation of this file.
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 
20 {
22  params.addRequiredParam<UserObjectName>("solution_uo",
23  "The SolutionUserObject to extract data from.");
24  params.addRequiredParam<VariableName>(
25  "from_variable", "The name of the variable in the file that is to be extracted");
26  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  params.addClassDescription(
31  "Sets the initial condition from a field variable stored in an Exodus file, "
32  "retrieved by a SolutionUserObject");
33  return params;
34 }
35 
37  : InitialCondition(parameters),
38  _solution_object(getUserObject<SolutionUserObjectBase>("solution_uo")),
39  _solution_object_var_name(getParam<VariableName>("from_variable"))
40 {
41 }
42 
43 void
45 {
46  // can only check blocks when the solution UO uses Exodus
47  if (_solution_object.getSolutionFileType() == "exodusII")
48  {
49  // remap block names this IC is defined on into the ExodusII file block IDs
50  const auto & block_names_to_ids_from = _solution_object.getBlockNamesToIds();
51 
52  const std::vector<SubdomainID> all_block_ids(meshBlockIDs().begin(), meshBlockIDs().end());
53  const auto blocks_to_check =
54  isParamValid("from_subdomains")
55  ? getParam<std::vector<SubdomainName>>("from_subdomains")
56  : (blockRestricted() ? blocks() : _sys.mesh().getSubdomainNames(all_block_ids));
57 
58  for (auto & blk_name : blocks_to_check)
59  {
60  auto it = block_names_to_ids_from.find(blk_name);
61  if (it != block_names_to_ids_from.end())
62  _exo_block_ids.insert(it->second);
63  else
64  {
65  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  const auto & block_ids_to_names_from = _solution_object.getBlockIdsToNames();
69  if (block_ids_to_names_from.find(blk_id) != block_ids_to_names_from.end() &&
70  block_ids_to_names_from.find(blk_id)->second.empty())
71  _exo_block_ids.insert(blk_id);
72  else
73  mooseError("Block '",
74  blk_name,
75  "' does not exist in the file '",
77  "'.");
78  }
79  }
80  }
81 
82  if (_solution_object.getSolutionFileType() != "exodusII" && isParamValid("from_subdomains"))
83  paramError("from_subdomains",
84  "Source subdomain block restriction is not supported if the solution file type is "
85  "not Exodus. Current file type: " +
86  std::string(_solution_object.getSolutionFileType()));
87 }
88 
89 Real
90 SolutionIC::value(const Point & p)
91 {
93 }
MooseMesh & mesh()
Definition: SystemBase.h:99
registerMooseObjectRenamed("MooseApp", SolutionInitialCondition, "06/30/2024 24:00", SolutionIC)
virtual void initialSetup() override
Gets called at the beginning of the simulation before this object is asked to do its job...
Definition: SolutionIC.C:44
virtual Real value(const Point &p) override
The value of the variable at a point.
Definition: SolutionIC.C:90
User object that reads an existing solution from an input file and uses it in the current simulation...
Class for reading an initial condition from a solution user object.
Definition: SolutionIC.h:19
This is a template class that implements the workhorse compute and computeNodal methods.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
MooseEnum getSolutionFileType() const
Get the type of file that was read.
static InputParameters validParams()
registerMooseObject("MooseApp", SolutionIC)
virtual bool blockRestricted() const
Returns true if this object has been restricted to a block.
const VariableName & _solution_object_var_name
The variable name extracted from the SolutionUserObject.
Definition: SolutionIC.h:33
const SolutionUserObjectBase & _solution_object
SolutionUserObject containing the solution of interest.
Definition: SolutionIC.h:30
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
const std::string getMeshFileName() const
Return the name of the mesh file this object read the solution from.
SystemBase & _sys
The system object.
static InputParameters validParams()
Definition: SolutionIC.C:19
std::set< SubdomainID > _exo_block_ids
Remapped IDs from the current mesh to the ExodusII mesh.
Definition: SolutionIC.h:36
SolutionIC(const InputParameters &parameters)
Definition: SolutionIC.C:36
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
std::vector< SubdomainName > getSubdomainNames(const std::vector< SubdomainID > &subdomain_ids) const
Get the associated subdomainNames for the subdomain ids that are passed in.
Definition: MooseMesh.C:1764
const std::vector< SubdomainName > & blocks() const
Return the block names for this object.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const std::map< SubdomainName, SubdomainID > & getBlockNamesToIds() const
Get the map from block name to block ID.
const std::set< SubdomainID > & meshBlockIDs() const
Return all of the SubdomainIDs for the mesh.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
const std::map< SubdomainID, SubdomainName > & getBlockIdsToNames() const
Get the map from block id to block name.
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object...
Real pointValue(Real t, const Point &p, const unsigned int local_var_index, const std::set< subdomain_id_type > *subdomain_ids=nullptr) const
Returns a value at a specific location and variable (see SolutionFunction)
SubdomainID getSubdomainID(const SubdomainName &subdomain_name) const
Get the associated subdomain ID for the subdomain name.
Definition: MooseMesh.C:1728