Skip to content

Commit 15e2fed

Browse files
author
Martin D. Weinberg
committed
A few minor fixes to case handling
1 parent b515bc1 commit 15e2fed

3 files changed

Lines changed: 76 additions & 45 deletions

File tree

expui/BiorthBasis.cc

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ namespace BasisClasses
753753
double tpotx = v[6]*x/R - v[8]*y/R ;
754754
double tpoty = v[6]*y/R + v[8]*x/R ;
755755

756-
return {v[0], v[1], v[2], v[3]*G, v[4]*G, v[5]*G, tpotx*G, tpoty*G, v[7]*G};
756+
return {v[0], v[1], v[2], v[3], v[4], v[5], tpotx, tpoty, v[7]};
757757
}
758758

759759
Spherical::BasisArray SphericalSL::getBasis
@@ -2053,9 +2053,9 @@ namespace BasisClasses
20532053
if (R>ortho->getRtable() or fabs(z)>ortho->getRtable()) {
20542054
double r2 = R*R + z*z;
20552055
double r = sqrt(r2);
2056-
pot0 = -totalMass/r;
2057-
rpot = -totalMass*R/(r*r2 + 10.0*std::numeric_limits<double>::min());
2058-
zpot = -totalMass*z/(r*r2 + 10.0*std::numeric_limits<double>::min());
2056+
pot0 = -G*totalMass/r;
2057+
rpot = -G*totalMass*R/(r*r2 + 10.0*std::numeric_limits<double>::min());
2058+
zpot = -G*totalMass*z/(r*r2 + 10.0*std::numeric_limits<double>::min());
20592059

20602060
return {den0, den1, den0+den1, pot0, pot1, pot0+pot1, rpot, zpot, ppot};
20612061
}
@@ -2158,8 +2158,8 @@ namespace BasisClasses
21582158
double r2 = R*R + z*z;
21592159
double r = sqrt(r2);
21602160

2161-
rpot = -totalMass*R/(r*r2 + 10.0*std::numeric_limits<double>::min());
2162-
zpot = -totalMass*z/(r*r2 + 10.0*std::numeric_limits<double>::min());
2161+
rpot = -G*totalMass*R/(r*r2 + 10.0*std::numeric_limits<double>::min());
2162+
zpot = -G*totalMass*z/(r*r2 + 10.0*std::numeric_limits<double>::min());
21632163

21642164
return {rpot, zpot, ppot};
21652165
}
@@ -2218,9 +2218,9 @@ namespace BasisClasses
22182218
}
22192219
}
22202220

2221-
rpot *= -1.0;
2222-
zpot *= -1.0;
2223-
ppot *= -1.0;
2221+
rpot *= -G;
2222+
zpot *= -G;
2223+
ppot *= -G;
22242224

22252225
double potx = rpot*x/R - ppot*y/R;
22262226
double poty = rpot*y/R + ppot*x/R;
@@ -2910,10 +2910,10 @@ namespace BasisClasses
29102910

29112911
den0 *= -1.0;
29122912
den1 *= -1.0;
2913-
pot0 *= -1.0;
2914-
pot1 *= -1.0;
2915-
rpot *= -1.0;
2916-
ppot *= -1.0;
2913+
pot0 *= -G;
2914+
pot1 *= -G;
2915+
rpot *= -G;
2916+
ppot *= -G;
29172917

29182918
return {den0, den1, den0+den1, pot0, pot1, pot0+pot1, rpot, zpot, ppot};
29192919
}
@@ -2977,8 +2977,8 @@ namespace BasisClasses
29772977
}
29782978
}
29792979

2980-
rpot *= -1.0;
2981-
ppot *= -1.0;
2980+
rpot *= -G;
2981+
ppot *= -G;
29822982

29832983

29842984
double potx = rpot*x/R - ppot*y/R;
@@ -3472,7 +3472,7 @@ namespace BasisClasses
34723472
}
34733473
}
34743474

3475-
return {accx.real(), accy.real(), accz.real()};
3475+
return {G*accx.real(), G*accy.real(), G*accz.real()};
34763476
}
34773477

34783478

@@ -3483,7 +3483,7 @@ namespace BasisClasses
34833483

34843484
auto [pot, den, frcx, frcy, frcz] = eval(x, y, z);
34853485

3486-
return {0, den, den, 0, pot, pot, frcx, frcy, frcz};
3486+
return {0, den, den, 0, pot*G, pot*G, frcx*G, frcy*G, frcz*G};
34873487
}
34883488

34893489
std::vector<double> Slab::cyl_eval(double R, double z, double phi)
@@ -3500,11 +3500,11 @@ namespace BasisClasses
35003500
double potp = -frcx*sin(phi) + frcy*cos(phi);
35013501
double potz = frcz;
35023502

3503-
potR *= -1;
3504-
potp *= -1;
3505-
potz *= -1;
3503+
potR *= -G;
3504+
potp *= -G;
3505+
potz *= -G;
35063506

3507-
return {0, den, den, 0, pot, pot, potR, potz, potp};
3507+
return {0, den, den, 0, pot*G, pot*G, potR, potz, potp};
35083508
}
35093509

35103510
std::vector<double> Slab::sph_eval(double r, double costh, double phi)
@@ -3522,11 +3522,11 @@ namespace BasisClasses
35223522
double pott = frcx*cos(phi)*costh + frcy*sin(phi)*costh - frcz*sinth;
35233523
double potp = -frcx*sin(phi) + frcy*cos(phi);
35243524

3525-
potr *= -1;
3526-
pott *= -1;
3527-
potp *= -1;
3525+
potr *= -G;
3526+
pott *= -G;
3527+
potp *= -G;
35283528

3529-
return {0, den, den, 0, pot, pot, potr, pott, potp};
3529+
return {0, den, den, 0, pot*G, pot*G, potr, pott, potp};
35303530
}
35313531

35323532

@@ -3841,7 +3841,7 @@ namespace BasisClasses
38413841
double frcy = -frc(1).real();
38423842
double frcz = -frc(2).real();
38433843

3844-
return {0, den1, den1, 0, pot1, pot1, frcx, frcy, frcz};
3844+
return {0, den1, den1, 0, pot1*G, pot1*G, frcx*G, frcy*G, frcz*G};
38453845
}
38463846

38473847
std::vector<double> Cube::getAccel(double x, double y, double z)
@@ -3855,7 +3855,7 @@ namespace BasisClasses
38553855
// Get the basis fields
38563856
auto frc = ortho->get_force(expcoef, pos);
38573857

3858-
return {-frc(0).real(), -frc(1).real(), -frc(2).real()};
3858+
return {-G*frc(0).real(), -G*frc(1).real(), -G*frc(2).real()};
38593859
}
38603860

38613861
std::vector<double> Cube::cyl_eval(double R, double z, double phi)
@@ -3873,7 +3873,7 @@ namespace BasisClasses
38733873
double den1 = ortho->get_dens(expcoef, pos).real();
38743874
double pot1 = ortho->get_pot (expcoef, pos).real();
38753875

3876-
auto frc = ortho->get_force(expcoef, pos);
3876+
auto frc = ortho->get_force(expcoef, pos)*G;
38773877

38783878
double frcx = frc(0).real(), frcy = frc(1).real(), frcz = frc(2).real();
38793879

@@ -3902,7 +3902,7 @@ namespace BasisClasses
39023902

39033903
// Get the basis fields
39043904
double den1 = ortho->get_dens(expcoef, pos).real();
3905-
double pot1 = ortho->get_pot (expcoef, pos).real();
3905+
double pot1 = ortho->get_pot (expcoef, pos).real() * G;
39063906

39073907
auto frc = ortho->get_force(expcoef, pos);
39083908

@@ -3914,9 +3914,9 @@ namespace BasisClasses
39143914
double pott = frcx*cos(phi)*costh + frcy*sin(phi)*costh - frcz*sinth;
39153915
double potp = -frcx*sin(phi) + frcy*cos(phi);
39163916

3917-
potr *= -1;
3918-
pott *= -1;
3919-
potp *= -1;
3917+
potr *= -G;
3918+
pott *= -G;
3919+
potp *= -G;
39203920

39213921
return {0, den1, den1, 0, pot1, pot1, potr, pott, potp};
39223922
}

expui/Coefficients.H

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,13 @@ namespace CoefClasses
3737

