Commit 825c64b3 by Francois Gygi

redesign of SampleReader for nspin=2

git-svn-id: http://qboxcode.org/svn/qb/trunk@1275 cba15fb0-1239-40c8-b417-11db7ca47a34
parent 2a50e049
......@@ -15,9 +15,6 @@
// AtomSetHandler.C
//
////////////////////////////////////////////////////////////////////////////////
// $Id: AtomSetHandler.C,v 1.13 2008-09-08 15:56:18 fgygi Exp $
#if USE_XERCES
#include "AtomSetHandler.h"
#include "AtomSet.h"
......@@ -104,20 +101,6 @@ void AtomSetHandler::endElement(const XMLCh* const uri,
istringstream stst(content);
if ( locname == "unit_cell")
{
event_type event = unit_cell;
as_.context().ibcast_send(1,1,(int*)&event,1);
// notify listening nodes
double buf[9];
buf[0] = as_.cell().a(0).x;
buf[1] = as_.cell().a(0).y;
buf[2] = as_.cell().a(0).z;
buf[3] = as_.cell().a(1).x;
buf[4] = as_.cell().a(1).y;
buf[5] = as_.cell().a(1).z;
buf[6] = as_.cell().a(2).x;
buf[7] = as_.cell().a(2).y;
buf[8] = as_.cell().a(2).z;
as_.context().dbcast_send(9,1,buf,9);
}
else if ( locname == "atom")
{
......@@ -143,21 +126,6 @@ void AtomSetHandler::endElement(const XMLCh* const uri,
throw;
}
// notify listening nodes and broadcast atom info
event_type event = atom;
as_.context().ibcast_send(1,1,(int*)&event,1);
as_.context().string_bcast(current_atom_name,0);
as_.context().string_bcast(current_atom_species,0);
double buf[3];
buf[0] = current_atom_position.x;
buf[1] = current_atom_position.y;
buf[2] = current_atom_position.z;
as_.context().dbcast_send(3,1,buf,3);
buf[0] = current_atom_velocity.x;
buf[1] = current_atom_velocity.y;
buf[2] = current_atom_velocity.z;
as_.context().dbcast_send(3,1,buf,3);
}
else if ( locname == "position" )
{
......@@ -193,7 +161,7 @@ StructureHandler* AtomSetHandler::startSubHandler(const XMLCh* const uri,
}
// delegate to SpeciesHandler
current_species = new Species(as_.context(),current_species_name);
current_species = new Species(current_species_name);
return new SpeciesHandler(*current_species);
}
else
......@@ -211,7 +179,7 @@ void AtomSetHandler::endSubHandler(const XMLCh* const uri,
// cout << " AtomSetHandler::endSubHandler " << locname << endl;
if ( locname == "species" )
{
SpeciesReader sp_reader(current_species->context());
SpeciesReader sp_reader;
// check if only the uri was provided
if ( current_species->uri() != "" )
......@@ -219,22 +187,9 @@ void AtomSetHandler::endSubHandler(const XMLCh* const uri,
// href was found in species definition
// attempt to read the species from that uri
try
{
sp_reader.readSpecies(*current_species,current_species->uri());
}
catch ( const SpeciesReaderException& e )
{
cout << " SpeciesReaderException caught in AtomSetHandler" << endl;
}
sp_reader.uri_to_species(current_species->uri(),*current_species);
}
// notify listening nodes and broadcast species info
event_type event = species;
as_.context().ibcast_send(1,1,(int*)&event,1);
as_.context().string_bcast(current_species_name,0);
sp_reader.bcastSpecies(*current_species);
// cout << "AtomSetHandler::endSubHandler: adding Species:"
// << current_species_name << endl;
try
......@@ -250,5 +205,3 @@ void AtomSetHandler::endSubHandler(const XMLCh* const uri,
}
delete last;
}
#endif
......@@ -139,7 +139,7 @@ CXXFLAGS += -DTARGET='"$(TARGET)"'
testBasisMapping: testBasisMapping.o BasisMapping.o Basis.o \
Context.o UnitCell.o
$(LD) $(DFLAGS) -o $@ $^ $(LDFLAGS)
testSpecies: testSpecies.o Species.o sinft.o spline.o Context.o \
testSpecies: testSpecies.o Species.o sinft.o spline.o \
SpeciesReader.o StructuredDocumentHandler.o SpeciesHandler.o
$(LD) $(DFLAGS) -o $@ $^ $(LDFLAGS)
testXCFunctional: testXCFunctional.o LDAFunctional.o PBEFunctional.o
......@@ -293,20 +293,6 @@ BOSampleStepper.o: SampleStepper.h Timer.h EnergyFunctional.h ChargeDensity.h
BOSampleStepper.o: Context.h StructureFactor.h Sample.h AtomSet.h Atom.h
BOSampleStepper.o: D3vector.h UnitCell.h ConstraintSet.h ExtForceSet.h
BOSampleStepper.o: Wavefunction.h Control.h
BOSampleStepper-merge.o: BOSampleStepper.h SampleStepper.h Timer.h
BOSampleStepper-merge.o: EnergyFunctional.h ChargeDensity.h Context.h
BOSampleStepper-merge.o: StructureFactor.h Sample.h AtomSet.h Atom.h
BOSampleStepper-merge.o: D3vector.h UnitCell.h ConstraintSet.h ExtForceSet.h
BOSampleStepper-merge.o: Wavefunction.h Control.h SlaterDet.h Basis.h
BOSampleStepper-merge.o: Matrix.h WavefunctionStepper.h
BOSampleStepper-merge.o: SDWavefunctionStepper.h PSDWavefunctionStepper.h
BOSampleStepper-merge.o: PSDAWavefunctionStepper.h JDWavefunctionStepper.h
BOSampleStepper-merge.o: SDIonicStepper.h IonicStepper.h Species.h
BOSampleStepper-merge.o: SDAIonicStepper.h LineMinimizer.h CGIonicStepper.h
BOSampleStepper-merge.o: CGOptimizer.h MDIonicStepper.h BMDIonicStepper.h
BOSampleStepper-merge.o: SDCellStepper.h CellStepper.h CGCellStepper.h
BOSampleStepper-merge.o: Preconditioner.h AndersonMixer.h MLWFTransform.h
BOSampleStepper-merge.o: BasisMapping.h
BtHF.o: Sample.h AtomSet.h Context.h Atom.h D3vector.h UnitCell.h
BtHF.o: ConstraintSet.h ExtForceSet.h Wavefunction.h Control.h
CellDyn.o: Sample.h AtomSet.h Context.h Atom.h D3vector.h UnitCell.h
......@@ -468,9 +454,6 @@ LineMinimizer.o: LineMinimizer.h
ListAtomsCmd.o: UserInterface.h Sample.h AtomSet.h Context.h Atom.h
ListAtomsCmd.o: D3vector.h UnitCell.h ConstraintSet.h ExtForceSet.h
ListAtomsCmd.o: Wavefunction.h Control.h
ListConstraintsCmd.o: UserInterface.h Sample.h AtomSet.h Context.h Atom.h
ListConstraintsCmd.o: D3vector.h UnitCell.h ConstraintSet.h ExtForceSet.h
ListConstraintsCmd.o: Wavefunction.h Control.h
ListSpeciesCmd.o: UserInterface.h Sample.h AtomSet.h Context.h Atom.h
ListSpeciesCmd.o: D3vector.h UnitCell.h ConstraintSet.h ExtForceSet.h
ListSpeciesCmd.o: Wavefunction.h Control.h
......@@ -592,9 +575,8 @@ SampleHandler.o: StrX.h
SampleHandler.o: StructureHandler.h
SampleReader.o: Sample.h AtomSet.h Context.h Atom.h D3vector.h UnitCell.h
SampleReader.o: ConstraintSet.h ExtForceSet.h Wavefunction.h Control.h
SampleReader.o: SampleReader.h SpeciesReader.h Species.h Basis.h
SampleReader.o: FourierTransform.h Timer.h SlaterDet.h Matrix.h
SampleReader.o: XMLGFPreprocessor.h SampleHandler.h StructureHandler.h
SampleReader.o: SampleReader.h XMLGFPreprocessor.h Matrix.h Timer.h
SampleReader.o: SampleHandler.h StructureHandler.h
SampleReader.o: StructuredDocumentHandler.h StrX.h
SampleStepper.o: SampleStepper.h Timer.h Sample.h AtomSet.h Context.h Atom.h
SampleStepper.o: D3vector.h UnitCell.h ConstraintSet.h ExtForceSet.h
......@@ -609,8 +591,6 @@ SaveCmd.o: D3vector.h UnitCell.h ConstraintSet.h ExtForceSet.h Wavefunction.h
SaveCmd.o: Control.h SampleWriter.h isodate.h release.h
SaveCmd.o: UserInterface.h Sample.h AtomSet.h Context.h Atom.h D3vector.h
SaveCmd.o: UnitCell.h ConstraintSet.h ExtForceSet.h Wavefunction.h Control.h
ScfTol.o: Sample.h AtomSet.h Context.h Atom.h D3vector.h UnitCell.h
ScfTol.o: ConstraintSet.h ExtForceSet.h Wavefunction.h Control.h
SDAIonicStepper.o: SDAIonicStepper.h IonicStepper.h Sample.h AtomSet.h
SDAIonicStepper.o: Context.h Atom.h D3vector.h UnitCell.h ConstraintSet.h
SDAIonicStepper.o: ExtForceSet.h Wavefunction.h Control.h Species.h
......@@ -643,21 +623,17 @@ SlaterDet.o: SlaterDet.h Context.h Basis.h D3vector.h UnitCell.h Matrix.h
SlaterDet.o: Timer.h FourierTransform.h blas.h Base64Transcoder.h
SlaterDet.o: SharedFilePtr.h
SlaterDet.o: Context.h Basis.h D3vector.h UnitCell.h Matrix.h Timer.h
Species.o: Species.h Context.h spline.h sinft.h
Species.o: Species.h spline.h sinft.h
SpeciesCmd.o: SpeciesCmd.h UserInterface.h Sample.h AtomSet.h Context.h
SpeciesCmd.o: Atom.h D3vector.h UnitCell.h ConstraintSet.h ExtForceSet.h
SpeciesCmd.o: Wavefunction.h Control.h SpeciesReader.h Species.h
SpeciesCmd.o: UserInterface.h Sample.h AtomSet.h Context.h Atom.h D3vector.h
SpeciesCmd.o: UnitCell.h ConstraintSet.h ExtForceSet.h Wavefunction.h
SpeciesCmd.o: Control.h
Species.o: Context.h
SpeciesHandler.o: SpeciesHandler.h StructureHandler.h Species.h Context.h
SpeciesHandler.o: StrX.h
SpeciesHandler.o: SpeciesHandler.h StructureHandler.h Species.h StrX.h
SpeciesHandler.o: StructureHandler.h
SpeciesReader.o: Species.h Context.h SpeciesReader.h
SpeciesReader.o: StructuredDocumentHandler.h StrX.h StructureHandler.h
SpeciesReader.o: SpeciesHandler.h
SpeciesReader.o: Context.h
SpeciesReader.o: Species.h SpeciesReader.h StructuredDocumentHandler.h StrX.h
SpeciesReader.o: StructureHandler.h SpeciesHandler.h
spline.o: spline.h
StatusCmd.o: UserInterface.h Sample.h AtomSet.h Context.h Atom.h D3vector.h
StatusCmd.o: UnitCell.h ConstraintSet.h ExtForceSet.h Wavefunction.h
......@@ -690,17 +666,16 @@ testFourierTransform.o: Context.h Basis.h D3vector.h UnitCell.h
testFourierTransform.o: FourierTransform.h Timer.h
testjacobi.o: Timer.h Context.h Matrix.h jacobi.h
testjade.o: Timer.h Context.h Matrix.h jade.h
test_lapiv.o: Context.h Matrix.h
testLDAFunctional.o: LDAFunctional.h XCFunctional.h
testLineMinimizer.o: LineMinimizer.h
testMatrix.o: Timer.h Context.h Matrix.h
testPParse.o: StrX.h
testSample.o: Context.h SlaterDet.h Basis.h D3vector.h UnitCell.h Matrix.h
testSample.o: Timer.h Sample.h AtomSet.h Atom.h ConstraintSet.h ExtForceSet.h
testSample.o: Wavefunction.h Control.h
test_sinft.o: sinft.h readTSC.h
testSlaterDet.o: Context.h SlaterDet.h Basis.h D3vector.h UnitCell.h Matrix.h
testSlaterDet.o: Timer.h FourierTransform.h
testSpecies.o: Species.h Context.h SpeciesReader.h
testSpecies.o: Species.h SpeciesReader.h
testUnitCell.o: UnitCell.h D3vector.h
testWavefunction.o: Context.h Wavefunction.h D3vector.h UnitCell.h
testWavefunction.o: SlaterDet.h Basis.h Matrix.h Timer.h
......@@ -723,8 +698,6 @@ TorsionConstraint.o: Constraint.h D3vector.h
UnitCell.o: UnitCell.h D3vector.h
UnitCell.o: D3vector.h
UserInterface.o: UserInterface.h qbox_xmlns.h
VWNFunctional.o: VWNFunctional.h XCFunctional.h
VWNFunctional.o: XCFunctional.h
Wavefunction.o: Wavefunction.h D3vector.h UnitCell.h SlaterDet.h Context.h
Wavefunction.o: Basis.h Matrix.h Timer.h jacobi.h SharedFilePtr.h
Wavefunction.o: D3vector.h UnitCell.h
......
......@@ -15,9 +15,6 @@
// SampleHandler.C
//
////////////////////////////////////////////////////////////////////////////////
// $Id: SampleHandler.C,v 1.11 2008-09-08 15:56:19 fgygi Exp $
#if USE_XERCES
#include "SampleHandler.h"
#include "Sample.h"
......@@ -30,13 +27,8 @@ using namespace xercesc;
using namespace std;
////////////////////////////////////////////////////////////////////////////////
SampleHandler::SampleHandler(Sample& s, DoubleMatrix& gfdata,
int& nx, int& ny, int& nz,
vector<vector<vector<double> > > &dmat,
Wavefunction& wfvtmp) :
s_(s), gfdata_(gfdata), nx_(nx), ny_(ny), nz_(nz),
dmat_(dmat), read_wf(false), read_wfv(false),
wfvtmp_(wfvtmp) {}
SampleHandler::SampleHandler(Sample& s, DoubleMatrix& gfdata) :
s_(s), gfdata_(gfdata) {}
////////////////////////////////////////////////////////////////////////////////
SampleHandler::~SampleHandler() {}
......@@ -53,8 +45,8 @@ void SampleHandler::startElement(const XMLCh* const uri,
void SampleHandler::endElement(const XMLCh* const uri,
const XMLCh* const localname, const XMLCh* const qname, string& content)
{
//istringstream stst(st);
string locname(XMLString::transcode(localname));
// istringstream stst(st);
// string locname(XMLString::transcode(localname));
// cout << " SampleHandler::endElement " << locname << endl;
}
......@@ -75,12 +67,13 @@ StructureHandler* SampleHandler::startSubHandler(const XMLCh* const uri,
else if ( qnm == "wavefunction" )
{
read_wf = true;
return new WavefunctionHandler(s_.wf,gfdata_,nx_,ny_,nz_,dmat_);
return new WavefunctionHandler(s_.wf,gfdata_);
}
else if ( qnm == "wavefunction_velocity" )
{
read_wfv = true;
return new WavefunctionHandler(wfvtmp_,gfdata_,nx_,ny_,nz_,dmat_);
s_.wfv = new Wavefunction(s_.ctxt_);
return new WavefunctionHandler(*s_.wfv,gfdata_);
}
else
{
......@@ -96,4 +89,3 @@ void SampleHandler::endSubHandler(const XMLCh* const uri,
// cout << " SampleHandler::endSubHandler " << StrX(qname) << endl;
delete subHandler;
}
#endif
......@@ -32,16 +32,11 @@ class SampleHandler : public StructureHandler
private:
Sample& s_;
std::vector<std::vector<std::vector<double> > > &dmat_;
DoubleMatrix& gfdata_;
Wavefunction& wfvtmp_;
public:
bool read_wf,read_wfv;
int& nx_;
int& ny_;
int& nz_;
// Start of the root element in the structure being handled
virtual void startElement(const XMLCh* const uri,const XMLCh* const localname,
......@@ -61,9 +56,7 @@ class SampleHandler : public StructureHandler
const XMLCh* const localname, const XMLCh* const qname,
const StructureHandler* const subHandler);
SampleHandler(Sample& s, DoubleMatrix& gfdata, int& nx, int& ny, int& nz,
std::vector<std::vector<std::vector<double> > > &dmat,
Wavefunction& wfvtmp);
SampleHandler(Sample& s, DoubleMatrix& gfdata);
~SampleHandler();
};
#endif
////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2008 The Regents of the University of California
// Copyright (c) 2008-2012 The Regents of the University of California
//
// This file is part of Qbox
//
......@@ -18,11 +18,6 @@
#include "Sample.h"
#include "SampleReader.h"
#include "SpeciesReader.h"
#include "Species.h"
#include "Basis.h"
#include "FourierTransform.h"
#include "SlaterDet.h"
#include "XMLGFPreprocessor.h"
......@@ -35,7 +30,6 @@
#include <fstream>
#include <sys/stat.h>
#if USE_XERCES
#include "SampleHandler.h"
#include "StructuredDocumentHandler.h"
#include <xercesc/util/XMLUniDefs.hpp>
......@@ -46,7 +40,6 @@
#include <xercesc/sax2/XMLReaderFactory.hpp>
#include <xercesc/framework/MemBufInputSource.hpp>
using namespace xercesc;
#endif
using namespace std;
////////////////////////////////////////////////////////////////////////////////
......@@ -57,586 +50,138 @@ void SampleReader::readSample (Sample& s, const string uri, bool serial)
{
Timer tm;
tm.start();
#if USE_XERCES
const char* encodingName = "UTF-8";
SAX2XMLReader::ValSchemes valScheme = SAX2XMLReader::Val_Auto;
//SAX2XMLReader::ValSchemes valScheme = SAX2XMLReader::Val_Always;
//SAX2XMLReader::ValSchemes valScheme = SAX2XMLReader::Val_Never;
bool expandNamespaces = false;
const bool onpe0 = ctxt_.onpe0();
SAX2XMLReader::ValSchemes valScheme;
valScheme = SAX2XMLReader::Val_Auto;
//alternate choices of validation schemes
//valScheme = SAX2XMLReader::Val_Always;
//valScheme = SAX2XMLReader::Val_Never;
bool doNamespaces = true;
bool doSchema = true;
// Validate agains schema on pe0 only to avoid multiple warning messages
// This does not weaken validation since all tasks parse the same document
bool doSchema = onpe0;
bool schemaFullChecking = true;
bool namespacePrefixes = false;
SAX2XMLReader* parser = 0;
Wavefunction* wfvtmp = new Wavefunction(s.wf);
Wavefunction* current_wf = &s.wf;
vector<vector<vector<double> > > dmat;
int nx, ny, nz; // size of <grid> in wavefunction
int nspin = 1;
int current_ispin = 0;
int current_ikp;
int current_size;
dmat.resize(nspin);
MemBufInputSource* memBufIS = 0;
// XMLPlatformUtils initialization on task 0 only
int ierr = 0;
if ( ctxt_.onpe0() )
// XMLPlatformUtils initialization on all tasks
try
{
try
{
XMLPlatformUtils::Initialize();
}
catch (const XMLException& toCatch)
{
cout << " Sample::readSample: Error during XML initialization :\n"
<< StrX(toCatch.getMessage()) << endl;
ierr = 1;
}
ctxt_.ibcast_send(1,1,&ierr,1);
XMLPlatformUtils::Initialize();
}
else
catch (const XMLException& toCatch)
{
ctxt_.ibcast_recv(1,1,&ierr,1,0,0);
cout << " Sample::readSample: Error during XML initialization :\n"
<< StrX(toCatch.getMessage()) << endl;
s.ctxt_.abort(1);
}
//cout << ctxt_.mype() <<": SampleReader: ierr=" << ierr << endl;
if ( ierr > 0 )
throw SampleReaderException("error in XMLPlatformUtils::Initialize");
// Determine if uri is a local file
struct stat statbuf;
bool read_from_file = !stat(uri.c_str(),&statbuf);
// check for serial override
read_from_file &= !serial;
string xmlcontent;
DoubleMatrix gfdata(ctxt_);
if ( read_from_file )
{
const char* const filename = uri.c_str();
if ( ctxt_.onpe0() )
cout << " SampleReader: reading from file "
<< filename << " size: "
<< statbuf.st_size << endl;
XMLGFPreprocessor xmlgfp;
XMLGFPreprocessor xmlgfp;
xmlgfp.process(uri.c_str(),gfdata,xmlcontent,serial);
xmlgfp.process(filename,gfdata,xmlcontent);
// Each task holds a copy of xmlcontent
// The distributed matrix gfdata contains the grid function data
if ( ctxt_.onpe0() )
{
cout << " xmlcontent.size(): " << xmlcontent.size()
<< endl;
if ( onpe0 )
{
cout << " xmlcontent.size(): " << xmlcontent.size() << endl;
#if DEBUG
cout << ctxt_.mype() << ": xmlcontent: " << xmlcontent << endl;
cout << ctxt_.mype() << ": xmlcontent: " << xmlcontent << endl;
#endif
memBufIS = new MemBufInputSource
( (const XMLByte*) &xmlcontent[0], xmlcontent.size(), "buf_id", false);
}
}
memBufIS = new MemBufInputSource
( (const XMLByte*) &xmlcontent[0], xmlcontent.size(), "buf_id", false);
bool read_wf = false;
bool read_wfv = false;
// initialize wavefunction_velocity in case it appears in the sample file
assert(sizeof(event_type)==sizeof(int));
// remove default kpoint in wf
s.wf.del_kpoint(D3vector(0.0,0.0,0.0));
wfvtmp->del_kpoint(D3vector(0.0,0.0,0.0));
if ( ctxt_.onpe0() )
// parse xmlcontent on each task
parser = XMLReaderFactory::createXMLReader();
if (valScheme == SAX2XMLReader::Val_Auto)
{
parser = XMLReaderFactory::createXMLReader();
if (valScheme == SAX2XMLReader::Val_Auto)
{
parser->setFeature(XMLUni::fgSAX2CoreValidation, true);
parser->setFeature(XMLUni::fgXercesDynamic, true);
}
if (valScheme == SAX2XMLReader::Val_Never)
{
parser->setFeature(XMLUni::fgSAX2CoreValidation, false);
}
if (valScheme == SAX2XMLReader::Val_Always)
{
parser->setFeature(XMLUni::fgSAX2CoreValidation, true);
parser->setFeature(XMLUni::fgXercesDynamic, false);
}
parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, doNamespaces);
parser->setFeature(XMLUni::fgXercesSchema, doSchema);
parser->setFeature(XMLUni::fgXercesSchemaFullChecking, schemaFullChecking);
parser->setFeature(XMLUni::fgSAX2CoreNameSpacePrefixes, namespacePrefixes);
int errorCount = 0;
SampleHandler* s_handler =
new SampleHandler(s,gfdata,nx,ny,nz,dmat,*wfvtmp);
try
{
StructuredDocumentHandler handler(s_handler);
parser->setContentHandler(&handler);
parser->setErrorHandler(&handler);
cout << " Starting XML parsing" << endl;
if ( read_from_file )
parser->parse(*memBufIS);
else
parser->parse(uri.c_str());
cout << " XML parsing done" << endl;
errorCount = parser->getErrorCount();
}
catch (const XMLException& toCatch)
{
cout << "\nAn error occurred\n Error: "
<< StrX(toCatch.getMessage())
<< "\n" << endl;
//XMLPlatformUtils::Terminate();
//delete parser;
//throw;
}
catch (const SAXParseException& e)
{
cout << "\na SAXParseException occurred in file "
<< StrX(e.getSystemId())
<< ", line " << e.getLineNumber()
<< ", char " << e.getColumnNumber()
<< "\n Message: " << StrX(e.getMessage()) << endl;
//XMLPlatformUtils::Terminate();
//delete parser;
//throw;
}
read_wf = s_handler->read_wf;
if ( read_wf )
cout << " wavefunction was read" << endl;
read_wfv = s_handler->read_wfv;
if ( read_wfv )
cout << " wavefunction velocity was read" << endl;
if ( read_wf )
cout << " SampleReader::readSample: grid nx,ny,nz="
<< nx << " " << ny << " " << nz << endl;
delete s_handler;
delete parser;
XMLPlatformUtils::Terminate();
// parsing of sample is complete, send end of sample tag to tasks > 0
event_type event = end;
ctxt_.ibcast_send(1,1,(int*)&event,1);
parser->setFeature(XMLUni::fgSAX2CoreValidation, true);
parser->setFeature(XMLUni::fgXercesDynamic, true);
}
} // onpe0
else
if (valScheme == SAX2XMLReader::Val_Never)
{
// tasks > 0
// listen for Sample events
// cout << ctxt_.mype() << ": listening..." << endl;
bool done = false;
event_type event = invalid;
while ( !done )
{
ctxt_.ibcast_recv(1,1,(int*)&event,1,0,0);
if ( event == end )
done = true;
else if ( event == unit_cell )
{
// unit_cell
double buf[9];
ctxt_.dbcast_recv(9,1,buf,9,0,0);
D3vector a(buf[0],buf[1],buf[2]);
D3vector b(buf[3],buf[4],buf[5]);
D3vector c(buf[6],buf[7],buf[8]);
s.atoms.set_cell(a,b,c);
}
else if ( event == species )
{
// Species
string curr_name;
ctxt_.string_bcast(curr_name,0);
//cout << ctxt_.mype() << ": receiving species " << curr_name << endl;
Species* sp = new Species(ctxt_,curr_name);
SpeciesReader sp_reader(ctxt_);
sp_reader.bcastSpecies(*sp);
s.atoms.addSpecies(sp,curr_name);
}
else if ( event == atom )
{
// Atom
string curr_atom_name,curr_atom_species;
D3vector curr_position, curr_velocity;
ctxt_.string_bcast(curr_atom_name,0);
ctxt_.string_bcast(curr_atom_species,0);
double buf[3];
ctxt_.dbcast_recv(3,1,buf,3,0,0);
curr_position = D3vector(buf[0],buf[1],buf[2]);
ctxt_.dbcast_recv(3,1,buf,3,0,0);
curr_velocity = D3vector(buf[0],buf[1],buf[2]);
//cout << ctxt_.mype() << ": receiving atom " << curr_atom_name << endl;
Atom* a = new Atom(curr_atom_name, curr_atom_species,
curr_position, curr_velocity);
s.atoms.addAtom(a);
}
else if ( event == wavefunction )
{
current_ikp = 0;
// Wavefunction
read_wf = true;
int nel,nempty;
ctxt_.ibcast_recv(1,1,&nel,1,0,0);
ctxt_.ibcast_recv(1,1,&nspin,1,0,0);
ctxt_.ibcast_recv(1,1,&nempty,1,0,0);
//cout << ctxt_.mype() << ": SampleReader: receiving wf nel=" << nel
// << " nspin=" << nspin << " nempty=" << nempty << endl;
s.wf.set_nel(nel);
s.wf.set_nspin(nspin);
s.wf.set_nempty(nempty);
//cout << ctxt_.mype() << ": SampleReader: nel=" << s.wf.nel()
// << " nst=" << s.wf.nst() << endl;
// domain
double buf[9];
ctxt_.dbcast_recv(9,1,buf,9,0,0);
D3vector a(buf[0],buf[1],buf[2]);
D3vector b(buf[3],buf[4],buf[5]);
D3vector c(buf[6],buf[7],buf[8]);
UnitCell uc(a,b,c);
// grid
int ibuf[3];
ctxt_.ibcast_recv(3,1,ibuf,3,0,0);
nx = ibuf[0];
ny = ibuf[1];
nz = ibuf[2];
// receive only computed ecut
double ecut;
ctxt_.dbcast_recv(1,1,&ecut,1,0,0);
// reference_domain
ctxt_.dbcast_recv(9,1,buf,9,0,0);
D3vector ar(buf[0],buf[1],buf[2]);
D3vector br(buf[3],buf[4],buf[5]);
D3vector cr(buf[6],buf[7],buf[8]);
UnitCell ruc(ar,br,cr);
s.wf.resize(uc,ruc,ecut);
//cout << ctxt_.mype() << ": wf resized, ecut=" << ecut << endl;
}
else if ( event == wavefunction_velocity )
{
current_wf = wfvtmp; // set ptr used by the slater det section
current_ikp = 0;
//cout << ctxt_.mype()
// << ": SampleReader received wavefunction_velocity" << endl;
read_wfv = true;
// Wavefunction velocity
int nel,nspin,nempty;
ctxt_.ibcast_recv(1,1,&nel,1,0,0);
ctxt_.ibcast_recv(1,1,&nspin,1,0,0);
ctxt_.ibcast_recv(1,1,&nempty,1,0,0);
//cout << ctxt_.mype() << ": receiving wf nel=" << nel
// << " nspin=" << nspin << " nempty=" << nempty << endl;
wfvtmp->set_nel(nel);
wfvtmp->set_nspin(nspin);
wfvtmp->set_nempty(nempty);
// domain
double buf[9];
ctxt_.dbcast_recv(9,1,buf,9,0,0);
D3vector a(buf[0],buf[1],buf[2]);
D3vector b(buf[3],buf[4],buf[5]);
D3vector c(buf[6],buf[7],buf[8]);
UnitCell uc(a,b,c);
// grid
int ibuf[3];
ctxt_.ibcast_recv(3,1,ibuf,3,0,0);
assert(nx == ibuf[0]);
assert(ny == ibuf[1]);
assert(nz == ibuf[2]);
// receive only computed ecut
double ecut;
ctxt_.dbcast_recv(1,1,&ecut,1,0,0);
// reference_domain
ctxt_.dbcast_recv(9,1,buf,9,0,0);
D3vector ar(buf[0],buf[1],buf[2]);
D3vector br(buf[3],buf[4],buf[5]);
D3vector cr(buf[6],buf[7],buf[8]);
UnitCell ruc(ar,br,cr);
current_wf->resize(uc,ruc,ecut);
//cout << ctxt_.mype() << ": wfv resized, ecut=" << ecut << endl;
}
else if ( event == slater_determinant )
{
// process SlaterDet
// receive kpoint and weight
double buf[7];
ctxt_.dbcast_recv(7,1,buf,7,0,0);
current_ispin=(int) buf[4];
current_ikp=(int) buf[5];
current_size=(int) buf[6];
if ( current_ispin == 0 )
current_wf->add_kpoint(D3vector(buf[0],buf[1],buf[2]),buf[3]);
// resize sd(current_ispin,current_ikp)->nst() == current_size
current_wf->sd(current_ispin,current_ikp)->resize(current_wf->cell(),
current_wf->refcell(), current_wf->ecut(), current_size);
// receive density_matrix
vector<double> dmat_tmp(current_wf->nst());
s.wf.context().dbcast_recv(s.wf.nst(),1,&dmat_tmp[0],s.wf.nst(),0,0);
dmat[current_ispin].push_back(dmat_tmp);
if ( !read_from_file )
{
// receive grid_functions
SlaterDet* sd = current_wf->sd(current_ispin,current_ikp);
const Basis& basis = sd->basis();
FourierTransform ft(basis,nx,ny,nz);
const int wftmpr_size = basis.real() ? ft.np012loc() :
2*ft.np012loc();
valarray<double> wftmpr(wftmpr_size);
vector<complex<double> > wftmp(ft.np012loc());