Commit 437415c1 authored by Chris Cantwell's avatar Chris Cantwell

Added VTK library support.

Added InputVtk filter to mesh converter.
Added utility to translate scalar data from VTK to FLD (not complete).


git-svn-id: https://gforge.sci.utah.edu/svn/nektar/trunk@3467 305cdda6-5ce1-45b3-a98d-dfc68c8b3305
parent 8b45dcda
......@@ -45,6 +45,8 @@ MARK_AS_ADVANCED(NEKTAR_USE_ARPACK)
SET(NEKTAR_USE_FFTW OFF CACHE BOOL "Use FFTW routines for performing the Fast Fourier Transform.")
MARK_AS_ADVANCED(NEKTAR_USE_FFTW)
SET(NEKTAR_USE_VTK OFF CACHE BOOL "Use VTK library for utilities.")
MARK_AS_ADVANCED(NEKTAR_USE_VTK)
# Parallelisation
SET(NEKTAR_USE_MPI OFF CACHE BOOL "Use MPICH2 for parallelisation.")
......@@ -168,6 +170,10 @@ IF(NEKTAR_USE_ARPACK)
INCLUDE_DIRECTORIES(${ARPACK_INCLUDE_DIR})
ENDIF(NEKTAR_USE_ARPACK)
IF(NEKTAR_USE_VTK)
INCLUDE_DIRECTORIES(${VTK_INCLUDE_DIRS})
ENDIF(NEKTAR_USE_VTK)
IF( NEKTAR_USE_PRECOMPILED_HEADERS )
ADD_DEFINITIONS(-DNEKTAR_USE_PRECOMPILED_HEADERS)
ELSE( NEKTAR_USE_PRECOMPILED_HEADERS )
......
......@@ -98,6 +98,14 @@ MARK_AS_ADVANCED(ARPACK_LIB)
MARK_AS_ADVANCED(ARPACK_INCLUDE_DIR)
MARK_AS_ADVANCED(NEKTAR_USE_ARPACK)
SET(VTK_FOUND "@VTK_FOUND@")
SET(NEKTAR_USE_VTK "@NEKTAR_USE_VTK@")
SET(VTK_USE_FILE "@VTK_USE_FILE@" CACHE FILEPATH "VTK library config." FORCE)
SET(VTK_INCLUDE_DIRS "@VTK_INCLUDE_DIRS@")
MARK_AS_ADVANCED(VTK_FOUND)
MARK_AS_ADVANCED(NEKTAR_USE_VTK)
MARK_AS_ADVANCED(VTK_USE_FILE)
MARK_AS_ADVANCED(VTK_INCLUDE_DIRS)
IF (${CMAKE_COMPILER_IS_GNUCXX})
SET(NEKTAR_ENABLE_PROFILE "@ NEKTAR_ENABLE_PROFILE@")
......
......@@ -56,11 +56,17 @@ IF( NEKTAR_USE_FFTW )
ADD_DEFINITIONS(-DNEKTAR_USING_FFTW)
ENDIF( NEKTAR_USE_FFTW )
IF( NEKTAR_USE_ARPACK)
IF( NEKTAR_USE_ARPACK )
INCLUDE (FindArpack)
ADD_DEFINITIONS(-DNEKTAR_USING_ARPACK)
ENDIF( NEKTAR_USE_ARPACK)
IF( NEKTAR_USE_VTK )
INCLUDE (FindVTK)
INCLUDE (${VTK_USE_FILE})
ADD_DEFINITIONS(-DNEKTAR_USING_VTK)
ENDIF( NEKTAR_USE_VTK )
IF( NEKTAR_USE_MKL )
INCLUDE (FindMKL)
ENDIF( NEKTAR_USE_MKL )
......
......@@ -79,6 +79,10 @@ MACRO(ADD_UTILITIES_EXECUTABLE name component source)
IF (NEKTAR_USE_MPI)
TARGET_LINK_LIBRARIES(${name} ${MPI_LIBRARY} ${MPI_EXTRA_LIBRARY})
ENDIF (NEKTAR_USE_MPI)
IF (NEKTAR_USE_VTK)
TARGET_LINK_LIBRARIES(${name} vtkHybrid)
ENDIF (NEKTAR_USE_VTK)
ENDIF( NEKTAR++_FOUND )
IF( ${CMAKE_SYSTEM} MATCHES "Linux.*")
......
SET(EnsiteToXmlSources EnsiteToXml.cpp)
ADD_UTILITIES_EXECUTABLE(EnsiteToXml util-extra ${EnsiteToXmlSources})
IF (NEKTAR_USE_VTK)
SET(VtkToFldSources VtkToFld.cpp)
ADD_UTILITIES_EXECUTABLE(VtkToFld util-extra ${VtkToFldSources})
ENDIF (NEKTAR_USE_VTK)
#include <LibUtilities/BasicUtils/SessionReader.h>
#include <LibUtilities/Communication/Comm.h>
#include <MultiRegions/ExpList2D.h>
#include <vtk-5.4/vtkPolyDataReader.h>
#include <vtk-5.4/vtkPolyData.h>
#include <vtk-5.4/vtkPointData.h>
#include <vtk-5.4/vtkPoints.h>
#include <vtk-5.4/vtkCellArray.h>
#include <vtk-5.4/vtkCellDataToPointData.h>
// Usage: VtkToFld session.xml input.vtk output.fld
int main(int argc, char* argv[])
{
MultiRegions::ExpList2DSharedPtr Exp;
std::vector<std::string> vFilenames;
vFilenames.push_back(std::string(argv[1]));
LibUtilities::SessionReaderSharedPtr vSession
= LibUtilities::SessionReader::CreateInstance(argc, argv, vFilenames);
cout << "Loaded session" << endl;
try
{
//----------------------------------------------
// Read in mesh from input file
SpatialDomains::MeshGraphSharedPtr graph2D = MemoryManager<SpatialDomains::MeshGraph2D>::AllocateSharedPtr(vSession);
//----------------------------------------------
cout << "Created graph" << endl;
//----------------------------------------------
// Define Expansion
Exp = MemoryManager<MultiRegions::ExpList2D>::
AllocateSharedPtr(vSession,graph2D);
//----------------------------------------------
cout << "Created ExpList" << endl;
//----------------------------------------------
// Set up coordinates of mesh for Forcing function evaluation
int coordim = Exp->GetCoordim(0);
int nq = Exp->GetTotPoints();
Array<OneD, NekDouble> xc0(nq,0.0);
Array<OneD, NekDouble> xc1(nq,0.0);
Array<OneD, NekDouble> xc2(nq,0.0);
switch(coordim)
{
case 2:
Exp->GetCoords(xc0,xc1);
break;
case 3:
Exp->GetCoords(xc0,xc1,xc2);
break;
default:
ASSERTL0(false,"Coordim not valid");
break;
}
//----------------------------------------------
vtkPolyDataReader *vtkMeshReader = vtkPolyDataReader::New();
vtkMeshReader->SetFileName(argv[2]);
vtkMeshReader->Update();
vtkPolyData *vtkMesh = vtkMeshReader->GetOutput();
vtkPoints *vtkPoints = vtkMesh->GetPoints();
vtkCellArray *vtkPolys = vtkMesh->GetPolys();
vtkCellDataToPointData* c2p = vtkCellDataToPointData::New();
c2p->SetInput(vtkMesh);
vtkPolyData *vtkDataAtPoints = c2p->GetPolyDataOutput();
vtkPointData *vtkPointData = vtkDataAtPoints->GetPointData();
for(int i = 0; i < nq; ++i)
{
cout << "Point: " << i << endl;
for (int j = 0; j < vtkDataAtPoints->GetNumberOfPoints(); ++i)
{
double p[3];
vtkDataAtPoints->GetPoint(j, p);
if (fabs(p[0]-xc0[i]) + fabs(p[1]-xc1[i]) + fabs(p[2]-xc2[i]) < 1e-06)
{
cout << "Found value" << endl;
Exp->UpdatePhys()[i] = vtkPointData->GetScalars("Image_Intensity")->GetTuple1(j);
}
}
}
//-----------------------------------------------
// Write solution to file
string out(argv[3]);
if (vSession->GetComm()->GetSize() > 1)
{
out += "." + boost::lexical_cast<string>(vSession->GetComm()->GetRank());
}
std::vector<SpatialDomains::FieldDefinitionsSharedPtr> FieldDef
= Exp->GetFieldDefinitions();
std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
for(int i = 0; i < FieldDef.size(); ++i)
{
FieldDef[i]->m_fields.push_back("u");
Exp->AppendFieldData(FieldDef[i], FieldData[i]);
}
graph2D->Write(out, FieldDef, FieldData);
//-----------------------------------------------
}
catch (...) {
cout << "ERROR" << endl;
}
}
......@@ -19,5 +19,10 @@ SET(MeshConvertSources
MeshConvert.cpp
MeshElements.cpp)
IF (NEKTAR_USE_VTK)
SET(MeshConvertHeaders ${MeshConvertHeaders} InputVtk.h)
SET(MeshConvertSources ${MeshConvertSources} InputVtk.cpp)
ENDIF (NEKTAR_USE_VTK)
ADD_UTILITIES_EXECUTABLE(MeshConvert util ${MeshConvertSources} ${MeshConvertHeaders})
////////////////////////////////////////////////////////////////////////////////
//
// File: InputVtk.cpp
//
// For more information, please see: http://www.nektar.info/
//
// The MIT License
//
// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
// Department of Aeronautics, Imperial College London (UK), and Scientific
// Computing and Imaging Institute, University of Utah (USA).
//
// License for the specific language governing rights and limitations under
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// Description: VTK converter.
//
////////////////////////////////////////////////////////////////////////////////
#include <string>
#include <fstream>
#include <iostream>
using namespace std;
#include <vtk-5.4/vtkPolyDataReader.h>
#include <vtk-5.4/vtkPolyData.h>
#include <vtk-5.4/vtkPoints.h>
#include <vtk-5.4/vtkCellArray.h>
#include "MeshElements.h"
#include "InputVtk.h"
namespace Nektar
{
namespace Utilities
{
ModuleKey InputVtk::className =
GetModuleFactory().RegisterCreatorFunction(
ModuleKey("vtk",eInputModule), InputVtk::create);
InputVtk::InputVtk(MeshSharedPtr m) : InputModule(m)
{
}
InputVtk::~InputVtk()
{
}
/**
* Gmsh file contains a list of nodes and their coordinates, along with
* a list of elements and those nodes which define them. We read in and
* store the list of nodes in #m_node and store the list of elements in
* #m_element. Each new element is supplied with a list of entries from
* #m_node which defines the element. Finally some mesh statistics are
* printed.
*
* @param pFilename Filename of Gmsh file to read.
*/
void InputVtk::Process()
{
vtkPolyDataReader *vtkMeshReader = vtkPolyDataReader::New();
vtkMeshReader->SetFileName(m->inFilename.c_str());
vtkMeshReader->Update();
vtkPolyData *vtkMesh = vtkMeshReader->GetOutput();
vtkPoints *vtkPoints = vtkMesh->GetPoints();
vtkCellArray *vtkPolys = vtkMesh->GetStrips();
vtkIdType npts;
vtkIdType *pts = 0;
double p[3];
for (int i = 0; i < vtkPoints->GetNumberOfPoints(); ++i)
{
vtkPoints->GetPoint(i, p);
m->node.push_back(boost::shared_ptr<Node>(new Node(i, p[0], p[1], p[2])));
}
vtkPolys->InitTraversal();
for (int i = 0; vtkPolys->GetNextCell(npts, pts); ++i)
{
for (int j = 0; j < npts - 2; ++j)
{
// Create element tags
vector<int> tags;
tags.push_back(0); // composite
tags.push_back(eTriangle); // element type
// Read element node list
vector<NodeSharedPtr> nodeList;
for (int k = j; k < j + 3; ++k)
{
nodeList.push_back(m->node[pts[k]]);
}
// Create element
ElmtConfig conf(eTriangle,1,false,false);
ElementSharedPtr E = GetElementFactory().
CreateInstance(eTriangle,conf,nodeList,tags);
// Determine mesh expansion dimension
if (E->GetDim() > m->expDim) {
m->expDim = E->GetDim();
}
m->element[E->GetDim()].push_back(E);
}
}
ProcessVertices();
ProcessEdges();
ProcessFaces();
ProcessElements();
ProcessComposites();
}
}
}
////////////////////////////////////////////////////////////////////////////////
//
// File: InputVtk.h
//
// For more information, please see: http://www.nektar.info/
//
// The MIT License
//
// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
// Department of Aeronautics, Imperial College London (UK), and Scientific
// Computing and Imaging Institute, University of Utah (USA).
//
// License for the specific language governing rights and limitations under
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// Description: VTK converter.
//
////////////////////////////////////////////////////////////////////////////////
#ifndef UTILITIES_PREPROCESSING_MESHCONVERT_INPUTVTK
#define UTILITIES_PREPROCESSING_MESHCONVERT_INPUTVTK
#include "Module.h"
namespace Nektar
{
namespace Utilities
{
/// Converter for VTK files.
class InputVtk : public InputModule
{
public:
/// Creates an instance of this class
static ModuleSharedPtr create(MeshSharedPtr m) {
return MemoryManager<InputVtk>::AllocateSharedPtr(m);
}
static ModuleKey className;
InputVtk(MeshSharedPtr m);
virtual ~InputVtk();
/// Populate and validate required data structures.
virtual void Process();
};
}
}
#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