Lagrangian Liquid Simulation
Master Thesis project on simulation of liquids using Lagrangian approach and SPH
Cache Class Reference

manage list of cache items per frame and writes them to disk at a regular interval More...

#include <Cache.h>

List of all members.

Public Member Functions

 Cache ()
 ctor
void addItem (const CacheItem &_cacheItem)
 add cache items to the cache
int getCacheCount () const
 return the number of items in the cache
void flushCache (const std::string _path)
 writes the contents of the cache to file

Private Member Functions

void writePointData (std::vector< ngl::Vector > &_positionList, const std::string &_filename)
 write point positions (fluid and sphere) to file
void writeBoundaryData (std::vector< ngl::Vector > &_positionList, const std::string &_filename)
 write the boundary box information to file

Private Attributes

std::vector< CacheItemm_fluidCache
 the list of cache items held in the cache

Detailed Description

manage list of cache items per frame and writes them to disk at a regular interval

Definition at line 16 of file Cache.h.


Constructor & Destructor Documentation

Cache::Cache ( )

ctor

Definition at line 8 of file Cache.cpp.

{

}

Member Function Documentation

void Cache::addItem ( const CacheItem _cacheItem)

add cache items to the cache

Parameters:
[in]_cacheItemthe item to add to the cache list

Definition at line 13 of file Cache.cpp.

References m_fluidCache.

{
    m_fluidCache.push_back(_cacheItem);
}

Here is the caller graph for this function:

void Cache::flushCache ( const std::string  _path)

writes the contents of the cache to file

Definition at line 18 of file Cache.cpp.

References BOUNDARY_CACHE, CAPSULE_CACHE, FLUID_CACHE, CacheItem::getCacheItemType(), CacheItem::getFrameNumber(), CacheItem::getNameList(), CacheItem::getPositionList(), m_fluidCache, SPHERE_CACHE, writeBoundaryData(), and writePointData().

{
    //loop through cache items
    for (int i = 0; i < m_fluidCache.size(); ++i)
    {
        //get cache item
        CacheItem item = m_fluidCache[i];

        //loop through name list of the item
        for (int j = 0; j < item.getNameList().size(); ++j)
        {
            //determine type of item
            std::string itemType;
            if (item.getCacheItemType() == FLUID_CACHE)
                itemType = "Fluid";
            else if (item.getCacheItemType() == BOUNDARY_CACHE)
                itemType = "Boundary";
            else if (item.getCacheItemType() == SPHERE_CACHE)
                itemType = "Sphere";
            else if (item.getCacheItemType() == CAPSULE_CACHE)
                itemType = "Capsule";
            else
                itemType = "NA";

            //construct filename of the item for the current frame number
            QString text = QString("%1%2_%3_Frame_%4.geo")
                            .arg(_path.c_str())
                            .arg(itemType.c_str())
                            .arg(std::string(item.getNameList()[j]).c_str())
                            .arg(item.getFrameNumber());

            //write data to file
            if (item.getCacheItemType() == FLUID_CACHE || item.getCacheItemType() == SPHERE_CACHE || item.getCacheItemType() == CAPSULE_CACHE)
                writePointData(item.getPositionList()[j], text.toStdString());
            else if (item.getCacheItemType() == BOUNDARY_CACHE)
                writeBoundaryData(item.getPositionList()[j], text.toStdString());

        }
    }

    //clear cache
    m_fluidCache.clear();
}

Here is the call graph for this function:

Here is the caller graph for this function:

int Cache::getCacheCount ( ) const [inline]

return the number of items in the cache

Definition at line 27 of file Cache.h.

References m_fluidCache.

{ return m_fluidCache.size(); }
void Cache::writeBoundaryData ( std::vector< ngl::Vector > &  _positionList,
const std::string &  _filename 
) [private]

write the boundary box information to file

Parameters:
[in]_positionListthe position list to write out
[in]_filenamethe name of the file on disk

Definition at line 96 of file Cache.cpp.

{
    //open file for writing
    std::ofstream outFile(_filename.c_str(), std::ios::out);

    //write header
    outFile << "PGEOMETRY V5\n";
    outFile << "NPoints 8 NPrims 6\n";
    outFile << "NPointGroups 0 NPrimGroups 0\n";
    outFile << "NPointAttrib 0 NVertexAttrib 0 NPrimAttrib 0 NAttrib 0\n";

    //loop through position list
    for (int i = 0; i < _positionList.size(); ++i)
    {
        outFile
                << _positionList[i].m_x << " "
                << _positionList[i].m_y << " "
                << _positionList[i].m_z << " "
                << _positionList[i].m_w << "\n";
    }

    //write box vertex connections
    outFile << "Run 6 Poly\n";
    outFile << " 4 < 1 5 4 0\n";
    outFile << " 4 < 2 6 5 1\n";
    outFile << " 4 < 3 7 6 2\n";
    outFile << " 4 < 0 4 7 3\n";
    outFile << " 4 < 2 1 0 3\n";
    outFile << " 4 < 5 6 7 4\n";

    //write the outro
    outFile << "beginExtra\n";
    outFile << "endExtra";

    //close file
    outFile.close();
}

Here is the caller graph for this function:

void Cache::writePointData ( std::vector< ngl::Vector > &  _positionList,
const std::string &  _filename 
) [private]

write point positions (fluid and sphere) to file

Parameters:
[in]_positionListthe position list to write out
[in]_filenamethe name of the file on disk

Definition at line 63 of file Cache.cpp.

{
    //open file for writing
    std::ofstream outFile(_filename.c_str(), std::ios::out);

    //write header
    outFile << "PGEOMETRY V5\n";
    outFile << "NPoints " << _positionList.size() << " NPrims 0\n";
    outFile << "NPointGroups 0 NPrimGroups 0\n";
    outFile << "NPointAttrib 0 NVertexAttrib 0 NPrimAttrib 0 NAttrib 0\n";

    //loop through position list
    for (int i = 0; i < _positionList.size(); ++i)
    {
        outFile
                << _positionList[i].m_x << " "
                << _positionList[i].m_y << " "
                << _positionList[i].m_z << " "
                << _positionList[i].m_w << "\n";
    }

    //write the outro
    outFile << "beginExtra\n";
    outFile << "endExtra";

    //close file
    outFile.close();
}

Here is the caller graph for this function:


Member Data Documentation

std::vector<CacheItem> Cache::m_fluidCache [private]

the list of cache items held in the cache

Definition at line 34 of file Cache.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator