Skip to content

Commit

Permalink
Remove state from more printers.
Browse files Browse the repository at this point in the history
  • Loading branch information
hughcars committed Jan 7, 2025
1 parent 2590733 commit c0cf0f5
Show file tree
Hide file tree
Showing 15 changed files with 188 additions and 216 deletions.
2 changes: 1 addition & 1 deletion cmake/ExternalMFEM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ if(CMAKE_BUILD_TYPE MATCHES "Debug|debug|DEBUG")
endif()

# Replace mfem abort calls with exceptions for testing, default off
set(PALACE_MFEM_USE_EXCEPTIONS NO "MFEM throw exceptions instead of abort calls")
set(PALACE_MFEM_USE_EXCEPTIONS NO)

set(MFEM_OPTIONS ${PALACE_SUPERBUILD_DEFAULT_ARGS})
list(APPEND MFEM_OPTIONS
Expand Down
31 changes: 27 additions & 4 deletions palace/drivers/basesolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,10 @@ void BaseSolver::DomainsPostPrinter::AddMeasurement(double idx_value_dimensionfu
const PostOperator &post_op,
const IoData &iodata)
{
if (!Mpi::Root(post_op.GetComm()))
{
return;
}
using VT = IoData::ValueType;
using fmt::format;

Expand Down Expand Up @@ -355,7 +359,10 @@ BaseSolver::SurfacesPostPrinter::SurfacesPostPrinter(const fs::path &post_dir,
const std::string &idx_col_name,
int n_expected_rows)
{
if (!Mpi::Root(post_op.GetComm())) { return; }
if (!Mpi::Root(post_op.GetComm()))
{
return;
}
using fmt::format;
if (post_op.GetSurfacePostOp().flux_surfs.size() > 0)
{
Expand Down Expand Up @@ -490,6 +497,10 @@ void BaseSolver::SurfacesPostPrinter::AddMeasurement(double idx_value_dimensionf
const PostOperator &post_op,
const IoData &iodata)
{
if (!Mpi::Root(post_op.GetComm()))
{
return;
}
// If surfaces have been specified for postprocessing, compute the corresponding values
// and write out to disk. The passed in E_elec is the sum of the E-field and lumped
// capacitor energies, and E_mag is the same for the B-field and lumped inductors.
Expand All @@ -509,7 +520,7 @@ BaseSolver::ProbePostPrinter::ProbePostPrinter(const fs::path &post_dir,
int n_expected_rows)
{
#if defined(MFEM_USE_GSLIB)
if (!Mpi::Root(post_op.GetComm()) || post_op.GetProbes().size() == 0)
if (post_op.GetProbes().size() == 0 || !Mpi::Root(post_op.GetComm()))
{
return;
}
Expand Down Expand Up @@ -597,14 +608,18 @@ void BaseSolver::ProbePostPrinter::AddMeasurementE(double idx_value_dimensionful
const PostOperator &post_op,
const IoData &iodata)
{
if (!post_op.HasE())
{
return;
}
using VT = IoData::ValueType;
using fmt::format;

auto probe_field = post_op.ProbeEField();
const int v_dim = post_op.GetInterpolationOpVDim();
const bool has_imag = post_op.HasImag();
MFEM_VERIFY(probe_field.size() == v_dim * post_op.GetProbes().size(),
format("Size mismatch: expect vector field to ahve size {} * {} = {}; got {}",
format("Size mismatch: expect vector field to have size {} * {} = {}; got {}",
v_dim, post_op.GetProbes().size(), v_dim * post_op.GetProbes().size(),
probe_field.size()))

Expand All @@ -630,14 +645,18 @@ void BaseSolver::ProbePostPrinter::AddMeasurementB(double idx_value_dimensionful
const PostOperator &post_op,
const IoData &iodata)
{
if (!post_op.HasB())
{
return;
}
using VT = IoData::ValueType;
using fmt::format;

auto probe_field = post_op.ProbeBField();
const int v_dim = post_op.GetInterpolationOpVDim();
const bool has_imag = post_op.HasImag();
MFEM_VERIFY(probe_field.size() == v_dim * post_op.GetProbes().size(),
format("Size mismatch: expect vector field to ahve size {} * {} = {}; got {}",
format("Size mismatch: expect vector field to have size {} * {} = {}; got {}",
v_dim, post_op.GetProbes().size(), v_dim * post_op.GetProbes().size(),
probe_field.size()))

Expand All @@ -664,6 +683,10 @@ void BaseSolver::ProbePostPrinter::AddMeasurement(double idx_value_dimensionful,
const IoData &iodata)
{
#if defined(MFEM_USE_GSLIB)
if (!Mpi::Root(post_op.GetComm()) || post_op.GetProbes().size() == 0)
{
return;
}
AddMeasurementE(idx_value_dimensionful, post_op, iodata);
AddMeasurementB(idx_value_dimensionful, post_op, iodata);
#endif
Expand Down
31 changes: 18 additions & 13 deletions palace/drivers/basesolver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,18 @@ class BaseSolver

// Parameters for writing postprocessing outputs.
fs::path post_dir;
bool root;

// Common domain postprocessing for all simulation types.
class DomainsPostPrinter
{
TableWithCSVFile domain_E;

public:
DomainsPostPrinter() = default;
DomainsPostPrinter(const fs::path &post_dir, const PostOperator &post_op, const std::string &idx_col_name, int n_expected_rows);
void AddMeasurement(double idx_value_dimensionful, const PostOperator &post_op, const IoData &iodata);
DomainsPostPrinter(const fs::path &post_dir, const PostOperator &post_op,
const std::string &idx_col_name, int n_expected_rows);
void AddMeasurement(double idx_value_dimensionful, const PostOperator &post_op,
const IoData &iodata);
};

// Common surface postprocessing for all simulation types.
Expand All @@ -53,10 +56,12 @@ class BaseSolver
const IoData &iodata);
void AddMeasurementEps(double idx_value_dimensionful, const PostOperator &post_op,
const IoData &iodata);

public:
SurfacesPostPrinter() = default;
SurfacesPostPrinter(const fs::path &post_dir, const PostOperator &post_op, const std::string &idx_col_name, int n_expected_rows);
void AddMeasurement(double idx_value_dimensionful, const PostOperator &post_op, const IoData &iodata);
SurfacesPostPrinter(const fs::path &post_dir, const PostOperator &post_op,
const std::string &idx_col_name, int n_expected_rows);
void AddMeasurement(double idx_value_dimensionful, const PostOperator &post_op,
const IoData &iodata);
};

// Common probe postprocessing for all simulation types.
Expand All @@ -69,27 +74,27 @@ class BaseSolver
const IoData &iodata);
void AddMeasurementB(double idx_value_dimensionful, const PostOperator &post_op,
const IoData &iodata);

public:
ProbePostPrinter() = default;
ProbePostPrinter(const fs::path &post_dir, const PostOperator &post_op, const std::string &idx_col_name, int n_expected_rows);
ProbePostPrinter(const fs::path &post_dir, const PostOperator &post_op,
const std::string &idx_col_name, int n_expected_rows);

void AddMeasurement(double idx_value_dimensionful, const PostOperator &post_op, const IoData &iodata);
void AddMeasurement(double idx_value_dimensionful, const PostOperator &post_op,
const IoData &iodata);
};

// Common error indicator postprocessing for all simulation types. //
// This is trivial since data is only added at the end of the solve, rather after each
// step (time / frequency / eigenvector).
class ErrorIndicatorPostPrinter
{
bool root_ = false;
bool do_measurement_ = false;
TableWithCSVFile error_indicator;

public:
ErrorIndicatorPostPrinter() = default;
ErrorIndicatorPostPrinter(const fs::path &post_dir);

void PrintIndicatorStatistics(const PostOperator &post_op, const ErrorIndicator::SummaryStatistics &indicator_stats);
void PrintIndicatorStatistics(const PostOperator &post_op,
const ErrorIndicator::SummaryStatistics &indicator_stats);
};

// Performs a solve using the mesh sequence, then reports error indicators and the number
Expand Down
65 changes: 39 additions & 26 deletions palace/drivers/drivensolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,14 +401,12 @@ int DrivenSolver::GetNumSteps(double start, double end, double delta) const
(delta > 0.0 && dfinal - end < delta_eps * end));
}

// -----------------
// Measurements / Postprocessing

DrivenSolver::CurrentsPostPrinter::CurrentsPostPrinter(
const fs::path &post_dir, const SpaceOperator &space_op, int n_expected_rows)
DrivenSolver::CurrentsPostPrinter::CurrentsPostPrinter(const fs::path &post_dir,
const SpaceOperator &space_op,
int n_expected_rows)
{
const auto &surf_j_op = space_op.GetSurfaceCurrentOp();
if (!Mpi::Root(space_op.GetComm()) || surf_j_op.Size() == 0)
if (surf_j_op.Size() == 0 || !Mpi::Root(space_op.GetComm()))
{
return;
}
Expand All @@ -423,9 +421,15 @@ DrivenSolver::CurrentsPostPrinter::CurrentsPostPrinter(
surface_I.AppendHeader();
}

void DrivenSolver::CurrentsPostPrinter::AddMeasurement(
double freq, const SurfaceCurrentOperator &surf_j_op, const IoData &iodata)
void DrivenSolver::CurrentsPostPrinter::AddMeasurement(double freq,
const SpaceOperator &space_op,
const IoData &iodata)
{
const auto &surf_j_op = space_op.GetSurfaceCurrentOp();
if (surf_j_op.Size() == 0 || !Mpi::Root(space_op.GetComm()))
{
return;
}
using VT = IoData::ValueType;
using fmt::format;

Expand All @@ -443,7 +447,7 @@ DrivenSolver::PortsPostPrinter::PortsPostPrinter(const fs::path &post_dir,
int n_expected_rows)
{
const auto &lumped_port_op = space_op.GetLumpedPortOp();
if (!Mpi::Root(space_op.GetComm()) || lumped_port_op.Size() == 0)
if (lumped_port_op.Size() == 0 || !Mpi::Root(space_op.GetComm()))
{
return;
}
Expand Down Expand Up @@ -478,6 +482,10 @@ void DrivenSolver::PortsPostPrinter::AddMeasurement(
double freq, const PostOperator &post_op, const LumpedPortOperator &lumped_port_op,
const IoData &iodata)
{
if (lumped_port_op.Size() == 0 || !Mpi::Root(post_op.GetComm()))
{
return;
}
using VT = IoData::ValueType;

// Postprocess the frequency domain lumped port voltages and currents (complex magnitude
Expand Down Expand Up @@ -512,7 +520,9 @@ void DrivenSolver::PortsPostPrinter::AddMeasurement(
port_I.AppendRow();
}

DrivenSolver::SParametersPostPrinter::SParametersPostPrinter(const fs::path &post_dir, const SpaceOperator &space_op, int n_expected_rows)
DrivenSolver::SParametersPostPrinter::SParametersPostPrinter(const fs::path &post_dir,
const SpaceOperator &space_op,
int n_expected_rows)
{
const auto &lumped_port_op = space_op.GetLumpedPortOp();
const auto &wave_port_op = space_op.GetWavePortOp();
Expand All @@ -534,8 +544,9 @@ DrivenSolver::SParametersPostPrinter::SParametersPostPrinter(const fs::path &pos
}
}

const bool do_measurement = ((lumped_port_op.Size() > 0) xor (wave_port_op.Size() > 0)) && (source_idx > 0);
if (!Mpi::Root(space_op.GetComm()) || !do_measurement)
const bool do_measurement =
((lumped_port_op.Size() > 0) xor (wave_port_op.Size() > 0)) && (source_idx > 0);
if (!do_measurement || !Mpi::Root(space_op.GetComm()))
{
return;
}
Expand Down Expand Up @@ -567,6 +578,10 @@ void DrivenSolver::SParametersPostPrinter::AddMeasurement(
double freq, const PostOperator &post_op, const LumpedPortOperator &lumped_port_op,
const WavePortOperator &wave_port_op, const IoData &iodata)
{
if (source_idx == -1 || !Mpi::Root(post_op.GetComm()))
{
return;
}
using VT = IoData::ValueType;
using fmt::format;

Expand All @@ -586,8 +601,9 @@ void DrivenSolver::SParametersPostPrinter::AddMeasurement(
for (const auto o_idx : all_port_indices)
{
std::complex<double> S_ij =
src_lumped_port ? post_op.GetSParameter(lumped_port_op, o_idx, source_idx)
: post_op.GetSParameter(wave_port_op, o_idx, source_idx);
(lumped_port_op.Size() > 0)
? post_op.GetSParameter(lumped_port_op, o_idx, source_idx)
: post_op.GetSParameter(wave_port_op, o_idx, source_idx);

auto abs_S_ij = 20.0 * std::log10(std::abs(S_ij));
auto arg_S_ij = std::arg(S_ij) * 180.0 / M_PI;
Expand All @@ -612,8 +628,7 @@ DrivenSolver::PostprocessPrintResults::PostprocessPrintResults(
currents{post_dir, space_op, n_expected_rows},
probes{post_dir, post_op, "f (GHz)", n_expected_rows},
ports{post_dir, space_op, n_expected_rows},
s_parameters{post_dir, space_op, n_expected_rows},
error_indicator{post_dir}
s_parameters{post_dir, space_op, n_expected_rows}, error_indicator{post_dir}
{
}

Expand All @@ -624,16 +639,14 @@ void DrivenSolver::PostprocessPrintResults::PostprocessStep(const IoData &iodata
{
double omega = post_op.GetFrequency().real();
auto freq = iodata.DimensionalizeValue(IoData::ValueType::FREQUENCY, omega);
if (Mpi::Root(post_op.GetComm()))
{
domains.AddMeasurement(freq, post_op, iodata);
surfaces.AddMeasurement(freq, post_op, iodata);
currents.AddMeasurement(freq, space_op.GetSurfaceCurrentOp(), iodata);
probes.AddMeasurement(freq, post_op, iodata);
ports.AddMeasurement(freq, post_op, space_op.GetLumpedPortOp(), iodata);
s_parameters.AddMeasurement(freq, post_op, space_op.GetLumpedPortOp(),
space_op.GetWavePortOp(), iodata);
}
domains.AddMeasurement(freq, post_op, iodata);
surfaces.AddMeasurement(freq, post_op, iodata);
currents.AddMeasurement(freq, space_op, iodata);
probes.AddMeasurement(freq, post_op, iodata);
ports.AddMeasurement(freq, post_op, space_op.GetLumpedPortOp(), iodata);
s_parameters.AddMeasurement(freq, post_op, space_op.GetLumpedPortOp(),
space_op.GetWavePortOp(), iodata);

// The internal GridFunctions in PostOperator have already been set:
if (write_paraview_fields && (step % delta_post == 0))
{
Expand Down
19 changes: 9 additions & 10 deletions palace/drivers/drivensolver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,21 @@ class DrivenSolver : public BaseSolver
class CurrentsPostPrinter
{
TableWithCSVFile surface_I;

public:
CurrentsPostPrinter() = default;
CurrentsPostPrinter(const fs::path &post_dir, const SpaceOperator &space_op, int n_expected_rows);
void AddMeasurement(double freq, const SurfaceCurrentOperator &surf_j_op, const IoData &iodata);
CurrentsPostPrinter(const fs::path &post_dir, const SpaceOperator &space_op,
int n_expected_rows);
void AddMeasurement(double freq, const SpaceOperator &space_op, const IoData &iodata);
};

class PortsPostPrinter
{
TableWithCSVFile port_V;
TableWithCSVFile port_I;

public:
PortsPostPrinter() = default;
PortsPostPrinter(const fs::path &post_dir, const SpaceOperator &space_op, int n_expected_rows);
PortsPostPrinter(const fs::path &post_dir, const SpaceOperator &space_op,
int n_expected_rows);
void AddMeasurement(double freq, const PostOperator &post_op,
const LumpedPortOperator &lumped_port_op, const IoData &iodata);
};
Expand All @@ -56,18 +58,15 @@ class DrivenSolver : public BaseSolver
// excited port index specified in the configuration file, storing |S_ij| and arg
// (S_ij) in dB and degrees, respectively. S-parameter output is only available for a
// single lumped or wave port excitation.

bool root_ = false;
bool do_measurement_ = false;
TableWithCSVFile port_S;

// Currently can't mix lumped and surface ports for s-matrix
bool src_lumped_port = true;
int source_idx = -1;

public:
SParametersPostPrinter() = default;
SParametersPostPrinter(const fs::path &post_dir, const SpaceOperator &space_op, int n_expected_rows);
SParametersPostPrinter(const fs::path &post_dir, const SpaceOperator &space_op,
int n_expected_rows);
void AddMeasurement(double freq, const PostOperator &post_op,
const LumpedPortOperator &lumped_port_op,
const WavePortOperator &wave_port_op, const IoData &iodata);
Expand Down
Loading

0 comments on commit c0cf0f5

Please sign in to comment.