root/trunk/matml/src/sphlow/BaseControls.java

Revision 148, 8.4 kB (checked in by powell, 7 years ago)

New Sphlow Java applet.

  • Property svn:keywords set to Author Date Id Revision
Line 
1import java.awt.*;
2
3// The class which handles the basic controls
4public class BaseControls extends Panel {
5  // FRe fff; // Friction factor-Reynolds number graph
6  PlotPanel pp; PlotSpecial ps;
7  TextField mufield, rhofield, gfield, rpfield, ufield, drfield, mdfield;
8  Label inplab, mulabel, rholabel, glabel, rplabel, ulabel;
9  Label reslab, Relab, flab, dlab, mlab;
10  Label curvlab, numlab, velab, velshow, drlab, mdlab;
11  Choice liquid, curvenumber; Font bigfont;
12  int currentCurve;
13
14public BaseControls(PlotPanel fff, PlotSpecial sss) {
15  pp=fff; ps=sss; currentCurve=1; setBackground(Color.lightGray);
16
17  GridBagLayout gb = new GridBagLayout();
18  setFont(new Font("Helvetica", Font.PLAIN, 12));
19  bigfont=new Font("Helvetica", Font.BOLD, 14);
20  setLayout(gb);
21
22  GridBagConstraints c = new GridBagConstraints();
23
24  inplab=new Label("Input Parameters (MKS units)", Label.CENTER);//Input params
25  inplab.setFont(bigfont);
26  c.gridx=0; c.gridy=0; c.gridwidth=2; c.gridheight=1;
27  c.anchor=GridBagConstraints.CENTER; gb.setConstraints(inplab,c); add(inplab);
28  c.anchor=GridBagConstraints.WEST; c.gridwidth=1;
29
30  mulabel=new Label("Viscosity:", Label.LEFT);               // Viscosity input
31  c.gridy++; gb.setConstraints(mulabel,c); add(mulabel);
32  mufield=new TextField(Double.toString(pp.mu),7);
33  c.gridx++; gb.setConstraints(mufield,c); add(mufield); c.gridx--;
34
35  rholabel=new Label("Fluid density:", Label.LEFT);      // Fluid density input
36  c.gridy++; gb.setConstraints(rholabel,c); add(rholabel);
37  rhofield=new TextField(Double.toString(pp.rho),7);
38  c.gridx++; gb.setConstraints(rhofield,c); add(rhofield); c.gridx--;
39
40  glabel=new Label("Gravity acceleration:", Label.LEFT);       // Gravity input
41  c.gridy++; gb.setConstraints(glabel,c); add(glabel);
42  gfield=new TextField(Double.toString(pp.g),7);
43  c.gridx++; gb.setConstraints(gfield,c); add(gfield); c.gridx--;
44
45  rplabel=new Label("Particle density:", Label.LEFT); // Particle density input
46  c.gridy++; gb.setConstraints(rplabel,c); add(rplabel);
47  rpfield=new TextField(Double.toString(pp.rho_p),7);
48  c.gridx++; gb.setConstraints(rpfield,c); add(rpfield); c.gridx--;
49
50  ulabel=new Label("Velocity:", Label.LEFT);                  // Velocity input
51  c.gridy++; gb.setConstraints(ulabel,c); add(ulabel);
52  ufield=new TextField(Double.toString(pp.u),7);
53  c.gridx++; gb.setConstraints(ufield,c); add(ufield); c.gridx--;
54
55  reslab=new Label("Results at this point", Label.CENTER);      // The results!
56  reslab.setFont(bigfont);
57  c.gridx=2; c.gridy=0; c.anchor=GridBagConstraints.CENTER;
58  c.gridwidth=2; gb.setConstraints(reslab,c); add(reslab);
59  c.anchor=GridBagConstraints.WEST;
60
61  double Re=pp.dc.rerat(pp.dc.free(pp.rho_p,pp.u));
62  Relab=new Label("Reynolds number: ", Label.LEFT);
63  c.gridy++; gb.setConstraints(Relab,c); add(Relab);
64
65  flab=new Label("Friction factor: ", Label.LEFT);
66  c.gridy++; gb.setConstraints(flab,c); add(flab);
67
68  dlab=new Label("Particle diameter: ", Label.LEFT);
69  c.gridy++; gb.setConstraints(dlab,c); add(dlab);
70
71  mlab=new Label("Liquid:", Label.LEFT);
72  c.gridy+=2; c.gridwidth=1; gb.setConstraints(mlab,c); add(mlab);
73  liquid=new Choice(); liquid.addItem("Water"); liquid.addItem("Molten Ti");
74  c.gridx++; gb.setConstraints(liquid,c); add(liquid); c.gridx--;
75
76  curvlab=new Label("D-rho curve controls", Label.CENTER);   // Curve controls!
77  curvlab.setFont(bigfont);
78  c.gridx=4; c.gridy=0; c.anchor=GridBagConstraints.CENTER;
79  c.gridwidth=2; gb.setConstraints(curvlab,c); add(curvlab);
80  c.anchor=GridBagConstraints.WEST; c.gridwidth=1;
81
82  numlab=new Label("Curve number:", Label.LEFT);
83  c.gridy++; gb.setConstraints(numlab,c); add(numlab);
84  curvenumber=new Choice(); curvenumber.addItem("1"); curvenumber.addItem("2");
85  curvenumber.addItem("3"); curvenumber.addItem("4"); curvenumber.addItem("5");
86  curvenumber.addItem("6"); curvenumber.addItem("7"); curvenumber.addItem("8");
87  curvenumber.addItem("9");
88  c.gridx++; gb.setConstraints(curvenumber,c); add(curvenumber); c.gridx--;
89
90  velab=new Label("Velocity:", Label.LEFT);
91  c.gridy++; gb.setConstraints(velab,c); add(velab);
92  velshow=new Label(Double.toString(pp.u), Label.LEFT);
93  c.gridx++; gb.setConstraints(velshow,c); add(velshow); c.gridx--;
94
95  drlab=new Label("Delta rho:", Label.LEFT);
96  c.gridy++; gb.setConstraints(drlab,c); add(drlab);
97  drfield=new TextField(Double.toString(ps.deltarho),7);
98  c.gridx++; gb.setConstraints(drfield,c); add(drfield); c.gridx--;
99
100  mdlab=new Label("Maximum diameter:", Label.LEFT);
101  c.gridy++; gb.setConstraints(mdlab,c); add(mdlab);
102  mdfield=new TextField(Double.toString(ps.dmax),7);
103  c.gridx++; gb.setConstraints(mdfield,c); add(mdfield); c.gridx--;
104
105  validate(); recalc(); }
106
107public void paint(Graphics g) {}
108
109private void recalc() {
110  double Re=pp.dc.rerat(pp.dc.free(pp.rho_p,pp.u));
111  if(Re==0) throw new Error("Reynolds number > 10^5 not allowed");
112  Relab.setText("Reynolds number: "+Double.toString(Re).substring(0,7));
113  flab.setText("Friction factor: "+
114               Double.toString(pp.dc.f(Re)).substring(0,7));
115  dlab.setText("Particle diameter: "+
116               Double.toString(Re*pp.mu/pp.rho/pp.u).substring(0,7));
117  velshow.setText(Double.toString(pp.u)); }
118
119public boolean action(Event e, Object arg) {
120  if(e.target instanceof TextField) {
121    Double temp; if(e.target==mufield) {
122      double tMu=Double.valueOf(mufield.getText()).doubleValue();
123      if(tMu<=0) {
124        mufield.setText(Double.toString(pp.mu));
125        throw new Error("Non-positive viscosity not allowed."); }
126      pp.mu=tMu; pp.dc.newfluid(pp.mu,pp.rho,pp.g);
127      recalc(); mufield.selectAll(); pp.drawLines(); ps.redoAllPlots(); }
128    else if(e.target==rhofield) {
129      double tRho=Double.valueOf(rhofield.getText()).doubleValue();
130      if(tRho<=0) {
131        rhofield.setText(Double.toString(pp.rho));
132        throw new Error("Non-positive fluid density not allowed."); }
133      if(tRho==pp.rho_p) {
134        rhofield.setText(Double.toString(pp.rho));
135        throw new Error("Don't use particle density as fluid density."); }
136      pp.rho=tRho; pp.dc.newfluid(pp.mu,pp.rho,pp.g);
137      recalc(); rhofield.selectAll(); pp.drawLines(); ps.redoAllPlots(); }
138    else if(e.target==gfield) {
139      double tg=Double.valueOf(gfield.getText()).doubleValue();
140      if(tg==0) {
141        gfield.setText(Double.toString(pp.g));
142        throw new Error("Zero gravity is verboten."); }
143      if(tg<0) gfield.setText(Double.toString(pp.g=-tg)); else pp.g=tg;
144      pp.dc.newfluid(pp.mu,pp.rho,pp.g);
145      recalc(); gfield.selectAll(); pp.drawLines(); ps.redoAllPlots(); }
146    else if(e.target==rpfield) {
147      double tRhop=Double.valueOf(rpfield.getText()).doubleValue();
148      if(tRhop<=0) {
149        rpfield.setText(Double.toString(pp.rho_p));
150        throw new Error("Non-positive particle density not allowed."); }
151      if(tRhop==pp.rho) {
152        rpfield.setText(Double.toString(pp.rho_p));
153        throw new Error("Don't use fluid density as particle density."); }
154      pp.rho_p=tRhop; rpfield.selectAll(); recalc(); pp.drawLines(); }
155    else if(e.target==ufield) {
156      double tu=Double.valueOf(ufield.getText()).doubleValue();
157      if(tu==0) {
158        ufield.setText(Double.toString(pp.u));
159        throw new Error("Zero velocity not allowed"); }
160      if(tu<0) ufield.setText(Double.toString(pp.u=-tu)); else pp.u=tu;
161      ufield.selectAll(); recalc();
162      pp.drawLines(); ps.drawPlot(currentCurve,pp.u); }
163    else if(e.target==drfield) {
164      double ndRho=Double.valueOf(drfield.getText()).doubleValue();
165      if(ndRho<=0) {
166        drfield.setText(Double.toString(ps.deltarho));
167        throw new Error("Non-positive density range not allowed."); }
168      ps.changedRho(ndRho); drfield.selectAll(); }
169    else if(e.target==mdfield) {
170      double nDmax=Double.valueOf(mdfield.getText()).doubleValue();
171      if(nDmax<=0) {
172        mdfield.setText(Double.toString(ps.dmax));
173        throw new Error("Non-positive diameter range not allowed."); }
174      ps.changeDmax(nDmax); mdfield.selectAll(); }
175    return true; }
176  if(e.target instanceof Choice) {
177    if(e.target==liquid) {
178      int i=liquid.getSelectedIndex();
179      if(i==0) { pp.mu=.001; pp.rho=1000; }
180      else if(i==1) { pp.mu=.0052; pp.rho=4100; }
181      mufield.setText(Double.toString(pp.mu));
182      rhofield.setText(Double.toString(pp.rho));
183      pp.dc.newfluid(pp.mu,pp.rho,pp.g);
184      recalc(); pp.drawLines(); ps.redoAllPlots(); }
185    if(e.target==curvenumber) {
186      currentCurve=curvenumber.getSelectedIndex()+1;
187      if(ps.curveExists[currentCurve]) {
188        pp.u=ps.curvelocities[currentCurve]; recalc();
189        ufield.setText(Double.toString(pp.u)); pp.drawLines(); }
190      else {
191        pp.drawLines(); ps.drawPlot(currentCurve,pp.u); }}
192    return true; }
193  return true; }}
Note: See TracBrowser for help on using the browser.