20#define HAVE_AMIRAMESH 1
24#include <boost/fusion/include/for_each.hpp>
25#include <boost/fusion/include/zip_view.hpp>
26#include <boost/fusion/include/vector.hpp>
52 template<
class Gr
idType>
58 typedef typename GridType::LeafGridView
GridView;
66 this->
addGrid(grid.leafGridView());
78 const typename GridView::IndexSet& indexSet = gridView.indexSet();
79 int noOfElements = indexSet.size(0);
83 for(
int i=0; i<noOfElements; i++)
84 ((
unsigned char*)data->dataPtr())[i] = materialData[i];
96 template <
class Gr
idView,
class Filter,
class RAIter>
97 struct AddDataTo<GridView,
Kaskade::MaterialAmiraMeshWriter<typename GridView::Grid>,Filter,RAIter>
99 typedef typename GridView::Grid Grid;
102 AddDataTo(GridView
const& gridView_, AmiraWriter& writer_, Filter
const& filter_, RAIter
const& names_):
110 template <
class Pair>
111 void operator()(Pair
const& pair)
const
115 int const id = boost::remove_reference<typename result_of::value_at_c<Pair,0>::type>::type::id;
117 if (!filter(names[
id]))
120 typedef typename boost::remove_reference<typename result_of::value_at_c<Pair,1>::type>::type
Function;
128 typedef typename Function::Space::IndexSet IndexSet;
129 IndexSet
const& indexSet = f.space().indexSet();
135 typename Function::Space::Evaluator eval(f.space());
138 if (Function::Space::continuity >= 0)
144 for (
auto const& cell: Dune::elements(f.space().gridView()))
149 auto const& refElem = Dune::ReferenceElements<typename Grid::ctype, GridView::dimension>::general(cell.type());
154 for (
int i=0; i<cell.subEntities(GridView::dimension); ++i)
157 eval.evaluateAt(refElem.position(i,GridView::dimension));
159 data[indexSet.subIndex(cell,i,GridView::dimension)] = f.
value(eval);
163 writer.addVertexData(data,gridView);
171 for (
auto const& cell: Dune::elements(f.space().grid().leafGridView()))
174 auto const& refElem = Dune::ReferenceElements<typename Grid::ctype, GridView::dimension>::general(cell.type());
176 data[indexSet.index(cell)] = f.
value(cell,refElem.position(0,0));
179 writer.addCellData(data,gridView);
184 GridView
const& gridView;
186 Filter
const& filter;
209 template <
class Gr
idView>
210 void copyHeader(GridView
const& gridView, std::string
const& file_in, std::string
const& file_out){
212 int nTet = gridView.indexSet().size(0);
213 int nNodes = gridView.indexSet().size(
int(GridView::dimensionworld));
215 std::string find1(
"nNodes ");
216 std::string find2(
"nTetrahedra ");
217 std::ofstream tmpFile(
"tmp.txt");
218 std::ifstream inFile(file_in);
219 std::ifstream outFile(file_out);
223 if (!file_in.empty())
225 while( getline(inFile, line) )
227 if( line.substr(0,7).compare(
"Nodes {") == 0 )
229 else if( line.substr(0,7).compare(find1) == 0)
230 tmpFile << find1 << nNodes << std::endl;
231 else if( line.substr(0,12).compare(find2) == 0)
232 tmpFile << find2 << nTet << std::endl;
234 tmpFile << line << std::endl;
243 while( getline(outFile,line) )
245 if (line.substr(0,7).compare(
"Nodes {") == 0)
249 tmpFile << line << std::endl;
255 if (std::rename(
"tmp.txt" , file_out.c_str()) == 0)
258 perror(
"Error renaming file in call of copyHeader() in writeAMIRAFile" );
260 std::remove(
"tmp.txt");
275 template <
class Gr
idView,
class VariableSet>
278 std::string file_out,
281 std::string file_in =
"")
284 if( (!file_in.empty()) && (file_in.substr( file_in.length()-3) !=
".am") ) file_in.append(
".am");
285 if( (file_out.substr( file_out.length()-3) !=
".am") ) file_out.append(
".am");
291 if( materialData.size() != 0) writer.addMaterialData(vars.
descriptions.gridView, materialData);
293 std::string fullname = file_out;
299 else std::cout <<
"Amira: graphic output for nonvalid driver" << std::endl;
Provides file writing facilities in the AmiraMesh format.
void addGrid(const GridType::LeafGridView &gridView, bool splitAll=false)
Add a grid view to the file.
Function is the interface for evaluatable functions .
ValueType value(Cell const &cell, Dune::FieldVector< typename Cell::Geometry::ctype, Cell::dimension > const &localCoordinate) const
MaterialAmiraMeshWriter()
Default constructor.
MaterialAmiraMeshWriter(const GridType &grid)
Constructor which initializes the AmiraMesh object with a given leaf grid.
Dune::BlockVector< Dune::FieldVector< double, 1 > > DataContainer
void addMaterialData(const GridView &gridView, DataContainer &materialData)
GridType::LeafGridView GridView
A class for storing a heterogeneous collection of FunctionSpaceElement s.
Descriptions const & descriptions
Descriptions of variable set, of type VariableSetDescription (lots of useful infos)
void writePartialFile(GridView const &gridView, Writer &writer, VariableSet const &vars, std::string const &filename, Filter const &filter, Options const &options)
Output of mesh and solution for visualization software.
void writeAMIRAFile(GridView const &gridView, VariableSet const &vars, std::string file_out, IoOptions options=ioOptions_default, Dune::BlockVector< Dune::FieldVector< double, 1 > > materialData=Dune::BlockVector< Dune::FieldVector< double, 1 > >(), std::string file_in="")
IoOptions ioOptions_default
void copyHeader(GridView const &gridView, std::string const &file_in, std::string const &file_out)
Convenience typedefs and creation functions for common function spaces.
options for VTK/AMIRA output
Output of mesh and solution for visualization software.