VtkWriter.cc 4.6 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/******************************************************************************
 *
 * AMDiS - Adaptive multidimensional simulations
 *
 * Copyright (C) 2013 Dresden University of Technology. All Rights Reserved.
 * Web: https://fusionforge.zih.tu-dresden.de/projects/amdis
 *
 * Authors: 
 * Simon Vey, Thomas Witkowski, Andreas Naumann, Simon Praetorius, et al.
 *
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 *
 * This file is part of AMDiS
 *
 * See also license.opensource.txt in the distribution.
 * 
 ******************************************************************************/
20
21


22
#include <stdio.h>
23
24
#include <string>
#include <fstream>
Thomas Witkowski's avatar
Thomas Witkowski committed
25
#include <sstream>
Peter Gottschling's avatar
Peter Gottschling committed
26
#include <cmath>
27

Thomas Witkowski's avatar
Thomas Witkowski committed
28
29
30
#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
#include <mpi.h>
#endif
Thomas Witkowski's avatar
Thomas Witkowski committed
31

32
33
34
35
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/convenience.hpp>
#include <boost/lexical_cast.hpp>

36
37
38
39
40
#include "VtkWriter.h"
#include "DataCollector.h"
#include "DOFVector.h"
#include "SurfaceRegion_ED.h"
#include "ElementRegion_ED.h"
41
#include "AdaptInfo.h"
42

43

44

45
46
47
namespace AMDiS 
{ 
  namespace io
Thomas Witkowski's avatar
Thomas Witkowski committed
48
  {
49
    namespace VtkWriter
50
    {
51
      using namespace std;
52

53
54
55
      
      void writeFile(DOFVector<double> *values, 
		     string filename,
56
57
58
59
		     Vtuformat format,
		     bool highPrecision, 
		     bool writeParallel
		    )
60
61
62
63
      {
	DataCollector<> dc(values->getFeSpace(), values);
	vector<DataCollector<>*> dcList(0);
	dcList.push_back(&dc);
64
	writeFile(dcList, filename, format, highPrecision, writeParallel);
65
      }
66

67

68
69
      void writeFile(vector<DOFVector<double>* > &values,
		     string filename,
70
71
72
73
		     Vtuformat format,
		     bool highPrecision, 
		     bool writeParallel
		    )
74
75
76
77
      {
	vector<DataCollector<>*> dcList(0);
	for (size_t i = 0; i < values.size(); i++)
	  dcList.push_back(new DataCollector<>(values[i]->getFeSpace(), values[i]));	
78
	writeFile(dcList, filename, format, highPrecision, writeParallel);
79
80
81
	for (size_t i = 0; i < values.size(); i++)
	  delete dcList[i];	
      }
82

83

84
85
      void writeFile(WorldVector<DOFVector<double>* > &values,
		     string filename,
86
87
88
89
		     Vtuformat format,
		     bool highPrecision, 
		     bool writeParallel
		    )
90
91
92
93
      {
	vector<DataCollector<>*> dcList(0);
	for (int i = 0; i < values.getSize(); i++)
	  dcList.push_back(new DataCollector<>(values[i]->getFeSpace(), values[i]));	
94
	writeFile(dcList, filename, format, highPrecision, writeParallel);
95
96
97
	for (int i = 0; i < values.getSize(); i++)
	  delete dcList[i];	
      }
98

99

100
101
      void writeFile(DOFVector<WorldVector<double> > *values,
		     string filename,
102
103
104
105
		     Vtuformat format,
		     bool highPrecision, 
		     bool writeParallel
		    )
106
107
108
109
110
111
      {
	WorldVector<DOFVector<double>*> valuesWV;
	for (int i =0 ; i < valuesWV.getSize(); i++)
	  valuesWV[i] = new DOFVector<double>(values->getFeSpace(), 
					      "values["+boost::lexical_cast<std::string>(i)+"]");
	transform(values, &valuesWV);
112
	writeFile(valuesWV, filename, format, highPrecision, writeParallel);
113
114
115
	for (int i = 0; i < valuesWV.getSize(); i++)
	  delete valuesWV[i];
      }
116

117
      
118
119
      void writeFile(SystemVector *values, 
		     string filename,
120
121
122
123
		     Vtuformat format,
		     bool highPrecision, 
		     bool writeParallel
		    )
124
125
126
127
128
      {
	vector<DataCollector<>*> dcList(0);
	for (int i = 0; i < values->getSize(); i++)
	  dcList.push_back(new DataCollector<>(values->getDOFVector(i)->getFeSpace(), 
					    values->getDOFVector(i)));    
129
	writeFile(dcList, filename, format, highPrecision, writeParallel);
130
131
	for (size_t i = 0; i < dcList.size(); i++)
	  delete dcList[i];    
Thomas Witkowski's avatar
Blub    
Thomas Witkowski committed
132
      }
133
      
134
135
136
      
      void writeFile(vector<DataCollector<>*> &dcList,
		     string filename,
137
138
139
140
		     Vtuformat format,
		     bool highPrecision, 
		     bool writeParallel
		    )
141
      {
Praetorius, Simon's avatar
Praetorius, Simon committed
142
143
144
145
	vector<string> componentNames;
	for (size_t i = 0; i < dcList.size(); i++)
	  componentNames.push_back(dcList[i]->getValues()->getName());
	::AMDiS::io::VtkWriter::Aux writer(&dcList, componentNames, format, highPrecision);
146
147
148
149
150
151
152
153
154
155
156
157
	
#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
	if (writeParallel) {
	  using boost::lexical_cast;
	  
	  int sPos = filename.find(".vtu");
	  TEST_EXIT(sPos >= 0)("Failed to find file postfix!\n");
	  string name = filename.substr(0, sPos);
	  
	  if (MPI::COMM_WORLD.Get_rank() == 0) {

	    detail::writeParallelFile(name + ".pvtu", MPI::COMM_WORLD.Get_size(), 
158
				      name, ".vtu", componentNames, format, highPrecision);
159
160
161
162
	  }
	  
	  filename = name + "-p" + lexical_cast<string>(MPI::COMM_WORLD.Get_rank()) + "-.vtu";
	}
163
#endif
164
165
166
167
168
169
	writer.writeFile(filename);
      }

    } // end namespace VtkWriter
  } // end namespace io
} // end namespace AMDiS