Skip to content
Snippets Groups Projects
Commit 239180e6 authored by Oliver Sander's avatar Oliver Sander
Browse files

Hack: a method for writing BlockVectors as AmiraMesh files

[[Imported from SVN: r1112]]
parent 79d81d37
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,8 @@
#include <algorithm>
#include <dune/istl/bvector.hh>
#if _3
/** \todo Make sure that the grid is three-dimensional */
template<class GridType, class DiscFuncType>
......@@ -28,7 +30,6 @@ void Dune::AmiraMeshWriter<GridType, DiscFuncType>::writeGrid(const GridType& gr
}
}
printf("This is the AmiraMesh writer!\n");
int maxVerticesPerElement = (containsOnlyTetrahedra) ? 4 : 8;
const int DIM = 3;
......@@ -179,7 +180,6 @@ void Dune::AmiraMeshWriter<GridType, DiscFuncType>::writeGrid(const GridType& gr
}
}
printf("This is the 2D AmiraMesh writer!\n");
int maxVerticesPerElement = (containsOnlyTetrahedra) ? 3 : 4;
const int DIM = 2;
......@@ -187,14 +187,9 @@ void Dune::AmiraMeshWriter<GridType, DiscFuncType>::writeGrid(const GridType& gr
int noOfNodes = grid.size(level, DIM);
int noOfElem = grid.size(level, 0);
printf("noOfNodes %d, nodeOfElem: %d\n", noOfNodes, noOfElem);
int i;
//int tl, k, noOfBndTri, MarkKey, ncomp, maxSubDom;
std::string solFilename;
// Construct the name for the geometry file
// Construct the name for the file
std::string geoFilename(filename);
geoFilename += ".am";
......@@ -264,7 +259,6 @@ void Dune::AmiraMeshWriter<GridType, DiscFuncType>::writeGrid(const GridType& gr
McPrimType::mc_int32, maxVerticesPerElement);
am_geometry.insert(element_data);
//int *(dPtr[maxVerticesPerElement]) = (int*)element_data->dataPtr();
int *dPtr = (int*)element_data->dataPtr();
typename GridType::template Traits<0>::LevelIterator element2 = grid.template lbegin<0>(level);
......@@ -357,3 +351,54 @@ void Dune::AmiraMeshWriter<GridType, DiscFuncType>::writeFunction(const DiscFunc
std::cout << "Solution written successfully to: " << filename << std::endl;
}
template<class GridType, class DiscFuncType>
void Dune::AmiraMeshWriter<GridType, DiscFuncType>::writeBlockVector(const Dune::BlockVector<Dune::FieldVector<double, 3> >& f,
const std::string& filename)
{
typedef Dune::BlockVector<Dune::FieldVector<double, 3> > VectorType;
// Get number of components
/** \todo Must depend on the BlockVector and not on the grid! */
const int ncomp = GridType::dimension;
// Create AmiraMesh object
AmiraMesh am;
// Set the appropriate content type for 2D grid data
if (GridType::dimension==2)
am.parameters.set("ContentType", "HxTriangularData");
AmiraMesh::Location* sol_nodes = new AmiraMesh::Location("Nodes", f.size());
am.insert(sol_nodes);
AmiraMesh::Data* nodeData = new AmiraMesh::Data("Data", sol_nodes, McPrimType::mc_double, ncomp);
am.insert(nodeData);
AmiraMesh::Field* nodeField = new AmiraMesh::Field("sol", ncomp, McPrimType::mc_double,
AmiraMesh::t_linear, nodeData);
am.insert(nodeField);
// write the data into the AmiraMesh object
typedef typename VectorType::ConstIterator Iterator;
Iterator dit = f.begin();
Iterator ditend = f.end();
int i=0;
for (; dit!=ditend; ++dit) {
for (int j=0; j<ncomp; j++)
((double*)nodeData->dataPtr())[i++] = (*dit)[j];
}
// actually save the solution file
// (the 1 means: ascii)
if (!am.write(filename.c_str(), 1) )
DUNE_THROW(IOError, "An error has occured writing file " << filename);
std::cout << "Solution written successfully to: " << filename << std::endl;
}
......@@ -4,6 +4,7 @@
#define __DUNE_AMIRAMESHWRITER_HH__
#include <string>
#include <dune/istl/bvector.hh>
namespace Dune {
......@@ -41,6 +42,8 @@ namespace Dune {
static void writeFunction(const DiscFuncType& f,
const std::string& filename);
static void writeBlockVector(const Dune::BlockVector<Dune::FieldVector<double, 3> >& f,
const std::string& filename);
AmiraMeshWriter() {}
};
......@@ -51,6 +54,6 @@ namespace Dune {
#include "amiramesh/amirameshwriter.cc"
// the amiramesh writer for SGrid
#include "amiramesh/amsgridwriter.cc"
//#include "amiramesh/amsgridwriter.cc"
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment