2009年7月28日星期二

linux批处理(二)

对一批目录中的某个文件进行相同操作。
for workdir in `cat final.txt`
do
awk '$0~/\./' $workdir/Z0.dat > raw.dat
#读入坐标及其计算结果,因为这些值都是实型,所以只需读入包含小数点的行即可。
./a.out
cp outer.dat $workdir/
done

列出某个目录下所有子目录名称

最简单的方式:
find /somepath -type d
如果要存到某个文件中:
find /somepath -type d > directory.txt
然后去掉不需要保留的部分:
awk '$0~/D/' directory.txt > temp
awk '$0~/ro/' temp > workdir.txt
rm temp

另外一个选择:
du /somepath > directory.txt
awk '$0~/D/' directory.txt > temp1
awk '$0~/ro/' temp1 > temp2
cut -b 6- temp2 > workdir.txt # 这里要检查前面的字段长度,因为du会把文件夹大小写在目录前。
rm temp1
rm temp2

Tecplot Macro范例

众所周知,Tecplot处理数据功能强大,同时它提供了一种Macro模式,如果需要进行大量重复性的工作,学习一点Macro的语法是很有必要的。其实,Tecplot本身提供了记录Macro的命令。下面的Macro就是按照它记录下来之后,稍加修改而成。这里很重要的一点是变量|macrofilepath|的使用,它代表了Macro所在的目录,如果数据和它放在同一个目录,但是Tecplot调用Macro的时候出现错误,找不到相关数据文件,那就必须按照下面这个例子,把|macrofilepath|加到相应的位置。
#!MC 1200
$!READDATASET '"|macrofilepath|\wall_tec.dat" '
READDATAOPTION = NEW
RESETSTYLE = YES
VARLOADMODE = BYNAME
ASSIGNSTRANDIDS = YES
INITIALPLOTTYPE = CARTESIAN3D
VARNAMELIST = '"X" "Y" "Z" "wall-shear" "pressure"'
$!GLOBALCONTOUR 1 VAR = 5
$!CONTOURLEVELS RESETTONICE
CONTOURGROUP = 1
APPROXNUMVALUES = 15
$!FIELDLAYERS SHOWCONTOUR = YES
$!REDRAWALL
$!CREATESLICEZONEFROMPLANE
SLICESOURCE = SURFACEZONES
FORCEEXTRACTIONTOSINGLEZONE = YES
COPYCELLCENTEREDVALUES = NO
$!WRITEDATASET "|macrofilepath|\Z0.dat"
INCLUDETEXT = NO
INCLUDEGEOM = NO
INCLUDECUSTOMLABELS = NO
ASSOCIATELAYOUTWITHDATAFILE = NO
ZONELIST = [2]
VARPOSITIONLIST = [1-2,4-5]
BINARY = NO
USEPOINTFORMAT = YES
PRECISION = 9
TECPLOTVERSIONTOWRITE = TECPLOTCURRENT

2009年7月26日星期日

Journal files for GAMBIT.

/4c.jou
import step "base020.stp"
/the base case has three volumes
/volume.4 is a torus
volume create radius1 4.25 radius2 0.25 zaxis torus
volume move "volume.4" offset 0 -2.964101615 0
/volume.5 is a brick
volume create width 14 offset 0 -7 0 brick
/volume move "volume.5" offset -7 0 -7
volume subtract "volume.4" volumes "volume.5"
/move volume.4 to the right position
/volume move "volume.4" offset 1 0 0
volume unite volumes "volume.1" "volume.2" "volume.3" "volume.4"
undo begingroup
/mesh process:
/mesh the intersection
edge picklink "edge.34" "edge.38" "edge.33" "edge.37"
edge mesh "edge.37" "edge.33" "edge.38" "edge.34" successive ratio1 1 \
intervals 15
undo endgroup
undo begingroup
/mesh the stenosis
edge picklink "edge.10" "edge.9"
edge mesh "edge.9" "edge.10" successive ratio1 1 intervals 20
undo endgroup
volume mesh "volume.1" tetrahedral size 0.1
window modify invisible mesh
/set the boundary conditions
physics create "inlet1" btype "VELOCITY_INLET" face "face.4"
physics create "outlet2" btype "OUTFLOW" face "face.9"
export fluent5 "4D020c.msh"


