VtkVectorWriter.cc 5.29 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//
// Software License for AMDiS
//
// Copyright (c) 2010 Dresden University of Technology 
// All rights reserved.
// Authors: Simon Vey, Thomas Witkowski et al.
//
// This file is part of AMDiS
//
// See also license.opensource.txt in the distribution.


#include <stdio.h>
#include <string>
#include <fstream>
#include <sstream>
#include <cmath>
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/convenience.hpp>
#include <boost/lexical_cast.hpp>

#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
#include <mpi.h>
#endif

#include "VtkVectorWriter.h"
#include "VtkVectorWriter.hh"
#include "DataCollector.h"
#include "DataCollector.hh"
#include "DOFVector.h"
#include "SurfaceRegion_ED.h"
#include "ElementRegion_ED.h"

namespace AMDiS { 

  int VtkVectorWriter::updateAnimationFile(std::string valueFilename,
				     std::vector< std::string > *paraViewAnimationFrames,
				     std::string animationFilename)
  {
    FUNCNAME("VtkVectorWriter::Impl<S>::updateAnimationFile()");

    size_t found = valueFilename.find_last_of("/\\");
    paraViewAnimationFrames->push_back(valueFilename.substr(found + 1));

    boost::iostreams::filtering_ostream file;
    {
      std::ofstream swapfile(animationFilename.c_str(),
			     std::ios::out | std::ios::trunc);
      TEST_EXIT(swapfile.is_open())
	("Cannot open file %s for writing!\n", animationFilename.c_str());
      swapfile.close();
    }
    file.push(boost::iostreams::file_descriptor_sink(animationFilename,
						     std::ios::trunc));

    file << "<?xml version=\"1.0\"?>\n";
    file << "<VTKFile type=\"Collection\" version=\"0.1\" >"  << "\n";
    file << "<Collection>\n";

    int counter = 0;
    std::vector< std::string >::iterator it;
    for (it = paraViewAnimationFrames->begin();
	 it < paraViewAnimationFrames->end();
	 ++it, counter++) {
      file << "<DataSet timestep=\"" << counter
	   << "\" part=\"0\" file=\"" << (*it) << "\"/>\n";
    }

    file << "</Collection>\n";
    file << "</VTKFile>\n";

    return 0;
  }


  void VtkVectorWriter::writeFile(std::vector<DOFVector<double>* > &values,
			    std::string filename,
78
79
			    bool writeParallel,
			    bool writeAs3dVector)
80
81
82
83
84
85
86
87
88
89
90
91
  {
    DOFVector<std::vector<double> > *newValues = new DOFVector<std::vector<double> >(values[0]->getFeSpace(), "values");
    std::vector<DOFIterator<double>* > iterators;
    for (size_t i = 0; i < values.size(); i++)
      iterators.push_back(new DOFIterator<double>(values[i],USED_DOFS));
    for (size_t i = 0; i < iterators.size(); i++)
      iterators[i]->reset();
    DOFIterator<std::vector<double> > resultIter(newValues, USED_DOFS);

    for(resultIter.reset(); !resultIter.end(); resultIter++)
    {
      std::vector<double> val;
92
      for (size_t i = 0; i < static_cast<size_t>(iterators.size()); i++)
93
94
95
	val.push_back(*(*(iterators[i])));

      *resultIter = val;
96
97
98
      
      for (size_t i = 0; i < static_cast<size_t>(iterators.size()); i++)
	(*(iterators[i]))++;
99
100
    }

101
    writeFile(newValues, filename, writeParallel, writeAs3dVector);
102
103
104
105
106
107
108
109
    for (size_t i = 0; i < iterators.size(); i++)
      delete iterators[i];
    delete newValues;
  }


  void VtkVectorWriter::writeFile(WorldVector<DOFVector<double>* > &values,
			    std::string filename,
110
111
			    bool writeParallel,
			    bool writeAs3dVector)
112
113
114
115
116
117
118
119
120
121
122
123
124
  {
    DOFVector<WorldVector<double> > *newValues = new DOFVector<WorldVector<double> >(values[0]->getFeSpace(), "values");
    WorldVector<DOFIterator<double>* > iterators;
    for (size_t i = 0; i < static_cast<size_t>(values.getSize()); i++)
      iterators[i] = new DOFIterator<double>(values[i],USED_DOFS);
    for (size_t i = 0; i < static_cast<size_t>(iterators.getSize()); i++)
      iterators[i]->reset();
    DOFIterator<WorldVector<double> > resultIter(newValues, USED_DOFS);

    for(resultIter.reset(); !resultIter.end(); resultIter++)
    {
      for (size_t i = 0; i < static_cast<size_t>(iterators.getSize()); i++)
	(*resultIter)[i] = *(*(iterators[i]));
125
126
127

      for (size_t i = 0; i < static_cast<size_t>(iterators.size()); i++)
	(*(iterators[i]))++;
128
129
    }

130
    writeFile(newValues, filename, writeParallel, writeAs3dVector);
131
132
133
134
135
136
137
138
    for (size_t i = 0; i < static_cast<size_t>(iterators.getSize()); i++)
      delete iterators[i];
    delete newValues;
  }


  void VtkVectorWriter::writeFile(SystemVector *values,
			    std::string filename,
139
140
			    bool writeParallel,
			    bool writeAs3dVector)
141
142
143
144
145
146
147
148
149
150
151
152
  {
    DOFVector<std::vector<double> > *newValues = new DOFVector<std::vector<double> >(values->getDOFVector(0)->getFeSpace(), "values");
    std::vector<DOFIterator<double>* > iterators;
    for (size_t i = 0; i < static_cast<size_t>(values->getSize()); i++)
      iterators.push_back(new DOFIterator<double>(values->getDOFVector(i),USED_DOFS));
    for (size_t i = 0; i < iterators.size(); i++)
      iterators[i]->reset();
    DOFIterator<std::vector<double> > resultIter(newValues, USED_DOFS);

    for(resultIter.reset(); !resultIter.end(); resultIter++)
    {
      std::vector<double> val;
153
      for (size_t i = 0; i < static_cast<size_t>(iterators.size()); i++)
154
155
156
	val.push_back(*(*(iterators[i])));

      *resultIter = val;
157
158
159

      for (size_t i = 0; i < static_cast<size_t>(iterators.size()); i++)
	(*(iterators[i]))++;
160
161
    }

162
    writeFile(newValues, filename, writeParallel, writeAs3dVector);
163
164
165
166
167
168
    for (size_t i = 0; i < iterators.size(); i++)
      delete iterators[i];
    delete newValues;
  }
  
}