Skip to content

Commit

Permalink
Make partitioner a plugin system like preconditioner. (idaholab#5543)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Schunert committed Sep 28, 2015
1 parent e5d3a14 commit 971c0a3
Show file tree
Hide file tree
Showing 18 changed files with 588 additions and 61 deletions.
34 changes: 34 additions & 0 deletions framework/include/actions/PartitionerAction.h
@@ -0,0 +1,34 @@
/****************************************************************/
/* 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 "MooseObjectAction.h"

class PartitionerAction;

template<>
InputParameters validParams<PartitionerAction>();


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

virtual void act();
};

#endif //PartitionerAction_H
3 changes: 2 additions & 1 deletion framework/include/base/Factory.h
Expand Up @@ -65,7 +65,7 @@
#define registerSplit(name) registerObject(name)
#define registerOutput(name) registerObject(name)
#define registerControl(name) registerObject(name)

#define registerPartitioner(name) registerObject(name)

#define registerNamedKernel(obj, name) registerNamedObject(obj, name)
#define registerNamedBoundaryCondition(obj, name) registerNamedObject(obj, name)
Expand Down Expand Up @@ -96,6 +96,7 @@
#define registerNamedSplit(obj, name) registerNamedObject(obj, name)
#define registerNamedOutput(obj, name) registerNamedObject(obj, name)
#define registerNamedControl(obj, name) registerNamedObject(obj, name)
#define registerNamedPartitioner(obj, name) registerNamedObject(obj, name)

/**
* Typedef to wrap shared pointer type
Expand Down
16 changes: 16 additions & 0 deletions framework/include/mesh/MooseMesh.h
Expand Up @@ -681,6 +681,18 @@ 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);

/**
* Setter and getter for _custom_partitioner_requested
*/
bool isCustomPartitionerRequested() const;
void setIsCustomPartitionerRequested(bool cpr);

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

/// The custom partitioner
Partitioner * _custom_partitioner;
bool _custom_partitioner_requested;

/// Convenience enums
enum {
X = 0,
Expand Down
37 changes: 37 additions & 0 deletions framework/include/partitioner/LibmeshPartitioner.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 LIBMESHPARTITIONER_H
#define LIBMESHPARTITIONER_H

#include "MoosePartitioner.h"

class LibmeshPartitioner;

template<>
InputParameters validParams<LibmeshPartitioner>();

class LibmeshPartitioner : public MoosePartitioner
{
public:
LibmeshPartitioner(const InputParameters & params);
virtual ~LibmeshPartitioner();

virtual Partitioner * getPartitioner();
protected:
Partitioner * _partitioner;
MooseEnum _partitioner_name;
};

#endif /* LIBMESHPARTITIONER_H */
48 changes: 48 additions & 0 deletions framework/include/partitioner/MoosePartitioner.h
@@ -0,0 +1,48 @@
/****************************************************************/
/* 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 MOOSEPARTITIONER_H
#define MOOSEPARTITIONER_H

#include "MooseObject.h"
#include "Restartable.h"

#include "libmesh/partitioner.h"

//Forward declarations
namespace libMesh
{
class MeshBase;
}

class MoosePartitioner;

template<>
InputParameters validParams<MoosePartitioner>();

/**
* Base class for MOOSE partitioner
*/
class MoosePartitioner :
public MooseObject,
public Restartable
{
public:
MoosePartitioner(const InputParameters & params);
virtual ~MoosePartitioner();

virtual Partitioner * getPartitioner() = 0;
};

#endif /* MOOSEPARTITIONER_H */
39 changes: 39 additions & 0 deletions framework/src/actions/PartitionerAction.C
@@ -0,0 +1,39 @@
/****************************************************************/
/* 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 "MoosePartitioner.h"

template<>
InputParameters validParams<PartitionerAction>()
{
InputParameters params = validParams<MooseObjectAction>();
return params;
}

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

void
PartitionerAction::act()
{
_mesh->setIsCustomPartitionerRequested(true);
MooseSharedPointer<MoosePartitioner> mp = MooseSharedNamespace::static_pointer_cast<MoosePartitioner>(_factory.create(_type, _name, _moose_object_pars));
_mesh->setCustomPartitioner(mp->getPartitioner());
}
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());
}
}
13 changes: 13 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 @@ -401,6 +402,9 @@
// Controls
#include "RealFunctionControl.h"

// Partitioner
#include "LibmeshPartitioner.h"

namespace Moose {

static bool registered = false;
Expand Down Expand Up @@ -733,6 +737,9 @@ registerObjects(Factory & factory)
// Controls
registerControl(RealFunctionControl);

// Partitioner
registerPartitioner(LibmeshPartitioner);

registered = true;
}

Expand Down Expand Up @@ -760,6 +767,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 @@ -804,6 +812,7 @@ addActionTypes(Syntax & syntax)
registerMooseObjectTask("add_output", Output, false);

registerMooseObjectTask("add_control", Control, false);
registerMooseObjectTask("add_partitioner", MoosePartitioner, false);

registerTask("dynamic_object_registration", false);
registerTask("common_output", true);
Expand Down Expand Up @@ -872,6 +881,8 @@ addActionTypes(Syntax & syntax)
"(setup_recover_file_base)"
"(check_copy_nodal_vars)"
"(setup_mesh)"
"(add_partitioner)"
"(init_mesh)"
"(prepare_mesh)"
"(add_mesh_modifier)"
"(add_mortar_interface)"
Expand Down Expand Up @@ -957,6 +968,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 @@ -1025,6 +1037,7 @@ registerActions(Syntax & syntax, ActionFactory & action_factory)
registerAction(AdaptivityAction, "setup_adaptivity");
#endif

registerAction(PartitionerAction, "add_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("add_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

0 comments on commit 971c0a3

Please sign in to comment.