Fish - FiberLib for VISH 0.3
Fish - The Fiber Bundle API for the Vish Visualization Shell
060-RegularFragmentTopology.cpp File Reference

[← Previous Example] [Next Example → 061-RegularFragmentTopologyWithHigherTopology.cpp ]. More...

#include <fiber/bundle/Bundle.hpp>
#include <fiber/finit/FinitAPI.h>
#include <fiber/field/ArrayRef.hpp>
#include <fiber/field/RegularlyFragmentedField.hpp>
#include <fiber/field/UniformCartesianArray.hpp>
#include <fiber/grid/types/FragmentedUniformGrid3D.hpp>

Functions

int main ()

Detailed Description

[← Previous Example] [Next Example → 061-RegularFragmentTopologyWithHigherTopology.cpp ].

In FiberLib Tutorial

#include <fiber/bundle/Bundle.hpp>
#include <fiber/finit/FinitAPI.h>
#include <fiber/field/ArrayRef.hpp>
#include <fiber/field/RegularlyFragmentedField.hpp>
#include <fiber/field/UniformCartesianArray.hpp>
#include <fiber/grid/types/FragmentedUniformGrid3D.hpp>
using namespace Fiber;
using namespace Eagle::PhysicalSpace;
int main()
{
// Initialize I/O layers (required for standalone programs)
Finit();
RefPtr<Cache>&theGlobalCache = Cache::MemCache();
const int KiB = 1024, MiB = KiB*KiB;
#if 1
theGlobalCache->setMaxCost( 3*MiB );
#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.
//
Grid&myGrid = BP[0.0]["DemoGrid"];
BP->bindTo("outfile.f5");
#if 0
Verbose(0) << " --> have regular positions.";
else
Verbose(0) << " --> we do NOT have regular positions.";
#endif
Eagle::point3 BBoxMin(-1.0, -1.0, -0.5), BBoxMax( 1.0, 1.0, 0.5);
MultiIndex<3> NumberOfFragments =
#if 0
MIndex(7,9,3); // large dataset
#else
MIndex(3,2,1); // small dataset
#endif
const MultiIndex<3> BlockSize = { 64,64,64 }; // blocksize is 256k
MyUniGrid3D = FragmentedUniformGrid3D::create( NumberOfFragments,
myGrid,
BBoxMin,
BlockSize,
BBoxMax);
if (!MyUniGrid3D)
{
Verbose(0) << "Could not create a fragmented uniform grid - incompatible bind file?";
return 0;
}
if (MyUniGrid3D.Positions->nFragments() == 0)
{
Verbose(0) << " error, no input fragments found!";
return 1;
}
RefPtr< RegularlyFragmentedField<3> > Values = MyUniGrid3D.newVertexField( "Values");
const MultiIndex<3>&N = MyUniGrid3D.NumberOfFragments();
//
// Iterate over all fragments
//
{
VerboseSection(0,' ');
Verbose(0) << "Iterating over " << N << " fragments.";
for(MultiIndex<3> FragmentIndex : N)
{
RefPtr<FragmentID> fID = MyUniGrid3D.getFragmentID( FragmentIndex );
//
// Add some data to each field fragment.
//
{
ArrayRef<double, 3> GridValues(BlockSize);
GridValues->CacheInfoString = "Data for " + fID->Name();
auto U = MyUniGrid3D.getCoords(FragmentIndex);
if (!U)
{
Verbose(0) << "Unsuitable fragment coordinates: " << MyUniGrid3D.FragmentCoordinates;
Verbose(0) << "Unsuitable positions: " << MyUniGrid3D.Positions;
RefPtr< RegularlyFragmentedField<3> > R = MyUniGrid3D.Positions;
Verbose(1) << "Fragments: " << R->getNumberOfFragments() << " Index: " << FragmentIndex;
Verbose(1) << "Regular Positions:\n" << R->xml();
auto C = MyUniGrid3D.getCoordCreator( FragmentIndex );
Verbose(0) << "Creator: " << C;
if (C) Verbose(0) << "Data: " << C->create();
break;
}
for(MultiIndex<3> I : BlockSize)
{
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();
}
if (MemBase::Creator_t
ValueCreator = Values->createCreator(GridValues, fID) )
{
ValueCreator->touch();
}
}
printf("**** At fragment [%s] cache uses %ld Bytes (%ldMiB) \n",
fID->Name().c_str(), long(theGlobalCache->totalCost() ),
long(theGlobalCache->totalCost() )/MiB
);fflush(stdout);
}
}
printf("After fragment loop: cache uses %ld Bytes\n", long(theGlobalCache->totalCost() ));fflush(stdout);
return 0;
}
int main()
Demonstrates minimal usage of the FiberLib Create Bundle, insert a time slice, and safe it to a file.
Definition 010-SimpleSave.cpp:13
An array reference class, which is a convenience class for reference pointers to multidimensional mem...
Definition ArrayRef.hpp:28
Convenience class that implements a pointer to a Bundle object but adds some useful member funtions t...
Definition Bundle.hpp:779
A Grid is a set of Skeleton objects, each of them accessed via some unique SkeletonID object.
Definition Grid.hpp:60
RefPtr< Field > getCartesianPositions() const
Shortcut function: get the coordinates of the vertices in the default cartesian chart.
Definition Grid.hpp:246
A multidimensional index that is automatically a lower-dimensional index via recursion.
Definition MultiIndex.hpp:449
A convenience class for optimized handling of fields that are fragmented in a regular manner (n-dimen...
Definition RegularlyFragmentedField.hpp:27
Convenience class for procedural linear arrays in cartesian coordinates.
Definition UniformCartesianArray.hpp:15
static RefPtr< Cache, CacheBase > & MemCache()
StrongPtr< Object, ObjectBase > RefPtr
Given a fragmented field of curvilinear coordinates, (3D array of coordinates), build a uniform Grid ...
Definition FAQ.dox:2
Definition FragmentedUniformGrid3D.hpp:12
static FragmentedUniformGrid3D create(const MultiIndex< 3 > &NumberOfFragments, Grid &myGrid, const Eagle::point3 &start, const MultiIndex< 3 > &PerFragmentDims, const Eagle::point3 &end, const MultiIndex< 3 > &Overlap={1, 1, 1})
Create a fragmented uniform grid in cartesian coordinates within the given bounding box as specified ...
Definition FragmentedUniformGrid3D.cpp:54
RefPtr< CoordsArray_t > getCoords(const MultiIndex< 3 > &I) const
Get the coordinates for the given fragment via its fragment index.
Definition FragmentedUniformGrid3D.hpp:64
RefPtr< UniformCartesianArray > FragmentCoordinates
The coordinates, i.e. corner points, of each fragment.
Definition FragmentedUniformGrid3D.hpp:17
RefPtr< RegularlyFragmentedField< VertexDims > > newVertexField(const char *Fieldname)
Create a new regularly fragmented field on the vertices under the given name, overwriting an existing...
Definition grid/types/RegularlyFragmentedGrid.hpp:338
RefPtr< RegularlyFragmentedField< VertexDims > > Positions
Field for the vertex coordinates.
Definition grid/types/RegularlyFragmentedGrid.hpp:310
MultiIndex< VertexDims > NumberOfFragments() const
Get the number of fragments here as multi-dimensional index.
Definition grid/types/RegularlyFragmentedGrid.hpp:374
RefPtr< FragmentID > getFragmentID(const MultiIndex< VertexDims > &FragmentIndex) const
Get the fragment ID for the given fragment index.
Definition grid/types/RegularlyFragmentedGrid.hpp:122