Skip to content
Merged
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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "FiniteElementContainers"
uuid = "d08262e4-672f-4e7f-a976-f2cea5767631"
version = "0.13.2"
version = "0.13.3"
authors = ["Craig M. Hamel <cmhamel32@gmail.com> and contributors"]

[deps]
Expand Down
2 changes: 2 additions & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ makedocs(;
"4 Transient Problem" => "tutorials/4_transient_problem.md",
"5 Solid Mechanics" => "tutorials/5_solid_mechanics.md"
],
"AppTools" => "app_tools.md",
"Assemblers" => "assemblers.md",
"Boundary Conditions" => "boundary_conditions.md",
"DofManager" => "dof_manager.md",
"Expressions" => "expressions.md",
"Fields" => "fields.md",
"Formulations" => "formulations.md",
"Function spaces" => "function_spaces.md",
Expand Down
6 changes: 6 additions & 0 deletions docs/src/app_tools.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# AppTools
```@autodocs
Modules = [FiniteElementContainers]
Pages = ["AppTools.jl"]
Order = [:module, :type, :function]
```
28 changes: 28 additions & 0 deletions docs/src/assemblers.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ sort the COO ```(row, col, val)``` triplets so they are ordered by row and then

NOTE: This is one of the most actively developed areas of the package. Please use caution with any method beginning with a "_" as these are internal methods that will change without notice.

## Matrix Diagonal
```@autodocs
Modules = [FiniteElementContainers]
Pages = ["Diagonal.jl"]
Order = [:function]
```

## Matrices
```@autodocs
Modules = [FiniteElementContainers]
Expand Down Expand Up @@ -42,20 +49,41 @@ Pages = ["QuadratureQuantity.jl"]
Order = [:function]
```

## Sources
```@autodocs
Modules = [FiniteElementContainers]
Pages = ["Source.jl"]
Order = [:function]
```

## Vector
```@autodocs
Modules = [FiniteElementContainers]
Pages = ["Vector.jl"]
Order = [:function]
```

## Weakly enforced BCs
```@autodocs
Modules = [FiniteElementContainers]
Pages = ["WeaklyEnforcedBCs.jl"]
Order = [:function]
```

## Abstract Interface
```@autodocs
Modules = [FiniteElementContainers]
Pages = ["Assemblers.jl"]
Order = [:type, :function]
```

## Assembly methods that are safe with Enzyme.jl
```@autodocs
Modules = [FiniteElementContainers]
Pages = ["Enzyme.jl"]
Order = [:type, :function]
```

## SparseMatrixAssembler
```@autodocs
Modules = [FiniteElementContainers]
Expand Down
20 changes: 17 additions & 3 deletions docs/src/boundary_conditions.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ and sideset ```sset_1``` with a zero function as follows.
```@repl
using FiniteElementContainers
bc_func(x, t) = 0.
bc = DirichletBC(:u, bc_func; sideset_name = :sset_1)
bc = DirichletBC("u", bc_func; sideset_name = "sset_1")
```
Internally this is eventually converted in a ```DirichletBCContainer```

Expand All @@ -27,15 +27,15 @@ simple constant function as follows
using FiniteElementContainers
using StaticArrays
bc_func(x, t) = SVector{1, Float64}(1.)
bc = NeumannBC(:u, :sset_1, bc_func)
bc = NeumannBC("u", bc_func, "sset_1")
```
Note that in comparison to the dirichlet bc example above, the function in this case returns a ```SVector``` of size 1. This will hold for any variable ```u``` that has a single dof. For vector variables, e.g. a traction vector in continuum mechanics, would need something like
```@repl
using FiniteElementContainers
using StaticArrays
ND = 2
bc_func(x, t) = SVector{ND, Float64}(1.)
bc = NeumannBC(:u, :sset_1, bc_func)
bc = NeumannBC("u", bc_func, "sset_1")
```
where ```ND``` is the number of dimensions.

