Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
package eu.mihosoft.vrl.user;
@ComponentInfo(name="JacobianInput", category="ODE")
public class JacobianInput implements Serializable, JacobianInputInterface {
private static final long serialVersionUID = 1L;
private transient Script script;
@MethodInfo(name="", valueName="", valueStyle="default", valueOptions="", hide=false)
public JacobianInputInterface setExpression(
@ParamInfo(name="<html><b>Jacobian J(t,u)</b>: <br>Param: double t, double[] <b>u</b><br>Return: double[][] <b>j</b></hmtl>", style="code", options="") String expression) {
GroovyShell shell = new GroovyShell();
script = shell.parse("import static java.lang.Math.*;"
+ "import eu.mihosoft.vrl.types.*;"
+ "j = new double[u.length][];"
+ expression);
return this
}
@MethodInfo(name="", valueName="Matrix J(t,u)", valueOptions="serialization=false", hide=true)
public double[][] run(
@ParamInfo(name="t", style="", options="") double t,
@ParamInfo(name="u", style="array", options="serialization=false") double[] u) {
if(script != null){
script.setProperty("u", u);
script.setProperty("t", t);
script.run();
return (double[][]) script.getProperty("j");
} 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