/* * THIS FILE IS AUTOMATICALLY GENERATED BY THE s2j SCRIPT * DO NOT EDIT. * If you wish to make permanent changes, you should use this file * to test your changes, and then modify s2j so that the automatically * generated version of Model.java has those changes. * When committing changes to CVS, please commit both the s2j * script and the new version of Model.java */ /* * Model.java - stella2java model file. * Copyright 1999-2003 David A. Joiner and the Shodor Edcuation * Foundation, Inc. */ import java.awt.*; import java.applet.Applet; import java.util.*; class Model extends Diffeq { double PI = 3.14159; Random randomNumber = new Random(); double tinitial; double tfinal; double tstep_default; int try_model=0; int ntime; double []xtime; int method; int n_vars; int n_varfs; int n_vartot; int n_rates; int n_convs; int n_flows; int n_graphs; int n_tot; String [] var_label; String [] varf_label; String [] rate_label; String [] conv_label; String [] flow_label; String output_header; double [] var_minsb; double [] rate_minsb; double [] var_maxsb; double [] rate_maxsb; double [] var_defaultsb; double [] rate_defaultsb; int [] var_stylesb; int [] rate_stylesb; double ymin_default; double ymax_default; double [] rate; double [] conv; double [] flow; double [][] x_graph; double [][] y_graph; int [] type_graph; int [] n_graph; static int LINE_GRAPH=0; static int BOX_GRAPH=1; boolean [] allow_display; boolean [] default_display; String gr_title; String gr_depLabel; boolean it_enable; boolean ft_enable; boolean st_enable; boolean imeth_enable; boolean ymin_enable; boolean ymax_enable; boolean adap_enable; boolean adap_default; double tstep; public void init_problem(double st){ // set default status of control display. it_enable=true; ft_enable=true; st_enable=true; imeth_enable=true; ymin_enable=true; ymax_enable=true; adap_enable=true; adap_default=true; tstep_default=0.25 ; ymin_default=0 ; ymax_default=50 ; tinitial=0 ; tfinal=12 ; tstep=st; time=tinitial; // CHANGE THE FOLLOWING WHEN USING THIS TEMPLATE // // --- Set the number of variables and rates --- // n_vars=2 ; n_varfs=0 ; n_vartot=n_vars+n_varfs; n_rates=1 ; n_convs=0 ; n_flows=1 ; n_tot=n_vartot+n_rates+n_convs+n_flows; allow_display = new boolean[n_tot]; default_display = new boolean[n_tot]; allow_display[0]=true; //A default_display[0]=true; allow_display[1]=true; //B default_display[1]=true; allow_display[2]=false; // default_display[2]=false; allow_display[3]=true; // default_display[3]=true; n_graphs=0; n_graph=new int[n_graphs]; type_graph=new int[n_graphs]; int max_graph=0; for (int i=0;imax_graph) max_graph=n_graph[i]; } // --------------------------------------------- // init(n_vartot); rate = new double[n_rates]; conv = new double[n_convs]; flow = new double[n_flows]; ntime=100; xtime = new double[ntime*(1+n_tot)]; var_label=new String[n_vars]; varf_label=new String[n_varfs]; rate_label=new String[n_rates]; conv_label=new String[n_convs]; flow_label=new String[n_flows]; var_minsb=new double[n_vars]; rate_minsb=new double[n_rates]; var_maxsb=new double[n_vars]; rate_maxsb=new double[n_rates]; var_defaultsb=new double[n_vars]; rate_defaultsb=new double[n_rates]; var_stylesb=new int[n_vars]; rate_stylesb=new int[n_rates]; // --- Set default size and value for model ---- // double atob; x[0] = 100.0; x[1] = 1.0; rate[0] = 0.001; flow[0] = rate[0]*x[0]*x[1]; var_minsb[0]=0; var_minsb[1]=0; rate_minsb[0]=0.0001; var_maxsb[0]=1000; var_maxsb[1]=1000; rate_maxsb[0]=0.1; var_defaultsb[0]=x[0]; var_defaultsb[1]=x[1]; rate_defaultsb[0]=rate[0]; var_stylesb[0]=Slider.STYLE_LINEAR; var_stylesb[1]=Slider.STYLE_LINEAR; rate_stylesb[0]=Slider.STYLE_LOG; gr_title = new String("graph"); gr_depLabel = new String("units"); // --------------------------------------------- // // ------- Label variables and rates ----------- // var_label[0]="A"; var_label[1]="B"; rate_label[0]="rate"; flow_label[0]="atob"; output_header=new String(); // --- Set the header line for text output ----- // output_header= "\tTime\tvar1\tvar2\tvar3 \n"; output_header+="---------------------------------------------------"; // --------------------------------------------- // method=EULER; } public void reset_xtime(int newn) { if(newn==ntime) return; ntime=newn; xtime = new double[ntime*(1+n_tot)]; } public void solve(double [] x_var, double [] x_rate, double it, double ft,double st, boolean adaptive){ tinitial=it; tfinal=ft; time=tinitial; tstep=st; int newn=(int)((tfinal-tinitial)/st)+1; reset_xtime(newn); for(int i=0;ifirst_t && remainder(time,interval_t)>0.0 && remainder(time,interval_t)<=tstep) return (x/tstep); else return 0.0; } public double ramp(double slope) { return time*slope; } public double ramp(double slope,double ramp_start) { if (time>ramp_start) { return (time-ramp_start)*slope; } else { return 0; } } public double step(double height,double step_time) { if(time>=step_time) { return height; } else { return 0; } } public double graph(int index,double dep_var) { //access xgraph_i,j, ygraph_i,j, ngraph_i, n_graphs. if(dep_varx_graph[index][n_graph[index]-1]) { //take upper boundary value return y_graph[index][n_graph[index]-1]; } else { //find which element to use, linear intepolation for(int i=0;i=x_graph[index][i]&&dep_vartest) { retval++; product*=Math.random(); } return (double)retval; } }