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
31 changes: 27 additions & 4 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,56 @@ on:
pull_request:
branches:
- main
- candidate-v2.0.0
concurrency:
group: ${ {github.event_name }}-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{github.event_name == 'pull_request'}}
jobs:
CI:
defaults:
run:
shell: bash -ileo pipefail {0}
shell: bash {0}
strategy:
matrix:
cxx: ['g++']
cmake_build_type: ['Release']

runs-on: ubuntu-latest
container:
image: docker.io/openfoam/openfoam10-paraview510
image: microfluidica/openfoam:13
options: --user root
steps:
- name: Checkout AdditiveFOAM
uses: actions/checkout@v2
- name: Build AdditiveFOAM
run: |
. /opt/openfoam10/etc/bashrc
. /opt/openfoam13/etc/bashrc || true
test -n "$WM_PROJECT_DIR"
./Allwmake
- name: Install GoogleTest
run: |
apt-get update
apt-get install -y --no-install-recommends cmake libgtest-dev
if ! find /usr/lib /usr/local/lib -name 'libgtest.a' -o -name 'libgtest.so' | grep -q .; then
cmake -S /usr/src/googletest -B /tmp/googletest-build
cmake --build /tmp/googletest-build -j2
cp /tmp/googletest-build/lib/libgtest*.a /usr/local/lib/
fi
test -f /usr/include/gtest/gtest.h
find /usr/lib /usr/local/lib -name 'libgtest.a' -o -name 'libgtest.so' | grep -q .
- name: Build native tests
run: |
. /opt/openfoam13/etc/bashrc || true
test -n "$WM_PROJECT_DIR"
./tests/Allwmake
- name: Run native tests
run: |
. /opt/openfoam13/etc/bashrc || true
test -n "$WM_PROJECT_DIR"
./tests/run
- name: Test AdditiveFOAM
run: |
. /opt/openfoam10/etc/bashrc
. /opt/openfoam13/etc/bashrc || true
cp -r tutorials/AMB2018-02-B userCase
cd userCase
# FIXME: use built-in "additiveFoam" smaller case when created
Expand Down
5 changes: 5 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@ maintainers.

Your pull request must work with all current AdditiveFOAM tutorial examples
and be reviewed by at least one AdditiveFOAM developer.

For local verification, build the code with `./Allwmake`, build the native
test harness with `./tests/Allwmake`, and run it with `./tests/run`. The test
workflow and instructions for adding new native tests are documented in
[TESTING.md](TESTING.md).
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

