Skip to content

Commit

Permalink
Merge branch 'master' into cuda-heat-example-w-quaditer
Browse files Browse the repository at this point in the history
  • Loading branch information
Abdelrahman912 committed Nov 4, 2024
2 parents ee1f77c + b56e2c9 commit fb7e1fc
Show file tree
Hide file tree
Showing 101 changed files with 5,690 additions and 5,143 deletions.
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# `pre-commit run --all-files` (https://github.com/Ferrite-FEM/Ferrite.jl/pull/928)
68e1ab15bea4618f76b9ed1d850e2ce33375e266
# Apply Runic.jl formatting (https://github.com/Ferrite-FEM/Ferrite.jl/pull/1096)
c50ce06f2261398ecfe6da4578e50baff88cf563
16 changes: 16 additions & 0 deletions .github/workflows/Check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
env:
# Skip runic-pre-commit since we use runic-action below instead
SKIP: runic

runic:
name: "Runic"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v2
with:
version: '1.11'
- uses: julia-actions/cache@v2
- uses: fredrikekre/runic-action@v1
with:
version: "d9a27b9d6279a103fedc7202258207a7b7afe18c"

explicit-imports:
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/Downstream.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
# - {user: 'Ferrite-FEM', repo: 'FerriteDistributed.jl'} # Requires more efforts to be updated to 1.0
- {user: 'Ferrite-FEM', repo: 'FerriteGmsh.jl'}
- {user: 'Ferrite-FEM', repo: 'FerriteMeshParser.jl'}
- {user: 'Ferrite-FEM', repo: 'FerriteInterfaceElements.jl'}
# - {user: 'Ferrite-FEM', repo: 'FerriteViz.jl'} # Requires release
steps:
- uses: actions/checkout@v4
Expand Down
22 changes: 13 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
- repo: 'https://github.com/pre-commit/pre-commit-hooks'
rev: v5.0.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
- id: check-toml
- id: check-yaml
- id: end-of-file-fixer
- id: mixed-line-ending
- id: trailing-whitespace
- id: check-added-large-files
- id: check-case-conflict
- id: check-toml
- id: check-yaml
- id: end-of-file-fixer
- id: mixed-line-ending
- id: trailing-whitespace
- repo: 'https://github.com/fredrikekre/runic-pre-commit'
rev: v1.0.0
hooks:
- id: runic
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
```
([#1083])

### Other
- Ferrite now uses [Runic.jl](https://github.com/fredrikekre/Runic.jl) for code formatting.
([#1096])

## [v1.0.0] - 2024-09-30

Ferrite version 1.0 is a relatively large release, with a lot of new features, improvements,
Expand Down Expand Up @@ -1027,3 +1031,4 @@ poking into Ferrite internals:
[#1058]: https://github.com/Ferrite-FEM/Ferrite.jl/issues/1058
[#1059]: https://github.com/Ferrite-FEM/Ferrite.jl/issues/1059
[#1083]: https://github.com/Ferrite-FEM/Ferrite.jl/issues/1083
[#1096]: https://github.com/Ferrite-FEM/Ferrite.jl/issues/1096
36 changes: 36 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,38 @@ issues][open-issues].
Remember to always include (when applicable): i) unit tests which exercises the new code,
ii) documentation, iii) a note in the [CHANGELOG.md](CHANGELOG.md) file.

### Code formatting

Ferrite uses [Runic.jl][runic] for code formatting. You can install Runic with the following
command:

```shell
julia --project=@runic -e 'using Pkg; Pkg.add(url = "https://github.com/fredrikekre/Runic.jl")'
```

and you can then run the formatter from the root of the repository with:

```shell
julia --project=@runic -e 'using Runic; exit(Runic.main(ARGS))' -- --inplace .
```

Refer to the Runic.jl [README][runic-readme] for more details (such as editor integration).


### pre-commit hooks

Ferrite uses [pre-commit] to run various checks (including Runic formatting). After
installing pre-commit (refer to the [pre-commit installation
instructions][pre-commit-install]) run the following from the root of the repository to
configure pre-commit to run before each commit:

```shell
pre-commit install
```

Note that this currently requires Runic.jl to be installed in the shared `@runic`
environment according to the instructions above.


[documenter]: https://juliadocs.github.io/Documenter.jl/
[first-contributions]: https://github.com/firstcontributions/first-contributions
Expand All @@ -80,6 +112,10 @@ ii) documentation, iii) a note in the [CHANGELOG.md](CHANGELOG.md) file.
[new-discussion]: https://github.com/Ferrite-FEM/Ferrite.jl/discussions/new
[new-issue]: https://github.com/Ferrite-FEM/Ferrite.jl/issues/new
[open-issues]: https://github.com/Ferrite-FEM/Ferrite.jl/issues
[pre-commit-install]: https://pre-commit.com/#install
[pre-commit]: https://pre-commit.com/
[runic-readme]: https://github.com/fredrikekre/Runic.jl/blob/master/README.md
[runic]: https://github.com/fredrikekre/Runic.jl
[so-mre]: https://stackoverflow.com/help/minimal-reproducible-example
[tim-doc]: https://youtu.be/ZpH1ry8qqfw
[tim-git]: https://youtu.be/cquJ9kPkwR8
42 changes: 21 additions & 21 deletions benchmark/benchmarks-assembly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,44 @@ SUITE["assembly"] = BenchmarkGroup()
# Permute over common combinations for some commonly required local matrices.
SUITE["assembly"]["common-local"] = BenchmarkGroup()
COMMON_LOCAL_ASSEMBLY = SUITE["assembly"]["common-local"]
for spatial_dim 1:3
ξ_dummy = Vec{spatial_dim}(ntuple(x->0.0, spatial_dim))
COMMON_LOCAL_ASSEMBLY["spatial-dim",spatial_dim] = BenchmarkGroup()
for geo_type FerriteBenchmarkHelper.geo_types_for_spatial_dim(spatial_dim)
COMMON_LOCAL_ASSEMBLY["spatial-dim",spatial_dim][string(geo_type)] = BenchmarkGroup()
for spatial_dim in 1:3
ξ_dummy = Vec{spatial_dim}(ntuple(x -> 0.0, spatial_dim))
COMMON_LOCAL_ASSEMBLY["spatial-dim", spatial_dim] = BenchmarkGroup()
for geo_type in FerriteBenchmarkHelper.geo_types_for_spatial_dim(spatial_dim)
COMMON_LOCAL_ASSEMBLY["spatial-dim", spatial_dim][string(geo_type)] = BenchmarkGroup()

grid = generate_grid(geo_type, tuple(repeat([2], spatial_dim)...));
grid = generate_grid(geo_type, tuple(repeat([2], spatial_dim)...))
topology = ExclusiveTopology(grid)
ip_geo = Ferrite.geometric_interpolation(geo_type)
ref_type = FerriteBenchmarkHelper.getrefshape(geo_type)

# Nodal interpolation tests
for order 1:2, ip_type [Lagrange, Serendipity]
for order in 1:2, ip_type in [Lagrange, Serendipity]
ip_type == Serendipity && (order < 2 || ref_type (RefQuadrilateral, RefHexahedron)) && continue
ip = ip_type{ref_type, order}()
ip_vectorized = ip^spatial_dim

# Skip over elements which are not implemented
!applicable(Ferrite.shape_value, ip, ξ_dummy, 1) && continue

qr = QuadratureRule{ref_type}(2*order-1)
qr = QuadratureRule{ref_type}(2 * order - 1)

# Currently we just benchmark nodal Lagrange bases.
COMMON_LOCAL_ASSEMBLY["spatial-dim",spatial_dim][string(geo_type)][string(ip_type),string(order)] = BenchmarkGroup()
LAGRANGE_SUITE = COMMON_LOCAL_ASSEMBLY["spatial-dim",spatial_dim][string(geo_type)][string(ip_type),string(order)]
COMMON_LOCAL_ASSEMBLY["spatial-dim", spatial_dim][string(geo_type)][string(ip_type), string(order)] = BenchmarkGroup()
LAGRANGE_SUITE = COMMON_LOCAL_ASSEMBLY["spatial-dim", spatial_dim][string(geo_type)][string(ip_type), string(order)]
LAGRANGE_SUITE["fe-values"] = BenchmarkGroup()
LAGRANGE_SUITE["ritz-galerkin"] = BenchmarkGroup()
LAGRANGE_SUITE["petrov-galerkin"] = BenchmarkGroup()

# Note: at the time of writing this PR the ctor makes the heavy lifting and caches important values.
LAGRANGE_SUITE["fe-values"]["scalar"] = @benchmarkable CellValues($qr, $ip, $ip_geo);
LAGRANGE_SUITE["fe-values"]["vector"] = @benchmarkable CellValues($qr, $ip_vectorized, $ip_geo);
LAGRANGE_SUITE["fe-values"]["scalar"] = @benchmarkable CellValues($qr, $ip, $ip_geo)
LAGRANGE_SUITE["fe-values"]["vector"] = @benchmarkable CellValues($qr, $ip_vectorized, $ip_geo)

csv = CellValues(qr, ip, ip_geo);
csv2 = CellValues(qr, ip, ip_geo);
csv = CellValues(qr, ip, ip_geo)
csv2 = CellValues(qr, ip, ip_geo)

cvv = CellValues(qr, ip_vectorized, ip_geo);
cvv2 = CellValues(qr, ip_vectorized, ip_geo);
cvv = CellValues(qr, ip_vectorized, ip_geo)
cvv2 = CellValues(qr, ip_vectorized, ip_geo)

# Scalar shape φ and test ψ: ∫ φ ψ
LAGRANGE_SUITE["ritz-galerkin"]["mass"] = @benchmarkable FerriteAssemblyHelper._generalized_ritz_galerkin_assemble_local_matrix($grid, $csv, shape_value, shape_value, *)
Expand All @@ -61,16 +61,16 @@ for spatial_dim ∈ 1:3
LAGRANGE_SUITE["petrov-galerkin"]["pressure-velocity"] = @benchmarkable FerriteAssemblyHelper._generalized_petrov_galerkin_assemble_local_matrix($grid, $cvv, shape_divergence, $csv, shape_value, *)

if spatial_dim > 1
qr_facet = FacetQuadratureRule{ref_type}(2*order-1)
fsv = FacetValues(qr_facet, ip, ip_geo);
fsv2 = FacetValues(qr_facet, ip, ip_geo);
qr_facet = FacetQuadratureRule{ref_type}(2 * order - 1)
fsv = FacetValues(qr_facet, ip, ip_geo)
fsv2 = FacetValues(qr_facet, ip, ip_geo)

LAGRANGE_SUITE["ritz-galerkin"]["face-flux"] = @benchmarkable FerriteAssemblyHelper._generalized_ritz_galerkin_assemble_local_matrix($grid, $fsv, shape_gradient, shape_value, *)
LAGRANGE_SUITE["petrov-galerkin"]["face-flux"] = @benchmarkable FerriteAssemblyHelper._generalized_petrov_galerkin_assemble_local_matrix($grid, $fsv, shape_gradient, $fsv2, shape_value, *)

ip = DiscontinuousLagrange{ref_type, order}()
isv = InterfaceValues(qr_facet, ip, ip_geo);
isv2 = InterfaceValues(qr_facet, ip, ip_geo);
isv = InterfaceValues(qr_facet, ip, ip_geo)
isv2 = InterfaceValues(qr_facet, ip, ip_geo)
dh = DofHandler(grid)
add!(dh, :u, ip)
close!(dh)
Expand Down
30 changes: 15 additions & 15 deletions benchmark/benchmarks-boundary-conditions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,37 @@ SUITE["boundary-conditions"] = BenchmarkGroup()
SUITE["boundary-conditions"]["Dirichlet"] = BenchmarkGroup()
DIRICHLET_SUITE = SUITE["boundary-conditions"]["Dirichlet"]
# span artificial scope...
for spatial_dim [2]
for spatial_dim in [2]
# Benchmark application on global system
DIRICHLET_SUITE["global"] = BenchmarkGroup()

geo_type = Quadrilateral
grid = generate_grid(geo_type, ntuple(x->2, spatial_dim));
grid = generate_grid(geo_type, ntuple(x -> 2, spatial_dim))
ref_type = FerriteBenchmarkHelper.getrefshape(geo_type)
ip_geo = Ferrite.geometric_interpolation(geo_type)
order = 2

# assemble a mass matrix to apply BCs on (because its cheap)
ip = Lagrange{ref_type, order}()
qr = QuadratureRule{ref_type}(2*order-1)
cellvalues = CellValues(qr, ip, ip_geo);
qr = QuadratureRule{ref_type}(2 * order - 1)
cellvalues = CellValues(qr, ip, ip_geo)
dh = DofHandler(grid)
push!(dh, :u, 1, ip)
close!(dh);
close!(dh)

ch = ConstraintHandler(dh);
∂Ω = union(getfacetset.((grid, ), ["left"])...);
ch = ConstraintHandler(dh)
∂Ω = union(getfacetset.((grid,), ["left"])...)
dbc = Dirichlet(:u, ∂Ω, (x, t) -> 0)
add!(ch, dbc);
close!(ch);
add!(ch, dbc)
close!(ch)

# Non-symmetric application
M, f = FerriteAssemblyHelper._assemble_mass(dh, cellvalues, false);
DIRICHLET_SUITE["global"]["apply!(M,f)"] = @benchmarkable apply!($M, $f, $ch);
M, f = FerriteAssemblyHelper._assemble_mass(dh, cellvalues, false)
DIRICHLET_SUITE["global"]["apply!(M,f)"] = @benchmarkable apply!($M, $f, $ch)
# Symmetric application
M, f = FerriteAssemblyHelper._assemble_mass(dh, cellvalues, true);
DIRICHLET_SUITE["global"]["apply!(M_sym,f)"] = @benchmarkable apply!($M, $f, $ch);
M, f = FerriteAssemblyHelper._assemble_mass(dh, cellvalues, true)
DIRICHLET_SUITE["global"]["apply!(M_sym,f)"] = @benchmarkable apply!($M, $f, $ch)

DIRICHLET_SUITE["global"]["apply!(f)"] = @benchmarkable apply!($f, $ch);
DIRICHLET_SUITE["global"]["apply_zero!(f)"] = @benchmarkable apply!($f, $ch);
DIRICHLET_SUITE["global"]["apply!(f)"] = @benchmarkable apply!($f, $ch)
DIRICHLET_SUITE["global"]["apply_zero!(f)"] = @benchmarkable apply!($f, $ch)
end
45 changes: 22 additions & 23 deletions benchmark/benchmarks-dofs.jl
Original file line number Diff line number Diff line change
@@ -1,71 +1,70 @@

#----------------------------------------------------------------------#
# Benchmarks around the dof management
#----------------------------------------------------------------------#
SUITE["dof-management"] = BenchmarkGroup()
SUITE["dof-management"]["numbering"] = BenchmarkGroup()
# !!! NOTE close! must wrapped into a custom function, because consecutive calls to close!, since the dofs are already distributed.
NUMBERING_SUITE = SUITE["dof-management"]["numbering"]
for spatial_dim [3]# 1:3
NUMBERING_SUITE["spatial-dim",spatial_dim] = BenchmarkGroup()
for geo_type FerriteBenchmarkHelper.geo_types_for_spatial_dim(spatial_dim)
NUMBERING_SUITE["spatial-dim",spatial_dim][string(geo_type)] = BenchmarkGroup()
for spatial_dim in [3] # 1:3
NUMBERING_SUITE["spatial-dim", spatial_dim] = BenchmarkGroup()
for geo_type in FerriteBenchmarkHelper.geo_types_for_spatial_dim(spatial_dim)
NUMBERING_SUITE["spatial-dim", spatial_dim][string(geo_type)] = BenchmarkGroup()

ref_type = FerriteBenchmarkHelper.getrefshape(geo_type)

for grid_size [2]#[3, 6, 9] #multiple grid sized to estimate computational complexity...
NUMBERING_SUITE["spatial-dim",spatial_dim][string(geo_type)]["grid-size-",grid_size] = BenchmarkGroup()
NUMBERING_SUITE["spatial-dim",spatial_dim][string(geo_type)]["grid-size-",grid_size] = BenchmarkGroup()
for grid_size in [2] #[3, 6, 9] #multiple grid sized to estimate computational complexity...
NUMBERING_SUITE["spatial-dim", spatial_dim][string(geo_type)]["grid-size-", grid_size] = BenchmarkGroup()
NUMBERING_SUITE["spatial-dim", spatial_dim][string(geo_type)]["grid-size-", grid_size] = BenchmarkGroup()

grid = generate_grid(geo_type, ntuple(x->grid_size, spatial_dim));
grid = generate_grid(geo_type, ntuple(x -> grid_size, spatial_dim))

for field_dim [3]#1:3
NUMBERING_SUITE["spatial-dim",spatial_dim][string(geo_type)]["grid-size-",grid_size]["field-dim-", field_dim] = BenchmarkGroup()
NUMBERING_FIELD_DIM_SUITE = NUMBERING_SUITE["spatial-dim",spatial_dim][string(geo_type)]["grid-size-",grid_size]["field-dim-", field_dim]
for field_dim in [3] #1:3
NUMBERING_SUITE["spatial-dim", spatial_dim][string(geo_type)]["grid-size-", grid_size]["field-dim-", field_dim] = BenchmarkGroup()
NUMBERING_FIELD_DIM_SUITE = NUMBERING_SUITE["spatial-dim", spatial_dim][string(geo_type)]["grid-size-", grid_size]["field-dim-", field_dim]
# Lagrange tests
for order 1:2
for order in 1:2
ip = Lagrange{ref_type, order}()

# Skip over elements which are not implemented
ξ_dummy = Vec{spatial_dim}(ntuple(x->0.0, spatial_dim))
ξ_dummy = Vec{spatial_dim}(ntuple(x -> 0.0, spatial_dim))
!applicable(Ferrite.shape_value, ip, ξ_dummy, 1) && continue

NUMBERING_FIELD_DIM_SUITE["Lagrange",order] = BenchmarkGroup()
LAGRANGE_SUITE = NUMBERING_FIELD_DIM_SUITE["Lagrange",order]
order2 = max(order-1, 1)
NUMBERING_FIELD_DIM_SUITE["Lagrange", order] = BenchmarkGroup()
LAGRANGE_SUITE = NUMBERING_FIELD_DIM_SUITE["Lagrange", order]
order2 = max(order - 1, 1)
ip2 = Lagrange{ref_type, order2}()

LAGRANGE_SUITE["DofHandler"] = BenchmarkGroup()

close_helper = function(grid, ip)
dh = DofHandler(grid)
push!(dh, :u, field_dim, ip)
close!(dh)
return close!(dh)
end
LAGRANGE_SUITE["DofHandler"]["one-field"] = @benchmarkable $close_helper($grid, $ip)

close_helper = function(grid, ip, ip2)
dh = DofHandler(grid)
push!(dh, :u, field_dim, ip)
push!(dh, :p, 1, ip2)
close!(dh)
return close!(dh)
end
LAGRANGE_SUITE["DofHandler"]["two-fields"] = @benchmarkable $close_helper($grid, $ip, $ip2)

close_helper = function(grid)
dh = DofHandler(grid)
sdh = SubDofHandler(dh, Set(1:Int(round(getncells(grid)/2))))
sdh = SubDofHandler(dh, Set(1:Int(round(getncells(grid) / 2))))
add!(sdh, :u, ip^field_dim)
close!(dh)
return close!(dh)
end
LAGRANGE_SUITE["DofHandler"]["one-field-subdomain"] = @benchmarkable $close_helper($grid)

close_helper = function(grid)
dh = DofHandler(grid)
sdh = SubDofHandler(dh, Set(1:Int(round(getncells(grid)/2))))
sdh = SubDofHandler(dh, Set(1:Int(round(getncells(grid) / 2))))
add!(sdh, :u, ip^field_dim)
add!(sdh, :p, ip2)
close!(dh)
return close!(dh)
end
LAGRANGE_SUITE["DofHandler"]["two-fields-subdomain"] = @benchmarkable $close_helper($grid)
end
Expand Down
9 changes: 4 additions & 5 deletions benchmark/benchmarks-mesh.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#----------------------------------------------------------------------#
# Benchmarks for mesh functionality within Ferrite
#----------------------------------------------------------------------#
Expand All @@ -10,10 +9,10 @@ SUITE["mesh"]["generator"] = BenchmarkGroup()
# Structured hyperrectangle generators
SUITE["mesh"]["generator"]["hyperrectangle"] = BenchmarkGroup()
HYPERRECTANGLE_GENERATOR = SUITE["mesh"]["generator"]["hyperrectangle"]
for spatial_dim 1:3
HYPERRECTANGLE_GENERATOR["spatial-dim",spatial_dim] = BenchmarkGroup()
for geo_type FerriteBenchmarkHelper.geo_types_for_spatial_dim(spatial_dim)
HYPERRECTANGLE_GENERATOR["spatial-dim",spatial_dim][string(geo_type)] = @benchmarkable generate_grid($geo_type, $(ntuple(x->4, spatial_dim)));
for spatial_dim in 1:3
HYPERRECTANGLE_GENERATOR["spatial-dim", spatial_dim] = BenchmarkGroup()
for geo_type in FerriteBenchmarkHelper.geo_types_for_spatial_dim(spatial_dim)
HYPERRECTANGLE_GENERATOR["spatial-dim", spatial_dim][string(geo_type)] = @benchmarkable generate_grid($geo_type, $(ntuple(x -> 4, spatial_dim)))
end
end

Expand Down
Loading

0 comments on commit fb7e1fc

Please sign in to comment.