You are on page 1of 7

Simulate the Electrostatic Field

YICHANG XU, USTC, China


Electrostatic field simulation is becoming more and more useful in engineering.A common way to solve
electrostatic problems is solving differential equations that fit Poisson equation and boundary conditions. How-
ever,when it comes to complex equations,solving the problem accurately is difficult.This paper proposes some
methods to simulate the electric field in computers numerically.In this paper,we first introduce the simulation
algorithm in the case of point charges and less than 1 conducting sphere with no charges inside,and we build
a simulator using C++.In the case of more complex situations, a simulating method is proposed,however,too
slow to execute on ordinary computers.Then we will introduce Poisson equation and the uniqueness theorem
in electrostatic field,and then we propose an approach to simulate the electrostatic field by using neural
network. After that,we introduce the Ritz method and deduct the finite-element method(FEM),and propose
another method to draw the electrostatic field by using the two theorems above.
Additional Key Words and Phrases: simulation,finite-element method(FEM),neural network,Galerkin method,electrostatic
problems

1 INTRODUCTION space/plain into particles,are always useful.And


Among all the tasks of simulating the electric this paper proposes another approach.It regards
field,the basic and easiest is to simulate the elec- the potential distribution in the plain as a func-
tric field generated by a set of point charges.The tion with two variebles and uses gradient descent
paper[1] proposes a numerical method to do to make it closer to the conditions.Because of the
this.In this paper,we developed a software us- diversified combination of the active function
ing C++ to draw the electric field generated by used in neural network,the distribution function
point charges.And it can also draw the electric will be more flexible than using ordinary FEM.
field generated by point charges and a conduct-
ing sphere with no charges inside by means of The rest of this paper is organized as follows.
electric image method.In case of complex condi- In the next section, we introduce the basic way
tions,however,it’s difficult to use electric image of simulating simple electric field.Then we will
method.For example, it’s not easy to apply elec- introduce Poisson’s equation and prove the
tric image method to calculate the electric field uniqueness of boundary values in electrostatic
distribution when there is a grounded conduct- field.After that,we deduct the electric image
ing ellipse sphere and point charges outside. To method applied in a conducting sphere and a
deal with these problems,this paper proposes a point charge outside. Then we will propose our
method that consumes the plain(or space) filled NN-based method to work out more complex sit-
with point charges (at least in some grids) and uations using electric image method.And we will
the approach is to use machine learning to make introduce the Ritz method and FEM.Finally,we
sure the absolute value of the electric potential at will propose our a more advanced method com-
the edge of the sphere as low as possible.Another pared with the Ritz method and FEM.However
way of solving the problem is by setting up Pois- this method has some limits,we will explain
son’s equation and list out the boundary values them later.
of the electric potential and solve them.There
2 SIMULATION OF POINT CHARGE
are many ways to solve the equations.This pa-
SYSTEM IN A PLAIN
per will introduce the Ritz method.And when it
comes to extremely complex situations,the finite- In the case of such a situation,we can compute
element method(FEM),which aims to divide the the electric field at every point in the plain. For
a given charge q whose coordinate is (𝑥 0, 𝑦0 ),the
Author’s address: Yichang Xu, xuyichang@mail.ustc.edu.cn, USTC, Hefei, China, 230000.

, Vol. 1, No. 1, Article . Publication date: June 2021.


2 Yichang Xu

electric field at point P(x,y) is given by 3 POISSON’S EQUATION AND THE


UNIQUENESS OF BOUNDARY VALUES

− 𝑞(𝑥 − 𝑥 0 ) 3.1 Poisson’s Equation
𝐸 = (𝑘 3
,
((𝑥 − 𝑥 0 + (𝑦 − 𝑦0
)2 )2) 2 The Maxwell’s equations of electric field can be
𝑞(𝑦 − 𝑦0 ) given as
𝑘 3
). →
− 𝜌
((𝑥 − 𝑥 0 ) 2 + (𝑦 − 𝑦0 ) 2 ) 2 ∇· 𝐸 = ,
𝜖0
→−
In case of point charge systems with charges ∇ × 𝐸 = 0.
→−
(𝑥 1, 𝑦1, 𝑞 1 ), ..., (𝑥𝑛 , 𝑦𝑛 , 𝑞𝑛 ), Since 𝐸 = −∇𝑈 ,we can see
→− 𝜌
∇ · 𝐸 = −∇ · ∇𝑈 = −∇2𝑈 = .
→− 𝑞(𝑥 − 𝑥 𝑖 ) 𝜖0
𝐸 = (𝑘Σ𝑛𝑖=1 3
,
((𝑥 − 𝑥𝑖 ) 2 + (𝑦 − 𝑦𝑖 ) 2 ) 2 It can also be written as
𝑞(𝑦 − 𝑦 𝑖 ) ∇2𝑈 = − .
𝜌
𝑘Σ𝑛𝑖=1 3
). 𝜖0
((𝑥 − 𝑥𝑖 ) 2 + (𝑦 − 𝑦𝑖 ) 2 ) 2
This is Poisson’s equation. If 𝜌 = 0,then the for-
To make the graph more accurate,we can nor- mula becomes Laplace’s equation
→−
malize 𝐸 : ∇2𝑈 = 0.
→− 3.2 the Uniqueness of Boundary Values

