Commit c9f7267b authored by Andrew Heather's avatar Andrew Heather
Browse files
parents 555c1ea3 270db50f
......@@ -22,27 +22,45 @@ License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
Prints out a description of the streams
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "vector.H"
#include "IFstream.H"
#include "BSpline.H"
#include "IPstream.H"
#include "OPstream.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
void Foam::IPstream::print(Ostream& os) const
int main(int argc, char *argv[])
{
os << "Reading from processor " << fromProcNo_
<< " to processor " << myProcNo() << Foam::endl;
}
argList::noParallel();
argList::validArgs.insert("file .. fileN");
argList args(argc, argv, false, true);
void Foam::OPstream::print(Ostream& os) const
{
os << "Writing from processor " << toProcNo_
<< " to processor " << myProcNo() << Foam::endl;
forAll(args.additionalArgs(), argI)
{
const string& srcFile = args.additionalArgs()[argI];
Info<< nl << "reading " << srcFile << nl;
IFstream ifs(srcFile);
List<pointField> splinePointFields(ifs);
forAll(splinePointFields, splineI)
{
Info<<"convert " << splinePointFields[splineI] << " to bspline" << endl;
BSpline spl(splinePointFields[splineI], vector::zero, vector::zero);
Info<< "1/2 = " << spl.position(0.5) << endl;
}
}
return 0;
}
......
BSplineTest.C
EXE = $(FOAM_USER_APPBIN)/BSplineTest
EXE_INC = \
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/mesh/blockMesh/lnInclude
EXE_LIBS = -lblockMesh
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 1.6 |
| \\ / A nd | Web: http://www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
(
// Upper body longitudinal splines.
(
(-0.22685 -0.01125166 0) // 7
(-0.21685 -0.01340204 0)
(-0.20685 -0.01529684 0)
(-0.19685 -0.01694748 0)
(-0.18685 -0.01836538 0)
(-0.17685 -0.01956197 0)
(-0.16685 -0.02054868 0)
(-0.15685 -0.02133693 0)
(-0.14685 -0.02193816 0)
(-0.13685 -0.02236377 0)
(-0.12685 -0.02262521 0)
(-0.11685 -0.02273389 0) // 2
)
(
(-0.22685 0 0.01125166) // 8
(-0.21685 0 0.01340204)
(-0.20685 0 0.01529684)
(-0.19685 0 0.01694748)
(-0.18685 0 0.01836538)
(-0.17685 0 0.01956197)
(-0.16685 0 0.02054868)
(-0.15685 0 0.02133693)
(-0.14685 0 0.02193816)
(-0.13685 0 0.02236377)
(-0.12685 0 0.02262521)
(-0.11685 0 0.02273389) // 3
)
(
(-0.22685 0.01125166 0) // 9
(-0.21685 0.01340204 0)
(-0.20685 0.01529684 0)
(-0.19685 0.01694748 0)
(-0.18685 0.01836538 0)
(-0.17685 0.01956197 0)
(-0.16685 0.02054868 0)
(-0.15685 0.02133693 0)
(-0.14685 0.02193816 0)
(-0.13685 0.02236377 0)
(-0.12685 0.02262521 0)
(-0.11685 0.02273389 0) // 4
)
(
(-0.22685 0 -0.01125166) // 6
(-0.21685 0 -0.01340204)
(-0.20685 0 -0.01529684)
(-0.19685 0 -0.01694748)
(-0.18685 0 -0.01836538)
(-0.17685 0 -0.01956197)
(-0.16685 0 -0.02054868)
(-0.15685 0 -0.02133693)
(-0.14685 0 -0.02193816)
(-0.13685 0 -0.02236377)
(-0.12685 0 -0.02262521)
(-0.11685 0 -0.02273389) // 1
)
);
......@@ -22,13 +22,9 @@ License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
\*---------------------------------------------------------------------------*/
#include "GatherBase.H"
#include "IPstream.H"
#include "OPstream.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
......@@ -108,11 +108,14 @@ StringStreams = $(Streams)/StringStreams
$(StringStreams)/StringStreamsPrint.C
Pstreams = $(Streams)/Pstreams
$(Pstreams)/Pstream.C
$(Pstreams)/PstreamCommsStruct.C
$(Pstreams)/UIPstream.C
$(Pstreams)/IPstream.C
$(Pstreams)/UPstream.C
$(Pstreams)/UPstreamCommsStruct.C
$(Pstreams)/Pstream.C
$(Pstreams)/UOPstream.C
$(Pstreams)/OPstream.C
$(Pstreams)/PstreamsPrint.C
$(Pstreams)/PstreamBuffers.C
dictionary = db/dictionary
$(dictionary)/dictionary.C
......
......@@ -114,7 +114,7 @@ void Foam::ParSortableList<Type>::checkAndSend
}
{
OPstream toSlave(destProcI);
OPstream toSlave(Pstream::blocking, destProcI);
toSlave << values << indices;
}
}
......@@ -311,7 +311,7 @@ void Foam::ParSortableList<Type>::sort()
Pout<< "Receiving from " << procI << endl;
}
IPstream fromSlave(procI);
IPstream fromSlave(Pstream::blocking, procI);
fromSlave >> recValues >> recIndices;
......
......@@ -24,291 +24,22 @@ License
\*---------------------------------------------------------------------------*/
#include "error.H"
#include "IPstream.H"
#include "int.H"
#include "token.H"
#include <cctype>
// * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * Private member functions * * * * * * * * * * * //
inline void Foam::IPstream::checkEof()
{
if (bufPosition_ == messageSize_)
{
setEof();
}
}
template<class T>
inline void Foam::IPstream::readFromBuffer(T& t)
{
const size_t align = sizeof(T);
bufPosition_ = align + ((bufPosition_ - 1) & ~(align - 1));
t = reinterpret_cast<T&>(buf_[bufPosition_]);
bufPosition_ += sizeof(T);
checkEof();
}
inline void Foam::IPstream::readFromBuffer
Foam::IPstream::IPstream
(
void* data,
size_t count,
size_t align
const commsTypes commsType,
const int fromProcNo,
const label bufSize,
streamFormat format,
versionNumber version
)
{
if (align > 1)
{
bufPosition_ = align + ((bufPosition_ - 1) & ~(align - 1));
}
register const char* bufPtr = &buf_[bufPosition_];
register char* dataPtr = reinterpret_cast<char*>(data);
register size_t i = count;
while (i--) *dataPtr++ = *bufPtr++;
bufPosition_ += count;
checkEof();
}
// * * * * * * * * * * * * * * * * 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);
}
}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
Foam::Istream& Foam::IPstream::read(token& t)
{
// Return the put back token if it exists
if (Istream::getBack(t))
{
return *this;
}
char c;
// return on error
if (!read(c))
{
t.setBad();
return *this;
}
// Set the line number of this token to the current stream line number
t.lineNumber() = lineNumber();
// Analyse input starting with this character.
switch (c)
{
// Punctuation
case token::END_STATEMENT :
case token::BEGIN_LIST :
case token::END_LIST :
case token::BEGIN_SQR :
case token::END_SQR :
case token::BEGIN_BLOCK :
case token::END_BLOCK :
case token::COLON :
case token::COMMA :
case token::ASSIGN :
case token::ADD :
case token::SUBTRACT :
case token::MULTIPLY :
case token::DIVIDE :
{
t = token::punctuationToken(c);
return *this;
}
// Word
case token::WORD :
{
word* pval = new word;
if (read(*pval))
{
if (token::compound::isCompound(*pval))
{
t = token::compound::New(*pval, *this).ptr();
delete pval;
}
else
{
t = pval;
}
}
else
{
delete pval;
t.setBad();
}
return *this;
}
// String
case token::STRING :
{
string* pval = new string;
if (read(*pval))
{
t = pval;
}
else
{
delete pval;
t.setBad();
}
return *this;
}
// Label
case token::LABEL :
{
label val;
if (read(val))
{
t = val;
}
else
{
t.setBad();
}
return *this;
}
// floatScalar
case token::FLOAT_SCALAR :
{
floatScalar val;
if (read(val))
{
t = val;
}
else
{
t.setBad();
}
return *this;
}
// doubleScalar
case token::DOUBLE_SCALAR :
{
doubleScalar val;
if (read(val))
{
t = val;
}
else
{
t.setBad();
}
return *this;
}
// Character (returned as a single character word) or error
default:
{
if (isalpha(c))
{
t = word(c);
return *this;
}
setBad();
t.setBad();
return *this;
}
}
}
Foam::Istream& Foam::IPstream::read(char& c)
{
c = buf_[bufPosition_];
bufPosition_++;
checkEof();
return *this;
}
Foam::Istream& Foam::IPstream::read(word& str)
{
size_t len;
readFromBuffer(len);
str = &buf_[bufPosition_];
bufPosition_ += len + 1;
checkEof();
return *this;
}
Foam::Istream& Foam::IPstream::read(string& str)
{
size_t len;
readFromBuffer(len);
str = &buf_[bufPosition_];
bufPosition_ += len + 1;
checkEof();
return *this;
}
Foam::Istream& Foam::IPstream::read(label& val)
{
readFromBuffer(val);
return *this;
}
Foam::Istream& Foam::IPstream::read(floatScalar& val)
{
readFromBuffer(val);
return *this;
}
Foam::Istream& Foam::IPstream::read(doubleScalar& val)
{
readFromBuffer(val);
return *this;
}
Foam::Istream& Foam::IPstream::read(char* data, std::streamsize count)
{
if (format() != BINARY)
{
FatalErrorIn("IPstream::read(char*, std::streamsize)")
<< "stream format not binary"
<< Foam::abort(FatalError);
}
readFromBuffer(data, count, 8);
return *this;
}
Foam::Istream& Foam::IPstream::rewind()
{
bufPosition_ = 0;
return *this;
}
:
Pstream(commsType, bufSize),
UIPstream(commsType, fromProcNo, buf_)
{}
// ************************************************************************* //
......@@ -38,7 +38,7 @@ SourceFiles
#ifndef IPstream_H
#define IPstream_H
#include "Istream.H"
#include "UIPstream.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -52,26 +52,8 @@ namespace Foam
class IPstream
:
public Pstream,
public Istream
public UIPstream
{
// Private data
int fromProcNo_;
label messageSize_;
// Private member functions
//- Check the bufferPosition_ against messageSize_ for EOF
inline void checkEof();
//- Read a T from the transfer buffer
template<class T>
inline void readFromBuffer(T&);
//- Read data from the transfer buffer
inline void readFromBuffer(void* data, size_t count, size_t align);
public:
......@@ -88,76 +70,6 @@ public:
versionNumber version=currentVersion
);
// Destructor
~IPstream();
// Member functions
// Inquiry
//- Return flags of output stream
ios_base::fmtflags flags() const
{
return ios_base::fmtflags(0);
}
// Read functions
//- Read into given buffer from given processor and return the
// message size
static label read
(
const commsTypes commsType,
const int fromProcNo,
char* buf,
const std::streamsize bufSize
);
//- Return next token from stream
Istream& read(token&);
//- Read a character
Istream& read(char&);
//- Read a word
Istream& read(word&);
// Read a string (including enclosing double-quotes)
Istream& read(string&);
//- Read a label
Istream& read(label&);
//- Read a floatScalar
Istream& read(floatScalar&);
//- Read a doubleScalar
Istream& read(doubleScalar&);
//- Read binary block
Istream& read(char*, std::streamsize);
//- Rewind and return the stream so that it may be read again
Istream& rewind();
// Edit
//- Set flags of stream
ios_base::fmtflags flags(const ios_base::fmtflags)
{
return ios_base::fmtflags(0);
}
// Print
//- Print description of IOstream to Ostream
void print(Ostream&) const;
};
......
......@@ -22,68 +22,9 @@ License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
Write primitive and binary block from OPstream
\*---------------------------------------------------------------------------*/