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