OK I simplified my code, so now it just requires the following commands for
wave on square + dirichlet (PDEs on disks/cylinders will come soon..):
using GLPlot, GLAbstraction, ModernGL, ApproxFun
h = 0.005
#
u0 =
TensorFun((x,y)->exp(-50x.^2-40(y-.1).^2)+.5exp(-30(x+.5).^2-40(y+.2).^2))
d = domain(u0)
B= dirichlet(d) # dirichlet boundary conditions, try neumann(d). mixed is
also possible
SBE = schurfact([B,I-h^2*lap(d)],100) # backward euler for first 2
time steps
SBDF = schurfact([B,I-4.0/9.0*h^2*lap(d)],100) # BDF formula for subsequent
itme steps
u = Array(TensorFun,10000)
u[1] = u0;u[2] = u0
n=3;u[n] = SBE\[zeros(4),2u[n-1]-u[n-2]]
n=4;u[n] = SBE\[zeros(4),2u[n-1]-u[n-2]]
N=90; xx =-1.:2/N:1.;yy = xx #grid for plotting
obj,window=ApproxFun.plot(xx,yy,u[n])#first plot creates window
m = 5000 # number of time steps
for k=n+1:n+m
u[k] = SBDF\[zeros(4),1/9.0*(24u[k-1]-22u[k-2]+8u[k-3]-u[k-4])]
ApproxFun.plot(xx,yy,u[k],obj,window)#updates window
if GLFW.WindowShouldClose(window.glfwWindow)
m=k-n
GLFW.Terminate()
break
end
end
n+=m
On 3 Sep 2014, at 11:28 am, Sheehan Olver <[email protected]> wrote:
>
> Works great, see attached. (I had to go to (1+h)π as otherwise there
> was a wedge missing from the plot)
>
>
> using GLPlot, GLAbstraction, ModernGL
>
>
> window = createdisplay(w=1000,h=1000,eyeposition=Vec3(1.,1.,1.),
> lookat=Vec3(0.,0.,0.));
> color = Vec4(1,0,0,1)
> n=100
> h=1./n
> r=h:h:1.
> t=(-1:h:1+h)*π
> x=float32(r*cos(t)')
> y=float32(r*sin(t)')
>
> f(x,y) = exp(-10x.^2-20y.^2) # arbitrary function of f
> z = Vec1[Vec1(f(x[k,j],y[k,j])) for k=1:size(x,1),j=1:size(x,2)]
> obj = glplot(z, xrange=x, yrange=y, color=color)
> render(obj)
> yield()
> GLFW.SwapBuffers(window.glfwWindow)
> renderloop(window)
>
> <PastedGraphic-3.png>
>
> On 3 Sep 2014, at 10:41 am, Simon Danisch <[email protected]> wrote:
>
>> I see... I'll look into this tomorrow.
>> For now, I updated the code, so that you can use non uniform grids. I'm not
>> sure how well it works, you need to try it out for yourself:
>>
>> color = Vec4(1,0,0,1)
>> h=.01
>> r=h:h:1.
>> t=-π:h*π:π-h
>> x=float32(r*cos(t)')
>> y=float32(r*sin(t)')
>>
>> f(x,y) = exp(-10x.^2-20y.^2) # arbitrary function of f
>> z = Vec1[Vec1(f(x[k,j],y[k,j])) for k=1:size(x,1),j=1:size(x,2)]
>> obj = glplot(z, xrange=x, yrange=y, color=color)
>> # could also be glplot(z, xrange=-1:2, yrange=0:3, color=color)
>>
>>
>> 2014-09-03 2:23 GMT+02:00 Sheehan Olver <[email protected]>:
>>
>> Yep, here's the same code working on my office machine (iMac), which is
>> successfully using the whole window. Maybe it's a video card issue? Let me
>> know if there's anything I can do to debug this.
>>
>> <PastedGraphic-2.png>
>>
>> On 3 Sep 2014, at 9:35 am, Simon Danisch <[email protected]> wrote:
>>
>>> Good to hear =)
>>> The plot does look really weird... Should it look like the other plots?
>>>
>>>
>>>
>>> 2014-09-03 0:51 GMT+02:00 Sheehan Olver <[email protected]>:
>>> I tried Interact.jl, and it's really fun! Here is code that does a contour
>>> plot of Helmholtz with a slider for different wave numbers, where ny is the
>>> discretization in y. (nx = ∞, which means adaptive).
>>>
>>>
>>> Pkg.add(“Interact”)
>>> Pkg.add(“Gadfly”)
>>> Pkg.add(“ApproxFun”)
>>> Pkg.checkout(“ApproxFun”)
>>> using ApproxFun,Interact
>>>
>>>
>>> d=Interval()⊗Interval()
>>> B=dirichlet(d)
>>> Δ=lap(d)
>>>
>>> @manipulate for k=-100.0:.01:2000.0,ny=10:200
>>> contour(pdesolve([B,Δ+k*I],[1.,1.,1.,1.],ny))
>>> end
>>>
>>>
>>> On 1 Sep 2014, at 8:21 pm, Shashi Gowda <[email protected]> wrote:
>>>
>>>> @Sheehan
>>>>
>>>> There is now Interact.jl (Pkg.add("Interact")) which lets you travel your
>>>> for-loops with sliders and such widgets, to put it one way. Here's an
>>>> example notebook showing how you can do interactive plotting with Gadfly
>>>> or PyPlot:
>>>> http://nbviewer.ipython.org/github/JuliaLang/Interact.jl/blob/master/doc/notebooks/Interactive%20Plotting.ipynb
>>>>
>>>>
>>>>
>>>> On Mon, Sep 1, 2014 at 12:28 PM, Sheehan Olver <[email protected]>
>>>> wrote:
>>>>
>>>> Got GLPlot working, it's awesome! The following does a movie of a
>>>> solution to wave equation on a square using latest version of ApproxFun
>>>> (the color is weird since I haven't figured that part out yet):
>>>>
>>>>
>>>>
>>>> window = createdisplay(w=1000,h=1000,eyeposition=Vec3(1,1,1),
>>>> lookat=Vec3(0))
>>>>
>>>> function zcolor(i, j, t)
>>>> x = float32(i - 0.5)
>>>> z = float32(j - 0.5)
>>>> radius = sqrt((x * x) + (z * z))
>>>>
>>>> r = sin(10.0f0 * radius + t)
>>>> g = cos(10.0f0 * radius + t)
>>>> b = radius
>>>> return Vec4(r,g,b, 1)
>>>> end
>>>> yy=xx=-1.:.05:1.
>>>> N=length(xx)
>>>> color = [zcolor(i/N, j/N, 15) for i=1:N, j=1:N];
>>>>
>>>>
>>>> h=0.01;
>>>> u0=TensorFun((x,y)->exp(-10x.^2-20(y-.1).^2))
>>>> d=Interval()⊗Interval()
>>>> L=I-h^2*lap(d);
>>>> B=dirichlet(d);
>>>> S=schurfact([B,L],80);
>>>>
>>>> u=Array(TensorFun,10000)
>>>> u[1]=u0
>>>> u[2]=u0
>>>> n=2;
>>>>
>>>>
>>>> GLPlot.glClearColor(1,1,1,0)
>>>> m=400
>>>> for k=n+1:n+m
>>>> u[k]=(S\[zeros(4),2u[k-1]-u[k-2]])
>>>> vals=[u[k][x,y] for x in xx,y in yy];
>>>> texdata=map(Vec1,vals)
>>>> obj = glplot(texdata, primitive=SURFACE(), color=color);
>>>> GLPlot.glClear(GLPlot.GL_COLOR_BUFFER_BIT | GLPlot.GL_DEPTH_BUFFER_BIT)
>>>> render(obj)
>>>> yield()
>>>> GLFW.SwapBuffers(window.glfwWindow)
>>>> end
>>>> n+=m
>>>>
>>>> On 21 Aug 2014, at 9:51 am, Simon Danisch <[email protected]> wrote:
>>>>
>>>>> Good to hear.
>>>>> The test looks funny, as I overlay everything GLPlot is able to do ;)
>>>>> I should remove example.jl, as it uses legacy code.
>>>>> I'm not sure about the surface example, though... Did you change anything?
>>>>> This might be due to a change of the output from imread (Images.jl) and
>>>>> shouldn't be a problem if you use your own arrays.
>>>>> I'll have a look at this tomorrow...
>>>>>
>>>>>
>>>>> 2014-08-20 23:58 GMT+02:00 Sheehan Olver <[email protected]>:
>>>>> OK I rebuilt julia and cleared my .julia folder, which seems to have
>>>>> cleared that issue. Pkg.test(“GLPlot”) seems to work, though the output
>>>>> looks funny. I also get the following:
>>>>>
>>>>> julia> include("surface.jl")
>>>>> INFO: loaded GLFW 3.0.4 Cocoa NSGL chdir menubar dynamic from
>>>>> /Users/solver/.julia/v0.4/GLFW/deps/usr64/lib/libglfw
>>>>> ERROR: Color Format RGBA not supported
>>>>> in error at error.jl:21
>>>>> in Texture at
>>>>> /Users/solver/.julia/v0.4/GLAbstraction/src/GLTexture.jl:156
>>>>> in include at ./boot.jl:245
>>>>> in include_from_node1 at ./loading.jl:128
>>>>> while loading /Users/solver/.julia/v0.4/GLPlot/example/surface.jl, in
>>>>> expression starting on line 24
>>>>>
>>>>> julia> include("example.jl")
>>>>> INFO: loaded GLFW 3.0.4 Cocoa NSGL chdir menubar dynamic from
>>>>> /Users/solver/.julia/v0.4/GLFW/deps/usr64/lib/libglfw
>>>>> ERROR: Cam not defined
>>>>> in include at ./boot.jl:245
>>>>> in include_from_node1 at ./loading.jl:128
>>>>> while loading /Users/solver/.julia/v0.4/GLPlot/example/example.jl, in
>>>>> expression starting on line 25
>>>>>
>>>>>
>>>>> On 20 Aug 2014, at 9:37 pm, Tim Holy <[email protected]> wrote:
>>>>>
>>>>> > You might need a Pkg.update(), or Pkg.build("Images") if the update
>>>>> > doesn't
>>>>> > solve it.
>>>>> >
>>>>> > --Tim
>>>>> >
>>>>> > On Wednesday, August 20, 2014 09:23:16 PM Sheehan Olver wrote:
>>>>> >> OK Now I get
>>>>> >>
>>>>> >> could not open file
>>>>> >> /Users/solver/.julia/v0.3/Images/src/ioformats/../../deps/deps.jl while
>>>>> >> loading
>>>>> >> /Users/solver/.julia/v0.3/Images/src/ioformats/libmagickwand.jl, in
>>>>> >> expression starting on line 24 while loading
>>>>> >> /Users/solver/.julia/v0.3/Images/src/Images.jl, in expression starting
>>>>> >> on
>>>>> >> line 38 while loading
>>>>> >> /Users/solver/.julia/v0.3/GLAbstraction/src/GLTexture.jl, in expression
>>>>> >> starting on line 1 while loading
>>>>> >> /Users/solver/.julia/v0.3/GLAbstraction/src/GLTypes.jl, in expression
>>>>> >> starting on line 40 while loading
>>>>> >> /Users/solver/.julia/v0.3/GLAbstraction/src/GLAbstraction.jl, in
>>>>> >> expression
>>>>> >> starting on line 8
>>>>> >> On 20 Aug 2014, at 9:06 pm, Simon Danisch <[email protected]> wrote:
>>>>> >>> Yes I do =)
>>>>> >>> You need to install Images.jl properly with its dependency.
>>>>> >>> https://github.com/timholy/Images.jl
>>>>> >>> I should at some point load this conditional, as you don't really need
>>>>> >>> Images.jl as long as you don't read images from your HD.
>>>>> >>>
>>>>> >>>
>>>>> >>> 2014-08-20 13:01 GMT+02:00 Sheehan Olver <[email protected]>:
>>>>> >>> OK I cloned all the necessary projects but get the following error on
>>>>> >>> OS
>>>>> >>> X, and thoughts?
>>>>> >>>
>>>>> >>> julia> include("surface.jl")
>>>>> >>> ERROR: error compiling Texture: error compiling __Texture#30__: error
>>>>> >>> compiling imread: error compiling imread: error compiling MagickWand:
>>>>> >>> could not load module : dlopen(.dylib, 1): image not found>
>>>>> >>> in GLFont at /Users/solver/.julia/v0.3/GLText/src/types.jl:97
>>>>> >>> in inittext at /Users/solver/.julia/v0.3/GLText/src/GLText.jl:13
>>>>> >>> in init_glutils at
>>>>> >>> /Users/solver/.julia/v0.3/GLAbstraction/src/GLInit.jl:13
>>>>> >>> in createwindow at
>>>>> >>> /Users/solver/.julia/v0.3/GLWindow/src/reactglfw.jl:299
>>>>> >>> in createdisplay at /Users/solver/.julia/v0.3/GLPlot/src/GLPlot.jl:43
>>>>> >>> in include at ./boot.jl:245
>>>>> >>> in include_from_node1 at ./loading.jl:128
>>>>> >>>
>>>>> >>> while loading /Users/solver/.julia/v0.3/GLPlot/example/surface.jl, in
>>>>> >>> expression starting on line 3>
>>>>> >>> On 20 Aug 2014, at 8:37 pm, Simon Danisch <[email protected]> wrote:
>>>>> >>>> In theory it does support 2D plotting, but I didn't invest much work
>>>>> >>>> into
>>>>> >>>> it, as 3D is my main focus. In other words:
>>>>> >>>> There's nothing working out of the box, but if you are willing to
>>>>> >>>> invest
>>>>> >>>> some work, there are already a lot of tools to make 2D plotting
>>>>> >>>> possible
>>>>> >>>> and I would be willing to support you with any efforts.
>>>>> >>>>
>>>>> >>>>
>>>>> >>>> Am Dienstag, 19. August 2014 07:46:22 UTC+2 schrieb Sheehan Olver:
>>>>> >>>> Hi,
>>>>> >>>>
>>>>> >>>> Is there a way to force plotting in PyPlot.jl, to simulate animation?
>>>>> >>>> Right now if I do a for loop over a sequence of plots, it only
>>>>> >>>> outputs
>>>>> >>>> the last plot.
>>>>> >>>>
>>>>> >>>> This is in IJulia running on OS X with matplotlib version 1.3.1
>>>>> >>>> installed, and pygui(true)
>>>>> >>>>
>>>>> >>>> Sheehan
>>>>> >
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>