Skip to content

Commit

Permalink
Merge pull request #22 from pyroteus/21_hook_up_actions
Browse files Browse the repository at this point in the history
Hook up GitHub Actions
  • Loading branch information
jwallwork23 authored Jan 13, 2023
2 parents 624c26c + 326e5f7 commit 822a72f
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 9 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Build Movement

on:
# Push to main or PR
push:
branches:
- main
pull_request:

jobs:
build:
name: "Build Movement"
# The type of runner that the job will run on
runs-on: ubuntu-latest
# The docker container to use.
container:
image: firedrakeproject/firedrake-vanilla:latest
options: --user root
steps:
- uses: actions/checkout@v2
- name: Cleanup
if: ${{ always() }}
run: |
cd ..
rm -rf build
- name: Setup python
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install
run: |
. /home/firedrake/firedrake/bin/activate
python -m pip install -r requirements.txt
python -m pip install -e .
- name: Test
run: |
. /home/firedrake/firedrake/bin/activate
python $(which firedrake-clean)
python -m pytest -n 3 -v test
- name: Lint
if: ${{ always() }}
run: |
. /home/firedrake/firedrake/bin/activate
make lint
24 changes: 24 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
all: install

.PHONY: test

install:
@echo "Installing dependencies..."
@python3 -m pip install -r requirements.txt
@echo "Done."
@echo "Installing Movement..."
@python3 -m pip install -e .
@echo "Done."

lint:
@echo "Checking lint..."
@flake8 --ignore=E501,E226,E402,E731,E741,F403,F405,F999,N803,N806,W503
@echo "PASS"

test: lint
@echo "Running test suite..."
@pytest -v test
@echo "PASS"

tree:
@tree -d .
6 changes: 3 additions & 3 deletions movement/monge_ampere.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,11 +335,11 @@ def move(self):
# Update monitor function
self.monitor.interpolate(self.monitor_function(self.mesh))
firedrake.assemble(self.L_P0, tensor=self.volume)
self.volume.assign(self.volume*self.original_volume**(-1))
self.volume.interpolate(self.volume / self.original_volume)
self.mesh.coordinates.assign(self.xi)

# Evaluate normalisation coefficient
self.theta.assign(firedrake.assemble(self.theta_form)*self.total_volume**(-1))
self.theta.assign(firedrake.assemble(self.theta_form) / self.total_volume)

# Check convergence criteria
minmax, residual, equi = self.diagnostics
Expand Down Expand Up @@ -470,7 +470,7 @@ def monitor(snes, i, rnorm):
update_monitor(cursol)
self.mesh.coordinates.assign(self.x)
firedrake.assemble(self.L_P0, tensor=self.volume)
self.volume.assign(self.volume/self.original_volume)
self.volume.interpolate(self.volume/self.original_volume)
self.mesh.coordinates.assign(self.xi)
minmax, residual, equi = self.diagnostics
PETSc.Sys.Print(f"{i:4d}"
Expand Down
Empty file added requirements.txt
Empty file.
13 changes: 8 additions & 5 deletions test/test_smoothing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from firedrake import *
from movement import *
import numpy as np
import os
import pytest


Expand All @@ -26,7 +28,7 @@ def test_forced(method, num_timesteps, plot=False, test=True):
T = 1.0 # Forcing period

# Construct mesh and mover
mesh = firedrake.SquareMesh(n, n, 2)
mesh = SquareMesh(n, n, 2)
V = mesh.coordinates.function_space()
coords = mesh.coordinates.dat.data.copy()
if method == 'laplacian':
Expand All @@ -36,7 +38,7 @@ def update_forcings(t):
"""
Sinusoidal forcing on the top boundary.
"""
for i in firedrake.DirichletBC(V, 0, 4).nodes:
for i in DirichletBC(V, 0, 4).nodes:
mover.f.dat.data[i][1] += A*np.sin(2*np.pi*t/T)*np.sin(np.pi*coords[i][0])

# Move the mesh
Expand All @@ -51,15 +53,16 @@ def update_forcings(t):
import matplotlib.pyplot as plt

fig, axes = plt.subplots()
firedrake.triplot(mover.mesh, axes=axes)
triplot(mover.mesh, axes=axes)
axes.axis(False)
plt.tight_layout()
plt.savefig(f"plots/mesh_{method}.png")

# Check as expected
if test:
expected = np.load("data/forced_mesh_laplacian.npy")
assert np.allclose(new_coords, expected)
pwd = os.path.dirname(__file__)
fname = os.path.join(pwd, "data", "forced_mesh_laplacian.npy")
assert np.allclose(new_coords, np.load(fname))
return mover


Expand Down
5 changes: 4 additions & 1 deletion test/test_spring.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import firedrake
from movement import SpringMover
import numpy as np
import os
import pytest


Expand Down Expand Up @@ -96,7 +97,9 @@ def update_forcings(t):

# Check as expected
if test:
expected = coords if np.isclose(time, 0.0) else np.load(f"data/forced_mesh_lineal_{it}.npy")
pwd = os.path.dirname(__file__)
fname = os.path.join(pwd, "data", f"forced_mesh_lineal_{it}.npy")
expected = coords if np.isclose(time, 0.0) else np.load(fname)
assert np.allclose(new_coords, expected)
return mover

Expand Down

0 comments on commit 822a72f

Please sign in to comment.