| 1 |
// ------------------------------------------------------------------------ |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 4 |
// Copyright (C) 2009 - 2025 by the deal.II authors |
| 5 |
// |
| 6 |
// This file is part of the deal.II library. |
| 7 |
// |
| 8 |
// Part of the source code is dual licensed under Apache-2.0 WITH |
| 9 |
// LLVM-exception OR LGPL-2.1-or-later. Detailed license information |
| 10 |
// governing the source code and code contributions can be found in |
| 11 |
// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II. |
| 12 |
// |
| 13 |
// ------------------------------------------------------------------------ |
| 14 |
|
| 15 |
|
| 16 |
#ifndef dealii_point_value_history_h |
| 17 |
#define dealii_point_value_history_h |
| 18 |
|
| 19 |
#include <deal.II/base/config.h> |
| 20 |
|
| 21 |
#include <deal.II/base/exceptions.h> |
| 22 |
#include <deal.II/base/observer_pointer.h> |
| 23 |
#include <deal.II/base/point.h> |
| 24 |
#include <deal.II/base/quadrature_lib.h> |
| 25 |
|
| 26 |
#include <deal.II/dofs/dof_accessor.h> |
| 27 |
#include <deal.II/dofs/dof_handler.h> |
| 28 |
|
| 29 |
#include <deal.II/fe/component_mask.h> |
| 30 |
#include <deal.II/fe/fe_q.h> |
| 31 |
#include <deal.II/fe/fe_values.h> |
| 32 |
#include <deal.II/fe/mapping.h> |
| 33 |
|
| 34 |
#include <deal.II/lac/vector.h> |
| 35 |
|
| 36 |
#include <deal.II/numerics/data_postprocessor.h> |
| 37 |
|
| 38 |
#include <boost/signals2/connection.hpp> |
| 39 |
|
| 40 |
#include <fstream> |
| 41 |
#include <iostream> |
| 42 |
#include <map> |
| 43 |
#include <sstream> |
| 44 |
#include <string> |
| 45 |
#include <vector> |
| 46 |
|
| 47 |
DEAL_II_NAMESPACE_OPEN |
| 48 |
|
| 49 |
namespace internal |
| 50 |
{ |
| 51 |
namespace PointValueHistoryImplementation |
| 52 |
{ |
| 53 |
/** |
| 54 |
* A class that stores the data needed to reference the support points |
| 55 |
* closest to one requested point. |
| 56 |
*/ |
| 57 |
template <int dim> |
| 58 |
class PointGeometryData |
| 59 |
{ |
| 60 |
public: |
| 61 |
/** |
| 62 |
* Only a constructor needed for this class (a struct really) |
| 63 |
*/ |
| 64 |
PointGeometryData( |
| 65 |
const Point<dim> &new_requested_location, |
| 66 |
const std::vector<Point<dim>> &new_locations, |
| 67 |
const std::vector<types::global_dof_index> &new_sol_indices); |
| 68 |
Point<dim> requested_location; |
| 69 |
std::vector<Point<dim>> support_point_locations; |
| 70 |
std::vector<types::global_dof_index> solution_indices; |
| 71 |
}; |
| 72 |
} // namespace PointValueHistoryImplementation |
| 73 |
} // namespace internal |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
/** |
| 78 |
* PointValueHistory tackles the overhead of plotting time (or any other |
| 79 |
* iterative process) graphs of solution values at specific points on the |
| 80 |
* mesh. The user specifies the points which the solution should be monitored |
| 81 |
* at ahead of time, as well as giving each solution vector that they want to |
| 82 |
* record a mnemonic name. Then, for each step the user calls one of the three |
| 83 |
* available "evaluate field" methods to store the data from each time step, |
| 84 |
* and the class extracts data for the requested points to store it. Finally, |
| 85 |
* once the computation is finished, the user can request output files to be |
| 86 |
* generated; these files are in Gnuplot format but are basically just regular |
| 87 |
* text and can easily be imported into other programs well, for example into |
| 88 |
* spreadsheets. |
| 89 |
* |
| 90 |
* The user can store extra variables which do not relate to mesh location |
| 91 |
* specifying n_independent_variables. The class then expects a std::vector of |
| 92 |
* size n_independent_variables to be added during each step using the method |
| 93 |
* @p push_back_independent. This may be used for example for recording |
| 94 |
* external input, logging solver performance data such as time taken to solve |
| 95 |
* the step and solver steps before convergence, saving norms calculated, or |
| 96 |
* simply saving the time, number of time step, or number of nonlinear |
| 97 |
* iteration along with the data evaluated from the mesh. |
| 98 |
* |
| 99 |
* The three "evaluate field" methods each have different strengths and |
| 100 |
* weaknesses making each suitable for different contexts: |
| 101 |
* <ol> |
| 102 |
* <li>Firstly, the @p evaluate_field version that does not take a @p |
| 103 |
* DataPostprocessor object selects the nearest support point (see |
| 104 |
* @ref GlossSupport "this entry in the glossary" |
| 105 |
* ) to a given point to extract data from. This makes the code that needs to |
| 106 |
* be run at each time step very short, since looping over the mesh to extract |
| 107 |
* the needed dof_index can be done just once at the start. However, this |
| 108 |
* method is not suitable for FiniteElement objects that do not assign dofs to |
| 109 |
* actual mesh locations (i.e. FEs without |
| 110 |
* @ref GlossSupport "support points" |
| 111 |
* ) or if adaptive mesh refinement is used. The reason for the latter |
| 112 |
* restriction is that the location of the closest support point to a given |
| 113 |
* point may change upon mesh refinement. The class will throw an exception if |
| 114 |
* any change to the triangulation is made (Although the nearest support point |
| 115 |
* could be re- computed upon mesh refinement, the location of the support |
| 116 |
* point will most likely change slightly, making the interpretation of the |
| 117 |
* data difficult, hence this is not implemented currently.) |
| 118 |
* |
| 119 |
* <li> Secondly, @p evaluate_field_at_requested_location calls @p |
| 120 |
* VectorTools::point_value to compute values at the specific point requested. |
| 121 |
* This method is valid for any FE that is supported by @p |
| 122 |
* VectorTools::point_value. Specifically, this method can be called by codes |
| 123 |
* using adaptive mesh refinement. |
| 124 |
* |
| 125 |
* <li>Finally, the class offers a function @p evaluate_field that takes a @p |
| 126 |
* DataPostprocessor object. This method allows the deal.II data postprocessor |
| 127 |
* to be used to compute new quantities from the solution on the fly. The |
| 128 |
* values are located at the nearest quadrature point to the requested point. |
| 129 |
* If the mesh is refined between calls, this point will change, so care must |
| 130 |
* be taken when using this method in code using adaptive refinement, but as |
| 131 |
* the output will be meaningful (in the sense that the quadrature point |
| 132 |
* selected is guaranteed to remain in the same vicinity, the class does not |
| 133 |
* prevent the use of this method in adaptive codes. The class provides |
| 134 |
* warnings in the output files if the mesh has changed. Note that one can |
| 135 |
* reduce the error this procedure introduces by providing a quadrature |
| 136 |
* formula that has more points, at the expense of performing more work since |
| 137 |
* then the closest quadrature points is nearer to the point at which the |
| 138 |
* evaluation is really supposed to happen. (As a sidenote: Why not do the |
| 139 |
* evaluation at the requested point right away? The reason for this is that |
| 140 |
* it would require setting up a new quadrature point object on each cell that |
| 141 |
* has only a single point corresponding to the reference coordinates of the |
| 142 |
* point you really want; then initializing a FEValues object with it; then |
| 143 |
* evaluating the solution at this point; then handing the result to the |
| 144 |
* DataPostprocessor object. This sequence of things is expensive -- which is |
| 145 |
* the reason why VectorTools::point_value() is expensive. Using the same |
| 146 |
* quadrature formula on each cell on which we want to evaluate the solution |
| 147 |
* and only having to initialize a FEValue object once is a much cheaper |
| 148 |
* alternative, albeit of course at the expense of getting only an approximate |
| 149 |
* result.) |
| 150 |
* </ol> |
| 151 |
* |
| 152 |
* When recording a new mnemonic name, the user must supply a component_mask |
| 153 |
* (see |
| 154 |
* @ref GlossComponentMask "this glossary entry" |
| 155 |
* ) to indicate the |
| 156 |
* @ref GlossComponent "(vector) components" |
| 157 |
* to be extracted from the given input. If the user simply wants to extract |
| 158 |
* all the components, the mask need not be explicitly supplied to the @p |
| 159 |
* add_field_name method and the default value of the parameter is sufficient. |
| 160 |
* If the @p evaluate_field with a @p DataPostprocessor object is used, the |
| 161 |
* component_mask is interpreted as the mask of the @p DataPostprocessor |
| 162 |
* return vector. The size of this mask can be different to that of the FE |
| 163 |
* space, but must be provided when the @p add_field_name method is called. |
| 164 |
* One variant of the @p add_field_name method allows an unsigned int input to |
| 165 |
* construct a suitable mask, if all values from the @p DataPostprocessor are |
| 166 |
* desired. |
| 167 |
* |
| 168 |
* The class automatically generates names for the data stored based on the |
| 169 |
* mnemonics supplied. The methods @p add_component_names and @p |
| 170 |
* add_independent_names allow the user to provide lists of names to use |
| 171 |
* instead if desired. |
| 172 |
* |
| 173 |
* Following is a little code snippet that shows a common usage of this class: |
| 174 |
* |
| 175 |
* @code |
| 176 |
* #include <deal.II/numerics/point_value_history.h> |
| 177 |
* //.... |
| 178 |
* |
| 179 |
* //... code to set up Triangulation, perform any refinement necessary |
| 180 |
* // and set up DoFHandler, sizing solution Vectors etc |
| 181 |
* |
| 182 |
* // just one independent value, which happens to be an input |
| 183 |
* unsigned int n_inputs = 1; |
| 184 |
* |
| 185 |
* // call the constructor |
| 186 |
* PointValueHistory<dim> node_monitor(dof_handler, n_inputs); |
| 187 |
* |
| 188 |
* // set up fields and points required |
| 189 |
* node_monitor.add_field_name("Solution"); |
| 190 |
* std::vector <Point <dim> > point_vector(2); |
| 191 |
* point_vector[0] = Point <dim>(0, 0); |
| 192 |
* point_vector[1] = Point <dim>(0.25, 0); |
| 193 |
* node_monitor.add_points(point_vector); // multiple points at once |
| 194 |
* node_monitor.add_point(Point<dim>(1, 0.2)); // add a single point |
| 195 |
* node_monitor.close(); // close the class once the setup is complete |
| 196 |
* node_monitor.status(std::cout); // print out status to check if desired |
| 197 |
* |
| 198 |
* // ... more code ... |
| 199 |
* |
| 200 |
* // ... in an iterative loop ... |
| 201 |
* // double time, vector <double> with size 1 input_value, |
| 202 |
* // and Vector <double> solution calculated in the loop |
| 203 |
* node_monitor.start_new_dataset(time); |
| 204 |
* node_monitor.push_back_independent(input_value); |
| 205 |
* node_monitor.evaluate_field("Solution", solution); |
| 206 |
* |
| 207 |
* // ... end of iterative loop ... |
| 208 |
* |
| 209 |
* node_monitor.write_gnuplot("node"); // write out data files |
| 210 |
* |
| 211 |
* @endcode |
| 212 |
*/ |
| 213 |
template <int dim> |
| 214 |
class PointValueHistory |
| 215 |
{ |
| 216 |
public: |
| 217 |
/** |
| 218 |
* Provide a stripped down instance of the class which does not support |
| 219 |
* adding points or mesh data. This may be used for example for recording |
| 220 |
* external input or logging solver performance data. |
| 221 |
*/ |
| 222 |
PointValueHistory(const unsigned int n_independent_variables = 0); |
| 223 |
|
| 224 |
/** |
| 225 |
* Constructor linking the class to a specific @p DoFHandler. This class |
| 226 |
* reads specific data from the @p DoFHandler and stores it internally for |
| 227 |
* quick access (in particular dof indices of closest neighbors to requested |
| 228 |
* points) the class is fairly intolerant to changes to the @p DoFHandler if |
| 229 |
* data at support points is required. Mesh refinement and @p DoFRenumbering |
| 230 |
* methods should be performed before the @p add_points method is called and |
| 231 |
* adaptive grid refinement is only supported by some methods. |
| 232 |
* |
| 233 |
* The user can store extra variables which do not relate to mesh location |
| 234 |
* by specifying the number required using n_independent_variables and |
| 235 |
* making calls to @p push_back_independent as needed. This may be used for |
| 236 |
* example for recording external input or logging solver performance data. |
| 237 |
*/ |
| 238 |
PointValueHistory(const DoFHandler<dim> &dof_handler, |
| 239 |
const unsigned int n_independent_variables = 0); |
| 240 |
|
| 241 |
/** |
| 242 |
* Copy constructor. This constructor can be safely called with a @p |
| 243 |
* PointValueHistory object that contains data, but this could be expensive |
| 244 |
* and should be avoided. |
| 245 |
*/ |
| 246 |
PointValueHistory(const PointValueHistory &point_value_history); |
| 247 |
|
| 248 |
/** |
| 249 |
* Assignment operator. This assignment operator can be safely called once |
| 250 |
* the class is closed and data added, but this is provided primarily to |
| 251 |
* allow a @p PointValueHistory object declared in a class to be |
| 252 |
* reinitialized later in the class. Using the assignment operator when the |
| 253 |
* object contains data could be expensive. |
| 254 |
*/ |
| 255 |
PointValueHistory & |
| 256 |
operator=(const PointValueHistory &point_value_history); |
| 257 |
|
| 258 |
/** |
| 259 |
* Deconstructor. |
| 260 |
*/ |
| 261 |
~PointValueHistory(); |
| 262 |
|
| 263 |
/** |
| 264 |
* Add a single point to the class. The support points (one per component) |
| 265 |
* in the mesh that are closest to that point are found and their details |
| 266 |
* stored for use when @p evaluate_field is called. If more than one point |
| 267 |
* is required rather use the @p add_points method since this minimizes |
| 268 |
* iterations over the mesh. |
| 269 |
*/ |
| 270 |
void |
| 271 |
add_point(const Point<dim> &location); |
| 272 |
|
| 273 |
/** |
| 274 |
* Add multiple points to the class. The support points (one per component) |
| 275 |
* in the mesh that are closest to that point is found and their details |
| 276 |
* stored for use when @p evaluate_field is called. If more than one point |
| 277 |
* is required, rather call this method as it is more efficient than the |
| 278 |
* add_point method since it minimizes iterations over the mesh. The points |
| 279 |
* are added to the internal database in the order they appear in the list |
| 280 |
* and there is always a one to one correspondence between the requested |
| 281 |
* point and the added point, even if a point is requested multiple times. |
| 282 |
*/ |
| 283 |
void |
| 284 |
add_points(const std::vector<Point<dim>> &locations); |
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
/** |
| 289 |
* Put another mnemonic string (and hence @p VectorType) into the class. |
| 290 |
* This method adds storage space for variables equal to the number of true |
| 291 |
* values in component_mask. This also adds extra entries for points that |
| 292 |
* are already in the class, so @p add_field_name and @p add_points can be |
| 293 |
* called in any order. |
| 294 |
*/ |
| 295 |
void |
| 296 |
add_field_name(const std::string &vector_name, |
| 297 |
const ComponentMask &component_mask = {}); |
| 298 |
|
| 299 |
/** |
| 300 |
* Put another mnemonic string (and hence @p VectorType) into the class. |
| 301 |
* This method adds storage space for n_components variables. This also adds |
| 302 |
* extra entries for points that are already in the class, so @p |
| 303 |
* add_field_name and @p add_points can be called in any order. This method |
| 304 |
* generates a std::vector 0, ..., n_components-1 and calls the previous |
| 305 |
* function. |
| 306 |
*/ |
| 307 |
void |
| 308 |
add_field_name(const std::string &vector_name, |
| 309 |
const unsigned int n_components); |
| 310 |
|
| 311 |
/** |
| 312 |
* Provide optional names for each component of a field. These names will be |
| 313 |
* used instead of names generated from the field name, if supplied. |
| 314 |
*/ |
| 315 |
void |
| 316 |
add_component_names(const std::string &vector_name, |
| 317 |
const std::vector<std::string> &component_names); |
| 318 |
|
| 319 |
/** |
| 320 |
* Provide optional names for the independent values. These names will be |
| 321 |
* used instead of "Indep_...", if supplied. |
| 322 |
*/ |
| 323 |
void |
| 324 |
add_independent_names(const std::vector<std::string> &independent_names); |
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
/** |
| 329 |
* Extract values at the stored points from the VectorType supplied and add |
| 330 |
* them to the new dataset in vector_name. The component mask supplied when |
| 331 |
* the field was added is used to select components to extract. If a @p |
| 332 |
* DoFHandler is used, one (and only one) evaluate_field method must be |
| 333 |
* called for each dataset (time step, iteration, etc) for each vector_name, |
| 334 |
* otherwise a @p ExcDataLostSync error can occur. |
| 335 |
*/ |
| 336 |
template <typename VectorType> |
| 337 |
void |
| 338 |
evaluate_field(const std::string &name, const VectorType &solution); |
| 339 |
|
| 340 |
|
| 341 |
/** |
| 342 |
* Compute values using a @p DataPostprocessor object with the @p VectorType |
| 343 |
* supplied and add them to the new dataset in vector_name. The |
| 344 |
* component_mask supplied when the field was added is used to select |
| 345 |
* components to extract from the @p DataPostprocessor return vector. This |
| 346 |
* method takes a vector of field names to process and is preferred if many |
| 347 |
* fields use the same @p DataPostprocessor object as each cell is only |
| 348 |
* located once. The quadrature object supplied is used for all components |
| 349 |
* of a vector field. Although this method will not throw an exception if |
| 350 |
* the mesh has changed. (No internal data structures are invalidated as the |
| 351 |
* quadrature points are repicked each time the function is called.) |
| 352 |
* Nevertheless the user must be aware that if the mesh changes the point |
| 353 |
* selected will also vary slightly, making interpretation of the data more |
| 354 |
* difficult. If a @p DoFHandler is used, one (and only one) evaluate_field |
| 355 |
* method must be called for each dataset (time step, iteration, etc) for |
| 356 |
* each vector_name, otherwise a @p ExcDataLostSync error can occur. |
| 357 |
*/ |
| 358 |
template <typename VectorType> |
| 359 |
void |
| 360 |
evaluate_field(const std::vector<std::string> &names, |
| 361 |
const VectorType &solution, |
| 362 |
const DataPostprocessor<dim> &data_postprocessor, |
| 363 |
const Quadrature<dim> &quadrature); |
| 364 |
|
| 365 |
/** |
| 366 |
* Construct a std::vector <std::string> containing only vector_name and |
| 367 |
* call the above function. The above function is more efficient if multiple |
| 368 |
* fields use the same @p DataPostprocessor object. |
| 369 |
*/ |
| 370 |
template <typename VectorType> |
| 371 |
void |
| 372 |
evaluate_field(const std::string &name, |
| 373 |
const VectorType &solution, |
| 374 |
const DataPostprocessor<dim> &data_postprocessor, |
| 375 |
const Quadrature<dim> &quadrature); |
| 376 |
|
| 377 |
|
| 378 |
/** |
| 379 |
* Extract values at the points actually requested from the VectorType |
| 380 |
* supplied and add them to the new dataset in vector_name. Unlike the other |
| 381 |
* evaluate_field methods this method does not care if the dof_handler has |
| 382 |
* been modified because it uses calls to @p VectorTools::point_value to |
| 383 |
* extract there data. Therefore, if only this method is used, the class is |
| 384 |
* fully compatible with adaptive refinement. The component_mask supplied |
| 385 |
* when the field was added is used to select components to extract. If a @p |
| 386 |
* DoFHandler is used, one (and only one) evaluate_field method must be |
| 387 |
* called for each dataset (time step, iteration, etc) for each vector_name, |
| 388 |
* otherwise a @p ExcDataLostSync error can occur. |
| 389 |
*/ |
| 390 |
template <typename VectorType> |
| 391 |
void |
| 392 |
evaluate_field_at_requested_location(const std::string &name, |
| 393 |
const VectorType &solution); |
| 394 |
|
| 395 |
|
| 396 |
/** |
| 397 |
* Add the key for the current dataset to the dataset. Although calling this |
| 398 |
* method first is sensible, the order in which this method, @p |
| 399 |
* evaluate_field and @p push_back_independent is not important. It is |
| 400 |
* however important that all the data for a give dataset is added to each |
| 401 |
* dataset and that it is added before a new data set is started. This |
| 402 |
* prevents a @p ExcDataLostSync. |
| 403 |
*/ |
| 404 |
void |
| 405 |
start_new_dataset(const double key); |
| 406 |
|
| 407 |
/** |
| 408 |
* If independent values have been set up, this method stores these values. |
| 409 |
* This should only be called once per dataset, and if independent values |
| 410 |
* are used it must be called for every dataset. A @p ExcDataLostSync |
| 411 |
* exception can be thrown if this method is not called. |
| 412 |
*/ |
| 413 |
void |
| 414 |
push_back_independent(const std::vector<double> &independent_values); |
| 415 |
|
| 416 |
|
| 417 |
/** |
| 418 |
* Write out a series of .gpl files named base_name + "-00.gpl", base_name + |
| 419 |
* "-01.gpl" etc. The data file gives information about where the support |
| 420 |
* points |
| 421 |
* selected and interpreting the data. If @p n_indep != 0 an additional file |
| 422 |
* base_name + "_indep.gpl" containing key and independent data. The file |
| 423 |
* name agrees with the order the points were added to the class. The names |
| 424 |
* of the data columns can be supplied using the functions @p |
| 425 |
* add_component_names and @p add_independent_names. The support point |
| 426 |
* information is only meaningful if the dof_handler has not been changed. |
| 427 |
* Therefore, if adaptive mesh refinement has been used the support point |
| 428 |
* data should not be used. The optional parameter postprocessor_locations |
| 429 |
* is used to add the postprocessor locations to the output files. If this |
| 430 |
* is desired, the data should be obtained from a call to |
| 431 |
* get_postprocessor_locations while the dof_handler is usable. The default |
| 432 |
* parameter is an empty vector of strings, and will suppress postprocessor |
| 433 |
* locations output. |
| 434 |
*/ |
| 435 |
void |
| 436 |
write_gnuplot(const std::string &base_name, |
| 437 |
const std::vector<Point<dim>> &postprocessor_locations = |
| 438 |
std::vector<Point<dim>>()); |
| 439 |
|
| 440 |
|
| 441 |
/** |
| 442 |
* Return a @p Vector with the indices of selected points flagged with a 1. |
| 443 |
* This method is mainly for testing and verifying that the class is working |
| 444 |
* correctly. By passing this vector to a DataOut object, the user can |
| 445 |
* verify that the positions returned by @p get_support_locations agree with |
| 446 |
* the positions that @p DataOut interprets from the @p Vector returned. The |
| 447 |
* code snippet below demonstrates how this could be done: |
| 448 |
* @code |
| 449 |
* // Make a DataOut object and attach the dof_handler |
| 450 |
* DataOut<dim> data_out; |
| 451 |
* data_out.attach_dof_handler(dof_handler); |
| 452 |
* |
| 453 |
* // Call the mark_locations method to get the vector with indices flagged |
| 454 |
* Vector<double> support_point_locations = node_monitor.mark_locations(); |
| 455 |
* |
| 456 |
* // Add the vector to the data_out object and |
| 457 |
* // write out a file in the usual way |
| 458 |
* data_out.add_data_vector(support_point_locations, "Monitor_Locations"); |
| 459 |
* data_out.build_patches(2); |
| 460 |
* std::ofstream output("locations.gpl"); |
| 461 |
* data_out.write_gnuplot(output); |
| 462 |
* @endcode |
| 463 |
*/ |
| 464 |
Vector<double> |
| 465 |
mark_support_locations(); |
| 466 |
|
| 467 |
/** |
| 468 |
* Stores the actual location of each support point selected by the @p |
| 469 |
* add_point(s) method. This can be used to compare with the point |
| 470 |
* requested, for example by using the @p Point<dim>::distance function. For |
| 471 |
* convenience, location is resized to the correct number of points by the |
| 472 |
* method. |
| 473 |
*/ |
| 474 |
void |
| 475 |
get_support_locations(std::vector<std::vector<Point<dim>>> &locations); |
| 476 |
|
| 477 |
/** |
| 478 |
* Stores the actual location of the points used by the data_postprocessor. |
| 479 |
* This can be used to compare with the points requested, for example by |
| 480 |
* using the @p Point<dim>::distance function. Unlike the support_locations, |
| 481 |
* these locations are computed every time the evaluate_field method is |
| 482 |
* called with a postprocessor. This method uses the same algorithm so can |
| 483 |
* will find the same points. For convenience, location is resized to the |
| 484 |
* correct number of points by the method. |
| 485 |
*/ |
| 486 |
void |
| 487 |
get_postprocessor_locations(const Quadrature<dim> &quadrature, |
| 488 |
std::vector<Point<dim>> &locations); |
| 489 |
|
| 490 |
/** |
| 491 |
* Once datasets have been added to the class, requests to add additional |
| 492 |
* points will make the data interpretation unclear. The boolean @p closed |
| 493 |
* defines a state of the class and ensures this does not happen. Additional |
| 494 |
* points or vectors can only be added while the class is not closed, and |
| 495 |
* the class must be closed before datasets can be added or written to file. |
| 496 |
* @p PointValueHistory::get_support_locations and @p PointValueHistory::status |
| 497 |
* do not require the class to be closed. If a method that requires a class to |
| 498 |
* be open or close is called while in the wrong state a @p ExcInvalidState |
| 499 |
* exception is thrown. |
| 500 |
*/ |
| 501 |
void |
| 502 |
close(); |
| 503 |
|
| 504 |
|
| 505 |
/** |
| 506 |
* Delete the lock this object has to the @p DoFHandler used the last time |
| 507 |
* the class was created. This method should not normally need to be |
| 508 |
* called, but can be useful to ensure that the @p DoFHandler is released |
| 509 |
* before it goes out of scope if the @p PointValueHistory class might live |
| 510 |
* longer than it. Once this method has been called, the majority of methods |
| 511 |
* will throw a @p ExcInvalidState exception, so if used this method should |
| 512 |
* be the last call to the class. |
| 513 |
*/ |
| 514 |
void |
| 515 |
clear(); |
| 516 |
|
| 517 |
/** |
| 518 |
* Print useful debugging information about the class, include details about |
| 519 |
* which support points were selected for each point and sizes of the data |
| 520 |
* stored. |
| 521 |
*/ |
| 522 |
void |
| 523 |
status(std::ostream &out); |
| 524 |
|
| 525 |
|
| 526 |
/** |
| 527 |
* Check the internal data sizes to test for a loss of data sync. This is |
| 528 |
* often used in @p Assert statements with the @p ExcDataLostSync exception. |
| 529 |
* If @p strict is @p false this method returns @p true if all sizes are |
| 530 |
* within 1 of each other (needed to allow data to be added), with @p strict |
| 531 |
* = @p true they must be exactly equal. |
| 532 |
*/ |
| 533 |
|
| 534 |
bool |
| 535 |
deep_check(const bool strict); |
| 536 |
|
| 537 |
/** |
| 538 |
* Exception |
| 539 |
*/ |
| 540 |
DeclExceptionMsg(ExcNoIndependent, |
| 541 |
"A call has been made to push_back_independent() when " |
| 542 |
"no independent values were requested."); |
| 543 |
|
| 544 |
/** |
| 545 |
* Exception |
| 546 |
*/ |
| 547 |
DeclExceptionMsg( |
| 548 |
ExcDataLostSync, |
| 549 |
"This error is thrown to indicate that the data sets appear to be out of " |
| 550 |
"sync. The class requires that the number of dataset keys is the same as " |
| 551 |
"the number of independent values sets and mesh linked value sets. The " |
| 552 |
"number of each of these is allowed to differ by one to allow new values " |
| 553 |
"to be added without restricting the order the user chooses to do so. " |
| 554 |
"Special cases of no FHandler and no independent values should not " |
| 555 |
"trigger this error."); |
| 556 |
|
| 557 |
|
| 558 |
/** |
| 559 |
* Exception |
| 560 |
*/ |
| 561 |
DeclExceptionMsg( |
| 562 |
ExcDoFHandlerRequired, |
| 563 |
"A method which requires access to a @p DoFHandler to be meaningful has " |
| 564 |
"been called when have_dof_handler is false (most likely due to default " |
| 565 |
"constructor being called). Only independent variables may be logged with " |
| 566 |
"no DoFHandler."); |
| 567 |
|
| 568 |
/** |
| 569 |
* Exception |
| 570 |
*/ |
| 571 |
DeclExceptionMsg( |
| 572 |
ExcDoFHandlerChanged, |
| 573 |
"The triangulation has been refined or coarsened in some way. This " |
| 574 |
"suggests that the internal DoF indices stored by the current " |
| 575 |
"object are no longer meaningful."); |
| 576 |
|
| 577 |
private: |
| 578 |
/** |
| 579 |
* Stores keys, values on the abscissa. This will often be time, but |
| 580 |
* possibly time step, iteration etc. |
| 581 |
*/ |
| 582 |
std::vector<double> dataset_key; |
| 583 |
|
| 584 |
/** |
| 585 |
* Values that do not depend on grid location. |
| 586 |
*/ |
| 587 |
std::vector<std::vector<double>> independent_values; |
| 588 |
|
| 589 |
/** |
| 590 |
* Save a vector listing component names associated with a |
| 591 |
* independent_values. This will be an empty vector if the user does not |
| 592 |
* supplies names. |
| 593 |
*/ |
| 594 |
std::vector<std::string> indep_names; |
| 595 |
|
| 596 |
/** |
| 597 |
* Save data for each mnemonic entry. data_store: mnemonic -> |
| 598 |
* [point_0_components point_1_components ... point_n-1_components][key] |
| 599 |
* This format facilitates scalar mnemonics in a vector space, because |
| 600 |
* scalar mnemonics will only have one component per point. Vector |
| 601 |
* components are strictly FE.n_components () long. |
| 602 |
*/ |
| 603 |
std::map<std::string, std::vector<std::vector<double>>> data_store; |
| 604 |
|
| 605 |
/** |
| 606 |
* Save a component mask for each mnemonic. |
| 607 |
*/ |
| 608 |
std::map<std::string, ComponentMask> component_mask; |
| 609 |
|
| 610 |
|
| 611 |
/** |
| 612 |
* Save a vector listing component names associated with a mnemonic. This |
| 613 |
* will be an empty vector if the user does not supplies names. |
| 614 |
*/ |
| 615 |
std::map<std::string, std::vector<std::string>> component_names_map; |
| 616 |
|
| 617 |
/** |
| 618 |
* Save the location and other mesh information about support points. |
| 619 |
*/ |
| 620 |
std::vector<internal::PointValueHistoryImplementation::PointGeometryData<dim>> |
| 621 |
point_geometry_data; |
| 622 |
|
| 623 |
|
| 624 |
/** |
| 625 |
* Used to enforce @p closed state for some methods. |
| 626 |
*/ |
| 627 |
bool closed; |
| 628 |
|
| 629 |
/** |
| 630 |
* Used to enforce @p !cleared state for some methods. |
| 631 |
*/ |
| 632 |
bool cleared; |
| 633 |
|
| 634 |
|
| 635 |
/** |
| 636 |
* A smart pointer to the dof_handler supplied to the constructor. This can |
| 637 |
* be released by calling @p clear(). |
| 638 |
*/ |
| 639 |
ObserverPointer<const DoFHandler<dim>, PointValueHistory<dim>> dof_handler; |
| 640 |
|
| 641 |
|
| 642 |
/** |
| 643 |
* Variable to check if the triangulation has changed. If it has changed, |
| 644 |
* certain data is out of date (especially the |
| 645 |
* PointGeometryData::solution_indices. |
| 646 |
*/ |
| 647 |
bool triangulation_changed; |
| 648 |
|
| 649 |
/** |
| 650 |
* A boolean to record whether the class was initialized with a DoFHandler |
| 651 |
* or not. |
| 652 |
*/ |
| 653 |
bool have_dof_handler; |
| 654 |
|
| 655 |
/** |
| 656 |
* Used to detect signals from the Triangulation. |
| 657 |
*/ |
| 658 |
boost::signals2::connection tria_listener; |
| 659 |
|
| 660 |
/** |
| 661 |
* Stores the number of independent variables requested. |
| 662 |
*/ |
| 663 |
unsigned int n_indep; |
| 664 |
|
| 665 |
|
| 666 |
/** |
| 667 |
* A function that will be triggered through signals whenever the |
| 668 |
* triangulation is modified. |
| 669 |
* |
| 670 |
* It is currently used to check if the triangulation has changed, |
| 671 |
* invalidating precomputed values. |
| 672 |
*/ |
| 673 |
void |
| 674 |
tria_change_listener(); |
| 675 |
}; |
| 676 |
|
| 677 |
|
| 678 |
DEAL_II_NAMESPACE_CLOSE |
| 679 |
#endif /* dealii_point_value_history_h */ |