Skip to content

Commit f0c86ea

Browse files
Merge pull request #67 from Zhaoli2042/push-branch
Push branch: Widom insertion adsorption energy
2 parents 83b8106 + a471242 commit f0c86ea

File tree

4 files changed

+133
-90
lines changed

4 files changed

+133
-90
lines changed

src_clean/axpy.cu

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,18 @@ void RunMoves(Variables& Vars, size_t box_index, int Cycle)
170170
double2& newScale = SystemComponents.TempVal.Scale;
171171
newScale = SystemComponents.Lambda[comp].SET_SCALE(1.0); //Set scale for full molecule (lambda = 1.0)//
172172
double Rosenbluth = MOVES.INSERTION.WidomMove(Vars, box_index);
173+
//Also record move energy (delta energy)
174+
//MoveEnergy widom_e = MOVES.INSERTION.energy;
175+
//printf("Widom E: "); widom_e.print();
173176

174177
if(Vars.SimulationMode == PRODUCTION)
175178
{
176179
size_t blockID = Cycle/Vars.BlockAverageSize;
177180
if(blockID >= SystemComponents.Nblock) blockID --;
178181
SystemComponents.Moves[comp].BlockID = blockID;
179182
SystemComponents.Moves[comp].RecordRosen(Rosenbluth, WIDOM);
183+
//weight with Rosenbluth (heavy weight on low (attractive) energy, lower on high energy)
184+
SystemComponents.Moves[comp].Rosen[blockID].widom_energy += MOVES.INSERTION.energy * Rosenbluth;
180185
}
181186
}
182187
else if(RANDOMNUMBER < SystemComponents.Moves[comp].ReinsertionProb)

src_clean/data_struct.h

Lines changed: 83 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ enum INTERACTION_TYPES {HH = 0, HG, GG};
3535
enum RESTART_FILE_TYPES {RASPA_RESTART = 0, LAMMPS_DATA};
3636

3737
//Zhao's note: For the stage of evaluating total energy of the system//
38-
enum ENERGYEVALSTAGE {INITIAL = 0, CREATEMOL, FINAL, CREATEMOL_DELTA, DELTA, CREATEMOL_DELTA_CHECK, DELTA_CHECK, DRIFT, GPU_DRIFT, AVERAGE, AVERAGE_ERR};
38+
enum ENERGYEVALSTAGE {INITIAL = 0, CREATEMOL, FINAL, CREATEMOL_DELTA, DELTA, CREATEMOL_DELTA_CHECK, DELTA_CHECK, DRIFT, GPU_DRIFT, AVERAGE, AVERAGE_ERR, WIDOM_AVG, WIDOM_ERR};
3939

4040
struct EnergyComplex
4141
{
@@ -409,6 +409,82 @@ struct TMMC
409409
}
410410
};
411411

