mirror of
https://github.com/paboyle/Grid.git
synced 2025-04-07 04:35:56 +01:00
Hadrons: proper metadata for eigenpacks
This commit is contained in:
parent
fb62035aa0
commit
d3f857b1c9
@ -44,9 +44,23 @@ class EigenPack
|
||||
{
|
||||
public:
|
||||
typedef F Field;
|
||||
struct PackRecord: Serializable
|
||||
{
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(PackRecord,
|
||||
std::string, operatorPar,
|
||||
std::string, solverPar);
|
||||
};
|
||||
struct VecRecord: Serializable
|
||||
{
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(VecRecord,
|
||||
unsigned int, index,
|
||||
double, eval);
|
||||
VecRecord(void): index(0), eval(0.) {}
|
||||
};
|
||||
public:
|
||||
std::vector<RealD> eval;
|
||||
std::vector<F> evec;
|
||||
PackRecord record;
|
||||
public:
|
||||
EigenPack(void) = default;
|
||||
virtual ~EigenPack(void) = default;
|
||||
@ -68,10 +82,10 @@ public:
|
||||
|
||||
makeFilenames(evecFilename, evalFilename, fileStem, traj);
|
||||
XmlReader xmlReader(evalFilename);
|
||||
basicRead(evec, evecFilename, evec.size());
|
||||
LOG(Message) << "Reading " << eval.size() << " eigenvalues from '"
|
||||
<< evalFilename << "'" << std::endl;
|
||||
Grid::read(xmlReader, "evals", eval);
|
||||
basicRead(evec, evecFilename, evec.size());
|
||||
}
|
||||
|
||||
virtual void write(const std::string fileStem, const int traj = -1)
|
||||
@ -80,10 +94,10 @@ public:
|
||||
|
||||
makeFilenames(evecFilename, evalFilename, fileStem, traj);
|
||||
XmlWriter xmlWriter(evalFilename);
|
||||
basicWrite(evecFilename, evec, evec.size());
|
||||
LOG(Message) << "Writing " << eval.size() << " eigenvalues to '"
|
||||
<< evalFilename << "'" << std::endl;
|
||||
Grid::write(xmlWriter, "evals", eval);
|
||||
basicWrite(evecFilename, evec, evec.size());
|
||||
}
|
||||
protected:
|
||||
void makeFilenames(std::string &evecFilename, std::string &evalFilename,
|
||||
@ -96,31 +110,43 @@ protected:
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static void basicRead(std::vector<T> &evec, const std::string filename,
|
||||
const unsigned int size)
|
||||
void basicRead(std::vector<T> &evec, const std::string filename,
|
||||
const unsigned int size)
|
||||
{
|
||||
emptyUserRecord record;
|
||||
ScidacReader binReader;
|
||||
|
||||
binReader.open(filename);
|
||||
binReader.readScidacFileRecord(evec[0]._grid, record);
|
||||
for(int k = 0; k < size; ++k)
|
||||
{
|
||||
binReader.readScidacFieldRecord(evec[k], record);
|
||||
VecRecord vecRecord;
|
||||
|
||||
binReader.readScidacFieldRecord(evec[k], vecRecord);
|
||||
if (vecRecord.index != k)
|
||||
{
|
||||
HADRON_ERROR(Io, "Eigenvector " + std::to_string(k) + " has a"
|
||||
+ " wrong index (expected " + std::to_string(vecRecord.index)
|
||||
+ ") in file '" + filename + "'");
|
||||
}
|
||||
}
|
||||
binReader.close();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static void basicWrite(const std::string filename, std::vector<T> &evec,
|
||||
const unsigned int size)
|
||||
void basicWrite(const std::string filename, std::vector<T> &evec,
|
||||
const unsigned int size)
|
||||
{
|
||||
emptyUserRecord record;
|
||||
ScidacWriter binWriter(evec[0]._grid->IsBoss());
|
||||
|
||||
binWriter.open(filename);
|
||||
binWriter.writeScidacFileRecord(evec[0]._grid, record);
|
||||
for(int k = 0; k < size; ++k)
|
||||
{
|
||||
binWriter.writeScidacFieldRecord(evec[k], record);
|
||||
VecRecord vecRecord;
|
||||
|
||||
vecRecord.index = k;
|
||||
vecRecord.eval = eval[k];
|
||||
binWriter.writeScidacFieldRecord(evec[k], vecRecord);
|
||||
}
|
||||
binWriter.close();
|
||||
}
|
||||
@ -160,12 +186,12 @@ public:
|
||||
this->makeFilenames(evecFineFilename, evalFineFilename,
|
||||
fileStem + "_fine", traj);
|
||||
XmlReader xmlFineReader(evalFineFilename);
|
||||
LOG(Message) << "Reading " << this->evec.size() << " fine eigenvectors from '"
|
||||
<< evecFineFilename << "'" << std::endl;
|
||||
this->basicRead(this->evec, evecFineFilename, this->evec.size());
|
||||
LOG(Message) << "Reading " << this->eval.size() << " fine eigenvalues from '"
|
||||
<< evalFineFilename << "'" << std::endl;
|
||||
Grid::read(xmlFineReader, "evals", this->eval);
|
||||
LOG(Message) << "Reading " << this->evec.size() << " fine eigenvectors from '"
|
||||
<< evecFineFilename << "'" << std::endl;
|
||||
this->basicRead(this->evec, evecFineFilename, this->evec.size());
|
||||
}
|
||||
|
||||
void readCoarse(const std::string fileStem, const int traj = -1)
|
||||
@ -175,12 +201,12 @@ public:
|
||||
this->makeFilenames(evecCoarseFilename, evalCoarseFilename,
|
||||
fileStem + "_coarse", traj);
|
||||
XmlReader xmlCoarseReader(evalCoarseFilename);
|
||||
LOG(Message) << "Reading " << evecCoarse.size() << " coarse eigenvectors from '"
|
||||
<< evecCoarseFilename << "'" << std::endl;
|
||||
this->basicRead(evecCoarse, evecCoarseFilename, evecCoarse.size());
|
||||
LOG(Message) << "Reading " << evalCoarse.size() << " coarse eigenvalues from '"
|
||||
<< evalCoarseFilename << "'" << std::endl;
|
||||
Grid::read(xmlCoarseReader, "evals", evalCoarse);
|
||||
LOG(Message) << "Reading " << evecCoarse.size() << " coarse eigenvectors from '"
|
||||
<< evecCoarseFilename << "'" << std::endl;
|
||||
this->basicRead(evecCoarse, evecCoarseFilename, evecCoarse.size());
|
||||
}
|
||||
|
||||
virtual void read(const std::string fileStem, const int traj = -1)
|
||||
@ -196,12 +222,12 @@ public:
|
||||
this->makeFilenames(evecFineFilename, evalFineFilename,
|
||||
fileStem + "_fine", traj);
|
||||
XmlWriter xmlFineWriter(evalFineFilename);
|
||||
LOG(Message) << "Writing " << this->evec.size() << " fine eigenvectors to '"
|
||||
<< evecFineFilename << "'" << std::endl;
|
||||
this->basicWrite(evecFineFilename, this->evec, this->evec.size());
|
||||
LOG(Message) << "Writing " << this->eval.size() << " fine eigenvalues to '"
|
||||
<< evalFineFilename << "'" << std::endl;
|
||||
Grid::write(xmlFineWriter, "evals", this->eval);
|
||||
LOG(Message) << "Writing " << this->evec.size() << " fine eigenvectors to '"
|
||||
<< evecFineFilename << "'" << std::endl;
|
||||
this->basicWrite(evecFineFilename, this->evec, this->evec.size());
|
||||
}
|
||||
|
||||
void writeCoarse(const std::string fileStem, const int traj = -1)
|
||||
@ -211,12 +237,12 @@ public:
|
||||
this->makeFilenames(evecCoarseFilename, evalCoarseFilename,
|
||||
fileStem + "_coarse", traj);
|
||||
XmlWriter xmlCoarseWriter(evalCoarseFilename);
|
||||
LOG(Message) << "Writing " << evecCoarse.size() << " coarse eigenvectors to '"
|
||||
<< evecCoarseFilename << "'" << std::endl;
|
||||
this->basicWrite(evecCoarseFilename, evecCoarse, evecCoarse.size());
|
||||
LOG(Message) << "Writing " << evalCoarse.size() << " coarse eigenvalues to '"
|
||||
<< evalCoarseFilename << "'" << std::endl;
|
||||
Grid::write(xmlCoarseWriter, "evals", evalCoarse);
|
||||
LOG(Message) << "Writing " << evecCoarse.size() << " coarse eigenvectors to '"
|
||||
<< evecCoarseFilename << "'" << std::endl;
|
||||
this->basicWrite(evecCoarseFilename, evecCoarse, evecCoarse.size());
|
||||
}
|
||||
|
||||
virtual void write(const std::string fileStem, const int traj = -1)
|
||||
|
@ -172,6 +172,8 @@ public:
|
||||
// parse parameters
|
||||
virtual void parseParameters(XmlReader &reader, const std::string name) = 0;
|
||||
virtual void saveParameters(XmlWriter &writer, const std::string name) = 0;
|
||||
// parameter string
|
||||
virtual std::string parString(void) const = 0;
|
||||
// setup
|
||||
virtual void setup(void) {};
|
||||
virtual void execute(void) = 0;
|
||||
@ -200,9 +202,11 @@ public:
|
||||
// parse parameters
|
||||
virtual void parseParameters(XmlReader &reader, const std::string name);
|
||||
virtual void saveParameters(XmlWriter &writer, const std::string name);
|
||||
// parameter string
|
||||
virtual std::string parString(void) const;
|
||||
// parameter access
|
||||
const P & par(void) const;
|
||||
void setPar(const P &par);
|
||||
const P & par(void) const;
|
||||
void setPar(const P &par);
|
||||
private:
|
||||
P par_;
|
||||
};
|
||||
@ -225,6 +229,8 @@ public:
|
||||
push(writer, "options");
|
||||
pop(writer);
|
||||
};
|
||||
// parameter string (empty)
|
||||
virtual std::string parString(void) const {return "";};
|
||||
};
|
||||
|
||||
/******************************************************************************
|
||||
@ -247,6 +253,17 @@ void Module<P>::saveParameters(XmlWriter &writer, const std::string name)
|
||||
write(writer, name, par_);
|
||||
}
|
||||
|
||||
template <typename P>
|
||||
std::string Module<P>::parString(void) const
|
||||
{
|
||||
std::string xmlstring;
|
||||
XmlWriter writer("","");
|
||||
|
||||
write(writer, par_.SerialisableClassName(), par_);
|
||||
|
||||
return writer.string();
|
||||
}
|
||||
|
||||
template <typename P>
|
||||
const P & Module<P>::par(void) const
|
||||
{
|
||||
|
@ -148,6 +148,8 @@ void TLocalCoherenceLanczos<FImpl, nBasis>::execute(void)
|
||||
auto &coarsePar = par().coarseParams;
|
||||
auto &epack = envGetDerived(BasePack, CoarsePack, getName());
|
||||
|
||||
epack.record.operatorPar = vm().getModule(par().action)->parString();
|
||||
epack.record.solverPar = parString();
|
||||
envGetTmp(LCL, solver);
|
||||
LOG(Message) << "Performing fine grid IRL -- Nstop= "
|
||||
<< finePar.Nstop << ", Nk= " << finePar.Nk << ", Nm= "
|
||||
@ -173,10 +175,10 @@ void TLocalCoherenceLanczos<FImpl, nBasis>::execute(void)
|
||||
coarsePar.MinRes);
|
||||
solver.testCoarse(coarsePar.resid*100.0, par().smoother,
|
||||
par().coarseRelaxTol);
|
||||
}
|
||||
if (!par().output.empty())
|
||||
{
|
||||
epack.writeCoarse(par().output, vm().getTrajectory());
|
||||
if (!par().output.empty())
|
||||
{
|
||||
epack.writeCoarse(par().output, vm().getTrajectory());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -328,7 +328,7 @@ class GridLimeWriter : public BinaryIO
|
||||
{
|
||||
XmlWriter WR("","");
|
||||
write(WR,object_name,object);
|
||||
xmlstring = WR.XmlString();
|
||||
xmlstring = WR.docString();
|
||||
}
|
||||
// std::cout << "WriteLimeObject" << record_name <<std::endl;
|
||||
uint64_t nbytes = xmlstring.size();
|
||||
|
@ -115,7 +115,7 @@ THE SOFTWARE.
|
||||
#define GRID_MACRO_WRITE_MEMBER(A,B) Grid::write(WR,#B,obj. B);
|
||||
|
||||
#define GRID_SERIALIZABLE_CLASS_MEMBERS(cname,...)\
|
||||
std::string SerialisableClassName(void) {return std::string(#cname);} \
|
||||
std::string SerialisableClassName(void) const {return std::string(#cname);} \
|
||||
GRID_MACRO_EVAL(GRID_MACRO_MAP(GRID_MACRO_MEMBER,__VA_ARGS__))\
|
||||
template <typename T>\
|
||||
static inline void write(Writer<T> &WR,const std::string &s, const cname &obj){ \
|
||||
|
@ -44,7 +44,7 @@ XmlWriter::XmlWriter(const std::string &fileName, std::string toplev) : fileName
|
||||
XmlWriter::~XmlWriter(void)
|
||||
{
|
||||
if ( fileName_ != std::string("") ) {
|
||||
doc_.save_file(fileName_.c_str(), " ");
|
||||
doc_.save_file(fileName_.c_str(), indent_.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@ -57,10 +57,18 @@ void XmlWriter::pop(void)
|
||||
{
|
||||
node_ = node_.parent();
|
||||
}
|
||||
std::string XmlWriter::XmlString(void)
|
||||
|
||||
std::string XmlWriter::docString(void)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
doc_.save(oss);
|
||||
doc_.save(oss, indent_.c_str());
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
std::string XmlWriter::string(void)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
doc_.save(oss, indent_.c_str(), pugi::format_default | pugi::format_no_declaration);
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
|
@ -55,8 +55,10 @@ namespace Grid
|
||||
void writeDefault(const std::string &s, const U &x);
|
||||
template <typename U>
|
||||
void writeDefault(const std::string &s, const std::vector<U> &x);
|
||||
std::string XmlString(void);
|
||||
std::string docString(void);
|
||||
std::string string(void);
|
||||
private:
|
||||
const std::string indent_{" "};
|
||||
pugi::xml_document doc_;
|
||||
pugi::xml_node node_;
|
||||
std::string fileName_;
|
||||
|
Loading…
x
Reference in New Issue
Block a user