Skip to content

Commit 5119587

Browse files
authored
Merge pull request #653 from awslabs/phdum/pre_cpp20
Fix small issues in preparation for C++20
2 parents 9403a6a + 99e88b3 commit 5119587

13 files changed

Lines changed: 247 additions & 226 deletions

File tree

.github/workflows/spack.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,19 @@ jobs:
7777
toolchain: gcc
7878
variant: "+openmp+int64~shared"
7979
run-regression-tests: 'false'
80-
80+
81+
build-x64-gcc-cxx20:
82+
needs: filter
83+
if: needs.filter.outputs.test == 'true'
84+
runs-on: [self-hosted, x64]
85+
steps:
86+
- uses: actions/checkout@v6
87+
- uses: ./.github/actions/palace-ci
88+
with:
89+
toolchain: gcc
90+
variant: " cxxstd=20"
91+
run-regression-tests: 'false'
92+
8193
build-test-x64-llvm:
8294
needs: filter
8395
if: needs.filter.outputs.test == 'true'

palace/CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,14 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
1515
message(FATAL_ERROR "In-source builds are prohibited")
1616
endif()
1717

18-
# C++17 required for std::filesystem, among others
18+
# C++17 required for std::filesystem, among others. Override via -DCMAKE_CXX_STANDARD=<VALUE>
19+
if(NOT DEFINED CMAKE_CXX_STANDARD)
20+
set(CMAKE_CXX_STANDARD 17)
21+
endif()
22+
if(CMAKE_CXX_STANDARD LESS 17)
23+
message(FATAL_ERROR "Palace requires C++17 or later (got ${CMAKE_CXX_STANDARD})")
24+
endif()
1925
set(CMAKE_CXX_STANDARD_REQUIRED ON)
20-
set(CMAKE_CXX_STANDARD 17)
2126
set(CMAKE_CXX_EXTENSIONS OFF)
2227

2328
# Initialize the project

palace/drivers/electrostaticsolver.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ void ElectrostaticSolver::PostprocessTerminals(
145145
return;
146146
}
147147
using VT = Units::ValueType;
148-
using fmt::format;
149148