412+
//Temporary energies for a move//
413+
//Zhao's note: consider making this the default return variable for moves, like RASPA-3?//
414+
struct MoveEnergy
415+
{
416+
double storedHGVDW=0.0;
417+
double storedHGReal=0.0;
418+
double storedHGEwaldE=0.0;
419+
// van der Waals //
420+
double HHVDW=0.0;
421+
double HGVDW=0.0;
422+
double GGVDW=0.0;
423+
// Real Part of Coulomb //
424+
double HHReal=0.0;
425+
double HGReal=0.0;
426+
double GGReal=0.0;
427+
// Long-Range Ewald Energy //
428+
double HHEwaldE=0.0;
429+
double HGEwaldE=0.0;
430+
double GGEwaldE=0.0;
431+
// Other Energies //
432+
double TailE =0.0;
433+
double DNN_E =0.0;
434+
double total()
435+
{
436+
return HHVDW + HGVDW + GGVDW +
437+
HHReal + HGReal + GGReal +
438+
HHEwaldE + HGEwaldE + GGEwaldE +
439+
TailE + DNN_E;
440+
};
441+
void take_negative()
442+
{
443+
storedHGVDW *= -1.0;
444+
storedHGReal*= -1.0;
445+
storedHGEwaldE *= -1.0;
446+
HHVDW *= -1.0; HHReal *= -1.0;
447+
HGVDW *= -1.0; HGReal *= -1.0;
448+
GGVDW *= -1.0; GGReal *= -1.0;
449+
HHEwaldE *= -1.0; HGEwaldE *= -1.0; GGEwaldE *= -1.0;
450+
TailE *= -1.0;
451+
DNN_E *= -1.0;
452+
};
453+
void zero()
454+
{
455+
storedHGVDW =0.0;
456+
storedHGReal=0.0;
457+
storedHGEwaldE=0.0;
458+
HHVDW=0.0; HHReal=0.0;
459+
HGVDW=0.0; HGReal=0.0;
460+
GGVDW=0.0; GGReal=0.0;
461+
HHEwaldE =0.0;
462+
HGEwaldE =0.0;
463+
GGEwaldE =0.0;
464+
TailE =0.0;
465+
DNN_E =0.0;
466+
};
467+
void print()
468+
{
469+
printf("HHVDW: %.5f, HHReal: %.5f, HGVDW: %.5f, HGReal: %.5f, GGVDW: %.5f, GGReal: %.5f, HHEwaldE: %.5f,\n HGEwaldE: %.5f,\n GGEwaldE: %.5f, TailE: %.5f, DNN_E: %.5f\n", HHVDW, HHReal, HGVDW, HGReal, GGVDW, GGReal, HHEwaldE, HGEwaldE, GGEwaldE, TailE, DNN_E);
470+
printf("Stored HGVDW: %.5f, Stored HGReal: %.5f, Stored HGEwaldE: %.5f\n", storedHGVDW, storedHGReal, storedHGEwaldE);
471+
};
472+
void DNN_Replace_Energy()
473+
{
474+
storedHGVDW = HGVDW;
475+
storedHGReal= HGReal;
476+
storedHGEwaldE = HGEwaldE;
477+
HGVDW = 0.0;
478+
HGReal= 0.0;
479+
HGEwaldE = 0.0;
480+
}
481+
double DNN_Correction() //Using DNN energy to replace HGVDW, HGReal and HGEwaldE//
482+
{
483+
double correction = DNN_E - storedHGVDW - storedHGReal - storedHGEwaldE;
484+
return correction;
485+
};
486+
};
487+
412488
//Zhao's note: keep track of the Rosenbluth weights during the simulation//
413489
struct RosenbluthWeight
414490
{
@@ -417,6 +493,7 @@ struct RosenbluthWeight
417493
double3 Insertion = {0.0, 0.0, 0.0};
418494
double3 Deletion = {0.0, 0.0, 0.0};
419495
//NOTE: DO NOT RECORD FOR REINSERTIONS, SINCE THE DELETION PART OF REINSERTION IS MODIFIED//
496+
MoveEnergy widom_energy;
420497
};
421498

422499
struct Move_Statistics
@@ -483,6 +560,10 @@ struct Move_Statistics
483560
std::vector<std::vector<double>>MolSQPerComponent;
484561
//x: average; y: average^2; z: Number of Widom insertion performed//
485562
std::vector<RosenbluthWeight>Rosen; //vector over Nblocks//
563+
564+
MoveEnergy WidomEnergy;
565+
MoveEnergy WidomEnergy_ERR;
566+
486567
void NormalizeProbabilities()
487568
{
488569
//Zhao's note: the probabilities here are what we defined in simulation.input, raw values//
@@ -640,81 +721,7 @@ struct Tail
640721
double Energy = {0.0};
641722
};
642723

