https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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"
12#include "MooseMesh.h"
13#include "SystemBase.h"
14
16registerMooseObjectRenamed("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<MooseEnum>(
27 "weighting_type",
29 "The policy used to select a unique value when the imported solution is multivalued.");
30 params.addParam<std::vector<SubdomainName>>(
31 "from_subdomains",
32 "The name(s) of the subdomain(s) in the solution file providing the data. If not specified, "
33 "will default to the block restriction specified by the 'block' parameter.");
35 "Sets the initial condition from a field variable stored in an Exodus file, "
36 "retrieved by a SolutionUserObject");
37 return params;
38}
39
41 : InitialCondition(parameters),
42 _solution_object(getUserObject<SolutionUserObjectBase>("solution_uo")),
43 _solution_object_var_name(getParam<VariableName>("from_variable")),
44 _weighting_type(isParamSetByUser("weighting_type")
45 ? std::make_optional(getParam<MooseEnum>("weighting_type")
46 .getEnum<SolutionUserObjectBase::WeightingType>())
47 : std::nullopt)
48{
49}
50
51void
53{
54 // can only check blocks when the solution UO uses Exodus
55 if (_solution_object.getSolutionFileType() == "exodusII")
56 {
57 // remap block names this IC is defined on into the ExodusII file block IDs
58 const auto & block_names_to_ids_from = _solution_object.getBlockNamesToIds();
59
60 const std::vector<SubdomainID> all_block_ids(meshBlockIDs().begin(), meshBlockIDs().end());
61 const auto blocks_to_check =
62 isParamValid("from_subdomains")
63 ? getParam<std::vector<SubdomainName>>("from_subdomains")
64 : (blockRestricted() ? blocks() : _sys.mesh().getSubdomainNames(all_block_ids));
65
66 for (auto & blk_name : blocks_to_check)
67 {
68 auto it = block_names_to_ids_from.find(blk_name);
69 if (it != block_names_to_ids_from.end())
70 _exo_block_ids.insert(it->second);
71 else
72 {
73 auto blk_id = _sys.mesh().getSubdomainID(blk_name);
74 // use the ids, it may be that the source file does not have block names
75 // and that we are using the id as the block name (block = 0 for example)
76 const auto & block_ids_to_names_from = _solution_object.getBlockIdsToNames();
77 if (block_ids_to_names_from.find(blk_id) != block_ids_to_names_from.end() &&
78 block_ids_to_names_from.find(blk_id)->second.empty())
79 _exo_block_ids.insert(blk_id);
80 else
81 mooseError("Block '",
82 blk_name,
83 "' does not exist in the file '",
85 "'.");
86 }
87 }
88 }
89
90 if (_solution_object.getSolutionFileType() != "exodusII" && isParamValid("from_subdomains"))
91 paramError("from_subdomains",
92 "Source subdomain block restriction is not supported if the solution file type is "
93 "not Exodus. Current file type: " +
95
98 "from_variable",
99 "The imported variable '",
101 "' is vector-valued, but SolutionIC supports only scalar-valued imported variables.");
102
103 // Warn when no explicit weighting policy is provided for a spatially discontinuous variable
107 "weighting_type",
108 "A weighting policy should be specified when the imported variable '",
110 "' is spatially discontinuous. Values evaluated on element interfaces may depend on "
111 "source element ordering.");
112}
113
114Real
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
registerMooseObjectRenamed("MooseApp", SolutionInitialCondition, "06/30/2024 24:00", SolutionIC)
registerMooseObject("MooseApp", SolutionIC)
const std::set< SubdomainID > & meshBlockIDs() const
Return all of the SubdomainIDs for the mesh.
virtual bool blockRestricted() const
Returns true if this object has been restricted to a block.
const std::vector< SubdomainName > & blocks() const
Return the block names for this object.
SystemBase & _sys
The system object.
This is a template class that implements the workhorse compute and computeNodal methods.
static InputParameters validParams()
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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.
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...
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.
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 ...
Definition MooseBase.h:457
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition MooseBase.h:199
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition MooseEnum.h:55
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:1720
SubdomainID getSubdomainID(const SubdomainName &subdomain_name) const
Get the associated subdomain ID for the subdomain name.
Definition MooseMesh.C:1678
Class for reading an initial condition from a solution user object.
Definition SolutionIC.h:20
virtual void initialSetup() override
Gets called at the beginning of the simulation before this object is asked to do its job.
Definition SolutionIC.C:52
const std::optional< SolutionUserObjectBase::WeightingType > _weighting_type
Policy used when the imported solution is multivalued at the query point.
Definition SolutionIC.h:36
const SolutionUserObjectBase & _solution_object
SolutionUserObject containing the solution of interest.
Definition SolutionIC.h:30
std::set< SubdomainID > _exo_block_ids
Remapped IDs from the current mesh to the ExodusII mesh.
Definition SolutionIC.h:39
static InputParameters validParams()
Definition SolutionIC.C:19
const VariableName & _solution_object_var_name
The variable name extracted from the SolutionUserObject.
Definition SolutionIC.h:33
SolutionIC(const InputParameters &parameters)
Definition SolutionIC.C:40
virtual Real value(const Point &p) override
The value of the variable at a point.
Definition SolutionIC.C:115
void paramWarning(const std::string &param, Args... args) const
User object that reads an existing solution from an input file and uses it in the current simulation.
MooseEnum getSolutionFileType() const
Get the type of file that was read.
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)
bool isVariableADiscontinuousScalarField(const std::string &var_name) const
Returns whether the imported variable is a discontinuous scalar finite element field.
const std::string getMeshFileName() const
Return the name of the mesh file this object read the solution from.
const std::map< SubdomainID, SubdomainName > & getBlockIdsToNames() const
Get the map from block id to block name.
bool isVariableScalarValued(const std::string &var_name) const
Returns whether the imported variable has a scalar finite element field type.
const std::map< SubdomainName, SubdomainID > & getBlockNamesToIds() const
Get the map from block name to block ID.
MooseMesh & mesh()
Definition SystemBase.h:100