Skip to content

Commit 1c8a6d4

Browse files
author
Martin D. Weinberg
committed
Require SLGridSlab to have a non-default cachename for consistency with SLGridSph and provenance policy
1 parent 09b429c commit 1c8a6d4

File tree

6 files changed

+69
-151
lines changed

6 files changed

+69
-151
lines changed

expui/BiorthBasis.cc

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3421,7 +3421,8 @@ namespace BasisClasses
34213421
"verbose",
34223422
"check",
34233423
"method",
3424-
"self_consistent"
3424+
"self_consistent",
3425+
"cachename"
34253426
};
34263427

34273428
Slab::Slab(const YAML::Node& CONF) : BiorthBasis(CONF, "slab")
@@ -3482,6 +3483,8 @@ namespace BasisClasses
34823483
if (conf["knots"]) knots = conf["knots"].as<int>();
34833484

34843485
if (conf["check"]) check = conf["check"].as<bool>();
3486+
3487+
if (conf["cachename"]) cachename = conf["cachename"].as<std::string>();
34853488
}
34863489
catch (YAML::Exception & error) {
34873490
if (myid==0) std::cout << "Error parsing parameter stanza for <"
@@ -3494,6 +3497,19 @@ namespace BasisClasses
34943497
throw std::runtime_error("Slab: error parsing YAML");
34953498
}
34963499

3500+
// Check for non-null cache file name. This must be specified
3501+
// to prevent recomputation and unexpected behavior.
3502+
//
3503+
if (cachename.size() == 0) {
3504+
throw std::runtime_error
3505+
("SlabSL requires a specified cachename in your YAML config\n"
3506+
"for consistency with previous invocations and existing coefficient\n"
3507+
"sets. Please add explicitly add 'cachename: name' to your config\n"
3508+
"with new 'name' for creating a basis or an existing 'name' for\n"
3509+
"reading a previously generated basis cache\n");
3510+
}
3511+
3512+
34973513
// Finally, make the basis
34983514
//
34993515
SLGridSlab::mpi = 0;
@@ -3503,7 +3519,7 @@ namespace BasisClasses
35033519

35043520
int nnmax = (nmaxx > nmaxy) ? nmaxx : nmaxy;
35053521

3506-
ortho = std::make_shared<SLGridSlab>(nnmax, nmaxz, ngrid, zmax, type);
3522+
ortho = std::make_shared<SLGridSlab>(nnmax, nmaxz, ngrid, zmax, cachename, type);
35073523

35083524
// Orthogonality sanity check
35093525
//

exputil/SLGridMP2.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1973,8 +1973,12 @@ void SLGridSlab::bomb(string oops)
19731973
// Constructors
19741974

