Skip to content

Commit

Permalink
Merge pull request #23 from aurora-multiphysics/HenriqueBR/Refinement
Browse files Browse the repository at this point in the history
Mesh Refinement
  • Loading branch information
alexanderianblair authored Aug 13, 2024
2 parents b7bb15a + 65ae7be commit 21c8d76
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 2 deletions.
5 changes: 5 additions & 0 deletions include/mesh/MFEMMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ class MFEMMesh : public FileMesh
*/
void buildDummyMooseMesh();

/**
* Performs a uniform refinement on the chosen mesh @nref times.
*/
void uniformRefinement(mfem::Mesh & mesh, int nref);

/**
* Smart pointers to mfem::ParMesh object. Do not access directly.
* Use the accessors instead.
Expand Down
33 changes: 33 additions & 0 deletions src/mesh/MFEMMesh.C
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,19 @@ InputParameters
MFEMMesh::validParams()
{
InputParameters params = FileMesh::validParams();
params.addParam<int>(
"serial_refine",
0,
"Number of serial refinements to perform on the mesh. Equivalent to uniform_refine.");
params.addParam<int>(
"uniform_refine",
0,
"Number of serial refinements to perform on the mesh. Equivalent to serial_refine");
params.addParam<int>(
"parallel_refine", 0, "Number of parallel refinements to perform on the mesh.");

params.addClassDescription("Class to read in and store an mfem::ParMesh from file.");

return params;
}

Expand All @@ -33,7 +45,20 @@ MFEMMesh::buildMesh()

// Build the MFEM ParMesh from a serial MFEM mesh
mfem::Mesh mfem_ser_mesh(getFileName());

if (isParamSetByUser("serial_refine") && isParamSetByUser("uniform_refine"))
paramError(
"Cannot define serial_refine and uniform_refine to be nonzero at the same time (they "
"are the same variable). Please choose one.\n");

uniformRefinement(mfem_ser_mesh,
isParamSetByUser("serial_refine") ? getParam<int>("serial_refine")
: getParam<int>("uniform_refine"));

_mfem_par_mesh = std::make_shared<mfem::ParMesh>(MPI_COMM_WORLD, mfem_ser_mesh);

// Perform parallel refinements
uniformRefinement(*_mfem_par_mesh, getParam<int>("parallel_refine"));
}

void
Expand All @@ -58,6 +83,14 @@ MFEMMesh::buildDummyMooseMesh()
getMesh().prepare_for_use();
}

void
MFEMMesh::uniformRefinement(mfem::Mesh & mesh, int nref)
{

for (int i = 0; i < nref; ++i)
mesh.UniformRefinement();
}

std::unique_ptr<MooseMesh>
MFEMMesh::safeClone() const
{
Expand Down
30 changes: 28 additions & 2 deletions unit/src/MFEMMeshTest.C
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class MFEMMeshTest : public ::testing::Test
{
protected:
void SetUp() override;
void buildMFEMMesh(MeshFileName filename);
void buildMFEMMesh(MeshFileName filename, int serial_ref = 0, int parallel_ref = 0);

std::shared_ptr<MooseApp> _app;
Factory * _factory;
Expand All @@ -30,10 +30,12 @@ MFEMMeshTest::SetUp()
* Helper method to set up and build mesh given mesh filename.
*/
void
MFEMMeshTest::buildMFEMMesh(MeshFileName filename)
MFEMMeshTest::buildMFEMMesh(MeshFileName filename, int serial_ref, int parallel_ref)
{
InputParameters params = _factory->getValidParams(_mesh_type);
params.set<MeshFileName>("file") = filename;
params.set<int>("serial_refine") = serial_ref;
params.set<int>("parallel_refine") = parallel_ref;
_mfem_mesh_ptr = _factory->create<MFEMMesh>(_mesh_type, "moose_mesh", params);
_app->actionWarehouse().mesh() = _mfem_mesh_ptr;
_mfem_mesh_ptr->setMeshBase(_mfem_mesh_ptr->buildMeshBaseObject());
Expand Down Expand Up @@ -120,3 +122,27 @@ TEST_F(MFEMMeshTest, MFEMHighOrderMeshFormatReader)
// Test MFEMMesh can be cloned
ASSERT_NE(_mfem_mesh_ptr->safeClone(), nullptr);
}

TEST_F(MFEMMeshTest, Refinement)
{
buildMFEMMesh("data/fichera-q3.mesh", 1, 2);
mfem::ParMesh & pmesh(_mfem_mesh_ptr->getMFEMParMesh());

// Check expected number of vertices have been read
EXPECT_EQ(pmesh.GetNV(), 4401);
// Check expected number of elements have been read
EXPECT_EQ(pmesh.GetNE(), 3584);
// Check expected number of boundary elements have been read
EXPECT_EQ(pmesh.GetNBE(), 1536);
// Check expected number of edges have been read
EXPECT_EQ(pmesh.GetNEdges(), 12336);
// Check expected number of faces have been read
EXPECT_EQ(pmesh.GetNFaces(), 11520);
// Check expected number of boundary attributes (sidesets) have been read
EXPECT_EQ(pmesh.bdr_attributes.Size(), 24);
// Check expected number of element attributes (blocks) have been read
EXPECT_EQ(pmesh.attributes.Size(), 1);

// Test MFEMMesh can be cloned
ASSERT_NE(_mfem_mesh_ptr->safeClone(), nullptr);
}

0 comments on commit 21c8d76

Please sign in to comment.