Created
March 3, 2025 12:20
-
-
Save ekibun/db3fb2199aa5418346c296fd4f68fa26 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$parallelcount = 4 | |
$tasks = @() | |
foreach ($angle in @(1, 3, -3)) { | |
foreach ($ubyfb in @(1, 2)) { | |
$tasks += @{ | |
dir = "v"; | |
velAmpl = "0.02"; | |
rotAmpl = "0.0"; | |
angle = $angle; | |
ubyfb = $ubyfb; | |
} | |
$tasks += @{ | |
dir = "r"; | |
velAmpl = "0.0"; | |
rotAmpl = "2.0"; | |
angle = $angle; | |
ubyfb = $ubyfb; | |
} | |
} | |
} | |
$taskblock = { | |
param($task) | |
Set-Location "$using:PWD" | |
$dir = "$($task.dir)$($task.angle)_$($task.ubyfb)"; | |
mkdir $dir; | |
(@" | |
(define case-name "0d") | |
(define ubyfb $($task.ubyfb)) | |
(define vel-ampl $($task.velAmpl)) | |
(define rot-ampl $($task.rotAmpl)) | |
(define attack-angle $($task.angle))`n | |
"@ + (Get-Content "cdlm.txt" -Raw)) | Out-File "$dir/cdlm.jou" ascii; | |
Copy-Item -Path "libudf" -Destination "$dir/libudf" -Recurse -Force | |
Set-Location "$dir" | |
& "C:\Program Files\ANSYS Inc\v241\fluent\ntbin\win64\fluent.exe" 2ddp -g -t2 -i cdlm.jou | |
} | |
# parallel run tasks | |
Get-Job | Remove-Job | |
$outs = @{} | |
$nextIndex = 0; | |
$taskCount = $tasks.Length; | |
while (($jobs = Get-Job).Length -gt 0 -or $nextIndex -lt $taskCount) { | |
# run task | |
if ($jobs.Length -lt $parallelcount -and $nextIndex -lt $taskCount) { | |
$task = $tasks[$nextIndex]; | |
$nextIndex++; | |
$job = Start-Job -ScriptBlock $taskblock -Name "($nextIndex/$taskCount)" -ArgumentList $task; | |
$outs[$job.Id] = ""; | |
} | |
# refresh output | |
Clear-Host; | |
# check esc to quit | |
Write-Output "press Esc to terminate ...`n" | |
if ([Console]::KeyAvailable) { | |
if ([Console]::ReadKey($true).Key -eq 'Escape') { | |
taskkill /T /F /PID $PID | |
} | |
} | |
# display log | |
foreach ($job in $jobs) { | |
if ($job.State -in ('Completed', 'Failed')) { | |
Remove-Job $job; | |
} | |
else { | |
$job | |
$out = Receive-Job $job; | |
if ($out) { | |
$outs[$job.Id] = $out; | |
} | |
else { | |
$out = $outs[$job.Id]; | |
} | |
($out -split "`n")[-1] | |
} | |
} | |
Start-Sleep -Milliseconds 100 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment