Skip to content

Commit

Permalink
allow loading elemental variables in exodus file for setting extra el…
Browse files Browse the repository at this point in the history
…ement integers idaholab#14916
  • Loading branch information
YaqiWang committed Apr 6, 2020
1 parent d461068 commit 4106b42
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 1 deletion.
11 changes: 11 additions & 0 deletions framework/doc/content/source/auxkernels/ElemExtraIDAux.md
@@ -0,0 +1,11 @@
# ElemExtraIDAux

## Description

This auxiliary kernel copies element integers into an auxiliary variable by evaluating the variable on quadrature points of any element with the element integer of the element.

!syntax parameters /AuxKernels/ElemExtraIDAux

!syntax inputs /AuxKernels/ElemExtraIDAux

!syntax children /AuxKernels/ElemExtraIDAux
Expand Up @@ -23,6 +23,9 @@ supports reading and writing a large number of formats and could be extended to
| .xda, .xdr | libMesh formats |
| .vtk, .pvtu | Visualization Toolkit |

When reading a mesh file in Sandia's ExodusII format, users can use parameter *exodus_extra_element_integers* to load elemental variables for setting extra element integers of the mesh.
The names of the extra element integers will be the same as the names of the element variables in the mesh file.

## Further FileMeshGenerator Documentation

!syntax parameters /MeshGenerators/FileMeshGenerator
Expand Down
31 changes: 31 additions & 0 deletions framework/include/auxkernels/ElemExtraIDAux.h
@@ -0,0 +1,31 @@
//* 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"

// Forward Declarations
class ElemExtraIDAux;

template <>
InputParameters validParams<ElemExtraIDAux>();

class ElemExtraIDAux : public AuxKernel
{
public:
static InputParameters validParams();

ElemExtraIDAux(const InputParameters & parameters);

protected:
virtual Real computeValue() override;

const dof_id_type & _id;
};
35 changes: 35 additions & 0 deletions framework/src/auxkernels/ElemExtraIDAux.C
@@ -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 "ElemExtraIDAux.h"

registerMooseObject("MooseApp", ElemExtraIDAux);

defineLegacyParams(ElemExtraIDAux);

InputParameters
ElemExtraIDAux::validParams()
{
InputParameters params = AuxKernel::validParams();
params.addRequiredParam<std::vector<ExtraElementIDName>>("extra_id_name",
"The extra ID name in the mesh");
params.addClassDescription("Puts element extra IDs into an aux variable.");
return params;
}

ElemExtraIDAux::ElemExtraIDAux(const InputParameters & parameters)
: AuxKernel(parameters), _id(getElementID("extra_id_name"))
{
}

Real
ElemExtraIDAux::computeValue()
{
return _id;
}
25 changes: 24 additions & 1 deletion framework/src/meshgenerators/FileMeshGenerator.C
Expand Up @@ -12,6 +12,8 @@

#include "libmesh/replicated_mesh.h"
#include "libmesh/face_quad4.h"
#include "libmesh/exodusII_io.h"
#include "libmesh/mesh_communication.h"

registerMooseObject("MooseApp", FileMeshGenerator);

Expand All @@ -23,6 +25,9 @@ FileMeshGenerator::validParams()
InputParameters params = MeshGenerator::validParams();

params.addRequiredParam<MeshFileName>("file", "The filename to read.");
params.addParam<std::vector<std::string>>(
"exodus_extra_element_integers",
"The variable names in the mesh file for loading extra element integers");

return params;
}
Expand All @@ -37,7 +42,25 @@ FileMeshGenerator::generate()
{
auto mesh = _mesh->buildMeshBaseObject();

mesh->read(_file_name);
bool exodus =
_file_name.rfind(".exd") < _file_name.size() || _file_name.rfind(".e") < _file_name.size();
bool has_exodus_integers = isParamValid("exodus_extra_element_integers");
if (exodus && has_exodus_integers)
{
if (mesh->processor_id() == 0)
{
ExodusII_IO io(*mesh);
io.set_extra_integer_vars(
getParam<std::vector<std::string>>("exodus_extra_element_integers"));
io.read(_file_name);
}
MeshCommunication().broadcast(*mesh);
mesh->prepare_for_use(false, false);
}
else if (!has_exodus_integers)
mesh->read(_file_name);
else
mooseError("\"exodus_extra_element_integers\" should be given only for Exodus mesh files");

return dynamic_pointer_cast<MeshBase>(mesh);
}
@@ -0,0 +1,35 @@
[Mesh]
[material_id_mesh]
type = FileMeshGenerator
file = mesh_with_material_id.e
exodus_extra_element_integers = material_id
[]
[]

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

[AuxKernels]
[set_material_id]
type = ElemExtraIDAux
variable = material_id
extra_id_name = material_id
[]
[]

[Problem]
kernel_coverage_check = false
solve = false
[]

[Executioner]
type = Steady
[]

[Outputs]
exodus = true
[]
Binary file not shown.
Binary file not shown.
10 changes: 10 additions & 0 deletions test/tests/meshgenerators/file_mesh_generator/tests
Expand Up @@ -11,4 +11,14 @@
design = 'meshgenerators/FileMeshGenerator.md'
issues = '#11640'
[../]
[./extra_integer_test]
type = 'Exodiff'
input = 'exodus_file_mesh_with_id.i'
exodiff = 'exodus_file_mesh_with_id_out.e'
recover = false

requirement = 'The system shall have the ability to assign element extra integers with elemental variables in an Exodus mesh file.'
design = 'meshgenerators/FileMeshGenerator.md'
issues = '#14916'
[../]
[]

0 comments on commit 4106b42

Please sign in to comment.