From 536085f67fc08966bab99b4b95450a8c006c3e6b Mon Sep 17 00:00:00 2001 From: John Date: Fri, 19 Sep 2025 15:24:46 -0400 Subject: [PATCH 1/8] add function object for solidification data --- .../additiveFoam/functionObjects/Make/files | 4 + .../additiveFoam/functionObjects/Make/options | 7 + .../solidificationData/solidificationData.C | 231 ++++++++++++++++++ .../solidificationData/solidificationData.H | 135 ++++++++++ tutorials/AMB2018-02-B/Allclean | 2 + tutorials/AMB2018-02-B/Allrun | 6 - tutorials/AMB2018-02-B/system/ExaCA | 19 -- tutorials/AMB2018-02-B/system/controlDict | 21 ++ tutorials/multiBeam/Allclean | 2 + tutorials/multiBeam/Allrun | 6 - tutorials/multiBeam/system/ExaCA | 19 -- tutorials/multiBeam/system/controlDict | 22 +- tutorials/multiLayerPBF/Allclean | 7 +- tutorials/multiLayerPBF/Allrun | 6 - tutorials/multiLayerPBF/system/ExaCA | 19 -- tutorials/multiLayerPBF/system/controlDict | 22 ++ 16 files changed, 447 insertions(+), 81 deletions(-) create mode 100644 applications/solvers/additiveFoam/functionObjects/Make/files create mode 100644 applications/solvers/additiveFoam/functionObjects/Make/options create mode 100644 applications/solvers/additiveFoam/functionObjects/solidificationData/solidificationData.C create mode 100644 applications/solvers/additiveFoam/functionObjects/solidificationData/solidificationData.H delete mode 100644 tutorials/AMB2018-02-B/system/ExaCA delete mode 100644 tutorials/multiBeam/system/ExaCA delete mode 100644 tutorials/multiLayerPBF/system/ExaCA diff --git a/applications/solvers/additiveFoam/functionObjects/Make/files b/applications/solvers/additiveFoam/functionObjects/Make/files new file mode 100644 index 0000000..194ab9e --- /dev/null +++ b/applications/solvers/additiveFoam/functionObjects/Make/files @@ -0,0 +1,4 @@ +ExaCA/ExaCA.C +solidificationData/solidificationData.C + +LIB = $(FOAM_USER_LIBBIN)/libadditiveFoamFunctionObjects diff --git a/applications/solvers/additiveFoam/functionObjects/Make/options b/applications/solvers/additiveFoam/functionObjects/Make/options new file mode 100644 index 0000000..a3ae8da --- /dev/null +++ b/applications/solvers/additiveFoam/functionObjects/Make/options @@ -0,0 +1,7 @@ +EXE_INC = \ + -I$(LIB_SRC)/finiteVolume/lnInclude \ + -I$(LIB_SRC)/meshTools/lnInclude + +LIB_LIBS = \ + -lfiniteVolume \ + -lmeshTools diff --git a/applications/solvers/additiveFoam/functionObjects/solidificationData/solidificationData.C b/applications/solvers/additiveFoam/functionObjects/solidificationData/solidificationData.C new file mode 100644 index 0000000..47e589a --- /dev/null +++ b/applications/solvers/additiveFoam/functionObjects/solidificationData/solidificationData.C @@ -0,0 +1,231 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2024 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2023 Oak Ridge National Laboratory +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "solidificationData.H" +#include "Time.H" +#include "fvMesh.H" +#include "addToRunTimeSelectionTable.H" +#include "volFields.H" +#include "fvc.H" +#include "OFstream.H" +#include "OSspecific.H" +#include "labelVector.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ +namespace functionObjects +{ + defineTypeNameAndDebug(solidificationData, 0); + + addToRunTimeSelectionTable + ( + functionObject, + solidificationData, + dictionary + ); +} +} + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::functionObjects::solidificationData::solidificationData +( + const word& name, + const Time& runTime, + const dictionary& dict +) +: + fvMeshFunctionObject(name, runTime, dict), + T_(mesh_.lookupObject>("T")), + R_ + ( + IOobject + ( + "R", + mesh_.time().timeName(), + mesh_, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + fvc::ddt(T_) + ), + searchEngine_(mesh_, polyMesh::CELL_TETS) +{ + read(dict); + + setOverlapCells(); +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::functionObjects::solidificationData::~solidificationData() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +bool Foam::functionObjects::solidificationData::read(const dictionary& dict) +{ + box_ = dict.lookup("box"); + isoValue_ = dict.lookup("isoValue"); + + return true; +} + +void Foam::functionObjects::solidificationData::setOverlapCells() +{ + // create a compact cell-stencil using the overlap sub-space + const pointField& points = mesh_.points(); + + boundBox procBb(points); + + const vector extend = 1e-10*vector::one; + + if (procBb.overlaps(box_)) + { + forAll(mesh_.cells(), celli) + { + boundBox cellBb(point::max, point::min); + + const labelList& vertices = mesh_.cellPoints()[celli]; + + forAll(vertices, i) + { + cellBb.min() = min(cellBb.min(), points[vertices[i]] - extend); + cellBb.max() = max(cellBb.max(), points[vertices[i]] + extend); + } + + if (cellBb.overlaps(box_)) + { + overlapCells.append(celli); + } + } + } + + overlapCells.shrink(); +} + + +Foam::wordList Foam::functionObjects::solidificationData::fields() const +{ + return wordList::null(); +} + + +bool Foam::functionObjects::solidificationData::execute() +{ + //- Get current time + const scalar& time = mesh_.time().value(); + + //- Get the temperature at the previous time + const volScalarField& T0_ = T_.oldTime(); + + //- Calculate the thermal gradient + const volScalarField G("G", mag(fvc::grad(T_))); + + forAll(overlapCells, i) + { + label celli = overlapCells[i]; + + // Cooled below specified isotherm + if ((T0_[celli] > isoValue_) && (T_[celli] <= isoValue_)) + { + const scalar Ri = mag(R_[celli]); + const scalar Gi = max(G[celli], small); + + const vector pt = mesh_.C()[celli]; + + List event(7); + + event[0] = pt[0]; + event[1] = pt[1]; + event[2] = pt[2]; + event[3] = time; + event[4] = Ri; + event[5] = Gi; + event[6] = Ri / Gi; + + events.append(event); + } + } + + //- Update cooling rate + R_ = fvc::ddt(T_); + + return true; +} + +bool Foam::functionObjects::solidificationData::end() +{ + Info<< "Number of solidification events: " + << returnReduce(events.size(), sumOp()) << endl; + + const fileName filePath + ( + mesh_.time().rootPath() + /mesh_.time().globalCaseName() + /"solidificationData" + ); + + mkDir(filePath); + + OFstream os + ( + filePath + "/" + "data_" + Foam::name(Pstream::myProcNo()) + ".csv" + ); + + os << "x,y,z,t,R,G,V" << endl; + + for(int i=0; i < events.size(); i++) + { + int n = events[i].size() - 1; + + for(int j=0; j < n; j++) + { + os << events[i][j] << ","; + } + os << events[i][n] << "\n"; + } + + Info<< "Successfully wrote solidification data in: " + << returnReduce(mesh_.time().cpuTimeIncrement(), maxOp()) << " s" + << endl << endl; + + return true; +} + + +bool Foam::functionObjects::solidificationData::write() +{ + return true; +} + + +// ************************************************************************* // diff --git a/applications/solvers/additiveFoam/functionObjects/solidificationData/solidificationData.H b/applications/solvers/additiveFoam/functionObjects/solidificationData/solidificationData.H new file mode 100644 index 0000000..519c0ae --- /dev/null +++ b/applications/solvers/additiveFoam/functionObjects/solidificationData/solidificationData.H @@ -0,0 +1,135 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2024 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2023 Oak Ridge National Laboratory +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +Class + Foam::functionObjects::solidificationData + +SourceFiles + solidificationData.C + +\*---------------------------------------------------------------------------*/ + +#ifndef solidificationData_H +#define solidificationData_H + +#include "fvMeshFunctionObject.H" +#include "volFields.H" +#include "meshSearch.H" +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace functionObjects +{ + +/*---------------------------------------------------------------------------*\ + Class solidificationData Declaration +\*---------------------------------------------------------------------------*/ + +class solidificationData +: + public fvMeshFunctionObject +{ + // Private Data + + const volScalarField& T_; + + volScalarField R_; + + DynamicList