How to...
WaterWaves1D.jl is meant to be versatile, and integrating new blocks to the package is easy. If you ever do so, please do not hesitate to contact the developers to either get help, or report on your advances.
build your model
Let us add the linear (Airy) water waves model whose equations are (using the notations introduced here)
\[ \left\{\begin{array}{l} ∂_tη+\frac{\tanh(\sqrt{μ} D)}{ν\sqrt{μ} D}∂_xv=0,\\[1ex] ∂_tv+∂_xη=0, \end{array}\right.\]
where we use the notation $F(D)$ for the action of pointwise multiplying by the function $F$ in the Fourier space.
In a dedicated file we write
export Airystruct Airy <: AbstractModel label :: String f! :: Function mapto :: Function mapfro :: Function # We build our model here.endOur purpose is to provide
label, a string used in subsequent informational messages, plots, etc.f!, a function to be called in explicit time-integration solvers such asEulerorRK4(one may provide other functions to be used with other solvers such asEulerSymp)mapto, a function which from a couple(η,v)of typeInitialDataprovides the raw data matrix on which computations are to be executedmapfro, a function which from raw data returns(η,v,x)whereηis the values of surface deformation at collocation pointsx;vis the derivative of the trace of the velocity potential atx.
To this aim, in place of the commented line, we write
function Airy(param::NamedTuple; # param is a NamedTuple containing all necessary parameters label = "linear (Airy)" # using a keyword argument allows the user to supersede the default label. ) # Set up μ = param.μ ν = get(param, :ν, min(1,1/√μ)) # set default ν if it is not provided # Collocation points and Fourier modes m = Mesh(param) x, k = m.x, m.k # Fourier multipliers ∂ₓ = 1im * k # Differentiation ∂ₓF₁ = 1im * tanh.(√μ*k)/(√μ*ν) # Pre-allocation fftη = zeros(Complex{Float64}, m.N) fftv = zeros(Complex{Float64}, m.N) # Evolution equations are ∂t U = f(U) function f!(U) fftη .= U[1] fftv .= U[2] U[1] .= -∂ₓF₁.*fftv U[2] .= -∂ₓ.*fftη end # Build raw data from physical data (discrete Fourier transform) function mapto(data::InitialData) U = [fft(data.η(x)) fft(data.v(x))] end # Return physical data `(η,v,x)` from raw data function mapfro(U) real(ifft(U[1])),real(ifft(U[2])),x end new( label, f!, mapto, mapfro )endA useful tool used in the above was the function Mesh. It takes as argument a NamedTuple containing typically a number of points/modes and the (half-)size of the domain and provides the vector of collocations points and Fourier wavenumbers (see this discussion).
The Airy model can now be built as follows
using WaterWaves1D# include your filemodel = Airy((μ=1,L=2π,N=2^8))build your initial data
The simplest way to build an initial data is to use the type Init, which takes as argument either
- a function
ηand a functionv(in this order); - an array of collocation points and two vectors representing
η(x)andv(x)(in this order); - a
mesh(generated withMesh) and two vectors representingη(mesh.x)andv(mesh.x)(in this order).
Some relevant initial data (e.g. travelling waves) are built-in; see the library section. You can build your own in the following lines.
struct Heap <: InitialData η v label :: String info :: String function Heap(L) η = x->exp.(-(L*x).^2) v = x->zero(x) init = Init(η,v) label = "Heap" info = "Heap of water, with length L=$L." new( init.η,init.v,label,info ) endendThe corresponding initial data can now be built as follows
using WaterWaves1D# include your fileinit = Heap(1)build your time solver
As an example, let us review how the explicit Euler solver, Euler, is built.
In a dedicated file we write
struct Euler{T,N} <: TimeSolver U1 :: Vector{Array{T,N}} label :: String function Euler( U :: Vector{Array{T, N}} ) where {T, N} U1 = deepcopy(U) new{T, N}( U1, "Euler" ) endendHere, Euler.U1 is a pre-allocated vector which can be used to speed-up calculations, and Euler-label is the string "Euler", used for future references. The type of data which the solver will take is either complex or real vectors.
T and N are the type parameters, T is the element type of the solution array (e.g. Float64, ComplexF64) and N the dimensionality of the solution array (1 for a vector, 2 for a matrix, ...)
The constructor's where {T, N} clause tells Julia to infer T and N from whatever array you actually pass in, and new{T,N}(...) builds the correctly parametrized instance.
We shall now add one method to the function step!, performing the explicit Euler step: that is replacing a vector U with U+dt*f(U) where f is provided by the model at stake.
export step!function step!(solver :: Euler, model :: AbstractModel, U , dt ) solver.U1 .= U # allocate U to U1 model.f!( solver.U1 ) # model.f!(U) replaces its argument U with f(U) U .+= dt .* solver.U1 # update Uendaccess to and manage your data
Once an initial-value problem problem has been solved (i.e. numerically integrated), the raw data is stored in problem.data.U, which is an array whose elements correspond (in chronological order) to values at the different computed times, problem.times.ts.
param = ( c = 1.1, ϵ = 1, μ = 1, N = 2^8, L = 16, T = 1, dt = 0.1)init = SolitaryWhitham(param)model = Airy(param)problem = Problem( model, init, param )solve!(problem; verbose=false)problem.data.U11-element Vector{Vector{Vector{ComplexF64}}}:
[[7.666279752905114 + 0.0im, -7.002608952054094 + 9.133738484642437e-10im, 5.49447877197345 - 1.4333285286771524e-9im, -3.928590087904742 + 1.5372549599717807e-9im, 2.6885226608788857 - 1.4026918724880705e-9im, -1.8119424679107856 + 1.1816879915763658e-9im, 1.2194337862673583 - 9.543318680245047e-10im, -0.8244860163977167 + 7.527853977871096e-10im, 0.5613249024834789 - 5.857261810987557e-10im, -0.3850334364887179 + 4.5199230215973344e-10im … 0.2660449757608595 + 3.4701090556068176e-10im, -0.38503343648871796 - 4.5199230485600475e-10im, 0.561324902483479 + 5.857262037454997e-10im, -0.8244860163977168 - 7.52785431467056e-10im, 1.2194337862673585 + 9.543318779434942e-10im, -1.8119424679107858 - 1.181687962468443e-9im, 2.6885226608788857 + 1.4026918178186332e-9im, -3.9285900879047424 - 1.537255169508347e-9im, 5.494478771973449 + 1.4333285430199028e-9im, -7.002608952054094 - 9.133737816159736e-10im], [7.418980406037193 + 0.0im, -6.762869498490986 + 8.821034309876048e-10im, 5.275526526412349 - 1.3762109873192106e-9im, -3.7389604467200126 + 1.4630556234103276e-9im, 2.531386111443549 - 1.3207108616198974e-9im, -1.6861880580844628 + 1.099676339839026e-9im, 1.1214100168794148 - 8.776164974343243e-10im, -0.7495384972661308 + 6.843547460636171e-10im, 0.5048065355835109 - 5.267495745142625e-10im, -0.342822154143422 + 4.024398894708559e-10im … 0.23472654909264049 + 3.061613632152658e-10im, -0.342822154143422 - 4.024399093347728e-10im, 0.5048065355835109 + 5.267495960973364e-10im, -0.7495384972661308 - 6.84354770551902e-10im, 1.1214100168794148 + 8.776165126817556e-10im, -1.6861880580844628 - 1.0996762834214515e-9im, 2.531386111443549 + 1.3207108753158432e-9im, -3.738960446720013 - 1.4630557515172436e-9im, 5.275526526412349 + 1.376211014282914e-9im, -6.762869498490985 - 8.821033763093476e-10im]]
[[7.666279752905114 + 0.0im, -7.001276215168337 + 0.13109975385088155im, 5.490447810424911 - 0.197090166103864im, -3.9224683614733347 + 0.197767105742955im, 2.6816018860523045 - 0.1658643293715663im, -1.8052418493767952 + 0.12695169795797395im, 1.2134992911488092 - 0.09257332581833944im, -0.8195065954933727 + 0.06580415270944713im, 0.5572863664031021 - 0.046187282728949605im, -0.3818287538106745 + 0.032248425697136256im … 0.26353796984541444 + 0.022494578025365277im, -0.38182875381067455 - 0.032248425697136256im, 0.5572863664031023 + 0.046187282728949626im, -0.8195065954933728 - 0.06580415270944716im, 1.2134992911488094 + 0.09257332581833945im, -1.8052418493767954 - 0.12695169795797392im, 2.6816018860523045 + 0.16586432937156625im, -3.922468361473335 - 0.19776710574295522im, 5.49044781042491 + 0.197090166103864im, -7.001276215168337 - 0.1310997538508815im], [7.418980406037193 + 0.0im, -6.761582388828596 + 0.1374871831111701im, 5.27165619666921 - 0.2157149065759647im, -3.7331342107048693 + 0.23129282839540607im, 2.524869836312886 - 0.2109748140678307im, -1.679952483156323 + 0.1776676243636019im, 1.1159525640831724 - 0.14342792288403117im, -0.7450117161834077 + 0.11309285448313607im, 0.5011746293100922 - 0.08796099859668574im, -0.339968801336605 + 0.06785199103874752im … 0.23251466421645586 + 0.052073467475830595im, -0.339968801336605 - 0.06785199103874755im, 0.5011746293100922 + 0.08796099859668578im, -0.7450117161834077 - 0.11309285448313613im, 1.1159525640831724 + 0.1434279228840312im, -1.679952483156323 - 0.17766762436360187im, 2.524869836312886 + 0.2109748140678307im, -3.7331342107048697 - 0.2312928283954062im, 5.27165619666921 + 0.21571490657596468im, -6.761582388828595 - 0.13748718311117006im]]
[[7.666279752905114 + 0.0im, -6.997278511843726 + 0.26214960496561857im, 5.478360840660887 - 0.39389114488289im, -3.904122262349203 + 0.39491786867807427im, 2.660875197657142 - 0.33087472393106876im, -1.7851895623143488 + 0.2529644522404303im, 1.1957535831879844 - 0.1842456162028093im, -0.8046284987820823 + 0.13081346627437462im, 0.5452288932323168 - 0.09170996223400694im, -0.3722680765400128 + 0.0639600353818062im … 0.2560642251924569 + 0.04456521205017951im, -0.37226807654001287 - 0.0639600353818062im, 0.5452288932323169 + 0.09170996223400696im, -0.8046284987820824 - 0.13081346627437468im, 1.1957535831879846 + 0.18424561620280933im, -1.785189562314349 - 0.2529644522404303im, 2.660875197657142 + 0.33087472393106876im, -3.9041222623492033 - 0.3949178686780745im, 5.478360840660886 + 0.39389114488289im, -6.997278511843726 - 0.2621496049656185im], [7.418980406037193 + 0.0im, -6.757721549808015 + 0.27492203220578515im, 5.26005088663012 - 0.43111329822862865im, -3.7156736618800053 + 0.4618648311280298im, 2.505354564234406 - 0.42086344726717706im, -1.661291886779449 + 0.3540212070516545im, 1.099633338764763 - 0.2854598325650316im, -0.731486069818293 + 0.22481967682534792im, 0.49033119218641125 - 0.17465629952513492im, -0.33145626272623324 + 0.13457450003955385im … 0.2259207178465101 + 0.10316553299265202im, -0.33145626272623324 - 0.13457450003955387im, 0.49033119218641125 + 0.174656299525135im, -0.731486069818293 - 0.22481967682534798im, 1.099633338764763 + 0.2854598325650317im, -1.661291886779449 - 0.3540212070516546im, 2.505354564234406 + 0.42086344726717706im, -3.7156736618800057 - 0.4618648311280299im, 5.26005088663012 + 0.43111329822862854im, -6.757721549808014 - 0.27492203220578515im]]
[[7.666279752905114 + 0.0im, -6.990617363766434 + 0.3930996714298969im, 5.458235597615399 - 0.5901141762054911im, -3.8736089661556274 + 0.590837869987834im, 2.626449304649907 - 0.49418164837148926im, -1.751933914622749 + 0.3771062667338838im, 1.16636938479224 - 0.27412460877118805im, -0.7800314364180377 + 0.19424270541052086im, 0.5253259813947807 - 0.13591300155213926im, -0.3565105539555579 + 0.09460695199276406im … 0.24376459536032866 + 0.06579595071710805im, -0.356510553955558 - 0.09460695199276406im, 0.5253259813947808 + 0.13591300155213926im, -0.7800314364180378 - 0.1942427054105209im, 1.1663693847922403 + 0.27412460877118805im, -1.7519339146227493 - 0.3771062667338838im, 2.626449304649907 + 0.49418164837148926im, -3.873608966155628 - 0.5908378699878343im, 5.458235597615398 + 0.5901141762054911im, -6.990617363766434 - 0.3930996714298968im], [7.418980406037193 + 0.0im, -6.751288451019376 + 0.41225223495202734im, 5.240727624500813 - 0.6458791272116844im, -3.686633216050934 + 0.6909974320119645im, 2.4729407673279082 - 0.6285853138482826im, -1.6303442838266462 + 0.5277564283195254im, 1.0726111791001218 - 0.42471330710672806im, -0.7091249322932294 + 0.3338309391219791im, 0.4724322535248575 - 0.2588384223196221im, -0.3174262400288753 + 0.19905685177285598im … 0.21506898246639067 + 0.1523132960307425im, -0.3174262400288753 - 0.199056851772856im, 0.4724322535248575 + 0.25883842231962223im, -0.7091249322932294 - 0.33383093912197914im, 1.0726111791001218 + 0.4247133071067282im, -1.6303442838266462 - 0.5277564283195255im, 2.4729407673279082 + 0.6285853138482826im, -3.6866332160509345 - 0.6909974320119646im, 5.240727624500813 + 0.6458791272116842im, -6.751288451019375 - 0.41225223495202734im]]
[[7.666279752905114 + 0.0im, -6.981295306436494 + 0.5239001083980673im, 5.430101610596593 - 0.7854713465158193im, -3.8310235675856763 + 0.7849165249863342im, 2.57850144473914 - 0.654944336101343im, -1.7057208669859572 + 0.4984589817225644im, 1.1256326979455171 - 0.3613354946975015im, -0.7460125122265507 + 0.2553257195410103im, 0.49786401934737917 - 0.17816035180474424im, -0.334818489203638 + 0.12367902113612969im … 0.22687088440131498 + 0.08578667135480528im, -0.33481848920363805 - 0.12367902113612969im, 0.4978640193473793 + 0.17816035180474424im, -0.7460125122265509 - 0.25532571954101035im, 1.1256326979455173 + 0.3613354946975015im, -1.7057208669859574 - 0.4984589817225644im, 2.57850144473914 + 0.654944336101343im, -3.8310235675856767 - 0.7849165249863345im, 5.4301016105965925 + 0.7854713465158193im, -6.981295306436494 - 0.5239001083980672im], [7.418980406037193 + 0.0im, -6.74228554115801 + 0.5494255179685713im, 5.2137147628612075 - 0.8596972725473323im, -3.6461033777722984 + 0.917976539294429im, 2.427795324259041 - 0.8330709820871671im, -1.5873385645501756 + 0.6975883328761271im, 1.0351490969015968 - 0.5598329667357662im, -0.6781984000692773 + 0.4388099135889358im, 0.4477353660626894 - 0.33929604880773767im, -0.29811228005221296 + 0.2602256607662404im … 0.20016397449405257 + 0.19859049893388145im, -0.29811228005221296 - 0.26022566076624043im, 0.4477353660626894 + 0.3392960488077378im, -0.6781984000692773 - 0.43880991358893584im, 1.0351490969015968 + 0.5598329667357663im, -1.5873385645501756 - 0.6975883328761272im, 2.427795324259041 + 0.8330709820871671im, -3.646103377772299 - 0.9179765392944291im, 5.2137147628612075 + 0.8596972725473321im, -6.742285541158009 - 0.5494255179685713im]]
[[7.666279752905114 + 0.0im, -6.969315888202691 + 0.6545011279794661im, 5.394000159959062 - 0.9796760127160544im, -3.776498784039578 + 0.9765489875437323im, 2.517278471897672 - 0.8123351192357862im, -1.6468922137332207 + 0.6161250658300689im, 1.073940020496712 - 0.44502943434214426im, -0.7029826350363608 + 0.31332469774664223im, 0.46323816465817624 - 0.21784410505394894im, -0.3075529729428909 + 0.15069230366430172im … 0.20570147818393747 + 0.10416062119077281im, -0.30755297294289097 - 0.15069230366430172im, 0.4632381646581763 + 0.21784410505394894im, -0.7029826350363609 - 0.3133246977466423im, 1.0739400204967122 + 0.44502943434214426im, -1.646892213733221 - 0.6161250658300689im, 2.517278471897672 + 0.8123351192357862im, -3.7764987840395783 - 0.9765489875437326im, 5.394000159959061 + 0.9796760127160544im, -6.969315888202691 - 0.654501127979466im], [7.418980406037193 + 0.0im, -6.730716247092376 + 0.6863896676040324im, 5.179051937064312 - 1.072254003772279im, -3.594210458290409 + 1.1420947725857769im, 2.3701506610838905 - 1.0332676814504307im, -1.5325928016962764 + 0.8622608345838887im, 0.9876117176740256 - 0.689503666880859im, -0.639080029495885 + 0.53848857776939im, 0.416595899965063 - 0.41487145360523625im, -0.27383588702411193 + 0.317062699485297im … 0.1814865998784674 + 0.24112498382376055im, -0.27383588702411193 - 0.31706269948529703im, 0.416595899965063 + 0.41487145360523636im, -0.639080029495885 - 0.53848857776939im, 0.9876117176740256 + 0.6895036668808591im, -1.5325928016962764 - 0.8622608345838889im, 2.3701506610838905 + 1.0332676814504307im, -3.5942104582904095 - 1.142094772585777im, 5.179051937064312 + 1.0722540037722788im, -6.730716247092375 - 0.6863896676040324im]]
[[7.666279752905114 + 0.0im, -6.954683668911912 + 0.7848530181896827im, 5.349984216534129 - 1.1724432227512511im, -3.710204542010925 + 1.1651380350892122im, 2.443095585463696 - 0.9655436897478651im, -1.5758830549087717 + 0.7292342542109471im, 1.011794486971402 - 0.5243918191646685im, -0.6514615553814257 + 0.3675390806534301im, 0.421946657977742 - 0.25439324164554883im, -0.27516787255344066 + 0.17519713141830692im … 0.18065534396110564 + 0.12057151777831043im, -0.2751678725534407 - 0.17519713141830692im, 0.42194665797774206 + 0.25439324164554883im, -0.6514615553814258 - 0.36753908065343016im, 1.0117944869714022 + 0.5243918191646685im, -1.575883054908772 - 0.7292342542109471im, 2.443095585463696 + 0.9655436897478651im, -3.710204542010925 - 1.1651380350892127im, 5.3499842165341285 + 1.1724432227512511im, -6.954683668911912 - 0.7848530181896824im], [7.418980406037193 + 0.0im, -6.716584972559662 + 0.8230925498115762im, 5.136790007080184 - 1.283237441267254im, -3.531116181894229 + 1.3626536674104868im, 2.3003035546304966 - 1.228144722661147im, -1.466511898021041 + 1.0205560065411414im, 0.9304617316459911 - 0.81246329871749im, -0.5922423246869548 + 0.6316629307526618im, 0.3794619293080164 - 0.48447716292296206im, -0.24500117076582603 + 0.3686218479412523im … 0.1593888600298507 + 0.2791151296211729im, -0.24500117076582603 - 0.36862184794125236im, 0.3794619293080164 + 0.48447716292296217im, -0.5922423246869547 - 0.6316629307526618im, 0.9304617316459911 + 0.8124632987174902im, -1.466511898021041 - 1.0205560065411414im, 2.3003035546304966 + 1.228144722661147im, -3.5311161818942294 - 1.362653667410487im, 5.136790007080184 + 1.2832374412672538im, -6.716584972559661 - 0.8230925498115762im]]
[[7.666279752905114 + 0.0im, -6.93740421817349 + 0.9149061618729335im, 5.298118363906959 - 1.3634901337129568im, -3.6323474475107402 + 1.3500959298551298im, 2.3563347073737178 - 1.1137812712445594im, -1.4932185782473082 + 0.8369499850774804im, 0.939800971469136 - 0.5986502004588512im, -0.5920715875230327 + 0.4173140223650642im, 0.3745836537216556 - 0.28728184675655655im, -0.23820227696732812 + 0.19678559248817104im … 0.1522045112707498 + 0.13471007516720682im, -0.23820227696732818 - 0.19678559248817104im, 0.3745836537216556 + 0.28728184675655655im, -0.5920715875230328 - 0.4173140223650642im, 0.9398009714691362 + 0.5986502004588512im, -1.4932185782473084 - 0.8369499850774804im, 2.3563347073737178 + 1.1137812712445594im, -3.6323474475107402 - 1.3500959298551305im, 5.2981183639069585 + 1.3634901337129568im, -6.93740421817349 - 0.9149061618729333im], [7.418980406037193 + 0.0im, -6.699897096489541 + 0.9594821299932264im, 5.086990982870261 - 1.4923380138708269im, -3.45701718190161 + 1.5789658519717045im, 2.218613604577955 - 1.4166988040819803im, -1.3895845916067469 + 1.1713030889366316im, 0.8642553903190412 - 0.9275150735057259im, -0.5382510302243894 + 0.7172075360877395im, 0.3368677846211818 - 0.5471116025047629im, -0.21208811979696612 + 0.4140448429814557im … 0.1342872178576976 + 0.31184495970174925im, -0.21208811979696612 - 0.4140448429814558im, 0.3368677846211818 + 0.547111602504763im, -0.5382510302243892 - 0.7172075360877395im, 0.8642553903190412 + 0.9275150735057262im, -1.3895845916067469 - 1.1713030889366316im, 2.218613604577955 + 1.4166988040819803im, -3.4570171819016102 - 1.578965851971705im, 5.086990982870261 + 1.4923380138708264im, -6.69989709648954 - 0.9594821299932264im]]
[[7.666279752905114 + 0.0im, -6.917484113239186 + 1.0446110555883417im, 5.238478703654545 - 1.5525364268481279im, -3.5431701421798243 + 1.5308462505617693im, 2.257442515882023 - 1.2562846798897196im, -1.3995101748559542 + 0.9384755869567439im, 0.8586602003107069 - 0.6670818077381997im, -0.5255300926228534 + 0.4620483002301157im, 0.32183067062540277 - 0.3160366779173608im, -0.1972715228850998 + 0.21509832139026547im … 0.1208851758769443 + 0.14630983282347515im, -0.19727152288509986 - 0.21509832139026547im, 0.32183067062540277 + 0.3160366779173608im, -0.5255300926228534 - 0.4620483002301157im, 0.8586602003107071 + 0.6670818077381997im, -1.3995101748559544 - 0.9384755869567439im, 2.257442515882023 + 1.2562846798897196im, -3.5431701421798243 - 1.53084625056177im, 5.238478703654544 + 1.5525364268481279im, -6.917484113239186 - 1.0446110555883414im], [7.418980406037193 + 0.0im, -6.680658970956735 + 1.0955064928063196im, 5.029727933401562 - 1.6992489131060744im, -3.3721443878515407 + 1.7903571893454524im, 2.12550138209942 - 1.5979591770962336im, -1.302379841127497 + 1.3133871480535755im, 0.7896370923677999 - 1.033539171155413im, -0.47775829762657596 + 0.7940891157301615im, 0.289426364264408 - 0.6018735095342205im, -0.17564461134950912 + 0.45257556509707986im … 0.1066547489429763 + 0.33869763546161497im, -0.17564461134950912 - 0.4525755650970799im, 0.289426364264408 + 0.6018735095342205im, -0.47775829762657585 - 0.7940891157301615im, 0.7896370923677999 + 1.0335391711554132im, -1.302379841127497 - 1.3133871480535755im, 2.12550138209942 + 1.5979591770962336im, -3.372144387851541 - 1.7903571893454528im, 5.029727933401562 + 1.699248913106074im, -6.680658970956734 - 1.0955064928063196im]]
[[7.666279752905114 + 0.0im, -6.894930936499623 + 1.1739183284529306im, 5.1711527436836064 - 1.73930471886441im, -3.4429505470960655 + 1.7068256888342628im, 2.146928145889821 - 1.3923202535667114im, -1.2954509173313304 + 1.0330601709166602im, 0.7691619317381113 - 0.7290205835940655im, -0.4526408138614017 + 0.5012015769033104im, 0.26444678519189674 - 0.3402439746174934im, -0.15305695175796824 + 0.22983048113107754im … 0.0872875944102319 + 0.15515217744411258im, -0.1530569517579683 - 0.22983048113107754im, 0.26444678519189674 + 0.3402439746174934im, -0.4526408138614017 - 0.5012015769033104im, 0.7691619317381115 + 0.7290205835940655im, -1.2954509173313307 - 1.0330601709166602im, 2.146928145889821 + 1.3923202535667114im, -3.4429505470960655 - 1.7068256888342634im, 5.171152743683606 + 1.73930471886441im, -6.894930936499623 - 1.1739183284529302im], [7.418980406037193 + 0.0im, -6.658877918763163 + 1.2311138619245658im, 4.965084879434269 - 1.9036665433536273im, -3.2767623058122215 + 1.996168878428354im, 2.021446264600507 - 1.7709926438934693im, -1.205542617798945 + 1.4457573223807807im, 0.7073331115874186 - 1.1295036396411282im, -0.4114948081228599 + 0.8613790308233937im, 0.237820315271929 - 0.6479749011336052im, -0.13627729129377014 + 0.48357262492718384im … 0.07701222576665095 + 0.35916708148813786im, -0.13627729129377014 - 0.4835726249271839im, 0.237820315271929 + 0.6479749011336052im, -0.41149480812285977 - 0.8613790308233937im, 0.7073331115874186 + 1.1295036396411284im, -1.205542617798945 - 1.4457573223807807im, 2.021446264600507 + 1.7709926438934693im, -3.276762305812222 - 1.9961688784283544im, 4.965084879434269 + 1.9036665433536268im, -6.658877918763162 - 1.2311138619245658im]]
[[7.666279752905114 + 0.0im, -6.869753272598125 + 1.302778760934162im, 5.096239269832245 - 1.9235209689282842im, -3.3320009966333815 + 1.8774858047531424im, 2.0253605677236513 - 1.5211876290519344im, -1.181810433755836 + 1.1200041841818154im, 0.6721772690504506 - 0.7838636665547972im, -0.3742841681635022 + 0.5343009269837269im, 0.20325770914068644 - 0.35955541200986335im, -0.10629456804286866 + 0.24073683757887365im … 0.052044960156796084 + 0.16107046302388656im, -0.10629456804286871 - 0.24073683757887365im, 0.20325770914068644 + 0.35955541200986335im, -0.3742841681635022 - 0.5343009269837269im, 0.6721772690504507 + 0.7838636665547972im, -1.1818104337558362 - 1.1200041841818154im, 2.0253605677236513 + 1.5211876290519344im, -3.3320009966333815 - 1.877485804753143im, 5.096239269832244 + 1.9235209689282842im, -6.869753272598125 - 1.3027787609341615im], [7.418980406037193 + 0.0im, -6.634562230650589 + 1.3662526197461948im, 4.89315667023999 - 2.1052909673105624im, -3.171168194047885 + 2.1957595070912754im, 1.906983967700693 - 1.934908361929188im, -1.0997891351350841 + 1.5674345948421466im, 0.6181445279354254 - 1.2144744391808753im, -0.3402609468816546 + 0.9182644985615667im, 0.18279221056523318 - 0.6847524128480398im, -0.09464147579091484 + 0.5065200399418829im … 0.045918303024726506 + 0.37286752324345585im, -0.09464147579091484 - 0.506520039941883im, 0.18279221056523318 + 0.6847524128480398im, -0.3402609468816545 - 0.9182644985615667im, 0.6181445279354254 + 1.2144744391808755im, -1.0997891351350841 - 1.5674345948421466im, 1.906983967700693 + 1.934908361929188im, -3.1711681940478855 - 2.195759507091276im, 4.89315667023999 + 2.105290967310562im, -6.634562230650588 - 1.3662526197461948im]]Physical data (say at final computed time) can be reconstructed using the model as follows:
η,v,x = problem.model.mapfro(last(problem.data.U))([1.3452999698737589e-5, 1.2648564815018193e-5, 1.1943588067414579e-5, 1.1332528165167166e-5, 1.0810582323633744e-5, 1.0373648567388316e-5, 1.0018293546992796e-5, 9.741725616158048e-6, 9.54177295943437e-6, 9.416866602968144e-6 … 2.8821704217644756e-5, 2.6515672474047435e-5, 2.4418100211098977e-5, 2.2512500837691338e-5, 2.0783896157675757e-5, 1.9218698792657085e-5, 1.7804605511088922e-5, 1.653050062875791e-5, 1.538636872894239e-5, 1.436321601783197e-5], [1.3452888212639458e-5, 1.2797168140343818e-5, 1.224207055065818e-5, 1.1783230465495231e-5, 1.1417039625857828e-5, 1.114061811259559e-5, 1.09517916888624e-5, 1.0849074691454685e-5, 1.0831658321136528e-5, 1.0899404252029399e-5 … 2.71342930944201e-5, 2.50326230496669e-5, 2.3127772695689507e-5, 2.140476688537404e-5, 1.985005975398916e-5, 1.845142831639196e-5, 1.7197876421645372e-5, 1.6079548363585883e-5, 1.5087651423169313e-5, 1.4214386778513971e-5], [-16.0, -15.875, -15.75, -15.625, -15.5, -15.375, -15.25, -15.125, -15.0, -14.875 … 14.75, 14.875, 15.0, 15.125, 15.25, 15.375, 15.5, 15.625, 15.75, 15.875])where η and v are respectively the values of the surface deformation and of the derivative of the trace of the velocity potential at the surface, at collocation points x.
This procedure is carried out by the function solution, which allows in addition to perform some interpolations (making use of the otherwise helpful function interpolate).
η,v,x = solution(problem)([1.3452999698737589e-5, 1.2648564815018193e-5, 1.1943588067414579e-5, 1.1332528165167166e-5, 1.0810582323633744e-5, 1.0373648567388316e-5, 1.0018293546992796e-5, 9.741725616158048e-6, 9.54177295943437e-6, 9.416866602968144e-6 … 2.8821704217644756e-5, 2.6515672474047435e-5, 2.4418100211098977e-5, 2.2512500837691338e-5, 2.0783896157675757e-5, 1.9218698792657085e-5, 1.7804605511088922e-5, 1.653050062875791e-5, 1.538636872894239e-5, 1.436321601783197e-5], [1.3452888212639458e-5, 1.2797168140343818e-5, 1.224207055065818e-5, 1.1783230465495231e-5, 1.1417039625857828e-5, 1.114061811259559e-5, 1.09517916888624e-5, 1.0849074691454685e-5, 1.0831658321136528e-5, 1.0899404252029399e-5 … 2.71342930944201e-5, 2.50326230496669e-5, 2.3127772695689507e-5, 2.140476688537404e-5, 1.985005975398916e-5, 1.845142831639196e-5, 1.7197876421645372e-5, 1.6079548363585883e-5, 1.5087651423169313e-5, 1.4214386778513971e-5], [-16.0, -15.875, -15.75, -15.625, -15.5, -15.375, -15.25, -15.125, -15.0, -14.875 … 14.75, 14.875, 15.0, 15.125, 15.25, 15.375, 15.5, 15.625, 15.75, 15.875], 1.0)Using (η,v,x) one can compute other quantities such as the mass, momentum, energy; for instance for the purpose of testing how well these quantities are numerically perserved (when the quantities are first integrals of the considered model). Built-in functions mass, momentum, energy (and mass_diff, momentum_diff, energy_diff) compute such quantities (or their variation).
plot your data
Once (η,v,x) is obtained as above, producing plots is as simple as
using Plotsplot(x, [ η v ], label = ["η" "v"])One can also plot the amplitude of discrete Fourier coefficients (in semi-log scale) as follows:
using FFTWk=fftshift(Mesh(x).k);fftη=fftshift(fft(η));fftv=fftshift(fft(v));indices = (fftη .!=0) .& (fftv .!=0 )plot(k[indices], [ abs.(fftη)[indices] abs.(fftv)[indices] ], yscale=:log10)Built-in plot recipes provide convenient ways of producing such plots, and animations.
plot(problem;var=[:surface,:velocity,:fourier])save and load your data
Thanks to the package HDF5.jl it is possible to save (raw) data to a local file, and then load them for future analyses.
Built-in functions ease the process. Here is a typical example.
Build and solve a problem.
param = ( c = 1.1, ϵ = 1, μ = 1, N = 2^8, L = 16, T = 1, dt = 0.1)init = SolitaryWhitham(param)model = Airy(param)problem = Problem( model, init, param )solve!(problem; verbose=false)[ Info: Converged : relative error 3.472628630637235e-15 in 4 stepsSave the initial data.
x = Mesh(param).xdump("file_name", x, init)Save the time-integrated (raw) data.
dump("file_name", problem) # or dump("file_name", problem.data)Reconstruct the problem, without solving it.
loaded_init = load_init("file_name") # load initial datanew_problem = Problem( model, loaded_init, param ) # re-build problemload_data!("file_name", new_problem) # incorporate time-integrated dataproblem.data == new_problem.datatrue