Expand All @@ -57,6 +57,20 @@ Pages = ["PeriodicBCs.jl"]
Order = [:type, :function]
```

# RobinBC
```@autodocs
Modules = [FiniteElementContainers]
Pages = ["RobinBCs.jl"]
Order = [:type, :function]
```

# Source
```@autodocs
Modules = [FiniteElementContainers]
Pages = ["Sources.jl"]
Order = [:type, :function]
```

## Boundary Condition Implementation Details
```@autodocs
Modules = [FiniteElementContainers]
Expand Down
6 changes: 3 additions & 3 deletions docs/src/dof_manager.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ The ```DofManager``` is a struct that keeps track of which dofs are unknown or c
A ```DofManager``` can be created as follows. First we must create functions for our variables of interest from their associated function spaces.

```@repl dof
using Exodus, FiniteElementContainers
using FiniteElementContainers
mesh = UnstructuredMesh("../../test/poisson/poisson.g")
V = FunctionSpace(mesh, H1Field, Lagrange)
u = VectorFunction(V, :u)
t = ScalarFunction(V, :t)
u = VectorFunction(V, "u")
t = ScalarFunction(V, "t")
f = FiniteElementContainers.GeneralFunction(u, t)
```
Now we can supply these variables to the ```DofManager``` which takes varargs as inputs
Expand Down
33 changes: 33 additions & 0 deletions docs/src/expressions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Expressions
This package supports type-stable expression functions that can be parsed from strings at runtime. This enables arbitrary boundary condition support in compiled binaries. This feature heavily leverages the package [DynamicExpressions.jl](https://github.com/SymbolicML/DynamicExpressions.jl)

## ScalarExpressionFunction
```@repl
import FiniteElementContainers.Expressions: ScalarExpressionFunction
using StaticArrays
expr = "5.0 * exp(-2 * t) * cos(2 * pi * t)"
var_names = ["x", "y", "z", "t"]
func = ScalarExpressionFunction{Float64}(expr, var_names)
X = SVector{3, Float64}(1., 2., 3.)
t = 5.0
val = func(X, t)
```

## VectorExpressionFunction
```@repl
import FiniteElementContainers.Expressions: VectorExpressionFunction
using StaticArrays
exprs = ["0", "5.0 * exp(-2 * t) * cos(2 * pi * t)", "0"]
var_names = ["x", "y", "z", "t"]
func = VectorExpressionFunction{3, Float64}(exprs, var_names)
X = SVector{3, Float64}(1., 2., 3.)
t = 5.0
val = func(X, t)
```

# API
```@autodocs
Modules = [FiniteElementContainers.Expressions]
Pages = ["Expressions.jl"]
Order = [:type, :function]
```
53 changes: 3 additions & 50 deletions docs/src/fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,57 +30,10 @@ field[1, :]
```
etc.

## Abstract type
## Fields
The base type for fields is the ```AbstractField``` abstract type.
```@autodocs
Modules = [FiniteElementContainers]
Pages = ["fields/Fields.jl"]
Order = [:type]
```
Any new field added to ```FiniteElementContainers``` should be a subtype of this type.

## Methods for ```AbstractField```
```@autodocs
Modules = [FiniteElementContainers]
Pages = ["fields/Fields.jl"]
Order = [:function]
```

## Implementations
The existing direct subtypes of ```AbstractField``` are the following

### Connectivity
The connectivity type is a simple alias for ```L2ElementField``` defined below
```@autodocs
Modules = [FiniteElementContainers]
Pages = ["fields/Connectivity.jl"]
Order = [:type, :function]
```

### H1 field
```@autodocs
Modules = [FiniteElementContainers]
Pages = ["fields/H1Field.jl"]
Order = [:type, :function]
```

### Hcurl field
```@autodocs
Modules = [FiniteElementContainers]
Pages = ["fields/HcurlField.jl"]
Pages = ["Fields.jl"]
Order = [:type, :function]
```

### Hdiv field
```@autodocs
Modules = [FiniteElementContainers]
Pages = ["fields/HdivField.jl"]
Order = [:type, :function]
```

### L2 field
```@autodocs
Modules = [FiniteElementContainers]
Pages = ["fields/L2Field.jl"]
Order = [:type, :function]
```
```
10 changes: 5 additions & 5 deletions docs/src/formulations.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,14 @@ CurrentModule = FiniteElementContainers

# Formulations
```@docs
AbstractMechanicsFormulation
AbstractElementFormulation
```

# Implementations
```@docs
PlaneStrain
```

```@docs
ScalarFormulation
```

```@docs
ThreeDimensional
```
Expand All @@ -29,4 +25,8 @@ extract_stiffness
extract_stress
modify_field_gradients
num_dimensions
scatter_with_gradients!
scatter_with_gradients_and_gradients!
scatter_with_values!
scatter_with_values_and_values!
```
25 changes: 14 additions & 11 deletions examples/app/input-file.toml
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
[device]
backend = "cpu"

[functions.zero_ic]
type = "scalar expression"
expression = "0.0"
variables = ["x", "y"]

[functions.zero_bc]
type = "scalar expression"
expression = "0.0"
variables = ["x", "y", "t"]

[functions.zero_neumann]
[functions.source_func]
type = "vector expression"
expressions = ["1.0"]
expressions = ["2 * pi^2 * sin(2 * pi * x) * sin(2 * pi * y)"]
variables = ["x", "y", "t"]

[mesh]
file_path = "poisson.g"
file_type = "exodus"

[[initial_conditions]]
function = "zero_ic"
blocks = ["block_1"]
[[boundary_conditions.dirichlet]]
function = "zero_bc"
side_sets = ["sset_1", "sset_2"]
variables = ["u"]

[[boundary_conditions.dirichlet]]
function = "zero_bc"
side_sets = ["sset_1", "sset_2", "sset_3", "sset_4"]
side_sets = ["sset_3", "sset_4"]
variables = ["u"]

[[boundary_conditions.source]]
function = "source_func"
blocks = ["block_1"]
variables = ["u"]

# [linear_solver.krylov]

8 changes: 5 additions & 3 deletions examples/app/src/MyApp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ using TimerOutputs
# include files
include("Physics.jl")

f(X, _) = 2. * π^2 * sin(2π * X[1]) * sin(2π * X[2])
# f(X, _) = 2. * π^2 * sin(2π * X[1]) * sin(2π * X[2])

const N = 1

Expand Down Expand Up @@ -38,10 +38,12 @@ function app_main(ARGS::Vector{String})
asm = SparseMatrixAssembler{SPT, false, false}(dof)

# setup physics and properties
physics = Poisson{typeof(f)}[]
# physics = Poisson{typeof(f)}[]
physics = Laplace[]
props = Vector{Float64}[]
for _ in 1:length(sim.mesh.element_conns)
temp_physics = Poisson(f)
# temp_physics = Poisson(f)
temp_physics = Laplace()
push!(physics, temp_physics)
push!(props, create_properties(temp_physics))
end
Expand Down
22 changes: 22 additions & 0 deletions examples/app/src/Physics.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
struct Laplace <: AbstractPhysics{1, 0, 0}
end

@inline function FiniteElementContainers.residual(
physics::Laplace, interps, x_el, t, dt, u_el, u_el_old, state_old_q, state_new_q, props_el
)
interps = map_interpolants(interps, x_el)
(; X_q, N, ∇N_X, JxW) = interps
∇u_q = interpolate_field_gradients(physics, interps, u_el)
R_q = ∇u_q * ∇N_X'
return JxW * R_q[:]
end

@inline function FiniteElementContainers.stiffness(
physics::Laplace, interps, x_el, t, dt, u_el, u_el_old, state_old_q, state_new_q, props_el
)
interps = map_interpolants(interps, x_el)
(; X_q, N, ∇N_X, JxW) = interps
K_q = ∇N_X * ∇N_X'
return JxW * K_q
end

struct Poisson{F <: Function} <: AbstractPhysics{1, 0, 0}
func::F
end
Expand Down
Loading
Loading