Skip to content

Commit

Permalink
add a function to retrieve the current last mesh generator for actions
Browse files Browse the repository at this point in the history
  • Loading branch information
YaqiWang committed Apr 22, 2020
1 parent 77b7537 commit 8cb44a5
Show file tree
Hide file tree
Showing 12 changed files with 156 additions and 1 deletion.
13 changes: 13 additions & 0 deletions framework/doc/content/source/actions/Action.md
@@ -1 +1,14 @@
# MOOSE Action System

MOOSE actions, derived from the base class *Action* are used to set up a problem with other MOOSE objects including mesh generators, kernels, materials, user objects, etc.
An action can be optionally linked to an input syntax, which provides the valid parameters to the action through the MOOSE input parser behind the scene.
An action is assocated with tasks, which determine when the action is to be acted, or the *act* function of an action is to be called by MOOSE.
Association with multiple tasks is allowed. In such case, it is developers' responsibility to switch the functions based on the current task in the act function.
A full list of tasks is available in Moose.C file.
Developers are allowed to register new tasks with MOOSE Action system.
When actions are built either through the input parser or internally by MOOSE, they will exist during the entire simulation.

MOOSE has lots of built-in actions for adding individual objects through input files.
But MOOSE action system is far beyond the basic capabilities provided by these built-in actions.
Developers are encouraged to explore the MOOSE actions system to create their own actions in order to perform problem setup in one place and potentially simplify the input syntax significantly.
One example is to use an action to append a mesh generator that generats a boundary surrounding a particular subdomain for imposing specific boundary conditions, based on the information not necessarily inside of a mesh generator block.
5 changes: 5 additions & 0 deletions framework/include/base/MooseApp.h
Expand Up @@ -652,6 +652,11 @@ class MooseApp : public ConsoleStreamInterface, public libMesh::ParallelObject
*/
void clearMeshGenerators();

/**
* Get the current final mesh generator regardless what users set in the input
*/
std::string getCurrentFinalMeshGenerator() const;

/**
* Execute and clear the Mesh Generators data structure
*/
Expand Down
2 changes: 1 addition & 1 deletion framework/include/interfaces/Coupleable.h
Expand Up @@ -79,7 +79,7 @@ class Coupleable
* Get the list of array coupled variables
* @return The list of array coupled variables
*/
const std::vector<ArrayMooseVariable *> & getCoupledArratMooseVars() const
const std::vector<ArrayMooseVariable *> & getCoupledArrayMooseVars() const
{
return _coupled_array_moose_vars;
}
Expand Down
2 changes: 2 additions & 0 deletions framework/src/base/Moose.C
Expand Up @@ -102,6 +102,7 @@ addActionTypes(Syntax & syntax)
registerMooseObjectTask("init_mesh", MooseMesh, false);
registerMooseObjectTask("add_mesh_modifier", MeshModifier, false);
registerMooseObjectTask("add_mesh_generator", MeshGenerator, false);
registerMooseObjectTask("append_mesh_generator", MeshGenerator, false);

registerMooseObjectTask("add_kernel", Kernel, false);
appendMooseObjectTask ("add_kernel", EigenKernel);
Expand Down Expand Up @@ -244,6 +245,7 @@ addActionTypes(Syntax & syntax)
"(setup_recover_file_base)"
"(setup_mesh)"
"(add_mesh_generator)"
"(append_mesh_generator)"
"(execute_mesh_generators)"
"(recover_meta_data)"
"(set_mesh_base)"
Expand Down
29 changes: 29 additions & 0 deletions framework/src/base/MooseApp.C
Expand Up @@ -1572,6 +1572,35 @@ MooseApp::getMeshGeneratorOutput(const std::string & name)
return outputs.back();
}

