From 376b3dee9e11db7ab6492e0a6853502a122afb05 Mon Sep 17 00:00:00 2001 From: Sebastian Schunert Date: Wed, 23 Sep 2015 09:50:30 -0600 Subject: [PATCH] Adding PartitionerAction and enabling MooseMesh to accept custom partitioner (#5543) --- framework/include/actions/PartitionerAction.h | 37 ++++++++ framework/include/mesh/MooseMesh.h | 9 ++ framework/src/actions/PartitionerAction.C | 47 ++++++++++ framework/src/base/Moose.C | 2 + framework/src/mesh/MooseMesh.C | 20 ++++- framework/src/parser/MooseSyntax.C | 2 + .../custom_linear_partitioner_test.i | 87 +++++++++++++++++++ .../linear_partitioner_test.i | 82 +++++++++++++++++ 8 files changed, 285 insertions(+), 1 deletion(-) create mode 100644 framework/include/actions/PartitionerAction.h create mode 100644 framework/src/actions/PartitionerAction.C create mode 100644 test/tests/mesh/linear_partitioner/custom_linear_partitioner_test.i create mode 100644 test/tests/mesh/linear_partitioner/linear_partitioner_test.i diff --git a/framework/include/actions/PartitionerAction.h b/framework/include/actions/PartitionerAction.h new file mode 100644 index 000000000000..2b55256ce418 --- /dev/null +++ b/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(); + + +class PartitionerAction: public Action +{ +public: + PartitionerAction(InputParameters params); + + virtual void act(); + +protected: + MooseEnum _partitioner_type; +}; + +#endif //PartitionerAction_H diff --git a/framework/include/mesh/MooseMesh.h b/framework/include/mesh/MooseMesh.h index 40969e154ceb..c8b545869746 100644 --- a/framework/include/mesh/MooseMesh.h +++ b/framework/include/mesh/MooseMesh.h @@ -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. @@ -699,6 +705,9 @@ class MooseMesh : MooseEnum _partitioner_name; bool _partitioner_overridden; + /// The custom partitioner + Partitioner * _custom_partitioner; + /// Convenience enums enum { X = 0, diff --git a/framework/src/actions/PartitionerAction.C b/framework/src/actions/PartitionerAction.C new file mode 100644 index 000000000000..803e170b18df --- /dev/null +++ b/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() +{ + InputParameters params = validParams(); + MooseEnum partitioning("linear=0", "linear"); + + params.addParam ("partitioner", partitioning, "The class name of the partitioner you want to use."); + return params; +} + +PartitionerAction::PartitionerAction(InputParameters params) : + Action(params), + _partitioner_type(getParam("partitioner")) +{ +} + +void +PartitionerAction::act() +{ + switch (_partitioner_type) + { + case 0: + _problem->mesh().setCustomPartitioner(new LinearPartitioner); + break; + } +} diff --git a/framework/src/base/Moose.C b/framework/src/base/Moose.C index 94598b3b8918..c0d711c4b060 100644 --- a/framework/src/base/Moose.C +++ b/framework/src/base/Moose.C @@ -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" @@ -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"); diff --git a/framework/src/mesh/MooseMesh.C b/framework/src/mesh/MooseMesh.C index 672999a9c3cd..9d8d963956ad 100644 --- a/framework/src/mesh/MooseMesh.C +++ b/framework/src/mesh/MooseMesh.C @@ -72,7 +72,7 @@ InputParameters validParams() "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("partitioner", partitioning, "Specifies a mesh partitioner to use when splitting the mesh for a parallel computation."); MooseEnum direction("x y z radial"); params.addParam("centroid_partitioner_direction", direction, "Specifies the sort direction if using the centroid partitioner. Available options: x, y, z, radial"); @@ -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; } } @@ -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), @@ -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) { diff --git a/framework/src/parser/MooseSyntax.C b/framework/src/parser/MooseSyntax.C index d7c9d6ea9439..ec69373047b9 100644 --- a/framework/src/parser/MooseSyntax.C +++ b/framework/src/parser/MooseSyntax.C @@ -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/*"); diff --git a/test/tests/mesh/linear_partitioner/custom_linear_partitioner_test.i b/test/tests/mesh/linear_partitioner/custom_linear_partitioner_test.i new file mode 100644 index 000000000000..2f8fd1c5b5f2 --- /dev/null +++ b/test/tests/mesh/linear_partitioner/custom_linear_partitioner_test.i @@ -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 + [../] +[] diff --git a/test/tests/mesh/linear_partitioner/linear_partitioner_test.i b/test/tests/mesh/linear_partitioner/linear_partitioner_test.i new file mode 100644 index 000000000000..978a69a576e6 --- /dev/null +++ b/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 + [../] +[]