Skip to content

Commit

Permalink
add element ID interface to support using extra element integers idah…
Browse files Browse the repository at this point in the history
  • Loading branch information
YaqiWang committed Aug 22, 2019
1 parent c952125 commit 6073f5f
Show file tree
Hide file tree
Showing 25 changed files with 416 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!template load file=stubs/moose_object.md.template name=ElementIntegerAux syntax=/AuxKernels/ElementIntegerAux
31 changes: 28 additions & 3 deletions framework/doc/content/syntax/Mesh/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

## Overview

In general, MOOSE is not designed for generating finite element meshes. Generally,
[CUBIT](https://cubit.sandia.gov/) from [Sandia National Laboratories](http://www.sandia.gov/) is
In general, MOOSE is not designed for generating finite element meshes currently.
Generally, [CUBIT](https://cubit.sandia.gov/) from [Sandia National Laboratories](http://www.sandia.gov/) is
recommended for creating meshes, especially complex geometries, for use in MOOSE. CUBIT can be
licensed from CSimSoft for a fee depending that varies based on the type of organization and work
being performed. Other mesh generators can work as long as they output a file format that is
Expand Down Expand Up @@ -147,4 +147,29 @@ recycled (because it might be a key to an important map), you should use unique_

The MooseMesh object has a method for building a map (technically a multimap) of paired periodic nodes in the
simulation. This map provides a quick lookup of all paired nodes on a periodic boundary. in the 2D and 3D cases
each corner node will map to 2 or 3 other nodes (respectively).
each corner node will map to 2 or 3 other nodes (respectively).

## Extra integer IDs

Extra integer IDs for all the elements of a mesh can be useful for handling complicated material assignment, performing specific calculations on groups of elements, etc.
Often times, we do not want to use subdomains for these tasks because otherwise too many subdomains can be needed, and in turn large penalty on run-time performance can be introduced.

MooseMesh[MooseMesh.md] has a parameter `extra_integers` to allow users to introduce more integer IDs for elements each identified with a name in the parameter.
When this parameter is specified, extra integers will be made available in `_current_elem` in type of libMesh::Elem available in almost all MOOSE objects like kernels, aux kernels, materials, etc.
To retrieve the integer on an element, one needs first to obtain the index $_id$ with its name in the constructor of the MOOSE object by calling
```
getElementID(integer_name_parameter, comp),
```
where `integer_name_parameter` is the name of the parameter in type of `std::vector<std::string>` of this object listing all integer names.
`comp` is the number of the integer names the returned $_id$ is for.
Then one can obtain the integer associated with the current element with
```
_current_elem->get_extra_integer(_id),
```
where $_id$ is the ID for the extra integer.
Based on this ID, one can proceed with any particular operations, for example, choosing a different set of data for evaluating material properties.

The IDs can be assigned to the mesh elements with mesh modifiers similarly as assigning subdomain IDs.
Currently we only extended SubdomainBoundingBoxGenerator[SubdomainBoundingBoxGenerator.md] for such assignment.
We possibly can enhance the extra integer assignment in the future for example, using an elemental variable in an Exodus file to assign integer IDs.
We note that the element IDs are part of the mesh and will be initialized properly for restart/recover.
4 changes: 3 additions & 1 deletion framework/include/auxkernels/AuxKernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "VectorPostprocessorInterface.h"
#include "MooseVariableInterface.h"
#include "MemberTemplateMacros.h"
#include "ElementIDInterface.h"

// forward declarations
template <typename ComputeValueType>
Expand Down Expand Up @@ -68,7 +69,8 @@ class AuxKernelTempl : public MooseObject,
protected GeometricSearchInterface,
public Restartable,
public MeshChangedInterface,
protected VectorPostprocessorInterface
protected VectorPostprocessorInterface,
public ElementIDInterface
{
public:
AuxKernelTempl(const InputParameters & parameters);
Expand Down
28 changes: 28 additions & 0 deletions framework/include/auxkernels/ElementIntegerAux.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#pragma once

#include "AuxKernel.h"

class ElementIntegerAux;

template <>
InputParameters validParams<ElementIntegerAux>();

class ElementIntegerAux : public AuxKernel
{
public:
ElementIntegerAux(const InputParameters & parameters);

protected:
virtual Real computeValue() override;

unsigned int _id;
};
4 changes: 3 additions & 1 deletion framework/include/ics/InitialConditionBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "BoundaryRestrictable.h"
#include "MooseTypes.h"
#include "MemberTemplateMacros.h"
#include "ElementIDInterface.h"

// forward declarations
class InitialConditionBase;
Expand All @@ -45,7 +46,8 @@ class InitialConditionBase : public MooseObject,
public UserObjectInterface,
public BoundaryRestrictable,
public DependencyResolverInterface,
public Restartable
public Restartable,
public ElementIDInterface
{
public:
/**
Expand Down
39 changes: 39 additions & 0 deletions framework/include/interfaces/ElementIDInterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#pragma once

#include <string>
#include <memory>

class InputParameters;
class MooseObject;
class MooseMesh;

class ElementIDInterface
{
public:
ElementIDInterface(const MooseObject * moose_object);
virtual ~ElementIDInterface() {}

/**
* Gets index of an element integer with a parameter of the object this interface attachs
* @param id_name Name of object parameter
* @param comp Component number for vector of integer names
* @return Index of the element integer to be used in get_extra_integer() function
*/
virtual unsigned int getElementID(const std::string & id_name, unsigned int comp = 0);

private:
/// Reference to the object's input parameters
const InputParameters & _obj_parameters;

/// References to the mesh and displaced mesh (currently in the ActionWarehouse)
std::shared_ptr<MooseMesh> & _mesh;
};
4 changes: 3 additions & 1 deletion framework/include/kernels/KernelBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "Restartable.h"
#include "MeshChangedInterface.h"
#include "TaggingInterface.h"
#include "ElementIDInterface.h"

class MooseMesh;
class SubProblem;
Expand Down Expand Up @@ -55,7 +56,8 @@ class KernelBase : public MooseObject,
protected GeometricSearchInterface,
public Restartable,
public MeshChangedInterface,
public TaggingInterface
public TaggingInterface,
public ElementIDInterface
{
public:
KernelBase(const InputParameters & parameters);
Expand Down
4 changes: 3 additions & 1 deletion framework/include/materials/Material.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "MeshChangedInterface.h"
#include "OutputInterface.h"
#include "RandomInterface.h"
#include "ElementIDInterface.h"

// forward declarations
class Material;
Expand Down Expand Up @@ -61,7 +62,8 @@ class Material : public MooseObject,
public Restartable,
public MeshChangedInterface,
public OutputInterface,
public RandomInterface
public RandomInterface,
public ElementIDInterface
{
public:
Material(const InputParameters & parameters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "MeshGenerator.h"
#include "MooseEnum.h"
#include "ElementIDInterface.h"

#include "libmesh/bounding_box.h"

Expand All @@ -28,7 +29,7 @@ class BoundingBox;
/**
* MeshGenerator for defining a Subdomain inside or outside of a bounding box
*/
class SubdomainBoundingBoxGenerator : public MeshGenerator
class SubdomainBoundingBoxGenerator : public MeshGenerator, public ElementIDInterface
{
public:
SubdomainBoundingBoxGenerator(const InputParameters & parameters);
Expand All @@ -46,5 +47,7 @@ class SubdomainBoundingBoxGenerator : public MeshGenerator

/// Bounding box for testing element centroids against
BoundingBox _bounding_box;
};

/// Whether or not we are setting an element integer instead of subdomain ID
bool _has_id;
};
5 changes: 3 additions & 2 deletions framework/include/userobject/UserObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "ScalarCoupleable.h"
#include "SetupInterface.h"
#include "PerfGraphInterface.h"
#include "ElementIDInterface.h"

#include "libmesh/parallel.h"

Expand All @@ -41,7 +42,8 @@ class UserObject : public MooseObject,
public Restartable,
public MeshChangedInterface,
public ScalarCoupleable,
public PerfGraphInterface
public PerfGraphInterface,
public ElementIDInterface
{
public:
UserObject(const InputParameters & params);
Expand Down Expand Up @@ -152,4 +154,3 @@ class UserObject : public MooseObject,
private:
UserObject * _primary_thread_copy = nullptr;
};

4 changes: 4 additions & 0 deletions framework/src/actions/SetupMeshAction.C
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,16 @@ SetupMeshAction::act()
"\" mesh.");

_type = "MeshGeneratorMesh";
auto saved_params = _moose_object_pars;
_moose_object_pars = _factory.getValidParams("MeshGeneratorMesh");
_moose_object_pars.applyParameters(saved_params);
}
// switch non-file meshes to be a file-mesh if using a pre-split mesh configuration.
if (_app.isUseSplit())
_type = modifyParamsForUseSplit(_moose_object_pars);

// create the mesh and make the mesh pointer available in all actions later on
// and in action warehouse
_mesh = _factory.create<MooseMesh>(_type, "mesh", _moose_object_pars);
}
}
Expand Down
1 change: 1 addition & 0 deletions framework/src/auxkernels/AuxKernel.C
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ AuxKernelTempl<ComputeValueType>::AuxKernelTempl(const InputParameters & paramet
Restartable(this, "AuxKernels"),
MeshChangedInterface(parameters),
VectorPostprocessorInterface(this),
ElementIDInterface(this),
_subproblem(*getCheckedPointerParam<SubProblem *>("_subproblem")),
_sys(*getCheckedPointerParam<SystemBase *>("_sys")),
_nl_sys(*getCheckedPointerParam<SystemBase *>("_nl_sys")),
Expand Down
35 changes: 35 additions & 0 deletions framework/src/auxkernels/ElementIntegerAux.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#include "ElementIntegerAux.h"

registerMooseObject("MooseApp", ElementIntegerAux);

template <>
InputParameters
validParams<ElementIntegerAux>()
{
InputParameters params = validParams<AuxKernel>();
params.addClassDescription("Creates a field showing the element integer.");
params.addParam<std::vector<std::string>>("integer_names", "Element integers to be retrieved");
return params;
}

ElementIntegerAux::ElementIntegerAux(const InputParameters & parameters)
: AuxKernel(parameters), _id(getElementID("integer_names"))
{
if (isNodal())
mooseError("ElementIntegerAux must be for an elemental variable");
}

Real
ElementIntegerAux::computeValue()
{
return _current_elem->get_extra_integer(_id);
}
1 change: 1 addition & 0 deletions framework/src/ics/InitialConditionBase.C
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ InitialConditionBase::InitialConditionBase(const InputParameters & parameters)
BoundaryRestrictable(this, _c_nodal),
DependencyResolverInterface(),
Restartable(this, "InitialConditionBases"),
ElementIDInterface(this),
_sys(*getCheckedPointerParam<SystemBase *>("_sys")),
_ignore_uo_dependency(getParam<bool>("ignore_uo_dependency"))
{
Expand Down
42 changes: 42 additions & 0 deletions framework/src/interfaces/ElementIDInterface.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#include "ElementIDInterface.h"

#include "InputParameters.h"
#include "MooseObject.h"
#include "MooseApp.h"
#include "ActionWarehouse.h"
#include "MooseMesh.h"

#include "libmesh/mesh_base.h"

ElementIDInterface::ElementIDInterface(const MooseObject * moose_object)
: _obj_parameters(moose_object->parameters()),
_mesh(moose_object->getMooseApp().actionWarehouse().mesh())
{
}

unsigned int
ElementIDInterface::getElementID(const std::string & id_name, unsigned int comp)
{
auto & p = _obj_parameters.get<std::vector<std::string>>(id_name);
if (comp >= p.size())
mooseError(id_name, " does not have enough integer names");

if (!_mesh.get())
mooseError("Mesh is not available for getting element integers");

auto mesh_base = _mesh->buildMeshBaseObject();

if (!mesh_base->has_elem_integer(p[comp]))
mooseError("Mesh does not have an element integer names as ", p[comp]);

return mesh_base->get_elem_integer_index(p[comp]);
}
1 change: 1 addition & 0 deletions framework/src/kernels/KernelBase.C
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ KernelBase::KernelBase(const InputParameters & parameters)
Restartable(this, "Kernels"),
MeshChangedInterface(parameters),
TaggingInterface(this),
ElementIDInterface(this),
_subproblem(*getCheckedPointerParam<SubProblem *>("_subproblem")),
_fe_problem(*parameters.get<FEProblemBase *>("_fe_problem_base")),
_sys(*getCheckedPointerParam<SystemBase *>("_sys")),
Expand Down
1 change: 1 addition & 0 deletions framework/src/materials/Material.C
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ Material::Material(const InputParameters & parameters)
*parameters.getCheckedPointerParam<FEProblemBase *>("_fe_problem_base"),
parameters.get<THREAD_ID>("_tid"),
false),
ElementIDInterface(this),
_subproblem(*getCheckedPointerParam<SubProblem *>("_subproblem")),
_fe_problem(*getCheckedPointerParam<FEProblemBase *>("_fe_problem_base")),
_tid(parameters.get<THREAD_ID>("_tid")),
Expand Down
9 changes: 9 additions & 0 deletions framework/src/mesh/MooseMesh.C
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ validParams<MooseMesh>()
"KDTree construction becomes faster but the nearest neighbor search"
"becomes slower.");

params.addParam<std::vector<std::string>>("extra_integers",
"Tags of extra integers in all elements");
params.registerBase("MooseMesh");

// groups
Expand Down Expand Up @@ -2056,6 +2058,13 @@ MooseMesh::buildMeshBaseObject(ParallelType override_type)
if (!getParam<bool>("allow_renumbering"))
mesh->allow_renumbering(false);

if (isParamValid("extra_integers"))
{
auto tags = getParam<std::vector<std::string>>("extra_integers");
for (auto & tag : tags)
mesh->add_elem_integer(tag);
}

return mesh;
}

Expand Down

0 comments on commit 6073f5f

Please sign in to comment.