Forum Message



We have moved the forum to . This is an archived version of the topics until 05/05/23. All the topics were moved to the new forum and conversations can be continued there. This forum is just kept as legacy to not invalidate old links. If you want to continue a conversation just look for the topic in the new forum.


The forum is in read only mode.

Help with Example Electrostatics Model

4 years 1 week ago #2555 by mneunteufel
Hi jleman,

if I load the saved mesh in python via
mesh = Mesh('dome.vol')
all boundaries seem to be saved and loaded properly.

for v in mesh.vertices: print(v.point)
you get all mesh points.

If you solve the problem in NGSolve and assume your solution is saved in the GridFunction gfu then you can access data at a point p=(p_x, p_y, p_z) by
value = gfu(mesh(p_x,p_y,p_z))

If you have a CoefficientFunction Q representing the charge density you can get values on the surface by
value = Q(mesh(p_x,p_y,p_z, BND))
Of course the point must be a surface point on the mesh.

If you have the equations by hand I would recommend doing everything in NGSolve via Python.

The following user(s) said Thank You: jleman
1 year 6 months ago #4501 by Yash.sooriya
Hello mneunteufel,

I was wondering if you still have access to this file or you remember how to do this, as it would be very helpful for my current project. Thanks!
1 year 6 months ago #4504 by christopher
This code snippet should solve this problem:
from netgen.occ import * from ngsolve import * air = Sphere((0,0,0), 1) = "air" ground = HalfSpace((0,0,0), (0,0,-1)) = "ground" box = Box((-0.1,-0.1,-0.1), (0.1,0.1,0.1)) = "volt" box.faces.maxh = 0.02 domain = (air * ground) - box geo = OCCGeometry(domain) mesh = Mesh(geo.GenerateMesh(maxh=0.2)) mesh.Curve(3) Draw(mesh) fes = H1(mesh, order=3, dirichlet="ground|volt") u,v = fes.TnT() eps = 1 a = BilinearForm(fes) a += eps * grad(u) * grad(v) * dx u = GridFunction(fes) with TaskManager():     r = u.vec.CreateVector()     a.Assemble()     u.Set(1, definedon=mesh.Boundaries("volt")) = - a.mat * u.vec += a.mat.Inverse(fes.FreeDofs()) * r     Draw(u, mesh, "potential")     Draw(-grad(u), mesh, "E")

Time to create page: 0.145 seconds