diff --git a/applications/solvers/additiveFoam/additiveFoam.C b/applications/solvers/additiveFoam/additiveFoam.C index 6a901be..d5c1ca8 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 4fa0112..2228986 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 e54b501..d02c2da 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 708087e..b12af41 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 327e07b..b1b4639 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 31f2c79..e16c163 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 5a9af14..10de52e 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 2baac7e..bbe9cbe 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 3fe605a..0043a04 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 0000000..3ca8f62 --- /dev/null +++ b/applications/solvers/additiveFoam/movingHeatSource/pathVector/pathVector.C @@ -0,0 +1,124 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / 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_; +} + +/* +bool Foam::pathVector::contains(const scalar t) const +{ + return + ( + ((t - startTime_) >= -small) + && ((endTime_ - t) > small) + ); +} + + +bool Foam::pathVector::overlaps +( + const scalar t0, + const scalar t1 +) const +{ + return + ( + ((endTime_ - t0) > small) + && ((t1 - startTime_) > small) + ); +} +*/ + +// ************************************************************************* // diff --git a/applications/solvers/additiveFoam/movingHeatSource/pathVector/pathVector.H b/applications/solvers/additiveFoam/movingHeatSource/pathVector/pathVector.H new file mode 100644 index 0000000..56ab93f --- /dev/null +++ b/applications/solvers/additiveFoam/movingHeatSource/pathVector/pathVector.H @@ -0,0 +1,199 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / 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; + +/* + //- Return true if the provided time is within the path vector + bool contains(const scalar time) const; + + //- Return true if the provided time interval overlaps the path + bool overlaps + ( + const scalar startTime, + const scalar endTime + ) 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 e644489..b20c43e 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 cd6ced2..9e06a77 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 0000000..a7a9f3e --- /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