150149
// Write capacitance matrix data.
151150
auto PrintMatrix = [&terminal_sources, this](const std::string &file,
@@ -158,11 +157,12 @@ void ElectrostaticSolver::PostprocessTerminals(
158157
int j = 0;
159158
for (const auto &[idx2, data2] : terminal_sources)
160159
{
161-
output.table.insert(format("i2{}", idx2), format("{}[i][{}] {}", name, idx2, unit));
160+
output.table.insert(fmt::format("i2{}", idx2),
161+
fmt::format("{}[i][{}] {}", name, idx2, unit));
162162
// Use the fact that iterator over i and j is the same span.
163163
output.table["i"] << idx2;
164164

165-
auto &col = output.table[format("i2{}", idx2)];
165+
auto &col = output.table[fmt::format("i2{}", idx2)];
166166
for (std::size_t i = 0; i < terminal_sources.size(); i++)
167167
{
168168
col << mat(i, j) * scale;

palace/drivers/magnetostaticsolver.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ void MagnetostaticSolver::PostprocessTerminals(
151151
{
152152
return;
153153
}
154-
using fmt::format;
155154

156155
// Write inductance matrix data.
157156
auto PrintMatrix = [&surf_j_op, this](const std::string &file, const std::string &name,
@@ -163,11 +162,12 @@ void MagnetostaticSolver::PostprocessTerminals(
163162
int j = 0;
164163
for (const auto &[idx2, data2] : surf_j_op)
165164
{
166-
output.table.insert(format("i2{}", idx2), format("{}[i][{}] {}", name, idx2, unit));
165+
output.table.insert(fmt::format("i2{}", idx2),
166+
fmt::format("{}[i][{}] {}", name, idx2, unit));
167167
// Use the fact that iterator over i and j is the same span.
168168
output.table["i"] << idx2;
169169

170-
auto &col = output.table[format("i2{}", idx2)];
170+
auto &col = output.table[fmt::format("i2{}", idx2)];
171171
for (std::size_t i = 0; i < surf_j_op.Size(); i++)
172172
{
173173
col << mat(i, j) * scale;

palace/linalg/rap.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -934,9 +934,9 @@ std::unique_ptr<ComplexParOperator>
934934
BuildParSumOperator(std::complex<double> (&&coeff_in)[N],
935935
const ComplexParOperator *(&&ops_in)[N], bool set_essential)
936936
{
937-
return BuildParSumOperator(to_array<std::complex<double>>(std::move(coeff_in)),
938-
to_array<const ComplexParOperator *>(std::move(ops_in)),
939-
set_essential);
937+
return BuildParSumOperator(
938+
palace::to_array<std::complex<double>>(std::move(coeff_in)),
939+
palace::to_array<const ComplexParOperator *>(std::move(ops_in)), set_essential);
940940
}
941941

942942
template <std::size_t N, typename ScalarType, typename OperType>
@@ -953,8 +953,8 @@ BuildParSumOperator(ScalarType (&&coeff_in)[N], const OperType *(&&ops_in)[N],
953953
std::transform(ops_in, ops_in + N, par_ops.begin(),
954954
[](const OperType *op) { return dynamic_cast<const ParOperType *>(op); });
955955

956-
return BuildParSumOperator(to_array<ScalarType>(std::move(coeff_in)), std::move(par_ops),
957-
set_essential);
956+
return BuildParSumOperator(palace::to_array<ScalarType>(std::move(coeff_in)),
957+
std::move(par_ops), set_essential);
958958
}
959959

960960
// Explicit instantiation.

palace/models/lumpedportoperator.cpp

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -361,70 +361,75 @@ void LumpedPortOperator::PrintBoundaryInfo(const IoData &iodata, const mfem::Par
361361
{
362362
return;
363363
}
364-
365-
fmt::memory_buffer buf{}; // Output buffer & buffer append lambda for cleaner code
366-
auto to = [](auto &buf, auto fmt, auto &&...args)
367-
{ fmt::format_to(std::back_inserter(buf), fmt, std::forward<decltype(args)>(args)...); };
364+
fmt::memory_buffer buffer{};
365+
auto out = fmt::appender{buffer};
368366
using VT = Units::ValueType;
369367

370368
// Print out BC info for all port attributes, for both active and inactive ports.
371-
to(buf, "\nConfiguring Robin impedance BC for lumped ports at attributes:\n");
369+
fmt::format_to(out, "\nConfiguring Robin impedance BC for lumped ports at attributes:\n");
372370
for (const auto &[idx, data] : ports)
373371
{
374372
for (const auto &elem : data.elems)
375373
{
376374
for (auto attr : elem->GetAttrList())
377375
{
378-
to(buf, " {:d}:", attr);
376+
fmt::format_to(out, " {:d}:", attr);
379377
if (std::abs(data.R) > 0.0)
380378
{
381379
double Rs = data.R * data.GetToSquare(*elem);
382-
to(buf, " Rs = {:.3e} Ω/sq,", iodata.units.Dimensionalize<VT::IMPEDANCE>(Rs));
380+
fmt::format_to(out, " Rs = {:.3e} Ω/sq,",
381+
iodata.units.Dimensionalize<VT::IMPEDANCE>(Rs));
383382
}
384383
if (std::abs(data.L) > 0.0)
385384
{
386385
double Ls = data.L * data.GetToSquare(*elem);
387-
to(buf, " Ls = {:.3e} H/sq,", iodata.units.Dimensionalize<VT::INDUCTANCE>(Ls));
386+
fmt::format_to(out, " Ls = {:.3e} H/sq,",
387+
iodata.units.Dimensionalize<VT::INDUCTANCE>(Ls));
388388
}
389389
if (std::abs(data.C) > 0.0)
390390
{
391391
double Cs = data.C / data.GetToSquare(*elem);
392-
to(buf, " Cs = {:.3e} F/sq,", iodata.units.Dimensionalize<VT::CAPACITANCE>(Cs));
392+
fmt::format_to(out, " Cs = {:.3e} F/sq,",
393+
iodata.units.Dimensionalize<VT::CAPACITANCE>(Cs));
393394
}
394-
to(buf, " n = ({:+.1f})\n", fmt::join(mesh::GetSurfaceNormal(mesh, attr), ","));
395+
fmt::format_to(out, " n = ({:+.1f})\n",
396+
fmt::join(mesh::GetSurfaceNormal(mesh, attr), ","));
395397
}
396398
}
397399
}
398400

399401
// Print out port info for all active ports.
400-
fmt::memory_buffer buf_a{};
402+
fmt::memory_buffer buffer_active{};
401403
for (const auto &[idx, data] : ports)
402404
{
403405
if (!data.active)
404406
{
405407
continue;
406408
}
407-
to(buf_a, " Index = {:d}: ", idx);
409+
std::vector<std::string> active_port_str;
408410
if (std::abs(data.R) > 0.0)
409411
{
410-
to(buf_a, "R = {:.3e} Ω,", iodata.units.Dimensionalize<VT::IMPEDANCE>(data.R));
412+
active_port_str.emplace_back(
413+
fmt::format("R = {:.3e} Ω", iodata.units.Dimensionalize<VT::IMPEDANCE>(data.R)));
411414
}
412415
if (std::abs(data.L) > 0.0)
413416
{
414-
to(buf_a, "L = {:.3e} H,", iodata.units.Dimensionalize<VT::INDUCTANCE>(data.L));
417+
active_port_str.emplace_back(
418+
fmt::format("L = {:.3e} H", iodata.units.Dimensionalize<VT::INDUCTANCE>(data.L)));
415419
}
416420
if (std::abs(data.C) > 0.0)
417421
{
418-
to(buf_a, "C = {:.3e} F,", iodata.units.Dimensionalize<VT::CAPACITANCE>(data.C));
422+
active_port_str.emplace_back(fmt::format(
423+
"C = {:.3e} F", iodata.units.Dimensionalize<VT::CAPACITANCE>(data.C)));
419424
}
420-
buf_a.resize(buf_a.size() - 1); // Remove last ","
421-
to(buf_a, "\n");
425+
fmt::format_to(fmt::appender{buffer_active}, " Index = {:d}: {}\n", idx,
426+
fmt::join(active_port_str, ", "));
422427
}
423-
if (buf_a.size() > 0)
428+
if (buffer_active.size() > 0)
424429
{
425-
to(buf, "\nConfiguring lumped port circuit properties:\n");
426-
buf.append(buf_a);
427-
buf_a.clear();
430+
fmt::format_to(out, "\nConfiguring lumped port circuit properties:\n");
431+
buffer.append(buffer_active);
432+
buffer_active.clear();
428433
}
429434

430435
// Print some information for excited lumped ports.
@@ -439,17 +444,18 @@ void LumpedPortOperator::PrintBoundaryInfo(const IoData &iodata, const mfem::Par
439444
{
440445
for (auto attr : elem->GetAttrList())
441446
{
442-
to(buf_a, " {:d}: Index = {:d}\n", attr, idx);
447+
fmt::format_to(fmt::appender{buffer_active}, " {:d}: Index = {:d}\n", attr, idx);
443448
}
444449
}
445450
}
446-
if (buf_a.size() > 0)
451+
if (buffer_active.size() > 0)
447452
{
448-
to(buf, "\nConfiguring lumped port excitation source term at attributes:\n");
449-
buf.append(buf_a);
453+
fmt::format_to(out,
454+
"\nConfiguring lumped port excitation source term at attributes:\n");
455+
buffer.append(buffer_active);
450456
}
451457

452-
Mpi::Print("{}", fmt::to_string(buf));
458+
Mpi::Print("{}", fmt::to_string(buffer));
453459
}
454460

455461
const LumpedPortData &LumpedPortOperator::GetPort(int idx) const

palace/models/portexcitations.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,34 @@ namespace palace
1818
[[nodiscard]] std::string PortExcitations::FmtLog() const
1919
{
2020
fmt::memory_buffer buf{};
21-
auto to = [&buf](auto f, auto &&...a) // mini-lambda for cleaner code
22-
{ fmt::format_to(std::back_inserter(buf), f, std::forward<decltype(a)>(a)...); };
21+
auto out = fmt::appender{buf};
2322

2423
int i = 1;
2524
for (const auto &[idx, ex] : excitations)
2625
{
27-
to("Excitation{} with index {:d} has contributions from:\n",
28-
(Size() > 1) ? fmt::format(" {:d}/{:d}", i, Size()) : "", idx);
26+
fmt::format_to(out, "Excitation{} with index {:d} has contributions from:\n",
27+
(Size() > 1) ? fmt::format(" {:d}/{:d}", i, Size()) : "", idx);
2928
if (!ex.lumped_port.empty())
3029
{
31-
to(" Lumped port{} {:2d}\n", (ex.lumped_port.size() > 1) ? "s" : "",
32-
fmt::join(ex.lumped_port, " "));
30+
fmt::format_to(out, " Lumped port{} {:2d}\n", (ex.lumped_port.size() > 1) ? "s" : "",
31+
fmt::join(ex.lumped_port, " "));
3332
}
3433
if (!ex.wave_port.empty())
3534
{
36-
to(" Wave port{} {:2d}\n", (ex.wave_port.size() > 1) ? "s" : "",
37-
fmt::join(ex.wave_port, " "));
35+
fmt::format_to(out, " Wave port{} {:2d}\n", (ex.wave_port.size() > 1) ? "s" : "",
36+
fmt::join(ex.wave_port, " "));
3837
}
3938
if (!ex.current_port.empty())
4039
{
41-
to(" Surface current port{} {:2d}\n", (ex.current_port.size() > 1) ? "s" : "",
42-
fmt::join(ex.current_port, " "));
40+
fmt::format_to(out, " Surface current port{} {:2d}\n",
41+
(ex.current_port.size() > 1) ? "s" : "",
42+
fmt::join(ex.current_port, " "));
4343
}
4444
if (!ex.current_dipole.empty())
4545
{
46-
to(" Current dipole{} {:2d}\n", (ex.current_dipole.size() > 1) ? "s" : "",
47-
fmt::join(ex.current_dipole, " "));
46+
fmt::format_to(out, " Current dipole{} {:2d}\n",
47+
(ex.current_dipole.size() > 1) ? "s" : "",
48+
fmt::join(ex.current_dipole, " "));
4849
}
4950
i++;
5051
}

palace/models/postoperator.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,6 @@ void PostOperator<solver_t>::MeasureSParameter() const
10001000
// Depends on LumpedPorts, WavePorts.
10011001
if constexpr (solver_t == ProblemType::DRIVEN)
10021002
{
1003-
using fmt::format;
10041003
using std::complex_literals::operator""i;
10051004

10061005
// Don't measure S-Matrix unless there is only one excitation per port. Also, we current
@@ -1034,7 +1033,7 @@ void PostOperator<solver_t>::MeasureSParameter() const
10341033
}
10351034

10361035
Mpi::Print(" {0} = {1:+.3e}{2:+.3e}i, |{0}| = {3:+.3e}, arg({0}) = {4:+.3e}\n",
1037-
format("S[{}][{}]", idx, drive_port_idx), vi.S.real(), vi.S.imag(),
1036+
fmt::format("S[{}][{}]", idx, drive_port_idx), vi.S.real(), vi.S.imag(),
10381037
Measurement::Magnitude(vi.S), Measurement::Phase(vi.S));
10391038
}
10401039
for (const auto &[idx, data] : fem_op->GetWavePortOp())
@@ -1055,7 +1054,7 @@ void PostOperator<solver_t>::MeasureSParameter() const
10551054
vi.S *= std::exp(1i * data.kn0 * data.d_offset);
10561055

10571056
Mpi::Print(" {0} = {1:+.3e}{2:+.3e}i, |{0}| = {3:+.3e}, arg({0}) = {4:+.3e}\n",
1058-
format("S[{}][{}]", idx, drive_port_idx), vi.S.real(), vi.S.imag(),
1057+
fmt::format("S[{}][{}]", idx, drive_port_idx), vi.S.real(), vi.S.imag(),
10591058
Measurement::Magnitude(vi.S), Measurement::Phase(vi.S));
10601059
}
10611060
}
@@ -1152,8 +1151,6 @@ void PostOperator<solver_t>::MeasureProbes() const
11521151
#endif
11531152
}
11541153

1155-
using fmt::format;
1156-
11571154
template <ProblemType solver_t>
11581155
template <ProblemType U>
11591156
auto PostOperator<solver_t>::MeasureAndPrintAll(int ex_idx, int step,

0 commit comments

Comments
 (0)