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