Merge branch 'master' into cvm

This commit is contained in:
graham
2009-08-11 23:17:56 +01:00
51 changed files with 1994 additions and 185 deletions

View File

@ -1,5 +1,4 @@
EXE_INC = \
-I$(WM_THIRD_PARTY_DIR)/zlib-1.2.3
EXE_INC =
LIB_LIBS = \
$(FOAM_LIBBIN)/libOSspecific.o \

View File

@ -78,7 +78,15 @@ inline void Foam::IPstream::readFromBuffer
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::IPstream::~IPstream()
{}
{
if (bufPosition_ < messageSize_)
{
FatalErrorIn("IPstream::~IPstream()")
<< "Message not fully consumed. messageSize:" << messageSize_
<< " bytes of which only " << bufPosition_
<< " consumed." << Foam::abort(FatalError);
}
}

View File

@ -350,6 +350,31 @@ public:
return oldCommsType;
}
//- Transfer buffer
const List<char>& buf() const
{
return buf_;
}
//- Transfer buffer
List<char>& buf()
{
return buf_;
}
//- Current buffer read/write location
int bufPosition() const
{
return bufPosition_;
}
//- Current buffer read/write location
int& bufPosition()
{
return bufPosition_;
}
//- Exit program
static void exit(int errnum = 1);

View File

