Upload
doandang
View
217
Download
3
Embed Size (px)
Citation preview
1
Visualizing the Physical Phenomena for Computational Science
with MATFORMATFOR®® 44
Liger Chen AnCAD Inc.
2
Outline
Introduction to MATFOR®
MATFOR® Functions
Cases Using MATFOR®
Visualization of Physical Problem
by MATFOR®
3
Introduction to MATFOR®
4
What’s MATFOR® ?
� MATFOR® is a new generation graphics library fully exploiting the
modules and the array features of Fortran 90/95 and C++ languages.
� MATFOR® is a collection of high-level graphical procedures
developed with the mission of reducing time spent on the program
development.
� MATFOR® is a set of numerical and visualization
libraries especially designed for programmers in
scientific computing field.
5
MATFOR® Structure
MATFOR®, a set of numerical and visualization libraries, is
developed to enhance programming in C++ and Fortran
environments. Especially designed for scientists and engineers,
MATFOR® fulfills the needs of speed and advanced visualization
capabilities simultaneously.
MATFOR
Graphics LibraryGraphics Library Numerical LibraryNumerical Library
VTK OpenGL Intel MKL
6
Numerical Library
Based on Intel® MKL, the numerical library contains over 200 easy-to-use numerical functions subject to assist users with computational problem-solving.
– Data Manipulation Functions: mfSort, mfMin, mfMax, …
– Elementary Math Functions: mfSin, mfCos, mfASin, mfExp, mfAbs, …
– Elementary Matrix-Manipulating Functions: mfEye, mfDiag, mfRand, mfZeros, …
– Matrix Analysis: mfEig, mfInv, mfSvd, mfQz, mfLu, mfDet, mfNorm, …
– Sparse Array:
msSpAdd, msSpSet, mfSpNNZ,mfSpLDiv,…
– File IO: mfSave, mfSaveAscii, mfLoad, mfLoadAscii, …
7
Graphics LibraryVisualization Modules I
surf mesh
plot
plot3
contour contour3
quiverquiver3
trimesh trisurf
pcolor molecules
surf mesh
solidcontour
8
Graphics LibraryVisualization Modules II
ribbon
contour3 solidconour3 molecule image
tetmesh tetcontour tetisosurface cube, sphere, …
slicesisosurface tube
tricontour
tetsurf
streamline
9
What Does MATFOR® Do?
By adding few lines of By adding few lines of
MATFORMATFOR®® codes to codes to
your Fortran/C/C++ your Fortran/C/C++
program, you can easily program, you can easily
visualize your visualize your
computing results, computing results,
performperform runrun--timetime
animations, or even animations, or even
produce an interactive produce an interactive
movie presentation as movie presentation as
you execute your you execute your
program.program.
…
call msSurf(x)call msDrawNow
10
MATFOR® Functions
11
MATFOR® Dynamic Array ImfArray Overview
mfArray is an advanced dynamic array defined by MATFOR® using
modern features of C++ and Fortran 90/95. The mfArray data type
consists of descriptors and values.
Values
2(3,3)
9(3,2)
4(3,1)
7(2,3)
5(2,2)
3(2,1)
6(1,3)
1(1,2)
8(1,1)
Descriptors
•Data Type
•Shape
•Status Flags
mfArray
12
MATFOR® Dynamic Array IImfArray Feature
A key to integrate MATFOR® toolkit into high-level
programming environments
� Automatic data typing and dimensioning
� Dynamic memory allocation
� Simple calling routines with Matlab-like syntax
type(mfArray)::x,y
x = mfMagic(5)
y = mfInv(x)
mfArray x,y;
x = mfMagic(5);
y = mfInv(x);
FortranC/C++
Construct and initialize the mfArray
13
Simple Using Mathmatical functions
� Calling msSVD in MATFOR® to perform singular value decomposition gives the same result as calling DGESVX in LAPACK. However, MATFOR® function only takes 3 pre-initialized parameters while LAPACK function takes 22 pre-initialized parameters.
Call DGESVX( FACT, TRANS, N, NRHS, A, LDA, AF, LDAF, IPIV, EQUED, R, C,
B, LDB, X, LDX, RCOND, FERR, BERR, WORK, IWORK, INFO ) LAPACK
Call msSVD( mfOut(A, B), C )
MATFOR
� Besides its simple and powerful visual functions, MATFOR® enables scientists and engineers to code in Matlab fashion using the simple calling concept in Fortran and C++ environments.
MATFOR a = mfInv(x) e = mfEig(x)
MATLAB a = inv(x) e = eig(x)
14
• Solving the symmetric tridiagonal matrix problem :
subroutine tridib(n,eps1,d,e,e2,lb,ub,m11,m,w,ind,ierr,rv4,rv5)
lamda= w LAPACK
eps1,lb,ub ,m11 , lb ,eps1,lb,ub ,m11 , lb ,eps1,lb,ub ,m11 , lb ,eps1,lb,ub ,m11 , lb ,indindindind , , , , ierrierrierrierr ,rv4 ,and rv5 = ????,rv4 ,and rv5 = ????,rv4 ,and rv5 = ????,rv4 ,and rv5 = ????
lamda = mfEig(x)MATFOR
(this eigsystem problem maybe be the reduction of a 2nd order differential equation
0))(()()(2
2
=−++ yxcdx
dyxb
dx
ydxa mλ
1,,1
2
1
2
1
,1,
,1
2,3
3,22,21,2
2,11,1
00
0
00
0
00
++
−
−
=
=
pppp
nnnnnn
nn
CC
y
y
y
y
y
y
CC
C
C
CCC
CC
M
M
M
M
L
OOM
OO
M
L
λ
15
Real-Time Animation
MATFOR® features real-
time program-monitoring mechanism to reduce time and effort spent on
post-processing and
debugging.
• MATFOR presenting simulation while calculating the data.
The simulation can be
presented as an animation
while the calculation is
proceeded and shown in
the console window.
16
MATFOR® Sample Code3D Presentation
program main
use fmluse fgl! Declare mfArray variablestype(mfArray) :: x, y, z
! Construct grid matrices for 3D plotcall msMeshgrid(mfOut(x, y), mfLinspace(-3,3,30), mfLinspace(-3,3,30))! Calculate Z valuez = mfSin(x) * mfCos(y) ! Plot surfcall msSurf(x,y,z)! Display the graphcall msViewPauseend program demo codes • MATFOR presents standalone
executables.
• MATFOR Standalone Executables
EXE
17
MATFOR® Sample CodeMovie Presentation
program main
use fmluse fgl
type(mfArray) :: x, y, z, h ! Declare mfArray variablesinteger(4) :: I ! Declare an integer variable
! Construct grid matrices for 3D plotcall msMeshgrid(mfOut(x, y), mfLinspace(-3,3,30), mfLinspace(-3,3,30))call msRecordStart('demo.avi') ! Begin AVI recording
do i=1,50 ! Do loopwrite (*,*) 'step=', iz = mfSin(x+i/8.0d0) * mfCos(y) ! Calculate Z valueif (i==1) then ! Initialize handle
h = mfSurf(x, y, z)call msDrawNow
elsecall msGSet(h, 'zdata', z) ! Update Z valuecall msDrawNow
end ifend do
call msRecordEnd ! End recordingcall msViewPause ! Pause to display the graph
end program
demo codes
• Viewing the recorded AVI file with media player.
• Movie FilesAVI
18
Runtime Data Manipulation
MATFOR® allows manipulation of the data displayed during execution; data can be examined with higher precision and customization at
runtime.
• Data Viewer• Graphics Viewer
19
Data Viewer
Snapshot Panelcaptures the snapshot of
the distribution and size of
the two dimensional data.Analysis Panel
shows the distribution of
the data including its
average, standard
deviation and min/max
values.Filter Panel
defines a range using
conditions of inequalities.
MATFOR® Data Viewer is a powerful tool that displays simulating data in a
spreadsheet format.
• Snapshot Panel
• Analysis Panel
• Filter Panel
20
Supported Data File Formats
MATFOR 4 supports common software data formats and 3-D object formats to enhance the reusability and interchangeability of data.
– Matlab
– Tecplot
– 3DS, OBJ, and STL
21
Graphics Viewer
MATFOR® Graphics Viewer provides a full range of graphical editing
procedures which can be manipulated directly using the menu and the toolbar.
• Axis Setting Editor • Colormap Setting Editor
• Material Setting Editor
22
Enhanced Graphics Viewer(Full-Screen Function)
The full-screen function allows users to view and/or present data at full screen. This function also serves to eliminate the context for on-screen data capturing and printing.
• Use the button indicated to show the graphs in full screen mode
Full Screen Mode
23
MATFOR® mfPlayerAn exclusive Visual Tool
mfPlayer is an exclusive visual tool by which the previously saved numerical data is read and displayed as an interactive movie presentation. As MATFOR® saves the simulated data into a MATFOR®-defined MFA file, mfPlayer is one approach to present the recorded animation. The complete video clip can then be viewed from different angles.
� resize
� rotate
� zoom
� pause
� forward
� reward
� view data
� change colormaps
• mfPlayer
• Data Viewer
24
mfPlayer Standalone
� Currently, the proprietary format dominates in most
visualization tools generates files that can only be executed on one specific application.
� MATFOR® possesses the ability to convert visualization files into standalone executables.
� Through the conversion, data sharing and publishing become much easier.
Compiling and linking the programs with MATFOR library.
Running compiled executables without installing MATFOR.
25
MATFOR® GUI Builder
MATFOR® GUI Builder allows users to customize an interface of their own; the interface can be saved into a MFUI file (based on XML format).
• MATFOR GUI Builder
MFUI
26
MATFOR® GUI System (An Use Case)
btnSurf1
!////////////////////////////////////////////////////////////!// MxUI Callback BEGINsubroutine btnSurf_Click(sender)use fmluse fgluse mxui
CHARACTER(*) :: senderinteger :: kindtype(mfArray) :: x, y, zexternal btnClose_Click
call msFigure()kind = mfUIGetPropertyInteger( sender, 'tag' )call msCreateSurfData( mfOut(x,y,z), mf(kind), mf(30), mf(30) )call msSurf(x,y,z)call msDrawNow
end subroutine btnSurf_Click
!// MxUI Callback END!////////////////////////////////////////////////////////////
Actor
Application
Click
• How does the communication work between the user and the application?
UI Engine
27
Cases Using MATFOR®
AnCAD Incorporated
28
Applied Fields
Solid Mechanics
Fluid Dynamics
Astrodynamics
Electromagnetic Analysis
Heat Transfer and Geology Analysis
Optical propagation
Molecular Dynamics
29
Thin-plate Vibration Analysis
(Data courtesy of Yuan-Sen Yang, National Center for Research on Earthquake Engineering)
Force Impulse
Fixed Boundary
Plate
Displacement
Speed
Acceleration
Stress
30
(Data courtesy of Professor Edward C. Ting/Chih-Cheng Lin, National Central University)
Simulation of the nonlinear, nonconsecutive destructive phenomenon of the dam structure based on the finite element method.
Destructive External Force
Elastic Material
3D Co-rotational Explicit Finite Element Analysis
31
Structural Earthquake Response
Beam Structure
Observation PointDisplacement
Moment
(Data courtesy of Professor Yuan-Sen Yang, National Center for Research on Earthquake Engineering)
32
(Data courtesy of Professor Edward C. Ting/Yeh-Chan Lin/Chih-Cheng Lin, National Central University)
Acting Force
Crack SupportSupport
Concrete Fracture 2D Analysis
33
Fluid Field Direction
Contaminant Obstacle
Reynolds number=100
Obstacle
Contaminant
(Data courtesy of Ming-Hsin Su, AnCAD, Inc.)
Fluid Field Turbulence I
34(Data courtesy of Dr. Lin and Dr. Huang, Institute of Science and Technology)
High-pressure wave
Sharp Obstacle
High Pressure Reflection
35
Channel Narrowing
Floodway
(Data courtesy of Ming-Hsin Su, AnCAD, Inc.)
Fluid Field Turbulence II
36
3D Inkjet System Simulation I
Blue Print
(Data courtesy of Weng-Sing Huang/Hsuan-Chung Wu, National Cheng Kung University) O
pen E
nd
Clo
se E
nd
Cavity
Flu
id
Sup
ply
Orific
e
Nozzle
L
PZ
T
Squeeze Tube Mode Inkjet Printhead
80 40 80
160
800
Unit: μm
37
(Data courtesy of Weng-Sing Huang/Hsuan-Chung Wu, National Cheng Kung University)
Computer Simulation
3D Inkjet System Simulation II
Time: 0 20 26 32 38 44 50 56
62 68 74 80 [μs ]
break
38
3D Solar System Model
(Data courtesy of Li-Ger Chen, AnCAD, Inc.)
39 (Data courtesy of Chun-Hao Teng, AnCAD, Inc.)
EM-impulse
Perfectly Matched Layer
Amplitude
EM-wave Scattering on Perfectly Matched Layer
40
(Data courtesy of Ruey-Beei Wu/Kuang-Hua Hsueh, National Taiwan University)
Single microstrip line crossing slot
CurrentSlot
Current Layer
Ground Layer Amplitude
Multi-layer Ground Noise in a Current Field I
41
Differential microstrip line crossing
slot (coupling factor = 0.305)
ground plane
power planeSlotline
CurrentSlot
Current Layer
Ground Layer Amplitude
(Data courtesy of Ruey-Beei Wu/Kuang-Hua Hsueh, National Taiwan University)
Multi-layer Ground Noise in a Current Field II
42
Micro-magnetic Simulations
(Data courtesy of Professor Lee, Ching-Ming, Chungchou Institute of Technology. )
43(Data courtesy of Department of Physics & Astronomy, University of St Andrews, UK)
The blueprint of future integrated optical circuits.
Photonic Band Gap Waveguide Transmission I
44
(Data courtesy of Dr. Pei-Kun Wei, Academia Sinica, Taiwan)
AmplitudeLight Source
Line Defect
Photonic Band Gap
Photonic Band Gap Waveguide Transmission II
45(Data courtesy of Yu-Jen Lin, Precision Instrument Development Center)
Wave Source
Obstacle
Wave Source
Obstacle
Finite-difference Time-domain Analysis
46
(Data courtesy of Tung-Lung Fu, Precision Instrument Development Center)
Light Source
Micro-lens
Analysis of Optical Thin-film Coated Micro-lens
47 (Data courtesy of Chin-Hsiang Cheng, Tatung University)
30 nm
Water Molecules
Water Molecule Phase Transition
48
Ion Perturbation Analysis
(Data courtesy of Yu-Chang Sheng, National Taiwan University)
Ion A
Ion BDistance between ions A and B
49
Visualization of Physical Problem
by MATFOR®
50
Electromagnetic Radiation
• Dipole
• Quadrupole
axial separation
laterial separation
2
2
3
42
0 1)(sin
42
1
rc
pnS θ
ω
π=⋅
vv
[ ]2
22
5
6
2
2 1)cos(sin)(sin
322
1
rkd
c
QnS θθ
ω
π=⋅
vv
2
22
3
42
0 1)cos()sin(
2sin)(sin
2
1
r
kd
c
pnS
=⋅ ϕθθ
ω
π
vv
逸奇科技. www.AnCAD.com
Visualizing the Radiation Pattern
52
Diffraction Integral
• Fresnel-Kirchhoff :
• Frauhofer :
∫ +=σ
θλ
ψψ da
r
e
iP
ikr
))cos(1(2
1)( 0
∫+−=
σ
βηαξ ηξλ
ψβαψ dde
Z
e
i
ik
ikR
)(01),( )
))(( βηαξλ +≈∴>>>> RrDR
53
Slit Diffraction
• In one dimensional ,The Fraunhofer Diffraction Integral becomes :
• If the slit is of width 2a, then the integral is :
∫−=
σ
αξ ξαψ deCik)(
∫−
− ====a
a
ik akauu
uCadeC )sin(
2,)
)sin((2)( θ
λ
παξθψ αξ
逸奇科技. www.AnCAD.com
Visualization of the Slit Diffraction
55
Circular Aperture
)sin(),cos()( )( ϕρηϕρξηξψσ
βηαξ === ∫+−
ddeCPik
)'cos( ϕϕρθβηαξ −=+
2
0
22
2
02
0
0
0
2
0
cos
)(,2
))(
(2)(2)(
ψλ
ππθ
λ
π
πρρθπρθρθψπ
ϕρθ
Z
aCaau
u
uJCadkaJCddeC
aa
ik
==
==⋅=∴ ∫∫ ∫−
逸奇科技. www.AnCAD.com
Visualizing the Circular-Aperture
Diffraction
57
Optical Soliton : Kerr Effect
This refractive index variation is responsible for the nonlinear optical effects of self-focusing and self-phase modulation, and is the basis for Kerr-lens modelocking.
Type Kerr effect:
Innn 20 +=
.
58
Slow Vary Approximation
βα
λλ
≡≡
⋅+∂
∂=
∂
∂⇒
≈+−=−
∂
∂>>
∂
∂→>>∆
=+
∂
∂+−+
∂
∂⋅+
∂
∂
∂
∂+
∂
∂=∇=+∇
2,
2
1
)2
(2
1.
)2())((
,1
~
0)())(1()2(
,0
2
00
00
22
00
2
2
00
000
2
0
2
2
2
0
2
02
22
00002
2
2
2
2
222
0
22
nkn
knset
aankn
ix
a
kni
z
aeq
Innnnnnnnand
z
a
z
akzkfor
ankx
akn
z
akni
z
a
zxEknE
59
Split Step Fourier Method
( )
][
ˆˆ
)(
22 )(
1
0
ˆˆ
0
)ˆˆ(
2
2
2
n
aizki
n
zNzLzNL
aeFea
aeeaeaaNLz
a
aaix
ai
z
a
βα
βα
∆⋅−+
⋅⋅+
=⇒
≈=⇒+=∂
∂⇒
⋅+∂
∂=
∂
∂
逸奇科技. www.AnCAD.com
SSF simulation result for Kerr soliton.
61
Sin-Gordon Equation
• Considing a 1-D chan of identiacl pendu;la connenctedby a torsion bar.
• The euqation of motion for pendulum j follows from Newton’s law for rotational motion in terms of torques:
2
2
11
)()sin()()(
dt
tdImg
I
j
jjjj
ij
jji
θθθθκθθκ
ατ
=−−−−−
=
+−
≠
∑
62
2D Sin-Gordon Equation
• If the wavelength in a pulse are much longer than the repeat disance a, the chain could be approximated as a continuous medium.
• Then generalizing the spatial derivatives:
( )
)sin(lim
)()(
2
2
2
2
0
2
2
2
11
1
θθκθ
θθθθθ
θθθ
I
mg
xI
a
t
ax
ax
a
jjjj
jj
=∂
∂−
∂
∂⇒
⋅∂
∂≈−−−−
⋅∂
∂+≈
→
+−
+
)sin(2
22 θβ
θαθ ⋅=
∂
∂⋅−∇
x
63
Sin-Gordon Equation: 1D solution
1-D analytic solution :
So the 2D initial gauss be :
where c be some constant.
( )
( )
+
−
−−
−
−
=−
±
−=
±=
=∂
∂−
∂
∂
−
−
π
θ
θξ
θ
ξ
θθθθ
2
12
1
2
12
1
2
2
2
2
2
2
2
2
1
exptan4
1
exptan4
)(
1~
)sin(1
),(,)sin(
v
vtx
v
vtx
vtx
vfor
v
v
d
d
v
xt
txxt
( )
+−== −
2
1221 exptan4)0,,( yxctyxθ
64
2D Dynamical Sin-Gordon Equation
Initial condition, left: above equation; right: Gaussian form.
65
Quantum bound
• In multiple-particle nature, the interaction leads the nonlocal potential :. It changes the interaction term in Schrodinger equation :
• Then the equation becomes :
∫ ′′′→ rdrrrVrrV )(),()()( ψψ
ψψ EH =
)()(),(2
)(2
0
22
kEdppkkpVkp
nnnn ψψπ
ψµ
++ ∫∞
66
• One way to deal with the equation is by going to k-
space(Bessel transformation):
the k-space potential is obtain by a double Bessel transform
Numerically, The Schrodinger equation be :
)()(),(2
)(2
0
22
kEdppkkpVkp
nnnn ψψπ
ψµ
++ ∫∞
∫∫ ∫∞∞ ∞
′=
′′′
0
23
0 0
3 )()()()2()(),()()2( drrrpjrVkrjrdrprjdrrrrVrkj llll ππ
)()(),(2
)(2 1
22
kEkkkkVkkk
nn
N
i
jnjjjn ψψπ
ψµ
=⋅∆+ ∑=
67
• In matrix form :
• To solve the eigensystem problem, we could receive several eigenvalues, but only one satisfys
(boundary condition). Once we find the , by inverse Bessel transformation we could get the wave function in r-space without any difficault : .
[ ] [ ] [ ]nnn EH ψψ =⋅jjjiij
i
ij kkkkVk
H ∆+= 2
2
),(2
2 πδ
µ
[ ]
=
)(
)(
)(
2
1
Nn
n
n
n
k
k
k
ψ
ψ
ψ
ψM
IEH n−
∫∞
=0
2)()()( dkkkrjkr lnψψ
)(kψ
68
The simplest case :
.
)(2
)( brrV −= δµ
λ
)()(2
)()()(),(2
0
2prjkrj
bdrrprjrVkrjpkV llll
µ
λ== ∫
∞
.
),(2
)( brrV −= δµ
λ
69
Summary :MATFOR Components
• mfArray
– integrates the entire MATFOR toolkit into high-level programming environments such as C++ and Fortran, simplifying the syntax and facilitating object-oriented programming.
– Basic data structure.
• Numerical Library
– contains useful linear algebraic functions subject to assist users with computational problem solving.
– Use mfArray to do numerical computation
• Visualization Library
– collects well-designed graphical procedures and controls to support a variety of 2D and 3D visual functions.
70
MATFOR Components (Cont)
• Data Viewer
– organized in spreadsheet format, is one convenient platform for data management, filter, and analysis.
• Graphics Viewer
– besides its highly customized user interface, overthrows the convention of post-processing as it instantly visualizes scientific and engineering data.
• mfPlayer
– captures picture frames, animates simulation results, and allowsadditional graphical manipulations.
71 AnCAD Incorporated
- MATFOR®-A Simple Yet Powerful Solution to Meet Your Needs!