/usr/include/deal.II/numerics/data_out.h is in libdeal.ii-dev 6.3.1-1.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 | //---------------------------------------------------------------------------
// $Id: data_out.h 20602 2010-02-13 17:44:17Z bangerth $
// Version: $Name$
//
// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 by the deal.II authors
//
// This file is subject to QPL and may not be distributed
// without copyright and license information. Please refer
// to the file deal.II/doc/license.html for the text and
// further information on this license.
//
//---------------------------------------------------------------------------
#ifndef __deal2__data_out_h
#define __deal2__data_out_h
#include <base/config.h>
#include <base/smartpointer.h>
#include <base/data_out_base.h>
#include <dofs/dof_handler.h>
#include <fe/mapping.h>
#include <hp/q_collection.h>
#include <hp/fe_collection.h>
#include <hp/mapping_collection.h>
#include <hp/fe_values.h>
#include <numerics/data_postprocessor.h>
#include <numerics/data_component_interpretation.h>
#include <base/std_cxx1x/shared_ptr.h>
DEAL_II_NAMESPACE_OPEN
template <int, int> class FEValuesBase;
namespace internal
{
namespace DataOut
{
/**
* A data structure that holds
* all data needed in one thread
* when building patches in
* parallel. These data
* structures are created
* globally rather than on each
* cell to avoid allocation of
* memory in the threads. This is
* a base class for the
* AdditionalData kind of data
* structure discussed in the
* documentation of the
* WorkStream class.
*
* The
* <code>cell_to_patch_index_map</code>
* is an array that stores for index
* <tt>[i][j]</tt> the number of the
* patch that associated with the cell
* with index @p j on level @p i. This
* information is set up prior to
* generation of the patches, and is
* needed to generate neighborship
* information.
*
* This structure is used by
* several of the DataOut*
* classes, which derived their
* own ParallelData classes from
* it for additional fields.
*/
template <int dim, int spacedim>
struct ParallelDataBase
{
template <class FE>
ParallelDataBase (const unsigned int n_components,
const unsigned int n_datasets,
const unsigned int n_subdivisions,
const unsigned int n_q_points,
const std::vector<unsigned int> &n_postprocessor_outputs,
const FE &finite_elements);
const unsigned int n_components;
const unsigned int n_datasets;
const unsigned int n_subdivisions;
std::vector<double> patch_values;
std::vector<dealii::Vector<double> > patch_values_system;
std::vector<Tensor<1,spacedim> > patch_gradients;
std::vector<std::vector<Tensor<1,spacedim> > > patch_gradients_system;
std::vector<Tensor<2,spacedim> > patch_hessians;
std::vector<std::vector<Tensor<2,spacedim> > > patch_hessians_system;
std::vector<std::vector<dealii::Vector<double> > > postprocessed_values;
const dealii::hp::FECollection<dim,spacedim> fe_collection;
};
/**
* A derived class for use in the
* DataOut class. This is
* a class for the
* AdditionalData kind of data
* structure discussed in the
* documentation of the
* WorkStream context.
*/
template <int dim, int spacedim>
struct ParallelData : public ParallelDataBase<dim,spacedim>
{
template <class FE>
ParallelData (const Quadrature<dim> &quadrature,
const unsigned int n_components,
const unsigned int n_datasets,
const unsigned int n_subdivisions,
const std::vector<unsigned int> &n_postprocessor_outputs,
const Mapping<dim,spacedim> &mapping,
const std::vector<std::vector<unsigned int> > &cell_to_patch_index_map,
const FE &finite_elements,
const UpdateFlags update_flags);
const dealii::hp::QCollection<dim> q_collection;
const dealii::hp::MappingCollection<dim,spacedim> mapping_collection;
dealii::hp::FEValues<dim,spacedim> x_fe_values;
const std::vector<std::vector<unsigned int> > *cell_to_patch_index_map;
};
}
}
//TODO: Most of the documentation of DataOut_DoFData applies to DataOut.
/**
* This is an abstract class which provides the functionality to
* generate patches for output by base classes from data vectors on a
* grid. It allows to store a pointer to a DoFHandler object and one
* or more pointers to node and cell data denoting functions on the
* grid which shall later be written in any of the implemented data
* formats.
*
*
* <h3>User visible interface</h3>
*
* The user visible interface of this class consists of functions which allow
* a user to make a DoFHandler object known to this class and to add data
* vectors which will later be written to a file in some format. Instead of
* pondering about the different functions, an example is probably the best
* way:
* @code
* ...
* ... // compute solution, which contains nodal values
* ...
* ... // compute error_estimator, which contains one value per cell
*
* std::vector<std::string> solution_names;
* solution_names.push_back ("x-displacement");
* solution_names.push_back ("y-displacement");
*
* DataOut<dim> data_out;
* data_out.attach_dof_handler (dof_handler);
* data_out.add_data_vector (solution, solution_names);
* data_out.add_data_vector (error_estimator, "estimated_error");
*
* data_out.build_patches ();
*
* ofstream output_file ("output");
* data_out.write_xxx (output_file);
*
* data_out.clear();
* @endcode
*
* attach_dof_handler() tells this class that all future operations
* are to take place with the DoFHandler object and the triangulation
* it lives on. We then add the solution vector and the error
* estimator; note that they have different dimensions, because the
* solution is a nodal vector, here consisting of two components
* ("x-displacement" and "y-displacement") while the error estimator
* probably is a vector holding cell data. When attaching a data
* vector, you have to give a name to each component of the vector,
* which is done through an object of type <tt>vector<string></tt> as
* second argument; if only one component is in the vector, for
* example if we are adding cell data as in the second case, or if the
* finite element used by the DoFHandler has only one component, then
* you can use the second add_data_vector() function which takes a @p
* string instead of the <tt>vector<string></tt>.
*
* The add_data_vector() functions have additional arguments (with default
* values) that can be used to specify certain transformations. In particular,
* it allows to attach DataPostprocessor arguments to compute derived
* information from a data vector at each quadrature point (for example, the
* Mach number in hypersonic flow can be computed from density and velocities;
* step-29 also shows an example); another piece of information
* specified through arguments with default values is how certain output
* components should be interpreted, i.e. whether each component of the data
* is logically an independent scalar field, or whether some of them together
* form logically a vector-field (see the
* DataComponentInterpretation::DataComponentInterpretation enum, and the @ref
* step_22 "step-22" tutorial program).
*
* It should be noted that this class does not copy the vector given to it through
* the add_data_vector() functions, for memory consumption reasons. It only
* stores a reference to it, so it is in your responsibility to make sure that
* the data vectors exist long enough.
*
* After adding all data vectors, you need to call a function which generates
* the patches for output from the stored data. Derived classes name this
* function build_patches(). Finally, you write() the data in one format or other,
* to a file.
*
* Please note, that in the example above, an object of type DataOut was
* used, i.e. an object of a derived class. This is necessary since this
* class does not provide means to actually generate the patches, only aids to
* store and access data.
*
* Note that the base class of this class, DataOutInterface offers
* several functions to ease programming with run-time determinable
* output formats (i.e. you need not use a fixed format by calling
* DataOutInterface::write_xxx in the above example, but you can
* select it by a run-time parameter without having to write the
* <tt>if () ... else ...</tt> clauses yourself), and also functions
* and classes offering ways to control the appearance of the output
* by setting flags for each output format.
*
*
* <h3>Information for derived classes</h3>
*
* What is actually missing this class is a way to produce the patches
* for output itself, from the stored data and degree of freedom
* information. Since this task is often application dependent it is
* left to derived classes. For example, in many applications, it
* might be wanted to limit the depth of output to a certain number of
* refinement levels and write data from finer cells only in a way
* interpolated to coarser cells, to reduce the amount of
* output. Also, it might be wanted to use different numbers of
* subdivisions on different cells when forming a patch, for example
* to accomplish for different polynomial degrees of the trial space
* on different cells. Also, the output need not necessarily consist
* of a patch for each cell, but might be made up of patches for
* faces, of other things. Take a look at derived classes to what is
* possible in this respect.
*
* For this reason, it is left to a derived class to provide a
* function, named usually build_patches() or the like, which fills
* the #patches array of this class.
*
* Regarding the templates of this class, it needs three values: first
* the space dimension in which the triangulation and the DoF handler
* operate, second the dimension of the objects which the patches
* represent. Although in most cases they are equal, there are also
* classes for which this does not hold, for example if one outputs
* the result of a computation exploiting rotational symmetry in the
* original domain (in which the space dimension of the output would
* be one higher than that of the DoF handler, see the
* DataOut_Rotation() class), or one might conceive that one could
* write a class that only outputs the solution on a cut through the
* domain, in which case the space dimension of the output is less
* than that of the DoF handler. The last template argument denotes
* the dimension of the space into which the patches are embedded;
* usually, this dimension is the same as the dimensio of the patches
* themselves (which is also the default value of the template
* parameter), but there might be cases where this is not so. For
* example, in the DataOut_Faces() class, patches are generated
* from faces of the triangulation. Thus, the dimension of the patch
* is one less than the dimension of the embedding space, which is, in
* this case, equal to the dimension of the triangulation and DoF
* handler. However, for the cut through the domain mentioned above,
* if the cut is a straight one, then the cut can be embedded into a
* space of one dimension lower than the dimension of the
* triangulation, so that the last template parameter has the same
* value as the second one.
*
* @ingroup output
* @author Wolfgang Bangerth, 1999
*/
template <class DH, int patch_dim, int patch_space_dim=patch_dim>
class DataOut_DoFData : public DataOutInterface<patch_dim,patch_space_dim>
{
public:
/**
* Typedef to the iterator type
* of the dof handler class under
* consideration.
*/
typedef typename DH::cell_iterator cell_iterator;
typedef typename DH::active_cell_iterator active_cell_iterator;
public:
/**
* Type describing what the
* vector given to
* add_data_vector() is: a
* vector that has one entry per
* degree of freedom in a
* DoFHandler object (such
* as solution vectors), or one
* entry per cell in the
* triangulation underlying the
* DoFHandler object (such
* as error per cell data). The
* value #type_automatic tells
* add_data_vector() to find
* out itself (see the
* documentation of
* add_data_vector() for the
* method used).
*/
enum DataVectorType
{
/**
* Data vector entries are
* associated to degrees of freedom
*/
type_dof_data,
/**
* Data vector entries are one per
* grid cell
*/
type_cell_data,
/**
* Find out automatically
*/
type_automatic
};
/**
* Constructor
*/
DataOut_DoFData ();
/**
* Destructor.
*/
virtual ~DataOut_DoFData ();
/**
* Designate a dof handler to be
* used to extract geometry data
* and the mapping between nodes
* and node values.
*/
void attach_dof_handler (const DH &);
/**
* Add a data vector together
* with its name and the physical
* unit (for example meter,
* kelvin, etc). By default,
* "<dimensionless>" is assumed
* for the units.
*
* A pointer to the vector is
* stored, so you have to make
* sure the vector exists at that
* address at least as long as
* you call the <tt>write_*</tt>
* functions.
*
* It is assumed that the vector
* has the same number of
* components as there are
* degrees of freedom in the dof
* handler, in which case it is
* assumed to be a vector storing
* nodal data; or the size may be
* the number of active cells on
* the present grid, in which
* case it is assumed to be a
* cell data vector. As the
* number of degrees of freedom
* and of cells is usually not
* equal, the function can
* determine itself which type of
* vector it is given; however,
* there is one corner case,
* namely if you compute with
* piecewise constant elements
* and have one scalar quantity,
* then there are as many cells
* as there are degrees of
* freedom, but they may be
* ordered differently. In that
* case, you can change the last
* argument of the function from
* its default value
* #type_automatic to either
* #type_dof_data or #type_cell_data,
* depending on what the vector
* represents. Apart from this
* corner case, you can leave the
* argument at its default value
* and let the function determine
* the type of the vector itself.
*
* If it is a vector holding DoF
* data, the names given shall be
* one for each component, if the
* finite element in use is
* composed of several
* subelements. If it is a
* finite element composed of
* only one subelement, then
* there is another function
* following which takes a single
* name instead of a vector of
* names.
*
* The data_component_interpretation
* argument contains information about
* how the individual components of
* output files that consist of more than
* one data set are to be interpreted.
*
* For example, if one has a finite
* element for the Stokes equations in
* 2d, representing components (u,v,p),
* one would like to indicate that the
* first two, u and v, represent a
* logical vector so that later on when
* we generate graphical output we can
* hand them off to a visualization
* program that will automatically know
* to render them as a vector field,
* rather than as two separate and
* independent scalar fields.
*
* The default value of this argument
* (i.e. an empty vector) corresponds is
* equivalent to a vector of values
* DataComponentInterpretation::component_is_scalar,
* indicating that all output components
* are independent scalar
* fields. However, if the given data
* vector represents logical vectors, you
* may pass a vector that contains values
* DataComponentInterpretation::component_is_part_of_vector. In
* the example above, one would pass in a
* vector with components
* (DataComponentInterpretation::component_is_part_of_vector,
* DataComponentInterpretation::component_is_part_of_vector,
* DataComponentInterpretation::component_is_scalar)
* for (u,v,p).
*
* The names of a data vector
* shall only contain characters
* which are letters, underscore
* and a few other ones. Refer to
* the ExcInvalidCharacter
* exception declared in this
* class to see which characters
* are valid and which are not.
*
* The actual type for the template
* argument may be any vector type from
* which FEValues can extract values
* on a cell using the
* FEValuesBase::get_function_values() function.
*/
template <class VECTOR>
void add_data_vector (const VECTOR &data,
const std::vector<std::string> &names,
const DataVectorType type = type_automatic,
const std::vector<DataComponentInterpretation::DataComponentInterpretation> &data_component_interpretation
= std::vector<DataComponentInterpretation::DataComponentInterpretation>());
/**
* This function is an abbreviation to
* the above one (see there for a
* discussion of the various arguments),
* intended for use with finite elements
* that are not composed of
* subelements. In this case, only one
* name per data vector needs to be
* given, which is what this function
* takes. It simply relays its arguments
* after a conversion of the @p name to a
* vector of strings, to the other
* add_data_vector() function above.
*
* If @p data is a vector with
* multiple components this
* function will generate
* distinct names for all
* components by appending an
* underscore and the number of
* each component to @p name
*
* The actual type for the template
* argument may be any vector type from
* which FEValues can extract values
* on a cell using the
* FEValuesBase::get_function_values() function.
*/
template <class VECTOR>
void add_data_vector (const VECTOR &data,
const std::string &name,
const DataVectorType type = type_automatic,
const std::vector<DataComponentInterpretation::DataComponentInterpretation> &data_component_interpretation
= std::vector<DataComponentInterpretation::DataComponentInterpretation>());
/**
* This function is an alternative to the
* above ones, allowing the output of
* derived quantities instead of the given
* data. This converison has to be done in
* a class derived from DataPostprocessor.
*
* The names for these derived quantities
* are provided by the @p
* data_postprocessor argument. Likewise,
* the data_component_interpretation
* argument of the other
* add_data_vector() functions is
* provided by the data_postprocessor
* argument. As only data of type @p
* type_dof_data can be transformed, this
* type is also known implicitly and does
* not have to be given.
*
* The actual type for the template
* argument may be any vector type from
* which FEValues can extract values
* on a cell using the
* FEValuesBase::get_function_values() function.
*/
template <class VECTOR>
void add_data_vector (const VECTOR &data,
const DataPostprocessor<DH::space_dimension> &data_postprocessor);
/**
* Release the pointers to the
* data vectors. This allows
* output of a new set of vectors
* without supplying the DoF
* handler again. Therefore, the
* DataOut object can be used
* in an algebraic context. Note
* that besides the data vectors
* also the patches already
* computed are deleted.
*/
void clear_data_vectors ();
/**
* Release pointers to all input
* data elements, i.e. pointers
* to data vectors and to the DoF
* handler object. This function
* may be useful when you have
* called the @p build_patches
* function of derived class,
* since then the patches are
* built and the input data is no
* more needed, nor is there a
* need to reference it. You can
* then output the patches
* detached from the main thread
* and need not make sure anymore
* that the DoF handler object
* and vectors must not be
* deleted before the output
* thread is finished.
*/
void clear_input_data_references ();
/**
* This function can be used to
* merge the patches that were
* created using the
* @p build_patches function of
* the object given as argument
* into the list of patches
* created by this object. This
* is sometimes handy if one has,
* for example, a domain
* decomposition algorithm where
* each block is represented by a
* DoFHandler of its own,
* but one wants to output the
* solution on all the blocks at
* the same time.
*
* For this to work, the given
* argument and this object need
* to have the same number of
* output vectors, and they need
* to use the same number of
* subdivisions per patch. The
* output will probably look
* rather funny if patches in
* both objects overlap in space.
*
* If you call
* build_patches() for this
* object after merging in
* patches, the previous state is
* overwritten, and the merged-in
* patches are lost.
*
* The second parameter allows to
* shift each node of the patches
* in the object passed in in the
* first parameter by a certain
* amount. This is sometimes
* useful to generate "exploded"
* views of a collection of
* blocks.
*
* This function will fail if
* either this or the other
* object did not yet set up any
* patches.
*/
template <class DH2>
void merge_patches (const DataOut_DoFData<DH2,patch_dim,patch_space_dim> &source,
const Point<patch_space_dim> &shift = Point<patch_space_dim>());
/**
* Release the pointers to the
* data vectors and the DoF
* handler. You have to set all
* data entries again using the
* add_data_vector()
* function. The pointer to the
* dof handler is cleared as
* well, along with all other
* data. In effect, this function
* resets everything to a virgin
* state.
*/
virtual void clear ();
/**
* Determine an estimate for the
* memory consumption (in bytes)
* of this object.
*/
unsigned int memory_consumption () const;
/**
* Exception
*/
DeclException0 (ExcNoDoFHandlerSelected);
/**
* Exception
*/
DeclException0 (ExcDataPostprocessingIsNotPossibleForCellData);
/**
* Exception
*/
DeclException3 (ExcInvalidVectorSize,
int, int, int,
<< "The vector has size " << arg1
<< " but the DoFHandler objects says there are " << arg2
<< " degrees of freedom and there are " << arg3
<< " active cells.");
/**
* Exception
*/
DeclException2 (ExcInvalidCharacter,
std::string, size_t,
<< "Please use only the characters [a-zA-Z0-9_<>()] for" << std::endl
<< "description strings since some graphics formats will only accept these."
<< std::endl
<< "The string you gave was <" << arg1
<< ">, the invalid character is <" << arg1[arg2]
<< ">." << std::endl);
/**
* Exception
*/
DeclException0 (ExcOldDataStillPresent);
/**
* Exception
*/
DeclException2 (ExcInvalidNumberOfNames,
int, int,
<< "You have to give one name per component in your "
<< "data vector. The number you gave was " << arg1
<< ", but the number of components is " << arg2);
/**
* Exception
*/
DeclException0 (ExcNoPatches);
/**
* Exception
*/
DeclException0 (ExcIncompatibleDatasetNames);
/**
* Exception
*/
DeclException0 (ExcIncompatiblePatchLists);
DeclException2 (ExcInvalidVectorDeclaration,
int, std::string,
<< "When declaring that a number of components in a data\n"
<< "set to be output logically form a vector instead of\n"
<< "simply a set of scalar fields, you need to specify\n"
<< "this for all relevant components. Furthermore,\n"
<< "vectors must always consist of exactly <dim>\n"
<< "components. However, the vector component at\n"
<< "position " << arg1 << " with name <" << arg2
<< "> does not satisfy these conditions.");
protected:
/**
* For each vector that has been added
* through the add_data_vector()
* functions, we need to keep track of a
* pointer to it, and allow data
* extraction from it when we generate
* patches. Unfortunately, we need to do
* this for a number of different vector
* types. Fortunately, they all have the
* same interface. So the way we go is to
* have a base class that provides the
* functions to access the vector's
* information, and to have a derived
* template class that can be
* instantiated for each vector
* type. Since the vectors all have the
* same interface, this is no big
* problem, as they can all use the same
* general templatized code.
*
* @author Wolfgang Bangerth, 2004
*/
class DataEntryBase
{
public:
/**
* Constructor. Give a list of names
* for the individual components of
* the vector and their
* interpretation as scalar or vector
* data. This constructor assumes
* that no postprocessor is going to
* be used.
*/
DataEntryBase (const std::vector<std::string> &names,
const std::vector<DataComponentInterpretation::DataComponentInterpretation> &data_component_interpretation);
/**
* Constructor when a data
* postprocessor is going to be
* used. In that case, the names and
* vector declarations are going to
* be aquired from the postprocessor.
*/
DataEntryBase (const DataPostprocessor<DH::space_dimension> *data_postprocessor);
/**
* Destructor made virtual.
*/
virtual ~DataEntryBase ();
/**
* Assuming that the stored vector is
* a cell vector, extract the given
* element from it.
*/
virtual
double
get_cell_data_value (const unsigned int cell_number) const = 0;
/**
* Given a FEValuesBase object,
* extract the values on the present
* cell from the vector we actually
* store.
*/
virtual
void
get_function_values (const FEValuesBase<DH::dimension,DH::space_dimension> &fe_patch_values,
std::vector<double> &patch_values) const = 0;
/**
* Given a FEValuesBase object,
* extract the values on the present
* cell from the vector we actually
* store. This function does the same
* as the one above but for
* vector-valued finite elements.
*/
virtual
void
get_function_values (const FEValuesBase<DH::dimension,DH::space_dimension> &fe_patch_values,
std::vector<Vector<double> > &patch_values_system) const = 0;
/**
* Given a FEValuesBase object,
* extract the gradients on the present
* cell from the vector we actually
* store.
*/
virtual
void
get_function_gradients (const FEValuesBase<DH::dimension,DH::space_dimension> &fe_patch_values,
std::vector<Tensor<1,DH::space_dimension> > &patch_gradients) const = 0;
/**
* Given a FEValuesBase object,
* extract the gradients on the present
* cell from the vector we actually
* store. This function does the same
* as the one above but for
* vector-valued finite elements.
*/
virtual
void
get_function_gradients (const FEValuesBase<DH::dimension,DH::space_dimension> &fe_patch_values,
std::vector<std::vector<Tensor<1,DH::space_dimension> > > &patch_gradients_system) const = 0;
/**
* Given a FEValuesBase object, extract
* the second derivatives on the
* present cell from the vector we
* actually store.
*/
virtual
void
get_function_hessians (const FEValuesBase<DH::dimension,DH::space_dimension> &fe_patch_values,
std::vector<Tensor<2,DH::space_dimension> > &patch_hessians) const = 0;
/**
* Given a FEValuesBase object, extract
* the second derivatives on the
* present cell from the vector we
* actually store. This function does
* the same as the one above but for
* vector-valued finite elements.
*/
virtual
void
get_function_hessians (const FEValuesBase<DH::dimension,DH::space_dimension> &fe_patch_values,
std::vector<std::vector< Tensor<2,DH::space_dimension> > > &patch_hessians_system) const = 0;
/**
* Clear all references to the
* vectors.
*/
virtual void clear () = 0;
/**
* Determine an estimate for
* the memory consumption (in
* bytes) of this object.
*/
virtual unsigned int memory_consumption () const = 0;
/**
* Names of the components of this
* data vector.
*/
const std::vector<std::string> names;
/**
* A vector that for each of the
* n_output_variables variables of
* the current data set indicates
* whether they are scalar fields,
* parts of a vector-field, or any of
* the other supported kinds of data.
*/
const std::vector<DataComponentInterpretation::DataComponentInterpretation>
data_component_interpretation;
/**
* Pointer to a DataPostprocessing
* object which shall be applied to
* this data vector.
*/
SmartPointer<const DataPostprocessor<DH::space_dimension>,DataOut_DoFData<DH,patch_dim,patch_space_dim> > postprocessor;
/**
* Number of output variables this
* dataset provides (either number of
* components in vector valued function
* / data vector or number of computed
* quantities, if DataPostprocessor is
* applied). This variable is
* determined via and thus equivalent
* to <tt>names.size()</tt>.
*/
unsigned int n_output_variables;
};
/**
* Class that stores a pointer to a
* vector of type equal to the template
* argument, and provides the functions
* to extract data from it.
*
* @author Wolfgang Bangerth, 2004
*/
template <typename VectorType>
class DataEntry : public DataEntryBase
{
public:
/**
* Constructor. Give a list of names
* for the individual components of
* the vector and their
* interpretation as scalar or vector
* data. This constructor assumes
* that no postprocessor is going to
* be used.
*/
DataEntry (const VectorType *data,
const std::vector<std::string> &names,
const std::vector<DataComponentInterpretation::DataComponentInterpretation> &data_component_interpretation);
/**
* Constructor when a data
* postprocessor is going to be
* used. In that case, the names and
* vector declarations are going to
* be aquired from the postprocessor.
*/
DataEntry (const VectorType *data,
const DataPostprocessor<DH::space_dimension> *data_postprocessor);
/**
* Assuming that the stored vector is
* a cell vector, extract the given
* element from it.
*/
virtual
double
get_cell_data_value (const unsigned int cell_number) const;
/**
* Given a FEValuesBase object,
* extract the values on the present
* cell from the vector we actually
* store.
*/
virtual
void
get_function_values (const FEValuesBase<DH::dimension,DH::space_dimension> &fe_patch_values,
std::vector<double> &patch_values) const;
/**
* Given a FEValuesBase object,
* extract the values on the present
* cell from the vector we actually
* store. This function does the same
* as the one above but for
* vector-valued finite elements.
*/
virtual
void
get_function_values (const FEValuesBase<DH::dimension,DH::space_dimension> &fe_patch_values,
std::vector<Vector<double> > &patch_values_system) const;
/**
* Given a FEValuesBase object,
* extract the gradients on the present
* cell from the vector we actually
* store.
*/
virtual
void
get_function_gradients (const FEValuesBase<DH::dimension,DH::space_dimension> &fe_patch_values,
std::vector<Tensor<1,DH::space_dimension> > &patch_gradients) const;
/**
* Given a FEValuesBase object,
* extract the gradients on the present
* cell from the vector we actually
* store. This function does the same
* as the one above but for
* vector-valued finite elements.
*/
virtual
void
get_function_gradients (const FEValuesBase<DH::dimension,DH::space_dimension> &fe_patch_values,
std::vector<std::vector<Tensor<1,DH::space_dimension> > > &patch_gradients_system) const;
/**
* Given a FEValuesBase object, extract
* the second derivatives on the
* present cell from the vector we
* actually store.
*/
virtual
void
get_function_hessians (const FEValuesBase<DH::dimension,DH::space_dimension> &fe_patch_values,
std::vector<Tensor<2,DH::space_dimension> > &patch_hessians) const;
/**
* Given a FEValuesBase object, extract
* the second derivatives on the
* present cell from the vector we
* actually store. This function does
* the same as the one above but for
* vector-valued finite elements.
*/
virtual
void
get_function_hessians (const FEValuesBase<DH::dimension,DH::space_dimension> &fe_patch_values,
std::vector<std::vector< Tensor<2,DH::space_dimension> > > &patch_hessians_system) const;
/**
* Clear all references to the
* vectors.
*/
virtual void clear ();
/**
* Determine an estimate for
* the memory consumption (in
* bytes) of this object.
*/
virtual unsigned int memory_consumption () const;
private:
/**
* Pointer to the data
* vector. Note that
* ownership of the vector
* pointed to remains with
* the caller of this class.
*/
const VectorType *vector;
};
/**
* Abbreviate the somewhat lengthy
* name for the Patch class.
*/
typedef dealii::DataOutBase::Patch<patch_dim,patch_space_dim> Patch;
/**
* Pointer to the dof handler object.
*/
SmartPointer<const DH, DataOut_DoFData<DH,patch_dim,patch_space_dim> > dofs;
/**
* List of data elements with vectors of
* values for each degree of freedom.
*/
std::vector<std_cxx1x::shared_ptr<DataEntryBase> > dof_data;
/**
* List of data elements with vectors of
* values for each cell.
*/
std::vector<std_cxx1x::shared_ptr<DataEntryBase> > cell_data;
/**
* This is a list of patches that is
* created each time build_patches()
* is called. These patches are used
* in the output routines of the base
* classes.
*/
std::vector<Patch> patches;
/**
* Function by which the base
* class's functions get to know
* what patches they shall write
* to a file.
*/
virtual
const std::vector<Patch> & get_patches () const;
/**
* Virtual function through
* which the names of data sets are
* obtained by the output functions
* of the base class.
*/
virtual
std::vector<std::string> get_dataset_names () const;
/**
* Overload of the respective
* DataOutInterface::get_vector_data_ranges()
* function. See there for a more
* extensive documentation.
*/
virtual
std::vector<std_cxx1x::tuple<unsigned int, unsigned int, std::string> >
get_vector_data_ranges () const;
/**
* Make all template siblings
* friends. Needed for the
* merge_patches() function.
*/
template <class, int, int>
friend class DataOut_DoFData;
#ifdef DEAL_II_NESTED_CLASS_FRIEND_BUG
/**
* Make DataEntry a friend. This should
* not be strictly necessary, since
* members are implicitly friends, but in
* this case it seems as if icc needs
* this. Otherwise, it complains that
* DataEntry can't derive from
* DataEntryBase since the latter is a
* private member of DataOut_DoFData.
*
* For whatever weird reason, it is also
* not enough to make just DataEntry a
* friend, but we have to fully qualify
* it for icc, while gcc 2.95 insists on
* the non-qualified version...
*/
# ifdef DEAL_II_NESTED_CLASS_TEMPL_FRIEND_BUG
template <typename>
friend class DataEntry;
# else
template <int N1, template <int> class DH1, int N2, int N3>
template <typename>
friend class DataOut_DoFData<DH1,N2,N3>::DataEntry;
# endif
#endif
};
/**
* This class is an actual implementation of the functionality proposed by
* the DataOut_DoFData class. It offers a function build_patches() that
* generates the patches to be written in some graphics format from the data
* stored in the base class. Most of the interface and an example of its
* use is described in the documentation of the base class.
*
* The only thing this class offers is the function build_patches() which
* loops over all cells of the triangulation stored by the
* attach_dof_handler() function of the base class and convert the data on
* these to actual patches which are the objects that are later output by the
* functions of the base classes. You can give a parameter to the function
* which determines how many subdivisions in each coordinate direction are to
* be performed, i.e. of how many subcells each patch shall consist. Default
* is one, but you may want to choose a higher number for higher order
* elements, so as two for quadratic elements, three for cubic elements three,
* and so on. The purpose of this parameter is because most graphics programs
* do not allow to specify higher order shape functions in the file formats:
* only data at vertices can be plotted and is then shown as a bilinear
* interpolation within the interior of cells. This may be insufficient if you
* have higher order finite elements, and the only way to achieve better
* output is to subdivide each cell of the mesh into several cells for
* graphical output.
*
* Note that after having called build_patches() once, you can call one or
* more of the write() functions of DataOutInterface. You can therefore
* output the same data in more than one format without having to rebuild
* the patches.
*
*
* <h3>User interface information</h3>
*
* The base classes of this class, DataOutBase, DataOutInterface and
* DataOut_DoFData() offer several interfaces of their own. Refer to the
* DataOutBase class's documentation for a discussion of the different
* output formats presently supported, DataOutInterface for ways of
* selecting which format to use upon output at run-time and without
* the need to adapt your program when new formats become available, as
* well as for flags to determine aspects of output. The DataOut_DoFData()
* class's documentation has an example of using nodal data to generate
* output.
*
*
* <h3>Extensions</h3>
*
* By default, this class produces patches for all active cells. Sometimes,
* this is not what you want, maybe because they are simply too many (and too
* small to be seen individually) or because you only want to see a certain
* region of the domain (for example in parallel programs such as the step-18
* example program), or for some other reason.
*
* For this, internally build_patches() does not generate
* the sequence of cells to be converted into patches itself, but relies
* on the two functions first_cell() and next_cell(). By default, they
* return the first active cell, and the next active cell, respectively.
* Since they are @p virtual functions, you may overload them to select other
* cells for output. If cells are not active, interpolated values are taken
* for output instead of the exact values on active cells.
*
* The two functions are not constant, so you may store information within
* your derived class about the last accessed cell. This is useful if the
* information of the last cell which was accessed is not sufficient to
* determine the next one.
*
* There is one caveat, however: if you have cell data (in contrast to nodal,
* or dof, data) such as error indicators, then you must make sure that
* first_cell() and next_cell() only walk over active cells, since cell data
* cannot be interpolated to a coarser cell. If you do have cell data and use
* this pair of functions and they return a non-active cell, then an exception
* will be thrown.
*
* @ingroup output
* @author Wolfgang Bangerth, 1999
*/
template <int dim, class DH=DoFHandler<dim> >
class DataOut : public DataOut_DoFData<DH, DH::dimension, DH::space_dimension>
{
public:
/**
* Typedef to the iterator type
* of the dof handler class under
* consideration.
*/
typedef typename DataOut_DoFData<DH,DH::dimension,DH::space_dimension>::cell_iterator cell_iterator;
typedef typename DataOut_DoFData<DH,DH::dimension,DH::space_dimension>::active_cell_iterator active_cell_iterator;
/**
* Enumeration describing the region of the
* domain in which curved cells shall be
* created.
*/
enum CurvedCellRegion
{
no_curved_cells,
curved_boundary,
curved_inner_cells
};
/**
* This is the central function
* of this class since it builds
* the list of patches to be
* written by the low-level
* functions of the base
* class. See the general
* documentation of this class
* for further information.
*
* The default value <tt>0</tt>
* of <tt>n_subdivisions</tt>
* indicates that the value
* stored in
* DataOutInterface::default_subdivisions
* is to be used.
*/
virtual void build_patches (const unsigned int n_subdivisions = 0);
/**
* Same as above, except that the
* additional first parameter
* defines a mapping that is to
* be used in the generation of
* output. If
* <tt>n_subdivisions>1</tt>, the
* points interior of subdivided
* patches which originate from
* cells at the boundary of the
* domain can be computed using the
* mapping, i.e. a higher order
* mapping leads to a
* representation of a curved
* boundary by using more
* subdivisions. Some mappings like
* MappingQEulerian result in curved cells
* in the interior of the domain. However,
* there is nor easy way to get this
* information from the Mapping. Thus the
* last argument @p curved_region take one
* of three values resulting in no curved
* cells at all, curved cells at the
* boundary (default) or curved cells in
* the whole domain.
*
* Even for non-curved cells the
* mapping argument can be used
* for the Eulerian mappings (see
* class MappingQ1Eulerian) where
* a mapping is used not only to
* determine the position of
* points interior to a cell, but
* also of the vertices. It
* offers an opportunity to watch
* the solution on a deformed
* triangulation on which the
* computation was actually
* carried out, even if the mesh
* is internally stored in its
* undeformed configuration and
* the deformation is only
* tracked by an additional
* vector that holds the
* deformation of each vertex.
*
* @todo The @p mapping argument should be
* replaced by a hp::MappingCollection in
* case of a hp::DoFHandler.
*/
virtual void build_patches (const Mapping<DH::dimension,DH::space_dimension> &mapping,
const unsigned int n_subdivisions = 0,
const CurvedCellRegion curved_region = curved_boundary);
/**
* Return the first cell which we
* want output for. The default
* implementation returns the
* first active cell, but you
* might want to return other
* cells in a derived class.
*/
virtual cell_iterator first_cell ();
/**
* Return the next cell after
* @p cell which we want output
* for. If there are no more
* cells, <tt>#dofs->end()</tt> shall
* be returned.
*
* The default implementation
* returns the next active cell,
* but you might want to return
* other cells in a derived
* class. Note that the default
* implementation assumes that
* the given @p cell is active,
* which is guaranteed as long as
* first_cell() is also used
* from the default
* implementation. Overloading
* only one of the two functions
* might not be a good idea.
*/
virtual cell_iterator next_cell (const cell_iterator &cell);
/**
* Exception
*/
DeclException1 (ExcInvalidNumberOfSubdivisions,
int,
<< "The number of subdivisions per patch, " << arg1
<< ", is not valid.");
private:
/**
* Build one patch. This function
* is called in a WorkStream
* context.
*/
void build_one_patch (const std::pair<cell_iterator, unsigned int> *cell_and_index,
internal::DataOut::ParallelData<DH::dimension, DH::space_dimension> &data,
DataOutBase::Patch<DH::dimension, DH::space_dimension> &patch,
const CurvedCellRegion curved_cell_region);
};
// -------------------- template and inline functions ------------------------
namespace internal
{
namespace DataOut
{
template <int dim, int spacedim>
template <class FE>
ParallelDataBase<dim,spacedim>::
ParallelDataBase (const unsigned int n_components,
const unsigned int n_datasets,
const unsigned int n_subdivisions,
const unsigned int n_q_points,
const std::vector<unsigned int> &n_postprocessor_outputs,
const FE &finite_elements)
:
n_components (n_components),
n_datasets (n_datasets),
n_subdivisions (n_subdivisions),
patch_values (n_q_points),
patch_values_system (n_q_points),
patch_gradients (n_q_points),
patch_gradients_system (n_q_points),
patch_hessians (n_q_points),
patch_hessians_system (n_q_points),
postprocessed_values (n_postprocessor_outputs.size()),
fe_collection (finite_elements)
{
for (unsigned int k=0; k<n_q_points; ++k)
{
patch_values_system[k].reinit(n_components);
patch_gradients_system[k].resize(n_components);
patch_hessians_system[k].resize(n_components);
}
for (unsigned int dataset=0; dataset<n_postprocessor_outputs.size(); ++dataset)
if (n_postprocessor_outputs[dataset] != 0)
postprocessed_values[dataset]
.resize(n_q_points,
dealii::Vector<double>(n_postprocessor_outputs[dataset]));
}
}
}
template <class DH, int patch_dim, int patch_space_dim>
template <class DH2>
void
DataOut_DoFData<DH,patch_dim,patch_space_dim>::
merge_patches (const DataOut_DoFData<DH2,patch_dim,patch_space_dim> &source,
const Point<patch_space_dim> &shift)
{
const std::vector<Patch> source_patches = source.get_patches ();
Assert (patches.size () != 0, ExcNoPatches ());
Assert (source_patches.size () != 0, ExcNoPatches ());
// check equality of component
// names
Assert (get_dataset_names() == source.get_dataset_names(),
ExcIncompatibleDatasetNames());
// make sure patches are compatible. we'll
// assume that if the first respective
// patches are ok that all the other ones
// are ok as well
Assert (patches[0].n_subdivisions == source_patches[0].n_subdivisions,
ExcIncompatiblePatchLists());
Assert (patches[0].data.n_rows() == source_patches[0].data.n_rows(),
ExcIncompatiblePatchLists());
Assert (patches[0].data.n_cols() == source_patches[0].data.n_cols(),
ExcIncompatiblePatchLists());
// check equality of the vector data
// specifications
Assert (get_vector_data_ranges().size() ==
source.get_vector_data_ranges().size(),
ExcMessage ("Both sources need to declare the same components "
"as vectors."));
for (unsigned int i=0; i<get_vector_data_ranges().size(); ++i)
{
Assert (get_vector_data_ranges()[i].template get<0>() ==
source.get_vector_data_ranges()[i].template get<0>(),
ExcMessage ("Both sources need to declare the same components "
"as vectors."));
Assert (get_vector_data_ranges()[i].template get<1>() ==
source.get_vector_data_ranges()[i].template get<1>(),
ExcMessage ("Both sources need to declare the same components "
"as vectors."));
Assert (get_vector_data_ranges()[i].template get<2>() ==
source.get_vector_data_ranges()[i].template get<2>(),
ExcMessage ("Both sources need to declare the same components "
"as vectors."));
}
// merge patches. store old number
// of elements, since we need to
// adjust patch numbers, etc
// afterwards
const unsigned int old_n_patches = patches.size();
patches.insert (patches.end(),
source_patches.begin(),
source_patches.end());
// perform shift, if so desired
if (shift != Point<patch_space_dim>())
for (unsigned int i=old_n_patches; i<patches.size(); ++i)
for (unsigned int v=0; v<GeometryInfo<patch_dim>::vertices_per_cell; ++v)
patches[i].vertices[v] += shift;
// adjust patch numbers
for (unsigned int i=old_n_patches; i<patches.size(); ++i)
patches[i].patch_index += old_n_patches;
// adjust patch neighbors
for (unsigned int i=old_n_patches; i<patches.size(); ++i)
for (unsigned int n=0; n<GeometryInfo<patch_dim>::faces_per_cell; ++n)
if (patches[i].neighbors[n] != Patch::no_neighbor)
patches[i].neighbors[n] += old_n_patches;
}
DEAL_II_NAMESPACE_CLOSE
#endif
|