<?xml version="1.0" encoding="UTF-8"?>
<simulation xmds-version="2">
  <testing>
    <command_line>mpirun -n 2 ./anharmonic_oscillator_wigner_mpi</command_line>
    <input_xsil_file name="anharmonic_oscillator_wigner_mpi_initial_even.xsil" />
    <input_xsil_file name="anharmonic_oscillator_wigner_mpi_initial_odd.xsil" />
    <xsil_file name="anharmonic_oscillator_wigner_mpi.xsil" expected="anharmonic_oscillator_wigner_mpi_expected.xsil" absolute_tolerance="1e-7" relative_tolerance="1e-5" />
  </testing>
  
  <name>anharmonic_oscillator_wigner_mpi</name>
  <author>Graham Dennis</author>
  <description>
    Simulation of the Truncated Wigner function for an anharmonic oscillator with the initial state
    being a coherent state.
  </description>
  
  <features>
    <benchmark />
    <bing />
    <fftw plan="patient"/>
    <globals>
      <![CDATA[

      /* system constants */
        const double omega = 0.0;
        const double g = 1.0;
        
      /* initial state constants */
        const double alpha_0 = 3.0;
        
      ]]>
    </globals>
    <validation kind="run-time" />
  </features>
  
  <driver name="distributed-mpi" />
  
  <geometry>
    <propagation_dimension> t </propagation_dimension>
    <transverse_dimensions>
      <integer_valued kind="first">
        <dimension name="m" lattice="21" domain="(0, 20)" />
      </integer_valued>
      <dimension name="r" lattice="64"  domain="(0, 6)" transform="dct" />
      <dimension name="s" lattice="64"  domain="(0, 6)" transform="dst" />
      <dimension name="theta" lattice="32"  domain="(-M_PI, M_PI)" />
    </transverse_dimensions>
  </geometry>
  
  <vector name="evens" dimensions="m r" type="complex">
    <components>
      hE
    </components>
    <initialisation kind="xsil">
      <filename>anharmonic_oscillator_wigner_mpi_initial_even.xsil</filename>
    </initialisation>
  </vector>
  
  <vector name="odds" dimensions="m s" type="complex">
    <components>
      hO
    </components>
    <initialisation kind="xsil">
      <filename>anharmonic_oscillator_wigner_mpi_initial_odd.xsil</filename>
    </initialisation>
  </vector>
  
  <vector name="trig" dimensions="m theta" type="double">
    <components>cos_me sin_me cos_mo sin_mo</components>
    <initialisation>
      <![CDATA[
        cos_me = cos(2.0*m*theta);
        sin_me = sin(2.0*m*theta);
        cos_mo = cos((2.0*m+1.0)*theta);
        sin_mo = sin((2.0*m+1.0)*theta);
      ]]>
    </initialisation>
  </vector>
  
  <computed_vector name="WignerEven" dimensions="r theta" type="double">
    <components>WE</components>
    <evaluation>
      <dependencies>evens trig</dependencies>
      <![CDATA[
        WE = hE.re*cos_me + hE.im*sin_me;
      ]]>
    </evaluation>
  </computed_vector>
  
  <computed_vector name="WignerOdd" dimensions="s theta" type="double">
    <components>WO</components>
    <evaluation>
      <dependencies>odds trig</dependencies>
      <![CDATA[
        WO = hO.re*cos_mo + hO.im*sin_mo;
      ]]>
    </evaluation>
  </computed_vector>
  
  <sequence>
    <integrate algorithm="ARK45" cutoff="1e-3" tolerance="1e-5" interval="7.0e-1" steps="100000">
      <samples>20 20 20 20 20 20</samples>
      <operators dimensions="r m">
        <integration_vectors>evens</integration_vectors>
        <![CDATA[
          const double M = 2*m;
          dhE_dt = -i*omega*M*hE - i*g*(r*r-1.0)*M*hE;
        ]]>
      </operators>
      <operators dimensions="s m">
        <integration_vectors>odds</integration_vectors>
        <![CDATA[
          const double M = 2*m+1.0;
          dhO_dt = -i*omega*M*hO - i*g*(s*s-1.0)*M*hO;
        ]]>
      </operators>
    </integrate>
  </sequence>
  
  <output format="binary">
      <sampling_group initial_sample="yes">
        <!-- Any dimension not mentioned is assumed to be in real space and its middle element will be sampled -->
        <!-- Note that this is different default behaviour to the filter operator. To integrate, put in a dimension -->
        <!-- with zero lattice points. -->
        <!-- Note that dimensions can be in any order. Not that I can think of a reason why you would want to do that -->
        <dimension name="r" fourier_space="no" />
        <dimension name="theta" fourier_space="no" />
        <moments>WER</moments>
        <dependencies>WignerEven</dependencies>
        <![CDATA[
          WER = WE;
        ]]>
      </sampling_group>
      <sampling_group initial_sample="yes">
        <dimension name="s" fourier_space="no" />
        <dimension name="theta" />
        <moments>WOR</moments>
        <dependencies>WignerOdd</dependencies>
        <![CDATA[
          WOR = WO;
        ]]>
      </sampling_group>
      <sampling_group initial_sample="yes">
        <dimension name="m"/>
        <dimension name="r" />
        <moments>hER hEI</moments>
        <dependencies>evens</dependencies>
        <![CDATA[
          _SAMPLE_COMPLEX(hE);
        ]]>
      </sampling_group>
      <sampling_group initial_sample="yes">
        <dimension name="m"/>
        <dimension name="s" />
        <moments>hOR hOI</moments>
        <dependencies>odds</dependencies>
        <![CDATA[
          _SAMPLE_COMPLEX(hO);
        ]]>
      </sampling_group>
      <sampling_group initial_sample="yes">
        <dimension name="m"/>
        <dimension name="r" fourier_space="yes" />
        <moments>hER hEI</moments>
        <dependencies>evens</dependencies>
        <![CDATA[
          _SAMPLE_COMPLEX(hE);
        ]]>
      </sampling_group>
      <sampling_group initial_sample="yes">
        <dimension name="m"/>
        <dimension name="s" fourier_space="yes" />
        <moments>hOR hOI</moments>
        <dependencies>odds</dependencies>
        <![CDATA[
          _SAMPLE_COMPLEX(hO);
        ]]>
      </sampling_group>
  </output>

