Skip to content

Commit

Permalink
Improve log printing
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastiangrimberg committed Mar 4, 2024
1 parent fd68098 commit 9ff2cac
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 36 deletions.
3 changes: 1 addition & 2 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ the frequency or time domain, using the

- Improved adaptive mesh refinement (AMR) support for transient simulations and numeric
wave ports on nonconformal meshes
- GPU support
- Perfectly matched layer (PML) boundaries
- Periodic boundaries with phase delay constraints
- Automatic mesh generation
- Automatic mesh generation and optimization
17 changes: 9 additions & 8 deletions palace/drivers/basesolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,11 @@ void BaseSolver::SolveEstimateMarkRefine(std::vector<std::unique_ptr<Mesh>> &mes
{
BlockTimer bt(Timer::ADAPTATION);
Mpi::Print("\nAdaptive mesh refinement (AMR) iteration {:d}:\n"
" Indicator norm = {:.3e}, size = {:d}\n"
" Maximum iterations = {:d}, tol. = {:.3e}{}\n",
" Indicator norm = {:.3e}, global unknowns = {:d}\n"
" Max. iterations = {:d}, tol. = {:.3e}{}\n",
++it, err, ntdof, refinement.max_it, refinement.tol,
(refinement.max_size > 0
? ", maximum size = " + std::to_string(refinement.max_size)
? ", max. size = " + std::to_string(refinement.max_size)
: ""));

// Optionally save off the previous solution.
Expand All @@ -210,7 +210,8 @@ void BaseSolver::SolveEstimateMarkRefine(std::vector<std::unique_ptr<Mesh>> &mes
const auto initial_elem_count = fine_mesh.GetGlobalNE();
fine_mesh.GeneralRefinement(marked_elements, -1, refinement.max_nc_levels);
const auto final_elem_count = fine_mesh.GetGlobalNE();
Mpi::Print(" Mesh refinement added {:d} elements (initial: {}, final: {})\n",
Mpi::Print(" {} mesh refinement added {:d} elements (initial = {:d}, final = {:d})\n",
fine_mesh.Nonconforming() ? "Nonconforming" : "Conforming",
final_elem_count - initial_elem_count, initial_elem_count, final_elem_count);

// Optionally rebalance and write the adapted mesh to file.
Expand All @@ -223,7 +224,7 @@ void BaseSolver::SolveEstimateMarkRefine(std::vector<std::unique_ptr<Mesh>> &mes
Mpi::GlobalMin(1, &min_elem, comm);
Mpi::GlobalMax(1, &max_elem, comm);
const auto ratio_post = double(max_elem) / min_elem;
Mpi::Print(" Rebalanced mesh: Ratio {:.3f} exceeded maximum allowed value {:.3f} "
Mpi::Print(" Rebalanced mesh: Ratio {:.3f} exceeded max. allowed value {:.3f} "
"(new ratio = {:.3f})\n",
ratio_pre, refinement.maximum_imbalance, ratio_post);
}
Expand All @@ -235,11 +236,11 @@ void BaseSolver::SolveEstimateMarkRefine(std::vector<std::unique_ptr<Mesh>> &mes
err = indicators.Norml2(comm);
}
Mpi::Print("\nCompleted {:d} iteration{} of adaptive mesh refinement (AMR):\n"
" Indicator norm = {:.3e}, size = {:d}\n"
" Maximum iterations = {:d}, tol. = {:.3e}{}\n",
" Indicator norm = {:.3e}, global unknowns = {:d}\n"
" Max. iterations = {:d}, tol. = {:.3e}{}\n",
it, (it == 1 ? "" : "s"), err, ntdof, refinement.max_it, refinement.tol,
(refinement.max_size > 0
? ", maximum size = " + std::to_string(refinement.max_size)
? ", max. size = " + std::to_string(refinement.max_size)
: ""));
}

Expand Down
4 changes: 2 additions & 2 deletions palace/models/waveportoperator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -888,8 +888,8 @@ void WavePortData::Initialize(double omega)
MFEM_ASSERT(e0.Size() == 0,
"Unexpected non-empty port FE space in wave port boundary mode solve!");
}
e0.Real().ReadWrite(); // Ensure memory is allocated on device before aliasing
e0.Imag().ReadWrite();
e0.Real().Read(); // Ensure memory is allocated on device before aliasing
e0.Imag().Read();
Vector e0tr(e0.Real(), 0, port_nd_fespace->GetTrueVSize());
Vector e0nr(e0.Real(), port_nd_fespace->GetTrueVSize(),
port_h1_fespace->GetTrueVSize());
Expand Down
64 changes: 40 additions & 24 deletions palace/utils/geodata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ std::unique_ptr<mfem::Mesh> LoadMesh(const std::string &, bool);

// Optionally reorder mesh elements based on MFEM's internal reordeing tools for improved
// cache usage.
void ReorderMesh(mfem::Mesh &);
void ReorderMesh(mfem::Mesh &, bool = true);

// Generate element-based mesh partitioning, using either a provided file or METIS.
std::unique_ptr<int[]> GetMeshPartitioning(mfem::Mesh &, int, const std::string & = "");
std::unique_ptr<int[]> GetMeshPartitioning(mfem::Mesh &, int, const std::string & = "",
bool = true);

// Cleanup the provided serial mesh by removing unnecessary domain and elements, adding
// boundary elements for material interfaces and exterior boundaries, and adding boundary
Expand Down Expand Up @@ -1223,7 +1224,7 @@ mfem::Vector GetSurfaceNormal(const mfem::ParMesh &mesh, const mfem::Array<int>
Mpi::GlobalMin(1, &rank, comm);
if (rank == Mpi::Size(comm))
{
// No boundary elements of attribute attr.
// No boundary elements are marked.
normal = 0.0;
return normal;
}
Expand All @@ -1246,16 +1247,18 @@ mfem::Vector GetSurfaceNormal(const mfem::ParMesh &mesh, const mfem::Array<int>
}
normal /= normal.Norml2();

// if (dim == 3)
// {
// Mpi::Print(comm, " Surface normal {:d} = ({:+.3e}, {:+.3e}, {:+.3e})", attr,
// normal(0), normal(1), normal(2));
// }
// else
// {
// Mpi::Print(comm, " Surface normal {:d} = ({:+.3e}, {:+.3e})", attr, normal(0),
// normal(1));
// }
if constexpr (false)
{
if (dim == 3)
{
Mpi::Print(comm, " Surface normal = ({:+.3e}, {:+.3e}, {:+.3e})", normal(0),
normal(1), normal(2));
}
else
{
Mpi::Print(comm, " Surface normal = ({:+.3e}, {:+.3e})", normal(0), normal(1));
}
}

return normal;
}
Expand Down Expand Up @@ -1288,7 +1291,7 @@ double RebalanceMesh(mfem::ParMesh &mesh, const IoData &iodata, double tol)
{
sfile += '/';
}
sfile += "serial.mesh";
sfile += std::filesystem::path(iodata.model.mesh).stem().string() + ".mesh";

auto PrintSerial = [&](mfem::Mesh &smesh)
{
Expand Down Expand Up @@ -1450,7 +1453,7 @@ std::unique_ptr<mfem::Mesh> LoadMesh(const std::string &path, bool remove_curvat
return mesh;
}

void ReorderMesh(mfem::Mesh &mesh)
void ReorderMesh(mfem::Mesh &mesh, bool print)
{
mfem::Array<int> ordering;

Expand All @@ -1471,7 +1474,10 @@ void ReorderMesh(mfem::Mesh &mesh)
best_cost = cost;
}
}
Mpi::Print("Final cost: {:e}\n", best_cost);
if (print)
{
Mpi::Print("Final cost: {:e}\n", best_cost);
}
}

// (Faster) Hilbert reordering.
Expand All @@ -1480,16 +1486,19 @@ void ReorderMesh(mfem::Mesh &mesh)
}

std::unique_ptr<int[]> GetMeshPartitioning(mfem::Mesh &mesh, int size,
const std::string &partition)
const std::string &partition, bool print)
{
MFEM_VERIFY(size <= mesh.GetNE(), "Mesh partitioning must have parts <= mesh elements ("
<< size << " vs. " << mesh.GetNE() << ")!");
if (partition.length() == 0)
{
const int part_method = 1;
std::unique_ptr<int[]> partitioning(mesh.GeneratePartitioning(size, part_method));
Mpi::Print("Finished partitioning mesh into {:d} subdomain{}\n", size,
(size > 1) ? "s" : "");
if (print)
{
Mpi::Print("Finished partitioning mesh into {:d} subdomain{}\n", size,
(size > 1) ? "s" : "");
}
return partitioning;
}
// User can optionally specify a mesh partitioning file as generated from the MFEM
Expand Down Expand Up @@ -1521,8 +1530,11 @@ std::unique_ptr<int[]> GetMeshPartitioning(mfem::Mesh &mesh, int size,
{
part_ifs >> partitioning[i++];
}
Mpi::Print("Read mesh partitioning into {:d} subdomain{} from disk\n", size,
(size > 1) ? "s" : "");
if (print)
{
Mpi::Print("Read mesh partitioning into {:d} subdomain{} from disk\n", size,
(size > 1) ? "s" : "");
}
return partitioning;
}

Expand Down Expand Up @@ -1825,8 +1837,12 @@ std::map<int, std::array<int, 2>> CheckMesh(mfem::Mesh &orig_mesh,
FlipVertices(el);
el->SetAttribute(new_attr);
new_mesh.AddBdrElement(el);
// Mpi::Print("Adding two BE with attr {:d} from elements {:d} and {:d}\n",
// new_attr, a, b);
if constexpr (false)
{
Mpi::Print(
"Adding two boundary elements with attr {:d} from elements {:d} and {:d}\n",
new_attr, a, b);
}
}
}
}
Expand Down Expand Up @@ -2035,7 +2051,7 @@ void RebalanceConformalMesh(mfem::ParMesh &pmesh)
std::unique_ptr<int[]> partitioning;
if (Mpi::Root(comm))
{
partitioning = GetMeshPartitioning(*smesh, Mpi::Size(comm));
partitioning = GetMeshPartitioning(*smesh, Mpi::Size(comm), "", false);
}
auto new_pmesh = DistributeMesh(comm, smesh, partitioning);
pmesh = std::move(*new_pmesh);
Expand Down

0 comments on commit 9ff2cac

Please sign in to comment.