/queue.jou
/identifier name "4c" new nosaveprevious
read file "4c.jou"
identifier name "4m" new nosaveprevious
read file "4m.jou"
identifier name "4p" new nosaveprevious
read file "4p.jou"
identifier name "5c" new nosaveprevious
read file "5c.jou"
identifier name "5m" new nosaveprevious
read file "5m.jou"
identifier name "5p" new nosaveprevious
read file "5p.jou"
identifier name "6c" new nosaveprevious
read file "6c.jou"
identifier name "6m" new nosaveprevious
read file "6m.jou"
identifier name "6p" new nosaveprevious
read file "6p.jou"

其中queue.jou仅仅调用文件4c~6p.jou。

TUI journal file in FLUENT.

;Read in the mesh file
file read-case 4D020c.msh
;
grid check
;Grid scale
grid scale 0.003 0.003 0.003
;Define the solver to be utilized
define/models/solver pressure-based
;Enable pressure based solver? [yes]
yes
;Define the material constants.
define/user-defined/interpreted-functions
;UDF Source File Name [""]
non.c
;CPP Command Name ["cpp"]
"cpp"
;virtual machine stack size [10000]
10000
;display assembly code listing? [no]
no
;
;Specify fluid properties and pertinent property models.
define/materials copy
;Material of type []>
fluid
;database-material-name>
water-liquid
define/materials change-create water-liquid
;material name [water-liquid]
water-liquid
;water-liquid is a fluid
;change Density? [no]
yes
;Density methods: (constant ideal-gas incompressible-ideal-gas boussinesq piecewise-line)
;new method [constant]
constant
;value(kg/m3) [998.2]
1050.
;change Cp (Specific Heat)? [no]
no
;change Thermal Conductivity? [no]
no
;change Viscosity? [no]
yes
;new method [constant]
user-defined
;new function ["cell_viscosity"]
"cell_viscosity"
;change Molecular Weight? [no]
no
;change L-J Characteristic Length? [no]
no
;change L-J Energy Parameter? [no]
no
;change Thermal Expansion Coefficient? [no]
no
;change Degrees of Freedom? [no]
no
;change Speed of Sound? [no]
no
;
;Set boundary conditions at inlet.
define/boundary-conditions velocity-inlet
;zone id/name [inlet]
inlet1
;Velocity Specification Method: Magnitude and Direction [no]
no
;Velocity Specification Method: Components [no]
no
;Velocity Specification Method: Magnitude, Normal to Boundary [yes]
yes
;Reference Fram: Absolute [yes]
yes
;Use Profile for velocity Magnitude? [no]
yes
;Use UDF Profile for Velocity Magnitude? [no]
yes
;profile names list: (udf udf)
;profile name ["udf"]
"udf"
;data name ["cell_viscosity"]
"inlet_x_velocity"
;Coordinate System: Cartesian (X, Y, Z)[yes]
yes
;
define/boundary-conditions fluid
;(fluid)
;zone id/name [fluid]
fluid
;material-name [air]: Change current value? [no]
yes
;material-name [air]>
water-liquid
;Specify source terms? [no]
no
;Specify fixed values? [no]
no
;Motion Type: Stationary [yes]
yes
;X-Origin of Rotation-Axis (m) [0]
0
;Y-Origin of Rotation-Axis (m) [0]
0
;Z-Origin of Rotation-Axis (m) [0]
0
;X-Component of Rotation-Axis [0]
0
;Y-Component of Rotation-Axis [0]
0
;Z-Component of Rotation-Axis [1]
1
;Deactivated Thread [no]
no
;Porous zone? [no]
no
;
solve/set/gradient-scheme
;use Green-Gauss Node-Based gradients? [no]
yes
;
solve/set/discretization-scheme mom
;Convective discretization scheme for Momentum (0 1 2 4 6) [0]
;4 means QUICK
4
;
solve/initialze/compute-defaults allzones
;
;Set the convergence criteria.
solve/monitors/residual convergence-criteria
;continuity residual convergence criterion [0.001]
0.000001
;x-velocity residual convergence criterion [0.001]
0.000001
;y-velocity residual convergence criterion [0.001]
0.000001
;z-velocity residual convergence criterion [0.001]
0.000001
;
solve/monitors/residual plot?
;Plot residuals? [no]
yes
;
solve iterate
;Number of iterations [1]
1000
;
;Write settings to a case file.
file write-case-data
;case file name [""]
"4D020c.cas"
;
;Exit fluent.
exit

