Skip to content

Instantly share code, notes, and snippets.

View eikehmueller's full-sized avatar

Eike Hermann Mueller eikehmueller

View GitHub Profile
@eikehmueller
eikehmueller / gist:d3a380f3135eb640b6636920e61e4aab
Created October 1, 2025 12:36
Project state to CG functions
from firedrake import *
class Projector:
def __init__(self, W, V):
"""Class for projecting functions in the mixed space W = L2 x HDiv to scalar functions in V
:arg W: function space W
:arg V: function space V
import torch
import numpy as np
class ExponentialFunction(torch.autograd.Function):
"""Differentiable implementation of exponential function exp(-(X.kappa)^2) for given kappa
If the input X is a vector compute
y = exp(-(sum_j kappa_j*X_j)^2)
(firedrake) eikehmueller@eikehmueller src $ python train.py
firedrake:WARNING OMP_NUM_THREADS is not set or is set to a value greater than 1, we suggest setting OMP_NUM_THREADS=1 to improve performance
/Users/eikehmueller/Software/firedrake/src/pyadjoint/firedrake_adjoint/__init__.py:9: FutureWarning: The firedrake_adjoint module is deprecated.
Instead, use the firedrake.adjoint module and explicitly start taping
by calling continue_annotation().
warnings.warn("""The firedrake_adjoint module is deprecated.
number of patches = 20
patchsize = 60
number of points in all patches = 1200
@eikehmueller
eikehmueller / mwe.py
Last active September 2, 2019 07:44
MWE for smoother
from firedrake import *
mesh = UnitSquareMesh(10, 10)
def get_p1_space():
return FunctionSpace(mesh, "CG", 1)
def get_p1_prb_bcs():
return DirichletBC(get_p1_space(), Constant(0.0), "on_boundary")
eikemueller@138-38-171-253 $ ./scripts/firedrake-clean
Traceback (most recent call last):
File "./scripts/firedrake-clean", line 3, in <module>
from firedrake.ffc_interface import clear_cache, FFCKernel
File "/Users/eikemueller/PostDocBath/EllipticSolvers/firedrake/firedrake/__init__.py", line 3, in <module>
import firedrake.petsc as petsc
File "/Users/eikemueller/PostDocBath/EllipticSolvers/firedrake/firedrake/petsc.py", line 5, in <module>
petsc4py.init(sys.argv)
File "/Users/eikemueller/PostDocBath/EllipticSolvers/petsc4py/arch-darwin-c-opt/lib/python2.7/site-packages/petsc4py/__init__.py", line 42, in init
PETSc = petsc4py.lib.ImportPETSc(arch)
This file has been truncated, but you can view the full file.
Running helmholtz
PBS_JOBID = 2918167.sdb
Started atSat May 30 18:30:21 BST 2015
+---------------------------+
! Mixed Gravity wave solver !
+---------------------------+
################################################################################
# General parameters
################################################################################
General:
warmup_run = True # Carry out a warmup run first?
nu_cfl = 2.0 # CFL number
speed_c = 300.0 # Sound wave speed [m/s]
speed_N = 0.01 # Buoyancy frequency [1/s]
solve_matrixfree = True # Use matrix-free solver?
solve_petsc = True # Use PETSc solver
ufl_form = phi_test*div(w_h_trial)*self._dx
compiled_form = compile_form(ufl_form, 'ufl_form')[0]
kernel = compiled_form[6]
coords = compiled_form[3]
coefficients = compiled_form[4]
arguments = ufl_form.arguments()
ndof_pressure = arguments[0].cell_node_map().arity
ndof_velocity_h = arguments[1].cell_node_map().arity
# Build LMA for B_h
eike@eslogin002 $ cat helmholtz_2692059.sdb/output.log
Running helmholtz
PBS_JOBID = 2692059.sdb
Started atThu Feb 5 08:39:45 GMT 2015
+---------------------------+
! Mixed Gravity wave solver !
+---------------------------+
Running helmholtz
PBS_JOBID = 2688816.sdb
Started atTue Feb 3 21:21:01 GMT 2015
+---------------------------+
! Mixed Gravity wave solver !
+---------------------------+