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