− 𝐸
𝐸′ = →− .
|𝐸 | Boundary value problems can be divided as the
following 3 types:
The algorithm goes as following: (1) Dirichlet problem:the electric potential
along the whole edge is given.
(1) For each charge,divide the evenly into 12 (2) Neumann problem:the normal derivative
points.Draw the field from each points of the electric potential along the whole
using function DrawFromStart(double edge is given.
x,double y,int q). Set q=1 if the charge is (3) In some parts of the edge,the elec-
positive,or set q=-1,making sure your line tric potential is given,while in other
is going forward. parts,insdead,its derivative is given.
(2) In function DrawFromStart(double
x,double y,int q):If point(int(x),int(y)) is Theorem 1. If a distributing function U satis-
too far away from the screen or the point fies Poisson’s equation and boundary value con-
is in the area of another point charge,stop ditions,then the electric field is unique.In other
the function(return).compute the nor- words,∇𝑈 is unique.
malized electric field by using formula proof.Suppose there are two different solutions
→−
above.Suppose 𝐸 ′ = (𝑥 ′, 𝑦 ′).Then make U and U’.Denote U”=U’-U. Obviously,
the pixel of point (int(x+x’),int(y+y’)) be
black,which indicates the field line.Then ∇2𝑈 ′′ = 0.
call DrawFromStart(x+x’,y+y’,q). Green’s theorem can be written as
∭ ∫∫
 2  →

In case of conducting objects,suppose there ex- 𝜙∇ 𝜓 + (∇𝜙 · ∇𝜓 ) 𝑑𝑉 = ⃝ (𝜙∇𝜓 ) ·𝑑 𝑆
ists small point charges inside,and move one 𝑉 𝑆
charge at the direction of its force each time until Replace 𝜙 and 𝜓 with U”.The formula can be
the charges are in a static balance. However,this written as
∭ ∫∫ ′′
method requires a large computing power of the
(∇𝑈 ′′ 2
) 𝑑𝑉 = ⃝ (𝑈 ′′ 𝜕𝑈 → −𝑛 ) · 𝑑→

𝑆.
computer. 𝑉 𝑆 𝜕𝑛

, Vol. 1, No. 1, Article . Publication date: June 2021.


Simulate the Electrostatic Field 3

For Dirichlet problem,since U”=0 is constantly If the sphere is not grounded,we can as-
true on S,the right part of the equation above is
sume a charge q(equal to the charge out-
0.So ∭ side) at a center of the sphere. In my
(∇𝑈 ′′) 2𝑑𝑉 = 0. C++ program,the electric field is drawn
𝑉 by drawing the field of point charge sys-
′′ ′′
Since (∇𝑈 ) ⩾ 0,∇𝑈 ≡ 0,which means tems.This program can be downloaded at
2

𝑈 − 𝑈 ′ = 𝑐.So the electric field is unique. As http://home.ustc.edu.cn/ xuyichang/share/simulator.


for Neumann problem,according to the condi- And the code can be seen at https://
tion,we can conducting github.com/Kobe972/electric-field-simulator.
𝜕𝑈 ′′ 𝜕𝑈 𝜕𝑈 ′ 4.2 Apply Neural Network to this
= − = 0.
𝜕𝑛 𝜕𝑛 𝜕𝑛 method
It is true on S.Similarly,we can prove that the In this section,we just talk about grounded ob-
right side of Green’s formula is 0 and U-U’=c. jects. We can regard the distribution of image
As for the third situation,we can divide S into charges as function f defined on the plain. f
two parts:𝑆 1 and 𝑆 2 ,which satisfies Dirichlet’s should be near zero outside of the objects.For
and Neumann’s condition respectively. By sep- a certain point in the plain,we can choose some
arating the right side of Green’s formula and representative points and compute f.Then com-
add them again,we can prove that in this situa- pute the electric potential at the edge of the prod-
tion,the uniqueness property still exists. ucts.Similarly,choose some representative points
at the edge of the conducting objects.Then we
4 ELECTRIC IMAGE METHOD
can regard as the average of the square of the
In case of point charges and a conducting ob- electric potential at these points as the objective
ject,we can put some virtual charges on the function. After that,we can optimize this func-
plain,making the electric potential satisfy bound- tion,making it approach 0.One thing we should
ary value conditions.By this way,we can calcu- pay attention to is that since the charge can’t
late the electric field in the plain. be put outside of the conducting objects,the rep-
resentative points on the plain must be chosen
4.1 Apply it To Conducting Sphere inside the conducting objects. Note that the dis-
To be simple,let’s consider a grounded conduct- tributing function is usually not smooth.So RELU
ing sphere and a point charge outside.Denote d are more suitable to be chosen as the active func-
as the distance between the center of the sphere tion of the neural network than sigmoid.
O and the charge q. And the radio of the square
is a.Suppose the image charge is d’ away from 5 THE RITZ METHOD
O and is on the line connecting O and q.On the In this section,we focus on the solution of func-
surface of the sphere,the electric potential is 0. tion
So DΦ = 𝑓 ,
1 𝑞 where D is a differential operator.
𝑈 = (√
4𝜋𝜖0 𝑎 2 + 𝑑 2 − 2𝑎𝑑 cos 𝜃 Definition 1. The inner product of Φ and 𝜓
𝑞′ can be given by:
√ )=0
𝑎 2 + 𝑑 ′2 − 2𝑎𝑑 ′ cos 𝜃

< Φ,𝜓 >= Φ𝜓 ∗𝑑 Ω,
is true for all 𝜃 .Now solve the equation and pay Ω
attention to the fact that the charge must be in- where * indicates the conjunction of a complex
side the sphere.We can solve the position and number. If < DΦ,𝜓 >=< Φ, D𝜓 >,we say that the
quantity of q as differential operator D is self-adjoint. And if for
𝑎2 ′ 𝑎 all Φ,< DΦ, Φ >⩾ 0 and the equality satisfies if
𝑑′ = , 𝑞 = − 𝑞. and only if Φ = 0,we say D is positive definite.
𝑑 𝑑

, Vol. 1, No. 1, Article . Publication date: June 2021.


4 Yichang Xu

If D is positive definite and self adjoint,then In the following part of this section,we will in-
the solution of equation DΦ = 𝑓 can be calcu- troduce them respectively.
lated by minimizing the following formula[2]:
6.1 Division of the area
1 1 1
𝐹 ( Φ̂) = < DΦ̂, Φ̂ > − < Φ̂, 𝑓 > − < 𝑓 , Φ̂ >, The area can be devided into different subar-
2 2 2
eas.The most common method is to divide it
where Φ̂ is a tentative function. In our case,we into simple elements like rectangles,triangles or
suppose Φ is a real function,and assume it can cubes,etc.Most interpolating function are rela-
be written as tive to the nodes of the elements. For example,if
Φ̂ = Σ 𝑗=1𝑐 𝑗 𝑣 𝑗 = c v = v c,
𝑁 𝑇 𝑇 the subarea is a triangle which has 3 nodes,then
the interpolating function can be written as the
where 𝑣 𝑗 are functions defined in the area and 𝑐 𝑗 linear combination of 3 polynomials.
are coefficients. Substituting the equation into
the former equation gives 6.2 Choice of interpolating functions
Denote n as the number of the nodes,Φ𝑒𝑗 as the Φ
∫ ∫
1
𝐹 = c𝑇 vDv𝑇 𝑑 Ωc − c𝑇 v𝑓 𝑑 Ω. value at node j,and 𝑁 𝑗𝑒 is an interpolating func-
2 Ω Ω
tion,which is nonzero inside the unit e while zero
To seek the local minimum of F,we compute the
outside of e. The formation of tentative function
partial derivative of F:
∫ ∫ in e can be given as
𝜕𝐹 1 1
= 𝑣𝑖 Dv𝑇 𝑑 Ωc + c𝑇 vD𝑣𝑖 𝑑 Ω Φ̂𝑒 = Σ𝑛𝑗=1 𝑁 𝑗𝑒 Φ𝑒𝑗 = N𝑒𝑇 𝚽𝑒 = 𝚽𝑒𝑇 N𝑒
𝜕𝑐𝑖 2 Ω 2 Ω
∫ ∫
𝑣𝑖 𝑓 𝑑 Ω 6.3 Institution of the equation system
1 𝑁
= Σ 𝑗=1𝑐 𝑗 (𝑣𝑖 D𝑣 𝑗 + 𝑣 𝑗 D𝑣𝑖 )𝑑 Ω −
2 Ω Ω Denote M as the number of the units.The objec-
= 0 𝑖 = 1, 2, 3, ..., 𝑁 . tive function F can be written as
(1)
It can also be written as 𝐹 ( Φ̂) = Σ𝑚 𝑒=1 𝐹 ( Φ̂ ).
𝑒 𝑒

Using the previous formula,


Sc = b, (2) ∫ ∫
1 𝑒𝑇
where𝑆𝑖 𝑗 = 2 Ω (𝑣𝑖 D𝑣 𝑗 + 𝑣 𝑗 D𝑣𝑖 )𝑑 Ω and 𝑏𝑖 = Ω𝚽 𝑓 N𝑒 𝑑 Ω.
∫ 𝑒 𝑒 𝑒𝑇 𝑒 𝑒𝑇
1 𝐹 = 𝚽 N DN 𝑑 −𝚽
2 Ω𝑒 Ω𝑒
𝑣 𝑓 𝑑 Ω. According to the self-adjointment of

Ω 𝑖 Or rewrite as the matrix formula
D,𝑆𝑖 𝑗 can be rewritten as
1
∫ 𝐹 𝑒 = 𝚽𝑒𝑇 K𝑒 𝚽𝑒 − 𝚽𝑒𝑇 b𝑒 ,
𝑆𝑖 𝑗 = 𝑣𝑖 D𝑣 𝑗 𝑑 Ω. 2
Ω
𝑁 𝑒 D𝑁 𝑗𝑒 𝑑 Ω,and 𝑏𝑖𝑒

where 𝐾𝑖𝑒𝑗 = Ω𝑒 𝑖
=
Φ can be solved by soving equation (2). ∫
𝑓 𝑁 𝑑 Ω. So,
𝑒
Ω𝑒 𝑖
6 FINITE ELEMENT METHOD 1
𝐹 = 𝚽𝑇 K𝑒 𝚽 − 𝚽𝑇 b.
In case of the Ritz method,need to choose an in- 2
terpolating function that at least approaches the To minimuze F,we render the partial derivative
accurate solution.However,in some situations,it of F to Φ𝑖 be 0:
is difficult. To better simulate this situation,we 𝜕𝐹 1
can use the finite element method. The main = Σ𝑁𝑗=1 (𝐾𝑖 𝑗 + 𝐾 𝑗𝑖 )Φ 𝑗 − 𝑏𝑖
𝜕Φ𝑖 2
procedure can be listed as following: (3)
= Σ𝑁𝑗=1 𝐾𝑖 𝑗 Φ 𝑗 − 𝑏𝑖
(1) Division of the area
= 0.
(2) Choice of interpolating functions
(3) Institution of the equation system Or
(4) Solution of the equations K𝚽 = b.

, Vol. 1, No. 1, Article . Publication date: June 2021.


Simulate the Electrostatic Field 5

6.4 Solution of the equations 8 CONCLUSION


The equation system above is a linear,which is Simulating the electric field is a tough anf impor-
easy to solve by using Gaussian Elimination or tant task in many engineering programs. This
other methods like using adjunctive matrix. paper introduced a basic point-charge system
simulator and then introduced some superior
methods,like Poisson’s equation,the unique-
ness theorem of electrostatic field,electric image
method,and the Ritz method,etc. Additionally,we
7 A NEW NN-BASED MODEL proposed some approaches based on machine
In Ritz method,as was said before,the in- learning,which is more flexible and easier to
terpolating function may be difficult to execute.
choose.However,by using full-connected neural
network,you needn’t work hard to choose a Future work needs to propose faster approaches
proper function.We can regard Φ as a function in case of complex situations and also improve
which takes in two or three variables and gen- the speed of neural network. Also,more ap-
erate a scalar. Our objective function is F.After proaches based on machine learning need to
determining the size of latent layers,we can write be proposed,such as approaches using convolu-
out DΦ.Then we can choose some representative tional neural network(CNN),etc.
points in Ω and simulate the effect of differ-
ential.With Pytorch,we can do it easily.As for REFERENCES
FEM,you can train interpolate functions of each [1] [n.d.]. Simulation of Point Charge System in a Plain.
unit.This means that you can choose different Experimental Science and Technology 6 ([n. d.]), 189–191.
[2] T. Broadbent, S. Mikhlin, and T. Boddington. 1965. Varia-
active functions according to the particular situ- tional Methods in Mathematical Physics. The Mathemat-
ation of each unit. Of course,in most scenarios,it ical Gazette 49 (12 1965), 481. https://doi.org/10.2307/
is not required. 3612235

9 APPENDIX
Running effects of my simulator

, Vol. 1, No. 1, Article . Publication date: June 2021.


6 Yichang Xu

Fig. 1. The electric field of point charges and a conducting sphere

, Vol. 1, No. 1, Article . Publication date: June 2021.


Simulate the Electrostatic Field 7

Fig. 2. The electric field with surface charge

, Vol. 1, No. 1, Article . Publication date: June 2021.

You might also like