JaRMoS  1.1
Java Reduced Model Simulations
 All Classes Namespaces Files Functions Variables Enumerator Groups Pages
ImplicitLinearEulerIntegrator.java
Go to the documentation of this file.
1 package kermor;
2 
4 
5 import org.apache.commons.math.linear.ArrayRealVector;
6 import org.apache.commons.math.linear.DecompositionSolver;
7 import org.apache.commons.math.linear.LUDecompositionImpl;
8 import org.apache.commons.math.linear.RealMatrix;
9 import org.apache.commons.math.linear.RealVector;
10 import org.apache.commons.math.ode.AbstractIntegrator;
11 import org.apache.commons.math.ode.DerivativeException;
12 import org.apache.commons.math.ode.FirstOrderDifferentialEquations;
13 import org.apache.commons.math.ode.IntegratorException;
14 
21 public class ImplicitLinearEulerIntegrator extends AbstractIntegrator {
22 
23  private double dt;
25 
27  this.dt = dt;
28  this.model = model;
29  if (!(model.system.f instanceof AffParamTimeCoreFun)) {
30  throw new RuntimeException("Not yet implemented.");
31  }
32  }
33 
38  @Override
39  public double integrate(FirstOrderDifferentialEquations equations, double t0, double[] y0, double T, double[] yarr)
40  throws DerivativeException, IntegratorException {
41 
42  // sanityChecks(equations, t0, y0, T, y);
43  // setEquations(equations);
44  // resetEvaluations();
45  ReducedSystem sys = model.system;
46 
47  if (yarr != y0) {
48  System.arraycopy(y0, 0, yarr, 0, y0.length);
49  }
50  RealVector y = new ArrayRealVector(yarr);
51 
52  // Mass matrix
53  RealMatrix M = null;
54  // Time-independent mass matrix
55  if (!sys.M.isTimeDependent()) {
56  M = sys.M.evaluate(0, sys.currentMu());
57  }
58  RealMatrix A = null;
59  // time-independent A matrix
60  if (!sys.f.timeDependent()) {
61  A = ((AffParamTimeCoreFun) sys.f).getAffParamMatrix().compose(0, sys.currentMu());
62  }
63 
64  DecompositionSolver solver = new LUDecompositionImpl(M.add(A.scalarMultiply(dt))).getSolver();
65  double t = t0;
66  RealVector rhs;
67  do {
68  t += dt;
69  rhs = M.operate(y);
70  if (sys.currentInput() > -1) {
71  double[] u = sys.u.evaluate(t, sys.currentInput());
72  RealMatrix B = sys.B.evaluate(t, sys.currentMu()).scalarMultiply(dt);
73  double[] tmp = B.operate(u);
74  rhs = rhs.add(tmp);
75  }
76 
77  y = solver.solve(rhs);
78 
79  model.handleStep(t, y.toArray(), null, t == T);
80  } while (t < T);
81 
82  return T;
83  }
84 
85 }
double integrate(FirstOrderDifferentialEquations equations, double t0, double[] y0, double T, double[] yarr)
Main reduced model class.
Custom implicit euler integrator class.
This class implements a time/parameter-affine linear core function .
Main reduced dynamical system class.
ImplicitLinearEulerIntegrator(ReducedModel model, double dt)
ReducedSystem system