Skip to content

Commit b0fa890

Browse files
Added ExaCA support to all tutorials (#39)
* Added ExaCA support to all tutorials with optional Allrun -withExaCA flag Co-authored-by: Matt Rolchigo <[email protected]> * cleaned up tutorials and added auto-enabled fucntion option with -withExaCA Allrun flag * Update Allrun to remove exaca openmp setting --------- Co-authored-by: Matt Rolchigo <[email protected]>
1 parent f484321 commit b0fa890

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+392
-115
lines changed

applications/solvers/additiveFoam/createFields.H

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ volScalarField alpha3
2121
runTime.timeName(),
2222
mesh,
2323
IOobject::READ_IF_PRESENT,
24-
IOobject::NO_WRITE
24+
IOobject::AUTO_WRITE
2525
),
2626
mesh,
2727
dimensionedScalar("alpha.powder", dimless, 0.0),

applications/solvers/additiveFoam/functionObjects/ExaCA/ExaCA.C

+22-22
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ License
3232
#include "volFields.H"
3333
#include "OFstream.H"
3434
#include "OSspecific.H"
35-
#include "meshSearch.H"
3635
#include "labelVector.H"
3736
#include "pointMVCWeight.H"
3837

@@ -76,7 +75,8 @@ Foam::functionObjects::ExaCA::ExaCA
7675
IOobject::NO_WRITE
7776
),
7877
vpi_.interpolate(T_)
79-
)
78+
),
79+
searchEngine_(mesh_, polyMesh::CELL_TETS)
8080
{
8181
read(dict);
8282

@@ -227,13 +227,11 @@ bool Foam::functionObjects::ExaCA::execute()
227227

228228
void Foam::functionObjects::ExaCA::mapPoints()
229229
{
230-
mesh_.time().cpuTimeIncrement();
231-
232230
if (events.size() == 0)
233231
{
234232
return;
235233
}
236-
234+
237235
// find event sub-space before constructing interpolant weights
238236
const pointField& points = mesh_.points();
239237

@@ -260,15 +258,15 @@ void Foam::functionObjects::ExaCA::mapPoints()
260258
}
261259

262260
// find interpolant weigthts for each point
263-
meshSearch searchEngine(mesh_, polyMesh::CELL_TETS);
264-
265261
label pI = 0;
266262
label seedi = events[0][0];
267263

268264
pointsInCell.setSize(mesh_.nCells());
269265

270266
const labelVector nPoints(vector::one + box_.span() / dx_);
271267

268+
Info << "starting point loop" << endl;
269+
272270
for (label k=0; k < nPoints.z(); ++k)
273271
{
274272
for (label j=0; j < nPoints.y(); ++j)
@@ -282,7 +280,7 @@ void Foam::functionObjects::ExaCA::mapPoints()
282280
// shift point during search to avoid edges in pointMVC
283281
const point spt = pt - vector::one*1e-10;
284282

285-
label celli = searchEngine.findCell(spt, seedi, true);
283+
label celli = searchEngine_.findCell(spt, seedi, true);
286284

287285
if (celli != -1)
288286
{
@@ -296,7 +294,7 @@ void Foam::functionObjects::ExaCA::mapPoints()
296294

297295
pI++;
298296
}
299-
297+
300298
seedi = celli;
301299
}
302300
}
@@ -311,16 +309,10 @@ void Foam::functionObjects::ExaCA::mapPoints()
311309
{
312310
pic.shrink();
313311
}
314-
315-
Info<< "Successfully mapped points to mesh in: "
316-
<< returnReduce(mesh_.time().cpuTimeIncrement(), maxOp<scalar>()) << " s"
317-
<< endl << endl;
318312
}
319313

320314
void Foam::functionObjects::ExaCA::interpolate()
321-
{
322-
mesh_.time().cpuTimeIncrement();
323-
315+
{
324316
if (events.size() == 0)
325317
{
326318
return;
@@ -423,24 +415,28 @@ void Foam::functionObjects::ExaCA::interpolate()
423415
}
424416
os << data[i][n] << "\n";
425417
}
426-
427-
Info<< "Successfully interpolated and wrote ExaCA data in: "
428-
<< returnReduce(mesh_.time().cpuTimeIncrement(), maxOp<scalar>()) << " s"
429-
<< endl << endl;
430418
}
431419

432420
bool Foam::functionObjects::ExaCA::end()
433421
{
422+
//- sort events by cell and in time
434423
events.shrink();
435424

436425
sort(events);
437426

438427
Info<< "Number of solidification events: "
439428
<< returnReduce(events.size(), sumOp<scalar>()) << endl;
440-
441-
mapPoints();
442429

430+
//- map points to cells
431+
mesh_.time().cpuTimeIncrement();
432+
433+
mapPoints();
434+
435+
Info<< "Successfully mapped points to mesh in: "
436+
<< returnReduce(mesh_.time().cpuTimeIncrement(), maxOp<scalar>()) << " s"
437+
<< endl << endl;
443438

439+
//- interpolate and write ExaCA data in reduced data format
444440
const fileName exacaPath
445441
(
446442
mesh_.time().rootPath()/mesh_.time().globalCaseName()/"ExaCA"
@@ -449,6 +445,10 @@ bool Foam::functionObjects::ExaCA::end()
449445
mkDir(exacaPath);
450446

451447
interpolate();
448+
449+
Info<< "Successfully interpolated and wrote ExaCA data in: "
450+
<< returnReduce(mesh_.time().cpuTimeIncrement(), maxOp<scalar>()) << " s"
451+
<< endl << endl;
452452

453453
return true;
454454
}

applications/solvers/additiveFoam/functionObjects/ExaCA/ExaCA.H

+3-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ SourceFiles
3636

3737
#include "fvMeshFunctionObject.H"
3838
#include "volPointInterpolation.H"
39-
39+
#include "meshSearch.H"
4040
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
4141

4242
namespace Foam
@@ -75,6 +75,8 @@ class ExaCA
7575
scalar isoValue_;
7676

7777
scalar dx_;
78+
79+
meshSearch searchEngine_;
7880

7981
// Private Member Functions
8082

applications/utilities/multiLayer/runLayers

+15-1
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,23 @@ do
153153
fi
154154

155155
thickness="$(foamDictionary -entry linearDirectionCoeffs/thickness -value system/extrudeMeshDict)"
156+
157+
# set powder height to the layer thickness
158+
foamDictionary -entry regions -set \
159+
"(
160+
boxToCell
161+
{
162+
box (-1 -1 -$layerThickness) (1 1 1);
163+
fieldValues
164+
(
165+
volScalarFieldValue alpha.powder 1
166+
);
167+
}
168+
)" system/setFieldsDict
169+
156170
nProcs="$(foamDictionary -entry numberOfSubdomains -value system/decomposeParDict)"
157171

158-
transformPoints "translate=(0 0 -$thickness)"
172+
transformPoints "translate=(0 0 -$thickness)"
159173
setFields
160174
decomposePar
161175
mpirun -np $nProcs additiveFoam -parallel

clean.sh

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
3+
# Function to attempt removing .nfs files, even if in use
4+
remove_nfs_files() {
5+
find "$1" -type f -name '.nfs*' | while read -r nfs_file; do
6+
echo "Removing: $nfs_file"
7+
8+
# Find the process holding the file and kill it
9+
lsof_output=$(lsof "$nfs_file" 2>/dev/null)
10+
if [[ -n "$lsof_output" ]]; then
11+
pid=$(echo "$lsof_output" | awk 'NR>1 {print $2}' | sort -u)
12+
if [[ -n "$pid" ]]; then
13+
echo "Killing process $pid holding file $nfs_file"
14+
kill -9 $pid
15+
fi
16+
fi
17+
18+
# Attempt to remove the file again
19+
rm -f "$nfs_file"
20+
done
21+
}
22+
23+
# Navigate through every directory from the current one
24+
echo "Starting search and removal of .nfs files from: $(pwd)"
25+
remove_nfs_files "$(pwd)"
26+
27+
# Traverse through all subdirectories
28+
find . -type d | while read -r dir; do
29+
remove_nfs_files "$dir"
30+
done
31+
32+
echo "Finished removing .nfs files."
33+

