Skip to content

Commit

Permalink
Distance should be in mesh units
Browse files Browse the repository at this point in the history
  • Loading branch information
LeilaGhaffari committed Aug 20, 2024
1 parent 8bae88a commit ddc90f5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 27 deletions.
2 changes: 1 addition & 1 deletion examples/cube/rectangular_waveguide_user.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"DonorAttributes": [5],
"ReceiverAttributes": [6],
"Direction": "Z",
"Distance": 1.0e-2 // in L0 units
"Distance": 1.0 // in mesh units
}
],
"PEC":
Expand Down
4 changes: 2 additions & 2 deletions palace/utils/configfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1057,8 +1057,8 @@ void PeriodicBoundaryData::SetUp(json &boundaries)
const bool yfound = direction.find("y") != std::string::npos;
const bool zfound = direction.find("z") != std::string::npos;
int direction_count = xfound + yfound + zfound;
MFEM_VERIFY(direction_count <= 1,
"Only one of the X, Y, or Z directions can be specified for the donor/receiver attributes pair!");
MFEM_VERIFY(direction_count <= 1, "Only one of the X, Y, or Z directions can be "
"specified for the donor/receiver attributes pair!");
if (xfound)
{
data.translation[0] = distance;
Expand Down
37 changes: 13 additions & 24 deletions palace/utils/geodata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ constexpr auto MSH_FLT_PRECISION = std::numeric_limits<double>::max_digits10;

// Load the serial mesh from disk.
std::unique_ptr<mfem::Mesh> LoadMesh(const std::string &, bool,
const config::BoundaryData &, double);
const config::BoundaryData &);

// Create a new mesh by splitting all elements of the mesh into simplices or hexes
// (using tet-to-hex). Optionally preserves curvature of the original mesh by interpolating
Expand Down Expand Up @@ -97,8 +97,7 @@ std::unique_ptr<mfem::ParMesh> ReadMesh(MPI_Comm comm, const IoData &iodata)
if ((use_mesh_partitioner && Mpi::Root(comm)) ||
(!use_mesh_partitioner && Mpi::Root(node_comm)))
{
smesh = LoadMesh(iodata.model.mesh, iodata.model.remove_curvature, iodata.boundaries,
iodata.model.L0);
smesh = LoadMesh(iodata.model.mesh, iodata.model.remove_curvature, iodata.boundaries);
MFEM_VERIFY(!(smesh->Nonconforming() && use_mesh_partitioner),
"Cannot use mesh partitioner on a nonconforming mesh!");
}
Expand Down Expand Up @@ -230,8 +229,7 @@ std::unique_ptr<mfem::ParMesh> ReadMesh(MPI_Comm comm, const IoData &iodata)
}
int width = 1 + static_cast<int>(std::log10(Mpi::Size(comm) - 1));
std::unique_ptr<mfem::Mesh> gsmesh =
LoadMesh(iodata.model.mesh, iodata.model.remove_curvature, iodata.boundaries,
iodata.model.L0);
LoadMesh(iodata.model.mesh, iodata.model.remove_curvature, iodata.boundaries);
std::unique_ptr<int[]> gpartitioning = GetMeshPartitioning(*gsmesh, Mpi::Size(comm));
mfem::ParMesh gpmesh(comm, *gsmesh, gpartitioning.get(), 0);
{
Expand Down Expand Up @@ -1668,7 +1666,7 @@ namespace
{

std::unique_ptr<mfem::Mesh> LoadMesh(const std::string &mesh_file, bool remove_curvature,
const config::BoundaryData &boundaries, double L0)
const config::BoundaryData &boundaries)
{
// Read the (serial) mesh from the given mesh file. Handle preparation for refinement and
// orientations here to avoid possible reorientations and reordering later on. MFEM
Expand Down Expand Up @@ -1727,25 +1725,16 @@ std::unique_ptr<mfem::Mesh> LoadMesh(const std::string &mesh_file, bool remove_c
}
if (!boundaries.periodic.empty())
{
mfem::real_t tol = 1E-5 / L0;
auto periodic_mesh = std::move(mesh);
for (auto &data : boundaries.periodic)
{
std::vector<mfem::Vector> translation;
mfem::Vector translation_vec(data.translation.size());
std::copy(data.translation.begin(), data.translation.end(),
translation_vec.GetData());
for (int i = 0; i < translation_vec.Size(); ++i)
{
translation_vec[i] /= L0;
}
translation.push_back(translation_vec);
auto p_mesh = std::make_unique<mfem::Mesh>(mfem::Mesh::MakePeriodic(
*periodic_mesh, periodic_mesh->CreatePeriodicVertexMapping(translation, tol)));
if (p_mesh)
{
periodic_mesh = std::move(p_mesh);
}
for (const auto &data : boundaries.periodic)
{
mfem::Vector translation(data.translation.size());
std::copy(data.translation.begin(), data.translation.end(), translation.GetData());
auto periodic_mapping =
periodic_mesh->CreatePeriodicVertexMapping({translation}, 1E-6);
auto p_mesh = std::make_unique<mfem::Mesh>(
mfem::Mesh::MakePeriodic(*periodic_mesh, periodic_mapping));
periodic_mesh = std::move(p_mesh);
}
mesh = std::move(periodic_mesh);
}
Expand Down

0 comments on commit ddc90f5

Please sign in to comment.