<commit_before><?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE testproblem SYSTEM "regressiontest.dtd">
<testproblem>
  <name>test energy stats and compare parallel and serial</name>
  <owner userid="hhiester"/>
  <problem_definition length="medium" nprocs="1">
    <command_line>
    mpiexec  -np 1 ../../bin/fluidity -v3 -l lock_exchange_2d.flml &amp;&amp;
    mpiexec -np 4 ../../bin/fluidity -v3 -l lock_exchange_2d_parallel.flml
    </command_line> 
  </problem_definition>
  <variables>
    <variable name="times" language="python">
from fluidity_tools import stat_parser
import glob

times = []
for statfile in glob.glob('*.stat'):
  stat = stat_parser(statfile)
  times.append(stat["ElapsedTime"]["value"][-1])
  print statfile, 'end_time: ', times[-1]
    </variable>
    <variable name="errors" language="python">
import vtk
import glob
import sys
from lxml import etree
import re
import os
import scipy.stats
import math
import vtktools
import numpy
from fluidity_tools import stat_parser

################################################################################################

def not_comment(x):
# function to filter stream for use in Getflmlvalue
  return not 'comment' in x.tag

################################################################################################


def Getflmlvalue(flml_name, xpath):

# We will be filtering the children of the elements later,
# to remove comments.

# The spud file to modify
  filename = flml_name

# The path to the node in the tree - xpath

# Open it up
  tree = etree.parse(open(filename))

  node = tree.xpath(xpath)[0]

  child = filter(not_comment, node.getchildren())[0]

  return child.text

################################################################################################

def SVG2PDF(fign, rmsvg = True):

  subprocess.Popen(['inkscape', '-z', '--export-pdf='+fign+'.pdf', fign+'.svg'], stdout=subprocess.PIPE).communicate()[0]
  subprocess.Popen(['pdfcrop', fign+'.pdf', fign+'.pdf'], stdout=subprocess.PIPE).communicate()[0]
  if rmsvg == True: 
    subprocess.Popen(['rm', fign+'.svg'], stdout=subprocess.PIPE).communicate()[0]

  return
    
################################################################################################

# extract values from flml

#dt
dt = float(Getflmlvalue('lock_exchange_2d.flml','/fluidity_options/timestepping/timestep'))
#diffusivity
try: kappa = float(Getflmlvalue('lock_exchange_2d.flml','/fluidity_options/material_phase[@name="fluid"]/scalar_field[@name="Temperature"]/prognostic/  tensor_field[@name="Diffusivity"]/prescribed/value[@name="WholeMesh"]/isotropic/constant'))
except: kappa = 0

#viscosity
try: nu = float(Getflmlvalue('lock_exchange_2d.flml','/fluidity_options/material_phase[@name="fluid"]/vector_field[@name="Velocity"]/prognostic/tensor_field[@name="Viscosity"]/prescribed/value[@name="WholeMesh"]/isotropic/constant')); #nu = 1E-6
except: nu = 0
# reference density (in EOS)
rho_0 = float(Getflmlvalue('lock_exchange_2d.flml','/fluidity_options/material_phase["@name=fluid"]/equation_of_state/fluids/linear/reference_density'))

energy_stats = []
for statfile in glob.glob('*.stat'):
  stat = stat_parser(statfile)

# Time
  time = stat["ElapsedTime"]["value"]

# Potential energy
  PE = stat["fluid"]["GravitationalPotentialEnergyDensity"]["integral"]
  PE_t = scipy.diff(PE)/dt

# Background potential energy
# Minimum potential energy available through an adiabatic restratification of the fluid
  try: BPE = stat["fluid"]["BackgroundPotentialEnergyDensity"]["integral"]
  except: BPE = []

# Potential energy diffused through boundaries 
  PEflux = stat["fluid"]["GravitationalPotentialEnergyDensity"]["surface_integral%PEFlux"]*kappa
  PEout = scipy.integrate.cumtrapz(PEflux,time)

# Potential change through diffusion within the domain
  DD = stat["fluid"]["DiffusiveDissipation"]["integral"]*2.0*kappa
  DDtot = scipy.integrate.cumtrapz(DD,time)

# Kinetic energy - taken from KineticEnergyDensity (non-Boussinesq) 
# and Velocity (Boussinesq) for illustration
  KE_1 = stat["fluid"]["KineticEnergyDensity"]["integral"]
  KE_1_t = scipy.diff(KE_1)/dt
<commit_msg>fixing the test case lucid and karmic returned files in a different order when using glob("*.stat"). Have now named files explicitly. Also removing some unecessary lines of code<commit_after><?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE testproblem SYSTEM "regressiontest.dtd">
<testproblem>
  <name>test energy stats and compare parallel and serial</name>
  <owner userid="hhiester"/>
  <problem_definition length="medium" nprocs="1">
    <command_line>
    mpiexec  -np 1 ../../bin/fluidity -v3 -l lock_exchange_2d.flml &amp;&amp;
    mpiexec -np 4 ../../bin/fluidity -v3 -l lock_exchange_2d_parallel.flml
    </command_line> 
  </problem_definition>
  <variables>
    <variable name="times" language="python">
from fluidity_tools import stat_parser
import glob

times = []
for statfile in glob.glob('*.stat'):
  stat = stat_parser(statfile)
  times.append(stat["ElapsedTime"]["value"][-1])
  print statfile, 'end_time: ', times[-1]
    </variable>
    <variable name="errors" language="python">
import vtk
import glob
import sys
from lxml import etree
import re
import os
import scipy.stats
import math
import vtktools
import numpy
from fluidity_tools import stat_parser

################################################################################################

def not_comment(x):
# function to filter stream for use in Getflmlvalue
  return not 'comment' in x.tag

################################################################################################


def Getflmlvalue(flml_name, xpath):

# We will be filtering the children of the elements later,
# to remove comments.

# The spud file to modify
  filename = flml_name

# The path to the node in the tree - xpath

# Open it up
  tree = etree.parse(open(filename))

  node = tree.xpath(xpath)[0]

  child = filter(not_comment, node.getchildren())[0]

  return child.text

################################################################################################

# extract values from flml

#dt
dt = float(Getflmlvalue('lock_exchange_2d.flml','/fluidity_options/timestepping/timestep'))
#diffusivity
try: kappa = float(Getflmlvalue('lock_exchange_2d.flml','/fluidity_options/material_phase[@name="fluid"]/scalar_field[@name="Temperature"]/prognostic/  tensor_field[@name="Diffusivity"]/prescribed/value[@name="WholeMesh"]/isotropic/constant'))
except: kappa = 0

#viscosity
try: nu = float(Getflmlvalue('lock_exchange_2d.flml','/fluidity_options/material_phase[@name="fluid"]/vector_field[@name="Velocity"]/prognostic/tensor_field[@name="Viscosity"]/prescribed/value[@name="WholeMesh"]/isotropic/constant')); #nu = 1E-6
except: nu = 0
# reference density (in EOS)
rho_0 = float(Getflmlvalue('lock_exchange_2d.flml','/fluidity_options/material_phase["@name=fluid"]/equation_of_state/fluids/linear/reference_density'))

energy_stats = []
for statfile in ['lock_exchange_2d.stat', 'lock_exchange_2d_parallel.stat']:
  stat = stat_parser(statfile)

# Time
  time = stat["ElapsedTime"]["value"]

# Potential energy
  PE = stat["fluid"]["GravitationalPotentialEnergyDensity"]["integral"]
  PE_t = scipy.diff(PE)/dt

# Background potential energy
# Minimum potential energy available through an adiabatic restratification of the fluid
  try: BPE = stat["fluid"]["BackgroundPotentialEnergyDensity"]["integral"]
  except: BPE = []

# Potential energy diffused through boundaries 
  PEflux = stat["fluid"]["GravitationalPotentialEnergyDensity"]["surface_integral%PEFlux"]*kappa
  PEout = scipy.integrate.cumtrapz(PEflux,time)

# Potential change through diffusion within the domain
  DD = stat["fluid"]["DiffusiveDissipation"]["integral"]*2.0*kappa
  DDtot = scipy.integrate.cumtrapz(DD,time)

# Kinetic energy - taken from KineticEnergyDensity (non-Boussinesq) 
# and Velocity (Boussinesq) for illustration
  KE_1 = stat["fluid"]["KineticEnergyDensity"]["integral"]
  KE_1_t = scipy.diff(KE_1)/dt

{'fraction_non_alphanumeric': 0.20895708582834333, 'fraction_numerical': 0.007734530938123752, 'mean_word_length': 6.341575091575091, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 2, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '519865', 'n_tokens_mistral': 2637, 'n_tokens_neox': 2489, 'n_words': 548}