| 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 "verbose.hpp" | 
|---|
| 15 | #include "log.hpp" | 
|---|
| 16 | #include "element.hpp" | 
|---|
| 17 | #include "molecule.hpp" | 
|---|
| 18 | #include "periodentafel.hpp" | 
|---|
| 19 | #include "vector.hpp" | 
|---|
| 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 "UIElements/ValueStorage.hpp" | 
|---|
| 30 |  | 
|---|
| 31 | const char AnalysisPairCorrelationAction::NAME[] = "pair-correlation"; | 
|---|
| 32 |  | 
|---|
| 33 | AnalysisPairCorrelationAction::AnalysisPairCorrelationAction() : | 
|---|
| 34 | Action(NAME) | 
|---|
| 35 | {} | 
|---|
| 36 |  | 
|---|
| 37 | AnalysisPairCorrelationAction::~AnalysisPairCorrelationAction() | 
|---|
| 38 | {} | 
|---|
| 39 |  | 
|---|
| 40 | Dialog* AnalysisPairCorrelationAction::createDialog() { | 
|---|
| 41 | Dialog *dialog = UIFactory::getInstance().makeDialog(); | 
|---|
| 42 |  | 
|---|
| 43 | dialog->queryElement("elements", ValueStorage::getInstance().getDescription("elements")); | 
|---|
| 44 | dialog->queryDouble("bin-start", ValueStorage::getInstance().getDescription("bin-start")); | 
|---|
| 45 | dialog->queryDouble("bin-width", ValueStorage::getInstance().getDescription("bin-width")); | 
|---|
| 46 | dialog->queryDouble("bin-end", ValueStorage::getInstance().getDescription("bin-end")); | 
|---|
| 47 | dialog->queryString("output-file", ValueStorage::getInstance().getDescription("output-file")); | 
|---|
| 48 | dialog->queryString("bin-output-file", ValueStorage::getInstance().getDescription("bin-output-file")); | 
|---|
| 49 | dialog->queryBoolean("periodic", ValueStorage::getInstance().getDescription("periodic")); | 
|---|
| 50 |  | 
|---|
| 51 | return dialog; | 
|---|
| 52 | } | 
|---|
| 53 |  | 
|---|
| 54 | Action::state_ptr AnalysisPairCorrelationAction::performCall() { | 
|---|
| 55 | int ranges[3] = {1, 1, 1}; | 
|---|
| 56 | double BinEnd = 0.; | 
|---|
| 57 | double BinStart = 0.; | 
|---|
| 58 | double BinWidth = 0.; | 
|---|
| 59 | molecule *Boundary = NULL; | 
|---|
| 60 | string outputname; | 
|---|
| 61 | string binoutputname; | 
|---|
| 62 | bool periodic; | 
|---|
| 63 | ofstream output; | 
|---|
| 64 | ofstream binoutput; | 
|---|
| 65 | std::vector< element *> elements; | 
|---|
| 66 | string type; | 
|---|
| 67 | Vector Point; | 
|---|
| 68 | BinPairMap *binmap = NULL; | 
|---|
| 69 | MoleculeListClass *molecules = World::getInstance().getMolecules(); | 
|---|
| 70 |  | 
|---|
| 71 | // obtain information | 
|---|
| 72 | ValueStorage::getInstance().queryCurrentValue("elements", elements); | 
|---|
| 73 | ValueStorage::getInstance().queryCurrentValue("bin-start", BinStart); | 
|---|
| 74 | ValueStorage::getInstance().queryCurrentValue("bin-width", BinWidth); | 
|---|
| 75 | ValueStorage::getInstance().queryCurrentValue("bin-end", BinEnd); | 
|---|
| 76 | ValueStorage::getInstance().queryCurrentValue("output-file", outputname); | 
|---|
| 77 | ValueStorage::getInstance().queryCurrentValue("bin-output-file", binoutputname); | 
|---|
| 78 | ValueStorage::getInstance().queryCurrentValue("periodic", periodic); | 
|---|
| 79 |  | 
|---|
| 80 | // execute action | 
|---|
| 81 | output.open(outputname.c_str()); | 
|---|
| 82 | binoutput.open(binoutputname.c_str()); | 
|---|
| 83 | PairCorrelationMap *correlationmap = NULL; | 
|---|
| 84 | if (periodic) | 
|---|
| 85 | correlationmap = PeriodicPairCorrelation(World::getInstance().getMolecules(), elements, ranges); | 
|---|
| 86 | else | 
|---|
| 87 | correlationmap = PairCorrelation(World::getInstance().getMolecules(), elements); | 
|---|
| 88 | OutputPairCorrelation(&output, correlationmap); | 
|---|
| 89 | binmap = BinData( correlationmap, BinWidth, BinStart, BinEnd ); | 
|---|
| 90 | OutputCorrelation ( &binoutput, binmap ); | 
|---|
| 91 | delete(binmap); | 
|---|
| 92 | delete(correlationmap); | 
|---|
| 93 | output.close(); | 
|---|
| 94 | binoutput.close(); | 
|---|
| 95 | return Action::success; | 
|---|
| 96 | } | 
|---|
| 97 |  | 
|---|
| 98 | Action::state_ptr AnalysisPairCorrelationAction::performUndo(Action::state_ptr _state) { | 
|---|
| 99 | return Action::success; | 
|---|
| 100 | } | 
|---|
| 101 |  | 
|---|
| 102 | Action::state_ptr AnalysisPairCorrelationAction::performRedo(Action::state_ptr _state){ | 
|---|
| 103 | return Action::success; | 
|---|
| 104 | } | 
|---|
| 105 |  | 
|---|
| 106 | bool AnalysisPairCorrelationAction::canUndo() { | 
|---|
| 107 | return true; | 
|---|
| 108 | } | 
|---|
| 109 |  | 
|---|
| 110 | bool AnalysisPairCorrelationAction::shouldUndo() { | 
|---|
| 111 | return true; | 
|---|
| 112 | } | 
|---|
| 113 |  | 
|---|
| 114 | const string AnalysisPairCorrelationAction::getName() { | 
|---|
| 115 | return NAME; | 
|---|
| 116 | } | 
|---|