-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzincman.tex
3394 lines (3007 loc) · 139 KB
/
zincman.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
\documentclass[a4paper,twoside,11pt]{book}
\usepackage{graphics}
\usepackage[cover,dius]{nplreport}
\usepackage{hyperref}
\setlength{\topmargin}{0cm}
\setlength{\textwidth}{16cm}
\setlength{\textheight}{22cm}
\setlength{\oddsidemargin}{0cm}
\setlength{\evensidemargin}{0cm}
\setlength{\marginparwidth}{2cm}
\begin{document}
\newcommand{\vecc}[1]{\mbox{\boldmath $#1$}}
\renewcommand{\vec}[1]{\mathbf{#1}}
\renewcommand{\d}{\partial}
\renewcommand{\t}[1]{\mathrm{#1}}
\renewcommand{\div}{\nabla\cdot}
\newcommand{\grad}{\nabla}
\newcommand{\curl}{\nabla\times}
\newcommand{\eq}[1]{(\ref{#1})}
\newcommand{\f}[1]{Figure \ref{#1}}
\newcommand{\tab}[1]{Table \ref{#1}}
\newcommand{\sect}[1]{Section \ref{#1}}
\newcommand{\chap}[1]{Chapter \ref{#1}}
\newcommand{\dee}{\mathrm{d}}
\newcommand{\dd}[2]{\left(\frac{\d #1}{\d #2}\right)}
\newcommand{\ddd}[3]{\left(\frac{\d #1}{\d #2}\right)_{#3}}
\newcommand{\tensor}[1]{\underline{\underline{#1}}}
\newcommand{\emf}{\mathcal{E}}
\newcommand{\caf}{\textbf{C}, \textbf{a}, \textbf{f}}
\newcommand{\qg}{\textbf{q}, \textbf{g}}
\newcommand{\zinc}{\textsc{Zinc}}
\newcommand{\zmesh}{\textsc{Zmesh}}
\newcommand{\zpp}{\textsc{Zpp}}
\newcommand{\uv}[1]{{\underline{#1}}}
\newcommand{\var}[1]{\texttt{#1}}
\NPLcentre{Mathematics and Modelling Group}
\NPLapprovername{Prof Alistair Forbes}
\NPLapproverjob{Science Area Leader for the Mathematics and Modelling Group}
\NPLnumber{}
\NPLyear{2016}
\title{ZINC 3.6 (Finite element code)\\User Manual}
\NPLheader{ZINC 3.6 user manual}
\author{John Blackburn}
\date{February 2016}
\makecover
\maketitle
\begin{abstract}
This document describes the operation of \zinc, version 3.6. \zinc\ is
a program to general solve (non-linear) multiphysics problems using the finite
element method. It can be used to model almost any physics system.
\end{abstract}
\begin{prelude}\tableofcontents\end{prelude}
\chapter{Introduction}
\zinc\ is a finite element code capable of solving a wide range of
physics and multiphysics problems. \zinc\ can solve pretty much any
physics problems which can be expressed as second order partial
differential equations. Examples of physics systems which \zinc\ can
solve include: electrostatics, magnetics, elastic problems, thermal
fluctuation, mass diffusion etc. Further, any \emph{combination} of
these physics theories can also be solved. For example, \zinc\ has
been successfully used to solve piezoelectric (elastic+electric),
multiferroic (elastic+electric+magnetic) and fuel cells (multiple
component diffusion+pressure variation). A near-infinity of other
systems could also be solved including all the most common scenarios
in electromangetics, mechanics, thermodynamics, fluid flow, diffusion
and so on. The reason for \zinc's generality is that it is
fundamentally a \emph{mathematical} rather than physics
program. \zinc\ solves equations and it is up to the user to tune
those equations to correspond to the needed physics system. This
requires a certain mathematical skill and familiarity with the problem
in hand. However, we believe that no FE code is a substitute for such
knowledge: computer modelling is a highly skilled activity and cannot
be done without human input. We'll see fully automated
modelling the day we have lawyer-less courtrooms and doctor-less
hospitals! Nonetheless, the level of experience required to use \zinc\ is
not enormously high. Anyone with a physics, maths or engineering
degree should have no difficulty following the step-by-step
instructions in this manual. If users don't wish to set up their own
problems, they can come to NPL for help. Once a set of input files has
been prepared, it is easy to adapt it to, say, change material
properties or geometry without needing to adjust the detailed
physics files. Several examples of common physics systems are supplied in
the supplied Tutorial Manual and it should be easy to adapt these for
many ``bread and butter'' problems. The beauty of \zinc\ is that it
can solve these familiar problems at full speed while at the same time
allowing the simulation of completely new or esoteric equations, which
might never have been written down before, let alone solved!
However, before we get too carried away, we should note that \zinc, in
common with other general purpose FE packages, cannot necessarily
solve \emph{any} problem input to it. Some problems will turn out to
be self-contradictory, a fact which is not always obvious when the
equations are written on paper. Other systems may be unstable giving a
very poorly conditioned matrix and needing special techniques to
solve. \zinc\ comes with several general-purpose equation solvers, but
users having particular problems should approach NPL for advice. In
some cases, problem-specific solution techniques may be needed which
NPL may be able to provide. We would like to emphasise that this
limitation is not specific to \zinc\ but is a necessary feature of all
general-purpose FE programs. We have tested \zinc\ extensively against
other FE packages capable of solving arbitrary equations and found
that some problems are easy to solve (whatever the package) while
others converge slowly or not at all (whatever the package). There
seems to be reasonable ``agreement'' between FE programs as to what
equations sets are difficult to solve. In general, the only way to see
if a set of equations can be solved accurately is to try solving it with
an FE package such as \zinc.
\section{Comparison to other general purpose FE programs}
We have tested \zinc\ against Comsol quite extensively with some
comparisions given in the Tutorial Manual. In Comsol, equations can be
set up in the so-called ``coefficient mode'', the ``general mode'' and the
``weak mode''. \zinc's operation mirrors Comsol's \emph{coefficient
mode} (Appendix A). That is the coefficients in a set of partial
differential equations are set to specify the required mathematical
system. A simulation run in \zinc\ can therefore be easily transfered
to Comsol and vice versa. The
``general" and "weak" formulations of Comsol are an alternative way of
writing the laws of physics using variational principles. Such
formulations do not appear naturally in most areas of physics, but
involve reformulating problems using advanced mathematical
techniques. Given the complexity and scope for error of these
approaches, the ``general'' and ``weak'' formulations are not
supported by \zinc.
However, many users of Comsol never come across these core
formulations but are instead encouraged to ``combine'' areas of physics
to get the system they need. For example a piezoelectric problem, you
would combine the ``elastic'' module with the ``electrostatic'' module. We
believe that this approach to physics is
potentially dangerous as the user could end up
simulating something different from what was intended. This method is
therefore not supported in \zinc.
Another general purpose FE package we have some experience of is
OpenFOAM. Whereas Comsol is very much a point-and-click style program,
requiring the user to enter data in dialog boxes, OpenFOAM takes the
opposite approach, requiring the user to (re)write large portions of
code and recompile openFOAM each time a new physics system is
attempted (specifically, the user rewrites the "main loop" of the code
and calls a large number of built in functions, the operation of which
the user must learn in detail). This provides enormous flexibility in
that the user can alter the fundamental operation of OpenFOAM, but it
also makes it very difficult to to use the package without specialist
help. It also raises issues of traceability since each time we run a
different system on OpenFOAM, a new executable needs to be prepared
raising the possilibity of getting executables confused when
revisiting simulations months later.
To use openFOAM you need, in addition to maths and physics knowledge,
considerable understanding of C++ (the language openFOAM is written
in) and you must also study the internal structure of the openFOAM
source code in detail. We can see the advantages that openFOAM has in
terms of flexibility but we think that users should not need to be
experts in a particular programming language to use an FE
package. Also, in our opinion, the user should not be exposed so much
to the internal workings of the code as they are in OpenFOAM.
In \zinc, we have therefore taken a middle ground. Most users will
never need to write any code to use \zinc. Normally, you just set up the
coefficients to correspond to the physics/material properties you
want. Running a new physics problem then just involves altering the input
file: no programming needed. To support non-linearity, material
properties can be entered as expressions of the variables being solved
for. For instance when solving a non-linear dielectric problem you can set
the permittivities to be expressions like
\var{1+2*V} (where, for example, $V$ is the electrostatic
potential). In this case the problem is non-linear since
the permittivities depend on the potentials being solved
for. Arbitrary expressions may be entered depending on the solution
variables (and their derivatives) and/or space position
\var{(x,y,z)}. For conveniance the user can also refer to constants
(in the \var{.con} file, see \sect{constfile}) which can be altered between
simulations. Thus we can change the shape of the system or its
material properties without going into details within the main
``physics'' input file (\var{.zin}).
However, sometimes a simple expression like \var{1+2*V} will not be
sufficient: it may is necessary to do a complex calculation with loops
and branches to discover the material properties. An extreme case
might involve running a molecular dynamics code to discover the
material property. This code could easily be larger than
\zinc\ itself! \zinc\ can therefore, optionally, be made to link to
arbitrary code. Instead of setting \var{1+2*V}, the user writes
several functions, an example of which is shown in \f{func}.
\begin{figure}
In Fortran:
\begin{verbatim}
function cfun(string,x,y,z,ur,dur, ...other args... )
character(*) string
double precision x,y,z,ur(1),dur(1,3)
integer nvar
if (string=='$permittivity') Cfun=1+2*ur(1) ! ie, permttivity = 1+2*V
end function cfun
\end{verbatim}
In C:
\begin{verbatim}
double cfun(char *label, double *x, double *y, double *z,
double ur[3], double dur[3][1], ...other args..., int length)
{
if (equal(label,length,"$permittivity"))
return 1+2*ur[0]; // ie, permittivity = 1+2*V
}
\end{verbatim}
\caption{Example of functions used in \zinc\ for non-linear
simulation. Fortran and C forms are shown but any language capable
of producing a DLL can be used. Function ``equal'' is described in
\f{equal}. \emph{Note that user-written functions should not alter any of
their arguments values}. The only task of user-written functions is
to return a single (scalar) value. Some arguments omitted for brevity}
\label{func}
\end{figure}
This function (and a few others like it) is \emph{all} that is
expected from the user even in this ``advanced'' method of using
\zinc. Note that any programming language can be used provided it can
be compiled into a Dynamic Link Library (DLL). Unlike OpenFOAM,
\zinc\ is deliberately language agnostic and never needs to be
recompiled. The user simply provides a function (in a DLL) which
calculates the needed material property given the point in space
\var{x,y,z} and the solved-for variables (\var{ur}) and their
derivatives (\var{dur}). The user is \emph{entirely shielded} from the
inner working of \zinc, and just needs to fill out a purely
mathematical function. Of course instead of the single line
\var{Cfun=1+2*ur(1)}, as above, the user can enter arbitrarily complex
code with loops, branches, calls to other functions, read/write from
files etc. We believe that this approach is much simpler than the
OpenFOAM paradigm while maintaining much of its generality. Note again
that programming of the sort shown in \f{func} is only needed for
advanced, non-linear simulations; for linear simulations, no
programming is needed. Full details of user functions accessed by
\zinc\ are given in \sect{expressions}.
\section{Zinc operation}
\begin{figure}
\scalebox{0.8}{\includegraphics{zincdia}}
\caption{The operation of \zinc. Ellipses are files and rectangles
are programs. Optional input files are shown in [brackets]. The
DLL file can be generated using any programming language}
\label{zincdia}
\end{figure}
With these ideas in mind, let us look at the operation of \zinc, which
is shown diagrammatically in \f{zincdia}. This looks complex but bear
with us! The user can choose any stem name "file" for the
simulation. Thus, \var{file.zin} might become
\var{fuelcellcathode.zin} for example. The \var{file.zin} file
contains all information about the physics of the problem to be
solved. \var{file.con} (optional) contains a list of convenient
constants in the simulation which may be referred in
\var{file.zin}. Eg, we can store \var{eps0=8.854e-12}, the
permittivity of free space. The permittivity of a material with
rel. permittivity 2 can then be entered as \var{2*eps0} rather than
the less meaningful \var{1.778e-11}. \var{file.dll}
contains the above-mentioned non-linear functions (if needed), more
details of which are shown in \sect{nonlin}.
Before a geometry can be solved in FE it needs to be broken up into
many small shapes called \emph{elements} through a process known as
\emph{meshing}. The \zinc\ program \zmesh\ provides this
functionalilty. The user writes \var{file.min} which specifies the
geometry in terms of primitive shapes. \zmesh\ then processes this
file to create an FE mesh and outputs \var{file.mtf} which contains
the geometry and position of all the elements.
The user than runs the core \zinc\ program which writes an output file
\var{file.zou} containing the solution on each of the FE nodes. This
file can be viewed directly using \zmesh\ but for more advanced views
and post processing, the code \zpp\ is provided. \zpp\ (\zinc\ post
processor) reads the file \var{file.zpp}, in which the user specifies
a series of linescans, plane scans, integrals etc and generates corresponding
graphs. The user can plot arbitrary expressions based on the
simulation variables and their derivatives. \zpp\ automatically plots
all files on the screen and also creates graph files in the form of
Enhanced Metafiles (EMF) or Encapsulated Postscript (EPS) files. EMF
files are convenient for Microsoft Office programs while EPS is
suitable for \LaTeX: both are vector formats.
In order to generate these graphs, \zpp\ outputs the datafiles
\var{file01.out, file02.out...} etc. These are simply numbered in
order created (depending on how many such plots the user has
requested). \zpp\ then calls Gnuplot \cite{gnuplot} (using
auto-generated command file \var{file.gnu}) to generate the graphs
needed. Since the \var{*.out} files are still left behind on disk, it
is easy to recreate the graphs when needed. The user can use Gnuplot
separately from \zinc\ to change the symbols, titles and formatting of
the graph or to plot several simulation results in one graph. One
could, for example, compare simulation results with experimental
data. Since the raw data files are always on disk there's never any
mystery about where a graph came from. This approach therefore
provides good traceability and flexiblity. See the Tutorial Manual,
Chapter 1 for more details on advanced graph plotting.
Gnuplot, by the way, is a general purpose free graph plotting program
that is bundled with the \zinc\ installation. You can use Gnuplot
independently of \zinc\ and it comes with its own manual and
tutorials.
\chapter{Installing and running Zinc}
\zinc\ is installed using an automatic installer which will guide you
through the process. The three programs, \zmesh, \zinc, \zpp, are
available to run from the Start Menu in Windows. The programs can also
be invoked from the command line as
\begin{verbatim}
zmesh filename
zinc filename
zpp filename
\end{verbatim}
This latter technique is useful for running \zinc\ under batch
control. \zinc\ can also be run from external programming systems like
Matlab, Python or Excel.
The actual filenames for the \zinc\ programs are:
\begin{description}
\item[zinc.exe] Core solver, runs at the command line.
\item[zincwin.exe] Windows version of \zinc.
\item[zpp.exe] Post processor, runs at the command line.
\item[zppwin.exe] Windows version of \zpp.
\item[zmesh.exe] Non-interactive mesh generation.
\item[zmeshwin.exe] Interactive mesh generation/visualization package.
\end{description}
When \zinc\ installs, the Windows versions of \zmesh, \zinc, and
\zpp\ appear in the Start Menu. The installer adds \zinc's directory
to your PATH so that you can conveniently run \zinc\ from the command
prompt. Windows programs like \var{zincwin.exe} provide a simple GUI front
end to their command line equivalents, like \var{zinc.exe}.
\zinc\ also comes bundled with Gnuplot. \zpp\ invokes Gnuplot to
generate graphs. Gnuplot is then available for the user to run
independently from \zinc. Gnuplot comes with documentation and many
tutorial examples. Since \zpp\ emits text output files as well, these
can be plotted using any graph plotter or spreadsheet
program. However, we recommend the use of Gnuplot for best speed and
quality.
For advanced, non-linear operation, the user will need to prepare DLL
files for \zinc\ to link to. A free compiler like \var{gcc} or
\var{gfortran} will do (\var{http://gcc.gnu.org/wiki/GFortran}). See
the Tutorial Manual, Chapter 3, for an example of preparing a DLL file
to link to \zinc. The user does not need to recompile \zinc.
\section{Zinc install directory}
In the install directory you will find the directory
\var{examples}. This contains several worked examples each of which is
described in the Tutorial Manual. Also there is a \var{mesh\_examples}
directory which contains various meshing examples (\var{.min}
files). You should try some of these out in \zmesh.
Other useful files include \var{nltemplate.f90, nltemplate.c} which
contain empty user specified functions for non-linear simulations. If
you are running an advanced non-linear simulation, you can create your
non-linear functions by copying these templates and filling in the
functions provided.
If you are running \zinc\ from another system like Python or Matlab,
it may be preferable to run \zinc\ and \zpp\ indirectly using the
provided batch files \var{zincrun, zpprun}. These tiny batch files
simply ensure that the \zinc, \zpp\ command prompts stay open
should an error occur. Otherwise you will not be able to read the
error before the box closes. Useage:
\begin{verbatim}
zincrun file
zpprun file
\end{verbatim}
\section{Uninstalling zinc}
Simply use the ``Unistall'' icon in the Start Menu. If you install a
newer version of \zinc, you should uninstall the old version
first. Note, everything in the \zinc\ install directory will be
deleted so you \emph{should not store simulation runs in the
\zinc\ install directory}.
\section{Linux and Mac}
While \zinc\ has been written for Windows computers, it runs perfectly
on Linux and Mac using the Wine system \cite{wine}. Wine comes bundled
with most Linux systems (if not try the EPEL repository) and is
available for download on Mac, under the name
WineBottler\cite{winebottler} (free) and CrossOver\cite{crossover}
(commercial). The Wine website contains comprehensive information on
running Windows programs with Wine. To install \zinc, you should run
the installer executable through Wine. Then run \zmesh, \zinc\ and
\zpp\ through Wine. Note that Wine Is Not an Emulator (hence, WINE) so
when \zinc\ runs through Wine on Linux or Mac it should run at the
same speed as on a Windows PC with comparable hardware.
One issue we've noticed on Linux: it's better to install \zinc\ in a directory
without spaces in its path, i.e., \emph{not} in the default
\var{c:\textbackslash program files\textbackslash zinc}
directory. Similarly the directory where you store your actual
simulations should probably be free of spaces.
\section{Zinc Memory requirements}
\label{memory}
Most of \zinc's memory requirement is due to storing the FE matrix
$Q$. This is stored in sparse format in \texttt{Qval(ip), iQ(ip),
jQ(ip), ip=1,...,lenQ} where \texttt{lenQ=nnod*nvar$^2$*27}. Here,
\var{nnod, nvar} are the total number of nodes and number of dependent
variables being solved-for respectively (e.g. in a piezoelectric
simulation \var{nvar=4} since we solve for the 3 components of elastic
displacement and also the voltage). \zinc\ uses 8 byte real numbers
(double precision) and 4 byte integers. Therefore each entry in $Q$
uses 8+4+4=16 bytes and the total memory requirement is about
\texttt{nnod*nvar$^2$*27*16} bytes. If \zinc\ cannot allocate enough
memory for the simulation it will tell you when it starts up.
\chapter{Meshing with Zmesh}
\label{zmeshchap}
Before we can simulate a problem in \zinc, the geometry must first be
meshed. This is the process of decomposing the required geometry into
small \emph{elements}. \zinc\ requires that the geometry be meshed
into \emph{hexahedral elements} and this may be accomplished by using
the included program \zmesh. A hexahedron is a six sided solid figures
resembling a squashed cube. Cuboids are special cases of hexahedrons:
if the geometry is a laminar system, for example, it may be sufficient
to use cuboid hexahedrons. In general, however, \zmesh\ will distort
the hexahedrons so as to conform to surfaces in the geometry
specified. \zmesh\ works by reading in the geometry specification from
file \var{file.min} and writing out \var{file.mtf} which contains the
shape and position of each element. \var{file.mtf} is just a text
file, whose format is described in Appendix \ref{mtfdesc}, so you can
write your own program to do the meshing if you want. This may be
useful in cases where the geometry consists of irregular shapes. For
example, we had a project to model the stress/strain of ferroelectric
domains. We wrote a program to convert the domain map output by a
microscopic imaging device into the corresponding
\var{file.mtf}. \zmesh\ would not have been helpful in this case,
since the shapes are irregular and better represented as a ``map''
rather than a series of primitive shapes like spheres and boxes.
\zmesh\ uses the same geometry specification format as
\emph{MetaMesh}, a commercial meshing program available from Field
Precision\footnote{www.fieldp.com}. As such, MetaMesh can be used in
place of \zmesh\ if required. Metamesh has many more features than
\zmesh\ including a more advanced graphical front end and the ability
to read stereo lithography (STL) and other popular CAD files for geometry
specification. Although more basic, \zmesh\ will do the job in most
systems and at least it's free! The user may want to try using
\zmesh\ first, to see whether the \zinc\ package as a whole is
suitable to his/her needs. Then, if more sophisticated geometries are
needed, the user can opt to purchase MetaMesh directly from the Field
Precision website.
\section{The Zmesh program}
\label{zmeshsec}
\begin{figure}
\includegraphics{zmesh}
\caption{Zmesh: a program for meshing arbitrary structures.}
\label{zmesh}
\end{figure}
Zmesh is an interactive program as shown in \f{zmesh}. The user first
prepares an input file, \var{file.min} which contains all the geometry
details, \sect{mindesc}. He/she then uses the \verb+File > Open MIN+
command to read this file. At this point the file can be examined
using \verb+File > View MIN+. If all is well, the file can be
processed using \verb+File > Process+. A meshed geometry is then
created and is saved automatically as \var{file.mtf}. This geometry
appears on screen and can be rotated by dragging on screen (the arrow
keys can also be used). Various viewing options also exist as
described below. A pre-existing mesh file \var{file.mtf} can be read
using \verb+File > open MTF+
If you have already run a \zinc\ simulation, you can view the result
using \verb+File > open ZOU+. This shows a colour-coded view of the
data with a colour bar (on the left) indicating values. You
can cycle through the variables using the ``\verb+<+'' and ``\verb+>+''
buttons. This feature is intended to give a basic look at the raw data
solved by the simulation. For post processing, linescans and surface
plots (i.e. more quantitative information) use \zpp.
\subsection{File menu}
\begin{description}
\item[Open MIN] read geometry input file.
\item[Open MTF] read pre-processed mesh definition file.
\item[Open ZOU] View a solution file. Shows a basic view of the
data. For more advanced views and post processing, use \zpp.
\item[Open RESID] read file showing residual distribution. Useful
for checking solution accuracy. \zinc\ outputs this file if the
\var{residual} command is set in the ZIN file: see \sect{zincini}.
\item[View MIN] Show input file on screen. Note that this file
cannot be edited. The user should use a text editor to create and edit the
file. Notepad will do but a programming text editor may be
preferable. We use Emacs, a free text editor with many advanced
features. For complex geometries it may be useful to generate
\var{file.min} using a computer program.
\item[Process] Process the currently loaded MIN file, create the
output MTF file and display the mesh.
\item[Exit] Terminate the program
\end{description}
\subsection{View Menu}
\begin{description}
\item[Bounding box] Brings up a dialog allowing user to select a
rectangular section of the simulation volume to display. User
selects minimum and maximum \var{i,j,k} values (indexing system
for elements). The maximum extents allowed are shown to the right
of the dialog. Click ``All'' to set the maximum extents and show
the whole system. Click ``one'' to select only one element which
is taken to be that specified by \var{imin, jmin, kmin}
\item[Show extra] Toggle ``extra'' user-specified geometry elements
on and off. The elements are specified in \var{file.extra} if
present. See \sect{extra} for more details.
\item[Distort] Normally the system geometry is shown to scale. It
may be more convenient to distort the system for easy
viewing. This option allows magnification factors to be entered in
the x, y and z directions.
\item[Show gridlines] Toggles showing the perimeters of finite
elements. Turning gridlines off can be useful for displaying
simulation results.
\item[Export View] Allows you to export the current view as an
Enhanced Metafile (EMF) (picture file).
\item[Copy View] Copies the current view to the clipboard.
\end{description}
\subsection{On screen controls}
Drag the on screen objects with the mouse to rotate (or use arrow
keys). Zoom in/out using keys ``A'' and ``Z''. Rotate in the plane
using keys ``N'' and ``M''. Shift the view around by holding ``Shift''
and dragging with the mouse.
When it meshes a geometry, \zmesh\ assigns a \emph{region number} to
each element. The region number will later be associated with a
materials in the \var{.zin} file. Eg region 1 might be set to copper
and region 2 to aluminium. This means all elements tagged as region 1
will contain copper material. Similarly nodes are also assigned region
numbers. This is typically done to specify Dirichlet boundary
conditions. Eg we might specify that all nodes in region 1 have their
voltage set to 1 V.
A legend for the region numbers are listed on the right of the
screen. Left click to toggle a region on or off. (when a region is off
a cross appears in the box). Switching a region off just means making
it invisible. For example, in \f{zmesh}(a), region 1 has been switched
off, meaning all elements with region 1 are invisible. This allows
easier viewing of region 2 (a sphere in this case). When viewing a
simultion result file (ZOU file), these buttons have three states: on,
DATA, off. The DATA state shows colour coded data for the given region
with a colour legend on the left of the screen.
A legend for node numbers is also listed on the right of the screen
and works in the same way. You can toggle regions of nodes on or off.
Right clicking on a region or node box within the legend brings up a
colour dialog box which allows the user to change the colour for the
indicated region number.
When viewing a simulation result (ZOU file), you can ctrl-click on an
element to see the solution value at that point. The solution value is
shown in the Output window.
The buttons along the bottom are as follows
\begin{description}
\item[x,y,z] View along the x, y or z axes.
\item[xslice, yslice, zslice] View a slice through the system (ie a
single plane of elements), for example as shown in \f{zmesh}(b). You can
change which slice is displayed using the up and down arrows on
the keyboard.
\item[off] Switch off slices so that the whole system is displayed.
\end{description}
\subsection{Output window}
\zmesh\ gives various notifications to the user in the output
window. These include, details of meshing or any errors encountered in
the input file.
\section{Structure of the geometry input file}
\label{mindesc}
The mesh input file \var{file.min} has the form
\begin{verbatim}
global
<global commands>
end
part 1
<part commands>
end
part 2
<part commands>
end
:
endfile
\end{verbatim}
\begin{figure}
\scalebox{0.7}{\includegraphics{logical}}
\caption{Logical mesh formed using the global commands shown. (In the
real file a \var{zmesh} command is also needed. For simplicity,
these figures show a 2-D analogy). (a) Single meshing interval with
one xmesh and one ymesh command; (b) variable meshing with
multiple meshing commands}
\label{logical}
\end{figure}
The global commands specifies the \emph{logical mesh} and various
global variables which define the quality of the meshing. The ``part''
commands define various shapes (spheres, cubes, extrusions etc) that
make up the geometry needed. Note that \emph{later parts overlap
earlier ones so the order of parts is important}. The logical mesh
is illustrated in \f{logical}: it is a simple cuboid mesh defined by
the global commands \var{xmesh, ymesh, zmesh} as illustrated in that
figure. The logical mesh defines the number of elements and nodes
(intersection of the lines shown) in the simulation and also the
extent of the simulation. In \f{logical}, for example, the simulation
stretches from $-0.5$ to $0.5$ in all directions. Note that the
overall simulation area is always cuboid shaped. (However, it is
possible to model curved outer boundaries by setting the properties of
an outer region to correspond to vacuum). Distance
units are not specified at this stage, so the value 0.5 may be metres
or angstroms. In \zinc\ input file \var{file.zin} it is possible to
scale the geometry using a scale factor as required, see \sect{zinctrl}. The
global commands \var{xmesh} has the form
\begin{verbatim}
xmesh
x1 x2 dx1
x2 x3 dx2
:
end
\end{verbatim}
where \var{[x1,x2]} is a line segment divided into intervals \var{dx1}
wide etc. If \var{xmesh} contains only one command line, the meshing
is uniform across the whole simulation region. If there are multiple
lines as in \f{logical}(b), this allows variable meshing as shown. The commands
\var{ymesh, zmesh} have exactly the same form.
\begin{figure}
\scalebox{0.7}{\includegraphics{meshing}}
\caption{Meshing of two parts using the commands shown. The second
part (sphere) is inserted into the initial box part. (a)
Identification of element region numbers in original logical mesh;
(b) nodes are moved onto surface between the two regions. Element
region numbers shown. Note that the element marked (*) is not
acceptable since it is inverted (see text). In practice, \zmesh\
avoids inverted elements or at least gives a warning; (c) Final
node region numbers}
\label{meshing}
\end{figure}
\zmesh\ then processes the parts one by one as shown in \f{meshing}. In
response to the two part commands shown, a sphere is created inside a
cube. The cube is specified first and covers the whole simulation
region. Then, the sphere is specified which is inserted into the cube
(ie the cube is \emph{overwritten}. This shows the importance of parts order in
the file). Notice that the cube is designated ``region 1'' and the
sphere as ``region 2''. These region numbers will later be linked to
material properties in \var{file.zin}. \f{meshing}(a) shows what
happens in response to the part 2 command. \zmesh\ identifies the
elements whose centroids are inside the sphere specified and sets the
elements as region 2. In response to the \var{surface} command in the
part 2 'block', \zmesh\ then moves nodes so that they lie on the sphere
creating a shape which more closely conforms to the sphere. Without
the surface command, the elements would remain cuboid and the
``sphere'' would have the blocky, ``staircase'' appearance shown in
\f{meshing}(a). The final appearance and region number of each element
is shown in \f{meshing}(b). (Note that the picture shows an inverted
element which would actually be fixed by \zmesh. An inverted element
has a Jacobian which changes sign across the element preventing the
code from integrating correctly over the element (See Theoretical
Manual). \zmesh\ determines whether elements are inverted by calculating
the Jacobian. If it is inverted \zmesh\ relaxes the lattice to attempt
to fix the element even if that means having a less conforming mesh. A
chevron shaped element is considered inverted, for example)
Nodes are also given ``region numbers'' as shown in
\f{meshing}(c). This is in order to specify Dirichlet boundary
conditions \sect{regionspec} whereby field values are specified on
particular nodes. For example, in an electrostatic problem we could
designate region 2 nodes as having a fixed potential which would make
the sphere into a perfectly conducting object. The default region
numbering of nodes -- in this example -- is shown in \f{meshing}(c):
all nodes surrounding an element are given the same region number as
that element. Thus, after processing part 1, all nodes are designated
region 1. After processing part 2, the nodes within the sphere
(including those on the sphere's surface) are renumbered region
2. Note that the nodes at the interface between the two regions are
set to region 2 (since part 2 was processed last). In some cases, it
is necessary to override this behaviour and give a different region
number to the interface nodes. This can be accomplished by use of the
\var{coat} command as shown in \f{coat}(a). In this case, while
processing part 2, \zmesh\ gathers all nodes at the interface between
this part and region 1 and numbers these as region 6.
\begin{figure}
\scalebox{0.7}{\includegraphics{coat}}
\caption{(a) Use of the coat command to change the node region
numbers at an interface; (b) use of open parts (\var{boundyup} and
\var{boundydn}) to change the node region numbers}
\label{coat}
\end{figure}
Another way to set node region numbers is to use ``open parts'' as shown
in \f{coat}(b). Here we have used two additional parts (3 and 4). These
define surfaces at the top and of the simulation whose nodes are set
to region 3 and region 4 respectively. In this example (assuming an
electrostatic problem), it would be possible to excite the system by
putting 1 V on region 3 nodes (top, Dirichlet boundary) and zero volts
on region 4 nodes (bottom, Dirichlet boundary). This would create an
electric field on the simulation. In elastic problems, this would
correspond to clamped displacements at the top and bottom of the
simulation, and so on.
\f{zintest} shows the corresponding \var{file.zin} for \f{coat} set up as an
electrostatic problem. This file will be described in more detail in
\sect{zincini} but for now note how region 1 and region 2 elements are given
permittivity values of $\epsilon_0$ (permittivity of free space,
$8.854\times10^{-12}$ F/m) and $2\epsilon_0$. Also, region 3 and
region 4 nodes are set to voltage values 1 V and 0 V
respectively. Region 1 and 2 nodes are not set at all, so these nodes
(the interior nodes in the problem) are allowed to vary in order to
solve the electrostatic equations.
\begin{figure}
\begin{verbatim}
<global commands>
:
region 1 elements C
V x V x = 8.854e-12
V y V y = 8.854e-12
V z V z = 8.854e-12
end
region 2 elements C
V x V x = 1.7708e-11
V y V y = 1.7708e-11
V z V z = 1.7708e-11
end
region 3 nodes
V=1
end
region 4 nodes
V=0
end
\end{verbatim}
\caption{Sample \zinc\ input file, \var{file.zin} corresponding to the
setup of \f{coat}(b)}
\label{zintest}
\end{figure}
By the end of the part fitting process, all elements and nodes should
be given an region number. If this is not the case, \zmesh\ will
report an error. It is common practice for the first part to be a box
part which covers the whole simulation area. Other parts are then
inserted into this part.
We have so far described most of the part commands: \var{type, region,
fab, surface, coat}. The other two commands are shift and rotate,
allowing the part to be shifted and rotated into the required
position. Parts are conceptually constructed at the origin $(0,0,0)$
with major axes generally along $x,y,z$. Thus, the ``box'' part is
constructed with principle axes along the x,y,z directions. It is
centred at the origin and its extents are given by the 3 numbers
following the \var{fab} (fabricate) command. The meaning of the fab
parameters depends on the part and is given in \tab{3dparts}.
The rotation command has the form
\begin{verbatim}
rotate rx ry rz [string]
\end{verbatim}
If string is absent then a rotation is performed about the (global)
x-axis, then the y-axis then the z-axis by the angle given, in
degrees. If a different order is required, this can be given using the
string. Eg using ``yzx'' would cause rotation to occur about y, then z
then x. Since these are Euler angles, \emph{rotation order is
important}. Furthermore, \emph{rotation is performed before the
object is shifted} irrespective of the order of commands in the part
block.
The shift command has the form
\begin{verbatim}
shift x y z
\end{verbatim}
and causes the part to be shifted along the displacement specified.
\section{Neuman Boundaries}
\label{neumanbc}
So far we have discussed the creation of elements and nodes and their
region numbers, which are later associated with volumetric material
properties and Dirichlet boundary conditions respectively. The other
boundary condition supported by \zinc\ is the Neuman boundary
condition. Whereas Dirichlet boundaries fix the variables being solved
for, eg, voltage, temperature, elastic displacement, Neuman boundaries
fix derivatives of these: surface charge, thermal flux, traction
respectively. These quantities may be classified as fluxes or applied
forces of some kind. These fluxes are applied at boundaries which may
be internal to the simulation or on the external surface of the
simulation. \zmesh\ does not specify such surfaces explicitly, rather
surfaces exist between volumetric regions. For example, the curved
surface in \f{coat}(b) between region 1 and region 2 would be
identified $1-2$ giving an extra command in \f{zintest}
\begin{verbatim}
surface 1-2 q
V V = 1.0
end
surface 1-2 g
V = 2
end
\end{verbatim}
\begin{figure}
\scalebox{0.7}{\includegraphics{outer}}
\caption{Specification of surfaces for Neumann boundary
conditions. Surface 1-2 is the circular surface between regions 1
and 2. Surface 1-XMIN is the red surface, surface 3-YMIN is shown
blue and surface 3-XMAX is shown green}
\label{outer}
\end{figure}
The simulation is conceptually surrounded by regions called
``XMAX'', ``XMIN'', ``YMAX'', ``YMIN'', ``ZMAX'', ``ZMIN'', as shown
in \f{outer}. Thus the red outer edge on the left hand of \f{outer}
can be designated
\begin{verbatim}
1-XMIN
\end{verbatim}
(interface between region 1 and XMIN).
\section{List of part specification commands}
There are seven (7) part specification commands which appear within a part
block (\var{part n...end}). These are: \var{type, fab, region,
surface, coat, rotate, shift}. We have already introduced these
commands but now specify them in more detail:
\begin{description}
\item[type] The type of part, see \tab{3dparts}. Simple parts are just of the
form \var{type part}. Advanced parts \tab{advparts} have the form
\verb+type <part> <Vector list> end+ with each vector on a
separate line, \sect{advpartsec}.
\item[fab] Fabrication info for the part. This depends on the part
in question and is described in \tab{3dparts}, \tab{openparts},
\tab{advparts}.
\item[region] Elements in this part will be assigned this region
number. Nodes around those elements will also be so assigned.
\item[surface] This command has the form
\verb+surface {region|part} [n] {edge} [tol]+. It causes nodes to
be moved towards the surface between the current part and the
specified part or region (n). This causes the mesh to conform to
the surfaces rather than having a ``staircase'' appearance. The
\var{edge} command causes edge fitting to take place also. If
present, \var{tol} determines the speed of relaxation onto the
surface. It is a number in the range 0-1. If omitted, the default
value is 0.9 is assumed
\item[coat] Has the form \var{coat reg regnew}. Finds all nodes at
the interface between the current part and region \var{reg}. These
nodes are then given region number \var{regnew}.
\item[rotate] Has the form \verb+rotate x y z {string}+. By default,
rotate part about the x, y and z axes in that order (angles in
degrees). If \var{string} is present, the order of rotation may be
altered. Eg \var{xzy} means rotate about x, then about z, then
about y. The order of rotation is important: x,y and z are Euler
angles. Rotation is performed before shifting.
\item[shift] \var{shift x y z} shift the part along the vector
specified after rotation is complete.
\item[protect] Protects node region numbers in current part from
being overwritten. This is useful in filled parts whose nodes
might be overwritten by open parts. Since open parts are always
processed \emph{after} filled parts, it is not possible to simply
rearrange the parts order. This only affects node, not elements.
\end{description}
\section{List of global commands}
These commands must appear in the \var{global} section of the input file.
\begin{description}
\item[xmesh, ymesh, zmesh] Specified line segments spanning the simulation
area in the x direction. This defines the logical mesh. Each line
segment is divided into intervals allowing variable meshing. Has
the form \verb+xmesh <line segments> end+ with each line segment
on a separate line of the form \var{x1 x2 dx}. Commands
\var{ymesh, zmesh} have the same form.
\item[presmooth N] Smooths the logical mesh using N smoothing
steps. This is only important when variable resolution is used in
the logical mesh. Default: no smoothing.
\item[axissmooth dir N] Smooths along one direction ``dir''
only. Dir is either x, y, or z. N is the number of steps. Default:
no axis smoothing.
\item[smooth N] Smooths the final mesh after part fitting has been
accomplished. N steps of relaxation, default 10.
\item[format] \verb+Format {ascii|binary}+ causes the mesh output
file to be text (\var{file.mtf}) or binary (\var{file.mdf}) respectively.
\end{description}
\section{List of basic 3D parts}
These parts may be rotated/shifted into position using \var{rotate}
and \var{shift} commands. They are listed in \tab{3dparts}.
\begin{table}
\begin{tabular}{lll}
Shape & Fab parameters & Description\\\hline\hline
\var{box} & Lx Ly Lz & Centred at origin and extends [-Lx,Lx] along x etc\\ \hline
\var{sphere} & R & Centred at origin with radius R\\ \hline
\var{cylinder} & R H & Centred at origin with radius R and extends [-H/2,H/2] along z\\ \hline
\var{cone} & R H Hz & Truncated cone along $z$ with base at $z=0$ with radius R. \\
& & Apex at $z=H$ and truncated at $z=Hz$\\ \hline
\var{ellipcyl} & Rx Ry H & Cylinder along z with elliptical cross section extending \\ & &x=[-Rx,Rx], y=[-Ry,Ry]\\\hline
\var{ellipsoid} & Rx Ry Rz & Ellipsoid given by $(x/R_x)^2+(y/R_y)^2+(z/R_z)^2=1$\\\hline
\var{torus} & R r & R is major radius and r is minor radius. \\ & & Plane of the ``hole'' is normal to $z$\\\hline
\var{helix} & R r H Hw & Circular cross section helix (radius r) which wraps around \\
& & a z-directed cylinder height H, radius R centred at the origin. \\
& & Hw is the height along z attained during 1 revolution.\\ \hline
\var{trapezoid} & LxU LxD Ly Lz & Prism along z with trapezoidal cross section. \\
& & Full width in x is LxU (top) and LxD (bottom). \\
& & Full width in y and z given by Ly, Lz \\ \hline
\end{tabular}
\caption{List of 3-D parts and the meaning of the fab command for each}
\label{3dparts}
\end{table}
\section{List of open parts}
These parts have no volume so elements are not effected. The only
result is to change the region numbers of nodes. These parts are 0-D, 1-D
or 2-D shapes and may be rotated and shifted into position using \var{rotate}
and \var{shift} commands. Note that \var{boundxup} etc do not need fab
commands and are unaffected by \var{rotate} and \var{shift}. The parts
are listed in \tab{openparts}.
\begin{table}
\begin{tabular}{lll}
Part & fab params & Description \\ \hline\hline
\var{point} & x y z & Creates a point at (x,y,z) \\ \hline
\var{boundxup} & (none) & plate comprising the upper x plane of the simulation \\ \hline
\var{boundxdn} & (none) & plate comprising the lower x plane of the simulation\\ \hline
\var{boundyup} & (none) & plate comprising the upper y plane of the simulation \\ \hline
\var{boundydn} & (none) & plate comprising the lower y plane of the simulation \\ \hline
\var{boundzup} & (none) & plate comprising the upper z plane of the simulation \\ \hline
\var{boundzdn} & (none) & plate comprising the lower z plane of the simulation \\ \hline
\var{line} & L & line from (0,0,-L/2) to (0,0,L/2)\\ \hline
\var{arc} & R $\theta_{min}$ $\theta_{max}$ & Arc in z=0 plane centred at origin from angle\\
& & $\theta_{min}$ to $\theta_{min}$, radius R. $\theta=0$ is the x-axis. Angles in degrees.\\ \hline
\var{circle} & R & open circle centred at origin radius R \\ \hline
\var{rectangle} & Lx Ly & Open rectangle in z=0 from [-Lx,Lx] in x and [-Ly,Ly] in y\\ \hline
\var{disk} & R & As circle but filled \\ \hline
\var{plate} & Lx Ly & As rectangle but filled \\ \hline
\var{bubble} & R & Spherical surface centred at origin radius R
\end{tabular}
\caption{List of open parts}
\label{openparts}
\end{table}
\section{Advanced parts}
\label{advpartsec}
\zmesh\ supports 4 types of advanced parts which allow more general
shapes to be created: \var{extrusion, turning, transition} and
\var{neon}. Whereas the simple parts above have a single line ``type''
command (E.g. type sphere), these parts have a multi-line type command
of the form,
\begin{verbatim}
type {extrusion|turning|transition|neon}
<data lines>
:
end
\end{verbatim}
Apart from this, the part specification is the same and \var{region,
surface, coat, shift, rotate} commands may be used as usual.
\subsection{Extrusion}
An extrusion is a prism shape along the z axis. The cross section is
built up using an arbitrary number of line or arc segments which must
form a closed 2-d shape in the x-y plane.
The \var{type} command has the form
\begin{verbatim}
type extrusion {sidefit}
Vector 1 {S|SE}