GUI journal file in FLUENT.

(cx-gui-do cx-activate-item "MenuBar*ReadSubMenu*Case...")
(cx-gui-do cx-set-text-entry "Select File*Text" "4D020c.msh")
(cx-gui-do cx-activate-item "Select File*OK")
(cx-gui-do cx-activate-item "MenuBar*GridMenu*Check")
(cx-gui-do cx-activate-item "MenuBar*GridMenu*Scale...")
(cx-gui-do cx-set-list-selections "Scale Grid*Frame3(Unit Conversion)*DropDownList1(Grid Was Created In)" '( 2))
(cx-gui-do cx-activate-item "Scale Grid*Frame3(Unit Conversion)*DropDownList1(Grid Was Created In)")
(cx-gui-do cx-set-real-entry-list "Scale Grid*Frame1(Scale Factors)*RealEntry1(X)" '( 0.003))
(cx-gui-do cx-set-real-entry-list "Scale Grid*Frame1(Scale Factors)*RealEntry2(Y)" '( 0.003))
(cx-gui-do cx-set-real-entry-list "Scale Grid*Frame1(Scale Factors)*RealEntry3(Z)" '( 0.003))
(cx-gui-do cx-activate-item "Scale Grid*PanelButtons*PushButton1(OK)")
(cx-gui-do cx-activate-item "Scale Grid*PanelButtons*PushButton2(Cancel)")
(cx-gui-do cx-activate-item "MenuBar*FunctionsSubMenu*Interpreted...")
(cx-gui-do cx-activate-item "Interpreted UDFs*PushButton3(Browse)")
(cx-gui-do cx-set-text-entry "Select File*Text" "non.c")
(cx-gui-do cx-activate-item "Select File*OK")
(cx-gui-do cx-set-text-entry "Interpreted UDFs*TextEntry1(Source File Name)" "non.c")
(cx-gui-do cx-activate-item "Interpreted UDFs*PanelButtons*PushButton1(OK)")
(cx-gui-do cx-activate-item "Interpreted UDFs*PanelButtons*PushButton2(Cancel)")
(cx-gui-do cx-activate-item "MenuBar*ModelsSubMenu*Solver...")
(cx-gui-do cx-set-toggle-button "Solver*Table1*Frame3(Gradient Option)*ToggleBox3(Gradient Option)*Green-Gauss Node Based" #f)
(cx-gui-do cx-activate-item "Solver*Table1*Frame3(Gradient Option)*ToggleBox3(Gradient Option)*Green-Gauss Node Based")
(cx-gui-do cx-activate-item "Solver*PanelButtons*PushButton1(OK)")
(cx-gui-do cx-activate-item "MenuBar*DefineMenu*Materials...")
(cx-gui-do cx-activate-item "Materials*Table1*Frame1*Frame3*ButtonBox3*PushButton1(Fluent Database)")
(cx-gui-do cx-set-list-selections "Database Materials*Table1*Frame1*Frame1*List1(Materials)" '( 552))
(cx-gui-do cx-activate-item "Database Materials*Table1*Frame1*Frame1*List1(Materials)")
(cx-gui-do cx-set-position "Database Materials" '(x 117 y 511))
(cx-gui-do cx-activate-item "Database Materials*PanelButtons*PushButton1(Copy)")
(cx-gui-do cx-activate-item "Database Materials*PanelButtons*PushButton1(Close)")
(cx-gui-do cx-set-real-entry-list "Materials*Frame2(Properties)*Table2(Properties)*Frame4*Frame2*RealEntry3" '( 1050))
(cx-gui-do cx-set-list-selections "Materials*Frame2(Properties)*Table2(Properties)*Frame10*Frame2*DropDownList1" '( 11))
(cx-gui-do cx-activate-item "Materials*Frame2(Properties)*Table2(Properties)*Frame10*Frame2*DropDownList1")
(cx-gui-do cx-activate-item "User-Defined Functions*PanelButtons*PushButton1(OK)")
(cx-gui-do cx-activate-item "Materials*PanelButtons*PushButton1(Change/Create)")
(cx-gui-do cx-activate-item "Materials*PanelButtons*PushButton1(Close)")
(cx-gui-do cx-activate-item "MenuBar*DefineMenu*Operating Conditions...")
(cx-gui-do cx-activate-item "Operating Conditions*PanelButtons*PushButton1(OK)")
(cx-gui-do cx-activate-item "MenuBar*DefineMenu*Boundary Conditions...")
(cx-gui-do cx-set-list-selections "Boundary Conditions*Table1*Frame1*List1(Zone)" '( 1))
(cx-gui-do cx-activate-item "Boundary Conditions*Table1*Frame1*List1(Zone)")
(cx-gui-do cx-activate-item "Boundary Conditions*PanelButtons*PushButton1(OK)")
(cx-gui-do cx-set-list-selections "fluid-2-1*Table3*Table1*DropDownList1(Material Name)" '( 0))
(cx-gui-do cx-activate-item "fluid-2-1*Table3*Table1*DropDownList1(Material Name)")
(cx-gui-do cx-activate-item "fluid-2-1*PanelButtons*PushButton1(OK)")
(cx-gui-do cx-set-list-selections "Boundary Conditions*Table1*Frame1*List1(Zone)" '( 2))
(cx-gui-do cx-activate-item "Boundary Conditions*Table1*Frame1*List1(Zone)")
(cx-gui-do cx-activate-item "Boundary Conditions*PanelButtons*PushButton1(OK)")
(cx-gui-do cx-set-list-selections "velocity-inlet-5-1*Frame4*Frame3(Momentum)*Table1*Table4*DropDownList1" '( 2))
(cx-gui-do cx-activate-item "velocity-inlet-5-1*Frame4*Frame3(Momentum)*Table1*Table4*DropDownList1")
(cx-gui-do cx-activate-item "velocity-inlet-5-1*PanelButtons*PushButton1(OK)")
(cx-gui-do cx-set-list-selections "Boundary Conditions*Table1*Frame1*List1(Zone)" '( 3))
(cx-gui-do cx-activate-item "Boundary Conditions*Table1*Frame1*List1(Zone)")
(cx-gui-do cx-set-list-selections "Boundary Conditions*Table1*Frame1*List1(Zone)" '( 4))
(cx-gui-do cx-activate-item "Boundary Conditions*Table1*Frame1*List1(Zone)")
(cx-gui-do cx-activate-item "Boundary Conditions*PanelButtons*PushButton2(Cancel)")
(cx-gui-do cx-activate-item "MenuBar*ControlsSubMenu*Solution...")
(cx-gui-do cx-set-list-selections "Solution Controls*Table2*Frame1(Discretization)*Table1(Discretization)*DropDownList2(Momentum)" '( 3))
(cx-gui-do cx-activate-item "Solution Controls*Table2*Frame1(Discretization)*Table1(Discretization)*DropDownList2(Momentum)")
(cx-gui-do cx-activate-item "Solution Controls*PanelButtons*PushButton1(OK)")
(cx-gui-do cx-activate-item "MenuBar*InitializeSubMenu*Initialize...")
(cx-gui-do cx-set-list-selections "Solution Initialization*DropDownList1(Compute From)" '( 0))
(cx-gui-do cx-activate-item "Solution Initialization*DropDownList1(Compute From)")
(cx-gui-do cx-activate-item "Solution Initialization*PanelButtons*PushButton1(OK)")
(cx-gui-do cx-activate-item "Solution Initialization*PanelButtons*PushButton1(Apply)")
(cx-gui-do cx-activate-item "Solution Initialization*PanelButtons*PushButton2(Cancel)")
(cx-gui-do cx-activate-item "MenuBar*MonitorsSubMenu*Residual...")
(cx-gui-do cx-set-toggle-button "Residual Monitors*Table1*Frame1(Options)*ToggleBox1(Options)*CheckButton2(Plot)" #f)
(cx-gui-do cx-activate-item "Residual Monitors*Table1*Frame1(Options)*ToggleBox1(Options)*CheckButton2(Plot)")
(cx-gui-do cx-set-real-entry-list "Residual Monitors*Table2*RealEntry11" '( 1e-006))
(cx-gui-do cx-set-real-entry-list "Residual Monitors*Table2*RealEntry17" '( 1e-006))
(cx-gui-do cx-set-real-entry-list "Residual Monitors*Table2*RealEntry23" '( 1e-006))
(cx-gui-do cx-set-real-entry-list "Residual Monitors*Table2*RealEntry29" '( 1e-006))
(cx-gui-do cx-activate-item "Residual Monitors*PanelButtons*PushButton1(Plot)")
(cx-gui-do cx-activate-item "Residual Monitors*PanelButtons*PushButton1(OK)")
(cx-gui-do cx-activate-item "MenuBar*SolveMenu*Case Check...")
(cx-gui-do cx-activate-item "Information*OK")
(cx-gui-do cx-activate-item "MenuBar*SolveMenu*Iterate...")
(cx-gui-do cx-set-integer-entry "Iterate*Table1*Frame2(Iteration)*Table2(Iteration)*IntegerEntry2(Reporting Interval)" 20)
(cx-gui-do cx-set-integer-entry "Iterate*Table1*Frame2(Iteration)*Table2(Iteration)*IntegerEntry1(Number of Iterations)" 1000)
(cx-gui-do cx-activate-item "Iterate*PanelButtons*PushButton1(Apply)")
(cx-gui-do cx-activate-item "MenuBar*WriteSubMenu*Stop Journal")

2009年7月20日星期一

More about sharing folders in VirtualBox.

前面说过在VirtualBox里面共享宿主机的文件夹。这里需要再说两点,因为上次的那条命令:
sudo mount -t shared_folders /path-to-share
并没有放在启动选项里面,所有要么就每次启动之后,用root用户执行一下这条命令,要么把它放入启动。

还有一个问题就是如果输入上面这条命令之后出现如下错误,
/sbin/mount.vboxsf: mounting failed with the error: No such device
有一个解决办法就是先看看
lsmod |grep vboxvfs
的输出,然后再执行
sudo modprobe vboxvfs
如果没有错误提示,再执行
sudo mount -t shared_folders /path-to-share
按照这个方式,可以重新加载共享文件夹。

2009年7月17日星期五

Plot in multiple windows under gnuplot.

gnuplot> set xrange [-1:1]
gnuplot> plot sin(x)
gnuplot> show terminal

terminal type is wxt 0

gnuplot> set terminal wxt 1
Terminal type set to 'wxt'
Options are '1'
gnuplot> plot cos(x)
gnuplot>