GLVis / glvis

Lightweight OpenGL tool for accurate and flexible finite element visualization
http://glvis.org
BSD 3-Clause "New" or "Revised" License
249 stars 51 forks source link

Visualization of quadrature functions #286

Closed najlkin closed 1 month ago

najlkin commented 2 months ago

This PR adds support for visualization of quadratures (QuadratureFunction). They can be loaded from a file through the new command line argument -q or in a socket stream with the keyword quadrature (instead of solution). Two options of visualization are offered (which can be switched by Q key):

Note that high-order quadratures are supported only for tensor finite elements with the first two options.

TODO 📑 :

najlkin commented 1 month ago

Unfortunately, there is nothing for high-order quadratures on non-tensor elements. The number of DOFs matches for L2 elements, but the points are different. We would need some special basis for that in MFEM 🤔 .

v-dobrev commented 1 month ago

Unfortunately, there is nothing for high-order quadratures on non-tensor elements. The number of DOFs matches for L2 elements, but the points are different. We would need some special basis for that in MFEM 🤔 .

Using the values at the quadrature points, one can compute a r.h.s vector for a local L2 projection on an appropriate L2 basis. There are probably multiple options for selecting the "appropriate" L2 basis. One possibility is to choose the order of the L2 basis based on the order of the quadrature rule -- e.g. if the quadrature rule is exact for polynomials of degree p, then we project on order p/2 basis -- this will ensure that we get invertible mass matrix if we use the same quadrature rule for the mass matrix as for the r.h.s.

najlkin commented 1 month ago

Well, that would work for sure, but there are many different ways, as you say, so it is less of visualization and more of processing. It might introduce some oscillations and does not necessarily match the quadrature point-wise. Therefore, I am not sure we want that 🤔

najlkin commented 1 month ago

Ok, you convinced me @v-dobrev , that was quick 😄 . I added L2 projection as another option, which is also the fallback for the other two when non-tensor elements are used. The order is the same as with that collocation, so the same number of points, which seems to me as the most logical. As the quadrature points and DOFs are close, the resulting grid function looks fine :wink: .

tzanio commented 1 month ago

I think this is really awesome, thank you for adding it @najlkin! 👍

To speed-up my review: do you have a simple driver to define and visualize a quadrature function and/or sample quadrature function files?

najlkin commented 1 month ago

To speed-up my review: do you have a simple driver to define and visualize a quadrature function and/or sample quadrature function files?

In ex1.cpp, add:

QuadratureSpace qspace(&mesh, order);
QuadratureFunction qf(&qspace);
qf.ProjectGridFunction(x);
ofstream qf_ofs("sol.qf");
qf_ofs.precision(8);
qf.Save(qf_ofs);

and then in the visualization part instead of ...solution... use: sol_sock << "quadrature\n" << mesh << qf << flush; 👍

tzanio commented 1 month ago
najlkin commented 1 month ago

We have a bigger problem here, it cannot pass on Mac suddenly after just changing README and CHANGELOG 🙃

tzanio commented 1 month ago

This is super cool!

Here are the three quadrature data visualization modes for Example 1p on star-q3.mesh

LOR Interpolation Projection
Screenshot 2024-07-17 at 11 58 51 AM Screenshot 2024-07-17 at 11 58 54 AM Screenshot 2024-07-17 at 11 58 58 AM
tzanio commented 1 month ago

We have a bigger problem here, it cannot pass on Mac suddenly after just changing README and CHANGELOG 🙃

The CI is quirky, don't worry about it

tzanio commented 1 month ago

Works in 3D, parallel, etc. too 😁

Screenshot 2024-07-17 at 12 13 08 PM
vladotomov commented 1 month ago

For the LOR case, is there some way to visualize mesh faces differently than internal LOR faces? Maybe draw only the mesh faces?

tzanio commented 1 month ago

For the LOR case, is there some way to visualize mesh faces differently than internal LOR faces? Maybe draw only the mesh faces?

I agree that this will be nice, but I'm not sure it is feasible.

As an alternative, we can give the same element attribute to the LOR elements from the same parent and pull them apart in GLVis:

Screenshot 2024-07-17 at 12 44 49 PM
najlkin commented 1 month ago

