Fish - FiberLib for VISH 0.3
Fish - The Fiber Bundle API for the Vish Visualization Shell
Macros | Functions
050-BigDataOutOfCoreFragments.cpp File Reference

[← Previous Example] [Next Example → 051-CopyBoundFragments.cpp ]. More...

#include <fiber/bundle/Bundle.hpp>
#include <fiber/finit/FinitAPI.h>
#include <fiber/field/ArrayRef.hpp>
#include <fiber/field/UniformCartesianArray.hpp>
#include <memcore/MemUsage.hpp>

Macros

#define Verbose(X)   AppVerbose("Example",X)
 

Functions

int main ()
 

Detailed Description

[← Previous Example] [Next Example → 051-CopyBoundFragments.cpp ].

In FiberLib Tutorial

#include <fiber/bundle/Bundle.hpp>
#include <fiber/finit/FinitAPI.h>
#include <fiber/field/ArrayRef.hpp>
#include <fiber/field/UniformCartesianArray.hpp>
#include <memcore/MemUsage.hpp>
using namespace Fiber;
using namespace Eagle::PhysicalSpace;
#undef Verbose
#define Verbose(X) AppVerbose("Example",X)
int main()
{
// Initialize I/O layers (only for static binaries)
Finit();
try
{
RefPtr<Cache>&theGlobalCache = Cache::MemCache();
const int kB = 1024, MB = kB*kB;
// Se the cache size to 1kB to test out the exception handling.
#if 0
theGlobalCache->setMaxCost( 1*kB );
#else
// theGlobalCache->setMaxCost( 3*MB );
/*
One fragment uses 2MB of RAM, so if the maxcost is set to e.g. 7MB
then we can hold three fragments in RAM and when creating a 4th
one the first one will need to be written.
*/
theGlobalCache->setMaxCost( 7*MB );
#endif
//
// Create a bundle object with a grid at T=1.0, named "DemoGrid", in
// a three-dimensional Cartesian representation, using the default
// coordinate system.
//
Representation&myCartesianRepresentation = BP[1.0]["DemoGrid"].makeCartesianRepresentation(3);
//
// Save the bundle to a file, which at this point
// associates the bundle with the given output file.
// The file will be kept open and any data that are
// added to the bundle will also be added to the file,
// either at destruction of the bundle or when
// memory becomes short.
//
BP->bindToNew("050_BigDataOutOfCoreFragments.f5");
//
// Create two fields, no data or fragmentation specified yet
//
RefPtr<Field>&Positions = myCartesianRepresentation[ FIBER_POSITIONS ];
Eagle::point3 BBoxMin(-1.0, -1.0, -0.5), BBoxMax( 1.0, 1.0, 0.5);
const int nTilesX = 4, nTilesY = 4;
Eagle::tvector3 FragmentDiagonal = (BBoxMax - BBoxMin).multiply( 1.0/ nTilesX, 1.0/ nTilesY, 1.0);
{
{
//
// Produce a couple of fragments
//
for(int tileY = 0; tileY < nTilesY; tileY++)
for(int tileX = 0; tileX < nTilesX; tileX++)
{
//
// Generate a unique name for the fragment
// The name is of no relevance and could also
// be just a random string.
//
const char xc[] = { char('0' + tileX),0},
yc[] = { char('0' + tileY),0};
string FragmentName = "tile";
FragmentName += xc;
FragmentName += "x";
FragmentName += yc;
Verbose(0) << "****Creating new fragment [" << FragmentName << "], currently using "
<< getMemUsage()-InitialMemUsage << "B of RAM"
<< ", cache uses "
<< theGlobalCache->totalCost() << " Bytes ("
<< theGlobalCache->totalCost()/MB << "MB)";
//
// Define the size of the fragment to be used henceforth
//
const MultiIndex<3> Dims = MIndex(64,64,64); // blocksize is 256k
Eagle::point3 FragmentBBoxMin = BBoxMin + FragmentDiagonal.multiply( tileX, tileY, 0.0);
//
// Produce uniform coordinates for the given fragment.
//
FragmentDiagonal.multiply(1.0/(Dims[0]-1), 1.0/(Dims[1]-1), 1.0/(Dims[2]-1) ) );
Coordinates->CacheInfoString = "Coordinates for " + FragmentName;
Positions->createCreator(Coordinates, FragmentName);
Positions->setFragmentOffset( FragmentName,
MIndex( tileX*Dims[0], tileY*Dims[1], 0*Dims[2] ) );
{
GridValues->CacheInfoString = "Data for " + FragmentName;
for(auto I : Dims)
{
double& value = GridValues[ I ];
Eagle::point3 P = Pts[ I ];
//
// Some analytic function here used to produce some
// halfway interestingly looking scalar field.
//
value = P.x()*P.x() - P.y()*P.y() + P.z()*P.z();
}
Values << FragmentName << GridValues;
// equivalent to:
// Values->createCreator(GridValues, FragmentName);
}
}
}
Verbose(0) << "Before purging: cache uses "<< theGlobalCache->totalCost() << " Bytes.";
theGlobalCache->purge();
}
Verbose(0) << "After purging: cache uses "<< theGlobalCache->totalCost() << " Bytes.";
}
{
if (MemError.myCacheable)
Verbose(0) << " Out of memory, could not handle object "
<< MemError.myCacheable->getCacheInfoString() << " .";
else
Verbose(0) << " Out of memory.";
}
return 0;
}
Convenience class that implements a pointer to a Bundle object but adds some useful member funtions t...
Definition Bundle.hpp:779
An iterator with an optional DataCreator, which is just a class to intercept creation of data along a...
Definition CreativeIterator.hpp:34
A Representation is a set of Field objects, each of them accessed via some FieldID identifier.
Definition Representation.hpp:101
Convenience class for procedural linear arrays in cartesian coordinates.
Definition UniformCartesianArray.hpp:22
Given a fragmented field of curvilinear coordinates, (3D array of coordinates), build a uniform Grid ...
Definition FAQ.dox:2
unsigned long long getMemUsage()