Skip to content

Commit

Permalink
Revert "Merge pull request #54 from EXP-code/CTests"
Browse files Browse the repository at this point in the history
This reverts commit d378c9a, reversing
changes made to 18bcb38.

It seems that main crept too far ahead of the CTest for a successful
merge.  I'll have to sort out the CTest mess later.
  • Loading branch information
Martin D. Weinberg committed Dec 29, 2023
1 parent d378c9a commit 3e17554
Show file tree
Hide file tree
Showing 15 changed files with 64 additions and 247 deletions.
43 changes: 7 additions & 36 deletions coefs/BasisFactory.H
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <YamlCheck.H>
#include <BiorthCyl.H>
#include <EmpCylSL.H>
#include <exputils.H>
#include <localmpi.H>

namespace Field
Expand Down Expand Up @@ -370,22 +369,13 @@ namespace BasisClasses
BasisArray getBasis
(double logxmin=-3.0, double logxmax=0.5, int numgrid=2000);

//! Compute the orthogonality of the basis by returning
//! inner-product matrices
std::vector<Eigen::MatrixXd> orthoCheck(int knots=100)
//! Compute the orthogonality of the basis by returning inner
//! produce matrices
std::vector<Eigen::MatrixXd> orthoCheck(int knots=40)
{
return sl->orthoCheck(knots);
}

//! Biorthogonality sanity check
bool orthoTest(int knots=100)
{
auto [ret, worst, lworst] = orthoCompute(sl->orthoCheck(knots));
// For the CTest log
std::cout << "SphericalSL::orthoTest: worst=" << worst << std::endl;
return ret;
}

};

