Skip to content

Commit

Permalink
Merge pull request #12782 from permcody/mesh_generator_cleanup
Browse files Browse the repository at this point in the history
Mesh generator cleanup
  • Loading branch information
permcody committed Jan 31, 2019
2 parents e595b55 + 0d90293 commit 5d74fe8
Show file tree
Hide file tree
Showing 27 changed files with 309 additions and 132 deletions.
1 change: 1 addition & 0 deletions framework/include/base/MooseObjectUnitTest.h
Expand Up @@ -78,6 +78,7 @@ class MooseObjectUnitTest : public ::testing::Test
mesh_params.set<std::string>("_type") = "GeneratedMesh"; mesh_params.set<std::string>("_type") = "GeneratedMesh";
mesh_params.set<MooseEnum>("dim") = "3"; mesh_params.set<MooseEnum>("dim") = "3";
_mesh = libmesh_make_unique<GeneratedMesh>(mesh_params); _mesh = libmesh_make_unique<GeneratedMesh>(mesh_params);
_mesh->setMeshBase(_mesh->buildMeshBaseObject());


InputParameters problem_params = _factory.getValidParams("FEProblem"); InputParameters problem_params = _factory.getValidParams("FEProblem");
problem_params.set<MooseMesh *>("mesh") = _mesh.get(); problem_params.set<MooseMesh *>("mesh") = _mesh.get();
Expand Down
6 changes: 5 additions & 1 deletion framework/include/mesh/FileMesh.h
Expand Up @@ -43,8 +43,12 @@ class FileMesh : public MooseMesh
/// Auxiliary object for restart /// Auxiliary object for restart
std::unique_ptr<ExodusII_IO> _exreader; std::unique_ptr<ExodusII_IO> _exreader;


/// The requested dimension of the mesh. For some file meshes, this is not required may be implied
/// from the element type(s).
const unsigned int _dim;

/// Timers /// Timers
PerfID _read_mesh_timer; const PerfID _read_mesh_timer;
}; };


#endif // FILEMESH_H #endif // FILEMESH_H
25 changes: 21 additions & 4 deletions framework/include/mesh/MooseMesh.h
Expand Up @@ -78,11 +78,16 @@ class MooseMesh : public MooseObject, public Restartable, public PerfGraphInterf
MooseMesh(const InputParameters & parameters); MooseMesh(const InputParameters & parameters);
MooseMesh(const MooseMesh & other_mesh); MooseMesh(const MooseMesh & other_mesh);


/**
* Destructor
*/
virtual ~MooseMesh(); virtual ~MooseMesh();


// The type of libMesh::MeshBase that will be used
enum class ParallelType
{
DEFAULT,
REPLICATED,
DISTRIBUTED
};

/** /**
* Clone method. Allocates memory you are responsible to clean up. * Clone method. Allocates memory you are responsible to clean up.
*/ */
Expand All @@ -95,6 +100,18 @@ class MooseMesh : public MooseObject, public Restartable, public PerfGraphInterf
*/ */
virtual std::unique_ptr<MooseMesh> safeClone() const = 0; virtual std::unique_ptr<MooseMesh> safeClone() const = 0;


/**
* Method to construct a libMesh::MeshBase object that is normally set and used by the MooseMesh
* object during the "init()" phase.
*/
std::unique_ptr<MeshBase> buildMeshBaseObject(ParallelType override_type = ParallelType::DEFAULT);

/**
* Method to set the mesh_base object. If this method is NOT called prior to calling init(), a
* MeshBase object will be automatically constructed and set.
*/
void setMeshBase(std::unique_ptr<MeshBase> mesh_base);

