Skip to content

Commit ace45af

Browse files
format SciML Style
1 parent 26d6607 commit ace45af

28 files changed

+834
-641
lines changed

Diff for: .JuliaFormatter.toml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
style = "sciml"

Diff for: .github/workflows/FormatCheck.yml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: format-check
2+
3+
on:
4+
push:
5+
branches:
6+
- 'master'
7+
- 'release-'
8+
tags: '*'
9+
pull_request:
10+
11+
jobs:
12+
build:
13+
runs-on: ${{ matrix.os }}
14+
strategy:
15+
matrix:
16+
julia-version: [1]
17+
julia-arch: [x86]
18+
os: [ubuntu-latest]
19+
steps:
20+
- uses: julia-actions/setup-julia@latest
21+
with:
22+
version: ${{ matrix.julia-version }}
23+
24+
- uses: actions/checkout@v1
25+
- name: Install JuliaFormatter and format
26+
# This will use the latest version by default but you can set the version like so:
27+
#
28+
# julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter", version="0.13.0"))'
29+
run: |
30+
julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter"))'
31+
julia -e 'using JuliaFormatter; format(".", verbose=true)'
32+
- name: Format check
33+
run: |
34+
julia -e '
35+
out = Cmd(`git diff --name-only`) |> read |> String
36+
if out == ""
37+
exit(0)
38+
else
39+
@error "Some files have not been formatted !!!"
40+
write(stdout, out)
41+
exit(1)
42+
end'

Diff for: deps/build.jl

+17-18
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
using PyCall
22

33
if Sys.iswindows()
4-
@warn("""
5-
FEniCS is not known to run on Windows!
6-
Please try installing from Windows Subsystem for Linux.
7-
""")
4+
@warn("""
5+
FEniCS is not known to run on Windows!
6+
Please try installing from Windows Subsystem for Linux.
7+
""")
8+
end
9+
try
10+
pyimport_conda("fenics", "fenics=2019.1.0", "conda-forge")
11+
pyimport_conda("mshr", "mshr=2019.1.0", "conda-forge")
12+
catch ee
13+
typeof(ee) <: PyCall.PyError || rethrow(ee)
14+
@warn("""
15+
Python Dependancies not installed
16+
Please either:
17+
- Rebuild PyCall using the path to FEniCS using
18+
- `ENV["PYTHON"]="/path/to/FEniCS"; Pkg.build("PyCall"); Pkg.build("FEniCS")`
19+
- Or install the Dependancies using the Docker image provided
20+
""")
821
end
9-
try
10-
pyimport_conda("fenics", "fenics=2019.1.0", "conda-forge")
11-
pyimport_conda("mshr", "mshr=2019.1.0", "conda-forge")
12-
catch ee
13-
typeof(ee) <: PyCall.PyError || rethrow(ee)
14-
@warn("""
15-
Python Dependancies not installed
16-
Please either:
17-
- Rebuild PyCall using the path to FEniCS using
18-
- `ENV["PYTHON"]="/path/to/FEniCS"; Pkg.build("PyCall"); Pkg.build("FEniCS")`
19-
- Or install the Dependancies using the Docker image provided
20-
"""
21-
)
22-
end

Diff for: examples/acoustic.jl

+22-22
Original file line numberDiff line numberDiff line change
@@ -3,54 +3,54 @@ using FEniCS
33

44
c = 5000
55
#problem variables, have been scaled down for faster test solution
6-
dt = 0.00004;
7-
global t = 0;
8-
T = 0.0004;
6+
dt = 0.00004
7+
global t = 0
8+
T = 0.0004
99

10-
mesh = RectangleMesh(Point([-2., -2.]),Point([2., 2.]),40,40)
11-
V = FunctionSpace(mesh,"Lagrange",1)
10+
mesh = RectangleMesh(Point([-2.0, -2.0]), Point([2.0, 2.0]), 40, 40)
11+
V = FunctionSpace(mesh, "Lagrange", 1)
1212

1313
# Previous and current solution
14-
u1= interpolate(Constant(0.0), V)
15-
u0= interpolate(Constant(0.0), V)
14+
u1 = interpolate(Constant(0.0), V)
15+
u0 = interpolate(Constant(0.0), V)
1616