3838
Unit(std::string n, std::string u, float v) : value(v)
3939
{
40-
std::memset(name, 0, 16); std::memset(unit, 0, 16);
41-
size_t arraySize = n.length() + 1, sz = strlen(name);
42-
strncpy(name, n.c_str(), std::min(arraySize, sz));
43-
arraySize = u.length() + 1; sz = strlen(unit);
44-
strncpy(unit, u.c_str(), std::min(arraySize, sz));
40+
// Constant string size
41+
const size_t sz=16;
42+
// Zero fill
43+
std::memset(name, 0, sz); std::memset(unit, 0, sz);
44+
// Copy strings to char arrays
45+
strncpy(name, n.c_str(), std::min(n.length()+1, sz));
46+
strncpy(unit, u.c_str(), std::min(u.length()+1, sz));
4547
}
4648

4749
};
@@ -106,8 +108,8 @@ namespace CoefClasses
106108
//! Time offset for interpolation
107109
double deltaT;
108110

109-
//! Default units
110-
std::vector<Unit> units {{"G", "", 1.0f}};
111+
//! Default units (EXP native)
112+
std::vector<Unit> units {{"G", "none", 1.0f}};
111113

112114
public:
113115

expui/Coefficients.cc

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,32 @@ HighFive::CompoundType create_compound_Unit() {
3131
HIGHFIVE_REGISTER_TYPE(CoefClasses::Unit, create_compound_Unit)
3232

3333

34+
// Helper ostream manipulator for debugging Unit info
35+
std::ostream& operator<< (std::ostream& out,
36+
const std::vector<CoefClasses::Unit>& t)
37+
{
38+
out << std::string(48, '-') << std::endl
39+
<< std::setw(16) << "Name"
40+
<< std::setw(16) << "Unit"
41+
<< std::setw(16) << "Value"
42+
<< std::endl
43+
<< std::setw(16) << std::string(10, '-')
44+
<< std::setw(16) << std::string(10, '-')
45+
<< std::setw(16) << std::string(10, '-')
46+
<< std::endl;
47+
for (auto p : t)
48+
out << std::setw(16) << p.name
49+
<< std::setw(16) << p.unit
50+
<< std::setw(16) << p.value
51+
<< std::endl;
52+
out << std::string(48, '-') << std::endl;
53+
54+
return out;
55+
}
56+
3457
namespace CoefClasses
3558
{
59+
3660
void Coefs::copyfields(std::shared_ptr<Coefs> p)
3761
{
3862
// These variables will copy data, not pointers
@@ -44,13 +68,17 @@ namespace CoefClasses
4468
p->times = times;
4569
}
4670

47-
void Coefs::setUnit(std::string name, std::string unit, float value)
71+
void Coefs::setUnit(std::string Name, std::string Unit, float Value)
4872
{
4973
auto copy_s = [](std::string& s, char* c) -> void {
50-
size_t arraySize = s.length() + 1, sz = strlen(c);
51-
strncpy(c, s.c_str(), std::min(arraySize, sz));
74+
const size_t sz = 16;
75+
strncpy(c, s.c_str(), std::min(s.length()+1, sz));
5276
};
5377

78+
// Keep copy with original case
79+
std::string name(Name);
80+
81+
// Convert to lower case for matching
5482
std::transform(name.begin(), name.end(), name.begin(),
5583
[](unsigned char c){ return std::tolower(c); });
5684

@@ -61,14 +89,14 @@ namespace CoefClasses
6189
[](unsigned char c){ return std::tolower(c); });
6290

6391
if (name.find(p_name) == 0) {
64-
copy_s(unit, &p.unit[0]);
65-
p.value = value;
92+
copy_s(Unit, &p.unit[0]);
93+
p.value = Value;
6694
return;
6795
}
6896
}
6997

7098
// No matches
71-
units.push_back({name, unit, value});
99+
units.push_back({Name, Unit, Value});
72100
}
73101

74102
//! Get units
@@ -94,6 +122,7 @@ namespace CoefClasses
94122
void Coefs::WriteH5Units(HighFive::File& file)
95123
{
96124
HighFive::DataSet dataset = file.createDataSet("Units", units);
125+
std::cout << units;
97126
}
98127

99128
void Coefs::ReadH5Units(HighFive::File& file)

0 commit comments

Comments
 (0)