/**
  * Computes and plots correlation functions
  *
  * @param tauMax is the maximum time for correlation functions
  */
 public void computeCorrelation(int tauMax) {
   plotFrame.clearData();
   double energyAccumulator = 0, magnetizationAccumulator = 0;
   double energySquaredAccumulator = 0, magnetizationSquaredAccumulator = 0;
   for (int t = 0; t < numberOfPoints; t++) {
     energyAccumulator += energy[t];
     magnetizationAccumulator += magnetization[t];
     energySquaredAccumulator += energy[t] * energy[t];
     magnetizationSquaredAccumulator += magnetization[t] * magnetization[t];
   }
   double averageEnergySquared = Math.pow(energyAccumulator / numberOfPoints, 2);
   double averageMagnetizationSquared = Math.pow(magnetizationAccumulator / numberOfPoints, 2);
   // compute normalization factors
   double normE = (energySquaredAccumulator / numberOfPoints) - averageEnergySquared;
   double normM = (magnetizationSquaredAccumulator / numberOfPoints) - averageMagnetizationSquared;
   for (int tau = 1; tau <= tauMax; tau++) {
     double c_MAccumulator = 0;
     double c_EAccumulator = 0;
     int counter = 0;
     for (int t = 0; t < numberOfPoints - tau; t++) {
       c_MAccumulator += magnetization[t] * magnetization[t + tau];
       c_EAccumulator += energy[t] * energy[t + tau];
       counter++;
     }
     // correlation function defined so that c(0) = 1 and c(infinity) -> 0
     plotFrame.append(0, tau, ((c_MAccumulator / counter) - averageMagnetizationSquared) / normM);
     plotFrame.append(1, tau, ((c_EAccumulator / counter) - averageEnergySquared) / normE);
   }
   plotFrame.setVisible(true);
 }
Beispiel #2
0
 public static void main(String[] args) {
   PlotFrame frame =
       new PlotFrame(
           "$\\theta$", "$\\Psi$_{$\\theta$}", "Special Characters: $\\alpha$ to $\\Omega$");
   String inputStr = "Wave function $\\Psi$_{$\\theta$}";
   DrawableTextLine textLine = new DrawableTextLine(inputStr, -8, 0);
   frame.addDrawable(textLine);
   textLine.setFontSize(22);
   textLine.setFontStyle(java.awt.Font.BOLD);
   frame.setVisible(true);
   frame.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
 }
 /**
  * Calculates the trajectory of a falling particle and plots the position as a function of time.
  */
 public void calculate() {
   plotFrame.setAutoclear(false); // data not cleared at beginning of each calculation
   // gets initial conditions
   double y0 = control.getDouble("Initial y");
   double v0 = control.getDouble("Initial v");
   // sets initial conditions
   Particle ball = new FallingParticle(y0, v0);
   // gets parameters
   ball.dt = control.getDouble("dt");
   while (ball.y > 0) {
     ball.step();
     plotFrame.append(0, ball.t, ball.y);
     plotFrame.append(1, ball.t, ball.analyticPosition());
   }
 }
 public void readXMLData() {
   energy = new double[0];
   magnetization = new double[0];
   numberOfPoints = 0;
   String filename = "ising_data.xml";
   JFileChooser chooser = OSPFrame.getChooser();
   int result = chooser.showOpenDialog(null);
   if (result == JFileChooser.APPROVE_OPTION) {
     filename = chooser.getSelectedFile().getAbsolutePath();
   } else {
     return;
   }
   XMLControlElement xmlControl = new XMLControlElement(filename);
   if (xmlControl.failedToRead()) {
     control.println("failed to read: " + filename);
   } else {
     // gets the datasets in the xml file
     Iterator it = xmlControl.getObjects(Dataset.class, false).iterator();
     while (it.hasNext()) {
       Dataset dataset = (Dataset) it.next();
       if (dataset.getName().equals("magnetization")) {
         magnetization = dataset.getYPoints();
       }
       if (dataset.getName().equals("energy")) {
         energy = dataset.getYPoints();
       }
     }
     numberOfPoints = magnetization.length;
     control.println("Reading: " + filename);
     control.println("Number of points = " + numberOfPoints);
   }
   calculate();
   plotFrame.repaint();
 }