1717
# Variational problem at each time
1818
u = TrialFunction(V)
1919
v = TestFunction(V)
2020

21-
a = u*v*dx + dt*dt*c*c*inner(grad(u), grad(v))*dx
22-
L = 2*u1*v*dx-u0*v*dx
21+
a = u * v * dx + dt * dt * c * c * inner(grad(u), grad(v)) * dx
22+
L = 2 * u1 * v * dx - u0 * v * dx
2323

24-
delta = Expression("sin(c*10*t)",degree=2,c=c,t=t)
24+
delta = Expression("sin(c*10*t)", degree = 2, c = c, t = t)
2525

2626
#Define boundary conditions
27-
top ="on_boundary && near(x[1], 2)"
28-
BCT = DirichletBC(V,Constant(0.0),top)
27+
top = "on_boundary && near(x[1], 2)"
28+
BCT = DirichletBC(V, Constant(0.0), top)
2929

30-
down ="on_boundary && near(x[1], -2)"
31-
BCD = DirichletBC(V,Constant(0.0),down)
30+
down = "on_boundary && near(x[1], -2)"
31+
BCD = DirichletBC(V, Constant(0.0), down)
3232

3333
left = "on_boundary && near(x[0],-2)"
34-
BCL = DirichletBC(V,delta,left)
34+
BCL = DirichletBC(V, delta, left)
3535

3636
right = "on_boundary && near(x[0],2)"
37-
BCR = DirichletBC(V,Constant(0.0),right)
37+
BCR = DirichletBC(V, Constant(0.0), right)
3838

3939
#bcs = [BCL.pyobject,BCD.pyobject,BCT.pyobject,BCR.pyobject]
40-
bcs = [BCL.pyobject,BCD.pyobject,BCT.pyobject]
40+
bcs = [BCL.pyobject, BCD.pyobject, BCT.pyobject]
4141

4242
#bc = DirichletBC(V, 0, "on_boundary")
4343

44-
u=FeFunction(V)
44+
u = FeFunction(V)
4545

4646
while t <= T
4747
A, b = assemble_system(a, L, bcs)
4848
delta.pyobject.t = t
49-
[apply(bcc,b) for bcc in bcs]
49+
[apply(bcc, b) for bcc in bcs]
5050
solve(A, vector(u), b)
51-
assign(u0,u1)
52-
assign(u1,u)
53-
global t +=dt
51+
assign(u0, u1)
52+
assign(u1, u)
53+
global t += dt
5454
#fenics.plot(u.pyobject,title="Acoustic wave Equation")#,mode="auto")
5555

5656
end

Diff for: examples/acoustic_new_assemble.jl

+23-24
Original file line numberDiff line numberDiff line change
@@ -3,50 +3,49 @@ using FEniCS
33

44
c = 5000
55
#problem variables
6-
dt = 0.000004;
7-
global t = 0;
8-
T = 0.004;
6+
dt = 0.000004
7+
global t = 0
8+
T = 0.004
99

10-
mesh = RectangleMesh(Point([-2., -2.]),Point([2., 2.]),40,40)
11-
V = FunctionSpace(mesh,"Lagrange",1)
10+
mesh = RectangleMesh(Point([-2.0, -2.0]), Point([2.0, 2.0]), 40, 40)
11+
V = FunctionSpace(mesh, "Lagrange", 1)
1212

1313
# Previous and current solution
14-
u1= interpolate(Constant(0.0), V)
15-
u0= interpolate(Constant(0.0), V)
14+
u1 = interpolate(Constant(0.0), V)
15+
u0 = interpolate(Constant(0.0), V)
1616

1717
# Variational problem at each time
1818
u = TrialFunction(V)
1919
v = TestFunction(V)
2020

21-
a = u*v*dx + dt*dt*c*c*inner(grad(u), grad(v))*dx
22-
L = 2*u1*v*dx-u0*v*dx
21+
a = u * v * dx + dt * dt * c * c * inner(grad(u), grad(v)) * dx
22+
L = 2 * u1 * v * dx - u0 * v * dx
2323

