Skip to content

Commit

Permalink
Adding PartitionerAction and enabling MooseMesh to accept custom part…
Browse files Browse the repository at this point in the history
…itioner (idaholab#5543)
  • Loading branch information
Sebastian Schunert committed Sep 23, 2015
1 parent c5d51d8 commit 20f713e
Show file tree
Hide file tree
Showing 10 changed files with 356 additions and 61 deletions.
37 changes: 37 additions & 0 deletions framework/include/actions/PartitionerAction.h
@@ -0,0 +1,37 @@
/****************************************************************/
/* DO NOT MODIFY THIS HEADER */
/* MOOSE - Multiphysics Object Oriented Simulation Environment */
/* */
/* (c) 2010 Battelle Energy Alliance, LLC */
/* ALL RIGHTS RESERVED */
/* */
/* Prepared by Battelle Energy Alliance, LLC */
/* Under Contract No. DE-AC07-05ID14517 */
/* With the U. S. Department of Energy */
/* */
/* See COPYRIGHT for full restrictions */
/****************************************************************/

#ifndef PARTITIONERACTION_H
#define PARTITIONERACTION_H

#include "Action.h"

class PartitionerAction;

template<>
InputParameters validParams<PartitionerAction>();


class PartitionerAction: public Action
{
public:
PartitionerAction(InputParameters params);

virtual void act();

protected:
MooseEnum _partitioner_type;
};

#endif //PartitionerAction_H
9 changes: 9 additions & 0 deletions framework/include/mesh/MooseMesh.h
Expand Up @@ -681,6 +681,12 @@ class MooseMesh :
MooseMesh::MortarInterface * getMortarInterfaceByName(const std::string name);
MooseMesh::MortarInterface * getMortarInterface(BoundaryID master, BoundaryID slave);

/**
* Setter and getter for custom partitioner
*/
Partitioner * getCustomPartitioner() const;
void setCustomPartitioner(Partitioner * custom_partitioner);

protected:
/// Can be set to PARALLEL, SERIAL, or DEFAULT. Determines whether
/// the underlying libMesh mesh is a SerialMesh or ParallelMesh.
Expand All @@ -699,6 +705,9 @@ class MooseMesh :
MooseEnum _partitioner_name;
bool _partitioner_overridden;

/// The custom partitioner
Partitioner * _custom_partitioner;

/// Convenience enums
enum {
X = 0,
Expand Down
47 changes: 47 additions & 0 deletions framework/src/actions/PartitionerAction.C
@@ -0,0 +1,47 @@
/****************************************************************/
/* DO NOT MODIFY THIS HEADER */
/* MOOSE - Multiphysics Object Oriented Simulation Environment */
/* */
/* (c) 2010 Battelle Energy Alliance, LLC */
/* ALL RIGHTS RESERVED */
/* */
/* Prepared by Battelle Energy Alliance, LLC */
/* Under Contract No. DE-AC07-05ID14517 */
/* With the U. S. Department of Energy */
/* */
/* See COPYRIGHT for full restrictions */
/****************************************************************/

#include "PartitionerAction.h"

#include "FEProblem.h"
#include "MooseEnum.h"

#include "libmesh/linear_partitioner.h"

template<>
InputParameters validParams<PartitionerAction>()
{
InputParameters params = validParams<Action>();
MooseEnum partitioning("linear=0", "linear");

params.addParam<MooseEnum> ("partitioner", partitioning, "The class name of the partitioner you want to use.");
return params;
}

PartitionerAction::PartitionerAction(InputParameters params) :
Action(params),
_partitioner_type(getParam<MooseEnum>("partitioner"))
{
}

void
PartitionerAction::act()
{
switch (_partitioner_type)
{
case 0:
_mesh->setCustomPartitioner(new LinearPartitioner());
break;
}
}
33 changes: 18 additions & 15 deletions framework/src/actions/SetupMeshAction.C
Expand Up @@ -137,23 +137,26 @@ void
SetupMeshAction::act()
{
// Create the mesh object and tell it to build itself
_mesh = MooseSharedNamespace::static_pointer_cast<MooseMesh>(_factory.create(_type, "mesh", _moose_object_pars));
_mesh->init();

if (isParamValid("displacements"))
if (_current_task == "setup_mesh")
_mesh = MooseSharedNamespace::static_pointer_cast<MooseMesh>(_factory.create(_type, "mesh", _moose_object_pars));
else if (_current_task == "init_mesh")
{
// Create the displaced mesh
_displaced_mesh = MooseSharedNamespace::static_pointer_cast<MooseMesh>(_factory.create(_type, "displaced_mesh", _moose_object_pars));
_displaced_mesh->init();
_mesh->init();

std::vector<std::string> displacements = getParam<std::vector<std::string> >("displacements");
if (displacements.size() != _displaced_mesh->dimension())
mooseError("Number of displacements and dimension of mesh MUST be the same!");
}
if (isParamValid("displacements"))
{
// Create the displaced mesh
_displaced_mesh = MooseSharedNamespace::static_pointer_cast<MooseMesh>(_factory.create(_type, "displaced_mesh", _moose_object_pars));
_displaced_mesh->init();

setupMesh(_mesh.get());
std::vector<std::string> displacements = getParam<std::vector<std::string> >("displacements");
if (displacements.size() != _displaced_mesh->dimension())
mooseError("Number of displacements and dimension of mesh MUST be the same!");
}

if (_displaced_mesh)
setupMesh(_displaced_mesh.get());
}
setupMesh(_mesh.get());

if (_displaced_mesh)
setupMesh(_displaced_mesh.get());
}
}
7 changes: 7 additions & 0 deletions framework/src/base/Moose.C
Expand Up @@ -349,6 +349,7 @@
#include "AddMaterialAction.h"
#include "GlobalParamsAction.h"
#include "AdaptivityAction.h"
#include "PartitionerAction.h"
#include "SetupDampersAction.h"
#include "CheckIntegrityAction.h"
#include "SetupQuadratureAction.h"
Expand Down Expand Up @@ -759,6 +760,7 @@ addActionTypes(Syntax & syntax)
registerMooseObjectTask("determine_system_type", Executioner, true);

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

