Skip to content

Commit ac8cd41

Browse files
committed
Fix max_size meaning in PROM construction
1 parent 7fd4b90 commit ac8cd41

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

palace/drivers/drivensolver.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -206,16 +206,15 @@ ErrorIndicator DrivenSolver::SweepAdaptive(SpaceOperator &space_op,
206206

207207
// Configure PROM parameters if not specified.
208208
double offline_tol = iodata.solver.driven.adaptive_tol;
209-
int max_size = iodata.solver.driven.adaptive_max_size;
210-
MFEM_VERIFY(max_size <= 0 || max_size > 2,
209+
int max_size_per_excitation = iodata.solver.driven.adaptive_max_size;
210+
MFEM_VERIFY(max_size_per_excitation <= 0 || max_size_per_excitation > 2,
211211
"Adaptive frequency sweep must sample at least two frequency points!");
212-
if (max_size <= 0)
212+
if (max_size_per_excitation <= 0)
213213
{
214-
max_size = 20 * excitation_helper.Size(); // Default value
214+
max_size_per_excitation = 20; // Default value
215215
}
216-
max_size = std::min(max_size,
217-
(n_step - step0) *
218-
int(excitation_helper.Size())); // Maximum size dictated by sweep
216+
// Maximum size — no more than nr steps needed
217+
max_size_per_excitation = std::min(max_size_per_excitation, (n_step - step0));
219218
int convergence_memory = iodata.solver.driven.adaptive_memory;
220219

221220
// Allocate negative curl matrix for postprocessing the B-field and vectors for the
@@ -247,7 +246,7 @@ ErrorIndicator DrivenSolver::SweepAdaptive(SpaceOperator &space_op,
247246
" {:d} points for frequency sweep over [{:.3e}, {:.3e}] GHz\n",
248247
n_step - step0, omega0 * unit_GHz,
249248
(omega0 + (n_step - step0 - 1) * delta_omega) * unit_GHz);
250-
RomOperator prom_op(iodata, space_op, max_size);
249+
RomOperator prom_op(iodata, space_op, max_size_per_excitation);
251250
space_op.GetWavePortOp().SetSuppressOutput(
252251
true); // Suppress wave port output for offline
253252

@@ -317,7 +316,7 @@ ErrorIndicator DrivenSolver::SweepAdaptive(SpaceOperator &space_op,
317316
{
318317
memory = 0;
319318
}
320-
if (it == max_size)
319+
if (it == max_size_per_excitation)
321320
{
322321
break;
323322
}
@@ -335,7 +334,7 @@ ErrorIndicator DrivenSolver::SweepAdaptive(SpaceOperator &space_op,
335334
}
336335
Mpi::Print("\nAdaptive sampling{} {:d} frequency samples:\n"
337336
" n = {:d}, error = {:.3e}, tol = {:.3e}, memory = {:d}/{:d}\n",
338-
(it == max_size) ? " reached maximum" : " converged with", it,
337+
(it == max_size_per_excitation) ? " reached maximum" : " converged with", it,
339338
prom_op.GetReducedDimension(), max_errors.back(), offline_tol, memory,
340339
convergence_memory);
341340
utils::PrettyPrint(prom_op.GetSamplePoints(excitation_idx), unit_GHz,

palace/models/romoperator.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,8 @@ std::vector<double> MinimalRationInterpolation::FindMaxError(int N) const
313313
return vals;
314314
}
315315

316-
RomOperator::RomOperator(const IoData &iodata, SpaceOperator &space_op, int max_size)
316+
RomOperator::RomOperator(const IoData &iodata, SpaceOperator &space_op,
317+
int max_size_per_excitation)
317318
: space_op(space_op)
318319
{
319320
// Construct the system matrices defining the linear operator. PEC boundaries are handled
@@ -336,11 +337,14 @@ RomOperator::RomOperator(const IoData &iodata, SpaceOperator &space_op, int max_
336337
ksp = std::make_unique<ComplexKspSolver>(iodata, space_op.GetNDSpaces(),
337338
&space_op.GetH1Spaces());
338339

340+
auto excitation_helper = space_op.BuildPortExcitationHelper();
341+
339342
// The initial PROM basis is empty. The provided maximum dimension is the number of sample
340343
// points (2 basis vectors per point). Basis orthogonalization method is configured using
341344
// GMRES/FGMRES settings.
342-
MFEM_VERIFY(max_size > 0, "Reduced order basis storage must have > 0 columns!");
343-
V.resize(2 * max_size, Vector());
345+
MFEM_VERIFY(max_size_per_excitation * excitation_helper.Size() > 0,
346+
"Reduced order basis storage must have > 0 columns!");
347+
V.resize(2 * max_size_per_excitation * excitation_helper.Size(), Vector());
344348
switch (iodata.solver.linear.gs_orthog_type)
345349
{
346350
case config::LinearSolverData::OrthogType::MGS:
@@ -354,10 +358,9 @@ RomOperator::RomOperator(const IoData &iodata, SpaceOperator &space_op, int max_
354358
break;
355359
}
356360
// Set up MRI
357-
auto excitation_helper = space_op.BuildPortExcitationHelper();
358361
for (const auto &[excitation_idx, data] : excitation_helper)
359362
{
360-
mri.emplace(excitation_idx, MinimalRationInterpolation(max_size));
363+
mri.emplace(excitation_idx, MinimalRationInterpolation(max_size_per_excitation));
361364
}
362365
}
363366

palace/models/romoperator.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class RomOperator
8282
std::map<ExcitationIdx, MinimalRationInterpolation> mri;
8383

8484
public:
85-
RomOperator(const IoData &iodata, SpaceOperator &space_op, int max_size);
85+
RomOperator(const IoData &iodata, SpaceOperator &space_op, int max_size_per_excitation);
8686

8787
// Return the HDM linear solver.
8888
const ComplexKspSolver &GetLinearSolver() const { return *ksp; }

0 commit comments

Comments
 (0)