https://mooseframework.inl.gov
CopyNodalVarsAction.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 // MOOSE includes
11 #include "CopyNodalVarsAction.h"
12 
13 #include "ActionWarehouse.h"
14 #include "AuxiliarySystem.h"
15 #include "FEProblem.h"
16 #include "MooseApp.h"
17 #include "NonlinearSystemBase.h"
18 
19 #include <map>
20 
21 registerMooseAction("MooseApp", CopyNodalVarsAction, "check_copy_nodal_vars");
22 
23 registerMooseAction("MooseApp", CopyNodalVarsAction, "copy_nodal_vars");
24 
25 registerMooseAction("MooseApp", CopyNodalVarsAction, "copy_nodal_aux_vars");
26 
29 {
31  params.addClassDescription("Copies variable information from a file.");
32  params.addParam<std::string>(
33  "initial_from_file_timestep",
34  "LATEST",
35  "Gives the timestep (or \"LATEST\") for which to read a solution from a file "
36  "for a given variable. (Default: LATEST)");
37  params.addParam<std::string>(
38  "initial_from_file_var",
39  "Gives the name of a variable for which to read an initial condition from a mesh file");
40 
41  params.addParamNamesToGroup("initial_from_file_timestep initial_from_file_var",
42  "Initial From File");
43 
44  return params;
45 }
46 
48 
49 void
51 {
52 
53  if (isParamValid("initial_from_file_var"))
54  {
55  if (_current_task == "check_copy_nodal_vars")
57  else
58  {
59  SystemBase * system;
60  // Is this a NonlinearSystem variable or an AuxiliarySystem variable?
61  if (_current_task == "copy_nodal_vars")
62  {
63  // This iterates through each nonlinear system and finds which one the current variable
64  // needs to be copied to
65  system = &_problem->getSolverSystem(/*sys_num=*/0);
66  for (unsigned int i = 0; i < _problem->numSolverSystems(); i++)
67  if (_problem->getSolverSystem(i).hasVariable(name()))
68  system = &_problem->getSolverSystem(i);
69  }
70  else
71  system = &_problem->getAuxiliarySystem();
72 
73  system->addVariableToCopy(name(),
74  getParam<std::string>("initial_from_file_var"),
75  getParam<std::string>("initial_from_file_timestep"));
76  }
77  }
78 }
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
virtual void addVariableToCopy(const std::string &dest_name, const std::string &source_name, const std::string &timestep)
Add info about variable that will be copied.
Definition: SystemBase.C:1167
static InputParameters validParams()
Base class for a system (of equations)
Definition: SystemBase.h:84
Base class for actions.
Definition: Action.h:33
CopyNodalVarsAction(const InputParameters &params)
const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:99
static InputParameters validParams()
Definition: Action.C:26
void setExodusFileRestart(bool flag)
Set the flag to indicate whether or not we need to use a separate Exodus reader to read the mesh BEFO...
Definition: MooseApp.h:417
registerMooseAction("MooseApp", CopyNodalVarsAction, "check_copy_nodal_vars")
const std::string & _current_task
The current action (even though we have separate instances for each action)
Definition: Action.h:165
MooseApp & _app
The MOOSE application this is associated with.
Definition: MooseBase.h:353
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...
std::shared_ptr< FEProblemBase > & _problem
Convenience reference to a problem this action works on.
Definition: Action.h:171
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...
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition: MooseBase.h:195
virtual void act() override
Method to add objects to the simulation or perform other setup tasks.
void addParamNamesToGroup(const std::string &space_delim_names, const std::string group_name)
This method takes a space delimited list of parameter names and adds them to the specified group name...