mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
Added new multiple interaction site, rigid 6DOF molecule.
This commit is contained in:
@ -26,9 +26,6 @@ $(reducedUnits)/reducedUnitsIO.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
|
||||
|
||||
179
src/lagrangian/molecularDynamics/molecule/molecule/molecule.C
Normal file
179
src/lagrangian/molecularDynamics/molecule/molecule/molecule.C
Normal file
@ -0,0 +1,179 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2008 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 "molecule.H"
|
||||
#include "Random.H"
|
||||
#include "Time.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::molecule::move(molecule::trackData& td)
|
||||
{
|
||||
td.switchProcessor = false;
|
||||
td.keepParticle = true;
|
||||
|
||||
scalar deltaT = cloud().pMesh().time().deltaT().value();
|
||||
scalar tEnd = (1.0 - stepFraction())*deltaT;
|
||||
scalar dtMax = tEnd;
|
||||
|
||||
if (td.part() == 0)
|
||||
{
|
||||
// Leapfrog velocity adjust part, required before and after
|
||||
// tracking+force part
|
||||
|
||||
U_ += 0.5*deltaT*A_;
|
||||
}
|
||||
else if (td.part() == 1)
|
||||
{
|
||||
// Leapfrog tracking part
|
||||
|
||||
while (td.keepParticle && !td.switchProcessor && tEnd > ROOTVSMALL)
|
||||
{
|
||||
// set the lagrangian time-step
|
||||
scalar dt = min(dtMax, tEnd);
|
||||
|
||||
dt *= trackToFace(position() + dt*U_, td);
|
||||
|
||||
tEnd -= dt;
|
||||
stepFraction() = 1.0 - tEnd/deltaT;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
FatalErrorIn("molecule::move(molecule::trackData& td)") << nl
|
||||
<< td.part()
|
||||
<< " is an invalid part of integration method: "
|
||||
<< method << nl
|
||||
<< abort(FatalError);
|
||||
}
|
||||
|
||||
return td.keepParticle;
|
||||
}
|
||||
|
||||
|
||||
void Foam::molecule::transformProperties(const tensor& T)
|
||||
{}
|
||||
|
||||
|
||||
void Foam::molecule::transformProperties(const vector& separation)
|
||||
{
|
||||
if (special_)
|
||||
{
|
||||
specialPosition_ += separation;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::molecule::hitProcessorPatch
|
||||
(
|
||||
const processorPolyPatch&,
|
||||
molecule::trackData& td
|
||||
)
|
||||
{
|
||||
td.switchProcessor = true;
|
||||
}
|
||||
|
||||
|
||||
void Foam::molecule::hitProcessorPatch
|
||||
(
|
||||
const processorPolyPatch&,
|
||||
int&
|
||||
)
|
||||
{}
|
||||
|
||||
|
||||
void Foam::molecule::hitWallPatch
|
||||
(
|
||||
const wallPolyPatch& wpp,
|
||||
molecule::trackData& td
|
||||
)
|
||||
{
|
||||
vector nw = wpp.faceAreas()[wpp.whichFace(face())];
|
||||
nw /= mag(nw);
|
||||
|
||||
scalar Un = U_ & nw;
|
||||
// vector Ut = U_ - Un*nw;
|
||||
|
||||
// Random rand(clock::getTime());
|
||||
|
||||
// scalar tmac = 0.8;
|
||||
|
||||
// scalar wallTemp = 2.5;
|
||||
|
||||
// if (rand.scalar01() < tmac)
|
||||
// {
|
||||
// // Diffuse reflection
|
||||
//
|
||||
// vector tw1 = Ut/mag(Ut);
|
||||
//
|
||||
// vector tw2 = nw ^ tw1;
|
||||
//
|
||||
// U_ = sqrt(wallTemp/mass_)*rand.GaussNormal()*tw1
|
||||
// + sqrt(wallTemp/mass_)*rand.GaussNormal()*tw2
|
||||
// - mag(sqrt(wallTemp/mass_)*rand.GaussNormal())*nw;
|
||||
// }
|
||||
|
||||
// else
|
||||
// {
|
||||
// Specular reflection
|
||||
|
||||
if (Un > 0)
|
||||
{
|
||||
U_ -= 2*Un*nw;
|
||||
}
|
||||
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Foam::molecule::hitWallPatch
|
||||
(
|
||||
const wallPolyPatch&,
|
||||
int&
|
||||
)
|
||||
{}
|
||||
|
||||
|
||||
void Foam::molecule::hitPatch
|
||||
(
|
||||
const polyPatch&,
|
||||
molecule::trackData& td
|
||||
)
|
||||
{
|
||||
td.keepParticle = false;
|
||||
}
|
||||
|
||||
|
||||
void Foam::molecule::hitPatch
|
||||
(
|
||||
const polyPatch&,
|
||||
int&
|
||||
)
|
||||
{}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
307
src/lagrangian/molecularDynamics/molecule/molecule/molecule.H
Normal file
307
src/lagrangian/molecularDynamics/molecule/molecule/molecule.H
Normal file
@ -0,0 +1,307 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2008 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::molecule
|
||||
|
||||
Description
|
||||
Foam::molecule
|
||||
|
||||
SourceFiles
|
||||
moleculeI.H
|
||||
molecule.C
|
||||
moleculeIO.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef molecule_H
|
||||
#define molecule_H
|
||||
|
||||
#include "Particle.H"
|
||||
#include "IOstream.H"
|
||||
#include "autoPtr.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Class forward declarations
|
||||
class moleculeCloud;
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class molecule Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class molecule
|
||||
:
|
||||
public Particle<molecule>
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
//- Class to hold molecule constant properties
|
||||
class constantProperties
|
||||
{
|
||||
|
||||
// Private data
|
||||
|
||||
List<vector> siteReferencePositions_;
|
||||
|
||||
List<scalar> siteCharges_;
|
||||
|
||||
List<label> siteIds_;
|
||||
|
||||
diagTensor momentOfInertia_;
|
||||
|
||||
scalar mass_;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Constructor
|
||||
inline constantProperties();
|
||||
|
||||
// Member functions
|
||||
|
||||
inline const List<vector>& siteReferencePositions() const;
|
||||
|
||||
inline const List<scalar>& siteCharges() const;
|
||||
|
||||
inline const List<label>& siteIds() const;
|
||||
|
||||
inline const diagTensor& momentOfInertia() const;
|
||||
|
||||
inline scalar mass() const;
|
||||
|
||||
};
|
||||
|
||||
|
||||
//- Class used to pass tracking data to the trackToFace function
|
||||
class trackData
|
||||
:
|
||||
public Particle<molecule>::trackData
|
||||
{
|
||||
moleculeCloud& molCloud_;
|
||||
|
||||
// label specifying which part of the integration algorithm is taking
|
||||
// place (i.e. leapfrog 1 or leapfrog 2. Predictor or Corrector)
|
||||
label part_;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
inline trackData
|
||||
(
|
||||
moleculeCloud& molCloud,
|
||||
label part
|
||||
);
|
||||
|
||||
// Member functions
|
||||
|
||||
inline moleculeCloud& molCloud();
|
||||
|
||||
inline label part() const;
|
||||
};
|
||||
|
||||
|
||||
private:
|
||||
|
||||
// Private data
|
||||
|
||||
//- Be careful with the ordering of data.
|
||||
// It has an impact on binary transfer:
|
||||
// -# Put the largest data members 1st
|
||||
// -# Pair up labels,
|
||||
// -# Don't go scalar-label, scalar-label, because in 64bit mode,
|
||||
// the labels will be padded by 4bytes.
|
||||
|
||||
// Centre of mass velocities and accelerations
|
||||
|
||||
vector u_;
|
||||
|
||||
vector a_;
|
||||
|
||||
vector omega_;
|
||||
|
||||
vector alpha_;
|
||||
|
||||
List<vector> siteForces_;
|
||||
|
||||
List<vector> sitePostions_;
|
||||
|
||||
vector specialPosition_;
|
||||
|
||||
scalar potentialEnergy_;
|
||||
|
||||
// - r_ij f_ij, stress dyad
|
||||
tensor rf_;
|
||||
|
||||
const constantProperties& constProps_;
|
||||
|
||||
label special_;
|
||||
|
||||
label id_;
|
||||
|
||||
public:
|
||||
|
||||
friend class Cloud<molecule>;
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from components
|
||||
inline molecule
|
||||
(
|
||||
const Cloud<molecule>& c,
|
||||
const vector& position,
|
||||
const label celli,
|
||||
const scalar mass,
|
||||
const vector& U,
|
||||
const vector& A,
|
||||
const vector& specialPosition,
|
||||
const label special,
|
||||
const label id
|
||||
);
|
||||
|
||||
//- Construct from Istream
|
||||
molecule
|
||||
(
|
||||
const Cloud<molecule>& c,
|
||||
Istream& is,
|
||||
bool readFields = true
|
||||
);
|
||||
|
||||
//- Construct and return a clone
|
||||
autoPtr<molecule> clone() const
|
||||
{
|
||||
return autoPtr<molecule>(new molecule(*this));
|
||||
}
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
void transformProperties(const tensor& T);
|
||||
|
||||
void transformProperties(const vector& separation);
|
||||
|
||||
// Access
|
||||
|
||||
inline label id() const;
|
||||
|
||||
inline scalar mass() const;
|
||||
|
||||
inline const vector& U() const;
|
||||
inline vector& U();
|
||||
|
||||
inline const vector& A() const;
|
||||
inline vector& A();
|
||||
|
||||
inline scalar potentialEnergy() const;
|
||||
inline scalar& potentialEnergy();
|
||||
|
||||
inline const tensor& rf() const;
|
||||
inline tensor& rf();
|
||||
|
||||
inline label special() const;
|
||||
|
||||
inline const vector& specialPosition() const;
|
||||
inline vector& specialPosition();
|
||||
|
||||
|
||||
//- Tracking
|
||||
bool move(trackData&);
|
||||
|
||||
|
||||
// Member Operators
|
||||
|
||||
//- Overridable function to handle the particle hitting a processorPatch
|
||||
void hitProcessorPatch
|
||||
(
|
||||
const processorPolyPatch&,
|
||||
molecule::trackData& td
|
||||
);
|
||||
|
||||
//- Overridable function to handle the particle hitting a processorPatch
|
||||
// without trackData
|
||||
void hitProcessorPatch
|
||||
(
|
||||
const processorPolyPatch&,
|
||||
int&
|
||||
);
|
||||
|
||||
//- Overridable function to handle the particle hitting a wallPatch
|
||||
void hitWallPatch
|
||||
(
|
||||
const wallPolyPatch&,
|
||||
molecule::trackData& td
|
||||
);
|
||||
|
||||
//- Overridable function to handle the particle hitting a wallPatch
|
||||
// without trackData
|
||||
void hitWallPatch
|
||||
(
|
||||
const wallPolyPatch&,
|
||||
int&
|
||||
);
|
||||
|
||||
//- Overridable function to handle the particle hitting a polyPatch
|
||||
void hitPatch
|
||||
(
|
||||
const polyPatch&,
|
||||
molecule::trackData& td
|
||||
);
|
||||
|
||||
//- Overridable function to handle the particle hitting a polyPatch
|
||||
// without trackData
|
||||
void hitPatch
|
||||
(
|
||||
const polyPatch&,
|
||||
int&
|
||||
);
|
||||
|
||||
static void readFields(moleculeCloud& mC);
|
||||
|
||||
static void writeFields(const moleculeCloud& mC);
|
||||
|
||||
|
||||
// IOstream Operators
|
||||
|
||||
friend Ostream& operator<<(Ostream&, const molecule&);
|
||||
};
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#include "moleculeI.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
204
src/lagrangian/molecularDynamics/molecule/molecule/moleculeI.H
Normal file
204
src/lagrangian/molecularDynamics/molecule/molecule/moleculeI.H
Normal file
@ -0,0 +1,204 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2008 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
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
inline Foam::molecule::constantProperties::constantProperties()
|
||||
:
|
||||
|
||||
{}
|
||||
|
||||
|
||||
inline Foam::molecule::trackData::trackData
|
||||
(
|
||||
moleculeCloud& molCloud,
|
||||
label part
|
||||
)
|
||||
:
|
||||
Particle<molecule>::trackData(refCast<Cloud<molecule> >(molCloud)),
|
||||
molCloud_(molCloud),
|
||||
part_(part)
|
||||
{}
|
||||
|
||||
|
||||
inline Foam::molecule::molecule
|
||||
(
|
||||
const Cloud<molecule>& c,
|
||||
const vector& position,
|
||||
const label celli,
|
||||
const scalar mass,
|
||||
const vector& U,
|
||||
const vector& A,
|
||||
const vector& tetherPosition,
|
||||
const label tethered,
|
||||
const label id
|
||||
)
|
||||
:
|
||||
Particle<molecule>(c, position, celli),
|
||||
mass_(mass),
|
||||
U_(U),
|
||||
A_(A),
|
||||
tetherPosition_(tetherPosition),
|
||||
potentialEnergy_(0.0),
|
||||
rf_(tensor::zero),
|
||||
tethered_(tethered),
|
||||
id_(id)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * constantProperties Member Functions * * * * * * * * * * * * //
|
||||
|
||||
inline const Foam::List<vector>&
|
||||
Foam::molecule::constantProperties::siteReferencePositions() const
|
||||
{
|
||||
return siteReferencePositions_;
|
||||
}
|
||||
|
||||
|
||||
inline const Foam::List<scalar>&
|
||||
Foam::molecule::constantProperties::siteCharges() const
|
||||
{
|
||||
return siteCharges_;
|
||||
}
|
||||
|
||||
|
||||
inline const Foam::List<label>&
|
||||
Foam::molecule::constantProperties::siteIds() const
|
||||
{
|
||||
return siteIds_;
|
||||
}
|
||||
|
||||
|
||||
inline const Foam::diagTensor&
|
||||
Foam::molecule::constantProperties::momentOfInertia() const
|
||||
{
|
||||
return momentOfInertia_;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::scalar Foam::molecule::constantProperties::mass() const
|
||||
{
|
||||
return mass_;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * trackData Member Functions * * * * * * * * * * * * //
|
||||
|
||||
inline moleculeCloud& Foam::molecule::trackData::molCloud()
|
||||
{
|
||||
return molCloud_;
|
||||
}
|
||||
|
||||
|
||||
inline label Foam::molecule::trackData::part() const
|
||||
{
|
||||
return part_;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * molecule Member Functions * * * * * * * * * * * * //
|
||||
|
||||
inline label Foam::molecule::id() const
|
||||
{
|
||||
return id_;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::scalar Foam::molecule::mass() const
|
||||
{
|
||||
return mass_;
|
||||
}
|
||||
|
||||
|
||||
inline const Foam::vector& Foam::molecule::U() const
|
||||
{
|
||||
return U_;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::vector& Foam::molecule::U()
|
||||
{
|
||||
return U_;
|
||||
}
|
||||
|
||||
|
||||
inline const Foam::vector& Foam::molecule::A() const
|
||||
{
|
||||
return A_;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::vector& Foam::molecule::A()
|
||||
{
|
||||
return A_;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::scalar Foam::molecule::potentialEnergy() const
|
||||
{
|
||||
return potentialEnergy_;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::scalar& Foam::molecule::potentialEnergy()
|
||||
{
|
||||
return potentialEnergy_;
|
||||
}
|
||||
|
||||
|
||||
inline const Foam::tensor& Foam::molecule::rf() const
|
||||
{
|
||||
return rf_;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::tensor& Foam::molecule::rf()
|
||||
{
|
||||
return rf_;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::label Foam::molecule::tethered() const
|
||||
{
|
||||
return tethered_;
|
||||
}
|
||||
|
||||
|
||||
inline const Foam::vector& Foam::molecule::tetherPosition() const
|
||||
{
|
||||
return tetherPosition_;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::vector& Foam::molecule::tetherPosition()
|
||||
{
|
||||
return tetherPosition_;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
// ************************************************************************* //
|
||||
208
src/lagrangian/molecularDynamics/molecule/molecule/moleculeIO.C
Normal file
208
src/lagrangian/molecularDynamics/molecule/molecule/moleculeIO.C
Normal file
@ -0,0 +1,208 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2008 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 "molecule.H"
|
||||
#include "IOstreams.H"
|
||||
|
||||
#include "moleculeCloud.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::molecule::molecule
|
||||
(
|
||||
const Cloud<molecule>& cloud,
|
||||
Istream& is,
|
||||
bool readFields
|
||||
)
|
||||
:
|
||||
Particle<molecule>(cloud, is)
|
||||
{
|
||||
if (readFields)
|
||||
{
|
||||
if (is.format() == IOstream::ASCII)
|
||||
{
|
||||
id_ = readLabel(is);
|
||||
mass_ = readScalar(is);
|
||||
is >> U_;
|
||||
is >> A_;
|
||||
is >> potentialEnergy_;
|
||||
is >> rf_;
|
||||
is >> tethered_;
|
||||
is >> tetherPosition_;
|
||||
}
|
||||
else
|
||||
{
|
||||
is.read
|
||||
(
|
||||
reinterpret_cast<char*>(&mass_),
|
||||
sizeof(mass_)
|
||||
+ sizeof(U_)
|
||||
+ sizeof(A_)
|
||||
+ sizeof(tetherPosition_)
|
||||
+ sizeof(potentialEnergy_)
|
||||
+ sizeof(rf_)
|
||||
+ sizeof(tethered_)
|
||||
+ sizeof(id_)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Check state of Istream
|
||||
is.check("Foam::molecule::molecule(Foam::Istream&)");
|
||||
}
|
||||
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
void molecule::readFields(moleculeCloud& mC)
|
||||
{
|
||||
if (!mC.size())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
IOField<label> id(mC.fieldIOobject("id"));
|
||||
mC.checkFieldIOobject(mC, id);
|
||||
|
||||
IOField<scalar> mass(mC.fieldIOobject("mass"));
|
||||
mC.checkFieldIOobject(mC, mass);
|
||||
|
||||
IOField<vector> U(mC.fieldIOobject("U"));
|
||||
mC.checkFieldIOobject(mC, U);
|
||||
|
||||
IOField<vector> A(mC.fieldIOobject("A"));
|
||||
mC.checkFieldIOobject(mC, A);
|
||||
|
||||
IOField<label> tethered(mC.fieldIOobject("tethered"));
|
||||
mC.checkFieldIOobject(mC, tethered);
|
||||
|
||||
IOField<vector> tetherPositions(mC.fieldIOobject("tetherPositions"));
|
||||
mC.checkFieldIOobject(mC, tetherPositions);
|
||||
|
||||
label i = 0;
|
||||
forAllIter(moleculeCloud, mC, iter)
|
||||
{
|
||||
molecule& mol = iter();
|
||||
|
||||
mol.id_ = id[i];
|
||||
mol.mass_ = mass[i];
|
||||
mol.U_ = U[i];
|
||||
mol.A_ = A[i];
|
||||
mol.potentialEnergy_ = 0.0;
|
||||
mol.rf_ = tensor::zero;
|
||||
mol.tethered_ = tethered[i];
|
||||
mol.tetherPosition_ = tetherPositions[i];
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void molecule::writeFields(const moleculeCloud& mC)
|
||||
{
|
||||
Particle<molecule>::writeFields(mC);
|
||||
|
||||
label np = mC.size();
|
||||
|
||||
IOField<label> id(mC.fieldIOobject("id"), np);
|
||||
IOField<scalar> mass(mC.fieldIOobject("mass"), np);
|
||||
IOField<vector> U(mC.fieldIOobject("U"), np);
|
||||
IOField<vector> A(mC.fieldIOobject("A"), np);
|
||||
IOField<label> tethered(mC.fieldIOobject("tethered"), np);
|
||||
IOField<vector> tetherPositions(mC.fieldIOobject("tetherPositions"), np);
|
||||
|
||||
label i = 0;
|
||||
forAllConstIter(moleculeCloud, mC, iter)
|
||||
{
|
||||
const molecule& mol = iter();
|
||||
|
||||
id[i] = mol.id_;
|
||||
mass[i] = mol.mass_;
|
||||
U[i] = mol.U_;
|
||||
A[i] = mol.A_;
|
||||
tethered[i] = mol.tethered_;
|
||||
tetherPositions[i] = mol.tetherPosition_;
|
||||
i++;
|
||||
}
|
||||
|
||||
id.write();
|
||||
mass.write();
|
||||
U.write();
|
||||
A.write();
|
||||
tethered.write();
|
||||
tetherPositions.write();
|
||||
}
|
||||
|
||||
}; // end of namespace Foam
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
||||
|
||||
Foam::Ostream& Foam::operator<<(Ostream& os, const molecule& mol)
|
||||
{
|
||||
if (os.format() == IOstream::ASCII)
|
||||
{
|
||||
os << mol.id_
|
||||
<< token::SPACE << mol.mass_
|
||||
<< token::SPACE << static_cast<const Particle<molecule>&>(mol)
|
||||
<< token::SPACE << mol.face()
|
||||
<< token::SPACE << mol.stepFraction()
|
||||
<< token::SPACE << mol.U_
|
||||
<< token::SPACE << mol.A_
|
||||
<< token::SPACE << mol.potentialEnergy_
|
||||
<< token::SPACE << mol.rf_
|
||||
<< token::SPACE << mol.tethered_
|
||||
<< token::SPACE << mol.tetherPosition_;
|
||||
}
|
||||
else
|
||||
{
|
||||
os << static_cast<const Particle<molecule>&>(mol);
|
||||
os.write
|
||||
(
|
||||
reinterpret_cast<const char*>(&mol.mass_),
|
||||
sizeof(mol.mass_)
|
||||
+ sizeof(mol.U_)
|
||||
+ sizeof(mol.A_)
|
||||
+ sizeof(mol.tetherPosition_)
|
||||
+ sizeof(mol.potentialEnergy_)
|
||||
+ sizeof(mol.rf_)
|
||||
+ sizeof(mol.tethered_)
|
||||
+ sizeof(mol.id_)
|
||||
);
|
||||
}
|
||||
|
||||
// Check state of Ostream
|
||||
os.check
|
||||
(
|
||||
"Foam::Ostream& Foam::operator<<"
|
||||
"(Foam::Ostream&, const Foam::molecule&)"
|
||||
);
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
Reference in New Issue
Block a user