Skip to content

Commit

Permalink
add actions workflow with unit tests for smarSimFunctionObject
Browse files Browse the repository at this point in the history
  • Loading branch information
FoamScience committed Oct 27, 2023
1 parent 260ad12 commit 0ce4ac2
Show file tree
Hide file tree
Showing 11 changed files with 157 additions and 34 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/smartsim.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: smartsim
defaults:
run:
shell: bash -o pipefail -i {0}
on:
push:
branches:
- main
- 'smartsim*'
- 'static_client'
- 'releases/**'
pull_request:
types: [opened, reopened]
workflow_dispatch:
inputs:
debug_enabled:
type: boolean
description: 'Tmate debugging session'
required: false
default: false

jobs:
build:
runs-on: ubuntu-22.04

container:
image: ghcr.io/foamscience/openfoam-smartsim:cpu
options: --user openfoam
env:
CATCH_TIMEOUT: 20
FOAM_FOAMUT: "/tmp/foamUT"
SSBD: "redis:6379"

services:
redis:
image: redislabs/redisai

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup tmate session
uses: mxschmitt/action-tmate@v3
if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }}
with:
detached: true

- name: Compile and Test
run: |
cd 2023-01/smartsim
source /usr/lib/openfoam/openfoam2212/etc/bashrc
mkdir -p $FOAM_USER_LIBBIN
./Allwmake
git clone https://github.com/FoamScience/foamUT $FOAM_FOAMUT
sed -i 's/mpirun/mpirun --oversubscribe/g' $FOAM_FOAMUT/Alltest
ln -s "$PWD"/smartsim_function_object/smartSimFunctionObject "$FOAM_FOAMUT"/smartSimFunctionObject
ln -s "$PWD"/smartsim_function_object/tests "$FOAM_FOAMUT"/tests/smartSimFOTests
cd $FOAM_FOAMUT || exit 1
rm -rf tests/exampleTests
./Alltest "$@"
if [ -f $FOAM_FOAMUT/tests/adaptiveFvMeshTests/log.wmake ]; then cat $FOAM_FOAMUT/tests/adaptiveFvMeshTests/log.wmake; fi
3 changes: 3 additions & 0 deletions 2023-01/smartsim/Allwmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/bash

wmake smartsim_function_object/smartSimFunctionObject
33 changes: 33 additions & 0 deletions 2023-01/smartsim/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Dockerfile to build SmartSim/SmartRedis-ready images for developing OpenFOAM-related stuff
#FROM opencfd/openfoam-dev
# The images from OpenCFD do not play nice with Github, so I use my own ones
FROM ghcr.io/foamscience/jammy-openfoam:v2212
LABEL maintainer="Mohammed Elwardi Fadeli <[email protected]>"

# Dependencies
USER root
RUN apt update && apt install -y python3-dev python3-pip git-core git-lfs cmake unzip vim wget
RUN apt clean && apt autoremove --yes && rm -rf /var/lib/{cache,log}/

# Software versions; overriding these has no effect on resulting containers; but nice to have
# as environment variables to remove version confusion
ENV SMARTREDIS_VERSION="6bfcf1deb0d726df75610fe8a352b9ecb13c44f7"
ENV SMARTSIM_VERSION="0.5.1"

# Install SmartSim (maybe get the development version for this too?)
RUN pip install smartsim[ml]==$SMARTSIM_VERSION

USER openfoam

# Build SmartRedis
ENV FOAM_SMARTREDIS=$HOME/smartredis
RUN git clone https://github.com/CrayLabs/SmartRedis $FOAM_SMARTREDIS &&\
cd $FOAM_SMARTREDIS && git reset --hard $SMARTREDIS_VERSION
RUN cd $FOAM_SMARTREDIS && sudo smart clobber && sudo smart build --device=cpu && make lib

# Environment variables to use for linking SmartRedis libs to OpenFOAM bins/libs
ENV SMARTREDIS_INCLUDE=$FOAM_SMARTREDIS/install/include
ENV SMARTREDIS_LIB=$FOAM_SMARTREDIS/install/lib
ENV LD_LIBRARY_PATH=$SMARTREDIS_LIB:$LD_LIBRARY_PATH
RUN find /usr/lib/openfoam -iname DiagonalMatrix.H -exec sudo sed -i 's/DiagonalMatrix<Type>/DiagonalMatrix/g' {} \;
WORKDIR $HOME
13 changes: 5 additions & 8 deletions 2023-01/smartsim/configure-smartredis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
# Define environmental variables for including and linking SmartRedis in
# OpenFOAM applications and libraries.

echo Warning: make sure you sourced configure-smartredis.sh in its folder.
# Otherwise, the include files for OpenFOAM application/library compilations will be wrong.

