Finite Element Domain Decomposition Library
FEDDLib
Loading...
Searching...
No Matches
ExporterParaView_def.hpp
1#ifndef ExporterParaView_DEF_hpp
2#define ExporterParaView_DEF_hpp
3
4#include "ExporterParaView_decl.hpp"
5
14
15namespace FEDD {
16template<class SC,class LO,class GO,class NO>
17ExporterParaView<SC,LO,GO,NO>::ExporterParaView():
18hdf5exporter_(),
19comm_(),
20commEpetra_(),
21closingLinesPosition_(),
22closingLinesPositionTimes_(),
23closingLines_(),
24xmf_out_(),
25xmf_times_out_(),
26filename_(),
27outputFilename_(),
28postfix_(),
29FEType_(),
30variables_(0),
31uniqueMaps_(0),
32varNames_(0),
33varTypes_(0),
34varDofPerNode_(0),
35pointsHDF_(),
36elementsHDF_(),
37dim_(0),
38nmbElementsGlob_(0),
39nmbPointsGlob_(0),
40nmbExportValuesGlob_(0),
41nmbPointsPerElement_(0),
42timeIndex_(0),
43writeDt_(0),
44saveTimestep_(1),
45verbose_(false),
46parameterList_(),
47pointsUnique_()
48{
49
50}
51
52template<class SC,class LO,class GO,class NO>
53void ExporterParaView<SC,LO,GO,NO>::setup(std::string filename,
54 MeshPtr_Type mesh,
55 std::string FEType,
56 int saveTimestep,
57 ParameterListPtr_Type parameterList){
58
59
60 setup( filename, mesh, FEType, parameterList);
61 saveTimestep_ = saveTimestep;
62}
63
64template<class SC,class LO,class GO,class NO>
65void ExporterParaView<SC,LO,GO,NO>::setup(std::string filename,
66 MeshPtr_Type mesh,
67 std::string FEType,
68 ParameterListPtr_Type parameterList){
69
70
71 parameterList_ = parameterList;
72 comm_ = mesh->getComm();
73 verbose_ = (comm_->getRank() == 0);
74 Teuchos::RCP<const Teuchos::MpiComm<int> > mpiComm = Teuchos::rcp_dynamic_cast<const Teuchos::MpiComm<int> >( mesh->getComm() );
75 commEpetra_.reset( new Epetra_MpiComm( *mpiComm->getRawMpiComm() ) );
76 filename_ = filename;
77 outputFilename_ = filename_ + ".h5";
78 FEType_ = FEType;
79 dim_ = mesh->getDimension();
80 nmbElementsGlob_ = mesh->getNumElementsGlobal();
81
82 pointsUnique_ = mesh->getPointsUnique();
83
84 if (FEType_ == "P0") {
85 if (dim_ == 2 ) {
86 nmbPointsPerElement_ = 3 ;
87
88 }
89 else if(dim_ == 3){
90 nmbPointsPerElement_ = 4 ;
91
92 }
93 }
94 else if (FEType_ == "P1") {
95 if (dim_ == 2 ) {
96 nmbPointsPerElement_ = 3 ;
97
98 }
99 else if(dim_ == 3){
100 nmbPointsPerElement_ = 4 ;
101
102 }
103 }
104 else if (FEType_ == "P1-disc") {
105 if (dim_ == 2 ) {
106 nmbPointsPerElement_ = 3 ;
107
108 }
109 else if(dim_ == 3){
110 nmbPointsPerElement_ = 4 ;
111
112 }
113 }
114 else if(FEType_ == "P2"){
115
116 if (dim_ == 2 ) {
117 nmbPointsPerElement_ = 6 ;
118
119 }
120 else if(dim_ == 3){
121 nmbPointsPerElement_ = 10 ;
122 }
123 }
124 else if(FEType_ == "P2-CR"){
125 if (dim_ == 2 ) {
126 TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error, "Wrong dimension for P2-CR.");
127 }
128 else if(dim_ == 3){
129 nmbPointsPerElement_ = 10 ; // only export P2 points. Paraview 5.6.0 and prior versions ignore face centered values.
130 }
131 }
132 else if(FEType_ == "Q1"){
133 if (dim_ == 2 ) {
134 TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error, "Wrong dimension for Q1.");
135 }
136 else if(dim_ == 3){
137 nmbPointsPerElement_ = 8 ;
138 }
139 }
140
141 else if(FEType_ == "Q2"){
142 if (dim_ == 2 ) {
143 TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error, "Wrong dimension for Q2.");
144 }
145 else if(dim_ == 3){
146 nmbPointsPerElement_ = 20 ; // only export Q20 points.
147 }
148 }
149 else if(FEType_ == "Q2-20"){
150 if (dim_ == 2 ) {
151 TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error, "Wrong dimension for Q2-20.");
152 }
153 else if(dim_ == 3){
154 nmbPointsPerElement_ = 20 ; // only export Q20 points.
155 }
156 }
157 else {
158 TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error, "Wrong FEType, choose either P0 or P1 or P1-disc or P2 or P2-CR or Q1 or Q2 or Q2-20. Subdomain export with P0 - Export stopped");
159 }
160
161 nmbPointsGlob_ = mesh->getMapUnique()->getGlobalNumElements();
162
163 closingLines_ = "\n </Grid>\n\n </Domain>\n</Xdmf>\n";
164
165 timeIndex_ = 0;
166
167 MapConstPtr_Type elementMap = mesh->getElementMap();
168 Teuchos::ArrayView<const GO> nodeElementList = elementMap->getNodeElementList();
169 vec_int_Type nodeElementListInteger( nmbPointsPerElement_ * nodeElementList.size() );
170 int counter=0;
171 for (int i=0; i<nodeElementList.size(); i++) {
172 for (int j=0; j<nmbPointsPerElement_; j++){
173 nodeElementListInteger[counter] = (int) nmbPointsPerElement_*nodeElementList[i] + j;
174 counter++;
175 }
176 }
177 Teuchos::RCP<Epetra_BlockMap> mapElements;
178 if (nodeElementListInteger.size()>0)
179 mapElements.reset(new Epetra_BlockMap( (int) (nmbPointsPerElement_*nmbElementsGlob_), (int) nodeElementListInteger.size(), &nodeElementListInteger[0],1, 0, *commEpetra_));
180 else
181 mapElements.reset(new Epetra_BlockMap( (int) (nmbPointsPerElement_*nmbElementsGlob_), (int) nodeElementListInteger.size(), NULL,1, 0, *commEpetra_));
182
183 elementsHDF_.reset(new Epetra_IntVector(*mapElements));
184
185 ElementsPtr_Type elements = mesh->getElementsC();
186 counter = 0;
187 for (int i=0; i<elements->numberElements(); i++) {
188 for (int j=0; j<nmbPointsPerElement_; j++) {
189 int globalIndex = (int) mesh->getMapRepeated()->getGlobalElement( elements->getElement(i).getNode(j) );
190 (*elementsHDF_)[counter] = globalIndex;
191 counter++;
192 }
193 }
194
195 Teuchos::ArrayView< const GO > indices = mesh->getMapUnique()->getNodeElementList();
196 int* intGlobIDs = new int[indices.size()];
197 for (int i=0; i<indices.size(); i++) {
198 intGlobIDs[i] = (int) indices[i];
199 }
200
201 EpetraMapPtr_Type mapEpetra = Teuchos::rcp(new Epetra_Map((int)nmbPointsGlob_,indices.size(),intGlobIDs,0,*commEpetra_));
202 delete [] intGlobIDs;
203
204 pointsHDF_.reset(new Epetra_MultiVector(*mapEpetra,dim_));
205
206 updatePoints();
207
208 this->initHDF5();
209
210 this->initXmf();
211
212 writeDt_ = false;
213
214 saveTimestep_ = 1;
215}
216
217template<class SC,class LO,class GO,class NO>
218void ExporterParaView<SC,LO,GO,NO>::addVariable(MultiVecConstPtr_Type &u,
219 std::string varName,
220 std::string varType,
221 int dofPerNode,
222 MapConstPtrConst_Type& mapUnique){
223
224 variables_.push_back(u);
225 varNames_.push_back(varName);
226 varTypes_.push_back(varType);
227 varDofPerNode_.push_back(dofPerNode);
228
229 nmbExportValuesGlob_ = mapUnique->getGlobalNumElements();
230
231
232
233 Teuchos::ArrayView< const GO > indices = mapUnique->getNodeElementList();
234 int* intGlobIDs = new int[indices.size()];
235 for (int i=0; i<indices.size(); i++) {
236 intGlobIDs[i] = (int) indices[i];
237 }
238
239 EpetraMapPtr_Type mapToStore = Teuchos::rcp(new Epetra_Map( (int) mapUnique->getGlobalNumElements(), indices.size(), intGlobIDs,0, *commEpetra_ ) );
240
241 uniqueMaps_.push_back(mapToStore);
242 delete [] intGlobIDs;
243
244}
245
246template<class SC,class LO,class GO,class NO>
247void ExporterParaView<SC,LO,GO,NO>::save(double time){
248
249 if (timeIndex_ % saveTimestep_ == 0) {
250 makePostfix();
251
252 if (!parameterList_.is_null()){
253 if ( parameterList_->sublist("Exporter").get("Write new mesh",false) )
254 writeMeshPointsHDF5();
255 }
256
257 writeVariablesHDF5();
258
259 writeXmf(time);
260 }
261 else{
262 if (this->verbose_)
263 std::cout << "\n \t ### Export criterion not satisfied for current time step - no export of time step! ###" << std::endl;
264 }
265
266 timeIndex_++;
267
268}
269
270template<class SC,class LO,class GO,class NO>
271void ExporterParaView<SC,LO,GO,NO>::save(double time, double dt){
272
273 if (timeIndex_ % saveTimestep_ == 0) {
274
275 makePostfix();
276 if (!parameterList_.is_null()){
277 if ( parameterList_->sublist("Exporter").get("Write new mesh",false) )
278 writeMeshPointsHDF5();
279 }
280 writeVariablesHDF5();
281
282 writeXmf(time);
283
284 if (timeIndex_==0) {
285 initXmfTimes();
286 }
287 writeXmfTime(time, dt);
288 }
289 else{
290 if (this->verbose_)
291 std::cout << "\n \t ### Export criterion not satisfied for current time step - no export of time step! ###" << std::endl;
292 }
293
294 timeIndex_++;
295
296}
297
298template<class SC,class LO,class GO,class NO>
299void ExporterParaView<SC,LO,GO,NO>::closeExporter(){
300
301 hdf5exporter_->Close();
302 xmf_out_.close();
303 if (writeDt_) {
304 xmf_times_out_.close();
305 }
306
307}
308
309template<class SC,class LO,class GO,class NO>
310void ExporterParaView<SC,LO,GO,NO>::initHDF5(){
311
312 hdf5exporter_.reset( new HDF5_Type(*commEpetra_) );
313 hdf5exporter_->Create(outputFilename_);
314 std::string nameConn = "Connections";
315
316 writeMeshElements(nameConn);
317 // Mesh is only written once. If we have a new mesh for a new export, we call writeMeshPointsHDF5() in function save(...), when all the data is updated.
318 if (parameterList_.is_null())
319 writeMeshPointsHDF5();
320 else if ( parameterList_->sublist("Exporter").get("Write new mesh",false) == false )
321 writeMeshPointsHDF5();
322
323}
324
325template<class SC,class LO,class GO,class NO>
326void ExporterParaView<SC,LO,GO,NO>::writeMeshPointsHDF5(){
327 if (!parameterList_.is_null()){
328 if ( parameterList_->sublist("Exporter").get("Write new mesh",false) ) {
329 updatePoints();
330 std::string nameP_X = "PointsX" + std::to_string(timeIndex_);
331 std::string nameP_Y = "PointsY" + std::to_string(timeIndex_);
332 std::string nameP_Z = "PointsZ" + std::to_string(timeIndex_);
333
334 writeMeshPoints(nameP_X, nameP_Y, nameP_Z );
335 }
336
337 else{
338 std::string nameP_X = "PointsX";
339 std::string nameP_Y = "PointsY";
340 std::string nameP_Z = "PointsZ";
341 writeMeshPoints( nameP_X, nameP_Y, nameP_Z );
342 }
343 }
344 else{
345 std::string nameP_X = "PointsX";
346 std::string nameP_Y = "PointsY";
347 std::string nameP_Z = "PointsZ";
348 writeMeshPoints( nameP_X, nameP_Y, nameP_Z );
349 }
350}
351
352template<class SC,class LO,class GO,class NO>
353void ExporterParaView<SC,LO,GO,NO>::writeMeshElements( std::string nameConn ){
354 //Triangle/Tetrahedron Connections
355 hdf5exporter_->CreateGroup(nameConn);
356
357 hdf5exporter_->Write(nameConn,*elementsHDF_);
358}
359
360template<class SC,class LO,class GO,class NO>
361void ExporterParaView<SC,LO,GO,NO>::writeMeshPoints(std::string nameP_X,
362 std::string nameP_Y,
363 std::string nameP_Z){
364
365
366
367 hdf5exporter_->CreateGroup(nameP_X);
368 hdf5exporter_->CreateGroup(nameP_Y);
369
370 hdf5exporter_->Write(nameP_X,*(*pointsHDF_)(0));
371 hdf5exporter_->Write(nameP_Y,*(*pointsHDF_)(1));
372
373 if (dim_ == 3) {
374 hdf5exporter_->CreateGroup(nameP_Z);
375 hdf5exporter_->Write(nameP_Z,*(*pointsHDF_)(2));
376 }
377 hdf5exporter_->Flush();
378
379}
380
381template<class SC,class LO,class GO,class NO>
382void ExporterParaView<SC,LO,GO,NO>::updatePoints(){
383 int dim = -1;
384 if (pointsUnique_->size()>0)
385 dim = pointsUnique_->at(0).size();
386
387 for (int i=0; i<pointsUnique_->size(); i++) {
388 for (int j = 0; j < dim; j++) {
389 pointsHDF_->ReplaceMyValue(i,j,(*pointsUnique_)[i][j]);
390 }
391 }
392}
393
394template<class SC,class LO,class GO,class NO>
395void ExporterParaView<SC,LO,GO,NO>::writeVariablesHDF5(){
396
397 for (int i=0; i<variables_.size(); i++) {
398
399 if (varTypes_.at(i)=="Vector") {
400 EpetraMVPtr_Type u_export(new Epetra_MultiVector(*(uniqueMaps_.at(i)),3)); // ParaView always uses 3D Data. for 2D Data the last entries (for the 3rd Dim) are all zero.
401
402 hdf5exporter_->CreateGroup(varNames_[i]+postfix_);
403
404 prepareVectorField(variables_.at(i),u_export, varDofPerNode_.at(i));
405
406 hdf5exporter_->Write(varNames_[i]+postfix_,*u_export,true);
407 }
408 else if(varTypes_.at(i)=="Scalar"){
409 EpetraMVPtr_Type u_export(new Epetra_MultiVector(*(uniqueMaps_.at(i)),1));
410
411 hdf5exporter_->CreateGroup(varNames_[i]+postfix_);
412
413 prepareScalar(variables_.at(i),u_export); //conversion to int
414
415 hdf5exporter_->Write(varNames_[i]+postfix_,*u_export);
416 }
417 hdf5exporter_->Flush();
418 }
419
420}
421
422template<class SC,class LO,class GO,class NO>
423void ExporterParaView<SC,LO,GO,NO>::initXmf(){
424
425 if (comm_->getRank()==0) {
426
427 xmf_out_.open((filename_ + ".xmf").c_str(),std::ios_base::out);
428 xmf_out_ << "<?xml version=\"1.0\" ?>\n"
429 << "<!DOCTYPE Xdmf SYSTEM \""
430 << filename_
431 << ".xdmf\" [\n"
432 << "<!ENTITY DataFile \""
433 << filename_
434 << ".h5\">\n"
435 << "]>\n"
436 << "<!-- "
437 << filename_
438 << ".h5 -->\n"
439 << "<Xdmf>\n"
440 << " <Domain Name=\""
441 << filename_
442 << "\">\n"
443 << " <Grid Name=\""
444 << filename_
445 << "Grid\" GridType=\"Collection\" CollectionType=\"Temporal\">\n"
446 << "\n";
447
448 closingLinesPosition_ = xmf_out_.tellp();
449 // write closing lines
450 xmf_out_ << closingLines_;
451 xmf_out_.flush();
452 }
453
454}
455
456template<class SC,class LO,class GO,class NO>
457void ExporterParaView<SC,LO,GO,NO>::initXmfTimes(){
458 writeDt_ = true;
459 if (comm_->getRank()==0) {
460
461 xmf_times_out_.open((filename_ + "_times.xmf").c_str(),std::ios_base::out);
462 xmf_times_out_ << "<?xml version=\"1.0\" ?>\n"
463 << "<!DOCTYPE Xdmf SYSTEM \""
464 << filename_
465 << ".xdmf\" []>\n"
466 << "<Xdmf>\n"
467 << " <Domain Name=\""
468 << filename_
469 << "\">\n"
470 << " <Grid Name=\""
471 << filename_
472 << "Grid\" GridType=\"Collection\" CollectionType=\"Temporal\">\n"
473 << "\n";
474
475 closingLinesPositionTimes_ = xmf_times_out_.tellp();
476 // write closing lines
477 xmf_times_out_ << closingLines_;
478 xmf_times_out_.flush();
479 }
480
481}
482template<class SC,class LO,class GO,class NO>
483void ExporterParaView<SC,LO,GO,NO>::writeXmf(double time){
484
485 std::string nameP_X;
486 std::string nameP_Y;
487 std::string nameP_Z;
488 std::string nameConn = "Connections";
489 if(redo_ == true)
490 nameConn = "Connections" + std::to_string(timeIndex_);
491 if (!parameterList_.is_null()){
492 if ( parameterList_->sublist("Exporter").get("Write new mesh",false) ) {
493 nameP_X = "PointsX" + std::to_string(timeIndex_);
494 nameP_Y = "PointsY" + std::to_string(timeIndex_);
495 nameP_Z = "PointsZ" + std::to_string(timeIndex_);
496 }
497 else{
498 nameP_X = "PointsX";
499 nameP_Y = "PointsY";
500 nameP_Z = "PointsZ";
501 }
502 }
503 else {
504 nameP_X = "PointsX";
505 nameP_Y = "PointsY";
506 nameP_Z = "PointsZ";
507 }
508 writeXmfElements( nameConn, time);
509 writeXmfPoints( nameP_X, nameP_Y, nameP_Z );
510 writeXmfVariables();
511
512}
513
514template<class SC,class LO,class GO,class NO>
515void ExporterParaView<SC,LO,GO,NO>::writeXmfElements( std::string nameConn, double time ){
516
517 if (verbose_) {
518 xmf_out_.seekp (closingLinesPosition_);
519
520 xmf_out_ <<
521 "<!-- Time " << time << " Iteration " << postfix_.substr (1, 5) << " -->\n" <<
522 " <Grid Name=\"Mesh" << FEType_ << " " << time << "\">\n" <<
523 " <Time TimeType=\"Single\" Value=\"" << time << "\" />\n";
524
525 // writeTopology (M_xdmf);
526 std::string FEstring;
527 if (FEType_=="P0") {
528 if (dim_ == 2) {
529 FEstring = "Triangle";
530 }
531 else if(dim_ == 3){
532 FEstring = "Tetrahedron";
533 }
534 }
535 else if (FEType_=="P1-disc") {
536 if (dim_ == 2) {
537 FEstring = "Triangle";
538 }
539 else if(dim_ == 3){
540 FEstring = "Tetrahedron";
541 }
542 }
543 else if (FEType_=="P1") {
544 if (dim_ == 2) {
545 FEstring = "Triangle";
546 }
547 else if(dim_ == 3){
548 FEstring = "Tetrahedron";
549 }
550 }
551
552 else if (FEType_=="P2"){
553 if (dim_ == 2) {
554 FEstring = "Tri_6";
555 }
556 else if(dim_ == 3){
557 FEstring = "Tet_10";
558 }
559 }
560 else if (FEType_=="P2-CR"){
561 //there is no 2D version
562 if(dim_ == 3){
563 FEstring = "Tet_10";
564 }
565 }
566 else if (FEType_=="Q1"){
567 //there is no 2D version
568 if(dim_ == 3){
569 FEstring = "Hexahedron";
570 }
571 }
572 else if (FEType_=="Q2"){
573 //there is no 2D version
574 if(dim_ == 3){
575 FEstring = "Hex_20";
576 }
577 }
578 else if (FEType_=="Q2-20"){
579 //there is no 2D version
580 if(dim_ == 3){
581 FEstring = "Hex_20";
582 }
583 }
584
585 xmf_out_ << " <Topology\n"
586 << " Type=\""
587 << FEstring
588 << "\"\n"
589 << " NumberOfElements=\""
590 << nmbElementsGlob_
591 << "\"\n"
592 << " BaseOffset=\""
593 << 0
594 << "\">\n"
595 << " <DataStructure Format=\"HDF\"\n"
596 << " Dimensions=\""
597 << nmbElementsGlob_//this->M_mesh->numGlobalElements()
598 << " "
599 << nmbPointsPerElement_//this->M_mesh->numLocalVertices()
600 << "\"\n" << " DataType=\"Int\"\n"
601 << " Precision=\"8\">\n" << " "
602 << outputFilename_ << ":/"<< nameConn <<"/Values\n"
603 << " </DataStructure>\n" << " </Topology>\n";
604
605 closingLinesPosition_ = xmf_out_.tellp();
606
607 }
608}
609template<class SC,class LO,class GO,class NO>
610void ExporterParaView<SC,LO,GO,NO>::writeXmfPoints(std::string nameP_X,
611 std::string nameP_Y,
612 std::string nameP_Z ){
613
614 if (verbose_) {
615 xmf_out_.seekp (closingLinesPosition_);
616 // writeGeometry (M_xdmf);
617 if (dim_ == 2) {
618 xmf_out_ <<
619 " <Geometry Type=\"X_Y\">\n" <<
620 " <DataStructure Format=\"HDF\"\n" <<
621 " Dimensions=\"" << nmbPointsGlob_ << "\"\n" <<
622 " DataType=\"Float\"\n" <<
623 " Precision=\"8\">\n" <<
624 " " << outputFilename_ << ":/" << nameP_X << "/Values\n" <<
625 " </DataStructure>\n" <<
626 " <DataStructure Format=\"HDF\"\n" <<
627 " Dimensions=\"" << nmbPointsGlob_ << "\"\n" <<
628 " DataType=\"Float\"\n" <<
629 " Precision=\"8\">\n" <<
630 " " << outputFilename_ << ":/" << nameP_Y << "/Values\n" <<
631 " </DataStructure>\n" <<
632 " </Geometry>\n" <<
633 "\n";
634 }
635 else if(dim_ ==3){
636 xmf_out_ <<
637 " <Geometry Type=\"X_Y_Z\">\n" <<
638 " <DataStructure Format=\"HDF\"\n" <<
639 " Dimensions=\"" << nmbPointsGlob_ << "\"\n" <<
640 " DataType=\"Float\"\n" <<
641 " Precision=\"8\">\n" <<
642 " " << outputFilename_ << ":/" << nameP_X << "/Values\n" <<
643 " </DataStructure>\n" <<
644 " <DataStructure Format=\"HDF\"\n" <<
645 " Dimensions=\"" << nmbPointsGlob_ << "\"\n" <<
646 " DataType=\"Float\"\n" <<
647 " Precision=\"8\">\n" <<
648 " " << outputFilename_ << ":/" << nameP_Y << "/Values\n" <<
649 " </DataStructure>\n" <<
650 " <DataStructure Format=\"HDF\"\n" <<
651 " Dimensions=\"" << nmbPointsGlob_ << "\"\n" <<
652 " DataType=\"Float\"\n" <<
653 " Precision=\"8\">\n" <<
654 " " << outputFilename_ << ":/" << nameP_Z << "/Values\n" <<
655 " </DataStructure>\n" <<
656 " </Geometry>\n" <<
657 "\n";
658 }
659 closingLinesPosition_ = xmf_out_.tellp();
660
661 }
662
663}
664
665template<class SC,class LO,class GO,class NO>
666void ExporterParaView<SC,LO,GO,NO>::writeXmfVariables(){
667
668 std::string centerString;
669 if (FEType_=="P0") {
670 centerString = "Cell";
671 }
672 else if (FEType_=="P1-disc") {
673
674 }
675 else if (FEType_=="P1") {
676 centerString = "Node";
677 }
678
679 else if (FEType_=="P2"){
680 centerString = "Node";
681 }
682 else if (FEType_=="Q2"){
683 centerString = "Node";
684 }
685
686 if(verbose_){
687 xmf_out_.seekp (closingLinesPosition_);
688
689 for (int i=0; i<varNames_.size(); i++) {
690 int dof = varDofPerNode_.at(i);
691 if (dof == 2) {
692 dof=3; // ParaView always uses 3D Data. for 2D Data the last entries (for the 3rd Dim) are all zero.
693 }
694 xmf_out_ <<
695 "\n <Attribute\n" <<
696 " Type=\"" << varTypes_.at(i) << "\"\n" <<
697 " Center=\"" << centerString << "\"\n" <<
698 " Name=\"" << varNames_.at(i) << "\">\n";
699
700
701 xmf_out_ <<
702 " <DataStructure ItemType=\"HyperSlab\"\n" <<
703 " Dimensions=\"" << nmbExportValuesGlob_ << " " << dof << "\"\n" <<
704 " Type=\"HyperSlab\">\n" <<
705 " <DataStructure Dimensions=\"3 2\"\n" <<
706 " Format=\"XML\">\n" <<
707 " 0 0\n" <<
708 " 1 1\n" <<
709 " " << nmbExportValuesGlob_ << " " << dof << "\n" <<
710 " </DataStructure>\n" <<
711
712 " <DataStructure Format=\"HDF\"\n" <<
713 " Dimensions=\"" << nmbExportValuesGlob_ << " " << dof << "\"\n" <<
714 " DataType=\"Float\"\n" <<
715 " Precision=\"8\">\n" <<
716 " " << outputFilename_ << ":/" << varNames_.at(i)
717 << postfix_ << "/Values\n" << // see also in writeVector/scalar
718 " </DataStructure>\n" <<
719 " </DataStructure>\n";
720
721
722 xmf_out_ <<
723 " </Attribute>\n";
724
725 }
726
727 xmf_out_ << "\n"
728 " </Grid>\n\n";
729 closingLinesPosition_ = xmf_out_.tellp();
730 // write closing lines
731 xmf_out_ << closingLines_;
732 xmf_out_.flush();
733 }
734}
735template<class SC,class LO,class GO,class NO>
736void ExporterParaView<SC,LO,GO,NO>::writeXmfTime(double time, double dt){
737
738 if (comm_->getRank()==0) {
739
740 xmf_times_out_.seekp (closingLinesPositionTimes_);
741
742 xmf_times_out_ <<
743 "<!-- Time " << time << " Iteration " << postfix_.substr (1, 5) << " -->\n" <<
744 " <Grid Name=\"Mesh Times " << time << "\">\n" <<
745 " <Time TimeType=\"Single\" Value=\"" << time << "\" />\n";
746 xmf_times_out_ <<
747 " <Topology\n"
748 << " Type=\"Polyvertex\"\n"
749 << " NumberOfElements=\""
750 << 2
751 << "\"\n"
752 << " BaseOffset=\""
753 << 0
754 << "\">\n"
755 << " <DataStructure Format=\"XML\"\n"
756 << " Dimensions=\"2\"\n"
757 << " DataType=\"Int\"\n"
758 << " Precision=\"8\">\n"
759 << " 0 1 \n"
760 << " </DataStructure>\n" << " </Topology>\n";
761
762
763 xmf_times_out_ <<
764 " <Geometry Type=\"X_Y\">\n" <<
765 " <DataStructure Format=\"XML\"\n" <<
766 " Dimensions=\"" << 2 << "\"\n" <<
767 " DataType=\"Float\"\n" <<
768 " Precision=\"8\">\n" <<
769 " " << "0.0 1.0 \n" <<
770 " </DataStructure>\n" <<
771 " <DataStructure Format=\"XML\"\n" <<
772 " Dimensions=\"" << 2 << "\"\n" <<
773 " DataType=\"Float\"\n" <<
774 " Precision=\"8\">\n" <<
775 " " << "0.0 1.0 \n" <<
776 " </DataStructure>\n" << " </Geometry>\n" <<
777 "\n";
778
779 xmf_times_out_ <<
780 "\n <Attribute\n" <<
781 " Type=\"" << "Scalar" << "\"\n" <<
782 " Center=\"" << "Node" << "\"\n" <<
783 " Name=\"" << "t_dt" << "\">\n";
784
785
786 xmf_times_out_ <<
787 " <DataStructure Format=\"XML\"\n" <<
788 " Dimensions=\"" << 2 << "\"\n" <<
789 " DataType=\"Float\"\n" <<
790 " Precision=\"8\">\n" <<
791 " " << time << " " << dt << "\n" <<
792 " </DataStructure>\n";
793
794 xmf_times_out_ <<
795 " </Attribute>\n";
796
797 xmf_times_out_ << "\n"
798 " </Grid>\n\n";
799 closingLinesPositionTimes_ = xmf_times_out_.tellp();
800 // write closing lines
801 xmf_times_out_ << closingLines_;
802 xmf_times_out_.flush();
803 }
804
805}
806
807template<class SC,class LO,class GO,class NO>
808void ExporterParaView<SC,LO,GO,NO>::prepareVectorField(MultiVecConstPtr_Type &u,
809 EpetraMVPtr_Type &u_export,
810 int dof) const{
811
812 TEUCHOS_TEST_FOR_EXCEPTION(u->getNumVectors()!=1, std::logic_error, "Can only export single vector");
813
814 for (int i=0; i<(u->getLocalLength()/dof); i++) {
815 for (int j=0; j < dof; j++) {
816 Teuchos::ArrayRCP<const SC> tmpData = u->getData(0);
817 u_export->ReplaceMyValue( i, j, tmpData[ dof * i + j ] );
818 }
819 }
820}
821
822template<class SC,class LO,class GO,class NO>
823void ExporterParaView<SC,LO,GO,NO>::prepareScalar(MultiVecConstPtr_Type &u,
824 EpetraMVPtr_Type &u_export) const{
825
826 TEUCHOS_TEST_FOR_EXCEPTION(u->getNumVectors()!=1, std::logic_error, "Can only export single vector");
827
828 Teuchos::ArrayRCP<const SC> tmpData = u->getData(0);
829 for (int i=0; i<tmpData.size(); i++) {
830
831 u_export->ReplaceMyValue( i, 0, tmpData[ i ] );
832 }
833
834}
835
836template<class SC,class LO,class GO,class NO>
837void ExporterParaView<SC,LO,GO,NO>::makePostfix(){
838
839 int postfixLength = 5;
840 std::ostringstream index;
841 index.fill ( '0' );
842
843 if (timeIndex_ % saveTimestep_ == 0){
844 index << std::setw (postfixLength) << ( timeIndex_ / saveTimestep_ );
845 postfix_ = "." + index.str();
846 }
847}
848}
849#endif
Adaptive Mesh Refinement.
Definition AdaptiveMeshRefinement.cpp:5