Created
January 29, 2023 02:54
-
-
Save christophernhill/8801f9615e92b174070945c8033ebd3d to your computer and use it in GitHub Desktop.
DJ 4 Earth Onan Enzyme Field only
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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