Skip to content

Commit

Permalink
change name to DJUICE
Browse files Browse the repository at this point in the history
  • Loading branch information
enigne committed Apr 23, 2024
1 parent 529c693 commit 4905431
Show file tree
Hide file tree
Showing 21 changed files with 57 additions and 61 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:

jobs:
test:
name: dJUICE on Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
name: DJUICE on Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
Expand Down Expand Up @@ -75,8 +75,8 @@ jobs:
# - run: |
# julia --project=docs -e '
# using Documenter: doctest
# using dJUICE
# doctest(dJUICE)'
# using DJUICE
# doctest(DJUICE)'
# - run: julia --project=docs docs/make.jl
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name = "dJUICE"
name = "DJUICE"
uuid = "1cb5fe60-6b70-416b-9050-039c23a62a10"
authors = ["Mathieu Morlighem <Mathieu.Morlighem@dartmouth.edu>"]
version = "0.1.0"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ Authors:
License: MIT

[build-stable-img]: https://github.com/DJ4Earth/DJUICE.jl/workflows/CI/badge.svg
[build-url]: https://github.com/DJ4Earth/dJUICE/actions?query=workflow
[build-url]: https://github.com/DJ4Earth/DJUICE/actions?query=workflow
4 changes: 2 additions & 2 deletions src/dJUICE.jl → src/DJUICE.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Author: Mathieu Morlighem
# email: mathieu.morlighem@dartmouth.edu

module dJUICE
module DJUICE
const userdir = "./usr"
const coredir = "./core"

Expand All @@ -20,7 +20,7 @@ export triangle_issm
include("$userdir/parameterization.jl")
export setmask, InterpFromMeshToMesh2d
include("$coredir/solve.jl")
export solve, solve2
export solve
include("$userdir/plotmodel.jl")
export plotmodel

Expand Down
4 changes: 2 additions & 2 deletions src/core/analyses/stressbalanceanalysis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,14 @@ end #}}}
function CreateKMatrix(analysis::StressbalanceAnalysis, element::Tria) #{{{
# a wrapper for Enzyme to know the type of friction law
frictionlaw = FindParam(Int64, element, FrictionLawEnum)
CreateKMatrix(analysis, element, Val(frictionlaw))::dJUICE.ElementMatrix
CreateKMatrix(analysis, element, Val(frictionlaw))::DJUICE.ElementMatrix
end #}}}
function CreateKMatrix(analysis::StressbalanceAnalysis, element::Tria, ::Val{frictionlaw}) where frictionlaw# {{{
#Internmediaries
numnodes = 3

#Initialize Element matrix and basis function derivatives
Ke = ElementMatrix(element.nodes)::dJUICE.ElementMatrix
Ke = ElementMatrix(element.nodes)::DJUICE.ElementMatrix
dbasis = Matrix{Float64}(undef,numnodes,2)

#Retrieve all inputs and parameters
Expand Down
2 changes: 1 addition & 1 deletion src/core/control.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ using Enzyme
Enzyme.API.looseTypeAnalysis!(false)
Enzyme.API.strictAliasing!(false)
Enzyme.API.typeWarning!(false)
Enzyme.Compiler.RunAttributor[] = false

using Optimization, OptimizationOptimJL

Enzyme.Compiler.RunAttributor[] = false

function Control_Core(md::model, femmodel::FemModel) #{{{
# solve for optimization
Expand Down
2 changes: 1 addition & 1 deletion src/core/costfunctions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function costfunction(α::Vector{Float64}, femmodel::FemModel) #{{{
# get the Enum
controlvar_enum = StringToEnum(control_string)
if isnothing(controlvar_enum)
error(control_string, " is not defined in dJUICE, therefore the derivative with respect to ", control_string, " is meaningless")
error(control_string, " is not defined in DJUICE, therefore the derivative with respect to ", control_string, " is meaningless")
end
# compute cost function
# TODO: loop through all controls with respect to all the components in the cost function
Expand Down
8 changes: 4 additions & 4 deletions src/usr/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ function issmdir() #{{{
if haskey(ENV, "ISSM_DIR")
issmdir = ENV["ISSM_DIR"]
else
println("Could not determine the location of ISSM, use dJUICE path instead")
return joinpath(dirname(pathof(dJUICE)), "..")
println("Could not determine the location of ISSM, use DJUICE path instead")
return joinpath(dirname(pathof(DJUICE)), "..")
end

if isempty(issmdir)
println("Could not determine the location of ISSM, use dJUICE path instead")
return joinpath(dirname(pathof(dJUICE)), "..")
println("Could not determine the location of ISSM, use DJUICE path instead")
return joinpath(dirname(pathof(DJUICE)), "..")
else
return issmdir
end
Expand Down
24 changes: 12 additions & 12 deletions test/modelstructtests.jl
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
module ModelStruct

