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 Oct 10, 2019
1 parent a29d9c2 commit bf47ec4
Show file tree
Hide file tree
Showing 27 changed files with 451 additions and 13 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
24 changes: 23 additions & 1 deletion framework/doc/content/syntax/Mesh/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,26 @@ 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 through `Assembly` for almost all MOOSE objects like kernels, aux kernels, materials, etc.
To retrieve the integer on an element, one needs to simply call
```
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.
It is noticed that the returned value of this function call must be in type of `const dof_id_type &`.
A const reference is used to refer the value set in `Assembly`.
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;

const dof_id_type & _id;
};
7 changes: 7 additions & 0 deletions framework/include/base/Assembly.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,11 @@ class Assembly
*/
const MooseArray<std::vector<Point>> & tangents() const { return _current_tangents; }

/**
* Returns an integer ID of the current element given the index associated with the integer
*/
const dof_id_type & extraElemID(unsigned int id) const { return _extra_elem_ids[id]; }

template <ComputeStage compute_stage>
const ADPoint & adNormals() const
{
Expand Down Expand Up @@ -1680,6 +1685,8 @@ class Assembly
std::vector<Eigen::Map<RealDIMValue>> _mapped_normals;
/// The current tangent vectors at the quadrature points
MooseArray<std::vector<Point>> _current_tangents;
/// Extra element IDs
std::vector<dof_id_type> _extra_elem_ids;
/// Holds face qrules for each dimension
std::map<unsigned int, QBase *> _holder_qrule_face;
/// Holds pointers to the dimension's q_points on a face
Expand Down
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
49 changes: 49 additions & 0 deletions framework/include/interfaces/ElementIDInterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//* 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 Integer for the current element
*/
virtual unsigned int getElementIDIndex(const std::string & id_parameter_name,
unsigned int comp = 0) const;

/**
* Gets 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 Integer for the current element
*/
virtual const dof_id_type & getElementID(const std::string & id_parameter_name,
unsigned int comp = 0) const;

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;
};

2 changes: 2 additions & 0 deletions framework/src/actions/SetupMeshAction.C
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ SetupMeshAction::act()
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 _id;
}
5 changes: 5 additions & 0 deletions framework/src/base/Assembly.C
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ Assembly::Assembly(SystemBase & sys, THREAD_ID tid)
// Prerequest xyz so that it is computed for _fe_msm so that it can be used for calculating
// _coord_msm
_fe_msm->get_xyz();

_extra_elem_ids.resize(_mesh.getMesh().n_elem_integers());
}

Assembly::~Assembly()
Expand Down Expand Up @@ -665,6 +667,9 @@ Assembly::reinitFE(const Elem * elem)
}
}

for (unsigned int i = 0; i < _extra_elem_ids.size(); ++i)
_extra_elem_ids[i] = _current_elem->get_extra_integer(i);

if (_xfem != nullptr)
modifyWeightsDueToXFEM(elem);
}
Expand Down
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
61 changes: 61 additions & 0 deletions framework/src/interfaces/ElementIDInterface.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//* 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 "SubProblem.h"
#include "Assembly.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::getElementIDIndex(const std::string & id_parameter_name,
unsigned int comp) const
{
auto & p = _obj_parameters.get<std::vector<std::string>>(id_parameter_name);
if (comp >= p.size())
mooseError(id_parameter_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]);

unsigned int id = mesh_base->get_elem_integer_index(p[comp]);

return id;
}

const unsigned int &
ElementIDInterface::getElementID(const std::string & id_parameter_name, unsigned int comp) const
{
unsigned int id = getElementIDIndex(id_parameter_name, comp);

auto & _subproblem = *_obj_parameters.getCheckedPointerParam<SubProblem *>("_subproblem");

auto tid = _obj_parameters.get<THREAD_ID>("_tid");

auto & assembly = _subproblem.assembly(tid);

return assembly.extraElemID(id);
}

0 comments on commit bf47ec4

Please sign in to comment.