-
Notifications
You must be signed in to change notification settings - Fork 707
/
data_out_base.cc
8527 lines (7215 loc) · 285 KB
/
data_out_base.cc
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ---------------------------------------------------------------------
//
// Copyright (C) 1999 - 2019 by the deal.II authors
//
// This file is part of the deal.II library.
//
// The deal.II library is free software; you can use it, redistribute
// it, and/or modify it under the terms of the GNU Lesser General
// Public License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// The full text of the license can be found in the file LICENSE.md at
// the top level directory of deal.II.
//
// ---------------------------------------------------------------------
// TODO: Do neighbors for dx and povray smooth triangles
//////////////////////////////////////////////////////////////////////
// Remarks on the implementations
//
// Variable names: in most functions, variable names have been
// standardized in the following way:
//
// n1, n2, ni Number of points in coordinate direction 1, 2, i
// will be 1 if i>=dim
//
// i1, i2, ii Loop variable running up to ni
//
// d1, d2, di Multiplicators for ii to find positions in the
// array of nodes.
//////////////////////////////////////////////////////////////////////
#include <deal.II/base/data_out_base.h>
#include <deal.II/base/memory_consumption.h>
#include <deal.II/base/mpi.h>
#include <deal.II/base/parameter_handler.h>
#include <deal.II/base/thread_management.h>
#include <deal.II/base/utilities.h>
#include <deal.II/numerics/data_component_interpretation.h>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <memory>
#include <set>
#include <sstream>
// we use uint32_t and uint8_t below, which are declared here:
#include <cstdint>
#ifdef DEAL_II_WITH_ZLIB
# include <zlib.h>
#endif
#ifdef DEAL_II_WITH_HDF5
# include <hdf5.h>
#endif
DEAL_II_NAMESPACE_OPEN
// we need the following exception from a global function, so can't declare it
// in the usual way inside a class
namespace
{
DeclException2(ExcUnexpectedInput,
std::string,
std::string,
<< "Unexpected input: expected line\n <" << arg1
<< ">\nbut got\n <" << arg2 << ">");
}
namespace
{
#ifdef DEAL_II_WITH_ZLIB
/**
* Convert between the enum specified inside VtkFlags and the preprocessor
* constant defined by zlib.
*/
int
get_zlib_compression_level(
const DataOutBase::VtkFlags::ZlibCompressionLevel level)
{
switch (level)
{
case (DataOutBase::VtkFlags::no_compression):
return Z_NO_COMPRESSION;
case (DataOutBase::VtkFlags::best_speed):
return Z_BEST_SPEED;
case (DataOutBase::VtkFlags::best_compression):
return Z_BEST_COMPRESSION;
case (DataOutBase::VtkFlags::default_compression):
return Z_DEFAULT_COMPRESSION;
default:
Assert(false, ExcNotImplemented());
return Z_NO_COMPRESSION;
}
}
/**
* Do a zlib compression followed by a base64 encoding of the given data. The
* result is then written to the given stream.
*/
template <typename T>
void
write_compressed_block(const std::vector<T> & data,
const DataOutBase::VtkFlags &flags,
std::ostream & output_stream)
{
if (data.size() != 0)
{
// allocate a buffer for compressing data and do so
auto compressed_data_length = compressBound(data.size() * sizeof(T));
std::vector<unsigned char> compressed_data(compressed_data_length);
int err =
compress2(&compressed_data[0],
&compressed_data_length,
reinterpret_cast<const Bytef *>(data.data()),
data.size() * sizeof(T),
get_zlib_compression_level(flags.compression_level));
(void)err;
Assert(err == Z_OK, ExcInternalError());
// Discard the unnecessary bytes
compressed_data.resize(compressed_data_length);
// now encode the compression header
const uint32_t compression_header[4] = {
1, /* number of blocks */
static_cast<uint32_t>(data.size() * sizeof(T)), /* size of block */
static_cast<uint32_t>(data.size() *
sizeof(T)), /* size of last block */
static_cast<uint32_t>(
compressed_data_length)}; /* list of compressed sizes of blocks */
const auto header_start =
reinterpret_cast<const unsigned char *>(&compression_header[0]);
output_stream << Utilities::encode_base64(
{header_start, header_start + 4 * sizeof(uint32_t)})
<< Utilities::encode_base64(compressed_data);
}
}
#endif
} // namespace
// some declarations of functions and locally used classes
namespace DataOutBase
{
namespace
{
/**
* Class holding the data of one cell of a patch in two space dimensions for
* output. It is the projection of a cell in three-dimensional space (two
* coordinates, one height value) to the direction of sight.
*/
class SvgCell
{
public:
// Center of the cell (three-dimensional)
Point<3> center;
/**
* Vector of vertices of this cell (three-dimensional)
*/
Point<3> vertices[4];
/**
* Depth into the picture, which is defined as the distance from an
* observer at an the origin in direction of the line of sight.
*/
float depth;
/**
* Vector of vertices of this cell (projected, two-dimensional).
*/
Point<2> projected_vertices[4];
// Center of the cell (projected, two-dimensional)
Point<2> projected_center;
/**
* Comparison operator for sorting.
*/
bool
operator<(const SvgCell &) const;
};
bool
SvgCell::operator<(const SvgCell &e) const
{
// note the "wrong" order in which we sort the elements
return depth > e.depth;
}
/**
* Class holding the data of one cell of a patch in two space dimensions for
* output. It is the projection of a cell in three-dimensional space (two
* coordinates, one height value) to the direction of sight.
*/
class EpsCell2d
{
public:
/**
* Vector of vertices of this cell.
*/
Point<2> vertices[4];
/**
* Data value from which the actual colors will be computed by the
* colorization function stated in the <tt>EpsFlags</tt> class.
*/
float color_value;
/**
* Depth into the picture, which is defined as the distance from an
* observer at an the origin in direction of the line of sight.
*/
float depth;
/**
* Comparison operator for sorting.
*/
bool
operator<(const EpsCell2d &) const;
};
bool
EpsCell2d::operator<(const EpsCell2d &e) const
{
// note the "wrong" order in which we sort the elements
return depth > e.depth;
}
/**
* This is a helper function for the write_gmv() function. There, the data
* in the patches needs to be copied around as output is one variable
* globally at a time, rather than all data on each vertex at a time. This
* copying around can be done detached from the main thread, and is thus
* moved into this separate function.
*
* Note that because of the similarity of the formats, this function is also
* used by the Vtk and Tecplot output functions.
*/
template <int dim, int spacedim, typename Number = double>
void
write_gmv_reorder_data_vectors(
const std::vector<Patch<dim, spacedim>> &patches,
Table<2, Number> & data_vectors)
{
// If there is nothing to write, just return
if (patches.size() == 0)
return;
// unlike in the main function, we don't have here the data_names field,
// so we initialize it with the number of data sets in the first patch.
// the equivalence of these two definitions is checked in the main
// function.
// we have to take care, however, whether the points are appended to the
// end of the patch.data table
const unsigned int n_data_sets = patches[0].points_are_available ?
(patches[0].data.n_rows() - spacedim) :
patches[0].data.n_rows();
Assert(data_vectors.size()[0] == n_data_sets, ExcInternalError());
// loop over all patches
unsigned int next_value = 0;
for (const auto &patch : patches)
{
const unsigned int n_subdivisions = patch.n_subdivisions;
(void)n_subdivisions;
Assert((patch.data.n_rows() == n_data_sets &&
!patch.points_are_available) ||
(patch.data.n_rows() == n_data_sets + spacedim &&
patch.points_are_available),
ExcDimensionMismatch(patch.points_are_available ?
(n_data_sets + spacedim) :
n_data_sets,
patch.data.n_rows()));
Assert((n_data_sets == 0) ||
(patch.data.n_cols() ==
Utilities::fixed_power<dim>(n_subdivisions + 1)),
ExcInvalidDatasetSize(patch.data.n_cols(),
n_subdivisions + 1));
for (unsigned int i = 0; i < patch.data.n_cols(); ++i, ++next_value)
for (unsigned int data_set = 0; data_set < n_data_sets; ++data_set)
data_vectors[data_set][next_value] = patch.data(data_set, i);
}
for (unsigned int data_set = 0; data_set < n_data_sets; ++data_set)
Assert(data_vectors[data_set].size() == next_value, ExcInternalError());
}
} // namespace
DataOutFilter::DataOutFilter()
: flags(false, true)
, node_dim(numbers::invalid_unsigned_int)
, vertices_per_cell(numbers::invalid_unsigned_int)
{}
DataOutFilter::DataOutFilter(const DataOutBase::DataOutFilterFlags &flags)
: flags(flags)
, node_dim(numbers::invalid_unsigned_int)
, vertices_per_cell(numbers::invalid_unsigned_int)
{}
template <int dim>
void
DataOutFilter::write_point(const unsigned int index, const Point<dim> &p)
{
node_dim = dim;
Point<3> int_pt;
for (unsigned int d = 0; d < dim; ++d)
int_pt(d) = p(d);
const Map3DPoint::const_iterator it = existing_points.find(int_pt);
unsigned int internal_ind;
// If the point isn't in the set, or we're not filtering duplicate points,
// add it
if (it == existing_points.end() || !flags.filter_duplicate_vertices)
{
internal_ind = existing_points.size();
existing_points.insert(std::make_pair(int_pt, internal_ind));
}
else
{
internal_ind = it->second;
}
// Now add the index to the list of filtered points
filtered_points[index] = internal_ind;
}
void
DataOutFilter::internal_add_cell(const unsigned int cell_index,
const unsigned int pt_index)
{
filtered_cells[cell_index] = filtered_points[pt_index];
}
void
DataOutFilter::fill_node_data(std::vector<double> &node_data) const
{
node_data.resize(existing_points.size() * node_dim);
for (const auto &existing_point : existing_points)
{
for (unsigned int d = 0; d < node_dim; ++d)
node_data[node_dim * existing_point.second + d] =
existing_point.first(d);
}
}
void
DataOutFilter::fill_cell_data(const unsigned int local_node_offset,
std::vector<unsigned int> &cell_data) const
{
cell_data.resize(filtered_cells.size());
for (const auto &filtered_cell : filtered_cells)
{
cell_data[filtered_cell.first] =
filtered_cell.second + local_node_offset;
}
}
std::string
DataOutFilter::get_data_set_name(const unsigned int set_num) const
{
return data_set_names.at(set_num);
}
unsigned int
DataOutFilter::get_data_set_dim(const unsigned int set_num) const
{
return data_set_dims.at(set_num);
}
const double *
DataOutFilter::get_data_set(const unsigned int set_num) const
{
return data_sets[set_num].data();
}
unsigned int
DataOutFilter::n_nodes() const
{
return existing_points.size();
}
unsigned int
DataOutFilter::n_cells() const
{
return filtered_cells.size() / vertices_per_cell;
}
unsigned int
DataOutFilter::n_data_sets() const
{
return data_set_names.size();
}
void
DataOutFilter::flush_points()
{}
void
DataOutFilter::flush_cells()
{}
template <int dim>
void
DataOutFilter::write_cell(const unsigned int index,
const unsigned int start,
const unsigned int d1,
const unsigned int d2,
const unsigned int d3)
{
const unsigned int base_entry =
index * GeometryInfo<dim>::vertices_per_cell;
vertices_per_cell = GeometryInfo<dim>::vertices_per_cell;
internal_add_cell(base_entry + 0, start);
if (dim >= 1)
{
internal_add_cell(base_entry + 1, start + d1);
if (dim >= 2)
{
internal_add_cell(base_entry + 2, start + d2 + d1);
internal_add_cell(base_entry + 3, start + d2);
if (dim >= 3)
{
internal_add_cell(base_entry + 4, start + d3);
internal_add_cell(base_entry + 5, start + d3 + d1);
internal_add_cell(base_entry + 6, start + d3 + d2 + d1);
internal_add_cell(base_entry + 7, start + d3 + d2);
}
}
}
}
void
DataOutFilter::write_data_set(const std::string & name,
const unsigned int dimension,
const unsigned int set_num,
const Table<2, double> &data_vectors)
{
unsigned int new_dim;
// HDF5/XDMF output only supports 1D or 3D output, so force rearrangement if
// needed
if (flags.xdmf_hdf5_output && dimension != 1)
new_dim = 3;
else
new_dim = dimension;
// Record the data set name, dimension, and allocate space for it
data_set_names.push_back(name);
data_set_dims.push_back(new_dim);
data_sets.emplace_back(new_dim * existing_points.size());
// TODO: averaging, min/max, etc for merged vertices
for (unsigned int i = 0; i < filtered_points.size(); ++i)
{
const unsigned int r = filtered_points[i];
for (unsigned int d = 0; d < new_dim; ++d)
{
if (d < dimension)
data_sets.back()[r * new_dim + d] = data_vectors(set_num + d, i);
else
data_sets.back()[r * new_dim + d] = 0;
}
}
}
} // namespace DataOutBase
//----------------------------------------------------------------------//
// Auxiliary data
//----------------------------------------------------------------------//
namespace
{
const char *gmv_cell_type[4] = {"", "line 2", "quad 4", "hex 8"};
const char *ucd_cell_type[4] = {"pt", "line", "quad", "hex"};
const char *tecplot_cell_type[4] = {"", "lineseg", "quadrilateral", "brick"};
#ifdef DEAL_II_HAVE_TECPLOT
const unsigned int tecplot_binary_cell_type[4] = {0, 0, 1, 3};
#endif
// NOTE: The dimension of the array is chosen to 5 to allow the choice
// DataOutBase<deal_II_dimension,deal_II_dimension+1> in general Wolfgang
// supposed that we don't need it in general, but however this choice avoids a
// -Warray-bounds check warning
const unsigned int vtk_cell_type[5] = {1, // VTK_VERTEX
3, // VTK_LINE
9, // VTK_QUAD
12, // VTK_HEXAHEDRON
static_cast<unsigned int>(-1)};
// VTK cell ids defined in vtk_cell_type are used for linear cells,
// the ones defined below are used when Lagrange cells are written.
const unsigned int vtk_lagrange_cell_type[5] = {
1, // VTK_VERTEX
68, // VTK_LAGRANGE_CURVE
70, // VTK_LAGRANGE_QUADRILATERAL
72, // VTK_LAGRANGE_HEXAHEDRON
static_cast<unsigned int>(-1)};
//----------------------------------------------------------------------//
// Auxiliary functions
//----------------------------------------------------------------------//
// For a given patch, compute the node interpolating the corner nodes linearly
// at the point (xstep, ystep, zstep)*1./n_subdivisions. If the points are
// saved in the patch.data member, return the saved point instead
template <int dim, int spacedim>
inline Point<spacedim>
compute_node(const DataOutBase::Patch<dim, spacedim> &patch,
const unsigned int xstep,
const unsigned int ystep,
const unsigned int zstep,
const unsigned int n_subdivisions)
{
Point<spacedim> node;
if (patch.points_are_available)
{
unsigned int point_no = 0;
switch (dim)
{
case 3:
AssertIndexRange(zstep, n_subdivisions + 1);
point_no += (n_subdivisions + 1) * (n_subdivisions + 1) * zstep;
DEAL_II_FALLTHROUGH;
case 2:
AssertIndexRange(ystep, n_subdivisions + 1);
point_no += (n_subdivisions + 1) * ystep;
DEAL_II_FALLTHROUGH;
case 1:
AssertIndexRange(xstep, n_subdivisions + 1);
point_no += xstep;
DEAL_II_FALLTHROUGH;
case 0:
// break here for dim<=3
break;
default:
Assert(false, ExcNotImplemented());
}
for (unsigned int d = 0; d < spacedim; ++d)
node[d] = patch.data(patch.data.size(0) - spacedim + d, point_no);
}
else
{
if (dim == 0)
node = patch.vertices[0];
else
{
// perform a dim-linear interpolation
const double stepsize = 1. / n_subdivisions,
xfrac = xstep * stepsize;
node =
(patch.vertices[1] * xfrac) + (patch.vertices[0] * (1 - xfrac));
if (dim > 1)
{
const double yfrac = ystep * stepsize;
node *= 1 - yfrac;
node += ((patch.vertices[3] * xfrac) +
(patch.vertices[2] * (1 - xfrac))) *
yfrac;
if (dim > 2)
{
const double zfrac = zstep * stepsize;
node *= (1 - zfrac);
node += (((patch.vertices[5] * xfrac) +
(patch.vertices[4] * (1 - xfrac))) *
(1 - yfrac) +
((patch.vertices[7] * xfrac) +
(patch.vertices[6] * (1 - xfrac))) *
yfrac) *
zfrac;
}
}
}
}
return node;
}
/**
* Given (i,j,k) coordinates within the Lagrange quadrilateral, return an
* offset into the local connectivity array.
*
* Modified from
* https://github.com/Kitware/VTK/blob/265ca48a/Common/DataModel/vtkLagrangeQuadrilateral.cxx#L558
*/
int
vtk_point_index_from_ijk(const unsigned i,
const unsigned j,
const unsigned,
const std::array<unsigned, 2> &order)
{
const bool ibdy = (i == 0 || i == order[0]);
const bool jbdy = (j == 0 || j == order[1]);
// How many boundaries do we lie on at once?
const int nbdy = (ibdy ? 1 : 0) + (jbdy ? 1 : 0);
if (nbdy == 2) // Vertex DOF
{ // ijk is a corner node. Return the proper index (somewhere in [0,3]):
return (i ? (j ? 2 : 1) : (j ? 3 : 0));
}
int offset = 4;
if (nbdy == 1) // Edge DOF
{
if (!ibdy)
{ // On i axis
return (i - 1) + (j ? order[0] - 1 + order[1] - 1 : 0) + offset;
}
if (!jbdy)
{ // On j axis
return (j - 1) +
(i ? order[0] - 1 : 2 * (order[0] - 1) + order[1] - 1) +
offset;
}
}
offset += 2 * (order[0] - 1 + order[1] - 1);
// nbdy == 0: Face DOF
return offset + (i - 1) + (order[0] - 1) * ((j - 1));
}
/**
* Given (i,j,k) coordinates within the Lagrange hexahedron, return an
* offset into the local connectivity array.
*
* Modified from
* https://github.com/Kitware/VTK/blob/265ca48a/Common/DataModel/vtkLagrangeHexahedron.cxx#L734
*/
int
vtk_point_index_from_ijk(const unsigned i,
const unsigned j,
const unsigned k,
const std::array<unsigned, 3> &order)
{
const bool ibdy = (i == 0 || i == order[0]);
const bool jbdy = (j == 0 || j == order[1]);
const bool kbdy = (k == 0 || k == order[2]);
// How many boundaries do we lie on at once?
const int nbdy = (ibdy ? 1 : 0) + (jbdy ? 1 : 0) + (kbdy ? 1 : 0);
if (nbdy == 3) // Vertex DOF
{ // ijk is a corner node. Return the proper index (somewhere in [0,7]):
return (i ? (j ? 2 : 1) : (j ? 3 : 0)) + (k ? 4 : 0);
}
int offset = 8;
if (nbdy == 2) // Edge DOF
{
if (!ibdy)
{ // On i axis
return (i - 1) + (j ? order[0] - 1 + order[1] - 1 : 0) +
(k ? 2 * (order[0] - 1 + order[1] - 1) : 0) + offset;
}
if (!jbdy)
{ // On j axis
return (j - 1) +
(i ? order[0] - 1 : 2 * (order[0] - 1) + order[1] - 1) +
(k ? 2 * (order[0] - 1 + order[1] - 1) : 0) + offset;
}
// !kbdy, On k axis
offset += 4 * (order[0] - 1) + 4 * (order[1] - 1);
return (k - 1) + (order[2] - 1) * (i ? (j ? 3 : 1) : (j ? 2 : 0)) +
offset;
}
offset += 4 * (order[0] - 1 + order[1] - 1 + order[2] - 1);
if (nbdy == 1) // Face DOF
{
if (ibdy) // On i-normal face
{
return (j - 1) + ((order[1] - 1) * (k - 1)) +
(i ? (order[1] - 1) * (order[2] - 1) : 0) + offset;
}
offset += 2 * (order[1] - 1) * (order[2] - 1);
if (jbdy) // On j-normal face
{
return (i - 1) + ((order[0] - 1) * (k - 1)) +
(j ? (order[2] - 1) * (order[0] - 1) : 0) + offset;
}
offset += 2 * (order[2] - 1) * (order[0] - 1);
// kbdy, On k-normal face
return (i - 1) + ((order[0] - 1) * (j - 1)) +
(k ? (order[0] - 1) * (order[1] - 1) : 0) + offset;
}
// nbdy == 0: Body DOF
offset +=
2 * ((order[1] - 1) * (order[2] - 1) + (order[2] - 1) * (order[0] - 1) +
(order[0] - 1) * (order[1] - 1));
return offset + (i - 1) +
(order[0] - 1) * ((j - 1) + (order[1] - 1) * ((k - 1)));
}
int
vtk_point_index_from_ijk(const unsigned,
const unsigned,
const unsigned,
const std::array<unsigned, 0> &)
{
Assert(false, ExcNotImplemented());
return 0;
}
int
vtk_point_index_from_ijk(const unsigned,
const unsigned,
const unsigned,
const std::array<unsigned, 1> &)
{
Assert(false, ExcNotImplemented());
return 0;
}
template <int dim, int spacedim>
static void
compute_sizes(const std::vector<DataOutBase::Patch<dim, spacedim>> &patches,
unsigned int & n_nodes,
unsigned int & n_cells)
{
n_nodes = 0;
n_cells = 0;
for (const auto &patch : patches)
{
n_nodes += Utilities::fixed_power<dim>(patch.n_subdivisions + 1);
n_cells += Utilities::fixed_power<dim>(patch.n_subdivisions);
}
}
/**
* Class describing common functionality between different output streams.
*
* @ingroup output
*/
template <typename FlagsType>
class StreamBase
{
public:
/*
* Constructor. Stores a reference to the output stream for immediate use.
*/
StreamBase(std::ostream &stream, const FlagsType &flags)
: selected_component(numbers::invalid_unsigned_int)
, stream(stream)
, flags(flags)
{}
/**
* Output operator for points. All inheriting classes should implement this
* function.
*/
template <int dim>
void
write_point(const unsigned int, const Point<dim> &)
{
Assert(false,
ExcMessage("The derived class you are using needs to "
"reimplement this function if you want to call "
"it."));
}
/**
* Do whatever is necessary to terminate the list of points. The default
* implementation does nothing; derived classes that do not require any
* action do not need to reimplement this.
*/
void
flush_points()
{}
/**
* Write dim-dimensional cell with first vertex at number start and further
* vertices offset by the specified values. Values not needed are ignored.
* All inheriting classes should implement this function.
*/
template <int dim>
void
write_cell(const unsigned int /*index*/,
const unsigned int /*start*/,
const unsigned int /*x_offset*/,
const unsigned int /*y_offset*/,
const unsigned int /*z_offset*/)
{
Assert(false,
ExcMessage("The derived class you are using needs to "
"reimplement this function if you want to call "
"it."));
}
/**
* Do whatever is necessary to terminate the list of cells. This function is
* usually only reimplemented if deal.II is compiled with zlib. The default
* implementation does nothing; derived classes that do not require any
* action do not need to reimplement this.
*/
void
flush_cells()
{}
/**
* Forwarding of an output stream. This function is usually only
* reimplemented if inheriting classes use zlib.
*/
template <typename T>
std::ostream &
operator<<(const T &t)
{
stream << t;
return stream;
}
/**
* Since the GMV and Tecplot formats read the x, y and z coordinates in
* separate fields, we enable write() to output only a single selected
* component at once and do this dim times for the whole set of nodes. This
* integer can be used to select the component written.
*/
unsigned int selected_component;
protected:
/**
* The ostream to use. Since the life span of these objects is small, we use
* a very simple storage technique.
*/
std::ostream &stream;
/**
* The flags controlling the output.
*/
const FlagsType flags;
};
/**
* Class for writing basic entities in @ref SoftwareOpenDX format, depending on the flags.
*/
class DXStream : public StreamBase<DataOutBase::DXFlags>
{
public:
DXStream(std::ostream &stream, const DataOutBase::DXFlags &flags);
template <int dim>
void
write_point(const unsigned int index, const Point<dim> &);
/**
* The order of vertices for these cells in different dimensions is
* <ol>
* <li> [0,1]
* <li> [0,2,1,3]
* <li> [0,4,2,6,1,5,3,7]
* </ol>
*/
template <int dim>
void
write_cell(const unsigned int index,
const unsigned int start,
const unsigned int x_offset,
const unsigned int y_offset,
const unsigned int z_offset);
/**
* Write a complete set of data for a single node.
*
* The index given as first argument indicates the number of a data set, as
* some output formats require this number to be printed.
*/
template <typename data>
void
write_dataset(const unsigned int index, const std::vector<data> &values);
};
/**
* Class for writing basic entities in @ref SoftwareGMV format, depending on the flags.
*/
class GmvStream : public StreamBase<DataOutBase::GmvFlags>
{
public:
GmvStream(std::ostream &stream, const DataOutBase::GmvFlags &flags);
template <int dim>
void
write_point(const unsigned int index, const Point<dim> &);
/**
* The order of vertices for these cells in different dimensions is
* <ol>
* <li> [0,1]
* <li> [0,1,3,2]
* <li> [0,1,3,2,4,5,7,6]
* </ol>
*/
template <int dim>
void
write_cell(const unsigned int index,
const unsigned int start,
const unsigned int x_offset,
const unsigned int y_offset,
const unsigned int z_offset);
};
/**
* Class for writing basic entities in @ref SoftwareTecplot format, depending on the flags.
*/
class TecplotStream : public StreamBase<DataOutBase::TecplotFlags>
{
public:
TecplotStream(std::ostream &stream, const DataOutBase::TecplotFlags &flags);
template <int dim>
void
write_point(const unsigned int index, const Point<dim> &);
/**
* The order of vertices for these cells in different dimensions is
* <ol>
* <li> [0,1]
* <li> [0,1,3,2]
* <li> [0,1,3,2,4,5,7,6]
* </ol>
*/
template <int dim>
void
write_cell(const unsigned int index,
const unsigned int start,
const unsigned int x_offset,
const unsigned int y_offset,
const unsigned int z_offset);
};
/**
* Class for writing basic entities in UCD format for @ref SoftwareAVS, depending on the flags.
*/
class UcdStream : public StreamBase<DataOutBase::UcdFlags>
{
public:
UcdStream(std::ostream &stream, const DataOutBase::UcdFlags &flags);