7 double *Known = (
double *) calloc(
pNPCh(),
sizeof(double));
8 double *UnKnown = (
double *) calloc(
pNPCh(),
sizeof(double));
10 int pInit = c*
pNPCh();
11 int pEnd = (c+1)*
pNPCh();
13 for(
int p=pInit;p<pEnd;p++)
14 Known[p-pInit] =
Pm[p].Pos[
CNorm] - Offset;
15 IntMatrix->
Apply(Known,UnKnown);
17 for(
int p=pInit;p<pEnd;p++){
19 if(
Pm[p].Typ != 0){
continue;}
30 double *Known = (
double *) calloc(
pNPart(),
sizeof(double));
31 double *UnKnown = (
double *) calloc(
pNPart(),
sizeof(double));
32 double Offset = .5*
pEdge(2);
33 for(
int p=0;p<
pNPart();p++)
34 Known[p] =
Pm[p].Pos[
CNorm] - Offset;
35 IntMatrix->
Apply(Known,UnKnown);
37 for(
int p=0;p<
pNPart();p++){
38 if(
Pm[p].Typ != 0){
continue;}
56 Weight.
a3 = 0./(Inter*SQR(Inter));
57 Weight.
a4 =
Kf.
SLap/(SQR(Inter)*SQR(Inter));
61 double *Known = (
double *) calloc(
pNPart(),
sizeof(double));
62 double *UnKnown = (
double *) calloc(
pNPart(),
sizeof(double));
67 for(
int i=0;i<NIter;i++){
68 for(
int p=0;p<
pNPart();p++)
69 Known[p] =
Pm[p].Pos[
CNorm] - Offset;
70 for(
int p=0;p<
pNPart();p++){
72 UnKnown[p] = Known[p];
77 Link[d][1] =
Ln[p].
Link[d*2];
78 Link[d][3] =
Ln[p].
Link[d*2+1];
79 Link[d][0] =
Ln[Link[d][1]].
Link[d*2];
80 Link[d][4] =
Ln[Link[d][3]].
Link[d*2+1];
81 for(
int l=0,l1=-2;l<5;l++,l1++){
92 Sol += CoeffMatrix->
Val(2,l)*
Pm[Link[d][l]].
Pos[2];
95 UnKnown[p] = .4*Known[p] - .6*Sol/CoeffMatrix->
Val(2,2);
97 for(
int p=0;p<
pNPart();p++){
98 if(
Pm[p].Typ != 0){
continue;}
113 double *Known = (
double *) calloc(
pNPart(),
sizeof(double));
114 double *UnKnown = (
double *) calloc(
pNPart(),
sizeof(double));
115 for(
int p=0;p<
pNPart();p++)
116 Known[p] =
Pm[p].Pos[
CNorm] - Offset;
117 IntMatrix->
Apply(Known,UnKnown);
118 for(
int p=0;p<
pNPart();p++){
119 if(
Pm[p].Typ != 0){
continue;}
322 for(
int n=0;n<
pNNano();n++){
327 for(
int d=0;d<3;d++){
340 Axis.
VetV(&Axis,&Normal);
341 double Angle = Ax.
Angle(&Axis,&Normal);
350 Resp.
Mult(RotT,InTensor);
351 Resp2.
Mult(Resp,Rot);
355 for(
int d=0;d<3;d++){
362 if(
Nano[n].Shape != 2)
continue;
366 VelTang.
VetV(&Omega,&BackBone);
367 for(
int d=0;d<3;d++){
369 Axis.
x[d] = BackBone.
x[d];
383 for(
int n=0;n<
pNNano();n++) {
384 for(
int d=0;d<3;d++){
395 if(exp(
pBeta()*Arg)*Weight > 1. )
return 1;
397 if(exp(
pBeta()*Arg)*Weight > Ran ){
449 for(
int d=0;d<3;d++){
459 if(
Pm[p].Typ >= 2)
return 1;
462 double Pot[3] = {0.,0.,0.};
472 double NrgDiff = Nrg1 - Nrg0;
476 for(
int d=0;d<3;d++)
Pm[p].Pos[d] = Pos[d];
491 double *LineS =
new double[NBin];
492 for(
int i=0;i<NBin;i++){
493 FirstBeadDistr[i] = 0.;
498 if(i < 0 || i >= NBin)
continue;
499 FirstBeadDistr[i] += 1.;
503 for(
int v=0;v<NBin;v++) LineS[v] = FirstBeadDistr[v];
505 for(
int v=0;v<NBin;v++) LineS[v] = FirstBeadDistr[v];
507 Norm = Norm >= 0. ? 1./Norm : 1.;
508 for(
int i=0;i<NBin;i++){
509 FirstBeadDistr[i] *= Norm;
512 for(
int i=1;i<NBin;i++){
513 FirstBeadDistr[i] += FirstBeadDistr[i-1];
514 if(FirstBeadDistr[i] > .25 && FirstBeadDistr[i-1] < .25)
516 else if(FirstBeadDistr[i] > .75 && FirstBeadDistr[i-1] < .75)
547 OldNrgCh[c*3+e] = OldNrgCh[c2*3+e];
556 for(
int p=0;p<
pNPCh();p++)
561 for(
int p=0;p<
pNPCh();p++)
571 for(
int p=0;p<
pNPCh();p++){
572 for(
int d=0;d<3;d++){
573 OldPos[p][d] =
Pm[p+p1].
Pos[d];
584 for(
int p=0;p<
pNPCh();p++){
585 for(
int d=0;d<3;d++){
586 Pm[p+p1].
Pos[d] = OldPos[p][d];
600 if(VAR_IF_TYPE(
CalcMode,CALC_BIL_BIAS)){
605 else if(VAR_IF_TYPE(
CalcMode,CALC_SPH_BIAS)){
609 double w = sqrt( 1 - z*z );
610 double x = w * cos( t );
611 double y = w * sin( t );
616 double Vol = 4./3.*M_PI*( CUBE(
Nano->
Rad + Incr) - CUBE(
Nano->
Rad));
617 Weight *= Vol/
pVol();
630 for(
int p=StartPos+1;p<
pNPCh();p++){
631 for(
int d=0;d<3;d++){
633 Pm[p+pCurr].
Pos[d] =
Pm[p-1+pCurr].
Pos[d] + Ran;
637 for(
int p=StartPos-1;p>=0;p--){
638 for(
int d=0;d<3;d++){
640 Pm[p+pCurr].
Pos[d] =
Pm[p+1+pCurr].
Pos[d] + Ran;
663 double NrgDiff = NrgNew - NrgOld;
668 OldNrgCh[c*3+2] = NrgNew;
669 OldNrgSys += NrgDiff;
676 if(
pNPart() <= 0)
return 0;
691 OldNrgSys -= NrgDiff;
718 OldNrgCh[c*3+2] = NrgDiff;
719 OldNrgSys += NrgDiff;
732 double Weight = exp(-NrgDiff+
NrgPBead);
735 for(
int p=p1+1;p<p1+
pNPCh();p++){
747 CumProbBias[0] = exp(-NrgDiff+
NrgPBead);
748 for(
int t=1;t<NTrialBias;t++){
749 for(
int d=0;d<3;d++){
751 BondPosBias[t][d] -= floor(BondPosBias[t][d]*
pInvEdge(d))*
pEdge(d);
756 NrgDiff +=
NanoNrg(BondPosBias[t],Type);
757 CumProbBias[t] = exp(-NrgDiff+
NrgPBead);
760 for(
int t=0;t<NTrialBias;t++){
761 Weight += CumProbBias[t];
763 return Weight/(double)NTrialBias;
774 if(VAR_IF_TYPE(
CalcMode,CALC_BIL_BIAS)){
779 else if(VAR_IF_TYPE(
CalcMode,CALC_SPH_BIAS)){
783 double w = sqrt( 1 - z*z );
784 double x = w * cos( t );
785 double y = w * sin( t );
790 double Vol = 4./3.*M_PI*( CUBE(
Nano->
Rad + Incr) - CUBE(
Nano->
Rad));
791 Weight *= Vol/
pVol();
796 fprintf(StatFile2,
"%lf %lf\n",NrgDiff,
NanoNrg(p1));
803 for(
int p=p1+1;p<(c+1)*
pNPCh();p++){
818 for(
int t=0;t<NTrialBias;t++){
819 for(
int d=0;d<3;d++){
821 BondPosBias[t][d] -= floor(BondPosBias[t][d]*
pInvEdge(d))*
pEdge(d);
824 fprintf(StatFile2,
"%lf %lf\n",NrgDiff,
NanoNrg(BondPosBias[t],Type));
826 NrgDiff +=
NanoNrg(BondPosBias[t],Type);
827 CumProbBias[t] = exp(-NrgDiff+
NrgPBead);
830 for(
int t=0;t<NTrialBias;t++){
831 Weight += CumProbBias[t];
833 CumProbBias[0] /= Weight;
835 for(
int t=1;t<NTrialBias;t++){
836 CumProbBias[t] /= Weight;
837 CumProbBias[t] += CumProbBias[t-1];
839 for(
int t=0;t<NTrialBias;t++){
840 if(Ran < CumProbBias[t]){
845 for(
int d=0;d<3;d++){
846 Pm[p].
Pos[d] = BondPosBias[tChoosen][d];
849 return Weight/(double)NTrialBias;
855 if(
pNPart() <= 0)
return 0;
879 double Weight = Weight1*
pVol()/(double)(
pNChain()+1);
919 NrgDiff[0] = OldNrgCh[c*3 ];
920 NrgDiff[1] = OldNrgCh[c*3+1];
921 NrgDiff[2] = OldNrgCh[c*3+2];
943 for(
int p=0;p<
pNPart();p++){
944 if(
Pm[p].Typ != 0)
continue;
945 for(
int d=0;d<3;d++){
959 double Zeta = sqrt(12.*2.*1.*Gamma/
pDeltat());
960 for(
int p=0;p<
pNPart();p++){
961 for(
int d=0;d<3;d++){
972 double Sigma = sqrt(
pTemp());
973 for(
int p=0;p<
pNPart();p++){
975 for(
int d=0;d<3;d++){
986 for(
int p=0;p<
pNPart();p++){
987 for(
int d=0;d<3;d++){
989 Temp += SQR(
Pm[p].Vel[d]);
993 double Norm = 1./sqrt(Temp);
994 for(
int p=0;p<
pNPart();p++){
995 for(
int d=0;d<3;d++){
996 Pm[p].
Vel[d] *= Norm;
1004 printf(
"Thermostat: ");
1005 if(Mode==THERM_LANG){
1007 printf(
"Langevin\n");
1009 else if((Mode==THERM_AND)){
1011 printf(
"Andersen\n");
1013 else if((Mode==THERM_BERE)){
1015 printf(
"Berendsen\n");
1017 else if((Mode==THERM_NO)){
1019 printf(
"no thermostat\n");
1022 printf(
"mode not present\n");
1030 for(
int p=0;p<
pNPart();p++){
1031 for(
int d=0;d<3;d++){
int TryMoveCh()
Trial desplacement of a chain.
void LangevinTherm()
Langevin thermostat.
void Export(double *x)
Export.
void AddPart(const int p, double *Pos)
Add a particle to the cell c.
void WidomBiasChIn(double *Weight)
Widom with Rosenbluth weight.
double a4
a0 + a1*x + a2*x^2 + a3*x^3 + a4^4
double InsertChBias(int c)
Put a chain in the box.
int InterBSpline1D(double *PlIn, double *PmOut, int NIn, int NOut)
1-d BSpline
double InsertRest(int pCurr, int StartPos)
Build the rest of the chain.
void VelVerlet1()
First step of the velocity Verlet.
double RemoveChBias(int c)
Remove a chain in the box.
double Vel[4]
xyzr Velocity of the particle
int TryRemoveChBias()
Trial biased removal of a chain.
LINKS * Ln
Array of linking between the particles.
void AddRigid()
Add all rigid bodies as a boundary condition.
CALC_THERM CalcTherm
Pointer to the energy calculation function.
NANO * Nano
Extra particle.
double CalcBendingGhost(double *Pos, int pExt)
Calculate the bending energy for a ghost particle.
double Normalize()
Normlizes a Vettore.
double Gamma
Friction term.
Geometrical operations on vectors.
double Lap
Prefactor of the Laplacian.
double CreateSetBond(int p, int t)
Create a set of bonds for the configurational bias.
void RemPart(const int p, double *Pos)
Remove a particle form the cell c.
int MoveBead(int p)
Move a particle in the box.
double Viscosity
Viscosity of the medium.
double pInvEdge(int d)
Inverted xyzr edges of the simulation box.
double GaussVar
Standard deviation of the gaussian chain.
double Height
Height of the cylinder.
int CLat2
lateral coordinate
double El[3]
Elastic force.
void CopyOn(Matrice *B)
Copy on a matrix.
int TryInsertCh()
Trial insertion of a chain.
void Mult(Matrice &A, Matrice &B)
Multiplication between two matrices.
double Pos[3]
xyz Position of the particle
void FillMatrix()
Fill the entries of the interaction matrix.
int IfMetropolis(double ExpArg, double Weight)
Metropolis acceptance criterium.
void WidomInsert(double *NrgDiff)
Widom insertion.
int RemDens(int pInit, int pEnd)
Substract the densities connected with the particles between pInit and pEnd.
double * x
Where the data are stored.
void SolveLinksIterative()
Solve a system of four oder differential equation of particles connected by links.
void NoTherm()
No thermostat.
int TryInsertChBias()
Trial biased insertion of a chain.
void WidomInsertCh(double *NrgDiff)
Widom insertion.
void WidomRemoveCh(double *NrgDiff, int c)
Widom removal.
double pVol()
xyzr edges of the simulation box
double ChemPotEx
Chemical potential of the particles.
void SwapPart(int p1, int p2)
Swap two particle.
int CalcMode
Calculation mode.
void ChooseThermostat(int Mode)
Choose a calculation mode.
void ConsiderCh(int c)
Consider a chain in the system (densities, pairlist)
double pEdge(int d)
xyzr edges of the simulation box
void IgnoreCh(int c)
Ignore a chain in the system (densities, pairlist)
void VelVerletRigid()
Velocity Verlet for a rigid body, first step.
int pNPCh()
Number of particle per chain.
double a3
a0 + a1*x + a2*x^2 + a3*x^3 + a4^4
int InsertBead(int p)
Insert a particle in the box.
void Transpose()
Transpose the matrix.
int ReSetNPart(int NewNPart)
Realloc the number of particles.
double NanoNrg(int p)
Exchange energy with the nano.
int TryMove()
Trial movement.
void BackBone(double *Line, int NBin)
Describe the backbone of a filament.
int * Link
with whom is bonded
void AndersenTherm()
Andersen thermostat.
int NEdge
Number of particles per edge.
double Casuale()
Random uniform number.
double Val(int row)
Returns a value in 1d.
KFORCES Kf
Prefactor of the forces.
double Zeta
Stochastic term.
void StudySys()
Obtain informations for a better performance in inserting the chains.
int TryRemove()
Trial removal.
int pNNano()
Number of nanoparticles.
double VetV(const Vettore *u, const Vettore *v)
Vectorial product between two Vettore returns the area.
double a2
a0 + a1*x + a2*x^2 + a3*x^3 + a4^4
double a1
a0 + a1*x + a2*x^2 + a3*x^3 + a4^4
void RemChFromSys(int c)
Delete a chain in the system.
void VelVerletRigid2()
Velocity Verlet for a rigid body, second step.
void SwapChain(int c1, int c2, int b)
Swap two chains.
int TryRemoveCh()
Trial removal of a chain.
double pBeta()
Beta factor 1/kTB.
Matrice computes the algebric operations on matrices.
void SolveLeaves()
Solve a system of four oder differential equation of particles in a line.
bool Set(int row, int column, double Val)
Set a coefficient.
double ChemPotId
Chemical potential of the particles.
void Apply(double *Known, double *UnKnown)
Apply Ax = y.
double Gaussiano(double Media, double Scarto)
Gaussian random number.
double CalcNrgCh(int c, double *Pot)
Pointer to the chain energy function.
int ReSetNChain(int NewNChain)
Realloc the number of chains.
void VelVerlet2()
Second step of the velocity Verlet.
int SwapPart(int p1, double *Pos1, int p2, double *Pos2)
Swap two particles.
Matematica * Mat
Implementation of all usefull algorythms.
double AMom[3]
Angular momentum.
double pTemp()
Temperature.
int pNChain()
Number of chain.
double Angle(Vettore *u, Vettore *v)
Computes the angle between two Vetttore.
int CLat1
lateral coordinate
double DensFuncNrgGhost(double *Pos, int p1, int t1)
Calculation of the energy from the density functional Hamiltonian for the ghost particle.
void WidomRemove(double *NrgDiff, int p)
Widom removal.
double a0
a0 + a1*x + a2*x^2 + a3*x^3 + a4^4
void SolveRod()
Solve a system of four oder differential equation of particles connected by links.
void BerendsenTherm()
Berendsen thermostat.
double AVel[3]
Angular velocity.
double Axis[3]
Rotation axis.
void ReInsertCh(int c)
Reinsert the chain in the previous position.
void MovePart(const int p, double *OldPos, double *NewPos)
Move a particle form the cell c1 to the cell c2.
PART * Pm
Particle information of all particle.
void SaveCh(int c)
Save the chain configuration.
int AddDens(int pInit, int pEnd)
Add the densities connected with the particles between pInit and pEnd.
void Print()
Print the entries.
double NrgPBead
Average energy per particle.
double WeightSetBond(int p, int t)
Weight a set of bonds for the configurational bias.
double InsertCh(int c)
Displace a chain in the box.
double SLap
Prefactor of the square laplacian.
void SolveLinks()
Solve a system of four oder differential equation of particles connected by links.
int TryInsert()
Trial insertion.
FORCES * Fm
Array containing the forces for each particle.
double CalcNrgBead(int p, double *Pot)
Pointer to the energy function.
int CNorm
Normal coordinate.
int pNPart()
Number of particle.
void WidomBiasChOut(double *Weight, int c)
Widom with Rosenbluth weight.