perl批量工作机器程序

Reading time: 15 minutes and 3 seconds with 3313 words. 本文总阅读量

背景分析

很多时候,我们需要执行一条命令比如`batchFluent.bat`, `cfdpost -batch \*.cse`, `fluent 3d -i batchFluent2000`等, 在执行该命令时候,我们需要打开 cmd或者terminal,然后切换到对应脚本目录,拷贝相应脚本需要的程序,甚是麻烦,可否把这个过程程序化?

单个文件处理

管道1: 转换Openfoam结果为msh和dat

通过下面的程序得到一个项目文件相关的msh, 比如YangJiang ,就会得到YangJiang.msh以及YangJiang.dat等, 也就是升华技术,可提取一个技术变量,projectName=“YangJiang”

batchFluent.bat(不需要修改!)

rem 路径相应修改为电脑上的安装文件夹路径
set OPENFOAM_WIN_DIR=D:/Program Files (x86)/AIWind/solver/OpenFOAMv18.06
set WM_PROJECT_DIR=%OPENFOAM_WIN_DIR%
set PATH=%OPENFOAM_WIN_DIR%\bin;%OPENFOAM_WIN_DIR%\bin/mpi;%OPENFOAM_WIN_DIR%\lib;
set MPI_BUFFER_SIZE=20000000
rem 将foamDataToFluentDict放入算例\noTurbine\10.00\0\kh\system
rem 转换网格
foamMeshToFluent
rem 转换数据
foamDataToFluent

system/foamdatatofluentdict(不需要修改)

FoamFile
{
  version     2.0;
  format      ascii;
  note        "OpenFOAM to Fluent interface control dictionary";
  class       dictionary;
  object      foamDataToFluentDict;
}

p               1;
U               2;
//T               3;//
//h               4;//
k               5;
epsilon         6;
//alpha1          150;//

管道2: 转换msh和dat为fluent的cas and dat(需要修改)

YangJiang.msh 和 YangJiang2000.dat和 YangJiang20001.cas得适配,应需进行修正,把这个升级为

