[14de469] | 1 | /** \file datacreator.cpp
|
---|
| 2 | *
|
---|
| 3 | * Declarations of assisting functions in creating data and plot files.
|
---|
| 4 | *
|
---|
| 5 | */
|
---|
| 6 |
|
---|
| 7 | //============================ INCLUDES ===========================
|
---|
| 8 |
|
---|
| 9 | #include "datacreator.hpp"
|
---|
| 10 |
|
---|
| 11 | //=========================== FUNCTIONS============================
|
---|
| 12 |
|
---|
| 13 | /** Opens a file with \a *filename in \a *dir.
|
---|
| 14 | * \param output file handle on return
|
---|
| 15 | * \param *dir directory
|
---|
| 16 | * \param *filename name of file
|
---|
| 17 | * \return true if file has been opened
|
---|
| 18 | */
|
---|
| 19 | bool OpenOutputFile(ofstream &output, const char *dir, const char *filename)
|
---|
| 20 | {
|
---|
| 21 | stringstream name;
|
---|
| 22 | name << dir << "/" << filename;
|
---|
| 23 | output.open(name.str().c_str(), ios::out);
|
---|
| 24 | if (output == NULL) {
|
---|
| 25 | cout << "Unable to open " << name.str() << " for writing, is directory correct?" << endl;
|
---|
| 26 | return false;
|
---|
| 27 | }
|
---|
| 28 | return true;
|
---|
| 29 | };
|
---|
| 30 |
|
---|
| 31 | /** Plots an energy vs. order.
|
---|
[390248] | 32 | * \param &Fragments EnergyMatrix class containing matrix values
|
---|
[14de469] | 33 | * \param KeySet KeySetContainer class holding bond KeySetContainer::Order
|
---|
| 34 | * \param *prefix prefix in filename (without ending)
|
---|
| 35 | * \param *msg message to be place in first line as a comment
|
---|
| 36 | * \return true if file was written successfully
|
---|
| 37 | */
|
---|
[390248] | 38 | bool CreateDataEnergyOrder(class EnergyMatrix &Fragments, class KeySetsContainer &KeySet, char *dir, char *prefix, char *msg, char *datum)
|
---|
[14de469] | 39 | {
|
---|
| 40 | stringstream filename;
|
---|
| 41 | ofstream output;
|
---|
| 42 |
|
---|
| 43 | filename << prefix << ".dat";
|
---|
| 44 | if (!OpenOutputFile(output, dir, filename.str().c_str())) return false;
|
---|
| 45 | cout << msg << endl;
|
---|
| 46 | output << "# " << msg << ", created on " << datum;
|
---|
[390248] | 47 | output << "#Order\tFrag.No.\t" << Fragments.Header << endl;
|
---|
[14de469] | 48 | for (int BondOrder=0;BondOrder<KeySet.Order;BondOrder++) {
|
---|
[7f3b9d] | 49 | for(int i=KeySet.FragmentsPerOrder[BondOrder];i--;) {
|
---|
[390248] | 50 | for(int j=Fragments.RowCounter[ KeySet.OrderSet[BondOrder][i] ];j--;)
|
---|
| 51 | for(int k=Fragments.ColumnCounter;k--;)
|
---|
| 52 | Fragments.Matrix[Fragments.MatrixCounter][j][k] += Fragments.Matrix[ KeySet.OrderSet[BondOrder][i] ][j][k];
|
---|
[14de469] | 53 | }
|
---|
| 54 | output << BondOrder+1 << "\t" << KeySet.FragmentsPerOrder[BondOrder];
|
---|
[390248] | 55 | for (int l=0;l<Fragments.ColumnCounter;l++)
|
---|
| 56 | output << scientific << "\t" << Fragments.Matrix[Fragments.MatrixCounter][ Fragments.RowCounter[Fragments.MatrixCounter]-1 ][l];
|
---|
| 57 | output << endl;
|
---|
| 58 | }
|
---|
| 59 | output.close();
|
---|
| 60 | return true;
|
---|
| 61 | };
|
---|
| 62 |
|
---|
| 63 | /** Plots an energy error vs. order.
|
---|
| 64 | * \param &Energy EnergyMatrix class containing reference values (in MatrixCounter matrix)
|
---|
| 65 | * \param &Fragments EnergyMatrix class containing matrix values
|
---|
| 66 | * \param KeySet KeySetContainer class holding bond KeySetContainer::Order
|
---|
| 67 | * \param *prefix prefix in filename (without ending)
|
---|
| 68 | * \param *msg message to be place in first line as a comment
|
---|
| 69 | * \return true if file was written successfully
|
---|
| 70 | */
|
---|
| 71 | bool CreateDataDeltaEnergyOrder(class EnergyMatrix &Energy, class EnergyMatrix &Fragments, class KeySetsContainer &KeySet, char *dir, char *prefix, char *msg, char *datum)
|
---|
| 72 | {
|
---|
| 73 | stringstream filename;
|
---|
| 74 | ofstream output;
|
---|
| 75 |
|
---|
| 76 | filename << prefix << ".dat";
|
---|
| 77 | if (!OpenOutputFile(output, dir, filename.str().c_str())) return false;
|
---|
| 78 | cout << msg << endl;
|
---|
| 79 | output << "# " << msg << ", created on " << datum;
|
---|
| 80 | output << "#Order\tFrag.No.\t" << Fragments.Header << endl;
|
---|
| 81 | Fragments.SetLastMatrix(Energy.Matrix[Energy.MatrixCounter],0);
|
---|
| 82 | for (int BondOrder=0;BondOrder<KeySet.Order;BondOrder++) {
|
---|
| 83 | for(int i=KeySet.FragmentsPerOrder[BondOrder];i--;) {
|
---|
| 84 | for(int j=Fragments.RowCounter[ KeySet.OrderSet[BondOrder][i] ];j--;)
|
---|
| 85 | for(int k=Fragments.ColumnCounter;k--;)
|
---|
| 86 | Fragments.Matrix[Fragments.MatrixCounter][j][k] -= Fragments.Matrix[ KeySet.OrderSet[BondOrder][i] ][j][k];
|
---|
| 87 | }
|
---|
| 88 | output << BondOrder+1 << "\t" << KeySet.FragmentsPerOrder[BondOrder];
|
---|
| 89 | for (int l=0;l<Fragments.ColumnCounter;l++)
|
---|
| 90 | if (fabs(Energy.Matrix[Energy.MatrixCounter][ Energy.RowCounter[Energy.MatrixCounter]-1 ][l]) < MYEPSILON)
|
---|
| 91 | output << scientific << "\t" << Fragments.Matrix[Fragments.MatrixCounter][ Fragments.RowCounter[Fragments.MatrixCounter]-1 ][l];
|
---|
[14de469] | 92 | else
|
---|
[390248] | 93 | output << scientific << "\t" << (Fragments.Matrix[Fragments.MatrixCounter][ Fragments.RowCounter[Fragments.MatrixCounter]-1 ][l] / Energy.Matrix[Energy.MatrixCounter][ Energy.RowCounter[Energy.MatrixCounter]-1 ][l]);
|
---|
[14de469] | 94 | output << endl;
|
---|
| 95 | }
|
---|
| 96 | output.close();
|
---|
| 97 | return true;
|
---|
| 98 | };
|
---|
| 99 |
|
---|
| 100 | /** Plot forces vs. order.
|
---|
[390248] | 101 | * \param &Fragments ForceMatrix class containing matrix values
|
---|
| 102 | * \param KeySet KeySetContainer class holding bond KeySetContainer::Order
|
---|
| 103 | * \param *prefix prefix in filename (without ending)
|
---|
| 104 | * \param *msg message to be place in first line as a comment
|
---|
| 105 | * \param *datum current date and time
|
---|
| 106 | * \return true if file was written successfully
|
---|
[14de469] | 107 | */
|
---|
[390248] | 108 | bool CreateDataForcesOrder(class ForceMatrix &Fragments, class KeySetsContainer &KeySet, char *dir, char *prefix, char *msg, char *datum, void (*CreateForce)(class MatrixContainer &, int))
|
---|
[14de469] | 109 | {
|
---|
| 110 | stringstream filename;
|
---|
| 111 | ofstream output;
|
---|
| 112 |
|
---|
| 113 | filename << prefix << ".dat";
|
---|
| 114 | if (!OpenOutputFile(output, dir, filename.str().c_str())) return false;
|
---|
| 115 | cout << msg << endl;
|
---|
| 116 | output << "# " << msg << ", created on " << datum;
|
---|
[390248] | 117 | output << "# Order\tFrag.No.\t" << Fragments.Header << endl;
|
---|
| 118 | Fragments.SetLastMatrix(0.,0);
|
---|
[14de469] | 119 | for (int BondOrder=0;BondOrder<KeySet.Order;BondOrder++) {
|
---|
[390248] | 120 | Fragments.SumSubForces(Fragments, KeySet, BondOrder, 1.);
|
---|
| 121 | output << BondOrder+1 << "\t" << KeySet.FragmentsPerOrder[BondOrder];
|
---|
| 122 | CreateForce(Fragments, Fragments.MatrixCounter);
|
---|
| 123 | for (int l=0;l<Fragments.ColumnCounter;l++)
|
---|
| 124 | output << scientific << "\t" << Fragments.Matrix[Fragments.MatrixCounter][ Fragments.RowCounter[Fragments.MatrixCounter] ][l];
|
---|
| 125 | output << endl;
|
---|
| 126 | }
|
---|
| 127 | output.close();
|
---|
| 128 | return true;
|
---|
| 129 | };
|
---|
| 130 |
|
---|
| 131 | /** Plot forces error vs. order.
|
---|
| 132 | * \param &Force ForceMatrix containing reference values (in MatrixCounter matrix)
|
---|
| 133 | * \param &Fragments ForceMatrix class containing matrix values
|
---|
| 134 | * \param KeySet KeySetContainer class holding bond KeySetContainer::Order
|
---|
| 135 | * \param *prefix prefix in filename (without ending)
|
---|
| 136 | * \param *msg message to be place in first line as a comment
|
---|
| 137 | * \param *datum current date and time
|
---|
| 138 | * \return true if file was written successfully
|
---|
| 139 | */
|
---|
| 140 | bool CreateDataDeltaForcesOrder(class ForceMatrix &Force, class ForceMatrix &Fragments, class KeySetsContainer &KeySet, char *dir, char *prefix, char *msg, char *datum, void (*CreateForce)(class MatrixContainer &, int))
|
---|
| 141 | {
|
---|
| 142 | stringstream filename;
|
---|
| 143 | ofstream output;
|
---|
| 144 |
|
---|
| 145 | filename << prefix << ".dat";
|
---|
| 146 | if (!OpenOutputFile(output, dir, filename.str().c_str())) return false;
|
---|
| 147 | cout << msg << endl;
|
---|
| 148 | output << "# " << msg << ", created on " << datum;
|
---|
| 149 | output << "# Order\tFrag.No.\t" << Fragments.Header << endl;
|
---|
| 150 | Fragments.SetLastMatrix(Force.Matrix[Force.MatrixCounter],0);
|
---|
| 151 | for (int BondOrder=0;BondOrder<KeySet.Order;BondOrder++) {
|
---|
| 152 | Fragments.SumSubForces(Fragments, KeySet, BondOrder, -1.);
|
---|
| 153 | output << BondOrder+1 << "\t" << KeySet.FragmentsPerOrder[BondOrder];
|
---|
| 154 | CreateForce(Fragments, Fragments.MatrixCounter);
|
---|
| 155 | for (int l=0;l<Fragments.ColumnCounter;l++)
|
---|
| 156 | output << scientific << "\t" << Fragments.Matrix[Fragments.MatrixCounter][ Fragments.RowCounter[Fragments.MatrixCounter] ][l];
|
---|
| 157 | output << endl;
|
---|
| 158 | }
|
---|
| 159 | output.close();
|
---|
| 160 | return true;
|
---|
| 161 | };
|
---|
| 162 |
|
---|
| 163 | /** Plot forces error vs. vs atom vs. order.
|
---|
| 164 | * \param &Force ForceMatrix containing reference values (in MatrixCounter matrix)
|
---|
| 165 | * \param &Fragments ForceMatrix class containing matrix values
|
---|
| 166 | * \param KeySet KeySetContainer class holding bond KeySetContainer::Order
|
---|
| 167 | * \param *prefix prefix in filename (without ending)
|
---|
| 168 | * \param *msg message to be place in first line as a comment
|
---|
| 169 | * \param *datum current date and time
|
---|
| 170 | * \return true if file was written successfully
|
---|
| 171 | */
|
---|
| 172 | bool CreateDataDeltaForcesOrderPerAtom(class ForceMatrix &Force, class ForceMatrix &Fragments, class KeySetsContainer &KeySet, char *dir, char *prefix, char *msg, char *datum)
|
---|
| 173 | {
|
---|
| 174 | stringstream filename;
|
---|
| 175 | ofstream output;
|
---|
| 176 | double norm = 0.;
|
---|
| 177 |
|
---|
| 178 | filename << prefix << ".dat";
|
---|
| 179 | if (!OpenOutputFile(output, dir, filename.str().c_str())) return false;
|
---|
| 180 | cout << msg << endl;
|
---|
| 181 | output << "# " << msg << ", created on " << datum;
|
---|
| 182 | output << "# AtomNo\t" << Fragments.Header << endl;
|
---|
| 183 | Fragments.SetLastMatrix(Force.Matrix[Force.MatrixCounter], 0);
|
---|
| 184 | for (int BondOrder=0;BondOrder<KeySet.Order;BondOrder++) {
|
---|
| 185 | //cout << "Current order is " << BondOrder << "." << endl;
|
---|
| 186 | Fragments.SumSubForces(Fragments, KeySet, BondOrder, -1.);
|
---|
| 187 | // errors per atom
|
---|
| 188 | output << "#Order\t" << BondOrder+1 << endl;
|
---|
| 189 | for(int j=0;j<Fragments.RowCounter[ Fragments.MatrixCounter ];j++) {
|
---|
| 190 | output << Fragments.Indices[Fragments.MatrixCounter][j] << "\t";
|
---|
| 191 | for (int l=0;l<Fragments.ColumnCounter;l++) {
|
---|
| 192 | if (((l+1) % 3) == 0) {
|
---|
| 193 | norm = 0.;
|
---|
| 194 | for (int m=0;m<NDIM;m++)
|
---|
| 195 | norm += Force.Matrix[Force.MatrixCounter][ j ][l+m]*Force.Matrix[Force.MatrixCounter][ j ][l+m];
|
---|
| 196 | norm = sqrt(norm);
|
---|
| 197 | }
|
---|
| 198 | // if (norm < MYEPSILON)
|
---|
| 199 | output << scientific << Fragments.Matrix[Fragments.MatrixCounter][ j ][l] << "\t";
|
---|
| 200 | // else
|
---|
| 201 | // output << scientific << (Fragments.Matrix[Fragments.MatrixCounter][ j ][l] / norm) << "\t";
|
---|
[14de469] | 202 | }
|
---|
[390248] | 203 | output << endl;
|
---|
| 204 | }
|
---|
| 205 | output << endl;
|
---|
| 206 | }
|
---|
| 207 | output.close();
|
---|
| 208 | return true;
|
---|
| 209 | };
|
---|
| 210 |
|
---|
| 211 | /** Plot forces error vs. vs atom vs. order.
|
---|
| 212 | * \param &Fragments ForceMatrix class containing matrix values
|
---|
| 213 | * \param KeySet KeySetContainer class holding bond KeySetContainer::Order
|
---|
| 214 | * \param *prefix prefix in filename (without ending)
|
---|
| 215 | * \param *msg message to be place in first line as a comment
|
---|
| 216 | * \param *datum current date and time
|
---|
| 217 | * \return true if file was written successfully
|
---|
| 218 | */
|
---|
| 219 | bool CreateDataForcesOrderPerAtom(class ForceMatrix &Fragments, class KeySetsContainer &KeySet, char *dir, char *prefix, char *msg, char *datum)
|
---|
| 220 | {
|
---|
| 221 | stringstream filename;
|
---|
| 222 | ofstream output;
|
---|
| 223 |
|
---|
| 224 | filename << prefix << ".dat";
|
---|
| 225 | if (!OpenOutputFile(output, dir, filename.str().c_str())) return false;
|
---|
| 226 | cout << msg << endl;
|
---|
| 227 | output << "# " << msg << ", created on " << datum;
|
---|
| 228 | output << "# AtomNo\t" << Fragments.Header << endl;
|
---|
| 229 | for (int BondOrder=0;BondOrder<KeySet.Order;BondOrder++) {
|
---|
| 230 | //cout << "Current order is " << BondOrder << "." << endl;
|
---|
| 231 | Fragments.SumSubForces(Fragments, KeySet, BondOrder, 1.);
|
---|
| 232 | // errors per atom
|
---|
| 233 | output << "#Order\t" << BondOrder+1 << endl;
|
---|
| 234 | for(int j=0;j<Fragments.RowCounter[ Fragments.MatrixCounter ];j++) {
|
---|
| 235 | output << Fragments.Indices[Fragments.MatrixCounter][j] << "\t";
|
---|
| 236 | for (int l=0;l<Fragments.ColumnCounter;l++)
|
---|
| 237 | output << scientific << Fragments.Matrix[Fragments.MatrixCounter][ j ][l] << "\t";
|
---|
| 238 | output << endl;
|
---|
[14de469] | 239 | }
|
---|
| 240 | output << endl;
|
---|
| 241 | }
|
---|
| 242 | output.close();
|
---|
| 243 | return true;
|
---|
| 244 | };
|
---|
| 245 |
|
---|
| 246 | /** Plot matrix vs. fragment.
|
---|
| 247 | */
|
---|
| 248 | bool CreateDataFragment(class MatrixContainer &Fragment, class KeySetsContainer &KeySet, char *dir, char *prefix, char *msg, char *datum, void (*CreateFragment)(class MatrixContainer &, int))
|
---|
| 249 | {
|
---|
| 250 | stringstream filename;
|
---|
| 251 | ofstream output;
|
---|
| 252 |
|
---|
| 253 | filename << prefix << ".dat";
|
---|
| 254 | if (!OpenOutputFile(output, dir, filename.str().c_str())) return false;
|
---|
| 255 | cout << msg << endl;
|
---|
[bf2db1] | 256 | output << "# " << msg << ", created on " << datum << endl;
|
---|
[14de469] | 257 | output << "#Order\tFrag.No.\t" << Fragment.Header << endl;
|
---|
| 258 | for (int BondOrder=0;BondOrder<KeySet.Order;BondOrder++) {
|
---|
| 259 | for(int i=0;i<KeySet.FragmentsPerOrder[BondOrder];i++) {
|
---|
| 260 | output << BondOrder+1 << "\t" << KeySet.OrderSet[BondOrder][i]+1;
|
---|
| 261 | CreateFragment(Fragment, KeySet.OrderSet[BondOrder][i]);
|
---|
| 262 | for (int l=0;l<Fragment.ColumnCounter;l++)
|
---|
| 263 | output << scientific << "\t" << Fragment.Matrix[ KeySet.OrderSet[BondOrder][i] ][ Fragment.RowCounter[ KeySet.OrderSet[BondOrder][i] ] ][l];
|
---|
| 264 | output << endl;
|
---|
| 265 | }
|
---|
| 266 | }
|
---|
| 267 | output.close();
|
---|
| 268 | return true;
|
---|
| 269 | };
|
---|
| 270 |
|
---|
| 271 | /** Copies fragment energy values into last matrix of \a Matrix with greatest total energy.
|
---|
| 272 | * \param &Matrix MatrixContainer with all fragment energy values
|
---|
| 273 | * \param &KeySet KeySetsContainer with associations of each fragment to a bond order
|
---|
| 274 | * \param BondOrder current bond order
|
---|
| 275 | */
|
---|
| 276 | void CreateMaxFragmentOrder(class MatrixContainer &Fragments, class KeySetsContainer &KeySet, int BondOrder)
|
---|
| 277 | {
|
---|
[7f3b9d] | 278 | for(int j=Fragments.RowCounter[ Fragments.MatrixCounter ];j--;) {
|
---|
| 279 | for(int i=KeySet.FragmentsPerOrder[BondOrder];i--;) {
|
---|
[14de469] | 280 | if (fabs(Fragments.Matrix[ Fragments.MatrixCounter ][j][1]) < fabs(Fragments.Matrix[ KeySet.OrderSet[BondOrder][i] ][j][1])) {
|
---|
[7f3b9d] | 281 | for (int k=Fragments.ColumnCounter;k--;)
|
---|
[14de469] | 282 | Fragments.Matrix[ Fragments.MatrixCounter ][j][k] = Fragments.Matrix[ KeySet.OrderSet[BondOrder][i] ][j][k];
|
---|
| 283 | }
|
---|
| 284 | }
|
---|
| 285 | }
|
---|
| 286 | };
|
---|
| 287 |
|
---|
| 288 | /** Copies fragment energy values into last matrix of \a Matrix with smallest total energy.
|
---|
| 289 | * \param &Matrix MatrixContainer with all fragment energy values
|
---|
| 290 | * \param &KeySet KeySetsContainer with associations of each fragment to a bond order
|
---|
| 291 | * \param BondOrder current bond order
|
---|
| 292 | */
|
---|
| 293 | void CreateMinFragmentOrder(class MatrixContainer &Fragments, class KeySetsContainer &KeySet, int BondOrder)
|
---|
| 294 | {
|
---|
| 295 | for(int j=0;j<Fragments.RowCounter[ Fragments.MatrixCounter ];j++) {
|
---|
| 296 | int i=0;
|
---|
| 297 | do { // first get a minimum value unequal to 0
|
---|
[7f3b9d] | 298 | for (int k=Fragments.ColumnCounter;k--;)
|
---|
[14de469] | 299 | Fragments.Matrix[ Fragments.MatrixCounter ][j][k] = Fragments.Matrix[ KeySet.OrderSet[BondOrder][i] ][j][k];
|
---|
| 300 | i++;
|
---|
| 301 | } while ((fabs(Fragments.Matrix[ Fragments.MatrixCounter ][j][1]) < MYEPSILON) && (i<KeySet.FragmentsPerOrder[BondOrder]));
|
---|
| 302 | for(;i<KeySet.FragmentsPerOrder[BondOrder];i++) { // then find lowest
|
---|
| 303 | if (fabs(Fragments.Matrix[ Fragments.MatrixCounter ][j][1]) > fabs(Fragments.Matrix[ KeySet.OrderSet[BondOrder][i] ][j][1])) {
|
---|
[7f3b9d] | 304 | for (int k=Fragments.ColumnCounter;k--;)
|
---|
[14de469] | 305 | Fragments.Matrix[ Fragments.MatrixCounter ][j][k] = Fragments.Matrix[ KeySet.OrderSet[BondOrder][i] ][j][k];
|
---|
| 306 | }
|
---|
| 307 | }
|
---|
| 308 | }
|
---|
| 309 | };
|
---|
| 310 |
|
---|
| 311 | /** Plot matrix vs. fragment.
|
---|
| 312 | */
|
---|
| 313 | bool CreateDataFragmentOrder(class MatrixContainer &Fragment, class KeySetsContainer &KeySet, char *dir, char *prefix, char *msg, char *datum, void (*CreateFragmentOrder)(class MatrixContainer &, class KeySetsContainer &, int))
|
---|
| 314 | {
|
---|
| 315 | stringstream filename;
|
---|
| 316 | ofstream output;
|
---|
| 317 |
|
---|
| 318 | filename << prefix << ".dat";
|
---|
| 319 | if (!OpenOutputFile(output, dir, filename.str().c_str())) return false;
|
---|
| 320 | cout << msg << endl;
|
---|
| 321 | output << "# " << msg << ", created on " << datum;
|
---|
| 322 | output << "#Order\tFrag.No.\t" << Fragment.Header << endl;
|
---|
| 323 | // max
|
---|
| 324 | for (int BondOrder=0;BondOrder<KeySet.Order;BondOrder++) {
|
---|
| 325 | Fragment.SetLastMatrix(0.,0);
|
---|
| 326 | CreateFragmentOrder(Fragment, KeySet, BondOrder);
|
---|
| 327 | output << BondOrder+1 << "\t" << KeySet.FragmentsPerOrder[BondOrder];
|
---|
| 328 | for (int l=0;l<Fragment.ColumnCounter;l++)
|
---|
| 329 | output << scientific << "\t" << Fragment.Matrix[ Fragment.MatrixCounter ][ Fragment.RowCounter[ Fragment.MatrixCounter ]-1 ][l];
|
---|
| 330 | output << endl;
|
---|
| 331 | }
|
---|
| 332 | output.close();
|
---|
| 333 | return true;
|
---|
| 334 | };
|
---|
| 335 |
|
---|
| 336 | /** Takes last but one row and copies into final row.
|
---|
| 337 | * \param Energy MatrixContainer with matrix values
|
---|
| 338 | * \param MatrixNumber the index for the ForceMatrix::matrix array
|
---|
| 339 | */
|
---|
| 340 | void CreateEnergy(class MatrixContainer &Energy, int MatrixNumber)
|
---|
| 341 | {
|
---|
| 342 | for(int k=0;k<Energy.ColumnCounter;k++)
|
---|
| 343 | Energy.Matrix[MatrixNumber][ Energy.RowCounter[MatrixNumber] ] [k] = Energy.Matrix[MatrixNumber][ Energy.RowCounter[MatrixNumber]-1 ] [k];
|
---|
| 344 | };
|
---|
| 345 |
|
---|
| 346 | /** Scans forces for the minimum in magnitude.
|
---|
| 347 | * Results are stored in the matrix ForceMatrix::MatrixCounter of \a Force.
|
---|
| 348 | * \param Force ForceMatrix class containing matrix values
|
---|
| 349 | * \param MatrixNumber the index for the ForceMatrix::matrix array
|
---|
| 350 | */
|
---|
| 351 | void CreateMinimumForce(class MatrixContainer &Force, int MatrixNumber)
|
---|
| 352 | {
|
---|
[7f3b9d] | 353 | for (int l=Force.ColumnCounter;l--;)
|
---|
[14de469] | 354 | Force.Matrix[MatrixNumber][ Force.RowCounter[MatrixNumber] ][l] = 0.;
|
---|
| 355 | for (int l=5;l<Force.ColumnCounter;l+=3) {
|
---|
| 356 | double stored = 0;
|
---|
| 357 | int k=0;
|
---|
| 358 | do {
|
---|
[7f3b9d] | 359 | for (int m=NDIM;m--;) {
|
---|
[14de469] | 360 | stored += Force.Matrix[MatrixNumber][ k ][l+m]
|
---|
| 361 | * Force.Matrix[MatrixNumber][ k ][l+m];
|
---|
| 362 | Force.Matrix[MatrixNumber][ Force.RowCounter[MatrixNumber] ][l+m] = Force.Matrix[MatrixNumber][ k ][l+m];
|
---|
| 363 | }
|
---|
| 364 | k++;
|
---|
| 365 | } while ((fabs(stored) < MYEPSILON) && (k<Force.RowCounter[MatrixNumber]));
|
---|
| 366 | for (;k<Force.RowCounter[MatrixNumber];k++) {
|
---|
| 367 | double tmp = 0;
|
---|
[7f3b9d] | 368 | for (int m=NDIM;m--;)
|
---|
[14de469] | 369 | tmp += Force.Matrix[MatrixNumber][ k ][l+m]
|
---|
| 370 | * Force.Matrix[MatrixNumber][ k ][l+m];
|
---|
| 371 | if ((fabs(tmp) > MYEPSILON) && (tmp < stored)) { // current force is greater than stored
|
---|
[7f3b9d] | 372 | for (int m=NDIM;m--;)
|
---|
[14de469] | 373 | Force.Matrix[MatrixNumber][ Force.RowCounter[MatrixNumber] ][l+m] = Force.Matrix[MatrixNumber][ k ][l+m];
|
---|
| 374 | stored = tmp;
|
---|
| 375 | }
|
---|
| 376 | }
|
---|
| 377 | }
|
---|
| 378 | };
|
---|
| 379 |
|
---|
| 380 | /** Scans forces for the mean in magnitude.
|
---|
| 381 | * Results are stored in the matrix ForceMatrix::MatrixCounter of \a Force.
|
---|
| 382 | * \param Force ForceMatrix class containing matrix values
|
---|
| 383 | * \param MatrixNumber the index for the ForceMatrix::matrix array
|
---|
| 384 | */
|
---|
| 385 | void CreateMeanForce(class MatrixContainer &Force, int MatrixNumber)
|
---|
| 386 | {
|
---|
| 387 | int divisor = 0;
|
---|
[7f3b9d] | 388 | for (int l=Force.ColumnCounter;l--;)
|
---|
[14de469] | 389 | Force.Matrix[MatrixNumber][ Force.RowCounter[MatrixNumber] ][l] = 0.;
|
---|
| 390 | for (int l=5;l<Force.ColumnCounter;l+=3) {
|
---|
| 391 | double tmp = 0;
|
---|
[7f3b9d] | 392 | for (int k=Force.RowCounter[MatrixNumber];k--;) {
|
---|
[14de469] | 393 | double norm = 0.;
|
---|
[7f3b9d] | 394 | for (int m=NDIM;m--;)
|
---|
[14de469] | 395 | norm += Force.Matrix[MatrixNumber][ k ][l+m]
|
---|
| 396 | * Force.Matrix[MatrixNumber][ k ][l+m];
|
---|
| 397 | tmp += sqrt(norm);
|
---|
| 398 | if (fabs(norm) > MYEPSILON) divisor++;
|
---|
| 399 | }
|
---|
| 400 | tmp /= (double)divisor;
|
---|
| 401 | Force.Matrix[MatrixNumber][ Force.RowCounter[MatrixNumber] ][l] = tmp;
|
---|
| 402 | }
|
---|
| 403 | };
|
---|
| 404 |
|
---|
| 405 | /** Scans forces for the maximum in magnitude.
|
---|
| 406 | * Results are stored in the matrix ForceMatrix::MatrixCounter of \a Force.
|
---|
| 407 | * \param Force ForceMatrix class containing matrix values
|
---|
| 408 | * \param MatrixNumber the index for the ForceMatrix::matrix array
|
---|
| 409 | */
|
---|
| 410 | void CreateMaximumForce(class MatrixContainer &Force, int MatrixNumber)
|
---|
| 411 | {
|
---|
| 412 | for (int l=5;l<Force.ColumnCounter;l+=3) {
|
---|
| 413 | double stored = 0;
|
---|
[7f3b9d] | 414 | for (int k=Force.RowCounter[MatrixNumber];k--;) {
|
---|
[14de469] | 415 | double tmp = 0;
|
---|
[7f3b9d] | 416 | for (int m=NDIM;m--;)
|
---|
[14de469] | 417 | tmp += Force.Matrix[MatrixNumber][ k ][l+m]
|
---|
| 418 | * Force.Matrix[MatrixNumber][ k ][l+m];
|
---|
| 419 | if (tmp > stored) { // current force is greater than stored
|
---|
[7f3b9d] | 420 | for (int m=NDIM;m--;)
|
---|
[14de469] | 421 | Force.Matrix[MatrixNumber][ Force.RowCounter[MatrixNumber] ][l+m] = Force.Matrix[MatrixNumber][ k ][l+m];
|
---|
| 422 | stored = tmp;
|
---|
| 423 | }
|
---|
| 424 | }
|
---|
| 425 | }
|
---|
| 426 | };
|
---|
| 427 |
|
---|
[390248] | 428 | /** Leaves the Force.Matrix as it is.
|
---|
| 429 | * \param Force ForceMatrix class containing matrix values
|
---|
| 430 | * \param MatrixNumber the index for the ForceMatrix::matrix array
|
---|
| 431 | */
|
---|
| 432 | void CreateSameForce(class MatrixContainer &Force, int MatrixNumber)
|
---|
| 433 | {
|
---|
| 434 | // does nothing
|
---|
| 435 | };
|
---|
| 436 |
|
---|
[14de469] | 437 | /** Adds vectorwise all forces.
|
---|
| 438 | * Results are stored in the matrix ForceMatrix::MatrixCounter of \a Force.
|
---|
| 439 | * \param Force ForceMatrix class containing matrix values
|
---|
| 440 | * \param MatrixNumber the index for the ForceMatrix::matrix array
|
---|
| 441 | */
|
---|
| 442 | void CreateVectorSumForce(class MatrixContainer &Force, int MatrixNumber)
|
---|
| 443 | {
|
---|
[7f3b9d] | 444 | for (int l=Force.ColumnCounter;l--;)
|
---|
[14de469] | 445 | Force.Matrix[MatrixNumber][ Force.RowCounter[MatrixNumber] ][l] = 0.;
|
---|
[390248] | 446 | for (int l=0;l<Force.ColumnCounter;l++) {
|
---|
[7f3b9d] | 447 | for (int k=Force.RowCounter[MatrixNumber];k--;)
|
---|
[14de469] | 448 | Force.Matrix[MatrixNumber][ Force.RowCounter[MatrixNumber] ][l] += Force.Matrix[MatrixNumber][k][l];
|
---|
| 449 | }
|
---|
| 450 | };
|
---|
| 451 |
|
---|
| 452 | /** Writes the standard pyxplot header info.
|
---|
| 453 | * \param keycolumns number of columns of the key
|
---|
| 454 | * \param *key position of key
|
---|
| 455 | * \param *logscale axis for logscale
|
---|
| 456 | * \param *extraline extra set lines if desired
|
---|
| 457 | * \param mxtics small tics at ...
|
---|
| 458 | * \param xtics large tics at ...
|
---|
| 459 | * \param *xlabel label for x axis
|
---|
| 460 | * \param *ylabel label for y axis
|
---|
| 461 | */
|
---|
| 462 | void CreatePlotHeader(ofstream &output, const char *prefix, const int keycolumns, const char *key, const char *logscale, const char *extraline, const int mxtics, const int xtics, const char *xlabel, const char *ylabel)
|
---|
| 463 | {
|
---|
| 464 | //output << "#!/home/heber/build/pyxplot/pyxplot" << endl << endl;
|
---|
| 465 | output << "reset" << endl;
|
---|
| 466 | output << "set keycolumns "<< keycolumns << endl;
|
---|
| 467 | output << "set key " << key << endl;
|
---|
| 468 | output << "set mxtics "<< mxtics << endl;
|
---|
| 469 | output << "set xtics "<< xtics << endl;
|
---|
[fa40b5] | 470 | if (logscale != NULL)
|
---|
[14de469] | 471 | output << "set logscale " << logscale << endl;
|
---|
[fa40b5] | 472 | if (extraline != NULL)
|
---|
[14de469] | 473 | output << extraline << endl;
|
---|
| 474 | output << "set xlabel '" << xlabel << "'" << endl;
|
---|
| 475 | output << "set ylabel '" << ylabel << "'" << endl;
|
---|
| 476 | output << "set terminal eps color" << endl;
|
---|
| 477 | output << "set output '"<< prefix << ".eps'" << endl;
|
---|
| 478 | };
|
---|
| 479 |
|
---|
| 480 | /** Creates the pyxplotfile for energy data.
|
---|
| 481 | * \param Matrix MatrixContainer with matrix values
|
---|
| 482 | * \param KeySet contains bond order
|
---|
| 483 | * \param *dir directory
|
---|
| 484 | * \param *prefix prefix for all filenames (without ending)
|
---|
| 485 | * \param keycolumns number of columns of the key
|
---|
| 486 | * \param *key position of key
|
---|
| 487 | * \param logscale axis for logscale
|
---|
| 488 | * \param mxtics small tics at ...
|
---|
| 489 | * \param xtics large tics at ...
|
---|
| 490 | * \param xlabel label for x axis
|
---|
| 491 | * \param xlabel label for x axis
|
---|
| 492 | * \param *xrange xrange
|
---|
| 493 | * \param *yrange yrange
|
---|
| 494 | * \param *xargument number of column to plot against (x axis)
|
---|
| 495 | * \param uses using string for plot command
|
---|
| 496 | * \param (*CreatePlotLines) function reference that writes a single plot line
|
---|
| 497 | * \return true if file was written successfully
|
---|
| 498 | */
|
---|
| 499 | bool CreatePlotOrder(class MatrixContainer &Matrix, const class KeySetsContainer &KeySet, const char *dir, const char *prefix, const int keycolumns, const char *key, const char *logscale, const char *extraline, const int mxtics, const int xtics, const char *xlabel, const char *ylabel, const char *xrange, const char *yrange, const char *xargument, const char *uses, void (*CreatePlotLines)(ofstream &, class MatrixContainer &, const char *, const char *, const char *))
|
---|
| 500 | {
|
---|
| 501 | stringstream filename;
|
---|
| 502 | ofstream output;
|
---|
| 503 |
|
---|
| 504 | filename << prefix << ".pyx";
|
---|
| 505 | if (!OpenOutputFile(output, dir, filename.str().c_str())) return false;
|
---|
| 506 | CreatePlotHeader(output, prefix, keycolumns, key, logscale, extraline, mxtics, xtics, xlabel, ylabel);
|
---|
| 507 | output << "plot " << xrange << " " << yrange << " \\" << endl;
|
---|
| 508 | CreatePlotLines(output, Matrix, prefix, xargument, uses);
|
---|
| 509 | output.close();
|
---|
| 510 | return true;
|
---|
| 511 | };
|
---|
| 512 |
|
---|
| 513 | /** Writes plot lines for absolute energies.
|
---|
| 514 | * \param output file handler
|
---|
| 515 | * \param Energy MatrixContainer with matrix values
|
---|
| 516 | * \param *prefix prefix of data file
|
---|
| 517 | * \param *xargument number of column to plot against (x axis)
|
---|
| 518 | * \param *uses uses command
|
---|
| 519 | */
|
---|
| 520 | void AbsEnergyPlotLine(ofstream &output, class MatrixContainer &Energy, const char *prefix, const char *xargument, const char *uses)
|
---|
| 521 | {
|
---|
| 522 | stringstream line(Energy.Header);
|
---|
[fb9364] | 523 | string token;
|
---|
[14de469] | 524 |
|
---|
[fb9364] | 525 | getline(line, token, '\t');
|
---|
[390248] | 526 | for (int i=2; i<= Energy.ColumnCounter;i++) {
|
---|
[fb9364] | 527 | getline(line, token, '\t');
|
---|
| 528 | while (token[0] == ' ') // remove leading white spaces
|
---|
| 529 | token.erase(0,1);
|
---|
| 530 | output << "'" << prefix << ".dat' title '" << token << "' using " << xargument << ":(abs($" << i+2 << ")) " << uses;
|
---|
[390248] | 531 | if (i != (Energy.ColumnCounter))
|
---|
[14de469] | 532 | output << ", \\";
|
---|
| 533 | output << endl;
|
---|
| 534 | }
|
---|
| 535 | };
|
---|
| 536 |
|
---|
| 537 | /** Writes plot lines for energies.
|
---|
| 538 | * \param output file handler
|
---|
| 539 | * \param Energy MatrixContainer with matrix values
|
---|
| 540 | * \param *prefix prefix of data file
|
---|
| 541 | * \param *xargument number of column to plot against (x axis)
|
---|
| 542 | * \param *uses uses command
|
---|
| 543 | */
|
---|
| 544 | void EnergyPlotLine(ofstream &output, class MatrixContainer &Energy, const char *prefix, const char *xargument, const char *uses)
|
---|
| 545 | {
|
---|
| 546 | stringstream line(Energy.Header);
|
---|
[fb9364] | 547 | string token;
|
---|
| 548 |
|
---|
| 549 | getline(line, token, '\t');
|
---|
| 550 | for (int i=1; i<= Energy.ColumnCounter;i++) {
|
---|
| 551 | getline(line, token, '\t');
|
---|
| 552 | while (token[0] == ' ') // remove leading white spaces
|
---|
| 553 | token.erase(0,1);
|
---|
| 554 | output << "'" << prefix << ".dat' title '" << token << "' using " << xargument << ":" << i+2 << " " << uses;
|
---|
[390248] | 555 | if (i != (Energy.ColumnCounter))
|
---|
[14de469] | 556 | output << ", \\";
|
---|
| 557 | output << endl;
|
---|
| 558 | }
|
---|
| 559 | };
|
---|
| 560 |
|
---|
| 561 | /** Writes plot lines for absolute force magnitudes.
|
---|
| 562 | * \param output file handler
|
---|
| 563 | * \param Force MatrixContainer with matrix values
|
---|
| 564 | * \param *prefix prefix of data file
|
---|
| 565 | * \param *xargument number of column to plot against (x axis)
|
---|
| 566 | * \param *uses uses command
|
---|
| 567 | */
|
---|
| 568 | void ForceMagnitudePlotLine(ofstream &output, class MatrixContainer &Force, const char *prefix, const char *xargument, const char *uses)
|
---|
| 569 | {
|
---|
| 570 | stringstream line(Force.Header);
|
---|
[fb9364] | 571 | string token;
|
---|
[14de469] | 572 |
|
---|
[fb9364] | 573 | getline(line, token, '\t');
|
---|
| 574 | getline(line, token, '\t');
|
---|
| 575 | getline(line, token, '\t');
|
---|
| 576 | getline(line, token, '\t');
|
---|
| 577 | getline(line, token, '\t');
|
---|
[7f3b9d] | 578 | for (int i=7; i< Force.ColumnCounter;i+=NDIM) {
|
---|
[fb9364] | 579 | getline(line, token, '\t');
|
---|
| 580 | while (token[0] == ' ') // remove leading white spaces
|
---|
| 581 | token.erase(0,1);
|
---|
| 582 | token.erase(token.length(), 1); // kill residual index char (the '0')
|
---|
| 583 | output << "'" << prefix << ".dat' title '" << token << "' using " << xargument << ":(sqrt($" << i+1 << "*$" << i+1 << "+$" << i+2 << "*$" << i+2 << "+$" << i+3 << "*$" << i+3 << ")) " << uses;
|
---|
[14de469] | 584 | if (i != (Force.ColumnCounter-1))
|
---|
| 585 | output << ", \\";
|
---|
| 586 | output << endl;
|
---|
[fb9364] | 587 | getline(line, token, '\t');
|
---|
| 588 | getline(line, token, '\t');
|
---|
[14de469] | 589 | }
|
---|
| 590 | };
|
---|
| 591 |
|
---|
| 592 | /** Writes plot lines for first component of force vector.
|
---|
| 593 | * \param output file handler
|
---|
| 594 | * \param Force MatrixContainer with matrix values
|
---|
| 595 | * \param *prefix prefix of data file
|
---|
| 596 | * \param *xargument number of column to plot against (x axis)
|
---|
| 597 | * \param *uses uses command
|
---|
| 598 | */
|
---|
| 599 | void AbsFirstForceValuePlotLine(ofstream &output, class MatrixContainer &Force, const char *prefix, const char *xargument, const char *uses)
|
---|
| 600 | {
|
---|
| 601 | stringstream line(Force.Header);
|
---|
[fb9364] | 602 | string token;
|
---|
[14de469] | 603 |
|
---|
[fb9364] | 604 | getline(line, token, '\t');
|
---|
| 605 | getline(line, token, '\t');
|
---|
| 606 | getline(line, token, '\t');
|
---|
| 607 | getline(line, token, '\t');
|
---|
| 608 | getline(line, token, '\t');
|
---|
[7f3b9d] | 609 | for (int i=7; i< Force.ColumnCounter;i+=NDIM) {
|
---|
[fb9364] | 610 | getline(line, token, '\t');
|
---|
| 611 | while (token[0] == ' ') // remove leading white spaces
|
---|
| 612 | token.erase(0,1);
|
---|
| 613 | token.erase(token.length(), 1); // kill residual index char (the '0')
|
---|
| 614 | output << "'" << prefix << ".dat' title '" << token << "' using " << xargument << ":(abs($" << i+1 << ")) " << uses;
|
---|
[14de469] | 615 | if (i != (Force.ColumnCounter-1))
|
---|
| 616 | output << ", \\";
|
---|
| 617 | output << endl;
|
---|
[fb9364] | 618 | getline(line, token, '\t');
|
---|
| 619 | getline(line, token, '\t');
|
---|
[14de469] | 620 | }
|
---|
| 621 | };
|
---|
| 622 |
|
---|
| 623 | /** Writes plot lines for force vector as boxes with a fillcolor.
|
---|
| 624 | * \param output file handler
|
---|
| 625 | * \param Force MatrixContainer with matrix values
|
---|
| 626 | * \param *prefix prefix of data file
|
---|
| 627 | * \param *xargument number of column to plot against (x axis)
|
---|
| 628 | * \param *uses uses command
|
---|
| 629 | */
|
---|
| 630 | void BoxesForcePlotLine(ofstream &output, class MatrixContainer &Force, const char *prefix, const char *xargument, const char *uses)
|
---|
| 631 | {
|
---|
| 632 | stringstream line(Force.Header);
|
---|
| 633 | char *fillcolor[5] = {"black", "red", "blue", "green", "cyan"};
|
---|
[fb9364] | 634 | string token;
|
---|
[14de469] | 635 |
|
---|
[fb9364] | 636 | getline(line, token, '\t');
|
---|
| 637 | getline(line, token, '\t');
|
---|
| 638 | getline(line, token, '\t');
|
---|
| 639 | getline(line, token, '\t');
|
---|
| 640 | getline(line, token, '\t');
|
---|
[7f3b9d] | 641 | for (int i=7; i< Force.ColumnCounter;i+=NDIM) {
|
---|
[fb9364] | 642 | getline(line, token, '\t');
|
---|
| 643 | while (token[0] == ' ') // remove leading white spaces
|
---|
| 644 | token.erase(0,1);
|
---|
| 645 | token.erase(token.length(), 1); // kill residual index char (the '0')
|
---|
| 646 | output << "'" << prefix << ".dat' title '" << token << "' using ($" << xargument << "+" << fixed << setprecision(1) << (double)((i-7)/3)*0.2 << "):(sqrt($" << i+1 << "*$" << i+1 << "+$" << i+2 << "*$" << i+2 << "+$" << i+3 << "*$" << i+3 << ")) " << uses << " " << fillcolor[(i-7)/3];
|
---|
[14de469] | 647 | if (i != (Force.ColumnCounter-1))
|
---|
| 648 | output << ", \\";
|
---|
| 649 | output << endl;
|
---|
[fb9364] | 650 | getline(line, token, '\t');
|
---|
| 651 | getline(line, token, '\t');
|
---|
[14de469] | 652 | }
|
---|
| 653 | };
|
---|
| 654 |
|
---|
| 655 | /** Writes plot lines for first force vector component as boxes with a fillcolor.
|
---|
| 656 | * \param output file handler
|
---|
| 657 | * \param Force MatrixContainer with matrix values
|
---|
| 658 | * \param *prefix prefix of data file
|
---|
| 659 | * \param *xargument number of column to plot against (x axis)
|
---|
| 660 | * \param *uses uses command
|
---|
| 661 | */
|
---|
| 662 | void BoxesFirstForceValuePlotLine(ofstream &output, class MatrixContainer &Force, const char *prefix, const char *xargument, const char *uses)
|
---|
| 663 | {
|
---|
| 664 | stringstream line(Force.Header);
|
---|
| 665 | char *fillcolor[5] = {"black", "red", "blue", "green", "cyan"};
|
---|
[fb9364] | 666 | string token;
|
---|
[14de469] | 667 |
|
---|
[fb9364] | 668 | getline(line, token, '\t');
|
---|
| 669 | getline(line, token, '\t');
|
---|
| 670 | getline(line, token, '\t');
|
---|
| 671 | getline(line, token, '\t');
|
---|
| 672 | getline(line, token, '\t');
|
---|
[7f3b9d] | 673 | for (int i=7; i< Force.ColumnCounter;i+=NDIM) {
|
---|
[fb9364] | 674 | getline(line, token, '\t');
|
---|
| 675 | while (token[0] == ' ') // remove leading white spaces
|
---|
| 676 | token.erase(0,1);
|
---|
| 677 | token.erase(token.length(), 1); // kill residual index char (the '0')
|
---|
| 678 | output << "'" << prefix << ".dat' title '" << token << "' using ($" << xargument << "+" << fixed << setprecision(1) << (double)((i-7)/3)*0.2 << "):" << i+1 << " " << uses << " " << fillcolor[(i-7)/3];
|
---|
[14de469] | 679 | if (i != (Force.ColumnCounter-1))
|
---|
| 680 | output << ", \\";
|
---|
| 681 | output << endl;
|
---|
[fb9364] | 682 | getline(line, token, '\t');
|
---|
| 683 | getline(line, token, '\t');
|
---|
[14de469] | 684 | }
|
---|
| 685 | };
|
---|