643-
//Temporary energies for a move//
644-
//Zhao's note: consider making this the default return variable for moves, like RASPA-3?//
645-
struct MoveEnergy
646-
{
647-
double storedHGVDW=0.0;
648-
double storedHGReal=0.0;
649-
double storedHGEwaldE=0.0;
650-
// van der Waals //
651-
double HHVDW=0.0;
652-
double HGVDW=0.0;
653-
double GGVDW=0.0;
654-
// Real Part of Coulomb //
655-
double HHReal=0.0;
656-
double HGReal=0.0;
657-
double GGReal=0.0;
658-
// Long-Range Ewald Energy //
659-
double HHEwaldE=0.0;
660-
double HGEwaldE=0.0;
661-
double GGEwaldE=0.0;
662-
// Other Energies //
663-
double TailE =0.0;
664-
double DNN_E =0.0;
665-
double total()
666-
{
667-
return HHVDW + HGVDW + GGVDW +
668-
HHReal + HGReal + GGReal +
669-
HHEwaldE + HGEwaldE + GGEwaldE +
670-
TailE + DNN_E;
671-
};
672-
void take_negative()
673-
{
674-
storedHGVDW *= -1.0;
675-
storedHGReal*= -1.0;
676-
storedHGEwaldE *= -1.0;
677-
HHVDW *= -1.0; HHReal *= -1.0;
678-
HGVDW *= -1.0; HGReal *= -1.0;
679-
GGVDW *= -1.0; GGReal *= -1.0;
680-
HHEwaldE *= -1.0; HGEwaldE *= -1.0; GGEwaldE *= -1.0;
681-
TailE *= -1.0;
682-
DNN_E *= -1.0;
683-
};
684-
void zero()
685-
{
686-
storedHGVDW =0.0;
687-
storedHGReal=0.0;
688-
storedHGEwaldE=0.0;
689-
HHVDW=0.0; HHReal=0.0;
690-
HGVDW=0.0; HGReal=0.0;
691-
GGVDW=0.0; GGReal=0.0;
692-
HHEwaldE =0.0;
693-
HGEwaldE =0.0;
694-
GGEwaldE =0.0;
695-
TailE =0.0;
696-
DNN_E =0.0;
697-
};
698-
void print()
699-
{
700-
printf("HHVDW: %.5f, HHReal: %.5f, HGVDW: %.5f, HGReal: %.5f, GGVDW: %.5f, GGReal: %.5f, HHEwaldE: %.5f,\n HGEwaldE: %.5f,\n GGEwaldE: %.5f, TailE: %.5f, DNN_E: %.5f\n", HHVDW, HHReal, HGVDW, HGReal, GGVDW, GGReal, HHEwaldE, HGEwaldE, GGEwaldE, TailE, DNN_E);
701-
printf("Stored HGVDW: %.5f, Stored HGReal: %.5f, Stored HGEwaldE: %.5f\n", storedHGVDW, storedHGReal, storedHGEwaldE);
702-
};
703-
void DNN_Replace_Energy()
704-
{
705-
storedHGVDW = HGVDW;
706-
storedHGReal= HGReal;
707-
storedHGEwaldE = HGEwaldE;
708-
HGVDW = 0.0;
709-
HGReal= 0.0;
710-
HGEwaldE = 0.0;
711-
}
712-
double DNN_Correction() //Using DNN energy to replace HGVDW, HGReal and HGEwaldE//
713-
{
714-
double correction = DNN_E - storedHGVDW - storedHGReal - storedHGEwaldE;
715-
return correction;
716-
};
717-
};
724+
718725
/*
719726
__host__ MoveEnergy MoveEnergy_Multiply(MoveEnergy A, MoveEnergy B)
720727
{

src_clean/fxn_main.h

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ inline void Copy_AtomData_from_Device(Atoms* System, Atoms* Host_System, Atoms*
442442
}
443443
}
444444

445-
inline void PRINT_ENERGY_AT_STAGE(Components& SystemComponents, int stage, Units& Constants)
445+
inline void PRINT_ENERGY_AT_STAGE(Components& SystemComponents, int stage, Units& Constants, size_t comp)
446446
{
447447
std::string stage_name;
448448
MoveEnergy E;
@@ -459,6 +459,8 @@ inline void PRINT_ENERGY_AT_STAGE(Components& SystemComponents, int stage, Units
459459
case GPU_DRIFT: {stage_name = "GPU DRIFT (GPU FINAL - CPU FINAL)"; E = SystemComponents.Final_Energy - SystemComponents.GPU_Energy; break;}
460460
case AVERAGE: {stage_name = "PRODUCTION PHASE AVERAGE ENERGY"; E = SystemComponents.AverageEnergy + SystemComponents.Initial_Energy;break;}
461461
case AVERAGE_ERR: {stage_name = "PRODUCTION PHASE AVERAGE ENERGY ERRORBAR"; E = SystemComponents.AverageEnergy_Errorbar; break;}
462+
case WIDOM_AVG: {stage_name = "AVERAGE WIDOM ADSORPTION ENERGY for " + SystemComponents.MoleculeName[comp]; E = SystemComponents.Moves[comp].WidomEnergy;break;}
463+
case WIDOM_ERR: {stage_name = "WIDOM ADSORPTION ENERGY ERRORBAR for " + SystemComponents.MoleculeName[comp]; E = SystemComponents.Moves[comp].WidomEnergy_ERR;break;}
462464
}
463465
fprintf(SystemComponents.OUTPUT, " *** %s *** \n", stage_name.c_str());
464466
fprintf(SystemComponents.OUTPUT, "========================================================================\n");
@@ -501,19 +503,28 @@ void ENERGY_SUMMARY(Variables& Vars)
501503
for(size_t i = 0; i < NumberOfSimulations; i++)
502504
{
503505
fprintf(SystemComponents[i].OUTPUT, "======================== ENERGY SUMMARY (Simulation %zu) =========================\n", i);
504-
PRINT_ENERGY_AT_STAGE(SystemComponents[i], INITIAL, Constants);
505-
PRINT_ENERGY_AT_STAGE(SystemComponents[i], CREATEMOL, Constants);
506-
PRINT_ENERGY_AT_STAGE(SystemComponents[i], CREATEMOL_DELTA, Constants);
507-
PRINT_ENERGY_AT_STAGE(SystemComponents[i], CREATEMOL_DELTA_CHECK, Constants);
508-
PRINT_ENERGY_AT_STAGE(SystemComponents[i], FINAL, Constants);
509-
PRINT_ENERGY_AT_STAGE(SystemComponents[i], DELTA, Constants);
510-
PRINT_ENERGY_AT_STAGE(SystemComponents[i], DELTA_CHECK, Constants);
511-
PRINT_ENERGY_AT_STAGE(SystemComponents[i], DRIFT, Constants);
512-
PRINT_ENERGY_AT_STAGE(SystemComponents[i], GPU_DRIFT, Constants);
506+
PRINT_ENERGY_AT_STAGE(SystemComponents[i], INITIAL, Constants, 0);
507+
PRINT_ENERGY_AT_STAGE(SystemComponents[i], CREATEMOL, Constants, 0);
508+
PRINT_ENERGY_AT_STAGE(SystemComponents[i], CREATEMOL_DELTA, Constants, 0);
509+
PRINT_ENERGY_AT_STAGE(SystemComponents[i], CREATEMOL_DELTA_CHECK, Constants, 0);
510+
PRINT_ENERGY_AT_STAGE(SystemComponents[i], FINAL, Constants, 0);
511+
PRINT_ENERGY_AT_STAGE(SystemComponents[i], DELTA, Constants, 0);
512+
PRINT_ENERGY_AT_STAGE(SystemComponents[i], DELTA_CHECK, Constants, 0);
513+
PRINT_ENERGY_AT_STAGE(SystemComponents[i], DRIFT, Constants, 0);
514+
PRINT_ENERGY_AT_STAGE(SystemComponents[i], GPU_DRIFT, Constants, 0);
513515
fprintf(SystemComponents[i].OUTPUT, "================================================================================\n");
514516
fprintf(SystemComponents[i].OUTPUT, "======================== PRODUCTION PHASE AVERAGE ENERGIES (Simulation %zu) =========================\n", i);
515-
PRINT_ENERGY_AT_STAGE(SystemComponents[i], AVERAGE, Constants);
516-
PRINT_ENERGY_AT_STAGE(SystemComponents[i], AVERAGE_ERR, Constants);
517+
PRINT_ENERGY_AT_STAGE(SystemComponents[i], AVERAGE, Constants, 0);
518+
PRINT_ENERGY_AT_STAGE(SystemComponents[i], AVERAGE_ERR, Constants, 0);
519+
fprintf(SystemComponents[i].OUTPUT, "================================================================================\n");
520+
521+
fprintf(SystemComponents[i].OUTPUT, "======================== WIDOM ADSORPTION ENERGIES (Simulation %zu) =========================\n", i);
522+
for(size_t j = 1; j < SystemComponents[i].NComponents.x; j++)
523+
{
524+
if(SystemComponents[i].Moves[j].WidomProb < 1e-10) continue;
525+
PRINT_ENERGY_AT_STAGE(SystemComponents[i], WIDOM_AVG, Constants, j);
526+
PRINT_ENERGY_AT_STAGE(SystemComponents[i], WIDOM_ERR, Constants, j);
527+
}
517528
fprintf(SystemComponents[i].OUTPUT, "================================================================================\n");
518529

519530
fprintf(SystemComponents[i].OUTPUT, "DNN Rejection Summary:\nTranslation+Rotation: %zu\nReinsertion: %zu\nInsertion: %zu\nDeletion: %zu\nSingleSwap: %zu\n", SystemComponents[i].TranslationRotationDNNReject, SystemComponents[i].ReinsertionDNNReject, SystemComponents[i].InsertionDNNReject, SystemComponents[i].DeletionDNNReject, SystemComponents[i].SingleSwapDNNReject);

src_clean/print_statistics.cuh

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,21 @@ static inline void ComputeFugacity(double& AverageWr, double& AverageMu, double&
8989

9090
static inline void Print_Widom_Statistics(Components& SystemComponents, Boxsize Box, Units& Constants, size_t comp)
9191
{
92-
Move_Statistics MoveStats = SystemComponents.Moves[comp];
92+
Move_Statistics& MoveStats = SystemComponents.Moves[comp];
9393
double2 totRosen = {0.0, 0.0};
9494
double2 totMu = {0.0, 0.0};
9595
double2 totHenry = {0.0, 0.0};
96-
double2 totFuga = {0.0, 0.0};
96+
double2 totFuga = {0.0, 0.0};
97+
MoveEnergy AverageEnergy;
98+
MoveEnergy AverageEnergy_SQ;
99+
97100
fprintf(SystemComponents.OUTPUT, "=====================Rosenbluth Summary For Component [%zu] (%s)=====================\n", comp, SystemComponents.MoleculeName[comp].c_str());
98101
fprintf(SystemComponents.OUTPUT, "There are %zu blocks\n", SystemComponents.Nblock);
99102
for(size_t i = 0; i < SystemComponents.Nblock; i++)
100103
{
101104
fprintf(SystemComponents.OUTPUT, "=====BLOCK %zu=====\n", i);
102105
fprintf(SystemComponents.OUTPUT, "Widom Performed: %.1f\n", MoveStats.Rosen[i].Total.z);
106+
double OverallAvgWr = 0.0;
103107
if(MoveStats.Rosen[i].Total.z > 0)
104108
{
105109
double AverageWr = 0.0; double AverageMu = 0.0; double AverageHenry = 0.0; double Fugacity = 0.0;
@@ -112,6 +116,8 @@ static inline void Print_Widom_Statistics(Components& SystemComponents, Boxsize
112116
totMu.x += AverageMu; totMu.y += AverageMu * AverageMu;
113117
totHenry.x += AverageHenry; totHenry.y += AverageHenry * AverageHenry;
114118
totFuga.x += Fugacity; totFuga.y += Fugacity * Fugacity;
119+
120+
OverallAvgWr = AverageWr;
115121
}
116122
if(MoveStats.Rosen[i].Insertion.z > 0)
117123
{
@@ -129,7 +135,21 @@ static inline void Print_Widom_Statistics(Components& SystemComponents, Boxsize
129135
fprintf(SystemComponents.OUTPUT, "(Deletion) Averaged Excess Mu: %.10f\n", AverageMu);
130136
fprintf(SystemComponents.OUTPUT, "(Deletion) Converted to Fugacity: %.10f [Pascal], Temp: %.5f [K]\n", Fugacity, SystemComponents.Temperature);
131137
}
138+
139+
//Add Widom Delta Energy
140+
//Calculate just the overall, now//
141+
if(MoveStats.Rosen[i].Total.z > 0)
142+
{
143+
printf("Raw WIDOM %zu", i); MoveStats.Rosen[i].widom_energy.print();
144+
MoveEnergy Average = MoveStats.Rosen[i].widom_energy / static_cast<double>(MoveStats.Rosen[i].Total.z) / OverallAvgWr;
145+
printf("AVG WIDOM %zu", i); Average.print();
146+
AverageEnergy += Average / static_cast<double>(SystemComponents.Nblock);
147+
AverageEnergy_SQ += Average * Average / static_cast<double>(SystemComponents.Nblock);
148+
}
132149
}
150+
MoveEnergy AverageEnergy_Errorbar = sqrt_MoveEnergy(AverageEnergy_SQ - AverageEnergy * AverageEnergy) * 2.0;
151+
SystemComponents.Moves[comp].WidomEnergy = AverageEnergy;
152+
SystemComponents.Moves[comp].WidomEnergy_ERR = AverageEnergy_Errorbar;
133153

134154
double2 AvgBlockRosen = {0.0, 0.0};
135155
AvgBlockRosen.x = totRosen.x / (double) SystemComponents.Nblock;

0 commit comments

Comments
 (0)