How to access variables in the postprocessor object

63 views
Skip to first unread message

Raúl Aparicio Yuste

unread,
Dec 12, 2022, 10:01:53 AM12/12/22
to deal.II User Group

It is not clear to me how to access an object in the structure “Postprocessor”. The idea is that I compute the solution, but I am also computing secondary variables using the postprocessor structure in this way:

dealii::DataOut<dim> data_out;

data_out.attach_dof_handler(dof_handler);

Postprocessor postprocessor;

data_out.add_data_vector(solution, postprocessor);

data_out.build_patches();

When declaring the postprocessor class, I declare a function evaluate_vector_field where I compute all the secondary variables that are written on a vtk file later:

void evaluate_vector_field(const dealii::DataPostprocessorInputs::Vector<dim>& input_data, std::vector<dealii::Vector<double>>& computed_quantities) const override;

                …..

    for (int q = 0; q < n_q_points; ++q) {

        // Displacements

        computed_quantities[q](0) = input_data.solution_values[q](0);

        computed_quantities[q](1) = input_data.solution_values[q](1);

        // Stress

        computed_quantities[q](2)  = sigma_x

        computed_quantities[q](3)  = sigma_y

    }

These variables are saved on the data_out object, so I use “data_out.write_vtk(output);” and I get them on the vtk file. However, I do not know how to access to these new variables (computed_quantities) from another file different from the one where I declare the functions.

The function evaluate_vector_field is a virtual function, and it is declared as const override. I do not know how to export the variables computed_quantities or modify them, because it is only allowed to read them since the function is declared as constant. Is there any way to access the structure postprocessor? Something like:

postprocessor.getVariables(xxxxxxxx)

Or an example where I can see how to implement it. Thank you very much in advance

Raul

Jean-Paul Pelteret

unread,
Dec 12, 2022, 11:37:00 AM12/12/22
to dea...@googlegroups.com
Hi Raul,

The “input_data” argument to the evaluate_vector_field() function has a method that can be called to retrieve the cell that is currently being processed:

Since you are defining your own data post processor, you are in control over what information from your simulation it has access to. You could therefore pass it the necessary data (or data structures) from the calling class in order to map the cell (+ evaluation point?) to the constitutive law that could be used to evaluate the stress in terms of the strain.

I hope that this helps!

Best,
Jean-Paul

--
The deal.II project is located at http://www.dealii.org/
For mailing list/forum options, see https://groups.google.com/d/forum/dealii?hl=en
---
You received this message because you are subscribed to the Google Groups "deal.II User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dealii+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dealii/d9a60280-0181-427b-a372-2eee29ab3257n%40googlegroups.com.

Wolfgang Bangerth

unread,
Dec 12, 2022, 7:05:13 PM12/12/22
to dea...@googlegroups.com
On 12/12/22 08:01, Raúl Aparicio Yuste wrote:
> These variables are saved on the data_out object, so I use
> “data_out.write_vtk(output);” and I get them on the vtk file. However, I do
> not know how to access to these new variables (computed_quantities) from
> another file different from the one where I declare the functions.
>
> The function evaluate_vector_field is a virtual function, and it is declared
> as const override. I do not know how to export the variables
> computed_quantities or modify them, because it is only allowed to read them
> since the function is declared as constant. Is there any way to access the
> structure postprocessor? Something like:
>
> postprocessor.getVariables(xxxxxxxx)
>
> Or an example where I can see how to implement it. Thank you very much in advance
>

Raul -- in addition to J-P's answer, start by explaining *what* it is you want
to do, not *how* you want to do it. Do I understand right that you want to use
what the DataPostprocessor computes in other parts of the program as well? If
so, why? Are you trying to solve a nonlinear system and you want to reuse the
computed stress for other computations?

Best
W.

--
------------------------------------------------------------------------
Wolfgang Bangerth email: bang...@colostate.edu
www: http://www.math.colostate.edu/~bangerth/


Raúl Aparicio Yuste

unread,
Dec 14, 2022, 3:29:10 AM12/14/22
to deal.II User Group

Hi Jean-Paul and Wolfgang,

Exactly, I would like to use what my DataPostprocessor computes in other parts of the programme.

Here my problem:

In my postprocessor, I compute stresses and principal stresses for all quadrature points (to give you the context, I am using quad elements with 4 quadrature points. The stress is constant for each cell/element as I am using quadratic functions for the displacement. I am solving a plane stress problem, isotropic elastic material). Principal stresses can be also computed.

So, for each element, I get the same principal stress at the 4 quadrature points (they are constant for each element). If I plot them, I get the following in Paraview (see screenshot.PNG)


Shared vertices with different principal stress components of different elements. To solve this, I would like to get the value of the principal stress of each element and plot it in the centre of the element, so that I can draw the arrow with the principal stress direction. For this I need the coordinates of the centre of the element and the value of stress. I do not know how to export these variables in other parts of the programme, so I can build the paraview file to plot that.

I still struggle to understand some of the c++ structures and how they can be accessed in the virtual functions of the dealii library.

I hope my problem is a little clearer now, thank you!!!

Raúl

screenshot.PNG

Wolfgang Bangerth

unread,
Dec 14, 2022, 11:56:39 AM12/14/22
to dea...@googlegroups.com

Raul:

> Exactly, I would like to use what my DataPostprocessor computes in other parts
> of the programme.

This is not the right approach. DataPostprocess is used to put derived
quantities into output files, not to compute data that can then be used in
other parts of the program. For what you want to do, you need to compute these
derived quantities at each quadrature point whenever you need it -- that's
exactly what step-15 does, for example.


> In my postprocessor, I compute stresses and principal stresses for all
> quadrature points (to give you the context, I am using quad elements with 4
> quadrature points. The stress is constant for each cell/element

This is unrelated to your actual question, but it's worth pointing out that it
is not true that the stress is constant. It *is* constant on triangles if you
use linear elements because then the gradient of the solution is constant. But
on quadrilaterals, the gradient of the solution is *not* constant, and so the
stress is not constant on each cell in general unless your solution happens to
be globally linear.

Raúl Aparicio Yuste

unread,
Dec 16, 2022, 5:24:45 AM12/16/22
to deal.II User Group

Hi Wolfgang,

Thank you for pointing that out. I was wrong because I thought that what happens with 1-D is the same as in 2-D, and that’s not true.

I will try to think again how I solve the problem and the structures related to it. Thank you for the suggestions!!

Best

Reply all
Reply to author
Forward
0 new messages