Skip to content

Commit

Permalink
try using mesh integers but get error idaholab#13764
Browse files Browse the repository at this point in the history
  • Loading branch information
YaqiWang committed Jul 19, 2019
1 parent c0c5e7c commit 0582fe8
Show file tree
Hide file tree
Showing 10 changed files with 304 additions and 6 deletions.
29 changes: 26 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,27 @@ 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
```
_mesh.getMesh().get_elem_integer_index(integer_name),
```
where `integer_name` is the integer name in type of standard string.
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 SubdomainBoundingBox[SubdomainBoundingBox.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.
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;
};
2 changes: 2 additions & 0 deletions framework/src/actions/SetupMeshAction.C
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ SetupMeshAction::act()
}
}

// 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
37 changes: 37 additions & 0 deletions framework/src/auxkernels/ElementIntegerAux.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//* 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::string>("integer_name",
"Element integer to be assigned (default to subdomain ID)");
return params;
}

ElementIntegerAux::ElementIntegerAux(const InputParameters & parameters)
: AuxKernel(parameters),
_id(_mesh.getMesh().get_elem_integer_index(getParam<std::string>("integer_name")))
{
if (isNodal())
mooseError("ElementIntegerAux must be for an elemental variable");
}

Real
ElementIntegerAux::computeValue()
{
return _current_elem->get_extra_integer(_id);
}
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 @@ -2049,6 +2051,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
23 changes: 20 additions & 3 deletions framework/src/meshmodifiers/SubdomainBoundingBox.C
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ validParams<SubdomainBoundingBox>()
params.addParam<MooseEnum>(
"location", location, "Control of where the subdomain id is to be set");

params.addParam<std::string>("integer_name",
"Element integer to be assigned (default to subdomain ID)");
return params;
}

Expand All @@ -54,17 +56,32 @@ SubdomainBoundingBox::modify()
if (!_mesh_ptr)
mooseError("_mesh_ptr must be initialized before calling SubdomainBoundingBox::modify()");

bool has_id = isParamValid("integer_name");
unsigned int id = 0;
if (has_id)
id = _mesh_ptr->getMesh().get_elem_integer_index(getParam<std::string>("integer_name"));

// Loop over the elements
for (const auto & elem : _mesh_ptr->getMesh().active_element_ptr_range())
{
bool contains = _bounding_box.contains_point(elem->centroid());
if (contains && _location == "INSIDE")
elem->subdomain_id() = _block_id;
{
if (has_id)
elem->set_extra_integer(id, _block_id);
else
elem->subdomain_id() = _block_id;
}
else if (!contains && _location == "OUTSIDE")
elem->subdomain_id() = _block_id;
{
if (has_id)
elem->set_extra_integer(id, _block_id);
else
elem->subdomain_id() = _block_id;
}
}

// Assign block name, if provided
if (isParamValid("block_name"))
if (isParamValid("block_name") && !has_id)
_mesh_ptr->getMesh().subdomain_name(_block_id) = getParam<SubdomainName>("block_name");
}
30 changes: 30 additions & 0 deletions test/include/materials/ConstantIDMaterial.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//* 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 "Material.h"

class ConstantIDMaterial;

template <>
InputParameters validParams<ConstantIDMaterial>();

class ConstantIDMaterial : public Material
{
public:
ConstantIDMaterial(const InputParameters & parameters);

protected:
virtual void computeQpProperties() override;

unsigned int _id;
MaterialProperty<Real> & _prop;
std::vector<Real> _values;
};
39 changes: 39 additions & 0 deletions test/src/materials/ConstantIDMaterial.C
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

#include "ConstantIDMaterial.h"

registerMooseObject("MooseTestApp", ConstantIDMaterial);

template <>
InputParameters
validParams<ConstantIDMaterial>()
{
InputParameters params = validParams<Material>();
params.addRequiredParam<MaterialPropertyName>("prop_name", "The name of the property");
params.addRequiredParam<std::vector<Real>>(
"prop_values", "List of values to be used for property values based on element integer");
params.addRequiredParam<std::string>("id_name", "The element integer name");

return params;
}

ConstantIDMaterial::ConstantIDMaterial(const InputParameters & parameters)
: Material(parameters),
_id(_mesh.getMesh().get_elem_integer_index(getParam<std::string>("id_name"))),
_prop(declareProperty<Real>(getParam<MaterialPropertyName>("prop_name"))),
_values(getParam<std::vector<Real>>("prop_values"))
{
}

void
ConstantIDMaterial::computeQpProperties()
{
_prop[_qp] = _values[_current_elem->get_extra_integer(_id)];
}
103 changes: 103 additions & 0 deletions test/tests/auxkernels/mesh_integer/mesh_integer.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
[Mesh]
type = GeneratedMesh
dim = 2
xmin = 0
xmax = 1
ymin = 0
ymax = 1
nx = 5
ny = 5
extra_integers = 'material_id'
[]

[MeshModifiers]
[set_material_id0]
type = SubdomainBoundingBox
bottom_left = '0 0 0'
top_right = '0.8 0.6 0'
block_id = 0
location = INSIDE
integer_name = material_id
[]
[set_material_id1]
type = SubdomainBoundingBox
bottom_left = '0 0 0'
top_right = '0.8 0.6 0'
block_id = 1
location = OUTSIDE
integer_name = material_id
[]
[]

[Variables]
[u][]
[]

[Kernels]
[diff]
type = MatDiffusion
variable = u
diffusivity = dc
[]
[timederivative]
type = TimeDerivative
variable = u
[]
[sourceterm]
type = BodyForce
variable = u
function = 1
[]
[]

[AuxVariables]
[id]
family = MONOMIAL
order = CONSTANT
[]
[]

[AuxKernels]
[id]
type = ElementIntegerAux
variable = id
integer_name = material_id
[]
[]

[BCs]
[vacuum]
type = VacuumBC
variable = u
boundary = 'right left top bottom'
[]
[]

[Materials]
[dc]
type = ConstantIDMaterial
prop_name = dc
prop_values = '1 2'
id_name = material_id
[]
[]

[Postprocessors]
[unorm]
type = ElementL2Norm
variable = u
[]
[]

[Executioner]
type = Transient

end_time = 0.1
dt = 0.01
nl_abs_tol = 1.e-15
[]

[Outputs]
execute_on = 'timestep_end'
exodus = true
[]
10 changes: 10 additions & 0 deletions test/tests/auxkernels/mesh_integer/tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Tests]
issues = '#13764'
design = 'syntax/Mesh/index.md'
[./mesh_integer]
type = 'Exodiff'
input = 'mesh_integer.i'
exodiff = 'mesh_integer_out.e'
requirement = "MOOSE shall include the ability to use extra element integers."
[../]
[]

0 comments on commit 0582fe8

Please sign in to comment.