9 if(
Pm[p1].CId ==
Pm[p1-1].CId ){
10 Link[NLink++] = p1 - 1;
14 if(
Pm[p1].CId ==
Pm[p1+1].CId ){
15 Link[NLink++] = p1 + 1;
18 for(
int l=0;l<NLink;l++){
38 if(
Pm[p].CId -1 ==
Pm[p-1].CId){
46 if(
Pm[p].CId + 1 ==
Pm[p+1].CId || p ==
pNPart()-1){
60 DistBA[3] = (SQR(DistBA[0])+SQR(DistBA[1])+SQR(DistBA[2]));
61 DistCB[3] = (SQR(DistCB[0])+SQR(DistCB[1])+SQR(DistCB[2]));
63 CosAngle += DistBA[d]*DistCB[d];
64 CosAngle /= (DistBA[3]*DistCB[3]);
69 NrgBen +=
pkBen()*(1.-CosAngle);
72 return NrgSpr + NrgBen;
81 if(
pkBen() <= 0.)
return 0.;
99 DistBA2 += SQR(DistBA[d]);
100 DistCB2 += SQR(DistCB[d]);
101 CosAngle += DistBA[d]*DistCB[d];
103 DistCB2 = sqrt(DistCB2);
104 DistBA2 = sqrt(DistBA2);
105 CosAngle /= (DistBA2*DistCB2);
106 NrgBen +=
pkBen()*(1.-CosAngle);
117 double CosAngle = 0.;
118 for(
int d=0;d<3;d++){
119 DistCB[d] =
pPos(p+1,d) +
pPos(p,d);
121 DistCB2 += SQR(DistCB[d]);
123 DistCB2 = sqrt(DistCB2);
125 if(p == c*
pNPCh())
continue;
126 for(
int d=0;d<3;d++){
127 DistBA[d] =
pPos(p,d) -
pPos(p-1,d);
129 DistBA2 += SQR(DistBA[d]);
130 CosAngle += DistBA[d]*DistCB[d];
132 DistBA2 = sqrt(DistBA2);
133 CosAngle /= (DistBA2*DistCB2);
134 NrgBend +=
pkBen()*(1.-CosAngle);
138 return NrgBend + NrgSpr;
141 if(
Ln[p1].NLink < 1)
return 0.;
142 if( !(p1%
pNPCh()) )
return 0.;
161 if(
Pm[p1].Typ ==
Pm[p2].Typ)
169 Pot[0] = 0.;Pot[1] = 0.;Pot[2] = 0.;
174 for(
int p=p1;p<p1+
pNPCh();p++){
180 if(p2 > p1 && p2 < p1 +
pNPCh() && p2 < p)
continue;
192 double DistRel[4] = {0.,0.,0.,0.};
196 for(
int p1=pInit;p1<pEnd;p1++){
202 if(p2>=pInit && p2<pEnd && p2<=p1)
continue;
205 double Dist = sqrt(DistRel[3]);
208 Dens2[p2*
pNType()+t1] -= w2;
209 Dens2[p1*
pNType()+t2] -= w2;
210 Dens3[p2*
pNType()+t1] -= w3;
211 Dens3[p1*
pNType()+t2] -= w3;
219 double DistRel[4] = {0.,0.,0.,0.};
222 for(
int p1=pInit;p1<pEnd;p1++){
228 if(p2>=pInit && p2<pEnd && p2<=p1)
continue;
231 double Dist = sqrt(DistRel[3]);
234 Dens2[p2*
pNType()+t1] += w2;
235 Dens2[p1*
pNType()+t2] += w2;
236 Dens3[p2*
pNType()+t1] += w3;
237 Dens3[p1*
pNType()+t2] += w3;
245 double OneThird = 1./3.;
246 for(
int p=pInit;p<pEnd;p++){
248 for(
int t2=0;t2<
pNType();t2++){
250 for(
int t3=0;t3<
pNType();t3++){
258 double DistRel[4] = {0.,0.,0.,0.};
261 double OneThird = 1./3.;
262 memset(LocDens2,0,
pNType()*
sizeof(
double));
263 memset(LocDens3,0,
pNType()*
sizeof(
double));
267 if(p1 == p2)
continue;
270 double Dist = sqrt(DistRel[3]);
273 LocDens2[t2] += w2*2.;
275 double W3Add[3] = {0.,0.,0.};
277 for(
int t3=0;t3<
pNType();t3++){
278 for(
int t4=0;t4<
pNType();t4++){
279 double Fact = Dens3[p2*
pNType()+t3]*W3Add[t4];
280 Fact += W3Add[t3]*Dens3[p2*
pNType()+t4];
281 Fact += W3Add[t3]*W3Add[t4];
283 Nrg += Fact*OneThird*
MInt->
Coeff(t2,t3,t4);
288 for(
int t2=0;t2<
pNType();t2++){
289 Nrg += .5*LocDens2[t2]*
MInt->
Coeff(t1,t2);
290 for(
int t3=0;t3<
pNType();t3++){
291 Nrg += LocDens3[t2]*LocDens3[t3]*OneThird*
MInt->
Coeff(t1,t2,t3);
297 double DistRel[4] = {0.,0.,0.,0.};
300 double OneThird = 1./3.;
301 memset(LocDens2,0,
pNPCh()*
pNType()*
sizeof(
double));
302 memset(LocDens3,0,
pNPCh()*
pNType()*
sizeof(
double));
310 for(
int p1=pInit,pc=0;p1<pEnd;p1++,pc++){
315 if(p1 == p2)
continue;
318 double Dist = sqrt(DistRel[3]);
321 LocDens2[pc*
pNType()+t2] += w2;
322 LocDens3[pc*
pNType()+t2] += w3;
324 if(p2 < p1 || p2 >= pEnd){
325 LocDens2[pc*
pNType()+t2] += w2;
326 double W3Add[3] = {0.,0.,0.};
329 for(
int t3=0;t3<
pNType();t3++){
330 for(
int t4=0;t4<
pNType();t4++){
331 double Fact = Dens3[p2*
pNType()+t3]*W3Add[t4];
332 Fact += W3Add[t3]*Dens3[p2*
pNType()+t4];
333 Fact += W3Add[t3]*W3Add[t4];
335 Nrg += Fact*OneThird*
MInt->
Coeff(t2,t3,t4);
342 for(
int pt=0;pt<
pNPCh();pt++){
343 int t1 =
pType(pInit+pt);
344 for(
int t2=0;t2<
pNType();t2++){
346 for(
int t3=0;t3<
pNType();t3++){
354 double DistRel[4] = {0.,0.,0.,0.};
357 double OneThird = 1./3.;
358 memset(LocDens2,0,
pNType()*
sizeof(
double));
359 memset(LocDens3,0,
pNType()*
sizeof(
double));
360 int c = (int)(p1/
pNPCh());
366 if(p1 == p2)
continue;
367 if(p2 < pInit)
continue;
368 if(p2 >= pEnd)
continue;
371 double Dist = sqrt(DistRel[3]);
374 LocDens2[t2] += w2*2.;
376 double W3Add[3] = {0.,0.,0.};
378 for(
int t3=0;t3<
pNType();t3++){
379 for(
int t4=0;t4<
pNType();t4++){
380 double Fact = Dens3[p2*
pNType()+t3]*W3Add[t4];
381 Fact += W3Add[t3]*Dens3[p2*
pNType()+t4];
382 Fact += W3Add[t3]*W3Add[t4];
384 Nrg += Fact*OneThird*
MInt->
Coeff(t2,t3,t4);
389 for(
int t2=0;t2<
pNType();t2++){
390 Nrg += .5*LocDens2[t2]*
MInt->
Coeff(t1,t2);
391 for(
int t3=0;t3<
pNType();t3++){
392 Nrg += LocDens3[t2]*LocDens3[t3]*OneThird*
MInt->
Coeff(t1,t2,t3);
412 Shout(
"Calculate chains energy");
413 double Pot[3] = {0.,0.,0.};
419 OldNrgCh[c*3 ] = Pot[0];
420 OldNrgCh[c*3+1] = Pot[1];
421 OldNrgCh[c*3+2] = Pot[2];
422 Nrg += Pot[0] + Pot[1] + Pot[2];
439 return Pot[0] + Pot[1] + Pot[2];
446 Pot[0] = 0.;Pot[1] = 0.;Pot[2] = 0.;
448 double DistRel[4] = {0.,0.,0.,0.};;
449 double Pot1[3] = {0.,0.,0.};
452 for(
int p=p1;p<p1+
pNPCh();p++){
457 if(p1 >= p2)
continue;
458 if(p2 > p1 && p2 < p1 +
pNPCh() && p2 < p)
continue;
466 return Pot[0] + Pot[1] + Pot[2];
471 Shout(
"Calculate chains energy");
472 double Pot[3] = {0.,0.,0.};
477 OldNrgBead[p*3 ] = Pot[0];
478 OldNrgBead[p*3+1] = Pot[1];
479 OldNrgBead[p*3+2] = Pot[2];
480 Nrg += Pot[0] + Pot[1] + Pot[2];
497 return Pot[0] + Pot[1] + Pot[2];
504 double DistRel[4] = {0.,0.,0.,0.};
505 Pot[0] = 0.;Pot[1] = 0.;Pot[2] = 0.;
509 if(p2 == p1)
continue;
515 NrgSum += Pot[0] + Pot[1] + Pot[2];
521 void Forces::ChooseCalcMode(
int Mode){
522 printf(
"Calculation mode: ");
523 if(VAR_IF_TYPE(Mode,CALC_PAIR)){
526 printf(
"Pairwise interactions\n");
528 else if(VAR_IF_TYPE(Mode,CALC_DENS)){
532 printf(
"Lipid model particle energy\n");
534 else if(VAR_IF_TYPE(Mode,CALC_DENS_CH)){
538 printf(
"Lipid model chain energy\n");
541 printf(
"mode not present\n");
545 void Forces::ChoosePot(
int Mode){
546 printf(
"Potential: ");
547 if(VAR_IF_TYPE(Mode,CALC_LJ)){
549 printf(
"Lennard Jones\n");
551 else if(VAR_IF_TYPE(Mode,CALC_LJ39)){
553 printf(
"Lennard Jones 3-9\n");
555 else if(VAR_IF_TYPE(Mode,CALC_HARM)){
557 printf(
"Harmonic\n");
559 else if(VAR_IF_TYPE(Mode,CALC_STEP)){
563 else if(VAR_IF_TYPE(Mode,CALC_ELECTRO)){
568 printf(
"not present\n");
575 double DistRel[4] = {0.,0.,0.,0.};
577 for(
int p1=0;p1<
pNPart();p1++){
580 if(p1 >= p2)
continue;
583 double InvDist = 1./sqrt(DistRel[3]);
585 for(
int d=0;d<3;d++){
586 Fm[p1].
Dir[d] += Cons*DistRel[d]*InvDist;
587 Fm[p2].
Dir[d] -= Cons*DistRel[d]*InvDist;
594 #include <sys/time.h> 597 int *PDom = (
int *)calloc(NAll*NAll,
sizeof(
int));
598 if(PDom == NULL){printf(
"Could not alloc PDom\n");
return;};
599 int *PLoop = (
int *)calloc(NAll*NAll,
sizeof(
int));
600 if(PLoop == NULL){printf(
"Could not alloc PLoop\n");
return;};
603 double NPairDom = 0.;
604 double NPairLoop = 0.;
608 double DistRel[4] = {0.,0.,0.,0.};
615 for(
int p1=0;p1<
pNPart();p1++){
618 if(p2 <= p1)
continue;
622 PLoop[NDom*2+0] = p2;
623 PLoop[NDom*2+1] = p2;
628 TimeDomDec = (double)(TimeInit.tv_nsec - TimeEnd.tv_nsec);
630 for(
int p1=0;p1<
pNPart();p1++){
631 for(
int p2=p1+1;p2<
pNPart();p2++){
633 for(
int d=0;d<3;d++){
636 Dist2 += SQR(Dist[d]);
640 PLoop[NLoop*2+0] = p1;
641 PLoop[NLoop*2+1] = p2;
646 TimeLoop = (double)(TimeInit.tv_nsec - TimeEnd.tv_nsec);
648 printf(
"[Pairs] %d=%d Gain (pair): %lf (time): %lf\n",NDom,NLoop,NPairLoop/NPairDom,TimeLoop/TimeDomDec);
649 for(
int p=0;p<MAX(NDom,NLoop);p++){
659 const int NAll =
pNPart();
660 int *PDom =
new int[NAll];
661 int *PCell =
new int[NAll];
663 int *PLoop =
new int[NAll];
667 double DistRel[4] = {0.,0.,0.,0.};
672 if(p2 == p1)
continue;
678 for(
int p2=0;p2<
pNPart();p2++){
679 if(p1 == p2)
continue;
681 for(
int d=0;d<3;d++){
682 DistRel[d] =
pPos(p1,d) -
pPos(p2,d);
684 Dist2 += SQR(DistRel[d]);
690 printf(
"-------------%d=%d Ratio %lf\n",NDom,NLoop,
pNPart()/NCell);
691 for(
int p=0;p<MAX(NDom,NLoop);p++){
692 printf(
"%d %d %d %d\n",p,PDom[p],PLoop[p],PCell[p]);
double DensFuncNrgBead(int p1)
Calculation of the energy from the density functional Hamiltonian for the particle p1...
CHAIN * Ch
Information on all chains.
double pkBen()
Bending coupling.
double CheckDomDec(int p)
Check if all the particles are taken in account.
double CalcTotNrgCh()
Calculate and sum up the energy of the chains.
double LJPot(double Dist2, int t1, int t2, double *Pot)
Classical Lennard Jones potential.
int cCurr
Cell where the current particle sits.
double NrgStepCh(int c, double *Pot)
The energy per chain is constant within the cutoff.
LINKS * Ln
Array of linking between the particles.
double CalcPairwiseCh(int c, double *Pot)
Calculate the non bonded interaction energy with the neighbouring particles.
double CalcBendingGhost(double *Pos, int pExt)
Calculate the bending energy for a ghost particle.
void Dist2CurrGhost(double *DistRel)
Retrun the squared current interparticle distance.
int pChain(int p)
Return the chain.
Geometrical operations on vectors.
void CalcNrgBeadDensFunc()
Calculate the spring, bending and non bonded interactions and write it in OldNrgPm.
void CheckPairList()
Check the pair list.
double CalcBending(int p)
Calculate the bonded interaction energy with the neighbouring particles.
double DensFuncNrgCh(int c, double *Pot)
Calculate the energy from the density functional Hamiltonian for the chain c.
double CalcTotNrgBead()
Calculate and sum up the energy of the part.
double Harmonic(double Dist2, int t1, int t2, double *Pot)
Harmonic potential.
double pInvEdge(int d)
Inverted xyzr edges of the simulation box.
int pType(int p)
Return the type.
double Pos[3]
xyz Position of the particle
double NrgChBondDens(int c, double *Pot)
Calculate the bond and the density functional energies.
double SumForcesMD()
Iterate all over the particles and calculate the forces.
int RemDens(int pInit, int pEnd)
Substract the densities connected with the particles between pInit and pEnd.
double pkSpr()
Spring coupling.
double pSprRest()
Rest distance of the harmonic potential.
void Dist2Curr(double *DistRel)
Retrun the squared current interparticle distance.
double CosAngle(Vettore *u)
Computes the cosine with respect to.
double CalcSpring(int p)
Calculate the spring interaction energy with the neighbouring particles.
int InitBead
Initial bead.
void Shout(const char *s,...)
Internal message.
double ElectroPot(double Dist2, int t1, int t2, double *Pot)
Potential for the electrical lines.
double pEdge(int d)
xyzr edges of the simulation box
int pNPCh()
Number of particle per chain.
int IfCurrGhost()
Tell when the curr loop is over.
void NextCurrGhost()
Increase the iterator to the next couple.
double NrgStep(int p)
The energy is constant within the cutoff.
double pWei3Par()
Parameter of the third order weighting function.
double TwoPartDist(int p1, int p2, double *RelDist)
Return the relative distance between two particles (wrapped)
double NanoNrg(int p)
Exchange energy with the nano.
MatInt * MInt
Matrix of the prefactor of the interactions.
KFORCES Kf
Prefactor of the forces.
void NextCurr()
Increase the iterator to the next couple.
double pWei2Par()
Parameter of the second order weighting function.
double DensFuncNrgSys()
Calculation of the energy from the density functional Hamiltonian for the system. ...
double Coeff(int t1, int t2)
Prefactor of the force.
double StepPot(double Dist2, int t1, int t2, double *Pot)
Step potential.
double Potential(double Dist, int t1, int t2, double *Pot)
Pointer to a potential.
double Wei3(const double r, const double a)
Cubic weighting function.
void ClearDens()
Set the local densities to zero.
double DensFuncNrgChAv(int c)
Calculate the average energy from the density functional Hamiltonian for the chain c...
void SetCurrGhost(double *Pos)
Gather information of the neighbouring cells.
double CalcNrgCh(int c, double *Pot)
Pointer to the chain energy function.
int pNType()
of types of the particle
double DensFuncNrgChInternal(int c)
Calculate the average energy from the density functional Hamiltonian for the chain c...
double CalcBondedCh(int c, double *Pot)
Calculate the bonded and spring interaction in a cell.
double pPos(int p, int d)
Return back folded position.
int pNChain()
Number of chain.
double CalcPairwise(int p, double *Pot)
Calculate the non bonded interaction energy with the neighbouring particles.
int IfCurr()
Tell when the curr loop is over.
double DensFuncNrgGhost(double *Pos, int p1, int t1)
Calculation of the energy from the density functional Hamiltonian for the ghost particle.
double CutOff2
CutOff of the lennard jones.
int p2Curr
Current particle.
double CalcBonded(int p, double *Pot)
Calculate the spring and the bonded interactions with the other monomers in the chain.
double SumDens(int pInit, int pEnd)
Sum the local density for the particles between pInit and pEnd and multiply the factors by the virial...
void CalcDens()
Calculate the densities.
PART * Pm
Particle information of all particle.
int AddDens(int pInit, int pEnd)
Add the densities connected with the particles between pInit and pEnd.
double LJ39(double Dist2, int t1, int t2, double *Pot)
Integrated Lennard Jones potential.
void SetCurr(int p)
Gather information of the neighbouring cells.
double Wei2(const double r, const double b)
Quadratic weighting function.
double DensFuncNrgGhostInternal(double *Pos, int p1, int t1)
Calculation of the energy from the density functional Hamiltonian for the ghost particle.
FORCES * Fm
Array containing the forces for each particle.
double CalcNrgBead(int p, double *Pot)
Pointer to the energy function.
int pNPart()
Number of particle.
void DefForceParam()
Define the parameters for calculating the force.