@ -42,7 +42,7 @@ char Foam::ISstream::nextValid()
while (get(c) && isspace(c))
{}
// Return if stream is bad
// Return if stream is bad - ie, previous get() failed
if (bad() || isspace(c))
{
return 0;
@ -102,7 +102,8 @@ char Foam::ISstream::nextValid()
Foam::Istream& Foam::ISstream::read(token& t)
{
static char charBuffer[128];
static const int maxLen = 128;
static char buf[maxLen];
// Return the put back token if it exists
if (Istream::getBack(t))
@ -114,7 +115,7 @@ Foam::Istream& Foam::ISstream::read(token& t)
// Lines are counted by '\n'
// Get next 'valid character': i.e. proceed through any whitespace
// and/or comments until a semantically valid character is hit upon.
// and/or comments until a semantically valid character is found
char c = nextValid();
@ -131,7 +132,7 @@ Foam::Istream& Foam::ISstream::read(token& t)
// Analyse input starting with this character.
switch (c)
{
// First check for punctuation characters.
// Check for punctuation first
case token::END_STATEMENT :
case token::BEGIN_LIST :
@ -144,7 +145,7 @@ Foam::Istream& Foam::ISstream::read(token& t)
case token::COMMA :
case token::ASSIGN :
case token::ADD :
// case token::SUBTRACT : // Handled later as the possible start of a number
// NB: token::SUBTRACT handled later as the possible start of a Number
case token::MULTIPLY :
case token::DIVIDE :
{
@ -153,26 +154,27 @@ Foam::Istream& Foam::ISstream::read(token& t)
}
// Strings: enclosed by double quotes.
// String: enclosed by double quotes.
case token::BEGIN_STRING :
{
putback(c);
string* sPtr = new string;
if (!read(*sPtr).bad())
{
t = sPtr;
}
else
if (read(*sPtr).bad())
{
delete sPtr;
t.setBad();
}
else
{
t = sPtr;
}
return *this;
}
// Numbers: do not distinguish at this point between Types.
// Number: integer or floating point
//
// ideally match the equivalent of this regular expression
//
@ -185,10 +187,11 @@ Foam::Istream& Foam::ISstream::read(token& t)
{
bool asLabel = (c != '.');
unsigned int nChar = 0;
charBuffer[nChar++] = c;
int nChar = 0;
buf[nChar++] = c;
// get everything that could reasonable look like a number
// get everything that could resemble a number and let
// strtod() determine the validity
while
(
is_.get(c)
@ -202,24 +205,38 @@ Foam::Istream& Foam::ISstream::read(token& t)
)
)
{
asLabel = asLabel && isdigit(c);
if (asLabel)
{
asLabel = isdigit(c);
}
charBuffer[nChar++] = c;
if (nChar >= sizeof(charBuffer))
buf[nChar++] = c;
if (nChar == maxLen)
{
// runaway argument - avoid buffer overflow
buf[maxLen-1] = '\0';
FatalIOErrorIn("ISstream::read(token&)", *this)
<< "number '" << buf << "...'\n"
<< " is too long (max. " << maxLen << " characters)"
<< exit(FatalIOError);
t.setBad();
return *this;
}
}
charBuffer[nChar] = '\0';
buf[nChar] = '\0';
setState(is_.rdstate());
if (!is_.bad())
if (is_.bad())
{
t.setBad();
}
else
{
is_.putback(c);
if (nChar == 1 && charBuffer[0] == '-')
if (nChar == 1 && buf[0] == '-')
{
// a single '-' is punctuation
t = token::punctuationToken(token::SUBTRACT);
@ -230,31 +247,43 @@ Foam::Istream& Foam::ISstream::read(token& t)
if (asLabel)
{
long longval = strtol(charBuffer, &endptr, 10);
t = label(longval);
long longVal(strtol(buf, &endptr, 10));
t = label(longVal);
// return as a scalar if doesn't fit in a label
if (t.labelToken() != longval)
if (t.labelToken() != longVal)
{
t = scalar(strtod(charBuffer, &endptr));
t = scalar(strtod(buf, &endptr));
}
}
else
{
t = scalar(strtod(charBuffer, &endptr));
scalar scalarVal(strtod(buf, &endptr));
t = scalarVal;
// ---------------------------------------
// this would also be possible if desired:
// ---------------------------------------
// // return as a label when possible
// // eg, 1E6 -> 1000000
// if (scalarVal <= labelMax && scalarVal >= labelMin)
// {
// label labelVal(scalarVal);
//
// if (labelVal == scalarVal)
// {
// t = labelVal;
// }
// }
}
// nothing converted (bad format), or trailing junk
if (endptr == charBuffer || *endptr != '\0')
if (endptr == buf || *endptr != '\0')
{
t.setBad();
}
}
}
else
{
t.setBad();
}
return *this;
}
@ -266,23 +295,21 @@ Foam::Istream& Foam::ISstream::read(token& t)
putback(c);
word* wPtr = new word;
if (!read(*wPtr).bad())
{
if (token::compound::isCompound(*wPtr))
{
t = token::compound::New(*wPtr, *this).ptr();
delete wPtr;
}
else
{
t = wPtr;
}
}
else
if (read(*wPtr).bad())
{
delete wPtr;
t.setBad();
}
else if (token::compound::isCompound(*wPtr))
{
t = token::compound::New(*wPtr, *this).ptr();
delete wPtr;
}
else
{
t = wPtr;
}
return *this;
}
}
@ -302,69 +329,64 @@ Foam::Istream& Foam::ISstream::read(word& str)
static const int errLen = 80; // truncate error message for readability
static char buf[maxLen];
register int i = 0;
register int bc = 0;
register int nChar = 0;
register int listDepth = 0;
char c;
while (get(c) && word::valid(c))
{
if (fail())
{
if (i < maxLen-1)
{
buf[i] = '\0';
}
else
{
buf[maxLen-1] = '\0';
}
buf[errLen] = '\0';
FatalIOErrorIn("ISstream::read(word&)", *this)
<< "problem while reading word '" << buf << "'\n"
<< exit(FatalIOError);
return *this;
}
if (i >= maxLen)
{
buf[maxLen-1] = '\0';
buf[errLen] = '\0';
FatalIOErrorIn("ISstream::read(word&)", *this)
<< "word '" << buf << "' ...\n"
<< " is too long (max. " << maxLen << " characters)"
<< exit(FatalIOError);
return *this;
}
if (c == token::BEGIN_LIST)
{
bc++;
listDepth++;
}
else if (c == token::END_LIST)
{
bc--;
if (bc == -1)
if (listDepth)
{
listDepth--;
}
else
{
break;
}
}
buf[i++] = c;
buf[nChar++] = c;
if (nChar == maxLen)
{
buf[errLen] = '\0';
FatalIOErrorIn("ISstream::read(word&)", *this)
<< "word '" << buf << "...'\n"
<< " is too long (max. " << maxLen << " characters)"
<< exit(FatalIOError);
return *this;
}
}
if (i == 0)
// we could probably skip this check
if (bad())
{
buf[errLen] = buf[nChar] = '\0';
FatalIOErrorIn("ISstream::read(word&)", *this)
<< "problem while reading word '" << buf << "...' after "
<< nChar << " characters\n"
<< exit(FatalIOError);
return *this;
}
if (nChar == 0)
{
FatalIOErrorIn("ISstream::read(word&)", *this)
<< "invalid first character found : " << c
<< exit(FatalIOError);
}
buf[i] = '\0'; // Terminator
// done reading
buf[nChar] = '\0';
str = buf;
putback(c);
@ -382,8 +404,6 @@ Foam::Istream& Foam::ISstream::read(string& str)
if (!get(c))
{
buf[0] = '\0';
FatalIOErrorIn("ISstream::read(string&)", *this)
<< "cannot read start of string"
<< exit(FatalIOError);
@ -391,36 +411,32 @@ Foam::Istream& Foam::ISstream::read(string& str)
return *this;
}
char endTok = token::END_STRING;
// Note, we could also handle single-quoted strings here (if desired)
if (c != token::BEGIN_STRING)
{
buf[0] = '\0';
FatalIOErrorIn("ISstream::read(string&)", *this)
<< "Incorrect start of string character"
<< "Incorrect start of string character found : " << c
<< exit(FatalIOError);
return *this;
}
register int i = 0;
register int nChar = 0;
bool escaped = false;
while (get(c))
{
if (c == endTok)
if (c == token::END_STRING)
{
if (escaped)
{
escaped = false;
i--; // overwrite backslash
nChar--; // overwrite backslash
}
else
{
// done reading string
buf[i] = '\0';
// done reading
buf[nChar] = '\0';
str = buf;
return *this;
}
@ -430,12 +446,11 @@ Foam::Istream& Foam::ISstream::read(string& str)
if (escaped)
{
escaped = false;
i--; // overwrite backslash
nChar--; // overwrite backslash
}
else
{
buf[i] = '\0';
buf[errLen] = '\0';
buf[errLen] = buf[nChar] = '\0';
FatalIOErrorIn("ISstream::read(string&)", *this)
<< "found '\\n' while reading string \""
@ -454,10 +469,9 @@ Foam::Istream& Foam::ISstream::read(string& str)
escaped = false;
}
buf[i] = c;
if (i++ == maxLen)
buf[nChar++] = c;
if (nChar == maxLen)
{
buf[maxLen-1] = '\0';
buf[errLen] = '\0';
FatalIOErrorIn("ISstream::read(string&)", *this)
@ -471,8 +485,7 @@ Foam::Istream& Foam::ISstream::read(string& str)
// don't worry about a dangling backslash if string terminated prematurely
buf[i] = '\0';
buf[errLen] = '\0';
buf[errLen] = buf[nChar] = '\0';
FatalIOErrorIn("ISstream::read(string&)", *this)
<< "problem while reading string \"" << buf << "...\""

View File

@ -60,8 +60,8 @@ Foam::argList::initValidTables dummyInitValidTables;
// transform sequences with "(" ... ")" into string lists in the process
bool Foam::argList::regroupArgv(int& argc, char**& argv)
{
int level = 0;
int nArgs = 0;
int listDepth = 0;
string tmpString;
// note: we also re-write directly into args_
@ -70,16 +70,16 @@ bool Foam::argList::regroupArgv(int& argc, char**& argv)
{
if (strcmp(argv[argI], "(") == 0)
{
level++;
listDepth++;
tmpString += "(";
}
else if (strcmp(argv[argI], ")") == 0)
{
if (level >= 1)
if (listDepth)
{
level--;
listDepth--;
tmpString += ")";
if (level == 0)
if (listDepth == 0)
{
args_[nArgs++] = tmpString;
tmpString.clear();
@ -90,7 +90,7 @@ bool Foam::argList::regroupArgv(int& argc, char**& argv)
args_[nArgs++] = argv[argI];
}
}
else if (level)
else if (listDepth)
{
// quote each string element
tmpString += "\"";

View File

@ -61,24 +61,38 @@ Foam::IPstream::IPstream
MPI_Status status;
// Cannot use buf_.size() since appends a few bytes extra
label realBufSize = bufSize;
// If the buffer size is not specified, probe the incomming message
// and set it
if (!bufSize)
{
if (commsType == nonBlocking)
{
FatalErrorIn
(
"IPstream::IPstream(const commsTypes, const int, "
"const label, streamFormat, versionNumber)"
) << "Can use nonBlocking mode only with pre-allocated buffers"
<< Foam::abort(FatalError);
}
MPI_Probe(procID(fromProcNo_), msgType(), MPI_COMM_WORLD, &status);
MPI_Get_count(&status, MPI_BYTE, &messageSize_);
buf_.setSize(messageSize_);
realBufSize = buf_.size();
}
messageSize_ = read(commsType, fromProcNo_, buf_.begin(), buf_.size());
messageSize_ = read(commsType, fromProcNo_, buf_.begin(), realBufSize);
if (!messageSize_)
{
FatalErrorIn
(
"IPstream::IPstream(const int fromProcNo, "
"const label bufSize, streamFormat format, versionNumber version)"
"IPstream::IPstream(const commsTypes, const int, "
"const label, streamFormat, versionNumber)"
) << "read failed"
<< Foam::abort(FatalError);
}
@ -173,7 +187,8 @@ Foam::label Foam::IPstream::read
IPstream_outstandingRequests_.append(request);
return 1;
// Assume the message is completely received.
return bufSize;
}
else
{

View File

@ -1,3 +1 @@
EXE_INC = \
-I$(WM_THIRD_PARTY_DIR)/zlib-1.2.3
EXE_INC =

View File

@ -41,8 +41,8 @@ namespace Foam
void triSurface::writeOBJ(const bool writeSorted, Ostream& os) const
{
// Write header
os << "# Wavefront OBJ file" << endl
<< "# Regions:" << endl;
os << "# Wavefront OBJ file" << nl
<< "# Regions:" << nl;
labelList faceMap;
@ -54,13 +54,13 @@ void triSurface::writeOBJ(const bool writeSorted, Ostream& os) const
forAll(myPatches, patchI)
{
os << "# " << patchI << " "
<< myPatches[patchI].name() << endl;
<< myPatches[patchI].name() << nl;
}
os << "#" << endl;
os << "#" << nl;
os << "# points : " << ps.size() << endl
<< "# triangles : " << size() << endl
<< "#" << endl;
os << "# points : " << ps.size() << nl
<< "# triangles : " << size() << nl
<< "#" << nl;
// Write vertex coords
@ -69,7 +69,7 @@ void triSurface::writeOBJ(const bool writeSorted, Ostream& os) const
os << "v "
<< ps[pointi].x() << ' '
<< ps[pointi].y() << ' '
<< ps[pointi].z() << endl;
<< ps[pointi].z() << nl;
}
if (writeSorted)
@ -80,7 +80,7 @@ void triSurface::writeOBJ(const bool writeSorted, Ostream& os) const
{
// Print all faces belonging to this patch
os << "g " << myPatches[patchI].name() << endl;
os << "g " << myPatches[patchI].name() << nl;
for
(
@ -96,20 +96,39 @@ void triSurface::writeOBJ(const bool writeSorted, Ostream& os) const
<< operator[](faceI)[1] + 1 << ' '
<< operator[](faceI)[2] + 1
//<< " # " << operator[](faceI).region()
<< endl;
<< nl;
}
}
}
else
{
// Get patch (=compact region) per face
labelList patchIDs(size());
forAll(myPatches, patchI)
{
label faceI = myPatches[patchI].start();
forAll(myPatches[patchI], i)
{
patchIDs[faceMap[faceI++]] = patchI;
}
}
label prevPatchI = -1;
forAll(*this, faceI)
{
if (prevPatchI != patchIDs[faceI])
{
prevPatchI = patchIDs[faceI];
os << "g " << myPatches[patchIDs[faceI]].name() << nl;
}
os << "f "
<< operator[](faceI)[0] + 1 << ' '
<< operator[](faceI)[1] + 1 << ' '
<< operator[](faceI)[2] + 1
//<< " # " << operator[](faceI).region()
<< endl;
<< nl;
}
}
}

View File

@ -70,8 +70,7 @@ tmp<scalarField> mutURoughWallFunctionFvPatchScalarField::calcYPlus
// of the wall will depend on yPlus
forAll(yPlus, facei)
{
const scalar magUpara = magUp[facei];
const scalar Re = rho[facei]*magUpara*y[facei]/muw[facei];
const scalar Re = rho[facei]*magUp[facei]*y[facei]/muw[facei];
const scalar kappaRe = kappa_*Re;
scalar yp = yPlusLam_;
@ -142,8 +141,7 @@ tmp<scalarField> mutURoughWallFunctionFvPatchScalarField::calcYPlus
// Smooth Walls
forAll(yPlus, facei)
{
const scalar magUpara = magUp[facei];
const scalar Re = rho[facei]*magUpara*y[facei]/muw[facei];
const scalar Re = rho[facei]*magUp[facei]*y[facei]/muw[facei];
const scalar kappaRe = kappa_*Re;
scalar yp = yPlusLam_;
@ -193,7 +191,8 @@ tmp<scalarField> mutURoughWallFunctionFvPatchScalarField::calcMut() const
{
if (yPlus[facei] > yPlusLam_)
{
const scalar Re = rho[facei]*magUp[facei]*y[facei]/muw[facei];
const scalar Re =
rho[facei]*magUp[facei]*y[facei]/muw[facei] + ROOTVSMALL;
mutw[facei] = muw[facei]*(sqr(yPlus[facei])/Re - 1);
}
}

View File

@ -66,10 +66,9 @@ tmp<scalarField> mutUSpaldingWallFunctionFvPatchScalarField::calcUTau
forAll(mutw, faceI)
{
scalar magUpara = magUp[faceI];
scalar ut =
sqrt((mutw[faceI] + muw[faceI])*magGradU[faceI]/rhow[faceI]);
sqrt((mutw[faceI] + muw[faceI])*magGradU[faceI]/rhow[faceI])
+ ROOTVSMALL;
if (ut > VSMALL)
{
@ -78,17 +77,17 @@ tmp<scalarField> mutUSpaldingWallFunctionFvPatchScalarField::calcUTau
do
{
scalar kUu = min(kappa_*magUpara/ut, 50);
scalar kUu = min(kappa_*magUp[faceI]/ut, 50);
scalar fkUu = exp(kUu) - 1 - kUu*(1 + 0.5*kUu);
scalar f =
- ut*y[faceI]/(muw[faceI]/rhow[faceI])
+ magUpara/ut
+ magUp[faceI]/ut
+ 1/E_*(fkUu - 1.0/6.0*kUu*sqr(kUu));
scalar df =
y[faceI]/(muw[faceI]/rhow[faceI])
+ magUpara/sqr(ut)
+ magUp[faceI]/sqr(ut)
+ 1/E_*kUu*fkUu/ut;
scalar uTauNew = ut + f/df;
@ -111,7 +110,7 @@ tmp<scalarField> mutUSpaldingWallFunctionFvPatchScalarField::calcMut() const
const RASModel& rasModel = db().lookupObject<RASModel>("RASProperties");
const fvPatchVectorField& Uw = rasModel.U().boundaryField()[patchI];
const scalarField magGradU = mag(Uw.snGrad());
const scalarField magGradU = mag(Uw.snGrad()) + ROOTVSMALL;
const scalarField& rhow = rasModel.rho().boundaryField()[patchI];
const scalarField& muw = rasModel.mu().boundaryField()[patchI];

View File

@ -63,7 +63,7 @@ tmp<scalarField> nutURoughWallFunctionFvPatchScalarField::calcNut() const
{
if (yPlus[facei] > yPlusLam_)
{
const scalar Re = magUp[facei]*y[facei]/nuw[facei];
const scalar Re = magUp[facei]*y[facei]/nuw[facei] + ROOTVSMALL;
nutw[facei] = nuw[facei]*(sqr(yPlus[facei])/Re - 1);
}
}

View File

@ -47,7 +47,7 @@ tmp<scalarField> nutUSpaldingWallFunctionFvPatchScalarField::calcNut() const
const RASModel& rasModel = db().lookupObject<RASModel>("RASProperties");
const fvPatchVectorField& Uw = rasModel.U().boundaryField()[patchI];
const scalarField magGradU = mag(Uw.snGrad());
const scalarField magGradU = mag(Uw.snGrad()) + ROOTVSMALL;
const scalarField& nuw = rasModel.nu().boundaryField()[patchI];
return max(scalar(0), sqr(calcUTau(magGradU))/magGradU - nuw);
@ -74,9 +74,8 @@ tmp<scalarField> nutUSpaldingWallFunctionFvPatchScalarField::calcUTau
forAll(uTau, facei)
{
scalar magUpara = magUp[facei];
scalar ut = sqrt((nutw[facei] + nuw[facei])*magGradU[facei]);
scalar ut =
sqrt((nutw[facei] + nuw[facei])*magGradU[facei]) + ROOTVSMALL;
if (ut > VSMALL)
{
@ -85,17 +84,17 @@ tmp<scalarField> nutUSpaldingWallFunctionFvPatchScalarField::calcUTau
do
{
scalar kUu = min(kappa_*magUpara/ut, 50);
scalar kUu = min(kappa_*magUp[facei]/ut, 50);
scalar fkUu = exp(kUu) - 1 - kUu*(1 + 0.5*kUu);
scalar f =
- ut*y[facei]/nuw[facei]
+ magUpara/ut
+ magUp[facei]/ut
+ 1/E_*(fkUu - 1.0/6.0*kUu*sqr(kUu));
scalar df =
y[facei]/nuw[facei]
+ magUpara/sqr(ut)
+ magUp[facei]/sqr(ut)
+ 1/E_*kUu*fkUu/ut;
scalar uTauNew = ut + f/df;
@ -103,6 +102,7 @@ tmp<scalarField> nutUSpaldingWallFunctionFvPatchScalarField::calcUTau
ut = uTauNew;
} while (ut > VSMALL && err > 0.01 && ++iter < 10);
uTau[facei] = max(0.0, ut);
}
}