3 if(VAR_IF_TYPE(
SysAlloc,ALL_TENS))
return;
8 Tens.
Dens = (
double **)calloc(2,
sizeof(
double));
49 for(
int p=0;p<
pNPart();p++){
66 for(
int p=0;p<
pNPart();p++){
86 if(!VAR_IF_TYPE(
SysAlloc,ALL_FORCES)){
87 printf(
"Forces not allocated\n");
95 for(
int p=0;p<
pNPart();p++){
102 for(
int p1=0;p1<
pNPart();p1++){
105 if(p2 <= p1)
continue;
108 double Dist = sqrt(DistRelBA[3]);
110 for(
int t=0;t<
pNType();t++){
115 SumTens(p1,p2,Force,DistRelBA);
117 SigErr(Force > 5000.,
"Forces over the limit %lf\n",Force);
118 for(
int d=0;d<3;d++){
119 Fm[p1].
Dir[d] += Force*DistRelBA[d];
120 Fm[p2].
Dir[d] -= Force*DistRelBA[d];
132 SumTens(p,p+1,ForceSp,DistRelBA);
133 for(
int d=0;d<3;d++){
134 Fm[p].
Dir[d] += ForceSp*DistRelBA[d];
135 Fm[p+1].
Dir[d] -= ForceSp*DistRelBA[d];
137 if(p < (c+1)*
pNPCh(b)-2){
139 double CosAngle = 0.;
140 for(
int d=0;d<3;d++){
141 DistRelBA[d] /= DistRelBA[3];
142 DistRelBC[d] /= DistRelBC[3];
143 CosAngle += DistRelBA[d]*DistRelBC[d];
145 double PreFactBA =
pkBen()/DistRelBA[3];
146 double PreFactBC =
pkBen()/DistRelBC[3];
147 for(
int d=0;d<3;d++){
148 Fm[p+0].
Dir[d] += PreFactBA*(DistRelBC[d]-DistRelBA[d]*CosAngle);
149 Fm[p+1].
Dir[d] -= PreFactBA*(DistRelBC[d]-DistRelBA[d]*CosAngle);
150 Fm[p+1].
Dir[d] += PreFactBC*(DistRelBA[d]-DistRelBC[d]*CosAngle);
151 Fm[p+2].
Dir[d] -= PreFactBC*(DistRelBA[d]-DistRelBC[d]*CosAngle);
152 Pre[d ] = DistRelBA[d]*
pkBen()*(DistRelBC[d]-DistRelBA[d]*CosAngle);
153 Pre[d+6] = DistRelBC[d]*
pkBen()*(DistRelBA[d]-DistRelBC[d]*CosAngle);
155 Pre[ 3] = DistRelBA[0]*
pkBen()*(DistRelBC[1]-DistRelBA[1]*CosAngle);
156 Pre[ 4] = DistRelBA[0]*
pkBen()*(DistRelBC[2]-DistRelBA[2]*CosAngle);
157 Pre[ 5] = DistRelBA[1]*
pkBen()*(DistRelBC[2]-DistRelBA[2]*CosAngle);
158 Pre[ 9] = DistRelBC[0]*
pkBen()*(DistRelBA[1]-DistRelBC[1]*CosAngle);
159 Pre[10] = DistRelBC[0]*
pkBen()*(DistRelBA[2]-DistRelBC[2]*CosAngle);
160 Pre[11] = DistRelBC[1]*
pkBen()*(DistRelBA[2]-DistRelBC[2]*CosAngle);
173 for(
int n=0;n<
pNNano();n++){
175 for(
int p=0;p<
pNPart();p++){
178 double InvDist = 1./Dr2;
180 for(
int d=0;d<3;d++){
185 double Norm = SQR(
Nano[n].Rad)/(SQR(dr[0]) + SQR(dr[1]) + SQR(dr[2]));
187 for(
int d=0;d<3;d++){
188 NPos[d] = NPos[d] + dr[d]*Norm;
189 Fm[p].
Dir[d] += Cons*dr[d]*InvDist;
190 Pre[d ] = Cons*dr[d]*dr[d]*InvDist;
192 Pre[3] = Cons*dr[0]*dr[1]*InvDist;
193 Pre[4] = Cons*dr[0]*dr[2]*InvDist;
194 Pre[5] = Cons*dr[1]*dr[2]*InvDist;
200 for(
int d=0;d<3;d++){
210 for(
int d=0;d<2;d++){
214 PosP1[0] = hypot(Pos1[0],Pos1[1]);
215 PosP2[0] = hypot(Pos2[0],Pos2[1]);
218 for(
int d=1;d<2;d++){
230 TensRef(Pos1,Pos2,PosP1,PosP2);
232 double PointInv = 1./(double)NPoint;
238 Pos[d] = PosP1[d] < PosP2[d] ? PosP1[d] : PosP2[d];
239 Deltav[d] = fabs((PosP2[d]-PosP1[d])*PointInv);
241 if( fabs(PosP2[d] - PosP1[d]) >
Tens.
Edge[d]*.5){
242 Deltav[d] = -fabs((MAX(PosP1[d],PosP2[d])-
Tens.
Edge[d]-Pos[d])*PointInv);
246 for(
int p=0;p<NPoint;p++){
250 if(vCurr[d] < 0 || vCurr[d] >=
Tens.
NSlab)
return;
267 Tens.
Pre[c][vTot] += Pre[c]*PointInv;
272 if(fabs(Force) < 0.)
return;
273 if(fabs(Force) > 5000.)
return;
275 double InvDist = Force/DistRel[3];
276 Pre[0] = DistRel[0]*DistRel[0]*InvDist;
277 Pre[1] = DistRel[1]*DistRel[1]*InvDist;
278 Pre[2] = DistRel[2]*DistRel[2]*InvDist;
279 Pre[3] = DistRel[0]*DistRel[1]*InvDist;
280 Pre[4] = DistRel[0]*DistRel[2]*InvDist;
281 Pre[5] = DistRel[1]*DistRel[2]*InvDist;
285 int link[4] = {0,0,0,0};
287 double *VolContr = (
double *)calloc(
Tens.
NSlab,
sizeof(
double));
289 for(
int sr=1,p=0,c=0;sr<
Tens.
NSlab;sr++){
295 double Press = -
Tens.
Pre[Comp][v]*InvNFile/VolContr[sr];
296 double Dens1 =
Tens.
Dens[0][v]*InvNFile/VolContr[sr];
297 double Dens2 =
Tens.
Dens[1][v]*InvNFile/VolContr[sr];
298 fprintf(FWrite,
"{x(%.3f %.3f %.3f) v( %lf %.2f %.2f)}\n",r,z,0.,Press,Dens1,Dens2);
continue;
303 for(
int lx=0;lx<2;lx++){
304 for(
int ly=0;ly<2;ly++){
306 int l1 = p + (p+1)%4;
307 int l2 = p + (p+2)%4;
308 int l3 = p + (p+3)%4;
309 fprintf(FWrite,
"{t[%d %d %d]",p,c,0);
310 fprintf(FWrite,
" x(%.3f %.3f %.3f)",r,z,Press);
311 fprintf(FWrite,
" v( %lf %.2f %.2f)",Press,Dens1,Dens2);
315 fprintf(FWrite,
" l[%d] l[%d] l[%d]}\n",l1,l2,l3);
329 MPI_Allreduce(MPI_IN_PLACE,
Tens.
Pre[Comp],SQR(
Tens.
NSlab),MPI_DOUBLE,MPI_SUM,Proc->CommGrid);
330 for(
int t=0;t<2;t++){
331 MPI_Allreduce(MPI_IN_PLACE,
Tens.
Dens[t],SQR(
Tens.
NSlab),MPI_DOUBLE,MPI_SUM,Proc->CommGrid);
334 MPI_Comm_rank(Proc->CommGrid, &Rank);
337 FILE *FWrite = fopen(FTens,
"w");
351 MPI_Allreduce(MPI_IN_PLACE,
Tens.
Pre[Comp],CUB(
Tens.
NSlab),MPI_DOUBLE,MPI_SUM,Proc->CommGrid);
352 for(
int t=0;t<2;t++){
353 MPI_Allreduce(MPI_IN_PLACE,
Tens.
Dens[t],CUB(
Tens.
NSlab),MPI_DOUBLE,MPI_SUM,Proc->CommGrid);
356 MPI_Comm_rank(Proc->CommGrid, &Rank);
359 FILE *FWrite = fopen(FTens,
"w");
369 fprintf(FWrite,
"{x(%.3f %.3f %.3f)",x,y,z);
370 fprintf(FWrite,
" v( %lf %.2f %.2f)}\n",
371 -
Tens.
Pre[Comp][v]*InvNFile*InvVolume,
373 Tens.
Dens[1][v]*InvNFile*InvVolume);
void CalcTens()
Calculate the forces for the tension profile.
TENS_REF Tens_Ref
Pointer to a coordinate distance.
double pkBen()
Bending coupling.
void WriteTens(char *TFile, int Comp, double InvNFile)
Write the pressure and density profile.
double NanoDist2(double *Pos, int n)
Pointer to a generic function.
double prho()
Density coexistence.
double ** Pre
Pressure array.
NANO * Nano
Extra particle.
void WriteTens2d(FILE *FWrite, int Comp, double InvNFile)
Write the 2d pressure profile.
double pInvEdge(int d)
Inverted xyzr edges of the simulation box.
int pType(int p)
Return the type.
int CLat2
lateral coordinate
double DerWei2(const double r, const double b)
Derivative of the quadratic weighting function.
double pkSpr()
Spring coupling.
double pSprRest()
Rest distance of the harmonic potential.
int Wrap[3]
Which coordinate to wrap.
double TensRef(double *Pos1, double *Pos2, double *PosP1, double *PosP2)
Particle positions back folded on the tension reference point.
void Dist2Curr(double *DistRel)
Retrun the squared current interparticle distance.
int SysAlloc
Which arrays are allocated.
double pVol()
xyzr edges of the simulation box
double TensRefPol(double *Pos1, double *Pos2, double *PosP1, double *PosP2)
Particle positions back folded on the tension reference point (polar coordinates) ...
double pNanoPos(int n, int d)
Return back folded nano position.
double pEdge(int d)
xyzr edges of the simulation box
int pNPCh()
Number of particle per chain.
double RefPos[3]
Reference point.
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)
int pNBlock()
Number of blocks.
void SumTens(int p1, int p2, double Forces, double *DistRel)
Sum the forces on the line joining the points p1 and p2.
MatInt * MInt
Matrix of the prefactor of the interactions.
KFORCES Kf
Prefactor of the forces.
void NextCurr()
Increase the iterator to the next couple.
void Point2Shape(int iShape)
Point to the shape function.
double EdgeInv[3]
Inverse of the edges.
double pWei2Par()
Parameter of the second order weighting function.
int pNNano()
Number of nanoparticles.
double Coeff(int t1, int t2)
Prefactor of the force.
double Potential(double Dist, int t1, int t2, double *Pot)
Pointer to a potential.
int CalcMode
Calculation mode.
double ** Dens
Density array.
void ClearDens()
Set the local densities to zero.
void AllocTens()
Alloc the pressure profile.
int pNType()
of types of the particle
double pPos(int p, int d)
Return back folded position.
double DerWei3(const double r, const double a)
Derivative of the cubic weighting function.
int pNChain()
Number of chain.
int CLat1
lateral coordinate
int IfCurr()
Tell when the curr loop is over.
double CutOff2
CutOff of the lennard jones.
int p2Curr
Current particle.
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.
void SetCurr(int p)
Gather information of the neighbouring cells.
TENS Tens
Structure for the pressure calculation.
void VolumeCircSlab(double *VolContr, int NSample)
Fill an array of.
double TensRefCart(double *Pos1, double *Pos2, double *PosP1, double *PosP2)
Particle positions back folded on the tension reference point (Cartesian coordinates) ...
void SetEdge(double Val, int d)
Set Edge.
FORCES * Fm
Array containing the forces for each particle.
int CNorm
Normal coordinate.
int pNPart()
Number of particle.