Skip to content

Instantly share code, notes, and snippets.



Last active Nov 16, 2017
What would you like to do?
@ComponentInfo(name="VectorRhsODE", category="ODE")
public class VectorRhsODE implements Serializable, VectorRhsODEInterface {
private static final long serialVersionUID = 1L;
private transient Script script;
@MethodInfo(name="", valueName="", valueStyle="default", valueOptions="", hide=false)
public VectorRhsODEInterface setExpression(
@ParamInfo(name="<html><b>Vector-valued Function f(t,u)</b>: <br>Param: double t, double[] <b>u</b><br>Return: double[] <b>f</b></hmtl>", style="code", options="") String expression) {
GroovyShell shell = new GroovyShell();
script = shell.parse("import static java.lang.Math.*;"
+ "import eu.mihosoft.vrl.types.*;"
+ "f = new double[u.length];"
+ expression);
return this;
@MethodInfo(name="", valueName="", valueStyle="array", valueOptions="", hide=true)
public double[] run(
@ParamInfo(name="t", style="", options="") double t,
@ParamInfo(name="u", style="array", options="") double[] u) {
if(script != null){
script.setProperty("u", u);
script.setProperty("t", t);;
return (double[]) script.getProperty("f");
} else {
throw(new RuntimeException("No user function specified."));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment