Afficher la pageAnciennes révisionsHaut de page Cette page est en lecture seule. Vous pouvez afficher le texte source, mais ne pourrez pas le modifier. Contactez votre administrateur si vous pensez qu'il s'agit d'une erreur. ====== Fenics 2017 ====== The new Fenics version is installed within Singularity container. ===== How to use Fenics (interactive mode) ===== <note tip>We use ''mesoshared.univ-fcomte.fr'' node for interactive computation.</note> First load the singularity container: <code bash> $ module load tools/singularity </code> Than we invoke the fenics image to execute a python program: <code bash> $ singularity exec $SING_SPOOL/fenics.img python poisson.py </code> Or simply run: <code bash> $ $SING_SPOOL/fenics.img poisson.py </code> <note important> Since Fenics is installed for sequential usage. Please ignore the following warning message. ''[[62548,1],0]: A high-performance Open MPI point-to-point messaging module was unable to find any relevant network interfaces: Module: OpenFabrics (openib) Host: mesoshared Another transport will be used instead, although this may result in lower performance. '' </note> =====Batch Mode with SGE ===== Example of SGE script to use. <code bash> #!/bin/bash #$ -N fenics_sge #$ -o $JOB_NAME.$JOB_ID.out #$ -e $JOB_NAME.$JOB_ID.err #$ -l h_vmem=4G module load tools/singularity export HOME=$WORK singularity exec $SING_SPOOL/fenics.img python poisson.py </code> submit the job: <code bash> $ qsub script.sge </code> ===== Program Example (poisson.py) ===== <file python poisson.py> """ FEniCS tutorial demo program: Poisson equation with Dirichlet conditions. Test problem is chosen to give an exact solution at all nodes of the mesh. -Laplace(u) = f in the unit square u = u_D on the boundary u_D = 1 + x^2 + 2y^2 f = -6 """ from __future__ import print_function from fenics import * # Create mesh and define function space mesh = UnitSquareMesh(8, 8) V = FunctionSpace(mesh, 'P', 1) # Define boundary condition u_D = Expression('1 + x[0]*x[0] + 2*x[1]*x[1]', degree=2) def boundary(x, on_boundary): return on_boundary bc = DirichletBC(V, u_D, boundary) # Define variational problem u = TrialFunction(V) v = TestFunction(V) f = Constant(-6.0) a = dot(grad(u), grad(v))*dx L = f*v*dx # Compute solution u = Function(V) solve(a == L, u, bc) # Plot solution and mesh plot(u) plot(mesh) # Save solution to file in VTK format vtkfile = File('poisson/solution.pvd') vtkfile << u # Compute error in L2 norm error_L2 = errornorm(u_D, u, 'L2') # Compute maximum error at vertices vertex_values_u_D = u_D.compute_vertex_values(mesh) vertex_values_u = u.compute_vertex_values(mesh) import numpy as np error_max = np.max(np.abs(vertex_values_u_D - vertex_values_u)) # Print errors print('error_L2 =', error_L2) print('error_max =', error_max) # Hold plot # interactive() //OLD methode to plot import matplotlib.pyplot as plt plot(u) plt.show() </file> fenics/2017.txt Dernière modification : 2018/06/28 09:29de admin