using dJUICE
using DJUICE
using Test
using MAT

@testset "Model basic sturct" begin
md = model()
@test (typeof(md.mesh)) <: dJUICE.AbstractMesh
@test (typeof(md.mesh)) == dJUICE.Mesh2dTriangle
@test (typeof(md.friction)) <: dJUICE.AbstractFriction
@test (typeof(md.friction)) <: dJUICE.BuddFriction
@test (typeof(md.mesh)) <: DJUICE.AbstractMesh
@test (typeof(md.mesh)) == DJUICE.Mesh2dTriangle
@test (typeof(md.friction)) <: DJUICE.AbstractFriction
@test (typeof(md.friction)) <: DJUICE.BuddFriction

md = model(md; friction=DNNFriction())
@test (typeof(md.friction)) == dJUICE.DNNFriction
@test (typeof(md.friction)) == DJUICE.DNNFriction

md = model(md; friction=SchoofFriction())
@test (typeof(md.friction)) == dJUICE.SchoofFriction
@test (typeof(md.friction)) == DJUICE.SchoofFriction
end

@testset "Enums <-> String" begin
@test dJUICE.StringToEnum("FrictionCoefficient") == dJUICE.FrictionCoefficientEnum
@test dJUICE.StringToEnum("MaterialsRheologyB") == dJUICE.MaterialsRheologyBEnum
@test dJUICE.EnumToString(dJUICE.FrictionCoefficientEnum) == "FrictionCoefficient"
@test dJUICE.EnumToString(dJUICE.MaterialsRheologyBEnum) == "MaterialsRheologyB"
@test DJUICE.StringToEnum("FrictionCoefficient") == DJUICE.FrictionCoefficientEnum
@test DJUICE.StringToEnum("MaterialsRheologyB") == DJUICE.MaterialsRheologyBEnum
@test DJUICE.EnumToString(DJUICE.FrictionCoefficientEnum) == "FrictionCoefficient"
@test DJUICE.EnumToString(DJUICE.MaterialsRheologyBEnum) == "MaterialsRheologyB"
end

@testset "Triangle" begin
md = model()
c = dJUICE.ExpStruct()
c = DJUICE.ExpStruct()
c.name = "domainoutline"
c.nods = 5
c.density = 1.0
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using dJUICE
using DJUICE
using Test

function searchdir(path,key)
Expand Down
2 changes: 1 addition & 1 deletion test/test101.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using dJUICE
using DJUICE

md = model()
md = triangle(md,issmdir()*"/test/Exp/Square.exp",50000.)
Expand Down
3 changes: 1 addition & 2 deletions test/test201.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/Applications/Julia-1.6.app/Contents/Resources/julia/bin/julia
using dJUICE
using DJUICE

md = model()
md = triangle(md,issmdir()*"/test/Exp/Square.exp", 50000.)
Expand Down
3 changes: 1 addition & 2 deletions test/test208.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/Applications/Julia-1.6.app/Contents/Resources/julia/bin/julia
using dJUICE
using DJUICE

md = model()
md = triangle(md,issmdir()*"/test/Exp/Square.exp", 150000.)
Expand Down
3 changes: 1 addition & 2 deletions test/test301.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/Applications/Julia-1.6.app/Contents/Resources/julia/bin/julia
using dJUICE
using DJUICE

md = model()
md = triangle(md,issmdir()*"/test/Exp/Square.exp",150000.)
Expand Down
3 changes: 1 addition & 2 deletions test/test501.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/Applications/Julia-1.6.app/Contents/Resources/julia/bin/julia
using dJUICE
using DJUICE

md = model()
md = triangle(md,issmdir()*"/test/Exp/Pig.exp",10000.)
Expand Down
2 changes: 1 addition & 1 deletion test/test807.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using dJUICE
using DJUICE

md = model()
md = triangle(md,issmdir()*"/test/Exp/Square.exp",200000.)
Expand Down
3 changes: 1 addition & 2 deletions test/testDNN.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/Applications/Julia-1.6.app/Contents/Resources/julia/bin/julia
using dJUICE
using DJUICE
using Flux
using BSON: @load

Expand Down
2 changes: 1 addition & 1 deletion test/testGPU.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/Applications/Julia-1.8.app/Contents/Resources/julia/bin/julia --project
using dJUICE
using DJUICE
import Statistics: mean
using Printf

Expand Down
19 changes: 10 additions & 9 deletions test/testad.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
module enzymeDiff_grad_frictionC

using dJUICE
using MAT
using Test
using Enzyme

Enzyme.API.typeWarning!(false)
Enzyme.Compiler.RunAttributor[] = false

