<?xml version="1.0" encoding="UTF-8"?>
<simulation xmds-version="2">
  <name>excitedstate_gaussian</name>
  <author>Graham Dennis</author>
  <description>
    Calculate the first excited state of a negative gaussian potential.
    
    The idea here is to use the imaginary time algorithm but at each step
    to project out the ground state that was calculated with the 
    groundstate_gaussian.xmds script.
  </description>
  
  <features>
    <auto_vectorise />
    <benchmark />
    <bing />
    <fftw plan="patient" />
  </features>
  
  <geometry>
    <propagation_dimension> t </propagation_dimension>
    <transverse_dimensions>
      <dimension name="y" lattice="1024"  domain="(-12.0, 12.0)" />
    </transverse_dimensions>
  </geometry>
  
  <vector name="potential" initial_basis="y" type="complex">
    <components>
      V1
    </components>
    <initialisation kind="hdf5">
      <!-- Use the same potential as the previous simulation -->
      <filename>groundstate_gaussian_break.h5</filename>
    </initialisation>
  </vector>
  
  <vector name="wavefunction" initial_basis="y" type="complex">
    <components>
      phi1
    </components>
    <initialisation>
      <![CDATA[
      
      // This will be automatically normalised later
      // The extra 'y' is there to make the wavefunction asymmetric
      phi1 = y*exp(-y*y);
      ]]>
    </initialisation>
  </vector>
  
  <vector name="groundstate" initial_basis="y" type="complex">
    <components>phi</components>
    <initialisation kind="hdf5">
      <filename>groundstate_gaussian_break.h5</filename>
    </initialisation>
  </vector>
  
  <computed_vector name="normalisation" dimensions="" type="real">
    <components>
      Ncalc
    </components>
    <evaluation>
      <dependencies basis="y">wavefunction</dependencies>
      <![CDATA[
        // Calculate the current normalisation of the wave function.
        Ncalc = mod2(phi1);
      ]]>
    </evaluation>
  </computed_vector>
  
  <computed_vector name="groundstate_overlap" dimensions="" type="complex">
    <components>overlap</components>
    <evaluation>
      <dependencies>groundstate wavefunction</dependencies>
      <![CDATA[
        overlap = phi1*conj(phi);
      ]]>
    </evaluation>
  </computed_vector>
  
  <sequence>
    <integrate algorithm="RK9" interval="10.0" steps="10000" tolerance="1e-8">
      <samples>500 500</samples>
      <filters>
        <filter>
          <dependencies>wavefunction groundstate_overlap groundstate</dependencies>
          <![CDATA[
            // Subtract out the projection of the groundstate
            phi1 -= overlap * phi;
          ]]>
        </filter>
        <filter>
          <dependencies>wavefunction normalisation</dependencies>
          <![CDATA[
            // Correct normalisation of the wavefunction
            phi1 *= sqrt(1.0/Ncalc);
          ]]>
        </filter>
      </filters>
      <operators>
        <operator kind="ip">
          <operator_names>T</operator_names>
          <![CDATA[
            T = -0.5*ky*ky;
          ]]>
        </operator>
        <integration_vectors>wavefunction</integration_vectors>
        <dependencies>potential</dependencies>
        <![CDATA[
          dphi1_dt = T[phi1] - (i*V1)*phi1;
        ]]>
      </operators>
    </integrate>
    <breakpoint filename="excitedstate_gaussian_break.xsil" format="hdf5">
      <dependencies>wavefunction</dependencies>
    </breakpoint>
  </sequence>
  
  <output>
      <sampling_group basis="y" initial_sample="no">
        <moments>dens</moments>
        <dependencies>wavefunction</dependencies>
        <![CDATA[
          dens = mod2(phi1);
        ]]>
      </sampling_group>
      <sampling_group initial_sample="no">
        <moments>N</moments>
        <dependencies>normalisation</dependencies>
        <![CDATA[
          N = Ncalc;
        ]]>
      </sampling_group>
  </output>
</simulation>