[97ebf8] | 1 | /*
|
---|
| 2 | * PairCorrelationToSurfaceAction.cpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: May 9, 2010
|
---|
| 5 | * Author: heber
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | #include "Actions/AnalysisAction/PairCorrelationToSurfaceAction.hpp"
|
---|
| 9 | #include "CommandLineParser.hpp"
|
---|
| 10 | #include "analysis_correlation.hpp"
|
---|
| 11 | #include "boundary.hpp"
|
---|
| 12 | #include "element.hpp"
|
---|
| 13 | #include "linkedcell.hpp"
|
---|
| 14 | #include "log.hpp"
|
---|
| 15 | #include "molecule.hpp"
|
---|
| 16 | #include "verbose.hpp"
|
---|
| 17 | #include "World.hpp"
|
---|
| 18 |
|
---|
| 19 | #include <iostream>
|
---|
| 20 | #include <string>
|
---|
| 21 |
|
---|
| 22 | using namespace std;
|
---|
| 23 |
|
---|
| 24 | #include "UIElements/UIFactory.hpp"
|
---|
| 25 | #include "UIElements/Dialog.hpp"
|
---|
| 26 | #include "Actions/MapOfActions.hpp"
|
---|
| 27 |
|
---|
| 28 | const char AnalysisPairCorrelationToSurfaceAction::NAME[] = "pair-correlation-surface";
|
---|
| 29 |
|
---|
| 30 | AnalysisPairCorrelationToSurfaceAction::AnalysisPairCorrelationToSurfaceAction() :
|
---|
| 31 | Action(NAME)
|
---|
| 32 | {}
|
---|
| 33 |
|
---|
| 34 | AnalysisPairCorrelationToSurfaceAction::~AnalysisPairCorrelationToSurfaceAction()
|
---|
| 35 | {}
|
---|
| 36 |
|
---|
| 37 | Action::state_ptr AnalysisPairCorrelationToSurfaceAction::performCall() {
|
---|
| 38 | Dialog *dialog = UIFactory::getInstance().makeDialog();
|
---|
| 39 | double BinStart = 0.;
|
---|
| 40 | double BinWidth = 0.;
|
---|
| 41 | double BinEnd = 0.;
|
---|
| 42 | string outputname;
|
---|
| 43 | string binoutputname;
|
---|
| 44 | bool periodic;
|
---|
| 45 | ofstream output;
|
---|
| 46 | ofstream binoutput;
|
---|
| 47 | int ranges[3] = {1, 1, 1};
|
---|
| 48 | const element *elemental = NULL;
|
---|
| 49 | molecule *Boundary = NULL;
|
---|
| 50 |
|
---|
| 51 | dialog->queryElement("elements", &elemental, MapOfActions::getInstance().getDescription("element"));
|
---|
| 52 | dialog->queryMolecule("molecule-by-id", &Boundary, MapOfActions::getInstance().getDescription("molecule-by-id"));
|
---|
| 53 | dialog->queryDouble("bin-start", &BinStart, MapOfActions::getInstance().getDescription("bin-start"));
|
---|
| 54 | dialog->queryDouble("bin-end", &BinEnd, MapOfActions::getInstance().getDescription("bin-end"));
|
---|
| 55 | dialog->queryString("output-file", &outputname, MapOfActions::getInstance().getDescription("output-file"));
|
---|
| 56 | dialog->queryString("bin-output-file", &binoutputname, MapOfActions::getInstance().getDescription("bin-output-file"));
|
---|
| 57 | dialog->queryBoolean("periodic", &periodic, MapOfActions::getInstance().getDescription("periodic"));
|
---|
| 58 |
|
---|
| 59 | if(dialog->display()) {
|
---|
| 60 | output.open(outputname.c_str());
|
---|
| 61 | binoutput.open(binoutputname.c_str());
|
---|
| 62 | const double radius = 4.;
|
---|
| 63 | double LCWidth = 20.;
|
---|
| 64 | if (BinEnd > 0) {
|
---|
| 65 | if (BinEnd > 2.*radius)
|
---|
| 66 | LCWidth = BinEnd;
|
---|
| 67 | else
|
---|
| 68 | LCWidth = 2.*radius;
|
---|
| 69 | }
|
---|
| 70 | class MoleculeListClass *molecules = World::getInstance().getMolecules();
|
---|
| 71 | class Tesselation *TesselStruct = NULL;
|
---|
| 72 | const LinkedCell *LCList = NULL;
|
---|
| 73 | LCList = new LinkedCell(Boundary, LCWidth);
|
---|
| 74 | FindNonConvexBorder(Boundary, TesselStruct, LCList, radius, NULL);
|
---|
| 75 | CorrelationToSurfaceMap *surfacemap = NULL;
|
---|
| 76 | if (periodic)
|
---|
| 77 | surfacemap = PeriodicCorrelationToSurface( molecules, elemental, TesselStruct, LCList, ranges);
|
---|
| 78 | else
|
---|
| 79 | surfacemap = CorrelationToSurface( molecules, elemental, TesselStruct, LCList);
|
---|
| 80 | OutputCorrelationToSurface(&output, surfacemap);
|
---|
| 81 | // check whether radius was appropriate
|
---|
| 82 | {
|
---|
| 83 | double start; double end;
|
---|
| 84 | GetMinMax( surfacemap, start, end);
|
---|
| 85 | if (LCWidth < end)
|
---|
| 86 | 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);
|
---|
| 87 | }
|
---|
| 88 | BinPairMap *binmap = BinData( surfacemap, BinWidth, BinStart, BinEnd );
|
---|
| 89 | OutputCorrelation ( &binoutput, binmap );
|
---|
| 90 | output.close();
|
---|
| 91 | binoutput.close();
|
---|
| 92 | delete(LCList);
|
---|
| 93 | delete(TesselStruct);
|
---|
| 94 | delete(binmap);
|
---|
| 95 | delete(surfacemap);
|
---|
| 96 | delete dialog;
|
---|
| 97 | return Action::success;
|
---|
| 98 | } else {
|
---|
| 99 | delete dialog;
|
---|
| 100 | return Action::failure;
|
---|
| 101 | }
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | Action::state_ptr AnalysisPairCorrelationToSurfaceAction::performUndo(Action::state_ptr _state) {
|
---|
| 105 | // ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
|
---|
| 106 |
|
---|
| 107 | return Action::failure;
|
---|
| 108 | // string newName = state->mol->getName();
|
---|
| 109 | // state->mol->setName(state->lastName);
|
---|
| 110 | //
|
---|
| 111 | // return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | Action::state_ptr AnalysisPairCorrelationToSurfaceAction::performRedo(Action::state_ptr _state){
|
---|
| 115 | return Action::failure;
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | bool AnalysisPairCorrelationToSurfaceAction::canUndo() {
|
---|
| 119 | return false;
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 | bool AnalysisPairCorrelationToSurfaceAction::shouldUndo() {
|
---|
| 123 | return false;
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 | const string AnalysisPairCorrelationToSurfaceAction::getName() {
|
---|
| 127 | return NAME;
|
---|
| 128 | }
|
---|