PRISMS-PF Manual
Loading...
Searching...
No Matches
integrator.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: © 2025 PRISMS Center at the University of Michigan
2// SPDX-License-Identifier: GNU Lesser General Public Version 2.1
3
4#pragma once
5
6#include <deal.II/dofs/dof_handler.h>
7#include <deal.II/fe/fe_values.h>
8#include <deal.II/lac/la_parallel_vector.h>
9
11
12#include <prismspf/config.h>
13
14#include <vector>
15
17
21template <unsigned int dim, unsigned int degree, typename number>
23{
24public:
25 using VectorType = dealii::LinearAlgebra::distributed::Vector<number>;
26
27 template <int rank>
28 static dealii::Vector<number>
29 integrate(const dealii::DoFHandler<dim> &dof_handler, const auto &solution_vector)
30 {
31 constexpr unsigned int expected_components =
32 dealii::Tensor<rank, dim>::n_independent_components;
33 Assert(dof_handler.get_fe().n_components() == expected_components,
34 dealii::ExcMessage("The provided DoFHandler does not have the same number of "
35 "components as the expected ones. For scalar fields there "
36 "should be 1 component."));
37
38 // Update ghosts
39 solution_vector.update_ghost_values();
40
41 // Set quadrature rule and FEValues to update the JxW values
42 dealii::FEValues<dim> fe_values(dof_handler.get_fe(),
44 dealii::update_values | dealii::update_JxW_values);
45
46 // Get the number of quadrature points
47 const unsigned int num_quad_points = SystemWide<dim, degree>::quadrature.size();
48
49 // Create a value vector
50 std::vector<dealii::Vector<number>> quad_values(num_quad_points,
51 dealii::Vector<number>(
53
54 // Loop over the cells provided by the DoFHandler
55 dealii::Vector<number> value(expected_components);
56 for (const auto &cell : dof_handler.active_cell_iterators())
57 {
58 if (cell->is_locally_owned())
59 {
60 // Reinitialize the cell
61 fe_values.reinit(cell);
62
63 // Get the values
64 fe_values.get_function_values(solution_vector, quad_values);
65
66 // Sum up the product of the JxW and values at each quadrature point to
67 // compute the element integral.
68 for (unsigned int q_point = 0; q_point < num_quad_points; ++q_point)
69 {
70 for (unsigned int component = 0; component < expected_components;
71 component++)
72 {
73 value[component] +=
74 quad_values[q_point][component] * fe_values.JxW(q_point);
75 }
76 }
77 }
78 }
79
80 for (unsigned int component = 0; component < expected_components; component++)
81 {
82 value[component] = dealii::Utilities::MPI::sum(value[component], MPI_COMM_WORLD);
83 }
84 return value;
85 }
86};
87
Compute the integral of a given field.
Definition integrator.h:23
static dealii::Vector< number > integrate(const dealii::DoFHandler< dim > &dof_handler, const auto &solution_vector)
Definition integrator.h:29
dealii::LinearAlgebra::distributed::Vector< number > VectorType
Definition integrator.h:25
This is the main class that handles the construction and solving of user-specified PDEs.
Definition system_wide.h:24
@ Value
Use value of the variable as a criterion for refinement.
Definition grid_refiner_criterion.h:31
Definition conditional_ostreams.cc:20