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