Skip to content

Commit 29245f2

Browse files
author
Martin D. Weinberg
committed
Added default EXP n-body units with L=M=T=G; Coefs throws an exception if units are not fully specified
1 parent 8d4ca2b commit 29245f2

7 files changed

Lines changed: 40 additions & 6 deletions

File tree

expui/Coefficients.cc

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,12 @@ namespace CoefClasses
152152
void Coefs::WriteH5Units(HighFive::File& file)
153153
{
154154
if (units.size() != 4) {
155-
std::cout << "---- Coefs::WriteH5Units: Warning, expected 4 units: "
156-
<< "(length, mass, time, G) or (length, mass, velocity, G), etc. " << std::endl
157-
<< "---- Coefs::WriteH5Units: I found " << units.size() << " units instead. Please "
158-
<< " provide a consistent unit set." << std::endl;
155+
std::ostringstream sout;
156+
sout << "---- Coefs::WriteH5Units: Warning, expected 4 units: "
157+
<< "(length, mass, time, G) or (length, mass, velocity, G), etc. "
158+
<< "I found " << units.size() << " units instead. Please "
159+
<< " provide a consistent unit set.";
160+
throw std::runtime_error(sout.str());
159161
}
160162

161163
HighFive::DataSet dataset = file.createDataSet("Units", units);
@@ -171,8 +173,10 @@ namespace CoefClasses
171173
if (file.exist("Units")) {
172174
HighFive::DataSet dataset = file.getDataSet("Units");
173175
units = dataset.read<std::vector<Unit>>();
174-
std::cout << "Coefs::ReadH5Units: read units from HDF5 file:" << std::endl;
175-
std::cout << units;
176+
if (verbose and myid==0) {
177+
std::cout << "Coefs::ReadH5Units: read units from HDF5 file:" << std::endl;
178+
std::cout << units;
179+
}
176180
}
177181
}
178182

src/Cube.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,11 @@ void Cube::dump_coefs_h5(const std::string& file)
520520
// Add the name attribute. We only need this on the first call.
521521
cubeCoefs.setName(component->name);
522522

523+
// Add the default units
524+
cubeCoefs.setUnits({{"length", "none", 1.0},
525+
{"mass", "none", 1.0},
526+
{"time", "none", 1.0}});
527+
523528
// And the new coefficients and write the new HDF5
524529
cubeCoefs.clear();
525530
cubeCoefs.add(cur);

src/Cylinder.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1587,6 +1587,11 @@ void Cylinder::dump_coefs_h5(const std::string& file)
15871587
// Add the name attribute. We only need this on the first call.
15881588
cylCoefs.setName(component->name);
15891589

1590+
// Add the default units
1591+
cylCoefs.setUnits({{"length", "none", 1.0},
1592+
{"mass", "none", 1.0},
1593+
{"time", "none", 1.0}});
1594+
15901595
// Add the new coefficients and write the new HDF5
15911596
cylCoefs.clear();
15921597
cylCoefs.add(cur);

src/PolarBasis.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1842,6 +1842,11 @@ void PolarBasis::dump_coefs_h5(const std::string& file)
18421842
// Add the name attribute. We only need this on the first call.
18431843
cylCoefs.setName(component->name);
18441844

1845+
// Add the default units
1846+
cylCoefs.setUnits({{"length", "none", 1.0},
1847+
{"mass", "none", 1.0},
1848+
{"time", "none", 1.0}});
1849+
18451850
// And the new coefficients and write the new HDF5
18461851
cylCoefs.clear();
18471852
cylCoefs.add(cur);

src/ShearSL.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,11 @@ void ShearSL::dump_coefs_h5(const std::string& file)
374374
// Add the name attribute. We only need this on the first call.
375375
slabCoefs.setName(component->name);
376376

377+
// Add the default units
378+
slabCoefs.setUnits({{"length", "none", 1.0},
379+
{"mass", "none", 1.0},
380+
{"time", "none", 1.0}});
381+
377382
// And the new coefficients and write the new HDF5
378383
slabCoefs.clear();
379384
slabCoefs.add(cur);

src/SlabSL.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,11 @@ void SlabSL::dump_coefs_h5(const std::string& file)
513513
// Add the name attribute. We only need this on the first call.
514514
slabCoefs.setName(component->name);
515515

516+
// Add the default units
517+
slabCoefs.setUnits({{"length", "none", 1.0},
518+
{"mass", "none", 1.0},
519+
{"time", "none", 1.0}});
520+
516521
// And the new coefficients and write the new HDF5
517522
slabCoefs.clear();
518523
slabCoefs.add(cur);

src/SphericalBasis.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,6 +1926,11 @@ void SphericalBasis::dump_coefs_h5(const std::string& file)
19261926
// Add the name attribute. We only need this on the first call.
19271927
sphCoefs.setName(component->name);
19281928

1929+
// Add the default units
1930+
sphCoefs.setUnits({{"length", "none", 1.0},
1931+
{"mass", "none", 1.0},
1932+
{"time", "none", 1.0}});
1933+
19291934
// And the new coefficients and write the new HDF5
19301935
sphCoefs.clear();
19311936
sphCoefs.add(cur);

0 commit comments

Comments
 (0)