Beispiel #5
0
  private static void test2() {
    int n1 = 11;
    int n2 = 11;
    float d1 = 1.0f / (float) max(1, n1 - 1);
    float d2 = 1.0f / (float) max(1, n2 - 1);
    float[][] f0 = rampfloat(0.0f, d1, d2, n1, n2);
    float[][] f1 = zerofloat(n1, n2);
    float[][] f2 = zerofloat(n1, n2);
    // float[][] f1 = rampfloat(0.0f,d1,d2,n1,n2);
    // float[][] f2 = rampfloat(0.0f,d1,d2,n1,n2);

    Sampling s1 = new Sampling(n1, 0.5, 0.25 * (n1 - 1));
    Sampling s2 = new Sampling(n2, 0.5, 0.25 * (n2 - 1));

    PlotPanel panel = new PlotPanel(1, 2);
    PixelsView pv0 = panel.addPixels(0, 0, new float[][][] {f0, f1, f2});
    pv0.setInterpolation(PixelsView.Interpolation.NEAREST);
    pv0.setClips(0, 0.0f, 2.0f);
    pv0.setClips(1, 0.0f, 2.0f);
    pv0.setClips(2, 0.0f, 2.0f);
    pv0.set(new float[][][] {f0, f1, f2}); // should have no effect!

    PixelsView pv0b = panel.addPixels(0, 0, s1, s2, new float[][][] {f1, f0, f2});
    pv0b.setInterpolation(PixelsView.Interpolation.LINEAR);
    pv0b.setClips(0, 0.0f, 2.0f);
    pv0b.setClips(1, 0.0f, 2.0f);
    pv0b.setClips(2, 0.0f, 2.0f);

    PixelsView pv1 = panel.addPixels(0, 1, new float[][][] {f1, f2, f0});
    pv1.setInterpolation(PixelsView.Interpolation.LINEAR);
    pv1.setClips(0, 0.0f, 2.0f);
    pv1.setClips(1, 0.0f, 2.0f);
    pv1.setClips(2, 0.0f, 2.0f);

    PixelsView pv1b = panel.addPixels(0, 1, s1, s2, new float[][][] {f1, f0, f2});
    pv1b.setInterpolation(PixelsView.Interpolation.NEAREST);
    pv1b.setClips(0, 0.0f, 2.0f);
    pv1b.setClips(1, 0.0f, 2.0f);
    pv1b.setClips(2, 0.0f, 2.0f);

    PlotFrame frame = new PlotFrame(panel);
    frame.setDefaultCloseOperation(PlotFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
    // frame.paintToPng(300,6,"junk.png");
  }
 /** Calculates the wave function. */
 public void calculate() {
   schroedinger.xmin = control.getDouble("xmin");
   schroedinger.xmax = control.getDouble("xmax");
   schroedinger.stepHeight = control.getDouble("step height at x = 0");
   schroedinger.numberOfPoints = control.getInt("number of points");
   schroedinger.energy = control.getDouble("energy");
   schroedinger.initialize();
   schroedinger.solve();
   frame.append(0, schroedinger.x, schroedinger.phi);
 }
Beispiel #7
0
  private static void go() {
    int n1 = 101;
    int n2 = 101;
    // float[][] f = sin(rampfloat(0.0f,0.1f,0.1f,n1,n2));
    float[][] f = zerofloat(n1, n2);

    PlotPanel.Orientation orientation = PlotPanel.Orientation.X1DOWN_X2RIGHT;
    PlotPanel panel = new PlotPanel(orientation);

    PixelsView pv = panel.addPixels(f);
    pv.setInterpolation(PixelsView.Interpolation.NEAREST);
    pv.setColorModel(ColorMap.JET);

    panel.addColorBar("time");
    panel.setVLabel("depth (km)");
    panel.setHLabel("distance (km)");

    PlotFrame frame = new PlotFrame(panel);
    frame.setDefaultCloseOperation(PlotFrame.EXIT_ON_CLOSE);
    frame.setSize(800, 700);
    frame.setFontSize(24);
    frame.setVisible(true);

    ModeManager mm = frame.getModeManager();
    ImageEditMode iem = new ImageEditMode(mm, pv, 0.0f, f);
    iem.setActive(true);
  }
Beispiel #8
0
  private static void test1() {
    int n1 = 11;
    int n2 = 11;
    float d1 = 1.0f / (float) max(1, n1 - 1);
    float d2 = 1.0f / (float) max(1, n2 - 1);
    float[][] f = rampfloat(0.0f, d1, d2, n1, n2);

    Sampling s1 = new Sampling(n1, 0.5, 0.25 * (n1 - 1));
    Sampling s2 = new Sampling(n2, 0.5, 0.25 * (n2 - 1));

    PlotPanel panel = new PlotPanel(1, 2);
    PixelsView pv0 = panel.addPixels(0, 0, f);
    pv0.setInterpolation(PixelsView.Interpolation.NEAREST);
    pv0.setColorModel(ColorMap.JET);
    pv0.setPercentiles(0.0f, 100.0f);
    f = mul(10.0f, f);
    pv0.set(f);

    PixelsView pv0b = panel.addPixels(0, 0, s1, s2, f);
    pv0b.setInterpolation(PixelsView.Interpolation.LINEAR);
    pv0b.setColorModel(ColorMap.GRAY);
    pv0b.setPercentiles(0.0f, 100.0f);

    PixelsView pv1 = panel.addPixels(0, 1, f);
    pv1.setInterpolation(PixelsView.Interpolation.LINEAR);
    pv1.setColorModel(ColorMap.GRAY);
    pv1.setPercentiles(0.0f, 100.0f);
    f = mul(10.0f, f);
    pv1.set(f);

    PixelsView pv1b = panel.addPixels(0, 1, s1, s2, f);
    pv1b.setInterpolation(PixelsView.Interpolation.NEAREST);
    pv1b.setColorModel(ColorMap.JET);
    pv1b.setPercentiles(0.0f, 100.0f);

    PlotFrame frame = new PlotFrame(panel);
    frame.setDefaultCloseOperation(PlotFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
    // frame.paintToPng(300,6,"junk.png");
  }
 public void computeDistribution(PlotFrame data) {
   int numberOfBins = 20;
   int numberOccupied = 0;
   double occupied[] = new double[numberOfBins];
   double number[] = new double[numberOfBins];
   double binSize = 1.0 / numberOfBins;
   int minX = Lx / 3;
   int maxX = 2 * minX;
   for (int x = minX; x <= maxX; x++) {
     for (int y = 0; y < Ly; y++) {
       int bin = (int) (numberOfBins * (site[x][y] % 1));
       number[bin]++;
       if ((site[x][y] > 1) && (site[x][y] < 2)) {
         numberOccupied++;
         occupied[bin]++;
       }
     }
   }
   data.setMessage("Number occupied = " + numberOccupied);
   for (int bin = 0; bin < numberOfBins; bin++) {
     data.append(0, (bin + 0.5) * binSize, occupied[bin] / number[bin]);
   }
 }
 /** Constructs SchroedingerApp and sets plotting frame parameters. */
 public SchroedingerApp() {
   frame.setConnected(0, true);
   frame.setMarkerShape(0, Dataset.NO_MARKER);
 }
Beispiel #11
0
  /**
   * This plots the samples, with the Window defined as parameter. It can used the scale of the last
   * plot and a vertical offset.
   *
   * @param samples the samples to plot
   * @param samplesPerPixel The number of samples in each pixel
   * @param verticalOffset The vertical offSet (in order to plot several frequencies in the same
   *     image)
   * @param useLastScale boolean that tells to user or not the last scale
   * @param color The color of the line
   */
  public void plot(
      ArrayList<Float> samples,
      final float samplesPerPixel,
      final float verticalOffset,
      final boolean useLastScale,
      final Color color) {
    synchronized (buffImage) {
      /*
       * if the size of the image is smaller than the ammount of values
       * (converted to pixels), then we draw a new rectangule to serve as
       * background
       */
      if (buffImage.getWidth() < samples.size() / samplesPerPixel) {
        buffImage =
            new BufferedImage(
                (int) (samples.size() / samplesPerPixel),
                frame.getHeight(),
                BufferedImage.TYPE_4BYTE_ABGR);
        Graphics2D graph = buffImage.createGraphics();
        graph.setColor(Color.black);
        graph.fillRect(0, 0, buffImage.getWidth(), buffImage.getHeight());
        graph.dispose();
        panel.setSize(buffImage.getWidth(), buffImage.getHeight());
      }

      /*
       * When useLastScale != true, we have to recalculate the scaling
       * factor
       */
      if (!useLastScale) {
        for (int i = 0; i < samples.size(); i++) {
          min = Math.min(samples.get(i), min);
          max = Math.max(samples.get(i), max);
        }
        scalingFactor = max - min;
      }

      Graphics2D graph = buffImage.createGraphics();
      // draws the reference lines (max, min, zero)
      drawReferenceLines(graph, true, true, true);
      graph.setColor(Color.white);

      graph.drawLine(
          0, buffImage.getHeight() / 2, (int) buffImage.getWidth(), buffImage.getHeight() / 2);
      graph.setColor(color);
      /*
       * float lastValue = (samples.get(0) / scalingFactor)
       * buffImage.getHeight() / 3 + buffImage.getHeight() / 2 -
       * verticalOffset * buffImage.getHeight() / 3;
       */

      // Scales the first value of the array in order to be plotted
      float lastSampleScaled = calculateScaledValue(buffImage, samples.get(0), verticalOffset);

      for (int i = 1; i < samples.size(); i++) {

        /*
         * float value = (samples.get(i) / scalingFactor)
         * buffImage.getHeight() / 3 + buffImage.getHeight() / 2 -
         * verticalOffset * buffImage.getHeight() / 3;
         */

        // Scales the ith value of the array in order to be plotted
        float sampleScaled = calculateScaledValue(buffImage, samples.get(i), verticalOffset);

        /*
         * draws a line between the value of this iteration and that of
         * the previous
         */
        graph.drawLine(
            (int) ((i - 1) / samplesPerPixel),
            buffImage.getHeight() - (int) lastSampleScaled,
            (int) (i / samplesPerPixel),
            buffImage.getHeight() - (int) sampleScaled);

        /*
         * the sample of this iteration will be next iteration's last
         * sample
         */
        lastSampleScaled = sampleScaled;
      }
      graph.dispose();
    }
  }
Beispiel #12
0
  /**
   * This method plots the arraylist of samples, with the Window defined as parameter
   *
   * @param samples the samples to plot
   * @param samplesPerPixel The number of samples in each pixel
   * @param color The color of the line
   */
  public void plot(ArrayList<Float> samples, final float samplesPerPixel, final Color color) {
    // System.out.println("Dentro plot");
    synchronized (buffImage) {

      // System.out.println("Dentro sync");

      /*
       * if the size of the image is smaller than the ammount of values
       * (converted to pixels), then we draw a new rectangule to serve as
       * background
       */
      if (buffImage.getWidth() < samples.size() / samplesPerPixel) {
        /*
         * BufferedImage tmpBuffImg = new BufferedImage((int) (samples
         * .size() / samplesPerPixel), frame.getHeight(),
         * BufferedImage.TYPE_4BYTE_ABGR);
         *
         * Graphics2D graph = tmpBuffImg.createGraphics();
         * graph.setColor(Color.black); graph.fillRect(0, 0,
         * tmpBuffImg.getWidth(), tmpBuffImg .getHeight()); //
         * graph.dispose(); panel.setSize(tmpBuffImg.getWidth(),
         * tmpBuffImg.getHeight());
         *
         * buffImage = tmpBuffImg;
         */

        buffImage =
            new BufferedImage(
                (int) (samples.size() / samplesPerPixel),
                frame.getHeight(),
                BufferedImage.TYPE_4BYTE_ABGR);
        Graphics2D graph = buffImage.createGraphics();
        graph.setColor(Color.black);
        graph.fillRect(0, 0, buffImage.getWidth(), buffImage.getHeight());
        // graph.dispose();
        panel.setSize(buffImage.getWidth(), buffImage.getHeight());
      }

      // System.out.println("Dentro sync2");

      /*
       * when the plot is cleared, we calculate the maximum and minimum of
       * all the values passed, i.e., the scaling factor
       */
      if (cleared) {
        for (int i = 0; i < samples.size(); i++) {
          this.min = Math.min(samples.get(i), min);
          this.max = Math.max(samples.get(i), max);
        }
        scalingFactor = max - min;
        cleared = false;
      }

      // System.out.println("Dentro sync 3");

      Graphics2D graph = buffImage.createGraphics();

      // draws the reference lines (max, min, zero)
      drawReferenceLines(graph, true, true, true);

      graph.setColor(color);

      // System.out.println("Dentro sync");

      // float lastValue = (samples.get(0) / scalingFactor)
      // * image.getHeight() / 3 + image.getHeight() / 2;

      // Scales the first value of the array in order to be plotted
      float lastSampleScaled = calculateScaledValue(buffImage, samples.get(0), 0);

      for (int i = 1; i < samples.size(); i++) {
        // float value = (samples.get(i) / scalingFactor)
        // * image.getHeight() / 3 + image.getHeight() / 2;

        // Scales the ith value of the array in order to be plotted
        float sampleScaled = calculateScaledValue(buffImage, samples.get(i), 0);

        /* it draws a line between the last and this value */
        graph.drawLine(
            (int) ((i - 1) / samplesPerPixel),
            buffImage.getHeight() - (int) lastSampleScaled,
            (int) (i / samplesPerPixel),
            buffImage.getHeight() - (int) sampleScaled);

        /*
         * the sample of this iteration will be next iteration's last
         * sample
         */
        lastSampleScaled = sampleScaled;
      }
      // graph.dispose();
    }
  }
Beispiel #13
0
  /**
   * This plots the values passed, with the Window defined as parameter. It updates the image
   * initialized in the constructor.
   *
   * @param samples the samples to plot
   * @param samplesPerPixel The number of samples in each pixel
   * @param color The color of the line
   */
  public void plot(float[] samples, final float samplesPerPixel, final Color color) {
    synchronized (buffImage) {
      /*
       * if the size of the image is smaller than the ammount of values
       * (converted to pixels), then we draw a new rectangule to serve as
       * background
       */
      if (buffImage.getWidth() < samples.length / samplesPerPixel) {
        buffImage =
            new BufferedImage(
                (int) (samples.length / samplesPerPixel),
                frame.getHeight(),
                BufferedImage.TYPE_4BYTE_ABGR);
        Graphics2D graph = buffImage.createGraphics();
        graph.setColor(Color.black);
        graph.fillRect(0, 0, buffImage.getWidth(), buffImage.getHeight());
        graph.dispose();
        panel.setSize(buffImage.getWidth(), buffImage.getHeight());
      }

      /*
       * when the plot is cleared, we calculate the maximum and minimum of
       * all the values passed, i.e., the scaling factor
       */
      if (cleared) {
        float min = 0;
        float max = 0;
        for (int i = 0; i < samples.length; i++) {
          min = Math.min(samples[i], min);
          max = Math.max(samples[i], max);
        }
        scalingFactor = max - min;
        cleared = false;
      }

      // it starts the class that allows to draw the line graph
      Graphics2D graph = buffImage.createGraphics();

      // draws the reference lines
      drawReferenceLines(graph, true, true, true);

      graph.setColor(color);

      // scales the values
      // float lastValue = (samples[0] / scalingFactor) *
      // image.getHeight()
      // / 3 + image.getHeight() / 2;

      // Scales the first value of the array in order to be plotted
      float lastSampleScaled = calculateScaledValue(buffImage, samples[0], 0);
      for (int i = 1; i < samples.length; i++) {
        // float value = (samples[i] / scalingFactor) *
        // image.getHeight()
        // / 3 + image.getHeight() / 2;

        // Scales the ith value of the array in order to be plotted
        float sampleScaled = calculateScaledValue(buffImage, samples[i], 0);

        /* it draws a line between the last and this value */
        graph.drawLine(
            (int) ((i - 1) / samplesPerPixel),
            buffImage.getHeight() - (int) lastSampleScaled,
            (int) (i / samplesPerPixel),
            buffImage.getHeight() - (int) sampleScaled);

        /*
         * the sample of this iteration will be next iteration's last
         * sample
         */
        lastSampleScaled = sampleScaled;
      }
      graph.dispose();
    }
  }