Skip to content

Commit

Permalink
Merge pull request festim-dev#764 from RemDelaporteMathurin/update-do…
Browse files Browse the repository at this point in the history
…lfinx-0.8

Update dolfinx 0.8
  • Loading branch information
RemDelaporteMathurin authored Aug 20, 2024
2 parents 8ebaedd + 4249ef7 commit 02a374f
Show file tree
Hide file tree
Showing 15 changed files with 51 additions and 56 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci_conda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ jobs:
with:
activate-environment: myenv
miniforge-version: latest
use-mamba: true
# use-mamba: true
channels: conda-forge

- name: Create Conda environment
shell: bash -l {0}
run: |
mamba install -c conda-forge fenics-dolfinx=0.7.2
conda install -c conda-forge fenics-dolfinx=0.8.0
- name: Install local package and dependencies
shell: bash -l {0}
Expand Down
9 changes: 6 additions & 3 deletions .github/workflows/ci_docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ on: [pull_request, push]

jobs:
run-tests:
runs-on: ubuntu-latest
container: dolfinx/dolfinx:v0.7.2
steps:
runs-on: ubuntu-latest
strategy:
matrix:
container_version: [v0.8.0, nightly]
container: dolfinx/dolfinx:${{ matrix.container_version }}
steps:
- name: Checkout code
uses: actions/checkout@v2

Expand Down
4 changes: 2 additions & 2 deletions festim/boundary_conditions/dirichlet_bc.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def temperature_dependent(self):
return False

def create_value(
self, mesh, function_space: fem.FunctionSpaceBase, temperature, t: fem.Constant
self, mesh, function_space: fem.FunctionSpace, temperature, t: fem.Constant
):
"""Creates the value of the boundary condition as a fenics object and sets it to
self.value_fenics.
Expand All @@ -138,7 +138,7 @@ def create_value(
Args:
mesh (dolfinx.mesh.Mesh) : the mesh
function_space (dolfinx.fem.FunctionSpaceBase): the function space
function_space (dolfinx.fem.FunctionSpace): the function space
temperature (float): the temperature
t (dolfinx.fem.Constant): the time
"""
Expand Down
12 changes: 4 additions & 8 deletions test/system_tests/test_1_mobile_1_trap.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ def v_exact(mod):
trapped_analytical_ufl = v_exact(ufl)
trapped_analytical_np = v_exact(np)

elements = ufl.FiniteElement("P", test_mesh_1d.mesh.ufl_cell(), 1)
V = fem.FunctionSpace(test_mesh_1d.mesh, elements)
V = fem.functionspace(test_mesh_1d.mesh, ("Lagrange", 1))
T = fem.Function(V)
f = fem.Function(V)
g = fem.Function(V)
Expand Down Expand Up @@ -132,8 +131,7 @@ def u_exact_alt(mod):
H_analytical_ufl = u_exact(ufl)
H_analytical_np = u_exact_alt(np)

elements = ufl.FiniteElement("P", test_mesh_1d.mesh.ufl_cell(), 1)
V = fem.FunctionSpace(test_mesh_1d.mesh, elements)
V = fem.functionspace(test_mesh_1d.mesh, ("Lagrange", 1))
T = fem.Function(V)

D_0 = 1
Expand Down Expand Up @@ -197,8 +195,7 @@ def v_exact(mod):
trapped_analytical_ufl = v_exact(ufl)
trapped_analytical_np = v_exact(np)

elements = ufl.FiniteElement("P", test_mesh_3d.ufl_cell(), 1)
V = fem.FunctionSpace(test_mesh_3d, elements)
V = fem.functionspace(test_mesh_3d, ("Lagrange", 1))
T = fem.Function(V)
f = fem.Function(V)
g = fem.Function(V)
Expand Down Expand Up @@ -311,8 +308,7 @@ def v_exact(mod):
trapped_analytical_ufl = v_exact(ufl)
trapped_analytical_np = v_exact(np)

elements = ufl.FiniteElement("P", test_mesh_2d.ufl_cell(), 1)
V = fem.FunctionSpace(test_mesh_2d, elements)
V = fem.functionspace(test_mesh_2d, ("Lagrange", 1))
T = fem.Function(V)
f = fem.Function(V)
g = fem.Function(V)
Expand Down
12 changes: 4 additions & 8 deletions test/system_tests/test_1_mobile_species.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ def u_exact(mod):
H_analytical_ufl = u_exact(ufl)
H_analytical_np = u_exact(np)

