예제 #1
0
 /// Relative permeabilities for all phases.
 /// \param[in]  sw     Array of n water saturation values.
 /// \param[in]  so     Array of n oil saturation values.
 /// \param[in]  sg     Array of n gas saturation values.
 /// \param[in]  cells  Array of n cell indices to be associated with the saturation values.
 /// \return            An std::vector with 3 elements, each an array of n relperm values,
 ///                    containing krw, kro, krg. Use PhaseIndex for indexing into the result.
 std::vector<V> BlackoilPropsAd::relperm(const V& sw,
                                         const V& so,
                                         const V& sg,
                                         const Cells& cells) const
 {
     const int n = cells.size();
     const int np = props_.numPhases();
     Block s_all(n, np);
     if (pu_.phase_used[Water]) {
         assert(sw.size() == n);
         s_all.col(pu_.phase_pos[Water]) = sw;
     }
     if (pu_.phase_used[Oil]) {
         assert(so.size() == n);
         s_all.col(pu_.phase_pos[Oil]) = so;
     }
     if (pu_.phase_used[Gas]) {
         assert(sg.size() == n);
         s_all.col(pu_.phase_pos[Gas]) = sg;
     }
     Block kr(n, np);
     props_.relperm(n, s_all.data(), cells.data(), kr.data(), 0);
     std::vector<V> relperms;
     relperms.reserve(3);
     for (int phase = 0; phase < 3; ++phase) {
         if (pu_.phase_used[phase]) {
             relperms.emplace_back(kr.col(pu_.phase_pos[phase]));
         } else {
             relperms.emplace_back();
         }
     }
     return relperms;
 }
예제 #2
0
void XWindow::OnKeyRelease(WindowEventKey *e)
{
    XkbStateRec s;
    Status st = XkbGetState(e->Handle()->display, XkbUseCoreKbd, &s);
    if (st != XkbOD_Success)
        throw new XException("Error getting xkb keyboard state", __FILE__, __LINE__, __func__);

    int shift = (s.mods & ShiftMask) != 0 ? 1 : 0;
    if (shift == 0) shift =  (s.mods & Mod5Mask) != 0 ? 2 : 0;
    //int lock = (s.mods & LockMask) != 0 ? 1 : 0;
    //int ctrl = (s.mods & ControlMask) != 0 ? 1 : 0;
    //int mod1 = (s.mods & Mod1Mask) != 0 ? 1 : 0;
    //int mod2 = (s.mods & Mod2Mask) != 0 ? 1 : 0;
    //int mod3 = (s.mods & Mod3Mask) != 0 ? 1 : 0;
    //int mod4 = (s.mods & Mod4Mask) != 0 ? 1 : 0;
    //int mod5 = (s.mods & Mod5Mask) != 0 ? 1 : 0;
    KeySym keySym = XkbKeycodeToKeysym(e->Handle()->display, e->Handle()->keycode, 0, shift);

    char cadena[10];
    int overflow = 0;
    int nbytes = XkbTranslateKeySym(e->Handle()->display, &keySym, s.mods, cadena, 10, &overflow);
    Text keyText = nbytes > 0 ? cadena : "";

    ControlEventKey kr(*e, KeyCompositionSymbol(keySym, keyText));

    // Key redirection until the focused control catches it
    bool redirected = false;
    for (int i=0; i<controls->Count() && !redirected; i++)
        redirected = (*controls)[i]->OnKeyRelease(&kr);

    DelegationOnKeyRelease().Execute(e);
}
예제 #3
0
    /// @brief Computes total mobility and omega for a set of s/c values.
    /// @param[in]  props     rock and fluid properties
    /// @param[in]  polyprops polymer properties
    /// @param[in]  cells     cells with which the saturation values are associated
    /// @param[in]  s         saturation values (for all phases)
    /// @param[in]  c         polymer concentration
    /// @param[out] totmob    total mobility
    /// @param[out] omega     mobility-weighted (or fractional-flow weighted)
    ///                       fluid densities.
    void computeTotalMobilityOmega(const Opm::IncompPropertiesInterface& props,
				   const Opm::PolymerProperties& polyprops,
				   const std::vector<int>& cells,
				   const std::vector<double>& s,
				   const std::vector<double>& c,
                                   const std::vector<double>& cmax,
				   std::vector<double>& totmob,
				   std::vector<double>& omega)
    {
	int num_cells = cells.size();
	int num_phases = props.numPhases();
	totmob.resize(num_cells);
	omega.resize(num_cells);
	assert(int(s.size()) == num_cells*num_phases);
	std::vector<double> kr(num_cells*num_phases);
	props.relperm(num_cells, &s[0], &cells[0], &kr[0], 0);
	const double* visc = props.viscosity();
	const double* rho = props.density();
        double mob[2]; // here we assume num_phases=2
	for (int cell = 0; cell < num_cells; ++cell) {
            double*  kr_cell = &kr[2*cell];
            polyprops.effectiveMobilities(c[cell], cmax[cell], visc, kr_cell,
                                          mob);
            totmob[cell] = mob[0] + mob[1];
            omega[cell] = rho[0]*mob[0]/totmob[cell] + rho[1]*mob[1]/totmob[cell];
        }
    }
