Changed usage of ArrayList in interface to regular List.

This commit is contained in:
Andreas Dräger 2010-02-18 17:52:39 +00:00
parent e69fdc8696
commit 9687ff1fa9
3 changed files with 49 additions and 51 deletions

View File

@ -3,7 +3,7 @@
*/ */
package eva2.tools.math.des; package eva2.tools.math.des;
import java.util.ArrayList; import java.util.List;
@ -22,13 +22,14 @@ public interface EventDESystem extends DESystem {
* of the species stored in Y. The new values for the species * of the species stored in Y. The new values for the species
* are stored in res. The positions in the array returned by this method * are stored in res. The positions in the array returned by this method
* correspond to the positions in Y/res. * correspond to the positions in Y/res.
* @param res
* *
* @return Returns an array with delays for the change of concentration due to events * @return Returns an array with delays for the change of concentration due to events
*/ */
public ArrayList<DESAssignment> processEvents(double t, double Y[]); public List<DESAssignment> processEvents(double t, double Y[], double[] res);
public ArrayList<DESAssignment> processAssignmentRules(double t, double Y[]); public List<DESAssignment> processAssignmentRules(double t, double Y[]);
public ArrayList<DESAssignment> processAlgebraicRules(double t, double Y[]); public List<DESAssignment> processAlgebraicRules(double t, double Y[]);
} }

View File

