<?xml version="1.0" encoding="UTF-8"?>
<simulation xmds-version="2">
  <name>groundstate_gaussian</name>
  <author>Graham Dennis</author>
  <description>
    Calculate the ground state of a negative gaussian potential.
  </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)" aliases="yp" />
    </transverse_dimensions>
  </geometry>
  
  <filter name="toplevelfilter">
    <![CDATA[
      printf("Hello world from a named filter!\n");
    ]]>
  </filter>

   <vector name="potential" initial_basis="y" type="complex">
    <components> V1 </components>
    <initialisation>
      <![CDATA[
        real Vtrap = -exp(-y*y);
      
        V1  = -i*Vtrap;
      
      ]]>
    </initialisation>
  </vector>
  
  <vector name="wavefunction" initial_basis="y" type="complex">
    <components>
      phi
    </components>
    <initialisation>
      <![CDATA[
      
      // This will be automatically normalised later
      phi = exp(-y*y);
      ]]>
    </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(phi);
      ]]>
    </evaluation>
  </computed_vector>
  
  <sequence>
      <filter name="sequencelevelfilter">
        <![CDATA[
          toplevelfilter();
          normalisy();
        ]]>
      </filter>
  
    <integrate algorithm="RK4" interval="10.0" steps="10000" tolerance="1e-8">
      <samples>50 50 1</samples>
      <filters>
        <filter name="normalisy">
          <dependencies>wavefunction normalisation</dependencies>
          <![CDATA[
            // Correct normalisation of the wavefunction
            phi *= sqrt(1.0/Ncalc);
          ]]>
        </filter>
      </filters>
      <operators>
        <operator kind="ip" type="real">
          <operator_names>T</operator_names>
          <![CDATA[
            T = -0.5*ky*ky;
          ]]>
        </operator>
        <integration_vectors>wavefunction</integration_vectors>
        <dependencies>potential</dependencies>
        <![CDATA[
          dphi_dt = T[phi] - (i*V1)*phi;
        ]]>
      </operators>
    </integrate>
    
    <breakpoint filename="groundstate_gaussian_break.xsil" format="hdf5">
      <dependencies>wavefunction potential</dependencies>
    </breakpoint>
  </sequence>

  <output>
      <sampling_group basis="y" initial_sample="no">
        <moments>dens</moments>
        <dependencies>wavefunction</dependencies>
        <![CDATA[
          dens = mod2(phi);
        ]]>
      </sampling_group>

      <sampling_group initial_sample="no">
        <moments>N</moments>
        <dependencies>normalisation</dependencies>
        <![CDATA[
          N = Ncalc;
        ]]>
      </sampling_group>

      <sampling_group basis="y yp" initial_sample="no">
        <moments>g1R g1I g2</moments>
        <dependencies>wavefunction</dependencies>
        <![CDATA[
          complex g1 = conj(phi(y => y)) * phi(y => yp);
          _SAMPLE_COMPLEX(g1);
          g2 = mod2(phi(y => y)) * mod2(phi(y => yp));
        ]]>
      </sampling_group>
  </output>
</simulation>
