https://mooseframework.inl.gov
THMCreateMeshAction.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 "THMCreateMeshAction.h"
11 #include "THMMesh.h"
12 #include "FEProblemBase.h"
13 #include "CreateProblemAction.h"
14 #include "Factory.h"
15 #include "MooseApp.h"
16 #include "ActionWarehouse.h"
17 
18 registerMooseAction("ThermalHydraulicsApp", THMCreateMeshAction, "setup_mesh");
19 registerMooseAction("ThermalHydraulicsApp", THMCreateMeshAction, "uniform_refine_mesh");
20 
23 {
25  params.addClassDescription("Action that creates an empty mesh (in case one was not already "
26  "created) and also builds THMProblem (same).");
27  return params;
28 }
29 
31 
32 void
34 {
35  if (_current_task == "setup_mesh")
36  {
37  if (!_mesh)
38  {
39  const std::string class_name = "THMMesh";
40  InputParameters params = _factory.getValidParams(class_name);
41  params.set<MooseEnum>("dim") = "3";
42  params.set<unsigned int>("patch_size") = 1;
43  // We need to go through the Factory to create the THMMesh so
44  // that its params object is properly added to the Warehouse.
45  _mesh = _factory.create<THMMesh>(class_name, "THM:mesh", params);
46  }
47 
48  if (!_mesh->hasMeshBase())
49  _mesh->setMeshBase(_mesh->buildMeshBaseObject());
50 
51  if (!_problem)
52  {
53  const std::string class_name = "THMProblem";
54  InputParameters params = _factory.getValidParams(class_name);
55  _app.builder().extractParams("", params); // extract global params
56  // apply common parameters of the object held by CreateProblemAction to honor user inputs in
57  // [Problem]
58  auto p = _awh.getActionByTask<CreateProblemAction>("create_problem");
59  if (p)
60  params.applyParameters(p->getObjectParams());
61  params.set<MooseMesh *>("mesh") = _mesh.get();
62  params.set<bool>("use_nonlinear") = _app.useNonlinear();
63  _problem = _factory.create<FEProblemBase>(class_name, "THM:problem", params);
64  }
65  }
66  else if (_current_task == "uniform_refine_mesh")
67  {
68  if (_app.isParamSetByUser("refinements"))
69  {
70  auto level = _app.getParam<unsigned int>("refinements");
71  _mesh->setUniformRefineLevel(level, false);
72  }
73  }
74 }
registerMooseAction("ThermalHydraulicsApp", THMCreateMeshAction, "setup_mesh")
bool & useNonlinear()
ActionWarehouse & _awh
MooseApp & _app
T & set(const std::string &name, bool quiet_mode=false)
std::shared_ptr< MooseObject > create(const std::string &obj_name, const std::string &name, const InputParameters &parameters, THREAD_ID tid=0, bool print_deprecated=true)
InputParameters getValidParams(const std::string &name) const
void applyParameters(const InputParameters &common, const std::vector< std::string > &exclude={}, const bool allow_private=false)
void extractParams(const std::string &prefix, InputParameters &p)
Mesh for THM.
Definition: THMMesh.h:18
Factory & _factory
static InputParameters validParams()
Moose::Builder & builder()
const std::string & _current_task
static InputParameters validParams()
const T & getParam(const std::string &name)
std::shared_ptr< MooseMesh > & _mesh
THMCreateMeshAction(const InputParameters &params)
const T * getActionByTask(const std::string &task)
void addClassDescription(const std::string &doc_string)
std::shared_ptr< FEProblemBase > & _problem
bool isParamSetByUser(const std::string &nm) const