template <int dim>
class HeatFluxPostprocessor : public DataPostprocessorVector<dim>
{
public:
HeatFluxPostprocessor ()
:
DataPostprocessorVector<dim> ("_k_grad_T",
update_gradients | update_quadrature_points)
{}
virtual void evaluate_scalar_field(
const DataPostprocessorInputs::Scalar<dim> &input_data,
std::vector<Vector<double> > &computed_quantities) const
{
// I recover the value of conductivity
MaterialData<dim> material_data;
const typename DoFHandler<dim>::cell_iterator current_cell = input_data.template get_cell<DoFHandler<dim>>();
FullMatrix<double> conductivity = material_data.get_th_conductivity(current_cell->material_id());
double heat_flux_cell_norm = 0.;
for (auto face_index : GeometryInfo<dim>::face_indices())
{
if (current_cell->face(face_index)->boundary_id() == 2)
{
double long_cell = 0;
long_cell = (current_cell->face(face_index)->vertex(0) - current_cell->face(face_index)->vertex(1)).norm();
for (unsigned int d=0; d<dim; ++d)
{
heat_flux_cell_norm += -conductivity[d][d]*input_data.solution_gradients[face_index][d] *
conductivity[d][d]*input_data.solution_gradients[face_index][d];
}
std::cout << "total heat flux = " << heat_flux_cell_norm << std::endl;
heat_flux_cell_norm *= long_cell;
}
}
Why I could not go further:
The problem is that since the evaluate_scalar_field() loops over the cells internally (I believe. Or is it add_data_vector() ?), I cannot sum my heat_flux_cell_norm double to obtain my integral.
What I tried :
So then I tried creating a separate function in my class HeatFluxPostProcessor and do it myself. This is my best attempt :
void output_heat_flux(const DataPostprocessorInputs::Scalar<dim> &input_data)
{
MaterialData<dim> material_data;
const typename DoFHandler<dim>::cell_iterator current_cell = input_data.template get_cell<DoFHandler<dim>>();
FullMatrix<double> conductivity = material_data.get_th_conductivity(current_cell->material_id());
double heat_flux_tot = 0;
for (current_cell.begin(); current_cell.end(); ++current_cell)
{
double long_cell = 0;
double heat_flux_cell_norm = 0;
for (auto face_index : GeometryInfo<dim>::face_indices())
{
if (current_cell->face(face_index)->boundary_id() == 2)
{
long_cell = (current_cell->face(face_index)->vertex(0) - current_cell->face(face_index)->vertex(1)).norm();
for (unsigned int d=0; d<dim; ++d)
{
heat_flux_cell_norm += - conductivity[d][d]*input_data.solution_gradients[face_index][d] *
conductivity[d][d]*input_data.solution_gradients[face_index][d];
}
}
}
heat_flux_tot += heat_flux_cell_norm * long_cell;
std::cout << "total heat flux = " << heat_flux_tot << std::endl;
}
}