Exemplo n.º 1
0
/// Set the derivative method, given a table and option name
void derivs_set(DiffLookup *table, const char* name, deriv_func &f)
{
    char *label = options.getString(name);

    DIFF_METHOD method = lookupFunc(table, label); // Find the function
    printFuncName(method); // Print differential function name
    f = lookupFunc(table, method); // Find the function pointer
}
Exemplo n.º 2
0
bool LuaInterface::call(const char *func, int a, int b)
{
    lookupFunc(func);
    lua_pushinteger(_lua, a);
    lua_pushinteger(_lua, b);
    return doCall(2);
}
Exemplo n.º 3
0
bool LuaInterface::call(const char *func, const char *a, const char *b)
{
	lookupFunc(func);
	lua_pushstring(_lua, a);
	lua_pushstring(_lua, b);
	return doCall(2);
}
Exemplo n.º 4
0
const Field3D DDY(const Field3D &f, CELL_LOC outloc, DIFF_METHOD method)
{
    deriv_func func = fDDY; // Set to default function
    DiffLookup *table = FirstDerivTable;

    CELL_LOC inloc = f.getLocation(); // Input location
    CELL_LOC diffloc = inloc; // Location of differential result

    Field3D result;

    if(StaggerGrids && (outloc == CELL_DEFAULT)) {
        // Take care of CELL_DEFAULT case
        outloc = diffloc; // No shift (i.e. same as no stagger case)
    }

    if(StaggerGrids && (outloc != inloc)) {
        // Shifting to a new location

        //output.write("\nSHIFTING %s -> %s\n", strLocation(inloc), strLocation(outloc));

        if(((inloc == CELL_CENTRE) && (outloc == CELL_YLOW)) ||
                ((inloc == CELL_YLOW) && (outloc == CELL_CENTRE))) {
            // Shifting in Y. Centre -> Ylow, or Ylow -> Centre

            //output.write("SHIFT");

            func = sfDDY; // Set default
            table = FirstStagDerivTable; // Set table for others
            diffloc = (inloc == CELL_CENTRE) ? CELL_YLOW : CELL_CENTRE;

        } else {
            // A more complicated shift. Get a result at cell centre, then shift.
            if(inloc == CELL_YLOW) {
                // Shifting

                func = sfDDY; // Set default
                table = FirstStagDerivTable; // Set table for others
                diffloc = CELL_CENTRE;

            } else if(inloc != CELL_CENTRE) {
                // Interpolate to centre then call DDY again
                return DDY(interp_to(f, CELL_CENTRE), outloc, method);
            }
        }
    }

    if(method != DIFF_DEFAULT) {
        // Lookup function
        func = lookupFunc(table, method);
        if(func == NULL)
            bout_error("Cannot use FFT for Y derivatives");
    }

    result = applyYdiff(f, func, dy, diffloc);
    //output.write("SETTING LOC %s\n", strLocation(diffloc));
    result.setLocation(diffloc); // Set the result location

    return interp_to(result, outloc); // Interpolate if necessary
}
Exemplo n.º 5
0
const Field3D D2DY2(const Field3D &f, CELL_LOC outloc, DIFF_METHOD method)
{
    deriv_func func = fD2DY2; // Set to default function
    DiffLookup *table = SecondDerivTable;

    CELL_LOC inloc = f.getLocation(); // Input location
    CELL_LOC diffloc = inloc; // Location of differential result

    Field3D result;

    if(StaggerGrids && (outloc == CELL_DEFAULT)) {
        // Take care of CELL_DEFAULT case
        outloc = diffloc; // No shift (i.e. same as no stagger case)
    }

    if(StaggerGrids && (outloc != inloc)) {
        // Shifting to a new location

        if(((inloc == CELL_CENTRE) && (outloc == CELL_YLOW)) ||
                ((inloc == CELL_YLOW) && (outloc == CELL_CENTRE))) {
            // Shifting in Y. Centre -> Ylow, or Ylow -> Centre

            func = sfD2DY2; // Set default
            table = SecondStagDerivTable; // Set table for others
            diffloc = (inloc == CELL_CENTRE) ? CELL_YLOW : CELL_CENTRE;

        } else {
            // A more complicated shift. Get a result at cell centre, then shift.
            if(inloc == CELL_YLOW) {
                // Shifting

                func = sfD2DY2; // Set default
                table = SecondStagDerivTable; // Set table for others
                diffloc = CELL_CENTRE;

            } else if(inloc != CELL_CENTRE) {
                // Interpolate then (centre -> centre) then interpolate
                return D2DY2(interp_to(f, CELL_CENTRE), outloc, method);
            }
        }
    }

    if(method != DIFF_DEFAULT) {
        // Lookup function
        func = lookupFunc(table, method);
        if(func == NULL)
            bout_error("Cannot use FFT for Y derivatives");
    }

    result = applyYdiff(f, func, (dy*dy));
    result.setLocation(diffloc);

    if(non_uniform) {
        // Correction for non-uniform mesh
        result += applyYdiff(f, fDDY, d2y);
    }

    return interp_to(result, outloc);
}
Exemplo n.º 6
0
bool LuaInterface::call(const char *func, int a, int b, int c, int d, int e)
{
	lookupFunc(func);
	lua_pushinteger(_lua, a);
	lua_pushinteger(_lua, b);
	lua_pushinteger(_lua, c);
	lua_pushinteger(_lua, d);
	lua_pushinteger(_lua, e);
	return doCall(5);
}
Exemplo n.º 7
0
bool LuaInterface::call(const char *func, const char *a, const char *b, const char *c, const char *d, const char *e)
{
	lookupFunc(func);
	lua_pushstring(_lua, a);
	lua_pushstring(_lua, b);
	lua_pushstring(_lua, c);
	lua_pushstring(_lua, d);
	lua_pushstring(_lua, e);
	return doCall(5);
}
Exemplo n.º 8
0
const Field3D DDZ(const Field3D &f, CELL_LOC outloc, DIFF_METHOD method, bool inc_xbndry)
{
    deriv_func func = fDDZ; // Set to default function
    DiffLookup *table = FirstDerivTable;

    CELL_LOC inloc = f.getLocation(); // Input location
    CELL_LOC diffloc = inloc; // Location of differential result

    if(StaggerGrids && (outloc == CELL_DEFAULT)) {
        // Take care of CELL_DEFAULT case
        outloc = diffloc; // No shift (i.e. same as no stagger case)
    }

    if(StaggerGrids && (outloc != inloc)) {
        // Shifting to a new location

        if(((inloc == CELL_CENTRE) && (outloc == CELL_ZLOW)) ||
                ((inloc == CELL_ZLOW) && (outloc == CELL_CENTRE))) {
            // Shifting in Z. Centre -> Zlow, or Zlow -> Centre

            func = sfDDZ; // Set default
            table = FirstStagDerivTable; // Set table for others
            diffloc = (inloc == CELL_CENTRE) ? CELL_ZLOW : CELL_CENTRE;

        } else {
            // A more complicated shift. Get a result at cell centre, then shift.
            if(inloc == CELL_ZLOW) {
                // Shifting

                func = sfDDZ; // Set default
                table = FirstStagDerivTable; // Set table for others
                diffloc = CELL_CENTRE;

            } else if(inloc != CELL_CENTRE) {
                // Interpolate then (centre -> centre) then interpolate
                return DDZ(interp_to(f, CELL_CENTRE), outloc, method);
            }
        }
    }

    if(method != DIFF_DEFAULT) {
        // Lookup function
        func = lookupFunc(table, method);
    }

    Field3D result;

    if(func == NULL) {
        // Use FFT

        real shift = 0.; // Shifting result in Z?
        if(StaggerGrids) {
            if((inloc == CELL_CENTRE) && (diffloc == CELL_ZLOW)) {
                // Shifting down - multiply by exp(-0.5*i*k*dz)
                shift = -1.;
            } else if((inloc == CELL_ZLOW) && (diffloc == CELL_CENTRE)) {
                // Shifting up
                shift = 1.;
            }
        }

        result.Allocate(); // Make sure data allocated

        static dcomplex *cv = (dcomplex*) NULL;
        int jx, jy, jz;
        real kwave;
        real flt;

        int xge = MXG, xlt = ngx-MXG;
        if(inc_xbndry) { // Include x boundary region (for mixed XZ derivatives)
            xge = 0;
            xlt = ngx;
        }

        if(cv == (dcomplex*) NULL)
            cv = new dcomplex[ncz/2 + 1];

        for(jx=xge; jx<xlt; jx++) {
            for(jy=0; jy<ngy; jy++) {

                rfft(f[jx][jy], ncz, cv); // Forward FFT

                for(jz=0; jz<=ncz/2; jz++) {
                    kwave=jz*2.0*PI/zlength; // wave number is 1/[rad]

                    if (jz>0.4*ncz) flt=1e-10;
                    else flt=1.0;
                    cv[jz] *= dcomplex(0.0, kwave) * flt;
                    if(StaggerGrids)
                        cv[jz] *= exp(Im * (shift * kwave * dz));
                }

                irfft(cv, ncz, result[jx][jy]); // Reverse FFT

                result[jx][jy][ncz] = result[jx][jy][0];

            }
        }

#ifdef CHECK
        // Mark boundaries as invalid
        result.bndry_xin = result.bndry_xout = result.bndry_yup = result.bndry_ydown = false;
#endif

    } else {
        // All other (non-FFT) functions
        result = applyZdiff(f, func, dz);
    }

    result.setLocation(diffloc);

    return interp_to(result, outloc);
}
Exemplo n.º 9
0
const Field3D DDX(const Field3D &f, CELL_LOC outloc, DIFF_METHOD method)
{
    deriv_func func = fDDX; // Set to default function
    DiffLookup *table = FirstDerivTable;

    CELL_LOC inloc = f.getLocation(); // Input location
    CELL_LOC diffloc = inloc; // Location of differential result

    Field3D result;

    if(StaggerGrids && (outloc == CELL_DEFAULT)) {
        // Take care of CELL_DEFAULT case
        outloc = diffloc; // No shift (i.e. same as no stagger case)
    }

    if(StaggerGrids && (outloc != inloc)) {
        // Shifting to a new location

        if(((inloc == CELL_CENTRE) && (outloc == CELL_XLOW)) ||
                ((inloc == CELL_XLOW) && (outloc == CELL_CENTRE))) {
            // Shifting in X. Centre -> Xlow, or Xlow -> Centre

            func = sfDDX; // Set default
            table = FirstStagDerivTable; // Set table for others
            diffloc = (inloc == CELL_CENTRE) ? CELL_XLOW : CELL_CENTRE;

        } else {
            // A more complicated shift. Get a result at cell centre, then shift.
            if(inloc == CELL_XLOW) {
                // Shifting

                func = sfDDX; // Set default
                table = FirstStagDerivTable; // Set table for others
                diffloc = CELL_CENTRE;

            } else if(inloc != CELL_CENTRE) {
                // Interpolate then (centre -> centre) then interpolate
                return DDX(interp_to(f, CELL_CENTRE), outloc, method);
            }
        }
    }

    if(method != DIFF_DEFAULT) {
        // Lookup function
        func = lookupFunc(table, method);
        if(func == NULL)
            bout_error("Cannot use FFT for X derivatives");
    }

    result = applyXdiff(f, func, dx, diffloc);
    result.setLocation(diffloc); // Set the result location

    result = interp_to(result, outloc); // Interpolate if necessary

    if(ShiftXderivs && IncIntShear) {
        // Using BOUT-06 style shifting
        result += IntShiftTorsion * DDZ(f, outloc);
    }

    return result;
}
Exemplo n.º 10
0
const Field3D D2DX2(const Field3D &f, CELL_LOC outloc, DIFF_METHOD method)
{
    deriv_func func = fD2DX2; // Set to default function
    DiffLookup *table = SecondDerivTable;

    CELL_LOC inloc = f.getLocation(); // Input location
    CELL_LOC diffloc = inloc; // Location of differential result

    Field3D result;

    if(StaggerGrids && (outloc == CELL_DEFAULT)) {
        // Take care of CELL_DEFAULT case
        outloc = diffloc; // No shift (i.e. same as no stagger case)
    }

    if(StaggerGrids && (outloc != inloc)) {
        // Shifting to a new location

        if(((inloc == CELL_CENTRE) && (outloc == CELL_XLOW)) ||
                ((inloc == CELL_XLOW) && (outloc == CELL_CENTRE))) {
            // Shifting in X. Centre -> Xlow, or Xlow -> Centre

            func = sfD2DX2; // Set default
            table = SecondStagDerivTable; // Set table for others
            diffloc = (inloc == CELL_CENTRE) ? CELL_XLOW : CELL_CENTRE;

        } else {
            // A more complicated shift. Get a result at cell centre, then shift.
            if(inloc == CELL_XLOW) {
                // Shifting

                func = sfD2DX2; // Set default
                table = SecondStagDerivTable; // Set table for others
                diffloc = CELL_CENTRE;

            } else if(inloc != CELL_CENTRE) {
                // Interpolate then (centre -> centre) then interpolate
                return D2DX2(interp_to(f, CELL_CENTRE), outloc, method);
            }
        }
    }

    if(method != DIFF_DEFAULT) {
        // Lookup function
        func = lookupFunc(table, method);
        if(func == NULL)
            bout_error("Cannot use FFT for X derivatives");
    }

    result = applyXdiff(f, func, (dx*dx));
    result.setLocation(diffloc);

    if(non_uniform) {
        // Correction for non-uniform mesh
        result += applyXdiff(f, fDDX, d2x); // CHECK THIS!
    }

    result = interp_to(result, outloc);

    if(ShiftXderivs && IncIntShear) {
        IncIntShear = false; // So DDX doesn't try to include I again
        // Add I^2 d^2/dz^2 term
        result += IntShiftTorsion^2 * D2DZ2(f, outloc);
        // Mixed derivative
        result += 2.*IntShiftTorsion * D2DXDZ(f);
        // DDZ term
        result += DDX(IntShiftTorsion) * DDZ(f, outloc);
        IncIntShear = true;
    }

    return result;
}
Exemplo n.º 11
0
bool LuaInterface::call(const char *func, float f)
{
    lookupFunc(func);
    lua_pushnumber(_lua, f);
    return doCall(1);
}
Exemplo n.º 12
0
bool LuaInterface::call(const char *func)
{
    lookupFunc(func);
    return doCall(0);
}