Q1 of 2: Using diewald_fluid library and GPU examples

Trying to tutor myself on fluid dynamics. Discovered both older and newer libraries contributed by Thomas Diewald.

This question is about running examples out of diewald_fluid library with option to use GPU (GLSL) context. I have downloaded GLGraphics zip package and moved files around so ~/libraries/codeanticode is seen by P3. I seem to crash on the execution of size() even after setting specific values for width and height. (The third argument remains as GLConstants.GLGRAPHICS.)

Any ideas on proper environment/setup to make this work?

Answers

  • Can you provide a link to those packages that you download. Also paste below the code your are attempting to run. Make sure you format the code before submitting. In the processing IDE, press ctrl+t. Then copy and paste it below. Select your code and hit ctrl+o. Ensure there is a line above and below your code block.

    Kf

  • I got GLGraphics 1.0 from here: https://sourceforge.net/projects/glgraphics/files/glgraphics/1.0/

    It is unzipped to reside in my Processing area as this:

    ~/libraries/GLGraphics with subdirectories examples, library, reference, src

    The library subdir contains GLGraphics.jar.

    The src subdir contains codeanticode/glgraphics. I copy the latter up to reside under ~/libraries to satisfy the "import" statement (codeanticode.glgraphics.*) in the fluid2d_basic_GPU_v2 sketch:

    //------------------------------------------------------------------------------
    
    import processing.opengl.*;
    import codeanticode.glgraphics.*;
    import diewald_fluid.Fluid2D;
    import diewald_fluid.Fluid2D_CPU;
    import diewald_fluid.Fluid2D_GPU;
    
    int  CPU_GPU        = 0; // 0 is GPU, 1 is CPU;
    int  fluid_size_x = 300; 
    int  fluid_size_y = 300;
    
    int  cell_size    = 2;
    int  window_size_x = fluid_size_x  * cell_size + (cell_size * 2);
    int  window_size_y = fluid_size_y  * cell_size + (cell_size * 2);
    
    Fluid2D fluid;
    PImage output_densityMap;
    boolean edit_quader = false;
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////
    public void setup() {
        size(604, 604, GLConstants.GLGRAPHICS);
        /* THE FOLLOWING CAUSES SEVERAL PROBLEMS
         IN ADDITION TO SYMBOLIC size() PARAMS,
         AN ERROR "size() cannot be used here" IS GIVEN.
         -bob97086
         */
        /*
      if ( CPU_GPU == 0 ){
         size(window_size_x, window_size_y, GLConstants.GLGRAPHICS);
         }
         if ( CPU_GPU == 1 ){
         size(window_size_x, window_size_y, JAVA2D);
         }
         */
        fluid = createFluidSolver();
        frameRate(60);
    }
    
    
    
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////
    public void draw() {
        background(255);
        if ( mousePressed ) 
            fluidInfluence(fluid);
        setVel (fluid, 10, 10, 2, 2, .2f, .2f);
        setDens(fluid, 10, 10, 8, 8, 4, 0, 0);
    
        setVel (fluid, width-10, cell_size*4, 2, 2, -.2f, .2f);
        setDens(fluid, width-10, cell_size*4, 8, 8, 4, 4, 4);
    
        setVel (fluid, width-10, height-10, 2, 2, -.2f, -.2f);
        setDens(fluid, width-10, height-10, 8, 8, 0, 0, 4);
    
        setVel (fluid, 10, height-10, 2, 2, .2f, -.2f);
        setDens(fluid, 10, height-10, 8, 8, 0, 4, 0);
    
        fluid.smoothDensityMap(!( keyPressed && key == 's'));
    
        fluid.update();
        image(fluid.getDensityMap(), 0, 0, width, height);
        println(frameRate);
    }
    
    
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // createFluidSolver();
    //
    Fluid2D createFluidSolver() {
        Fluid2D fluid_tmp = new Fluid2D_GPU(this, fluid_size_x, fluid_size_y); // initialize de solver
    
        fluid_tmp.setParam_Timestep  ( 0.10f );
        fluid_tmp.setParam_Iterations( 16 );
        fluid_tmp.setParam_IterationsDiffuse(1);
        fluid_tmp.setParam_Viscosity ( 0.00000001f );
        fluid_tmp.setParam_Diffusion ( 0.0000000001f );
        fluid_tmp.setParam_Vorticity ( 2.0f );
        fluid_tmp.processDensityMap  ( true );
        fluid_tmp.processDiffusion   ( true );
        fluid_tmp.processViscosity   ( true );
        fluid_tmp.processVorticity   ( true );
        fluid_tmp.processDensityMap  ( true );
        fluid_tmp.setObjectsColor    (1, 1, 1, 1); 
    
        output_densityMap    = createImage(window_size_x, window_size_y, RGB);
        fluid_tmp.setDensityMap(output_densityMap);
        return fluid_tmp;
    }
    

    Upon "run" I get this crash output:

    java.lang.NoClassDefFoundError: processing/opengl/PGraphicsOpenGL$ImageCache at java.lang.Class.getDeclaredConstructors0(Native Method) at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671) at java.lang.Class.getConstructor0(Class.java:3075) at java.lang.Class.getConstructor(Class.java:1825) at processing.core.PApplet.makeGraphics(PApplet.java:2226) at processing.core.PApplet.createPrimaryGraphics(PApplet.java:2306) at processing.core.PApplet.initSurface(PApplet.java:10553) at processing.core.PApplet.runSketch(PApplet.java:10492) at processing.core.PApplet.main(PApplet.java:10211) Caused by: java.lang.ClassNotFoundException: processing.opengl.PGraphicsOpenGL$ImageCache at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 9 more Could not run the sketch (Target VM failed to initialize). For more information, read revisions.txt and Help ? Troubleshooting.

    Thanks for your help.

Sign In or Register to comment.