Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggested improvements for #85 #103

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
121f9e8
Cleanup of some style issues
hughcars Aug 21, 2023
bf73494
Fixes to all the driver classes to better call the estimators
hughcars Oct 2, 2023
a97349c
Fixes to better handle normalization
hughcars Oct 3, 2023
21c8022
Adding reference data for the error indicator outputs
hughcars Oct 3, 2023
97372d7
Cleanup debris and formatting fixes
hughcars Oct 3, 2023
d161003
Add option to exclude columns of reference data from regression testi…
hughcars Oct 3, 2023
8abe8b5
Some first PR comment fixes
hughcars Oct 4, 2023
700d047
More PR comment fixes
hughcars Oct 4, 2023
24c800d
Revert integrator changes
hughcars Oct 4, 2023
c7eb850
More PR fixes. Redo fix on integrator, regenerate the error indicator…
hughcars Oct 4, 2023
a33bd0d
Small change to have flux projector templated on FEC and use that to …
hughcars Oct 4, 2023
802b446
Use GetVectorValue rather than precomputed components
hughcars Oct 4, 2023
3d65f39
style fixes
hughcars Oct 4, 2023
512bce4
Change grad flux estimation to use matrix free. A little slower than …
hughcars Oct 4, 2023
3051448
Refactor to combine many elements in the ErrorIndicator capability
hughcars Oct 4, 2023
d9e23c1
More PR comments and removing more allocations from the estimator cal…
hughcars Oct 4, 2023
7cf2dea
style
hughcars Oct 4, 2023
aed614d
Change FluxProjector constructor to look more like DivFree
hughcars Oct 4, 2023
def6d78
Move error indicator calculation outside of reporting loop for eigen …
hughcars Oct 4, 2023
e1251ad
Fixes for some log printing
hughcars Oct 4, 2023
a7d9f69
Regenerate reference error indicator data. Reflects changes to mean c…
hughcars Oct 4, 2023
d275f02
style
hughcars Oct 4, 2023
fc50006
Removing printing the mean row
hughcars Oct 5, 2023
cf6a2b0
Reduce LOC in drivers
hughcars Oct 5, 2023
5dfadba
Remove normalization option from compute indicators. Treat the transi…
hughcars Oct 5, 2023
386f087
Remove inplace flux projector Mult calls
hughcars Oct 5, 2023
3202fda
Compute vector of indicators and then postprocess combined
hughcars Oct 5, 2023
a001210
Remove unneeded defaults and use Norml2
hughcars Oct 6, 2023
78f0946
Delete some unused methods/debris, use member functions on Vector, an…
hughcars Oct 6, 2023
f536eec
Move from utils to fem, CwiseSqrt, and more debris
hughcars Oct 6, 2023
75cc87a
Rename ErrorIndicators to ErrorIndicator. Small cleanups
hughcars Oct 6, 2023
045043d
Add a folding method to error estimator class. Change to only dumping…
hughcars Oct 9, 2023
4d0dc70
New Eval method to avoid duplicate gradient evaluation
hughcars Oct 9, 2023
a2c47c0
Refactor postprocessing of an ErrorIndicator in BaseSolver and PostOp…
sebastiangrimberg Oct 9, 2023
9152d2d
Clean up for problem drivers with new simpler postprocessing
sebastiangrimberg Oct 9, 2023
20655eb
Rework errorestimator.cpp classes: Improve performance including avoi…
sebastiangrimberg Oct 10, 2023
c6e51e1
Final cleanup and bug fixes
sebastiangrimberg Oct 10, 2023
8be72f1
Remove normalization from ErrorIndicator class (not used, the stored …
sebastiangrimberg Oct 10, 2023
467a3aa
Rebaseline tests for changed column headings and fixed integration ru…
sebastiangrimberg Oct 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ The format of this changelog is based on
based for now).
- Added improved OpenMP support in `palace` wrapper script and CI tests.
- Added Apptainer/Singularity container build definition for Palace.
- Added flux-based error estimation, reported in `error-estimate.csv`. This computes the
difference between the numerical gradient (electrostatics) or curl (otherwise) of the
solution, and a smoother approximation obtained through a global mass matrix inversion.
The results are reported in `error-estimates.csv` within the `"Output"` folder.

## [0.11.2] - 2023-07-14

Expand Down
8 changes: 7 additions & 1 deletion docs/src/config/solver.md
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,15 @@ iterative solver choices, and the default choice depends on the iterative solver
`"DivFreeTol" [1.0e-12]` : Relative tolerance for divergence-free cleaning used in the
eigenmode simulation type.

`"DivFreeMaxIts" [100]` : Maximum number of iterations for divergence-free cleaning use in
`"DivFreeMaxIts" [1000]` : Maximum number of iterations for divergence-free cleaning use in
the eigenmode simulation type.

`"EstimatorTol" [1e-6]` : Relative tolerance for flux projection used in the
error estimate calculation.

`"EstimatorMaxIts" [100]` : Maximum number of iterations for flux projection use in
the error estimate calculation.

