Example #1
0
size_t Phase::addUniqueElementAfterFreeze(const std::string& symbol,
        doublereal weight, int atomicNumber,
        doublereal entropy298, int elem_type)
{
    size_t ii = elementIndex(symbol);
    if (ii != npos) {
        return ii;
    }
    // Check to see that the element isn't really in the list
    m_elementsFrozen = false;
    addUniqueElement(symbol, weight, atomicNumber, entropy298, elem_type);
    m_elementsFrozen = true;
    ii = elementIndex(symbol);
    if (ii != m_mm-1) {
        throw CanteraError("Phase::addElementAfterFreeze()", "confused");
    }
    if (m_kk > 0) {
        vector_fp old(m_speciesComp);
        m_speciesComp.resize(m_kk*m_mm, 0.0);
        for (size_t k = 0; k < m_kk; k++) {
            size_t m_old = m_mm - 1;
            for (size_t m = 0; m < m_old; m++) {
                m_speciesComp[k * m_mm + m] =  old[k * (m_old) + m];
            }
            m_speciesComp[k * (m_mm) + (m_mm-1)] = 0.0;
        }
    }
    return ii;
}
Example #2
0
 doublereal MineralEQ3::LookupGe(const std::string& elemName) {
#ifdef OLDWAY
    int num = sizeof(geDataTable) / sizeof(struct GeData);
    string s3 = elemName.substr(0,3);
    for (int i = 0; i < num; i++) {
      //if (!std::strncmp(elemName.c_str(), aWTable[i].name, 3)) {
      if (s3 == geDataTable[i].name) {
        return (geDataTable[i].GeValue);
      }
    }
    throw CanteraError("LookupGe", "element " + s + " not found");
    return -1.0;
#else
    int iE = elementIndex(elemName);
    if (iE < 0) {
      throw CanteraError("PDSS_HKFT::LookupGe", "element " + elemName + " not found");
    }
    doublereal geValue = entropyElement298(iE);
    if (geValue == ENTROPY298_UNKNOWN) {
      throw CanteraError("PDSS_HKFT::LookupGe",
                         "element " + elemName + " doesn not have a supplied entropy298");
    }
    geValue *= (-298.15);
    return geValue;
#endif
  }
