Getting the CTYPE of a nearby element

  • moonheart08
    20th Jun 2016 Member 0 Permalink

    Hi, im currently working on a new element, ALUM (in C++), and i would like some assistance: how can i detect the CTYPE of a nearby element?

  • LBPHacker
    21st Jun 2016 Developer 0 Permalink

    Depends on *which* nearby particle you want to detect the [.ctype] of. If you want to detect the [.ctype] of *all* nearby elements, just do it like DTEC does. DTEC looks for [.type]s though, so look out for that. It's a bit intermingled with FILT spectra changing code, but it's easy to decipher.

  • boxmein
    21st Jun 2016 Former Staff 1 Permalink
    @moonheart08 (View Post)
    A
    struct particle
    has a property "ctype" - so if you iterate, say, over pmap entries, you can do this:
    (note, this goes in your particle's update function)


    int partid, parttype;
    for (int i=-1; i<=1; i++) {
    for (int j=-1; j<=1; j++) {
    if (i != 0 && j != 0 && BOUNDS_CHECK) {
    // pmap[y][x] = topmost particle ID shifted 1 byte right, bit-AND-ed together with the particle type
    partid = pmap[y+i][x+i] >> 8;
    parttype = pmap[y+i][x+i] & 0xFF;
    if (sim->parts[partid].ctype == PT_COAL) {
    // do stuff!
    }
    }
    }
    }
    Edited once by boxmein. Last: 21st Jun 2016