View Javadoc

1   /*
2     The TauP Toolkit: Flexible Seismic Travel-Time and Raypath Utilities.
3     Copyright (C) 1998-2000 University of South Carolina
4   
5     This program is free software; you can redistribute it and/or
6     modify it under the terms of the GNU General Public License
7     as published by the Free Software Foundation; either version 2
8     of the License, or (at your option) any later version.
9   
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14  
15    You should have received a copy of the GNU General Public License
16    along with this program; if not, write to the Free Software
17    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18  
19    The current version can be found at 
20    <A HREF="www.seis.sc.edu">http://www.seis.sc.edu</A>
21  
22    Bug reports and comments should be directed to 
23    H. Philip Crotwell, crotwell@seis.sc.edu or
24    Tom Owens, owens@seis.sc.edu
25  
26  */
27  
28  /***
29   * package for storage and manipulation of seismic earth models.
30   *
31   */
32  package edu.sc.seis.TauP;
33  
34  
35  import java.io.DataInputStream;
36  import java.io.DataOutputStream;
37  import java.io.IOException;
38  import java.io.Serializable;
39  
40  /***
41    * The VelocityModelLayer class stores and manipulates a singly layer.
42    * An entire velocity model is implemented as an Vector of layers.
43    *
44    * @version 1.1.3 Wed Jul 18 15:00:35 GMT 2001
45  
46  
47  
48    * @author H. Philip Crotwell
49   */
50  public class VelocityLayer 
51     implements Cloneable, Serializable
52  {
53     private int myLayerNumber;
54     private double topDepth;
55     private double botDepth;
56     private double topPVelocity;
57     private double botPVelocity;
58     private double topSVelocity;
59     private double botSVelocity;
60     private double topDensity=2.6;
61     private double botDensity=2.6;
62     private double topQp=1000;
63     private double botQp=1000;
64     private double topQs=2000;
65     private double botQs=2000;
66  
67     public VelocityLayer() {
68        this.myLayerNumber = 0;
69     }
70  
71     public VelocityLayer(int myLayerNumber) {
72        this.myLayerNumber = myLayerNumber;
73     }
74  
75     public VelocityLayer(int myLayerNumber,
76                           double topDepth,
77                           double botDepth,
78                           double topPVelocity,
79                           double botPVelocity,
80                           double topSVelocity,
81                           double botSVelocity) {
82          this(myLayerNumber,
83               topDepth,
84               botDepth,
85               topPVelocity,
86               botPVelocity,
87               topSVelocity,
88               botSVelocity,
89               2.6,
90               2.6);
91      }
92     public VelocityLayer(int myLayerNumber,
93                           double topDepth,
94                           double botDepth,
95                           double topPVelocity,
96                           double botPVelocity,
97                           double topSVelocity,
98                           double botSVelocity,
99                           double topDensity,
100                          double bottomDensity) {
101         this(myLayerNumber,
102              topDepth,
103              botDepth,
104              topPVelocity,
105              botPVelocity,
106              topSVelocity,
107              botSVelocity,
108              topDensity,
109              bottomDensity,
110              1000,
111              1000,
112              2000,
113              2000);
114     }
115    
116    public VelocityLayer(int myLayerNumber,
117                          double topDepth,
118                          double botDepth,
119                          double topPVelocity,
120                          double botPVelocity,
121                          double topSVelocity,
122                          double botSVelocity,
123                          double topDensity,
124                          double botDensity,
125                          double topQp,
126                          double botQp,
127                          double topQs,
128                          double botQs) {
129        if (topPVelocity <=0) { throw new IllegalArgumentException("topPVelocity must be positive: "+topPVelocity);}
130        if (botPVelocity <=0) { throw new IllegalArgumentException("botPVelocity must be positive: "+botPVelocity);}
131        if (topSVelocity <0) { throw new IllegalArgumentException("topSVelocity must be nonnegative: "+topSVelocity);}
132        if (botSVelocity <0) { throw new IllegalArgumentException("botSVelocity must be nonnegative: "+botSVelocity);}
133        this.myLayerNumber = myLayerNumber;
134        this.topDepth = topDepth;
135        this.botDepth = botDepth;
136        this.topPVelocity = topPVelocity;
137        this.botPVelocity = botPVelocity;
138        this.topSVelocity = topSVelocity;
139        this.botSVelocity = botSVelocity;
140        this.topDensity = topDensity;
141        this.botDensity = botDensity;
142        this.topQp = topQp;
143        this.botQp = botQp;
144        this.topQs = topQs;
145        this.botQs = botQs;
146    }
147 
148    public Object clone() {
149       try {
150          VelocityLayer newObject = (VelocityLayer)super.clone();
151          return newObject;
152       } catch (CloneNotSupportedException e) {
153 	         // Cannot happen, we support clone
154 	         // and our parent is Object, which supports clone.
155          throw new InternalError(e.toString());
156       }
157    }
158 
159    public double evaluateAtBottom(char materialProperty) 
160       throws NoSuchMatPropException
161    {
162       double answer;
163 
164       switch (materialProperty) {
165          case 'P':
166          case 'p':
167             answer = getBotPVelocity();
168             break;
169          case 's':
170          case 'S':
171             answer = getBotSVelocity();
172             break;
173          case 'r': case 'R':
174          case 'D': case 'd':
175             answer = getBotDensity();
176             break;
177          default:
178             throw new NoSuchMatPropException(materialProperty);
179       }
180       return answer;
181    }
182 
183    public double evaluateAtTop(char materialProperty) 
184       throws NoSuchMatPropException
185    {
186       double answer;
187 
188       switch (materialProperty) {
189          case 'P':
190          case 'p':
191             answer = getTopPVelocity();
192             break;
193          case 's':
194          case 'S':
195             answer = getTopSVelocity();
196             break;
197          case 'r': case 'R':
198          case 'D': case 'd':
199             answer = getTopDensity();
200             break;
201          default:
202             throw new NoSuchMatPropException(materialProperty);
203       }
204       return answer;
205    }
206 
207    public double evaluateAt(double depth, char materialProperty) 
208       throws NoSuchMatPropException
209    {
210       double slope, answer;
211 
212       switch (materialProperty) {
213          case 'P':
214          case 'p':
215             slope = (getBotPVelocity() - getTopPVelocity())/
216                      (getBotDepth() - getTopDepth());
217             answer = slope*(depth - getTopDepth())+getTopPVelocity();
218             break;
219          case 's':
220          case 'S':
221             slope = (getBotSVelocity() - getTopSVelocity())/
222                      (getBotDepth() - getTopDepth());
223             answer = slope*(depth - getTopDepth())+getTopSVelocity();
224             break;
225          case 'r': case 'R':
226          case 'D': case 'd':
227             slope = (getBotDensity() - getTopDensity())/
228                      (getBotDepth() - getTopDepth());
229             answer = slope*(depth - getTopDepth())+getTopDensity();
230             break;
231          default:
232             System.out.println("I don't understand this material property: " +
233                                 materialProperty +
234                                "\nUse one of P p S s R r D d");
235             throw new NoSuchMatPropException(materialProperty);
236       }
237       return answer;
238    }
239    
240    public String toString() {
241       String description;
242 
243       description = myLayerNumber + " " + getTopDepth() + " " + getBotDepth();
244       description += " P " + getTopPVelocity() + " " + getBotPVelocity();
245       description += " S " + getTopSVelocity() + " " + getBotSVelocity();
246       description += " Density " + getTopDensity() + " " + getBotDensity();
247       return description;
248    }
249 
250 public void setTopDepth(double topDepth) {
251     this.topDepth = topDepth;
252 }
253 
254 public double getTopDepth() {
255     return topDepth;
256 }
257 
258 public void setBotDepth(double botDepth) {
259     this.botDepth = botDepth;
260 }
261 
262 public double getBotDepth() {
263     return botDepth;
264 }
265 
266 public void setTopPVelocity(double topPVelocity) {
267     this.topPVelocity = topPVelocity;
268 }
269 
270 public double getTopPVelocity() {
271     return topPVelocity;
272 }
273 
274 public void setBotPVelocity(double botPVelocity) {
275     this.botPVelocity = botPVelocity;
276 }
277 
278 public double getBotPVelocity() {
279     return botPVelocity;
280 }
281 
282 public void setTopSVelocity(double topSVelocity) {
283     this.topSVelocity = topSVelocity;
284 }
285 
286 public double getTopSVelocity() {
287     return topSVelocity;
288 }
289 
290 public void setBotSVelocity(double botSVelocity) {
291     this.botSVelocity = botSVelocity;
292 }
293 
294 public double getBotSVelocity() {
295     return botSVelocity;
296 }
297 
298 public void setTopDensity(double topDensity) {
299     this.topDensity = topDensity;
300 }
301 
302 public double getTopDensity() {
303     return topDensity;
304 }
305 
306 public void setBotDensity(double botDensity) {
307     this.botDensity = botDensity;
308 }
309 
310 public double getBotDensity() {
311     return botDensity;
312 }
313 
314 public void setTopQp(double topQp) {
315     this.topQp = topQp;
316 }
317 
318 public double getTopQp() {
319     return topQp;
320 }
321 
322 public void setBotQp(double botQp) {
323     this.botQp = botQp;
324 }
325 
326 public double getBotQp() {
327     return botQp;
328 }
329 
330 public void setTopQs(double topQs) {
331     this.topQs = topQs;
332 }
333 
334 public double getTopQs() {
335     return topQs;
336 }
337 
338 public void setBotQs(double botQs) {
339     this.botQs = botQs;
340 }
341 
342 public double getBotQs() {
343     return botQs;
344 }
345 }