Commit 062ffbe8 authored by Utkarsh Ayachit's avatar Utkarsh Ayachit

Adding parallel3d/DataAdaptor.

parent 9f226fd4
......@@ -15,7 +15,8 @@ if(NOT VTK_FOUND)
endif()
add_library(core STATIC ${sources})
target_include_directories(core SYSTEM PUBLIC ${VTK_INCLUDE_DIRS})
target_include_directories(core SYSTEM PUBLIC ${VTK_INCLUDE_DIRS}
INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
target_compile_definitions(core PUBLIC ${VTK_DEFINITIONS}
INTERFACE ENABLE_SENSEI)
target_link_libraries(core PUBLIC ${VTK_LIBRARIES})
#------------------------------------------------------------------------------
set (sources
set(sources
parallel_3D.c)
if(ENABLE_SENSEI)
list(APPEND sources
DataAdaptor.h
DataAdaptor.cxx)
endif()
#------------------------------------------------------------------------------
add_executable(3D_Grid ${sources})
target_link_libraries(3D_Grid PRIVATE histogram)
......
#include "DataAdaptor.h"
#include "vtkObjectFactory.h"
#include "vtkDataObject.h"
#include "vtkDoubleArray.h"
namespace parallel3d
{
vtkStandardNewMacro(DataAdaptor);
//-----------------------------------------------------------------------------
DataAdaptor::DataAdaptor()
{
}
//-----------------------------------------------------------------------------
DataAdaptor::~DataAdaptor()
{
}
//-----------------------------------------------------------------------------
void DataAdaptor::Initialize(
int g_x, int g_y, int g_z,
int l_x, int l_y, int l_z,
uint64_t start_extents_x, uint64_t start_extents_y, uint64_t start_extents_z,
int tot_blocks_x, int tot_blocks_y, int tot_blocks_z,
int block_id_x, int block_id_y, int block_id_z)
{
// we only really need to save the local extents for our current example. So
// we'll just save that.
this->Extent[0] = start_extents_x;
this->Extent[1] = start_extents_x + l_x - 1;
this->Extent[2] = start_extents_y;
this->Extent[3] = start_extents_y + l_y - 1;
this->Extent[4] = start_extents_z;
this->Extent[5] = start_extents_z + l_z - 1;
}
//-----------------------------------------------------------------------------
void DataAdaptor::AddArray(const std::string& name, double* data)
{
if (this->Variables[name] != data)
{
this->Variables[name] = data;
this->Arrays.erase(name);
}
}
//-----------------------------------------------------------------------------
void DataAdaptor::ClearArrays()
{
this->Variables.clear();
this->Arrays.clear();
}
//-----------------------------------------------------------------------------
vtkDataObject* DataAdaptor::GetMesh()
{
// our analysis doesn't need a mesh so we punt on it for now.
// In theory, we'll create a new vtkImageData and return that.
vtkGenericWarningMacro("TODO: Not implemented currently.");
return NULL;
}
//-----------------------------------------------------------------------------
vtkAbstractArray* DataAdaptor::GetArray(int association, const char* name)
{
if (association != vtkDataObject::FIELD_ASSOCIATION_POINTS || name == NULL)
{
return NULL;
}
VariablesType::iterator iterV = this->Variables.find(name);
if (iterV == this->Variables.end())
{
return NULL;
}
ArraysType::iterator iterA = this->Arrays.find(iterV->first);
if (iterA == this->Arrays.end())
{
vtkSmartPointer<vtkDoubleArray>& vtkarray = this->Arrays[iterV->first];
vtkarray = vtkSmartPointer<vtkDoubleArray>::New();
vtkarray->SetName(name);
const vtkIdType size = (this->Extent[1] - this->Extent[0] + 1) *
(this->Extent[3] - this->Extent[2] + 1) *
(this->Extent[5] - this->Extent[4] + 1);
vtkarray->SetArray(iterV->second, size, 1);
return vtkarray;
}
else
{
return iterA->second;
}
}
//-----------------------------------------------------------------------------
unsigned int DataAdaptor::GetNumberOfArrays(int association)
{
return (association == vtkDataObject::FIELD_ASSOCIATION_POINTS)?
static_cast<unsigned int>(this->Variables.size()): 0;
}
//-----------------------------------------------------------------------------
const char* DataAdaptor::GetArrayName(int association, unsigned int index)
{
if (association != vtkDataObject::FIELD_ASSOCIATION_POINTS)
{
return NULL;
}
unsigned int count = 0;
for (VariablesType::iterator iter=this->Variables.begin(), max=this->Variables.end();
iter != max; ++iter, ++count)
{
if (count==index)
{
return iter->first.c_str();
}
}
return NULL;
}
//-----------------------------------------------------------------------------
void DataAdaptor::ReleaseData()
{
this->ClearArrays();
}
}
#ifndef PARALLEL3D_DATAADAPTOR_H
#define PARALLEL3D_DATAADAPTOR_H
#include "vtkInsituDataAdaptor.h"
#include "vtkSmartPointer.h"
#include <map>
#include <string>
class vtkDoubleArray;
namespace parallel3d
{
/// DataAdaptor is an adaptor for the parallel_3d simulation (miniapp).
/// Its purpose is to map the simulation datastructures to VTK
/// data model.
class DataAdaptor : public vtkInsituDataAdaptor
{
public:
static DataAdaptor* New();
vtkTypeMacro(DataAdaptor, vtkInsituDataAdaptor);
/// Initialize the data adaptor.
void Initialize(
int g_x, int g_y, int g_z,
int l_x, int l_y, int l_z,
uint64_t start_extents_x, uint64_t start_extents_y, uint64_t start_extents_z,
int tot_blocks_x, int tot_blocks_y, int tot_blocks_z,
int block_id_x, int block_id_y, int block_id_z);
/// Set the pointers to simulation memory.
void AddArray(const std::string& name, double* data);
/// Clear all arrays.
void ClearArrays();
/// Return the topology/geometry for the simulation grid.
virtual vtkDataObject* GetMesh();
/// Return an array.
virtual vtkAbstractArray* GetArray(int association, const char* name);
/// Return number of arrays.
virtual unsigned int GetNumberOfArrays(int association);
/// Returns an arrays name given the index.
virtual const char* GetArrayName(int association, unsigned int index);
/// Release all data.
virtual void ReleaseData();
protected:
DataAdaptor();
virtual ~DataAdaptor();
typedef std::map<std::string, double*> VariablesType;
VariablesType Variables;
typedef std::map<std::string, vtkSmartPointer<vtkDoubleArray> > ArraysType;
ArraysType Arrays;
int Extent[6];
private:
DataAdaptor(const DataAdaptor&); // not implemented.
void operator=(const DataAdaptor&); // not implemented.
};
}
#endif
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