forked from tsotchke/PIMC
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPIMCApp.java
More file actions
119 lines (108 loc) · 3.46 KB
/
Copy pathPIMCApp.java
File metadata and controls
119 lines (108 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package PIMC;
import java.awt.Color;
import org.opensourcephysics.controls.*;
import org.opensourcephysics.frames.PlotFrame;
/**
* Application for simulating Feynman's Quantum Path Integral with various potentials by Monte Carlo method
*
* @author tsotchke
* @version 0.1
*/
public class PIMCApp extends AbstractSimulation {
PIMC action = new PIMC();
PlotFrame path = new PlotFrame("Time (ω⁻¹)", "Atomic Displacement ((ħ/mω)¹ᐟ²)", "Ring of Virtual Atoms");
PlotFrame probability = new PlotFrame("x", "P(x)", "Ground State Probability Distribution");
PlotFrame wave = new PlotFrame("x", "|Ψ₀(x)|²", "Ground State Wave Function Probability Density");
PlotFrame energy = new PlotFrame("Time", "E₀", "Ground State Energy");
/**
* Sets path frame properties
*/
public PIMCApp() {
// path graph
path.setAutoscaleX(true);
path.setAutoscaleY(true);
path.setMarkerShape(0, 0);
path.setConnected(true); // draw lines between points
// probability distribution graph
probability.setAutoscaleY(true);
probability.setPreferredMinMaxX(-4.0, 4.01);
probability.setMarkerShape(0, 1);
probability.setMarkerColor(0, Color.black);
// wave function graph
wave.setAutoscaleY(true);
wave.setPreferredMinMaxX(-4.0, 4.01);
wave.setMarkerShape(0, 1);
wave.setMarkerColor(0, Color.blue);
// energy graph
energy.setAutoscaleY(true);
energy.setMarkerShape(0, 1);
energy.setMarkerColor(0, Color.green);
}
/**
* Gets parameters and initializes medium
*/
public void initialize() {
action.N = control.getInt("Total number of segments");
action.τ = control.getDouble("Total time (ω⁻¹)");
action.δ = control.getDouble("Maximum change in atomic displacement ((ħ/mω)¹ᐟ²)");
action.s = control.getInt("Potential Function (1: Harmonic, 2: Morse, 3: Double-well; 4: Anharmonic)");
action.initialize();
path.clearData();
drawPath();
}
/**
* Draw a path
*/
public void drawPath() {
for(int i = 0;i<action.N;i++) {
path.append(0, i*action.Δτ, action.x[i]);
}
}
/**
* Makes one change in path at a time
*/
public void doStep() {
action.changePath();
path.clearData();
drawPath();
path.setMessage(action.mcs + " Monte Carlo steps");
probability.append(0, action.xv, action.pdistNorm);
wave.append(0, action.xv, action.Ψ0);
energy.append(0, action.mcs, action.E0);
energy.setMessage("E₀ = " + action.E0);
}
/**
* Resets to default values
*/
public void reset() {
control.setValue("Total number of segments", 200);
control.setValue("Total time (ω⁻¹)", 10.0);
control.setValue("Maximum change in atomic displacement ((ħ/mω)¹ᐟ²)", 1.0);
control.setValue("Potential Function (1: Harmonic, 2: Morse, 3: Double-well; 4: Anharmonic)", 1);
path.clearData();
enableStepsPerDisplay(true);
setStepsPerDisplay(100);
}
/**
* Resets the accumulated data.
*/
public void resetData() {
action.resetData();
path.clearData();
path.repaint();
probability.clearData();
probability.repaint();
wave.clearData();
wave.repaint();
energy.clearData();
energy.repaint();
}
/**
* Starts the Java application.
* @param args command line parameters
*/
public static void main(String[] args) {
SimulationControl control = SimulationControl.createApp(new PIMCApp());
control.addButton("resetData", "Reset Data");
}
}