From c77d06326a88eafb9d5e7f82f7d3df4b43b7cf46 Mon Sep 17 00:00:00 2001 From: John Date: Thu, 30 Apr 2026 12:22:56 -0400 Subject: [PATCH 01/17] ported to OpenFOAM-13. Function Objects not yet supported. --- README.md | 2 +- applications/solvers/additiveFoam/Allwmake | 4 +- .../solvers/additiveFoam/Make/options | 3 + .../solvers/additiveFoam/additiveFoam.C | 64 ++-- .../solvers/additiveFoam/additiveFoamInfo.H | 2 +- .../solvers/additiveFoam/createFields.H | 80 +++-- .../marangoni/marangoniFvPatchVectorField.C | 17 +- .../marangoni/marangoniFvPatchVectorField.H | 15 +- .../mixedTemperatureFvPatchScalarField.C | 81 ++--- .../mixedTemperatureFvPatchScalarField.H | 65 ++-- .../functionObjects/ExaCA/ExaCA.C | 2 +- .../solidificationData/solidificationData.C | 2 +- applications/solvers/additiveFoam/moveMesh.H | 59 ++++ .../absorptionModel/absorptionModel.C | 2 +- .../heatSourceModel/heatSourceModel.C | 4 +- .../movingHeatSource/movingBeam/movingBeam.H | 3 +- .../movingHeatSourceModel.C | 4 +- .../movingHeatSourceModel.H | 1 - applications/solvers/additiveFoam/pU/UEqn.H | 2 - applications/solvers/additiveFoam/pU/pEqn.H | 19 +- applications/solvers/additiveFoam/setDeltaT.H | 9 +- .../solvers/additiveFoam/solutionControls.H | 4 +- .../solvers/additiveFoam/thermo/TEqn.H | 2 +- .../solvers/additiveFoam/utilities/Make/files | 4 + .../additiveFoam/utilities/Make/options | 7 + .../additiveFoam/utilities/graph/curve.C | 68 +++++ .../additiveFoam/utilities/graph/curve.H | 181 ++++++++++++ .../additiveFoam/utilities/graph/graph.C | 262 +++++++++++++++++ .../additiveFoam/utilities/graph/graph.H | 278 ++++++++++++++++++ .../interpolateXY/interpolateXY.C | 4 +- .../interpolateXY/interpolateXY.H | 6 +- .../utilities/createScanPath/createFields.H | 2 +- .../utilities/createScanPath/createScanPath.C | 8 +- .../utilities/multiLayer/reconstructLayers | 2 +- applications/utilities/multiLayer/runLayers | 6 +- .../multiLayerPBF/system/extrudeMeshDict | 5 +- 36 files changed, 1089 insertions(+), 190 deletions(-) create mode 100644 applications/solvers/additiveFoam/moveMesh.H create mode 100644 applications/solvers/additiveFoam/utilities/Make/files create mode 100644 applications/solvers/additiveFoam/utilities/Make/options create mode 100644 applications/solvers/additiveFoam/utilities/graph/curve.C create mode 100644 applications/solvers/additiveFoam/utilities/graph/curve.H create mode 100644 applications/solvers/additiveFoam/utilities/graph/graph.C create mode 100644 applications/solvers/additiveFoam/utilities/graph/graph.H rename applications/solvers/additiveFoam/{ => utilities}/interpolateXY/interpolateXY.C (97%) rename applications/solvers/additiveFoam/{ => utilities}/interpolateXY/interpolateXY.H (95%) diff --git a/README.md b/README.md index 85ae7fc7..ae69d800 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ The documentation for `AdditiveFOAM` is hosted on [GitHub Pages](https://ornl.gi | [tutorials](tutorials) | Tutorial cases | ## Installation and Dependencies -[![OpenFOAM-10](https://img.shields.io/badge/OpenFOAM-10-blue.svg)](https://github.com/OpenFOAM/OpenFOAM-10) +[![OpenFOAM-13](https://img.shields.io/badge/OpenFOAM-13-blue.svg)](https://github.com/OpenFOAM/OpenFOAM-13) AdditiveFOAM is built on source code released by the OpenFOAM Foundation [openfoam.org](https://openfoam.org/), which is available in public [OpenFOAM repositories](https://github.com/OpenFOAM). diff --git a/applications/solvers/additiveFoam/Allwmake b/applications/solvers/additiveFoam/Allwmake index e54e7e16..c5b828ad 100755 --- a/applications/solvers/additiveFoam/Allwmake +++ b/applications/solvers/additiveFoam/Allwmake @@ -27,7 +27,9 @@ export ADDITIVEFOAM_BUILD_FLAGS="-DGIT_MODULE_ENABLED=1" #------------------------------------------------------------------------------ # Build libraries and solver -wmake $targetType functionObjects +#wmake $targetType functionObjects + +wmake $targetType utilities wmake $targetType movingHeatSource wmake $targetType diff --git a/applications/solvers/additiveFoam/Make/options b/applications/solvers/additiveFoam/Make/options index c61a6445..2e81c929 100644 --- a/applications/solvers/additiveFoam/Make/options +++ b/applications/solvers/additiveFoam/Make/options @@ -2,13 +2,16 @@ EXE_INC = \ $(ADDITIVEFOAM_BUILD_FLAGS) \ -I. \ -ImovingHeatSource/lnInclude \ + -Iutilities/lnInclude \ -I$(LIB_SRC)/finiteVolume/lnInclude \ + -I$(LIB_SRC)/dynamicMesh/lnInclude \ -I$(LIB_SRC)/meshTools/lnInclude \ -I$(LIB_SRC)/randomProcesses/lnInclude EXE_LIBS = \ -L$(FOAM_USER_LIBBIN) \ -lmovingBeamModels \ + -ladditiveFoamUtilities \ -lfiniteVolume \ -lmeshTools \ -lrandomProcesses diff --git a/applications/solvers/additiveFoam/additiveFoam.C b/applications/solvers/additiveFoam/additiveFoam.C index 20d70b1a..6a901be2 100644 --- a/applications/solvers/additiveFoam/additiveFoam.C +++ b/applications/solvers/additiveFoam/additiveFoam.C @@ -31,58 +31,88 @@ Description simulations. \*---------------------------------------------------------------------------*/ -#include "additiveFoamInfo.H" -#include "fvCFD.H" + +#include "argList.H" +#include "timeSelector.H" +#include "zeroGradientFvPatchFields.H" +#include "IFstream.H" +#include "uniformDimensionedFields.H" +#include "pressureReference.H" +#include "findRefCell.H" + +#include "fvmDiv.H" +#include "fvmDdt.H" +#include "fvcSurfaceIntegrate.H" +#include "fvcVolumeIntegrate.H" +#include "fvmLaplacian.H" +#include "constrainPressure.H" +#include "constrainHbyA.H" #include "pimpleControl.H" -#include "graph.H" +#include "fvCorrectPhi.H" #include "Polynomial.H" -#include "interpolateXY/interpolateXY.H" -#include "movingHeatSourceModel.H" + #include "EulerDdtScheme.H" #include "CrankNicolsonDdtScheme.H" +// AdditiveFOAM Headers +#include "additiveFoamInfo.H" +#include "movingHeatSourceModel.H" +#include "graph.H" +#include "interpolateXY.H" + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // int main(int argc, char *argv[]) -{ +{ + using namespace Foam; + #include "postProcess.H" #include "setRootCase.H" + AdditiveFoamInfo::write(); + #include "createTime.H" #include "createMesh.H" - #include "createControl.H" + #include "createDyMControls.H" #include "createFields.H" - #include "createTimeControls.H" #include "initContinuityErrs.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + // Initialize time-stepping controls scalar DiNum = 0.0; scalar alphaCoNum = 0.0; movingHeatSourceModel sources(mesh); Info<< "\nStarting time loop\n" << endl; - + while (runTime.run()) { #include "updateProperties.H" - #include "readTimeControls.H" + #include "readDyMControls.H" #include "CourantNo.H" #include "setDeltaT.H" sources.update(); - + + mesh.update(); + runTime++; - Info<< "Time = " << runTime.timeName() << nl << endl; + Info<< "Time = " << runTime.name() << nl << endl; #include "solutionControls.H" - - while (pimple.loop() && fluidInDomain) + + while (pimple.loop()) { - #include "pU/UEqn.H" - #include "pU/pEqn.H" + #include "moveMesh.H" + + if (fluidInDomain) + { + #include "pU/UEqn.H" + #include "pU/pEqn.H" + } } #include "thermo/TEqn.H" @@ -93,7 +123,7 @@ int main(int argc, char *argv[]) << " ClockTime = " << runTime.elapsedClockTime() << " s" << nl << endl; } - + return 0; } diff --git a/applications/solvers/additiveFoam/additiveFoamInfo.H b/applications/solvers/additiveFoam/additiveFoamInfo.H index 88cea642..f9b27feb 100644 --- a/applications/solvers/additiveFoam/additiveFoamInfo.H +++ b/applications/solvers/additiveFoam/additiveFoamInfo.H @@ -21,7 +21,7 @@ Description #endif // Static version -#define ADDITIVEFOAM_VERSION "1.2.0-dev" +#define ADDITIVEFOAM_VERSION "2.0.0-dev" namespace Foam { diff --git a/applications/solvers/additiveFoam/createFields.H b/applications/solvers/additiveFoam/createFields.H index a197af73..d49dadfe 100644 --- a/applications/solvers/additiveFoam/createFields.H +++ b/applications/solvers/additiveFoam/createFields.H @@ -4,7 +4,7 @@ volScalarField T IOobject ( "T", - runTime.timeName(), + runTime.name(), mesh, IOobject::MUST_READ, IOobject::AUTO_WRITE @@ -18,7 +18,7 @@ volScalarField alpha3 IOobject ( IOobject::groupName("alpha", "powder"), - runTime.timeName(), + runTime.name(), mesh, IOobject::READ_IF_PRESENT, IOobject::AUTO_WRITE @@ -33,7 +33,7 @@ volScalarField alpha1 IOobject ( IOobject::groupName("alpha", "solid"), - runTime.timeName(), + runTime.name(), mesh, IOobject::NO_READ, IOobject::NO_WRITE @@ -45,7 +45,8 @@ volScalarField alpha1 IFstream thermoFile ( - runTime.rootPath()/runTime.globalCaseName()/runTime.constant()/"thermoPath" + runTime.rootPath()/runTime.globalCaseName() + /runTime.constant()/"thermoPath" ); graph thermo @@ -71,10 +72,10 @@ dimensionedScalar Tsol ); // set solid fraction field consistent with temperature -forAll(mesh.cells(), cellI) +forAll(mesh.cells(), celli) { - scalar alpha1_ = interpolateXY(T[cellI], thermo.x(), thermo.y()); - alpha1[cellI] = min(max(alpha1_, 0.0), 1.0); + scalar alpha1_ = interpolateXY(T[celli], thermo.x(), thermo.y()); + alpha1[celli] = min(max(alpha1_, 0.0), 1.0); } alpha1.correctBoundaryConditions(); @@ -86,7 +87,7 @@ volScalarField Cp IOobject ( "Cp", - runTime.timeName(), + runTime.name(), mesh, IOobject::NO_READ, IOobject::NO_WRITE @@ -101,7 +102,7 @@ volScalarField kappa IOobject ( "kappa", - runTime.timeName(), + runTime.name(), mesh ), mesh, @@ -117,7 +118,7 @@ volScalarField p_rgh IOobject ( "p_rgh", - runTime.timeName(), + runTime.name(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE @@ -132,7 +133,7 @@ volVectorField U IOobject ( "U", - runTime.timeName(), + runTime.name(), mesh, IOobject::READ_IF_PRESENT, IOobject::AUTO_WRITE @@ -148,22 +149,37 @@ volScalarField rhok IOobject ( "rhok", - runTime.timeName(), + runTime.name(), mesh ), 1.0 - beta*(T - Tliq) ); #include "readGravitationalAcceleration.H" -#include "readhRef.H" -#include "gh.H" + +uniformDimensionedScalarField hRef +( + IOobject + ( + "hRef", + runTime.constant(), + mesh, + IOobject::READ_IF_PRESENT, + IOobject::NO_WRITE + ), + dimensionedScalar(dimLength, 0) +); + +dimensionedScalar ghRef(-mag(g)*hRef); +volScalarField gh("gh", (g & mesh.C()) - ghRef); +surfaceScalarField ghf("ghf", (g & mesh.Cf()) - ghRef); volScalarField p ( IOobject ( "p", - runTime.timeName(), + runTime.name(), mesh, IOobject::NO_READ, IOobject::NO_WRITE @@ -171,16 +187,8 @@ volScalarField p p_rgh + rhok*gh ); -label pRefCell = 0; -scalar pRefValue = 0.0; -setRefCell -( - p, - p_rgh, - pimple.dict(), - pRefCell, - pRefValue -); +// Create pressure reference +Foam::pressureReference pressureReference(p, pimple.dict()); if (p_rgh.needReference()) { @@ -188,10 +196,30 @@ if (p_rgh.needReference()) ( "p", p.dimensions(), - pRefValue - getRefCellValue(p, pRefCell) + pressureReference.refValue() + - getRefCellValue(p, pressureReference.refCell()) ); } mesh.schemes().setFluxRequired(p_rgh.name()); #include "createMRF.H" + +autoPtr Uf; +if(mesh.dynamic() || MRF.size()) +{ + U.correctBoundaryConditions(); + + Uf = new surfaceVectorField + ( + IOobject + ( + "Uf", + runTime.name(), + mesh, + IOobject::READ_IF_PRESENT, + IOobject::AUTO_WRITE + ), + fvc::interpolate(U) + ); +} diff --git a/applications/solvers/additiveFoam/derivedFvPatchFields/marangoni/marangoniFvPatchVectorField.C b/applications/solvers/additiveFoam/derivedFvPatchFields/marangoni/marangoniFvPatchVectorField.C index 8788bb7e..4ca6e766 100644 --- a/applications/solvers/additiveFoam/derivedFvPatchFields/marangoni/marangoniFvPatchVectorField.C +++ b/applications/solvers/additiveFoam/derivedFvPatchFields/marangoni/marangoniFvPatchVectorField.C @@ -91,22 +91,13 @@ Foam::marangoniFvPatchVectorField::marangoniFvPatchVectorField // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -void Foam::marangoniFvPatchVectorField::autoMap +void Foam::marangoniFvPatchVectorField::map ( - const fvPatchFieldMapper& m -) -{ - transformFvPatchVectorField::autoMap(m); -} - - -void Foam::marangoniFvPatchVectorField::rmap -( - const fvPatchVectorField& ptf, - const labelList& addr + const fvPatchVectorField& pvf, + const fvPatchFieldMapper& mapper ) { - transformFvPatchVectorField::rmap(ptf, addr); + transformFvPatchVectorField::map(pvf, mapper); } diff --git a/applications/solvers/additiveFoam/derivedFvPatchFields/marangoni/marangoniFvPatchVectorField.H b/applications/solvers/additiveFoam/derivedFvPatchFields/marangoni/marangoniFvPatchVectorField.H index f856c091..5b38e936 100644 --- a/applications/solvers/additiveFoam/derivedFvPatchFields/marangoni/marangoniFvPatchVectorField.H +++ b/applications/solvers/additiveFoam/derivedFvPatchFields/marangoni/marangoniFvPatchVectorField.H @@ -45,7 +45,7 @@ namespace Foam { /*---------------------------------------------------------------------------*\ - Class marangoniFvPatchVectorField Declaration + Class marangoniFvPatchVectorField Declaration \*---------------------------------------------------------------------------*/ class marangoniFvPatchVectorField @@ -123,13 +123,12 @@ public: // Mapping functions - //- Map (and resize as needed) from self given a mapping object - // Used to update fields following mesh topology change - virtual void autoMap(const fvPatchFieldMapper&); - - //- Reverse map the given fvPatchField onto this fvPatchField - // Used to reconstruct fields - virtual void rmap(const fvPatchVectorField&, const labelList&); + //- Map the given fvPatchField onto this fvPatchField + virtual void map + ( + const fvPatchVectorField&, + const fvPatchFieldMapper& + ); //- Reset the fvPatchField to the given fvPatchField // Used for mesh to mesh mapping diff --git a/applications/solvers/additiveFoam/derivedFvPatchFields/mixedTemperature/mixedTemperatureFvPatchScalarField.C b/applications/solvers/additiveFoam/derivedFvPatchFields/mixedTemperature/mixedTemperatureFvPatchScalarField.C index 5f218fba..9f900402 100644 --- a/applications/solvers/additiveFoam/derivedFvPatchFields/mixedTemperature/mixedTemperatureFvPatchScalarField.C +++ b/applications/solvers/additiveFoam/derivedFvPatchFields/mixedTemperature/mixedTemperatureFvPatchScalarField.C @@ -2,10 +2,8 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2023 OpenFOAM Foundation \\/ M anipulation | -------------------------------------------------------------------------------- - Copyright (C) 2023 Oak Ridge National Laboratory ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -33,24 +31,6 @@ License // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -Foam::mixedTemperatureFvPatchScalarField:: -mixedTemperatureFvPatchScalarField -( - const fvPatch& p, - const DimensionedField& iF -) -: - mixedFvPatchScalarField(p, iF), - h_(0.0), - emissivity_(0.0), - Tinf_(p.size(), Zero) -{ - refValue() = Zero; - refGrad() = Zero; - valueFraction() = 1; -} - - Foam::mixedTemperatureFvPatchScalarField:: mixedTemperatureFvPatchScalarField ( @@ -61,25 +41,14 @@ mixedTemperatureFvPatchScalarField : mixedFvPatchScalarField(p, iF), h_(dict.lookup("h")), - emissivity_(dict.lookup("emissivity")), + emissivity_(dict.lookupOrDefault("emissivity", 0.0)), Tinf_("Tinf", dict, p.size()) { - fvPatchScalarField::operator=(scalarField("value", dict, p.size())); + refGrad() = Zero; + valueFraction() = 0.0; - if (dict.found("refValue")) - { - // Full restart - refValue() = scalarField("refValue", dict, p.size()); - refGrad() = scalarField("refGradient", dict, p.size()); - valueFraction() = scalarField("valueFraction", dict, p.size()); - } - else - { - // Start from user entered data. Assume fixedValue. - refValue() = *this; - refGrad() = 0; - valueFraction() = 1; - } + refValue() = scalarField("Tinf", dict, p.size()); + fvPatchScalarField::operator=(refValue()); } @@ -115,28 +84,18 @@ mixedTemperatureFvPatchScalarField // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -void Foam::mixedTemperatureFvPatchScalarField::autoMap -( - const fvPatchFieldMapper& m -) -{ - mixedFvPatchScalarField::autoMap(m); - m(Tinf_, Tinf_); -} - - -void Foam::mixedTemperatureFvPatchScalarField::rmap +void Foam::mixedTemperatureFvPatchScalarField::map ( const fvPatchScalarField& ptf, - const labelList& addr + const fvPatchFieldMapper& mapper ) { - mixedFvPatchScalarField::rmap(ptf, addr); + mixedFvPatchScalarField::map(ptf, mapper); const mixedTemperatureFvPatchScalarField& tiptf = refCast(ptf); - Tinf_.rmap(tiptf.Tinf_, addr); + mapper(Tinf_, tiptf.Tinf_); } @@ -161,27 +120,23 @@ void Foam::mixedTemperatureFvPatchScalarField::updateCoeffs() return; } - refValue() = Tinf_; - + mixedFvPatchScalarField::refValue() = (Tinf_); + const scalarField& Tp(*this); - + const scalarField& kappa_ = patch().lookupPatchField("kappa"); - + const scalar sigma_(5.67e-8); scalarField hEff_ ( - h_ + sigma_*emissivity_*(sqr(Tp) + sqr(Tinf_))*(Tp + Tinf_) + h_ + sigma_ * emissivity_ * (sqr(Tp) + sqr(Tinf_)) * (Tp + Tinf_) ); - + valueFraction() = - 1.0/ - ( - 1.0 - + kappa_*patch().deltaCoeffs()/max(hEff_, 1e-15) - ); - + 1.0 / (1.0 + kappa_ * patch().deltaCoeffs() / max(hEff_, 1e-15)); + refGrad() = Zero; mixedFvPatchScalarField::updateCoeffs(); diff --git a/applications/solvers/additiveFoam/derivedFvPatchFields/mixedTemperature/mixedTemperatureFvPatchScalarField.H b/applications/solvers/additiveFoam/derivedFvPatchFields/mixedTemperature/mixedTemperatureFvPatchScalarField.H index 3d813a34..954d9e67 100644 --- a/applications/solvers/additiveFoam/derivedFvPatchFields/mixedTemperature/mixedTemperatureFvPatchScalarField.H +++ b/applications/solvers/additiveFoam/derivedFvPatchFields/mixedTemperature/mixedTemperatureFvPatchScalarField.H @@ -2,10 +2,8 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2023 OpenFOAM Foundation \\/ M anipulation | -------------------------------------------------------------------------------- - Copyright (C) 2023 Oak Ridge National Laboratory ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -30,15 +28,40 @@ Description This boundary condition provides a mixedTemperature condition, calculated as: -SourceFiles - mixedTemperatureFvPatchScalarField.C + \f[ + Q = h * (T - T_inf) + e * sigma * (T^4 - T_inf^$) + \f] + + where + \vartable + h | Convection coefficient [W/m^2/K] + e | Surface emissivity [-] + sigma | Stefan-Boltzmann constant [5.67e-8 W/m^2/K^4] + \endtable + +Usage + \table + Property | Description | Req'd? | Default + h | Uniform convection coeff | yes | + emissivity | Uniform surface emissivity | no | 0.0 + Tinf | Ambient temperature | yes | + \endtable + + Example of the boundary condition specification: + \verbatim + + { + type mixedTemperature; + h 10.0; + emissivity 0.4; + } + \endverbatim SourceFiles mixedTemperatureFvPatchScalarField.C \*---------------------------------------------------------------------------*/ - #ifndef BC_H #define BC_H @@ -60,13 +83,13 @@ class mixedTemperatureFvPatchScalarField { // Private Data - //- convective heat transfer coefficient [W/m^2/k] + //- Convective heat transfer coefficient [W/m^2/K] scalar h_; - - //- effective emissivity of the boundary + + //- Effective emissivity of the boundary scalar emissivity_; - - //- ambient temperature + + //- Ambient temperature scalarField Tinf_; @@ -78,13 +101,6 @@ public: // Constructors - //- Construct from patch and internal field - mixedTemperatureFvPatchScalarField - ( - const fvPatch&, - const DimensionedField& - ); - //- Construct from patch, internal field and dictionary mixedTemperatureFvPatchScalarField ( @@ -137,13 +153,12 @@ public: // Mapping functions - //- Map (and resize as needed) from self given a mapping object - // Used to update fields following mesh topology change - virtual void autoMap(const fvPatchFieldMapper&); - - //- Reverse map the given fvPatchField onto this fvPatchField - // Used to reconstruct fields - virtual void rmap(const fvPatchScalarField&, const labelList&); + //- Map the given fvPatchField onto this fvPatchField + virtual void map + ( + const fvPatchScalarField&, + const fvPatchFieldMapper& + ); //- Reset the fvPatchField to the given fvPatchField // Used for mesh to mesh mapping diff --git a/applications/solvers/additiveFoam/functionObjects/ExaCA/ExaCA.C b/applications/solvers/additiveFoam/functionObjects/ExaCA/ExaCA.C index f8878348..595b39db 100644 --- a/applications/solvers/additiveFoam/functionObjects/ExaCA/ExaCA.C +++ b/applications/solvers/additiveFoam/functionObjects/ExaCA/ExaCA.C @@ -69,7 +69,7 @@ Foam::functionObjects::ExaCA::ExaCA IOobject ( "Tp_", - runTime.timeName(), + runTime.name(), mesh_, IOobject::NO_READ, IOobject::NO_WRITE diff --git a/applications/solvers/additiveFoam/functionObjects/solidificationData/solidificationData.C b/applications/solvers/additiveFoam/functionObjects/solidificationData/solidificationData.C index dca5d2f1..64908121 100644 --- a/applications/solvers/additiveFoam/functionObjects/solidificationData/solidificationData.C +++ b/applications/solvers/additiveFoam/functionObjects/solidificationData/solidificationData.C @@ -68,7 +68,7 @@ Foam::functionObjects::solidificationData::solidificationData IOobject ( "R", - mesh_.time().timeName(), + mesh_.time().name(), mesh_, IOobject::NO_READ, IOobject::NO_WRITE diff --git a/applications/solvers/additiveFoam/moveMesh.H b/applications/solvers/additiveFoam/moveMesh.H new file mode 100644 index 00000000..4cd1eae4 --- /dev/null +++ b/applications/solvers/additiveFoam/moveMesh.H @@ -0,0 +1,59 @@ +if (pimple.firstPimpleIter() || pimple.moveMeshOuterCorrectors()) +{ + // Move the mesh + mesh.move(); + + if (mesh.changing()) + { + gh = (g & mesh.C()) - ghRef; + ghf = (g & mesh.Cf()) - ghRef; + + MRF.update(); + + if (correctPhi || mesh.topoChanged()) + { + // Calculate absolute flux + // from the mapped surface velocity + phi = mesh.Sf() & Uf(); + + correctUphiBCs(U, phi, true); + + fv::correctPhi + ( + phi, + U, + p, + autoPtr(), + autoPtr(), + pressureReference, + pimple + ); + + // Make the flux relative to the mesh motion + fvc::makeRelative(phi, U); + } + + if (checkMeshCourantNo) + { + const scalarField sumPhi + ( + fvc::surfaceSum(mag(mesh.phi()))().primitiveField() + ); + + const scalar meshCoNum + ( + 0.5*gMax(sumPhi/mesh.V().primitiveField())*runTime.deltaTValue() + ); + + const scalar meanMeshCoNum + ( + 0.5 + *(gSum(sumPhi)/gSum(mesh.V().primitiveField())) + *runTime.deltaTValue() + ); + + Info<< "Mesh Courant Number mean: " << meanMeshCoNum + << " max: " << meshCoNum << endl; + } + } +} diff --git a/applications/solvers/additiveFoam/movingHeatSource/absorptionModels/absorptionModel/absorptionModel.C b/applications/solvers/additiveFoam/movingHeatSource/absorptionModels/absorptionModel/absorptionModel.C index 9cf78b89..e9b00385 100644 --- a/applications/solvers/additiveFoam/movingHeatSource/absorptionModels/absorptionModel/absorptionModel.C +++ b/applications/solvers/additiveFoam/movingHeatSource/absorptionModels/absorptionModel/absorptionModel.C @@ -52,7 +52,7 @@ Foam::IOobject Foam::absorptionModel::createIOobject typeIOobject io ( dict.name(), - mesh.time().timeName(), + mesh.time().name(), mesh.thisDb(), IOobject::MUST_READ, IOobject::NO_WRITE diff --git a/applications/solvers/additiveFoam/movingHeatSource/heatSourceModels/heatSourceModel/heatSourceModel.C b/applications/solvers/additiveFoam/movingHeatSource/heatSourceModels/heatSourceModel/heatSourceModel.C index 02a7d04e..708087ec 100644 --- a/applications/solvers/additiveFoam/movingHeatSource/heatSourceModels/heatSourceModel/heatSourceModel.C +++ b/applications/solvers/additiveFoam/movingHeatSource/heatSourceModels/heatSourceModel/heatSourceModel.C @@ -228,7 +228,7 @@ Foam::heatSourceModel::qDot() IOobject ( "qDot_", - mesh_.time().timeName(), + mesh_.time().name(), mesh_, IOobject::NO_READ, IOobject::NO_WRITE @@ -265,7 +265,7 @@ Foam::heatSourceModel::qDot() IOobject ( "weights", - mesh_.time().timeName(), + mesh_.time().name(), mesh_, IOobject::NO_READ, IOobject::NO_WRITE diff --git a/applications/solvers/additiveFoam/movingHeatSource/movingBeam/movingBeam.H b/applications/solvers/additiveFoam/movingHeatSource/movingBeam/movingBeam.H index 81efb05c..5a9af14c 100644 --- a/applications/solvers/additiveFoam/movingHeatSource/movingBeam/movingBeam.H +++ b/applications/solvers/additiveFoam/movingHeatSource/movingBeam/movingBeam.H @@ -40,7 +40,8 @@ SourceFiles // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -#include "fvCFD.H" +#include +#include "fvc.H" #include "segment.H" #include "HashTable.H" #include "absorptionModel.H" diff --git a/applications/solvers/additiveFoam/movingHeatSource/movingHeatSourceModel/movingHeatSourceModel.C b/applications/solvers/additiveFoam/movingHeatSource/movingHeatSourceModel/movingHeatSourceModel.C index ba998bc1..2baac7ed 100644 --- a/applications/solvers/additiveFoam/movingHeatSource/movingHeatSourceModel/movingHeatSourceModel.C +++ b/applications/solvers/additiveFoam/movingHeatSource/movingHeatSourceModel/movingHeatSourceModel.C @@ -54,7 +54,7 @@ Foam::movingHeatSourceModel::movingHeatSourceModel IOobject ( "qDot", - mesh_.time().timeName(), + mesh_.time().name(), mesh_, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE @@ -120,7 +120,7 @@ void Foam::movingHeatSourceModel::update() IOobject ( "qDoti", - mesh_.time().timeName(), + mesh_.time().name(), mesh_ ), mesh_, diff --git a/applications/solvers/additiveFoam/movingHeatSource/movingHeatSourceModel/movingHeatSourceModel.H b/applications/solvers/additiveFoam/movingHeatSource/movingHeatSourceModel/movingHeatSourceModel.H index 43143091..3fe605ab 100644 --- a/applications/solvers/additiveFoam/movingHeatSource/movingHeatSourceModel/movingHeatSourceModel.H +++ b/applications/solvers/additiveFoam/movingHeatSource/movingHeatSourceModel/movingHeatSourceModel.H @@ -40,7 +40,6 @@ SourceFiles // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -#include "fvCFD.H" #include "heatSourceModel.H" #include "movingBeam.H" diff --git a/applications/solvers/additiveFoam/pU/UEqn.H b/applications/solvers/additiveFoam/pU/UEqn.H index a7444bc3..26524f83 100644 --- a/applications/solvers/additiveFoam/pU/UEqn.H +++ b/applications/solvers/additiveFoam/pU/UEqn.H @@ -1,7 +1,5 @@ // Solve the Momentum equation -MRF.correctBoundaryVelocity(U); - const volScalarField D ( "D", diff --git a/applications/solvers/additiveFoam/pU/pEqn.H b/applications/solvers/additiveFoam/pU/pEqn.H index a1527d71..c71cd569 100644 --- a/applications/solvers/additiveFoam/pU/pEqn.H +++ b/applications/solvers/additiveFoam/pU/pEqn.H @@ -11,7 +11,7 @@ while (pimple.correct()) ( "phiHbyA", fvc::flux(HbyA) - + rAUf*fvc::ddtCorr(U, phi) + + fvc::interpolate(rAU)*fvc::ddtCorr(U, phi, Uf) + phig ); MRF.makeRelative(phiHbyA); @@ -26,7 +26,11 @@ while (pimple.correct()) - fvm::laplacian(rAUf, p_rgh) ); - p_rghEqn.setReference(pRefCell, getRefCellValue(p_rgh, pRefCell)); + p_rghEqn.setReference + ( + pressureReference.refCell(), + pressureReference.refValue() + ); p_rghEqn.solve(); @@ -42,8 +46,14 @@ while (pimple.correct()) } #include "continuityErrs.H" + + // Correct Uf if the mesh is moving + fvc::correctUf(Uf, U, phi, MRF); - p = p_rgh + rhok*gh; + // Make the fluxes relative to the mesh motion + fvc::makeRelative(phi, U); + + p == p_rgh + rhok*gh; if (p_rgh.needReference()) { @@ -51,7 +61,8 @@ while (pimple.correct()) ( "p", p.dimensions(), - pRefValue - getRefCellValue(p, pRefCell) + pressureReference.refValue() + - getRefCellValue(p, pressureReference.refCell()) ); p_rgh = p - rhok*gh; } diff --git a/applications/solvers/additiveFoam/setDeltaT.H b/applications/solvers/additiveFoam/setDeltaT.H index ee980b4b..348471c3 100644 --- a/applications/solvers/additiveFoam/setDeltaT.H +++ b/applications/solvers/additiveFoam/setDeltaT.H @@ -5,9 +5,8 @@ if (adjustTimeStep) const volScalarField::Internal alphaNum ( - mag(fvc::ddt(T))()() - /(Tliq - Tsol) - *runTime.deltaT() + mag(fvc::ddt(T)) / (Tliq - Tsol) + *runTime.deltaT() ); alphaCoNum = gMax(alphaNum); @@ -23,8 +22,8 @@ if (adjustTimeStep) mesh.magSf() *fvc::interpolate(kappa) *mesh.surfaceInterpolation::deltaCoeffs() - )()() - /(mesh.V()*rho.value()*Cp()) + ) + /(mesh.V()*rho*Cp) *runTime.deltaT() ); diff --git a/applications/solvers/additiveFoam/solutionControls.H b/applications/solvers/additiveFoam/solutionControls.H index 4c26ab4a..f8fcdc26 100644 --- a/applications/solvers/additiveFoam/solutionControls.H +++ b/applications/solvers/additiveFoam/solutionControls.H @@ -40,8 +40,8 @@ if (explicitSolve) mesh.magSf() *fvc::interpolate(kappa) *mesh.surfaceInterpolation::deltaCoeffs() - )()() - /(mesh.V()*rho.value()*Cp()) + ) + /(mesh.V()*rho*Cp) *runTime.deltaT() ); diff --git a/applications/solvers/additiveFoam/thermo/TEqn.H b/applications/solvers/additiveFoam/thermo/TEqn.H index 4c22f5d9..c4fe5354 100644 --- a/applications/solvers/additiveFoam/thermo/TEqn.H +++ b/applications/solvers/additiveFoam/thermo/TEqn.H @@ -7,7 +7,7 @@ IOobject ( "dFdT", - runTime.timeName(), + runTime.name(), mesh ), mesh, diff --git a/applications/solvers/additiveFoam/utilities/Make/files b/applications/solvers/additiveFoam/utilities/Make/files new file mode 100644 index 00000000..962c68ee --- /dev/null +++ b/applications/solvers/additiveFoam/utilities/Make/files @@ -0,0 +1,4 @@ +graph/curve.C +graph/graph.C + +LIB = $(FOAM_USER_LIBBIN)/libadditiveFoamUtilities diff --git a/applications/solvers/additiveFoam/utilities/Make/options b/applications/solvers/additiveFoam/utilities/Make/options new file mode 100644 index 00000000..a3ae8da8 --- /dev/null +++ b/applications/solvers/additiveFoam/utilities/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/utilities/graph/curve.C b/applications/solvers/additiveFoam/utilities/graph/curve.C new file mode 100644 index 00000000..b289574e --- /dev/null +++ b/applications/solvers/additiveFoam/utilities/graph/curve.C @@ -0,0 +1,68 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +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 "curve.H" +#include "Ostream.H" + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +Foam::curve::curve +( + const string& name, + const curveStyle& style, + const label l +) +: + scalarField(l, 0.0), + name_(name), + style_(style) +{} + + +Foam::curve::curve +( + const string& name, + const curveStyle& style, + const scalarField& y +) +: + scalarField(y), + name_(name), + style_(style) +{} + + +// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // + +Foam::Ostream& Foam::operator<<(Ostream& os, const curve& c) +{ + os << nl + << c.name_ << nl + << c.style_ << nl + << static_cast(c); + + os.check("Ostream& operator>>(Ostream&, const curve&)"); + + return os; +} + + +// ************************************************************************* // diff --git a/applications/solvers/additiveFoam/utilities/graph/curve.H b/applications/solvers/additiveFoam/utilities/graph/curve.H new file mode 100644 index 00000000..1cd07fe5 --- /dev/null +++ b/applications/solvers/additiveFoam/utilities/graph/curve.H @@ -0,0 +1,181 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +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::curve +Description + A single curve in a graph. +SourceFiles + curve.C +\*---------------------------------------------------------------------------*/ + +#ifndef curve_H +#define curve_H + +#include "string.H" +#include "primitiveFields.H" +#include "autoPtr.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// Forward declaration of friend functions and operators + +class curve; +Ostream& operator<<(Ostream&, const curve&); + + +/*---------------------------------------------------------------------------*\ + Class curve Declaration +\*---------------------------------------------------------------------------*/ + +class curve +: + public scalarField +{ + +public: + + //- The style (line, symbol, etc) of a curve + class curveStyle + { + + public: + + //- Enumeration definitions + enum curveStyleNo + { + CONTINUOUS, + SYMBOL, + SYMBOL_CURVE, + SYMBOL_WITH_ERROR_BARS, + SYMBOL_WITH_VARIABLE_SIZE + }; + + + private: + + // Private Data + + curveStyleNo CurveStyleNo; + + + public: + + + // Constructors + + //- Construct given a curveStyleNo + curveStyle(const curveStyleNo csn) + : + CurveStyleNo(csn) + {} + + //- Construct from Istream + curveStyle(Istream& is) + : + CurveStyleNo(curveStyleNo(readInt(is))) + {} + + + // Ostream operator + + friend Ostream& operator<<(Ostream& os, const curveStyle& cs) + { + os << int(cs.CurveStyleNo); + return os; + } + }; + + +private: + + // Private Data + + string name_; + curveStyle style_; + + +public: + + // Constructors + + //- Construct as interpolation of an existing curve + // curve(const curve&, const label); + + //- Construct from name, style and size + curve + ( + const string& name, + const curveStyle& style, + const label l + ); + + //- Construct from the components + curve + ( + const string&, + const curveStyle&, + const scalarField& y + ); + + autoPtr clone() const + { + return autoPtr(new curve(*this)); + } + + + // Member Functions + + // Access + + const string& name() const + { + return name_; + } + + const curveStyle& style() const + { + return style_; + } + + + // Friend Functions + + //- Gradient of the curve + // friend curve grad(const curve&); + + + // Ostream operator + + friend Ostream& operator<<(Ostream&, const curve&); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/applications/solvers/additiveFoam/utilities/graph/graph.C b/applications/solvers/additiveFoam/utilities/graph/graph.C new file mode 100644 index 00000000..c7e1abfc --- /dev/null +++ b/applications/solvers/additiveFoam/utilities/graph/graph.C @@ -0,0 +1,262 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +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 "graph.H" +#include "OFstream.H" +#include "IOmanip.H" +#include "Pair.H" +#include "OSspecific.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + typedef graph::writer graphWriter; + defineTypeNameAndDebug(graphWriter, 0); + defineRunTimeSelectionTable(graphWriter, word); +} + + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +Foam::word Foam::graph::wordify(const Foam::string& sname) +{ + string wname = sname; + wname.replace(' ', '_'); + wname.replace('(', '_'); + wname.replace(')', ""); + + return word(wname); +} + + +void Foam::graph::readCurves(Istream& is) +{ + List xyData(is); + + x_.setSize(xyData.size()); + scalarField y(xyData.size()); + + forAll(xyData, i) + { + x_[i] = xyData[i].x_; + y[i] = xyData[i].y_; + } + + insert + ( + wordify(yName_), + new curve(wordify(yName_), curve::curveStyle::CONTINUOUS, y) + ); +} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +Foam::graph::graph +( + const string& title, + const string& xName, + const string& yName, + const scalarField& x +) +: + title_(title), + xName_(xName), + yName_(yName), + x_(x) +{} + + +Foam::graph::graph +( + const string& title, + const string& xName, + const string& yName, + const scalarField& x, + const scalarField& y +) +: + title_(title), + xName_(xName), + yName_(yName), + x_(x) +{ + insert(wordify(yName), new curve(yName, curve::curveStyle::CONTINUOUS, y)); +} + + +Foam::graph::graph +( + const string& title, + const string& xName, + const string& yName, + Istream& is +) +: + title_(title), + xName_(xName), + yName_(yName) +{ + readCurves(is); +} + + +Foam::graph::graph(Istream& is) +: + title_(is), + xName_(is), + yName_(is) +{ + readCurves(is); +} + + +const Foam::scalarField& Foam::graph::y() const +{ + if (size() != 1) + { + FatalErrorInFunction + << "y field requested for graph containing " << size() + << "ys" << exit(FatalError); + } + + return *begin()(); +} + + +Foam::scalarField& Foam::graph::y() +{ + if (size() != 1) + { + FatalErrorInFunction + << "y field requested for graph containing " << size() + << "ys" << exit(FatalError); + } + + return *begin()(); +} + + +Foam::autoPtr Foam::graph::writer::New +( + const word& graphFormat +) +{ + if (!wordConstructorTablePtr_) + { + FatalErrorInFunction + << "Graph writer table is empty" + << exit(FatalError); + } + + wordConstructorTable::iterator cstrIter = + wordConstructorTablePtr_->find(graphFormat); + + if (cstrIter == wordConstructorTablePtr_->end()) + { + FatalErrorInFunction + << "Unknown graph format " << graphFormat + << endl << endl + << "Valid graph formats are : " << endl + << wordConstructorTablePtr_->sortedToc() + << exit(FatalError); + } + + return autoPtr(cstrIter()()); +} + + +void Foam::graph::writer::writeXY +( + const scalarField& x, + const scalarField& y, + Ostream& os +) const +{ + forAll(x, xi) + { + os << setw(10) << x[xi] << token::SPACE << setw(10) << y[xi]<< endl; + } +} + + +void Foam::graph::writeTable(Ostream& os) const +{ + forAll(x_, xi) + { + os << setw(10) << x_[xi]; + + forAllConstIter(graph, *this, iter) + { + os << token::SPACE << setw(10) << (*iter())[xi]; + } + os << endl; + } +} + + +void Foam::graph::write(Ostream& os, const word& format) const +{ + writer::New(format)().write(*this, os); +} + + +void Foam::graph::write(const fileName& pName, const word& format) const +{ + autoPtr graphWriter(writer::New(format)); + + OFstream graphFile(pName + '.' + graphWriter().ext()); + + if (graphFile.good()) + { + write(graphFile, format); + } + else + { + WarningInFunction + << "Could not open graph file " << graphFile.name() + << endl; + } +} + + +void Foam::graph::write +( + const fileName& path, + const word& name, + const word& format +) const +{ + mkDir(path); + write(path/name, format); +} + + +Foam::Ostream& Foam::operator<<(Ostream& os, const graph& g) +{ + g.writeTable(os); + os.check("Ostream& operator<<(Ostream&, const graph&)"); + return os; +} + + +// ************************************************************************* // diff --git a/applications/solvers/additiveFoam/utilities/graph/graph.H b/applications/solvers/additiveFoam/utilities/graph/graph.H new file mode 100644 index 00000000..820209ef --- /dev/null +++ b/applications/solvers/additiveFoam/utilities/graph/graph.H @@ -0,0 +1,278 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +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::graph +Description + Class to create, store and output qgraph files. +SourceFiles + graph.C +\*---------------------------------------------------------------------------*/ + +#ifndef graph_H +#define graph_H + +#include "string.H" +#include "point.H" +#include "HashPtrTable.H" +#include "curve.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// Forward declaration of friend functions and operators + +class graph; + +Ostream& operator<<(Ostream&, const graph&); + + +/*---------------------------------------------------------------------------*\ + Class graph Declaration +\*---------------------------------------------------------------------------*/ + +class graph +: + public HashPtrTable +{ + // private data + + string title_; + string xName_; + string yName_; + + scalarField x_; + + + struct xy + { + scalar x_, y_; + + xy() + {} + + // Friend Operators + + friend bool operator==(const xy& a, const xy& b) + { + return equal(a.x_, b.x_) && equal(a.y_, b.y_); + } + + friend bool operator!=(const xy& a, const xy& b) + { + return !(a == b); + } + + friend Istream& operator>>(Istream& is, xy& xyd) + { + is >> xyd.x_ >> xyd.y_; + return is; + } + + friend Ostream& operator<<(Ostream& os, const xy& xyd) + { + os << xyd.x_ << ' ' << xyd.y_; + return os; + } + }; + + + // Private Member Functions + + void readCurves(Istream&); + + +public: + + // Constructors + + //- Construct from title and labels (no curves) + graph + ( + const string& title, + const string& xName, + const string& yName, + const scalarField& x + ); + + //- Construct from title, labels and y data for 1 curve + graph + ( + const string& title, + const string& xName, + const string& yName, + const scalarField& x, + const scalarField& y + ); + + //- Construct from Istream given title and labels + graph + ( + const string& title, + const string& xName, + const string& yName, + Istream& is + ); + + //- Construct from Istream + graph(Istream& is); + + + // Member Functions + + // Access + + const string& title() const + { + return title_; + } + + const string& xName() const + { + return xName_; + } + + const string& yName() const + { + return yName_; + } + + + const scalarField& x() const + { + return x_; + } + + scalarField& x() + { + return x_; + } + + + const scalarField& y() const; + + scalarField& y(); + + + // Write + + //- Abstract base class for a graph writer + class writer + { + + protected: + + void writeXY + ( + const scalarField& x, + const scalarField& y, + Ostream& + ) const; + + public: + + //- Runtime type information + TypeName("writer"); + + //- Declare run-time constructor selection table + declareRunTimeSelectionTable + ( + autoPtr, + writer, + word, + (), + () + ); + + + // Selectors + + //- Return a reference to the selected writer + static autoPtr New + ( + const word& writeFormat + ); + + + // Constructors + + //- Construct null + writer() + {} + + + //- Destructor + virtual ~writer() + {} + + + // Member Functions + + // Access + + //- Return the appropriate fileName extension + // for this graph format + virtual const word& ext() const = 0; + + + // Write + + //- Write graph in appropriate format + virtual void write(const graph&, Ostream&) const = 0; + }; + + //- Write out graph data as a simple table + void writeTable(Ostream&) const; + + //- Write graph to stream in given format + void write(Ostream&, const word& format) const; + + //- Write graph to file in given path-name and format + void write(const fileName& pName, const word& format) const; + + //- Write graph to file in given path, name and format + void write + ( + const fileName& path, + const word& name, + const word& format + ) const; + + //- Helper function to convert string name into appropriate word + static word wordify(const string& sname); + + + // Friend operators + + //- Ostream Operator + friend Ostream& operator<<(Ostream&, const graph&); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/applications/solvers/additiveFoam/interpolateXY/interpolateXY.C b/applications/solvers/additiveFoam/utilities/interpolateXY/interpolateXY.C similarity index 97% rename from applications/solvers/additiveFoam/interpolateXY/interpolateXY.C rename to applications/solvers/additiveFoam/utilities/interpolateXY/interpolateXY.C index aee871fd..ca22a497 100644 --- a/applications/solvers/additiveFoam/interpolateXY/interpolateXY.C +++ b/applications/solvers/additiveFoam/utilities/interpolateXY/interpolateXY.C @@ -21,7 +21,9 @@ License along with OpenFOAM. If not, see . \*---------------------------------------------------------------------------*/ -#include "interpolateXY/interpolateXY.H" +#include "interpolateXY.H" +#include "primitiveFields.H" +#include "labelPair.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/applications/solvers/additiveFoam/interpolateXY/interpolateXY.H b/applications/solvers/additiveFoam/utilities/interpolateXY/interpolateXY.H similarity index 95% rename from applications/solvers/additiveFoam/interpolateXY/interpolateXY.H rename to applications/solvers/additiveFoam/utilities/interpolateXY/interpolateXY.H index 9fe5e5cc..1ce39cc6 100644 --- a/applications/solvers/additiveFoam/interpolateXY/interpolateXY.H +++ b/applications/solvers/additiveFoam/utilities/interpolateXY/interpolateXY.H @@ -29,6 +29,10 @@ SourceFiles #ifndef interpolateXY_H #define interpolateXY_H +#include "scalar.H" +#include "primitiveFieldsFwd.H" +#include "labelPair.H" + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam @@ -59,7 +63,7 @@ labelPair interpolateXYLabels // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #ifdef NoRepository - #include "interpolateXY/interpolateXY.C" + #include "interpolateXY.C" #endif // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/applications/utilities/createScanPath/createFields.H b/applications/utilities/createScanPath/createFields.H index 2cbab3ba..e937ecf6 100644 --- a/applications/utilities/createScanPath/createFields.H +++ b/applications/utilities/createScanPath/createFields.H @@ -28,7 +28,7 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#include "fvCFD.H" +#include "timeSelector.H" #include "OFstream.H" #include #include diff --git a/applications/utilities/createScanPath/createScanPath.C b/applications/utilities/createScanPath/createScanPath.C index 9667dfcf..c180a42e 100644 --- a/applications/utilities/createScanPath/createScanPath.C +++ b/applications/utilities/createScanPath/createScanPath.C @@ -28,13 +28,17 @@ Application \*---------------------------------------------------------------------------*/ +#include "argList.H" +#include "Time.H" #include "createFields.H" +#include "point2D.H" + +using namespace Foam; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // int main(int argc, char *argv[]) -{ - +{ #include "setRootCase.H" #include "createTime.H" diff --git a/applications/utilities/multiLayer/reconstructLayers b/applications/utilities/multiLayer/reconstructLayers index dcad4369..5d3d6fd4 100755 --- a/applications/utilities/multiLayer/reconstructLayers +++ b/applications/utilities/multiLayer/reconstructLayers @@ -36,7 +36,7 @@ do caseList+=("$baseDir/$layer") done nLayers=${#caseList[@]} -echo "Found $nLayers parallel-in-time layers in $baseDir" +echo "Found $nLayers layers in $baseDir" for (( layer=$(($nLayers-1)); layer>=0; layer-- )) do diff --git a/applications/utilities/multiLayer/runLayers b/applications/utilities/multiLayer/runLayers index 215772e9..c509949a 100755 --- a/applications/utilities/multiLayer/runLayers +++ b/applications/utilities/multiLayer/runLayers @@ -138,14 +138,14 @@ do if [ $layer -gt 0 ] then - nLayers0="$(foamDictionary -entry nLayers -value $previous/system/extrudeMeshDict)" + nLayers0="$(foamDictionary -entry linearDirectionCoeffs/nLayers -value $previous/system/extrudeMeshDict)" thickness0="$(foamDictionary -entry linearDirectionCoeffs/thickness -value $previous/system/extrudeMeshDict)" thickness=`awk "BEGIN {print $thickness0 + $layerThickness; exit}"` - foamDictionary -entry nLayers -set "$(($nLayers0+$nCellsPerLayer))" $case/system/extrudeMeshDict + foamDictionary -entry linearDirectionCoeffs/nLayers -set "$(($nLayers0+$nCellsPerLayer))" $case/system/extrudeMeshDict foamDictionary -entry linearDirectionCoeffs/thickness -set "$thickness" $case/system/extrudeMeshDict - extrudeMesh -case $case > /dev/null 2>&1 + extrudeMesh -case $case fi done diff --git a/tutorials/multiLayerPBF/system/extrudeMeshDict b/tutorials/multiLayerPBF/system/extrudeMeshDict index 1f1d5c06..136f419b 100644 --- a/tutorials/multiLayerPBF/system/extrudeMeshDict +++ b/tutorials/multiLayerPBF/system/extrudeMeshDict @@ -21,13 +21,12 @@ sourcePatches (top); flipNormals false; -nLayers 0; -expansionRatio 1; - extrudeModel linearDirection; linearDirectionCoeffs { + nLayers 0; + expansionRatio 1; direction (0 0 1); thickness 0; } From 24a348074d1fce2c34f51b8dc9abae40a9077b51 Mon Sep 17 00:00:00 2001 From: John Coleman <103219962+colemanjs@users.noreply.github.com> Date: Wed, 20 May 2026 14:02:17 -0400 Subject: [PATCH 02/17] WIP V2.0 refinement model (#92) * added refinement model * fixup: still need helper functions for moving beam * fixup * remove DTI * Replace segment class with more flexible pathVector class * first target volume refinement attempt * fixup * removed commented query functions from pathVector * removed commented query functions from pathVector * revert thermopath * revert time step --- .../solvers/additiveFoam/additiveFoam.C | 3 +- .../additiveFoam/movingHeatSource/Make/files | 9 +- .../movingHeatSource/Make/options | 3 +- .../heatSourceModel/heatSourceModel.C | 3 +- .../heatSourceModel/heatSourceModel.H | 20 +- .../movingHeatSource/movingBeam/movingBeam.C | 210 +++--- .../movingHeatSource/movingBeam/movingBeam.H | 45 +- .../movingHeatSourceModel.C | 9 +- .../movingHeatSourceModel.H | 4 + .../movingHeatSource/pathVector/pathVector.C | 99 +++ .../movingHeatSource/pathVector/pathVector.H | 187 +++++ .../noRefinementModel/noRefinementModel.C} | 59 +- .../noRefinementModel/noRefinementModel.H} | 92 +-- .../refinementModel/refinementModel.C | 703 ++++++++++++++++++ .../refinementModel/refinementModel.H | 261 +++++++ .../refinementModel/refinementModelNew.C | 69 ++ .../targetCellLoad/targetCellLoad.C | 215 ++++++ .../targetCellLoad/targetCellLoad.H | 132 ++++ .../refinementModels/timeStep/timeStep.C | 88 +++ .../refinementModels/timeStep/timeStep.H | 101 +++ .../uniformTimeIntervals.C | 127 ++++ .../uniformTimeIntervals.H | 121 +++ tutorials/AMB2018-02-B/0/T | 5 + tutorials/AMB2018-02-B/0/U | 5 + tutorials/AMB2018-02-B/0/alpha.solid | 5 + tutorials/AMB2018-02-B/0/p_rgh | 5 + .../AMB2018-02-B/constant/dynamicMeshDict | 49 ++ .../AMB2018-02-B/constant/heatSourceDict | 31 +- tutorials/AMB2018-02-B/system/blockMeshDict | 6 + 29 files changed, 2431 insertions(+), 235 deletions(-) create mode 100644 applications/solvers/additiveFoam/movingHeatSource/pathVector/pathVector.C create mode 100644 applications/solvers/additiveFoam/movingHeatSource/pathVector/pathVector.H rename applications/solvers/additiveFoam/movingHeatSource/{segment/segment.C => refinementModels/noRefinementModel/noRefinementModel.C} (63%) rename applications/solvers/additiveFoam/movingHeatSource/{segment/segment.H => refinementModels/noRefinementModel/noRefinementModel.H} (62%) 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/targetCellLoad/targetCellLoad.C create mode 100644 applications/solvers/additiveFoam/movingHeatSource/refinementModels/targetCellLoad/targetCellLoad.H create mode 100644 applications/solvers/additiveFoam/movingHeatSource/refinementModels/timeStep/timeStep.C create mode 100644 applications/solvers/additiveFoam/movingHeatSource/refinementModels/timeStep/timeStep.H create mode 100644 applications/solvers/additiveFoam/movingHeatSource/refinementModels/uniformTimeIntervals/uniformTimeIntervals.C create mode 100644 applications/solvers/additiveFoam/movingHeatSource/refinementModels/uniformTimeIntervals/uniformTimeIntervals.H create mode 100644 tutorials/AMB2018-02-B/constant/dynamicMeshDict diff --git a/applications/solvers/additiveFoam/additiveFoam.C b/applications/solvers/additiveFoam/additiveFoam.C index 6a901be2..d5c1ca89 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" @@ -116,7 +115,7 @@ int main(int argc, char *argv[]) } #include "thermo/TEqn.H" - + runTime.write(); Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s" diff --git a/applications/solvers/additiveFoam/movingHeatSource/Make/files b/applications/solvers/additiveFoam/movingHeatSource/Make/files index 4fa0112d..22289862 100644 --- a/applications/solvers/additiveFoam/movingHeatSource/Make/files +++ b/applications/solvers/additiveFoam/movingHeatSource/Make/files @@ -3,7 +3,7 @@ absorptionModels/absorptionModel/absorptionModelNew.C absorptionModels/constant/constantAbsorption.C absorptionModels/Kelly/KellyAbsorption.C -segment/segment.C +pathVector/pathVector.C movingBeam/movingBeam.C @@ -13,6 +13,13 @@ 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/targetCellLoad/targetCellLoad.C +refinementModels/uniformTimeIntervals/uniformTimeIntervals.C + movingHeatSourceModel/movingHeatSourceModel.C LIB = $(FOAM_USER_LIBBIN)/libmovingBeamModels diff --git a/applications/solvers/additiveFoam/movingHeatSource/Make/options b/applications/solvers/additiveFoam/movingHeatSource/Make/options index e54b5011..d02c2daf 100644 --- a/applications/solvers/additiveFoam/movingHeatSource/Make/options +++ b/applications/solvers/additiveFoam/movingHeatSource/Make/options @@ -2,7 +2,8 @@ EXE_INC = \ -ImovingBeam \ -IheatSourceModels \ -IabsorptionModels \ - -Isegment \ + -IpathVector \ + -IrefinementModel \ -I$(LIB_SRC)/meshTools/lnInclude \ -I$(LIB_SRC)/OpenFOAM/lnInclude \ -I$(LIB_SRC)/finiteVolume/lnInclude diff --git a/applications/solvers/additiveFoam/movingHeatSource/heatSourceModels/heatSourceModel/heatSourceModel.C b/applications/solvers/additiveFoam/movingHeatSource/heatSourceModels/heatSourceModel/heatSourceModel.C index 708087ec..b12af41b 100644 --- a/applications/solvers/additiveFoam/movingHeatSource/heatSourceModels/heatSourceModel/heatSourceModel.C +++ b/applications/solvers/additiveFoam/movingHeatSource/heatSourceModels/heatSourceModel/heatSourceModel.C @@ -87,7 +87,6 @@ Foam::heatSourceModel::heatSourceModel heatSourceDict_(dict), sourceDict_(heatSourceDict_.optionalSubDict(sourceName_)), heatSourceModelCoeffs_(sourceDict_.optionalSubDict(type + "Coeffs")), - mesh_(mesh), absorptionModel_(nullptr), movingBeam_(nullptr) @@ -250,7 +249,7 @@ Foam::heatSourceModel::qDot() const scalar aspectRatio = dimensions_.z() / min(dimensions_.x(), dimensions_.y()); - dimensionedScalar absorbedPower + const dimensionedScalar absorbedPower ( "etaP", dimPower, diff --git a/applications/solvers/additiveFoam/movingHeatSource/heatSourceModels/heatSourceModel/heatSourceModel.H b/applications/solvers/additiveFoam/movingHeatSource/heatSourceModels/heatSourceModel/heatSourceModel.H index 327e07b0..b1b4639c 100644 --- a/applications/solvers/additiveFoam/movingHeatSource/heatSourceModels/heatSourceModel/heatSourceModel.H +++ b/applications/solvers/additiveFoam/movingHeatSource/heatSourceModels/heatSourceModel/heatSourceModel.H @@ -156,33 +156,39 @@ public: // Member Functions - + //- Return access to the movingBeam instance - movingBeam& beam() + inline movingBeam& beam() { return movingBeam_(); } - + + //- Return const access to the movingBeam instance + inline const movingBeam& beam() const + { + return movingBeam_(); + } + //- Return boolean of heat source type - Switch transient() + inline Switch transient() const { return transient_; } //- Return scalar of the isovalue - scalar isoValue() + inline scalar isoValue() const { return isoValue_; } //- Return vector of current heat source dimensions - vector dimensions() + inline vector dimensions() const { return dimensions_; } //- Return vector of original heat source dimensions - vector staticDimensions() + inline vector staticDimensions() const { return staticDimensions_; } diff --git a/applications/solvers/additiveFoam/movingHeatSource/movingBeam/movingBeam.C b/applications/solvers/additiveFoam/movingHeatSource/movingBeam/movingBeam.C index 31f2c797..e16c163e 100644 --- a/applications/solvers/additiveFoam/movingHeatSource/movingBeam/movingBeam.C +++ b/applications/solvers/additiveFoam/movingHeatSource/movingBeam/movingBeam.C @@ -26,6 +26,7 @@ License \*---------------------------------------------------------------------------*/ #include "movingBeam.H" +#include // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -50,32 +51,44 @@ Foam::movingBeam::movingBeam dict_(dict), runTime_(runTime), beamDict_(dict_.optionalSubDict(sourceName_)), - path_(1, segment()), + path_(0), index_(0), position_(Zero), - power_(0.0), - endTime_(0.0), + power_(Zero), + endTime_(Zero), deltaT_(GREAT), hitPathIntervals_(true) { //- Get beam parameters deltaT_ = beamDict_.lookupOrDefault("deltaT", GREAT); - hitPathIntervals_ = beamDict_.lookupOrDefault("hitPathIntervals", true); + hitPathIntervals_ = beamDict_.lookupOrDefault + ( + "hitPathIntervals", + true + ); + //- Read scan path file readPath(); - //- Initialize the path index - index_ = findIndex(runTime_.value()); - + //- Initialize path index + if (path_.size()) + { + index_ = getIndex(runTime_.value()); + + move(runTime_.value()); + } + Info << "Initial path index: " << index_ << endl; - - //- Find the beam end time - for (label i = path_.size() - 1; i > 0; i--) + + //- Find path end time + for (label i = path_.size(); i > 0; --i) { - if (path_[i].power() > small) + const label pathi = i - 1; + + if (path_[pathi].power() > eps) { - endTime_ = min(path_[i].time(), runTime_.endTime().value()); + endTime_ = min(path_[pathi].endTime(), runTime_.endTime().value()); break; } } @@ -114,6 +127,10 @@ void Foam::movingBeam::readPath() // skip the header line std::getline(is, line); + scalar time = Zero; + + point position0 = Zero; + while (std::getline(is, line)) { if (line.empty()) @@ -121,138 +138,133 @@ void Foam::movingBeam::readPath() continue; } - path_.append(segment(line)); - } - - for (label i=1; i < path_.size(); i++) - { - if (path_[i].mode() == 1) + std::stringstream lineStream(line); + + scalar mode = Zero; + + point position = Zero; + + scalar power = Zero; + + scalar parameter = Zero; + + lineStream + >> mode + >> position.x() + >> position.y() + >> position.z() + >> power + >> parameter; + + point startPosition = position0; + + scalar dt = Zero; + + //- Spot mode + if (mode == 1) { - path_[i].setTime - ( - path_[i-1].time() + path_[i].parameter() - ); + startPosition = position; + + dt = parameter; + } + //- Line mode + else if (mode == 0) + { + dt = mag(position - startPosition)/parameter; } - else + + // add path vectors with non-zero duration to the list + if (dt > eps) { - scalar d_ = mag(path_[i].position() - path_[i-1].position()); - - path_[i].setTime + path_.append ( - path_[i-1].time() + d_/path_[i].parameter() + pathVector + ( + startPosition, // startPosition + position, // endPosition + time, // startTime + time + dt, // endTime + power // power + ) ); } - - Info << i << tab << path_[i].time() << endl; + + time += dt; + position0 = position; } } -bool Foam::movingBeam::activePath() +bool Foam::movingBeam::activePath() const { return ((endTime_ - runTime_.value()) > eps); } -void Foam::movingBeam::move(const scalar time) -{ - // update the current index of the path - index_ = findIndex(time); - - const label i = index_; - - // update the beam center - if (path_[i].mode() == 1) - { - position_ = path_[i].position(); - } - else - { - vector displacement = vector::zero; - - scalar dt = path_[i].time() - path_[i-1].time(); - - if (dt > 0) - { - const vector dx = path_[i].position() - path_[i-1].position(); - displacement = dx*(time - path_[i-1].time())/dt; - } - - position_ = path_[i-1].position() + displacement; - } - - // update the beam power - if ((time - path_[i-1].time()) > eps) - { - power_ = path_[i].power(); - } - else - { - power_ = path_[i-1].power(); - } -} - - Foam::label -Foam::movingBeam::findIndex(const scalar time) +Foam::movingBeam::getIndex(const scalar time) const { label i = index_; const label n = path_.size() - 1; // step back path index for safe updating - for (i = i; i > 0 && path_[i].time() > time; --i) + for (i = i; i > 0 && (time - path_[i].startTime()) <= eps; --i) {} // update the path index to the provided time - for (i = i; i < n && path_[i].time() < time; ++i) + for (i = i; i < n && (time - path_[i].endTime()) > eps; ++i) {} - // skip any point sources with zero time - while (i < n) - { - if (path_[i].mode() == 1 && path_[i].parameter() == 0) - { - ++i; - } - else - { - break; - } - } - return min(max(i, 0), n); } -void Foam::movingBeam::adjustDeltaT(scalar& dt) +void Foam::movingBeam::adjustDeltaT(scalar& dt) const { - if (activePath() && hitPathIntervals_) + if (!(activePath() && hitPathIntervals_ && path_.size())) { - scalar timeToNextPath = 0; - label i = index_; - - while (timeToNextPath < eps) - { - timeToNextPath = max(0, path_[i].time() - runTime_.value()); + return; + } + + scalar timeToNextPath = 0; + + label i = index_; - i++; + while (i < path_.size() && timeToNextPath < eps) + { + timeToNextPath = max(0, path_[i].endTime() - runTime_.value()); - if (i == path_.size()) - { - break; - } - } + ++i; + } + if (timeToNextPath > eps) + { const scalar nSteps = timeToNextPath/dt; if (nSteps < labelMax) { // allow time step to dilate 1% to hit target path time const label nStepsToNextPath = label(max(nSteps, 1) + 0.99); + + // reduce the time step to hit the next path vector end time dt = min(timeToNextPath/nStepsToNextPath, dt); } } } + +void Foam::movingBeam::move(const scalar time) +{ + // update the current index of the path + index_ = getIndex(time); + + const pathVector& pv = path_[index_]; + + //- Update the beam center + position_ = pv.position(time); + + //- Update the beam power + power_ = pv.power(); +} // ************************************************************************* // diff --git a/applications/solvers/additiveFoam/movingHeatSource/movingBeam/movingBeam.H b/applications/solvers/additiveFoam/movingHeatSource/movingBeam/movingBeam.H index 5a9af14c..10de52ea 100644 --- a/applications/solvers/additiveFoam/movingHeatSource/movingBeam/movingBeam.H +++ b/applications/solvers/additiveFoam/movingHeatSource/movingBeam/movingBeam.H @@ -42,7 +42,7 @@ SourceFiles #include #include "fvc.H" -#include "segment.H" +#include "pathVector.H" #include "HashTable.H" #include "absorptionModel.H" #include "DynamicList.H" @@ -73,8 +73,8 @@ private: //- Individual beam sub-dict const dictionary& beamDict_; - //- List of beam segments - DynamicList path_; + //- List of beam pathVectors + DynamicList path_; //- Index of path label index_; @@ -91,7 +91,7 @@ private: //- Time step used for heat source integration scalar deltaT_; - //- Adjust solution time to hit path segment start times? (d = true) + //- Adjust solution time to hit path vector start times? bool hitPathIntervals_; // Static Data Members @@ -161,26 +161,39 @@ public: { return power_; } - - scalar deltaT() const + + //- Return time step for path + inline scalar deltaT() const { return deltaT_; } - //- Read the path file - void readPath(); - + //- Return path end time + inline scalar endTime() const + { + return endTime_; + } + + //- Return access to the scan path vectors + inline const DynamicList& path() const + { + return path_; + } + + //- Returns the path index at the provided time + label getIndex(const scalar time) const; + //- Returns true if the simulation time is less than path endTime - bool activePath(); - + bool activePath() const; + + //- Adjust solution time step to hit pathInterval + void adjustDeltaT(scalar& dt) const; + //- Move the beam to the provided time void move(const scalar time); - //- Returns the path index at the provided time - label findIndex(const scalar time); - - //- Adjust solution time step to hit pathInterval - void adjustDeltaT(scalar& dt); + //- Read the path file + void readPath(); }; diff --git a/applications/solvers/additiveFoam/movingHeatSource/movingHeatSourceModel/movingHeatSourceModel.C b/applications/solvers/additiveFoam/movingHeatSource/movingHeatSourceModel/movingHeatSourceModel.C index 2baac7ed..bbe9cbe1 100644 --- a/applications/solvers/additiveFoam/movingHeatSource/movingHeatSourceModel/movingHeatSourceModel.C +++ b/applications/solvers/additiveFoam/movingHeatSource/movingHeatSourceModel/movingHeatSourceModel.C @@ -61,7 +61,8 @@ Foam::movingHeatSourceModel::movingHeatSourceModel ), mesh_, dimensionedScalar(dimPower/dimVolume, 0.0) - ) + ), + refinementModel_(nullptr) { sources_.resize(sourceNames_.size()); @@ -80,6 +81,8 @@ Foam::movingHeatSourceModel::movingHeatSourceModel ).ptr() ); } + + refinementModel_ = refinementModel::New(sources_, dict_, mesh_); } // * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * * // @@ -147,6 +150,10 @@ void Foam::movingHeatSourceModel::update() qDot_ += qDoti; } } + + qDot_.correctBoundaryConditions(); + + refinementModel_->update(); } // ************************************************************************* // diff --git a/applications/solvers/additiveFoam/movingHeatSource/movingHeatSourceModel/movingHeatSourceModel.H b/applications/solvers/additiveFoam/movingHeatSource/movingHeatSourceModel/movingHeatSourceModel.H index 3fe605ab..0043a042 100644 --- a/applications/solvers/additiveFoam/movingHeatSource/movingHeatSourceModel/movingHeatSourceModel.H +++ b/applications/solvers/additiveFoam/movingHeatSource/movingHeatSourceModel/movingHeatSourceModel.H @@ -42,6 +42,7 @@ SourceFiles #include "heatSourceModel.H" #include "movingBeam.H" +#include "refinementModel.H" namespace Foam { @@ -70,6 +71,9 @@ private: //- Pointer list to each beam instance PtrList sources_; + + //- Pointer to refinement model + autoPtr refinementModel_; public: diff --git a/applications/solvers/additiveFoam/movingHeatSource/pathVector/pathVector.C b/applications/solvers/additiveFoam/movingHeatSource/pathVector/pathVector.C new file mode 100644 index 00000000..52712ce8 --- /dev/null +++ b/applications/solvers/additiveFoam/movingHeatSource/pathVector/pathVector.C @@ -0,0 +1,99 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / 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 "pathVector.H" + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::pathVector::pathVector() +: + startPosition_(Zero), + endPosition_(Zero), + startTime_(Zero), + endTime_(Zero), + power_(Zero), + displacement_(Zero), + distance_(Zero), + duration_(Zero), + speed_(Zero) +{} + + +Foam::pathVector::pathVector +( + const point& startPosition, + const point& endPosition, + const scalar startTime, + const scalar endTime, + const scalar power +) +: + startPosition_(startPosition), + endPosition_(endPosition), + startTime_(startTime), + endTime_(endTime), + power_(power), + displacement_(Zero), + distance_(Zero), + duration_(Zero), + speed_(Zero) +{ + displacement_ = endPosition_ - startPosition_; + + distance_ = mag(displacement_); + + duration_ = max(endTime_ - startTime_, scalar(0)); + + if (duration_ > small) + { + speed_ = distance_/duration_; + } + else + { + speed_ = Zero; + } +} + + +// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // + +Foam::point Foam::pathVector::position(const scalar time) const +{ + if (duration_ <= small) + { + return endPosition_; + } + + scalar fraction = (time - startTime_)/duration_; + + fraction = min(max(fraction, scalar(0)), scalar(1)); + + return startPosition_ + fraction*displacement_; +} + +// ************************************************************************* // diff --git a/applications/solvers/additiveFoam/movingHeatSource/pathVector/pathVector.H b/applications/solvers/additiveFoam/movingHeatSource/pathVector/pathVector.H new file mode 100644 index 00000000..d509aeb4 --- /dev/null +++ b/applications/solvers/additiveFoam/movingHeatSource/pathVector/pathVector.H @@ -0,0 +1,187 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / 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 . + +Class + Foam::pathVector + +Description + Normalized representation of a scan path vector with start/end position + and start/end time. Derived quantities such as displacement, distance, + duration, and speed are calculated on construction and accessed through + getter functions. + +SourceFiles + pathVector.C + +\*---------------------------------------------------------------------------*/ + +#ifndef pathVector_H +#define pathVector_H + +#include "point.H" +#include "scalar.H" +#include "vector.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class pathVector Declaration +\*---------------------------------------------------------------------------*/ + +class pathVector +{ + // Private Data + + //- Start position of the path vector + point startPosition_; + + //- End position of the path vector + point endPosition_; + + //- Start time of the path vector + scalar startTime_; + + //- End time of the path vector + scalar endTime_; + + //- Beam power over the path vector + scalar power_; + + //- Displacement from start position to end position + vector displacement_; + + //- Magnitude of the displacement + scalar distance_; + + //- Duration of the path vector + scalar duration_; + + //- Speed along the path vector + scalar speed_; + + + // Private Member Functions + + //- Set derived quantities + void setDerived(); + + +public: + + // Constructors + + //- Construct default path vector as a zero-power stationary vector + pathVector(); + + //- Construct from components + pathVector + ( + const point& startPosition, + const point& endPosition, + const scalar startTime, + const scalar endTime, + const scalar power + ); + + + // Member Functions + + // Access + + //- Return start position + inline const point startPosition() const + { + return startPosition_; + } + + //- Return end position + inline const point endPosition() const + { + return endPosition_; + } + + //- Return start time + inline scalar startTime() const + { + return startTime_; + } + + //- Return end time + inline scalar endTime() const + { + return endTime_; + } + + //- Return beam power + inline scalar power() const + { + return power_; + } + + // Derived + + //- Return displacement + inline const vector& displacement() const + { + return displacement_; + } + + //- Return distance + inline scalar distance() const + { + return distance_; + } + + //- Return duration + inline scalar duration() const + { + return duration_; + } + + //- Return speed + inline scalar speed() const + { + return speed_; + } + + // Query + + //- Return position at the provided time + point position(const scalar time) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/applications/solvers/additiveFoam/movingHeatSource/segment/segment.C b/applications/solvers/additiveFoam/movingHeatSource/refinementModels/noRefinementModel/noRefinementModel.C similarity index 63% rename from applications/solvers/additiveFoam/movingHeatSource/segment/segment.C rename to applications/solvers/additiveFoam/movingHeatSource/refinementModels/noRefinementModel/noRefinementModel.C index e6444890..b20c43e8 100644 --- a/applications/solvers/additiveFoam/movingHeatSource/segment/segment.C +++ b/applications/solvers/additiveFoam/movingHeatSource/refinementModels/noRefinementModel/noRefinementModel.C @@ -23,57 +23,32 @@ License You should have received a copy of the GNU General Public License along with OpenFOAM. If not, see . -Class - segment - -Description - \*---------------------------------------------------------------------------*/ -#include "segment.H" -#include "IFstream.H" -#include "IStringStream.H" +#include "noRefinementModel.H" +#include "addToRunTimeSelectionTable.H" -// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // -// Set the segment time to provided value -void Foam::segment::setTime(scalar time) +namespace Foam { - time_ = time; -} - -void Foam::segment::setPosition(point position) +namespace refinementModels { - position_ = position; + defineTypeNameAndDebug(noRefinementModel, 0); + addToRunTimeSelectionTable(refinementModel, noRefinementModel, dictionary); } - - -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -// construct default segment as a zero point source -Foam::segment::segment() -: - mode_(1), - position_(Zero), - power_(Zero), - parameter_(Zero), - time_(Zero) -{ } -// set the segement properties given a space-delimited string -Foam::segment::segment(std::string line) -{ - std::stringstream lineStream(line); - - lineStream - >> mode_ - >> position_.x() - >> position_.y() - >> position_.z() - >> power_ - >> parameter_; -} +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +Foam::refinementModels::noRefinementModel::noRefinementModel +( + const PtrList& sources, + const dictionary& dict, + const fvMesh& mesh +) +: + refinementModel(typeName, sources, dict, mesh) +{} // ************************************************************************* // diff --git a/applications/solvers/additiveFoam/movingHeatSource/segment/segment.H b/applications/solvers/additiveFoam/movingHeatSource/refinementModels/noRefinementModel/noRefinementModel.H similarity index 62% rename from applications/solvers/additiveFoam/movingHeatSource/segment/segment.H rename to applications/solvers/additiveFoam/movingHeatSource/refinementModels/noRefinementModel/noRefinementModel.H index cd6ced26..9e06a77c 100644 --- a/applications/solvers/additiveFoam/movingHeatSource/segment/segment.H +++ b/applications/solvers/additiveFoam/movingHeatSource/refinementModels/noRefinementModel/noRefinementModel.H @@ -24,102 +24,78 @@ License along with OpenFOAM. If not, see . Class - segment + Foam::refinementModel::none Description - Class for properties of a moving heat source - - mode: 0 or 1 (0 = line source, 1 = point source) - position: position of the heat source center - power: power of the heat source - parameter: (mode = 0: time interval, mode = 1: scan velocity) + No refinement. SourceFiles - segment.C + none.C \*---------------------------------------------------------------------------*/ -#ifndef segment_H -#define segment_H +#ifndef noRefinementModel_H +#define noRefinementModel_H -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +#include "refinementModel.H" -#include "point.H" +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { +namespace refinementModels +{ /*---------------------------------------------------------------------------*\ - Class segment Declaration + Class noRefinementModel \*---------------------------------------------------------------------------*/ -class segment +class noRefinementModel +: + public refinementModel { -private: - - // Private data - - scalar mode_; - point position_; - - scalar power_; +public: - scalar parameter_; - - scalar time_; + //- Runtime type information + TypeName("none"); -public: // Constructors - //- Default construction - segment(); - - //- Construct from space-delimited string - segment(std::string); + //- Default empty constructor + noRefinementModel + ( + const PtrList& sources, + const dictionary& dict, + const fvMesh& mesh + ); //- Destructor - virtual ~segment() + virtual ~noRefinementModel() {} - // Member Functions - - //- Set time to provided value - void setTime(scalar time); - //- Set position to provided value - void setPosition(vector position); + // Member Functions - scalar mode() - { - return mode_; - } - - point position() - { - return position_; - } - - scalar power() - { - return power_; - } - - scalar parameter() + //- Return true + virtual bool update() { - return parameter_; + return true; } - - scalar time() + + //- Return true + virtual bool read() { - return time_; + return true; } }; + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +} // End namespace refinementModel } // End namespace Foam // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/applications/solvers/additiveFoam/movingHeatSource/refinementModels/refinementModel/refinementModel.C b/applications/solvers/additiveFoam/movingHeatSource/refinementModels/refinementModel/refinementModel.C new file mode 100644 index 00000000..a7a9f3e8 --- /dev/null +++ b/applications/solvers/additiveFoam/movingHeatSource/refinementModels/refinementModel/refinementModel.C @@ -0,0 +1,703 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / 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. + +\*---------------------------------------------------------------------------*/ + +#include "refinementModel.H" +#include "fvc.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(refinementModel, 0); + defineRunTimeSelectionTable(refinementModel, dictionary); +} + +const Foam::word Foam::refinementModel::refinementModelDictName +( + "refinementModelDict" +); + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +Foam::IOobject Foam::refinementModel::createIOobject +( + const dictionary& dict, + const fvMesh& mesh +) const +{ + typeIOobject io + ( + dict.name(), + mesh.time().constant(), + mesh.thisDb(), + IOobject::MUST_READ, + IOobject::NO_WRITE + ); + + if (io.headerOk()) + { + io.readOpt() = IOobject::MUST_READ_IF_MODIFIED; + } + else + { + io.readOpt() = IOobject::NO_READ; + } + + return io; +} + + +void Foam::refinementModel::calculateCellAABBs +( + List& cellAABBs +) const +{ + cellAABBs.setSize(mesh_.nCells()); + + const pointField& points = mesh_.points(); + + const vector extend = 1e-10*vector::one; + + forAll(mesh_.cells(), celli) + { + treeBoundBox cellAABB(point::max, point::min); + + const labelList& vertices = mesh_.cellPoints()[celli]; + + forAll(vertices, vertexi) + { + cellAABB.min() = + min(cellAABB.min(), points[vertices[vertexi]] - extend); + + cellAABB.max() = + max(cellAABB.max(), points[vertices[vertexi]] + extend); + } + + cellAABBs[celli] = cellAABB; + } +} + + +void Foam::refinementModel::scanPathFrame +( + const point& p0, + const point& p1, + vector& e0, + vector& e1, + vector& e2 +) const +{ + const vector d = p1 - p0; + + const scalar Lxy = sqrt(sqr(d.x()) + sqr(d.y())); + + if (Lxy < small) + { + e0 = vector(1, 0, 0); + e1 = vector(0, 1, 0); + } + else + { + //- Scan direction + e0 = vector(d.x()/Lxy, d.y()/Lxy, 0); + + //- Transverse direction + e1 = vector(-d.y()/Lxy, d.x()/Lxy, 0); + } + + //- Depth/vertical direction + e2 = vector(0, 0, 1); +} + + +bool Foam::refinementModel::cellOverlapsOBB +( + const treeBoundBox& cellAABB, + const point& centre, + const vector& e0, + const vector& e1, + const vector& e2, + const vector& L +) const +{ + const point cellCentre = 0.5*(cellAABB.min() + cellAABB.max()); + + const vector cellHalfLength = 0.5*(cellAABB.max() - cellAABB.min()); + + const vector d = cellCentre - centre; + + const scalar r0 = + cellHalfLength.x()*mag(e0.x()) + + cellHalfLength.y()*mag(e0.y()) + + cellHalfLength.z()*mag(e0.z()); + + if (mag(d & e0) > L.x() + r0) + { + return false; + } + + const scalar r1 = + cellHalfLength.x()*mag(e1.x()) + + cellHalfLength.y()*mag(e1.y()) + + cellHalfLength.z()*mag(e1.z()); + + if (mag(d & e1) > L.y() + r1) + { + return false; + } + + const scalar r2 = + cellHalfLength.x()*mag(e2.x()) + + cellHalfLength.y()*mag(e2.y()) + + cellHalfLength.z()*mag(e2.z()); + + if (mag(d & e2) > L.z() + r2) + { + return false; + } + + return true; +} + + +Foam::scalar Foam::refinementModel::markScanPath +( + const scalar startTime, + const scalar endTime, + const List& cellAABBs, + const bool commit +) +{ + if ((endTime - startTime) <= small) + { + return Zero; + } + + List