From ae456bd358dda830565edec9165719de45d63225 Mon Sep 17 00:00:00 2001 From: John Date: Mon, 4 May 2026 14:09:01 -0400 Subject: [PATCH 1/7] added refinement model --- .../solvers/additiveFoam/additiveFoam.C | 1 - .../additiveFoam/movingHeatSource/Make/files | 8 + .../heatSourceModel/heatSourceModel.H | 2 +- .../movingHeatSource/movingBeam/movingBeam.H | 21 +- .../dynamicTimeIntervals.C | 213 +++++++++ .../dynamicTimeIntervals.H | 131 ++++++ .../noRefinementModel/noRefinementModel.C | 54 +++ .../noRefinementModel/noRefinementModel.H | 108 +++++ .../refinementModel/refinementModel.C | 418 ++++++++++++++++++ .../refinementModel/refinementModel.H | 200 +++++++++ .../refinementModel/refinementModelNew.C | 73 +++ .../refinementVolume/refinementVolume.C | 165 +++++++ .../refinementVolume/refinementVolume.H | 125 ++++++ .../staticTimeIntervals/staticTimeIntervals.C | 121 +++++ .../staticTimeIntervals/staticTimeIntervals.H | 119 +++++ .../refinementModels/timeStep/timeStep.C | 88 ++++ .../refinementModels/timeStep/timeStep.H | 101 +++++ 17 files changed, 1939 insertions(+), 9 deletions(-) create mode 100644 applications/solvers/additiveFoam/movingHeatSource/refinementModels/dynamicTimeIntervals/dynamicTimeIntervals.C create mode 100644 applications/solvers/additiveFoam/movingHeatSource/refinementModels/dynamicTimeIntervals/dynamicTimeIntervals.H create mode 100644 applications/solvers/additiveFoam/movingHeatSource/refinementModels/noRefinementModel/noRefinementModel.C create mode 100644 applications/solvers/additiveFoam/movingHeatSource/refinementModels/noRefinementModel/noRefinementModel.H create mode 100644 applications/solvers/additiveFoam/movingHeatSource/refinementModels/refinementModel/refinementModel.C create mode 100644 applications/solvers/additiveFoam/movingHeatSource/refinementModels/refinementModel/refinementModel.H create mode 100644 applications/solvers/additiveFoam/movingHeatSource/refinementModels/refinementModel/refinementModelNew.C create mode 100644 applications/solvers/additiveFoam/movingHeatSource/refinementModels/refinementVolume/refinementVolume.C create mode 100644 applications/solvers/additiveFoam/movingHeatSource/refinementModels/refinementVolume/refinementVolume.H create mode 100644 applications/solvers/additiveFoam/movingHeatSource/refinementModels/staticTimeIntervals/staticTimeIntervals.C create mode 100644 applications/solvers/additiveFoam/movingHeatSource/refinementModels/staticTimeIntervals/staticTimeIntervals.H create mode 100644 applications/solvers/additiveFoam/movingHeatSource/refinementModels/timeStep/timeStep.C create mode 100644 applications/solvers/additiveFoam/movingHeatSource/refinementModels/timeStep/timeStep.H diff --git a/applications/solvers/additiveFoam/additiveFoam.C b/applications/solvers/additiveFoam/additiveFoam.C index 6a901be..285d195 100644 --- a/applications/solvers/additiveFoam/additiveFoam.C +++ b/applications/solvers/additiveFoam/additiveFoam.C @@ -54,7 +54,6 @@ Description #include "EulerDdtScheme.H" #include "CrankNicolsonDdtScheme.H" -// AdditiveFOAM Headers #include "additiveFoamInfo.H" #include "movingHeatSourceModel.H" #include "graph.H" diff --git a/applications/solvers/additiveFoam/movingHeatSource/Make/files b/applications/solvers/additiveFoam/movingHeatSource/Make/files index 4fa0112..236e76e 100644 --- a/applications/solvers/additiveFoam/movingHeatSource/Make/files +++ b/applications/solvers/additiveFoam/movingHeatSource/Make/files @@ -13,6 +13,14 @@ heatSourceModels/superGaussian/superGaussian.C heatSourceModels/modifiedSuperGaussian/modifiedSuperGaussian.C heatSourceModels/projectedGaussian/projectedGaussian.C +# refinementModels/refinementModel/refinementModel.C +# refinementModels/refinementModel/refinementModelNew.C +# refinementModels/norefinementModel/norefinementModel.C +# refinementModels/timeStep/timeStep.C +# refinementModels/staticTimeIntervals/staticTimeIntervals.C +# refinementModels/dynamicTimeIntervals/dynamicTimeIntervals.C +# refinementModels/refinementVolume/refinementVolume.C + movingHeatSourceModel/movingHeatSourceModel.C LIB = $(FOAM_USER_LIBBIN)/libmovingBeamModels diff --git a/applications/solvers/additiveFoam/movingHeatSource/heatSourceModels/heatSourceModel/heatSourceModel.H b/applications/solvers/additiveFoam/movingHeatSource/heatSourceModels/heatSourceModel/heatSourceModel.H index 327e07b..29857f0 100644 --- a/applications/solvers/additiveFoam/movingHeatSource/heatSourceModels/heatSourceModel/heatSourceModel.H +++ b/applications/solvers/additiveFoam/movingHeatSource/heatSourceModels/heatSourceModel/heatSourceModel.H @@ -176,7 +176,7 @@ public: } //- Return vector of current heat source dimensions - vector dimensions() + const vector dimensions() const { return dimensions_; } diff --git a/applications/solvers/additiveFoam/movingHeatSource/movingBeam/movingBeam.H b/applications/solvers/additiveFoam/movingHeatSource/movingBeam/movingBeam.H index 5a9af14..ef892a5 100644 --- a/applications/solvers/additiveFoam/movingHeatSource/movingBeam/movingBeam.H +++ b/applications/solvers/additiveFoam/movingHeatSource/movingBeam/movingBeam.H @@ -151,25 +151,29 @@ public: // Member Functions //- Return current position of the moving beam - inline vector position() const + inline vector position() { return position_; } //- Return current power of the moving beam - inline scalar power() const + inline scalar power() { return power_; } - - scalar deltaT() const + + //- Return time step for path + inline scalar deltaT() { return deltaT_; } - //- Read the path file - void readPath(); - + //- Return path end time + inline scalar endTime() + { + return endTime_; + } + //- Returns true if the simulation time is less than path endTime bool activePath(); @@ -181,6 +185,9 @@ public: //- Adjust solution time step to hit pathInterval void adjustDeltaT(scalar& dt); + + //- Read the path file + void readPath(); }; diff --git a/applications/solvers/additiveFoam/movingHeatSource/refinementModels/dynamicTimeIntervals/dynamicTimeIntervals.C b/applications/solvers/additiveFoam/movingHeatSource/refinementModels/dynamicTimeIntervals/dynamicTimeIntervals.C new file mode 100644 index 0000000..4c085c8 --- /dev/null +++ b/applications/solvers/additiveFoam/movingHeatSource/refinementModels/dynamicTimeIntervals/dynamicTimeIntervals.C @@ -0,0 +1,213 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2011-2022 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 "dynamicTimeIntervals.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ +namespace refinementModel +{ + defineTypeNameAndDebug(dynamicTimeIntervals, 0); + addToRunTimeSelectionTable + ( + refinementModel, + dynamicTimeIntervals, + dictionary + ); +} +} + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::refinementModel::dynamicTimeIntervals::dynamicTimeIntervals +( + const PtrList& sources, + const dictionary& dict, + const fvMesh& mesh +) +: + refinementModel(typeName, sources, dict, mesh), + coeffs_(refinementDict_.optionalSubDict(typeName + "Coeffs")), + cellsPerProc_(coeffs_.lookupOrDefault("cellsPerProc", 10000)), + relax_(coeffs_.lookupOrDefault("relax", 0.9)), + unrefinedSize_(coeffs_.lookupOrDefault("unrefinedSize", -1.0)), + minIntervalTime_(0.0), + intervalLength_(0.0), + updateTime_(0.0) +{ + //- Search beams to find maximum number of intervals, corresponding to + // the beam with the highest ratio of scan path length to beam width + scalar maxIntervals = 0.0; + + forAll(sources_, i) + { + const scalar bbLen = sources_[i].beam().totalLength(); + const label bbSpots = sources_[i].beam().nSpots(); + + treeBoundBox beamBb + ( + min(-1.5 * sources_[i].dimensions(), -buffer_), + max(1.5 * sources_[i].dimensions(), buffer_) + ); + + point bbMin = beamBb.min(); + point bbMax = beamBb.max(); + + const scalar bbMaxDim = max(bbMax[0] - bbMin[0], bbMax[1] - bbMin[1]); + + maxIntervals = max(maxIntervals, bbLen / bbMaxDim + bbSpots); + } + + //- Set minimum interval time from the maximum number of intervals + minIntervalTime_ = endTime_ / maxIntervals; + + //- Target mesh size + scalar targetCells = cellsPerProc_ * Pstream::nProcs(); + + //- Find initial mesh size + scalar nCells0 = mesh_.nCells(); + reduce(nCells0, sumOp()); + + //- Provide warning if target mesh size is smaller than initial mesh size + if (nCells0 > targetCells) + { + Info << "dynamicTimeIntervals: WARNING - initial mesh size larger than " + "target mesh size." << endl; + } + //- Otherwise, estimate refined volume required to hit target mesh size + else + { + //- Estimate unrefined mesh size if not provided + if (unrefinedSize_ < 0.0) + { + unrefinedSize_ = gSum(mesh_.V()) / nCells0; + + Info << "dynamicTimeIntervals: estimated unrefined mesh size " + << "to be " << unrefinedSize_ << " m." << endl; + } + + //- Estimate volume of refined scan path to hit target mesh size + const scalar refVol + = Foam::pow(unrefinedSize_, 3.0) * (targetCells - nCells0) + / (Foam::pow(2.0, 3.0 * nLevels_) - 1.0); + + //- Refine first interval using volume estimate, and set next update + // time using the refinementModel::refineUsingVolume function + updateTime_ = + refinementModel::refineUsingVolume + ( + refVol, + minIntervalTime_ + ).value(); + + intervalLength_ + = max(updateTime_ - mesh_.time().value(), minIntervalTime_); + + const scalar intervals = endTime_ / intervalLength_; + + Info << "dynamicTimeIntervals: estimated length of first interval to " + << "be " << intervalLength_ << " s from refined scan path volume," + << " corresponding to " << intervals << " intervals." << endl; + } +} + + +// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // + +bool Foam::refinementModel::dynamicTimeIntervals::update() +{ + //- Update if mesh time equals update time + // OR if time index is equal to the max refinement level. + // This second condition adjusts the mesh after the guess at the first + // refinement interval size to prevent an overly long first interval. + if ((updateTime_ - mesh_.time().value() < small) + || + (mesh_.time().timeIndex() == nLevels_ + 1)) + { + //- Refine in regions above specified temperature + refinementModel::refineUsingTemperature(); + + //- Don't perform additional refinements if scan path is completed + if ((endTime_ - mesh_.time().value()) < small) + { + Info << "dynamicTimeIntervals: Scan path completed. Continuing AMR" + << " checks for possible mesh coarsening" << endl; + + updateTime_ = mesh_.time().value() + intervalLength_; + + return true; + } + + //- Calculate current CPU load (cells per processor) + label nCells = mesh_.nCells(); + reduce(nCells, sumOp