Electrostatic Examples for NGSolve Beginners

More
4 years 7 months ago #2590 by jleman
Gauss's law applied at the surface can be used to calculate surface charge density. The resulting equation is the dot product of the Electric field vector and surface normal vector at the surface of interest. How would I correct the following code to implement that at the "top" surface defined in bnd_verts?
Code:
Emag = set() #electric field magnitude array for vert in bnd_verts: #bnd_verts contains the mesh vertices of the "top" boundary (see above reply) n = specialcf.normal(mesh(*vert.point)) #surface normal at each of the vertices in "top"? Emag.add(InnerProduct(n,E(mesh(*vert.point)))) #dot product between normal,n and electric field, E? print(Emag)
More
4 years 6 months ago #2592 by mneunteufel
Hi jleman,

the constructor of the specialcf.normal needs the dimension. Then it can be evaluated
Code:
n = specialcf.normal(2) value = n(mesh(*vert.point))
However, on the corner the normal vector may direct into the wrong direction (e.g. to the right instead to the top on the top right corner). It is better to directly use n=(0,1)
Code:
n = (0,1) for vert in bnd_verts: E_p =E(mesh(*vert.point)) Emag.add(n[0]*E_p[0]+n[1]*E_p[1])

Best
Michael
The following user(s) said Thank You: jleman
More
4 years 6 months ago - 4 years 6 months ago #2594 by christopher
You can as well multiply the functions and evaluate the product:
Code:
Emag = InnerProduct(E, n)
and then evaluate Emag at boundary points:
Code:
Emag_vals = Emag(mesh(*bnd_verts, BND)))
Note that the BND flag gives you a boundary mesh point, which is needed to evaluate the normal vector.
Best
Last edit: 4 years 6 months ago by christopher.
The following user(s) said Thank You: jleman
Time to create page: 0.091 seconds