std::string
MooseApp::getCurrentFinalMeshGenerator() const
{
DependencyResolver<std::shared_ptr<MeshGenerator>> resolver;

// Add all of the dependencies into the resolver and sort them
for (const auto & it : _mesh_generators)
{
// Make sure an item with no dependencies comes out too!
resolver.addItem(it.second);

std::vector<std::string> & generators = it.second->getDependencies();
for (const auto & depend_name : generators)
{
auto depend_it = _mesh_generators.find(depend_name);
if (depend_it != _mesh_generators.end())
resolver.insertDependency(it.second, depend_it->second);
}
}

const auto & ordered_generators = resolver.getSortedValuesSets();

std::string final_generator_name;
if (ordered_generators.size())
final_generator_name = ordered_generators.back().back()->name();

return final_generator_name;
}

void
MooseApp::executeMeshGenerators()
{
Expand Down
1 change: 1 addition & 0 deletions test/doc/remove.yml
@@ -1,3 +1,4 @@
- /ModifyMesh
- /BadKernels
- /MoreAuxVariables
- /Kernels/OldNamedKernel
28 changes: 28 additions & 0 deletions test/include/actions/AppendMeshGeneratorAction.h
@@ -0,0 +1,28 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#pragma once

#include "MooseObjectAction.h"

// Forward Declaration
class AppendMeshGeneratorAction;

template <>
InputParameters validParams<AppendMeshGeneratorAction>();

class AppendMeshGeneratorAction : public MooseObjectAction
{
public:
static InputParameters validParams();

AppendMeshGeneratorAction(InputParameters params);

virtual void act() override;
};
43 changes: 43 additions & 0 deletions test/src/actions/AppendMeshGeneratorAction.C
@@ -0,0 +1,43 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#include "AppendMeshGeneratorAction.h"
#include "MooseMesh.h"
#include "MeshGenerator.h"
#include "Factory.h"
#include "MooseApp.h"

registerMooseAction("MooseApp", AppendMeshGeneratorAction, "append_mesh_generator");

defineLegacyParams(AppendMeshGeneratorAction);

InputParameters
AppendMeshGeneratorAction::validParams()
{
InputParameters params = MooseObjectAction::validParams();
return params;
}

AppendMeshGeneratorAction::AppendMeshGeneratorAction(InputParameters params)
: MooseObjectAction(params)
{
}

void
AppendMeshGeneratorAction::act()
{
if (!_mesh)
mooseError("No mesh file was supplied and no generation block was provided");

if (!_moose_object_pars.have_parameter<MeshGeneratorName>("input"))
mooseError("Cannot append a mesh generator that does not take input mesh generators");

_moose_object_pars.set<MeshGeneratorName>("input") = _app.getCurrentFinalMeshGenerator();
_app.addMeshGenerator(_type, _name, _moose_object_pars);
}
1 change: 1 addition & 0 deletions test/src/base/MooseTestApp.C
Expand Up @@ -82,6 +82,7 @@ MooseTestApp::registerAll(Factory & f, ActionFactory & af, Syntax & s, bool use_
registerSyntax("CreateSpecialProblemAction", "TestProblem");
registerSyntax("AddDGDiffusion", "DGDiffusionAction");
registerSyntax("MeshMetaDataDependenceAction", "AutoLineSamplerTest");
registerSyntax("AppendMeshGeneratorAction", "ModifyMesh/*");
}
}

Expand Down
@@ -0,0 +1,20 @@
[Mesh]
[gmg]
type = GeneratedMeshGenerator
dim = 2
nx = 3
ny = 3
[]
[]

[ModifyMesh]
[addss]
type = SideSetsAroundSubdomainGenerator
new_boundary = whole
block = 0
[]
[]

[Outputs]
exodus = true
[]
Binary file not shown.
13 changes: 13 additions & 0 deletions test/tests/meshgenerators/append_mesh_generator/tests
@@ -0,0 +1,13 @@
[Tests]
[./append_mesh_generator_test]
type = 'Exodiff'
input = 'append_mesh_generator.i'
cli_args = '--mesh-only'
exodiff = 'append_mesh_generator_in.e'
requirement = 'MOOSE shall be able to allow actions to append mesh generators.'
design = 'actions/Action.md'
issues = '#15121'
mesh_mode = 'REPLICATED'
recover = false
[../]
[]

0 comments on commit 8cb44a5

Please sign in to comment.