diff --git a/src/lagrangian/molecularDynamics/molecule/Make/files b/src/lagrangian/molecularDynamics/molecule/Make/files new file mode 100755 index 0000000000..a490edafe1 --- /dev/null +++ b/src/lagrangian/molecularDynamics/molecule/Make/files @@ -0,0 +1,50 @@ +correlationFunction = correlationFunction + +distribution = distribution + +molecule = molecule +moleculeCloud = moleculeCloud + +reducedUnits = reducedUnits + +referredMolecule = referredMolecule +referredCellList = referredCellList +referredCell = referredCell +referralLists = referralLists + +tetherPotential = tetherPotential + +$(distribution)/distribution.C + +$(reducedUnits)/reducedUnits.C +$(reducedUnits)/reducedUnitsIO.C + +$(molecule)/molecule.C +$(molecule)/moleculeIO.C + +$(moleculeCloud)/moleculeCloud.C +$(moleculeCloud)/moleculeCloudBuildCellOccupancy.C +$(moleculeCloud)/moleculeCloudBuildCellInteractionLists.C +$(moleculeCloud)/moleculeCloudBuildCellReferralLists.C + +$(moleculeCloud)/moleculeCloudTestEdgeEdgeDistance.C +$(moleculeCloud)/moleculeCloudTestPointFaceDistance.C +$(moleculeCloud)/moleculeCloudRealCellsInRangeOfSegment.C +$(moleculeCloud)/moleculeCloudReferredCellsInRangeOfSegment.C + +$(moleculeCloud)/moleculeCloudCalculateForce.C +$(moleculeCloud)/moleculeCloudCalculatePairForce.C +$(moleculeCloud)/moleculeCloudCalculateTetherForce.C +$(moleculeCloud)/moleculeCloudCalculateExternalForce.C +$(moleculeCloud)/moleculeCloudIntegrateEquationsOfMotion.C +$(moleculeCloud)/moleculeCloudRemoveHighEnergyOverlaps.C +$(moleculeCloud)/moleculeCloudApplyConstraintsAndThermostats.C + +$(referralLists)/receivingReferralList.C +$(referralLists)/sendingReferralList.C +$(referredCellList)/referredCellList.C +$(referredCell)/referredCell.C +$(referredMolecule)/referredMolecule.C + +LIB = $(FOAM_LIBBIN)/libmolecule + diff --git a/src/lagrangian/molecularDynamics/molecule/Make/options b/src/lagrangian/molecularDynamics/molecule/Make/options new file mode 100755 index 0000000000..cc91fd4bbe --- /dev/null +++ b/src/lagrangian/molecularDynamics/molecule/Make/options @@ -0,0 +1,10 @@ +EXE_INC = \ + -I$(LIB_SRC)/finiteVolume/lnInclude \ + -I$(LIB_SRC)/lagrangian/basic/lnInclude \ + -I$(LIB_SRC)/lagrangian/molecularDynamics/potential/lnInclude + +EXE_LIBS = \ + -lfiniteVolume \ + -llagrangian \ + -lpotential + diff --git a/src/lagrangian/molecularDynamics/molecule/correlationFunction/bufferedAccumulator/bufferedAccumulator.C b/src/lagrangian/molecularDynamics/molecule/correlationFunction/bufferedAccumulator/bufferedAccumulator.C new file mode 100755 index 0000000000..c8a5ca0f30 --- /dev/null +++ b/src/lagrangian/molecularDynamics/molecule/correlationFunction/bufferedAccumulator/bufferedAccumulator.C @@ -0,0 +1,238 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd. + \\/ 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "bufferedAccumulator.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +template +const char* const + Foam::bufferedAccumulator::typeName("bufferedAccumulator"); + + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +template +void Foam::bufferedAccumulator::accumulateAndResetBuffer(const label b) +{ + accumulationBuffer() += (*this)[b]; + + averagesTaken_++; + + (*this)[b] = Field(bufferLength(), pTraits::zero); + + bufferOffsets_[b] = 0; +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template +Foam::bufferedAccumulator::bufferedAccumulator() +: + List< Field >(), + averagesTaken_(), + bufferOffsets_() +{} + + +template +Foam::bufferedAccumulator::bufferedAccumulator +( + const label nBuffers, + const label bufferLength, + const label bufferingInterval +) +: + List< Field >(), + averagesTaken_(), + bufferOffsets_() +{ + setSizes + ( + nBuffers, + bufferLength, + bufferingInterval + ); +} + + +template +Foam::bufferedAccumulator::bufferedAccumulator +( + const bufferedAccumulator& bA +) +: + List< Field >(static_cast< List< Field > >(bA)), + averagesTaken_(bA.averagesTaken()), + bufferOffsets_(bA.bufferOffsets()) +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +template +Foam::bufferedAccumulator::~bufferedAccumulator() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template +void Foam::bufferedAccumulator::setSizes +( + const label nBuffers, + const label bufferLength, + const label bufferingInterval +) +{ + (*this).setSize(nBuffers + 1); + + forAll((*this), b) + { + (*this)[b] = Field(bufferLength, pTraits::zero); + } + + averagesTaken_ = 0; + + bufferOffsets_.setSize(nBuffers); + + forAll(bufferOffsets_, bO) + { + bufferOffsets_[bO] = -bufferingInterval * bO - 1; + } +} + +template +Foam::label Foam::bufferedAccumulator::addToBuffers +( + const List& valuesToAdd +) +{ + label bufferToRefill = -1; + + for (label b = 0; b < nBuffers(); b++) + { + Field& buf((*this)[b]); + + label& bO = bufferOffsets_[b]; + + if (bO >= 0) + { + buf[bO] = valuesToAdd[b]; + } + + bO++; + + if (bO == bufferLength()) + { + accumulateAndResetBuffer(b); + } + + if (bO == 0) + { + if (bufferToRefill != -1) + { + FatalErrorIn("bufferedAccumulator::addToBuffers ") + << "More than one bufferedAccumulator accumulation " + << "buffer filled at once, this is considered an error." + << abort(FatalError); + } + + bufferToRefill = b; + } + } + + return bufferToRefill; +} + + +template +Foam::Field Foam::bufferedAccumulator::averaged() const +{ + if (averagesTaken_) + { + Field bA = accumulationBuffer()/averagesTaken_; + + return bA; + } + else + { + WarningIn + ( + "bufferedAccumulator::averagedbufferedAccumulator() const" + ) + << "Averaged correlation function requested but averagesTaken = " + << averagesTaken_ + << ". Returning empty field." + << endl; + + return Field(bufferLength(), pTraits::zero); + } +} + + +template +void Foam::bufferedAccumulator::resetAveraging() +{ + accumulationBuffer() = Field(bufferLength(), pTraits::zero); + + averagesTaken_ = 0; +} + + +// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // + +template +void Foam::bufferedAccumulator::operator= +( + const bufferedAccumulator& rhs +) +{ + // Check for assignment to self + if (this == &rhs) + { + FatalErrorIn + ( + "bufferedAccumulator::operator=(const bufferedAccumulator&)" + ) + << "Attempted assignment to self" + << abort(FatalError); + } + + List< Field >::operator=(rhs); + + averagesTaken_ = rhs.averagesTaken(); + + bufferOffsets_ = rhs.bufferOffsets(); +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +# include "bufferedAccumulatorIO.C" + +// ************************************************************************* // diff --git a/src/lagrangian/molecularDynamics/molecule/correlationFunction/bufferedAccumulator/bufferedAccumulator.H b/src/lagrangian/molecularDynamics/molecule/correlationFunction/bufferedAccumulator/bufferedAccumulator.H new file mode 100755 index 0000000000..27bd52771c --- /dev/null +++ b/src/lagrangian/molecularDynamics/molecule/correlationFunction/bufferedAccumulator/bufferedAccumulator.H @@ -0,0 +1,178 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd. + \\/ 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Class + Foam::bufferedAccumulator + +Description + +SourceFiles + bufferedAccumulatorI.H + bufferedAccumulator.C + bufferedAccumulatorIO.C + +\*---------------------------------------------------------------------------*/ + +#ifndef bufferedAccumulator_H +#define bufferedAccumulator_H + +#include "Field.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +template +class bufferedAccumulator; + +template +Ostream& operator<< +( + Ostream&, + const bufferedAccumulator& +); + +/*---------------------------------------------------------------------------*\ + Class bufferedAccumulator Declaration +\*---------------------------------------------------------------------------*/ + +template +class bufferedAccumulator +: + public List< Field > +{ + // Private data + + label averagesTaken_; + + List