Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Visualization for 3D Heater Julia Example #121

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

hammy4815
Copy link

@hammy4815 hammy4815 commented Jan 27, 2024

Hi all. This PR contains my implementation for visualization of the 3D heater. I am using GridapMakie with some extra work around it to make it more readable and allow subplots.

So far, I've added a visualization for the mesh, and plots for the potential, current, temperature, and heat flux. I have also included animations for the transient simulation, but it takes awhile to compute so we may want to keep that part commented out.

Ideally, one would be able to interact with the plot since 3D visuals are nicer when interactive. However, I don't think this is possible in the docs export via Makie without binder or some other way to run a Julia environment live, but happy to be proven wrong here.

@hammy4815
Copy link
Author

These are the plots rendered in the update:

f714742011ecc4e55f4c90392e3e008f9cfc29a9984d5e21452eaa89101e754f
169d1e04d8223951cf03e8c12a406d8dd9e2229100ea9fa6944ead945b4792cf
animation-heatup

If we want cleaner images, we can simply increase the resolution and font size proportionally.

@HelgeGehring
Copy link
Owner

Looks great!
Might using WLGMakie be an option to have it interactive? https://docs.makie.org/stable/explanations/backends/wglmakie/index.html
I'm also wondering if there's a reason, that GridapMakie uses a rather old version of Makie, did you try to just change the version to the current one, maybe it works with little or even no adjustments?

Would be amazing to also have the animation online, let's see how long the docs need to build like this :)
(Checks are now running)

Any idea where those little dots in the Potential-plot are coming from?

@HelgeGehring
Copy link
Owner

Ah, and besides that, could you use pre-commit?

pip install pre-commit
pre-commit install
pre-commit run --all

should format everything :)

@hammy4815
Copy link
Author

Thanks! Yep, in my next commit I'll make sure to fix the formatting with pre commit.

I'm working on getting interactive to work. I've updated (locally) the dependencies for GridapMakie and found no issues with the recipes. I'm working to get the main repo (GridapMakie) updated. Using this, plotting is indeed much faster.

In addition, with the updated Makie related packages, I can get WGLMakie to serve my figures in the examples interactively. Once updated and interactive, several of the strange artifacts in my plots above seem to disappear (including the dots).

When testing the compiled docs, I can serve simple WGLMakie plots, but it seems to struggle for some of my plots in the example. I'm working to settle these issues and then I'll push the changes with hopefully the GridapMakie updates as well.

@HelgeGehring
Copy link
Owner

Wow, that sounds amazing!

Might it make sense to have them as individual plots and not 4 in one? Or would they roatate all the same if you have them in one?

@hammy4815
Copy link
Author

hammy4815 commented Jan 30, 2024

Might it make sense to have them as individual plots and not 4 in one? Or would they roatate all the same if you have them in one?

You can interact with each subplot in the figure individually. So you rotate each plot on its own. But I can also separate them without any trouble if we prefer.

I have discovered there is an issue keeping the interactivity in offline mode for user defined Axis3 objects. It just builds a static axis. User provided LScenes also seem to have problems. However, some returned axis types from various plot routines (like the one in the tutorial, see the 3D surface plot below) seem to work out of the box, so I'm just figuring out what's missing.

@HelgeGehring
Copy link
Owner

Ok, then I'm also fine with having them in one plot, might also look better then all in a row :) However you like it more :)
I just thought that that might be a cause of potential problems, but if it works it's just fine!

@hammy4815
Copy link
Author

hammy4815 commented Feb 17, 2024

I've managed to get the interactive plots working...with a few caveats.

  1. When you rotate the figure, the device rotates, but the axis itself (labels and ticks) does not. There seemed to be backend issues trying to get an LScene working for these systems...the whole figure just disappears whenever you rotate the figure. So I had to stick with an Axis3 and a custom camera. However, there does not seem to be a way yet to get the axis to move with the camera unless you keep the server running.

Personally, I think it looks okay as is, but if we want we can either remove the axis itself or find a way to get the axis to move with the camera.

  1. I could not render subplots without the server running. So, I had to separate the figures into their own blocks. Which is not a big deal.

  2. Some browsers, including Safari, will not render the figures. Chrome seems to work however. The problem seems to be related to the amount of data that is being rendered because I can render just the first few tagged mesh components, but there is a point at which it breaks.

In addition, I'm currently working to get GridapMakie updated before we can allow this PR.

@HelgeGehring
Copy link
Owner

Yay, amazing progress! 🥳

Should we maybe make an issue on Makie.jl about the axis not rotating?

Could we separate the javascript-related code in a second file? I.e. having in the example a using statement, which redefines the display function to separate the javascript-code? Would be good to have the example rather independent of the Makie-backend.
That would also allow to decide on the user side if we want interactive plots or static (the latter one might be good once the models get large. Something like 50M elements might be challenging in the browser, as it would be quite a lot of data to transfer(?))

How large are the files right now? Would it lead to long loading times if it the files need to be downloaded?
If Safari already crashes, it seems it's a lot of data? Then it might be better to stay with this with static images? What do you think?

I'm wondering if there is a way to have optional/docs-only dependencies - having femwell depend on libraries which are for web-development sounds a bit too much (?)

@hammy4815
Copy link
Author

hammy4815 commented Feb 22, 2024

The commit I just made separates the javascript code into a separate file (js.jl). In addition, I created a way to dispatch display so the user can change the backend activated in the script, and then it will swap between interactive and non interactive accordingly.

I'm wondering if there is a way to have optional/docs-only dependencies

There seems to be some progress in allowing the user to specify different dependencies for parts of the repo (such as docs) which require dependencies not used in the main package. Julia already supports this for testing, but there doesn't seem to be a way to generalize this for other areas such as docs yet.

I agree it doesn't make much sense to introduce a bunch of front end packages to the whole repo. One alternative could be an additional Manifest that lives in the docs and is either loaded by just the js.jl module or the docs builder?

How large are the files right now?

The javascript files are a bit large (mostly just in the data that is exported from the FEM cells). The entire js folder which gets build is around 750MB. They build really fast, but they are quite large which is why the browser has trouble rendering the HTML code if the javascript is not kept separate.

Luckily, I found out safari only doesn't render it when I don't disable local file restrictions and cross-origin restrictions. If I disable these two, then it is able to render the data. Thus, there just seems to be some extra restrictions when debugging the scripts I am serving locally. I believe once this is hosted by the docs, since the page is secure, these restrictions will no longer matter for Safari. In other words, there doesn't seem to be any problem with the size of the data, as long as the javascript code is kept outside of the HTML file.

Should we maybe make an issue on Makie.jl about the axis not rotating?

The WGLMakie developers are aware of the Axis3 limitations and are planning on implementing the missing features at some point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants