Пример #1
0
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()

(u, p) = split(state)
J = j + assemble(3.14 * dot(state, state) * dx)


def compute_J(ic):
    j, state = sw_lib.timeloop_theta(M,
                                     G,
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

def compute_J(ic):
    j, state = sw_lib.timeloop_theta(M, G, rhs_contr, ufl, ufr, ic, divett.params, annotate=False)
    return j + assemble(3.14*dot(state, state)*dx)
Пример #3
0
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()

J = assemble(dot(state, state)*dx)
ic = Function(W)
ic.interpolate(kelvin.InitialConditions(degree=1))
def compute_J(ic):
    state = sw_lib.timeloop_theta(M, G, ic.copy(deepcopy=True), kelvin.params, annotate=False)
    return assemble(dot(state, state)*dx)

h = Function(W)
Пример #4
0
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])
f_direct = assemble(dot(state, state) * dx)
for (adj_state, var) in compute_adjoint(J):
    pass

ic = Function(W)
ic.interpolate(kelvin.InitialConditions())