export FOAM_SMARTREDIS=$PWD/smartredis
export FOAM_SMARTREDIS_INCLUDE=$FOAM_SMARTREDIS/include
export FOAM_SMARTREDIS_DEP_INCLUDE=$FOAM_SMARTREDIS/install/include
export FOAM_SMARTREDIS_LIB=$FOAM_SMARTREDIS/install/lib
export FOAM_SMARTREDIS_BUILD_LIB=$FOAM_SMARTREDIS/build
export LD_LIBRARY_PATH=$FOAM_SMARTREDIS_BUILD_LIB:$LD_LIBRARY_PATH
if [ ! -d "$FOAM_SMARTREDIS" ]; then
echo "$FOAM_SMARTREDIS does not exist, please source configure-smartredis.sh from its folder"
fi
export SMARTREDIS_INCLUDE=$FOAM_SMARTREDIS/install/include
export SMARTREDIS_LIB=$FOAM_SMARTREDIS/install/lib
export LD_LIBRARY_PATH=$FOAM_SMARTREDIS_LIB:$LD_LIBRARY_PATH
export SSDB="127.0.0.1:8000" # for multinode setup let smartsim do this
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ EXE_INC = \
-I$(LIB_SRC)/TurbulenceModels/incompressible/lnInclude \
-I$(LIB_SRC)/transportModels \
-I$(LIB_SRC)/transportModels/incompressible/singlePhaseTransportModel \
-I$(FOAM_SMARTREDIS_INCLUDE) \
-I$(FOAM_SMARTREDIS_DEP_INCLUDE)
-I$(SMARTREDIS_INCLUDE)

EXE_LIBS = \
-lfiniteVolume \
Expand All @@ -19,5 +18,5 @@ EXE_LIBS = \
-lincompressibleTurbulenceModels \
-lincompressibleTransportModels \
-latmosphericModels \
-L$(FOAM_SMARTREDIS_LIB) -lhiredis -lredis++ \
-L$(FOAM_SMARTREDIS_BUILD_LIB) -lsmartredis
-L$(SMARTREDIS_LIB) -lhiredis -lredis++ \
-lsmartredis
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ EXE_INC = \
-Wno-old-style-cast \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(FOAM_SMARTREDIS_INCLUDE) \
-I$(FOAM_SMARTREDIS_DEP_INCLUDE)
-I$(SMARTREDIS_INCLUDE)

LIB_LIBS = \
-L$(FOAM_SMARTREDIS_LIB) \
-lfiniteVolume \
-lmeshTools \
-L$(FOAM_SMARTREDIS_LIB) -lhiredis -lredis++ \
-L$(SMARTREDIS_LIB) -lhiredis -lredis++ \
-lsmartredis
5 changes: 5 additions & 0 deletions 2023-01/smartsim/smartsim_function_object/tests/Make/files
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
$(FOAM_FOAMUT)/tests/testDriver.C

smartSimFOTest.C

EXE = ./testDriver
17 changes: 17 additions & 0 deletions 2023-01/smartsim/smartsim_function_object/tests/Make/options
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
EXE_INC = -std=c++2a \
-Wno-old-style-cast \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(SMARTREDIS_INCLUDE) \
-I$(FOAM_FOAMUT)/smartSimFunctionObject/lnInclude \
-I$(FOAM_USER_LIBBIN)/catch2/include \
-I$(LIB_SRC)/Pstream/lnInclude

EXE_LIBS = \
-lfiniteVolume \
-lmeshTools \
-L$(FOAM_USER_LIBBIN) -L$(FOAM_LIBBIN)/$(FOAM_MPI) \
-L$(FOAM_USER_LIBBIN)/catch2/lib -l:libCatch2.a \
-lPstream \
-L$(SMARTREDIS_LIB) -lhiredis -lredis++ \
-lsmartredis -lsmartSimFunctionObject
26 changes: 26 additions & 0 deletions 2023-01/smartsim/smartsim_function_object/tests/smartSimFOTest.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "IOobject.H"
#include "PstreamReduceOps.H"
#include "catch2/catch_all.hpp"
#include "catch2/catch_test_macros.hpp"
#include "fvCFD.H"
#include "fvMesh.H"

#include <csetjmp>
#include <csignal>
#include <cstdlib>
#include <functional>

using namespace Foam;
extern Time* timePtr;
extern argList* argsPtr;

TEST_CASE("Shared SmartRedis client", "[cavity][serial][parallel]")
{
dictionary dict;
dict.set("type", "smartSimFunctionObject");
dict.set("fieldNames", wordList());
dict.set("fieldDimensions", labelList());
functionObjects::smartSimFunctionObject fo1("smartSimFo1", *timePtr, dict);
functionObjects::smartSimFunctionObject fo2("smartSimFo2", *timePtr, dict);
REQUIRE(&fo1.redisDB == &fo2.redisDB);
}
15 changes: 0 additions & 15 deletions 2023-01/smartsim/smartsim_mesh_motion/configure-smartredis.sh

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ EXE_INC = \
-I$(LIB_SRC)/dynamicMesh/lnInclude \
-I$(LIB_SRC)/functionObjects/forces/lnInclude \
-I$(LIB_SRC)/fvMotionSolver/lnInclude \
-I$(FOAM_SMARTREDIS_INCLUDE) \
-I$(FOAM_SMARTREDIS_DEP_INCLUDE)
-I$(SMARTREDIS_INCLUDE)

LIB_LIBS = \
-lfiniteVolume \
Expand All @@ -19,7 +18,7 @@ LIB_LIBS = \
-lmeshTools \
-ldynamicMesh \
-lfvMotionSolvers \
-L$(FOAM_SMARTREDIS_LIB) -lhiredis -lredis++ \
-L$(SMARTREDIS_LIB) -lhiredis -lredis++ \
-lsmartredis

/* -lforces include in controlDict if needed */

0 comments on commit 0ce4ac2

Please sign in to comment.