24-
delta = Expression("sin(c*10*t)",degree=2,c=c,t=t)
24+
delta = Expression("sin(c*10*t)", degree = 2, c = c, t = t)
2525

2626
#Define boundary conditions
27-
top ="on_boundary && near(x[1], 2)"
28-
BCT = DirichletBC(V,Constant(0.0),top)
27+
top = "on_boundary && near(x[1], 2)"
28+
BCT = DirichletBC(V, Constant(0.0), top)
2929

30-
down ="on_boundary && near(x[1], -2)"
31-
BCD = DirichletBC(V,Constant(0.0),down)
30+
down = "on_boundary && near(x[1], -2)"
31+
BCD = DirichletBC(V, Constant(0.0), down)
3232

3333
left = "on_boundary && near(x[0],-2)"
34-
BCL = DirichletBC(V,delta,left)
34+
BCL = DirichletBC(V, delta, left)
3535

3636
right = "on_boundary && near(x[0],2)"
37-
BCR = DirichletBC(V,Constant(0.0),right)
37+
BCR = DirichletBC(V, Constant(0.0), right)
3838

39-
bcs_dir = [BCL,BCD,BCT,BCR]
40-
bcs_neu = [BCL,BCD,BCT]
39+
bcs_dir = [BCL, BCD, BCT, BCR]
40+
bcs_neu = [BCL, BCD, BCT]
4141

42-
43-
u=FeFunction(V)
42+
u = FeFunction(V)
4443

4544
while t <= T
4645
delta.pyobject.t = t
47-
lvsolve(a,L,u,bcs_dir) #linear variational solver
48-
assign(u0,u1)
49-
assign(u1,u)
50-
global t +=dt
46+
lvsolve(a, L, u, bcs_dir) #linear variational solver
47+
assign(u0, u1)
48+
assign(u1, u)
49+
global t += dt
5150
end
5251
end#module

Diff for: examples/heat_equation.jl

+8-8
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@ using OrdinaryDiffEq
1313
using FEniCS
1414

1515
mesh = UnitIntervalMesh(50)
16-
V = FunctionSpace(mesh,"P",1)
16+
V = FunctionSpace(mesh, "P", 1)
1717
u_str = "sin(2*pi*x[0]) * exp(-t*pow(2*pi, 2))"
1818

1919
tspan = (0.0, 0.1)
20-
u = interpolate(Expression(u_str, degree=2, pi=Float64(pi), t=tspan[1]), V)
20+
u = interpolate(Expression(u_str, degree = 2, pi = Float64(pi), t = tspan[1]), V)
2121

2222
bc = DirichletBC(V, 0.0, "on_boundary")
2323
dudt = TrialFunction(V)
2424
v = TestFunction(V)
2525
Dudt = FeFunction(V)
26-
F = dot(dudt, v)*dx + dot(grad(u), grad(v))*dx
26+
F = dot(dudt, v) * dx + dot(grad(u), grad(v)) * dx
2727
a = lhs(F)
2828
L = rhs(F)
29-
p = (u=u, Dudt=Dudt, bc=bc, a=a, L=L)
29+
p = (u = u, Dudt = Dudt, bc = bc, a = a, L = L)
3030

3131
function f!(dudt_vec, u_vec, p, t)
3232
assign(p.u, u_vec)
@@ -37,18 +37,18 @@ end
3737
u0_vec = get_array(u)
3838
t_final = 0.1
3939
prob = ODEProblem(f!, u0_vec, tspan, p)
40-
u_true = interpolate(Expression(u_str, degree=2, pi=Float64(pi), t=tspan[2]), V)
40+
u_true = interpolate(Expression(u_str, degree = 2, pi = Float64(pi), t = tspan[2]), V)
4141

4242
# some algorithms to try:
4343
# alg = ImplicitEuler(autodiff=false)
4444
# alg = Rosenbrock23(autodiff=false)
4545
# alg = Rodas5(autodiff=false)
4646

47-
alg = KenCarp4(autodiff=false)
48-
sol = OrdinaryDiffEq.solve(prob, alg, reltol=1e-6, abstol=1e-6)
47+
alg = KenCarp4(autodiff = false)
48+
sol = OrdinaryDiffEq.solve(prob, alg, reltol = 1e-6, abstol = 1e-6)
4949

