Skip to content

Commit

Permalink
Merge pull request #209 from kreft/April_fixes
Browse files Browse the repository at this point in the history
Fix for agent spawners not completing spine function initialization
  • Loading branch information
Secondus2 authored Apr 20, 2022
2 parents 6fe068f + b61f6cd commit 30ff2d2
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 11 deletions.
56 changes: 56 additions & 0 deletions src/agent/AgentHelperMethods.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package agent;

import dataIO.Log;
import expression.Expression;
import idynomics.Global;
import idynomics.Idynomics;
import referenceLibrary.AspectRef;
import surface.link.LinearSpring;
import surface.link.Spring;
import surface.link.TorsionSpring;
import utility.Helper;

public class AgentHelperMethods {
public static void springInitialization(Agent a)
{
Body b = (Body) a.get(AspectRef.agentBody);
for( Spring s : b.getSpringsToEvaluate())
{
if( s != null )
{
if( !s.ready())
{
s.setStiffness( Helper.setIfNone( a.getDouble(AspectRef.spineStiffness),
1e6));
//TODO warn user if not set
if( s instanceof LinearSpring)
{
Expression spineFun;
if ( !Helper.isNullOrEmpty( a.getValue(
AspectRef.agentSpineFunction )))
spineFun = new Expression((String)
a.getValue(AspectRef.agentSpineFunction ));
else
spineFun = Global.fallback_spinefunction;
s.setSpringFunction( spineFun );
}
else if( s instanceof TorsionSpring)
{
Expression torsFun = null;
if ( !Helper.isNullOrEmpty(
a.getValue(AspectRef.torsionFunction)))
torsFun = (Expression)
a.getValue(AspectRef.torsionFunction);
else
{
/* TODO set default maybe? */
Idynomics.simulator.interupt(
"missing torsion spring function in relax");
}
s.setSpringFunction( torsFun );
}
}
}
}
}
}
1 change: 1 addition & 0 deletions src/agent/Body.java
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ public Body(Morphology morphology, double[] positionA, double[] positionB,
default:
break;
}
this.constructBody();
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/compartment/agentStaging/DistributedSpawner.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.LinkedList;

import agent.AgentHelperMethods;
import org.w3c.dom.Element;

import agent.Agent;
Expand Down Expand Up @@ -120,6 +121,7 @@ private void spawnAgent(double[] location)
newAgent.set(AspectRef.agentBody,
new Body( this.getMorphology(), location, 0.0, 0.0 ) );
newAgent.setCompartment( this.getCompartment() );
AgentHelperMethods.springInitialization(newAgent);
newAgent.registerBirth();
}
}
2 changes: 2 additions & 0 deletions src/compartment/agentStaging/RandomSpawner.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package compartment.agentStaging;

import agent.AgentHelperMethods;
import org.w3c.dom.Element;

import agent.Agent;
Expand Down Expand Up @@ -32,6 +33,7 @@ public void spawn()
newRandom.set(AspectRef.agentBody,
new Body( this.getMorphology(), this.getSpawnDomain() ));
newRandom.setCompartment( this.getCompartment() );
AgentHelperMethods.springInitialization(newRandom);
newRandom.registerBirth();
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/idynomics/Global.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.text.SimpleDateFormat;
import java.util.Date;

import expression.Expression;
import org.w3c.dom.Element;

import dataIO.Log;
Expand Down Expand Up @@ -382,4 +383,11 @@ public void updateSettings()
* Number of digits (including leading zeros) in file numbering
*/
public static int file_number_of_digits = 5;

/**
* fall back spine function for if nothing is set TODO it may be a better option to just
* warn and instruct the user, function might not be the best as a default
*/
public static Expression fallback_spinefunction =
new Expression( "stiffness * ( dh + SIGN(dh) * dh * dh * 100.0 )" );
}
15 changes: 4 additions & 11 deletions src/processManager/library/AgentRelaxation.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,13 @@ private enum Method
* limit duration of biofilm compression
*/
private double compresionDuration = 0.0;

/**
* TODO check whether implementation is finished
* Default spine function, fall back for if none is defined by the agent.
*/
private Expression _spineFunction =
new Expression( "stiffness * ( dh + SIGN(dh) * dh * dh * 100.0 )" );
//private Expression _spineFunction =
// new Expression( "stiffness * ( dh + SIGN(dh) * dh * dh * 100.0 )" );

private Boolean _decompression;

Expand Down Expand Up @@ -274,13 +274,6 @@ public void init(Element xmlElem, EnvironmentContainer environment,
this.compresionDuration = Helper.setIfNone(
this.getDouble(COMPRESSION_DURATION), 0.0 );

/* Set default spine function for rod type agents, this function is
* used if it is not overwritten by the agent, obtain
* ComponentExpression from process manager otherwise fall back default
* is used. */
if ( ! Helper.isNullOrEmpty( this.getValue(SPINE_FUNCTION) ) )
this._spineFunction = new Expression((String) this.getValue(SPINE_FUNCTION));

/* Include decompression */
this._decompression = Helper.setIfNone( this.getBoolean(DECOMPRESSION),
false);
Expand Down Expand Up @@ -609,7 +602,7 @@ private void springEvaluation(Agent a, Body b)
spineFun = new Expression((String)
a.getValue(AspectRef.agentSpineFunction ));
else
spineFun = this._spineFunction;
spineFun = Global.fallback_spinefunction;
s.setSpringFunction( spineFun );
}
else if( s instanceof TorsionSpring )
Expand Down

0 comments on commit 30ff2d2

Please sign in to comment.