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 376b3de
Show file tree
Hide file tree
Showing 8 changed files with 285 additions and 1 deletion.
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:
_problem->mesh().setCustomPartitioner(new LinearPartitioner);
break;
}
}
2 changes: 2 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 @@ -1024,6 +1025,7 @@ registerActions(Syntax & syntax, ActionFactory & action_factory)
registerAction(AdaptivityAction, "setup_adaptivity");
#endif

registerAction(PartitionerAction, "check_copy_nodal_vars");
registerAction(AddDiracKernelAction, "add_dirac_kernel");
registerAction(SetupDebugAction, "setup_debug");
registerAction(SetupResidualDebugAction, "setup_residual_debug");
Expand Down
20 changes: 19 additions & 1 deletion 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 @@ -199,6 +199,11 @@ MooseMesh::MooseMesh(const InputParameters & parameters) :
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;
}
}

Expand All @@ -211,6 +216,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 @@ -2166,6 +2172,18 @@ 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,0 +1,87 @@
[Mesh]
type = GeneratedMesh
dim = 2

nx = 10
ny = 100

xmin = 0.0
xmax = 1.0

ymin = 0.0
ymax = 10.0

partitioner = custom

distribution = serial
[]

[Partitioner]
partitioner_type = linear
[]

[Variables]
active = 'u'

[./u]
order = FIRST
family = LAGRANGE
[../]
[]

[AuxVariables]
[./proc_id]
order = CONSTANT
family = MONOMIAL
[../]
[]

[Kernels]
active = 'diff'

[./diff]
type = Diffusion
variable = u
[../]
[]

[AuxKernels]
[./proc_id]
type = ProcessorIDAux
variable = proc_id
[../]
[]

[BCs]
active = 'left right'

[./left]
type = DirichletBC
variable = u
boundary = 3
value = 0
[../]

[./right]
type = DirichletBC
variable = u
boundary = 1
value = 1
[../]
[]

[Executioner]
type = Steady

# Preconditioned JFNK (default)
solve_type = 'PJFNK'
[]

[Outputs]
file_base = out
[./exodus]
type = Exodus
elemental_as_nodal = true
[../]
[]
82 changes: 82 additions & 0 deletions test/tests/mesh/linear_partitioner/linear_partitioner_test.i
@@ -0,0 +1,82 @@
[Mesh]
type = GeneratedMesh
dim = 2

nx = 10
ny = 100

xmin = 0.0
xmax = 1.0

ymin = 0.0
ymax = 10.0

partitioner = linear

distribution = serial
[]

[Variables]
active = 'u'

[./u]
order = FIRST
family = LAGRANGE
[../]
[]

[AuxVariables]
[./proc_id]
order = CONSTANT
family = MONOMIAL
[../]
[]

[Kernels]
active = 'diff'

[./diff]
type = Diffusion
variable = u
[../]
[]

[AuxKernels]
[./proc_id]
type = ProcessorIDAux
variable = proc_id
[../]
[]

[BCs]
active = 'left right'

[./left]
type = DirichletBC
variable = u
boundary = 3
value = 0
[../]

[./right]
type = DirichletBC
variable = u
boundary = 1
value = 1
[../]
[]

[Executioner]
type = Steady

# Preconditioned JFNK (default)
solve_type = 'PJFNK'
[]

[Outputs]
file_base = out
[./exodus]
type = Exodus
elemental_as_nodal = true
[../]
[]

0 comments on commit 376b3de

Please sign in to comment.