コード例 #1
0
ファイル: serial_heateq.cpp プロジェクト: jakhog/equelle
void equelleGeneratedCode(equelle::EquelleRuntimeCPU& er) {
    using namespace equelle;
    ensureRequirements(er);

    // ============= Generated code starts here ================

    const Scalar k = er.inputScalarWithDefault("k", double(0.3));
    const SeqOfScalar timesteps = er.inputSequenceOfScalar("timesteps");
    const CollOfScalar u0 = er.inputCollectionOfScalar("u_initial", er.allCells());
    const CollOfFace dirichlet_boundary = er.inputDomainSubsetOf("dirichlet_boundary", er.boundaryFaces());
    const CollOfScalar dirichlet_val = er.inputCollectionOfScalar("dirichlet_val", dirichlet_boundary);
    const CollOfScalar vol = er.norm(er.allCells());
    const CollOfFace interior_faces = er.interiorFaces();
    const CollOfCell first = er.firstCell(interior_faces);
    const CollOfCell second = er.secondCell(interior_faces);
    const CollOfScalar itrans = (k * (er.norm(interior_faces) / er.norm((er.centroid(first) - er.centroid(second)))));
    const CollOfFace bf = er.boundaryFaces();
    const CollOfCell bf_cells = er.trinaryIf(er.isEmpty(er.firstCell(bf)), er.secondCell(bf), er.firstCell(bf));
    const CollOfScalar bf_sign = er.trinaryIf(er.isEmpty(er.firstCell(bf)), er.operatorExtend(-double(1), bf), er.operatorExtend(double(1), bf));
    const CollOfScalar btrans = (k * (er.norm(bf) / er.norm((er.centroid(bf) - er.centroid(bf_cells)))));
    const CollOfScalar dir_sign = er.operatorOn(bf_sign, er.boundaryFaces(), dirichlet_boundary);
    std::function<CollOfScalar(const CollOfScalar&)> computeInteriorFlux = [&](const CollOfScalar& u) -> CollOfScalar {
        return (-itrans * er.gradient(u));
    };
    std::function<CollOfScalar(const CollOfScalar&)> computeBoundaryFlux = [&](const CollOfScalar& u) -> CollOfScalar {
        const CollOfScalar u_dirbdycells = er.operatorOn(u, er.allCells(), er.operatorOn(bf_cells, er.boundaryFaces(), dirichlet_boundary));
        const CollOfScalar dir_fluxes = ((er.operatorOn(btrans, er.boundaryFaces(), dirichlet_boundary) * dir_sign) * (u_dirbdycells - dirichlet_val));
        return er.operatorExtend(dir_fluxes, dirichlet_boundary, er.boundaryFaces());
    };
    CollOfScalar expU;
    expU = u0;
    for (const Scalar& dt : timesteps) {
        std::function<CollOfScalar(const CollOfScalar&)> computeResidual = [&](const CollOfScalar& u) -> CollOfScalar {
            const CollOfScalar ifluxes = computeInteriorFlux(u);
            const CollOfScalar bfluxes = computeBoundaryFlux(u);
            const CollOfScalar fluxes = (er.operatorExtend(ifluxes, er.interiorFaces(), er.allFaces()) + er.operatorExtend(bfluxes, er.boundaryFaces(), er.allFaces()));
            const CollOfScalar residual = ((dt / vol) * er.divergence(fluxes));
            return residual;
        };
        expU = (expU - computeResidual(expU));
        er.output("serial_expU", expU);
        er.output("maximum of u", er.maxReduce(expU));
    }
    er.output("serial_expU", expU);

    // ============= Generated code ends here ================

}
コード例 #2
0
void equelleGeneratedCode(equelle::EquelleRuntimeCPU& er) {
    using namespace equelle;
    ensureRequirements(er);

    // ============= Generated code starts here ================

    const CollOfScalar a = CollOfScalar(er.centroid(er.allCells()).col(0));
    const CollOfScalar b = CollOfScalar(er.centroid(er.allCells()).col(1));
    er.output("hmmm", er.trinaryIf((a > er.operatorExtend(double(0), er.allCells())), (a + b), er.operatorExtend(double(0), er.allCells())));
    const CollOfScalar a1 = er.operatorOn((a + b), er.allCells(), er.interiorCells());
    const CollOfScalar b1 = er.operatorOn(b, er.allCells(), er.interiorCells());
    const CollOfScalar c = er.operatorExtend((a1 + b1), er.interiorCells(), er.allCells());
    const std::tuple<CollOfScalar, CollOfScalar, CollOfScalar> array = makeArray((a1 + b1), (a1 - b1), a1);
    const String qww = "This is a string with \"quoted escapes\" and others \n\n\n such as newlines";
    er.output(qww, double(2));

    // ============= Generated code ends here ================

}
コード例 #3
0
void equelleGeneratedCode(equelle::EquelleRuntimeCPU& er) {
    using namespace equelle;
    ensureRequirements(er);

    // ============= Generated code starts here ================

    const Scalar rsp = double(287.058);
    const Scalar temp = double(290);
    const Scalar perm = (9.869232667160128e-13*double(1));
    const Scalar viscosity = (1e-06*double(18.27));
    const Scalar mobility = (double(1) / viscosity);
    const CollOfScalar q = (er.inputCollectionOfScalar("source", er.allCells()) * double(1));
    const SeqOfScalar timesteps = (er.inputSequenceOfScalar("timesteps") * double(1));
    const CollOfScalar p_initial = er.operatorExtend(double(3000000), er.allCells());
    const CollOfFace intf = er.interiorFaces();
    const CollOfCell f = er.firstCell(intf);
    const CollOfCell s = er.secondCell(intf);
    const CollOfScalar area = er.norm(intf);
    const CollOfScalar vol = er.norm(er.allCells());
    const CollOfVector d1 = (er.centroid(f) - er.centroid(intf));
    const CollOfVector d2 = (er.centroid(s) - er.centroid(intf));
    const CollOfScalar h1 = ((-area * perm) * (er.dot(er.normal(intf), d1) / er.dot(d1, d1)));
    const CollOfScalar h2 = ((area * perm) * (er.dot(er.normal(intf), d2) / er.dot(d2, d2)));
    const CollOfScalar trans = (double(1) / ((double(1) / h1) + (double(1) / h2)));
    auto density_i0_ = [&](const CollOfScalar& p) -> CollOfScalar {
        return (p / (rsp * temp));
    };
    auto density_i1_ = [&](const CollOfScalar& p) -> CollOfScalar {
        return (p / (rsp * temp));
    };
    auto residual = [&](const CollOfScalar& p, const CollOfScalar& p0, const Scalar& dt) -> CollOfScalar {
        const CollOfScalar v = ((mobility * trans) * (er.operatorOn(p, er.allCells(), f) - er.operatorOn(p, er.allCells(), s)));
        const CollOfScalar rho = density_i0_(p);
        const CollOfScalar rho0 = density_i1_(p0);
        const CollOfScalar rho_face = ((er.operatorOn(rho, er.allCells(), f) + er.operatorOn(rho, er.allCells(), s)) / double(2));
        const CollOfScalar res = ((((vol / dt) * (rho - rho0)) + er.divergence((v * rho_face))) - q);
        return res;
    };
    auto p0 = p_initial;
    for (const Scalar& dt : timesteps) {
        auto locRes = [&](const CollOfScalar& p) -> CollOfScalar {
            return residual(p, p0, dt);
        };
        const CollOfScalar p = er.newtonSolve(locRes, p0);
        er.output("pressure", p);
        p0 = p;
    }

    // ============= Generated code ends here ================

}
コード例 #4
0
void equelleGeneratedCode(equelle::EquelleRuntimeCPU& er) {
    using namespace equelle;
    ensureRequirements(er);

    // ============= Generated code starts here ================

    const CollOfScalar perm = er.inputCollectionOfScalar("perm", er.allCells());
    const CollOfScalar poro = er.inputCollectionOfScalar("poro", er.allCells());
    const Scalar watervisc = er.inputScalarWithDefault("watervisc", double(0.0005));
    const Scalar oilvisc = er.inputScalarWithDefault("oilvisc", double(0.005));
    const CollOfScalar pv = (poro * er.norm(er.allCells()));
    auto computeTransmissibilities = [&](const CollOfScalar& permeability) -> CollOfScalar {
        const CollOfFace interior_faces = er.interiorFaces();
        const CollOfCell first = er.firstCell(interior_faces);
        const CollOfCell second = er.secondCell(interior_faces);
        const CollOfVector cdiff1 = (er.centroid(first) - er.centroid(interior_faces));
        const CollOfVector cdiff2 = (er.centroid(second) - er.centroid(interior_faces));
        const CollOfScalar p1 = er.operatorOn(permeability, er.allCells(), first);
        const CollOfScalar p2 = er.operatorOn(permeability, er.allCells(), second);
        const CollOfScalar a = er.norm(interior_faces);
        const CollOfScalar halftrans1 = ((-a * p1) * (er.dot(er.normal(interior_faces), cdiff1) / er.dot(cdiff1, cdiff1)));
        const CollOfScalar halftrans2 = ((a * p2) * (er.dot(er.normal(interior_faces), cdiff2) / er.dot(cdiff2, cdiff2)));
        const CollOfScalar trans = (double(1) / ((double(1) / halftrans1) + (double(1) / halftrans2)));
        return trans;
    };
    const CollOfScalar trans = computeTransmissibilities(perm);
    const CollOfScalar zero = er.operatorExtend(double(0), er.allCells());
    const CollOfScalar one = er.operatorExtend(double(1), er.allCells());
    auto upwind_i3_ = [&](const CollOfScalar& flux, const CollOfScalar& x) -> CollOfScalar {
        const CollOfScalar x1 = er.operatorOn(x, er.allCells(), er.firstCell(er.interiorFaces()));
        const CollOfScalar x2 = er.operatorOn(x, er.allCells(), er.secondCell(er.interiorFaces()));
        return er.trinaryIf((flux >= double(0)), x1, x2);
    };
    auto upwind_i7_ = [&](const CollOfScalar& flux, const CollOfScalar& x) -> CollOfScalar {
        const CollOfScalar x1 = er.operatorOn(x, er.allCells(), er.firstCell(er.interiorFaces()));
        const CollOfScalar x2 = er.operatorOn(x, er.allCells(), er.secondCell(er.interiorFaces()));
        return er.trinaryIf((flux >= double(0)), x1, x2);
    };
    auto upwind_i12_ = [&](const CollOfScalar& flux, const CollOfScalar& x) -> CollOfScalar {
        const CollOfScalar x1 = er.operatorOn(x, er.allCells(), er.firstCell(er.interiorFaces()));
        const CollOfScalar x2 = er.operatorOn(x, er.allCells(), er.secondCell(er.interiorFaces()));
        return er.trinaryIf((flux >= double(0)), x1, x2);
    };
    auto upwind_i16_ = [&](const CollOfScalar& flux, const CollOfScalar& x) -> CollOfScalar {
        const CollOfScalar x1 = er.operatorOn(x, er.allCells(), er.firstCell(er.interiorFaces()));
        const CollOfScalar x2 = er.operatorOn(x, er.allCells(), er.secondCell(er.interiorFaces()));
        return er.trinaryIf((flux >= double(0)), x1, x2);
    };
    auto computeTotalFlux_i4_ = [&](const CollOfScalar& pressure, const CollOfScalar& total_mobility) -> CollOfScalar {
        const CollOfScalar ngradp = -er.gradient(pressure);
        const CollOfScalar face_total_mobility = upwind_i12_(ngradp, total_mobility);
        return ((trans * face_total_mobility) * ngradp);
    };
    auto computeTotalFlux_i13_ = [&](const CollOfScalar& pressure, const CollOfScalar& total_mobility) -> CollOfScalar {
        const CollOfScalar ngradp = -er.gradient(pressure);
        const CollOfScalar face_total_mobility = upwind_i12_(ngradp, total_mobility);
        return ((trans * face_total_mobility) * ngradp);
    };
    auto computeWaterMob_i1_ = [&](const CollOfScalar& sw) -> CollOfScalar {
        const CollOfScalar krw = sw;
        return (krw / watervisc);
    };
    auto computeWaterMob_i5_ = [&](const CollOfScalar& sw) -> CollOfScalar {
        const CollOfScalar krw = sw;
        return (krw / watervisc);
    };
    auto computeWaterMob_i10_ = [&](const CollOfScalar& sw) -> CollOfScalar {
        const CollOfScalar krw = sw;
        return (krw / watervisc);
    };
    auto computeWaterMob_i14_ = [&](const CollOfScalar& sw) -> CollOfScalar {
        const CollOfScalar krw = sw;
        return (krw / watervisc);
    };
    auto computeOilMob_i2_ = [&](const CollOfScalar& sw) -> CollOfScalar {
        const CollOfScalar so = (er.operatorExtend(double(1), er.allCells()) - sw);
        const CollOfScalar kro = so;
        return (kro / oilvisc);
    };
    auto computeOilMob_i6_ = [&](const CollOfScalar& sw) -> CollOfScalar {
        const CollOfScalar so = (er.operatorExtend(double(1), er.allCells()) - sw);
        const CollOfScalar kro = so;
        return (kro / oilvisc);
    };
    auto computeOilMob_i11_ = [&](const CollOfScalar& sw) -> CollOfScalar {
        const CollOfScalar so = (er.operatorExtend(double(1), er.allCells()) - sw);
        const CollOfScalar kro = so;
        return (kro / oilvisc);
    };
    auto computeOilMob_i15_ = [&](const CollOfScalar& sw) -> CollOfScalar {
        const CollOfScalar so = (er.operatorExtend(double(1), er.allCells()) - sw);
        const CollOfScalar kro = so;
        return (kro / oilvisc);
    };
    auto waterConservation = [&](const CollOfScalar& sw, const CollOfScalar& sw0, const CollOfScalar& flux, const CollOfScalar& source, const CollOfScalar& insource_sw, const Scalar& dt) -> CollOfScalar {
        const CollOfScalar insource = er.trinaryIf((source > double(0)), source, er.operatorExtend(double(0), er.allCells()));
        const CollOfScalar outsource = er.trinaryIf((source < double(0)), source, er.operatorExtend(double(0), er.allCells()));
        const CollOfScalar mw = computeWaterMob_i5_(sw);
        const CollOfScalar mo = computeOilMob_i6_(sw);
        const CollOfScalar fracflow = (mw / (mw + mo));
        const CollOfScalar face_fracflow = upwind_i7_(flux, fracflow);
        const CollOfScalar water_flux = (face_fracflow * flux);
        const CollOfScalar q = ((insource * insource_sw) + (outsource * fracflow));
        return ((sw - sw0) + ((dt / pv) * (er.divergence(water_flux) - q)));
    };
    auto oilConservation = [&](const CollOfScalar& sw, const CollOfScalar& sw0, const CollOfScalar& flux, const CollOfScalar& source, const CollOfScalar& insource_sw, const Scalar& dt) -> CollOfScalar {
        const CollOfScalar insource = er.trinaryIf((source > double(0)), source, er.operatorExtend(double(0), er.allCells()));
        const CollOfScalar outsource = er.trinaryIf((source < double(0)), source, er.operatorExtend(double(0), er.allCells()));
        const CollOfScalar mw = computeWaterMob_i14_(sw);
        const CollOfScalar mo = computeOilMob_i15_(sw);
        const CollOfScalar fracflow = (mo / (mw + mo));
        const CollOfScalar face_fracflow = upwind_i16_(flux, fracflow);
        const CollOfScalar oil_flux = (face_fracflow * flux);
        const CollOfScalar insource_so = (er.operatorExtend(double(1), er.allCells()) - insource_sw);
        const CollOfScalar qo = ((insource * insource_so) + (outsource * fracflow));
        const CollOfScalar so = (er.operatorExtend(double(1), er.allCells()) - sw);
        const CollOfScalar so0 = (er.operatorExtend(double(1), er.allCells()) - sw0);
        return ((so - so0) + ((dt / pv) * (er.divergence(oil_flux) - qo)));
    };
    const SeqOfScalar timesteps = er.inputSequenceOfScalar("timesteps");
    const CollOfScalar sw_initial = er.inputCollectionOfScalar("sw_initial", er.allCells());
    const CollOfCell source_cells = er.inputDomainSubsetOf("source_cells", er.allCells());
    const CollOfScalar source_values = er.inputCollectionOfScalar("source_values", source_cells);
    const CollOfScalar source = er.operatorExtend(source_values, source_cells, er.allCells());
    const CollOfScalar insource_sw = er.operatorExtend(double(1), er.allCells());
    auto sw0 = sw_initial;
    auto p0 = er.operatorExtend(double(0), er.allCells());
    er.output("pressure", p0);
    er.output("saturation", sw0);
    for (const Scalar& dt : timesteps) {
        auto waterResLocal = [&](const CollOfScalar& pressure, const CollOfScalar& sw) -> CollOfScalar {
            const CollOfScalar total_mobility = (computeWaterMob_i1_(sw) + computeOilMob_i2_(sw));
            const CollOfScalar flux = computeTotalFlux_i4_(pressure, total_mobility);
            return waterConservation(sw, sw0, flux, source, insource_sw, dt);
        };
        auto oilResLocal = [&](const CollOfScalar& pressure, const CollOfScalar& sw) -> CollOfScalar {
            const CollOfScalar total_mobility = (computeWaterMob_i10_(sw) + computeOilMob_i11_(sw));
            const CollOfScalar flux = computeTotalFlux_i13_(pressure, total_mobility);
            return oilConservation(sw, sw0, flux, source, insource_sw, dt);
        };
        const std::tuple<CollOfScalar, CollOfScalar> newvals = er.newtonSolveSystem(makeArray(waterResLocal, oilResLocal), makeArray(p0, er.operatorExtend(double(0.5), er.allCells())));
        p0 = std::get<0>(newvals);
        sw0 = std::get<1>(newvals);
        er.output("pressure", p0);
        er.output("saturation", sw0);
    }

    // ============= Generated code ends here ================

}