`"GSOrthogonalization" ["MGS"]` : Gram-Schmidt variant used to explicitly orthogonalize
vectors in Krylov subspace methods or other parts of the code.

Expand Down
43 changes: 38 additions & 5 deletions palace/drivers/basesolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@

#include "basesolver.hpp"

#include <array>
#include <complex>
#include <mfem.hpp>
#include <nlohmann/json.hpp>
#include "fem/errorindicator.hpp"
#include "linalg/ksp.hpp"
#include "models/domainpostoperator.hpp"
#include "models/postoperator.hpp"
#include "models/surfacepostoperator.hpp"
#include "utils/communication.hpp"
#include "utils/errorindicators.hpp"
#include "utils/filesystem.hpp"
#include "utils/iodata.hpp"
#include "utils/timer.hpp"
Expand Down Expand Up @@ -552,18 +553,50 @@ void BaseSolver::PostprocessProbes(const PostOperator &postop, const std::string
#endif
}

void BaseSolver::PostprocessFields(const PostOperator &postop, int step, double time) const
void BaseSolver::PostprocessFields(const PostOperator &postop, int step, double time,
const ErrorIndicator *indicator) const
{
// Save the computed fields in parallel in format for viewing with ParaView.
BlockTimer bt(Timer::IO);
if (post_dir.length() == 0)
{
Mpi::Warning("No file specified under [\"Problem\"][\"Output\"]!\nSkipping saving of "
Mpi::Warning(postop.GetComm(),
"No file specified under [\"Problem\"][\"Output\"]!\nSkipping saving of "
"fields to disk!\n");
return;
}
postop.WriteFields(step, time);
Mpi::Barrier();
postop.WriteFields(step, time, indicator);
Mpi::Barrier(postop.GetComm());
}

void BaseSolver::PostprocessErrorIndicator(const PostOperator &postop,
const ErrorIndicator &indicator) const
{
// Write the indicator statistics.
if (post_dir.length() == 0)
{
return;
}
MPI_Comm comm = postop.GetComm();
std::array<double, 4> data = {indicator.Norml2(comm), indicator.Min(comm),
indicator.Max(comm), indicator.Mean(comm)};
if (root)
{
std::string path = post_dir + "error-indicators.csv";
auto output = OutputFile(path, false);
// clang-format off
output.print("{:>{}s},{:>{}s},{:>{}s},{:>{}s}\n",
"Norm", table.w,
"Minimum", table.w,
"Maximum", table.w,
"Mean", table.w);
output.print("{:+{}.{}e},{:+{}.{}e},{:+{}.{}e},{:+{}.{}e}\n",
data[0], table.w, table.p,
data[1], table.w, table.p,
data[2], table.w, table.p,
data[3], table.w, table.p);
// clang-format on
}
}

template void BaseSolver::SaveMetadata<KspSolver>(const KspSolver &) const;
Expand Down
24 changes: 19 additions & 5 deletions palace/drivers/basesolver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@

namespace mfem
{

class ParFiniteElementSpaceHierarchy;
class ParMesh;

} // namespace mfem

namespace palace
{

struct ErrorIndicators;
class ErrorIndicator;
class IoData;
class PostOperator;
class Timer;
Expand Down Expand Up @@ -56,24 +58,36 @@ class BaseSolver
fmt::file::TRUNC);
}

// Common postprocessing functions for all simulation types.
// Common domain postprocessing for all simulation types.
void PostprocessDomains(const PostOperator &postop, const std::string &name, int step,
double time, double E_elec, double E_mag, double E_cap,
double E_ind) const;

// Common surface postprocessing for all simulation types.
void PostprocessSurfaces(const PostOperator &postop, const std::string &name, int step,
double time, double E_elec, double E_mag, double Vinc,
double Iinc) const;

// Common probe postprocessing for all simulation types.
void PostprocessProbes(const PostOperator &postop, const std::string &name, int step,
double time) const;
void PostprocessFields(const PostOperator &postop, int step, double time) const;

// Common field visualization postprocessing for all simulation types.
void PostprocessFields(const PostOperator &postop, int step, double time,
const ErrorIndicator *indicator = nullptr) const;

// Common error indicator postprocessing for all simulation types.
void PostprocessErrorIndicator(const PostOperator &postop,
const ErrorIndicator &indicator) const;

public:
BaseSolver(const IoData &iodata, bool root, int size = 0, int num_thread = 0,
const char *git_tag = nullptr);
virtual ~BaseSolver() = default;

// Performs a solve using the mesh sequence, and report error indicators.
virtual ErrorIndicators Solve(const std::vector<std::unique_ptr<mfem::ParMesh>> &mesh) const = 0;
// Performs a solve using the mesh sequence, then reports error indicators.
virtual ErrorIndicator
Solve(const std::vector<std::unique_ptr<mfem::ParMesh>> &mesh) const = 0;

// These methods write different simulation metadata to a JSON file in post_dir.
void SaveMetadata(const mfem::ParFiniteElementSpaceHierarchy &fespaces) const;
Expand Down
Loading