www.mooseframework.org
CreateProblemAction.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 #include "CreateProblemAction.h"
16 #include "Factory.h"
17 #include "FEProblem.h"
18 #include "EigenProblem.h"
19 #include "MooseApp.h"
20 
21 template <>
24 {
25  MultiMooseEnum coord_types("XYZ RZ RSPHERICAL", "XYZ");
26  MooseEnum rz_coord_axis("X=0 Y=1", "Y");
27 
29  params.set<std::string>("type") = "FEProblem";
30  params.addParam<std::string>("name", "MOOSE Problem", "The name the problem");
31  params.addParam<std::vector<SubdomainName>>("block", "Block IDs for the coordinate systems");
32  params.addParam<MultiMooseEnum>(
33  "coord_type", coord_types, "Type of the coordinate system per block param");
34  params.addParam<MooseEnum>(
35  "rz_coord_axis", rz_coord_axis, "The rotation axis (X | Y) for axisymetric coordinates");
36 
37  params.addParam<bool>("fe_cache",
38  false,
39  "Whether or not to turn on the finite element shape "
40  "function caching system. This can increase speed with "
41  "an associated memory cost.");
42 
43  params.addParam<bool>(
44  "kernel_coverage_check", true, "Set to false to disable kernel->subdomain coverage check");
45  params.addParam<bool>("material_coverage_check",
46  true,
47  "Set to false to disable material->subdomain coverage check");
48 
49  params.addParam<FileNameNoExtension>("restart_file_base",
50  "File base name used for restart (e.g. "
51  "<path>/<filebase> or <path>/LATEST to "
52  "grab the latest file available)");
53 
54  return params;
55 }
56 
58  : MooseObjectAction(parameters),
59  _blocks(getParam<std::vector<SubdomainName>>("block")),
60  _coord_sys(getParam<MultiMooseEnum>("coord_type")),
61  _fe_cache(getParam<bool>("fe_cache"))
62 {
63 }
64 
65 void
67 {
68  if (_mesh.get() != NULL)
69  {
70  // build the problem only if we have mesh
71  {
72  _moose_object_pars.set<MooseMesh *>("mesh") = _mesh.get();
73  _moose_object_pars.set<bool>("use_nonlinear") = _app.useNonlinear();
74 
75 #ifdef LIBMESH_HAVE_PETSC
76  // put in empty arrays for PETSc options
77  _moose_object_pars.set<MultiMooseEnum>("petsc_options") = MultiMooseEnum("", "", true);
78  _moose_object_pars.set<std::vector<std::string>>("petsc_inames") = std::vector<std::string>();
79  _moose_object_pars.set<std::vector<std::string>>("petsc_values") = std::vector<std::string>();
80 #endif
81  _problem =
82  _factory.create<FEProblemBase>(_type, getParam<std::string>("name"), _moose_object_pars);
83  if (!_problem.get())
84  mooseError("Problem has to be of a FEProblemBase type");
85 
86  // if users provide a problem type, the type has to be an EigenProblem or its derived subclass
87  // when uing an eigen executioner
88  if (_app.useEigenvalue() && _type != "EigenProblem" &&
89  !(std::dynamic_pointer_cast<EigenProblem>(_problem)))
90  mooseError("Problem has to be of a EigenProblem (or derived subclass) type when using "
91  "eigen executioner");
92  }
93  // set up the problem
94  _problem->setCoordSystem(_blocks, _coord_sys);
95  _problem->setAxisymmetricCoordAxis(getParam<MooseEnum>("rz_coord_axis"));
96  _problem->useFECache(_fe_cache);
97  _problem->setKernelCoverageCheck(getParam<bool>("kernel_coverage_check"));
98  _problem->setMaterialCoverageCheck(getParam<bool>("material_coverage_check"));
99 
100  if (isParamValid("restart_file_base"))
101  {
102  std::string restart_file_base = getParam<FileNameNoExtension>("restart_file_base");
103 
104  std::size_t slash_pos = restart_file_base.find_last_of("/");
105  std::string path = restart_file_base.substr(0, slash_pos);
106  std::string file = restart_file_base.substr(slash_pos + 1);
107 
112  if (file == "LATEST")
113  {
114  std::list<std::string> dir_list(1, path);
115  std::list<std::string> files = MooseUtils::getFilesInDirs(dir_list);
116  restart_file_base = MooseUtils::getLatestAppCheckpointFileBase(files);
117 
118  if (restart_file_base == "")
119  mooseError("Unable to find suitable restart file");
120  }
121 
122  _console << "\nUsing " << restart_file_base << " for restart.\n\n";
123  _problem->setRestartFile(restart_file_base);
124  }
125  }
126 }
bool & useNonlinear()
Set a Boolean indicating whether this app will use a Nonlinear or Eigen System.
Definition: MooseApp.h:243
std::shared_ptr< MooseObject > create(const std::string &obj_name, const std::string &name, InputParameters parameters, THREAD_ID tid=0, bool print_deprecated=true)
Build an object (must be registered) - THIS METHOD IS DEPRECATED (Use create<T>()) ...
Definition: Factory.C:46
MultiMooseEnum _coord_sys
virtual void act() override
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
std::list< std::string > getFilesInDirs(const std::list< std::string > &directory_list)
Retrieves the names of all of the files contained within the list of directories passed into the rout...
Definition: MooseUtils.C:466
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
Factory & _factory
The Factory associated with the MooseApp.
Definition: Action.h:101
InputParameters validParams< CreateProblemAction >()
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
std::string getLatestAppCheckpointFileBase(const std::list< std::string > &checkpoint_files)
Definition: MooseUtils.C:503
bool & useEigenvalue()
Set a Boolean indicating whether this app will use an eigenvalue executioner.
Definition: MooseApp.h:248
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:74
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:37
std::vector< SubdomainName > _blocks
InputParameters validParams< MooseObjectAction >()
bool isParamValid(const std::string &name) const
Definition: Action.h:80
std::shared_ptr< MooseMesh > & _mesh
Definition: Action.h:127
std::string _type
The Object type that is being created.
InputParameters _moose_object_pars
The parameters for the object to be created.
std::shared_ptr< FEProblemBase > & _problem
Convenience reference to a problem this action works on.
Definition: Action.h:131
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object...
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
Definition: EigenProblem.h:32
MooseApp & _app
The MOOSE application this is associated with.
Definition: Action.h:98
bool _fe_cache
One entry of coord system per block, the size of _blocks and _coord_sys has to match, except:
CreateProblemAction(InputParameters parameters)