The documentation for `AdditiveFOAM` is hosted on [GitHub Pages](https://ornl.github.io/AdditiveFOAM/).

For local test commands, GoogleTest prerequisites, and guidance on adding native C++ tests, see [TESTING.md](TESTING.md).

### Repository Features
| Link | Description |
|-----------------------------------------------------------|------------------------------------------|
Expand Down
71 changes: 71 additions & 0 deletions TESTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Testing

AdditiveFOAM has two test layers:

- Native C++ unit-style tests under [`tests/`](tests), built with `wmake`, linked against the existing AdditiveFOAM/OpenFOAM libraries, and driven by GoogleTest.
- The tutorial smoke run in GitHub Actions, which checks end-to-end integration.

## Prerequisites

- An OpenFOAM-13 environment must be sourced before building or running tests.
- AdditiveFOAM must be built first so the native tests can link against `libmovingBeamModels`.
- GoogleTest must be installed outside the repository. `./tests/Allwmake` auto-detects standard install locations and also honors `GTEST_ROOT`, `GTEST_INCLUDE_DIR`, and `GTEST_LIB_DIR`.

## Install GoogleTest

On Debian/Ubuntu systems:

```bash
sudo apt-get update
sudo apt-get install -y --no-install-recommends cmake libgtest-dev

if [ ! -f /usr/lib/x86_64-linux-gnu/libgtest.a ] && [ ! -f /usr/local/lib/libgtest.a ]; then
cmake -S /usr/src/googletest -B /tmp/googletest-build
cmake --build /tmp/googletest-build -j2
sudo cp /tmp/googletest-build/lib/libgtest*.a /usr/local/lib/
fi
```

If GoogleTest is installed somewhere else, set `GTEST_ROOT` or both
`GTEST_INCLUDE_DIR` and `GTEST_LIB_DIR` before running `./tests/Allwmake`.

## Build And Run

From the repository root:

```bash
. /path/to/openfoam/etc/bashrc
./Allwmake
./tests/Allwmake
./tests/run
```

If GoogleTest is installed in a non-standard location, export one of these before `./tests/Allwmake`:

```bash
export GTEST_ROOT=/path/to/gtest
# or
export GTEST_INCLUDE_DIR=/path/to/include
export GTEST_LIB_DIR=/path/to/lib
```

`./tests/Allwmake` builds the native test executables without changing the default production build path. `./tests/run` executes the complete native suite.

## Current Coverage

The native suite currently builds four executables:

- `additiveFoamSegmentTests` validates `Foam::segment` default construction and parsing.
- `additiveFoamMovingBeamTests` covers scan-path timing, index selection, interpolation, and timestep adjustment in `Foam::movingBeam`.
- `additiveFoamMovingHeatSourceModelTests` exercises absorption-model and heat-source-model math for the current beam model implementations.
- `additiveFoamUtilityTests` protects `interpolateXY` and the graph utilities used by solver setup and post-processing.

The `movingBeam` and heat-source-model tests use a small file-backed fixture case under [`tests/fixtures/movingHeatSourceCase`](tests/fixtures/movingHeatSourceCase) so the constructors read real OpenFOAM dictionaries and scan-path files.

## Adding A New Native Test

1. Create a new subdirectory under `tests/`.
2. Add a `Make/files` that includes `../shared/testMain.C`, your test source, and an `EXE` target name.
3. Add a `Make/options` file with the required include paths and linked AdditiveFOAM/OpenFOAM libraries.
4. Add the new directory to [`tests/Allwmake`](tests/Allwmake).
5. Add the produced executable to [`tests/run`](tests/run).
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ License
#include "heatSourceModel.H"
#include "labelVector.H"
#include "hexMatcher.H"
#include "treeBoundBox.H"

// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //

Expand Down
6 changes: 3 additions & 3 deletions applications/solvers/additiveFoam/utilities/graph/graph.C
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ namespace Foam
Foam::word Foam::graph::wordify(const Foam::string& sname)
{
string wname = sname;
wname.replace(' ', '_');
wname.replace('(', '_');
wname.replace(')', "");
wname.replaceAll(' ', '_');
wname.replaceAll('(', '_');
wname.replaceAll(')', "");

return word(wname);
}
Expand Down
67 changes: 67 additions & 0 deletions tests/Allwmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/bin/sh
cd "${0%/*}" || exit 1

if [ -z "${WM_PROJECT_DIR:-}" ]; then
echo "Source the OpenFOAM environment before running ./tests/Allwmake" >&2
exit 1
fi

find_gtest_include_dir()
{
for candidate in \
"${GTEST_INCLUDE_DIR:-}" \
"${GTEST_ROOT:-}/include" \
/usr/include \
/usr/local/include
do
if [ -n "$candidate" ] && [ -f "$candidate/gtest/gtest.h" ]; then
printf '%s\n' "$candidate"
return 0
fi
done

return 1
}

find_gtest_lib_dir()
{
for candidate in \
"${GTEST_LIB_DIR:-}" \
"${GTEST_ROOT:-}/lib" \
"${GTEST_ROOT:-}/lib64" \
/usr/lib/x86_64-linux-gnu \
/usr/lib64 \
/usr/lib \
/usr/local/lib64 \
/usr/local/lib
do
if [ -n "$candidate" ] && \
{ [ -f "$candidate/libgtest.a" ] || [ -f "$candidate/libgtest.so" ]; }
then
printf '%s\n' "$candidate"
return 0
fi
done

return 1
}

GTEST_INCLUDE_DIR=$(find_gtest_include_dir) || {
echo "Unable to find GoogleTest headers. Install gtest or set GTEST_ROOT/GTEST_INCLUDE_DIR." >&2
exit 1
}

GTEST_LIB_DIR=$(find_gtest_lib_dir) || {
echo "Unable to find the GoogleTest library. Install gtest or set GTEST_ROOT/GTEST_LIB_DIR." >&2
exit 1
}

export GTEST_INCLUDE_DIR
export GTEST_LIB_DIR

. "$WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments"

wmake $targetType segment
wmake $targetType movingBeam
wmake $targetType movingHeatSourceModels
wmake $targetType utilities
4 changes: 4 additions & 0 deletions tests/fixtures/movingHeatSourceCase/constant/beamPath.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
mode x y z power parameter
1 1 0 0 100 1.5
0 4 0 0 200 2.0
1 4 0 0 50 0.5
Loading
Loading