19751975
SLGridSlab::SLGridSlab(int NUMK, int NMAX, int NUMZ, double ZMAX,
1976-
const std::string TYPE, bool VERBOSE)
1976+
const std::string cachename, const std::string TYPE,
1977+
bool VERBOSE)
19771978
{
1979+
if (cachename.size()) slab_cache_name = cachename;
1980+
else throw std::runtime_error("SLGridSlab: you must specify a cachename");
1981+
19781982
int kx, ky;
19791983

19801984
numk = NUMK;
@@ -2210,9 +2214,6 @@ SLGridSlab::SLGridSlab(int NUMK, int NMAX, int NUMZ, double ZMAX,
22102214
}
22112215

22122216

2213-
const string slab_cache_name = ".slgrid_slab_cache";
2214-
2215-
22162217
bool SLGridSlab::ReadH5Cache(void)
22172218
{
22182219
if (!cache) return false;

include/SLGridMP2.H

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,9 @@ private:
305305
void WriteH5Cache(void);
306306
//@}
307307

308+
//! Cache file name
309+
std::string slab_cache_name;
310+
308311
//! Cache versioning
309312
inline static const std::string Version = "1.0";
310313

@@ -412,7 +415,8 @@ public:
412415

413416
//! Constructor
414417
SLGridSlab(int kmax, int nmax, int numz, double zmax,
415-
const std::string type="isothermal", bool Verbose=false);
418+
const std::string cachename, const std::string type="isothermal",
419+
bool Verbose=false);
416420

417421
//! Destructor
418422
~SLGridSlab();

src/SlabSL.H

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
under the time-dependent basis expansion. For a basis fixed in time to
4949
the initial time: set to false.
5050
51+
@param cachename is the name of the basis cache file. This is a
52+
required parameter.
5153
*/
5254
class SlabSL : public PotAccel
5355
{
@@ -86,6 +88,7 @@ private:
8688
int imx, imy, imz, jmax, nnmax;
8789
double dfac;
8890
std::complex<double> kfac;
91+
std::string cachename;
8992

9093
std::vector<Eigen::VectorXd> zfrc, zpot;
9194

src/SlabSL.cc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ SlabSL::valid_keys = {
1818
"zmax",
1919
"ngrid",
2020
"type",
21-
"self_consistent"
21+
"self_consistent",
22+
"cachename"
2223
};
2324

2425
//@{
@@ -35,13 +36,17 @@ SlabSL::SlabSL(Component* c0, const YAML::Node& conf) : PotAccel(c0, conf)
3536
zmax = 10.0;
3637
hslab = 0.2;
3738
coef_dump = true;
39+
cachename = "";
3840

3941
#if HAVE_LIBCUDA==1
4042
cuda_aware = true;
4143
#endif
4244

4345
initialize();
4446

47+
if (cachename.size()==0)
48+
throw std::runtime_error("SlabSL: you must specify a cachename");
49+
4550
SLGridSlab::mpi = 1;
4651
SLGridSlab::ZBEG = 0.0;
4752
SLGridSlab::ZEND = 0.1;
@@ -51,7 +56,7 @@ SlabSL::SlabSL(Component* c0, const YAML::Node& conf) : PotAccel(c0, conf)
5156

5257
// Make the Sturm-Liouville grid and basis functions
5358
//
54-
grid = std::make_shared<SLGridSlab>(nnmax, nmaxz, ngrid, zmax, type);
59+
grid = std::make_shared<SLGridSlab>(nnmax, nmaxz, ngrid, zmax, cachename, type);
5560

5661
// Test for basis consistency (will generate an exception if maximum
5762
// error is out of tolerance)
@@ -167,6 +172,7 @@ void SlabSL::initialize()
167172
if (conf["hslab"]) hslab = conf["hslab"].as<double>();
168173
if (conf["zmax" ]) zmax = conf["zmax" ].as<double>();
169174
if (conf["type" ]) type = conf["type" ].as<std::string>();
175+
if (conf["cachename"]) cachename = conf["cachename"].as<std::string>();
170176

171177
if (conf["self_consistent"]) {
172178
self_consistent = conf["self_consistent"].as<bool>();

utils/SL/orthochk.cc

Lines changed: 30 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -4,171 +4,59 @@
44
#include <string>
55
#include <cmath>
66

7-
#include <getopt.h>
8-
97
#include "biorth1d.H"
108
#include "SLGridMP2.H"
119
#include "gaussQ.H"
1210
#include "localmpi.H"
11+
#include "cxxopts.H"
1312

14-
//===========================================================================
15-
16-
void usage(char *prog)
17-
{
18-
cout << "Usage:\n\n"
19-
<< prog << " [options]\n\n"
20-
<< setw(15) << "Option" << setw(10) << "Argument" << setw(10) << " "
21-
<< setiosflags(ios::left)
22-
<< setw(40) << "Description" << endl << endl
23-
<< resetiosflags(ios::left)
24-
<< setw(15) << "-m or --mpi" << setw(10) << "No" << setw(10) << " "
25-
<< setiosflags(ios::left)
26-
<< setw(40) << "Turn on MPI for SL computation" << endl
27-
<< resetiosflags(ios::left)
28-
<< setw(15) << "-t or --Trig" << setw(10) << "No" << setw(10) << " "
29-
<< setiosflags(ios::left)
30-
<< setw(40) << "Use trigonometric basis" << endl
31-
<< resetiosflags(ios::left)
32-
<< setw(15) << "-s or --SL" << setw(10) << "No" << setw(10) << " "
33-
<< setiosflags(ios::left)
34-
<< setw(40) << "Use Sturm-Liouville basis" << endl
35-
<< setw(15) << "-T or --type" << setw(10) << "string" << setw(10) << " "
36-
<< setiosflags(ios::left)
37-
<< setw(40) << "Density target (isothermal, constant, parabolic)" << endl
38-
<< resetiosflags(ios::left)
39-
<< setw(15) << "-n " << setw(10) << "int" << setw(10) << " "
40-
<< setiosflags(ios::left)
41-
<< setw(40) << "Number of basis functions" << endl
42-
<< resetiosflags(ios::left)
43-
<< setw(15) << "-H " << setw(10) << "double" << setw(10) << " "
44-
<< setiosflags(ios::left)
45-
<< setw(40) << "Slab scale height" << endl
46-
<< resetiosflags(ios::left)
47-
<< setw(15) << "-k " << setw(10) << "double" << setw(10) << " "
48-
<< setiosflags(ios::left)
49-
<< setw(40) << "Wave number for Trig basis" << endl
50-
<< resetiosflags(ios::left)
51-
<< setw(15) << "-x " << setw(10) << "double" << setw(10) << " "
52-
<< setiosflags(ios::left)
53-
<< setw(40) << "Wave number in X for SL basis" << endl
54-
<< resetiosflags(ios::left)
55-
<< setw(15) << "-y " << setw(10) << "double" << setw(10) << " "
56-
<< setiosflags(ios::left)
57-
<< setw(40) << "Wave number in Y for SL basis" << endl
58-
<< resetiosflags(ios::left)
59-
<< "" << endl;
60-
61-
exit(0);
62-
}
6313

6414
enum BioType1d {Trig, SL};
6515

6616
int
6717
main(int argc, char** argv)
6818
{
69-
bool use_mpi = false;
7019
double KX = 0.5;
7120
double H = 0.1;
7221
double ZMAX = 1.0;
7322
int NMAX = 10;
7423
int IKX = 1;
7524
int IKY = 3;
7625
BioType1d Type = Trig;
26+
std::string cachename = ".slab_sl_cache";
7727
std::string slabID = "iso";
28+
bool use_mpi = false;
7829

79-
int c;
80-
while (1) {
81-
int this_option_optind = optind ? optind : 1;
82-
int option_index = 0;
83-
static struct option long_options[] = {
84-
{"mpi", 0, 0, 0},
85-
{"Trig", 0, 0, 0},
86-
{"SL", 0, 0, 0},
87-
{0, 0, 0, 0}
88-
};
89-
90-
c = getopt_long (argc, argv, "msT:tx:y:k:n:z:H:h",
91-
long_options, &option_index);
92-
93-
if (c == -1) break;
94-
95-
switch (c) {
96-
case 0:
97-
{
98-
string optname(long_options[option_index].name);
99-
100-
if (!optname.compare("mpi")) {
101-
use_mpi = true;
102-
} else if (!optname.compare("Trig")) {
103-
Type = Trig;
104-
} else if (!optname.compare("SL")) {
105-
Type = SL;
106-
} else if (!optname.compare("type")) {
107-
slabID = optarg;
108-
} else {
109-
cout << "Option " << long_options[option_index].name;
110-
if (optarg) cout << " with arg " << optarg;
111-
cout << " is not defined " << endl;
112-
exit(0);
113-
}
114-
}
115-
break;
116-
117-
case 'm':
118-
use_mpi = true;
119-
break;
120-
121-
case 's':
122-
Type = SL;
123-
break;
124-
125-
case 'T':
126-
slabID = optarg;
127-
break;
128-
129-
case 't':
130-
Type = Trig;
131-
break;
132-
133-
case 'x':
134-
IKX = atoi(optarg);
135-
break;
136-
137-
case 'y':
138-
IKY = atoi(optarg);
139-
break;
140-
141-
case 'k':
142-
KX = atof(optarg);
143-
break;
144-
145-
case 'z':
146-
ZMAX = atof(optarg);
147-
break;
148-
149-
case 'H':
150-
H = atof(optarg);
151-
break;
152-
153-
case 'n':
154-
NMAX = atoi(optarg);
155-
break;
156-
157-
case 'h':
158-
default:
159-
usage(argv[0]);
160-
}
161-
30+
cxxopts::Options options("orthochk", "Check orthogonality of 1D basis functions");
31+
32+
options.add_options()
33+
("m,mpi", "Use MPI")
34+
("s,SL", "Use Sturm-Liouville slab basis")
35+
("T,type", "Slab type (iso, parabolic, or constant)", cxxopts::value<std::string>())
36+
("t,Trig", "Use trigonometric basis")
37+
("x,ikx", "IKX for SLGridSlab (default: 1)", cxxopts::value<int>())
38+
("y,iky", "IKY for SLGridSlab (default: 3)", cxxopts::value<int>())
39+
("k,kx", "KX for OneDTrig (default: 0.5)", cxxopts::value<double>())
40+
("z,zmax", "ZMAX for OneDTrig and SLGridSlab (default: 1.0)", cxxopts::value<double>())
41+
("H,h", "Scale height H for SLGridSlab (default: 0.1)", cxxopts::value<double>())
42+
("n,nmax", "NMAX for SLGridSlab (default: 10)", cxxopts::value<int>())
43+
("c,cachename", "Cache file name for SLGridSlab (default: .slab_sl_cache)", cxxopts::value<std::string>())
44+
("h,help", "Print usage");
45+
46+
auto result = options.parse(argc, argv);
47+
48+
if (result.count("mpi")) {
49+
local_init_mpi(argc, argv);
50+
use_mpi = true;
16251
}
16352

164-
//===================
165-
// MPI preliminaries
166-
//===================
167-
168-
if (use_mpi) {
169-
local_init_mpi(argc, argv);
53+
if (result.count("help")) {
54+
if (myid==0)
55+
std::cout << options.help() << std::endl;
56+
return 0;
17057
}
17158

59+
17260
//===================
17361
// Construct ortho
17462
//===================
@@ -190,7 +78,7 @@ main(int argc, char** argv)
19078
SLGridSlab::H = H;
19179
if (use_mpi) SLGridSlab::mpi = 1;
19280

193-
orthoSL = std::make_shared<SLGridSlab>(KMAX, NMAX, NUMZ, ZMAX, slabID, true);
81+
orthoSL = std::make_shared<SLGridSlab>(KMAX, NMAX, NUMZ, ZMAX, cachename, slabID, true);
19482
}
19583
break;
19684

0 commit comments

Comments
 (0)