Repository navigation
|
I am struggling to use pymor to solve systems with non-linear elements. I am attempting to solve a simple harmonic oscillator but am uncertain on how to include a term with x**2. Is there a specific syntax for this? |
Answered by
pmli
May 16, 2023
Replies: 1 comment
|
Hi @Ub3rJosh, the For instance, to build import numpy as np
from pymor.algorithms.timestepping import ExplicitEulerTimeStepper
from pymor.models.basic import InstationaryModel
from pymor.operators.constructions import ZeroOperator
from pymor.operators.numpy import NumpyGenericOperator
from pymor.vectorarrays.numpy import NumpyVectorSpace
mapping = lambda x: np.hstack((x[..., 1], x[..., 0]**2))
T = 1
operator = NumpyGenericOperator(mapping, dim_source=2, dim_range=2)
initial_data = operator.source.zeros(1)
rhs = ZeroOperator(operator.range, NumpyVectorSpace(1))
time_stepper = ExplicitEulerTimeStepper(10)
m = InstationaryModel(T, initial_data, operator, rhs, time_stepper=time_stepper) |
0 replies
Answer selected by
Ub3rJosh
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @Ub3rJosh, the
SecondOrderModelonly supports linearOperators. For nonlinear time-dependent problems, you would need to use theInstationaryModelor define a newModelclass.For instance, to build$\ddot{x} = x^2$ , which is $\dot{x}_1 = x_2$ , $\dot{x}_2 = x_1^2$ in first-order form, this can be done with