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

Cleanup of readers #332

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
205 changes: 3 additions & 202 deletions src/io/ASCIIReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,208 +46,9 @@ void ASCIIReader::readXML(XMLfileUnits& xmlconfig) {
}

void ASCIIReader::readPhaseSpaceHeader(Domain* domain, double timestep) {
std::string token;

Log::global_log->info() << "Opening phase space header file " << _phaseSpaceHeaderFile << std::endl;
_phaseSpaceHeaderFileStream.open(_phaseSpaceHeaderFile.c_str());
_phaseSpaceHeaderFileStream >> token;
if(token != "mardyn") {
Log::global_log->error() << _phaseSpaceHeaderFile << " not a valid mardyn input file." << std::endl;
Simulation::exit(1);
}

std::string inputversion;
_phaseSpaceHeaderFileStream >> token >> inputversion;
// FIXME: remove tag trunk from file specification?
if(token != "trunk") {
Log::global_log->error() << "Wrong input file specifier (\'" << token << "\' instead of \'trunk\')." << std::endl;
Simulation::exit(1);
}

if(std::stoi(inputversion) < 20080701) {
Log::global_log->error() << "Input version too old (" << inputversion << ")" << std::endl;
Simulation::exit(1);
}

Log::global_log->info() << "Reading phase space header from file " << _phaseSpaceHeaderFile << std::endl;

std::vector<Component>& dcomponents = *(_simulation.getEnsemble()->getComponents());
bool header = true; // When the last header element is reached, "header" is set to false

while(header) {
char c;
_phaseSpaceHeaderFileStream >> c;
if(c == '#') {
// comment line
_phaseSpaceHeaderFileStream.ignore(INT_MAX, '\n');
continue;
}
_phaseSpaceHeaderFileStream.putback(c);

token.clear();
_phaseSpaceHeaderFileStream >> token;
Log::global_log->info() << "{{" << token << "}}" << std::endl;

if((token == "currentTime") || (token == "t")) {
// set current simulation time
_phaseSpaceHeaderFileStream >> token;
_simulation.setSimulationTime(strtod(token.c_str(), NULL));
} else if((token == "Temperature") || (token == "T")) {
// set global thermostat temperature
domain->disableComponentwiseThermostat(); //disable component wise thermostats
double targetT;
_phaseSpaceHeaderFileStream >> targetT;
domain->setGlobalTemperature(targetT);
} else if((token == "ThermostatTemperature") || (token == "ThT") || (token == "h")) {
// set up a new thermostat
int thermostat_id;
double targetT;
_phaseSpaceHeaderFileStream >> thermostat_id;
_phaseSpaceHeaderFileStream >> targetT;
Log::global_log->info() << "Thermostat number " << thermostat_id << " has T = " << targetT << ".\n";
domain->setTargetTemperature(thermostat_id, targetT);
} else if((token == "ComponentThermostat") || (token == "CT") || (token == "o")) {
// specify a thermostat for a component
if(!domain->severalThermostats())
domain->enableComponentwiseThermostat();
int component_id;
int thermostat_id;
_phaseSpaceHeaderFileStream >> component_id >> thermostat_id;
Log::global_log->info() << "Component " << component_id << " (internally: " << component_id - 1
<< ") is regulated by thermostat number " << thermostat_id << ".\n";
component_id--; // FIXME thermostat IDs start with 0 in the program but not in the config file?!
if(thermostat_id < 0) // thermostat IDs start with 0
continue;
domain->setComponentThermostat(component_id, thermostat_id);
} else if((token == "Undirected") || (token == "U")) {
// set undirected thermostat
int thermostat_id;
_phaseSpaceHeaderFileStream >> thermostat_id;
domain->enableUndirectedThermostat(thermostat_id);
} else if((token == "Length") || (token == "L")) {
// simulation box dimensions
double globalLength[3];
_phaseSpaceHeaderFileStream >> globalLength[0] >> globalLength[1] >> globalLength[2];
delete _simulation.getEnsemble()->domain();
_simulation.getEnsemble()->domain() = new BoxDomain();
for(int d = 0; d < 3; d++) {
static_cast<BoxDomain*>(_simulation.getEnsemble()->domain())->setLength(d, globalLength[d]);
domain->setGlobalLength(d, _simulation.getEnsemble()->domain()->length(d));
}
} else if((token == "HeatCapacity") || (token == "cv") || (token == "I")) {
unsigned N;
double U, UU;
_phaseSpaceFileStream >> N >> U >> UU;
domain->init_cv(N, U, UU);
} else if((token == "NumberOfComponents") || (token == "C")) {
// read in component definitions and
// read in mixing coefficients

// components:
unsigned int numcomponents = 0;
_phaseSpaceHeaderFileStream >> numcomponents;
Log::global_log->info() << "Reading " << numcomponents << " components" << std::endl;
dcomponents.resize(numcomponents);
for(unsigned int i = 0; i < numcomponents; i++) {
Log::global_log->info() << "comp. i = " << i << ": " << std::endl;
dcomponents[i].setID(i);
unsigned int numljcenters = 0;
unsigned int numcharges = 0;
unsigned int numdipoles = 0;
unsigned int numquadrupoles = 0;
unsigned int numtersoff = 0; //previously tersoff
_phaseSpaceHeaderFileStream >> numljcenters >> numcharges >> numdipoles
>> numquadrupoles >> numtersoff;
if(numtersoff != 0) {
Log::global_log->error() << "tersoff no longer supported."
<< std::endl;
Simulation::exit(-1);
}
double x, y, z, m;
for(unsigned int j = 0; j < numljcenters; j++) {
double eps, sigma, tcutoff, do_shift;
_phaseSpaceHeaderFileStream >> x >> y >> z >> m >> eps >> sigma >> tcutoff >> do_shift;
dcomponents[i].addLJcenter(x, y, z, m, eps, sigma, tcutoff, (do_shift != 0));
Log::global_log->info() << "LJ at [" << x << " " << y << " " << z << "], mass: " << m << ", epsilon: "
<< eps << ", sigma: " << sigma << std::endl;
}
for(unsigned int j = 0; j < numcharges; j++) {
double q;
_phaseSpaceHeaderFileStream >> x >> y >> z >> m >> q;
dcomponents[i].addCharge(x, y, z, m, q);
Log::global_log->info() << "charge at [" << x << " " << y << " " << z << "], mass: " << m << ", q: " << q
<< std::endl;
}
for(unsigned int j = 0; j < numdipoles; j++) {
double eMyx, eMyy, eMyz, absMy;
_phaseSpaceHeaderFileStream >> x >> y >> z >> eMyx >> eMyy >> eMyz >> absMy;
dcomponents[i].addDipole(x, y, z, eMyx, eMyy, eMyz, absMy);
Log::global_log->info() << "dipole at [" << x << " " << y << " " << z << "] " << std::endl;
}
for(unsigned int j = 0; j < numquadrupoles; j++) {
double eQx, eQy, eQz, absQ;
_phaseSpaceHeaderFileStream >> x >> y >> z >> eQx >> eQy >> eQz >> absQ;
dcomponents[i].addQuadrupole(x, y, z, eQx, eQy, eQz, absQ);
Log::global_log->info() << "quad at [" << x << " " << y << " " << z << "] " << std::endl;
}
double IDummy1, IDummy2, IDummy3;
// FIXME! Was soll das hier? Was ist mit der Initialisierung im Fall I <= 0.
_phaseSpaceHeaderFileStream >> IDummy1 >> IDummy2 >> IDummy3;
if(IDummy1 > 0.) dcomponents[i].setI11(IDummy1);
if(IDummy2 > 0.) dcomponents[i].setI22(IDummy2);
if(IDummy3 > 0.) dcomponents[i].setI33(IDummy3);
domain->setProfiledComponentMass(dcomponents[i].m());
Log::global_log->info() << std::endl;
}

#ifndef NDEBUG
for(unsigned int i = 0; i < numcomponents; i++) {
Log::global_log->debug() << "Component " << (i + 1) << " of " << numcomponents << std::endl;
Log::global_log->debug() << dcomponents[i] << std::endl;
}
#endif

// Mixing coefficients
std::vector<double>& dmixcoeff = domain->getmixcoeff();
dmixcoeff.clear();
for(unsigned int i = 1; i < numcomponents; i++) {
for(unsigned int j = i + 1; j <= numcomponents; j++) {
double xi, eta;
_phaseSpaceHeaderFileStream >> xi >> eta;
dmixcoeff.push_back(xi);
dmixcoeff.push_back(eta);
}
}
// read in global factor \epsilon_{RF}
// FIXME: Maybe this should go better to a seperate token?!
_phaseSpaceHeaderFileStream >> token;
domain->setepsilonRF(strtod(token.c_str(), NULL));
long int fpos;
if(_phaseSpaceFile == _phaseSpaceHeaderFile) {
// in the case of a single phase space header + phase space file
// find out the actual position, because the phase space definition will follow
// FIXME: is there a more elegant way?
fpos = _phaseSpaceHeaderFileStream.tellg();
_phaseSpaceFileStream.seekg(fpos, std::ios::beg);
}
// FIXME: Is there a better solution than skipping the rest of the file?
header = false;
} else if((token == "NumberOfMolecules") || (token == "N")) {
// set number of Molecules
// FIXME: Is this part called in any case as the token is handled in the readPhaseSpace method?
_phaseSpaceHeaderFileStream >> token;
domain->setglobalNumMolecules( strtoul(token.c_str(),NULL,0) );
}
// LOCATION OF OLD PRESSURE GRADIENT TOKENS
else {
Log::global_log->error() << "Invalid token \'" << token << "\' found. Skipping rest of the header." << std::endl;
header = false;
}
}

_simulation.getEnsemble()->setComponentLookUpIDs();

_phaseSpaceHeaderFileStream.close();
Log::global_log->error() << "[ASCII Reader] Using the header of the ASCII checkpoints is deprecated" << std::endl;
Log::global_log->error() << "[ASCII Reader] Use the config xml file instead to set according values" << std::endl;
Simulation::exit(1);
}

unsigned long
Expand Down
2 changes: 2 additions & 0 deletions src/io/ASCIIReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class ASCIIReader : public InputBase {
//! @brief For this class, header and data are in the same file, so there is no separate header file
void setPhaseSpaceHeaderFile(std::string filename);

//! DEPRECATED!
//! The information stored in the header must be provided via the xml config file
//! @brief reads in header of the input file (including component description)
//!
//! The Header in the input file consists of several elements. An element starts
Expand Down
Loading