registerMooseObjectTask("add_kernel", Kernel, false);
Expand Down Expand Up @@ -817,6 +819,7 @@ addActionTypes(Syntax & syntax)
registerTask("uniform_refine_mesh", false);
registerTask("prepare_mesh", false);
registerTask("setup_mesh_complete", false); // calls prepare
registerTask("setup_partitioner", false);

registerTask("init_displaced_problem", false);

Expand Down Expand Up @@ -871,6 +874,8 @@ addActionTypes(Syntax & syntax)
"(setup_recover_file_base)"
"(check_copy_nodal_vars)"
"(setup_mesh)"
"(setup_partitioner)"
"(init_mesh)"
"(prepare_mesh)"
"(add_mesh_modifier)"
"(add_mortar_interface)"
Expand Down Expand Up @@ -956,6 +961,7 @@ registerActions(Syntax & syntax, ActionFactory & action_factory)
registerAction(SetupPostprocessorDataAction, "setup_postprocessor_data");

registerAction(SetupMeshAction, "setup_mesh");
registerAction(SetupMeshAction, "init_mesh");
registerAction(SetupMeshCompleteAction, "prepare_mesh");
registerAction(AddMeshModifierAction, "add_mesh_modifier");
registerAction(AddMortarInterfaceAction, "add_mortar_interface");
Expand Down Expand Up @@ -1024,6 +1030,7 @@ registerActions(Syntax & syntax, ActionFactory & action_factory)
registerAction(AdaptivityAction, "setup_adaptivity");
#endif

registerAction(PartitionerAction, "setup_partitioner");
registerAction(AddDiracKernelAction, "add_dirac_kernel");
registerAction(SetupDebugAction, "setup_debug");
registerAction(SetupResidualDebugAction, "setup_residual_debug");
Expand Down
2 changes: 2 additions & 0 deletions framework/src/base/MooseApp.C
Expand Up @@ -456,6 +456,8 @@ MooseApp::meshOnly(std::string mesh_file_name)
*/
_action_warehouse.executeActionsWithAction("set_global_params");
_action_warehouse.executeActionsWithAction("setup_mesh");
_action_warehouse.executeActionsWithAction("setup_partitioner");
_action_warehouse.executeActionsWithAction("init_mesh");
_action_warehouse.executeActionsWithAction("prepare_mesh");
_action_warehouse.executeActionsWithAction("add_mesh_modifier");
_action_warehouse.executeActionsWithAction("execute_mesh_modifiers");
Expand Down
111 changes: 65 additions & 46 deletions framework/src/mesh/MooseMesh.C
Expand Up @@ -72,7 +72,7 @@ InputParameters validParams<MooseMesh>()
"In particular you must supply this for GMSH meshes. "
"Note: This is completely ignored for ExodusII meshes!");

MooseEnum partitioning("default=-3 metis=-2 parmetis=-1 linear=0 centroid hilbert_sfc morton_sfc", "default");
MooseEnum partitioning("default=-3 metis=-2 parmetis=-1 linear=0 centroid hilbert_sfc morton_sfc custom", "default");
params.addParam<MooseEnum>("partitioner", partitioning, "Specifies a mesh partitioner to use when splitting the mesh for a parallel computation.");
MooseEnum direction("x y z radial");
params.addParam<MooseEnum>("centroid_partitioner_direction", direction, "Specifies the sort direction if using the centroid partitioner. Available options: x, y, z, radial");
Expand Down Expand Up @@ -155,51 +155,6 @@ MooseMesh::MooseMesh(const InputParameters & parameters) :
}
else
_mesh = new SerialMesh(_communicator, dim);

