30 template<
class F,
class G>
40 template<
class F,
class G>
57 const uint points = 5);
66 template<
class G,
class F>
75 std::ostringstream stream;
76 writeValues_(stream,
function, name);
77 *
ofs_ << stream.str();
87 template<
class F,
class G>
94 std::ostringstream stream;
96 writeValues_(stream,
function, name);
97 *
ofs_ << stream.str();
105 template<
class G,
class F>
106 void storeData_(
bool data, std::string filename,
113 void writeHead_(std::string&, std::ostringstream& stream,
115 template<
class G,
class F>
118 void writePoints_(std::ostringstream& stream,
125 void writeMesh_(std::ostringstream& stream,
130 void writeEdgeMesh_(std::ostringstream& stream,
135 void writeValues_(std::ostringstream& stream,
137 const std::string name =
"solution");
141 void writeWeightsAndAttr_(std::ostringstream& stream,
146 void cellType_(std::ostringstream& stream,
152 std::string vtkEnding_(
const std::string& filename) {
153 uint size = filename.size();
154 if (size < 4 || std::string(filename, size - 4, 4) !=
".vtk")
155 return (filename +
".vtk");
163 uint outputDimension_;
167 template<
class F,
class G>
177 storeData_(
true, filename, dmc, functionValues);
180 template<
class F,
class G>
189 storeData_(
true, filename, dmc, functionValues);
194 const std::string filename) :
197 outputDimension_ = 0;
199 storeData_<G, concepts::Real>(
true, filename, dmc);
204 template<
class G,
class F>
205 void VtkGraphics::storeData_(
bool data, std::string filename,
209 std::ostringstream stream;
212 writeHead_(filename, stream, dense_ptr_);
215 writePoints_(stream, dense_ptr_, functionValue);
219 writeMesh_(stream, dense_ptr_);
222 if ((dense_ptr_.find(
"z") != dense_ptr_.end()) && (dense_ptr_[
"msh"]->m() >= 8))
223 cellType_(stream, dense_ptr_);
228 writeWeightsAndAttr_(stream, dense_ptr_);
230 writeValues_(stream, functionValue);
234 *
ofs_ << stream.str();
238 void VtkGraphics::writeMesh_(std::ostringstream& stream,
239 DenseMatrixCollection<G>& dense_ptr_) {
242 if (dense_ptr_[
"msh"]->m() < 4) {
243 stream <<
"LINES" <<
" " << dense_ptr_[
"msh"]->n() <<
" "
244 << dense_ptr_[
"msh"]->n() * 3 <<
"\n";
246 for (uint i = 0; i < dense_ptr_[
"msh"]->n(); ++i)
247 stream <<
"2 " << dense_ptr_[
"msh"]->
operator()(0, i) - 1 <<
" "
248 << dense_ptr_[
"msh"]->
operator()(1, i) - 1 <<
'\n';
252 else if ((((dense_ptr_.find(
"z") == dense_ptr_.end())
253 && (dense_ptr_.find(
"y") != dense_ptr_.end()))
255 ((dense_ptr_.find(
"z") != dense_ptr_.end())
256 && (dense_ptr_[
"msh"]->m() < 8)))
258 stream <<
"POLYGONS" <<
" " << dense_ptr_[
"msh"]->n() <<
" "
259 << dense_ptr_[
"msh"]->n() * 5 <<
"\n";
261 for (uint i = 0; i < dense_ptr_[
"msh"]->n(); ++i)
262 stream <<
"4 " << dense_ptr_[
"msh"]->
operator()(0, i) - 1 <<
" "
263 << dense_ptr_[
"msh"]->
operator()(1, i) - 1 <<
" "
264 << dense_ptr_[
"msh"]->
operator()(2, i) - 1 <<
" "
265 << dense_ptr_[
"msh"]->
operator()(3, i) - 1 <<
'\n';
269 else if (dense_ptr_.find(
"z") != dense_ptr_.end()) {
270 stream <<
"CELLS" <<
" " << dense_ptr_[
"msh"]->n() <<
" "
271 << dense_ptr_[
"msh"]->n() * 9 <<
"\n";
272 for (uint i = 0; i < dense_ptr_[
"msh"]->n(); ++i)
273 stream <<
"8 " << dense_ptr_[
"msh"]->
operator()(0, i) - 1 <<
" "
274 << dense_ptr_[
"msh"]->
operator()(1, i) - 1 <<
" "
275 << dense_ptr_[
"msh"]->
operator()(2, i) - 1 <<
" "
276 << dense_ptr_[
"msh"]->
operator()(3, i) - 1 <<
" "
277 << dense_ptr_[
"msh"]->
operator()(4, i) - 1 <<
" "
278 << dense_ptr_[
"msh"]->
operator()(5, i) - 1 <<
" "
279 << dense_ptr_[
"msh"]->
operator()(6, i) - 1 <<
" "
280 << dense_ptr_[
"msh"]->
operator()(7, i) - 1 <<
'\n';
285 void VtkGraphics::writeEdgeMesh_(std::ostringstream& stream,
286 DenseMatrixCollection<G>& dense_ptr_) {
287 stream <<
"LINES" <<
" " << dense_ptr_[
"edgemsh"]->n() <<
" "
288 << dense_ptr_[
"edgemsh"]->n() * 3 <<
"\n";
290 for (uint i = 0; i < dense_ptr_[
"edgemsh"]->n(); ++i)
291 stream <<
"2 " << dense_ptr_[
"edgemsh"]->
operator()(0, i) - 1 <<
" "
292 << dense_ptr_[
"edgemsh"]->
operator()(1, i) - 1 <<
"\n";
296 void VtkGraphics::writeWeightsAndAttr_(std::ostringstream& stream,
297 DenseMatrixCollection<G>& dense_ptr_) {
300 stream <<
"POINT_DATA " << dense_ptr_[
"w"]->n() <<
"\n";
301 stream <<
"SCALARS weights FLOAT\n";
302 stream <<
"LOOKUP_TABLE default\n";
303 for (uint i = 0; i < dense_ptr_[
"w"]->n(); ++i)
304 stream << dense_ptr_[
"w"]->
operator()(0, i) <<
"\n";
306 stream <<
"SCALARS pointAttributes FLOAT\n";
307 stream <<
"LOOKUP_TABLE default\n";
308 for (uint i = 0; i < dense_ptr_[
"pattr"]->n(); ++i)
309 stream << dense_ptr_[
"pattr"]->
operator()(0, i) <<
"\n";
313 void VtkGraphics::cellType_(std::ostringstream& stream,
314 DenseMatrixCollection<G>& dense_ptr_) {
317 stream <<
"CELL_TYPES " << dense_ptr_[
"msh"]->n() <<
"\n";
318 for (uint i = 0; i < dense_ptr_[
"msh"]->n(); ++i)
319 stream << 12 <<
"\n";
323 template<
class G,
class F>
324 void VtkGraphics::writePoints_(std::ostringstream& stream,
325 DenseMatrixCollection<G>& dense_ptr_,
328 stream <<
"POINTS " << dense_ptr_[
"x"]->n() <<
" float\n";
329 for (uint i = 0; i < dense_ptr_[
"x"]->n(); ++i) {
330 stream << dense_ptr_[
"x"]->operator()(0, i) <<
" "
331 << dense_ptr_[
"y"]->
operator()(0, i) <<
" ";
333 if (dense_ptr_.find(
"z") == dense_ptr_.end())
336 stream << dense_ptr_[
"z"]->operator()(0, i) <<
"\n";
341 void VtkGraphics::writeHead_(std::string& filename,
342 std::ostringstream& stream, DenseMatrixCollection<G>& dense_ptr_) {
343 stream <<
"# vtk DataFile Version 2.0\n";
345 stream <<
"\nASCII\n";
348 if (dense_ptr_[
"msh"]->m() < 8)
349 stream <<
"DATASET POLYDATA\n";
353 stream <<
"DATASET UNSTRUCTURED_GRID\n";
concepts::RCP< concepts::ElementMatrix< typename concepts::Datatype< F >::type > > getFunction(const concepts::Space< G > &spc, const concepts::ElementFormula< F, G > &frm)
concepts::RCP< concepts::ElementMatrix< F > > getSolution(const concepts::Space< G > &spc, const concepts::Vector< F > &sol, const concepts::ElementFunction< F, G > *fun=0)
DenseMatrixCollection< G > getSpace(const concepts::Space< G > &spc)
std::unique_ptr< std::ofstream > ofs_
Stream for output file.
VtkGraphics(concepts::Mesh &msh, const std::string filename, const uint points=5)
void addFunction(const concepts::Space< G > &spc, const std::string name, const concepts::ElementFormula< F, G > &frm)
void addSolution(const concepts::Space< G > &spc, const std::string name, const concepts::Vector< F > &sol, const concepts::ElementFunction< F, G > *fun=0)