Skip to content

Instantly share code, notes, and snippets.

@christophernhill
Created January 29, 2023 02:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christophernhill/8801f9615e92b174070945c8033ebd3d to your computer and use it in GitHub Desktop.
Save christophernhill/8801f9615e92b174070945c8033ebd3d to your computer and use it in GitHub Desktop.
DJ 4 Earth Onan Enzyme Field only
using Pkg
Pkg.add("Enzyme")
Pkg.add("Oceananigans")
using Enzyme
using Oceananigans
# Lets create a one-dimensional array, with N elements, using Oceananigans data structures
#
# Specify computation parameters
arch=CPU()
FT=Float64
# We need a grid to create an Oceananigans array
N = 6
topo = (Bounded, Flat, Flat)
grid = RectilinearGrid(arch, FT, topology=topo, size=(N), halo=1, x=(-1, 1), y=(-1, 1), z=(-1, 1))
# Now lets create the array, a cell centered field.
c = CenterField(grid)
set!(c,2)
# Now lets create a primitive operator
function f!(y, x)
y[1] = sum(x.*x)
return nothing
end
y=[0.]
f!(y,c)
bc=CenterField(grid)
set!(c,2)
set!(bc,0)
by=[1.]
y=[0.]
autodiff(f!,Duplicated(y,by),Duplicated(c,bc))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment