From 064145c02f52bbd58a46a2afc353d311f9cfdd37 Mon Sep 17 00:00:00 2001 From: "Kellis Kincaid (khk)" Date: Fri, 21 Mar 2025 12:22:11 -0400 Subject: [PATCH] add scan path list to multi-layer utility to allow specification of different scan path files for each heat source/layer --- .../utilities/multiLayer/reconstructLayers | 2 +- applications/utilities/multiLayer/runLayers | 81 ++++++++++++++++--- tutorials/multiLayerPBF/Allrun | 2 +- .../multiLayerPBF/constant/heatSourceDict | 2 +- tutorials/multiLayerPBF/constant/scanPathList | 5 ++ .../constant/{scanPath => scanPath_0} | 0 tutorials/multiLayerPBF/constant/scanPath_1 | 3 + tutorials/multiLayerPBF/system/controlDict | 1 - 8 files changed, 79 insertions(+), 17 deletions(-) create mode 100644 tutorials/multiLayerPBF/constant/scanPathList rename tutorials/multiLayerPBF/constant/{scanPath => scanPath_0} (100%) create mode 100644 tutorials/multiLayerPBF/constant/scanPath_1 diff --git a/applications/utilities/multiLayer/reconstructLayers b/applications/utilities/multiLayer/reconstructLayers index dcad4369..c8dc7dfc 100755 --- a/applications/utilities/multiLayer/reconstructLayers +++ b/applications/utilities/multiLayer/reconstructLayers @@ -40,7 +40,7 @@ echo "Found $nLayers parallel-in-time layers in $baseDir" for (( layer=$(($nLayers-1)); layer>=0; layer-- )) do - reconstructPar -case "${caseList[$layer]}" -newTimes + reconstructPar -case "${caseList[$layer]}" -newTimes > log.reconstructPar_layer$layer timeList=( $(foamListTimes -case "${caseList[$layer]}" -withZero) ) for time in "${timeList[@]:1}" do diff --git a/applications/utilities/multiLayer/runLayers b/applications/utilities/multiLayer/runLayers index 17552dd5..849022a8 100755 --- a/applications/utilities/multiLayer/runLayers +++ b/applications/utilities/multiLayer/runLayers @@ -41,6 +41,7 @@ options: -nLayers number of layers -layerThickness thickness of each layer (deposition) -nCellsPerLayer number of desired cells in each deposited layer + -scanPathList list of scan path files for each source and layer -help print the usage * Run an additiveFoam simulation for sequential layers. * Currently, only a single repeating scan pattern is supported. @@ -73,6 +74,10 @@ do nCellsPerLayer="$2" shift 2 ;; + -scanPathList) + scanPathList="$2" + shift 2 + ;; --) shift break @@ -86,7 +91,32 @@ do esac done -args_check $nLayers $layerThickness $nCellsPerLayer +args_check $nLayers $layerThickness $nCellsPerLayer $scanPathList + +# Check number of heat sources +nSources=`foamDictionary -entry sources -value constant/heatSourceDict | wc -w` +nSources=$(($nSources - 2)) + +# Check that scan path list contains files for all sources and layers +nScanPathFiles=`grep -c "" $scanPathList` + +# Discard first line of scanPathList which contains source names +nScanPathFiles=$((nScanPathFiles - 1)) + +if [ $nScanPathFiles != $nLayers ]; then + echo "runLayers error: number of files in scan path list must match" + echo "number of layers." + exit 1 +fi + +# Check that there is a scan path list for each heat source +nSourceLists=`head -n 1 $scanPathList | wc -w` + +if [ $nSourceLists != $nSources ]; then + echo "runLayers error: number of sources in scan path list must match" + echo "number of sources in heatSourceDict." + exit 1 +fi # create case directories baseDir=${PWD} @@ -101,6 +131,19 @@ do cp -r "$baseDir/0" $case cp -r "$baseDir/constant" $case cp -r "$baseDir/system" $case + + # Iterate over list of heat sources + for (( source=0; source<$nSources; source++ )) + do + # Get name of current heat source + sourceName=`head -n 1 $scanPathList | cut -d " " -f $(($source + 1))` + + # Get name of scan path file associated with current heat source and layer + layerPathName=`head -n $(($layer + 2)) $scanPathList | tail -n 1 | cut -d " " -f $(($source + 1))` + + # Set scan path for current heat source / layer + foamDictionary -entry $sourceName/pathName -set $layerPathName $case/constant/heatSourceDict + done done # extrude mesh in each directory @@ -137,19 +180,27 @@ do time="$(foamDictionary -entry endTime -value $previous/system/controlDict)" # update start and end time of simulation + echo "Setting up layer $layer..." + echo "" mv 0 "$time" endTime=`awk "BEGIN {print $time + $layerTime; exit}"` foamDictionary -entry startTime -set $time system/controlDict foamDictionary -entry endTime -set $endTime system/controlDict - # update wait time for scan path (assumes repeating scan) - path=(`sed '2q;d' constant/scanPath`) - path[5]=$time - path=`echo $(echo ${path[@]}) | tr ' ' '\t\t'` - sed -i "2s/.*/$path/" "$case/constant/scanPath" + # Update wait time for scan path (assumes all layers/sources have equal times) + for (( source=0; source<$nSources; source++ )) + do + # Get name of scan path file associated with current heat source and layer + layerPathName=`head -n $(($layer + 2)) $scanPathList | tail -n 1 | cut -d " " -f $(($source + 1))` + + path=(`sed '2q;d' constant/$layerPathName`) + path[5]=$time + path=`echo $(echo ${path[@]}) | tr ' ' '\t\t'` + sed -i "2s/.*/$path/" "$case/constant/$layerPathName" + done # map previous layer fields to new layer - mapFields -case $case -sourceTime "$time" -mapMethod mapNearest $previous + mapFields -case $case -sourceTime "$time" -mapMethod mapNearest $previous > log.mapFields fi thickness="$(foamDictionary -entry linearDirectionCoeffs/thickness -value system/extrudeMeshDict)" @@ -169,12 +220,16 @@ do nProcs="$(foamDictionary -entry numberOfSubdomains -value system/decomposeParDict)" - transformPoints "translate=(0 0 -$thickness)" - setFields - decomposePar - mpirun -np $nProcs additiveFoam -parallel - reconstructPar -latestTime - transformPoints "translate=(0 0 $thickness)" + transformPoints "translate=(0 0 -$thickness)" > log.transformPoints_0 + setFields > log.setFields + decomposePar > log.decomposePar + echo "Running additiveFoam for layer $layer..." + echo "" + mpirun -np $nProcs additiveFoam -parallel > log.additiveFoam + reconstructPar -latestTime > log.reconstructPar + transformPoints "translate=(0 0 $thickness)" > log.transformPoints_1 + echo "Completed layer $layer." + echo "" done #------------------------------------------------------------------------------ diff --git a/tutorials/multiLayerPBF/Allrun b/tutorials/multiLayerPBF/Allrun index 1503c12c..b0e2b9dd 100755 --- a/tutorials/multiLayerPBF/Allrun +++ b/tutorials/multiLayerPBF/Allrun @@ -29,7 +29,7 @@ runApplication blockMesh # Change to AdditiveFOAM install path path="$WM_PROJECT_INST_DIR/AdditiveFOAM/applications/utilities/multiLayer" -$path/runLayers -nLayers 4 -nCellsPerLayer 4 -layerThickness 40e-6 +$path/runLayers -nLayers 4 -nCellsPerLayer 4 -layerThickness 40e-6 -scanPathList constant/scanPathList $path/reconstructLayers #------------------------------------------------------------------------------ diff --git a/tutorials/multiLayerPBF/constant/heatSourceDict b/tutorials/multiLayerPBF/constant/heatSourceDict index 0c24aa03..5b1e745e 100644 --- a/tutorials/multiLayerPBF/constant/heatSourceDict +++ b/tutorials/multiLayerPBF/constant/heatSourceDict @@ -25,7 +25,7 @@ Citation: \*---------------------------------------------------------------------------*/ beam { - pathName scanPath; + pathName scanPath_0; absorptionModel Kelly; KellyCoeffs diff --git a/tutorials/multiLayerPBF/constant/scanPathList b/tutorials/multiLayerPBF/constant/scanPathList new file mode 100644 index 00000000..b925e6b8 --- /dev/null +++ b/tutorials/multiLayerPBF/constant/scanPathList @@ -0,0 +1,5 @@ +beam +scanPath_0 +scanPath_1 +scanPath_0 +scanPath_1 diff --git a/tutorials/multiLayerPBF/constant/scanPath b/tutorials/multiLayerPBF/constant/scanPath_0 similarity index 100% rename from tutorials/multiLayerPBF/constant/scanPath rename to tutorials/multiLayerPBF/constant/scanPath_0 diff --git a/tutorials/multiLayerPBF/constant/scanPath_1 b/tutorials/multiLayerPBF/constant/scanPath_1 new file mode 100644 index 00000000..0ecd555c --- /dev/null +++ b/tutorials/multiLayerPBF/constant/scanPath_1 @@ -0,0 +1,3 @@ +Mode X Y Z Power Param +1 0.002 0.000 0 0 0 +0 0.000 0.000 0 195.0 0.8 diff --git a/tutorials/multiLayerPBF/system/controlDict b/tutorials/multiLayerPBF/system/controlDict index 7a3443c1..46e522e7 100644 --- a/tutorials/multiLayerPBF/system/controlDict +++ b/tutorials/multiLayerPBF/system/controlDict @@ -55,7 +55,6 @@ maxAlphaCo 1; functions { - #includeFunc ExaCA }