at 25.11-pre 1.2 kB view raw
1import ./make-test-python.nix ( 2 { pkgs, ... }: 3 4 let 5 fenicsScript = pkgs.writeScript "poisson.py" '' 6 #!/usr/bin/env python 7 from dolfin import * 8 9 mesh = UnitSquareMesh(4, 4) 10 V = FunctionSpace(mesh, "Lagrange", 1) 11 12 def boundary(x): 13 return x[0] < DOLFIN_EPS or x[0] > 1.0 - DOLFIN_EPS 14 15 u0 = Constant(0.0) 16 bc = DirichletBC(V, u0, boundary) 17 18 u = TrialFunction(V) 19 v = TestFunction(V) 20 f = Expression("10*exp(-(pow(x[0] - 0.5, 2) + pow(x[1] - 0.5, 2)) / 0.02)", degree=2) 21 g = Expression("sin(5*x[0])", degree=2) 22 a = inner(grad(u), grad(v))*dx 23 L = f*v*dx + g*v*ds 24 25 u = Function(V) 26 solve(a == L, u, bc) 27 print(u) 28 ''; 29 in 30 { 31 name = "fenics"; 32 meta = { 33 maintainers = with pkgs.lib.maintainers; [ ]; 34 }; 35 36 nodes = { 37 fenicsnode = 38 { pkgs, ... }: 39 { 40 environment.systemPackages = with pkgs; [ 41 gcc 42 (python3.withPackages (ps: with ps; [ fenics ])) 43 ]; 44 }; 45 }; 46 testScript = 47 { nodes, ... }: 48 '' 49 start_all() 50 fenicsnode.succeed("${fenicsScript}") 51 ''; 52 } 53)