From c78f64279338b7f4c9a9d7ccbee08bd1818e6773 Mon Sep 17 00:00:00 2001 From: jessicasyu <15913767+jessicasyu@users.noreply.github.com> Date: Tue, 6 Jun 2023 14:41:54 -0400 Subject: [PATCH] Modify junction hamiltonian delta --- src/arcade/potts/parameter.potts.xml | 2 +- .../sim/hamiltonian/JunctionHamiltonian.java | 28 ++++------ .../hamiltonian/JunctionHamiltonianTest.java | 51 +++++++++++++++---- 3 files changed, 53 insertions(+), 28 deletions(-) diff --git a/src/arcade/potts/parameter.potts.xml b/src/arcade/potts/parameter.potts.xml index a5496b8b..c0d66c6f 100644 --- a/src/arcade/potts/parameter.potts.xml +++ b/src/arcade/potts/parameter.potts.xml @@ -24,7 +24,7 @@ - + diff --git a/src/arcade/potts/sim/hamiltonian/JunctionHamiltonian.java b/src/arcade/potts/sim/hamiltonian/JunctionHamiltonian.java index ca55b7c9..64a01e4a 100644 --- a/src/arcade/potts/sim/hamiltonian/JunctionHamiltonian.java +++ b/src/arcade/potts/sim/hamiltonian/JunctionHamiltonian.java @@ -52,28 +52,22 @@ public void deregister(PottsCell cell) { /** * {@inheritDoc} *

- * Junction energy is calculated only for the case where the source is media - * (id == 0) and the target is not media (id =/= 0). + * Junction energy is calculated only for the case where both the source + * and the target are not media (id =/= 0). */ @Override public double getDelta(int sourceID, int targetID, int x, int y, int z) { - if (sourceID == 0 && targetID > 0) { - double lambda = configs.get(targetID).getLambda(); - int neighbors = 0; - - for (int i = x - 1; i <= x + 1; i++) { - for (int j = y - 1; j <= y + 1; j++) { - - if (!(i == x && j == y) && ids[z][i][j] != 0) { - neighbors += 1; - } - } - } - - return lambda * neighbors; + if (sourceID == 0 || targetID == 0) { + return 0; } - return 0; + double lambda = configs.get(targetID).getLambda(); + + if (ids[z - 1][x][y] == targetID) { + return -lambda; + } + + return lambda; } /** diff --git a/test/arcade/potts/sim/hamiltonian/JunctionHamiltonianTest.java b/test/arcade/potts/sim/hamiltonian/JunctionHamiltonianTest.java index 4507f606..a0b414bb 100644 --- a/test/arcade/potts/sim/hamiltonian/JunctionHamiltonianTest.java +++ b/test/arcade/potts/sim/hamiltonian/JunctionHamiltonianTest.java @@ -105,21 +105,21 @@ public void deregister_exists_removesConfig() { } @Test - public void getDelta_validIDs_calculatesValue() { + public void getDelta_validIDsTargetMatch_calculatesValue() { int id1 = randomIntBetween(1, 100); int id2 = id1 + randomIntBetween(1, 100); Potts potts = mock(Potts.class); potts.ids = new int[][][] { { - { id1, id1, id1, id1 }, - { id1, id1, id1, id1 }, - { id1, id1, id1, id1 }, + { 0, 0, 0, 0 }, + { 0, 0, id1, 0 }, + { 0, 0, 0, 0 }, }, { - { id2, id2, 0, 0 }, - { id2, 0, 0, id1 }, - { id2, id2, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, id2, 0 }, + { 0, 0, 0, 0 }, }, }; @@ -131,8 +131,39 @@ public void getDelta_validIDs_calculatesValue() { jh.configs.put(id1, config); - double delta = jh.getDelta(0, id1, 1, 2, 1); - assertEquals(3 * lambda, delta, EPSILON); + double delta = jh.getDelta(id2, id1, 1, 2, 1); + assertEquals(-lambda, delta, EPSILON); + } + + @Test + public void getDelta_validIDsSourceMatch_calculatesValue() { + int id1 = randomIntBetween(1, 100); + int id2 = id1 + randomIntBetween(1, 100); + + Potts potts = mock(Potts.class); + potts.ids = new int[][][] { + { + { 0, 0, 0, 0 }, + { 0, 0, id2, 0 }, + { 0, 0, 0, 0 }, + }, + { + { 0, 0, 0, 0 }, + { 0, 0, id2, 0 }, + { 0, 0, 0, 0 }, + }, + }; + + JunctionHamiltonianConfig config = mock(JunctionHamiltonianConfig.class); + double lambda = randomDoubleBetween(10, 100); + doReturn(lambda).when(config).getLambda(); + + JunctionHamiltonian jh = new JunctionHamiltonian(mock(PottsSeries.class), potts); + + jh.configs.put(id1, config); + + double delta = jh.getDelta(id2, id1, 1, 2, 1); + assertEquals(lambda, delta, EPSILON); } @Test @@ -148,7 +179,7 @@ public void getDelta_invalidIDs_returnsZeros() { double delta2 = jh.getDelta(id1, 0, 0, 0, 0); assertEquals(0, delta2, EPSILON); - double delta3 = jh.getDelta(id1, id2, 0, 0, 0); + double delta3 = jh.getDelta(0, id2, 0, 0, 0); assertEquals(0, delta3, EPSILON); }