Commit b15eb5d1 authored by Utkarsh Ayachit's avatar Utkarsh Ayachit

Adding dataadaptor for oscillator miniapp.

parent 58bc99a5
......@@ -20,3 +20,7 @@ target_link_libraries(oscillator PRIVATE mpi)
# Threads
find_package(Threads)
target_link_libraries(oscillator PRIVATE util ${CMAKE_THREAD_LIBS_INIT})
if(ENABLE_SENSEI)
target_link_libraries(oscillator PRIVATE core)
endif()
#ifndef GRIDADAPTOR_H
#define GRIDADAPTOR_H
#include <grid/grid.h>
#include <diy/master.hpp>
#include <vtkAOSDataArrayTemplate.h>
#include <vtkDataObject.h>
#include <vtkImageData.h>
#include <vtkInsituDataAdaptor.h>
#include <vtkPointData.h>
namespace gridadaptor
{
/// vtkInsituDataAdaptor specialization for grid::GridRef.
template <class C, unsigned D>
class GridAdaptor : public vtkInsituDataAdaptor
{
public:
typedef grid::GridRef<C, D> GridRef;
typedef typename GridRef::Vertex Vertex;
typedef diy::DiscreteBounds Bounds;
public:
static GridAdaptor* New() { return new GridAdaptor(); }
vtkTypeMacro(GridAdaptor, vtkInsituDataAdaptor);
void Initialize(int gid, const Bounds& bounds, const Vertex& domain_shape)
{
this->GridBounds = bounds;
this->DomainShape = domain_shape;
this->GID = gid;
}
void SetGrid(GridRef grid)
{
this->Grid = grid;
}
/// Return the topology/geometry for the simulation grid.
virtual vtkDataObject* GetMesh()
{
if (!this->Mesh)
{
this->Mesh = vtkSmartPointer<vtkImageData>::New();
assert(this->Grid.c_order());
this->Mesh->SetExtent(
this->GridBounds.min[0], this->GridBounds.max[0],
this->GridBounds.min[1], this->GridBounds.max[1],
this->GridBounds.min[2], this->GridBounds.max[2]);
/// XXX: This is for the time-being. We need to add API to
/// vtkInsituDataAdaptor to add arrays to a mesh passed in as the argument.
/// Until we do that, we assume GetMesh() will ask for all provided
/// arrays.
this->Mesh->GetPointData()->SetScalars(
static_cast<vtkDataArray*>(this->GetArray(vtkDataObject::FIELD_ASSOCIATION_POINTS, "data")));
}
return this->Mesh;
}
/// Return an array.
virtual vtkAbstractArray* GetArray(int association, const char* name)
{
if (association != vtkDataObject::FIELD_ASSOCIATION_POINTS ||
name == NULL ||
strcmp(name, "data") != 0)
{
return NULL;
}
if (!this->DataArray)
{
this->DataArray = vtkSmartPointer<vtkAOSDataArrayTemplate<C> > ::New();
this->DataArray->SetName("data");
this->DataArray->SetArray(this->Grid.data(), this->Grid.size(), 1);
}
return this->DataArray;
}
/// Return number of arrays.
virtual unsigned int GetNumberOfArrays(int association)
{ return 1; }
/// Returns an arrays name given the index.
virtual const char* GetArrayName(int association, unsigned int index)
{ return index==0? "data" : NULL; }
/// Release all data.
virtual void ReleaseData()
{
this->DataArray = NULL;
this->Mesh = NULL;
this->SetGrid(GridRef(NULL, Vertex()));
}
protected:
GridAdaptor() : Grid(NULL, Vertex()) {}
virtual ~GridAdaptor() {}
int GID;
GridRef Grid;
Bounds GridBounds;
Vertex DomainShape;
vtkSmartPointer<vtkAOSDataArrayTemplate<C> > DataArray;
vtkSmartPointer<vtkImageData> Mesh;
private:
GridAdaptor(const GridAdaptor&); // not implemented.
void operator=(const GridAdaptor&); // not implemented.
};
}
#endif
......@@ -10,6 +10,13 @@
#include <grid/grid.h>
#include <grid/vertices.h>
#ifdef ENABLE_SENSEI
#include <gridadaptor/gridadaptor.h>
#include <vtkNew.h>
using GridAdaptor
= gridadaptor::GridAdaptor<float,3>;
#endif
#include "oscillator.h"
#include "analysis.h"
......@@ -21,6 +28,8 @@ using Link = diy::RegularGridLink;
using Master = diy::Master;
using Proxy = Master::ProxyWithLink;
struct Block
{
Block(int gid_, const Bounds& bounds_, const Vertex& domain_shape_, const Oscillators& oscillators_):
......@@ -29,7 +38,12 @@ struct Block
domain_shape(domain_shape_),
from(bounds.min),
grid(Vertex(bounds.max) - Vertex(bounds.min) + Vertex::one()),
oscillators(oscillators_) {}
oscillators(oscillators_)
{
#ifdef ENABLE_SENSEI
gridadaptor->Initialize(gid, bounds, domain_shape);
#endif
}
void advance(float t)
{
......@@ -42,8 +56,14 @@ struct Block
for (auto& o : oscillators)
gv += o.evaluate(v_global, t);
});
#ifdef ENABLE_SENSEI
gridadaptor->SetGrid(grid);
// TODO: bridge->analyze()
gridadaptor->ReleaseData();
#else
analyze(gid, grid.data());
#endif
}
static void* create() { return new Block; }
......@@ -55,6 +75,9 @@ struct Block
Vertex from;
Grid grid;
Oscillators oscillators;
#ifdef ENABLE_SENSEI
vtkNew<GridAdaptor> gridadaptor;
#endif
private:
Block() {} // for create; to let Master manage the blocks
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment