Here is a simple example to get started with SpectraVVave:
We first import the relevant bits in SpectraVVave:
from travwave.diagram import BifurcationDiagram
import travwave.equations as teq
import travwave.boundary as tbc
Define the half length of the travelling wave:
length = 30
Which equation are we solving. Look in the travwave/equations
folder, or implement your own equation. Here we choose the KDV equation.
equation = teq.kdv.KDV(length)
Which boundary condition are we using? You will find some possible boundary conditions in travwave/bounday
, or you can implement your own. Here we use the Minimum
boundary condition, which enforces the minimum to be at zero.
boundary_cond = tbc.Minimum()
Setup the diagram object, initialize and run it:
bd = BifurcationDiagram(equation, boundary_cond)
# initialize it with default parameters
bd.initialize()
# run for fifty steps
bd.navigation.run(50)
Let us see what the amplitude reached is:
print('Amplitude = ', bd.navigation[-1]['parameter'][bd.navigation.amplitude_])
We plot the current computed solution, at coarse resolution:
bd.plot_solution(bd.navigation[-1]['solution'])
We refine to get a higher resolution travelling wave:
new_size = 500
refined, v, parameter = bd.navigation.refine_at(new_size)
and we plot that refined solution:
bd.plot_solution(refined)
We plot the bifurcation diagram, as well as the last refined parameter:
bd.nplot_diagram()
plt.plot(parameter[0], parameter[1], 'or')