예제 #4
0
    /// Computes the fractional flow for each cell in the cells argument
    /// @param[in]  props            rock and fluid properties
    /// @param[in]  polyprops        polymer properties
    /// @param[in]  cells            cells with which the saturation values are associated
    /// @param[in]  p                pressure (one value per cell)
    /// @param[in]  z                surface-volume values (for all P phases)
    /// @param[in]  s                saturation values (for all phases)
    /// @param[in]  c                concentration values
    /// @param[in]  cmax             max polymer concentration experienced by cell
    /// @param[out] fractional_flow  the fractional flow for each phase for each cell.
    void computeFractionalFlow(const Opm::BlackoilPropertiesInterface& props,
                               const Opm::PolymerProperties& polyprops,
                               const std::vector<int>& cells,
                               const std::vector<double>& p,
                               const std::vector<double>& T,
                               const std::vector<double>& z,
                               const std::vector<double>& s,
                               const std::vector<double>& c,
                               const std::vector<double>& cmax,
                               std::vector<double>& fractional_flows)
    {
	int num_cells = cells.size();
	int num_phases = props.numPhases();
        if (num_phases != 2) {
            OPM_THROW(std::runtime_error, "computeFractionalFlow() assumes 2 phases.");
        }
	fractional_flows.resize(num_cells*num_phases);
	assert(int(s.size()) == num_cells*num_phases);
	std::vector<double> kr(num_cells*num_phases);
	props.relperm(num_cells, &s[0], &cells[0], &kr[0], 0);
	std::vector<double> mu(num_cells*num_phases);
	props.viscosity(num_cells, &p[0], &T[0], &z[0], &cells[0], &mu[0], 0);
        double mob[2]; // here we assume num_phases=2
	for (int cell = 0; cell < num_cells; ++cell) {
            double* kr_cell = &kr[2*cell];
            double* mu_cell = &mu[2*cell];
            polyprops.effectiveMobilities(c[cell], cmax[cell], mu_cell, kr_cell, mob);
            fractional_flows[2*cell]     = mob[0] / (mob[0] + mob[1]);
            fractional_flows[2*cell + 1] = mob[1] / (mob[0] + mob[1]);
        }
    }
