Demonstration of Creation of a scalar field on a uniform grid.
#include <iostream> #include <bundle/Bundle.hpp> #include <grid/CartesianChart.hpp> #include <field/DirectProductArray.hpp> #include <ocean/eagle/PhysicalSpace.hpp> using namespace Fiber; using namespace std; using namespace MemCore; using namespace Eagle; int main() { BundlePtr B; // Create a grid object Grid &G = B[0.0][ "UniformGrid" ]; // Make a 3-dimensional skeleton object to hold vertices within this grid RefPtr<Skeleton> Vertices = G.makeVertices(3); // Get a chart object to access data in cartesian coordinates RefPtr<Chart> myCartesian = G.makeChart( typeid(Fiber::CartesianChart3D) ); // Create a representation of the vertices in these coordinates Representation&R = (*Vertices)[ myCartesian ]; // Access a field object representing the positions RefPtr<Field> Coords = R[ FIBER_POSITIONS ]; // Set coordinates on this grid typedef DirectProductMemArray<Eagle::point3> ProcArray_t; RefPtr<ProcArray_t> PCrds = new ProcArray_t(); { int X = 63, Y = 61, Z = 79; double B = 1.0; PCrds->Components[0] = new LinearArray<double>(-B, 2*B/(X-1), X); PCrds->Components[1] = new LinearArray<double>(-B, 2*B/(Y-1), Y); PCrds->Components[2] = new LinearArray<double>(-B, 2*B/(Z-1), Z); } // Set data without memory management Coords->setPersistentData( PCrds ); // Set additional data on the grid RefPtr<Field>&myField = G[ "ScalarField" ]; typedef MemArray<3, double> ScalarData3D_t; RefPtr<ScalarData3D_t> ScalarData = new ScalarData3D_t( PCrds->Size() ); MultiArray<3, double>&ScalarArray = *ScalarData; ProcArray_t&P = *PCrds; MultiIndex<3> M = MIndex(0,0,0); do { const Eagle::point3&Pt = P[ M ]; double S = Pt.x()*Pt.x() + Pt.y()*Pt.y() + Pt.z()*Pt.z(); ScalarArray[ M ] = S; } while( M.inc( PCrds->Size() ) ); myField->setPersistentData ( ScalarData ); // B.save("MyUnigrid.f5"); return 0; }