tutorials/AMB2018-02-B/Allclean

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ cd ${0%/*} || exit 1 # Run from this directory
55
. $WM_PROJECT_DIR/bin/tools/CleanFunctions
66

77
cleanCase
8-
9-
rm -rf ExaCA
8+
#------------------------------------------------------------------------------
9+
rm -rf ExaCA/Output*
10+
rm -rf ExaCA/time-temperature.csv
1011
#------------------------------------------------------------------------------

tutorials/AMB2018-02-B/Allrun

+29-1
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,41 @@ cd ${0%/*} || exit 1 # Run from this directory
33

44
# Source tutorial run functions
55
. $WM_PROJECT_DIR/bin/tools/RunFunctions
6-
76
application=`getApplication`
87

8+
# Parse arguments
9+
withExaCA=false
10+
while [ "$#" -gt 0 ]; do
11+
case "$1" in
12+
-withExaCA)
13+
withExaCA=true
14+
;;
15+
esac
16+
shift
17+
done
18+
19+
if [ "$withExaCA" = true ]; then
20+
foamDictionary -entry functions -set "{#includeFunc ExaCA}" system/controlDict
21+
else
22+
foamDictionary -entry functions -set "{}" system/controlDict
23+
fi
24+
25+
#------------------------------------------------------------------------------
26+
# AdditiveFOAM
927
runApplication blockMesh
1028
runApplication decomposePar
1129
runParallel $application
1230

1331
runApplication reconstructPar
1432

1533
#------------------------------------------------------------------------------
34+
# ExaCA (Version 2.0.1)
35+
if [ "$withExaCA" = true ]; then
36+
echo "x,y,z,tm,ts,cr" > ExaCA/time-temperature.csv
37+
cat ExaCA/data_* >> ExaCA/time-temperature.csv
38+
rm -rf ExaCA/data_*
39+
40+
NPROCS="$(foamDictionary -expand -entry numberOfSubdomains -value system/decomposeParDict)"
41+
mpirun -np $NPROCS ~/install/exaca/bin/ExaCA ExaCA/input.json
42+
fi
43+
#------------------------------------------------------------------------------
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"SimulationType": "FromFile",
3+
"MaterialFileName": "Inconel625.json",
4+
"GrainOrientationFile": "GrainOrientationVectors.csv",
5+
"RandomSeed": 0,
6+
"Domain": {
7+
"CellSize": 2.5,
8+
"TimeStep": 0.125,
9+
"NumberOfLayers": 1,
10+
"LayerOffset": 0
11+
},
12+
"Nucleation": {
13+
"Density": 100,
14+
"MeanUndercooling": 5,
15+
"StDev": 0.5
16+
},
17+
"TemperatureData": {
18+
"LayerwiseTempRead": false,
19+
"TemperatureFiles": ["./ExaCA/time-temperature.csv"]
20+
},
21+
"Substrate": {
22+
"MeanBaseplateGrainSize": 8.3,
23+
"MeanPowderGrainSize": 2.5
24+
},
25+
"Printing": {
26+
"PathToOutput": "./ExaCA/",
27+
"OutputFile": "Output",
28+
"PrintBinary": false,
29+
"PrintExaConstitSize": 0,
30+
"Interlayer": {
31+
"Fields": ["GrainID", "LayerID", "GrainMisorientation", "UndercoolingCurrent", "SolidificationEventCounter"],
32+
"Layers": [0, 1]
33+
}
34+
}
35+
}

tutorials/AMB2018-02-B/constant/heatSourceDict

+7-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ FoamFile
1717

1818
sources (beam);
1919

20+
/*---------------------------------------------------------------------------*\
21+
Citation:
22+
G.L. Knapp, J. Coleman, M. Rolchigo, M. Stoyanov, A. Plotkowski,
23+
Calibrating uncertain parameters in melt pool simulations of additive
24+
manufacturing (2023), https://doi.org/10.1016/j.commatsci.2022.11190.
25+
\*---------------------------------------------------------------------------*/
2026
beam
2127
{
2228
pathName scanPath;
@@ -25,7 +31,7 @@ beam
2531

2632
constantCoeffs
2733
{
28-
eta 0.3;
34+
eta 0.33;
2935
}
3036

3137
heatSourceModel superGaussian;

tutorials/AMB2018-02-B/system/ExaCA

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ ExaCA
1212
libs ("libExaCAFunctionObject.so");
1313

1414
box (0 -0.0001 -0.0002) (0.002 0.0001 0);
15-
dx 5e-6;
15+
dx 2.5e-6;
1616
isoValue 1620;
1717
}
1818

tutorials/AMB2018-02-B/system/controlDict

+11-7
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
\*---------------------------------------------------------------------------*/
88
FoamFile
99
{
10-
version 2.0;
11-
format ascii;
12-
class dictionary;
13-
location "system";
14-
object controlDict;
10+
version 2;
11+
format ascii;
12+
class dictionary;
13+
location "system";
14+
object controlDict;
1515
}
1616
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1717

@@ -25,7 +25,7 @@ stopAt endTime;
2525

2626
endTime 0.004;
2727

28-
deltaT 1e-7;
28+
deltaT 1e-07;
2929

3030
writeControl adjustableRunTime;
3131

@@ -48,11 +48,15 @@ runTimeModifiable yes;
4848
adjustTimeStep yes;
4949

5050
maxCo 0.5;
51+
5152
maxDi 1;
53+
5254
maxAlphaCo 1;
5355

5456
functions
5557
{
56-
#includeFunc ExaCA
58+
#includeFunc ExaCA
5759
}
60+
61+
5862
// ************************************************************************* //

tutorials/multiBeam/Allclean

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ cd ${0%/*} || exit 1 # Run from this directory
55
. $WM_PROJECT_DIR/bin/tools/CleanFunctions
66

77
cleanCase
8-
9-
rm -rf ExaCA
8+
#------------------------------------------------------------------------------
9+
rm -rf ExaCA/Output*
10+
rm -rf ExaCA/time-temperature.csv
1011
#------------------------------------------------------------------------------

0 commit comments

Comments
 (0)