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