5050
vec_sol = get_array(p.u)
5151
vec_true = get_array(u_true)
52-
@test vec_sol vec_true rtol=1e-2
52+
@test vec_solvec_true rtol=1e-2
5353

5454
end#module

Diff for: examples/tutorial1.jl

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
module Tutorial1
22
using FEniCS
33

4-
mesh = UnitSquareMesh(8,8)
5-
V = FunctionSpace(mesh,"P",1)
6-
u_D = Expression("1+x[0]*x[0]+2*x[1]*x[1]", degree=2)
4+
mesh = UnitSquareMesh(8, 8)
5+
V = FunctionSpace(mesh, "P", 1)
6+
u_D = Expression("1+x[0]*x[0]+2*x[1]*x[1]", degree = 2)
77
u = TrialFunction(V)
8-
bc1 = DirichletBC(V,u_D, "on_boundary")
8+
bc1 = DirichletBC(V, u_D, "on_boundary")
99
v = TestFunction(V)
1010
f = Constant(-6.0)
11-
a = dot(grad(u),grad(v))*dx
12-
L = f*v*dx
13-
U=FeFunction(V)
14-
lvsolve(a,L,U,bc1) #linear variational solver
11+
a = dot(grad(u), grad(v)) * dx
12+
L = f * v * dx
13+
U = FeFunction(V)
14+
lvsolve(a, L, U, bc1) #linear variational solver
1515
#lvsolve(a,L,U,bc1,solver_parameters=Dict("linear_solver"=>"lu"),form_compiler_parameters=Dict("optimize"=>true))
16-
error_L2= errornorm(u_D, U, norm="L2")
16+
error_L2 = errornorm(u_D, U, norm = "L2")
1717

1818
#get_array(L) #this returns an array for the stiffness matrix
1919
#get_array(U) #this returns an array for the solution values
2020
#vtkfile = File("poisson/solution.pvd")
2121
#vtkfile << U.pyobject #exports the solution to a vtkfile
22-
File("poisson/solutionnew.pvd",U)
23-
vertex_values_u_D = compute_vertex_values(u_D,mesh)
24-
vertex_values_u = compute_vertex_values(U,mesh)
25-
error_max = maximum(abs.(vertex_values_u_D-vertex_values_u))
22+
File("poisson/solutionnew.pvd", U)
23+
vertex_values_u_D = compute_vertex_values(u_D, mesh)
24+
vertex_values_u = compute_vertex_values(U, mesh)
25+
error_max = maximum(abs.(vertex_values_u_D - vertex_values_u))
2626
end#module

Diff for: examples/tutorial2.jl

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
module Tutorial2
22
using FEniCS
3-
domain = Circle(Point([0.0,0.0]),1)
4-
mesh = generate_mesh(domain,16)
5-
V = FunctionSpace(mesh,"P",2)
3+
domain = Circle(Point([0.0, 0.0]), 1)
4+
mesh = generate_mesh(domain, 16)
5+
V = FunctionSpace(mesh, "P", 2)
66
w_D = Constant(0)
77

8-
bc = DirichletBC(V,w_D,"on_boundary")
9-
beta =8
8+
bc = DirichletBC(V, w_D, "on_boundary")
9+
beta = 8
1010
R0 = 0.6
1111
p = Expression("4*exp(-pow(beta, 2)*(pow(x[0], 2) + pow(x[1] - R0, 2)))",
12-
degree=1, beta=beta, R0=R0)
12+
degree = 1, beta = beta, R0 = R0)
1313
w = TrialFunction(V)
1414
v = TestFunction(V)
15-
a = dot(grad(w), grad(v))*dx
16-
L = p*v*dx
17-
w=FeFunction(V)
18-
lvsolve(a,L,w,bc)
19-
p = interpolate(p,V)
15+
a = dot(grad(w), grad(v)) * dx
16+
L = p * v * dx
17+
w = FeFunction(V)
18+
lvsolve(a, L, w, bc)
19+
p = interpolate(p, V)
2020

2121
vtkfile_w = File("poisson_membrane/deflection.pvd")
2222
vtkfile_w << w.pyobject

0 commit comments

Comments
 (0)