forked from WolfgangLechner/StructureAnalysis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparameter.cpp
More file actions
executable file
·92 lines (82 loc) · 3.03 KB
/
parameter.cpp
File metadata and controls
executable file
·92 lines (82 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include "parameter.h"
#include<fstream>
const string PF_NUMBEROFPARTICLES = "NumberOfParticles";
const string PF_BOXX = "xBox";
const string PF_BOXY = "yBox";
const string PF_BOXZ = "zBox";
const string PF_XYZFILE = "XYZFile";
const string PF_BASEUNIT = "BaseUnit";
const string PF_NUMBEROFCELLS = "NumberOfCells";
const string PF_NEIGHBORDISTANCE = "NeighborDistance";
//Constructor
CParameter::CParameter()
{
this->nop = -1;
this->boxx = -1.0;
this->boxy = -1.0;
this->boxz = -1.0;
this->xyzFile = "notset";
this->baseunit = -1;
this->noc = -1;
}
// Destructor
CParameter::~CParameter()
{
}
//****************************************************************************************
//This procedure reads the parameter.txt file. The keywords are defined above with PF_...
//if a line starts with // it is handled as comment
//do not have spaces before or after =
//****************************************************************************************
void CParameter::readParameter(int myrank)
{
char IntStr[80];
sprintf( IntStr, "input/parameter.%d.txt", myrank);
ifstream AnfangsFile;
if (myrank == 0)
{
AnfangsFile.open("parameter.txt");
} else {
AnfangsFile.open(IntStr);
}
string line;
string::size_type pos;
int i = 0;
while (getline(AnfangsFile,line))
{
if(line.substr(0, 2).compare("//")!=0)
{
pos = line.find('=');
if (pos != string::npos)
{
this->rawParameter[i].name = line.substr(0, pos );
this->rawParameter[i].value = line.substr(pos+1, string::npos );
i += 1;
} else {if (line.compare("")>0) {cerr << "malformed line in parameterfile :" << line << "\n";}}
}
}
for (int j = 0;j < i;j++)
{
if (rawParameter[j].name.compare(PF_NUMBEROFPARTICLES) == 0) {this->nop = atoi(rawParameter[j].value.c_str());}
if (rawParameter[j].name.compare(PF_BOXX) == 0) {this->boxx = atof(rawParameter[j].value.c_str());}
if (rawParameter[j].name.compare(PF_BOXY) == 0) {this->boxy = atof(rawParameter[j].value.c_str());}
if (rawParameter[j].name.compare(PF_BOXZ) == 0) {this->boxz = atof(rawParameter[j].value.c_str());}
if (rawParameter[j].name.compare(PF_XYZFILE) == 0) {this->xyzFile = rawParameter[j].value;}
if (rawParameter[j].name.compare(PF_BASEUNIT) == 0) {this->baseunit = atoi(rawParameter[j].value.c_str());}
if (rawParameter[j].name.compare(PF_NUMBEROFCELLS) == 0) {this->noc = atoi(rawParameter[j].value.c_str());}
if (rawParameter[j].name.compare(PF_NEIGHBORDISTANCE) == 0) {this->neighbordistance = atof(rawParameter[j].value.c_str());}
}
checkParameter();
}
//Check some consitances, minnd = min Neighbor distance
void CParameter::checkParameter()
{
double minnd;
minnd = double(this->boxx)/double(this->baseunit)*sqrt(2.0)/2.0;
if (this->neighbordistance < minnd)
{
cerr << "The minimal neighbor distance is " << minnd << "in parameter.txt it is set to " << this->neighbordistance << "\n";
cerr << "I now set the neighbordistance to reach the first shell " <<"\n";
this->neighbordistance = minnd + 0.2;
}
}