inheritance is cool, pointers to local objects not so much

This commit is contained in:
dqueteschiner
2015-03-26 16:09:44 +01:00
parent 343d1cba5b
commit 29cc6d9d74
2 changed files with 89 additions and 102 deletions

View File

@ -71,10 +71,6 @@ oneWayVTK::oneWayVTK
maxNumberOfParticles_ = readScalar(propsDict_.lookup("maxNumberOfParticles"));
setNumberOfParticles(maxNumberOfParticles_);
// make a const char* from word
string HH=string(filename_);
charFilename_=HH.c_str();
Info << "relativePath_" << relativePath_ << endl;
}
@ -94,107 +90,100 @@ void oneWayVTK::getData
label step
) const
{
if (type == "scalar-atom")
{
// get path to particle VTK files
char index[100];
sprintf(index, charFilename_, step);
//fileName H(particleCloud_.mesh().time().path()/".."/"DEM"/"post"/index);
fileName H(particleCloud_.mesh().time().path()/relativePath_/index);
Info << "opening file: " <<H << endl;
// set file pointer
string HH=string(H);
const char * paricleFilePath=HH.c_str();
ifstream* inputPtr;
inputPtr = new ifstream(paricleFilePath);
if (name == "radius")
if (type == "scalar-atom")
{
// read data
string just_read = " ";
while(just_read.compare(name) != 0) *inputPtr >> just_read; //read until we read "name"
*inputPtr >> just_read; // skip text for dataType
*inputPtr >> just_read; // skip text for "1"
*inputPtr >> just_read; // skip text for "LookUp"
*inputPtr >> just_read; // skip text for "default"
for(int index = 0;index < particleCloud_.numberOfParticles(); ++index)
// get path to particle VTK files
char index[100];
sprintf(index, filename_.c_str(), step);
fileName paricleFilePath(particleCloud_.mesh().time().path()/relativePath_/index);
Info << "opening file: " << paricleFilePath << endl;
// open file
ifstream input(paricleFilePath.c_str());
if (!input.is_open()) cerr << "File not found!, " << paricleFilePath << endl;
if (name == "radius")
{
*inputPtr >> field[index][0];
// read data
string just_read;
while (just_read.compare(name) != 0) input >> just_read; //read until we read "name"
input >> just_read; // skip text for dataType
input >> just_read; // skip text for "1"
input >> just_read; // skip text for "LookUp"
input >> just_read; // skip text for "default"
for (int index = 0; index<particleCloud_.numberOfParticles(); ++index)
{
input >> field[index][0];
}
}
else
{
// read data
string just_read;
while (just_read.compare(name) != 0) input >> just_read; //read until we read "name"
input >> just_read; // skip text for dataType
for (int index = 0; index<particleCloud_.numberOfParticles(); ++index)
{
input >> field[index][0];
}
}
// close inputStream
input.close();
}
else if (type == "vector-atom")
{
// get path to particle VTK files
char index[100];
sprintf(index, filename_.c_str(), step);
fileName paricleFilePath(particleCloud_.mesh().time().path()/relativePath_/index);
Info << "opening file: " << paricleFilePath << endl;
// open file
ifstream input(paricleFilePath.c_str());
if (!input.is_open()) cerr << "File not found!, " << paricleFilePath << endl;
// read position data from VTK file
//NP: special case as position data has no "name" in the vtk file
if (name == "x")
{
int numberOfParticles; // remove this?
string just_read;
while (just_read.compare("POINTS") != 0) input >> just_read; // read until we read "POINTS"
input >> numberOfParticles; // this is now the number of points in the file
input >> just_read; // skip text for dataType
// give nr of particles to cloud
setNumberOfParticles(numberOfParticles);
// re-allocate arrays of cloud
particleCloud_.reAllocArrays();
for (int index = 0; index<numberOfParticles; ++index)
{
input >> field[index][0] >> field[index][1] >> field[index][2];
}
}
else
{
string just_read;
while (just_read.compare(name) != 0) input >> just_read; // read until we read "name"
input >> just_read; // skip text for dataType
for (int index = 0; index<particleCloud_.numberOfParticles(); ++index)
{
input >> field[index][0] >> field[index][1] >> field[index][2];
}
}
// close inputStream
input.close();
}
else
{
// read data
string just_read = " ";
while(just_read.compare(name) != 0) *inputPtr >> just_read; //read until we read "name"
*inputPtr >> just_read; // skip text for dataType
for(int index = 0;index < particleCloud_.numberOfParticles(); ++index)
{
*inputPtr >> field[index][0];
}
Info << "unknown type in getData!!!" << endl;
}
// clean up inputStream
delete inputPtr;
} else if (type == "vector-atom")
{
// get path to particle VTK files
char index[100];
sprintf(index, charFilename_, step);
//fileName H(particleCloud_.mesh().time().path()/".."/"DEM"/"post"/index);
fileName H(particleCloud_.mesh().time().path()/relativePath_/index);
Info << "opening file: " <<H << endl;
// set file pointer
string HH=string(H);
const char * paricleFilePath=HH.c_str();
ifstream* inputPtr;
inputPtr = new ifstream(paricleFilePath);
// read position data from VTK file
//NP: secial case as position data has no "name" in the vtk file
if (name == "x")
{
int numberOfParticles; // remove this?
string just_read = " ";
if(!*inputPtr) cerr << "File not found!, " << H << endl;
while(just_read.compare("POINTS") != 0) *inputPtr >> just_read; //read until we read "POINTS"
*inputPtr >> numberOfParticles; //this is now the number of points in the file
*inputPtr >> just_read; // skip text for dataType
// give nr of particles to cloud
setNumberOfParticles(numberOfParticles);
// re-allocate arrays of cloud
particleCloud_.reAllocArrays();
for(int index = 0;index < numberOfParticles; ++index)
{
*inputPtr >> field[index][0] >> field[index][1] >> field[index][2];
}
}
else
{
string just_read = " ";
while(just_read.compare(name) != 0) *inputPtr >> just_read; //read until we read "name"
*inputPtr >> just_read; // skip text for dataType
for(int index = 0;index < particleCloud_.numberOfParticles(); ++index)
{
*inputPtr >> field[index][0] >> field[index][1] >> field[index][2];
}
}
// clean up inputStream
delete inputPtr;
}
else
{
Info << "unknown type in getData!!!" << endl;
}
}
void oneWayVTK::giveData

View File

@ -64,8 +64,6 @@ private:
fileName relativePath_;
const char* charFilename_;
public:
//- Runtime type information
@ -102,7 +100,7 @@ public:
int ** const& field,
label step
) const
{};
{}
void giveData
(
@ -112,7 +110,7 @@ public:
const char* datatype = ""
) const;
word myType() const{return typeName; };
word myType() const{ return typeName; }
};