26 #include "../include/VarData.h" 29 if(VAR_IF_TYPE(
SysType,VAR_CHAIN_DEF)){
30 for(
int c=0,b=0;c<Gen->
NChain;c++){
41 double *xc = (
double *)calloc(
pNPCh(b),
sizeof(double));
42 double *yc = (
double *)calloc(
pNPCh(b),
sizeof(double));
43 double *zc = (
double *)calloc(
pNPCh(b),
sizeof(double));
45 int ChType = CHAIN_POLY;
46 if(
Block[b].Asym == 0) ChType = CHAIN_ADDED;
50 if(
Block[b].Asym == 0){
51 VAR_ADD_TYPE(
Ch[c].Type,CHAIN_ADDED);
58 for(
int p=p1;p<p1+
pNPCh(b);p++){
68 for(
int ppc=0;ppc<
pNPCh(b);ppc++){
69 xc[ppc] =
Pm[p1+ppc].
Pos[0];
70 yc[ppc] =
Pm[p1+ppc].
Pos[1];
71 zc[ppc] =
Pm[p1+ppc].
Pos[2];
75 double x1 =
Pm[p1].
Pos[2]*rzx.
m + rzx.
q;
77 double y1 =
Pm[p1].
Pos[2]*rzy.
m + rzy.
q;
80 Ch[c].
Dir[1] = y1 - y2;
81 Ch[c].
Dir[0] = x1 - x2;
83 Ch[c].Angle = Ax0.
Angle(&Ax2,&ChDir);
84 if(
Ch[c].Angle > .5*M_PI)
85 VAR_ADD_TYPE(
Ch[c].Type,CHAIN_UP);
87 VAR_ADD_TYPE(
Ch[c].Type,CHAIN_DOWN);
89 double Angle = Origin.
Angle(&ChDir);
91 VAR_ADD_TYPE(
Ch[c].Type,CHAIN_OUTER);
93 VAR_ADD_TYPE(
Ch[c].Type,CHAIN_INNER);
99 VAR_ADD_TYPE(
SysType,VAR_CHAIN_DEF);
104 for(
int n=0;n<
pNNano();n++){
105 if(
Nano[n].Shape != SHAPE_CLUSTER)
continue;
107 for(
int b=0;b<Gen->
NBlock;b++){
108 if(!strncmp(
Block[b].Name,
"PEP",3)){
117 double Cm[3] = {0.,0.,0.};
119 double *xc = (
double *)calloc(
pNPCh(nBlock),
sizeof(double));
120 double *yc = (
double *)calloc(
pNPCh(nBlock),
sizeof(double));
121 double *zc = (
double *)calloc(
pNPCh(nBlock),
sizeof(double));
122 for(
int ppc=0;ppc<
pNPCh(nBlock);ppc++){
123 xc[ppc] =
Pm[p1+ppc].
Pos[0];
124 yc[ppc] =
Pm[p1+ppc].
Pos[1];
125 zc[ppc] =
Pm[p1+ppc].
Pos[2];
129 double x1 =
Pm[p1].
Pos[2]*rzx.
m + rzx.
q;
130 double x2 =
Pm[p1+
pNPCh(nBlock)-1].
Pos[2]*rzx.
m + rzx.
q;
131 double y1 =
Pm[p1].
Pos[2]*rzy.
m + rzy.
q;
132 double y2 =
Pm[p1+
pNPCh(nBlock)-1].
Pos[2]*rzy.
m + rzy.
q;
137 for(
int d=0;d<3;d++) Cm[d] +=
Pm[p].Pos[d];
140 for(
int d=0;d<3;d++)
Nano[n].Pos[d] = Cm[d]/NCm;
143 for(
int d=0;d<3;d++){
145 Norm += SQR(
Nano[n].Axis[d]);
148 for(
int d=0;d<3;d++){
158 if( VAR_IF_TYPE(
SysType,VAR_EDGE) )
return 0;
159 Edge[0][0] =
Pm[0].
Pos[0];Edge[0][1] =
Pm[0].
Pos[0];
160 Edge[1][0] =
Pm[0].
Pos[1];Edge[1][1] =
Pm[0].
Pos[1];
161 Edge[2][0] =
Pm[0].
Pos[2];Edge[2][1] =
Pm[0].
Pos[2];
162 for(
int p=0;p<Gen->
NPart;p++){
163 for(
int d=0;d<3;d++){
164 if(Edge[d][1] <
Pm[p].Pos[d] )
165 Edge[d][1] =
Pm[p].
Pos[d];
166 if(Edge[d][0] >
Pm[p].Pos[d])
167 Edge[d][0] =
Pm[p].
Pos[d];
171 SetEdge(Edge[d][1] - Edge[d][0],d);
173 VAR_ADD_TYPE(
SysType,VAR_EDGE);
178 if(BackFold == BF_SKIP) return ;
182 for(
int d=0;d<3;d++){
185 for(
int c=0;c<Gen->
NChain;c++){
186 for(
int d=0;d<3;d++){
187 Ch[c].
Pos[d] -= Shift[d];
191 if(BackFold == BF_CHAIN){
193 for(
int p=0;p<Gen->
NPart;p++){
194 for(
int d=0;d<3;d++){
195 Pm[p].
Pos[d] -= Shift[d];
199 for(
int c=0;c<Gen->
NChain;c++){
200 for(
int d=0;d<3;d++){
205 else if(BackFold == BF_PART){
206 for(
int p=0;p<Gen->
NPart;p++){
207 for(
int d=0;d<3;d++){
208 Pm[p].
Pos[d] -= Shift[d];
213 else if(BackFold == BF_NANO){
214 for(
int d=0;d<3;d++){
218 for(
int p=0;p<Gen->
NPart;p++){
219 for(
int d=0;d<3;d++){
220 Pm[p].
Pos[d] -= Shift[d];
225 else if(BackFold == BF_TILT){
227 for(
int d=0;d<3;d++){
239 double Angle = Ex.
Angle(&NanoAx);
240 if(isnan(Angle)) Angle = 0.;
247 for(
int p=0;p<
pNPart();p++){
248 for(
int d=0;d<3;d++){
251 for(
int r=0;r<NRow;r++){
253 for(
int c=0;c<NRow;c++)
254 Temp += M.
Val(r,c)*PosOld.
Val(c);
258 for(
int d=0;d<3;d++){
266 for(
int n=0;n<MAX(1,Gen->NNano);n++){
267 for(
int d=0;d<3;d++){
275 if(How == VAR_OPPOSED){
278 sprintf(
Block[0].Name,
"Lower1");
279 sprintf(
Block[1].Name,
"Upper1");
280 sprintf(
Block[2].Name,
"Lower2");
281 sprintf(
Block[3].Name,
"Upper2");
283 else if(How == VAR_VESICLE || How == VAR_TUBE){
286 sprintf(
Block[0].Name,
"Inner");
287 sprintf(
Block[1].Name,
"Outer");
293 for(
int b=1;b<Gen->
NBlock;b++){
299 for(
int b=0;b<Gen->
NBlock;b++)
305 if(How == BF_SKIP)
return 0;
310 for(
int p=0;p<Gen->
NPart;p++)
312 Pm[p].Bkf[d] = -floor(
Pm[p].Pos[d]/Gen->
Edge[d])*Gen->
Edge[d];
313 else if(How == BF_CHAIN)
314 for(
int p=0;p<Gen->
NPart;p++){
316 if(c < 0 || c >= Gen->
NChain)
continue;
318 Pm[p].Bkf[d] = -floor(
Ch[c].Pos[d]/Gen->
Edge[d])*Gen->
Edge[d];
320 else if(How == BF_NANO)
321 for(
int p=0;p<Gen->
NPart;p++)
323 Pm[p].Pos[d] += ShiftNano[d];
329 if(How == SHIFT_NO)
return 0;
330 double Shift[3] = {0.,0.,0.};
335 for(
int p=0;p<Gen->NPart;p++){
340 for(
int d=0;d<3;d++){
341 Gen->
Cm[d] /= (double)Gen->
NPart;
342 Shift[d] = (Gen->
Edge[d]*.5-Gen->
Cm[d]);
347 else if(How == SHIFT_NANO){
348 for(
int d=0;d<3;d++){
354 else if(How == SHIFT_CM_NANO){
357 for(
int p=0;p<Gen->NPart;p++){
362 Gen->
Cm[2] /= (double)Gen->
NPart;
363 for(
int d=0;d<3;d++){
364 Shift[d] = (Gen->
Edge[d]*.5 - Gen->
Cm[d]);
365 if(d < 2)
Nano->
Pos[d] += Shift[d];
370 for(
int p=0;p<Gen->
NPart;p++){
377 Pm[p].
Pos[0] += Shift[0];
378 Pm[p].
Pos[1] += Shift[1];
379 Pm[p].
Pos[2] += Shift[2];
385 double *Count =
new double[NBin];
386 double *LineS =
new double[NBin];
387 for(
int b=0;b<NBin;b++){
394 for(
int p=0;p<
pNPart();p++){
395 if(
Pm[p].Pos[2] < .02*
pEdge(2))
continue;
397 if(b<0 || b >= NBin)
continue;
398 double Weight =
Pm[p].
Pos[2];
402 for(
int b=0;b<NBin;b++){
403 Line[b] /= Count[b] > 0. ? Count[b] : 1.;
406 for(
int v=0;v<NBin;v++) LineS[v] = Line[v];
408 for(
int v=0;v<NBin;v++) LineS[v] = Line[v];
444 fftw_complex *FouOut = (fftw_complex *)fftw_malloc(NBin*
sizeof(fftw_complex));
445 fftw_complex *FouIn = (fftw_complex *)fftw_malloc(NBin*
sizeof(fftw_complex));
446 fftw_plan direct = fftw_plan_dft_1d(NBin,
447 FouIn,FouOut,FFTW_FORWARD,FFTW_PATIENT);
448 fftw_plan reverse = fftw_plan_dft_1d(NBin,
449 FouOut,FouIn,FFTW_BACKWARD,FFTW_PATIENT);
450 for(
int b=0;b<NBin;b++) FouIn[b][0] = Line[b];
451 fftw_execute(direct);
453 for(
int b=NBin-1;b>=NComp;b--){
457 fftw_execute(reverse);
458 for(
int b=0;b<NBin;b++) Line[b] = FouIn[b][0]/(
double)NBin;
462 FILE *FOut = fopen(
"BackBone.dat",
"w");
465 for(
int p=0;p<
pNPart();p++){
466 if(
Pm[p].Pos[2] < .02*
pEdge(2))
continue;
470 for(
int b=0;b<NBin;b++){
471 double x = (b+.5) *
pEdge(
CLat1)/(double)NBin;
473 fprintf(FOut,
"{t[0 0 1] x(%lf %lf 0.) l[%d]} \n",x,Line[b],NPart+1);
478 FILE *FOut1 = fopen(
"LineProf.dat",
"w");
479 for(
int b=0;b<NBin;b++){
480 double x = (b+.5) *
pEdge(
CLat1)/(double)NBin;
482 fprintf(FOut1,
"%lf %lf\n",x,Line[b]);
493 double *CountStalk = (
double *)calloc(NBin,
sizeof(
double));
502 double InvNSample = 1./(double)NSample;
503 double **PlotUp = (
double **)calloc(NSample,
sizeof(
double));
504 double **PlotUpS = (
double **)calloc(NSample,
sizeof(
double));
505 double **CountUp = (
double **)calloc(NSample,
sizeof(
double));
506 double **PlotDown = (
double **)calloc(NSample,
sizeof(
double));
507 double **PlotDownS = (
double **)calloc(NSample,
sizeof(
double));
508 double **CountDown = (
double **)calloc(NSample,
sizeof(
double));
509 double *LineS = (
double *)calloc(NBin,
sizeof(
double));
510 for(
int s=0;s<NSample;s++){
511 PlotUp[s] = (
double *)calloc(NSample,
sizeof(
double));
512 PlotUpS[s] = (
double *)calloc(NSample,
sizeof(
double));
513 CountUp[s] = (
double *)calloc(NSample,
sizeof(
double));
514 PlotDown[s] = (
double *)calloc(NSample,
sizeof(
double));
515 PlotDownS[s] = (
double *)calloc(NSample,
sizeof(
double));
516 CountDown[s] = (
double *)calloc(NSample,
sizeof(
double));
518 for(
int vx=0;vx<NBin;vx++){
526 if(!VAR_IF_TYPE(
Ch[
Pm[p].CId].Type,CHAIN_UP))
continue;
527 if(
Pm[p].Typ == 0)
continue;
533 CountDown[sx][sy] += 1.;
540 if(!VAR_IF_TYPE(
Ch[
Pm[p].CId].Type,CHAIN_DOWN))
continue;
541 if(
Pm[p].Typ == 0)
continue;
548 CountUp[sx][sy] += 1.;
551 for(
int sx=0;sx<NSample;sx++){
552 for(
int sy=0;sy<NSample;sy++){
553 PlotUp[sx][sy] /= CountUp[sx][sy] > 0. ? CountUp[sx][sy] : 1.;
554 PlotDown[sx][sy] /= CountDown[sx][sy] > 0. ? CountDown[sx][sy] : 1.;
559 for(
int sx=0;sx<NSample;sx++){
560 for(
int sy=0;sy<NSample;sy++){
561 PlotUpS[sx][sy] = PlotUp[sx][sy];
562 PlotDownS[sx][sy] = PlotDown[sx][sy];
566 double AngleMax = 1./(.5*M_PI);
567 for(
int p=0;p<
pNPart();p++){
568 if(
Pm[p].Typ == 1)
continue;
570 if(sx < 0 || sx >= NSample)
continue;
572 if(sy < 0 || sy >= NSample)
continue;
573 if(
Pm[p].Pos[
CNorm] > PlotUpS[sx][sy] ||
Pm[p].Pos[
CNorm] < PlotDownS[sx][sy])
continue;
575 if(vx < 0 || vx >= NBin)
continue;
578 double Angle = Ax0.
Angle(&Ax2,&ChDir);
579 if(Angle < .7 || Angle > 2.3)
continue;
582 CountStalk[vx] += Weight;
584 for(
int vx=0;vx<NBin;vx++){
585 Line[vx] /= CountStalk[vx] > 0. ? CountStalk[vx] : 1.;
589 for(
int v=0;v<NBin;v++) LineS[v] = Line[v];
591 for(
int v=0;v<NBin;v++) LineS[v] = Line[v];
599 for(
int i=0;i<NIter;i++){
600 for(
int v=0;v<NBin;v++){
606 for(
int p=0;p<
pNPart();p++){
607 if(
Pm[p].Typ == 1)
continue;
609 if(sx < 0 || sx >= NSample)
continue;
611 if(sy < 0 || sy >= NSample)
continue;
612 if(
Pm[p].Pos[
CNorm] > PlotUpS[sx][sy] ||
Pm[p].Pos[
CNorm] < PlotDownS[sx][sy])
continue;
614 if(vx < 0 || vx >= NBin)
continue;
615 double Dist = SQR(
Pm[p].Pos[
CLat1] - LineS[vx]);
616 if(Dist > SQR(3.))
continue;
617 double Weight = 100.*(1. - SQR((
Pm[p].Pos[
CLat1]-LineS[vx])*NormDist));
619 CountStalk[vx] += Weight;
622 for(
int vx=0;vx<NBin;vx++){
623 Line[vx] /= CountStalk[vx] > 0. ? CountStalk[vx] : 1.;
628 for(
int v=0;v<NBin;v++) LineS[v] = Line[v];
630 for(
int v=0;v<NBin;v++) LineS[v] = Line[v];
640 FILE *F2Write = fopen(
"TwoMid.dat",
"w");
641 FILE *FWrite = fopen(
"StalkLine.dat",
"w");
642 FILE *FWrite1 = fopen(
"StalkLine1.dat",
"w");
643 fprintf(F2Write,
"#l(%lf %lf %lf) v[%d] d[part]\n",
pEdge(0),
pEdge(1),
pEdge(2),NSample);
645 WriteSurf(F2Write,PlotDownS,NSample,SQR(NSample));
646 for(
int p=0;p<
pNPart();p++){
647 if(
Pm[p].Typ == 1)
continue;
649 if(sx < 0 || sx >= NSample)
continue;
651 if(sy < 0 || sy >= NSample)
continue;
652 if(
Pm[p].Pos[
CNorm] > PlotUpS[sx][sy] ||
Pm[p].Pos[
CNorm] < PlotDownS[sx][sy])
continue;
655 double Angle = Ax0.
Angle(&Ax2,&ChDir);
656 if(Angle < .7 || Angle > 2.3)
continue;
657 fprintf(F2Write,
"{t[0 0 1] x(%lf %lf %lf)}\n",
Pm[p].Pos[0],
Pm[p].Pos[1],
Pm[p].Pos[2]);
658 fprintf(FWrite,
"%lf %lf \n",
Pm[p].Pos[1],
Pm[p].Pos[0]);
660 for(
int vx=0;vx<NBin;vx++){
661 fprintf(FWrite1,
"%lf %lf \n",vx*
pEdge(
CLat2)/(
double)NBin,Line[vx]);
667 for(
int s=0;s<NSample;s++){
688 double CountStalk = 1.;
690 if(strncmp(
Block[b].Name,
"TT",2))
continue;
693 double Angle = Ax0.
Angle(&Ax2,&ChDir);
694 if(
Ch[c].Pos[2] < OldPos[2] - 1.5 ||
Ch[c].Pos[2] > OldPos[2] + 1.5)
continue;
695 if(Angle < 1. || Angle > 2.)
continue;
698 if(
Pm[p].Typ == 1)
continue;
699 for(
int d=0;d<3;d++){
700 Dist[d] =
Pm[p].
Pos[d] - OldPos[d];
703 Dist[3] = (SQR(Dist[0])+SQR(Dist[1])+SQR(Dist[2]));
704 double Weight = .00001/(Dist[3]*SQR(Angle-.5*M_PI));
706 if(Weight > 1.)
continue;
708 for(
int d=0;d<3;d++){
709 CmStalk[d] +=
Pm[p].
Pos[d]*Weight;
711 CountStalk += Weight;
715 if(CountStalk <= 0.) CountStalk = 1.;
716 for(
int d=0;d<3;d++){
717 CmStalk[d] /= CountStalk;
722 int NGrid = NSample-1;
723 double VolEl =
pVol()/(double)CUB(NSample);
724 double *Plot3d = (
double *)calloc(CUBE(NSample),
sizeof(double));
725 double *Plot2d = (
double *)calloc(SQR(NGrid),
sizeof(double));
728 double CountStalk = 0.;
731 for(
int d=0;d<3;d++) CmStalk[d] = 0.;
732 for(
int p=0;p<
pNPart();p++){
737 int sx = (int)(Posx*
pInvEdge(0)*NSample);
738 int sy = (int)(Posy*
pInvEdge(1)*NSample);
739 int sz = (int)(Posz*
pInvEdge(2)*NSample);
740 int sTot = (sx*NSample+sy)*NSample+sz;
741 Plot3d[sTot] += VolEl;
743 if(Max < Plot3d[sTot]) Max = Plot3d[sTot];
744 if(Min > Plot3d[sTot]) Min = Plot3d[sTot];
746 double IsoLevel = .1*Max;
750 for(
int gx=0;gx<NGrid;gx++){
751 for(
int gy=0;gy<NGrid;gy++){
752 Plot2d[gx*NGrid+gy] = 1.;
755 for(
int t=0;t<NTri;t++){
756 for(
int v=0;v<3;v++){
757 for(
int d=0;d<3;d++){
758 Dist[d] = OldPos[d] - Triang[t].
p[v].
x[d];
760 Dist[3] = SQR(Dist[0])+SQR(Dist[1])+SQR(Dist[2]);
763 if(gx < 0 || gx >= NGrid)
continue;
764 if(gy < 0 || gy >= NGrid)
continue;
765 Plot2d[gx*NGrid+gy] += sqrt(Dist[3]);
772 FILE *Ciccia = fopen(
"Ciccia.dat",
"w");
773 for(
int gx=0;gx<NGrid;gx++){
774 double x = gx/(double)NGrid*
pEdge(
CLat1) + Dx;
775 for(
int gy=0;gy<NGrid;gy++){
776 double y = gy/(double)NGrid*
pEdge(
CLat1) + Dy;
777 double Weight = 1./(Plot2d[gx*NGrid+gy]);
778 fprintf(Ciccia,
"%lf %lf %lf\n",x,y,Weight*10000.);
784 for(
int gx=0;gx<NGrid;gx++){
785 double x = gx/(double)NGrid*
pEdge(
CLat1) + Dx;
786 for(
int gy=0;gy<NGrid;gy++){
787 double y = gy/(double)NGrid*
pEdge(
CLat1) + Dy;
788 double Weight = 1./(Plot2d[gx*NGrid+gy]*SQR(x-OldPos[0])*SQR(y-OldPos[1]));
789 CmStalk[
CLat1] += x*Weight;
790 CmStalk[
CLat2] += y*Weight;
791 CountStalk += Weight;
795 CmStalk[0] /= CountStalk;
796 CmStalk[1] /= CountStalk;
805 double kElPhob = 40000.;
806 double kElPhil = -1.;
813 double GainRad = 100.;
814 double GainHei = 2000.;
815 double MoveStep = .05;
816 double RadStep = .01;
819 double *Count = (
double *)calloc(NBin*NBin,
sizeof(
double));
821 for(
int d=0;d<3;d++)
Nano->
Pos[d] = OldPos[d];
822 Nano->
Rad = MAX(MIN(RadMax,OldPos[3] + 1.0 ),RadMin);
823 Nano->
Height = MAX(MIN(HeiMax,OldPos[4] + 0.),HeiMin);
825 for(
int p=0;p<
pNPart();p++){
827 if(Dist2 > SQR(2.*
Nano->
Rad))
continue;
828 if(
Pm[p].Typ == 0) OldNrg += kElPhob*Dist2;
829 if(
Pm[p].Typ == 1) OldNrg += kElPhil*Dist2;
833 for(
int i=0;i<NInt;i++){
836 for(
int m=0;m<3;m++){
839 for(
int d=0;d<3;d++){
860 for(
int p=0;p<
pNPart();p++){
862 if(Dist2 > SQR(2.*
Nano->
Rad))
continue;
863 if(
Pm[p].Typ == 0) Nrg += kElPhob*Dist2;
864 if(
Pm[p].Typ == 1) Nrg += kElPhil*Dist2;
870 printf(
"NewNrg \t%lf Rad ___ Hei ___ Pos %.2f %.2f %.2f\n",Nrg-OldNrg,
Nano->
Pos[0]-OldNPos[0],
Nano->
Pos[1]-OldNPos[1],
Nano->
Pos[2]-OldNPos[2]);
873 printf(
"NewNrg \t%lf Rad %.3f Hei ___ Pos ___ ___ ___\n",Nrg-OldNrg,
Nano->
Rad);
876 printf(
"NewNrg \t%lf Rad ___ Hei %.3f Pos ___ ___ ___\n",Nrg-OldNrg,
Nano->
Height);
882 for(
int d=0;d<3;d++){
900 for(
int p=0;p<
pNPart();p++){
901 if(
Pm[p].Typ == 1)
continue;
903 for(
int d=0;d<3;d++){
907 double Rad = sqrt( SQR(Pos[
CLat1]) + SQR(Pos[
CLat2]) );
909 for(
int d=0;d<3;d++){
910 Cm[d] +=
Pm[p].
Pos[d];
916 if(vx < 0 || vx >= NBin)
continue;
919 if(vy < 0 || vy >= NBin)
continue;
920 Count[vx*NBin+vy] += 1.;
923 for(
int vx=0;vx<NBin;vx++){
924 for(
int vy=0;vy<NBin;vy++){
925 if(Count[vx*NBin+vy] < 1.)
continue;
930 printf(
"No particles in the torus\n");
934 for(
int d=0;d<3;d++){
948 double CountStalk = 0.;
953 for(
int t=0;t<NTri;t++){
954 for(
int v=0;v<3;v++){
955 int vCurr = Triang[t].
v[v];
956 VList.
Add(vCurr,t,Triang[t].p[v].x);
961 for(
int t=0;t<NTri;t++){
962 for(
int v=0;v<3;v++){
963 int vCurr = Triang[t].
v[v];
968 for(
int d=0;d<3;d++){
969 n1.
Set(
Pm[p].Vel[d],d);
971 if(n1.
Norm() <= 0.)
continue;
972 Weight += n2.
Angle(&Ax,&n1);
974 WeightL[vCurr] = Weight;
975 if(Max < Weight) Max = Weight;
983 int *Exist = (
int *)calloc(NGrid*NGrid,
sizeof(
int));
986 double InvNGrid = 1./(double)NGrid;
987 for(
int t=0;t<NTri;t++){
988 for(
int v=0;v<2;v++){
989 int vx = (int)(Triang[t].p[v].x[0]*
pEdge(0)*InvNGrid);
990 int vy = (int)(Triang[t].p[v].x[1]*
pEdge(1)*InvNGrid);
991 int vv = vx*NGrid+vy;
993 if(Exist[vv] > 1)
continue;
994 Pc->
AddPart(NPart,Triang[t].p[v].x);
995 for(
int d=0;d<3;d++)
Pm[NPart].Pos[d] = Triang[t].p[v].x[d];
1000 for(
int p=0;p<
pNPart();p++){
1008 for(
int p=0,c=0;p<
pNPart();p++){
1016 for(
int p=pList[0],c=0;c<4;c++,p=pList[c]){
1017 sprintf(FName,
"Chain%d.dat",c);
1018 FILE *FChain = fopen(FName,
"w");
1019 fprintf(FChain,
"%lf %lf\n",
Pm[p].Pos[0],
Pm[p].Pos[1]);
1021 for(
int p1=0;p1<
pNPart();p1++){
1023 if(p1 == Pc->
p2Curr)
continue;
1026 fprintf(FChain,
"%lf %lf\n",
Pm[p1].Pos[0],
Pm[p1].Pos[1]);
1038 int *Called = (
int *)calloc(
pNPart(),
sizeof(int));
1039 int *Exist = (
int *)calloc(NGrid*NGrid,
sizeof(
int));
1040 double *DirPrev = (
double *)calloc(3*
pNPart(),
sizeof(int));
1043 double InvNGrid = 1./(double)NGrid;
1045 for(
int t=0;t<NTri;t++){
1046 for(
int v=0;v<2;v++){
1047 int vx = (int)(Triang[t].p[v].x[0]*
pEdge(0)*InvNGrid);
1048 int vy = (int)(Triang[t].p[v].x[1]*
pEdge(1)*InvNGrid);
1049 int vv = vx*NGrid+vy;
1051 if(Exist[vv] > 1)
continue;
1052 Pc->
AddPart(NPart,Triang[t].p[v].x);
1053 for(
int d=0;d<3;d++)
Pm[NPart].Pos[d] = Triang[t].p[v].x[d];
1058 for(
int p=0;p<
pNPart();p++){
1071 for(
int p=0;p<
pNPart();p++){
1073 double Closest = 1000000.;
1077 if(link == p)
continue;
1078 if(
Ln[link].Link[0] == p)
continue;
1080 double Weight = DirPrev[link*3+0]*DistRel[0] + DirPrev[link*3+1]*DistRel[1];
1081 if(Weight >= 0.) Weight = 0.9;
1082 else if(Weight < 0.) Weight = 1.1;
1083 if(DistRel[3]*Weight < Closest){
1084 Closest = DistRel[3];
1086 for(
int d=0;d<3;d++){
1087 DirPrev[3*p+d] = DistRel[d];
1095 Ln[p].
Link[0] = pClosest;
1096 Exist[pClosest] += 1;
1097 if(Exist[pClosest] > 1 &&
Ln[pClosest].NLink == 1)
Ln[p].
NLink = 0;
1100 for(
int p=0;p<
pNPart();p++){
1101 int link =
Ln[p].
Link[0];
1102 if(
Pm[p].CId > NChain){
1109 for(
int p=
pNPart();p>=0;p--){
1110 int link =
Ln[p].
Link[0];
1111 if(
Pm[p].CId > NChain){
1118 for(
int p=0;p<
pNPart();p++){
1119 int link =
Ln[p].
Link[0];
1120 if(
Pm[p].CId > NChain){
1137 for(
int p=0;p<
pNPart()-1;p++){
1138 if(
Ln[p].NLink == 0)
continue;
1139 int link =
Ln[p].
Link[0];
1141 for(
int pp=p+1;pp<
pNPart();pp++){
1142 if(
Pm[pp].Idx == link){
1151 printf(
"%d %d %d %d\n",p,link,MemPos,
Pm[p+1].Idx);
1154 printf(
"%d %d\n",
Pm[p+1].Idx,
Pm[MemPos].Idx);
1156 for(
int p=0;p<
pNPart()-1;p++){
1170 for(
int p=0;p<
pNPart();p++){
1172 if(
Ln[p].NLink == 0) NChain++;
1184 double CountStalk = 0.;
1190 for(
int t=0;t<NTri;t++){
1191 if(Triang[t].p[0].x[0] == Triang[t].p[1].x[0] && Triang[t].p[0].x[1] == Triang[t].p[1].x[1])
continue;
1192 for(
int v=0;v<2;v++){
1193 int vCurr = Triang[t].
v[v];
1194 VList.
Add(vCurr,NTria,Triang[t].p[v].x);
1195 for(
int d=0;d<3;d++)
Pm[NTria*2+v].Pos[d] = Triang[t].p[v].x[d];
1203 for(
int p=0;p<
pNPart();p++){
1206 for(
int t=0;t<NTri;t++){
1207 for(
int v=0;v<2;v++){
1208 int vCurr = Triang[t].
v[v];
1223 for(
int p=0;p<
pNPart();p++){
1224 if(
Pm[p].CId <= nChain)
continue;
1228 printf(
"------ %d %d\n",p,pp1);
1230 printf(
" %d %d\n",pp,
Ch[nChain].NPCh);
1231 Pm[pp1].
CId = nChain;
1234 if(pp == pp1)
break;
1241 printf(
"%d %d %d %d\n",c,
Ch[c].InitBead,
Ch[c].EndBead,
Ch[c].NPCh);
1243 printf(
"%d %d \n",c,p);
1248 double CmStalk[3] = {OldPos[0],OldPos[1],OldPos[2]};
1255 if(n > NTrials)
continue;
1258 for(
int d=0;d<3;d++){
1276 const int NGrid = 26;
1277 double *Plot = (
double *)calloc(NGrid*NGrid,
sizeof(
double));
1278 double *Plot2 = (
double *)calloc(NGrid*NGrid,
sizeof(
double));
1279 double Cm[3] = {0.,0.,0.};
1280 double Cm1[3] = {0.,0.,0.};
1282 double Threshold = SQR(SQR(1./Incr));
1284 for(
int gx=0;gx<NGrid;gx++){
1285 for(
int gy=0;gy<NGrid;gy++){
1286 Plot[gx*NGrid+gy] = 1.;
1289 for(
int p=0;p<
pNPart();p++){
1290 if(
Pm[p].Typ != 0 )
continue;
1293 if(gx < 0 || gx >= NGrid)
continue;
1294 if(gy < 0 || gy >= NGrid)
continue;
1295 Plot[gx*NGrid+gy] += Incr;
1303 for(
int gx=0;gx<NGrid;gx++){
1304 for(
int gy=0;gy<NGrid;gy++){
1305 Plot2[gx*NGrid+gy] = Plot[gx*NGrid+gy];
1308 for(
int gx=0;gx<NGrid;gx++){
1309 for(
int gy=0;gy<NGrid;gy++){
1310 if(gx == 0){ Plot[gx*NGrid+gy] = 1./SQR(SQR(Plot2[gx*NGrid+gy]));
continue;}
1311 if(gy == 0){ Plot[gx*NGrid+gy] = 1./SQR(SQR(Plot2[gx*NGrid+gy]));
continue;}
1312 if(gx == NGrid-1){ Plot[gx*NGrid+gy] = 1./SQR(SQR(Plot2[gx*NGrid+gy]));
continue;}
1313 if(gy == NGrid-1){ Plot[gx*NGrid+gy] = 1./SQR(SQR(Plot2[gx*NGrid+gy]));
continue;}
1314 Plot[gx*NGrid+gy] = 1./(Plot2[(gx-1)*NGrid+gy]*Plot2[(gx+1)*NGrid+gy]*Plot2[gx*NGrid+(gy-1)]*Plot2[gx*NGrid+(gy+1)]);
1318 for(
int gx=0;gx<NGrid;gx++){
1319 double x = gx/(double)NGrid*
pEdge(
CLat1) + Dx;
1320 for(
int gy=0;gy<NGrid;gy++){
1321 double y = gy/(double)NGrid*
pEdge(
CLat2) + Dy;
1324 Cm[
CLat1] += x*Plot[gx*NGrid+gy];
1325 Cm[
CLat2] += y*Plot[gx*NGrid+gy];
1326 Count += Plot[gx*NGrid+gy];
1327 if(Plot[gx*NGrid+gy] > Threshold ){
1340 for(
int r=0;r<NReweight;r++){
1342 Cm1[0] = Cm[0];Cm1[1] = Cm[1];
1343 Cm[0] = 0.;Cm[1] = 0.;
1346 for(
int gx=0;gx<NGrid;gx++){
1347 double x = gx/(double)NGrid*
pEdge(
CLat1) + Dx;
1348 for(
int gy=0;gy<NGrid;gy++){
1349 double y = gy/(double)NGrid*
pEdge(
CLat2) + Dy;
1350 double Dist = (SQR(x-Cm1[
CLat1]) + SQR(y-Cm1[
CLat2]));
1351 if(Dist > SQR(1.1*
Nano->
Rad))
continue;
1352 double Weight = 1./pow(Dist,.2);
1354 Cm[
CLat1] += x*Plot[gx*NGrid+gy]*Weight;
1355 Cm[
CLat2] += y*Plot[gx*NGrid+gy]*Weight;
1356 Count += Plot[gx*NGrid+gy]*Weight;
1357 if(Plot[gx*NGrid+gy] > Threshold ) Area += 1.;
1367 for(
int d=0;d<3;d++){
1372 double AreaOut = 0.;
1374 for(
int gx=0;gx<NGrid;gx++){
1375 double x = gx/(double)NGrid*
pEdge(
CLat1) + Dx;
1376 for(
int gy=0;gy<NGrid;gy++){
1377 double y = gy/(double)NGrid*
pEdge(
CLat2) + Dy;
1378 double Dist = SQR(x-Cm[0]) + SQR(y-Cm[1]);
1381 if(Plot[gx*NGrid+gy] < Threshold ) AreaOut += 1.;
1385 if(Plot[gx*NGrid+gy] > Threshold ) AreaOut += 1.;
1391 return AreaOut/AreaIn;
void AddPart(const int p, double *Pos)
Add a particle to the cell c.
CHAIN * Ch
Information on all chains.
int VertCurr(int v)
Current vertex iterator for the vertex v.
int InterBSpline1D(double *PlIn, double *PmOut, int NIn, int NOut)
1-d BSpline
int NLink
How many links per particle.
double x[3]
Cartesian coordinates.
double NanoDist2(double *Pos, int n)
Pointer to a generic function.
int Type
Type of the chain (see list CHAIN_)
BLOCK * Block
Information for every block.
double Vel[4]
xyzr Velocity of the particle
LINKS * Ln
Array of linking between the particles.
double Norm()
Return the norm of a Vettore.
double ShiftPos[3]
Reference position.
NANO * Nano
Extra particle.
double Bkf[3]
xyz Backfold distance
double Normalize()
Normlizes a Vettore.
int SetNChain(int NewNCh)
Set and reallocate the number of chains.
Geometrical operations on vectors.
double Edge[4]
xyzr edges of the simulation box
double Vel[3]
Chain velocity.
int IfItCell(int v)
End of the counters.
int BfDefChain()
Definition of the chain.
void SetNanoBkf(int n)
Set the back folded array for the nano n.
double pInvEdge(int d)
Inverted xyzr edges of the simulation box.
double Height
Height of the cylinder.
double pCm(int d)
Center of mass of the system.
Connects the triangles by vertices.
int CLat2
lateral coordinate
Information for every block.
int v[2]
Reference for the vectors.
VAR_TRIANGLE * MarchingCubes(double *Plot, int NSample, double IsoLevel, int *NTri)
Defines the triangles close to the IsoLevel of the 3d density Plot.
double Pos[3]
xyz Position of the particle
void ConnectLineChain(VAR_LINE *Triang, int NGrid, int NTri)
Connect the lines in a chain.
XYZ p[3]
The three vertices.
double Val(int N)
Value of the N column.
double * x
Where the data are stored.
void BfPep()
Backfold the nano described as a cluster of monomers.
void Dist2Curr(double *DistRel)
Retrun the squared current interparticle distance.
void ConvoluteMatrix(double *Plot, int NGrid, int NDim, int IfMinImConv)
Convolute with a matrix.
int InitBead
Initial bead.
double Area
Area of a pore or a stalk.
double pVol()
xyzr edges of the simulation box
int v[3]
Reference for the vectors.
void SwapPart(int p1, int p2)
Swap two particle.
int InitIdx
Initial particle position.
int Shape
0 none, 1 spherical, 2 cylindrical 3 wall
double pNanoPos(int n, int d)
Return back folded nano position.
int SetNPart(int NewNPart)
Set and reallocate the number of particles.
int StalkPos4(double *OldPos, double *CmStalk)
Find the position of the stalk forth method.
double pEdge(int d)
xyzr edges of the simulation box
int pNPCh()
Number of particle per chain.
void Add(int v, int t, double *Pos)
Add the triangle t at the vertex v.
double PorePos()
Find the position of the pore.
int pNBlock()
Number of blocks.
int StalkPos(double *OldPos)
Find the position of the stalk.
double Dir[3]
Directive of the chain.
void BackBone(double *Line, int NBin)
Describe the backbone of a filament.
int NChain
Number of chain.
void IncrCurr(int v)
Increment the counter.
int * Link
with whom is bonded
double Casuale()
Random uniform number.
double Val(int row)
Returns a value in 1d.
void Reorder()
Reorder and fill the vertices.
void NextCurr()
Increase the iterator to the next couple.
void Point2Shape(int iShape)
Point to the shape function.
int NPCh
Number of particle per chain.
bool ShiftSys(int How)
Shift the system accordin to the SHIFT_ definitions.
void StalkPos2(double *OldPos, double *CmStalk)
Find the position of the stalk second method.
void ShiftRef(int BackFold)
Backfold the system wrt the reference position.
int SysType
Contains the definition of the system.
void ConnectLineChain2(VAR_LINE *Triang, int NGrid, int NTri)
Connect the lines in a chain.
int pNNano()
Number of nanoparticles.
void FillGaussian(double Sigma, double CutOff)
Fill the entries for the Gauss blur.
double Cm[3]
Center of mass of the system.
void SetCounters(int v)
Set counters to zero for the point v.
void WriteSurf(FILE *F2Write, double **Plot, int NSample, int OffSet)
Write the particle position as linked edges of squares.
double Pos[4]
xyzr Postion of the chain
int NPCh
particles per chain
void DefBlock(int *NChStep, int How)
Define four different blocks.
Matrice computes the algebric operations on matrices.
int TriaCurr(int v)
Current triangle for the vertex v.
void ConnectLineChain3(VAR_LINE *Triang, int NGrid, int NTri)
Connect the lines in a chain.
Matematica * Mat
Implementation of all usefull algorythms.
void StalkPos3(double *OldPos, double *CmStalk)
Find the position of the stalk third method.
double NormalWeight(VAR_TRIANGLE *Triang, double *Weight, int NGrid, int NTri)
Weight of the neighblorung normal on a vertex.
int EndIdx
End particle position.
int pNChain()
Number of chain.
int BfEdge()
Find the box size if missing.
double Angle(Vettore *u, Vettore *v)
Computes the angle between two Vetttore.
int CLat1
lateral coordinate
int IfCurr()
Tell when the curr loop is over.
bool BackFold(int How)
Backfold the particle position.
int p2Curr
Current particle.
double Axis[3]
Rotation axis.
int NPart
Number of particle.
Domain decomposition as pointer to linked particles.
PART * Pm
Particle information of all particle.
int NPCh
Number of particles per chain.
int NBlock
Number of blocks.
void VarMessage(const char *s,...)
If enabled call the function position.
void SetCurr(int p)
Gather information of the neighbouring cells.
void Set(double Val, int Col)
Set the N column.
void SetEdge(double Val, int d)
Set Edge.
int CNorm
Normal coordinate.
void StalkLineProf(double *Line, int NBin)
Describe the line for a linear stalk.
int pNPart()
Number of particle.
RETTA InterRett(double *Px, double *Py, int NMass)
Linear interpolation.