Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 106 additions & 0 deletions tests/apps/openfoam/compile_openfoam.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#!/usr/bin/env python3

"""Reframe test for OpenFoam"""

# Based on original work from:
# Copyright 2016-2022 Swiss National Supercomputing Centre (CSCS/ETH Zurich)
# ReFrame Project Developers. See the top-level LICENSE file for details.
# SPDX-License-Identifier: BSD-3-Clause

import os
import reframe as rfm
import reframe.utility.sanity as sn


class FetchOpenFoam(rfm.RunOnlyRegressionTest):
"""Downlaod OpenFoam"""

version = variable(str, value="v2412")
executable = "wget"
executable_opts = [
f"https://sourceforge.net/projects/openfoam/files/{version}/OpenFOAM-{version}.tgz",
f"https://sourceforge.net/projects/openfoam/files/{version}/ThirdParty-{version}.tgz",
]
local = True
valid_systems = ["archer2:login"]
valid_prog_environs = ["PrgEnv-gnu"]

tags = {"fetch"}

@sanity_function
def validate_download(self):
"""Validate OpenFoam Downloaded"""
return sn.path_isfile(f"ThirdParty-{self.version}.tgz") and sn.path_isfile(f"OpenFOAM-{self.version}.tgz")


@rfm.simple_test
class CompileOpenFoam(rfm.CompileOnlyRegressionTest):
"""Test compilation of OpenFoam"""

build_system = "Make"
fetch_openfoam = fixture(FetchOpenFoam, scope="environment")

valid_systems = ["archer2:compute"]
valid_prog_environs = ["PrgEnv-gnu"]

tags = {"compile"}

modules = ["gcc/11.2.0", "mkl", "cray-fftw"]

build_prefix = ""

env_vars = {"FOAM_VERBOSE": "1", "FFTW_ARCH_PATH": "${FFTW_DIR}"}

num_nodes = 1
num_tasks_per_node = 1
num_cpus_per_task = 1
num_tasks = num_nodes * num_tasks_per_node * num_cpus_per_task
time_limit = "4h"

@run_before("compile")
def prepare_build(self):
"""Prepare environment for build"""
version = "v2412"
label1 = "OpenFOAM"
name1 = f"{label1}-{version}"
archive1 = f"{label1}-{version}.tgz"
label2 = "ThirdParty"
name2 = f"{label2}-{version}"
archive2 = f"{label2}-{version}.tgz"

self.build_prefix = f"{name1}"

config_file_fftw = f"{name1}/etc/config.sh/FFTW"
config_file_paraview = f"{name1}/etc/config.sh/paraview"

fullpath1 = os.path.join(self.fetch_openfoam.stagedir, archive1)
fullpath2 = os.path.join(self.fetch_openfoam.stagedir, archive2)

self.prebuild_cmds = [
f"cp {fullpath1} {self.stagedir}",
f"cp {fullpath2} {self.stagedir}",
f"tar xzf {archive1}",
f"tar xzf {archive2}",
f"export FOAM_SRC={self.build_prefix}",
f"export FOAM_THIRDPARTY={name2}",
f"cp prefs.sh {name1}/etc/prefs.sh",
f"sed -i 's/^fftw_version.*/fftw_version=fftw-system/' {config_file_fftw}",
f"sed -i 's/^export FFTW_ARCH_PATH.*//' {config_file_fftw}",
f"sed -i 's/^ParaView_VERSION.*/ParaView_VERSION=none/' {config_file_paraview}",
f"cd {self.build_prefix}",
"pwd",
"ls",
"module list",
"source ./etc/bashrc",
"echo $WM_PROJECT_DIR",
"ls $WM_PROJECT_DIR",
"./Allwmake -j 16",
"./Allwmake -j 1",
]

self.build_system.options = ["-v", "-n"]

@sanity_function
def validate_compile(self):
"""Validate compilation by checking existance of binary"""
return sn.assert_eq(0, 0)
33 changes: 33 additions & 0 deletions tests/apps/openfoam/fetch_openfoam.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env python3

"""Reframe test for OpenFoam"""

# Based on original work from:
# Copyright 2016-2022 Swiss National Supercomputing Centre (CSCS/ETH Zurich)
# ReFrame Project Developers. See the top-level LICENSE file for details.
# SPDX-License-Identifier: BSD-3-Clause

import reframe as rfm
import reframe.utility.sanity as sn


@rfm.simple_test
class FetchOpenFoam(rfm.RunOnlyRegressionTest):
"""Downlaod OpenFoam"""

version = variable(str, value="v2412")
executable = "wget"
executable_opts = [
f"https://sourceforge.net/projects/openfoam/files/{version}/OpenFOAM-{version}.tgz",
f"https://sourceforge.net/projects/openfoam/files/{version}/ThirdParty-{version}.tgz",
]
local = True
valid_systems = ["archer2:login"]
valid_prog_environs = ["PrgEnv-gnu"]

tags = {"fetch"}

@sanity_function
def validate_download(self):
"""Validate openFoam Downloaded"""
return sn.path_isfile(f"ThirdParty-{self.version}.tgz") and sn.path_isfile(f"OpenFOAM-{self.version}.tgz")
17 changes: 17 additions & 0 deletions tests/apps/openfoam/src/prefs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

export WM_MPLIB=CRAY-MPICH
export WM_COMPILER=Cray

export WM_COMPILER_LIB_ARCH=64
export WM_CC='cc'
export WM_CXX='CC'
export WM_CFLAGS='-fPIC'
export WM_CXXFLAGS='-fPIC'
export WM_LDFLAGS=''

