MCPcopy Create free account
hub / github.com/OpenSourcePhysics/osp / getME

Method getME

src/debugging/physicsapps/IsingApp.java:188–209  ·  view source on GitHub ↗

Calculate the total energy and magnetization by summing over all spin states.

()

Source from the content-addressed store, hash-verified

186 * Calculate the total energy and magnetization by summing over all spin states.
187 */
188 synchronized void getME() {
189 newH = H; // force the two values of H to be equal since we are about to recalculte M and E.
190 fieldChanged = false;
191 int nn_sum = 0;
192 M = 0;
193 for(int i = 0; i<size; i++) {
194 for(int j = 0; j<size; j++) {
195 M += spinData[i][j];
196 if(spinData[i][(j+1)%size]==spinData[i][j]) {
197 nn_sum++;
198 } else {
199 nn_sum--;
200 }
201 if(spinData[(i+1)%size][j]==spinData[i][j]) {
202 nn_sum++;
203 } else {
204 nn_sum--;
205 }
206 }
207 }
208 E = -J*nn_sum-H*M;
209 }
210
211 /**
212 * Adjust the energy to account for changes in the external field.

Callers 2

randomizeCellsMethod · 0.95
initializeAnimationMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected