Allink
v0.1
|
00001 #ifndef FORCES_H 00002 #define FORCES_H 00003 #include <VarData.h> 00004 #include <Cubo.h> 00005 #include <SingProc.h> 00006 #include <time.h> 00007 #ifdef USE_GL 00008 #include <GL/glut.h> 00009 #endif//USE_GL 00010 00011 enum SYS_SHAPE{ 00013 SYS_1D = 0x0001, 00015 SYS_2D = 0x0002, 00017 SYS_3D = 0x0004, 00019 SYS_LEAVES = 0x0008, 00021 SYS_RIGID = 0x0010, 00023 SYS_STALK = 0x0020, 00025 SYS_MD = 0x0040, 00027 SYS_MC = 0x0080, 00029 SYS_WIDOM = 0x0100, 00031 SYS_TRIAL = 0x0200, 00033 SYS_PORE = 0x0400, 00035 SYS_ROD = 0x0800, 00037 SYS_ELECTRO = 0x1000, 00038 }; 00040 enum CALC_MODE{ 00042 CALC_NVT = 0x00001, 00044 CALC_mVT = 0x00002, 00046 CALC_SOLVE = 0x00004, 00048 CALC_PAIR = 0x00008, 00050 CALC_HARM = 0x00010, 00052 CALC_LJ39 = 0x00020, 00054 CALC_LJ = 0x00040, 00056 CALC_DENS_CH = 0x00080, 00058 CALC_NcVT = 0x00100, 00060 CALC_mcVT = 0x00200, 00062 CALC_3d = 0x00400, 00064 CALC_2d = 0x00800, 00066 CALC_DENS = 0x01000, 00068 CALC_CONF_BIAS = 0x02000, 00070 CALC_BIL_BIAS = 0x04000, 00072 CALC_SPH_BIAS = 0x08000, 00074 CALC_STEP = 0x10000, 00076 CALC_ELECTRO = 0x20000, 00077 }; 00079 enum THERM_MODE{ 00081 THERM_NO = 0x0001, 00083 THERM_LANG = 0x0002, 00085 THERM_AND = 0x0003, 00087 THERM_BERE = 0x0004, 00088 }; 00090 enum FIT_TYPE{ 00092 FIT_SPLINE3 = 0, 00094 FIT_SPLINE4 = 1, 00096 FIT_PARAB2 = 2, 00098 FIT_CUBIC = 3, 00100 FIT_DERIV = -1, 00102 FIT_FORTH = 4, 00104 FIT_POLY = 5, 00106 FIT_BSPLINE = 6, 00107 }; 00109 enum IntMethod{ 00111 INT_MD = 0, 00113 INT_DIFF = 1, 00115 INT_MC = 2, 00116 }; 00118 enum ALLOCATED{ 00120 ALL_FORCES = 0x001, 00122 ALL_METR = 0x002, 00124 ALL_POT = 0x004, 00126 ALL_MC = 0x008, 00128 ALL_MD = 0x010, 00130 ALL_SPLINE = 0x020, 00132 ALL_CYL = 0x040, 00134 ALL_FFIELD = 0x080, 00136 ALL_TENS = 0x100, 00138 ALL_DENS = 0x200, 00140 ALL_BIAS = 0x400, 00142 ALL_MATRIX = 0x800, 00143 }; 00145 typedef struct{ 00147 double Lap; 00149 double SLap; 00151 double El[3]; 00153 double Ext; 00155 double LJ; 00157 double Cont; 00159 double Elong[3]; 00161 double LJMin; 00163 double LJCutOff; 00165 double CutOff2; 00167 double BaseLine; 00169 double PotThr; 00171 double ForThr; 00173 double DistThr; 00174 } KFORCES; 00176 typedef struct{ 00178 double Dir[3]; 00179 /* /// Helfrich */ 00180 /* double Hel[3]; */ 00182 double Ext[3]; 00183 /* /// Elastic */ 00184 /* double El[3]; */ 00185 /* /// Lennard-Jones */ 00186 /* double LJ[3]; */ 00187 } FORCES; 00189 typedef struct{ 00191 int NComp; 00193 int NDim; 00195 int NSlab; 00197 int CalcMode; 00199 double **Pre; 00201 double **Dens; 00203 double PreTot[3]; 00205 double RefPos[3]; 00207 double Edge[3]; 00209 int Wrap[3]; 00211 double EdgeInv[3]; 00212 }TENS; 00214 //typedef DdDoubleLoop DomDec; 00215 typedef DdLinkedList DomDec; 00216 //typedef DdFixedSize DomDec; 00217 //typedef DdArray DomDec; 00223 class Forces : public VarData{ 00224 private: 00226 char ConfFile[60]; 00228 time_t InitTime; 00230 time_t CurrTime; 00232 double *Dens2; 00234 double *Dens3; 00236 double *PTab; 00238 double *FTab; 00240 double *MTab; 00242 double OldNrgSys; 00244 double *OldNrgBead; 00246 double *OldNrgCh; 00248 double **OldPos; 00250 double *LocDens2; 00252 double *LocDens3; 00254 double *FirstBeadDistr; 00256 double **BondPosBias; 00258 double *CumProbBias; 00260 double BorderBias[2]; 00262 int NBin; 00264 int NGrid; 00266 int NTrialBias; 00268 int BoundCond[6]; 00270 int PeriodicImage[3]; 00272 FILE *StatFile1; 00274 FILE *StatFile2 ; 00276 typedef double(Forces::*CALC_NRG)(int p,double *Pot); 00278 CALC_NRG NrgBead; 00280 CALC_NRG NrgCh; 00282 //static CALC_NRG ChooseCalcMode(int Mode); 00283 void ChooseCalcMode(int Mode); 00285 typedef double(Forces::*CALC_POT)(double Dist,int t1,int t2,double *Pot); 00287 CALC_POT CalcPot; 00289 //static CALC_POT ChoosePot(int Mode); 00290 void ChoosePot(int Mode); 00292 int NTab; 00294 int DynFlag; 00296 typedef double(Forces::*STEP_CONF)(); 00298 typedef double(Forces::*STEP_SIM)(); 00300 STEP_CONF ConfigSys(); 00302 STEP_SIM CalcUpdate(); 00304 Matrice *IntMatrix; 00305 public: 00306 //-----------Forces.cpp--------------------- 00308 Forces(int argc,char **argv,int NPart,char *ConfFile); 00310 Forces(int argc,char **argv,char *ConfFileExt,char *Snapshot); 00312 void Shout(const char * s, ...); 00314 void AllocMethod(); 00316 void PrepareSys(); 00318 void PrepareParallel(int argc,char **argv); 00320 ~Forces(); 00322 void Info(); 00324 int ReadConfDinamica(char *File); 00326 void InitConst(); 00328 int ReSetNPart(int NewNPart); 00330 int ReSetNChain(int NewNChain); 00332 void ReSetNPCh(int NewNPCh); 00334 void ReOpen(char *FName,int Bf); 00336 void FillMatrix(); 00337 //-----------ForcesIntegration.cpp---------- 00340 void StudySys(); 00342 int MinHelfrich(); 00344 int DynIntegration(); 00346 void Dynamics(); 00348 void Solve(); 00350 void SolveLinks(); 00352 void SolveLinksSparse(); 00354 void SolveLinksIterative(); 00356 void SolveRod(); 00358 void SolveLeaves(); 00360 int Update(); 00362 void VelVerletRigid(); 00364 void VelVerletRigid2(); 00366 int IfMetropolis(double ExpArg,double Weight); 00368 int InsertBead(int p); 00370 void IgnoreCh(int c); 00372 void RemChFromSys(int c); 00374 void SaveCh(int c); 00376 void ReInsertCh(int c); 00378 void ConsiderCh(int c); 00380 double InsertCh(int c); 00382 double InsertRest(int pCurr,int StartPos); 00384 double RemoveChBias(int c); 00386 double InsertChBias(int c); 00388 double WeightSetBond(int p,int t); 00390 double CreateSetBond(int p,int t); 00392 int MoveBead(int p); 00394 int TryInsert(); 00396 int TryRemove(); 00398 int TryMove(); 00400 int TryMoveCh(); 00402 int TryInsertCh(); 00404 int TryRemoveCh(); 00406 int TryInsertChBias(); 00408 int TryRemoveChBias(); 00410 void WidomInsert(double *NrgDiff); 00412 void WidomRemove(double *NrgDiff,int p); 00414 void WidomInsertCh(double *NrgDiff); 00416 void WidomRemoveCh(double *NrgDiff,int c); 00418 void WidomBiasChIn(double *Weight); 00420 void WidomBiasChOut(double *Weight,int c); 00422 void VelVerlet1(); 00424 void LangevinTherm(); 00426 void AndersenTherm(); 00428 void BerendsenTherm(); 00430 void NoTherm(){}; 00432 void VelVerlet2(); 00434 //static CALC_NRG ChooseCalcMode(int Mode); 00435 void ChooseThermostat(int Mode); 00437 typedef void (Forces::*CALC_THERM)(); 00439 CALC_THERM CalcTherm; 00441 void ApplyTherm(){return (*this.*CalcTherm)();}; 00442 //-----------ForcesForceField.cpp----------- 00444 int ForceFieldLine(); 00446 int SumSomeForces(int HowMany); 00448 int ForceFieldLeaves(); 00450 int ForceFieldBulk(); 00452 void ForceFieldRod(); 00454 void ForceFieldRigid(); 00456 void CalcForcesDensFunc(); 00458 void PrintForce(); 00460 void GetForceField(); 00462 void TabForceAlloc(int NTabExt); 00464 void TabPot(); 00466 void NanoInteraction(); 00468 double NanoNrg(int p); 00470 double NanoNrg(double *Pos,int t); 00472 void DefForceParam(); 00474 void DefNanoForceParam(); 00476 double RigidLJ(int nNano,double Dist,double *Pot,double Sign); 00478 double RigidHamaker(int n,double Dist,double *Pot,double Sign); 00480 double RigidCoulomb(int nNano,double Dist,double *Pot,double Sign); 00482 double RigidDistanceRad(int n,int nn,double *dr); 00484 double RigidDistanceAxis(int n,int nn,double *dr); 00485 // Point to the potential 00486 void PointShape(int iShape); 00487 /* /// Data type for distance/field functions */ 00488 /* typedef double(Forces::*NANO_FORCE)(double Dist2,int n,int p); */ 00489 /* /// Pointer to a distance/field function */ 00490 /* NANO_FORCE Nano_Force; */ 00491 /* /// Pointer to a generic function */ 00492 /* double NanoForce(double Dist2,int n,int p){return (*this.*Nano_Force)(Dist2,n,p);} */ 00494 double Harmonic(double Dist2,int t1,int t2,double *Pot); 00496 double StepPot(double Dist2,int t1,int t2,double *Pot); 00498 double ElectroPot(double Dist2,int t1,int t2,double *Pot); 00500 double LJ39(double Dist2,int t1,int t2,double *Pot); 00502 double LJPot(double Dist2,int t1,int t2,double *Pot); 00504 double Potential(double Dist,int t1,int t2,double *Pot){return (*this.*CalcPot)(Dist,t1,t2,Pot);}; 00505 //-----------ForcesCalcNrg.cpp----------- 00507 double CalcTotNrgCh(); 00509 double CalcTotNrgBead(); 00511 double CalcNrgBead(int p,double *Pot){return (*this.*NrgBead)(p,Pot);}; 00513 double CalcNrgCh(int c,double *Pot){return (*this.*NrgCh)(c,Pot);}; 00515 double NrgChBondDens(int c,double *Pot); 00517 double NrgChDens(int c,double *Pot); 00519 double CalcPairwise(int p,double *Pot); 00521 double CalcPairwiseCh(int c,double *Pot); 00523 double CalcBending(int p); 00525 double CalcSpring(int p); 00527 double CalcBonded(int p,double *Pot); 00529 double CalcBendingGhost(double *Pos,int pExt); 00531 double CalcBondedCh(int c,double *Pot); 00532 /* ///Calculate the spring, bending and non bonded interactions */ 00533 /* double CalcNrgCh(int c,double *Pot); */ 00535 void CalcNrgBeadDensFunc(); 00537 double CalcNrgBeadDensFunc(int p,double *Pot); 00539 double CheckDomDec(int p); 00541 void CheckPairList(); 00543 double SumForcesMD(); 00545 double Wei3(const double r, const double a); 00547 double DerWei3(const double r, const double a); 00549 double Wei2(const double r, const double b); 00551 double DerWei2(const double r, const double b); 00553 double DensFuncNrgGhost(double *Pos,int p1,int t1); 00555 double DensFuncNrgGhostInternal(double *Pos,int p1,int t1); 00557 double DensFuncNrgBead(int p1); 00559 double DensFuncNrgCh(int c,double *Pot); 00561 double DensFuncNrgChAv(int c); 00563 double DensFuncNrgChInternal(int c); 00565 double DensFuncNrgSys(); 00567 void CalcDens(int pInit,int pEnd); 00569 void ClearDens(); 00571 double NrgStep(int p); 00573 double NrgStepCh(int c,double *Pot); 00575 double NrgElectro(int p); 00577 int AddDens(int pInit,int pEnd); 00579 int RemDens(int pInit,int pEnd); 00583 double SumDens(int pInit,int pEnd); 00585 int ListNeiCell(int p,double *Pos,int *NeiList){ 00586 return Pc->GetNei(Pos,NeiList); 00587 //return Pc->GetCell(p,NeiList); 00588 }; 00589 //-----------ForcesBoundary.cpp------------- 00591 void PullBead(); 00593 void PushBead(); 00595 void SelectBead(int p); 00597 void Wave(); 00599 void AddCircle(int nNano); 00601 void AddCylinder(int nNano); 00603 void AddPore(int nNano); 00605 void AddRigid(); 00607 double HeightBoundary(double *Pos,int dir); 00608 //-----------ForceCreate.cpp---------------- 00610 void CreateInitial(); 00612 void Create2d(); 00614 void Create3d(); 00616 void CreateLeaves(); 00618 void CreateStalk(); 00620 void CreatePore(); 00622 void Create1d(); 00624 void CreateRigid(); 00626 void CreateMC(); 00628 void CreateMD(); 00630 void CreateRod(); 00632 void CreateElectro(); 00633 //---------ElPolyTens.cpp-------------------------------- 00635 void AllocTens(); 00637 void CalcTens(); 00639 void CalcDens(); 00641 double TensRefCart(double *Pos1,double *Pos2,double *PosP1,double *PosP2); 00643 double TensRefPol(double *Pos1,double *Pos2,double *PosP1,double *PosP2); 00645 typedef double(Forces::*TENS_REF)(double *Pos1,double *Pos2,double *PosP1,double *PosP2); 00647 TENS_REF Tens_Ref; 00649 double TensRef(double *Pos1,double *Pos2,double *PosP1,double *PosP2){ 00650 return (*this.*Tens_Ref)(Pos1,Pos2,PosP1,PosP2); 00651 }; 00653 void SumTens(int p1,int p2,double Forces,double *DistRel); 00655 void SumTens(int p1,int p2,double *Pre); 00657 void SumTens(double *Pos1,double *Pos2,double *Pre); 00659 void WriteTens(char *TFile,int Comp,double InvNFile); 00661 void WriteTens2d(FILE *FWrite,int Comp,double InvNFile); 00662 //---------ForcesLoop.cpp-------------------------------- 00664 void ExplorePepSize(); 00666 void ExplorePepSize2d(); 00668 void ExploreDoubleMin(); 00670 void CalcTotNrg(char *FName,int nFile); 00672 void CalcNrgPep(char *File2Open,int f); 00674 void RunDynamics(); 00676 void RunWidom(char *File2Read,int f); 00678 void RunWidomChIn(char *File2Read,int f); 00680 void RunWidomChOut(char *File2Read,int f); 00682 void RosenIn(FILE *WidomIn); 00684 void RosenOut(FILE *WidomIn); 00686 void RunWidomBiasChOut(FILE *WidomOut); 00688 void ChooseSimMode(); 00690 void Task(); 00692 void CalcTens(char **argv,int *FilePos,int NFile); 00694 void AvForces(char **argv,int *FilePos,int NFile); 00696 void Trial(); 00698 void MinimalMD(); 00700 double MinimalNrg(); 00702 void Sim1d(){VelVerlet1();ForceFieldLine();VelVerlet2();}; 00704 void Sim2d(){VelVerlet1();Wave();VelVerlet2();}; 00706 void Sim3d(){VelVerlet1();ForceFieldBulk();VelVerlet2();}; 00708 void SimLeaves(){VelVerlet1();ForceFieldLeaves();AddRigid();VelVerlet2();}; 00710 void SimRigid(){VelVerlet1();ForceFieldRigid();VelVerletRigid();VelVerlet2();}; 00712 void MinimizeSol(); 00713 //----------------CONSTANTS---------------------------- 00715 double IncrDist; 00717 double Deltat; 00719 double NChemPotId; 00721 double ChemPotId; 00723 double ChemPotEx; 00725 double GaussVar; 00727 double CutOff; 00729 double Dx; 00731 double Viscosity; 00733 double Time; 00735 double NrgPBead; 00737 int Bead2Move; 00739 int Old2Move; 00741 int IntMax; 00743 int nEdge[3]; 00745 int SysShape; 00747 int CalcMode; 00749 int ThermMode; 00751 int SimLimit; 00753 int SysAlloc; 00755 int IfInterp; 00757 int IfLeaves; 00759 int IfMove; 00761 int IfNano; 00763 int IfFillMatrix; 00765 int IfExit; 00767 int NInsertion; 00769 int NRemoval; 00771 int NFile[2]; 00773 int NUpdate; 00775 int NWrite; 00777 int NSpline; 00779 KFORCES Kf; 00781 FORCES *Fm; 00783 TENS Tens; 00785 DomDec *Pc; 00787 PART *Pl; 00788 #ifdef USE_MPI 00789 SingProc *Proc; 00790 #endif 00791 #ifdef __glut_h__ 00792 00793 int Interp(); 00795 int Graphics(int argc,char **argv); 00797 void keyboard(unsigned char key,int x, int y); 00799 void DrawSoil(); 00801 void DrawCarpet(); 00803 void DrawParticles(); 00805 void DrBondLine(int p); 00807 void DrawScene(); 00809 void DrawNano(); 00811 void DynamicsView(); 00813 void Menu(); 00815 GLuint *Cylinder; 00817 GLuint Particles; 00819 int NShow; 00821 int IfMovie; 00823 int Frame; 00825 int IfExt; 00827 int IfSpline; 00829 int IfRot; 00831 int IfSphere; 00833 int BeadType; 00835 int menu,submenu; 00837 int IfLine; 00838 #endif 00839 }; 00841 extern void DynamicsMotion(); 00842 #endif //ELPOLY_H