1 /* 2 * Copyright (C) 2010 Thorsten Liebig (Thorsten.Liebig@gmx.de) 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 /*! 19 \class AdrOp 20 \author Thorsten Liebig 21 \version $Revision: 1.10 $ 22 \date $Date: 2006/10/29 18:50:44 $ 23 */ 24 25 #ifndef ADROP_H 26 #define ADROP_H 27 28 #include <iostream> 29 #include <stdio.h> 30 #include <stdlib.h> 31 #include <vector> 32 #include "ExpenseLog.h" 33 #include "ErrorMsg.h" 34 35 class AdrOp 36 { 37 public: 38 ///Constructor, define dimension/size here 39 AdrOp(unsigned int muiImax, unsigned int muiYmax, unsigned int muiKmax=0, unsigned int muiLmax=0); 40 ///Copy-Constructor 41 AdrOp(AdrOp* origOP); 42 ///Deconstructor 43 virtual ~AdrOp(); 44 ///Set the current n-dim position, get 1-dim array position as return value 45 /*!A position has to be set or all other methodes will case error! \n The methode will exit with error message if invalid position is set! \sa ErrorMsg */ 46 unsigned int SetPos(unsigned int muiIpos, unsigned int muiJpos, unsigned int muiKpos=0, unsigned int muiLpos=0); 47 48 bool SetPosChecked(unsigned int muiIpos, unsigned int muiJpos, unsigned int muiKpos=0, unsigned int muiLpos=0); 49 50 void SetGrid(double *gridI,double *gridJ,double *gridK=NULL,double *gridL=NULL); SetGridDelta(double delta)51 void SetGridDelta(double delta) {this->dDeltaUnit=delta;}; 52 53 bool CheckPos(unsigned int muiIpos, unsigned int muiJpos, unsigned int muiKpos=0, unsigned int muiLpos=0); 54 bool CheckRelativePos(int muiIrel=0,int muiJrel=0,int muiKrel=0, int muiLrel=0); 55 ///will return current 1-dim position, in addition to a relative n-dim shift 56 /*!In case of crossing the boundaries, activate reflection or an error will be invoked\sa SetReflection2Node \sa SetReflection2Cell \sa SetReflectionOff */ 57 unsigned int GetPos(int muiIrel=0,int muiJrel=0,int muiKrel=0, int muiLrel=0); 58 59 double GetNodeVolume(unsigned int uiNode); 60 61 double GetIndexWidth(int ny, int index); 62 double GetIndexCoord(int ny, int index); 63 ///Get the gird delta at the given index of direction ny. (if index<0 return negative value as index=0 would give, if index>=max-1 returns negative value as index=max-2 would give) 64 double GetIndexDelta(int ny, int index); 65 66 // double GetCellVolume(unsigned int uiCell); 67 68 unsigned int GetPosFromNode(int ny, unsigned int uiNode); 69 ///Set a shift in ny direction (e.g. 0 for i-direction) 70 /*!Shift set by this methode will be ignored by methode GetPos*/ 71 unsigned int Shift(int ny, int step); 72 ///Set a checked shift in ny direction (e.g. 0 for i-direction) 73 /*!Shift set by this methode will be ignored by methode GetPos*/ 74 bool CheckShift(int ny, int step); 75 ///Returns the current 1-dim position including shift by methode "Shift" + additional (transitory) shift 76 unsigned int GetShiftedPos(int ny=-1, int step=0); 77 ///Reset shift set by "Shift"-methode 78 void ResetShift(); 79 ///Iterates through AdrOp; --- obsolete --- 80 unsigned int Iterate(int jump=1); 81 ///Retruns size of array 82 unsigned int GetSize(); 83 ///Set mode to reflect by node 84 /*!1D-example (6 nodes): \image html node_reflect.PNG order: 0,1,2,3,4,5,4,3,...*/ 85 void SetReflection2Node(); 86 ///Set mode to reflect by cell 87 /*!1D-example (5 cells): \image html cell_reflect.PNG order: 0,1,2,3,4,4,3,...*/ 88 void SetReflection2Cell(); 89 ///Deactivate reflection (default) 90 void SetReflectionOff(); 91 ///Add a cell adress operator (dimensions: i-1 j-1 k-1 l-1) 92 /*!\image html cells_nodes.png */ 93 AdrOp* AddCellAdrOp(); 94 GetCellAdrOp()95 AdrOp* GetCellAdrOp() {return clCellAdr;}; 96 97 ///Deconstructed cell adress operator if no longer needed 98 AdrOp* DeleteCellAdrOp(); 99 ///Shift cell in ny dircetion; cell reflection is active 100 unsigned int ShiftCell(int ny, int step); 101 ///Shift cell in ny dircetion; cell reflection is active; return check 102 bool ShiftCellCheck(int ny, int step); 103 ///Reset cell shift 104 void ResetCellShift(); 105 ///Get current cell position from cell adress operator 106 unsigned int GetCellPos(bool incShift=true); 107 ///Get cell position from cell adress operator 108 unsigned int GetCellPos(int i, int j, int k=0); 109 //get volume of cell; incl shift 110 double GetShiftCellVolume(int ny, int step); 111 112 SetDebugOn()113 void SetDebugOn() {this->bDebug=true;}; SetDebugOff()114 void SetDebugOff() {this->bDebug=false;}; 115 116 protected: 117 AdrOp *clCellAdr; 118 unsigned int uiDimension; 119 unsigned int uiSize; 120 unsigned int uiImax,uiJmax,uiKmax,uiLmax; 121 unsigned int uiIpos, uiJpos, uiKpos, uiLpos; 122 double *dGrid[4]; 123 double dDeltaUnit; 124 int iIshift, iJshift, iKshift; 125 int iCellShift[3]; 126 unsigned int i,j,k,l; 127 bool reflect; 128 unsigned int uiTypeOffset; 129 130 bool bPosSet; 131 bool bDebug; 132 ErrorMsg *error; 133 }; 134 135 136 class deltaAdrOp 137 { 138 public: 139 deltaAdrOp(unsigned int max=0); 140 virtual ~deltaAdrOp(); 141 void SetMax(unsigned int max); 142 unsigned int GetAdr(int pos); 143 144 protected: 145 unsigned int uiMax; 146 }; 147 148 149 #endif // ADROP_H 150