# Drawing mesh and Generating ellipsoid

Hello, everyone!

I just successfully installed NGSolve in my laptop.

I’m trying to run examples on the documentation.

However, I have some questions.

1. After importing ngsolve.webgui,
I’d like to draw (or plot) the mesh in “new window (or pop-up window)”.
How can I do this?

2. I have information about ellipsoid.
(e.g., xyz coordinates, diameters, and euler angles)

I’d like to generate
“the ellipsoids (particles) based on the information” + “matrix (electrolyte) for the rest of space”
which documentation would be helpful for me in this case?

Sincerely,
Hokon Kim

You cannot start a webgui object in a popup window (Matthias, some quick hack ?)

You can use a general transformation from OCC to create an ellipsoid from a sphere:
(see gp_GTrsf Class Reference - Open CASCADE Technology Documentation)

``````sp = Sphere( (0,0,0), 1)
gtr = gp_GTrsf( (1,0,0, 0,1,0, 0,0,2), (0,0,0))
ell = gtr (sp)
Draw (ell);
``````

Joachim

Hello Hokon!

To open a webgui in a separate tab, you can generate an `.html` file and open it using the `webbrowser` python module:

``````import webbrowser
from netgen.occ import *
from netgen.webgui import Draw

sp = Sphere( (0,0,0), 1)
gtr = gp_GTrsf( (1,0,0, 0,1,0, 0,0,2), (0,0,0))
ell = gtr (sp)
Draw (ell, filename="ell.html");

webbrowser.open("ell.html")
``````

I tried to copy and paste the codes in my laptop.

But, the opened webbrowser didn’t show me the result.

Also, what I would like to output the result mesh in the pop-up window and not showing result in my local jupyter notebook.

In other words, I want to output the result ONLY in the new window.

Is this possible? If yes, please let me know the way.

The following is working on Linux and Mac, didn’t test it on Windows yet:

``````import os.path
webbrowser.open("file://" + os.path.abspath("ell.html"))
``````

If it’s still not working: Which system are you using?

To generate the `.html` without drawing it in jupyter you can use the following code:

``````from ngsolve.webgui import WebGLScene
WebGLScene(mesh).GenerateHTML(filename="ell.html")
``````

Best,
Matthias

I tried the code below, first.

``````import os.path
import webbrowser
from netgen.occ import *
from netgen.webgui import Draw
from ngsolve.webgui import WebGLScene

sp = Sphere( (0,0,0), 1)
gtr = gp_GTrsf( (1,0,0, 0,1,0, 0,0,2), (0,0,0))
ell = gtr (sp)

WebGLScene(mesh).GenerateHTML(filename="ell.html")
Draw (ell, filename="ell.html")
webbrowser.open("file://" + os.path.abspath("ell.html"))
``````

However, error message was popped up. In this case, “mesh” was not defined yet.
My operating system is Windows 11 and I use Jupyter notebook via Visual Code.

While waiting the reply, I was finding out how to do what I wanted.
Here are the code currently I compromised. I use “Netgen GUI”.
Inside of Interactive mode(webgui) in Visual Code, I cannot specify what I want easily.
By introducing “clear_output” command, after generating the microstructure, the result will not be shown in the interactive mode and I will be able to see the result via Netgen GUI window.

``````from netgen.csg import *
from ngsolve.webgui import Draw
from IPython.display import clear_output
import netgen.gui

geo = CSGeometry()
sphere1 = Sphere(Pnt(0,0,0),0.5)
sphere2 = Sphere(Pnt(1,1,1),1)
# "maxh" arguments specifies the desired maximal global mesh-size.

ngmesh = geo.GenerateMesh(maxh=2)

# for visualization we need a NGSolve mesh
from ngsolve import Mesh
Draw(Mesh(ngmesh))
clear_output()
``````

I have another question.

gp_GTrsf( (1,0,0, 0,1,0, 0,0,2), (0,0,0))
Inside of gp_GTrsf, what does mean (1,0,0, 0,1,0, 0,0,2) and (0,0,0)?

Even in the document about “gp_Gtrsf Class Reference”, I cannot understand easily what it means.

This is meant to be like this (WebGLScene substitutes the Draw call):

``````import os.path
import webbrowser
from netgen.occ import *
from netgen.webgui import Draw, WebGLScene

sp = Sphere( (0,0,0), 1)
gtr = gp_GTrsf( (1,0,0, 0,1,0, 0,0,2), (0,0,0))
ell = gtr (sp)

WebGLScene(ell, None, None).GenerateHTML(filename="ell.html")
webbrowser.open("file://" + os.path.abspath("ell.html"))
``````

Edit: Fixed the code (again)

When trying the code latter, I got the message like above.

Sorry, I copied the wrong code above (in both postings):

``````WebGLScene(ell, None, None).GenerateHTML(filename="ell.html")
``````

There was still an issue with the code above (WebGLScene from netgen and ngsolve have different interfaces, we will clean this up soon).
Please try the code again (I edited it).

Best,
Matthias

With the modified code above, after running the code I was able to see the output html file.

When I open the html file, I can see the output (ellipsoid).

Thank you!