using DJUICE
using MAT
using Test

#Load model from MATLAB file
#file = matopen(joinpath(@__DIR__, "..", "data","temp12k.mat")) #BIG model
file = matopen(joinpath(@__DIR__, "..", "data","temp.mat")) #SMALL model (35 elements)
Expand Down Expand Up @@ -36,21 +37,21 @@ addJ = md.results["StressbalanceSolution"]["Gradient"]
md.inversion.independent_string = "FrictionCoefficient"

α = md.inversion.independent
femmodel=dJUICE.ModelProcessor(md, :StressbalanceSolution)
J1 = dJUICE.costfunction(α, femmodel)
femmodel=DJUICE.ModelProcessor(md, :StressbalanceSolution)
J1 = DJUICE.costfunction(α, femmodel)
@test ~isnothing(J1)
end

@testset "AD gradient calculation for FrictionC" begin
α = md.inversion.independent
delta = 1e-7
femmodel=dJUICE.ModelProcessor(md, :StressbalanceSolution)
J1 = dJUICE.costfunction(α, femmodel)
femmodel=DJUICE.ModelProcessor(md, :StressbalanceSolution)
J1 = DJUICE.costfunction(α, femmodel)
for i in 1:md.mesh.numberofvertices
= zero(md.friction.coefficient)
dα[i] = delta
femmodel=dJUICE.ModelProcessor(md, :StressbalanceSolution)
J2 = dJUICE.costfunction+dα, femmodel)
femmodel=DJUICE.ModelProcessor(md, :StressbalanceSolution)
J2 = DJUICE.costfunction+dα, femmodel)
dJ = (J2-J1)/delta

@test abs(dJ - addJ[i])< 1e-5
Expand Down
14 changes: 7 additions & 7 deletions test/testad2.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module enzymeDiff_grad_rheologyB

using dJUICE
using DJUICE
using MAT
using Test
using Enzyme
Expand Down Expand Up @@ -35,21 +35,21 @@ addJ = md.results["StressbalanceSolution"]["Gradient"]
md.inversion.independent_string = "MaterialsRheologyB"

α = md.inversion.independent
femmodel=dJUICE.ModelProcessor(md, :StressbalanceSolution)
J1 = dJUICE.costfunction(α, femmodel)
femmodel=DJUICE.ModelProcessor(md, :StressbalanceSolution)
J1 = DJUICE.costfunction(α, femmodel)
@test ~isnothing(J1)
end

@testset "AD results RheologyB" begin
α = md.inversion.independent
delta = 1e-8
femmodel=dJUICE.ModelProcessor(md, :StressbalanceSolution)
J1 = dJUICE.costfunction(α, femmodel)
femmodel=DJUICE.ModelProcessor(md, :StressbalanceSolution)
J1 = DJUICE.costfunction(α, femmodel)
for i in 1:md.mesh.numberofvertices
= zero(md.friction.coefficient)
dα[i] = delta
femmodel=dJUICE.ModelProcessor(md, :StressbalanceSolution)
J2 = dJUICE.costfunction+dα, femmodel)
femmodel=DJUICE.ModelProcessor(md, :StressbalanceSolution)
J2 = DJUICE.costfunction+dα, femmodel)
dJ = (J2-J1)/delta

@test abs(dJ - addJ[i])< 1e-6
Expand Down
8 changes: 4 additions & 4 deletions test/testoptimization.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module enzymeDiff

using dJUICE
using DJUICE
using MAT
using Test
using Enzyme
Expand Down Expand Up @@ -28,11 +28,11 @@ md.inversion.independent_string = "FrictionCoefficient"
α = md.inversion.independent
∂J_∂α = zero(α)

femmodel=dJUICE.ModelProcessor(md, :StressbalanceSolution)
femmodel=DJUICE.ModelProcessor(md, :StressbalanceSolution)
n = length(α)
# use user defined grad, errors!
optprob = OptimizationFunction(dJUICE.costfunction, Optimization.AutoEnzyme(), grad=dJUICE.computeGradient)
#optprob = OptimizationFunction(dJUICE.costfunction, Optimization.AutoEnzyme())
optprob = OptimizationFunction(DJUICE.costfunction, Optimization.AutoEnzyme(), grad=DJUICE.computeGradient)
#optprob = OptimizationFunction(DJUICE.costfunction, Optimization.AutoEnzyme())
#prob = Optimization.OptimizationProblem(optprob, α, femmodel, lb=md.inversion.min_parameters, ub=md.inversion.max_parameters)
prob = Optimization.OptimizationProblem(optprob, α, femmodel)
sol = Optimization.solve(prob, Optim.LBFGS())
Expand Down

0 comments on commit 4905431

Please sign in to comment.