1 | /*
|
---|
2 | * PairCorrelationAction.cpp
|
---|
3 | *
|
---|
4 | * Created on: May 9, 2010
|
---|
5 | * Author: heber
|
---|
6 | */
|
---|
7 |
|
---|
8 | #include "Helpers/MemDebug.hpp"
|
---|
9 |
|
---|
10 | #include "Actions/AnalysisAction/PairCorrelationAction.hpp"
|
---|
11 | #include "analysis_correlation.hpp"
|
---|
12 | #include "boundary.hpp"
|
---|
13 | #include "linkedcell.hpp"
|
---|
14 | #include "log.hpp"
|
---|
15 | #include "element.hpp"
|
---|
16 | #include "molecule.hpp"
|
---|
17 | #include "periodentafel.hpp"
|
---|
18 | #include "vector.hpp"
|
---|
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.;
|
---|
43 | double BinStart = 0.;
|
---|
44 | double BinWidth = 0.;
|
---|
45 | molecule *Boundary = NULL;
|
---|
46 | string outputname;
|
---|
47 | string binoutputname;
|
---|
48 | bool periodic;
|
---|
49 | ofstream output;
|
---|
50 | ofstream binoutput;
|
---|
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 | }
|
---|
65 |
|
---|
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"));
|
---|
73 | dialog->queryDouble("bin-start", &BinStart, MapOfActions::getInstance().getDescription("bin-start"));
|
---|
74 | dialog->queryDouble("bin-width", &BinWidth, MapOfActions::getInstance().getDescription("bin-width"));
|
---|
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());
|
---|
83 | PairCorrelationMap *correlationmap = NULL;
|
---|
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);
|
---|
90 | //OutputCorrelationToSurface(&output, correlationmap);
|
---|
91 | binmap = BinData( correlationmap, BinWidth, BinStart, BinEnd );
|
---|
92 | } else if (type == "P") {
|
---|
93 | cout << "Point to correlate to is " << Point << endl;
|
---|
94 | CorrelationToPointMap *correlationmap = NULL;
|
---|
95 | if (periodic)
|
---|
96 | correlationmap = PeriodicCorrelationToPoint(molecules, elements, &Point, ranges);
|
---|
97 | else
|
---|
98 | correlationmap = CorrelationToPoint(molecules, elements, &Point);
|
---|
99 | //OutputCorrelationToSurface(&output, correlationmap);
|
---|
100 | binmap = BinData( correlationmap, BinWidth, BinStart, BinEnd );
|
---|
101 | } else if (type == "S") {
|
---|
102 | ASSERT(Boundary != NULL, "No molecule specified for SurfaceCorrelation.");
|
---|
103 | const double radius = 4.;
|
---|
104 | double LCWidth = 20.;
|
---|
105 | if (BinEnd > 0) {
|
---|
106 | if (BinEnd > 2.*radius)
|
---|
107 | LCWidth = BinEnd;
|
---|
108 | else
|
---|
109 | LCWidth = 2.*radius;
|
---|
110 | }
|
---|
111 |
|
---|
112 | // get the boundary
|
---|
113 | class Tesselation *TesselStruct = NULL;
|
---|
114 | const LinkedCell *LCList = NULL;
|
---|
115 | // find biggest molecule
|
---|
116 | int counter = molecules->ListOfMolecules.size();
|
---|
117 | bool *Actives = new bool[counter];
|
---|
118 | counter = 0;
|
---|
119 | for (MoleculeList::iterator BigFinder = molecules->ListOfMolecules.begin(); BigFinder != molecules->ListOfMolecules.end(); BigFinder++) {
|
---|
120 | Actives[counter++] = (*BigFinder)->ActiveFlag;
|
---|
121 | (*BigFinder)->ActiveFlag = (*BigFinder == Boundary) ? false : true;
|
---|
122 | }
|
---|
123 | LCList = new LinkedCell(Boundary, LCWidth);
|
---|
124 | FindNonConvexBorder(Boundary, TesselStruct, LCList, radius, NULL);
|
---|
125 | CorrelationToSurfaceMap *surfacemap = NULL;
|
---|
126 | if (periodic)
|
---|
127 | surfacemap = PeriodicCorrelationToSurface( molecules, elements, TesselStruct, LCList, ranges);
|
---|
128 | else
|
---|
129 | surfacemap = CorrelationToSurface( molecules, elements, TesselStruct, LCList);
|
---|
130 | OutputCorrelationToSurface(&output, surfacemap);
|
---|
131 | // check whether radius was appropriate
|
---|
132 | {
|
---|
133 | double start; double end;
|
---|
134 | GetMinMax( surfacemap, start, end);
|
---|
135 | if (LCWidth < end)
|
---|
136 | 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);
|
---|
137 | }
|
---|
138 | binmap = BinData( surfacemap, BinWidth, BinStart, BinEnd );
|
---|
139 | } else
|
---|
140 | return Action::failure;
|
---|
141 | OutputCorrelation ( &binoutput, binmap );
|
---|
142 | output.close();
|
---|
143 | binoutput.close();
|
---|
144 | delete(binmap);
|
---|
145 | delete(correlationmap);
|
---|
146 | delete dialog;
|
---|
147 | return Action::success;
|
---|
148 | } else {
|
---|
149 | delete dialog;
|
---|
150 | return Action::failure;
|
---|
151 | }
|
---|
152 | }
|
---|
153 |
|
---|
154 | Action::state_ptr AnalysisPairCorrelationAction::performUndo(Action::state_ptr _state) {
|
---|
155 | // ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
|
---|
156 |
|
---|
157 | return Action::failure;
|
---|
158 | // string newName = state->mol->getName();
|
---|
159 | // state->mol->setName(state->lastName);
|
---|
160 | //
|
---|
161 | // return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
|
---|
162 | }
|
---|
163 |
|
---|
164 | Action::state_ptr AnalysisPairCorrelationAction::performRedo(Action::state_ptr _state){
|
---|
165 | return Action::failure;
|
---|
166 | }
|
---|
167 |
|
---|
168 | bool AnalysisPairCorrelationAction::canUndo() {
|
---|
169 | return false;
|
---|
170 | }
|
---|
171 |
|
---|
172 | bool AnalysisPairCorrelationAction::shouldUndo() {
|
---|
173 | return false;
|
---|
174 | }
|
---|
175 |
|
---|
176 | const string AnalysisPairCorrelationAction::getName() {
|
---|
177 | return NAME;
|
---|
178 | }
|
---|