@ -3,19 +3,19 @@ package eva2.tools.math.des;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import eva2.tools.math.Mathematics; import eva2.tools.math.Mathematics;
/** /**
* Title: JAVA-EVA Description: Runge-Kutta Method with Events Copyright: Copyright (c) 2002 * Title: JAVA-EVA Description: Runge-Kutta Method with Events Copyright:
* Company: University of T&uuml;bingen, Computer Architecture * Copyright (c) 2002 Company: University of T&uuml;bingen, Computer
* Architecture
* *
* @author Hannes Planatscher * @author Hannes Planatscher
* @author Andreas Dr&auml;ger * @author Andreas Dr&auml;ger
* @author Marcel Kronfeld * @author Marcel Kronfeld
* @author Alexander D&ouml;rr * @author Alexander D&ouml;rr
* @version 1.1 Status: works, but numerical inaccurate. Modified to process events, e.g. sudden * @version 1.1 Status: works, but numerical inaccurate. Modified to process
* changes in the absolute values of the system * events, e.g. sudden changes in the absolute values of the system
*/ */
public class RKEventSolver extends AbstractDESSolver implements Serializable { public class RKEventSolver extends AbstractDESSolver implements Serializable {
/** /**
@ -26,6 +26,7 @@ public class RKEventSolver extends AbstractDESSolver implements Serializable {
* *
*/ */
private static boolean useLinearCalc = true; private static boolean useLinearCalc = true;
/** /**
* *
* @param args * @param args
@ -327,8 +328,7 @@ public class RKEventSolver extends AbstractDESSolver implements Serializable {
} }
/** /**
* Processes sudden changes in the system due to events in * Processes sudden changes in the system due to events in the EDES
* the EDES
* *
* @param time * @param time
* @param Ytemp * @param Ytemp
@ -343,17 +343,19 @@ public class RKEventSolver extends AbstractDESSolver implements Serializable {
for (DESAssignment event : EDES.processEvents(time, Ytemp)) { for (DESAssignment event : EDES.processEvents(time, Ytemp)) {
index = event.getIndex(); index = event.getIndex();
//newYtemp[index] = event.getValue() - (Ytemp[index]); // newYtemp[index] = event.getValue() - (Ytemp[index]);
newYtemp[index] = event.getValue() - (Ytemp[index] - change[index]); newYtemp[index] = event.getValue() - (Ytemp[index] - change[index]);
System.out.printf("time %s: \tYtemp[%s]_old = %s\tYtemp[%s]_new = %s\t change %s \n", System.out
time,index, Ytemp[index], index, (event.getValue() - (Ytemp[index])),change[index]); .printf(
"time %s: \tYtemp[%s]_old = %s\tYtemp[%s]_new = %s\t change %s \n",
time, index, Ytemp[index], index,
(event.getValue() - (Ytemp[index])), change[index]);
} }
return newYtemp; return newYtemp;
} }
/** /**
* *
* @param time * @param time
@ -361,8 +363,7 @@ public class RKEventSolver extends AbstractDESSolver implements Serializable {
* @param EDES * @param EDES
* @return * @return
*/ */
public void processRules(double time, double[] Ytemp, public void processRules(double time, double[] Ytemp, EventDESystem EDES) {
EventDESystem EDES){
int index; int index;
for (DESAssignment event : EDES.processAssignmentRules(time, Ytemp)) { for (DESAssignment event : EDES.processAssignmentRules(time, Ytemp)) {
index = event.getIndex(); index = event.getIndex();
@ -371,7 +372,6 @@ public class RKEventSolver extends AbstractDESSolver implements Serializable {
} }
/** /**
* When set to <code>TRUE</code>, <code>includeTimes</code> will make the * When set to <code>TRUE</code>, <code>includeTimes</code> will make the
* solver to return a matrix with the first column containing the times. By * solver to return a matrix with the first column containing the times. By
@ -418,22 +418,18 @@ public class RKEventSolver extends AbstractDESSolver implements Serializable {
else else
Ytemp = result[i - 1].clone(); Ytemp = result[i - 1].clone();
// Ytemp = processEventsVoid(x, Ytemp,EDES); // Ytemp = processEventsVoid(x, Ytemp,EDES);
for (int j = 0; j < inbetweensteps; j++) { for (int j = 0; j < inbetweensteps; j++) {
if (useLinearCalc) if (useLinearCalc)
rkTerm2(EDES, h, x, Ytemp, change); rkTerm2(EDES, h, x, Ytemp, change);
else else
change = rkTerm(EDES, h, x, Ytemp); change = rkTerm(EDES, h, x, Ytemp);
// System.out.println("aft change 0 " + change[0]); // System.out.println("aft change 0 " + change[0]);
Mathematics.vvAdd(Ytemp, change, Ytemp); Mathematics.vvAdd(Ytemp, change, Ytemp);
if (this.nonnegative) { if (this.nonnegative) {
for (int k = 0; k < Ytemp.length; k++) { for (int k = 0; k < Ytemp.length; k++) {
if (Ytemp[k] < 0) if (Ytemp[k] < 0)
@ -537,14 +533,14 @@ public class RKEventSolver extends AbstractDESSolver implements Serializable {
return result; return result;
} }
@Override // @Override
public double[][] solveAtTimePoints(DESystem DES, double[] initialvalue, public double[][] solveAtTimePoints(DESystem DES, double[] initialvalue,
double[] timepoints) { double[] timepoints) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
@Override // @Override
public double[][] solveAtTimePointsWithInitialConditions(DESystem DES, public double[][] solveAtTimePointsWithInitialConditions(DESystem DES,
double[][] initconditions, double[] timepoints) { double[][] initconditions, double[] timepoints) {
// TODO Auto-generated method stub // TODO Auto-generated method stub

View File

@ -326,19 +326,21 @@ public class RKSolverV2 extends AbstractDESSolver implements Serializable {
double[] res = new double[Ytemp.length]; double[] res = new double[Ytemp.length];
// Arrays.fill(res, 0); // Arrays.fill(res, 0);
double[] delays = EDES.processEvents(time, Ytemp, res); double[] delays = EDES.processEvents(time, Ytemp, res);
System.out.println("delay " +Arrays.toString(delays)); System.out.println("delay " + Arrays.toString(delays));
for (int j = 0; j < delays.length; j++) for (int j = 0; j < delays.length; j++)
if (!Double.isNaN(delays[j])) { if (!Double.isNaN(delays[j])) {
System.out.printf("time %s :Ytemp[%s]_old = %s\tYtemp[%s]_new = %s\n", System.out.printf(
time,j, Ytemp[j], j, (res[j] - Ytemp[j])); "time %s :Ytemp[%s]_old = %s\tYtemp[%s]_new = %s\n",
Ytemp[j] = res[j] - Ytemp[j]; time, j, Ytemp[j], j, (res[j] - Ytemp[j]));
} else Ytemp[j] = 0d; Ytemp[j] = res[j] - Ytemp[j];
} else
Ytemp[j] = 0d;
return Ytemp; return Ytemp;
} }
public static boolean containsNaN(double[] arr){ public static boolean containsNaN(double[] arr) {
for (int i = 0; i < arr.length; i++) { for (int i = 0; i < arr.length; i++) {
if (Double.isNaN(arr[i])) if (Double.isNaN(arr[i]))
return true; return true;
@ -408,7 +410,7 @@ public class RKSolverV2 extends AbstractDESSolver implements Serializable {
Ytemp = result[i - 1].clone(); Ytemp = result[i - 1].clone();
// process events // process events
//double[] YtempClone = processEvents(x, Ytemp.clone(), EDES); // double[] YtempClone = processEvents(x, Ytemp.clone(), EDES);
// Ytemp = processEventsVoid(x, Ytemp,EDES); // Ytemp = processEventsVoid(x, Ytemp,EDES);
for (int j = 0; j < inbetweensteps; j++) { for (int j = 0; j < inbetweensteps; j++) {
@ -421,7 +423,6 @@ public class RKSolverV2 extends AbstractDESSolver implements Serializable {
Mathematics.vvAdd(Ytemp, change, Ytemp); Mathematics.vvAdd(Ytemp, change, Ytemp);
if (this.nonnegative) { if (this.nonnegative) {
for (int k = 0; k < Ytemp.length; k++) { for (int k = 0; k < Ytemp.length; k++) {
if (Ytemp[k] < 0) if (Ytemp[k] < 0)
@ -434,11 +435,11 @@ public class RKSolverV2 extends AbstractDESSolver implements Serializable {
// process events // process events
double[] YtempClone2 = processEvents(x, Ytemp.clone(), EDES); double[] YtempClone2 = processEvents(x, Ytemp.clone(), EDES);
Mathematics.vvAdd(Ytemp, YtempClone2, Ytemp); Mathematics.vvAdd(Ytemp, YtempClone2, Ytemp);
//processEventsVoid(x, Ytemp,EDES); // processEventsVoid(x, Ytemp,EDES);
} }
// ohne wirkung // ohne wirkung
//Mathematics.vvAdd(Ytemp, YtempClone, Ytemp); // Mathematics.vvAdd(Ytemp, YtempClone, Ytemp);
h = timePoints[i] - x; h = timePoints[i] - x;
@ -523,14 +524,14 @@ public class RKSolverV2 extends AbstractDESSolver implements Serializable {
return result; return result;
} }
@Override // @Override
public double[][] solveAtTimePoints(DESystem DES, double[] initialvalue, public double[][] solveAtTimePoints(DESystem DES, double[] initialvalue,
double[] timepoints) { double[] timepoints) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
@Override // @Override
public double[][] solveAtTimePointsWithInitialConditions(DESystem DES, public double[][] solveAtTimePointsWithInitialConditions(DESystem DES,
double[][] initconditions, double[] timepoints) { double[][] initconditions, double[] timepoints) {
// TODO Auto-generated method stub // TODO Auto-generated method stub