예제 #5
0
Foam::scalar Foam::ReversibleReaction<ReactionThermo, ReactionRate>::kr
(
    const scalar T,
    const scalar p,
    const scalarField& c
) const
{
    return kr(kf(T, p, c), T, p, c);
}
예제 #6
0
 /// Relative permeabilities for all phases.
 /// \param[in]  sw     Array of n water saturation values.
 /// \param[in]  so     Array of n oil saturation values.
 /// \param[in]  sg     Array of n gas saturation values.
 /// \param[in]  cells  Array of n cell indices to be associated with the saturation values.
 /// \return            An std::vector with 3 elements, each an array of n relperm values,
 ///                    containing krw, kro, krg. Use PhaseIndex for indexing into the result.
 std::vector<ADB> BlackoilPropsAd::relperm(const ADB& sw,
                                           const ADB& so,
                                           const ADB& sg,
                                           const Cells& cells) const
 {
     const int n = cells.size();
     const int np = props_.numPhases();
     Block s_all(n, np);
     if (pu_.phase_used[Water]) {
         assert(sw.value().size() == n);
         s_all.col(pu_.phase_pos[Water]) = sw.value();
     }
     if (pu_.phase_used[Oil]) {
         assert(so.value().size() == n);
         s_all.col(pu_.phase_pos[Oil]) = so.value();
     } else {
         OPM_THROW(std::runtime_error, "BlackoilPropsAd::relperm() assumes oil phase is active.");
     }
     if (pu_.phase_used[Gas]) {
         assert(sg.value().size() == n);
         s_all.col(pu_.phase_pos[Gas]) = sg.value();
     }
     Block kr(n, np);
     Block dkr(n, np*np);
     props_.relperm(n, s_all.data(), cells.data(), kr.data(), dkr.data());
     const int num_blocks = so.numBlocks();
     std::vector<ADB> relperms;
     relperms.reserve(3);
     typedef const ADB* ADBPtr;
     ADBPtr s[3] = { &sw, &so, &sg };
     for (int phase1 = 0; phase1 < 3; ++phase1) {
         if (pu_.phase_used[phase1]) {
             const int phase1_pos = pu_.phase_pos[phase1];
             std::vector<ADB::M> jacs(num_blocks);
             for (int block = 0; block < num_blocks; ++block) {
                 jacs[block] = ADB::M(n, s[phase1]->derivative()[block].cols());
             }
             for (int phase2 = 0; phase2 < 3; ++phase2) {
                 if (!pu_.phase_used[phase2]) {
                     continue;
                 }
                 const int phase2_pos = pu_.phase_pos[phase2];
                 // Assemble dkr1/ds2.
                 const int column = phase1_pos + np*phase2_pos; // Recall: Fortran ordering from props_.relperm()
                 ADB::M dkr1_ds2_diag = spdiag(dkr.col(column));
                 for (int block = 0; block < num_blocks; ++block) {
                     jacs[block] += dkr1_ds2_diag * s[phase2]->derivative()[block];
                 }
             }
             relperms.emplace_back(ADB::function(kr.col(phase1_pos), jacs));
         } else {
             relperms.emplace_back(ADB::null());
         }
     }
     return relperms;
 }
