@@ -41,6 +41,11 @@ shiftScaledWfns::usage="";
41
41
$defaults ::usage = "" ;
42
42
43
43
44
+ iWavefunctionEigensystem ::usage = "" ;
45
+ iWavefunctions ::usage = "" ;
46
+ iWavefunctionPlot ::usage = "" ;
47
+
48
+
44
49
EndPackage []
45
50
46
51
@@ -70,38 +75,43 @@ pib[{l_, min_}]:=
70
75
pib ~SetAttributes ~HoldRest ;
71
76
72
77
73
- (* ::Subsubsection::Closed:: *)
78
+ (* ::Subsubsection:: *)
74
79
(*ho*)
75
80
76
81
77
- ho [{omega_ , m_ , hb_ }, x_ ][n_ ]:=
78
- With [{a = m * omega / hb },
79
- (1 / Sqrt [(2 ^ n )n ! ])* Power [a / Pi , 1 / 4 ]* Exp [- a / 2 * x ^ 2 ]* HermiteH [n , Sqrt [a ]* x ]
82
+ ho [{omega_ , m_ , hb_ , x0_ }, x_ ][nn_ ]:=
83
+ With [{a = m * omega / hb , n = nn - 1 },
84
+ (1 / Sqrt [(2 ^ n )n ! ])* Power [a / Pi , 1 / 4 ]* Exp [- a / 2 * ( x - x0 ) ^ 2 ]* HermiteH [n , Sqrt [a ]* ( x - x0 ) ]
80
85
];
81
- ho [{omega_ , m_ , hb_ }]:=
82
- Function [Null , ho [{omega , m , hb }, # ], HoldFirst ];
86
+ ho [{omega_ , m_ , hb_ , x0_ }]:=
87
+ Function [Null , ho [{omega , m , hb , x0 }, # ], HoldFirst ];
83
88
ho ~SetAttributes ~HoldRest ;
84
89
85
90
86
- (* ::Subsubsection::Closed:: *)
91
+ (* ::Subsubsection:: *)
87
92
(*getBasisFunction*)
88
93
89
94
90
95
getBasisFunction // Clear ;
91
96
getBasisFunction ["ParticleInABox" , ops___ ]:=
92
- pib [
93
- {
94
- Lookup [{ops }, "Length" , 1. ],
95
- Lookup [{ops }, "Minimum" , 0. ]
96
- }
97
+ With [{oop = Select [{ops }, OptionQ ]},
98
+ pib [
99
+ {
100
+ Lookup [oop , "Length" , 1. ],
101
+ Lookup [oop , "Minimum" , 0. ]
102
+ }
103
+ ]
97
104
];
98
105
getBasisFunction ["HarmonicOscillator" , ops___ ]:=
99
- ho [
100
- {
101
- Lookup [{ops }, "Frequency" , 1. ],
102
- Lookup [{ops }, "Mass" , 1 ],
103
- Lookup [{ops }, "PlanckConstant" , 1 ]
104
- }
106
+ With [{oop = Select [{ops }, OptionQ ]},
107
+ ho [
108
+ {
109
+ Lookup [oop , "Frequency" , 1. ],
110
+ Lookup [oop , "Mass" , 1 ],
111
+ Lookup [oop , "PlanckConstant" , 1 ],
112
+ Lookup [oop , "Center" , 0. ]
113
+ }
114
+ ]
105
115
];
106
116
getBasisFunction [l_ List ]:=
107
117
getBasisFunction @@ l ;
@@ -117,30 +127,53 @@ $integrator=NIntegrate;
117
127
(* I put this here so people can hack it later *)
118
128
119
129
120
- hel [{n_ , m_ }, bf_ , pot_ , {hb_ , mu_ }, {min_ , max_ }, x_ Symbol ]:=
121
- hel [{n , m }, bf , pot , {hb , mu },{min , max }, x ]=
122
- With [{psin = bf [x ][n ], psim = bf [x ][m ], p = pot [x ]},
123
- Quiet [
124
- $integrator [
125
- psin * (
126
- - hb / (2 mu )* D [psim , {x , 2 }]+ p * psim
127
- ),
128
- {x , min , max }
129
- ],
130
- {
131
- NIntegrate ::ncvb ,
132
- NIntegrate ::slwcon
133
- }
134
- ]
135
- ];
130
+ ihel [{n_ , m_ }, bf_ , pot_ , {hb_ , mu_ }, {min_ , max_ }, x_ Symbol ]:=
131
+ With [{psin = bf [x ][n ], psim = bf [x ][m ], p = pot [x ]},
132
+ Quiet [
133
+ $integrator [
134
+ psin * (
135
+ - hb / (2 mu )* D [psim , {x , 2 }]+ p * psim
136
+ ),
137
+ {x , min , max }
138
+ ],
139
+ {
140
+ NIntegrate ::ncvb ,
141
+ NIntegrate ::slwcon
142
+ }
143
+ ]
144
+ ]
136
145
137
146
138
- (* ::Subsubsection::Closed:: *)
147
+ hel [{n_ , m_ }, bf_ , pot_ , {hb_ , mu_ }, {min_ , max_ }, x_ Symbol , useCached_ ]:=
148
+ Module [{res },
149
+ res = ihel [{n , m }, bf , pot , {hb , mu },{min , max }, x ];
150
+ If [NumericQ @ res ,
151
+ If [useCached ,
152
+ hel [{n , m }, bf , pot , {hb , mu },{min , max }, x , True ]= res ,
153
+ res
154
+ ],
155
+ Throw @
156
+ Failure ["BadHam" ,
157
+ < |
158
+ "MessageTemplate" -> "Non-numeric Hamiltonian element ``" ,
159
+ "MessageParameter" -> {res }
160
+ |>
161
+ ]
162
+ ]
163
+ ]
164
+
165
+
166
+ (* ::Subsubsection:: *)
139
167
(*ham*)
140
168
141
169
142
- ham [nT_ , bf_ , pot_ ,{hb_ , mu_ }, {min_ , max_ }, x_ ]:=
143
- Table [hel [{n ,m }, bf , pot ,{hb , mu }, {min , max }, x ], {n , 1 , nT }, {m , 1 , nT }];
170
+ ham // Clear
171
+ ham [nT_ , bf_ , pot_ ,{hb_ , mu_ }, {min_ , max_ }, x_ , useCached_ ]:=
172
+ Table [
173
+ hel [{n ,m }, bf , pot ,{hb , mu }, {min , max }, x , useCached ],
174
+ {n , 1 , nT },
175
+ {m , 1 , nT }
176
+ ];
144
177
145
178
146
179
(* ::Subsubsection::Closed:: *)
@@ -189,9 +222,9 @@ $defaults=
189
222
"PotentialFunction" ->
190
223
(
191
224
Piecewise [{
192
- {10 ^ 4 , # <= 0 },
225
+ {10 ^ 6 , # <= 0 },
193
226
{0 , 0 < # < 1 },
194
- {10 ^ 4 , # >= 1 }
227
+ {10 ^ 6 , # >= 1 }
195
228
}]&
196
229
),
197
230
"Range" -> {0. , 1. }
@@ -202,16 +235,17 @@ $defaults=
202
235
(*WavefunctionEigensystem*)
203
236
204
237
205
- Options [WavefunctionEigensystem ]=
238
+ Options [iWavefunctionEigensystem ]=
206
239
{
207
240
"BasisFunction" -> Automatic ,
208
241
"PotentialFunction" -> Automatic ,
209
242
"Range" -> Automatic ,
210
243
"BasisSize" -> Automatic ,
211
244
"Mass" -> Automatic ,
212
- "PlanckConstant" -> Automatic
245
+ "PlanckConstant" -> Automatic ,
246
+ "UseCachedElements" -> False
213
247
};
214
- WavefunctionEigensystem [ops :OptionsPattern []]:=
248
+ iWavefunctionEigensystem [ops :OptionsPattern []]:=
215
249
Module [
216
250
{
217
251
nT =
@@ -236,49 +270,67 @@ WavefunctionEigensystem[ops:OptionsPattern[]]:=
236
270
es
237
271
},
238
272
bf = getBasisFunction @ bf ;
239
- h = ham [nT , bf , pot , {hb , m }, r , \[FormalX ]];
273
+ h = ham [nT , bf , pot , {hb , m }, r , \[FormalX ], TrueQ @ OptionValue [ "UseCachedElements" ] ];
240
274
es = getSolns @ h ;
241
275
es [[2 ]]= Threshold [es [[2 ]], 10 ^ - 6 ];
242
276
es
243
277
]
244
278
245
279
280
+ WavefunctionEigensystem // ClearAll
281
+ Options [WavefunctionEigensystem ]=
282
+ Options [iWavefunctionEigensystem ];
283
+ WavefunctionEigensystem [e___ ]:=
284
+ Module [{res = Catch @ iWavefunctionEigensystem [e ]},
285
+ res /; Head [res ]=!= iWavefunctionEigensystem
286
+ ]
287
+
288
+
246
289
(* ::Subsubsection::Closed:: *)
247
290
(*Wavefunctions*)
248
291
249
292
250
- Options [Wavefunctions ]=
251
- Options [WavefunctionEigensystem ];
252
- Wavefunctions [es :{_ List , _ List }, bf :Except [_ ? OptionQ ]]:=
293
+ Options [iWavefunctions ]=
294
+ Options [iWavefunctionEigensystem ];
295
+ iWavefunctions [es :{_ List , _ List }, bf :Except [_ ? OptionQ ]]:=
253
296
{es [[1 ]], expandSoln [{# , bf }, \[FormalX ]]& /@ es [[2 ]]};
254
- Wavefunctions [es :{_ List , _ List }, ops :OptionsPattern []]:=
297
+ iWavefunctions [es :{_ List , _ List }, ops :OptionsPattern []]:=
255
298
Module [
256
299
{
257
300
bf =
258
301
Replace [OptionValue ["BasisFunction" ],
259
302
Automatic :> $defaults ["BasisFunction" ]]
260
303
},
261
304
bf = getBasisFunction @ bf ;
262
- Wavefunctions [es , bf ]
305
+ iWavefunctions [es , bf ]
263
306
];
264
- Wavefunctions [ops :OptionsPattern []]:=
265
- Wavefunctions [ WavefunctionEigensystem [ops ], ops ]
307
+ iWavefunctions [ops :OptionsPattern []]:=
308
+ iWavefunctions [ iWavefunctionEigensystem [ops ], ops ]
266
309
267
310
268
- (* ::Subsubsection:: *)
311
+ Wavefunctions // ClearAll
312
+ Options [Wavefunctions ]=
313
+ Options [iWavefunctions ];
314
+ Wavefunctions [e___ ]:=
315
+ Module [{res = Catch @ iWavefunctions [e ]},
316
+ res /; Head [res ]=!= iWavefunctions
317
+ ]
318
+
319
+
320
+ (* ::Subsubsection::Closed:: *)
269
321
(*WavefunctionPlot*)
270
322
271
323
272
- WavefunctionPlot // Clear
273
- Options [WavefunctionPlot ]=
324
+ iWavefunctionPlot // Clear
325
+ Options [iWavefunctionPlot ]=
274
326
Join [
275
327
Options [Wavefunctions ],
276
328
Options [Plot ],
277
329
{
278
330
"WavefunctionScaling" -> 1
279
331
}
280
332
];
281
- WavefunctionPlot [
333
+ iWavefunctionPlot [
282
334
wfs :{_ List , _ List ? (Not @ MatrixQ [# , Internal ` RealValuedNumberQ ]& )},
283
335
pot_ ,
284
336
{min_ ? NumericQ , max_ ? NumericQ },
@@ -297,7 +349,7 @@ WavefunctionPlot[
297
349
Options [Plot ]
298
350
]
299
351
];
300
- WavefunctionPlot [
352
+ iWavefunctionPlot [
301
353
wfs :{_ List , _ List ? (Not @ MatrixQ [# , Internal ` RealValuedNumberQ ]& )},
302
354
ops :OptionsPattern []
303
355
]:=
@@ -315,23 +367,32 @@ WavefunctionPlot[
315
367
)
316
368
]
317
369
},
318
- WavefunctionPlot [wfs , pot , range , ops ]
370
+ iWavefunctionPlot [wfs , pot , range , ops ]
319
371
];
320
- WavefunctionPlot [
372
+ iWavefunctionPlot [
321
373
es :{_ List , _ List ? (MatrixQ [# , Internal ` RealValuedNumberQ ]& )},
322
374
ops :OptionsPattern []
323
375
]:=
324
- WavefunctionPlot [
325
- Wavefunctions [es , FilterRules [{ops }, Options [Wavefunctions ]]],
376
+ iWavefunctionPlot [
377
+ iWavefunctions [es , FilterRules [{ops }, Options [iWavefunctions ]]],
326
378
ops
327
379
];
328
- WavefunctionPlot [ops :OptionsPattern []]:=
329
- WavefunctionPlot [
330
- Wavefunctions [FilterRules [{ops }, Options [Wavefunctions ]]],
380
+ iWavefunctionPlot [ops :OptionsPattern []]:=
381
+ iWavefunctionPlot [
382
+ iWavefunctions [FilterRules [{ops }, Options [iWavefunctions ]]],
331
383
ops
332
384
]
333
385
334
386
387
+ WavefunctionPlot // ClearAll
388
+ Options [WavefunctionPlot ]=
389
+ Options [iWavefunctionPlot ];
390
+ WavefunctionPlot [e___ ]:=
391
+ Module [{res = Catch @ iWavefunctionPlot [e ]},
392
+ res /; Head [res ]=!= iWavefunctionPlot
393
+ ]
394
+
395
+
335
396
(* ::Subsubsection:: *)
336
397
(*End*)
337
398
0 commit comments