anderkve / FYS3150

https://anderkve.github.io/FYS3150
26 stars 14 forks source link

Total energy function #77

Closed JohanCarlsen closed 1 year ago

JohanCarlsen commented 1 year ago

Hi! I've implemented the MCMC algorithm and started running some tests. I can't seem to get the right results for the total energy. I'm not sure at all that what I have done is correct, but I really think it should be. The link to the code I think is making trouble is here: https://github.com/Madssb/FYS3150_H22_4_pers/blob/c56b21cc240ceed11f092d8e9b4eada9b00a7fcc/Project_4/src/energy_magnetization.cpp. If anyone has the time, a quick review of the other files in the repo would be much appreciated. Either way, the group teachers will have to help me tomorrow =)

anderkve commented 1 year ago

Hi @JohanCarlsen!

It's easier to provide help if you provide some more specific info on exactly what the presumed wrong results look like (e.g. are the numbers zero, or too large, or does it crash, or...?) But I had a very quick look now, and one thing that looks problematic is this line: https://github.com/Madssb/FYS3150_H22_4_pers/blob/c56b21cc240ceed11f092d8e9b4eada9b00a7fcc/Project_4/ising.cpp#L31

In computing the energy per spin you end up doing integer division, since you use integers both for the total energy and the number of spins. So I assume that will just give you 0 most of the time. Maybe there are other issues I didn't spot, but I'd suggest you start by converting the total energy to a double and test your code again :)

JohanCarlsen commented 1 year ago

Oh, my! This again, hehe! Too used to the python syntax. Thank you!