Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
postprocessors.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2019-2026 The Lethe Authors
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
3
4#ifndef lethe_postprocessors_h
5#define lethe_postprocessors_h
6
8
9#include <deal.II/base/tensor.h>
10
11#include <deal.II/numerics/data_postprocessor.h>
12
13#include <utility>
14#include <vector>
15
16using namespace dealii;
17
18/**
19 * @brief Compute the vorticity vector field within a domain.
20 *
21 * The vorticity is defined as \f$\mathbf{\omega} = \nabla \times \mathbf{u}
22 * = \mathrm{rot}(\mathbf{u})\f$ where \f$\mathbf{u}\f$ is the velocity vector.
23 */
24template <int dim>
25class VorticityPostprocessor : public DataPostprocessorVector<dim>
26{
27public:
28 /**
29 * @brief Constructor of the vorticity postprocessor.
30 */
32 : DataPostprocessorVector<dim>("vorticity", update_gradients)
33 {}
34
35 /**
36 * @brief Compute the vorticity vector from the velocity vector at given
37 * evaluation points.
38 *
39 * @param[in] input_data Fluid dynamics velocity and pressure information.
40 *
41 * @param[out] computed_quantities Computed vorticity vector at evaluation
42 * points.
43 *
44 * @note @p input_data contains both velocity and pressure data since fluid
45 * dynamics in Lethe is solved in a monolithic way, but only the velocity
46 * gradient is used to compute the vorticity.
47 */
48 virtual void
50 const DataPostprocessorInputs::Vector<dim> &input_data,
51 std::vector<Vector<double>> &computed_quantities) const override
52 {
53 AssertDimension(input_data.solution_gradients.size(),
54 computed_quantities.size());
55 for (unsigned int p = 0; p < input_data.solution_gradients.size(); ++p)
56 {
57 AssertDimension(computed_quantities[p].size(), dim);
58 if constexpr (dim == 3)
59 {
60 computed_quantities[p](0) =
61 (input_data.solution_gradients[p][2][1] -
62 input_data.solution_gradients[p][1][2]);
63 computed_quantities[p](1) =
64 (input_data.solution_gradients[p][0][2] -
65 input_data.solution_gradients[p][2][0]);
66 computed_quantities[p](2) =
67 (input_data.solution_gradients[p][1][0] -
68 input_data.solution_gradients[p][0][1]);
69 }
70 if constexpr (dim == 2)
71 {
72 computed_quantities[p][0] =
73 (input_data.solution_gradients[p][1][0] -
74 input_data.solution_gradients[p][0][1]);
75 }
76 }
77 }
78};
79
80/**
81 * @brief Compute the Q-criterion scalar field within a domain.
82 *
83 * The Q-criterion is defined as \f$Q = 0.5 (||\mathbf{\omega}||^2 -
84 * ||\mathbf{S}||^2)\f$ where \f$\mathbf{\omega}\f$ is the vorticity vector and
85 * \f$\mathbf{S}\f$ is the symmetric deformation tensor.
86 */
87template <int dim>
88class QCriterionPostprocessor : public DataPostprocessorScalar<dim>
89{
90public:
91 /**
92 * @brief Constructor of the Q-criterion postprocessor.
93 */
95 : DataPostprocessorScalar<dim>("q_criterion", update_gradients)
96 {}
97
98 /**
99 * @brief Computes the Q-criterion from the velocity vector at given
100 * evaluation points.
101 *
102 * @param[in] input_data Fluid dynamics velocity and pressure information.
103 *
104 * @param[out] computed_quantities Computed Q-criterion value at evaluation
105 * points.
106 *
107 * @note @p input_data contains both velocity and pressure data since fluid
108 * dynamics in Lethe is solved in a monolithic way, but only the velocity
109 * gradient is used to compute the Q-criterion.
110 */
111 virtual void
113 const DataPostprocessorInputs::Vector<dim> &input_data,
114 std::vector<Vector<double>> &computed_quantities) const override
115 {
116 for (unsigned int p = 0; p < input_data.solution_gradients.size(); ++p)
117 {
118 AssertDimension(computed_quantities[p].size(), 1);
119 double p1 = 0.0, r1 = 0.0;
120 std::vector<Tensor<2, dim>> vorticity_vector(
121 input_data.solution_gradients.size());
122 std::vector<Tensor<2, dim>> strain_rate_tensor(
123 input_data.solution_gradients.size());
124 for (int j = 0; j < dim; j++)
125 {
126 for (int k = 0; k < dim; k++)
127 {
128 vorticity_vector[p][j][k] =
129 0.5 * ((input_data.solution_gradients[p][j][k]) -
130 input_data.solution_gradients[p][k][j]);
131 strain_rate_tensor[p][j][k] =
132 0.5 * ((input_data.solution_gradients[p][j][k]) +
133 input_data.solution_gradients[p][k][j]);
134 }
135 }
136 for (int m = 0; m < dim; m++)
137 {
138 for (int n = 0; n < dim; n++)
139 {
140 p1 += (vorticity_vector[p][m][n]) * (vorticity_vector[p][m][n]);
141 r1 +=
142 (strain_rate_tensor[p][m][n]) * (strain_rate_tensor[p][m][n]);
143 }
144 }
145 computed_quantities[p] = 0.5 * (p1 - r1);
146 }
147 }
148};
149
150
151/**
152 * @brief Compute the velocity divergence scalar field within a domain.
153 *
154 * The divergence is defined as \f$\nabla \cdot \mathbf{u}\f$ where
155 * \f$\mathbf{u}\f$ is the velocity vector.
156 */
157template <int dim>
158class DivergencePostprocessor : public DataPostprocessorScalar<dim>
159{
160public:
161 /**
162 * @brief Constructor of the velocity divergence postprocessor.
163 */
165 : DataPostprocessorScalar<dim>("velocity_divergence", update_gradients)
166 {}
167
168 /**
169 * @brief Compute the divergence of the velocity at given evaluation points.
170 *
171 * @param[in] input_data Fluid dynamics velocity and pressure information.
172 *
173 * @param[out] computed_quantities Computed velocity divergence value at
174 * evaluation points.
175 *
176 * @note @p input_data contains both velocity and pressure data since fluid
177 * dynamics in Lethe is solved in a monolithic way, but only the velocity
178 * gradient is used to compute the velocity divergence.
179 */
180 virtual void
182 const DataPostprocessorInputs::Vector<dim> &input_data,
183 std::vector<Vector<double>> &computed_quantities) const override
184 {
185 AssertDimension(input_data.solution_gradients.size(),
186 computed_quantities.size());
187 for (unsigned int p = 0; p < input_data.solution_gradients.size(); ++p)
188 {
189 double velocity_divergence = 0;
190 for (int d = 0; d < dim; ++d)
191 {
192 velocity_divergence += input_data.solution_gradients[p][d][d];
193 }
194 computed_quantities[p] = velocity_divergence;
195 }
196 }
197};
198
199
200/**
201 * @brief Return the velocity gradient field within a domain.
202 *
203 * The gradient is defined as \f$\nabla \mathbf{u}\f$ where
204 * \f$\mathbf{u}\f$ is the velocity vector. Note that the gradient components
205 * are numbered such that:
206 * 0 = xx, 1 = xy, 2 = xz, 3 = yx, 4 = yy, 5 = yz, 6 = zx, 7 = zy, 8 = zz
207 */
208template <int dim>
209class GradientPostprocessor : public DataPostprocessorTensor<dim>
210{
211public:
212 /**
213 * @brief Constructor of the velocity gradient postprocessor.
214 */
216 : DataPostprocessorTensor<dim>("velocity_gradient", update_gradients)
217 {}
218
219 /**
220 * @brief Return the gradient of the velocity at given evaluation points.
221 *
222 * @param[in] input_data Fluid dynamics velocity and pressure information.
223 *
224 * @param[out] computed_quantities Velocity gradient at evaluation
225 * points.
226 *
227 * @note @p input_data contains both velocity and pressure data since fluid
228 * dynamics in Lethe is solved in a monolithic way, but only the velocity
229 * gradient is used.
230 */
231 virtual void
233 const DataPostprocessorInputs::Vector<dim> &input_data,
234 std::vector<Vector<double>> &computed_quantities) const override
235 {
236 AssertDimension(input_data.solution_gradients.size(),
237 computed_quantities.size());
238 for (unsigned int p = 0; p < input_data.solution_gradients.size(); ++p)
239 {
240 AssertDimension(computed_quantities[p].size(),
241 (Tensor<2, dim>::n_independent_components));
242
243 for (int d = 0; d < dim; ++d)
244 for (int e = 0; e < dim; ++e)
245 computed_quantities[p][Tensor<2, dim>::component_to_unrolled_index(
246 TableIndices<2>(d, e))] = input_data.solution_gradients[p][d][e];
247 }
248 }
249};
250
251
252/**
253 * @brief Compute the velocity field in the Eulerian frame of reference for
254 * simulations carried out in a single rotating frame (SRF).
255 *
256 * The velocity in the Eulerian frame is \f$\mathbf{u}_\mathrm{E}
257 * =\mathbf{u}_\mathrm{L}+ \mathbf{\Omega} \times \mathbf{R}\f$ where
258 * \f$\mathbf{\Omega}\f$ is the velocity of the frame of reference and
259 * \f$\mathbf{R}\f$ the position vector.
260 */
261template <int dim>
262class SRFPostprocessor : public DataPostprocessorVector<dim>
263{
264public:
265 /**
266 * @brief Constructor of the single rotating frame SRF postprocessor.
267 *
268 * @param[in] p_omega_x Value of the \f$x\f$ component of the SRF's velocity.
269 *
270 * @param[in] p_omega_y Value of the \f$y\f$ component of the SRF's velocity.
271 *
272 * @param[in] p_omega_z Value of the \f$z\f$ component of the SRF's velocity.
273 */
274 SRFPostprocessor(double p_omega_x, double p_omega_y, double p_omega_z)
275 : DataPostprocessorVector<dim>(std::string("velocity_eulerian"),
276 update_values | update_quadrature_points)
277 , omega_x(p_omega_x)
278 , omega_y(p_omega_y)
279 , omega_z(p_omega_z)
280 {}
281
282 /**
283 * @brief Compute the Eulerian velocity in a SRF at given evaluation points.
284 *
285 * @param[in] inputs Fluid dynamics velocity and pressure information.
286 *
287 * @param[out] computed_quantities Computed Eulerian velocity vector at
288 * evaluation points.
289 *
290 * @note @p input_data contains both velocity and pressure data since fluid
291 * dynamics in Lethe is solved in a monolithic way, but only the velocity
292 * vector is used to compute the Eulerian velocity.
293 */
294 virtual void
296 const DataPostprocessorInputs::Vector<dim> &inputs,
297 std::vector<Vector<double>> &computed_quantities) const override
298 {
299 Tensor<1, dim> omega;
300 omega[0] = omega_x;
301 omega[1] = omega_y;
302 if (dim == 3)
303 omega[2] = omega_z;
304
305 const unsigned int n_quadrature_points = inputs.solution_values.size();
306 for (unsigned int q = 0; q < n_quadrature_points; ++q)
307 {
308 Tensor<1, dim> velocity;
309 velocity[0] = inputs.solution_values[q][0];
310 velocity[1] = inputs.solution_values[q][1];
311 if (dim == 2)
312 velocity = velocity + omega_z * (-1.) *
313 cross_product_2d(inputs.evaluation_points[q]);
314
315 if constexpr (dim == 3)
316 {
317 velocity[2] = inputs.solution_values[q][2];
318 velocity =
319 velocity + cross_product_3d(omega, inputs.evaluation_points[q]);
320 }
321 for (int d = 0; d < dim; ++d)
322 {
323 computed_quantities[q][d] = velocity[d];
324 }
325 }
326 }
327
328private:
329 /// Value of the \f$x\f$ component of the SRF's velocity.
330 double omega_x;
331 /// Value of the \f$y\f$ component of the SRF's velocity.
332 double omega_y;
333 /// Value of the \f$z\f$ component of the SRF's velocity.
334 double omega_z;
335};
336
337
338/**
339 * @brief Compute the kinematic viscosity scalar field of a fluid within a
340 * domain.
341 *
342 * The expression for the kinematic viscosity depends on the rheological
343 * model of the fluid. See <a href="https://chaos-polymtl.github.io/lethe/
344 * documentation/parameters/cfd/physical_properties.html#rheological-models"
345 * target="_blank">documentation on rheological models</a>.
346 */
347template <int dim>
348class KinematicViscosityPostprocessor : public DataPostprocessorScalar<dim>
349{
350public:
351 /**
352 * @brief Constructor of the kinematic viscosity postprocessor.
353 *
354 * @param[in] rheological_model Rheological model of the fluid.
355 *
356 * @param[in] fluid_id Identifier corresponding to the fluid.
357 */
359 std::shared_ptr<RheologicalModel> rheological_model,
360 const unsigned int fluid_id = 0)
361 : DataPostprocessorScalar<dim>("kinematic_viscosity" +
362 Utilities::to_string(fluid_id, 2),
363 update_gradients)
365 {}
366
367 /**
368 * @brief Compute the kinematic viscosity of a fluid at given evaluation
369 * points.
370 *
371 * @param[in] inputs Fluid dynamics velocity and pressure information.
372 *
373 * @param[out] computed_quantities Computed kinematic viscosity value at
374 * evaluation points.
375 *
376 * @note @p input_data contains both velocity and pressure data since fluid
377 * dynamics in Lethe is solved in a monolithic way, but only the velocity
378 * gradient is used to compute the kinematic viscosity when the rheological
379 * model requires it.
380 */
381 virtual void
383 const DataPostprocessorInputs::Vector<dim> &inputs,
384 std::vector<Vector<double>> &computed_quantities) const override
385 {
386 const unsigned int n_quadrature_points = inputs.solution_gradients.size();
387
388 for (unsigned int q = 0; q < n_quadrature_points; ++q)
389 {
390 const auto gradient = inputs.solution_gradients[q];
391 Tensor<2, dim> shear_rate;
392 for (int i = 0; i < dim; ++i)
393 {
394 for (int j = 0; j < dim; ++j)
395 {
396 shear_rate[i][j] += gradient[i][j] + gradient[j][i];
397 }
398 }
399 const double shear_rate_magnitude =
401
402 std::map<field, double> field_values;
403 field_values[field::shear_rate] = shear_rate_magnitude;
404
405 computed_quantities[q] = rheological_model->value(field_values);
406 }
407 }
408
409private:
410 /// Model describing the fluid's rheology.
411 std::shared_ptr<RheologicalModel> rheological_model;
412};
413
414
415/**
416 * @brief Compute the dynamic viscosity scalar field of a fluid within a
417 * domain.
418 *
419 * The dynamic viscosity is defined as \f$\mu = \frac{\nu}{\rho_\mathrm{ref}}\f$
420 * where \f$\nu\f$ is the kinematic viscosity and \f$\rho_\mathrm{ref}\f$ is the
421 * density of the fluid at reference state.
422 *
423 * The expression for the kinematic viscosity depends on the rheological
424 * model of the fluid. See <a href="https://chaos-polymtl.github.io/lethe/
425 * documentation/parameters/cfd/physical_properties.html#rheological-models"
426 * target="_blank">documentation on rheological models</a>.
427 */
428template <int dim>
429class DynamicViscosityPostprocessor : public DataPostprocessorScalar<dim>
430{
431public:
432 /**
433 * @brief Constructor of the dynamic viscosity postprocessor.
434 *
435 * @param[in] rheological_model Rheological model of the fluid.
436 *
437 * @param[in] density_ref Density of the fluid at reference state.
438 *
439 * @param[in] fluid_id Identifier corresponding to the fluid.
440 */
442 std::shared_ptr<RheologicalModel> rheological_model,
443 const double density_ref,
444 const unsigned int fluid_id = 0)
445 : DataPostprocessorScalar<dim>("dynamic_viscosity_" +
446 Utilities::to_string(fluid_id, 2),
447 update_gradients)
450 {}
451
452 /**
453 * @brief Compute the dynamic viscosity of a fluid at given evaluation
454 * points.
455 *
456 * @param[in] inputs Fluid dynamics velocity and pressure information.
457 *
458 * @param[out] computed_quantities Computed dynamic viscosity value at
459 * evaluation points.
460 *
461 * @note @p input_data contains both velocity and pressure data since fluid
462 * dynamics in Lethe is solved in a monolithic way, but only the velocity
463 * gradient is used to compute the dynamic viscosity when the rheological
464 * model requires it.
465 */
466 virtual void
468 const DataPostprocessorInputs::Vector<dim> &inputs,
469 std::vector<Vector<double>> &computed_quantities) const override
470 {
471 const unsigned int n_quadrature_points = inputs.solution_gradients.size();
472
473 for (unsigned int q = 0; q < n_quadrature_points; ++q)
474 {
475 const auto gradient = inputs.solution_gradients[q];
476 Tensor<2, dim> shear_rate;
477 for (int i = 0; i < dim; ++i)
478 {
479 for (int j = 0; j < dim; ++j)
480 {
481 shear_rate[i][j] += gradient[i][j] + gradient[j][i];
482 }
483 }
484 const double shear_rate_magnitude =
486
487 std::map<field, double> field_values;
488 field_values[field::shear_rate] = shear_rate_magnitude;
489
490 computed_quantities[q] =
491 rheological_model->get_dynamic_viscosity(density_ref, field_values);
492 }
493 }
494
495private:
496 /// Model describing the fluid's rheology.
497 std::shared_ptr<RheologicalModel> rheological_model;
498 /// Density of the fluid at reference state.
500};
501
502
503/**
504 * @brief Compute the shear rate scalar field within a domain.
505 *
506 * The shear rate is defined as \f$\dot \gamma = \frac{\partial u_i}
507 * {\partial x_j} + \frac{\partial u_j}{\partial x_i}\f$ where \f$i\f$ and
508 * \f$j\f$ are dimension component indexes.
509 */
510template <int dim>
511class ShearRatePostprocessor : public DataPostprocessorScalar<dim>
512{
513public:
514 /**
515 * @brief Constructor of the shear rate postprocessor.
516 */
518 : DataPostprocessorScalar<dim>("shear_rate", update_gradients)
519 {}
520
521 /**
522 * @brief Compute the shear rate at given evaluation points.
523 *
524 * @param[in] inputs Fluid dynamics velocity and pressure information.
525 *
526 * @param[out] computed_quantities Computed shear rate value at evaluation
527 * points.
528 *
529 * @note @p input_data contains both velocity and pressure data since fluid
530 * dynamics in Lethe is solved in a monolithic way, but only the velocity
531 * gradient is used to compute the shear rate.
532 */
533 virtual void
535 const DataPostprocessorInputs::Vector<dim> &inputs,
536 std::vector<Vector<double>> &computed_quantities) const override
537 {
538 const unsigned int n_quadrature_points = inputs.solution_gradients.size();
539
540 for (unsigned int q = 0; q < n_quadrature_points; ++q)
541 {
542 const auto gradient = inputs.solution_gradients[q];
543 Tensor<2, dim> shear_rate;
544 for (int i = 0; i < dim; ++i)
545 {
546 for (int j = 0; j < dim; ++j)
547 {
548 shear_rate[i][j] += gradient[i][j] + gradient[j][i];
549 }
550 }
551 computed_quantities[q] = calculate_shear_rate_magnitude(shear_rate);
552 }
553 }
554};
555
556
557/**
558 * @brief Compute a scalar field for a given function within a domain.
559 */
560template <int dim>
561class ScalarFunctionPostprocessor : public DataPostprocessorScalar<dim>
562{
563public:
564 /**
565 * @brief Constructor of the scalar function postprocessor.
566 *
567 * @param[in] name Name of the outputted field.
568 *
569 * @param[in] scalar_function Postprocessing scalar function.
570 *
571 */
573 std::string name,
574 const std::shared_ptr<Function<dim>> scalar_function)
575 : DataPostprocessorScalar<dim>(name, update_quadrature_points)
577 {}
578
579 /**
580 * @brief Compute the scalar given by the postprocessing function at given
581 * evaluation points.
582 *
583 * @param[in] input_data Independent variable of the postprocessing function.
584 *
585 * @param[out] computed_quantities Computed scalar value at evaluation
586 * points.
587 */
588 virtual void
590 const DataPostprocessorInputs::Vector<dim> &input_data,
591 std::vector<Vector<double>> &computed_quantities) const override
592 {
593 const unsigned int n_quadrature_points =
594 input_data.evaluation_points.size();
595
596 for (unsigned int q = 0; q < n_quadrature_points; ++q)
597 {
598 AssertDimension(computed_quantities[q].size(), 1);
599
600 const Point<dim> evaluation_point = input_data.evaluation_points[q];
601 computed_quantities[q] = scalar_function->value(evaluation_point);
602 }
603 }
604
605private:
606 /// Scalar postprocessing function
607 std::shared_ptr<Function<dim>> scalar_function;
608};
609
610/**
611 * @brief Compute level set field for a given shape within a domain.
612 */
613template <int dim>
614class LevelsetPostprocessor : public DataPostprocessorScalar<dim>
615{
616public:
617 /**
618 * @brief Constuctor of the level set postprocessor.
619 *
620 * @param[in] shape Geometrical entity.
621 */
622 LevelsetPostprocessor(const std::shared_ptr<Shape<dim>> &shape)
623 : DataPostprocessorScalar<dim>("levelset", update_quadrature_points)
624 , shape(shape)
625 {}
626
627 /**
628 * @brief Compute signed distance value of evaluation points with respect to
629 * the specified shape.
630 *
631 * @param[in] input_data Fluid dynamics velocity and pressure information.
632 *
633 * @param[out] computed_quantities Computed signed distance value at
634 * evaluation points.
635 *
636 * @note @p input_data contains both velocity and pressure data since fluid
637 * dynamics in Lethe is solved in a monolithic way, but here only the
638 * positions of evaluation points are used.
639 */
640 virtual void
642 const DataPostprocessorInputs::Vector<dim> &input_data,
643 std::vector<Vector<double>> &computed_quantities) const override
644 {
645 const unsigned int n_quadrature_points =
646 input_data.evaluation_points.size();
647
648 for (unsigned int q = 0; q < n_quadrature_points; ++q)
649 {
650 AssertDimension(computed_quantities[q].size(), 1);
651
652 const Point<dim> evaluation_point = input_data.evaluation_points[q];
653 const auto cell = input_data.template get_cell<dim>();
654 computed_quantities[q] =
655 shape->value_with_cell_guess(evaluation_point, cell);
656 }
657 }
658
659private:
660 /// Geometrical entity
661 std::shared_ptr<Shape<dim>> shape;
662};
663
664/**
665 * @brief Compute a level set gradient vector field for a given shape within a
666 * domain.
667 */
668template <int dim>
669class LevelsetGradientPostprocessor : public DataPostprocessorVector<dim>
670{
671public:
672 /**
673 * @brief Constructor for the level set gradient postprocessor
674 *
675 * @param[in] shape Geometrical entity.
676 */
678 : DataPostprocessorVector<dim>(std::string("levelset_gradient"),
679 update_values | update_quadrature_points)
680 , shape(shape)
681 {}
682
683 /**
684 * @brief Compute signed distance gradient of evaluation points with respect
685 * to the specified shape.
686 *
687 * @param[in] input_data Fluid dynamics velocity and pressure information.
688 *
689 * @param[out] computed_quantities Computed signed distance value at
690 * evaluation points.
691 *
692 * @note @p input_data contains both velocity and pressure data since fluid
693 * dynamics in Lethe is solved in a monolithic way, but here only the
694 * positions of evaluation points are used.
695 */
696 virtual void
698 const DataPostprocessorInputs::Vector<dim> &inputs,
699 std::vector<Vector<double>> &computed_quantities) const override
700 {
701 const unsigned int n_quadrature_points = inputs.evaluation_points.size();
702
703 Tensor<1, dim> levelset_gradient{};
704 for (unsigned int q = 0; q < n_quadrature_points; ++q)
705 {
706 AssertDimension(computed_quantities[q].size(), dim);
707
708 const Point<dim> evaluation_point = inputs.evaluation_points[q];
709 const auto cell = inputs.template get_cell<dim>();
710 levelset_gradient =
711 shape->gradient_with_cell_guess(evaluation_point, cell);
712 for (int d = 0; d < dim; d++)
713 computed_quantities[q][d] = levelset_gradient[d];
714 }
715 }
716
717private:
718 /// Geometrical entity
719 std::shared_ptr<Shape<dim>> shape;
720};
721
722
723/**
724 * @brief Compute the density scalar field of a material within a domain.
725 *
726 * The expression for the density depends on the density model of the material.
727 * See <a
728 * href="https://chaos-polymtl.github.io/lethe/documentation/parameters/cfd/
729 * physical_properties.html#density-models" target="_blank">documentation on
730 * density models</a>.
731 */
732template <int dim>
733class DensityPostprocessor : public DataPostprocessorScalar<dim>
734{
735public:
736 /**
737 * @brief Constructor for the density postprocessor.
738 *
739 * @param[in] p_density_model Density model of the material.
740 *
741 * @param[in] material_id Identifier corresponding to the material (fluid or
742 * solid).
743 */
744 DensityPostprocessor(std::shared_ptr<DensityModel> p_density_model,
745 const unsigned int material_id = 0)
746 : DataPostprocessorScalar<dim>("density_" +
747 Utilities::to_string(material_id, 2),
748 update_values)
749 , density_model(std::move(p_density_model))
750 {}
751
752 /**
753 * @brief Compute the density of a material at given evaluation points.
754 *
755 * @param[in] inputs Fluid dynamics velocity and pressure information.
756 *
757 * @param[out] computed_quantities Computed density value at evaluation
758 * points.
759 */
760 virtual void
762 const DataPostprocessorInputs::Vector<dim> &inputs,
763 std::vector<Vector<double>> &computed_quantities) const override
764 {
765 const unsigned int n_quadrature_points = inputs.solution_values.size();
766 std::map<field, double> field_values;
767
768 for (unsigned int q = 0; q < n_quadrature_points; ++q)
769 {
770 AssertDimension(computed_quantities[q].size(), 1);
771
772 field_values[field::pressure] = inputs.solution_values[q][dim];
773 computed_quantities[q] = density_model->value(field_values);
774 }
775 }
776
777private:
778 /// Model describing the material's density.
779 std::shared_ptr<DensityModel> density_model;
780};
781
782/**
783 * @brief Compute the local heat flux vector field within a domain.
784 *
785 * The local heat flux is defined as \f$\mathbf{q} = -k \nabla T\f$ where
786 * \f$k\f$ is the thermal conductivity of the material and \f$\nabla T\f$ the
787 * temperature gradient.
788 */
789template <int dim>
790class HeatFluxPostprocessor : public DataPostprocessorVector<dim>
791{
792public:
793 /**
794 * @brief Constructor of the heat flux postprocessor.
795 *
796 * @param[in] p_thermal_conductivity_model Thermal conductivity model of the
797 * material
798 *
799 * @param[in] p_material_string Type of material: "f" (fluid) or "s" (solid)
800 *
801 * @param[in] p_id Either fluid ID or solid ID (as initialized in the physical
802 * properties). It is used to name the postprocessed variable vector.
803 *
804 * @param[in] p_mesh_material_id Identifier corresponding to the material as
805 * identified in the mesh. By convention, fluids are given the material_id 0
806 * and solids follow with ids 1, 2, etc. This is used to identify which cell
807 * lies in which material.
808 *
809 * @param[in] p_solid_phase_present Boolean indicating if the simulation has
810 * solids. If there is no solid, the @p material_id of cells is not checked.
811 */
812 HeatFluxPostprocessor(const std::shared_ptr<ThermalConductivityModel>
813 &p_thermal_conductivity_model,
814 const std::string &p_material_string = "f",
815 const unsigned int &p_id = 0,
816 const unsigned int &p_mesh_material_id = 0,
817 const bool &p_solid_phase_present = false)
818 : DataPostprocessorVector<dim>("heat_flux_" + p_material_string +
819 Utilities::to_string(p_id, 2),
820 update_values | update_gradients)
821 , thermal_conductivity_model(p_thermal_conductivity_model)
822 , mesh_material_id(p_mesh_material_id)
823 , solid_phase_present(p_solid_phase_present)
824 {}
825
826 /**
827 * @brief Compute local heat fluxes from temperature gradient vector field and
828 * thermal conductivity at given evaluation points.
829 *
830 * @param[in] inputs Temperature information.
831 *
832 * @param[out] computed_quantities Computed local heat flux vectors at
833 * evaluation points.
834 */
835 virtual void
837 const DataPostprocessorInputs::Scalar<dim> &inputs,
838 std::vector<Vector<double>> &computed_quantities) const override
839 {
840 const unsigned int n_evaluation_points = computed_quantities.size();
841 AssertDimension(inputs.solution_gradients.size(), n_evaluation_points);
842
843 // If solid materials are present, identify each material's subdomain.
845 {
846 // Get Cell
847 const auto cell = inputs.template get_cell<dim>();
848
849 // Check if the cell lies in the material of interest
850 if (cell->material_id() == mesh_material_id)
851 {
852 compute_quantities(inputs, computed_quantities);
853 }
854 // Apply null values to irrelevant subdomain
855 else
856 {
857 Vector<double> null_vector(dim);
858 std::vector<Vector<double>> null_computed_quantities(
859 n_evaluation_points, null_vector);
860 computed_quantities = null_computed_quantities;
861 }
862 }
863 // Only fluids are present
864 else
865 {
866 compute_quantities(inputs, computed_quantities);
867 }
868 }
869
870private:
871 /**
872 * @brief Computes local heat flux vectors.
873 *
874 * @note The function is used to improve readability of the
875 * HeatFluxPostprocessor::evaluate_scalar_field function and avoid repeated
876 * lines.
877 *
878 * @param[in] inputs Temperature information.
879 *
880 * @param[out] computed_quantities Computed local heat flux vectors at
881 * evaluation points.
882 */
883 void
884 compute_quantities(const DataPostprocessorInputs::Scalar<dim> &inputs,
885 std::vector<Vector<double>> &computed_quantities) const
886 {
887 std::map<field, double> field_values;
888 for (unsigned int p = 0; p < computed_quantities.size(); ++p)
889 {
890 AssertDimension(computed_quantities[p].size(), dim);
891 field_values[field::temperature] = inputs.solution_values[p];
892
893 for (int i = 0; i < dim; ++i)
894 {
895 computed_quantities[p][i] =
896 -thermal_conductivity_model->value(field_values) *
897 inputs.solution_gradients[p][i];
898 }
899 }
900 }
901
902 /// Model describing of thermal conductivity of the material.
903 std::shared_ptr<ThermalConductivityModel> thermal_conductivity_model;
904 /// Identifier corresponding to the material as identified in the mesh.
905 const unsigned int mesh_material_id;
906 /// Boolean indicating if the simulation has solids.
908};
909#endif
virtual void evaluate_vector_field(const DataPostprocessorInputs::Vector< dim > &inputs, std::vector< Vector< double > > &computed_quantities) const override
Compute the density of a material at given evaluation points.
DensityPostprocessor(std::shared_ptr< DensityModel > p_density_model, const unsigned int material_id=0)
Constructor for the density postprocessor.
std::shared_ptr< DensityModel > density_model
Model describing the material's density.
virtual void evaluate_vector_field(const DataPostprocessorInputs::Vector< dim > &input_data, std::vector< Vector< double > > &computed_quantities) const override
Compute the divergence of the velocity at given evaluation points.
DivergencePostprocessor()
Constructor of the velocity divergence postprocessor.
DynamicViscosityPostprocessor(std::shared_ptr< RheologicalModel > rheological_model, const double density_ref, const unsigned int fluid_id=0)
Constructor of the dynamic viscosity postprocessor.
virtual void evaluate_vector_field(const DataPostprocessorInputs::Vector< dim > &inputs, std::vector< Vector< double > > &computed_quantities) const override
Compute the dynamic viscosity of a fluid at given evaluation points.
double density_ref
Density of the fluid at reference state.
std::shared_ptr< RheologicalModel > rheological_model
Model describing the fluid's rheology.
GradientPostprocessor()
Constructor of the velocity gradient postprocessor.
virtual void evaluate_vector_field(const DataPostprocessorInputs::Vector< dim > &input_data, std::vector< Vector< double > > &computed_quantities) const override
Return the gradient of the velocity at given evaluation points.
const bool solid_phase_present
Boolean indicating if the simulation has solids.
void compute_quantities(const DataPostprocessorInputs::Scalar< dim > &inputs, std::vector< Vector< double > > &computed_quantities) const
Computes local heat flux vectors.
virtual void evaluate_scalar_field(const DataPostprocessorInputs::Scalar< dim > &inputs, std::vector< Vector< double > > &computed_quantities) const override
Compute local heat fluxes from temperature gradient vector field and thermal conductivity at given ev...
HeatFluxPostprocessor(const std::shared_ptr< ThermalConductivityModel > &p_thermal_conductivity_model, const std::string &p_material_string="f", const unsigned int &p_id=0, const unsigned int &p_mesh_material_id=0, const bool &p_solid_phase_present=false)
Constructor of the heat flux postprocessor.
const unsigned int mesh_material_id
Identifier corresponding to the material as identified in the mesh.
std::shared_ptr< ThermalConductivityModel > thermal_conductivity_model
Model describing of thermal conductivity of the material.
virtual void evaluate_vector_field(const DataPostprocessorInputs::Vector< dim > &inputs, std::vector< Vector< double > > &computed_quantities) const override
Compute the kinematic viscosity of a fluid at given evaluation points.
KinematicViscosityPostprocessor(std::shared_ptr< RheologicalModel > rheological_model, const unsigned int fluid_id=0)
Constructor of the kinematic viscosity postprocessor.
std::shared_ptr< RheologicalModel > rheological_model
Model describing the fluid's rheology.
std::shared_ptr< Shape< dim > > shape
Geometrical entity.
LevelsetGradientPostprocessor(const std::shared_ptr< Shape< dim > > &shape)
Constructor for the level set gradient postprocessor.
virtual void evaluate_vector_field(const DataPostprocessorInputs::Vector< dim > &inputs, std::vector< Vector< double > > &computed_quantities) const override
Compute signed distance gradient of evaluation points with respect to the specified shape.
virtual void evaluate_vector_field(const DataPostprocessorInputs::Vector< dim > &input_data, std::vector< Vector< double > > &computed_quantities) const override
Compute signed distance value of evaluation points with respect to the specified shape.
std::shared_ptr< Shape< dim > > shape
Geometrical entity.
LevelsetPostprocessor(const std::shared_ptr< Shape< dim > > &shape)
Constuctor of the level set postprocessor.
virtual void evaluate_vector_field(const DataPostprocessorInputs::Vector< dim > &input_data, std::vector< Vector< double > > &computed_quantities) const override
Computes the Q-criterion from the velocity vector at given evaluation points.
QCriterionPostprocessor()
Constructor of the Q-criterion postprocessor.
double omega_x
Value of the component of the SRF's velocity.
double omega_y
Value of the component of the SRF's velocity.
virtual void evaluate_vector_field(const DataPostprocessorInputs::Vector< dim > &inputs, std::vector< Vector< double > > &computed_quantities) const override
Compute the Eulerian velocity in a SRF at given evaluation points.
SRFPostprocessor(double p_omega_x, double p_omega_y, double p_omega_z)
Constructor of the single rotating frame SRF postprocessor.
double omega_z
Value of the component of the SRF's velocity.
ScalarFunctionPostprocessor(std::string name, const std::shared_ptr< Function< dim > > scalar_function)
Constructor of the scalar function postprocessor.
std::shared_ptr< Function< dim > > scalar_function
Scalar postprocessing function.
virtual void evaluate_vector_field(const DataPostprocessorInputs::Vector< dim > &input_data, std::vector< Vector< double > > &computed_quantities) const override
Compute the scalar given by the postprocessing function at given evaluation points.
A base class used to represent geometrical entities. Its main uses are to return signed distance and ...
Definition shape.h:53
virtual void evaluate_vector_field(const DataPostprocessorInputs::Vector< dim > &inputs, std::vector< Vector< double > > &computed_quantities) const override
Compute the shear rate at given evaluation points.
ShearRatePostprocessor()
Constructor of the shear rate postprocessor.
VorticityPostprocessor()
Constructor of the vorticity postprocessor.
virtual void evaluate_vector_field(const DataPostprocessorInputs::Vector< dim > &input_data, std::vector< Vector< double > > &computed_quantities) const override
Compute the vorticity vector from the velocity vector at given evaluation points.
@ velocity
Velocity vector field from fluid dynamics.
double calculate_shear_rate_magnitude(const Tensor< 2, dim > shear_rate)
Calculates the magnitude of the shear rate tensor given as input.