static word getFieldViewName(const word& foamName)
{
    if (FieldviewNames.found(foamName))
    {
        return FieldviewNames[foamName];
    }
    else
    {
        return foamName;
    }
}
Esempio n. 2
0
Foam::label Foam::HashTable<T, Key, Hash>::erase
(
    const HashTable<AnyType, Key, AnyHash>& rhs
)
{
    label count = 0;

    // Remove rhs keys from this table - terminates early if possible
    // Could optimize depending on which hash is smaller ...
    for (iterator iter = begin(); iter != end(); ++iter)
    {
        if (rhs.found(iter.key()) && erase(iter))
        {
            count++;
        }
    }

    return count;
}
Esempio n. 3
0
/* For each column of fixed x value, find the point whose z value is closest to h.
   Update those points to have a z value of h.
 */
void snapNearestPointsToSurface(
        IOField<point>& newPoints,
        const Mountain& mountain)
{
	HashTable<int, scalar> minDistances;
	HashTable<int, scalar> closestZcoords;

	forAll(newPoints, ip)
	{
	    int x = roundUp(newPoints[ip].x(), 10); // FIXME: this hashtable method is dubious because it's not safe to compare doubles for equality
	    scalar z = newPoints[ip].z();
	    scalar h = mountain.heightAt(x);
	    scalar distance = abs(z - h);
	    
	    if (!minDistances.found(x) || distance < minDistances[x])
	    {
            minDistances.set(x, distance);
            closestZcoords.set(x, z);
	    }
	}
Esempio n. 4
0
Foam::processorGAMGInterface::processorGAMGInterface
(
    const lduInterface& fineInterface,
    const labelField& localRestrictAddressing,
    const labelField& neighbourRestrictAddressing
)
:
    GAMGInterface
    (
        fineInterface,
        localRestrictAddressing,
        neighbourRestrictAddressing
    ),
    fineProcInterface_(refCast<const processorLduInterface>(fineInterface))
{
    // Make a lookup table of entries for owner/neighbour
    HashTable<SLList<label>, label, Hash<label> > neighboursTable
    (
        localRestrictAddressing.size()
    );

    // Table of face-sets to be agglomerated
    HashTable<SLList<SLList<label> >, label, Hash<label> > faceFaceTable
    (
        localRestrictAddressing.size()
    );

    label nCoarseFaces = 0;

    forAll (localRestrictAddressing, ffi)
    {
        label curMaster = -1;
        label curSlave = -1;

        // Do switching on master/slave indexes based on the owner/neighbour of
        // the processor index such that both sides get the same answer.
        if (myProcNo() < neighbProcNo())
        {
            // Master side
            curMaster = localRestrictAddressing[ffi];
            curSlave = neighbourRestrictAddressing[ffi];
        }
        else
        {
            // Slave side
            curMaster = neighbourRestrictAddressing[ffi];
            curSlave = localRestrictAddressing[ffi];
        }

        // Look for the master cell.  If it has already got a face,
        // add the coefficient to the face.  If not, create a new face.
        if (neighboursTable.found(curMaster))
        {
            // Check all current neighbours to see if the current slave already
            // exists and if so, add the fine face to the agglomeration.

            SLList<label>& curNbrs = neighboursTable.find(curMaster)();

            SLList<SLList<label> >& curFaceFaces =
                faceFaceTable.find(curMaster)();

            bool nbrFound = false;

            SLList<label>::iterator nbrsIter = curNbrs.begin();

            SLList<SLList<label> >::iterator faceFacesIter =
                curFaceFaces.begin();

            for
            (
                ;
                nbrsIter != curNbrs.end(), faceFacesIter != curFaceFaces.end();
                ++nbrsIter, ++faceFacesIter
            )
            {
                if (nbrsIter() == curSlave)
                {
                    nbrFound = true;
                    faceFacesIter().append(ffi);
                    break;
                }
            }

            if (!nbrFound)
            {
                curNbrs.append(curSlave);
                curFaceFaces.append(ffi);

                // New coarse face created
                nCoarseFaces++;
            }
        }
        else
        {
            // This master has got no neighbours yet.  Add a neighbour
            // and a coefficient, thus creating a new face
            neighboursTable.insert(curMaster, SLList<label>(curSlave));
            faceFaceTable.insert(curMaster, SLList<SLList<label> >(ffi));

            // New coarse face created
            nCoarseFaces++;
        }
    } // end for all fine faces
Esempio n. 5
0
void setUpdater::updateSets(const mapPolyMesh& morphMap) const
{
    //
    // Update all sets in memory.
    //

    HashTable<const Type*> memSets = 
        morphMap.mesh().objectRegistry::lookupClass<Type>();

    for
    (
        typename HashTable<const Type*>::iterator iter = memSets.begin();
        iter != memSets.end();
        ++iter
    )
    {
        Type& set = const_cast<Type&>(*iter());

        if (debug)
        {
            Pout<< "Set:" << set.name() << " size:" << set.size()
                << " updated in memory" << endl;
        }

        set.updateMesh(morphMap);

        // Write or not? Debatable.
        set.write();
    }


    //
    // Update all sets on disk
    //

    // Get last valid mesh (discard points-only change)
    IOobjectList Objects
    (
        morphMap.mesh().time(),
        morphMap.mesh().time().findInstance
        (
            morphMap.mesh().meshDir(),
            "faces"
        ),
        "polyMesh/sets"
    );

    IOobjectList fileSets(Objects.lookupClass(Type::typeName));

    for
    (
        IOobjectList::const_iterator iter = fileSets.begin();
        iter != fileSets.end();
        ++iter
    )
    {
        if (!memSets.found(iter.key()))
        {
            // Not in memory. Load it.
            Type set(*iter());

            if (debug)
            {
                Pout<< "Set:" << set.name() << " size:" << set.size()
                    << " updated on disk" << endl;
            }

            set.updateMesh(morphMap);

            set.write();
        }
        else
        {
            if (debug)
            {
                Pout<< "Set:" << iter.key() << " already updated from memory"
                    << endl;
            }
        }
    }
}
Esempio n. 6
0
void Foam::PrintTable<KeyType, DataType>::print
(
    Ostream& os,
    const bool printSum,
    const bool printAverage
) const
{
    HashTable<HashTable<DataType, label>, KeyType> combinedTable;

    List<HashTableData> procData(Pstream::nProcs(), HashTableData());

    procData[Pstream::myProcNo()] = table_;

    Pstream::gatherList(procData);

    if (Pstream::master())
    {
        label largestKeyLength = 6;
        label largestDataLength = 0;

        List<label> largestProcSize(Pstream::nProcs(), 0);

        forAll(procData, procI)
        {
            const HashTableData& procIData = procData[procI];

            for
            (
                typename HashTableData::const_iterator iter = procIData.begin();
                iter != procIData.end();
                ++iter
            )
            {
                if (!combinedTable.found(iter.key()))
                {
                    combinedTable.insert
                    (
                        iter.key(),
                        HashTable<DataType, label>()
                    );
                }

                HashTable<DataType, label>& key = combinedTable[iter.key()];

                key.insert(procI, iter());

                for
                (
                    typename HashTable<DataType, label>
                        ::const_iterator dataIter = key.begin();
                    dataIter != key.end();
                    ++dataIter
                )
                {
                    std::ostringstream buf;
                    buf << dataIter();

                    largestDataLength = max
                    (
                        largestDataLength,
                        label(buf.str().length())
                    );
                }

                std::ostringstream buf;
                buf << iter.key();

                largestKeyLength = max
                (
                    largestKeyLength,
                    label(buf.str().length())
                );
            }
        }

        os.width(largestKeyLength);
        os  << nl << indent << tab << "# " << title_.c_str() << endl;

        os.width(largestKeyLength);
        os  << indent << "# Proc";

        forAll(procData, procI)
        {
            os  << tab;
            os.width(largestDataLength);
            os  << procI;
        }

        if (printSum)
        {
            os  << tab;
            os.width(largestDataLength);
            os  << "Sum";
        }

        if (printAverage)
        {
            os  << tab;
            os.width(largestDataLength);
            os  << "Average";
        }

        os  << endl;

        const List<KeyType>& sortedTable = combinedTable.sortedToc();

        forAll(sortedTable, keyI)
        {
            const HashTable<DataType, label>& procDataList
                = combinedTable[sortedTable[keyI]];

            os.width(largestKeyLength);
            os  << indent << sortedTable[keyI];

            forAll(procDataList, elemI)
            {
                os  << tab;
                os.width(largestDataLength);
                os  << procDataList[elemI];
            }

            if (printSum)
            {
                DataType sum = 0;
                forAll(procDataList, elemI)
                {
                    sum += procDataList[elemI];
                }

                os  << tab;
                os.width(largestDataLength);
                os  << sum;

                if (printAverage)
                {
                    os  << tab;
                    os.width(largestDataLength);
                    os  << sum/Pstream::nProcs();
                }
            }

            os  << endl;
        }