elements = ufl.FiniteElement("CG", test_mesh_1d.mesh.ufl_cell(), 1)
V = fem.FunctionSpace(test_mesh_1d.mesh, elements)
V = fem.functionspace(test_mesh_1d.mesh, ("Lagrange", 1))
T = fem.Function(V)

D_0 = 1
Expand Down Expand Up @@ -86,8 +85,7 @@ def u_exact_alt(mod):
H_analytical_ufl = u_exact(ufl)
H_analytical_np = u_exact_alt(np)

elements = ufl.FiniteElement("P", test_mesh_1d.mesh.ufl_cell(), 1)
V = fem.FunctionSpace(test_mesh_1d.mesh, elements)
V = fem.functionspace(test_mesh_1d.mesh, ("Lagrange", 1))
T = fem.Function(V)

D_0 = 1
Expand Down Expand Up @@ -146,8 +144,7 @@ def u_exact(mod):
H_analytical_ufl = u_exact(ufl)
H_analytical_np = u_exact(np)

elements = ufl.FiniteElement("CG", test_mesh_2d.ufl_cell(), 1)
V = fem.FunctionSpace(test_mesh_2d, elements)
V = fem.functionspace(test_mesh_2d, ("Lagrange", 1))
T = fem.Function(V)

D_0 = 1
Expand Down Expand Up @@ -212,8 +209,7 @@ def u_exact(mod):
H_analytical_ufl = u_exact(ufl)
H_analytical_np = u_exact(np)

elements = ufl.FiniteElement("CG", test_mesh_3d.ufl_cell(), 1)
V = fem.FunctionSpace(test_mesh_3d, elements)
V = fem.functionspace(test_mesh_3d, ("Lagrange", 1))
T = fem.Function(V)

D_0 = 1
Expand Down
7 changes: 1 addition & 6 deletions test/system_tests/test_fluxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ def test_flux_bc_1_mobile_MMS_steady_state():

u_exact = lambda x: 1 + 2 * x[0] ** 2

elements = ufl.FiniteElement("CG", test_mesh_1d.mesh.ufl_cell(), 1)
V = fem.FunctionSpace(test_mesh_1d.mesh, elements)
V = fem.functionspace(test_mesh_1d.mesh, ("Lagrange", 1))
T = fem.Function(V)

D_0 = 1
Expand Down Expand Up @@ -65,10 +64,6 @@ def test_flux_bc_heat_transfer_steady_state():

u_exact = lambda x: 1 + 2 * x[0] ** 2

elements = ufl.FiniteElement("CG", test_mesh_1d.mesh.ufl_cell(), 1)
V = fem.FunctionSpace(test_mesh_1d.mesh, elements)
T = fem.Function(V)

thermal_cond = 2.3

my_model = F.HeatTransferProblem()
Expand Down
3 changes: 1 addition & 2 deletions test/system_tests/test_heat_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ def u_exact(mod):
T_analytical_ufl = u_exact(ufl)
T_analytical_np = u_exact(np)

elements = ufl.FiniteElement("CG", test_mesh_1d.mesh.ufl_cell(), 1)
V = fem.FunctionSpace(test_mesh_1d.mesh, elements)
V = fem.functionspace(test_mesh_1d.mesh, ("Lagrange", 1))
T_solution = fem.Function(V)
T_solution.interpolate(lambda x: 1 + np.sin(2 * np.pi * x[0]))

Expand Down
6 changes: 3 additions & 3 deletions test/system_tests/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

def error_L2(u_computed, u_exact, degree_raise=3):
# Create higher order function space
degree = u_computed.function_space.ufl_element().degree()
family = u_computed.function_space.ufl_element().family()
degree = u_computed.function_space.ufl_element().degree
family = u_computed.function_space.ufl_element().family_name
mesh = u_computed.function_space.mesh
W = fem.FunctionSpace(mesh, (family, degree + degree_raise))
W = fem.functionspace(mesh, (family, degree + degree_raise))
# Interpolate approximate solution
u_W = fem.Function(W)
u_W.interpolate(u_computed)
Expand Down
24 changes: 12 additions & 12 deletions test/test_dirichlet_bc.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def test_callable_for_value():
assert isinstance(bc.value_fenics, fem.Function)