For the LOR case, is there some way to visualize mesh faces differently than internal LOR faces? Maybe draw only the mesh faces?

@vladotomov How it works internally is that it converts the quadrature function to grid function before the visualization happens, so there is no way how to do that currently, but it is true I store the original mesh (non-refined), so we could theoretically tunnel the original mesh to the visualization code for the mesh lines one day 😉 But I would not delay this PR and release because of that.

tzanio commented 1 month ago

We have a bigger problem here, it cannot pass on Mac suddenly after just changing README and CHANGELOG 🙃

The CI is quirky, don't worry about it

If you look at the failing Mac screenshots at the bottom of https://github.com/GLVis/glvis/actions/runs/9980266401?pr=286, the zoom level appear a bit different. Maybe something changes in GitHub, but just to double-check: are we sure nothing changed with respect to zoom or keys handling that could cause this?

test fail shifted saved

najlkin commented 1 month ago

I do not believe so, nothing of that sort. Mainly, it was passing, I just changed README and CHANGELOG 😂 (Compare https://github.com/GLVis/glvis/pull/286/commits/226fd1bafe50a2d8b50a1ef8a93a76be607cc8ab and https://github.com/GLVis/glvis/pull/286/commits/597a94479daebdc8e5aa9a7cc5812c4eec78bde6)

tzanio commented 1 month ago

It could be a change in GitHub's mac version or something.

Just to triple-check, can you try some of the tests from https://github.com/GLVis/data/tree/53fbee222cceb0581122cb72518bfc1b85766b4e with master and this PR and make sure the images are the same size?

najlkin commented 1 month ago

I do not have a Mac and on Ubuntu it passes.

tzanio commented 1 month ago

I do not have a Mac and on Ubuntu it passes.

Good point 😄

I manually re-run all the test in this PR and in #483 (which passed before)... Let's see what happens

najlkin commented 1 month ago

And now someone tell me how a text file can break a code on Mac and only with CMake 😂

najlkin commented 1 month ago

Btw, I am close to implementing that @vladotomov 's suggestion. The difficult part was not the tunneling the mesh, but mixing the meshes together in 2D, where the surface is lifted by the values on the refined mesh, but I have solved that. So like in an hour I may have it 😉 .

tzanio commented 1 month ago

Looks like https://github.com/GLVis/glvis/pull/286/commits/f25e99eb03776702991b9d88ac95cb44a1282c61 fixed the CI

tzanio commented 1 month ago

Here is the above picture with the mesh drawn as @vladotomov suggested

Screenshot 2024-07-18 at 4 45 54 PM
tzanio commented 1 month ago

I like the latest changes @najlkin, re-approving 👍

najlkin commented 1 month ago

Wait for 3D 😮 😎

justinlaughlin commented 1 month ago

Looks very cool! Just curious, is there a way to toggle back and forth between quadrature function / grid function or is it one or the other? I naively tried doing both but it didn't like that.

./glvis -np 8 -m ../mfem-parallel/examples/mesh -g ../mfem-parallel/examples/sol -q ../mfem-parallel/examples/sol_qf

I see a lot of nice refactoring work here too like with the enum :).

najlkin commented 1 month ago

Nice to hear @justinlaughlin , you need to choose what you want to visualize - a grid function or quadrature function. If you have a bit of time, please test different options, like dimensions, vector/scalar, shadings, ...

najlkin commented 1 month ago

Ok, I think I am done 🙌 . There is 3D scalar/vector visualization of original quadrature mesh lines, including element-wise cutting plane (cplane=2) 😉 Flat cutting plane (cplane=1) would be difficult and I will leave it for some other day.

justinlaughlin commented 1 month ago

Nice to hear @justinlaughlin , you need to choose what you want to visualize - a grid function or quadrature function. If you have a bit of time, please test different options, like dimensions, vector/scalar, shadings, ...

Forgot to mention I tried some things using ex1: different meshes, mesh refinement, function space order, serial/parallel, shadings, stream/command line; I saw no issues. I can test it out more but it would be next week. Looks good to me!

justinlaughlin commented 1 month ago

oh, forgot to mention I tested on WSL2 ubuntu 20.04

tzanio commented 1 month ago

Very cool, thanks @najlkin!!

Screenshot 2024-07-19 at 1 07 25 PM