import divett import sw_lib from fenics import * from fenics_adjoint import * from numpy.random import rand W = sw_lib.p1dgp2(divett.mesh) state = Function(W) state.interpolate(divett.InitialConditions(degree=1)) m = Control(state) divett.params["basename"] = "p1dgp2" divett.params["finish_time"] = 2 * pi / ( sqrt(divett.params["g"] * divett.params["depth"]) * pi / 3000) divett.params["dt"] = divett.params["finish_time"] / 5 divett.params["period"] = 60 * 60 * 1.24 divett.params["dump_period"] = 1 M, G, rhs_contr, ufl, ufr = sw_lib.construct_shallow_water( W, divett.ds, divett.params) j, state = sw_lib.timeloop_theta(M, G, rhs_contr, ufl, ufr, state, divett.params) if False: # TODO: Not implemented. replay_dolfin()
import sys import divett import sw_lib from dolfin import * from dolfin_adjoint import * W=sw_lib.p1dgp2(divett.mesh) dolfin.parameters["adjoint"]["record_all"]=True state=Function(W) state.interpolate(divett.InitialConditions()) divett.params["basename"]="p1dgp2" divett.params["finish_time"]=2*pi/(sqrt(divett.params["g"]*divett.params["depth"])*pi/3000) divett.params["dt"]=divett.params["finish_time"]/5 divett.params["period"]=60*60*1.24 divett.params["dump_period"]=1 M, G, rhs_contr, ufl,ufr=sw_lib.construct_shallow_water(W, divett.ds, divett.params) j, state = sw_lib.timeloop_theta(M, G, rhs_contr, ufl, ufr, state, divett.params) adj_html("sw_forward.html", "forward") adj_html("sw_adjoint.html", "adjoint") replay_dolfin() (u,p) = split(state) J = Functional(dot(u, u)*dx*dt + 3.14*dot(state, state)*dx*dt[FINISH_TIME]) for (adj_state, var) in compute_adjoint(J): pass
import sys import kelvin_new as kelvin import sw_lib from fenics import * from fenics_adjoint import * from numpy.random import rand, seed mesh = UnitSquareMesh(6, 6) W=sw_lib.p1dgp2(mesh) state=Function(W) state.interpolate(kelvin.InitialConditions(degree=1)) m = Control(state) kelvin.params["basename"] = "p1dgp2" kelvin.params["dt"] = 2 kelvin.params["finish_time"] = kelvin.params["dt"]*2 kelvin.params["dump_period"] = 1 M, G=sw_lib.construct_shallow_water(W, kelvin.params) state = sw_lib.timeloop_theta(M, G, state, kelvin.params) if False: # TODO: Not implemented. replay_dolfin()
import sys import kelvin_new as kelvin import sw_lib from dolfin import * from dolfin_adjoint import * dolfin.parameters["adjoint"]["record_all"] = True mesh = UnitSquareMesh(6, 6) W = sw_lib.p1dgp2(mesh) state = Function(W) state.interpolate(kelvin.InitialConditions()) kelvin.params["basename"] = "p1dgp2" kelvin.params["dt"] = 2 kelvin.params["finish_time"] = kelvin.params["dt"] * 2 kelvin.params["dump_period"] = 1 M, G = sw_lib.construct_shallow_water(W, kelvin.params) state = sw_lib.timeloop_theta(M, G, state, kelvin.params) adj_html("sw_forward.html", "forward") adj_html("sw_adjoint.html", "adjoint") replay_dolfin() J = Functional(dot(state, state) * dx * dt[FINISH_TIME])