Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clang compliance #90

Merged
merged 9 commits into from
Oct 16, 2024
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ set(CMAKE_FIND_PACKAGE_SORT_DIRECTION DEC)

find_package(MPI REQUIRED COMPONENTS C CXX)
find_package(OpenMP)
find_package(FFTW)
find_package(FFTW REQUIRED)
find_package(HDF5 COMPONENTS C CXX HL REQUIRED)
find_package(TIRPC) # Check for alternative Sun rpc support
find_package(Eigen3 REQUIRED)
Expand Down
10 changes: 5 additions & 5 deletions expui/BiorthBasis.cc
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ namespace BasisClasses
{
// Sanity check on derived class type
//
if (typeid(*coef) != typeid(CoefClasses::SphStruct))
if (not dynamic_cast<CoefClasses::SphStruct*>(coef.get()))
throw std::runtime_error("Spherical::set_coefs: you must pass a CoefClasses::SphStruct");

// Sanity check on dimensionality
Expand Down Expand Up @@ -1431,7 +1431,7 @@ namespace BasisClasses

void Cylindrical::set_coefs(CoefClasses::CoefStrPtr coef)
{
if (typeid(*coef) != typeid(CoefClasses::CylStruct))
if (not dynamic_cast<CoefClasses::CylStruct*>(coef.get()))
throw std::runtime_error("Cylindrical::set_coefs: you must pass a CoefClasses::CylStruct");

CoefClasses::CylStruct* cf = dynamic_cast<CoefClasses::CylStruct*>(coef.get());
Expand Down Expand Up @@ -1708,7 +1708,7 @@ namespace BasisClasses
{
// Sanity check on derived class type
//
if (typeid(*coef) != typeid(CoefClasses::CylStruct))
if (not dynamic_cast<CoefClasses::CylStruct*>(coef.get()))
throw std::runtime_error("FlatDisk::set_coefs: you must pass a CoefClasses::CylStruct");

// Sanity check on dimensionality
Expand Down Expand Up @@ -2140,7 +2140,7 @@ namespace BasisClasses
{
// Sanity check on derived class type
//
if (typeid(*coef) != typeid(CoefClasses::SlabStruct))
if (not dynamic_cast<CoefClasses::SlabStruct*>(coef.get()))
throw std::runtime_error("Slab::set_coefs: you must pass a CoefClasses::SlabStruct");

// Sanity check on dimensionality
Expand Down Expand Up @@ -2572,7 +2572,7 @@ namespace BasisClasses
{
// Sanity check on derived class type
//
if (typeid(*coef) != typeid(CoefClasses::CubeStruct))
if (not dynamic_cast<CoefClasses::CubeStruct*>(coef.get()))
throw std::runtime_error("Cube::set_coefs: you must pass a CoefClasses::CubeStruct");

// Sanity check on dimensionality
Expand Down
6 changes: 3 additions & 3 deletions expui/CoefContainer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ namespace MSSA
unpack_cylfld();
}
else {
throw std::runtime_error(std::string("CoefDB::unpack_channels(): can not reflect coefficient type=") + typeid(*coefs.get()).name());
throw std::runtime_error(std::string("CoefDB::unpack_channels(): can not reflect coefficient type=") + typeid(coefs.get()).name());
}

return coefs;
Expand All @@ -91,7 +91,7 @@ namespace MSSA
else if (dynamic_cast<CoefClasses::CylFldCoefs*>(coefs.get()))
{ } // Do nothing
else {
throw std::runtime_error(std::string("CoefDB::background(): can not reflect coefficient type=") + typeid(*coefs.get()).name());
throw std::runtime_error(std::string("CoefDB::background(): can not reflect coefficient type=") + typeid(coefs.get()).name());
}
}

Expand All @@ -112,7 +112,7 @@ namespace MSSA
else if (dynamic_cast<CoefClasses::CylFldCoefs*>(coefs.get()))
pack_cylfld();
else {
throw std::runtime_error(std::string("CoefDB::pack_channels(): can not reflect coefficient type=") + typeid(*coefs.get()).name());
throw std::runtime_error(std::string("CoefDB::pack_channels(): can not reflect coefficient type=") + typeid(coefs.get()).name());
}
}

Expand Down
23 changes: 22 additions & 1 deletion expui/FieldGenerator.H
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace Field

std::vector<double> times, pmin, pmax;
std::vector<int> grid;
Eigen::MatrixXd mesh;

//! Sanity check time vector with coefficient DB
void check_times(CoefClasses::CoefsPtr coefs);
Expand All @@ -35,12 +36,32 @@ namespace Field

public:

//! Constructor
//! Constructor for a rectangular grid
FieldGenerator(const std::vector<double> &time,
const std::vector<double> &pmin,
const std::vector<double> &pmax,
const std::vector<int> &grid);

//! Constructor for an arbitrary point mesh. The mesh should be
//! an Nx3 array
FieldGenerator(const std::vector<double> &time,
const Eigen::MatrixXd &mesh);

/** Get field quantities at user defined points

For example:
.
.
// Generate the fields for all coefficients in 'coefs'
auto db = points(basis, coefs);

// Get fields evaluated at Time=3.14 and for all points in
// your supplied mesh for density ("dens")
Eigen::MatrixXf points = db["3.14"]["dens"];
*/
std::map<double, std::map<std::string, Eigen::VectorXf>>
points(BasisClasses::BasisPtr basis, CoefClasses::CoefsPtr coefs);

/** Get a field slices as a map in time and type

For example:
Expand Down
178 changes: 178 additions & 0 deletions expui/FieldGenerator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,33 @@ namespace Field
}
}

FieldGenerator::FieldGenerator(const std::vector<double> &time,
const Eigen::MatrixXd &mesh) :

times(time), mesh(mesh)
{
// Sanity check on mesh
//
if (mesh.cols() != 3)
throw std::runtime_error("FieldGenerator: bad mesh specification. The mesh must be an Nx3 array where the columns are Cartesian points");

// Check whether MPI is initialized
//
int flag;
MPI_Initialized(&flag);
if (flag) use_mpi = true;
else use_mpi = false;


// Fall back sanity (works for me but this needs to be fixed
// generally)
//
if (use_mpi) {
MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
MPI_Comm_rank(MPI_COMM_WORLD, &myid);
}
}

void FieldGenerator::check_times(CoefClasses::CoefsPtr coefs)
{
std::vector<double> ctimes = coefs->Times();
Expand Down Expand Up @@ -867,5 +894,156 @@ namespace Field
}
// END histogram1d

std::map<double, std::map<std::string, Eigen::VectorXf>>
FieldGenerator::points(BasisClasses::BasisPtr basis,
CoefClasses::CoefsPtr coefs)
{
// Sanity check on mesh
//
if (mesh.size() == 0)
throw std::runtime_error("FieldGenerator::points: bad mesh specification. Did you call the mesh constructor?");

// Set midplane evaluation parameters
//
basis->setMidplane(midplane);
basis->setColumnHeight(colheight);

// Check
//
check_times(coefs);

std::map<double, std::map<std::string, Eigen::VectorXf>> ret;

// Now get the desired coordinate type
//
auto ctype = basis->coordinates;

// Field labels (force field labels added below)
//
auto labels = basis->getFieldLabels(ctype);

int ncnt = 0; // Process counter for MPI

std::map<std::string, Eigen::VectorXf> frame;
for (auto label : labels) {
frame[label].resize(mesh.rows());
}

for (auto T : times) {

if (ncnt++ % numprocs > 0) continue;

if (not coefs->getCoefStruct(T)) {
std::cout << "Could not find time=" << T << ", continuing" << std::endl;
continue;
}

basis->set_coefs(coefs->getCoefStruct(T));

#pragma omp parallel for
for (int k=0; k<mesh.rows(); k++) {

// Cartesian to spherical for all_eval
//
double x = mesh(k, 0);
double y = mesh(k, 1);
double z = mesh(k, 2);

// Coordinate values
double r, costh, phi, R;

// Return values
double p0, p1, d0, d1, f1, f2, f3;
std::vector<double> v;

if (ctype == BasisClasses::Basis::Coord::Spherical) {
r = sqrt(x*x + y*y + z*z) + 1.0e-18;
costh = z/r;
phi = atan2(y, x);
v = (*basis)(r, costh, phi, ctype);
} else if (ctype == BasisClasses::Basis::Coord::Cylindrical) {
R = sqrt(x*x + y*y) + 1.0e-18;
phi = atan2(y, x);
v = (*basis)(R, z, phi, ctype);
} else {
v = (*basis)(x, y, z, BasisClasses::Basis::Coord::Cartesian);
}

// Pack the frame structure
//
for (int n=0; n<labels.size(); n++)
frame[labels[n]](k) = v[n];
}

ret[T] = frame;
}

if (use_mpi) {

std::vector<char> bf(9);

for (int n=1; n<numprocs; n++) {

if (myid==n) {
int sz = ret.size();
MPI_Send(&sz, 1, MPI_INT, 0, 102, MPI_COMM_WORLD);
for (auto & v : ret) {
MPI_Send(&v.first, 1, MPI_DOUBLE, 0, 103, MPI_COMM_WORLD);
int fsz = v.second.size();
MPI_Send(&fsz, 1, MPI_INT, 0, 104, MPI_COMM_WORLD);

for (auto & f : v.second) {
MPI_Send(f.first.c_str(), f.first.length(), MPI_CHAR, 0, 105,
MPI_COMM_WORLD);

MPI_Send(f.second.data(), f.second.size(),
MPI_FLOAT, 0, 106, MPI_COMM_WORLD);
}
}
}

if (myid==0) {
MPI_Status status;
int sz, fsz, l;
double T;

MPI_Recv(&sz, 1, MPI_INT, n, 102, MPI_COMM_WORLD, &status);
for (int i=0; i<sz; i++) {
MPI_Recv(&T, 1, MPI_DOUBLE, n, 103, MPI_COMM_WORLD, &status);
MPI_Recv(&fsz, 1, MPI_INT, n, 104, MPI_COMM_WORLD, &status);

for (int j=0; j<fsz; j++) {
// Get the field name
//
MPI_Probe(n, 105, MPI_COMM_WORLD, &status);
MPI_Get_count(&status, MPI_CHAR, &l);
MPI_Recv(bf.data(), l, MPI_CHAR, n, 105, MPI_COMM_WORLD, &status);
std::string s(bf.data(), l);

// Sanity check
//
if (frame.find(s) == frame.end()) {
std::cerr << "Error finding <" << s << "> in field map"
<< std::endl;
}

// Get the data
//
MPI_Recv(frame[s].data(), frame[s].size(), MPI_FLOAT, n, 106,
MPI_COMM_WORLD, &status);
}

ret[T] = frame;
}
}
}
}

// Toggle off midplane evaluation
basis->setMidplane(false);

return ret;
}

}
// END namespace Field
7 changes: 4 additions & 3 deletions exputil/BarrierWrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,13 @@ void BarrierWrapper::light_operator(const string& label,

// Compare adjacent strings in the list
if (localid==0) {
char tmp[cbufsz]; // Working buffer
// Working buffer
auto tmp = std::make_unique<char[]>(cbufsz);
bool firstime = true;
string one, two = strncpy(tmp, &bufferT[0], cbufsz);
string one, two = strncpy(tmp.get(), &bufferT[0], cbufsz);
for (int n=1; n<commsize; n++) {
one = two;
two = strncpy(tmp, &bufferT[cbufsz*n], cbufsz);
two = strncpy(tmp.get(), &bufferT[cbufsz*n], cbufsz);
if (one.compare(two) != 0) {
if (firstime) {
cout << std::string(60,'-') << std::endl << left
Expand Down
2 changes: 1 addition & 1 deletion exputil/EmpCylSL.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5875,7 +5875,7 @@ void EmpCylSL::dump_images(const string& OUTFILE,
//============
// Open files
//============
std::ofstream out[Number];
auto out = std::make_unique<std::ofstream[]>(Number);
for (int j=0; j<Number; j++) {
Name = OUTFILE + Types[j] + ".eof_recon";
out[j].open(Name.c_str());
Expand Down
20 changes: 8 additions & 12 deletions exputil/GaussCore.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,18 @@
/*
Forward declaration for function QQp:
*/
static int QQp();
static int QQp(double, double*, double*);

/*
Function to test a real value for exceeding -1,
and quit on an error if condition not met.
*/
void GaussCheck(value)
double value;
void GaussCheck(double value)
{
if (value <= (-1.0)) {
fprintf(stderr, "Gauss package: parameter out of range: %g\n", value);
exit(1);
}
if (value <= (-1.0)) {
fprintf(stderr, "Gauss package: parameter out of range: %g\n", value);
exit(1);
}
}


Expand All @@ -54,11 +53,8 @@ static int n1;
/*
The workhorse.
*/
void GaussMaster(n, alpha, beta, conflag, abscis, weight)
int n;
double alpha, beta;
int conflag;
double abscis[], weight[];
void GaussMaster(int n, double alpha, double beta, int conflag,
double abscis[], double weight[])
{
#define FALSE 0
#define TRUE 1
Expand Down
6 changes: 4 additions & 2 deletions exputil/GaussCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
#define CONFLUENT 1
#define NOCONFLUENT 0

extern void GaussMaster();
extern void GaussCheck();
extern void GaussMaster(int n, double alpha, double beta, int conflag,
double abscis[], double weight[]);

extern void GaussCheck(double value);

/* ARGUMENT LISTS:

Expand Down
Loading