Commit 161ff8ba by Francois Gygi

Remove obsolete comment


git-svn-id: http://qboxcode.org/svn/qb/trunk@101 cba15fb0-1239-40c8-b417-11db7ca47a34
parents
////////////////////////////////////////////////////////////////////////////////
//
// Atom.C:
//
////////////////////////////////////////////////////////////////////////////////
// $Id: Atom.C,v 1.3 2003-05-16 16:14:00 fgygi Exp $
#include "Atom.h"
#include <iomanip>
using namespace std;
Atom::Atom (string newname, string newspecies, D3vector pos, D3vector vel)
{
name_ = newname;
species_ = newspecies;
position_ = pos;
velocity_ = vel;
}
ostream& operator << ( ostream &os, Atom &a )
{
os.setf(ios::left,ios::adjustfield);
os << " <atom name=\"" << a.name() << "\""
<< " species=\"" << a.species() << "\">\n"
<< " <position> ";
os.setf(ios::fixed,ios::floatfield);
os.setf(ios::right,ios::adjustfield);
os << setw(12) << setprecision(8) << a.position().x << " "
<< setw(12) << setprecision(8) << a.position().y << " "
<< setw(12) << setprecision(8) << a.position().z << " "
<< " </position>\n"
<< " <velocity> ";
os.setf(ios::scientific,ios::floatfield);
os << setw(13) << setprecision(6) << a.velocity().x << " "
<< setw(13) << setprecision(6) << a.velocity().y << " "
<< setw(13) << setprecision(6) << a.velocity().z
<< " </velocity>\n </atom>" << endl;
return os;
}
////////////////////////////////////////////////////////////////////////////////
//
// Atom.h:
//
////////////////////////////////////////////////////////////////////////////////
// $Id: Atom.h,v 1.2 2003-05-16 16:14:00 fgygi Exp $
#ifndef ATOM_H
#define ATOM_H
#include "D3vector.h"
#include <string>
using namespace std;
class Atom
{
private:
string name_;
string species_;
D3vector position_;
D3vector velocity_;
public:
Atom (string name, string species, D3vector position, D3vector velocity);
string name(void) { return name_; };
string species(void) { return species_; };
D3vector position(void) { return position_; };
D3vector velocity(void) { return velocity_; };
void set_position(D3vector p) { position_ = p; };
void set_velocity(D3vector v) { velocity_ = v; };
void block(void) { velocity_ = D3vector(0.0,0.0,0.0); };
};
ostream& operator << ( ostream &os, Atom &a );
#endif
////////////////////////////////////////////////////////////////////////////////
//
// AtomCmd.h:
//
////////////////////////////////////////////////////////////////////////////////
// $Id: AtomCmd.h,v 1.4 2003-09-16 16:24:26 fgygi Exp $
#ifndef ATOMCMD_H
#define ATOMCMD_H
#include <string>
#include <cstdlib>
#include <iostream>
using namespace std;
#include "UserInterface.h"
#include "Sample.h"
class AtomCmd : public Cmd
{
public:
Sample *s;
AtomCmd(Sample *sample) : s(sample) {};
char *name(void) const { return "atom"; }
char *help_msg(void) const
{
return
"\n atom\n\n"
" syntax: atom name species x y z [vx vy vz]\n\n"
" The atom command defines a new atom and adds it to the atom list.\n"
" The name can be any character string, the species must be the name\n"
" of a file containing the definition of the pseudopotential for this\n"
" atomic species. The position of the atom is specified by x y and z.\n"
" Optionally, the atom velocity can be specified by vx vy and vz.\n\n";
}
int action(int argc, char **argv)
{
string name;
string species;
D3vector position;
D3vector velocity;
// atom must be defined with either 3 or 6 arguments
if ( argc != 6 && argc != 9 )
{
if ( ui->onpe0() )
cout << " use: atom name species x y z [vx vy vz]" << endl;
return 1;
}
name = argv[1];
species = argv[2];
position.x = atof(argv[3]);
position.y = atof(argv[4]);
position.z = atof(argv[5]);
if ( argc == 9 )
{
velocity.x = atof(argv[6]);
velocity.y = atof(argv[7]);
velocity.z = atof(argv[8]);
}
Atom *a = new Atom(name,species,position,velocity);
if ( !(s->atoms.addAtom( a ) ) )
{
if ( ui->onpe0() )
cout << " AtomCmd: could not add atom " << name << endl;
delete a;
return 1;
}
#if DEBUG
cout << " dbg check "<< __FILE__ <<" "<< __LINE__ <<" mype="<< mype << endl;
#endif
s->wf.set_nel(s->atoms.nel());
s->wf.update_occ();
if ( s->wfv != 0 )
{
s->wfv->set_nel(s->atoms.nel());
s->wfv->clear();
}
#if DEBUG
cout << " dbg check "<< __FILE__ <<" "<< __LINE__ <<" mype="<< mype << endl;
#endif
return 0;
}
};
#endif
////////////////////////////////////////////////////////////////////////////////
//
// AtomSet.C
//
////////////////////////////////////////////////////////////////////////////////
// $Id: AtomSet.C,v 1.8 2003-08-28 00:28:51 fgygi Exp $
#include "AtomSet.h"
#include "NameOf.h"
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
////////////////////////////////////////////////////////////////////////////////
bool AtomSet::addSpecies(Species* sp, string name)
{
if ( findSpecies(name) )
{
if ( ctxt_.onpe0() )
cout << " AtomSet::addSpecies: species " << name
<< " is already defined" << endl;
return false;
}
const double rcps = 1.0;
sp->initialize(rcps);
// create new entry in species list
species_list.push_back(sp);
spname.push_back(name);
isp_[name] = species_list.size()-1;
na_.insert(map<string,int>::value_type(name,0));
atom_list.resize(atom_list.size()+1);
return true;
}
////////////////////////////////////////////////////////////////////////////////
bool AtomSet::addAtom(Atom *a)
{
// check atom_list for name
if ( findAtom(a->name()) )
{
// this name is already in the atom list, reject atom definition
if ( ctxt_.onpe0() )
cout << " AtomSet:addAtom: atom " << a->name()
<< " is already defined" << endl;
return false;
}
// check if species is defined
string spname = a->species();
Species *s = findSpecies(spname);
if ( !s )
{
// species not found, cannot define atom
if ( ctxt_.onpe0() )
cout << " AtomSet:addAtom: species " << spname
<< " is undefined" << endl;
return false;
}
// add an atom to the atom_list
int is = isp(spname);
assert ( is >= 0 );
atom_list[is].push_back(a);
// update count of atoms of species spname
// increment count
na_[spname]++;
// update total number of electrons
nel_ = 0;
for ( int is = 0; is < species_list.size(); is++ )
{
nel_ += species_list[is]->zval() * atom_list[is].size();
}
return true;
}
////////////////////////////////////////////////////////////////////////////////
bool AtomSet::delAtom(string name)
{
vector<vector<Atom*> >::iterator psa = atom_list.begin();
vector<Species*>::iterator ps = species_list.begin();
for ( int is = 0; is < species_list.size(); is++ )
{
vector<Atom*>::iterator pa = atom_list[is].begin();
for ( int ia = 0; ia < atom_list[is].size(); ia++ )
{
if ( atom_list[is][ia]->name() == name )
{
string spname = atom_list[is][ia]->species();
na_[spname]--;
delete atom_list[is][ia];
atom_list[is].erase(pa);
nel_ -= species_list[is]->zval();
return true;
}
pa++;
}
psa++;
ps++;
}
// this name was not found in the atom list
if ( ctxt_.onpe0() )
cout << " AtomSet:delAtom: no such atom: " << name << endl;
return false;
}
////////////////////////////////////////////////////////////////////////////////
Atom *AtomSet::findAtom(string name) const
{
for ( int is = 0; is < species_list.size(); is++ )
{
for ( int ia = 0; ia < atom_list[is].size(); ia++ )
{
if ( atom_list[is][ia]->name() == name )
return atom_list[is][ia];
}
}
return 0;
}
////////////////////////////////////////////////////////////////////////////////
Species *AtomSet::findSpecies(string name) const
{
int is = isp(name);
if ( is >= 0 )
return species_list[is];
else
return 0;
}
////////////////////////////////////////////////////////////////////////////////
int AtomSet::isp(string name) const
{
map<string,int>::const_iterator i = isp_.find(name);
if ( i != isp_.end() )
return (*i).second;
else
return -1;
}
////////////////////////////////////////////////////////////////////////////////
void AtomSet::listAtoms(void) const
{
for ( int is = 0; is < species_list.size(); is++ )
{
for ( int ia = 0; ia < atom_list[is].size(); ia++ )
{
if ( ctxt_.onpe0() )
cout << *atom_list[is][ia];
}
}
}
////////////////////////////////////////////////////////////////////////////////
void AtomSet::listSpecies(void) const
{
for ( int is = 0; is < species_list.size(); is++ )
{
if ( ctxt_.onpe0() )
{
cout << endl << " species " << spname[is] << ":" << endl;
species_list[is]->info(cout);
cout << endl;
}
}
}
////////////////////////////////////////////////////////////////////////////////
int AtomSet::na(string spname) const
{
map<string,int>::const_iterator i = na_.find(spname);
if ( i != na_.end() )
return (*i).second;
else
return 0;
}
////////////////////////////////////////////////////////////////////////////////
int AtomSet::na(int is) const
{
assert( is >= 0 && is < atom_list.size() );
return atom_list[is].size();
}
////////////////////////////////////////////////////////////////////////////////
int AtomSet::size(void)
{
int n = 0;
for ( int is = 0; is < atom_list.size(); is++ )
n += atom_list[is].size();
return n;
}
////////////////////////////////////////////////////////////////////////////////
bool AtomSet::reset(void)
{
// delete all atoms and species
for ( int is = 0; is < species_list.size(); is++ )
{
for ( int ia = 0; ia < atom_list[is].size(); ia++ )
{
delete atom_list[is][ia];
}
atom_list[is].resize(0);
delete species_list[is];
}
atom_list.resize(0);
species_list.resize(0);
nel_ = 0;
return true;
}
////////////////////////////////////////////////////////////////////////////////
void AtomSet::get_positions(vector<vector<double> >& tau) const
{
assert(tau.size() == atom_list.size());
for ( int is = 0; is < atom_list.size(); is++ )
{
assert(tau[is].size() == 3*atom_list[is].size());
int i = 0;
for ( int ia = 0; ia < atom_list[is].size(); ia++ )
{
D3vector t = atom_list[is][ia]->position();
tau[is][i++] = t.x;
tau[is][i++] = t.y;
tau[is][i++] = t.z;
}
}
}
////////////////////////////////////////////////////////////////////////////////
void AtomSet::set_positions(const vector<vector<double> >& tau)
{
assert(tau.size() == atom_list.size());
for ( int is = 0; is < atom_list.size(); is++ )
{
assert(tau[is].size() == 3*atom_list[is].size());
int i = 0;
for ( int ia = 0; ia < atom_list[is].size(); ia++ )
{
atom_list[is][ia]->set_position(
D3vector(tau[is][i],tau[is][i+1],tau[is][i+2]));
i += 3;
}
}
}
////////////////////////////////////////////////////////////////////////////////
void AtomSet::get_velocities(vector<vector<double> >& vel) const
{
assert(vel.size() == atom_list.size());
for ( int is = 0; is < atom_list.size(); is++ )
{
assert(vel[is].size() == 3*atom_list[is].size());
int i = 0;
for ( int ia = 0; ia < atom_list[is].size(); ia++ )
{
D3vector t = atom_list[is][ia]->velocity();
vel[is][i++] = t.x;
vel[is][i++] = t.y;
vel[is][i++] = t.z;
}
}
}
////////////////////////////////////////////////////////////////////////////////
void AtomSet::set_velocities(const vector<vector<double> >& vel)
{
assert(vel.size() == atom_list.size());
for ( int is = 0; is < atom_list.size(); is++ )
{
assert(vel[is].size() == 3*atom_list[is].size());
int i = 0;
for ( int ia = 0; ia < atom_list[is].size(); ia++ )
{
atom_list[is][ia]->set_velocity(
D3vector(vel[is][i],vel[is][i+1],vel[is][i+2]));
i += 3;
}
}
}
////////////////////////////////////////////////////////////////////////////////
ostream& operator << ( ostream &os, AtomSet &as )
{
if ( as.context().onpe0() )
{
os << "<atomset>\n";
for ( int is = 0; is < as.species_list.size(); is++ )
{
os << *as.species_list[is];
}
for ( int is = 0; is < as.species_list.size(); is++ )
{
for ( int ia = 0; ia < as.atom_list[is].size(); ia++ )
{
os << *as.atom_list[is][ia];
}
}
}
os << "</atomset>\n";
return os;
}
////////////////////////////////////////////////////////////////////////////////
//
// AtomSet.h
//
////////////////////////////////////////////////////////////////////////////////
// $Id: AtomSet.h,v 1.8 2003-08-28 00:28:51 fgygi Exp $
#ifndef ATOMSET_H
#define ATOMSET_H
#include "Context.h"
#include "Atom.h"
#include "Species.h"
#include <list>
#include <map>
#include <string>
using namespace std;
class AtomSet
{
private:
const Context& ctxt_;
int nel_;
map<string,int> na_; // na_[sp_name]: number of atoms of species sp_name
map<string,int> isp_; // isp_[sp_name]: index of species sp_name
vector<string> spname; // spname[is]: name of species is
public:
AtomSet(const Context& ctxt) : ctxt_(ctxt) {}
vector<vector<Atom *> > atom_list; // atom_list[is][ia]
vector<Species *> species_list; // species_list[is]
const Context& context(void) const { return ctxt_; }
bool addAtom(Atom *a);
bool delAtom(string name);
bool addSpecies(Species *sp, string name);
bool delSpecies(string name);
bool reset(void); // remove all atoms and species
Atom *findAtom(string name) const;
Species *findSpecies(string name) const;
void listAtoms(void) const;
void listSpecies(void) const;
int na(string spname) const; // number of atoms of species spname
int na(int is) const; // number of atoms of species is
int isp(string spname) const; // index of species spname
int nel(void) const { return nel_; };
int nsp(void) const { return species_list.size(); }
void get_positions(vector<vector<double> >& tau) const;
void set_positions(const vector<vector<double> >& tau);
void get_velocities(vector<vector<double> >& tau) const;
void set_velocities(const vector<vector<double> >& tau);
int size(void);
};
ostream& operator << ( ostream &os, AtomSet &as );
#endif
////////////////////////////////////////////////////////////////////////////////
//
// AtomSetHandler.C
//
////////////////////////////////////////////////////////////////////////////////
// $Id: AtomSetHandler.C,v 1.2 2003-05-23 21:51:04 fgygi Exp $
#include "AtomSetHandler.h"
#include "AtomSet.h"
#include "SpeciesHandler.h"
#include "SpeciesReader.h"
#include "StrX.h"
using namespace xercesc;
#include <iostream>
#include <cassert>
#include <sstream>
using namespace std;
////////////////////////////////////////////////////////////////////////////////
AtomSetHandler::AtomSetHandler(AtomSet& as) :
as_(as) {}
////////////////////////////////////////////////////////////////////////////////
AtomSetHandler::~AtomSetHandler() {}
////////////////////////////////////////////////////////////////////////////////
void AtomSetHandler::startElement(const XMLCh* const uri,
const XMLCh* const localname, const XMLCh* const qname,
const Attributes& attributes)
{
// cout << " AtomSetHandler::startElement " << StrX(qname) << endl;
string locname(XMLString::transcode(localname));
// consider only elements that are dealt with directly by AtomSetHandler
// i.e. "atom". The "species" element is delegated to a SpeciesHandler
if ( locname == "atom")
{
// set default velocity to zero
current_atom_velocity = D3vector(0.0,0.0,0.0);
unsigned int len = attributes.getLength();
for (unsigned int index = 0; index < len; index++)
{
string attrname(XMLString::transcode(attributes.getLocalName(index)));
if ( attrname == "name")
{
current_atom_name = StrX(attributes.getValue(index)).localForm();
}
else if ( attrname == "species" )
{
current_atom_species = StrX(attributes.getValue(index)).localForm();
}
}
}
}
////////////////////////////////////////////////////////////////////////////////
void AtomSetHandler::endElement(const XMLCh* const uri,
const XMLCh* const localname, const XMLCh* const qname, string& content)
{
string locname(XMLString::transcode(localname));
// cout << " AtomSetHandler::endElement " << locname << endl;
istringstream stst(content);
if ( locname == "atom")
{
// create an instance of Atom using the current values read so far
// add the Atom to the current AtomSet
// cout << " AtomSetHandler::endElement: creating Atom(position="
// << current_atom_position
// << ", velocity=" << current_atom_velocity
// << ", name=" << current_atom_name
// << ", species=" << current_atom_species
// << ")" << endl;
try
{
Atom* a = new Atom(current_atom_name, current_atom_species,
current_atom_position, current_atom_velocity);
as_.addAtom(a);
}
catch (...)
{
cout << " AtomSetHandler::endElement: and exception occurred"
<< " in AtomSet::addAtom" << endl;
throw;
}
// notify listening nodes and broadcast atom info
int tag = 2; // species tag
as_.context().ibcast_send(1,1,&tag,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,1);
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,1);
}
else if ( locname == "position" )
{
stst >> current_atom_position;
}
else if ( locname == "velocity" )
{
stst >> current_atom_velocity;
}
}
////////////////////////////////////////////////////////////////////////////////
StructureHandler* AtomSetHandler::startSubHandler(const XMLCh* const uri,
const XMLCh* const localname, const XMLCh* const qname,
const Attributes& attributes)
{
// check if element qname can be processed by another StructureHandler
// If it can, return a pointer to the StructureHandler, otherwise return 0
// cout << " AtomSetHandler::startSubHandler " << StrX(qname) << endl;
string locname(XMLString::transcode(localname));
if ( locname == "species")
{
// check for species attributes
unsigned int len = attributes.getLength();