// Set the partitioner
switch (_partitioner_name)
{
case -3: // default
// We'll use the default partitioner, but notify the user of which one is being used...
if (_use_parallel_mesh)
_partitioner_name = "parmetis";
else
_partitioner_name = "metis";
break;

// No need to explicitily create the metis or parmetis partitioners,
// They are the default for serial and parallel mesh respectively
case -2: // metis
case -1: // parmetis
break;

case 0: // linear
getMesh().partitioner().reset(new LinearPartitioner);
break;
case 1: // centroid
{
if (!isParamValid("centroid_partitioner_direction"))
mooseError("If using the centroid partitioner you _must_ specify centroid_partitioner_direction!");

MooseEnum direction = getParam<MooseEnum>("centroid_partitioner_direction");

if (direction == "x")
getMesh().partitioner().reset(new CentroidPartitioner(CentroidPartitioner::X));
else if (direction == "y")
getMesh().partitioner().reset(new CentroidPartitioner(CentroidPartitioner::Y));
else if (direction == "z")
getMesh().partitioner().reset(new CentroidPartitioner(CentroidPartitioner::Z));
else if (direction == "radial")
getMesh().partitioner().reset(new CentroidPartitioner(CentroidPartitioner::RADIAL));
break;
}
case 2: // hilbert_sfc
getMesh().partitioner().reset(new HilbertSFCPartitioner);
break;
case 3: // morton_sfc
getMesh().partitioner().reset(new MortonSFCPartitioner);
break;
}
}

MooseMesh::MooseMesh(const MooseMesh & other_mesh) :
Expand All @@ -211,6 +166,7 @@ MooseMesh::MooseMesh(const MooseMesh & other_mesh) :
_mesh(other_mesh.getMesh().clone().release()),
_partitioner_name(other_mesh._partitioner_name),
_partitioner_overridden(other_mesh._partitioner_overridden),
_custom_partitioner(other_mesh.getCustomPartitioner()),
_uniform_refine_level(other_mesh.uniformRefineLevel()),
_is_changed(false),
_is_nemesis(false),
Expand Down Expand Up @@ -1743,6 +1699,56 @@ MooseMesh::getNormalByBoundaryID(BoundaryID id) const
void
MooseMesh::init()
{
// Set the partitioner
switch (_partitioner_name)
{
case -3: // default
// We'll use the default partitioner, but notify the user of which one is being used...
if (_use_parallel_mesh)
_partitioner_name = "parmetis";
else
_partitioner_name = "metis";
break;

// No need to explicitily create the metis or parmetis partitioners,
// They are the default for serial and parallel mesh respectively
case -2: // metis
case -1: // parmetis
break;

case 0: // linear
getMesh().partitioner().reset(new LinearPartitioner);
break;
case 1: // centroid
{
if (!isParamValid("centroid_partitioner_direction"))
mooseError("If using the centroid partitioner you _must_ specify centroid_partitioner_direction!");

MooseEnum direction = getParam<MooseEnum>("centroid_partitioner_direction");

if (direction == "x")
getMesh().partitioner().reset(new CentroidPartitioner(CentroidPartitioner::X));
else if (direction == "y")
getMesh().partitioner().reset(new CentroidPartitioner(CentroidPartitioner::Y));
else if (direction == "z")
getMesh().partitioner().reset(new CentroidPartitioner(CentroidPartitioner::Z));
else if (direction == "radial")
getMesh().partitioner().reset(new CentroidPartitioner(CentroidPartitioner::RADIAL));
break;
}
case 2: // hilbert_sfc
getMesh().partitioner().reset(new HilbertSFCPartitioner);
break;
case 3: // morton_sfc
getMesh().partitioner().reset(new MortonSFCPartitioner);
break;
case 4: // custom
if (!_custom_partitioner)
mooseError("If using partitioner type custom you must explicitly provide a partitioner in your input file!");
getMesh().partitioner().reset(_custom_partitioner);
break;
}

if (_app.isRecovering() && _allow_recovery && _app.isUltimateMaster())
// For now, only read the recovery mesh on the Ultimate Master.. sub-apps need to just build their mesh like normal
getMesh().read(_app.getRecoverFileBase() + "_mesh.cpr");
Expand Down Expand Up @@ -2166,6 +2172,19 @@ MooseMesh::getMortarInterface(BoundaryID master, BoundaryID slave)
mooseError("Requesting non-existing mortar interface (master = " << master << ", slave = " << slave << ").");
}

Partitioner *
MooseMesh::getCustomPartitioner() const
{
return _custom_partitioner;
}


void
MooseMesh::setCustomPartitioner(Partitioner * custom_partitioner)
{
_custom_partitioner = custom_partitioner;
}

void
MooseMesh::addMortarInterface(const std::string & name, BoundaryName master, BoundaryName slave, SubdomainName domain_name)
{
Expand Down
2 changes: 2 additions & 0 deletions framework/src/parser/MooseSyntax.C
Expand Up @@ -104,6 +104,8 @@ void associateSyntax(Syntax & syntax, ActionFactory & action_factory)
syntax.registerActionSyntax("AdaptivityAction", "Executioner/Adaptivity");
#endif

syntax.registerActionSyntax("PartitionerAction", "Partitioner");

syntax.registerActionSyntax("AddDiracKernelAction", "DiracKernels/*");

syntax.registerActionSyntax("AddDGKernelAction", "DGKernels/*");
Expand Down

0 comments on commit 20f713e

Please sign in to comment.