# check the initial value of the boundary condition
assert bc.value_fenics.vector.array[-1] == float(
assert bc.value_fenics.x.petsc_vec.array[-1] == float(
value(x=np.array([subdomain.x]), t=0.0)
)

Expand All @@ -85,7 +85,7 @@ def test_callable_for_value():
t.value = i
bc.update(float(t))
expected_value = float(value(x=np.array([subdomain.x]), t=float(t)))
computed_value = bc.value_fenics.vector.array[-1]
computed_value = bc.value_fenics.x.petsc_vec.array[-1]
assert np.isclose(computed_value, expected_value)


Expand Down Expand Up @@ -115,7 +115,7 @@ def test_value_callable_x_t_T():

# check the initial value of the boundary condition
assert np.isclose(
bc.value_fenics.vector.array[-1],
bc.value_fenics.x.petsc_vec.array[-1],
float(value(x=np.array([subdomain.x]), t=float(t), T=float(T))),
)

Expand All @@ -126,7 +126,7 @@ def test_value_callable_x_t_T():
bc.update(float(t))

expected_value = float(value(x=np.array([subdomain.x]), t=float(t), T=float(T)))
computed_value = bc.value_fenics.vector.array[-1]
computed_value = bc.value_fenics.x.petsc_vec.array[-1]
assert np.isclose(computed_value, expected_value)


Expand Down Expand Up @@ -203,7 +203,7 @@ def test_callable_x_only():

# check the initial value of the boundary condition
assert np.isclose(
bc.value_fenics.vector.array[-1],
bc.value_fenics.x.petsc_vec.array[-1],
float(value(x=np.array([subdomain.x]))),
)

Expand All @@ -212,7 +212,7 @@ def test_callable_x_only():
t.value = i
bc.update(float(t))
expected_value = float(value(x=np.array([subdomain.x])))
computed_value = bc.value_fenics.vector.array[-1]
computed_value = bc.value_fenics.x.petsc_vec.array[-1]
assert np.isclose(computed_value, expected_value)


Expand Down Expand Up @@ -265,13 +265,13 @@ def test_integration_with_HTransportProblem(value):
arguments = value.__code__.co_varnames
if "x" in arguments and "t" in arguments and "T" in arguments:
expected_value = value(x=np.array([subdomain.x]), t=2.0, T=550.0)
computed_value = my_bc.value_fenics.vector.array[-1]
computed_value = my_bc.value_fenics.x.petsc_vec.array[-1]
elif "x" in arguments and "t" in arguments:
expected_value = value(x=np.array([subdomain.x]), t=2.0)
computed_value = my_bc.value_fenics.vector.array[-1]
computed_value = my_bc.value_fenics.x.petsc_vec.array[-1]
elif "x" in arguments:
expected_value = value(x=np.array([subdomain.x]))
computed_value = my_bc.value_fenics.vector.array[-1]
computed_value = my_bc.value_fenics.x.petsc_vec.array[-1]
elif "t" in arguments:
expected_value = value(t=2.0)
computed_value = float(my_bc.value_fenics)
Expand Down Expand Up @@ -387,13 +387,13 @@ def test_integration_with_a_multispecies_HTransportProblem(value_A, value_B):
arguments = value_B.__code__.co_varnames
if "x" in arguments and "t" in arguments and "T" in arguments:
expected_value = value_B(x=np.array([subdomain_B.x]), t=2.0, T=550.0)
computed_value = my_bc_B.value_fenics.vector.array[-1]
computed_value = my_bc_B.value_fenics.x.petsc_vec.array[-1]
elif "x" in arguments and "t" in arguments:
expected_value = value_B(x=np.array([subdomain_B.x]), t=2.0)
computed_value = my_bc_B.value_fenics.vector.array[-1]
computed_value = my_bc_B.value_fenics.x.petsc_vec.array[-1]
elif "x" in arguments:
expected_value = value_B(x=np.array([subdomain_B.x]))
computed_value = my_bc_B.value_fenics.vector.array[-1]
computed_value = my_bc_B.value_fenics.x.petsc_vec.array[-1]
elif "t" in arguments:
expected_value = value_B(t=2.0)
computed_value = float(my_bc_B.value_fenics)
Expand Down
2 changes: 1 addition & 1 deletion test/test_h_transport_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ def test_create_initial_conditions_expr_fenics(input_value, expected_value):
my_model.initialise()

assert np.isclose(
my_model.species[0].prev_solution.vector.array[-1],
my_model.species[0].prev_solution.x.petsc_vec.array[-1],
expected_value,
)

Expand Down
9 changes: 6 additions & 3 deletions test/test_heat_transfer_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ def source_from_exact_solution(

def error_L2(u_computed, u_exact, degree_raise=3):
# Create higher order function space
degree = u_computed.function_space.ufl_element().degree()
family = u_computed.function_space.ufl_element().family()
degree = u_computed.function_space.ufl_element().degree
family = u_computed.function_space.ufl_element().family_name
mesh = u_computed.function_space.mesh
W = fem.FunctionSpace(mesh, (family, degree + degree_raise))
W = fem.functionspace(mesh, (family, degree + degree_raise))
# Interpolate approximate solution
u_W = fem.Function(W)
u_W.interpolate(u_computed)
Expand Down Expand Up @@ -388,6 +388,9 @@ def test_meshtags_from_xdmf(tmp_path, mesh):
facet_tag = np.full(len(facet_indices[i]), idx + 1, dtype=np.int32)
facet_tags.append(facet_tag)

facet_tags = np.array(facet_tags).flatten()
facet_indices = np.array(facet_indices).flatten()

facet_meshtags = dolfinx.mesh.meshtags(mesh, fdim, facet_indices, facet_tags)

# create volume meshtags
Expand Down
4 changes: 2 additions & 2 deletions test/test_initial_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def test_warning_raised_when_giving_time_as_arg_initial_temperature():
"""Test that a warning is raised if the value is given with t in its arguments"""

# give function to species
V = fem.FunctionSpace(test_mesh.mesh, ("CG", 1))
V = fem.functionspace(test_mesh.mesh, ("Lagrange", 1))
my_species = F.Species("test")
my_species.prev_solution = fem.Function(V)

Expand Down Expand Up @@ -107,7 +107,7 @@ def test_create_value_fenics_initial_temperature(input_value, expected_type):
# BUILD

# give function to species
V = fem.FunctionSpace(test_mesh.mesh, ("CG", 1))
V = fem.functionspace(test_mesh.mesh, ("Lagrange", 1))
c = fem.Function(V)

my_species = F.Species("test")
Expand Down
3 changes: 3 additions & 0 deletions test/test_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ def test_meshtags_from_xdmf(tmp_path, mesh):
facet_tag = np.full(len(facet_indices[i]), idx + 1, dtype=np.int32)
facet_tags.append(facet_tag)

facet_tags = np.array(facet_tags).flatten()
facet_indices = np.array(facet_indices).flatten()

facet_meshtags = fenics_mesh.meshtags(mesh, fdim, facet_indices, facet_tags)

# create volume meshtags
Expand Down
6 changes: 3 additions & 3 deletions test/test_surface_quantity.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ def test_surface_flux_export_compute():
facet_indices = np.array(
dummy_surface.locate_boundary_facet_indices(my_mesh.mesh),
dtype=np.int32,
)
).flatten()
tags_facets = np.array(
[1],
dtype=np.int32,
)
).flatten()
facet_meshtags = meshtags(my_mesh.mesh, 0, facet_indices, tags_facets)
ds = ufl.Measure("ds", domain=my_mesh.mesh, subdomain_data=facet_meshtags)

# give function to species
V = fem.functionspace(my_mesh.mesh, ("CG", 1))
V = fem.functionspace(my_mesh.mesh, ("Lagrange", 1))
c = fem.Function(V)
c.interpolate(lambda x: 2 * x[0] ** 2 + 1)

Expand Down
2 changes: 1 addition & 1 deletion test/test_total_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_total_volume_export_compute():
dx = ufl.Measure("dx", domain=my_mesh.mesh, subdomain_data=cell_meshtags)

# give function to species
V = fem.functionspace(my_mesh.mesh, ("CG", 1))
V = fem.functionspace(my_mesh.mesh, ("Lagrange", 1))
c = fem.Function(V)
c.interpolate(lambda x: 2 * x[0] ** 2 + 1)

Expand Down

0 comments on commit 02a374f

Please sign in to comment.