예제 #7
0
Foam::boundBox Foam::searchableCylinder::calcBounds() const
{

    // Adapted from
    // http://www.gamedev.net/community/forums
    //       /topic.asp?topic_id=338522&forum_id=20&gforum_id=0

    // Let cylinder have end points A,B and radius r,

    // Bounds in direction X (same for Y and Z) can be found as:
    // Let A.X<B.X (otherwise swap points)
    // Good approximate lowest bound is A.X-r and highest is B.X+r (precise for
    // capsule). At worst, in one direction it can be larger than needed by 2*r.

    // Accurate bounds for cylinder is
    // A.X-kx*r, B.X+kx*r
    // where
    // kx=sqrt(((A.Y-B.Y)^2+(A.Z-B.Z)^2)/((A.X-B.X)^2+(A.Y-B.Y)^2+(A.Z-B.Z)^2))

    // similar thing for Y and Z
    // (i.e.
    // ky=sqrt(((A.X-B.X)^2+(A.Z-B.Z)^2)/((A.X-B.X)^2+(A.Y-B.Y)^2+(A.Z-B.Z)^2))
    // kz=sqrt(((A.X-B.X)^2+(A.Y-B.Y)^2)/((A.X-B.X)^2+(A.Y-B.Y)^2+(A.Z-B.Z)^2))
    // )

    // How derived: geometric reasoning. Bounds of cylinder is same as for 2
    // circles centered on A and B. This sqrt thingy gives sine of angle between
    // axis and direction, used to find projection of radius.

    vector kr
    (
        sqrt(sqr(unitDir_.y()) + sqr(unitDir_.z())),
        sqrt(sqr(unitDir_.x()) + sqr(unitDir_.z())),
        sqrt(sqr(unitDir_.x()) + sqr(unitDir_.y()))
    );

    kr *= radius_;

    point min = point1_ - kr;
    point max = point1_ + kr;

    min = ::Foam::min(min, point2_ - kr);
    max = ::Foam::max(max, point2_ + kr);

    return boundBox(min, max);
}
예제 #8
0
void CAST256::setkey(std::string KEY){
    if (keyset){
        throw std::runtime_error("Error: Key has already been set.");
    }

    if ((KEY.size() != 16) && (KEY.size() != 20) && (KEY.size() != 24) && (KEY.size() != 28) && (KEY.size() != 32)){
        throw std::runtime_error("Error: Key must be 128, 160, 192, 224, or 256 bits in length.");
    }

    KEY += std::string(32 - KEY.size(), 0);
    a = toint(KEY.substr(0, 4), 256);
    b = toint(KEY.substr(4, 4), 256);
    c = toint(KEY.substr(8, 4), 256);
    d = toint(KEY.substr(12, 4), 256);
    e = toint(KEY.substr(16, 4), 256);
    f = toint(KEY.substr(20, 4), 256);
    g = toint(KEY.substr(24, 4), 256);
    h = toint(KEY.substr(28, 4), 256);

    uint32_t Cm = 0x5A827999, Mm = 0x6ED9EBA1, Cr = 19, Mr = 17;

    std::vector <uint8_t> range24_8(24, 0);
    std::vector <uint32_t> range24_32(24, 0);

    Tm.push_back(range24_32); Tr.push_back(range24_8);
    for(uint8_t x = 0; x < 8; x++){
        Tm.push_back(range24_32);
        Tr.push_back(range24_8);
    }
    for(uint8_t i = 0; i < 24; i++){
        for(uint8_t j = 0; j < 8; j++){
            Tm[j][i] = Cm;
            Cm = (Cm + Mm) & mod32;
            Tr[j][i] = Cr;
            Cr = (Cr + Mr) & 31;
        }
    }
    for(uint8_t i = 0; i < 12; i++){
        W(i << 1);
        W((i << 1) + 1);
        Kr.push_back(kr());
        Km.push_back(km());
    }

    keyset = true;
}
예제 #9
0
    /// @brief Computes total mobility for a set of s/c values.
    /// @param[in]  props     rock and fluid properties
    /// @param[in]  polyprops polymer properties
    /// @param[in]  cells     cells with which the saturation values are associated
    /// @param[in]  s         saturation values (for all phases)
    /// @param[in]  c         polymer concentration
    /// @param[out] totmob    total mobilities.
    void computeTotalMobility(const Opm::IncompPropertiesInterface& props,
			      const Opm::PolymerProperties& polyprops,
			      const std::vector<int>& cells,
			      const std::vector<double>& s,
			      const std::vector<double>& c,
			      const std::vector<double>& cmax,
			      std::vector<double>& totmob)
    {
	int num_cells = cells.size();
	totmob.resize(num_cells);
	std::vector<double> kr(2*num_cells);
	props.relperm(num_cells, &s[0], &cells[0], &kr[0], 0);
        const double* visc = props.viscosity();
	for (int cell = 0; cell < num_cells; ++cell) {
            double*  kr_cell = &kr[2*cell];
            polyprops.effectiveTotalMobility(c[cell], cmax[cell], visc, kr_cell,
                                             totmob[cell]);
	}
    }