Example #3
0
void Phase::addSpecies(const std::string& name_, const doublereal* comp,
                       doublereal charge_, doublereal size_)
{
    freezeElements();
    m_speciesNames.push_back(name_);
    m_speciesCharge.push_back(charge_);
    m_speciesSize.push_back(size_);
    size_t ne = nElements();
    // Create a changeable copy of the element composition. We now change
    // the charge potentially
    vector_fp compNew(ne);
    for (size_t m = 0; m < ne; m++) {
        compNew[m] = comp[m];
    }
    double wt = 0.0;
    const vector_fp& aw = atomicWeights();
    if (charge_ != 0.0) {
        size_t eindex = elementIndex("E");
        if (eindex != npos) {
            doublereal ecomp = compNew[eindex];
            if (fabs(charge_ + ecomp) > 0.001) {
                if (ecomp != 0.0) {
                    throw CanteraError("Phase::addSpecies",
                                       "Input charge and element E compositions differ "
                                       "for species " + name_);
                } else {
                    // Just fix up the element E composition based on the input
                    // species charge
                    compNew[eindex] = -charge_;
                }
            }
        } else {
            addUniqueElementAfterFreeze("E", 0.000545, 0, 0.0,
                                        CT_ELEM_TYPE_ELECTRONCHARGE);
            ne = nElements();
            eindex = elementIndex("E");
            compNew.resize(ne);
            compNew[ne - 1] = - charge_;
        }
    }
    for (size_t m = 0; m < ne; m++) {
        m_speciesComp.push_back(compNew[m]);
        wt += compNew[m] * aw[m];
    }
    m_molwts.push_back(wt);
    m_kk++;
}
Example #4
0
doublereal MineralEQ3::LookupGe(const std::string& elemName)
{
    size_t iE = elementIndex(elemName);
    if (iE == npos) {
        throw CanteraError("PDSS_HKFT::LookupGe", "element " + elemName + " not found");
    }
    doublereal geValue = entropyElement298(iE);
    if (geValue == ENTROPY298_UNKNOWN) {
        throw CanteraError("PDSS_HKFT::LookupGe",
                           "element " + elemName + " does not have a supplied entropy298");
    }
    geValue *= (-298.15);
    return geValue;
}
Example #5
0
bool Phase::addSpecies(shared_ptr<Species> spec) {
    m_species[spec->name] = spec;
    vector_fp comp(nElements());
    for (const auto& elem : spec->composition) {
        size_t m = elementIndex(elem.first);
        if (m == npos) { // Element doesn't exist in this phase
            switch (m_undefinedElementBehavior) {
            case UndefElement::ignore:
                return false;

            case UndefElement::add:
                addElement(elem.first);
                comp.resize(nElements());
                m = elementIndex(elem.first);
                break;

            case UndefElement::error:
            default:
                throw CanteraError("Phase::addSpecies",
                    "Species '{}' contains an undefined element '{}'.",
                    spec->name, elem.first);
            }
        }
        comp[m] = elem.second;
    }

    m_speciesNames.push_back(spec->name);
    m_speciesIndices[spec->name] = m_kk;
    m_speciesCharge.push_back(spec->charge);
    m_speciesSize.push_back(spec->size);
    size_t ne = nElements();

    double wt = 0.0;
    const vector_fp& aw = atomicWeights();
    if (spec->charge != 0.0) {
        size_t eindex = elementIndex("E");
        if (eindex != npos) {
            doublereal ecomp = comp[eindex];
            if (fabs(spec->charge + ecomp) > 0.001) {
                if (ecomp != 0.0) {
                    throw CanteraError("Phase::addSpecies",
                                       "Input charge and element E compositions differ "
                                       "for species " + spec->name);
                } else {
                    // Just fix up the element E composition based on the input
                    // species charge
                    comp[eindex] = -spec->charge;
                }
            }
        } else {
            addElement("E", 0.000545, 0, 0.0, CT_ELEM_TYPE_ELECTRONCHARGE);
            ne = nElements();
            eindex = elementIndex("E");
            comp.resize(ne);
            comp[ne - 1] = - spec->charge;
        }
    }
    for (size_t m = 0; m < ne; m++) {
        m_speciesComp.push_back(comp[m]);
        wt += comp[m] * aw[m];
    }

    // Some surface phases may define species representing empty sites
    // that have zero molecular weight. Give them a very small molecular
    // weight to avoid dividing by zero.
    wt = std::max(wt, Tiny);
    m_molwts.push_back(wt);
    m_rmolwts.push_back(1.0/wt);
    m_kk++;

    // Ensure that the Phase has a valid mass fraction vector that sums to
    // one. We will assume that species 0 has a mass fraction of 1.0 and mass
    // fraction of all other species is 0.0.
    if (m_kk == 1) {
        m_y.push_back(1.0);
        m_ym.push_back(m_rmolwts[0]);
        m_mmw = 1.0 / m_ym[0];
    } else {
        m_y.push_back(0.0);
        m_ym.push_back(0.0);
    }
    invalidateCache();
    return true;
}
Example #6
0
void WaterSSTP::initThermoXML(XML_Node& phaseNode, const std::string& id)
{
    /*
     * Do initializations that don't depend on knowing the XML file
     */
    initThermo();
    /*
     * Calculate the molecular weight. Note while there may
     * be a very good calculated weight in the steam table
     * class, using this weight may lead to codes exhibiting
     * mass loss issues. We need to grab the elemental
     * atomic weights used in the Element class and calculate
     * a consistent H2O molecular weight based on that.
     */
    size_t nH = elementIndex("H");
    if (nH == npos) {
        throw CanteraError("WaterSSTP::initThermo",
                           "H not an element");
    }
    double mw_H = atomicWeight(nH);
    size_t nO = elementIndex("O");
    if (nO == npos) {
        throw CanteraError("WaterSSTP::initThermo",
                           "O not an element");
    }
    double mw_O = atomicWeight(nO);
    m_mw = 2.0 * mw_H + mw_O;
    setMolecularWeight(0,m_mw);
    double one = 1.0;
    setMoleFractions(&one);

    /*
     * Set the baseline
     */
    doublereal T = 298.15;
    Phase::setDensity(7.0E-8);
    Phase::setTemperature(T);

    doublereal presLow = 1.0E-2;
    doublereal oneBar = 1.0E5;
    doublereal dd = m_sub.density(T, presLow, WATER_GAS, 7.0E-8);
    setDensity(dd);
    setTemperature(T);
    SW_Offset = 0.0;
    doublereal s = entropy_mole();
    s -= GasConstant * log(oneBar/presLow);
    if (s != 188.835E3) {
        SW_Offset = 188.835E3 - s;
    }
    s = entropy_mole();
    s -= GasConstant * log(oneBar/presLow);

    doublereal h = enthalpy_mole();
    if (h != -241.826E6) {
        EW_Offset = -241.826E6 - h;
    }
    h = enthalpy_mole();

    /*
     * Set the initial state of the system to 298.15 K and
     * 1 bar.
     */
    setTemperature(298.15);
    double rho0 = m_sub.density(298.15, OneAtm, WATER_LIQUID);
    setDensity(rho0);

    m_waterProps.reset(new WaterProps(&m_sub));

    /*
     * We have to do something with the thermo function here.
     */
    delete m_spthermo;
    m_spthermo = 0;

    /*
     * Set the flag to say we are ready to calculate stuff
     */
    m_ready = true;
}
Example #7
0
void LatticeSolidPhase::installSlavePhases(Cantera::XML_Node* phaseNode)
{
    size_t kk = 0;
    size_t kstart = 0;
    m_speciesData.clear();

    XML_Node& eosdata = phaseNode->child("thermo");
    XML_Node& la = eosdata.child("LatticeArray");
    std::vector<XML_Node*> lattices = la.getChildren("phase");
    for (size_t n = 0; n < m_nlattice; n++) {
        LatticePhase* lp = m_lattice[n];
        size_t nsp =  lp->nSpecies();
        vector<doublereal> constArr(lp->nElements());
        const vector_fp& aws = lp->atomicWeights();
        for (size_t es = 0; es < lp->nElements(); es++) {
            string esName = lp->elementName(es);
            double wt = aws[es];
            int an = lp->atomicNumber(es);
            int e298 = lp->entropyElement298(es); //! @todo Why is this an int instead of a double?
            int et = lp->elementType(es);
            addElement(esName, wt, an, e298, et);
        }
        const std::vector<const XML_Node*> & spNode =  lp->speciesData();
        kstart = kk;


        for (size_t k = 0; k < nsp; k++) {
            std::string sname = lp->speciesName(k);
            std::map<std::string, double> comp;
            lp->getAtoms(k, DATA_PTR(constArr));
            size_t nel = nElements();
            vector_fp ecomp(nel, 0.0);
            for (size_t m = 0; m < lp->nElements(); m++) {
                if (constArr[m] != 0.0) {
                    std::string oldEname = lp->elementName(m);
                    size_t newIndex = elementIndex(oldEname);
                    if (newIndex == npos) {
                        throw CanteraError("LatticeSolidPhase::installSlavePhases",
                                           "element not found");
                    }
                    ecomp[newIndex] = constArr[m];
                }
            }
            double chrg = lp->charge(k);
            double sz = lp->size(k);
            addUniqueSpecies(sname, &ecomp[0], chrg, sz);
            SpeciesThermoInterpType* stit = newSpeciesThermoInterpType(*spNode[k]);
            stit->setIndex(kk);
            stit->validate(spNode[k]->attrib("name"));
            m_spthermo->install_STIT(stit);
            m_speciesData.push_back(new XML_Node(*(spNode[k])));
            kk++;
        }
        /*
         *  Add in the lattice stoichiometry constraint
         */
        if (n > 0) {
            string econ = "LC_";
            econ += int2str(n);
            econ += "_" + id();
            size_t m = addElement(econ, 0.0, 0, 0.0, CT_ELEM_TYPE_LATTICERATIO);
            size_t mm = nElements();
            LatticePhase* lp0 = m_lattice[0];
            size_t nsp0 =  lp0->nSpecies();
            for (size_t k = 0; k < nsp0; k++) {
                m_speciesComp[k * mm + m] = -theta_[0];
            }
            for (size_t k = 0; k < nsp; k++) {
                size_t ks = kstart + k;
                m_speciesComp[ks * mm + m] = theta_[n];
            }
        }
    }
}
Example #8
0
    /**
     * The algorithm used is fast marching reinitialization.
     */
    void Grid::reinitialize() {
        struct Element {
            vec3i position;

            float distance;
            float sign;
            float signedDistance;

            Element(vec3i const& position_, float distance_)
                : position(position_), distance(distance_) {
                sign = distance > 0.0f ? 1.0f : -1.0f;

                signedDistance = std::abs(distance);
            }

            bool operator < (Element const& rhs) const {
                return signedDistance > rhs.signedDistance;
            }
        };

        std::priority_queue<Element> elements;

        for(int z=0; z<dimensions_.z; ++z)
        for(int y=0; y<dimensions_.y; ++y)
        for(int x=0; x<dimensions_[0]; ++x) {
            int i = elementIndex(vec3i(x,y,z));

            if(!isnan(values_[i])) {
                elements.push(
                    Element(vec3i(x,y,z),values_[i]));
            }
        }

        if(elements.empty()) {
            int nVoxels = dimensions_[0] * dimensions_.y * dimensions_.z;

            for(int i=0; i<nVoxels; ++i) {
                values_[i] = std::numeric_limits<float>::infinity();
            }
        }

        while(!elements.empty()) {
            Element element = elements.top();
            elements.pop();

            if(element.distance != values_[elementIndex(element.position)]) {
                // invalidated
                continue;
            }

            for(int dz=-1; dz<=1; ++dz)
            for(int dy=-1; dy<=1; ++dy)
            for(int dx=-1; dx<=1; ++dx) {
                if(dx==0 && dy==0 && dz==0) {
                    continue;
                }

                vec3i position = element.position + vec3i(dx,dy,dz);

                if(!isInBounds(position, vec3i(0,0,0), dimensions_)) {
                    continue;
                }

                vec3f direction(
                    voxelDimensions_[0] * dx,
                    voxelDimensions_.y * dy,
                    voxelDimensions_.z * dz);

                float candidateDistance =
                    element.distance 
                    + element.sign * direction.length();

                int i = elementIndex(position);

                if(isnan(values_[i])
                    || (std::abs(candidateDistance) < std::abs(values_[i])
                    && candidateDistance * values_[i] > 0)) {
                    values_[i] = candidateDistance;

                    elements.push(
                        Element(position,candidateDistance));
                }
            }
        }
    }
