17#error "libamiramesh is required for Amira file IO, but HAVE_AMIRA is set to 0"
28#include <boost/fusion/include/for_each.hpp>
29#include <boost/fusion/include/zip_view.hpp>
30#include <boost/fusion/include/vector.hpp>
56 template<
class Gr
idType>
62 typedef typename GridType::LeafGridView
GridView;
70 this->
addGrid(grid.leafGridView());
82 const typename GridView::IndexSet& indexSet = gridView.indexSet();
83 int noOfElements = indexSet.size(0);
87 for(
int i=0; i<noOfElements; i++)
88 ((
unsigned char*)data->dataPtr())[i] = materialData[i];
100 template <
class Gr
idView,
class Filter,
class RAIter>
101 struct AddDataTo<GridView,
Kaskade::MaterialAmiraMeshWriter<typename GridView::Grid>,Filter,RAIter>
103 typedef typename GridView::Grid Grid;
106 AddDataTo(GridView
const& gridView_, AmiraWriter& writer_, Filter
const& filter_, RAIter
const& names_):
114 template <
class Pair>
115 void operator()(Pair
const& pair)
const
117 using namespace boost::fusion;
119 int const id = boost::remove_reference<typename result_of::value_at_c<Pair,0>::type>::type::id;
121 if (!filter(names[
id]))
124 typedef typename boost::remove_reference<typename result_of::value_at_c<Pair,1>::type>::type Function;
126 Function
const& f = at_c<1>(pair);
132 typedef typename Function::Space::IndexSet IndexSet;
133 IndexSet
const& indexSet = f.space().indexSet();
139 typename Function::Space::Evaluator eval(f.space());
142 if (Function::Space::continuity >= 0)
145 Dune::BlockVector<typename Function::ValueType> data(indexSet.size(GridView::dimension));
148 for (
auto const& cell: Dune::elements(f.space().gridView()))
153 auto const& refElem = Dune::ReferenceElements<typename Grid::ctype, GridView::dimension>::general(cell.type());
158 for (
int i=0; i<cell.subEntities(GridView::dimension); ++i)
161 eval.evaluateAt(refElem.position(i,GridView::dimension));
163 data[indexSet.subIndex(cell,i,GridView::dimension)] = f.
value(eval);
167 writer.addVertexData(data,gridView);
172 Dune::BlockVector<typename Function::ValueType> data(indexSet.size(0));
175 for (
auto const& cell: Dune::elements(f.space().grid().leafGridView()))
178 auto const& refElem = Dune::ReferenceElements<typename Grid::ctype, GridView::dimension>::general(cell.type());
180 data[indexSet.index(cell)] = f.
value(cell,refElem.position(0,0));
183 writer.addCellData(data,gridView);
188 GridView
const& gridView;
190 Filter
const& filter;
213 template <
class Gr
idView>
216 int nTet = gridView.indexSet().size(0);
217 int nNodes = gridView.indexSet().size(
int(GridView::dimensionworld));
219 std::string find1(
"nNodes ");
220 std::string find2(
"nTetrahedra ");
221 std::ofstream tmpFile(
"tmp.txt");
222 std::ifstream inFile(file_in);
223 std::ifstream outFile(file_out);
227 if (!file_in.empty())
229 while( getline(inFile, line) )
231 if( line.substr(0,7).compare(
"Nodes {") == 0 )
233 else if( line.substr(0,7).compare(find1) == 0)
234 tmpFile << find1 << nNodes <<
'\n';
235 else if( line.substr(0,12).compare(find2) == 0)
236 tmpFile << find2 << nTet <<
'\n';
238 tmpFile << line <<
'\n';
247 while( getline(outFile,line) )
249 if (line.substr(0,7).compare(
"Nodes {") == 0)
253 tmpFile << line <<
'\n';
259 if (std::rename(
"tmp.txt" , file_out.c_str()) == 0)
262 perror(
"Error renaming file in call of copyHeader() in writeAMIRAFile" );
264 std::remove(
"tmp.txt");
279 template <
class Gr
idView,
class VariableSet>
282 std::string file_out,
285 std::string file_in =
"")
288 if( (!file_in.empty()) && (file_in.substr( file_in.length()-3) !=
".am") )
289 file_in.append(
".am");
290 if( (file_out.substr( file_out.length()-3) !=
".am") )
291 file_out.append(
".am");
296 AmiraWriter writer(gv.grid());
298 if( materialData.size() != 0)
299 writer.addMaterialData(gv, materialData);
301 std::string fullname = file_out;
307 else std::cout <<
"Amira: graphic output for nonvalid driver" <<
'\n';
Provides file writing facilities in the AmiraMesh format.
void addGrid(const GridType::LeafGridView &gridView, bool splitAll=false)
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.