# MPI
# Because ${WM_PROJECT_DIR}/etc/config.sh/mpi is sourced after this file
# we need to induce the system to set the appropriate variables:

export MPICH_DIR=${CRAY_MPICH_BASEDIR}
export MPI_ARCH_PATH=${MPICH_DIR}
162 changes: 162 additions & 0 deletions tests/apps/openfoam/test_module_openfoam.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
#!/usr/bin/env python3

"""ReFrame test for cp2k"""

import reframe as rfm
import reframe.utility.sanity as sn


class OpenFoamBaseCheck(rfm.RunOnlyRegressionTest):
"""ReFrame OpenFoam test base class"""

# Which modules to load in test
modules = ["openfoam/org/v10.20230119"]
# Identify the executable
executable = "interFoam"
# Additional Slurm parameters. Requires adding to config file first.
extra_resources = {"qos": {"qos": "standard"}}
# Output files to be retained
keep_files = ["rfm_job.out"]

maintainers = ["j.richings@epcc.ed.ac.uk"]
use_multithreading = False
tags = {"applications", "performance"}

# Reference value to validate run with

reference = {
"archer2:compute": {"performance": (6, -0.05, 0.05, "seconds")},
}

@sanity_function
def assert_finished(self):
"""Sanity check that simulation finished successfully"""
return sn.assert_found("End", self.keep_files[0])

@performance_function("seconds", perf_key="performance")
def extract_perf(self):
"""Extract performance value to compare with reference value"""
return sn.extractsingle(
r"ExecutionTime\s+=\s+(?P<time>\d+.?\d*\s+)s\s+ClockTime\s+=\s+\d*\s+s\n\nEnd",
self.keep_files[0],
"time",
float,
)


@rfm.simple_test
class OpenFoamDamnBreak(OpenFoamBaseCheck):
"""OpenFoam Damn break test"""

# Select system to use
valid_systems = ["archer2:compute"]
# Set Programming Environment
valid_prog_environs = ["PrgEnv-gnu"]
# Description of test
descr = "OpenFoam damnBreak"
# Command line options for executable
executable_opts = ("").split()
# different cpu frequencies
freq = parameter(["2250000", "2000000"])
# slurm parameters
num_tasks = 1
num_tasks_per_node = 1
num_cpus_per_task = 128
time_limit = "10m"

reference_performance = {
"2000000": (6, -0.1, 0.1, "seconds"),
"2250000": (3.6, -0.1, 0.1, "seconds"),
}

@run_after("init")
def setup_params(self):
"""sets up extra parameters"""
self.descr += self.freq
if self.current_system.name in ["archer2"]:
self.env_vars = {
"OMP_NUM_THREADS": str(self.num_cpus_per_task),
"OMP_PLACES": "cores",
"SLURM_CPU_FREQ_REQ": self.freq,
}

@run_before("run")
def setup_testcase(self):
"""set up test case"""
self.prerun_cmds = [
"source ${FOAM_INSTALL_DIR}/etc/bashrc",
"cp -r ${FOAM_INSTALL_DIR}/tutorials/multiphase/interFoam/laminar/damBreak/damBreak .",
"cd damBreak",
"blockMesh",
"cp 0/alpha.water.orig 0/alpha.water",
"setFields",
]

@run_before("performance")
def set_reference(self):
"""Changes reference values"""
if self.current_system.name in ["archer2"]:
# https://reframe-hpc.readthedocs.io/en/stable/utility_functions_reference.html#reframe.utility.ScopedDict
self.reference["archer2:compute:performance"] = self.reference_performance[self.freq]


@rfm.simple_test
class OpenFoamDamnBreakParallel(OpenFoamBaseCheck):
"""OpenFoam Damn break test"""

# Select system to use
valid_systems = ["archer2:compute"]
# Set Programming Environment
valid_prog_environs = ["PrgEnv-gnu"]
# Description of test
descr = "OpenFoam damnBreak"
# Command line options for executable
executable_opts = ("-parallel").split()
# different cpu frequencies
freq = parameter(["2250000", "2000000"])
# slurm parameters
num_tasks = 4
num_tasks_per_node = 1
num_cpus_per_task = 128
time_limit = "10m"

reference_performance = {
"2000000": (5, -0.5, 0.5, "seconds"),
"2250000": (5, -0.5, 0.5, "seconds"),
}

@run_after("init")
def setup_params(self):
"""sets up extra parameters"""
self.descr += self.freq
if self.current_system.name in ["archer2"]:
self.env_vars = {
"OMP_NUM_THREADS": str(self.num_cpus_per_task),
"OMP_PLACES": "cores",
"SLURM_CPU_FREQ_REQ": self.freq,
}

@run_before("run")
def setup_testcase(self):
"""set up test case"""
self.prerun_cmds = [
"source ${FOAM_INSTALL_DIR}/etc/bashrc",
"cp -r ${FOAM_INSTALL_DIR}/tutorials/multiphase/interFoam/laminar/damBreak/damBreak .",
"cd damBreak",
"blockMesh",
"cp 0/alpha.water.orig 0/alpha.water",
"setFields",
"decomposePar",
]

@sanity_function
def assert_finished_parallel(self):
"""Sanity check that simulation finished successfully"""
return sn.assert_found("Finalising parallel run", self.keep_files[0])

@run_before("performance")
def set_reference(self):
"""Changes reference values"""
if self.current_system.name in ["archer2"]:
# https://reframe-hpc.readthedocs.io/en/stable/utility_functions_reference.html#reframe.utility.ScopedDict
self.reference["archer2:compute:performance"] = self.reference_performance[self.freq]
Loading