Skip to content

Commit

Permalink
Modify junction hamiltonian delta
Browse files Browse the repository at this point in the history
  • Loading branch information
jessicasyu committed Jun 6, 2023
1 parent 4f8ed6e commit fb4da17
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/arcade/potts/parameter.potts.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<potts.term term="height" id="LAMBDA_NUCLEUS" value="1" />

<!-- height term parameters -->
<potts.term term="junction" id="LAMBDA" value="1" />
<potts.term term="junction" id="LAMBDA" value="100" />

<!-- substrate term parameters -->
<potts.term term="substrate" id="HEIGHT_THRESHOLD" value="9" units="um" conversion="DS^-1" />
Expand Down
28 changes: 11 additions & 17 deletions src/arcade/potts/sim/hamiltonian/JunctionHamiltonian.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,28 +52,22 @@ public void deregister(PottsCell cell) {
/**
* {@inheritDoc}
* <p>
* 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;
}

/**
Expand Down
51 changes: 41 additions & 10 deletions test/arcade/potts/sim/hamiltonian/JunctionHamiltonianTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
},
};

Expand All @@ -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
Expand All @@ -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);
}

Expand Down

0 comments on commit fb4da17

Please sign in to comment.