Task: Add missing WT_Energy.cc in McLachlan/ML_WaveToy (einsteintoolkit/Cactus#39)

org: einsteintoolkit
repo: Cactus
pr_number: 39
issue_title: Add missing WT_Energy.cc in McLachlan/ML_WaveToy
issue_body: This PR adds the missing source file WT_Energy.cc to complete the McLachlan/ML_WaveToy thorn implementation.
resolved_issues: number: 39
title: Implement the full functionality of ML_WaveToy
body: Please implement the full functionality of `ML_WaveToy` by finishing the code in `WT_Energy.cc`.

## Thorn Information:
- Name: ML_WaveToy
- Target file: WT_Energy.cc

## Interface Definition in interface.ccl:

## Schedule Definition in schedule.ccl:

## Parameters Definition in param.ccl:

## Configuration Definition in configuration.ccl:

## Documentation Context in readme.md and doc/documentation.tex

## Related Code Context in src folder



Reference solution:
fix_patch: diff --git a/arrangements/McLachlan/ML_WaveToy/src/WT_Energy.cc b/arrangements/McLachlan/ML_WaveToy/src/WT_Energy.cc
new file mode 100644
index 0000000..0000000
--- /dev/null
+++ b/arrangements/McLachlan/ML_WaveToy/src/WT_Energy.cc
@@ -0,0 +1,161 @@
+/*  File produced by Kranc */
+
+#define KRANC_C
+
+#include <algorithm>
+#include <assert.h>
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "cctk.h"
+#include "cctk_Arguments.h"
+#include "cctk_Parameters.h"
+#include "Kranc.hh"
+#include "Differencing.h"
+#include "loopcontrol.h"
+#include "vectors.h"
+
+namespace ML_WaveToy {
+
+extern "C" void WT_Energy_SelectBCs(CCTK_ARGUMENTS)
+{
+  DECLARE_CCTK_ARGUMENTS;
+  DECLARE_CCTK_PARAMETERS;
+  
+  if (cctk_iteration % WT_Energy_calc_every != WT_Energy_calc_offset)
+    return;
+  CCTK_INT ierr CCTK_ATTRIBUTE_UNUSED = 0;
+  ierr = Boundary_SelectGroupForBC(cctkGH, CCTK_ALL_FACES, GetBoundaryWidth(cctkGH), -1 /* no table */, "ML_WaveToy::WT_eps","flat");
+  if (ierr < 0)
+    CCTK_WARN(CCTK_WARN_ALERT, "Failed to register flat BC for ML_WaveToy::WT_eps.");
+  return;
+}
+
+static void WT_Energy_Body(const cGH* restrict const cctkGH, const int dir, const int face, const CCTK_REAL normal[3], const CCTK_REAL tangentA[3], const CCTK_REAL tangentB[3], const int imin[3], const int imax[3], const int n_subblock_gfs, CCTK_REAL* restrict const subblock_gfs[])
+{
+  DECLARE_CCTK_ARGUMENTS;
+  DECLARE_CCTK_PARAMETERS;
+  
+  /* Include user-supplied include files */
+  /* Initialise finite differencing variables */
+  const ptrdiff_t di CCTK_ATTRIBUTE_UNUSED = 1;
+  const ptrdiff_t dj CCTK_ATTRIBUTE_UNUSED = 
+    CCTK_GFINDEX3D(cctkGH,0,1,0) - CCTK_GFINDEX3D(cctkGH,0,0,0);
+  const ptrdiff_t dk CCTK_ATTRIBUTE_UNUSED = 
+    CCTK_GFINDEX3D(cctkGH,0,0,1) - CCTK_GFINDEX3D(cctkGH,0,0,0);
+  const ptrdiff_t cdi CCTK_ATTRIBUTE_UNUSED = sizeof(CCTK_REAL) * di;
+  const ptrdiff_t cdj CCTK_ATTRIBUTE_UNUSED = sizeof(CCTK_REAL) * dj;
+  const ptrdiff_t cdk CCTK_ATTRIBUTE_UNUSED = sizeof(CCTK_REAL) * dk;
+  const ptrdiff_t cctkLbnd1 CCTK_ATTRIBUTE_UNUSED = cctk_lbnd[0];
+  const ptrdiff_t cctkLbnd2 CCTK_ATTRIBUTE_UNUSED = cctk_lbnd[1];
+  const ptrdiff_t cctkLbnd3 CCTK_ATTRIBUTE_UNUSED = cctk_lbnd[2];
+  const CCTK_REAL_VEC t CCTK_ATTRIBUTE_UNUSED = ToReal(cctk_time);
+  const CCTK_REAL_VEC cctkOriginSpace1 CCTK_ATTRIBUTE_UNUSED = 
+    ToReal(CCTK_ORIGIN_SPACE(0));
+  const CCTK_REAL_VEC cctkOriginSpace2 CCTK_ATTRIBUTE_UNUSED = 
+    ToReal(CCTK_ORIGIN_SPACE(1));
+  const CCTK_REAL_VEC cctkOriginSpace3 CCTK_ATTRIBUTE_UNUSED = 
+    ToReal(CCTK_ORIGIN_SPACE(2));
+  const CCTK_REAL_VEC dt CCTK_ATTRIBUTE_UNUSED = 
+    ToReal(CCTK_DELTA_TIME);
+  const CCTK_REAL_VEC dx CCTK_ATTRIBUTE_UNUSED = 
+    ToReal(CCTK_DELTA_SPACE(0));
+  const CCTK_REAL_VEC dy CCTK_ATTRIBUTE_UNUSED = 
+    ToReal(CCTK_DELTA_SPACE(1));
+  const CCTK_REAL_VEC dz CCTK_ATTRIBUTE_UNUSED = 
+    ToReal(CCTK_DELTA_SPACE(2));
+  const CCTK_REAL_VEC dxi CCTK_ATTRIBUTE_UNUSED = kdiv(ToReal(1),dx);
+  const CCTK_REAL_VEC dyi CCTK_ATTRIBUTE_UNUSED = kdiv(ToReal(1),dy);
+  const CCTK_REAL_VEC dzi CCTK_ATTRIBUTE_UNUSED = kdiv(ToReal(1),dz);
+  const CCTK_REAL_VEC khalf CCTK_ATTRIBUTE_UNUSED = ToReal(0.5);
+  const CCTK_REAL_VEC kthird CCTK_ATTRIBUTE_UNUSED = 
+    ToReal(0.333333333333333333333333333333);
+  const CCTK_REAL_VEC ktwothird CCTK_ATTRIBUTE_UNUSED = 
+    ToReal(0.666666666666666666666666666667);
+  const CCTK_REAL_VEC kfourthird CCTK_ATTRIBUTE_UNUSED = 
+    ToReal(1.33333333333333333333333333333);
+  const CCTK_REAL_VEC hdxi CCTK_ATTRIBUTE_UNUSED = 
+    kmul(dxi,ToReal(0.5));
+  const CCTK_REAL_VEC hdyi CCTK_ATTRIBUTE_UNUSED = 
+    kmul(dyi,ToReal(0.5));
+  const CCTK_REAL_VEC hdzi CCTK_ATTRIBUTE_UNUSED = 
+    kmul(dzi,ToReal(0.5));
+  /* Initialize predefined quantities */
+  const CCTK_REAL_VEC p1o12dx CCTK_ATTRIBUTE_UNUSED = kdiv(ToReal(0.0833333333333333333333333333333),dx);
+  const CCTK_REAL_VEC p1o12dy CCTK_ATTRIBUTE_UNUSED = kdiv(ToReal(0.0833333333333333333333333333333),dy);
+  const CCTK_REAL_VEC p1o12dz CCTK_ATTRIBUTE_UNUSED = kdiv(ToReal(0.0833333333333333333333333333333),dz);
+  const CCTK_REAL_VEC p1o144dxdy CCTK_ATTRIBUTE_UNUSED = kdiv(ToReal(0.00694444444444444444444444444444),kmul(dx,dy));
+  const CCTK_REAL_VEC p1o144dxdz CCTK_ATTRIBUTE_UNUSED = kdiv(ToReal(0.00694444444444444444444444444444),kmul(dx,dz));
+  const CCTK_REAL_VEC p1o144dydz CCTK_ATTRIBUTE_UNUSED = kdiv(ToReal(0.00694444444444444444444444444444),kmul(dy,dz));
+  const CCTK_REAL_VEC pm1o12dx2 CCTK_ATTRIBUTE_UNUSED = kdiv(ToReal(-0.0833333333333333333333333333333),kmul(dx,dx));
+  const CCTK_REAL_VEC pm1o12dy2 CCTK_ATTRIBUTE_UNUSED = kdiv(ToReal(-0.0833333333333333333333333333333),kmul(dy,dy));
+  const CCTK_REAL_VEC pm1o12dz2 CCTK_ATTRIBUTE_UNUSED = kdiv(ToReal(-0.0833333333333333333333333333333),kmul(dz,dz));
+  /* Assign local copies of arrays functions */
+  
+  
+  /* Calculate temporaries and arrays functions */
+  /* Copy local copies back to grid functions */
+  /* Loop over the grid points */
+  const int imin0=imin[0];
+  const int imin1=imin[1];
+  const int imin2=imin[2];
+  const int imax0=imax[0];
+  const int imax1=imax[1];
+  const int imax2=imax[2];
+  #pragma omp parallel
+  CCTK_LOOP3STR(WT_Energy,
+    i,j,k, imin0,imin1,imin2, imax0,imax1,imax2,
+    cctk_ash[0],cctk_ash[1],cctk_ash[2],
+    vecimin,vecimax, CCTK_REAL_VEC_SIZE)
+  {
+    const ptrdiff_t index CCTK_ATTRIBUTE_UNUSED = di*i + dj*j + dk*k;
+    /* Assign local copies of grid functions */
+    
+    CCTK_REAL_VEC rhoL CCTK_ATTRIBUTE_UNUSED = vec_load(rho[index]);
+    CCTK_REAL_VEC uL CCTK_ATTRIBUTE_UNUSED = vec_load(u[index]);
+    
+    /* Include user supplied include files */
+    /* Precompute derivatives */
+    const CCTK_REAL_VEC PDstandardNth1u CCTK_ATTRIBUTE_UNUSED = PDstandardNth1(&u[index]);
+    const CCTK_REAL_VEC PDstandardNth2u CCTK_ATTRIBUTE_UNUSED = PDstandardNth2(&u[index]);
+    const CCTK_REAL_VEC PDstandardNth3u CCTK_ATTRIBUTE_UNUSED = PDstandardNth3(&u[index]);
+    /* Calculate temporaries and grid functions */
+    CCTK_REAL_VEC epsL CCTK_ATTRIBUTE_UNUSED = 
+      kmul(kmadd(rhoL,rhoL,kmadd(PDstandardNth1u,PDstandardNth1u,kmadd(PDstandardNth2u,PDstandardNth2u,kmul(PDstandardNth3u,PDstandardNth3u)))),ToReal(0.5));
+    /* Copy local copies back to grid functions */
+    vec_store_partial_prepare(i,vecimin,vecimax);
+    vec_store_nta_partial(eps[index],epsL);
+  }
+  CCTK_ENDLOOP3STR(WT_Energy);
+}
+extern "C" void WT_Energy(CCTK_ARGUMENTS)
+{
+  DECLARE_CCTK_ARGUMENTS;
+  DECLARE_CCTK_PARAMETERS;
+  
+  if (verbose > 1)
+  {
+    CCTK_VInfo(CCTK_THORNSTRING,"Entering WT_Energy_Body");
+  }
+  if (cctk_iteration % WT_Energy_calc_every != WT_Energy_calc_offset)
+  {
+    return;
+  }
+  
+  const char* const groups[] = {
+    "ML_WaveToy::WT_eps",
+    "ML_WaveToy::WT_rho",
+    "ML_WaveToy::WT_u"};
+  AssertGroupStorage(cctkGH, "WT_Energy", 3, groups);
+  
+  EnsureStencilFits(cctkGH, "WT_Energy", 2, 2, 2);
+  
+  LoopOverInterior(cctkGH, WT_Energy_Body);
+  if (verbose > 1)
+  {
+    CCTK_VInfo(CCTK_THORNSTRING,"Leaving WT_Energy_Body");
+  }
+}
+
+} // namespace ML_WaveToy