# NTNUJAVA Virtual Physics LaboratoryEnjoy the fun of physics with simulations! Backup site http://enjoy.phy.ntnu.edu.tw/ntnujava/

## JDK1.0.2 simulations (1996-2001) => Electromagnetics => Topic started by: computer on October 17, 2009, 03:05:21 am

 Title: divergence modeling Post by: computer on October 17, 2009, 03:05:21 am Hi,people.My question is about finite difference modeling of EM fields.Exist some methods to force numeric divergence be zero,not changing too much the overall field picture?Like [E(x+dx,y,z) - E(x-dx,y,z)] / dx + [E(x,y+dy,z) - E(x,y-dy,z)] / dy + [E(x,y,z+dz) - E(x,y,z-dz)] / dz = 0.Theoretically Maxwell equations maintain divergence stable,but numeric errors accumulate.Or it maybe necessary setting initial field state.Thanks in advance. Title: Re: divergence modeling Post by: Fu-Kwun Hwang on October 17, 2009, 10:25:25 am The equestion you wrote is first order Euler's method for no free charge case.You can modify it to second order differential method (use potential V)$\frac{\partial^2 V}{\partial x^2}+\frac{\partial^2 V}{\partial y^2}+\frac{\partial^2 V}{\partial z^2}=0$and use relazation method (change to boundary value problem) to find the solution for V. Then calculate Ex,Ey,Ez from V. Title: Re: divergence modeling Post by: computer on October 21, 2009, 06:33:12 pm As I'd understood,you propose convert vector field into scalar (easy to smooth),and vice versa.But from no charge electric field we can not restore potentials unequivocally.It can be closed,circular. Title: Re: divergence modeling Post by: Fu-Kwun Hwang on October 21, 2009, 08:26:11 pm I will try to help if you can describe your problem in more detail (all the background information).Otherwise, I do not know how to help. Title: Re: divergence modeling Post by: computer on October 22, 2009, 08:55:25 pm I use model for dynamic field visualization,so calculations must be fast,not like solution of equations system.Field represented as structure of double-precision values,three for electric vector Ex,Ey,Ez,and three for magnetic Hx,Hy,Hz.Time step (dt) is equal to distance step (dl) divided by velocity of light (c).Rectangular block of points.Finite-difference like algorithm calculates new vector valuesafter time step,like Ex += [dt * K] * [[Hz(x,y+dy,z) - Hz(x,y-dy,z)] / [2 * dy]- [Hy(x,y,z+dz) - Hy(x,y,z-dz)] / [2 * dz]] with some factor K following from Maxwell equations(background equation dEx/dt = K * [dHz/dy - dHy/dz]).The main problem arisestrying to zero divergence,as in real-world fields.For example,setting initial conditionswe wish to connect two regions described by different analytic functions.It is difficult do it "manually" for each case.I seek an universal algorithm.Seems I need rather some programming trick then deep scientific explanation.Scalar fields are smoothed easily,but voluntary electric field we can not represent as some gradient.