Example #9
0
		acwordlist[0].y1 = 0;
		acwordlist[0].x2 = 0;
		acwordlist[0].y2 = 0;
		acwordlist[0].pnum = paragraph;
		acwordlist[0].wnum = cr.elementIndex();

		cr = is_footnote_mode() ? footview->textArea().endCursor() : bookview->textArea().endCursor();
		paragraph = !cr.isNull() ? cr.paragraphCursor().index() : 0;

		acwordlist[1].word = strdup("");
		acwordlist[1].x1 = ScreenWidth();
		acwordlist[1].y1 = ScreenHeight() - PanelHeight();
		acwordlist[1].x2 = ScreenWidth();
		acwordlist[1].y2 = ScreenHeight() - PanelHeight();
		acwordlist[1].pnum = paragraph;
		acwordlist[1].wnum = cr.elementIndex();

		acwlistcount = 2;
	}
}

void new_synopsis_note()
{
	PrepareSynTOC(0);
	restore_current_position();
	mainApplication->refreshWindow();
	IfEmptyWordList();
	List.Clear();
	List.Add(acwordlist, acwlistcount, 1);

	ibitmap *bm1=NULL, *bm2=NULL;
Example #10
0
// ---------------------------------------------------------------------------
// CCmFmUpnpMngr::ParseImageResolutions
// ---------------------------------------------------------------------------
//
const CUpnpElement& CCmFmUpnpMngr::ParseImageResolutions(
    RUPnPElementsArray& aResElementsArray )
{
    LOG(_L("[FILL MNGR]\t CCmFmUpnpMngr::ParseImageResolutions"));

    TInt elementIndex( KErrNone );
    TSize matchingSize( 0, 0 );
    for( TInt i = 0 ; i < aResElementsArray.Count(); i++ )
    {
        const CUpnpAttribute* attribute =
            UPnPItemUtility::FindAttributeByName( *aResElementsArray[i],
                    KAttributeResolution() );

        if( attribute )
        {
            TPtrC8 resolution( attribute->Value() );
            TInt index = resolution.Find( KCmFmXMark );
            if( index != KErrNotFound )
            {
                TLex8 lexH( resolution.Mid( index + 1 ) );
                TInt height( KErrNone );
                TInt err = lexH.Val( height );
                TRACE(Print(_L("[FILL MNGR]\t Val( height ) = %d"), err ));

                TInt width( KErrNone );
                TLex8 lexW( resolution.Mid( 0, index ) );
                err = lexW.Val( width );
                TRACE(Print(_L("[FILL MNGR]\t Val( width ) = %d"), err ));

                TRACE(Print(_L("[FILL MNGR]\t Sizes in landscape mode!!!")));
                TRACE(Print(_L("[FILL MNGR]\t Image heigth = %d"), height ));
                TRACE(Print(_L("[FILL MNGR]\t Image width = %d"), width ));
                if( height >= iScreenSize.iWidth && width >=
                        iScreenSize.iHeight )
                {
                    if( matchingSize.iHeight == 0 )
                    {
                        matchingSize.iHeight = height;
                        matchingSize.iWidth = width;
                        elementIndex = i;
                    }
                    else
                    {
                        if( matchingSize.iHeight > height &&
                                matchingSize.iWidth > width )
                        {
                            matchingSize.iHeight = height;
                            matchingSize.iWidth = width;
                            elementIndex = i;
                        }

                    }
                }
            }
        }
        else
        {
            LOG(_L("[FILL MNGR]\t attribute == NULL"));
        }
    }
    TRACE(Print(_L("[FILL MNGR]\t Selected height = %d"),
                matchingSize.iHeight ));
    TRACE(Print(_L("[FILL MNGR]\t Selected width = %d"),
                matchingSize.iWidth ));
    TRACE(Print(_L("[FILL MNGR]\t Selected elementIndex = %d"),
                elementIndex ));
    return *aResElementsArray[ elementIndex ];
}