/** /**
* Initialize the Mesh object. Most of the time this will turn around * Initialize the Mesh object. Most of the time this will turn around
* and call build_mesh so the child class can build the Mesh object. * and call build_mesh so the child class can build the Mesh object.
Expand Down Expand Up @@ -838,7 +855,7 @@ class MooseMesh : public MooseObject, public Restartable, public PerfGraphInterf


/// Can be set to DISTRIBUTED, REPLICATED, or DEFAULT. Determines whether /// Can be set to DISTRIBUTED, REPLICATED, or DEFAULT. Determines whether
/// the underlying libMesh mesh is a ReplicatedMesh or DistributedMesh. /// the underlying libMesh mesh is a ReplicatedMesh or DistributedMesh.
MooseEnum _mesh_parallel_type; ParallelType _parallel_type;


/// False by default. Final value is determined by several factors /// False by default. Final value is determined by several factors
/// including the 'distribution' setting in the input file, and whether /// including the 'distribution' setting in the input file, and whether
Expand Down
2 changes: 1 addition & 1 deletion framework/include/mesh/PatternedMesh.h
Expand Up @@ -38,7 +38,7 @@ class PatternedMesh : public MooseMesh
public: public:
PatternedMesh(const InputParameters & parameters); PatternedMesh(const InputParameters & parameters);
PatternedMesh(const PatternedMesh & other_mesh); PatternedMesh(const PatternedMesh & other_mesh);
virtual ~PatternedMesh(); virtual ~PatternedMesh() = default;


virtual std::unique_ptr<MooseMesh> safeClone() const override; virtual std::unique_ptr<MooseMesh> safeClone() const override;


Expand Down
2 changes: 0 additions & 2 deletions framework/include/mesh/StitchedMesh.h
Expand Up @@ -33,8 +33,6 @@ class StitchedMesh : public MooseMesh
StitchedMesh(const InputParameters & parameters); StitchedMesh(const InputParameters & parameters);
StitchedMesh(const StitchedMesh & other_mesh); StitchedMesh(const StitchedMesh & other_mesh);


virtual ~StitchedMesh();

virtual std::unique_ptr<MooseMesh> safeClone() const override; virtual std::unique_ptr<MooseMesh> safeClone() const override;


virtual void buildMesh() override; virtual void buildMesh() override;
Expand Down
6 changes: 6 additions & 0 deletions framework/include/meshgenerators/MeshGenerator.h
Expand Up @@ -13,6 +13,9 @@
#include "MooseObject.h" #include "MooseObject.h"
#include "Restartable.h" #include "Restartable.h"


// Included so mesh generators don't need to include this when constructing MeshBase objects
#include "MooseMesh.h"

#include "libmesh/mesh_base.h" #include "libmesh/mesh_base.h"


// Forward declarations // Forward declarations
Expand Down Expand Up @@ -66,6 +69,9 @@ class MeshGenerator : public MooseObject, public Restartable
std::unique_ptr<MeshBase> & std::unique_ptr<MeshBase> &
getMeshByName(const MeshGeneratorName & input_mesh_generator_parameter_name); getMeshByName(const MeshGeneratorName & input_mesh_generator_parameter_name);


/// References to the mesh and displaced mesh (currently in the ActionWarehouse)
std::shared_ptr<MooseMesh> & _mesh;

private: private:
/// A list of generators that are required to run before this generator may run /// A list of generators that are required to run before this generator may run
std::vector<std::string> _depends_on; std::vector<std::string> _depends_on;
Expand Down
3 changes: 3 additions & 0 deletions framework/src/actions/AddMeshGeneratorAction.C
Expand Up @@ -34,5 +34,8 @@ AddMeshGeneratorAction::act()
if (_app.isRecovering()) if (_app.isRecovering())
return; return;


if (!_mesh)
mooseError("No mesh file was supplied and no generation block was provided");

_app.addMeshGenerator(_type, _name, _moose_object_pars); _app.addMeshGenerator(_type, _name, _moose_object_pars);
} }
8 changes: 7 additions & 1 deletion framework/src/actions/SetupMeshAction.C
Expand Up @@ -16,7 +16,7 @@
#include "Factory.h" #include "Factory.h"


registerMooseAction("MooseApp", SetupMeshAction, "setup_mesh"); registerMooseAction("MooseApp", SetupMeshAction, "setup_mesh");

registerMooseAction("MooseApp", SetupMeshAction, "set_mesh_base");
registerMooseAction("MooseApp", SetupMeshAction, "init_mesh"); registerMooseAction("MooseApp", SetupMeshAction, "init_mesh");


template <> template <>
Expand Down Expand Up @@ -218,6 +218,12 @@ SetupMeshAction::act()
if (isParamValid("displacements") && getParam<bool>("use_displaced_mesh")) if (isParamValid("displacements") && getParam<bool>("use_displaced_mesh"))
_displaced_mesh = _factory.create<MooseMesh>(_type, "displaced_mesh", _moose_object_pars); _displaced_mesh = _factory.create<MooseMesh>(_type, "displaced_mesh", _moose_object_pars);
} }
else if (_current_task == "set_mesh_base")
{
_mesh->setMeshBase(_mesh->buildMeshBaseObject());
if (isParamValid("displacements") && getParam<bool>("use_displaced_mesh"))
_displaced_mesh->setMeshBase(_displaced_mesh->buildMeshBaseObject());
}
else if (_current_task == "init_mesh") else if (_current_task == "init_mesh")
{ {
_mesh->init(); _mesh->init();
Expand Down
8 changes: 5 additions & 3 deletions framework/src/base/Moose.C
Expand Up @@ -97,9 +97,10 @@ addActionTypes(Syntax & syntax)
registerMooseObjectTask("determine_system_type", Executioner, true); registerMooseObjectTask("determine_system_type", Executioner, true);


registerMooseObjectTask("setup_mesh", MooseMesh, false); registerMooseObjectTask("setup_mesh", MooseMesh, false);
registerMooseObjectTask("set_mesh_base", MooseMesh, false);
registerMooseObjectTask("init_mesh", MooseMesh, false); registerMooseObjectTask("init_mesh", MooseMesh, false);
registerMooseObjectTask("add_mesh_modifier", MeshModifier, false); registerMooseObjectTask("add_mesh_modifier", MeshModifier, false);
registerMooseObjectTask("add_mesh_generator", MeshGenerator, false); registerMooseObjectTask("add_mesh_generator", MeshGenerator, false);


registerMooseObjectTask("add_kernel", Kernel, false); registerMooseObjectTask("add_kernel", Kernel, false);
appendMooseObjectTask ("add_kernel", EigenKernel); appendMooseObjectTask ("add_kernel", EigenKernel);
Expand Down Expand Up @@ -171,7 +172,7 @@ addActionTypes(Syntax & syntax)
registerTask("uniform_refine_mesh", false); registerTask("uniform_refine_mesh", false);
registerTask("prepare_mesh", false); registerTask("prepare_mesh", false);
registerTask("add_geometric_rm", true); registerTask("add_geometric_rm", true);
registerTask("setup_mesh_complete", false); // calls prepare registerTask("setup_mesh_complete", true); // calls prepare


registerTask("init_displaced_problem", false); registerTask("init_displaced_problem", false);


Expand Down Expand Up @@ -232,10 +233,11 @@ addActionTypes(Syntax & syntax)
"(common_output)" "(common_output)"
"(set_global_params)" "(set_global_params)"
"(setup_recover_file_base)" "(setup_recover_file_base)"
"(setup_mesh)"
"(add_mesh_generator)" "(add_mesh_generator)"
"(execute_mesh_generators)" "(execute_mesh_generators)"
"(set_mesh_base)"
"(check_copy_nodal_vars)" "(check_copy_nodal_vars)"
"(setup_mesh)"
"(add_partitioner)" "(add_partitioner)"
"(add_geometric_rm)" "(add_geometric_rm)"
"(init_mesh)" "(init_mesh)"
Expand Down
19 changes: 1 addition & 18 deletions framework/src/base/MooseApp.C
Expand Up @@ -1538,9 +1538,6 @@ MooseApp::executeMeshGenerators()
} }
} }
} }

// Prepare the final mesh
_final_generated_mesh->prepare_for_use();
} }
} }


Expand Down Expand Up @@ -1589,12 +1586,11 @@ MooseApp::createMinimalApp()
{ {
TIME_SECTION(_create_minimal_app_timer); TIME_SECTION(_create_minimal_app_timer);


// SetupMeshAction (setup_mesh) // SetupMeshAction
{ {
// Build the Action parameters // Build the Action parameters
InputParameters action_params = _action_factory.getValidParams("SetupMeshAction"); InputParameters action_params = _action_factory.getValidParams("SetupMeshAction");
action_params.set<std::string>("type") = "GeneratedMesh"; action_params.set<std::string>("type") = "GeneratedMesh";
action_params.set<std::string>("task") = "setup_mesh";


// Create The Action // Create The Action
std::shared_ptr<MooseObjectAction> action = std::static_pointer_cast<MooseObjectAction>( std::shared_ptr<MooseObjectAction> action = std::static_pointer_cast<MooseObjectAction>(
Expand All @@ -1609,19 +1605,6 @@ MooseApp::createMinimalApp()
_action_warehouse.addActionBlock(action); _action_warehouse.addActionBlock(action);
} }


// SetupMeshAction (init_mesh)
{
// Action parameters
InputParameters action_params = _action_factory.getValidParams("SetupMeshAction");
action_params.set<std::string>("type") = "GeneratedMesh";
action_params.set<std::string>("task") = "init_mesh";

// Build the action
std::shared_ptr<Action> action =
_action_factory.create("SetupMeshAction", "Mesh", action_params);
_action_warehouse.addActionBlock(action);
}

// Executioner // Executioner
{ {
// Build the Action parameters // Build the Action parameters
Expand Down
5 changes: 3 additions & 2 deletions framework/src/mesh/FileMesh.C
Expand Up @@ -32,14 +32,15 @@ validParams<FileMesh>()
FileMesh::FileMesh(const InputParameters & parameters) FileMesh::FileMesh(const InputParameters & parameters)
: MooseMesh(parameters), : MooseMesh(parameters),
_file_name(getParam<MeshFileName>("file")), _file_name(getParam<MeshFileName>("file")),
_dim(getParam<MooseEnum>("dim")),
_read_mesh_timer(registerTimedSection("readMesh", 2)) _read_mesh_timer(registerTimedSection("readMesh", 2))
{ {
getMesh().set_mesh_dimension(getParam<MooseEnum>("dim"));
} }


FileMesh::FileMesh(const FileMesh & other_mesh) FileMesh::FileMesh(const FileMesh & other_mesh)
: MooseMesh(other_mesh), : MooseMesh(other_mesh),
_file_name(other_mesh._file_name), _file_name(other_mesh._file_name),
_dim(other_mesh._dim),
_read_mesh_timer(other_mesh._read_mesh_timer) _read_mesh_timer(other_mesh._read_mesh_timer)
{ {
} }
Expand All @@ -57,7 +58,7 @@ FileMesh::buildMesh()
{ {
TIME_SECTION(_read_mesh_timer); TIME_SECTION(_read_mesh_timer);


std::string _file_name = getParam<MeshFileName>("file"); getMesh().set_mesh_dimension(getParam<MooseEnum>("dim"));


if (_is_nemesis) if (_is_nemesis)
{ {
Expand Down

0 comments on commit 5d74fe8

Please sign in to comment.