<info>
Script compiled with xpdeint version VERSION_PLACEHOLDER (SUBVERSION_REVISION_PLACEHOLDER)
See http://www.xmds.org for more information.
</info>

<XSIL Name="moment_group_1">
  <Param Name="n_independent">3</Param>
  <Array Name="variables" Type="Text">
    <Dim>4</Dim>
    <Stream><Metalink Format="Text" Delimiter=" \n"/>
t r theta WER 
    </Stream>
  </Array>
  <Array Name="data" Type="double">
    <Dim>21</Dim>
    <Dim>64</Dim>
    <Dim>32</Dim>
    <Dim>4</Dim>
    <Stream><Metalink Format="Binary" UnsignedLong="uint32" precision="double" Type="Remote" Encoding="LittleEndian"/>
anharmonic_oscillator_wigner_mpi_expected_mg0.dat
    </Stream>
  </Array>
</XSIL>

<XSIL Name="moment_group_2">
  <Param Name="n_independent">3</Param>
  <Array Name="variables" Type="Text">
    <Dim>4</Dim>
    <Stream><Metalink Format="Text" Delimiter=" \n"/>
t s theta WOR 
    </Stream>
  </Array>
  <Array Name="data" Type="double">
    <Dim>21</Dim>
    <Dim>64</Dim>
    <Dim>32</Dim>
    <Dim>4</Dim>
    <Stream><Metalink Format="Binary" UnsignedLong="uint32" precision="double" Type="Remote" Encoding="LittleEndian"/>
anharmonic_oscillator_wigner_mpi_expected_mg1.dat
    </Stream>
  </Array>
</XSIL>

<XSIL Name="moment_group_3">
  <Param Name="n_independent">3</Param>
  <Array Name="variables" Type="Text">
    <Dim>5</Dim>
    <Stream><Metalink Format="Text" Delimiter=" \n"/>
t m r hER hEI 
    </Stream>
  </Array>
  <Array Name="data" Type="double">
    <Dim>21</Dim>
    <Dim>21</Dim>
    <Dim>64</Dim>
    <Dim>5</Dim>
    <Stream><Metalink Format="Binary" UnsignedLong="uint32" precision="double" Type="Remote" Encoding="LittleEndian"/>
anharmonic_oscillator_wigner_mpi_expected_mg2.dat
    </Stream>
  </Array>
</XSIL>

<XSIL Name="moment_group_4">
  <Param Name="n_independent">3</Param>
  <Array Name="variables" Type="Text">
    <Dim>5</Dim>
    <Stream><Metalink Format="Text" Delimiter=" \n"/>
t m s hOR hOI 
    </Stream>
  </Array>
  <Array Name="data" Type="double">
    <Dim>21</Dim>
    <Dim>21</Dim>
    <Dim>64</Dim>
    <Dim>5</Dim>
    <Stream><Metalink Format="Binary" UnsignedLong="uint32" precision="double" Type="Remote" Encoding="LittleEndian"/>
anharmonic_oscillator_wigner_mpi_expected_mg3.dat
    </Stream>
  </Array>
</XSIL>

<XSIL Name="moment_group_5">
  <Param Name="n_independent">3</Param>
  <Array Name="variables" Type="Text">
    <Dim>5</Dim>
    <Stream><Metalink Format="Text" Delimiter=" \n"/>
t m kr hER hEI 
    </Stream>
  </Array>
  <Array Name="data" Type="double">
    <Dim>21</Dim>
    <Dim>21</Dim>
    <Dim>64</Dim>
    <Dim>5</Dim>
    <Stream><Metalink Format="Binary" UnsignedLong="uint32" precision="double" Type="Remote" Encoding="LittleEndian"/>
anharmonic_oscillator_wigner_mpi_expected_mg4.dat
    </Stream>
  </Array>
</XSIL>

<XSIL Name="moment_group_6">
  <Param Name="n_independent">3</Param>
  <Array Name="variables" Type="Text">
    <Dim>5</Dim>
    <Stream><Metalink Format="Text" Delimiter=" \n"/>
t m ks hOR hOI 
    </Stream>
  </Array>
  <Array Name="data" Type="double">
    <Dim>21</Dim>
    <Dim>21</Dim>
    <Dim>64</Dim>
    <Dim>5</Dim>
    <Stream><Metalink Format="Binary" UnsignedLong="uint32" precision="double" Type="Remote" Encoding="LittleEndian"/>
anharmonic_oscillator_wigner_mpi_expected_mg5.dat
    </Stream>
  </Array>
</XSIL>
</simulation>
