delphi_cb
 All Classes Namespaces Files Functions Variables Macros
solver_fastSOR.h
1 #ifndef SOLVER_FASTSOR_H
2 #define SOLVER_FASTSOR_H
3 
4 #include <iostream>
5 #include <iomanip>
6 #include <fstream>
7 #include <string>
8 #include <memory>
9 #include <cmath> // std::abs
10 //#include <deque>
11 
12 #include "../interface/interface_abstractmodule.h"
13 #include "../misc/misc_timer.h"
14 #include "../delphi/delphi_constants.h"
15 #include "../io/io.h"
16 #include "solver_exceptions.h"
17 
18 using namespace std;
19 
20 class CDelphiFastSOR:virtual public IAbstractModule
21 {
22  private: // In DATA CONTAINER
23  shared_ptr<CTimer> pTimer;
24 
25  /*********************************************************************************************
26  * *
27  * references to the variables obtained from the data container *
28  * *
29  ********************************************************************************************/
30 
31  //++++++++++++++ const references to read-only variables from data container +++++++++++++++//
32  //----- uniform parameters
33  const string& strBioModel; // biomodel
34  const string& strNumSolver; // solver
35  //----- set by Statements
36  const delphi_integer& iAtomNum; // natom
37  const bool& bCrgInterplateType; // isph true-spherical false-cubic
38  const bool& bSpectralRadius; // iuspec
39  const delphi_real& fSpectralRadius; // uspec
40  const vector<bool>& rgbPeriodicBndy; // iper
41  const int& iNonIterateNum; // nnit
42  const delphi_real& fIonRadius; // exrad
43  const bool& bFixedRelaxParam; // icheb
44  const bool& bAutoConverge; // iautocon
45  const delphi_real& fGridConverge; // gten
46  const delphi_real& fRmsc; // res1
47  const delphi_real& fMaxc; // res2
48  const bool& bLogGraph; // igraph
49  const bool& bLogPotential; // ipoten
50  const bool& bManualRelaxParam; // imanual
51  //----- io file names
52  const string& strEpsFile; // epsnam
53  const string& strPhiiFile; // phiinam
54  //----- set by functions
55  const bool& bDbOut; // idbwrt
56  const bool& bGridCrgOut; // iwgcrg
57  const bool& bEpsOut; // epswrt
58  const bool& bIonsEng; // logions
59  //----- set by DelPhi
60  const delphi_real& fEpsOut; // epsout
61  const delphi_real& fDebyeLength; // deblen
62  const delphi_real& fScale; // scale
63  const delphi_real& fEpsIn; // epsin
64  const delphi_real& fIonStrength; // rionst
65  const int& iDirectEpsMap; // idirectalg
66  const delphi_real& fEPKT; // epkt
67  const SGrid<delphi_real>& fgBoxCenter; // oldmid
68  const SGrid<delphi_real>& fgPotentialDrop; // vdrop
69  const delphi_real& fTaylorCoeff2; // chi2
70  const delphi_real& fTaylorCoeff3; // chi3
71  const delphi_real& fTaylorCoeff4; // chi4
72  const delphi_real& fTaylorCoeff5; // chi5
73  //----- set by IO class
74  const delphi_integer& iMediaNum; // nmedia
75  const delphi_integer& iObjectNum; // nobject
76  const vector<delphi_real>& prgfMediaEps; // medeps(0:nmediamax)
77  //----- set by Surface class
78  const delphi_integer& iCrgGridNum; // nqass
79  const delphi_real& fMinusCrg; // qmin
80  const delphi_real& fPlusCrg; // qplus
81  const SGrid<delphi_real>& fgPlusCrgCenter; // cqplus
82  const SGrid<delphi_real>& fgMinusCrgCenter; // cqmin
83  const delphi_integer& iBndyGridNum; // ibnum
84  const vector< SGrid<delphi_integer> >& prgigBndyGrid; // ibgrd(ibnum)
85  const vector< SGrid<delphi_integer> >& prgigEpsMap; // iepsmp(igrid,igrid,igrid)
86  const vector<bool>& prgbDielecMap; // idebmap(igrid,igrid,igrid)
87  const delphi_integer& iCrg2GridNum; // nqgrd
88  const vector< SGridValue<delphi_real> >& prggvCrg2Grid; // chrgv2(nqgrd)
89  const vector<delphi_integer>& prgiCrg2GridMap; // nqgrdtonqass(nqgrd)
90  const vector<delphi_real>& prgfAtomEps; // atmeps(nqass)
91  const vector< SGridValue<delphi_real> >& prggvCrgedAtom;// atmcrg(nqass)
92  //const vector< SGrid<delphi_real> >& prgfgSurfCrgA; // scspos(ibnum)
93 
94  //++++++++++++++++ reference to read-and-write variables from data container +++++++++++++++//
95  delphi_integer& iGrid; // igrid (modified in setFocusBndy)
96  int& iBndyType; // ibctyp (modified in setBndy)
97  delphi_real& fNetCrg; // qnet (modified in setCoulombBndy and setDipolarBndy)
98  int& iLinIterateNum; // nlit
99  int& iIterateInterval; // icon1
100  int& iConvergeFract; // icon2
101  delphi_real& fRelaxParam; // relpar
102  //----- out into data container
103  delphi_integer& iDielecBndyOdd; // icount2b
104  delphi_integer& iCrgedGridSum; // icount1b
105  vector<delphi_real>& prgfGridCrg; // gchrg(icount1b)
106  vector< SGrid<delphi_integer> >& prgigGridCrgPose; // gchrgp(icount1b)
107  delphi_integer& iCrgBndyGridNum; // ibc
108  vector< SDoubleGridValue >& prgdgvCrgBndyGrid; // cgbp(ibc)
109  vector<delphi_real>& prgfPhiMap; // phimap(igrid,igrid,igrid)
110  /*********************************************************************************************
111  * *
112  * variables defined in this class *
113  * *
114  ********************************************************************************************/
115 
116  //+++++++++++++++++++++++++++++++++ const class variables ++++++++++++++++++++++++++++++++++//
117  const delphi_integer iTotalGridNum; // ngp=igrid*igrid*igrid+1
118  const delphi_integer iHalfGridNum; // nhgp=ngp/2
119  const delphi_integer iBndyDielecNum; // nsp=2*(ibnum+1)
120  const delphi_real fDebFct; // debfct
121  const delphi_real fEpsDiff; // difeps
122  const delphi_real fSixEps; // sixeps
123  const delphi_integer iEpsDim; // epsdim
124  const int nxran; // nxran
125  const int nyran; // nyran
126 
127  //+++++++++++++++++++++++++++++ local variables in this class ++++++++++++++++++++++++++++++//
128  //------ Using either std:vector or std:deque we can construct idpos, db etc. w/o realignment
129  delphi_integer iDielecBndyEven; // icount2a
130  vector<delphi_integer> prgiBndyDielecIndex; // idpos(nsp)
131  vector< vector<delphi_real> > prgfBndyDielec; // db(6,nsp) <--> prgfBndyDielec[iBndyDielecNum][6]
132  vector<delphi_real> prgfSaltMap1; // sf1(nhgp)
133  vector<delphi_real> prgfSaltMap2; // sf2(nhgp)
134 
135  delphi_integer iCrgedGridEven; // icount1a
136  vector<delphi_integer> prgiCrgPose; // iqpos(icount1b)
137  vector<delphi_real> prgfCrgValA; // qval(icount1b)
138  vector<delphi_real> prgfCrgValG; // gval(icount1b)
139 
140  delphi_real fSpec; // spec
141  vector<delphi_integer> ibndx,ibndy,ibndz;
142  delphi_integer idif1x,idif2x,inc1xa,inc1xb,inc2xa,inc2xb;
143  delphi_integer idif1y,idif2y,inc1ya,inc1yb,inc2ya,inc2yb;
144  delphi_integer idif1z,idif2z,inc1za,inc1zb,inc2za,inc2zb;
145  vector<delphi_integer> sta1,sta2,fi1,fi2;
146  delphi_integer lat1,lat2,long1,long2;
147  vector<delphi_real> phimap1,phimap2;
148  vector<delphi_real> bndx1,bndx2,bndx3,bndx4;
149  vector<delphi_real> qmap1,qmap2;
150  vector<delphi_real> debmap1,debmap2;
151  delphi_real om1,om2,om3,om4,sixth;
152 
153 #ifdef MCCE
154  SMCCE* pmcce;
155 #endif
156 
157  void setDielecBndySaltMap(); // subroutine mkdbsf()
158 
159  void setCrg(); // subroutine setcrg()
160 
161  void setBndy(); // subroutine setbc()
162 
163  //+++++ choices of boundary conditions
164  bool isDipolarBndy(delphi_real *** phimap); // ibctyp = 2
165 
166  bool isFocusBndy(delphi_real *** phimap); // ibctyp = 3
167 
168  bool isCoulombBndy(delphi_real *** phimap); // ibctyp = 4
169 
170  void initOddEvenItr(const int& forWhom);
171 
172  void itrOddPoints(const int& forWhom);
173 
174  void itrEvenPoints(const int& forWhom);
175 
176  void conplt(const vector<delphi_real>& array,const string& title,const int& iclr,const int& iscl,const int& imk,
177  const int& iplt,const char symb,const int& ixmin,const int& ixmax,vector<string>& iplot,delphi_real& ymin,delphi_real& ymax);
178 
179  void postItr(const vector<delphi_real>& rmaxl,const vector<delphi_real>& rmsl);
180 
181  delphi_real calculateRelaxFactor(); // subroutine relfac()
182 
183  void itit(); // subroutine itit()
184 
185  void nitit(const delphi_real& qfact); // subroutine nitit(qfact)
186 
187  public:
188  CDelphiFastSOR(shared_ptr<IDataContainer> pdc,shared_ptr<CTimer> pt):
189  /*********************************************************************************************
190  * *
191  * references to the variables obtained from the data container *
192  * *
193  ********************************************************************************************/
194 
195  //++++++++++++++ const references to read-only variables from data container +++++++++++++++//
196  IAbstractModule(pdc),
197  pTimer(pt),
198  //----- uniform parameters
199  strBioModel(pdc->getKey_constRef<string>("biomodel")),
200  strNumSolver(pdc->getKey_constRef<string>("solver")),
201  //----- set by Statments
202  iAtomNum(pdc->getKey_constRef<delphi_integer>("natom")),
203  bCrgInterplateType(pdc->getKey_constRef<bool>("isph")),
204  bSpectralRadius(pdc->getKey_constRef<bool>("iuspec")),
205  fSpectralRadius(pdc->getKey_constRef<delphi_real>("uspec")),
206  rgbPeriodicBndy(pdc->getKey_constRef< vector<bool> >("iper")),
207  iNonIterateNum(pdc->getKey_constRef<int>("nnit")),
208  fIonRadius(pdc->getKey_constRef<delphi_real>("exrad")),
209  bFixedRelaxParam(pdc->getKey_constRef<bool>("icheb")),
210  bAutoConverge(pdc->getKey_constRef<bool>("iautocon")),
211  fGridConverge(pdc->getKey_constRef<delphi_real>("gten")),
212  fRmsc(pdc->getKey_constRef<delphi_real>("res1")),
213  fMaxc(pdc->getKey_constRef<delphi_real>("res2")),
214  bLogGraph(pdc->getKey_constRef<bool>("igraph")),
215  bLogPotential(pdc->getKey_constRef<bool>("ipoten")),
216  bManualRelaxParam(pdc->getKey_constRef<bool>("imanual")),
217  //----- io file names
218  strEpsFile(pdc->getKey_constRef<string>("epsnam")),
219  strPhiiFile(pdc->getKey_constRef<string>("phiinam")),
220  //----- set by functions
221  bDbOut(pdc->getKey_constRef<bool>("idbwrt")),
222  bGridCrgOut(pdc->getKey_constRef<bool>("iwgcrg")),
223  bEpsOut(pdc->getKey_constRef<bool>("epswrt")),
224  bIonsEng(pdc->getKey_constRef<bool>("logions")),
225  //----- set by DelPhi
226  fEpsOut(pdc->getKey_constRef<delphi_real>("epsout")),
227  fDebyeLength(pdc->getKey_constRef<delphi_real>("deblen")),
228  fScale(pdc->getKey_constRef<delphi_real>("scale")),
229  fEpsIn(pdc->getKey_constRef<delphi_real>("epsin")),
230  fIonStrength(pdc->getKey_constRef<delphi_real>("rionst")),
231  iDirectEpsMap(pdc->getKey_constRef<int>("idirectalg")),
232  fEPKT(pdc->getKey_constRef<delphi_real>("epkt")),
233  fgBoxCenter(pdc->getKey_constRef< SGrid<delphi_real> >("oldmid")),
234  fgPotentialDrop(pdc->getKey_constRef< SGrid<delphi_real> >("vdrop")),
235  fTaylorCoeff2(pdc->getKey_constRef<delphi_real>("chi2")),
236  fTaylorCoeff3(pdc->getKey_constRef<delphi_real>("chi3")),
237  fTaylorCoeff4(pdc->getKey_constRef<delphi_real>("chi4")),
238  fTaylorCoeff5(pdc->getKey_constRef<delphi_real>("chi5")),
239  //----- set by IO class
240  iMediaNum(pdc->getKey_constRef<delphi_integer>("nmedia")),
241  iObjectNum(pdc->getKey_constRef<delphi_integer>("nobject")),
242  prgfMediaEps(pdc->getKey_constRef< vector<delphi_real> >("medeps")),
243  //----- set by Surface class
244  iCrgGridNum(pdc->getKey_constRef<delphi_integer>("nqass")),
245  fMinusCrg(pdc->getKey_constRef<delphi_real>("qmin")),
246  fPlusCrg(pdc->getKey_constRef<delphi_real>("qplus")),
247  fgPlusCrgCenter(pdc->getKey_constRef< SGrid<delphi_real> >("cqplus")),
248  fgMinusCrgCenter(pdc->getKey_constRef< SGrid<delphi_real> >("cqmin")),
249  iBndyGridNum(pdc->getKey_constRef<delphi_integer>("ibnum")),
250  prgigBndyGrid(pdc->getKey_constRef< vector< SGrid<delphi_integer> > >("ibgrd")),
251  prgigEpsMap(pdc->getKey_constRef< vector< SGrid<delphi_integer> > >("iepsmp")),
252  prgbDielecMap(pdc->getKey_constRef< vector<bool> >("idebmap")),
253  iCrg2GridNum(pdc->getKey_constRef<delphi_integer>("nqgrd")),
254  prggvCrg2Grid(pdc->getKey_constRef< vector< SGridValue<delphi_real> > >("chrgv2")),
255  prgiCrg2GridMap(pdc->getKey_constRef< vector<delphi_integer> >("nqgrdtonqass")),
256  prgfAtomEps(pdc->getKey_constRef< vector<delphi_real> >("atmeps")),
257  prggvCrgedAtom(pdc->getKey_constRef< vector<SGridValue<delphi_real> > >("atmcrg")),
258  //prgfgSurfCrgA(pdc->getKey_constRef< vector< SGrid<delphi_real> > >("scspos")),
259 
260  //++++++++++++++++ reference to read-and-write variables from data container +++++++++++++++//
261  iGrid(pdc->getKey_Ref<delphi_integer>("igrid")), // modified in setFocusBndy
262  iBndyType(pdc->getKey_Ref<int>("ibctyp")), // modified in setBndy
263  fNetCrg(pdc->getKey_Ref<delphi_real>("qnet")), // modified in setCoulombBndy and setDipolarBndy
264  iLinIterateNum(pdc->getKey_Ref<int>("nlit")),
265  iIterateInterval(pdc->getKey_Ref<int>("icon1")),
266  iConvergeFract(pdc->getKey_Ref<int>("icon2")),
267  fRelaxParam(pdc->getKey_Ref<delphi_real>("relpar")),
268  //----- out into data container
269  iDielecBndyOdd(pdc->getKey_Ref<delphi_integer>("icount2b")),
270  iCrgedGridSum(pdc->getKey_Ref<delphi_integer>("icount1b")), // modified in setcrg
271  prgfGridCrg(pdc->getKey_Ref< vector<delphi_real> >("gchrg")), // modified in setcrg
272  prgigGridCrgPose(pdc->getKey_Ref< vector< SGrid<delphi_integer> > >("gchrgp")), // modified in setcrg
273  iCrgBndyGridNum(pdc->getKey_Ref<delphi_integer>("ibc")), // modified in setcrg
274  prgdgvCrgBndyGrid(pdc->getKey_Ref< vector<SDoubleGridValue> >("cgbp")), // modified in setcrg
275  prgfPhiMap(pdc->getKey_Ref< vector<delphi_real> >("phimap")),
276  /*********************************************************************************************
277  * *
278  * variables defined in this class *
279  * *
280  ********************************************************************************************/
281 
282  //+++++++++++++++++++++++++++++++++ const class variables ++++++++++++++++++++++++++++++++++//
283  iTotalGridNum(iGrid*iGrid*iGrid+1),
284  iHalfGridNum(iTotalGridNum/2),
285  iBndyDielecNum(2*(iBndyGridNum+1)),
286  fDebFct(fEpsOut/(fDebyeLength*fScale*fDebyeLength*fScale)),
287  fEpsDiff(fEpsIn-fEpsOut),
288  fSixEps(fEpsOut*6.0),
289  iEpsDim(iAtomNum+iObjectNum+2),
290  nxran(60),
291  nyran(20)
292  {
293 #ifdef DEBUG_OBJECT
294  cout << endl;
295  cout << "****************************************************************\n";
296  cout << "* CDelphiFastSOR is constructed *\n";
297  cout << "****************************************************************\n";
298 #endif
299 
300  if (0 != strBioModel.compare("PBE") && 0 != strNumSolver.compare("DELPHI"))
301  throw CUnknownBioModelSolver(strBioModel,strNumSolver);
302 
303  //++++++++++++++++++++++++++++ local variables in this class ++++++++++++++++++++++++++++//
304  iDielecBndyEven = 0;
305  iCrgedGridEven = 0;
306  fSpec = 0.0;
307  prgfPhiMap.assign(iGrid*iGrid*iGrid,0.0);
308  qmap1.assign(iHalfGridNum,0.0);
309  qmap2.assign(iHalfGridNum,0.0);
310 
311  };
312 
313  ~CDelphiFastSOR()
314  {
315 #ifdef DEBUG_OBJECT
316  cout << endl;
317  cout << "****************************************************************\n";
318  cout << "* CDelphiFastSOR is destroyed *\n";
319  cout << "****************************************************************\n";
320 #endif
321  };
322 
323 #ifdef MCCE
324  void getMCCE(SMCCE* mcce_data) { pmcce = mcce_data; }
325 #endif
326 
327  virtual void validateInput();
328 
329  virtual void run();
330 };
331 
332 #endif // SOLVER_FASTSOR_H
Definition: solver_fastSOR.h:20
Definition: solver_exceptions.h:6
Definition: delphi_constants.h:73
Definition: interface_abstractmodule.h:23