16 for(
int p=0;p<
pNPart();p++){
21 else if( p <
pNPart() - 2 )
23 else if( p ==
pNPart() - 2 )
33 else if( p <
pNPart() - 3 )
35 else if( p ==
pNPart() - 3 ){
40 else if( p ==
pNPart() - 2 ){
105 fSLap = -(24.*Sp2.
a4)*QUAD(QUAD(
Dx));
106 fLap = (2.*Sp2.
a2)*QUAD(
Dx);
146 else if( p < NEdge*(c+1) - 3 )
150 else if( p == NEdge*(c+1) - 3 ){
154 else if( p ==
pNPart() - 2 ){
158 fSLap = -(24.*Sp2.
a4)*QUAD(QUAD(
Dx));
159 fLap = (2.*Sp2.
a2)*QUAD(
Dx);
160 if(fLap > 100.)fLap = 100.;
161 if(fLap < -100.)fLap = -100.;
162 if(fSLap > 100.)fSLap = 100.;
163 if(fSLap < -100.)fSLap = -100.;
168 for(
int d=0;d<3;d++){
169 Rad2 += QUAD((
Pm[p].Pos[d] -
Nano->
Pos[d]));
171 if( Rad2 > QUAD((3.*
Nano->
Rad)))
continue;
173 double SenTh = sqrt(1 - QUAD(CosTh));
175 double Rad = sqrt(Rad2);
176 double Strength = 12.*pow( (
Nano->
Rad/Rad) , 13) + 6.*pow( (
Nano->
Rad/Rad) , 7);
180 Fm[p].
Dir[2] =
Kf.
LJ * Strength * SenTh * Sign;
188 for(
int p=0;p<
pNPart();p++){
189 for(
int d=0;d<3;d++){
192 for(
int l=0;l<
Ln[p].
NLink;l++){
194 for(
int d=0;d<3;d++){
195 double Delta = ASS((
Pm[link].Pos[d] -
Pm[p].Pos[d]));
196 if(Delta < 0.001)
continue;
199 if(
Pm[p].Pos[d] <
Pm[link].Pos[d] )
219 for(
int d=0;d<3;d++){
220 Fm[p].
Dir[d] += ForceSp*DistRelBA[d];
221 Fm[p+1].
Dir[d] -= ForceSp*DistRelBA[d];
223 if(p < (c+1)*
pNPCh(b)-2){
225 double CosAngle = 0.;
226 for(
int d=0;d<3;d++){
227 DistRelBA[d] /= DistRelBA[3];
228 DistRelBC[d] /= DistRelBC[3];
229 CosAngle += DistRelBA[d]*DistRelBC[d];
231 double PreFactBA =
pkBen()/DistRelBA[3];
232 double PreFactBC =
pkBen()/DistRelBC[3];
233 for(
int d=0;d<3;d++){
234 Fm[p+0].
Dir[d] += PreFactBA*(DistRelBC[d]-DistRelBA[d]*CosAngle);
235 Fm[p+1].
Dir[d] -= PreFactBA*(DistRelBC[d]-DistRelBA[d]*CosAngle);
236 Fm[p+1].
Dir[d] += PreFactBC*(DistRelBA[d]-DistRelBC[d]*CosAngle);
237 Fm[p+2].
Dir[d] -= PreFactBC*(DistRelBA[d]-DistRelBC[d]*CosAngle);
256 for(
int h = 0;h<HowMany;h++){
257 int link1 =
Ln[pp].
Link[0];
258 int link2 =
Ln[pp].
Link[1];
275 if(
Pm[pp].Pos[2] <0) Sign = -1.;
277 Fm[pp].
Dir[2] *= Sign;
285 for(
int n=0;n<
pNNano();n++){
286 for(
int d=0;d<3;d++){
291 for(
int n=0;n<
pNNano();n++){
292 for(
int nn=n+1;nn<
pNNano();nn++){
293 double dr[3] = {0.,0.,0.};
296 double Cons =
RigidLJ(n,Dist,Pot,0);
297 for(
int d=0;d<3;d++){
305 for(
int d=0;d<3;d++){
316 Vettore PosRel(Pos2[0]-Pos1[0],Pos2[1]-Pos1[1],Pos2[2]-Pos1[2]);
320 double Dist = Perp.
PerpTo(&PosRel,&Axis);
322 AMomTemp.
VetV(&Perp,&PosRel);
325 double HeiOnAxis = Perp.
ProjOnAxis(&PosRel,&Axis);
326 if( fabs(HeiOnAxis) >
Nano[n].Height*.5){
327 double Sign = HeiOnAxis > 0 ? 1. : -1.;
329 for(
int d=0;d<3;d++){
330 dr[d] = Pos2[d] - Pos1[d];
339 for(
int n=0;n<
pNNano();n++){
340 for(
int d=0;d<3;d++){
345 for(
int n=0;n<
pNNano();n++){
347 for(
int p=0;p<
pNPart();p++){
348 double dr[3] = {0.,0.,0.};
351 double Cons =
RigidLJ(n,Dist2,Pot,0);
352 for(
int d=0;d<3;d++){
354 Fm[p].
Dir[d] += Cons*dr[d];
358 for(
int d=0;d<3;d++){
374 for(
int n=0;n<
pNNano();n++){
378 double Dist = sqrt(Dist2);
380 if(t == 1) Sign = 1.;
395 for(
int i=10000;i>0;i--){
396 double x = CutOff/10000.*i;
397 double For =
Potential(SQR(x),0,0,Pot)/x;
407 for(
int n=0;n<
pNNano();n++){
415 for(
int i=10000;i>0;i--){
419 if(For >=
Nano[n].ForThr){
432 for(
int d=0;d<3;d++){
433 dr[d] = Pos2[d] - Pos1[d];
442 if( Dist <
Nano[n].DistThr){
449 double idr2 = idr*idr;
450 double idr4 = idr2*idr2;
451 double idr6 = idr2*idr4;
452 Pot[0] = idr*idr2*(Strength*idr6 +Sign*Hamaker)+
Nano[n].BaseLine;
453 Cons = idr4 *(Strength*9.*idr6+Sign*3.*Hamaker);
454 Pot[1] = idr4 *(Strength*9.*idr6+Sign*3.*Hamaker);
462 double Slope = 1.00203;
463 double Intercept = 0.31739;
464 double Rnp =
Nano[n].
Rad/Slope-Intercept;
465 if( Dr <
Nano[n].DistThr){
470 double DrInv = 1./Dr;
471 double DrP1 = 1./(Dr+Rnp);
472 double DrP3 = CUBE(DrP1);
473 double DrP6 = SQR(DrP3);
474 double DrP9 = DrP6*DrP3;
475 double DrM1 = 1./(-Dr+Rnp);
476 double DrM3 = CUBE(DrM1);
477 double DrM6 = SQR(DrM3);
478 double DrM9 = DrM6*DrM3;
479 double PreRep = Sigma*1./360.*DrInv*SurfTens;
480 double PreAttr = 1./12.*DrInv*SurfTens;
481 double Rep = (9.0*Rnp+Dr)*DrP9 - (9.0*Rnp-Dr)*DrM9;
482 double Attr= (3.0*Rnp+Dr)*DrP3 - (3.0*Rnp-Dr)*DrM3;
483 double RepP = -DrP9+9.*(9.*Rnp+Dr)*DrP9*DrP1
484 -(9.*Rnp+Dr)*DrP9*DrInv;
485 double RepM = -DrM9+9.*(9.*Rnp-Dr)*DrM9*DrM1
486 -(9.*Rnp-Dr)*DrM9*DrInv;
487 double AttrP = -DrP3+3.*(3.*Rnp+Dr)*DrP3*DrP1
488 -(3.*Rnp+Dr)*DrP3*DrInv;
489 double AttrM = -DrM3+3.*(3.*Rnp-Dr)*DrM3*DrM1
490 -(3.*Rnp-Dr)*DrM3*DrInv;
491 double RepChem = 9.*DrP9 - (9.*Rnp+Dr)*9.*DrP9*DrP1
492 - 9.*DrM9 + 9.*(9.*Rnp-Dr)*DrM9*DrM1;
493 double AttrChem = 3.*DrP3 - (3.*Rnp+Dr)*3.*DrP3*DrP1
494 - 3.*DrM9 + 3.*(3.*Rnp-Dr)*DrM3*DrM1;
495 Pot[0] = PreRep*Rep + Sign*PreAttr*Attr +
Nano[n].
BaseLine;
496 Pot[1] = PreRep*RepChem + Sign*PreAttr*AttrChem;
497 Cons = PreRep*(RepP+RepM) + Sign*PreAttr*(AttrP+AttrM);
501 if(Dist < 2.*
Nano[n].Rad)
507 void Forces::PointShape(
int iShape){
509 if(VAR_IF_TYPE(iShape,SHAPE_SPH))
511 if(VAR_IF_TYPE(iShape,SHAPE_CYL))
513 if(VAR_IF_TYPE(iShape,SHAPE_PILL))
515 if(VAR_IF_TYPE(iShape,SHAPE_TILT))
517 if(VAR_IF_TYPE(iShape,SHAPE_WALL))
519 if(VAR_IF_TYPE(iShape,SHAPE_PORE))
521 if(VAR_IF_TYPE(iShape,SHAPE_EXT))
523 if(VAR_IF_TYPE(iShape,SHAPE_JANUS))
525 if(VAR_IF_TYPE(iShape,SHAPE_STALK))
527 if(VAR_IF_TYPE(iShape,SHAPE_TIP))
529 if(VAR_IF_TYPE(iShape,SHAPE_TORUS))
531 if(VAR_IF_TYPE(iShape,SHAPE_HARM))
533 if(VAR_IF_TYPE(iShape,SHAPE_UMBR))
538 double Dist = sqrt(Dist2);
542 Pot[2] = a*Dist2 + b*Dist + c;
543 double For = - 2.*a*Dist2 - b*Dist;
552 double idr6 = CUBE(SQR(
Kf.
LJMin)/Dist2);
553 double idr3 = CUBE(
Kf.
LJMin)/(Dist2*sqrt(Dist2));
560 return Kf.
LJ*idr3*(9.*idr6-3.);
564 return Kf.
LJ*idr3*(9.*idr6+3.);
568 double idr6 = CUBE(SQR(
Kf.
LJMin)/Dist2);
575 return Kf.
LJ*48.*(idr6*idr6-.5*idr6);
579 return Kf.
LJ*48.*(idr6*idr6+.5*idr6);
592 Pot[2] =
Kf.
Ext/Dist2;
594 Pot[2] = -
Kf.
LJ/Dist2;
598 if(!VAR_IF_TYPE(
SysAlloc,ALL_FORCES)){
599 printf(
"Forces not allocated\n");
604 double *Count = (
double *)calloc(NTab*
pNType()*
pNType(),
sizeof(double));
611 for(
int p=0;p<
pNPart();p++){
612 for(
int d=0;d<3;d++){
617 for(
int p1=0;p1<
pNPart();p1++){
620 if(p2 <= p1)
continue;
624 double Dist = sqrt(DistRelBA[3]);
625 for(
int t=0;t<
pNType();t++){
631 int x = (int)(Dist*InvCutOff*NTab);
632 if( x < 0 || x >= NTab)
continue;
633 int t = MIN(
Pm[p1].Typ,
Pm[p2].Typ)*
pNType()+MAX(
Pm[p1].Typ,
Pm[p2].Typ);
636 for(
int d=0;d<3;d++){
637 Fm[p1].
Dir[d] += Force*DistRelBA[d];
638 Fm[p2].
Dir[d] -= Force*DistRelBA[d];
642 for(
int t=0;t<NTab;t++){
643 for(
int t1=0;t1<
pNType();t1++){
644 for(
int t2=0;t2<
pNType();t2++){
645 int tType = MIN(t1,t2)*
pNType()+MAX(t1,t2);
659 for(
int d=0;d<3;d++){
660 Fm[p].
Dir[d] += ForceSp*DistRelBA[d];
661 Fm[p+1].
Dir[d] -= ForceSp*DistRelBA[d];
663 if(p < (c+1)*
pNPCh(b)-2){
665 double CosAngle = 0.;
666 for(
int d=0;d<3;d++){
667 DistRelBA[d] /= DistRelBA[3];
668 DistRelBC[d] /= DistRelBC[3];
669 CosAngle += DistRelBA[d]*DistRelBC[d];
671 double PreFactBA =
pkBen()/DistRelBA[3];
672 double PreFactBC =
pkBen()/DistRelBC[3];
673 for(
int d=0;d<3;d++){
674 Fm[p+0].
Dir[d] -= PreFactBA*(DistRelBC[d]-DistRelBA[d]*CosAngle);
675 Fm[p+1].
Dir[d] += PreFactBA*(DistRelBC[d]-DistRelBA[d]*CosAngle);
676 Fm[p+1].
Dir[d] -= PreFactBC*(DistRelBA[d]-DistRelBC[d]*CosAngle);
677 Fm[p+2].
Dir[d] += PreFactBC*(DistRelBA[d]-DistRelBC[d]*CosAngle);
685 double NPoint = 1000.;
686 FILE *FWrite = fopen(
"Force.dat",
"w");
690 for(
double x=Delta;x<
CutOff;x+=Delta){
691 double Cons =
LJPot(x,0,0,Pot);
692 fprintf(FWrite,
"%lf %lf %lf\n",x,Cons,*Pot);
699 double Delta = sqrt(
Kf.
CutOff2)/(double)NTab;
701 FTab = (
double *)calloc(NTab*
pNType()*
pNType(),
sizeof(double));
702 MTab = (
double *)calloc(NTab,
sizeof(
double));
703 PTab = (
double *)calloc(NTab*
pNType()*
pNType(),
sizeof(double));
704 VAR_ADD_TYPE(DynFlag,ALL_FORCES);
709 double Delta = 2.*NrgLim/(double)NTab;
711 for(
double Nrg=-NrgLim;Nrg<NrgLim;Nrg+=Delta,i++){
713 MTab[i] = exp(-
pTemp()*Nrg);
715 VAR_ADD_TYPE(DynFlag,ALL_METR);
716 VAR_ADD_TYPE(DynFlag,ALL_POT);
719 if(r < 0.0001)
return 0.;
720 return (r < b) ? 15. / (2. * M_PI * CUBE(b)) * SQR(1. - r / b) : 0.;
723 if(r < 0.0001)
return 0.;
724 return (r < b) ? 15. / (M_PI * SQR(SQR(b))) * (r / b - 1.) : 0.;
727 if(r < 0.0001)
return 0.;
729 double Ai = .5 * 15. / M_PI / (CUBE(a) + CUBE(a + b) + CUBE(b));
730 return (r < a) ? Ai : (Ai / CUBE(a - b)) *
731 ((((-2. * r) + 3. * (a + b)) * r - 6. * a * b) * r +
732 3. * a * b * b - b * b * b);
735 if(r < 0.0001)
return 0.;
737 double Ai = 15. / (M_PI * (((((4. * a) + 6.) * a) + 6.) * a + 4.));
738 return (r > a && r < b) ? (6. * Ai / CUBE(a - b) * (-r * r + (a + b) *
void Export(double *x)
Export.
SPLINE Spline4Beg(double *P1, double *P2, double *P3, double *P4, int x, int y)
Four order spline first boundary.
double a4
a0 + a1*x + a2*x^2 + a3*x^3 + a4^4
double LJMin
Lennard-Jones.
double pkBen()
Bending coupling.
double Ext
External force.
double LJPot(double Dist2, int t1, int t2, double *Pot)
Classical Lennard Jones potential.
int NLink
How many links per particle.
int ForceFieldLine()
Helfrich Hamiltonian for a line.
double NanoDist2(double *Pos, int n)
Pointer to a generic function.
LINKS * Ln
Array of linking between the particles.
double RigidCoulomb(int nNano, double Dist, double *Pot, double Sign)
Force between to rigid bodies.
NANO * Nano
Extra particle.
void TabForceAlloc(int NTabExt)
Tabulate the values of the force.
double Gamma
Friction term.
double Hamaker
Strength of the interaction.
double DistThr
Minimum distance threshold.
Geometrical operations on vectors.
double Lap
Prefactor of the Laplacian.
double RigidLJ(int nNano, double Dist, double *Pot, double Sign)
Force between to rigid bodies.
SPLINE Spline3Beg(double *P1, double *P2, double *P3, int x, int y)
Three order spline first boundary.
double Harmonic(double Dist2, int t1, int t2, double *Pot)
Harmonic potential.
int pType(int p)
Return the type.
double DerWei2(const double r, const double b)
Derivative of the quadratic weighting function.
double El[3]
Elastic force.
double PotThr
Maximum potential allowed.
double Pos[3]
xyz Position of the particle
int IfInterp
If interpolates with the splines.
double pkSpr()
Spring coupling.
double pSprRest()
Rest distance of the harmonic potential.
void ForceFieldRod()
Bending potential on a rod.
void Dist2Curr(double *DistRel)
Retrun the squared current interparticle distance.
int SysAlloc
Which arrays are allocated.
void CalcForcesDensFunc()
Calculate the forces for the density functional.
double ElectroPot(double Dist2, int t1, int t2, double *Pot)
Potential for the electrical lines.
void NanoInteraction()
Calculate all the interaction with the nano.
SPLINE Parab2(double *PA, double *PB, double *PC, int x, int y)
Three points parabolic interpolation.
int pNPCh()
Number of particle per chain.
void ForceFieldRigid()
Interaction between rigid bodies.
double DistThr
Correspondent radial distance for this force.
double Dx
Spatial separation between particles.
double pWei3Par()
Parameter of the third order weighting function.
SPLINE Spline4(double *P1, double *P2, double *P3, double *P4, int x, int y)
Four order spline.
double TwoPartDist(int p1, int p2, double *RelDist)
Return the relative distance between two particles (wrapped)
int pNBlock()
Number of blocks.
double NanoNrg(int p)
Exchange energy with the nano.
double BaseLine
Baseline of the potential.
MatInt * MInt
Matrix of the prefactor of the interactions.
int * Link
with whom is bonded
int NEdge
Number of particles per edge.
void TabPot()
Tabulate the values of the potential.
double Casuale()
Random uniform number.
double ProjOnAxis(Vettore *a)
Projects along the axis.
KFORCES Kf
Prefactor of the forces.
void NextCurr()
Increase the iterator to the next couple.
double Zeta
Stochastic term.
double ForThr
Maximum value of the force.
int ForceFieldLeaves()
Helfrich Hamiltonian with an elastic coupling.
void Point2Shape(int iShape)
Point to the shape function.
double CutOff
Cut off of the interactions.
void PrintForce()
Print the force and the potential.
double pWei2Par()
Parameter of the second order weighting function.
int pNNano()
Number of nanoparticles.
double VetV(const Vettore *u, const Vettore *v)
Vectorial product between two Vettore returns the area.
double Coating
Thickness of the LJ well.
int SumSomeForces(int HowMany)
Boh.
double a2
a0 + a1*x + a2*x^2 + a3*x^3 + a4^4
double Coeff(int t1, int t2)
Prefactor of the force.
int ForceFieldBulk()
Armonic potential on a lattice.
SPLINE Spline3End(double *P1, double *P2, int x, int y)
Three order spline last boundary.
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.
double RigidDistanceRad(int n, int nn, double *dr)
Distance between two bodies.
double PotThr
Maximum value of the potential.
void ClearDens()
Set the local densities to zero.
double RigidDistanceAxis(int n, int nn, double *dr)
Distance between two bodies.
Matematica * Mat
Implementation of all usefull algorythms.
int pNType()
of types of the particle
SPLINE Parab(double *P1, double *P2, double *P3, int x, int y)
Three points parabolic interpolation.
double AMom[3]
Angular momentum.
double pPos(int p, int d)
Return back folded position.
double CutOff
Cut off of the potential.
double pTemp()
Temperature.
double DerWei3(const double r, const double a)
Derivative of the cubic weighting function.
int pNChain()
Number of chain.
double AMomTemp[3]
Temporal angular momentum.
int IfCurr()
Tell when the curr loop is over.
double Elong[3]
Elongation of the springs.
SPLINE Spline3(double *P1, double *P2, double *P3, int x, int y)
Three order spline.
double CutOff2
CutOff of the lennard jones.
SPLINE Forth(double *PA, double *PB, double *PC, double *PD, double *PE, int x, int y)
Five points four order interpolation.
int p2Curr
Current particle.
SPLINE Cubica(double *PA, double *PB, double *PC, double *PD, int x, int y)
Four point cubic interpolation.
double SumDens(int pInit, int pEnd)
Sum the local density for the particles between pInit and pEnd and multiply the factors by the virial...
double BaseLine
Baseline of the potential.
PART * Pm
Particle information of all particle.
double RigidHamaker(int n, double Dist, double *Pot, double Sign)
Hamaker potential.
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 SLap
Prefactor of the square laplacian.
void DefNanoForceParam()
Define the parameters for calculating the force.
double ForThr
Maximum force allowed.
int Bead2Move
Bead to move.
FORCES * Fm
Array containing the forces for each particle.
void PerpTo(Vettore *o)
The vector perpendicolar.
int pNPart()
Number of particle.
void DefForceParam()
Define the parameters for calculating the force.