[97ebf8] | 1 | /*
|
---|
| 2 | * PairCorrelationAction.cpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: May 9, 2010
|
---|
| 5 | * Author: heber
|
---|
| 6 | */
|
---|
| 7 |
|
---|
[112b09] | 8 | #include "Helpers/MemDebug.hpp"
|
---|
| 9 |
|
---|
[97ebf8] | 10 | #include "Actions/AnalysisAction/PairCorrelationAction.hpp"
|
---|
| 11 | #include "analysis_correlation.hpp"
|
---|
[104524] | 12 | #include "boundary.hpp"
|
---|
| 13 | #include "linkedcell.hpp"
|
---|
[36166d] | 14 | #include "verbose.hpp"
|
---|
[97ebf8] | 15 | #include "log.hpp"
|
---|
| 16 | #include "element.hpp"
|
---|
[104524] | 17 | #include "molecule.hpp"
|
---|
[97ebf8] | 18 | #include "periodentafel.hpp"
|
---|
[104524] | 19 | #include "vector.hpp"
|
---|
[97ebf8] | 20 | #include "World.hpp"
|
---|
| 21 |
|
---|
| 22 | #include <iostream>
|
---|
| 23 | #include <string>
|
---|
| 24 |
|
---|
| 25 | using namespace std;
|
---|
| 26 |
|
---|
| 27 | #include "UIElements/UIFactory.hpp"
|
---|
| 28 | #include "UIElements/Dialog.hpp"
|
---|
| 29 | #include "Actions/MapOfActions.hpp"
|
---|
| 30 |
|
---|
| 31 | const char AnalysisPairCorrelationAction::NAME[] = "pair-correlation";
|
---|
| 32 |
|
---|
| 33 | AnalysisPairCorrelationAction::AnalysisPairCorrelationAction() :
|
---|
| 34 | Action(NAME)
|
---|
| 35 | {}
|
---|
| 36 |
|
---|
| 37 | AnalysisPairCorrelationAction::~AnalysisPairCorrelationAction()
|
---|
| 38 | {}
|
---|
| 39 |
|
---|
| 40 | Action::state_ptr AnalysisPairCorrelationAction::performCall() {
|
---|
| 41 | Dialog *dialog = UIFactory::getInstance().makeDialog();
|
---|
| 42 | int ranges[3] = {1, 1, 1};
|
---|
| 43 | double BinEnd = 0.;
|
---|
[104524] | 44 | double BinStart = 0.;
|
---|
| 45 | double BinWidth = 0.;
|
---|
| 46 | molecule *Boundary = NULL;
|
---|
[97ebf8] | 47 | string outputname;
|
---|
| 48 | string binoutputname;
|
---|
| 49 | bool periodic;
|
---|
| 50 | ofstream output;
|
---|
| 51 | ofstream binoutput;
|
---|
[104524] | 52 | std::vector< element *> elements;
|
---|
| 53 | string type;
|
---|
| 54 | Vector Point;
|
---|
| 55 | BinPairMap *binmap = NULL;
|
---|
| 56 | MoleculeListClass *molecules = World::getInstance().getMolecules();
|
---|
| 57 |
|
---|
| 58 | // first dialog: Obtain which type of correlation
|
---|
| 59 | dialog->queryString(NAME, &type, MapOfActions::getInstance().getDescription(NAME));
|
---|
| 60 | if(dialog->display()) {
|
---|
| 61 | delete dialog;
|
---|
| 62 | } else {
|
---|
| 63 | delete dialog;
|
---|
| 64 | return Action::failure;
|
---|
| 65 | }
|
---|
[97ebf8] | 66 |
|
---|
[104524] | 67 | // second dialog: Obtain parameters specific to this type
|
---|
| 68 | dialog = UIFactory::getInstance().makeDialog();
|
---|
| 69 | if (type == "P")
|
---|
[84c494] | 70 | dialog->queryVector("position", &Point, false, MapOfActions::getInstance().getDescription("position"));
|
---|
[104524] | 71 | if (type == "S")
|
---|
| 72 | dialog->queryMolecule("molecule-by-id", &Boundary, MapOfActions::getInstance().getDescription("molecule-by-id"));
|
---|
| 73 | dialog->queryElement("elements", &elements, MapOfActions::getInstance().getDescription("elements"));
|
---|
[97ebf8] | 74 | dialog->queryDouble("bin-start", &BinStart, MapOfActions::getInstance().getDescription("bin-start"));
|
---|
[104524] | 75 | dialog->queryDouble("bin-width", &BinWidth, MapOfActions::getInstance().getDescription("bin-width"));
|
---|
[97ebf8] | 76 | dialog->queryDouble("bin-end", &BinEnd, MapOfActions::getInstance().getDescription("bin-end"));
|
---|
| 77 | dialog->queryString("output-file", &outputname, MapOfActions::getInstance().getDescription("output-file"));
|
---|
| 78 | dialog->queryString("bin-output-file", &binoutputname, MapOfActions::getInstance().getDescription("bin-output-file"));
|
---|
| 79 | dialog->queryBoolean("periodic", &periodic, MapOfActions::getInstance().getDescription("periodic"));
|
---|
| 80 |
|
---|
| 81 | if(dialog->display()) {
|
---|
| 82 | output.open(outputname.c_str());
|
---|
| 83 | binoutput.open(binoutputname.c_str());
|
---|
[104524] | 84 | if (type == "E") {
|
---|
| 85 | PairCorrelationMap *correlationmap = NULL;
|
---|
| 86 | if (periodic)
|
---|
| 87 | correlationmap = PeriodicPairCorrelation(World::getInstance().getMolecules(), elements, ranges);
|
---|
| 88 | else
|
---|
| 89 | correlationmap = PairCorrelation(World::getInstance().getMolecules(), elements);
|
---|
[edb454] | 90 | OutputPairCorrelation(&output, correlationmap);
|
---|
[104524] | 91 | binmap = BinData( correlationmap, BinWidth, BinStart, BinEnd );
|
---|
[edb454] | 92 | OutputCorrelation ( &binoutput, binmap );
|
---|
| 93 | delete(binmap);
|
---|
| 94 | delete(correlationmap);
|
---|
[104524] | 95 | } else if (type == "P") {
|
---|
| 96 | cout << "Point to correlate to is " << Point << endl;
|
---|
| 97 | CorrelationToPointMap *correlationmap = NULL;
|
---|
| 98 | if (periodic)
|
---|
| 99 | correlationmap = PeriodicCorrelationToPoint(molecules, elements, &Point, ranges);
|
---|
| 100 | else
|
---|
| 101 | correlationmap = CorrelationToPoint(molecules, elements, &Point);
|
---|
[edb454] | 102 | OutputCorrelationToPoint(&output, correlationmap);
|
---|
[104524] | 103 | binmap = BinData( correlationmap, BinWidth, BinStart, BinEnd );
|
---|
[edb454] | 104 | OutputCorrelation ( &binoutput, binmap );
|
---|
| 105 | delete(binmap);
|
---|
| 106 | delete(correlationmap);
|
---|
[104524] | 107 | } else if (type == "S") {
|
---|
| 108 | ASSERT(Boundary != NULL, "No molecule specified for SurfaceCorrelation.");
|
---|
| 109 | const double radius = 4.;
|
---|
| 110 | double LCWidth = 20.;
|
---|
| 111 | if (BinEnd > 0) {
|
---|
| 112 | if (BinEnd > 2.*radius)
|
---|
[edb454] | 113 | LCWidth = BinEnd;
|
---|
[104524] | 114 | else
|
---|
| 115 | LCWidth = 2.*radius;
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | // get the boundary
|
---|
| 119 | class Tesselation *TesselStruct = NULL;
|
---|
| 120 | const LinkedCell *LCList = NULL;
|
---|
| 121 | // find biggest molecule
|
---|
| 122 | int counter = molecules->ListOfMolecules.size();
|
---|
| 123 | bool *Actives = new bool[counter];
|
---|
| 124 | counter = 0;
|
---|
| 125 | for (MoleculeList::iterator BigFinder = molecules->ListOfMolecules.begin(); BigFinder != molecules->ListOfMolecules.end(); BigFinder++) {
|
---|
| 126 | Actives[counter++] = (*BigFinder)->ActiveFlag;
|
---|
| 127 | (*BigFinder)->ActiveFlag = (*BigFinder == Boundary) ? false : true;
|
---|
| 128 | }
|
---|
| 129 | LCList = new LinkedCell(Boundary, LCWidth);
|
---|
| 130 | FindNonConvexBorder(Boundary, TesselStruct, LCList, radius, NULL);
|
---|
| 131 | CorrelationToSurfaceMap *surfacemap = NULL;
|
---|
| 132 | if (periodic)
|
---|
| 133 | surfacemap = PeriodicCorrelationToSurface( molecules, elements, TesselStruct, LCList, ranges);
|
---|
| 134 | else
|
---|
| 135 | surfacemap = CorrelationToSurface( molecules, elements, TesselStruct, LCList);
|
---|
[2a374e] | 136 | delete LCList;
|
---|
[104524] | 137 | OutputCorrelationToSurface(&output, surfacemap);
|
---|
[2a374e] | 138 | // re-set ActiveFlag
|
---|
| 139 | counter = 0;
|
---|
| 140 | for (MoleculeList::iterator BigFinder = molecules->ListOfMolecules.begin(); BigFinder != molecules->ListOfMolecules.end(); BigFinder++) {
|
---|
| 141 | (*BigFinder)->ActiveFlag = Actives[counter++];
|
---|
| 142 | }
|
---|
| 143 | delete[] Actives;
|
---|
[104524] | 144 | // check whether radius was appropriate
|
---|
| 145 | {
|
---|
| 146 | double start; double end;
|
---|
| 147 | GetMinMax( surfacemap, start, end);
|
---|
| 148 | if (LCWidth < end)
|
---|
| 149 | DoeLog(1) && (eLog()<< Verbose(1) << "Linked Cell width is smaller than the found range of values! Bins can only be correct up to: " << radius << "." << endl);
|
---|
| 150 | }
|
---|
| 151 | binmap = BinData( surfacemap, BinWidth, BinStart, BinEnd );
|
---|
[edb454] | 152 | OutputCorrelation ( &binoutput, binmap );
|
---|
[2a374e] | 153 | delete TesselStruct; // surfacemap contains refs to triangles! delete here, not earlier!
|
---|
[edb454] | 154 | delete(binmap);
|
---|
| 155 | delete(surfacemap);
|
---|
| 156 | } else {
|
---|
[104524] | 157 | return Action::failure;
|
---|
[edb454] | 158 | }
|
---|
[97ebf8] | 159 | output.close();
|
---|
| 160 | binoutput.close();
|
---|
| 161 | delete dialog;
|
---|
| 162 | return Action::success;
|
---|
| 163 | } else {
|
---|
| 164 | delete dialog;
|
---|
| 165 | return Action::failure;
|
---|
| 166 | }
|
---|
| 167 | }
|
---|
| 168 |
|
---|
| 169 | Action::state_ptr AnalysisPairCorrelationAction::performUndo(Action::state_ptr _state) {
|
---|
| 170 | // ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
|
---|
| 171 |
|
---|
| 172 | return Action::failure;
|
---|
| 173 | // string newName = state->mol->getName();
|
---|
| 174 | // state->mol->setName(state->lastName);
|
---|
| 175 | //
|
---|
| 176 | // return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
|
---|
| 177 | }
|
---|
| 178 |
|
---|
| 179 | Action::state_ptr AnalysisPairCorrelationAction::performRedo(Action::state_ptr _state){
|
---|
| 180 | return Action::failure;
|
---|
| 181 | }
|
---|
| 182 |
|
---|
| 183 | bool AnalysisPairCorrelationAction::canUndo() {
|
---|
| 184 | return false;
|
---|
| 185 | }
|
---|
| 186 |
|
---|
| 187 | bool AnalysisPairCorrelationAction::shouldUndo() {
|
---|
| 188 | return false;
|
---|
| 189 | }
|
---|
| 190 |
|
---|
| 191 | const string AnalysisPairCorrelationAction::getName() {
|
---|
| 192 | return NAME;
|
---|
| 193 | }
|
---|