(cx-gui-do cx-activate-item "MenuBar*ReadSubMenu*Mesh...")
(cx-gui-do cx-set-file-dialog-entries "Select File" '( "YangJiang.msh") "Mesh Files (*.msh* *.MSH* )")
(cx-gui-do cx-activate-item "MenuBar*ReadSubMenu*Data...")
(cx-gui-do cx-set-file-dialog-entries "Select File" '( "YangJiang2000.dat") "Data Files (*.dat* *.pdat* )")
(cx-gui-do cx-activate-item "MenuBar*WriteSubMenu*Case & Data...")
(cx-gui-do cx-set-file-dialog-entries "Select File" '( "YangJiang20001.cas") "Case/Data Files (*.cas* *.pdat* )")
(cx-gui-do cx-activate-item "MenuBar*WriteSubMenu*Stop Journal")
(cx-gui-do cx-activate-item "MenuBar*FileMenu*Exit")

运行方式为 `fluent 3d -i batchFluent2000`

由此可得到YangJiang20001.cas和YangJiang20001.dat

管道3: 提取post结果(需要修改, 修改一次,然后进行循环即可)

然后针对cas和dat进行线信息提取即可

!@processDir=("D:\\AIwind\\AIWindCases\\Dongping20191105\\noTurbine\\10.00\\0\\YangJiang\\fluentInterface");

################################################
## 文件过滤设置
################################################


!$length=@processDir; #get the length of the processDir array
!for($count=0;$count<$length;$count++){

  !$pathDir = $processDir[$count];
  #!$file = "huailai20m220001.dat"; ## for 814w and 1425w
  !$file = "YangJiang20001.dat"; ## for 325w
  !$currentFilename = "${pathDir}//$file";

  ###   Create output directory
  !$outputLine="forLinesOutput0";
  !$outputLineDir="${pathDir}//$outputLine";
  !if(! -e $outputLineDir){
    !mkdir $outputLineDir;
    !print "$outputLineDir create successfully!";
    !}

技术分解1—- 批量后处理Openfoam结果到dat格式

  1. 准备文件
  2. 链接目录,切换到脚本目录,执行脚本

技术实现1

基础版本(初始版本)

事先拷贝好需要的文件放在指定位置处,使用system运行系统命令即可

#!/usr/bin/env perl

#===============================================================================

#

#         FILE: batchProcess814w.pl

#

#        USAGE: ./batchProcess814w.pl

#

#  DESCRIPTION:

#

#      OPTIONS: ---

# REQUIREMENTS: ---

#         BUGS: ---

#        NOTES: ---

#       AUTHOR: YOUR NAME (),

# ORGANIZATION:

#      VERSION: 1.0

#      CREATED: 2019/9/24 1149

#     REVISION: ---

#===============================================================================


use strict;
use warnings;
use utf8;
use Cwd;

my  $directory   = "D:\\huaiiLaiPP\\AIWindProject1\\noTurbine\\10.00\\";
my  $specialDirSign=[0,22.5,45,67.5,90,112.5,135,157.5,180,202.5,225,247.5,270,292.5,315,337.5];


foreach my $name ( @$specialDirSign ) {
    my  $tempdirectory=sprintf("$directory\\$name\\huailai20m2\\");
    #my  $tempBatchFile=sprintf("$directory\\$name\\huailai20m2\\batchFluent.bat");

    print "$tempdirectory\n";
    chdir($tempdirectory);
    my  $mypath=getcwd();
    print " Temp Director: -----------> $mypath\n";
    #system($tempBatchFile)

    system("batchFluent.bat")
}

高级版本

让程序在指定的位置自己拷贝需要的文件, 采用<:Copy函数>

根据目录结构可以进行对应修改

下面针对的是不同风速,相同扇区【0扇区】的结果

  1. 规律:找到noturbine文件夹
  2. 规律:找到项目文件名kh, yandun,YangJiang等
#!/usr/bin/env perl

#===============================================================================

#

#         FILE: batchProcess814w.pl

#

#        USAGE: ./batchProcess814w.pl

#

#  DESCRIPTION:

#

#      OPTIONS: ---

# REQUIREMENTS: ---

#         BUGS: ---

#        NOTES: ---

#       AUTHOR: YOUR NAME (),

# ORGANIZATION:

#      VERSION: 1.0

#      CREATED: 2019/9/24 1149

#     REVISION: ---

#===============================================================================


use strict;
use warnings;
use utf8;
use Cwd;
use File::Copy;

my  $directory   = "D:\\NewCosMount\\noTurbine\\";
my  $specialDirSign=["6.00","7.00","8.00","9.00","10.00"];

my $sourceFileDirs="D:\\NewCosMount\\noTurbine\\batChProcess\\";
my  $targetFileSign1="foamDataToFluentDict";
my  $targetFileSign2="batchFluent.bat";

foreach my $name ( @$specialDirSign ) {
    my  $tempdirectory=sprintf("$directory\\$name\\0\\kh\\");
    print "$tempdirectory\n";
    chdir($tempdirectory);

    my  $mypath=getcwd();
    my $dictFile="$tempdirectory//system//$targetFileSign1";
    my $batchFile="$tempdirectory//$targetFileSign2";
    copy("$sourceFileDirs\\$targetFileSign1","$dictFile");

    copy("$sourceFileDirs\\$targetFileSign2","$batchFile");
    print " Temp Director: -----------> $mypath\n";
    #system($tempBatchFile)

    system("batchFluent.bat")
}

相同风速,不同扇区的结果

  1. 找到noTurbine文件夹
  #!/usr/bin/env perl

  #===============================================================================

  #

  #         FILE: batchProcessHuailai814w.pl

  #

  #        USAGE: ./batchProcessHuailai814w.pl

  #

  #  DESCRIPTION:

  #

  #      OPTIONS: ---

  # REQUIREMENTS: ---

  #         BUGS: ---

  #        NOTES: ---

  #       AUTHOR: YOUR NAME (),

  # ORGANIZATION:

  #      VERSION: 1.0

  #      CREATED: 2019/11/7 1843

  #     REVISION: ---

  #===============================================================================


  use strict;
  use warnings;
  use utf8;
  use Cwd;
  use File::Copy;

  #my  $directory   = "";

  my  $directory   = "D:\\YanDun20191106\\yuandun\\noTurbine\\";
  my  $specialDirSign=[0,22.5,45,67.5,90,112.5,135,157.5,180,202.5,225,247.5,270,292.5,315];

  my $sourceFileDirs="D:\\huaiiLaiPP\\NewSolverLimit10e9KE\\noTurbine\\10.00\\0\\huailai20m2\\";
  my  $targetFileSign1="foamDataToFluentDict";
  my  $targetFileSign2="batchFluent.bat";

  my  $projectVelocity='10.00';
  my $projectName="yandun";
  foreach my $name ( @$specialDirSign ) {
      my  $tempdirectory=sprintf("$directory\\$projectVelocity\\$name\\$projectName\\");
      print "$tempdirectory\n";
      chdir($tempdirectory);

      my  $mypath=getcwd();
      print " Temp Director: -----------> $mypath\n";
      my $dictFile="$tempdirectory//system//$targetFileSign1";
      my $batchFile="$tempdirectory//$targetFileSign2";
## bug 修复!

      copy("$sourceFileDirs\\system\\$targetFileSign1","$dictFile");

      copy("$sourceFileDirs\\$targetFileSign2","$batchFile");
      #system($tempBatchFile)

      system("batchFluent.bat");
  }

技术分解2—-批量处理dat文件到post格式

需要执行fluent的journal命令核心是fluent脚本

  1. 读入msh
  2. 读入dat
  3. 保存cas & dat 具体文件需要修改msh和dat前缀
(cx-gui-do cx-activate-item "MenuBar*ReadSubMenu*Mesh...")
(cx-gui-do cx-set-file-dialog-entries "Select File" '( "huailai20m2.msh") "Mesh Files (*.msh* *.MSH* )")
  (cx-gui-do cx-activate-item "MenuBar*ReadSubMenu*Data...")
  (cx-gui-do cx-set-file-dialog-entries "Select File" '( "huailai20m22000.dat") "Data Files (*.dat* *.pdat* )")
  (cx-gui-do cx-activate-item "MenuBar*WriteSubMenu*Case & Data...")
  (cx-gui-do cx-set-file-dialog-entries "Select File" '( "huailai20m220001.cas") "Case/Data Files (*.cas* *.pdat* )")
  (cx-gui-do cx-activate-item "MenuBar*WriteSubMenu*Stop Journal")
  (cx-gui-do cx-activate-item "MenuBar*FileMenu*Exit")

核心命令: `fluent 3d -i batchFluent2000`

技术实现2

相同风速下,不同扇区处理

#!/usr/bin/env perl

#===============================================================================

#

#         FILE: journalTransferAIWINDTOFluentCasDat814w.pl

#

#        USAGE: ./journalTransferAIWINDTOFluentCasDat814w.pl

#

#  DESCRIPTION:

#

#      OPTIONS: ---

# REQUIREMENTS: ---

#         BUGS: ---

#        NOTES: ---

#       AUTHOR: YOUR NAME (),

# ORGANIZATION:

#      VERSION: 1.0

#      CREATED: 2019/9/27 1535

#     REVISION: ---

#===============================================================================


use strict;
use warnings;
use utf8;
use Cwd;
use File::Copy;

#my  $directory   = "D:\\huaiLaiUnder\\huaiLaiNew20190722\\huaiLaiNew20190722\\noTurbine\\10.00\\";

my  $directory = "D:\\huaiiLaiPP\\AIWindProject1\\noTurbine\\10.00\\";
#my  $specialDirSign=[0,22.5,45,67.5,90,112.5,135,157.5,180,202.5,225,247.5,270,292.5,315,337.5];

#my  $specialDirSign=[0,45,135,270,292.5];


my  $sourceFluentBatchFile="D:\\huaiLaiUnder\\huaiLaiNew20190722\\huaiLaiNew20190722\\noTurbine\\10.00\\90\\huailai20m2\\fluentInterface\\batchFluent2000";

foreach my $name ( @$specialDirSign ) {
    my  $tempdirectory=sprintf("$directory\\$name\\huailai20m2\\fluentInterface\\");
    my  $destinationFile="$tempdirectory\\batchFluent2000";

    copy($sourceFluentBatchFile,$destinationFile) or die "Copy failed: $!";
    #my  $tempBatchFile=sprintf("$directory\\$name\\huailai20m2\\batchFluent.bat");

    print "$tempdirectory\n";
    chdir($tempdirectory);
    my  $mypath=getcwd();
    print " Temp Director: -----------> $mypath\n";
    #system($tempBatchFile)

    system("fluent 3d -i batchFluent2000");
}

快速格式化项目的batchFluent2000

use strict;
use warnings;

use File::Slurp qw(read_file write_file);
#open(FEIJI,"C:\\Users\\yezhaoliang\\Desktop\\probe.cse") or die "can't open the file \n";

#my $car ="@lidarX1";



my $filename = "C:\\Users\\yezhaoliang\\Desktop\\batchFluent2000";

my  $projectOld="huailai20m2";
my  $projectNew="YangJiang";
my $data = read_file $filename, {binmode => 'utf8'};
## 文件内容替换---- 也可以用IO:All->slurp函数


$data =~ s/$projectOld/$projectNew/g;
## 删除掉^M

$data =~ s/\r//g;
write_file $filename, {binmode => ':utf8'},$data;

技术升维

  1. 思考目录结构
  2. 思考要执行命令
  3. 思考命令执行的内容—可升级对应文件内容的修改
  4. 一个可以生成你需要的可执行程序,并具备普适性!Macro programming

附录

  1. perl单行替换文件内容(先temp,然后rename到原始文件名,删除temp备份)
  2. perl s替换
  3. perl slurp(输入s命令到slurp中,执行! `cpanm <:Slurp>`)
  4. File::Slurp edit_file command file

        use File::Slurp qw(edit_file);
        # perl -0777 -pi -e 's/foo/bar/g' /path/file
    
        edit_file { s/foo/bar/g } '/path/file';
        edit_file sub { s/foo/bar/g }, '/path/file';
        sub replace_foo { s/foo/bar/g }
        edit_file \&replace_foo, '/path/file';
        
  5. perl slurp bugs and unmaintained 可以选用Slurper, Path:Tiny or Io:ALL

  6. path::Tiny `path(“foo.txt”)->move(“bar.txt”);`

  7. 简单处理IO::All

  8. 虽然slurp废弃了,但发现依然不错文件内容单行处理,所以无法循环,没有if判断等。但可以执行批处理,而IO:All使用 `my $line = $io->getline` ,其实使用内置的函数即可`while(<$fh>)`即可

             use strict;
             use warnings;
             use File::Slurp qw(read_file write_file);
             my $filename = "C:\\Users\\yezhaoliang\\Desktop\\probe.cse";
    
        ##gbk or gb2312
    
             my $data = read_file $filename, {binmode => 'gbk'};
             ## 文件内容替换---- 也可以用IO:All->slurp函数
    
             $data =~ s/风廓线/小心了/g;
             ## 删除掉^M
    
             $data =~ s/\r//g;
             write_file $filename, {binmode => ':gbk'},$data;
        

    英文替换

        use strict;
        use warnings;
        use File::Slurp qw(read_file write_file);
        my $filename = "C:\\Users\\yezhaoliang\\Desktop\\probe.cse";
    
        my $data = read_file $filename, {binmode => 'utf8'};
        ## 文件内容替换---- 也可以用IO:All->slurp函数
    
        $data =~ s/lidar/Leida/g;
        ## 删除掉^M
    
        $data =~ s/\r//g;
        write_file $filename, {binmode => ':utf8'},$data;
        
  9. 回归到原始程序,只用内置函数

        open(F1,'<test.txt');
        open(F2,'>test.txt.tmp');
        while ($s=<F1>){
            $s =~ s/1234/ABCD/g;
            print F2, $s;
        }
        close(F2);
        close(F1);
    
        unlink('test.txt');
        rename('test.txt.tmp','test.txt');
        

    其实外置、内置的思路都是open、循环、删除、重命名的过程这样还可以不断拓展,增加判断等。

增强版的自定义功能

如果遇到某种条件下的文件则执行对应的修正

use strict;
use warnings;


my	$input_file_name = qw"c:\users\yezhaoliang\desktop\probe1.cse";

open  my $input, '<', $input_file_name
    or die  "$0 : failed to open  input file '$input_file_name' : $!\n";


my	$output_file_name = qw"c:\users\yezhaoliang\desktop\probe2.cse"; # output file name


open  my $output, '>', $output_file_name
    or die  "$0 : failed to open  output file '$output_file_name' : $!\n";


while (my $line=<$input>){

    if (  $line =~ m/(^!\@processDir=)/xm) {
        $line =~ s/(^!\@processDir=)/$1She/g;
    }
    elsif (   $line =~ m/(^!\$file\s=\s"(.*)")/xm ) {
        $line =~ s/$2/hello.dat/g;
    }
    print $output $line;
}


close  $output
    or warn "$0 : failed to close output file '$output_file_name' : $!\n";
close  $input
    or warn "$0 : failed to close input file '$input_file_name' : $!\n";

案例1:批量修改batchFluent2000、替换 然后执行【完美版】

  1. 修改
  2. 执行
use strict;
use warnings;
use utf8;
use Cwd;

#my  $directory   = "D:\\huaiLaiUnder\\huaiLaiNew20190722\\huaiLaiNew20190722\\noTurbine\\10.00\\";

my  $directory = "D:\\AIwind\\AIWindCases\\Dongping20191105\\noTurbine\\10.00";
#my  $specialDirSign=[0,22.5,45,67.5,90,112.5,135,157.5,180,202.5,225,247.5,270,292.5,315,337.5];

my  $specialDirSign=[22.5,45,67.5,90,112.5,135,157.5];
#my  $specialDirSign=[0,45,135,270,292.5];


my  $sourceFluentBatchFile="D:\\AIwind\\AIWindCases\\Dongping20191105\\noTurbine\\10.00\\0\\YangJiang\\fluentInterface\\batchFluent2000";

my  $oldProjectName="Huailai20m2";
my  $projectName="YangJiang";

foreach my $name ( @$specialDirSign ) {
    my  $tempdirectory=sprintf("$directory\\$name\\$projectName\\fluentInterface\\");
    my  $destinationFile="$tempdirectory\\batchFluent2000";

    my	$input_file_name = $sourceFluentBatchFile;
    open  my $input, '<', $input_file_name
        or die  "$0 : failed to open  input file '$input_file_name' : $!\n";
    my	$output_file_name = sprintf("$tempdirectory\\batchFluent2000"); # output file name

    open  my $output, '>', $output_file_name
        or die  "$0 : failed to open  output file '$output_file_name' : $!\n";

    while (my $line=<$input>){

        if ( $line =~ m/$oldProjectName/xm) {
            ## 要求1

            $line =~ s/$oldProjectName/$projectName/gm
        }
        print $output $line;
    }

    close  $output
        or warn "$0 : failed to close output file '$output_file_name' : $!\n";
    close  $input
        or warn "$0 : failed to close input file '$input_file_name' : $!\n";


    #copy($sourceFluentBatchFile,$destinationFile) or die "Copy failed: $!";

    #my  $tempBatchFile=sprintf("$directory\\$name\\huailai20m2\\batchFluent.bat");

    print "$tempdirectory\n";
    chdir($tempdirectory);
    my  $mypath=getcwd();
    print " Temp Director: -----------> $mypath\n";
    #system($tempBatchFile)

    system("fluent 3d -i batchFluent2000");
}

案例2:批量修改probelinesAndexport.cse、替换 然后执行【完美版】

原先是使用copy命令,现在完全用perl程序,控制不同扇区或者速度的修正,并更新到对应文件后,写入到具体目录, 最终执行即可!

  1. 修改
  2. 执行
use strict;
use warnings;
use Cwd;

#my  $directory   = "D:\\huaiLaiUnder\\huaiLaiNew20190722\\huaiLaiNew20190722\\noTurbine\\10.00\\";

my  $directory = "D:\\AIwind\\AIWindCases\\Dongping20191105\\noTurbine\\10.00";
#my  $specialDirSign=[0,22.5,45,67.5,90,112.5,135,157.5,180,202.5,225,247.5,270,292.5,315,337.5];

my  $specialDirSign=[22.5,45,67.5,90,112.5,135,157.5];
#my  $specialDirSign=[0,45,135,270,292.5];

my  $projectName="YangJiang";

my  $sourceFluentBatchFile="D:\\AIwind\\AIWindCases\\Dongping20191105\\noTurbine\\10.00\\0\\YangJiang\\fluentInterface\\probeLinesAndExportYangJiang.cse";

foreach my $Sectorname ( @$specialDirSign ) {
    my  $tempdirectory=sprintf("$directory\\$Sectorname\\$projectName\\fluentInterface\\");

    my	$input_file_name = $sourceFluentBatchFile;
    open  my $input, '<', $input_file_name
        or die  "$0 : failed to open  input file '$input_file_name' : $!\n";
    my	$output_file_name = sprintf("$tempdirectory\\probelinesAndExport.cse"); # output file name

    open  my $output, '>', $output_file_name
        or die  "$0 : failed to open  output file '$output_file_name' : $!\n";

    while (my $line=<$input>){

        if ( $line =~ m/(^!\@processDir=\("(.*)"\))/xm) {
            $line = sprintf("!\@processDir=\"$tempdirectory\";");
            ## 要求1

            $line =~ s/\\/\\\\/gxm
        }
        elsif (  $line =~ m/(^!\$file\s=\s"(.*)")/xm ) {
            ## 规律

            $line =~ s/$2/${projectName}20001.dat/xg;
        }
        print $output $line;
    }

    close  $output
        or warn "$0 : failed to close output file '$output_file_name' : $!\n";
    close  $input
        or warn "$0 : failed to close input file '$input_file_name' : $!\n";

    #copy($sourceFluentBatchFile,$destinationFile) or die "Copy failed: $!";

    #my  $tempBatchFile=sprintf("$directory\\$name\\huailai20m2\\batchFluent.bat");

    print "$tempdirectory\n";
    chdir($tempdirectory);
    my  $mypath=getcwd();
    print " Temp Director: -----------> $mypath\n";
    #system($tempBatchFile)

    #system("fluent 3d -i batchFluent2000");

    system("cfdpost -batch probeLinesAndExport.cse");
}

上述两个过程案例1、2可以合并

  1. 确定处理哪个case, 烟墩? 怀来? 东平?
  2. 确定源文件是否存在! 原先的BatchFluent2000和cse文件在?
#!/usr/bin/env perl

#===============================================================================

#

#         FILE: journalTransferAIWINDTOFluentCasDat814w.pl

#

#        USAGE: ./journalTransferAIWINDTOFluentCasDat814w.pl

#

#  DESCRIPTION:

#

#      OPTIONS: ---

# REQUIREMENTS: ---

#         BUGS: ---

#        NOTES: ---

#       AUTHOR: YOUR NAME (),

# ORGANIZATION:

#      VERSION: 1.0

#      CREATED: 2019/9/27 1535

#     REVISION: ---

#===============================================================================


use strict;
use warnings;
use utf8;
use Cwd;
use File::Copy;

#my  $directory   = "D:\\huaiLaiUnder\\huaiLaiNew20190722\\huaiLaiNew20190722\\noTurbine\\10.00\\";

my  $directory = "D:\\AIwind\\AIWindCases\\Dongping20191105\\noTurbine\\10.00";
#my  $specialDirSign=[0,22.5,45,67.5,90,112.5,135,157.5,180,202.5,225,247.5,270,292.5,315,337.5];

my  $specialDirSign=[22.5];
#my  $specialDirSign=[0,45,135,270,292.5];


## 确认文件是否存在

my  $sourceFluentBatchFileStep2="D:\\AIwind\\AIWindCases\\Dongping20191105\\noTurbine\\10.00\\0\\YangJiang\\fluentInterface\\batchFluent2000";

## 确认文件是否存在

my  $sourceFluentBatchFileStep3="D:\\AIwind\\AIWindCases\\Dongping20191105\\noTurbine\\10.00\\0\\YangJiang\\fluentInterface\\probeLinesAndExportYangJiang.cse";

## step1

my $sourceFileDirs="D:\\AIwind\\AIWindCases\\Dongping20191105\\noTurbine\\10.00\\0\\YangJiang\\";
my  $targetFileSign1="foamDataToFluentDict";
my  $targetFileSign2="batchFluent.bat";
my  $projectVelocity='10.00';
my $projectName="YangJiang";

## step2

my  $oldProjectName="Huailai20m2";
#my  $projectName="YangJiang";


foreach my $name ( @$specialDirSign ) {


    ###########################STEP 2 ###########################

    my  $tempdirectory=sprintf("$directory\\$name\\$projectName\\fluentInterface\\");
    my  $destinationFile="$tempdirectory\\batchFluent2000";

    my	$input_file_name = $sourceFluentBatchFileStep2;
    open  my $input, '<', $input_file_name
        or die  "$0 : failed to open  input file '$input_file_name' : $!\n";
    my	$output_file_name = sprintf("$tempdirectory\\batchFluent2000"); # output file name

    open  my $output, '>', $output_file_name
        or die  "$0 : failed to open  output file '$output_file_name' : $!\n";

    while (my $line=<$input>){

        if ( $line =~ m/$oldProjectName/xm) {
            ## 要求1

            $line =~ s/$oldProjectName/$projectName/gm
        }
        print $output $line;
    }

    close  $output
        or warn "$0 : failed to close output file '$output_file_name' : $!\n";
    close  $input
        or warn "$0 : failed to close input file '$input_file_name' : $!\n";


    #copy($sourceFluentBatchFile,$destinationFile) or die "Copy failed: $!";

    #my  $tempBatchFile=sprintf("$directory\\$name\\huailai20m2\\batchFluent.bat");

    print "$tempdirectory\n";
    chdir($tempdirectory);
    my  $mypath=getcwd();
    print " Temp Director: -----------> $mypath\n";
    #system($tempBatchFile)

    system("fluent 3d -i batchFluent2000");

    ###########################STEP 2 ###########################


    ###########################STEP 3 ###########################

    my	$input_file_name = $sourceFluentBatchFileStep3;
    open  my $input, '<', $input_file_name
        or die  "$0 : failed to open  input file '$input_file_name' : $!\n";
    my	$output_file_name = sprintf("$tempdirectory\\probelinesAndExport.cse"); # output file name

    open  my $output, '>', $output_file_name
        or die  "$0 : failed to open  output file '$output_file_name' : $!\n";

    while (my $line=<$input>){

        if ( $line =~ m/(^!\@processDir=\("(.*)"\))/xm) {
            $line = sprintf("!\@processDir=\"$tempdirectory\";");
            ## 要求1

            $line =~ s/\\/\\\\/gxm
        }
        elsif (  $line =~ m/(^!\$file\s=\s"(.*)")/xm ) {
            ## 规律

            $line =~ s/$2/${projectName}20001.dat/xg;
        }
        print $output $line;
    }

    close  $output
        or warn "$0 : failed to close output file '$output_file_name' : $!\n";
    close  $input
        or warn "$0 : failed to close input file '$input_file_name' : $!\n";

    #copy($sourceFluentBatchFile,$destinationFile) or die "Copy failed: $!";

    #my  $tempBatchFile=sprintf("$directory\\$name\\huailai20m2\\batchFluent.bat");

    print "$tempdirectory\n";
    chdir($tempdirectory);
    my  $mypath=getcwd();
    print " Temp Director: -----------> $mypath\n";
    #system($tempBatchFile)

    #system("fluent 3d -i batchFluent2000");

    system("cfdpost -batch probeLinesAndExport.cse");

    ###########################STEP 3 ###########################


}
Avatar
Ye Zhaoliang
Engineer of offshore wind turbine technique research

My research interests include distributed energy, wind turbine power generation technique , Computational fluid dynamic and programmable matter.

Related

本站访问量: