@@ -102,46 +102,71 @@ __device__ void Initialize_Vectors_thread(Complex* eik, size_t numberOfAtoms, in
102102 eik[i + k * numberOfAtoms] = multiply (eik[i + (k - 1 ) * numberOfAtoms], eik[i + 1 * numberOfAtoms]);
103103 }
104104}
105-
106- __global__ void Initialize_WaveVector_General (Boxsize Box, int3 kmax, Atoms* d_a, Atoms New, Atoms Old, size_t Oldsize, size_t Newsize, size_t SelectedComponent, size_t Location, size_t chainsize, size_t numberOfAtoms, int MoveType)
105+ // Copy Old positions and new positions together into Old//
106+ // including double3* temp, for reinsertion//
107+ __device__ void Initialize_Copy_Positions_Together (Atoms*& d_a, Atoms& New, Atoms& Old, double3* temp, size_t Oldsize, size_t Newsize, size_t SelectedComponent, size_t Location, size_t chainsize, int MoveType)
107108{
108- // Zhao's note: need to think about changing this boolean to switch//
109109 size_t ij = blockIdx.x * blockDim.x + threadIdx.x ;
110- if (ij < (Newsize + Oldsize))
110+ if (MoveType == TRANSLATION || MoveType == ROTATION || MoveType == SPECIAL_ROTATION || MoveType == SINGLE_INSERTION || MoveType == SINGLE_DELETION) // Translation/Rotation/single_insertion/single_deletion //
111111 {
112- if (MoveType == TRANSLATION || MoveType == ROTATION || MoveType == SPECIAL_ROTATION || MoveType == SINGLE_INSERTION || MoveType == SINGLE_DELETION) // Translation/Rotation/single_insertion/single_deletion //
112+ // For Translation/Rotation, the Old positions are already in the Old struct, just need to put the New positions into Old, after the Old positions//
113+ if (ij >= Oldsize)
113114 {
114- // For Translation/Rotation, the Old positions are already in the Old struct, just need to put the New positions into Old, after the Old positions//
115- if (ij >= Oldsize)
116- {
117- Old.pos [ij] = New.pos [ij - Oldsize];
118- Old.scale [ij] = New.scale [ij - Oldsize];
119- Old.charge [ij] = New.charge [ij - Oldsize];
120- Old.scaleCoul [ij] = New.scaleCoul [ij - Oldsize];
121- }
115+ Old.pos [ij] = New.pos [ij - Oldsize];
116+ Old.scale [ij] = New.scale [ij - Oldsize];
117+ Old.charge [ij] = New.charge [ij - Oldsize];
118+ Old.scaleCoul [ij] = New.scaleCoul [ij - Oldsize];
122119 }
123- else if (MoveType == INSERTION || MoveType == CBCF_INSERTION) // Insertion & Fractional Insertion //
120+ }
121+ else if (MoveType == INSERTION || MoveType == CBCF_INSERTION) // Insertion & Fractional Insertion //
122+ {
123+ // Put the trial orientations in New to Old, right after the first bead position//
124+ if (ij < chainsize)
124125 {
125- // Put the trial orientations in New to Old, right after the first bead position//
126- if (ij < chainsize)
127- {
128- Old.pos [ij + 1 ] = New.pos [Location * chainsize + ij];
129- Old.scale [ij + 1 ] = New.scale [Location * chainsize + ij];
130- Old.charge [ij + 1 ] = New.charge [Location * chainsize + ij];
131- Old.scaleCoul [ij + 1 ] = New.scaleCoul [Location * chainsize + ij];
132- }
126+ Old.pos [ij + 1 ] = New.pos [Location * chainsize + ij];
127+ Old.scale [ij + 1 ] = New.scale [Location * chainsize + ij];
128+ Old.charge [ij + 1 ] = New.charge [Location * chainsize + ij];
129+ Old.scaleCoul [ij + 1 ] = New.scaleCoul [Location * chainsize + ij];
133130 }
134- else if (MoveType == DELETION || MoveType == CBCF_DELETION) // Deletion //
131+ }
132+ else if (MoveType == DELETION || MoveType == CBCF_DELETION) // Deletion //
133+ {
134+ if (ij < Oldsize)
135135 {
136- if (ij < Oldsize)
137- {
138- // For deletion, Location = UpdateLocation, see Deletion Move //
139- Old.pos [ij] = d_a[SelectedComponent].pos [Location + ij];
140- Old.scale [ij] = d_a[SelectedComponent].scale [Location + ij];
141- Old.charge [ij] = d_a[SelectedComponent].charge [Location + ij];
142- Old.scaleCoul [ij] = d_a[SelectedComponent].scaleCoul [Location + ij];
143- }
136+ // For deletion, Location = UpdateLocation, see Deletion Move //
137+ Old.pos [ij] = d_a[SelectedComponent].pos [Location + ij];
138+ Old.scale [ij] = d_a[SelectedComponent].scale [Location + ij];
139+ Old.charge [ij] = d_a[SelectedComponent].charge [Location + ij];
140+ Old.scaleCoul [ij] = d_a[SelectedComponent].scaleCoul [Location + ij];
144141 }
142+ }
143+ else if (MoveType == REINSERTION)
144+ {
145+ if (ij < Oldsize)
146+ {
147+ Old.pos [ij] = d_a[SelectedComponent].pos [Location + ij];
148+ Old.scale [ij] = d_a[SelectedComponent].scale [Location + ij];
149+ Old.charge [ij] = d_a[SelectedComponent].charge [Location + ij];
150+ Old.scaleCoul [ij] = d_a[SelectedComponent].scaleCoul [Location + ij];
151+ }
152+ else
153+ {
154+ Old.pos [ij] = temp[ij - Oldsize];
155+ Old.scale [ij] = d_a[SelectedComponent].scale [Location + ij - Oldsize];
156+ Old.charge [ij] = d_a[SelectedComponent].charge [Location + ij - Oldsize];
157+ Old.scaleCoul [ij] = d_a[SelectedComponent].scaleCoul [Location + ij - Oldsize];
158+ }
159+ }
160+ }
161+
162+ __global__ void Initialize_WaveVector_General (Boxsize Box, int3 kmax, Atoms* d_a, Atoms New, Atoms Old, double3* temp, size_t Oldsize, size_t Newsize, size_t SelectedComponent, size_t Location, size_t chainsize, size_t numberOfAtoms, int MoveType)
163+ {
164+ // Zhao's note: need to think about changing this boolean to switch//
165+ size_t ij = blockIdx.x * blockDim.x + threadIdx.x ;
166+
167+ if (ij < (Newsize + Oldsize))
168+ {
169+ Initialize_Copy_Positions_Together (d_a, New, Old, temp, Oldsize, Newsize, SelectedComponent, Location, chainsize, MoveType);
145170 // Old+New//
146171 Complex tempcomplex; tempcomplex.real = 1.0 ; tempcomplex.imag = 0.0 ;
147172 tempcomplex.real = 1.0 ; tempcomplex.imag = 0.0 ;
@@ -224,8 +249,6 @@ __global__ void Initialize_WaveVector_IdentitySwap(Boxsize Box, int3 kmax, doubl
224249 Old.charge [ij] = d_a[NEWComponent].charge [ij - Oldsize];
225250 Old.scaleCoul [ij] = 1.0 ;
226251 }
227-
228-
229252 // Old+New//
230253 Complex tempcomplex; tempcomplex.real = 1.0 ; tempcomplex.imag = 0.0 ;
231254 tempcomplex.real = 1.0 ; tempcomplex.imag = 0.0 ;
@@ -467,8 +490,10 @@ double2 GPU_EwaldDifference_General(Simulations& Sim, ForceField& FF, Components
467490 }
468491 case REINSERTION: // Reinsertion //
469492 {
470- throw std::runtime_error (" EWALD: Use the Special Function for Reinsertion" );
471- // break;
493+ Newsize = SystemComponents.Moleculesize [SelectedComponent];
494+ Oldsize = SystemComponents.Moleculesize [SelectedComponent];
495+ chainsize = SystemComponents.Moleculesize [SelectedComponent] - 1 ;
496+ break ;
472497 }
473498 case IDENTITY_SWAP:
474499 {
@@ -501,7 +526,7 @@ double2 GPU_EwaldDifference_General(Simulations& Sim, ForceField& FF, Components
501526 size_t numberOfAtoms = Oldsize + Newsize;
502527
503528 size_t Nblock = 0 ; size_t Nthread = 0 ; Setup_threadblock (Oldsize + Newsize, Nblock, Nthread);
504- Initialize_WaveVector_General<<<Nblock,Nthread>>>(Box, Box.kmax , d_a, New, Old, Oldsize, Newsize, SelectedComponent, Location, chainsize, numberOfAtoms, MoveType); checkCUDAErrorEwald (" error Initializing Ewald Vectors" );
529+ Initialize_WaveVector_General<<<Nblock,Nthread>>>(Box, Box.kmax , d_a, New, Old, SystemComponents. tempMolStorage , Oldsize, Newsize, SelectedComponent, Location, chainsize, numberOfAtoms, MoveType); checkCUDAErrorEwald (" error Initializing Ewald Vectors" );
505530
506531 // Fourier Loop//
507532 size_t numberOfStructureFactors = (Box.kmax .x + 1 ) * (2 * Box.kmax .y + 1 ) * (2 * Box.kmax .z + 1 );
@@ -552,39 +577,6 @@ double2 GPU_EwaldDifference_General(Simulations& Sim, ForceField& FF, Components
552577 return {SameSum, 2.0 * CrossSum};
553578}
554579
555- // Zhao's note: THIS IS A SPECIAL FUNCTION JUST FOR REINSERTION//
556- double2 GPU_EwaldDifference_Reinsertion (Boxsize& Box, Atoms*& d_a, Atoms& Old, double3* temp, ForceField& FF, double * Blocksum, Components& SystemComponents, size_t SelectedComponent, size_t UpdateLocation)
557- {
558- if (FF.noCharges && !SystemComponents.hasPartialCharge [SelectedComponent]) return {0.0 , 0.0 };
559- double alpha = Box.Alpha ; double alpha_squared = alpha * alpha;
560- double prefactor = Box.Prefactor * (2.0 * M_PI / Box.Volume );
561-
562- size_t numberOfAtoms = SystemComponents.Moleculesize [SelectedComponent];
563- size_t Oldsize = 0 ; size_t Newsize = numberOfAtoms;
564- // Zhao's note: translation/rotation/reinsertion involves new + old states. Insertion/Deletion only has the new state.
565- Oldsize = SystemComponents.Moleculesize [SelectedComponent];
566- numberOfAtoms += Oldsize;
567-
568- Complex* SameType = Box.AdsorbateEik ; Complex* CrossType = Box.FrameworkEik ;
569-
570- // Construct exp(ik.r) for atoms and k-vectors kx, ky, kz = 0, 1 explicitly
571- size_t Nblock = 0 ; size_t Nthread = 0 ; Setup_threadblock (Oldsize + Newsize, Nblock, Nthread);
572- Initialize_WaveVector_Reinsertion<<<Nblock,Nthread>>>(Box, Box.kmax , temp, d_a, Old, Oldsize, Newsize, UpdateLocation, numberOfAtoms, SelectedComponent);
573-
574- // Fourier Loop//
575- size_t numberOfStructureFactors = (Box.kmax .x + 1 ) * (2 * Box.kmax .y + 1 ) * (2 * Box.kmax .z + 1 );
576- Nblock = 0 ; Nthread = 0 ; Setup_threadblock (numberOfStructureFactors, Nblock, Nthread);
577- Fourier_Ewald_Diff<<<Nblock * 2 , Nthread, Nthread * sizeof (double )>>>(Box, SameType, CrossType, Old, alpha_squared, prefactor, Box.kmax , Oldsize, Newsize, Blocksum, false , Nblock);
578- // double sum[Nblock * 2];
579- double SameSum = 0.0 ; double CrossSum = 0.0 ;
580- cudaMemcpy (SystemComponents.host_array , Blocksum, 2 * Nblock * sizeof (double ), cudaMemcpyDeviceToHost);
581-
582- for (size_t i = 0 ; i < Nblock; i++){SameSum += SystemComponents.host_array [i];}
583- for (size_t i = Nblock; i < 2 * Nblock; i++){CrossSum += SystemComponents.host_array [i];}
584-
585- return {SameSum, 2.0 * CrossSum};
586- }
587-
588580double2 GPU_EwaldDifference_IdentitySwap (Boxsize& Box, Atoms*& d_a, Atoms& Old, double3* temp, ForceField& FF, double * Blocksum, Components& SystemComponents, size_t OLDComponent, size_t NEWComponent, size_t UpdateLocation)
589581{
590582 if (FF.noCharges && !SystemComponents.hasPartialCharge [NEWComponent] && !SystemComponents.hasPartialCharge [OLDComponent]) return {0.0 , 0.0 };
0 commit comments