/**
Expand Down Expand Up @@ -514,19 +504,10 @@ namespace BasisClasses
BasisArray getBasis
(double logxmin=-3.0, double logxmax=0.5, int numgrid=2000);

//! Compute the orthogonality of the basis by returning
//! inner-product matrices
//! Compute the orthogonality of the basis by returning inner
//! produce matrices
std::vector<Eigen::MatrixXd> orthoCheck();

//! Biorthogonality sanity check
bool orthoTest()
{
auto [ret, worst, lworst] = orthoCompute(orthoCheck());
// For the CTest log
std::cout << "FlatDisk::orthoTest: worst=" << worst << std::endl;
return ret;
}

};

/**
Expand Down Expand Up @@ -674,22 +655,12 @@ namespace BasisClasses
(double xmin=0.0, double xmax=1.0, int numr=40,
double zmin=-0.1, double zmax=0.1, int numz=40);

//! Compute the orthogonality of the basis by returning
//! inner-product matrices
//! Compute the orthogonality of the basis by returning inner
//! produce matrices
std::vector<Eigen::MatrixXd> orthoCheck()
{
return sl->orthoCheck();
}

//! Biorthogonality sanity check
bool orthoTest()
{
auto [ret, worst, lworst] = orthoCompute(sl->orthoCheck());
// For the CTest log
std::cout << "Cylindrical::orthoTest: worst=" << worst << std::endl;
return ret;
}

};

/**
Expand Down
5 changes: 3 additions & 2 deletions coefs/BasisFactory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <EXPException.H>
#include <BasisFactory.H>
#include <DiskModels.H>
#include <exputils.H>
#include <gaussQ.H>

#ifdef HAVE_FE_ENABLE
Expand Down Expand Up @@ -319,7 +320,7 @@ namespace BasisClasses
0, 1, cachename);

// Test basis for consistency
orthoCompare(orthoCheck(std::max<int>(nmax*50, 200)), classname(), harmonic());
orthoTest(orthoCheck(std::max<int>(nmax*50, 200)), classname(), harmonic());

// Number of possible threads
int nthrds = omp_get_max_threads();
Expand Down Expand Up @@ -1655,7 +1656,7 @@ namespace BasisClasses

// Orthogonality sanity check
//
orthoCompare(orthoCheck(), classname(), harmonic());
orthoTest(orthoCheck(), classname(), harmonic());

// Get max threads
//
Expand Down
36 changes: 11 additions & 25 deletions exputil/BiorthCyl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,6 @@ using namespace __EXP__; // For reference to n-body globals
// Constructor
BiorthCyl::BiorthCyl(const YAML::Node& conf) : conf(conf)
{
// Check whether MPI is initialized. Use flag to suppress MPI calls
// if MPI is not active.
//
{
int flag;
MPI_Initialized(&flag);
if (flag) use_mpi = true;
else use_mpi = false;
}

// Read and assign parameters
//
try {
Expand Down Expand Up @@ -120,7 +110,7 @@ BiorthCyl::BiorthCyl(const YAML::Node& conf) : conf(conf)
<< std::string(60, '-') << std::endl
<< conf
<< std::string(60, '-') << std::endl;
if (use_mpi) MPI_Finalize();
MPI_Finalize();
exit(-1);
}

Expand Down Expand Up @@ -164,7 +154,6 @@ void BiorthCyl::initialize()
zforce[m][n].resize(numx, numy);
}
}

}

void BiorthCyl::create_tables()
Expand Down Expand Up @@ -241,21 +230,18 @@ void BiorthCyl::create_tables()
}
// END: m loop

// Does not require mpi; mpid=0 for non-MPI invocations
if (verbose and myid==0) std::cout << std::endl;

if (use_mpi) {
for (int m=0; m<=mmax; m++) {
for (int n=0; n<nmax; n++) {
MPI_Allreduce(MPI_IN_PLACE, dens [m][n].data(), numx*numy,
MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
MPI_Allreduce(MPI_IN_PLACE, pot [m][n].data(), numx*numy,
MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
MPI_Allreduce(MPI_IN_PLACE, rforce[m][n].data(), numx*numy,
MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
MPI_Allreduce(MPI_IN_PLACE, zforce[m][n].data(), numx*numy,
MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
}
for (int m=0; m<=mmax; m++) {
for (int n=0; n<nmax; n++) {
MPI_Allreduce(MPI_IN_PLACE, dens [m][n].data(), numx*numy,
MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
MPI_Allreduce(MPI_IN_PLACE, pot [m][n].data(), numx*numy,
MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
MPI_Allreduce(MPI_IN_PLACE, rforce[m][n].data(), numx*numy,
MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
MPI_Allreduce(MPI_IN_PLACE, zforce[m][n].data(), numx*numy,
MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
}
}

Expand Down
28 changes: 9 additions & 19 deletions exputil/orthoTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#include <localmpi.H> // MPI support
#include <libvars.H> // For orthoTol

std::tuple<bool, double, std::vector<double>>
orthoCompute(const std::vector<Eigen::MatrixXd>& tests)
void orthoTest(const std::vector<Eigen::MatrixXd>& tests,
const std::string& classname, const std::string& indexname)
{
// Number of possible threads
int nthrds = omp_get_max_threads();
Expand Down Expand Up @@ -53,28 +53,18 @@ orthoCompute(const std::vector<Eigen::MatrixXd>& tests)
double worst_ever = *std::max_element(lworst.begin(), lworst.end());

if (worst_ever > __EXP__::orthoTol) {
return {false, worst_ever, lworst};
} else {
return {true, worst_ever, lworst};
}
}


void orthoCompare(const std::vector<Eigen::MatrixXd>& tests,
const std::string& classname, const std::string& indexname)
{
auto [good, worst, lworst] = orthoCompute(tests);

if (good) {
if (myid==0)
std::cout << classname + ": biorthogonal check passed" << std::endl;
} else {
std::cout << classname << ": orthogonality failure" << std::endl
<< std::right
<< std::setw(4) << indexname
<< std::setw(16) << "Worst" << std::endl;
for (int l=0; l<lworst.size(); l++) {
for (int l=0; l<tests.size(); l++) {
std::cout << std::setw(4) << l << std::setw(16) << lworst[l] << std::endl;
}

throw std::runtime_error(classname + ": biorthogonal sanity check");
} else {
if (myid==0)
std::cout << classname + ": biorthogonal check passed" << std::endl;
}
}

6 changes: 3 additions & 3 deletions include/BiorthCyl.H
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ protected:
//! Read the HDF5 cache
virtual bool ReadH5Cache();

//! Flag for MPI enabled (default: 0=off)
int use_mpi;

public:

//! Flag for MPI enabled (default: 0=off)
static int mpi;

//! Constructor
BiorthCyl(const YAML::Node& conf);

Expand Down
12 changes: 2 additions & 10 deletions include/exputils.H
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,7 @@
#include <string>
#include <Eigen/Eigen>

//! Compare biorthogoal matrices with idenity and return worst case
//! error and success value based on __EXP__::orthoTol
std::tuple<bool, double, std::vector<double>>
orthoCompute(const std::vector<Eigen::MatrixXd>& tests);

//! Use orthoCompute() to compare biorthogonal matrices with idenity
//! and throw std::runtime_error if worst case exceeds tolerance
void
orthoCompare(const std::vector<Eigen::MatrixXd>& tests,
const std::string& classname, const std::string& indexname);
void orthoTest(const std::vector<Eigen::MatrixXd>& tests,
const std::string& classname, const std::string& indexname);

#endif
60 changes: 5 additions & 55 deletions pyEXP/BasisWrappers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -868,25 +868,7 @@ void BasisFactoryClasses(py::module &m) {
list(numpy.ndarray)
list of numpy.ndarrays from [0, ... , Lmax]
)",
py::arg("knots")=100)
.def("orthoTest", [](BasisClasses::SphericalSL& A, int knots)
{
return A.orthoTest(knots);
},
R"(
Check orthgonality of basis functions by quadrature and return
success value. Uses orthoCheck() to test orthogonality.
Parameters
----------
knots : int, default=40
Number of quadrature knots
Returns
-------
boolean
)",
py::arg("knots")=100)
py::arg("knots")=40)
.def_static("cacheInfo", [](std::string cachefile)
{
return BasisClasses::SphericalSL::cacheInfo(cachefile);
Expand Down Expand Up @@ -973,31 +955,14 @@ void BasisFactoryClasses(py::module &m) {
Parameters
----------
None
knots : int
Number of quadrature knots
Returns
-------
list(numpy.ndarray)
list of numpy.ndarrays from [0, ... , Mmax]
)")
.def("orthoTest", [](BasisClasses::Cylindrical& A)
{
return A.orthoTest();
},
R"(
Check orthgonality of basis functions by quadrature.
Uses orthoTest() to return a success value based on distance
from the identity matrix.
Parameters
----------
None
Returns
-------
boolean
)")
.def_static("cacheInfo", [](std::string cachefile)
{
return BasisClasses::Cylindrical::cacheInfo(cachefile);
Expand Down Expand Up @@ -1077,30 +1042,15 @@ void BasisFactoryClasses(py::module &m) {
Parameters
----------
None
knots : int, default=40
Number of quadrature knots
Returns
-------
list(numpy.ndarray)
list of numpy.ndarrays from [0, ... , Mmax]
)"
)
.def("orthoTest", [](BasisClasses::FlatDisk& A)
{
return A.orthoTest();
},
R"(
Check orthgonality of basis functions by quadrature and return
success value. Uses orthoCheck() to test orthogonality.
Parameters
----------
None
Returns
-------
boolean
)")
.def_static("cacheInfo", [](std::string cachefile)
{
return BasisClasses::FlatDisk::cacheInfo(cachefile);
Expand Down
2 changes: 1 addition & 1 deletion src/Cylinder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ Cylinder::Cylinder(Component* c0, const YAML::Node& conf, MixtureBasis *m) :
// error is out of tolerance)
//
std::cout << "---- ";
orthoCompare(ortho->orthoCheck(), "Cylinder", "m");
orthoTest(ortho->orthoCheck(), "Cylinder", "m");

// Initialize internal variables
//
Expand Down
12 changes: 9 additions & 3 deletions src/OutLog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,21 @@ void OutLog::Run(int n, int mstep, bool last)
std::ifstream in(backupfile.c_str());

if (in.fail()) {
std::ostringstream message;
ostringstream message;
message << "OutLog: error opening original log file <"
<< backupfile << "> for reading";
throw GenericError(message.str(), __FILE__, __LINE__, 1036, true);
}

// Temporary character buffer
const int cbufsiz = 16384;
auto cbuffer = std::make_unique<char[]>(cbufsiz);
std::shared_ptr<char> cbuffer;

// Use this as of C++17
// info = std::make_shared<char[]>(ninfochar+1);

// C++14 workaround:
cbuffer = std::shared_ptr<char>(new char[cbufsiz],
std::default_delete<char[]>());

// Null fill the buffer
std::fill(cbuffer.get(), cbuffer.get()+cbufsiz, 0);
Expand Down
Loading

0 comments on commit 3e17554

Please sign in to comment.