예제 #10
0
void FEdgeXDetector::postProcessSuggestiveContourFace(WXFace *iFace) {

    // Compute the derivative of the radial curvature in the radial direction,
    // at the two extremities of the smooth edge.
    // If the derivative is smaller than a given threshold _kr_derivative_epsilon,
    // discard the edge.

    // Find the suggestive contour layer of the face (zero or one edge).
    vector<WXFaceLayer*> sc_layers;
    iFace->retrieveSmoothEdgesLayers(Nature::SUGGESTIVE_CONTOUR, sc_layers);
    if(sc_layers.empty())
        return;

    WXFaceLayer *sc_layer;
    sc_layer = sc_layers[0];

    // Compute the derivative value at each vertex of the face, and add it in a vector.
    vector<real> kr_derivatives;

    unsigned vertices_nb = iFace->numberOfVertices();
    WXVertex *v, *opposite_vertex_a, *opposite_vertex_b;
    WXFace *wxf;
    WOEdge *opposite_edge;
    Vec3r opposite_edge_vec, normal_vec, radial_normal_vec, er_vec, v_vec, inter, inter1, inter2, tmp_vec;
    GeomUtils::intersection_test res;
    real kr(0), kr1(0), kr2(0), t;

    for (unsigned i = 0; i < vertices_nb; ++i) {
        v = (WXVertex*)(iFace->GetVertex(i));

        // v is a singular vertex, skip it.
        if (v->isBoundary()) {
            kr_derivatives.push_back(0);
            continue;
        }

        v_vec = v->GetVertex();
        er_vec = v->curvatures()->er;

        // For each vertex, iterate on its adjacent faces.
        for (WVertex::face_iterator fit = v->faces_begin(), fitend = v->faces_end();
             fit != fitend;
             ++fit) {
            wxf = dynamic_cast<WXFace*>(*fit);
            if(!(wxf->getOppositeEdge(v, opposite_edge)))
                continue;

            opposite_vertex_a = (WXVertex*)opposite_edge->GetaVertex();
            opposite_vertex_b = (WXVertex*)opposite_edge->GetbVertex();
            opposite_edge_vec = opposite_vertex_b->GetVertex() - opposite_vertex_a->GetVertex();
            normal_vec = wxf->GetVertexNormal(v); // FIXME: what about e1 ^ e2 ?
            radial_normal_vec = er_vec ^ normal_vec;

            // Test wether the radial plan intersects with the edge at the opposite of v.
            res = GeomUtils::intersectRayPlane(opposite_vertex_a->GetVertex(), opposite_edge_vec,
                                               radial_normal_vec, -(v_vec * radial_normal_vec),
                                               t,
                                               1.e-06);

            // If there is an intersection, compute the value of the derivative ath that point.
            if ((res == GeomUtils::DO_INTERSECT) && (t >= 0) && (t <= 1)) {
                kr = t * opposite_vertex_a->curvatures()->Kr + (1 - t) * opposite_vertex_b->curvatures()->Kr;
                inter = opposite_vertex_a->GetVertex() + t * opposite_edge_vec;
                tmp_vec = inter - v->GetVertex();
                // Is it kr1 or kr2?
                if (tmp_vec * er_vec > 0) {
                    kr2 = kr;
                    inter2 = inter;
                } else {
                    kr1 = kr;
                    inter1 = inter;
                }
            }
        }

        // Now we have kr1 and kr2 along the radial direction, for one vertex of iFace.
        // We have to compute the derivative of kr for that vertex, equal to:
        // (kr2 - kr1) / dist(inter1, inter2).
        // Then we add it to the vector of derivatives.
        v->curvatures()->dKr = (kr2 - kr1) / (inter2 - inter1).norm();
        kr_derivatives.push_back(v->curvatures()->dKr);
    }

    // At that point, we have the derivatives for each vertex of iFace.
    // All we have to do now is to use linear interpolation to compute the values at
    // the extremities of the smooth edge.
    WXSmoothEdge *sc_edge = sc_layer->getSmoothEdge();
    WOEdge *sc_oedge = sc_edge->woea();
    t = sc_edge->ta();
    if (t * kr_derivatives[iFace->GetIndex(sc_oedge->GetaVertex())] +
            (1 - t) * kr_derivatives[iFace->GetIndex(sc_oedge->GetbVertex())] < _kr_derivative_epsilon) {
        sc_layer->removeSmoothEdge();
        return;
    }
    sc_oedge = sc_edge->woeb();
    t = sc_edge->tb();
    if (t * kr_derivatives[iFace->GetIndex(sc_oedge->GetaVertex())] +
            (1 - t) * kr_derivatives[iFace->GetIndex(sc_oedge->GetbVertex())] < _kr_derivative_epsilon)
        sc_layer->removeSmoothEdge();
}