Hi, I’m trying to solve a system of two coupled equations. The system (the Hopf oscillator), has two coefficients: a and w. I have succesfully trained a model capable of solve the system for a=0.6 and w=1, but now I want to parameterize it with respect to a in the range (-1,1).
Following a tutorial (Parameterized 3D Heat Sink - NVIDIA Docs), I’ve modified my scripts to add the parameterization but it seem like I’m not getting the desired output.
Can someone tell me what I’m doing wrong? And also, how can I plot the results?
class Hopf(PDE):
name = "Hopf"
def __init__(self, a=0.6, w=1):
self.a = a
self.a = w
t = Symbol("t")
input_variables = {"t": t}
x = Function("x")(*input_variables)
y = Function("y")(*input_variables)
if type(a) is str:
a = Function(a)(*input_variables)
elif type(a) in [float, int]:
a = Number(a)
if type(w) is str:
w = Function(w)(*input_variables)
elif type(w) in [float, int]:
w = Number(w)
self.equations = {}
self.equations["ode_x"] = x.diff(t)-(a*x - w*y - x*(x**2 + y**2))
self.equations["ode_y"] = y.diff(t)-(a*y + w*x - y*(x**2 + y**2))
@modulus.sym.main(config_path="conf", config_name="config")
def run(cfg: ModulusConfig) -> None:
# make list of nodes to unroll graph on
a, w = 0.6, 1
hopf = Hopf(a=a, w=w)
hopf_net = instantiate_arch(
input_keys=[Key("t"), Key("a")],
output_keys=[Key("x"), Key("y")],
cfg=cfg.arch.fully_connected,
activation_fn=Activation.SIN
)
nodes = hopf.make_nodes() + [hopf_net.make_node(name="hopf_network")]
# add constraints to solver
# make geometry
geo = Point1D(0)
t_min = 0.0
t_max = 20.0
t_symbol = Symbol("t")
a_symbol = Symbol("a")
x = Symbol("x")
y = Symbol("y")
time_range = {t_symbol: (t_min, t_max)}
ic_param = {t_symbol: 0, a_symbol: (-1.0, 1.0)}
initial_param = {t_symbol: (t_min, t_max), a_symbol: (-1.0, 1.0)}
# make domain
domain = Domain()
# initial conditions
IC = PointwiseBoundaryConstraint(
nodes=nodes,
geometry=geo,
outvar={"x": 1.0, "y": 0},
batch_size=cfg.batch_size.IC,
# parameterization={t_symbol: 0},
parameterization=ic_param,
)
domain.add_constraint(IC, name="IC")
# solve over given time period
interior = PointwiseBoundaryConstraint(
nodes=nodes,
geometry=geo,
outvar={"ode_x": 0.0, "ode_y": 0.0},
batch_size=cfg.batch_size.interior,
# parameterization=time_range,
parameterization=initial_param,
)
domain.add_constraint(interior, "interior")
# make solver
slv = Solver(cfg, domain)
# start solver
slv.solve()
Thank you!