mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-12-28 03:37:59 +00:00
Merge branch 'master' of /home/noisy3/OpenFOAM/OpenFOAM-dev
This commit is contained in:
@ -1,4 +1,7 @@
|
||||
calcEntry/calcEntry.C
|
||||
dictionaryTest.C
|
||||
|
||||
calcEntry/calcEntry.C
|
||||
calcEntry/calcEntryParser.cpp
|
||||
calcEntry/calcEntryScanner.cpp
|
||||
|
||||
EXE = $(FOAM_USER_APPBIN)/dictionaryTest
|
||||
|
||||
141
applications/test/dictionary/calcEntry/CocoParserErrors.H
Normal file
141
applications/test/dictionary/calcEntry/CocoParserErrors.H
Normal file
@ -0,0 +1,141 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2009-2009 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::CocoParserErrors
|
||||
|
||||
Description
|
||||
Templated class to shadow the error handling for Coco/R parsers
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef CocoParserErrors_H
|
||||
#define CocoParserErrors_H
|
||||
|
||||
#include "error.H"
|
||||
#include "wchar.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class CocoParserErrors Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
template<class BaseClass>
|
||||
class CocoParserErrors
|
||||
:
|
||||
public BaseClass
|
||||
{
|
||||
// Private data
|
||||
|
||||
//- The name issued in warnings and errors
|
||||
word name_;
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct with given name
|
||||
CocoParserErrors(const word& name)
|
||||
:
|
||||
BaseClass(),
|
||||
name_(name)
|
||||
{}
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~CocoParserErrors()
|
||||
{}
|
||||
|
||||
|
||||
// Member functions
|
||||
|
||||
//- Return the name issued for warnings
|
||||
virtual const word& name() const
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
//- Return the name issued for warnings
|
||||
virtual word& name()
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
|
||||
// Error Handling
|
||||
|
||||
//- Handle a general warning 'msg'
|
||||
virtual void Warning(const wchar_t* msg)
|
||||
{
|
||||
WarningIn(name_)
|
||||
<< msg << endl;
|
||||
}
|
||||
|
||||
//- Handle a general warning 'msg'
|
||||
virtual void Warning(int line, int col, const wchar_t* msg)
|
||||
{
|
||||
WarningIn(name_)
|
||||
<<"line " << line << " col " << col << ": "
|
||||
<< msg << endl;
|
||||
}
|
||||
|
||||
//- Handle general error 'msg' (eg, a semantic error)
|
||||
virtual void Error(int line, int col, const wchar_t* msg)
|
||||
{
|
||||
FatalErrorIn(name_)
|
||||
<< "line " << line << " col " << col <<": " << msg << endl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
//- Handle general error 'msg' (eg, a semantic error)
|
||||
virtual void Error(const wchar_t* msg)
|
||||
{
|
||||
FatalErrorIn(name_)
|
||||
<< msg << endl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
//- Handle a general exception 'msg'
|
||||
virtual void Exception(const wchar_t* msg)
|
||||
{
|
||||
this->Error(msg);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
225
applications/test/dictionary/calcEntry/SimpleCalc.atg
Normal file
225
applications/test/dictionary/calcEntry/SimpleCalc.atg
Normal file
@ -0,0 +1,225 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
compile with:
|
||||
Coco \
|
||||
-frames $WM_THIRD_PARTY_DIR/coco-r \
|
||||
-prefix calcEntry \
|
||||
-namespace Foam::functionEntries::calcEntryInternal \
|
||||
SimpleCalc.atg
|
||||
-------------------------------------------------------------------------*/
|
||||
|
||||
#include "dictionary.H"
|
||||
#include "scalar.H"
|
||||
#include "error.H"
|
||||
#include "wchar.H"
|
||||
|
||||
|
||||
COMPILER SimpleCalc
|
||||
// Simple four function calculator for OpenFOAM dictionaries
|
||||
|
||||
//! with debug
|
||||
static const int debug = 0;
|
||||
|
||||
//! The parent dictionary
|
||||
mutable dictionary* dict_;
|
||||
|
||||
//! The calculation result
|
||||
scalar val;
|
||||
|
||||
//! token -> scalar
|
||||
scalar getScalar() const
|
||||
{
|
||||
return coco_string_toDouble(t->val);
|
||||
}
|
||||
|
||||
//! token -> string
|
||||
std::string getString() const
|
||||
{
|
||||
char* str = coco_string_create_char(t->val);
|
||||
std::string s(str);
|
||||
coco_string_delete(str);
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
//! attach a dictionary
|
||||
void dict(const dictionary& dict) const
|
||||
{
|
||||
dict_ = const_cast<dictionary*>(&dict);
|
||||
}
|
||||
|
||||
|
||||
//! lookup dictionary entry
|
||||
scalar getDictLookup() const
|
||||
{
|
||||
scalar dictValue = 0;
|
||||
|
||||
if (!dict_)
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"SimpleCalc::getDictEntry() const"
|
||||
) << "No dictionary attached!"
|
||||
<< exit(FatalError);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
char* chars = coco_string_create_char
|
||||
(
|
||||
t->val,
|
||||
1,
|
||||
(coco_string_length(t->val) - 1)
|
||||
);
|
||||
word keyword(chars);
|
||||
coco_string_delete(chars);
|
||||
|
||||
if (debug)
|
||||
{
|
||||
Info<<"lookup: " << keyword << nl;
|
||||
}
|
||||
|
||||
entry* entryPtr = dict_->lookupEntryPtr(keyword, true, false);
|
||||
if (entryPtr && !entryPtr->isDict())
|
||||
{
|
||||
entryPtr->stream() >> dictValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"SimpleCalc::getDictEntry() const"
|
||||
) << "keyword " << keyword << " is undefined in dictionary "
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
|
||||
return dictValue;
|
||||
}
|
||||
|
||||
scalar Result() const
|
||||
{
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * CHARACTERS * * * * * * * * * * * * * * * * //
|
||||
|
||||
CHARACTERS
|
||||
letter = 'A'..'Z' + 'a'..'z'.
|
||||
qualifier = '_' + ':'.
|
||||
dollar = '$'.
|
||||
digit = "0123456789".
|
||||
sign = '+' + '-'.
|
||||
cr = '\r'.
|
||||
lf = '\n'.
|
||||
tab = '\t'.
|
||||
stringCh = ANY - '"' - '\\' - cr - lf.
|
||||
printable = '\u0020' .. '\u007e'.
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * TOKENS * * * * * * * * * * * * * * * * * //
|
||||
|
||||
TOKENS
|
||||
|
||||
// identifier
|
||||
ident =
|
||||
letter { letter | digit | qualifier }.
|
||||
|
||||
// string
|
||||
string =
|
||||
'"' { stringCh | '\\' printable } '"'.
|
||||
|
||||
// dictionary lookup identifier
|
||||
// starts with '$' and otherwise limited to a normal indentifier
|
||||
variable =
|
||||
dollar letter { letter | digit | qualifier }.
|
||||
|
||||
// floating point and integer numbers
|
||||
number =
|
||||
[sign] ('.' digit { digit } ) | ( digit { digit } [ '.' { digit } ])
|
||||
[ ('E' | 'e') [sign] digit { digit } ].
|
||||
|
||||
|
||||
// * * * * * * * * * * * PRAGMAS / COMMENTS / IGNORE * * * * * * * * * * * //
|
||||
|
||||
COMMENTS FROM "/*" TO "*/" NESTED
|
||||
COMMENTS FROM "//" TO lf
|
||||
|
||||
// ignore unprintables
|
||||
IGNORE ANY - printable
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * PRODUCTIONS * * * * * * * * * * * * * * * //
|
||||
|
||||
PRODUCTIONS
|
||||
|
||||
SimpleCalc (. val = 0;
|
||||
if (debug){Info<<"start val"<< nl;}
|
||||
.)
|
||||
=
|
||||
( '{' Expr<val> '}' | Expr<val> )
|
||||
EOF
|
||||
.
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
Expr<scalar& val> (. scalar val2 = 0;
|
||||
if (debug) {Info<<"Expr:"<< val<< nl;}
|
||||
.)
|
||||
=
|
||||
Term<val>
|
||||
{
|
||||
"+" Term<val2> (. if (debug) {Info<<"+Term:"<<val2 <<nl;}
|
||||
val += val2;
|
||||
if (debug) {Info<<"="<< val << nl;}
|
||||
.)
|
||||
| "-" Term<val2> (. if (debug) {Info<<"-Term:"<<val2 <<nl;}
|
||||
val -= val2;
|
||||
if (debug) {Info<<"="<< val << nl;}
|
||||
.)
|
||||
}
|
||||
.
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
Term<scalar& val> (. scalar val2 = 0;
|
||||
if (debug) {Info<<"Term:"<< val<< nl;}
|
||||
.)
|
||||
=
|
||||
Factor<val>
|
||||
{
|
||||
"*" Factor<val2> (. if (debug) {Info<<"*Factor:"<<val2 << nl;}
|
||||
val *= val2;
|
||||
if (debug) {Info<<"="<< val << nl; }
|
||||
.)
|
||||
| "/" Factor<val2> (. if (debug) {Info<<"/Factor:"<<val2 << nl;}
|
||||
val /= val2;
|
||||
if (debug) {Info<<"="<< val << nl; }
|
||||
.)
|
||||
}
|
||||
.
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
Factor<scalar& val>
|
||||
=
|
||||
variable (. val = getDictLookup();
|
||||
if (debug) {Info<<"lookup:"<<val<<nl;}
|
||||
.)
|
||||
| number (. val = getScalar();
|
||||
if (debug) {Info<<"got num:"<<val<<nl;}
|
||||
.)
|
||||
| '-' '(' Expr<val> ')' (. val = -val;
|
||||
if (debug) {Info<<"inv:"<<val<<nl;}
|
||||
.)
|
||||
| '(' Expr<val> ')' (. if (debug){Info<<"got Expr:"<<val<<nl;} .)
|
||||
.
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
END SimpleCalc.
|
||||
|
||||
// ************************************************************************* //
|
||||
11
applications/test/dictionary/calcEntry/build.sh
Executable file
11
applications/test/dictionary/calcEntry/build.sh
Executable file
@ -0,0 +1,11 @@
|
||||
#/bin/sh
|
||||
cd ${0%/*} || exit 1 # run from this directory
|
||||
|
||||
# this will have to do until we make a makefile rule
|
||||
|
||||
Coco \
|
||||
-frames $WM_THIRD_PARTY_DIR/coco-r \
|
||||
-prefix calcEntry \
|
||||
-namespace Foam::functionEntries::calcEntryInternal \
|
||||
SimpleCalc.atg
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2009-2009 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -30,6 +30,10 @@ License
|
||||
#include "OStringStream.H"
|
||||
#include "addToMemberFunctionSelectionTable.H"
|
||||
|
||||
#include "ISstream.H"
|
||||
#include "CocoParserErrors.H"
|
||||
#include "calcEntryParser.h"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
@ -56,14 +60,121 @@ bool Foam::functionEntries::calcEntry::execute
|
||||
(
|
||||
const dictionary& parentDict,
|
||||
primitiveEntry& entry,
|
||||
Istream& is
|
||||
Istream& istr
|
||||
)
|
||||
{
|
||||
dictionary args(parentDict, is);
|
||||
OStringStream resultStream;
|
||||
resultStream
|
||||
<< (args.lookup("x")[0].number() + args.lookup("y")[0].number());
|
||||
entry.read(parentDict, IStringStream(resultStream.str())());
|
||||
static const int maxLen = 1024;
|
||||
static const int errLen = 80; // truncate error message for readability
|
||||
static char buf[maxLen];
|
||||
|
||||
ISstream& is = dynamicCast<ISstream>(istr);
|
||||
|
||||
// get the { ... } argument without the enclosing brace brackets
|
||||
//
|
||||
// THIS NEEDS REWORKING (LATER) ...
|
||||
|
||||
char c = 0;
|
||||
|
||||
if (!is.read(c).good() || c != token::BEGIN_BLOCK)
|
||||
{
|
||||
is.setBad();
|
||||
FatalIOErrorIn("functionEntries::calcEntry::execute()", is)
|
||||
<< "Expected a '" << token::BEGIN_BLOCK
|
||||
<< "', found '" << c << "'" << exit(FatalIOError);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
register int nChar = 0;
|
||||
buf[nChar++] = token::BEGIN_BLOCK;
|
||||
int listDepth = 1; // already saw the first '{'
|
||||
|
||||
while (is.get(c).good())
|
||||
{
|
||||
buf[nChar++] = c;
|
||||
if (nChar == maxLen)
|
||||
{
|
||||
buf[errLen] = '\0';
|
||||
|
||||
FatalIOErrorIn("functionEntries::calcEntry::execute()", is)
|
||||
<< "argument \"" << buf << "...\"\n"
|
||||
<< " is too long (max. " << maxLen << " characters)"
|
||||
<< exit(FatalIOError);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// handle nested blocks, even if we don't know what they'd
|
||||
// be useful for
|
||||
if (c == token::BEGIN_BLOCK)
|
||||
{
|
||||
++listDepth;
|
||||
}
|
||||
else if (c == token::END_BLOCK)
|
||||
{
|
||||
if (--listDepth == 0)
|
||||
{
|
||||
// done reading - overwrite the final '}'
|
||||
// --nChar;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
buf[nChar] = '\0';
|
||||
|
||||
|
||||
// emit some info
|
||||
Info<< "grabbed " << nChar << " characters:" << nl
|
||||
<< "----------\n"
|
||||
<< buf << nl
|
||||
<< "----------\n"
|
||||
<< nl;
|
||||
|
||||
|
||||
// define parser error handler
|
||||
CocoParserErrors<calcEntryInternal::Errors>
|
||||
myErrorHandler("calcEntry::Parser--");
|
||||
|
||||
calcEntryInternal::Scanner scanner(buf, nChar);
|
||||
calcEntryInternal::Parser parser(&scanner, &myErrorHandler);
|
||||
|
||||
// Attach dictionary context
|
||||
parser.dict(parentDict);
|
||||
|
||||
parser.Parse();
|
||||
|
||||
// Info<<"got: " << parser.Result() << endl;
|
||||
|
||||
tokenList tokens(2);
|
||||
tokens[0] = parser.Result();
|
||||
tokens[1] = token::END_STATEMENT;
|
||||
|
||||
// Info<<"tokens[0] = " << tokens[0].info() <<nl;
|
||||
// Info<<"tokens[1] = " << tokens[1].info() <<nl;
|
||||
//
|
||||
// {
|
||||
// const tokenList& toks = entry;
|
||||
//
|
||||
// forAll(toks, tokI)
|
||||
// {
|
||||
// Info<< tokI <<":= " << toks[tokI].info() << endl;
|
||||
// }
|
||||
// }
|
||||
|
||||
ITstream its("ParserResult", tokens);
|
||||
entry.read(parentDict, its);
|
||||
// Info<< "size: " << entry.size() << endl;
|
||||
// entry = newente;
|
||||
// entry.print(Info);
|
||||
|
||||
/// const tokenList& toks = entry;
|
||||
///
|
||||
/// forAll(toks, tokI)
|
||||
/// {
|
||||
/// Info<< tokI <<":= " << toks[tokI].info() << endl;
|
||||
/// }
|
||||
///
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2009-2009 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -26,6 +26,8 @@ Class
|
||||
Foam::functionEntries::calcEntry
|
||||
|
||||
Description
|
||||
This dictionary function entry may or may not do anything particularly
|
||||
useful - depending upon what is currently being used to test.
|
||||
|
||||
SourceFiles
|
||||
calcEntry.C
|
||||
@ -45,7 +47,7 @@ namespace functionEntries
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class calcEntry Declaration
|
||||
Class calcEntry Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class calcEntry
|
||||
|
||||
324
applications/test/dictionary/calcEntry/calcEntryParser.cpp
Normal file
324
applications/test/dictionary/calcEntry/calcEntryParser.cpp
Normal file
@ -0,0 +1,324 @@
|
||||
|
||||
|
||||
#include <wchar.h>
|
||||
#include "calcEntryParser.h"
|
||||
|
||||
|
||||
namespace Foam {
|
||||
namespace functionEntries {
|
||||
namespace calcEntryInternal {
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Parser Implementation
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void Parser::SynErr(int n) {
|
||||
if (errDist >= minErrDist) errors->SynErr(la->line, la->col, n);
|
||||
errDist = 0;
|
||||
}
|
||||
|
||||
|
||||
void Parser::SemErr(const wchar_t* msg) {
|
||||
if (errDist >= minErrDist) errors->Error(t->line, t->col, msg);
|
||||
errDist = 0;
|
||||
}
|
||||
|
||||
|
||||
void Parser::Get() {
|
||||
for (;;) {
|
||||
t = la;
|
||||
la = scanner->Scan();
|
||||
if (la->kind <= maxT) {
|
||||
++errDist;
|
||||
break;
|
||||
}
|
||||
|
||||
if (dummyToken != t) {
|
||||
dummyToken->kind = t->kind;
|
||||
dummyToken->pos = t->pos;
|
||||
dummyToken->col = t->col;
|
||||
dummyToken->line = t->line;
|
||||
dummyToken->next = NULL;
|
||||
coco_string_delete(dummyToken->val);
|
||||
dummyToken->val = coco_string_create(t->val);
|
||||
t = dummyToken;
|
||||
}
|
||||
la = t;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Parser::Expect(int n) {
|
||||
if (la->kind == n) {
|
||||
Get();
|
||||
}
|
||||
else {
|
||||
SynErr(n);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Parser::ExpectWeak(int n, int follow) {
|
||||
if (la->kind == n) {
|
||||
Get();
|
||||
}
|
||||
else {
|
||||
SynErr(n);
|
||||
while (!StartOf(follow)) {
|
||||
Get();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool Parser::WeakSeparator(int n, int syFol, int repFol) {
|
||||
if (la->kind == n) {
|
||||
Get();
|
||||
return true;
|
||||
}
|
||||
else if (StartOf(repFol)) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
SynErr(n);
|
||||
while (!(StartOf(syFol) || StartOf(repFol) || StartOf(0))) {
|
||||
Get();
|
||||
}
|
||||
return StartOf(syFol);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Parser::SimpleCalc() {
|
||||
val = 0;
|
||||
if (debug){Info<<"start val"<< nl;}
|
||||
|
||||
if (la->kind == 5) {
|
||||
Get();
|
||||
Expr(val);
|
||||
Expect(6);
|
||||
} else if (StartOf(1)) {
|
||||
Expr(val);
|
||||
} else SynErr(14);
|
||||
Expect(0);
|
||||
}
|
||||
|
||||
void Parser::Expr(scalar& val) {
|
||||
scalar val2 = 0;
|
||||
if (debug) {Info<<"Expr:"<< val<< nl;}
|
||||
|
||||
Term(val);
|
||||
while (la->kind == 7 || la->kind == 8) {
|
||||
if (la->kind == 7) {
|
||||
Get();
|
||||
Term(val2);
|
||||
if (debug) {Info<<"+Term:"<<val2 <<nl;}
|
||||
val += val2;
|
||||
if (debug) {Info<<"="<< val << nl;}
|
||||
|
||||
} else {
|
||||
Get();
|
||||
Term(val2);
|
||||
if (debug) {Info<<"-Term:"<<val2 <<nl;}
|
||||
val -= val2;
|
||||
if (debug) {Info<<"="<< val << nl;}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Parser::Term(scalar& val) {
|
||||
scalar val2 = 0;
|
||||
if (debug) {Info<<"Term:"<< val<< nl;}
|
||||
|
||||
Factor(val);
|
||||
while (la->kind == 9 || la->kind == 10) {
|
||||
if (la->kind == 9) {
|
||||
Get();
|
||||
Factor(val2);
|
||||
if (debug) {Info<<"*Factor:"<<val2 << nl;}
|
||||
val *= val2;
|
||||
if (debug) {Info<<"="<< val << nl; }
|
||||
|
||||
} else {
|
||||
Get();
|
||||
Factor(val2);
|
||||
if (debug) {Info<<"/Factor:"<<val2 << nl;}
|
||||
val /= val2;
|
||||
if (debug) {Info<<"="<< val << nl; }
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Parser::Factor(scalar& val) {
|
||||
if (la->kind == 3) {
|
||||
Get();
|
||||
val = getDictLookup();
|
||||
if (debug) {Info<<"lookup:"<<val<<nl;}
|
||||
|
||||
} else if (la->kind == 4) {
|
||||
Get();
|
||||
val = getScalar();
|
||||
if (debug) {Info<<"got num:"<<val<<nl;}
|
||||
|
||||
} else if (la->kind == 8) {
|
||||
Get();
|
||||
Expect(11);
|
||||
Expr(val);
|
||||
Expect(12);
|
||||
val = -val;
|
||||
if (debug) {Info<<"inv:"<<val<<nl;}
|
||||
|
||||
} else if (la->kind == 11) {
|
||||
Get();
|
||||
Expr(val);
|
||||
Expect(12);
|
||||
if (debug){Info<<"got Expr:"<<val<<nl;}
|
||||
} else SynErr(15);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Parser::Parse() {
|
||||
t = NULL;
|
||||
if (dummyToken) { // safety: someone might call Parse() twice
|
||||
delete dummyToken;
|
||||
}
|
||||
la = dummyToken = new Token();
|
||||
la->val = coco_string_create(L"Dummy Token");
|
||||
Get();
|
||||
SimpleCalc();
|
||||
|
||||
Expect(0);
|
||||
}
|
||||
|
||||
|
||||
Parser::Parser(Scanner* scan, Errors* err)
|
||||
:
|
||||
dummyToken(NULL),
|
||||
deleteErrorsDestruct_(!err),
|
||||
minErrDist(2),
|
||||
errDist(minErrDist),
|
||||
scanner(scan),
|
||||
errors(err),
|
||||
t(NULL),
|
||||
la(NULL)
|
||||
{
|
||||
maxT = 13;
|
||||
|
||||
if (!errors) { // add in default error handling
|
||||
errors = new Errors();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool Parser::StartOf(int s) {
|
||||
const bool T = true;
|
||||
const bool x = false;
|
||||
|
||||
static bool set[2][15] = {
|
||||
{T,x,x,x, x,x,x,x, x,x,x,x, x,x,x},
|
||||
{x,x,x,T, T,x,x,x, T,x,x,T, x,x,x}
|
||||
};
|
||||
|
||||
|
||||
|
||||
return set[s][la->kind];
|
||||
}
|
||||
|
||||
|
||||
Parser::~Parser() {
|
||||
if (deleteErrorsDestruct_) { // delete default error handling
|
||||
delete errors;
|
||||
}
|
||||
delete dummyToken;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Errors Implementation
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
Errors::Errors()
|
||||
:
|
||||
count(0)
|
||||
{}
|
||||
|
||||
|
||||
Errors::~Errors()
|
||||
{}
|
||||
|
||||
|
||||
void Errors::clear() {
|
||||
count = 0;
|
||||
}
|
||||
|
||||
|
||||
wchar_t* Errors::strerror(int n)
|
||||
{
|
||||
wchar_t* s;
|
||||
switch (n) {
|
||||
case 0: s = coco_string_create(L"EOF expected"); break;
|
||||
case 1: s = coco_string_create(L"ident expected"); break;
|
||||
case 2: s = coco_string_create(L"string expected"); break;
|
||||
case 3: s = coco_string_create(L"variable expected"); break;
|
||||
case 4: s = coco_string_create(L"number expected"); break;
|
||||
case 5: s = coco_string_create(L"\"{\" expected"); break;
|
||||
case 6: s = coco_string_create(L"\"}\" expected"); break;
|
||||
case 7: s = coco_string_create(L"\"+\" expected"); break;
|
||||
case 8: s = coco_string_create(L"\"-\" expected"); break;
|
||||
case 9: s = coco_string_create(L"\"*\" expected"); break;
|
||||
case 10: s = coco_string_create(L"\"/\" expected"); break;
|
||||
case 11: s = coco_string_create(L"\"(\" expected"); break;
|
||||
case 12: s = coco_string_create(L"\")\" expected"); break;
|
||||
case 13: s = coco_string_create(L"??? expected"); break;
|
||||
case 14: s = coco_string_create(L"invalid SimpleCalc"); break;
|
||||
case 15: s = coco_string_create(L"invalid Factor"); break;
|
||||
|
||||
default:
|
||||
{
|
||||
wchar_t format[20];
|
||||
coco_swprintf(format, 20, L"error %d", n);
|
||||
s = coco_string_create(format);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
void Errors::Warning(const wchar_t* msg) {
|
||||
wprintf(L"%ls\n", msg);
|
||||
}
|
||||
|
||||
|
||||
void Errors::Warning(int line, int col, const wchar_t* msg) {
|
||||
wprintf(L"-- line %d col %d: %ls\n", line, col, msg);
|
||||
}
|
||||
|
||||
|
||||
void Errors::Error(int line, int col, const wchar_t* msg) {
|
||||
wprintf(L"-- line %d col %d: %ls\n", line, col, msg);
|
||||
count++;
|
||||
}
|
||||
|
||||
|
||||
void Errors::SynErr(int line, int col, int n) {
|
||||
wchar_t* msg = this->strerror(n);
|
||||
this->Error(line, col, msg);
|
||||
coco_string_delete(msg);
|
||||
}
|
||||
|
||||
|
||||
void Errors::Exception(const wchar_t* msg) {
|
||||
wprintf(L"%ls", msg);
|
||||
::exit(1);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
|
||||
192
applications/test/dictionary/calcEntry/calcEntryParser.h
Normal file
192
applications/test/dictionary/calcEntry/calcEntryParser.h
Normal file
@ -0,0 +1,192 @@
|
||||
|
||||
|
||||
#ifndef COCO_calcEntryPARSER_H__
|
||||
#define COCO_calcEntryPARSER_H__
|
||||
|
||||
#include "dictionary.H"
|
||||
#include "scalar.H"
|
||||
#include "error.H"
|
||||
#include "wchar.H"
|
||||
|
||||
|
||||
#include "calcEntryScanner.h"
|
||||
|
||||
namespace Foam {
|
||||
namespace functionEntries {
|
||||
namespace calcEntryInternal {
|
||||
|
||||
|
||||
//! Parser error handing
|
||||
class Errors {
|
||||
public:
|
||||
int count; //!< The number of errors detected
|
||||
|
||||
//! Allocate and return a string describing the given error code.
|
||||
/** It is the responsibility of the caller to free this string,
|
||||
* eg, with coco_string_delete()
|
||||
*/
|
||||
static wchar_t* strerror(int n);
|
||||
|
||||
Errors(); //!< Construct null - start with no errors
|
||||
virtual ~Errors(); //!< Destructor
|
||||
virtual void clear(); //!< Clear the error count
|
||||
|
||||
//! Handle a general warning 'msg'
|
||||
virtual void Warning(const wchar_t* msg);
|
||||
//! Handle a general warning 'msg'
|
||||
virtual void Warning(int line, int col, const wchar_t* msg);
|
||||
//! Handle general error 'msg' (eg, a semantic error)
|
||||
virtual void Error(int line, int col, const wchar_t* msg);
|
||||
//! Handle syntax error 'n', uses strerror for the message, calls Error()
|
||||
virtual void SynErr(int line, int col, int n);
|
||||
//! Handle a general exception 'msg'
|
||||
virtual void Exception(const wchar_t* msg);
|
||||
|
||||
}; // Errors
|
||||
|
||||
|
||||
//! A Coco/R Parser
|
||||
class Parser {
|
||||
private:
|
||||
enum {
|
||||
_EOF=0,
|
||||
_ident=1,
|
||||
_string=2,
|
||||
_variable=3,
|
||||
_number=4,
|
||||
};
|
||||
int maxT;
|
||||
|
||||
Token *dummyToken;
|
||||
bool deleteErrorsDestruct_; //!< delete the 'errors' member in destructor
|
||||
int minErrDist;
|
||||
int errDist;
|
||||
|
||||
void SynErr(int n); //!< Handle syntax error 'n'
|
||||
void Get();
|
||||
void Expect(int n);
|
||||
bool StartOf(int s);
|
||||
void ExpectWeak(int n, int follow);
|
||||
bool WeakSeparator(int n, int syFol, int repFol);
|
||||
|
||||
public:
|
||||
Scanner *scanner;
|
||||
Errors *errors;
|
||||
|
||||
Token *t; //!< last recognized token
|
||||
Token *la; //!< lookahead token
|
||||
|
||||
static const int debug = 0;
|
||||
|
||||
//! The parent dictionary
|
||||
mutable dictionary* dict_;
|
||||
|
||||
//! The calculation result
|
||||
scalar val;
|
||||
|
||||
//! token -> scalar
|
||||
scalar getScalar() const
|
||||
{
|
||||
return coco_string_toDouble(t->val);
|
||||
}
|
||||
|
||||
//! token -> string
|
||||
std::string getString() const
|
||||
{
|
||||
char* str = coco_string_create_char(t->val);
|
||||
std::string s(str);
|
||||
coco_string_delete(str);
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
//! attach a dictionary
|
||||
void dict(const dictionary& dict) const
|
||||
{
|
||||
dict_ = const_cast<dictionary*>(&dict);
|
||||
}
|
||||
|
||||
|
||||
//! lookup dictionary entry
|
||||
scalar getDictLookup() const
|
||||
{
|
||||
scalar dictValue = 0;
|
||||
|
||||
if (!dict_)
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"SimpleCalc::getDictEntry() const"
|
||||
) << "No dictionary attached!"
|
||||
<< exit(FatalError);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
char* chars = coco_string_create_char
|
||||
(
|
||||
t->val,
|
||||
1,
|
||||
(coco_string_length(t->val) - 1)
|
||||
);
|
||||
word keyword(chars);
|
||||
coco_string_delete(chars);
|
||||
|
||||
if (debug)
|
||||
{
|
||||
Info<<"lookup: " << keyword << nl;
|
||||
}
|
||||
|
||||
entry* entryPtr = dict_->lookupEntryPtr(keyword, true, false);
|
||||
if (entryPtr && !entryPtr->isDict())
|
||||
{
|
||||
entryPtr->stream() >> dictValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"SimpleCalc::getDictEntry() const"
|
||||
) << "keyword " << keyword << " is undefined in dictionary "
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
|
||||
return dictValue;
|
||||
}
|
||||
|
||||
scalar Result() const
|
||||
{
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * CHARACTERS * * * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
|
||||
//! Construct for the specified scanner
|
||||
/**
|
||||
* Use the default error handling, or optionally provide an error
|
||||
* handler, which will not be deleted upon destruction.
|
||||
*/
|
||||
Parser(Scanner* scan, Errors* err = 0);
|
||||
~Parser(); //!< Destructor - cleanup errors and dummyToken
|
||||
void SemErr(const wchar_t* msg); //!< Handle semantic error
|
||||
|
||||
void SimpleCalc();
|
||||
void Expr(scalar& val);
|
||||
void Term(scalar& val);
|
||||
void Factor(scalar& val);
|
||||
|
||||
void Parse(); //!< Execute the parse operation
|
||||
|
||||
}; // end Parser
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
|
||||
#endif // COCO_calcEntryPARSER_H__
|
||||
|
||||
825
applications/test/dictionary/calcEntry/calcEntryScanner.cpp
Normal file
825
applications/test/dictionary/calcEntry/calcEntryScanner.cpp
Normal file
@ -0,0 +1,825 @@
|
||||
|
||||
|
||||
#include <memory.h>
|
||||
#include <string.h>
|
||||
#include "calcEntryScanner.h"
|
||||
|
||||
namespace Foam {
|
||||
namespace functionEntries {
|
||||
namespace calcEntryInternal {
|
||||
|
||||
|
||||
// * * * * * * * * * * Wide Character String Routines * * * * * * * * * * * //
|
||||
|
||||
// string handling, wide character
|
||||
|
||||
wchar_t* coco_string_create(const wchar_t* str) {
|
||||
int len = coco_string_length(str);
|
||||
wchar_t* dest = new wchar_t[len + 1];
|
||||
if (len) {
|
||||
wcsncpy(dest, str, len);
|
||||
}
|
||||
dest[len] = 0;
|
||||
return dest;
|
||||
}
|
||||
|
||||
wchar_t* coco_string_create(const wchar_t* str, int index, int length) {
|
||||
int len = coco_string_length(str);
|
||||
if (len) {
|
||||
len = length;
|
||||
}
|
||||
wchar_t* dest = new wchar_t[len + 1];
|
||||
if (len) {
|
||||
wcsncpy(dest, &(str[index]), len);
|
||||
}
|
||||
dest[len] = 0;
|
||||
return dest;
|
||||
}
|
||||
|
||||
wchar_t* coco_string_create_upper(const wchar_t* str) {
|
||||
if (!str) { return NULL; }
|
||||
return coco_string_create_upper(str, 0, wcslen(str));
|
||||
}
|
||||
|
||||
|
||||
wchar_t* coco_string_create_upper(const wchar_t* str, int index, int len) {
|
||||
if (!str) { return NULL; }
|
||||
wchar_t* dest = new wchar_t[len + 1];
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
const wchar_t ch = str[index + i];
|
||||
if ((L'a' <= ch) && (ch <= L'z')) {
|
||||
dest[i] = ch + (L'A' - L'a');
|
||||
}
|
||||
else {
|
||||
dest[i] = ch;
|
||||
}
|
||||
}
|
||||
dest[len] = L'\0';
|
||||
return dest;
|
||||
}
|
||||
|
||||
|
||||
wchar_t* coco_string_create_lower(const wchar_t* str) {
|
||||
if (!str) { return NULL; }
|
||||
return coco_string_create_lower(str, 0, wcslen(str));
|
||||
}
|
||||
|
||||
|
||||
wchar_t* coco_string_create_lower(const wchar_t* str, int index, int len) {
|
||||
if (!str) { return NULL; }
|
||||
wchar_t* dest = new wchar_t[len + 1];
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
const wchar_t ch = str[index + i];
|
||||
if ((L'A' <= ch) && (ch <= L'Z')) {
|
||||
dest[i] = ch - (L'A' - L'a');
|
||||
}
|
||||
else {
|
||||
dest[i] = ch;
|
||||
}
|
||||
}
|
||||
dest[len] = L'\0';
|
||||
return dest;
|
||||
}
|
||||
|
||||
|
||||
wchar_t* coco_string_create_append(const wchar_t* str1, const wchar_t* str2) {
|
||||
int str1Len = coco_string_length(str1);
|
||||
int str2Len = coco_string_length(str2);
|
||||
|
||||
wchar_t* dest = new wchar_t[str1Len + str2Len + 1];
|
||||
|
||||
if (str1Len) { wcscpy(dest, str1); }
|
||||
if (str2Len) { wcscpy(dest + str1Len, str2); }
|
||||
|
||||
dest[str1Len + str2Len] = 0;
|
||||
return dest;
|
||||
}
|
||||
|
||||
wchar_t* coco_string_create_append(const wchar_t* str1, const wchar_t ch) {
|
||||
int len = coco_string_length(str1);
|
||||
wchar_t* dest = new wchar_t[len + 2];
|
||||
wcsncpy(dest, str1, len); // or use if (len) { wcscpy(dest, str1); }
|
||||
dest[len] = ch;
|
||||
dest[len + 1] = 0;
|
||||
return dest;
|
||||
}
|
||||
|
||||
void coco_string_delete(wchar_t* &str) {
|
||||
delete [] str;
|
||||
str = NULL;
|
||||
}
|
||||
|
||||
int coco_string_length(const wchar_t* str) {
|
||||
return str ? wcslen(str) : 0;
|
||||
}
|
||||
|
||||
bool coco_string_endswith(const wchar_t* str, const wchar_t* endstr) {
|
||||
int strLen = wcslen(str);
|
||||
int endLen = wcslen(endstr);
|
||||
return (endLen <= strLen) && (wcscmp(str + strLen - endLen, endstr) == 0);
|
||||
}
|
||||
|
||||
int coco_string_indexof(const wchar_t* str, const wchar_t ch) {
|
||||
const wchar_t* fnd = wcschr(str, ch);
|
||||
return fnd ? (fnd - str) : -1;
|
||||
}
|
||||
|
||||
int coco_string_lastindexof(const wchar_t* str, const wchar_t ch) {
|
||||
const wchar_t* fnd = wcsrchr(str, ch);
|
||||
return fnd ? (fnd - str) : -1;
|
||||
}
|
||||
|
||||
void coco_string_merge(wchar_t* &dest, const wchar_t* str) {
|
||||
if (!str) { return; }
|
||||
wchar_t* newstr = coco_string_create_append(dest, str);
|
||||
delete [] dest;
|
||||
dest = newstr;
|
||||
}
|
||||
|
||||
bool coco_string_equal(const wchar_t* str1, const wchar_t* str2) {
|
||||
return wcscmp(str1, str2) == 0;
|
||||
}
|
||||
|
||||
int coco_string_compareto(const wchar_t* str1, const wchar_t* str2) {
|
||||
return wcscmp(str1, str2);
|
||||
}
|
||||
|
||||
int coco_string_hash(const wchar_t* str) {
|
||||
int h = 0;
|
||||
if (!str) { return 0; }
|
||||
while (*str != 0) {
|
||||
h = (h * 7) ^ *str;
|
||||
++str;
|
||||
}
|
||||
if (h < 0) { h = -h; }
|
||||
return h;
|
||||
}
|
||||
|
||||
|
||||
double coco_string_toDouble(const wchar_t* str)
|
||||
{
|
||||
return str ? wcstod(str, NULL) : 0;
|
||||
}
|
||||
|
||||
float coco_string_toFloat(const wchar_t* str)
|
||||
{
|
||||
return str ? wcstof(str, NULL) : 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// string handling, byte character
|
||||
//
|
||||
|
||||
wchar_t* coco_string_create(const char* str) {
|
||||
int len = str ? strlen(str) : 0;
|
||||
wchar_t* dest = new wchar_t[len + 1];
|
||||
for (int i = 0; i < len; ++i) {
|
||||
dest[i] = (wchar_t) str[i];
|
||||
}
|
||||
dest[len] = 0;
|
||||
return dest;
|
||||
}
|
||||
|
||||
wchar_t* coco_string_create(const char* str, int index, int length) {
|
||||
int len = str ? length : 0;
|
||||
wchar_t* dest = new wchar_t[len + 1];
|
||||
for (int i = 0; i < len; ++i) {
|
||||
dest[i] = (wchar_t) str[index + i];
|
||||
}
|
||||
dest[len] = 0;
|
||||
return dest;
|
||||
}
|
||||
|
||||
|
||||
char* coco_string_create_char(const wchar_t* str) {
|
||||
int len = coco_string_length(str);
|
||||
char *dest = new char[len + 1];
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
dest[i] = (char) str[i];
|
||||
}
|
||||
dest[len] = 0;
|
||||
return dest;
|
||||
}
|
||||
|
||||
char* coco_string_create_char(const wchar_t* str, int index, int length) {
|
||||
int len = coco_string_length(str);
|
||||
if (len) {
|
||||
len = length;
|
||||
}
|
||||
char *dest = new char[len + 1];
|
||||
for (int i = 0; i < len; ++i) {
|
||||
dest[i] = (char) str[index + i];
|
||||
}
|
||||
dest[len] = 0;
|
||||
return dest;
|
||||
}
|
||||
|
||||
|
||||
void coco_string_delete(char* &str) {
|
||||
delete [] str;
|
||||
str = NULL;
|
||||
}
|
||||
|
||||
|
||||
double coco_string_toDouble(const char* str)
|
||||
{
|
||||
return str ? strtod(str, NULL) : 0;
|
||||
}
|
||||
|
||||
float coco_string_toFloat(const char* str)
|
||||
{
|
||||
return str ? strtof(str, NULL) : 0;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * End of Wide Character String Routines * * * * * * * * * //
|
||||
|
||||
|
||||
Token::Token()
|
||||
:
|
||||
kind(0),
|
||||
pos(0),
|
||||
col(0),
|
||||
line(0),
|
||||
val(NULL),
|
||||
next(NULL)
|
||||
{}
|
||||
|
||||
|
||||
Token::~Token() {
|
||||
coco_string_delete(val);
|
||||
}
|
||||
|
||||
|
||||
Buffer::Buffer(FILE* s, bool isUserStream) {
|
||||
// ensure binary read on windows
|
||||
#if _MSC_VER >= 1300
|
||||
_setmode(_fileno(s), _O_BINARY);
|
||||
#endif
|
||||
stream = s; this->isUserStream = isUserStream;
|
||||
if (CanSeek()) {
|
||||
fseek(s, 0, SEEK_END);
|
||||
fileLen = ftell(s);
|
||||
fseek(s, 0, SEEK_SET);
|
||||
bufLen = (fileLen < MAX_BUFFER_LENGTH) ? fileLen : MAX_BUFFER_LENGTH;
|
||||
bufStart = INT_MAX; // nothing in the buffer so far
|
||||
}
|
||||
else {
|
||||
fileLen = bufLen = bufStart = 0;
|
||||
}
|
||||
bufCapacity = (bufLen > 0) ? bufLen : MIN_BUFFER_LENGTH;
|
||||
buf = new unsigned char[bufCapacity];
|
||||
if (fileLen > 0) SetPos(0); // setup buffer to position 0 (start)
|
||||
else bufPos = 0; // index 0 is already after the file, thus Pos = 0 is invalid
|
||||
if (bufLen == fileLen && CanSeek()) Close();
|
||||
}
|
||||
|
||||
|
||||
Buffer::Buffer(Buffer* b) {
|
||||
buf = b->buf;
|
||||
bufCapacity = b->bufCapacity;
|
||||
b->buf = NULL;
|
||||
bufStart = b->bufStart;
|
||||
bufLen = b->bufLen;
|
||||
fileLen = b->fileLen;
|
||||
bufPos = b->bufPos;
|
||||
stream = b->stream;
|
||||
b->stream = NULL;
|
||||
isUserStream = b->isUserStream;
|
||||
}
|
||||
|
||||
|
||||
Buffer::Buffer(const unsigned char* buf, int len) {
|
||||
this->buf = new unsigned char[len];
|
||||
memcpy(this->buf, buf, len*sizeof(unsigned char));
|
||||
bufStart = 0;
|
||||
bufCapacity = bufLen = len;
|
||||
fileLen = len;
|
||||
bufPos = 0;
|
||||
stream = NULL;
|
||||
}
|
||||
|
||||
|
||||
Buffer::Buffer(const char* buf, int len) {
|
||||
this->buf = new unsigned char[len];
|
||||
memcpy(this->buf, buf, len*sizeof(unsigned char));
|
||||
bufStart = 0;
|
||||
bufCapacity = bufLen = len;
|
||||
fileLen = len;
|
||||
bufPos = 0;
|
||||
stream = NULL;
|
||||
}
|
||||
|
||||
|
||||
Buffer::~Buffer() {
|
||||
Close();
|
||||
if (buf != NULL) {
|
||||
delete [] buf;
|
||||
buf = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Buffer::Close() {
|
||||
if (!isUserStream && stream != NULL) {
|
||||
fclose(stream);
|
||||
stream = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int Buffer::Read() {
|
||||
if (bufPos < bufLen) {
|
||||
return buf[bufPos++];
|
||||
} else if (GetPos() < fileLen) {
|
||||
SetPos(GetPos()); // shift buffer start to Pos
|
||||
return buf[bufPos++];
|
||||
} else if ((stream != NULL) && !CanSeek() && (ReadNextStreamChunk() > 0)) {
|
||||
return buf[bufPos++];
|
||||
} else {
|
||||
return EoF;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int Buffer::Peek() {
|
||||
int curPos = GetPos();
|
||||
int ch = Read();
|
||||
SetPos(curPos);
|
||||
return ch;
|
||||
}
|
||||
|
||||
|
||||
wchar_t* Buffer::GetString(int beg, int end) {
|
||||
int len = 0;
|
||||
wchar_t *buf = new wchar_t[end - beg];
|
||||
int oldPos = GetPos();
|
||||
SetPos(beg);
|
||||
while (GetPos() < end) buf[len++] = (wchar_t) Read();
|
||||
SetPos(oldPos);
|
||||
wchar_t *res = coco_string_create(buf, 0, len);
|
||||
coco_string_delete(buf);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
int Buffer::GetPos() {
|
||||
return bufPos + bufStart;
|
||||
}
|
||||
|
||||
|
||||
void Buffer::SetPos(int value) {
|
||||
if ((value >= fileLen) && (stream != NULL) && !CanSeek()) {
|
||||
// Wanted position is after buffer and the stream
|
||||
// is not seek-able e.g. network or console,
|
||||
// thus we have to read the stream manually till
|
||||
// the wanted position is in sight.
|
||||
while ((value >= fileLen) && (ReadNextStreamChunk() > 0))
|
||||
{}
|
||||
}
|
||||
|
||||
if ((value < 0) || (value > fileLen)) {
|
||||
wprintf(L"--- buffer out of bounds access, position: %d\n", value);
|
||||
::exit(1);
|
||||
}
|
||||
|
||||
if ((value >= bufStart) && (value < (bufStart + bufLen))) { // already in buffer
|
||||
bufPos = value - bufStart;
|
||||
} else if (stream != NULL) { // must be swapped in
|
||||
fseek(stream, value, SEEK_SET);
|
||||
bufLen = fread(buf, sizeof(unsigned char), bufCapacity, stream);
|
||||
bufStart = value; bufPos = 0;
|
||||
} else {
|
||||
bufPos = fileLen - bufStart; // make Pos return fileLen
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Read the next chunk of bytes from the stream, increases the buffer
|
||||
// if needed and updates the fields fileLen and bufLen.
|
||||
// Returns the number of bytes read.
|
||||
int Buffer::ReadNextStreamChunk() {
|
||||
int freeLen = bufCapacity - bufLen;
|
||||
if (freeLen == 0) {
|
||||
// in the case of a growing input stream
|
||||
// we can neither seek in the stream, nor can we
|
||||
// foresee the maximum length, thus we must adapt
|
||||
// the buffer size on demand.
|
||||
bufCapacity = bufLen * 2;
|
||||
unsigned char *newBuf = new unsigned char[bufCapacity];
|
||||
memcpy(newBuf, buf, bufLen*sizeof(unsigned char));
|
||||
delete [] buf;
|
||||
buf = newBuf;
|
||||
freeLen = bufLen;
|
||||
}
|
||||
int read = fread(buf + bufLen, sizeof(unsigned char), freeLen, stream);
|
||||
if (read > 0) {
|
||||
fileLen = bufLen = (bufLen + read);
|
||||
return read;
|
||||
}
|
||||
// end of stream reached
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
bool Buffer::CanSeek() {
|
||||
return (stream != NULL) && (ftell(stream) != -1);
|
||||
}
|
||||
|
||||
|
||||
int UTF8Buffer::Read() {
|
||||
int ch;
|
||||
do {
|
||||
ch = Buffer::Read();
|
||||
// until we find a utf8 start (0xxxxxxx or 11xxxxxx)
|
||||
} while ((ch >= 128) && ((ch & 0xC0) != 0xC0) && (ch != EoF));
|
||||
if (ch < 128 || ch == EoF) {
|
||||
// nothing to do, first 127 chars are the same in ascii and utf8
|
||||
// 0xxxxxxx or end of file character
|
||||
} else if ((ch & 0xF0) == 0xF0) {
|
||||
// 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
|
||||
int c1 = ch & 0x07; ch = Buffer::Read();
|
||||
int c2 = ch & 0x3F; ch = Buffer::Read();
|
||||
int c3 = ch & 0x3F; ch = Buffer::Read();
|
||||
int c4 = ch & 0x3F;
|
||||
ch = (((((c1 << 6) | c2) << 6) | c3) << 6) | c4;
|
||||
} else if ((ch & 0xE0) == 0xE0) {
|
||||
// 1110xxxx 10xxxxxx 10xxxxxx
|
||||
int c1 = ch & 0x0F; ch = Buffer::Read();
|
||||
int c2 = ch & 0x3F; ch = Buffer::Read();
|
||||
int c3 = ch & 0x3F;
|
||||
ch = (((c1 << 6) | c2) << 6) | c3;
|
||||
} else if ((ch & 0xC0) == 0xC0) {
|
||||
// 110xxxxx 10xxxxxx
|
||||
int c1 = ch & 0x1F; ch = Buffer::Read();
|
||||
int c2 = ch & 0x3F;
|
||||
ch = (c1 << 6) | c2;
|
||||
}
|
||||
return ch;
|
||||
}
|
||||
|
||||
|
||||
Scanner::Scanner(const unsigned char* buf, int len) {
|
||||
buffer = new Buffer(buf, len);
|
||||
Init();
|
||||
}
|
||||
|
||||
|
||||
Scanner::Scanner(const char* buf, int len) {
|
||||
buffer = new Buffer(buf, len);
|
||||
Init();
|
||||
}
|
||||
|
||||
|
||||
Scanner::Scanner(const wchar_t* fileName) {
|
||||
FILE* stream;
|
||||
char *chFileName = coco_string_create_char(fileName);
|
||||
if ((stream = fopen(chFileName, "rb")) == NULL) {
|
||||
wprintf(L"--- Cannot open file %ls\n", fileName);
|
||||
::exit(1);
|
||||
}
|
||||
coco_string_delete(chFileName);
|
||||
buffer = new Buffer(stream, false);
|
||||
Init();
|
||||
}
|
||||
|
||||
|
||||
Scanner::Scanner(FILE* s) {
|
||||
buffer = new Buffer(s, true);
|
||||
Init();
|
||||
}
|
||||
|
||||
|
||||
Scanner::~Scanner() {
|
||||
char* cur = (char*) firstHeap;
|
||||
|
||||
while (cur != NULL) {
|
||||
cur = *(char**) (cur + HEAP_BLOCK_SIZE);
|
||||
free(firstHeap);
|
||||
firstHeap = cur;
|
||||
}
|
||||
delete [] tval;
|
||||
delete buffer;
|
||||
}
|
||||
|
||||
|
||||
void Scanner::Init() {
|
||||
maxT = 13;
|
||||
noSym = 13;
|
||||
int i;
|
||||
for (i = 65; i <= 90; ++i) start.set(i, 1);
|
||||
for (i = 97; i <= 122; ++i) start.set(i, 1);
|
||||
for (i = 36; i <= 36; ++i) start.set(i, 5);
|
||||
start.set(45, 20);
|
||||
for (i = 48; i <= 57; ++i) start.set(i, 9);
|
||||
start.set(34, 2);
|
||||
start.set(46, 7);
|
||||
start.set(123, 14);
|
||||
start.set(125, 15);
|
||||
start.set(43, 21);
|
||||
start.set(42, 16);
|
||||
start.set(47, 17);
|
||||
start.set(40, 18);
|
||||
start.set(41, 19);
|
||||
start.set(Buffer::EoF, -1);
|
||||
|
||||
|
||||
tvalLength = 128;
|
||||
tval = new wchar_t[tvalLength]; // text of current token
|
||||
|
||||
// HEAP_BLOCK_SIZE byte heap + pointer to next heap block
|
||||
heap = malloc(HEAP_BLOCK_SIZE + sizeof(void*));
|
||||
firstHeap = heap;
|
||||
heapEnd = (void**) (((char*) heap) + HEAP_BLOCK_SIZE);
|
||||
*heapEnd = 0;
|
||||
heapTop = heap;
|
||||
if (sizeof(Token) > HEAP_BLOCK_SIZE) {
|
||||
wprintf(L"--- Too small HEAP_BLOCK_SIZE\n");
|
||||
::exit(1);
|
||||
}
|
||||
|
||||
pos = -1; line = 1; col = 0;
|
||||
oldEols = 0;
|
||||
NextCh();
|
||||
if (ch == 0xEF) { // check optional byte order mark for UTF-8
|
||||
NextCh(); int ch1 = ch;
|
||||
NextCh(); int ch2 = ch;
|
||||
if (ch1 != 0xBB || ch2 != 0xBF) {
|
||||
wprintf(L"Illegal byte order mark at start of file");
|
||||
::exit(1);
|
||||
}
|
||||
Buffer *oldBuf = buffer;
|
||||
buffer = new UTF8Buffer(buffer); col = 0;
|
||||
delete oldBuf; oldBuf = NULL;
|
||||
NextCh();
|
||||
}
|
||||
|
||||
|
||||
pt = tokens = CreateToken(); // first token is a dummy
|
||||
}
|
||||
|
||||
|
||||
void Scanner::NextCh() {
|
||||
if (oldEols > 0) {
|
||||
ch = EOL;
|
||||
oldEols--;
|
||||
}
|
||||
else {
|
||||
pos = buffer->GetPos();
|
||||
ch = buffer->Read(); col++;
|
||||
// replace isolated '\r' by '\n' in order to make
|
||||
// eol handling uniform across Windows, Unix and Mac
|
||||
if (ch == L'\r' && buffer->Peek() != L'\n') ch = EOL;
|
||||
if (ch == EOL) { line++; col = 0; }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Scanner::AddCh() {
|
||||
if (tlen >= tvalLength) {
|
||||
tvalLength *= 2;
|
||||
wchar_t *newBuf = new wchar_t[tvalLength];
|
||||
memcpy(newBuf, tval, tlen*sizeof(wchar_t));
|
||||
delete [] tval;
|
||||
tval = newBuf;
|
||||
}
|
||||
if (ch != Buffer::EoF) {
|
||||
tval[tlen++] = ch;
|
||||
NextCh();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Scanner::Comment0() {
|
||||
int level = 1, pos0 = pos, line0 = line, col0 = col;
|
||||
NextCh();
|
||||
if (ch == L'/') {
|
||||
NextCh();
|
||||
for(;;) {
|
||||
if (ch == 10) {
|
||||
level--;
|
||||
if (level == 0) { oldEols = line - line0; NextCh(); return true; }
|
||||
NextCh();
|
||||
} else if (ch == buffer->EoF) return false;
|
||||
else NextCh();
|
||||
}
|
||||
} else {
|
||||
buffer->SetPos(pos0); NextCh(); line = line0; col = col0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Scanner::Comment1() {
|
||||
int level = 1, pos0 = pos, line0 = line, col0 = col;
|
||||
NextCh();
|
||||
if (ch == L'*') {
|
||||
NextCh();
|
||||
for(;;) {
|
||||
if (ch == L'*') {
|
||||
NextCh();
|
||||
if (ch == L'/') {
|
||||
level--;
|
||||
if (level == 0) { oldEols = line - line0; NextCh(); return true; }
|
||||
NextCh();
|
||||
}
|
||||
} else if (ch == L'/') {
|
||||
NextCh();
|
||||
if (ch == L'*') {
|
||||
level++; NextCh();
|
||||
}
|
||||
} else if (ch == buffer->EoF) return false;
|
||||
else NextCh();
|
||||
}
|
||||
} else {
|
||||
buffer->SetPos(pos0); NextCh(); line = line0; col = col0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void Scanner::CreateHeapBlock() {
|
||||
void* newHeap;
|
||||
char* cur = (char*) firstHeap;
|
||||
|
||||
while (((char*) tokens < cur) || ((char*) tokens > (cur + HEAP_BLOCK_SIZE))) {
|
||||
cur = *((char**) (cur + HEAP_BLOCK_SIZE));
|
||||
free(firstHeap);
|
||||
firstHeap = cur;
|
||||
}
|
||||
|
||||
// HEAP_BLOCK_SIZE byte heap + pointer to next heap block
|
||||
newHeap = malloc(HEAP_BLOCK_SIZE + sizeof(void*));
|
||||
*heapEnd = newHeap;
|
||||
heapEnd = (void**) (((char*) newHeap) + HEAP_BLOCK_SIZE);
|
||||
*heapEnd = 0;
|
||||
heap = newHeap;
|
||||
heapTop = heap;
|
||||
}
|
||||
|
||||
|
||||
Token* Scanner::CreateToken() {
|
||||
Token *t;
|
||||
if (((char*) heapTop + (int) sizeof(Token)) >= (char*) heapEnd) {
|
||||
CreateHeapBlock();
|
||||
}
|
||||
t = (Token*) heapTop;
|
||||
heapTop = (void*) ((char*) heapTop + sizeof(Token));
|
||||
t->val = NULL;
|
||||
t->next = NULL;
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
void Scanner::AppendVal(Token *t) {
|
||||
int reqMem = (tlen + 1) * sizeof(wchar_t);
|
||||
if (((char*) heapTop + reqMem) >= (char*) heapEnd) {
|
||||
if (reqMem > HEAP_BLOCK_SIZE) {
|
||||
wprintf(L"--- Too long token value\n");
|
||||
::exit(1);
|
||||
}
|
||||
CreateHeapBlock();
|
||||
}
|
||||
t->val = (wchar_t*) heapTop;
|
||||
heapTop = (void*) ((char*) heapTop + reqMem);
|
||||
|
||||
wcsncpy(t->val, tval, tlen);
|
||||
t->val[tlen] = L'\0';
|
||||
}
|
||||
|
||||
|
||||
Token* Scanner::NextToken() {
|
||||
while (ch == ' ' ||
|
||||
ch <= 31 || (ch >= 127 && ch <= 65535)
|
||||
) NextCh();
|
||||
if ((ch == L'/' && Comment0()) || (ch == L'/' && Comment1())) return NextToken();
|
||||
t = CreateToken();
|
||||
t->pos = pos; t->col = col; t->line = line;
|
||||
int state = start.state(ch);
|
||||
tlen = 0; AddCh();
|
||||
|
||||
switch (state) {
|
||||
case -1: { t->kind = eofSym; break; } // NextCh already done
|
||||
case 0: { t->kind = noSym; break; } // NextCh already done
|
||||
case 1:
|
||||
case_1:
|
||||
if ((ch >= L'0' && ch <= L':') || (ch >= L'A' && ch <= L'Z') || ch == L'_' || (ch >= L'a' && ch <= L'z')) {AddCh(); goto case_1;}
|
||||
else {t->kind = 1; break;}
|
||||
case 2:
|
||||
case_2:
|
||||
if (ch <= 9 || (ch >= 11 && ch <= 12) || (ch >= 14 && ch <= L'!') || (ch >= L'#' && ch <= L'[') || (ch >= L']' && ch <= 65535)) {AddCh(); goto case_2;}
|
||||
else if (ch == L'"') {AddCh(); goto case_4;}
|
||||
else if (ch == 92) {AddCh(); goto case_3;}
|
||||
else {t->kind = noSym; break;}
|
||||
case 3:
|
||||
case_3:
|
||||
if ((ch >= L' ' && ch <= L'~')) {AddCh(); goto case_2;}
|
||||
else {t->kind = noSym; break;}
|
||||
case 4:
|
||||
case_4:
|
||||
{t->kind = 2; break;}
|
||||
case 5:
|
||||
if ((ch >= L'A' && ch <= L'Z') || (ch >= L'a' && ch <= L'z')) {AddCh(); goto case_6;}
|
||||
else {t->kind = noSym; break;}
|
||||
case 6:
|
||||
case_6:
|
||||
if ((ch >= L'0' && ch <= L':') || (ch >= L'A' && ch <= L'Z') || ch == L'_' || (ch >= L'a' && ch <= L'z')) {AddCh(); goto case_6;}
|
||||
else {t->kind = 3; break;}
|
||||
case 7:
|
||||
case_7:
|
||||
if ((ch >= L'0' && ch <= L'9')) {AddCh(); goto case_8;}
|
||||
else {t->kind = noSym; break;}
|
||||
case 8:
|
||||
case_8:
|
||||
if ((ch >= L'0' && ch <= L'9')) {AddCh(); goto case_8;}
|
||||
else {t->kind = 4; break;}
|
||||
case 9:
|
||||
case_9:
|
||||
if ((ch >= L'0' && ch <= L'9')) {AddCh(); goto case_9;}
|
||||
else if (ch == L'E' || ch == L'e') {AddCh(); goto case_10;}
|
||||
else if (ch == L'.') {AddCh(); goto case_13;}
|
||||
else {t->kind = 4; break;}
|
||||
case 10:
|
||||
case_10:
|
||||
if ((ch >= L'0' && ch <= L'9')) {AddCh(); goto case_12;}
|
||||
else if (ch == L'+' || ch == L'-') {AddCh(); goto case_11;}
|
||||
else {t->kind = noSym; break;}
|
||||
case 11:
|
||||
case_11:
|
||||
if ((ch >= L'0' && ch <= L'9')) {AddCh(); goto case_12;}
|
||||
else {t->kind = noSym; break;}
|
||||
case 12:
|
||||
case_12:
|
||||
if ((ch >= L'0' && ch <= L'9')) {AddCh(); goto case_12;}
|
||||
else {t->kind = 4; break;}
|
||||
case 13:
|
||||
case_13:
|
||||
if ((ch >= L'0' && ch <= L'9')) {AddCh(); goto case_13;}
|
||||
else if (ch == L'E' || ch == L'e') {AddCh(); goto case_10;}
|
||||
else {t->kind = 4; break;}
|
||||
case 14:
|
||||
{t->kind = 5; break;}
|
||||
case 15:
|
||||
{t->kind = 6; break;}
|
||||
case 16:
|
||||
{t->kind = 9; break;}
|
||||
case 17:
|
||||
{t->kind = 10; break;}
|
||||
case 18:
|
||||
{t->kind = 11; break;}
|
||||
case 19:
|
||||
{t->kind = 12; break;}
|
||||
case 20:
|
||||
if (ch == L'.') {AddCh(); goto case_7;}
|
||||
else {t->kind = 8; break;}
|
||||
case 21:
|
||||
if (ch == L'.') {AddCh(); goto case_7;}
|
||||
else {t->kind = 7; break;}
|
||||
|
||||
}
|
||||
AppendVal(t);
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
// get the next token (possibly a token already seen during peeking)
|
||||
Token* Scanner::Scan() {
|
||||
if (tokens->next == NULL) {
|
||||
return pt = tokens = NextToken();
|
||||
} else {
|
||||
pt = tokens = tokens->next;
|
||||
return tokens;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// peek for the next token, ignore pragmas
|
||||
Token* Scanner::Peek() {
|
||||
do {
|
||||
if (pt->next == NULL) {
|
||||
pt->next = NextToken();
|
||||
}
|
||||
pt = pt->next;
|
||||
} while (pt->kind > maxT); // skip pragmas
|
||||
|
||||
return pt;
|
||||
}
|
||||
|
||||
|
||||
// make sure that peeking starts at the current scan position
|
||||
void Scanner::ResetPeek() {
|
||||
pt = tokens;
|
||||
}
|
||||
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
|
||||
379
applications/test/dictionary/calcEntry/calcEntryScanner.h
Normal file
379
applications/test/dictionary/calcEntry/calcEntryScanner.h
Normal file
@ -0,0 +1,379 @@
|
||||
|
||||
|
||||
#ifndef COCO_calcEntrySCANNER_H__
|
||||
#define COCO_calcEntrySCANNER_H__
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
|
||||
// io.h and fcntl are used to ensure binary read from streams on windows
|
||||
#if _MSC_VER >= 1300
|
||||
#include <io.h>
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
|
||||
#if _MSC_VER >= 1400
|
||||
#define coco_swprintf swprintf_s
|
||||
#elif _MSC_VER >= 1300
|
||||
#define coco_swprintf _snwprintf
|
||||
#else
|
||||
// assume every other compiler knows swprintf
|
||||
#define coco_swprintf swprintf
|
||||
#endif
|
||||
|
||||
#define COCO_WCHAR_MAX 65535
|
||||
#define MIN_BUFFER_LENGTH 1024
|
||||
#define MAX_BUFFER_LENGTH (64*MIN_BUFFER_LENGTH)
|
||||
#define HEAP_BLOCK_SIZE (64*1024)
|
||||
|
||||
|
||||
namespace Foam {
|
||||
namespace functionEntries {
|
||||
namespace calcEntryInternal {
|
||||
|
||||
|
||||
|
||||
// * * * * * * * * * * Wide Character String Routines * * * * * * * * * * * //
|
||||
|
||||
//
|
||||
// string handling, wide character
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
//! Create by copying str
|
||||
wchar_t* coco_string_create(const wchar_t* str);
|
||||
|
||||
//! Create a substring of str starting at index and length characters long
|
||||
wchar_t* coco_string_create(const wchar_t* str, int index, int length);
|
||||
|
||||
//! Create an uppercase string from str
|
||||
wchar_t* coco_string_create_upper(const wchar_t* str);
|
||||
|
||||
//! Create an uppercase substring from str starting at index and length characters long
|
||||
wchar_t* coco_string_create_upper(const wchar_t* str, int index, int length);
|
||||
|
||||
//! Create a lowercase string from str
|
||||
wchar_t* coco_string_create_lower(const wchar_t* str);
|
||||
|
||||
//! Create a lowercase substring from str starting at index and length characters long
|
||||
wchar_t* coco_string_create_lower(const wchar_t* str, int index, int length);
|
||||
|
||||
//! Create a string by concatenating str1 and str2
|
||||
wchar_t* coco_string_create_append(const wchar_t* str1, const wchar_t* str2);
|
||||
|
||||
//! Create a string by concatenating a character to the end of str
|
||||
wchar_t* coco_string_create_append(const wchar_t* str, const wchar_t ch);
|
||||
|
||||
//! Free storage and nullify the argument
|
||||
void coco_string_delete(wchar_t* &str);
|
||||
|
||||
//! The length of the str, or 0 if the str is NULL
|
||||
int coco_string_length(const wchar_t* str);
|
||||
|
||||
//! Return true if the str ends with the endstr
|
||||
bool coco_string_endswith(const wchar_t* str, const wchar_t* endstr);
|
||||
|
||||
//! Return the index of the first occurrence of ch.
|
||||
// Return -1 if nothing is found.
|
||||
int coco_string_indexof(const wchar_t* str, const wchar_t ch);
|
||||
|
||||
//! Return the index of the last occurrence of ch.
|
||||
// Return -1 if nothing is found.
|
||||
int coco_string_lastindexof(const wchar_t* str, const wchar_t ch);
|
||||
|
||||
//! Append str to dest
|
||||
void coco_string_merge(wchar_t* &dest, const wchar_t* str);
|
||||
|
||||
//! Compare strings, return true if they are equal
|
||||
bool coco_string_equal(const wchar_t* str1, const wchar_t* str2);
|
||||
|
||||
//! Compare strings, return 0 if they are equal
|
||||
int coco_string_compareto(const wchar_t* str1, const wchar_t* str2);
|
||||
|
||||
//! Simple string hashing function
|
||||
int coco_string_hash(const wchar_t* str);
|
||||
|
||||
//
|
||||
// String conversions
|
||||
// ~~~~~~~~~~~~~~~~~~
|
||||
|
||||
//! Convert wide string to double
|
||||
double coco_string_toDouble(const wchar_t* str);
|
||||
|
||||
//! Convert wide string to float
|
||||
float coco_string_toFloat(const wchar_t* str);
|
||||
|
||||
//
|
||||
// String handling, byte character
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
//! Create by copying byte str
|
||||
wchar_t* coco_string_create(const char* str);
|
||||
|
||||
//! Create a substring of byte str starting at index and length characters long
|
||||
wchar_t* coco_string_create(const char* str, int index, int length);
|
||||
|
||||
//! Create a byte string by copying str
|
||||
char* coco_string_create_char(const wchar_t* str);
|
||||
|
||||
//! Create a byte substring of str starting at index and length characters long
|
||||
char* coco_string_create_char(const wchar_t* str, int index, int length);
|
||||
|
||||
//! Free storage and nullify the argument
|
||||
void coco_string_delete(char* &str);
|
||||
|
||||
|
||||
//
|
||||
// String conversions, byte character
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
//! Convert byte string to double
|
||||
double coco_string_toDouble(const char* str);
|
||||
|
||||
//! Convert byte string to float
|
||||
float coco_string_toFloat(const char* str);
|
||||
|
||||
// * * * * * * * * * End of Wide Character String Routines * * * * * * * * * //
|
||||
|
||||
|
||||
|
||||
//! Scanner Token
|
||||
class Token
|
||||
{
|
||||
public:
|
||||
int kind; //!< token kind
|
||||
int pos; //!< token position in the source text (starting at 0)
|
||||
int col; //!< token column (starting at 1)
|
||||
int line; //!< token line (starting at 1)
|
||||
wchar_t* val; //!< token value
|
||||
Token *next; //!< Peek tokens are kept in linked list
|
||||
|
||||
Token(); //!< Construct null
|
||||
~Token(); //!< Destructor - cleanup allocated val
|
||||
};
|
||||
|
||||
|
||||
//! Scanner Buffer
|
||||
//
|
||||
//! This Buffer supports the following cases:
|
||||
//! -# seekable stream (file)
|
||||
//! -# whole stream in buffer
|
||||
//! -# part of stream in buffer
|
||||
//! -# non seekable stream (network, console)
|
||||
class Buffer {
|
||||
private:
|
||||
unsigned char *buf; //!< input buffer
|
||||
int bufCapacity; //!< capacity of buf
|
||||
int bufStart; //!< position of first byte in buffer relative to input stream
|
||||
int bufLen; //!< length of buffer
|
||||
int fileLen; //!< length of input stream (may change if the stream is no file)
|
||||
int bufPos; //!< current position in buffer
|
||||
FILE* stream; //!< input stream (seekable)
|
||||
bool isUserStream; //!< was the stream opened by the user?
|
||||
|
||||
int ReadNextStreamChunk();
|
||||
bool CanSeek(); //!< true if stream can be seeked otherwise false
|
||||
|
||||
public:
|
||||
static const int EoF = COCO_WCHAR_MAX + 1;
|
||||
|
||||
Buffer(FILE*, bool isUserStream);
|
||||
Buffer(const unsigned char* buf, int len);
|
||||
Buffer(const char* buf, int len);
|
||||
Buffer(Buffer*);
|
||||
virtual ~Buffer();
|
||||
|
||||
virtual void Close();
|
||||
virtual int Read();
|
||||
virtual int Peek();
|
||||
virtual wchar_t* GetString(int beg, int end);
|
||||
virtual int GetPos();
|
||||
virtual void SetPos(int value);
|
||||
};
|
||||
|
||||
|
||||
//! A Scanner buffer that handles UTF-8 characters
|
||||
class UTF8Buffer : public Buffer {
|
||||
public:
|
||||
UTF8Buffer(Buffer* b) : Buffer(b) {}
|
||||
virtual int Read();
|
||||
};
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// StartStates
|
||||
//------------------------------------------------------------------------------
|
||||
//! maps characters to start states of tokens
|
||||
class StartStates {
|
||||
private:
|
||||
class Elem {
|
||||
public:
|
||||
int key, val;
|
||||
Elem *next;
|
||||
Elem(int key, int val) {
|
||||
this->key = key;
|
||||
this->val = val;
|
||||
next = NULL;
|
||||
}
|
||||
};
|
||||
|
||||
Elem **tab;
|
||||
|
||||
public:
|
||||
StartStates() {
|
||||
tab = new Elem*[128];
|
||||
memset(tab, 0, 128 * sizeof(Elem*));
|
||||
}
|
||||
virtual ~StartStates() {
|
||||
for (int i = 0; i < 128; ++i) {
|
||||
Elem *e = tab[i];
|
||||
while (e != NULL) {
|
||||
Elem *next = e->next;
|
||||
delete e;
|
||||
e = next;
|
||||
}
|
||||
}
|
||||
delete [] tab;
|
||||
}
|
||||
|
||||
void set(int key, int val) {
|
||||
Elem *e = new Elem(key, val);
|
||||
int k = ((unsigned int) key) % 128;
|
||||
e->next = tab[k];
|
||||
tab[k] = e;
|
||||
}
|
||||
|
||||
int state(int key) {
|
||||
Elem *e = tab[((unsigned int) key) % 128];
|
||||
while (e != NULL && e->key != key) e = e->next;
|
||||
return e == NULL ? 0 : e->val;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// KeywordMap
|
||||
//------------------------------------------------------------------------------
|
||||
//! maps strings to integers (identifiers to keyword kinds)
|
||||
class KeywordMap {
|
||||
private:
|
||||
class Elem {
|
||||
public:
|
||||
wchar_t *key;
|
||||
int val;
|
||||
Elem *next;
|
||||
Elem(const wchar_t *key, int val) {
|
||||
this->key = coco_string_create(key);
|
||||
this->val = val;
|
||||
next = NULL;
|
||||
}
|
||||
virtual ~Elem() {
|
||||
coco_string_delete(key);
|
||||
}
|
||||
};
|
||||
|
||||
Elem **tab;
|
||||
|
||||
public:
|
||||
KeywordMap() {
|
||||
tab = new Elem*[128];
|
||||
memset(tab, 0, 128 * sizeof(Elem*));
|
||||
}
|
||||
virtual ~KeywordMap() {
|
||||
for (int i = 0; i < 128; ++i) {
|
||||
Elem *e = tab[i];
|
||||
while (e != NULL) {
|
||||
Elem *next = e->next;
|
||||
delete e;
|
||||
e = next;
|
||||
}
|
||||
}
|
||||
delete [] tab;
|
||||
}
|
||||
|
||||
void set(const wchar_t *key, int val) {
|
||||
Elem *e = new Elem(key, val);
|
||||
int k = coco_string_hash(key) % 128;
|
||||
e->next = tab[k]; tab[k] = e;
|
||||
}
|
||||
|
||||
int get(const wchar_t *key, int defaultVal) {
|
||||
Elem *e = tab[coco_string_hash(key) % 128];
|
||||
while (e != NULL && !coco_string_equal(e->key, key)) e = e->next;
|
||||
return e == NULL ? defaultVal : e->val;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//! A Coco/R Scanner
|
||||
class Scanner {
|
||||
private:
|
||||
static const unsigned char EOL = '\n'; // end-of-line character
|
||||
static const int eofSym = 0; // end-of-file token id
|
||||
|
||||
void *firstHeap;
|
||||
void *heap;
|
||||
void *heapTop;
|
||||
void **heapEnd;
|
||||
|
||||
int noSym; //!< noSym gets highest number, set in Parser
|
||||
int maxT;
|
||||
int charSetSize; //!< unused?
|
||||
StartStates start;
|
||||
KeywordMap keywords;
|
||||
|
||||
Token *t; //!< current token
|
||||
wchar_t *tval; //!< text of current token
|
||||
int tvalLength; //!< length of text of current token
|
||||
int tlen; //!< length of current token
|
||||
|
||||
Token *tokens; //!< list of tokens already peeked (first token is a dummy)
|
||||
Token *pt; //!< current peek token
|
||||
|
||||
int ch; //!< current input character
|
||||
|
||||
int pos; //!< byte position of current character
|
||||
int line; //!< line number of current character
|
||||
int col; //!< column number of current character
|
||||
int oldEols; //!< EOLs that appeared in a comment;
|
||||
|
||||
void CreateHeapBlock();
|
||||
Token* CreateToken();
|
||||
void AppendVal(Token*);
|
||||
|
||||
void Init();
|
||||
void NextCh();
|
||||
void AddCh();
|
||||
bool Comment0();
|
||||
bool Comment1();
|
||||
|
||||
Token* NextToken();
|
||||
|
||||
public:
|
||||
//! scanner buffer
|
||||
Buffer *buffer;
|
||||
|
||||
//! Attach scanner to an existing character buffer
|
||||
Scanner(const unsigned char* buf, int len);
|
||||
//! Attach scanner to an existing character buffer
|
||||
Scanner(const char* buf, int len);
|
||||
//! Open a file for reading and attach scanner
|
||||
Scanner(const wchar_t* fileName);
|
||||
//! Using an existing open file handle for the scanner
|
||||
Scanner(FILE* s);
|
||||
~Scanner();
|
||||
Token* Scan();
|
||||
Token* Peek();
|
||||
void ResetPeek();
|
||||
|
||||
}; // end Scanner
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
|
||||
#endif // COCO_calcEntrySCANNER_H__
|
||||
|
||||
@ -43,70 +43,86 @@ using namespace Foam;
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
argList::noParallel();
|
||||
argList args(argc, argv);
|
||||
argList::validArgs.insert("dict .. dictN");
|
||||
argList args(argc, argv, false, true);
|
||||
|
||||
Info<< nl
|
||||
<< "FOAM_CASE=" << getEnv("FOAM_CASE") << nl
|
||||
<< "FOAM_CASENAME=" << getEnv("FOAM_CASENAME") << nl
|
||||
<< endl;
|
||||
|
||||
|
||||
if (args.additionalArgs().empty())
|
||||
{
|
||||
dictionary dict1(IFstream("testDict")());
|
||||
Info<< "dict1: " << dict1 << nl
|
||||
<< "toc: " << dict1.toc() << nl
|
||||
<< "keys: " << dict1.keys() << nl
|
||||
<< "patterns: " << dict1.keys(true) << endl;
|
||||
{
|
||||
dictionary dict1(IFstream("testDict")());
|
||||
Info<< "dict1: " << dict1 << nl
|
||||
<< "toc: " << dict1.toc() << nl
|
||||
<< "keys: " << dict1.keys() << nl
|
||||
<< "patterns: " << dict1.keys(true) << endl;
|
||||
|
||||
dictionary dict2(dict1.xfer());
|
||||
dictionary dict2(dict1.xfer());
|
||||
|
||||
Info<< "dict1.toc(): " << dict1.name() << " " << dict1.toc() << nl
|
||||
<< "dict2.toc(): " << dict2.name() << " " << dict2.toc() << endl;
|
||||
Info<< "dict1.toc(): " << dict1.name() << " " << dict1.toc() << nl
|
||||
<< "dict2.toc(): " << dict2.name() << " " << dict2.toc() << endl;
|
||||
|
||||
// copy back
|
||||
dict1 = dict2;
|
||||
Info<< "dict1.toc(): " << dict1.name() << " " << dict1.toc() << endl;
|
||||
// copy back
|
||||
dict1 = dict2;
|
||||
Info<< "dict1.toc(): " << dict1.name() << " " << dict1.toc() << endl;
|
||||
|
||||
dictionary dict3(dict2.subDictPtr("boundaryField"));
|
||||
dictionary dict4(dict2.subDictPtr("NONEXISTENT"));
|
||||
dictionary dict3(dict2.subDictPtr("boundaryField"));
|
||||
dictionary dict4(dict2.subDictPtr("NONEXISTENT"));
|
||||
|
||||
Info<< "dictionary construct from pointer" << nl
|
||||
<< "ok = " << dict3.name() << " " << dict3.toc() << nl
|
||||
<< "no = " << dict4.name() << " " << dict4.toc() << endl;
|
||||
Info<< "dictionary construct from pointer" << nl
|
||||
<< "ok = " << dict3.name() << " " << dict3.toc() << nl
|
||||
<< "no = " << dict4.name() << " " << dict4.toc() << endl;
|
||||
}
|
||||
|
||||
|
||||
IOobject::writeDivider(Info);
|
||||
|
||||
{
|
||||
dictionary dict(IFstream("testDictRegex")());
|
||||
dict.add(keyType("fooba[rz]", true), "anything");
|
||||
|
||||
Info<< "dict:" << dict << nl
|
||||
<< "toc: " << dict.toc() << nl
|
||||
<< "keys: " << dict.keys() << nl
|
||||
<< "patterns: " << dict.keys(true) << endl;
|
||||
|
||||
Info<< "Pattern find \"abc\" in top directory : "
|
||||
<< dict.lookup("abc") << endl;
|
||||
Info<< "Pattern find \"abc\" in sub directory : "
|
||||
<< dict.subDict("someDict").lookup("abc")
|
||||
<< endl;
|
||||
Info<< "Recursive pattern find \"def\" in sub directory : "
|
||||
<< dict.subDict("someDict").lookup("def", true)
|
||||
<< endl;
|
||||
Info<< "Recursive pattern find \"foo\" in sub directory : "
|
||||
<< dict.subDict("someDict").lookup("foo", true)
|
||||
<< endl;
|
||||
Info<< "Recursive pattern find \"fooz\" in sub directory : "
|
||||
<< dict.subDict("someDict").lookup("fooz", true)
|
||||
<< endl;
|
||||
Info<< "Recursive pattern find \"bar\" in sub directory : "
|
||||
<< dict.subDict("someDict").lookup("bar", true)
|
||||
<< endl;
|
||||
Info<< "Recursive pattern find \"xxx\" in sub directory : "
|
||||
<< dict.subDict("someDict").lookup("xxx", true)
|
||||
<< endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
IOobject::writeDivider(Info);
|
||||
|
||||
else
|
||||
{
|
||||
dictionary dict(IFstream("testDictRegex")());
|
||||
dict.add(keyType("fooba[rz]", true), "anything");
|
||||
IOobject::writeDivider(Info);
|
||||
forAll(args.additionalArgs(), argI)
|
||||
{
|
||||
const string& dictFile = args.additionalArgs()[argI];
|
||||
IFstream is(dictFile);
|
||||
|
||||
Info<< "dict:" << dict << nl
|
||||
<< "toc: " << dict.toc() << nl
|
||||
<< "keys: " << dict.keys() << nl
|
||||
<< "patterns: " << dict.keys(true) << endl;
|
||||
dictionary dict(is);
|
||||
|
||||
Info<< "Pattern find \"abc\" in top directory : "
|
||||
<< dict.lookup("abc") << endl;
|
||||
Info<< "Pattern find \"abc\" in sub directory : "
|
||||
<< dict.subDict("someDict").lookup("abc")
|
||||
<< endl;
|
||||
Info<< "Recursive pattern find \"def\" in sub directory : "
|
||||
<< dict.subDict("someDict").lookup("def", true)
|
||||
<< endl;
|
||||
Info<< "Recursive pattern find \"foo\" in sub directory : "
|
||||
<< dict.subDict("someDict").lookup("foo", true)
|
||||
<< endl;
|
||||
Info<< "Recursive pattern find \"fooz\" in sub directory : "
|
||||
<< dict.subDict("someDict").lookup("fooz", true)
|
||||
<< endl;
|
||||
Info<< "Recursive pattern find \"bar\" in sub directory : "
|
||||
<< dict.subDict("someDict").lookup("bar", true)
|
||||
<< endl;
|
||||
Info<< "Recursive pattern find \"xxx\" in sub directory : "
|
||||
<< dict.subDict("someDict").lookup("xxx", true)
|
||||
<< endl;
|
||||
Info<< dict << endl;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
33
applications/test/dictionary/testDictCalc
Normal file
33
applications/test/dictionary/testDictCalc
Normal file
@ -0,0 +1,33 @@
|
||||
/*--------------------------------*- C++ -*----------------------------------*\
|
||||
| ========= | |
|
||||
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
|
||||
| \\ / O peration | Version: Any |
|
||||
| \\ / A nd | Web: www.OpenFOAM.org |
|
||||
| \\/ M anipulation | |
|
||||
\*---------------------------------------------------------------------------*/
|
||||
FoamFile
|
||||
{
|
||||
version 2.0;
|
||||
format ascii;
|
||||
class dictionary;
|
||||
object testDictTest;
|
||||
}
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
x 10 /* what ever */ 20;
|
||||
y 20;
|
||||
// z #test{ // this
|
||||
// 123 - 456
|
||||
// // comments // are
|
||||
// /* stripped
|
||||
// * 10
|
||||
// * {}
|
||||
// */
|
||||
// + 1 /*100 */ 10
|
||||
// };
|
||||
|
||||
p #test{ 1 + 2 + 10 * 15 + $x - $y };
|
||||
|
||||
foo 30;
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
@ -67,9 +67,15 @@ int main(int argc, char *argv[])
|
||||
while (is.good())
|
||||
{
|
||||
token tok(is);
|
||||
// char ch;
|
||||
// is.get(ch);
|
||||
// is.putback(ch);
|
||||
int lookahead = is.peek();
|
||||
|
||||
if (count == 0)
|
||||
{
|
||||
Info<< "token: " << tok.info() << endl;
|
||||
Info<< "token: " << tok.info();
|
||||
Info<< " lookahead: '" << char(lookahead) << "'" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -42,7 +42,7 @@ Usage
|
||||
@param -region \<name\> \n
|
||||
Specify an alternative mesh region.
|
||||
|
||||
@param -dict \<dictionary\> \n
|
||||
@param -dict \<filename\> \n
|
||||
Specify an alternative dictionary for the block mesh description.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
@ -80,7 +80,7 @@ int main(int argc, char *argv[])
|
||||
argList::addOption
|
||||
(
|
||||
"dict",
|
||||
"NAME",
|
||||
"file",
|
||||
"specify an alternative dictionary for the blockMesh description"
|
||||
);
|
||||
|
||||
|
||||
@ -142,14 +142,45 @@ void rotateFields(const argList& args, const Time& runTime, const tensor& T)
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
# include "addRegionOption.H"
|
||||
argList::addOption("translate", "vector");
|
||||
argList::addOption("rotate", "(vector vector)");
|
||||
argList::addOption("rollPitchYaw", "(roll pitch yaw)");
|
||||
argList::addOption("yawPitchRoll", "(yaw pitch roll)");
|
||||
argList::addBoolOption("rotateFields");
|
||||
argList::addOption("scale", "vector");
|
||||
argList::addOption
|
||||
(
|
||||
"translate",
|
||||
"vector",
|
||||
"translate by the specified <vector> - eg, '(1 0 0)'"
|
||||
);
|
||||
argList::addOption
|
||||
(
|
||||
"rotate",
|
||||
"(vectorA vectorB)",
|
||||
"transform in terms of a rotation between <vectorA> and <vectorB> "
|
||||
"- eg, '( (1 0 0) (0 0 1) )'"
|
||||
);
|
||||
argList::addOption
|
||||
(
|
||||
"rollPitchYaw",
|
||||
"vector",
|
||||
"transform in terms of '( roll pitch yaw )' in degrees"
|
||||
);
|
||||
argList::addOption
|
||||
(
|
||||
"yawPitchRoll",
|
||||
"vector",
|
||||
"transform in terms of '( yaw pitch roll )' in degrees"
|
||||
);
|
||||
argList::addBoolOption
|
||||
(
|
||||
"rotateFields",
|
||||
"read and transform vector and tensor fields too"
|
||||
);
|
||||
argList::addOption
|
||||
(
|
||||
"scale",
|
||||
"vector",
|
||||
"scale by the specified amount - eg, '(0.001 0.001 0.001)' for a "
|
||||
"uniform [mm] to [m] scaling"
|
||||
);
|
||||
|
||||
# include "addRegionOption.H"
|
||||
# include "setRootCase.H"
|
||||
# include "createTime.H"
|
||||
|
||||
|
||||
@ -101,13 +101,13 @@ int main(int argc, char *argv[])
|
||||
argList::addBoolOption
|
||||
(
|
||||
"noPatches",
|
||||
"Suppress writing any patches"
|
||||
"suppress writing any patches"
|
||||
);
|
||||
argList::addOption
|
||||
(
|
||||
"patches",
|
||||
"patchList",
|
||||
"Specify particular patches to write. "
|
||||
"wordList",
|
||||
"specify particular patches to write - eg '(inlet outlet)'. "
|
||||
"An empty list suppresses writing the internalMesh."
|
||||
);
|
||||
|
||||
|
||||
@ -94,7 +94,7 @@ int main(int argc, char *argv[])
|
||||
argList::addBoolOption
|
||||
(
|
||||
"noMesh",
|
||||
"Suppress writing the geometry. "
|
||||
"suppress writing the geometry. "
|
||||
"Can be useful for converting partial results for a static geometry"
|
||||
);
|
||||
|
||||
|
||||
@ -241,20 +241,46 @@ int main(int argc, char *argv[])
|
||||
|
||||
# include "addRegionOption.H"
|
||||
|
||||
argList::addOption("fields", "fields");
|
||||
argList::addOption("cellSet", "cellSet name");
|
||||
argList::addOption("faceSet", "faceSet name");
|
||||
argList::addOption("pointSet", "pointSet name");
|
||||
argList::addBoolOption("ascii");
|
||||
argList::addOption
|
||||
(
|
||||
"fields", "wordList",
|
||||
"only convert the specified fields - eg '(p T U)'"
|
||||
);
|
||||
argList::addOption
|
||||
(
|
||||
"cellSet",
|
||||
"name",
|
||||
"convert a mesh subset corresponding to the specified cellSet"
|
||||
);
|
||||
argList::addOption("faceSet", "name");
|
||||
argList::addOption("pointSet", "name");
|
||||
argList::addBoolOption
|
||||
(
|
||||
"ascii",
|
||||
"write in ASCII format instead of binary"
|
||||
);
|
||||
argList::addBoolOption("surfaceFields");
|
||||
argList::addBoolOption("nearCellValue");
|
||||
argList::addBoolOption("noInternal");
|
||||
argList::addBoolOption("noPointValues");
|
||||
argList::addBoolOption("allPatches");
|
||||
argList::addOption("excludePatches","patches to exclude");
|
||||
argList::addOption
|
||||
(
|
||||
"excludePatches",
|
||||
"wordReList",
|
||||
"a list of patches to exclude - eg '( inlet \".*Wall\" )' "
|
||||
);
|
||||
argList::addBoolOption("noFaceZones");
|
||||
argList::addBoolOption("noLinks");
|
||||
argList::addBoolOption("useTimeName");
|
||||
argList::addBoolOption
|
||||
(
|
||||
"noLinks",
|
||||
"don't link processor VTK files - parallel only"
|
||||
);
|
||||
argList::addBoolOption
|
||||
(
|
||||
"useTimeName",
|
||||
"use the time name instead of the time index when naming the files"
|
||||
);
|
||||
|
||||
# include "setRootCase.H"
|
||||
# include "createTime.H"
|
||||
|
||||
@ -21,7 +21,7 @@ surfaceFind
|
||||
- Finds nearest vertex and face to given point.
|
||||
|
||||
surfaceMeshTriangulate
|
||||
- Triangulate external facses of mesh and write as surface.
|
||||
- Triangulate external faces of mesh and write as surface.
|
||||
|
||||
surfacePointMerge
|
||||
- Explicit point merge of surface.
|
||||
|
||||
@ -26,266 +26,85 @@ Application
|
||||
surfaceFeatureConvert
|
||||
|
||||
Description
|
||||
Extracts and writes surface features to file
|
||||
Convert between edgeMesh formats
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "featureEdgeMesh.H"
|
||||
#include "argList.H"
|
||||
#include "Time.H"
|
||||
#include "IFstream.H"
|
||||
#include "IStringStream.H"
|
||||
#include "OFstream.H"
|
||||
#include "Map.H"
|
||||
|
||||
#include "edgeMesh.H"
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
void readNASEdges
|
||||
(
|
||||
const fileName& inFileName,
|
||||
pointField& allPoints,
|
||||
edgeList& allEdges
|
||||
)
|
||||
{
|
||||
IFstream is(inFileName);
|
||||
|
||||
if (!is.good())
|
||||
{
|
||||
FatalErrorIn("readNASEdges")
|
||||
<< "Cannot read file " << inFileName
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
// coordinates of point
|
||||
DynamicList<point> points;
|
||||
// Nastran index of point
|
||||
DynamicList<label> pointIndices;
|
||||
|
||||
// beams
|
||||
DynamicList<edge> edges;
|
||||
DynamicList<label> edgeIndices;
|
||||
|
||||
|
||||
while (is.good())
|
||||
{
|
||||
string line;
|
||||
is.getLine(line);
|
||||
|
||||
if (line.empty() || line[0] == '$')
|
||||
{
|
||||
// Skip empty and comment
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check if character 72 is continuation
|
||||
if (line.size() > 72 && line[72] == '+')
|
||||
{
|
||||
line = line.substr(0, 72);
|
||||
|
||||
while (true)
|
||||
{
|
||||
string buf;
|
||||
is.getLine(buf);
|
||||
|
||||
if (buf.size() > 72 && buf[72] == '+')
|
||||
{
|
||||
line += buf.substr(8, 64);
|
||||
}
|
||||
else
|
||||
{
|
||||
line += buf.substr(8, buf.size()-8);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Read first word
|
||||
IStringStream lineStream(line);
|
||||
word cmd;
|
||||
lineStream >> cmd;
|
||||
|
||||
if (cmd == "GRID")
|
||||
{
|
||||
label index;
|
||||
lineStream >> index;
|
||||
pointIndices.append(index);
|
||||
|
||||
scalar x = readScalar(IStringStream(line.substr(24, 8))());
|
||||
scalar y = readScalar(IStringStream(line.substr(32, 8))());
|
||||
scalar z = readScalar(IStringStream(line.substr(40, 8))());
|
||||
points.append(point(x, y, z));
|
||||
}
|
||||
else if (cmd == "CBEAM")
|
||||
{
|
||||
// Read shell type since gives patchnames.
|
||||
label index, group, v0, v1;
|
||||
lineStream >> index >> group >> v0 >> v1;
|
||||
|
||||
edgeIndices.append(index);
|
||||
edges.append(edge(v0, v1));
|
||||
}
|
||||
}
|
||||
|
||||
points.shrink();
|
||||
pointIndices.shrink();
|
||||
edges.shrink();
|
||||
edgeIndices.shrink();
|
||||
|
||||
Pout<< "Read from " << inFileName
|
||||
<< " edges:" << edges.size() << " points:" << points.size()
|
||||
<< endl;
|
||||
|
||||
{
|
||||
// Build inverse mapping (index to point)
|
||||
Map<label> indexToPoint(2*pointIndices.size());
|
||||
forAll(pointIndices, i)
|
||||
{
|
||||
indexToPoint.insert(pointIndices[i], i);
|
||||
}
|
||||
|
||||
// Relabel edges
|
||||
forAll(edges, i)
|
||||
{
|
||||
edge& e = edges[i];
|
||||
e[0] = indexToPoint[e[0]];
|
||||
e[1] = indexToPoint[e[1]];
|
||||
}
|
||||
}
|
||||
|
||||
allPoints.transfer(points);
|
||||
allEdges.transfer(edges);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void write
|
||||
(
|
||||
const Time& runTime,
|
||||
const fileName& inFileName,
|
||||
const fileName& outFileName,
|
||||
const edgeMesh& eMesh
|
||||
)
|
||||
{
|
||||
if (outFileName.ext() == "eMesh")
|
||||
{
|
||||
featureEdgeMesh fem
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
outFileName, // name
|
||||
runTime.constant(), // instance
|
||||
runTime, // registry
|
||||
IOobject::NO_READ,
|
||||
IOobject::AUTO_WRITE,
|
||||
false
|
||||
),
|
||||
eMesh.points(),
|
||||
eMesh.edges()
|
||||
);
|
||||
|
||||
Pout<< "Writing feature edge mesh to " << fem.objectPath()
|
||||
<< endl;
|
||||
|
||||
fem.write();
|
||||
}
|
||||
else if (outFileName.ext() == "vtk")
|
||||
{
|
||||
OFstream str(outFileName);
|
||||
|
||||
str << "# vtk DataFile Version 2.0" << nl
|
||||
<< "featureEdgeMesh " << inFileName << nl
|
||||
<< "ASCII" << nl
|
||||
<< "DATASET POLYDATA" << nl;
|
||||
|
||||
str << "POINTS " << eMesh.points().size() << " float" << nl;
|
||||
forAll(eMesh.points(), pointI)
|
||||
{
|
||||
const point& pt = eMesh.points()[pointI];
|
||||
|
||||
str << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl;
|
||||
}
|
||||
|
||||
str << "LINES " << eMesh.edges().size() << ' '
|
||||
<< 3*eMesh.edges().size() << nl;
|
||||
forAll(eMesh.edges(), edgeI)
|
||||
{
|
||||
const edge& e = eMesh.edges()[edgeI];
|
||||
|
||||
str << "2 " << e[0] << ' ' << e[1] << nl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
FatalErrorIn("write")
|
||||
<< "Supported output formats: .eMesh, .vtk"
|
||||
<< exit(FatalError);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Main program:
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
argList::addNote
|
||||
(
|
||||
"Convert between edgeMesh formats"
|
||||
);
|
||||
argList::noParallel();
|
||||
argList::validArgs.append("input file");
|
||||
argList::validArgs.append("output file");
|
||||
# include "setRootCase.H"
|
||||
# include "createTime.H"
|
||||
argList::validArgs.append("inputFile");
|
||||
argList::validArgs.append("outputFile");
|
||||
argList::addOption
|
||||
(
|
||||
"scale",
|
||||
"factor",
|
||||
"specify a scaling factor for the points"
|
||||
);
|
||||
|
||||
const fileName inFileName(args.additionalArgs()[0]);
|
||||
const word outFileName(args.additionalArgs()[1]);
|
||||
argList args(argc, argv);
|
||||
Time runTime(args.rootPath(), args.caseName());
|
||||
const stringList& params = args.additionalArgs();
|
||||
|
||||
Pout<< "Input features file : " << inFileName << nl
|
||||
<< "Output features file : " << outFileName << nl
|
||||
<< endl;
|
||||
const fileName importName(params[0]);
|
||||
const fileName exportName(params[1]);
|
||||
|
||||
|
||||
// Read
|
||||
// ~~~~
|
||||
|
||||
if (inFileName.ext() == "nas")
|
||||
{
|
||||
pointField points;
|
||||
edgeList edges;
|
||||
readNASEdges(inFileName, points, edges);
|
||||
|
||||
edgeMesh eMesh(points, edges);
|
||||
|
||||
write(runTime, inFileName, outFileName, eMesh);
|
||||
}
|
||||
else if (inFileName.ext() == "eMesh")
|
||||
{
|
||||
featureEdgeMesh fem
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
inFileName, // name
|
||||
runTime.constant(), // instance
|
||||
runTime, // registry
|
||||
IOobject::MUST_READ,
|
||||
IOobject::AUTO_WRITE,
|
||||
false
|
||||
)
|
||||
);
|
||||
|
||||
Pout<< "Read from " << inFileName
|
||||
<< " edges:" << fem.edges().size()
|
||||
<< " points:" << fem.points().size()
|
||||
<< endl;
|
||||
|
||||
write(runTime, inFileName, outFileName, fem);
|
||||
}
|
||||
else
|
||||
// disable inplace editing
|
||||
if (importName == exportName)
|
||||
{
|
||||
FatalErrorIn(args.executable())
|
||||
<< "Can only handle NASTRAN data formats (.nas extension)."
|
||||
<< "Output file " << exportName << " would overwrite input file."
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
Pout<< "End\n" << endl;
|
||||
// check that reading/writing is supported
|
||||
if
|
||||
(
|
||||
!edgeMesh::canReadType(importName.ext(), true)
|
||||
|| !edgeMesh::canWriteType(exportName.ext(), true)
|
||||
)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
edgeMesh mesh(importName);
|
||||
|
||||
Info<< "\nRead edgeMesh " << importName << nl;
|
||||
mesh.writeStats(Info);
|
||||
Info<< nl
|
||||
<< "\nwriting " << exportName;
|
||||
|
||||
scalar scaleFactor = 0;
|
||||
if (args.optionReadIfPresent("scale", scaleFactor) && scaleFactor > 0)
|
||||
{
|
||||
Info<< " with scaling " << scaleFactor << endl;
|
||||
mesh.scalePoints(scaleFactor);
|
||||
}
|
||||
else
|
||||
{
|
||||
Info<< " without scaling" << endl;
|
||||
}
|
||||
|
||||
mesh.write(exportName);
|
||||
mesh.writeStats(Info);
|
||||
Info<< endl;
|
||||
|
||||
Info<< "\nEnd\n" << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -199,7 +199,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
// Trim away small groups of features
|
||||
if (minLen > 0 || minLen > 0)
|
||||
if (minElem > 0 || minLen > 0)
|
||||
{
|
||||
set.trimFeatures(minLen, minElem);
|
||||
Pout<< endl << "Removed small features" << endl;
|
||||
|
||||
@ -23,8 +23,8 @@ License
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Description
|
||||
Transform (scale/rotate) a surface. Like transformPoints but then for
|
||||
surfaces.
|
||||
Transform (scale/rotate) a surface.
|
||||
Like transformPoints but for surfaces.
|
||||
|
||||
The rollPitchYaw option takes three angles (degrees):
|
||||
- roll (rotation about x) followed by
|
||||
@ -54,16 +54,47 @@ using namespace Foam::constant::mathematical;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
argList::addNote
|
||||
(
|
||||
"Transform (scale/rotate) a surface. "
|
||||
"Like transformPoints but for surfaces."
|
||||
);
|
||||
argList::noParallel();
|
||||
argList::validArgs.clear();
|
||||
|
||||
argList::validArgs.append("surface file");
|
||||
argList::validArgs.append("output surface file");
|
||||
argList::addOption("translate", "vector");
|
||||
argList::addOption("rotate", "(vector vector)");
|
||||
argList::addOption("scale", "vector");
|
||||
argList::addOption("rollPitchYaw", "(roll pitch yaw)");
|
||||
argList::addOption("yawPitchRoll", "(yaw pitch roll)");
|
||||
argList::addOption
|
||||
(
|
||||
"translate",
|
||||
"vector",
|
||||
"translate by the specified <vector> - eg, '(1 0 0)'"
|
||||
);
|
||||
argList::addOption
|
||||
(
|
||||
"rotate",
|
||||
"(vectorA vectorB)",
|
||||
"transform in terms of a rotation between <vectorA> and <vectorB> "
|
||||
"- eg, '( (1 0 0) (0 0 1) )'"
|
||||
);
|
||||
argList::addOption
|
||||
(
|
||||
"scale",
|
||||
"vector",
|
||||
"scale by the specified amount - eg, '(0.001 0.001 0.001)' for a "
|
||||
"uniform [mm] to [m] scaling"
|
||||
);
|
||||
argList::addOption
|
||||
(
|
||||
"rollPitchYaw",
|
||||
"vector",
|
||||
"transform in terms of '( roll pitch yaw )' in degrees"
|
||||
);
|
||||
argList::addOption
|
||||
(
|
||||
"yawPitchRoll",
|
||||
"vector",
|
||||
"transform in terms of '( yaw pitch roll )' in degrees"
|
||||
);
|
||||
argList args(argc, argv);
|
||||
|
||||
fileName surfFileName(args.additionalArgs()[0]);
|
||||
|
||||
@ -132,7 +132,7 @@ unset MPI_ARCH_PATH
|
||||
|
||||
switch ("$WM_MPLIB")
|
||||
case OPENMPI:
|
||||
set mpi_version=openmpi-1.3.4
|
||||
set mpi_version=openmpi-1.4
|
||||
setenv MPI_HOME $WM_THIRD_PARTY_DIR/$mpi_version
|
||||
setenv MPI_ARCH_PATH $MPI_HOME/platforms/$WM_OPTIONS
|
||||
|
||||
|
||||
@ -163,7 +163,7 @@ unset MPI_ARCH_PATH
|
||||
|
||||
case "$WM_MPLIB" in
|
||||
OPENMPI)
|
||||
mpi_version=openmpi-1.3.4
|
||||
mpi_version=openmpi-1.4
|
||||
export MPI_HOME=$WM_THIRD_PARTY_DIR/$mpi_version
|
||||
export MPI_ARCH_PATH=$MPI_HOME/platforms/$WM_OPTIONS
|
||||
|
||||
|
||||
@ -22,9 +22,9 @@ wmake libso OpenFOAM
|
||||
|
||||
wmake libso lagrangian/basic
|
||||
|
||||
wmake libso triSurface
|
||||
wmake libso edgeMesh
|
||||
wmake libso surfMesh
|
||||
wmake libso triSurface
|
||||
|
||||
# Decomposition methods needed by meshTools
|
||||
wmake libso parallel/decompositionMethods
|
||||
|
||||
@ -10,7 +10,9 @@ $(bools)/bool/boolIO.C
|
||||
$(bools)/Switch/Switch.C
|
||||
$(bools)/Switch/SwitchIO.C
|
||||
|
||||
primitives/char/charIO.C
|
||||
chars = primitives/chars
|
||||
$(chars)/char/charIO.C
|
||||
$(chars)/wchar/wcharIO.C
|
||||
|
||||
ints = primitives/ints
|
||||
$(ints)/int/intIO.C
|
||||
|
||||
@ -25,35 +25,9 @@ License
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "Istream.H"
|
||||
#include "bool.H"
|
||||
#include "token.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
// Set t to the put back token if there is one and return true,
|
||||
// otherwise return false
|
||||
bool Foam::Istream::getBack(token& t)
|
||||
{
|
||||
if (bad())
|
||||
{
|
||||
FatalIOErrorIn("void Istream::getBack(token&)", *this)
|
||||
<< "Attempt to get back from bad stream"
|
||||
<< exit(FatalIOError);
|
||||
|
||||
return false;
|
||||
}
|
||||
else if (putBack_)
|
||||
{
|
||||
t = putBackToken_;
|
||||
putBack_ = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Keep the put back token
|
||||
void Foam::Istream::putBack(const token& t)
|
||||
{
|
||||
if (bad())
|
||||
@ -76,6 +50,40 @@ void Foam::Istream::putBack(const token& t)
|
||||
}
|
||||
|
||||
|
||||
bool Foam::Istream::getBack(token& t)
|
||||
{
|
||||
if (bad())
|
||||
{
|
||||
FatalIOErrorIn("void Istream::getBack(token&)", *this)
|
||||
<< "Attempt to get back from bad stream"
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
else if (putBack_)
|
||||
{
|
||||
t = putBackToken_;
|
||||
putBack_ = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::Istream::peekBack(token& t)
|
||||
{
|
||||
if (putBack_)
|
||||
{
|
||||
t = putBackToken_;
|
||||
}
|
||||
else
|
||||
{
|
||||
t = token::undefinedToken;
|
||||
}
|
||||
|
||||
return putBack_;
|
||||
}
|
||||
|
||||
|
||||
// Functions for reading object delimiters ( ... )
|
||||
|
||||
Foam::Istream& Foam::Istream::readBegin(const char* funcName)
|
||||
|
||||
@ -62,7 +62,7 @@ class Istream
|
||||
{
|
||||
// Private data
|
||||
|
||||
//- Has a token been put back on the stream
|
||||
//- Has a token been put back on the stream?
|
||||
bool putBack_;
|
||||
|
||||
//- The last token put back on the stream
|
||||
@ -97,12 +97,19 @@ public:
|
||||
// Read functions
|
||||
|
||||
//- Put back token
|
||||
// Only a single put back is permitted
|
||||
void putBack(const token&);
|
||||
|
||||
//- Get the put back token
|
||||
//- Get the put back token if there is one and return true.
|
||||
// Return false if no put back token is available.
|
||||
bool getBack(token&);
|
||||
|
||||
//- Return next token from stream
|
||||
//- Peek at the put back token without removing it.
|
||||
// Returns false if no put back token is available and set the
|
||||
// token to undefined.
|
||||
bool peekBack(token&);
|
||||
|
||||
//- Return next token from stream
|
||||
virtual Istream& read(token&) = 0;
|
||||
|
||||
//- Read a character
|
||||
|
||||
@ -137,6 +137,12 @@ public:
|
||||
//- Raw, low-level get character function.
|
||||
inline ISstream& get(char&);
|
||||
|
||||
//- Raw, low-level peek function.
|
||||
// Does not remove the character from the stream.
|
||||
// Returns the next character in the stream or EOF if the
|
||||
// end of file is read.
|
||||
inline int peek();
|
||||
|
||||
//- Raw, low-level getline into a string function.
|
||||
inline ISstream& getLine(string&);
|
||||
|
||||
|
||||
@ -69,6 +69,12 @@ inline Foam::ISstream& Foam::ISstream::get(char& c)
|
||||
}
|
||||
|
||||
|
||||
inline int Foam::ISstream::peek()
|
||||
{
|
||||
return is_.peek();
|
||||
}
|
||||
|
||||
|
||||
inline Foam::ISstream& Foam::ISstream::getLine(string& s)
|
||||
{
|
||||
getline(is_, s);
|
||||
|
||||
@ -79,7 +79,7 @@ Foam::Istream& Foam::ITstream::read(token& t)
|
||||
{
|
||||
FatalIOErrorIn
|
||||
(
|
||||
"ITstream::read(token& t)",
|
||||
"ITstream::read(token&)",
|
||||
*this
|
||||
) << "attempt to read beyond EOF"
|
||||
<< exit(FatalIOError);
|
||||
@ -91,17 +91,16 @@ Foam::Istream& Foam::ITstream::read(token& t)
|
||||
setEof();
|
||||
}
|
||||
|
||||
t = token::undefinedToken;
|
||||
|
||||
if (size())
|
||||
{
|
||||
token::undefinedToken.lineNumber()
|
||||
= operator[](size() - 1).lineNumber();
|
||||
t.lineNumber() = tokenList::last().lineNumber();
|
||||
}
|
||||
else
|
||||
{
|
||||
token::undefinedToken.lineNumber() = lineNumber();
|
||||
t.lineNumber() = lineNumber();
|
||||
}
|
||||
|
||||
t = token::undefinedToken;
|
||||
}
|
||||
|
||||
return *this;
|
||||
@ -110,7 +109,7 @@ Foam::Istream& Foam::ITstream::read(token& t)
|
||||
|
||||
Foam::Istream& Foam::ITstream::read(char&)
|
||||
{
|
||||
notImplemented("Istream& ITstream::read(char& c)");
|
||||
notImplemented("Istream& ITstream::read(char&)");
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -157,14 +156,13 @@ Foam::Istream& Foam::ITstream::read(char*, std::streamsize)
|
||||
}
|
||||
|
||||
|
||||
// Rewind the token stream so that it may be read again
|
||||
Foam::Istream& Foam::ITstream::rewind()
|
||||
{
|
||||
tokenIndex_ = 0;
|
||||
|
||||
if (size())
|
||||
{
|
||||
lineNumber_ = operator[](0).lineNumber();
|
||||
lineNumber_ = tokenList::first().lineNumber();
|
||||
}
|
||||
|
||||
setGood();
|
||||
|
||||
@ -70,7 +70,26 @@ public:
|
||||
ITstream
|
||||
(
|
||||
const string& name,
|
||||
const tokenList& tokens,
|
||||
const UList<token>& tokens,
|
||||
streamFormat format=ASCII,
|
||||
versionNumber version=currentVersion
|
||||
)
|
||||
:
|
||||
Istream(format, version),
|
||||
tokenList(tokens),
|
||||
name_(name),
|
||||
tokenIndex_(0)
|
||||
{
|
||||
setOpened();
|
||||
setGood();
|
||||
}
|
||||
|
||||
|
||||
//- Construct from components, transferring the tokens
|
||||
ITstream
|
||||
(
|
||||
const string& name,
|
||||
const Xfer< List<token> >& tokens,
|
||||
streamFormat format=ASCII,
|
||||
versionNumber version=currentVersion
|
||||
)
|
||||
@ -98,8 +117,7 @@ public:
|
||||
}
|
||||
|
||||
|
||||
// Destructor
|
||||
|
||||
//- Destructor
|
||||
virtual ~ITstream()
|
||||
{}
|
||||
|
||||
|
||||
@ -92,7 +92,7 @@ public:
|
||||
const dictionary& dict
|
||||
);
|
||||
|
||||
//- Construct as copy for the given parentDict
|
||||
//- Construct as copy for the given parent dictionary
|
||||
dictionaryEntry
|
||||
(
|
||||
const dictionary& parentDict,
|
||||
|
||||
@ -79,7 +79,7 @@ void Foam::dictionaryEntry::write(Ostream& os) const
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Ostream operator * * * * * * * * * * * * * * * //
|
||||
// * * * * * * * * * * * * * * Ostream operator * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::Ostream& Foam::operator<<(Ostream& os, const dictionaryEntry& de)
|
||||
{
|
||||
|
||||
@ -26,33 +26,92 @@ License
|
||||
|
||||
#include "primitiveEntry.H"
|
||||
#include "dictionary.H"
|
||||
#include "OSspecific.H"
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::primitiveEntry::append(const UList<token>& varTokens)
|
||||
{
|
||||
forAll(varTokens, i)
|
||||
{
|
||||
newElmt(tokenIndex()++) = varTokens[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool Foam::primitiveEntry::expandVariable
|
||||
(
|
||||
const word& w,
|
||||
const dictionary& dict
|
||||
)
|
||||
{
|
||||
word varName = w(1, w.size()-1);
|
||||
|
||||
// lookup the variable name in the given dictionary....
|
||||
// Note: allow wildcards to match? For now disabled since following
|
||||
// would expand internalField to wildcard match and not expected
|
||||
// internalField:
|
||||
// internalField XXX;
|
||||
// boundaryField { ".*" {YYY;} movingWall {value $internalField;}
|
||||
const entry* ePtr = dict.lookupEntryPtr(varName, true, false);
|
||||
|
||||
// ...if defined append its tokens into this
|
||||
if (ePtr)
|
||||
{
|
||||
append(ePtr->stream());
|
||||
}
|
||||
else
|
||||
{
|
||||
// not in the dictionary - try an environment variable
|
||||
string envStr = getEnv(varName);
|
||||
|
||||
if (envStr.empty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
append(tokenList(IStringStream('(' + envStr + ')')()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::primitiveEntry::primitiveEntry(const keyType& key, const ITstream& tokens)
|
||||
Foam::primitiveEntry::primitiveEntry(const keyType& key, const ITstream& is)
|
||||
:
|
||||
entry(key),
|
||||
ITstream(tokens)
|
||||
ITstream(is)
|
||||
{
|
||||
name() += "::" + keyword();
|
||||
}
|
||||
|
||||
|
||||
Foam::primitiveEntry::primitiveEntry(const keyType& keyword, const token& t)
|
||||
Foam::primitiveEntry::primitiveEntry(const keyType& key, const token& t)
|
||||
:
|
||||
entry(keyword),
|
||||
ITstream(keyword, tokenList(1, t))
|
||||
entry(key),
|
||||
ITstream(key, tokenList(1, t))
|
||||
{}
|
||||
|
||||
|
||||
Foam::primitiveEntry::primitiveEntry
|
||||
(
|
||||
const keyType& keyword,
|
||||
const tokenList& tokens
|
||||
const keyType& key,
|
||||
const UList<token>& tokens
|
||||
)
|
||||
:
|
||||
entry(keyword),
|
||||
ITstream(keyword, tokens)
|
||||
entry(key),
|
||||
ITstream(key, tokens)
|
||||
{}
|
||||
|
||||
|
||||
Foam::primitiveEntry::primitiveEntry
|
||||
(
|
||||
const keyType& key,
|
||||
const Xfer< List<token> >& tokens
|
||||
)
|
||||
:
|
||||
entry(key),
|
||||
ITstream(key, tokens)
|
||||
{}
|
||||
|
||||
|
||||
@ -60,34 +119,39 @@ Foam::primitiveEntry::primitiveEntry
|
||||
|
||||
Foam::label Foam::primitiveEntry::startLineNumber() const
|
||||
{
|
||||
if (size())
|
||||
const tokenList& tokens = *this;
|
||||
|
||||
if (tokens.empty())
|
||||
{
|
||||
return operator[](0).lineNumber();
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
return tokens.first().lineNumber();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Foam::label Foam::primitiveEntry::endLineNumber() const
|
||||
{
|
||||
if (size())
|
||||
const tokenList& tokens = *this;
|
||||
|
||||
if (tokens.empty())
|
||||
{
|
||||
return operator[](size()-1).lineNumber();
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
return tokens.last().lineNumber();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Foam::ITstream& Foam::primitiveEntry::stream() const
|
||||
{
|
||||
ITstream& dataStream = const_cast<primitiveEntry&>(*this);
|
||||
dataStream.rewind();
|
||||
return dataStream;
|
||||
ITstream& is = const_cast<primitiveEntry&>(*this);
|
||||
is.rewind();
|
||||
return is;
|
||||
}
|
||||
|
||||
|
||||
@ -113,43 +177,4 @@ Foam::dictionary& Foam::primitiveEntry::dict()
|
||||
}
|
||||
|
||||
|
||||
void Foam::primitiveEntry::insert
|
||||
(
|
||||
const tokenList& varTokens,
|
||||
const label posI
|
||||
)
|
||||
{
|
||||
tokenList& tokens = *this;
|
||||
|
||||
if (varTokens.empty())
|
||||
{
|
||||
label end = tokens.size() - 1;
|
||||
|
||||
for (label j=posI; j<end; j++)
|
||||
{
|
||||
tokens[j] = tokens[j+1];
|
||||
}
|
||||
|
||||
tokens.setSize(tokens.size() - 1);
|
||||
}
|
||||
else if (varTokens.size() > 1)
|
||||
{
|
||||
tokens.setSize(tokens.size() + varTokens.size() - 1);
|
||||
|
||||
label end = tokens.size() - 1;
|
||||
label offset = varTokens.size() - 1;
|
||||
|
||||
for (label j=end; j>posI; j--)
|
||||
{
|
||||
tokens[j] = tokens[j-offset];
|
||||
}
|
||||
}
|
||||
|
||||
forAll(varTokens, j)
|
||||
{
|
||||
tokens[posI + j] = varTokens[j];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -68,6 +68,9 @@ class primitiveEntry
|
||||
{
|
||||
// Private member functions
|
||||
|
||||
//- Append the given tokens starting at the current tokenIndex
|
||||
void append(const UList<token>&);
|
||||
|
||||
//- Append the given token to this entry
|
||||
void append
|
||||
(
|
||||
@ -76,9 +79,6 @@ class primitiveEntry
|
||||
Istream&
|
||||
);
|
||||
|
||||
//- Append the given tokens starting at the current tokenIndex
|
||||
void append(const tokenList&);
|
||||
|
||||
//- Expand the given variable (keyword starts with $)
|
||||
bool expandVariable(const word&, const dictionary&);
|
||||
|
||||
@ -93,9 +93,6 @@ class primitiveEntry
|
||||
//- Read the complete entry from the given stream
|
||||
void readEntry(const dictionary&, Istream&);
|
||||
|
||||
//- Insert the given tokens at token posI
|
||||
void insert(const tokenList&, const label posI);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
@ -110,11 +107,14 @@ public:
|
||||
//- Construct from keyword and a ITstream
|
||||
primitiveEntry(const keyType&, const ITstream&);
|
||||
|
||||
//- Construct from keyword and a token
|
||||
//- Construct from keyword and a single token
|
||||
primitiveEntry(const keyType&, const token&);
|
||||
|
||||
//- Construct from keyword and a tokenList
|
||||
primitiveEntry(const keyType&, const tokenList&);
|
||||
//- Construct from keyword and a list of tokens
|
||||
primitiveEntry(const keyType&, const UList<token>&);
|
||||
|
||||
//- Construct from keyword and by transferring a list of tokens
|
||||
primitiveEntry(const keyType&, const Xfer< List<token> >&);
|
||||
|
||||
//- Construct from keyword and a T
|
||||
template<class T>
|
||||
@ -166,7 +166,7 @@ public:
|
||||
//- Read tokens from the given stream
|
||||
bool read(const dictionary&, Istream&);
|
||||
|
||||
// Write
|
||||
//- Write
|
||||
void write(Ostream&) const;
|
||||
|
||||
//- Return info proxy.
|
||||
|
||||
@ -28,10 +28,9 @@ Description
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "primitiveEntry.H"
|
||||
#include "OSspecific.H"
|
||||
#include "functionEntry.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::primitiveEntry::append
|
||||
(
|
||||
@ -63,55 +62,6 @@ void Foam::primitiveEntry::append
|
||||
}
|
||||
|
||||
|
||||
void Foam::primitiveEntry::append(const tokenList& varTokens)
|
||||
{
|
||||
forAll(varTokens, i)
|
||||
{
|
||||
newElmt(tokenIndex()++) = varTokens[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool Foam::primitiveEntry::expandVariable
|
||||
(
|
||||
const word& w,
|
||||
const dictionary& dict
|
||||
)
|
||||
{
|
||||
word varName = w(1, w.size()-1);
|
||||
|
||||
// lookup the variable name in the given dictionary....
|
||||
// Note: allow wildcards to match? For now disabled since following
|
||||
// would expand internalField to wildcard match and not expected
|
||||
// internalField:
|
||||
// internalField XXX;
|
||||
// boundaryField { ".*" {YYY;} movingWall {value $internalField;}
|
||||
const entry* ePtr = dict.lookupEntryPtr(varName, true, false);
|
||||
|
||||
// ...if defined insert its tokens into this
|
||||
if (ePtr != NULL)
|
||||
{
|
||||
append(ePtr->stream());
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// if not in the dictionary see if it is an environment
|
||||
// variable
|
||||
|
||||
string enVarString = getEnv(varName);
|
||||
|
||||
if (enVarString.size())
|
||||
{
|
||||
append(tokenList(IStringStream('(' + enVarString + ')')()));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool Foam::primitiveEntry::expandFunction
|
||||
(
|
||||
const word& keyword,
|
||||
@ -221,6 +171,8 @@ void Foam::primitiveEntry::readEntry(const dictionary& dict, Istream& is)
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::primitiveEntry::primitiveEntry
|
||||
(
|
||||
const keyType& key,
|
||||
|
||||
@ -30,13 +30,13 @@ License
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
template<class T>
|
||||
Foam::primitiveEntry::primitiveEntry(const keyType& keyword, const T& t)
|
||||
Foam::primitiveEntry::primitiveEntry(const keyType& key, const T& t)
|
||||
:
|
||||
entry(keyword),
|
||||
ITstream(keyword, tokenList(10))
|
||||
entry(key),
|
||||
ITstream(key, tokenList(10))
|
||||
{
|
||||
OStringStream os;
|
||||
os << t << token::END_STATEMENT;
|
||||
os << t << token::END_STATEMENT;
|
||||
readEntry(dictionary::null, IStringStream(os.str())());
|
||||
}
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2008-2009 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -57,7 +57,9 @@ class StaticAssertionFailed<true>
|
||||
template<unsigned Test>
|
||||
class StaticAssertionTest {};
|
||||
|
||||
}
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
@ -62,7 +62,7 @@ Ostream& operator<<(Ostream&, const error&);
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class error Declaration
|
||||
Class error Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class error
|
||||
@ -92,10 +92,10 @@ public:
|
||||
error(const string& title);
|
||||
|
||||
//- Construct from dictionary
|
||||
error(const dictionary& errDict);
|
||||
error(const dictionary&);
|
||||
|
||||
//- Construct as copy
|
||||
error(const error& err);
|
||||
error(const error&);
|
||||
|
||||
|
||||
// Destructor
|
||||
@ -132,8 +132,8 @@ public:
|
||||
throwExceptions_ = false;
|
||||
}
|
||||
|
||||
//- Convert to Ostream
|
||||
// Prints basic message and then returns Ostream for further info.
|
||||
//- Convert to OSstream
|
||||
// Prints basic message and returns OSstream for further info.
|
||||
OSstream& operator()
|
||||
(
|
||||
const char* functionName,
|
||||
@ -141,6 +141,8 @@ public:
|
||||
const int sourceFileLineNumber = 0
|
||||
);
|
||||
|
||||
//- Convert to OSstream
|
||||
// Prints basic message and returns OSstream for further info.
|
||||
OSstream& operator()
|
||||
(
|
||||
const string& functionName,
|
||||
@ -148,11 +150,11 @@ public:
|
||||
const int sourceFileLineNumber = 0
|
||||
);
|
||||
|
||||
//- Convert to Ostream
|
||||
// Prints basic message and then returns Ostream for further info.
|
||||
//- Convert to OSstream
|
||||
// Prints basic message and returns OSstream for further info.
|
||||
operator OSstream&();
|
||||
|
||||
//- Explicitly convert to Ostream for << operations
|
||||
//- Explicitly convert to OSstream for << operations
|
||||
OSstream& operator()()
|
||||
{
|
||||
return operator OSstream&();
|
||||
@ -163,14 +165,14 @@ public:
|
||||
|
||||
|
||||
//- Helper function to print a stack
|
||||
static void printStack(Ostream& os);
|
||||
static void printStack(Ostream&);
|
||||
|
||||
//- Exit : can be called for any error to exit program. Prints stack
|
||||
// before exiting.
|
||||
//- Exit : can be called for any error to exit program.
|
||||
// Prints stack before exiting.
|
||||
void exit(const int errNo = 1);
|
||||
|
||||
//- Abort : used to stop code for fatal errors. Prints stack before
|
||||
// exiting.
|
||||
//- Abort : used to stop code for fatal errors.
|
||||
// Prints stack before exiting.
|
||||
void abort();
|
||||
|
||||
|
||||
@ -181,9 +183,7 @@ public:
|
||||
|
||||
|
||||
// Forward declaration of friend functions and operators
|
||||
|
||||
class IOerror;
|
||||
|
||||
Ostream& operator<<(Ostream&, const IOerror&);
|
||||
|
||||
|
||||
@ -211,7 +211,7 @@ public:
|
||||
IOerror(const string& title);
|
||||
|
||||
//- Construct from dictionary
|
||||
IOerror(const dictionary& errDict);
|
||||
IOerror(const dictionary&);
|
||||
|
||||
|
||||
// Destructor
|
||||
@ -236,8 +236,8 @@ public:
|
||||
return ioEndLineNumber_;
|
||||
}
|
||||
|
||||
//- Convert to Ostream
|
||||
// Prints basic message and then returns Ostream for further info.
|
||||
//- Convert to OSstream
|
||||
// Prints basic message and returns OSstream for further info.
|
||||
OSstream& operator()
|
||||
(
|
||||
const char* functionName,
|
||||
@ -248,8 +248,8 @@ public:
|
||||
const label ioEndLineNumber = -1
|
||||
);
|
||||
|
||||
//- Convert to Ostream
|
||||
// Prints basic message and then returns Ostream for further info.
|
||||
//- Convert to OSstream
|
||||
// Prints basic message and returns OSstream for further info.
|
||||
OSstream& operator()
|
||||
(
|
||||
const char* functionName,
|
||||
@ -258,8 +258,8 @@ public:
|
||||
const IOstream&
|
||||
);
|
||||
|
||||
//- Convert to Ostream
|
||||
// Prints basic message and then returns Ostream for further info.
|
||||
//- Convert to OSstream
|
||||
// Prints basic message and returns OSstream for further info.
|
||||
OSstream& operator()
|
||||
(
|
||||
const char* functionName,
|
||||
@ -288,24 +288,47 @@ public:
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
// Global error declarations: defined in error.C
|
||||
|
||||
extern error FatalError;
|
||||
extern error FatalError;
|
||||
extern IOerror FatalIOError;
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
// Convienient macros to add the file name and line number to the function name
|
||||
|
||||
#define FatalErrorIn(fn) FatalError(fn, __FILE__, __LINE__)
|
||||
#define FatalIOErrorIn(fn, ios) FatalIOError(fn, __FILE__, __LINE__, ios)
|
||||
|
||||
// Call for functions which are not currently implemented.
|
||||
// The functionName is printed and then abort is called.
|
||||
#define notImplemented(fn) \
|
||||
FatalErrorIn(fn) << "Not implemented" << Foam::abort(FatalError);
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
// Convenience macros to add the file name and line number to the function name
|
||||
|
||||
/**
|
||||
* @def FatalErrorIn(functionName)
|
||||
* Report an error message using Foam::FatalError for functionName in
|
||||
* file __FILE__ at line __LINE__
|
||||
*/
|
||||
#define FatalErrorIn(fn) \
|
||||
::Foam::FatalError((fn), __FILE__, __LINE__)
|
||||
|
||||
/**
|
||||
* @def FatalIOErrorIn(functionName, ios)
|
||||
* Report an error message using Foam::FatalIOError for functionName in
|
||||
* file __FILE__ at line __LINE__
|
||||
* for a particular IOstream
|
||||
*/
|
||||
#define FatalIOErrorIn(fn, ios) \
|
||||
::Foam::FatalIOError((fn), __FILE__, __LINE__, (ios))
|
||||
|
||||
/**
|
||||
* @def notImplemented(functionName)
|
||||
* Issue a FatalErrorIn for the functionName.
|
||||
* This is used for functions that are not currently implemented.
|
||||
* The functionName is printed and then abort is called.
|
||||
*
|
||||
* @note
|
||||
* This macro can be particularly useful when methods must be defined to
|
||||
* complete the interface of a derived class even if they should never be
|
||||
* called for this derived class.
|
||||
*/
|
||||
#define notImplemented(fn) \
|
||||
FatalErrorIn(fn) << "Not implemented" << ::Foam::abort(FatalError);
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#include "errorManip.H"
|
||||
|
||||
@ -49,7 +49,6 @@ namespace Foam
|
||||
{
|
||||
|
||||
// Forward declaration of friend functions and operators
|
||||
|
||||
template<class Err> class errorManip;
|
||||
template<class Err> Ostream& operator<<(Ostream&, errorManip<Err>);
|
||||
|
||||
@ -59,7 +58,7 @@ Ostream& operator<<(Ostream&, errorManipArg<Err, T>);
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class errorManip Declaration
|
||||
Class errorManip Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
template<class Err>
|
||||
@ -89,7 +88,7 @@ inline Ostream& operator<<(Ostream& os, errorManip<Err> m)
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class errorManipArg Declaration
|
||||
Class errorManipArg Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
//- errorManipArg
|
||||
@ -123,23 +122,29 @@ inline Ostream& operator<<(Ostream& os, errorManipArg<Err, T> m)
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
inline errorManipArg<error, int> exit(error& err, const int errNo = 1)
|
||||
inline errorManipArg<error, int>
|
||||
exit(error& err, const int errNo = 1)
|
||||
{
|
||||
return errorManipArg<error, int>(&error::exit, err, errNo);
|
||||
}
|
||||
|
||||
inline errorManip<error> abort(error& err)
|
||||
|
||||
inline errorManip<error>
|
||||
abort(error& err)
|
||||
{
|
||||
return errorManip<error>(&error::abort, err);
|
||||
}
|
||||
|
||||
|
||||
inline errorManipArg<IOerror, int> exit(IOerror& err, const int errNo = 1)
|
||||
inline errorManipArg<IOerror, int>
|
||||
exit(IOerror& err, const int errNo = 1)
|
||||
{
|
||||
return errorManipArg<IOerror, int>(&IOerror::exit, err, errNo);
|
||||
}
|
||||
|
||||
inline errorManip<IOerror> abort(IOerror& err)
|
||||
|
||||
inline errorManip<IOerror>
|
||||
abort(IOerror& err)
|
||||
{
|
||||
return errorManip<IOerror>(&IOerror::abort, err);
|
||||
}
|
||||
|
||||
@ -36,7 +36,8 @@ Description
|
||||
|
||||
Usage
|
||||
@code
|
||||
messageStream << "message1" << "message2" << FoamDataType << endl;
|
||||
messageStream
|
||||
<< "message1" << "message2" << FoamDataType << endl;
|
||||
@endcode
|
||||
|
||||
SourceFiles
|
||||
@ -55,6 +56,7 @@ SourceFiles
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declaration of classes
|
||||
class IOstream;
|
||||
class Ostream;
|
||||
class OSstream;
|
||||
@ -103,13 +105,13 @@ public:
|
||||
messageStream
|
||||
(
|
||||
const string& title,
|
||||
errorSeverity sev,
|
||||
errorSeverity,
|
||||
const int maxErrors = 0
|
||||
);
|
||||
|
||||
|
||||
//- Construct from dictionary
|
||||
messageStream(const dictionary& dict);
|
||||
messageStream(const dictionary&);
|
||||
|
||||
|
||||
// Member functions
|
||||
@ -133,8 +135,8 @@ public:
|
||||
return maxErrors_;
|
||||
}
|
||||
|
||||
//- Convert to Ostream
|
||||
// Prints basic message and then returns Ostream for further info.
|
||||
//- Convert to OSstream
|
||||
// Prints basic message and returns OSstream for further info.
|
||||
OSstream& operator()
|
||||
(
|
||||
const char* functionName,
|
||||
@ -142,6 +144,8 @@ public:
|
||||
const int sourceFileLineNumber = 0
|
||||
);
|
||||
|
||||
//- Convert to OSstream
|
||||
// Prints basic message and returns OSstream for further info.
|
||||
OSstream& operator()
|
||||
(
|
||||
const string& functionName,
|
||||
@ -149,8 +153,8 @@ public:
|
||||
const int sourceFileLineNumber = 0
|
||||
);
|
||||
|
||||
//- Convert to Ostream
|
||||
// Prints basic message and then returns Ostream for further info.
|
||||
//- Convert to OSstream
|
||||
// Prints basic message and returns OSstream for further info.
|
||||
OSstream& operator()
|
||||
(
|
||||
const char* functionName,
|
||||
@ -161,8 +165,8 @@ public:
|
||||
const label ioEndLineNumber = -1
|
||||
);
|
||||
|
||||
//- Convert to Ostream
|
||||
// Prints basic message and then returns Ostream for further info.
|
||||
//- Convert to OSstream
|
||||
// Prints basic message and returns OSstream for further info.
|
||||
OSstream& operator()
|
||||
(
|
||||
const char* functionName,
|
||||
@ -171,8 +175,8 @@ public:
|
||||
const IOstream&
|
||||
);
|
||||
|
||||
//- Convert to Ostream
|
||||
// Prints basic message and then returns Ostream for further info.
|
||||
//- Convert to OSstream
|
||||
// Prints basic message and returns OSstream for further info.
|
||||
OSstream& operator()
|
||||
(
|
||||
const char* functionName,
|
||||
@ -181,10 +185,10 @@ public:
|
||||
const dictionary&
|
||||
);
|
||||
|
||||
//- Convert to Ostream for << operations
|
||||
//- Convert to OSstream for << operations
|
||||
operator OSstream&();
|
||||
|
||||
//- Explicitly convert to Ostream for << operations
|
||||
//- Explicitly convert to OSstream for << operations
|
||||
OSstream& operator()()
|
||||
{
|
||||
return operator OSstream&();
|
||||
@ -199,18 +203,6 @@ extern messageStream SeriousError;
|
||||
extern messageStream Warning;
|
||||
extern messageStream Info;
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
// Convienient macros to add the file name and line number to the function name
|
||||
|
||||
#define SeriousErrorIn(fn) SeriousError(fn, __FILE__, __LINE__)
|
||||
#define SeriousIOErrorIn(fn, ios) SeriousError(fn, __FILE__, __LINE__, ios)
|
||||
|
||||
#define WarningIn(fn) Warning(fn, __FILE__, __LINE__)
|
||||
#define IOWarningIn(fn, ios) Warning(fn, __FILE__, __LINE__, ios)
|
||||
|
||||
#define InfoIn(fn) Info(fn, __FILE__, __LINE__)
|
||||
#define IOInfoIn(fn, ios) Info(fn, __FILE__, __LINE__, ios)
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
@ -219,6 +211,60 @@ extern messageStream Info;
|
||||
|
||||
#include "OSstream.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
// Convenience macros to add the file name and line number to the function name
|
||||
|
||||
/**
|
||||
* @def SeriousErrorIn(functionName)
|
||||
* Report an error message using Foam::SeriousError for functionName in
|
||||
* file __FILE__ at line __LINE__
|
||||
*/
|
||||
#define SeriousErrorIn(fn) \
|
||||
::Foam::SeriousError((fn), __FILE__, __LINE__)
|
||||
|
||||
/**
|
||||
* @def SeriousIOErrorIn(functionName, ios)
|
||||
* Report an IO error message using Foam::SeriousError for functionName in
|
||||
* file __FILE__ at line __LINE__
|
||||
* for a particular IOstream
|
||||
*/
|
||||
#define SeriousIOErrorIn(fn, ios) \
|
||||
::Foam::SeriousError((fn), __FILE__, __LINE__, ios)
|
||||
|
||||
/**
|
||||
* @def WarningIn(functionName)
|
||||
* Report a warning using Foam::Warning for functionName in
|
||||
* file __FILE__ at line __LINE__
|
||||
*/
|
||||
#define WarningIn(fn) \
|
||||
::Foam::Warning((fn), __FILE__, __LINE__)
|
||||
|
||||
/**
|
||||
* @def IOWarningIn(functionName, ios)
|
||||
* Report an IO warning using Foam::Warning for functionName in
|
||||
* file __FILE__ at line __LINE__
|
||||
* for a particular IOstream
|
||||
*/
|
||||
#define IOWarningIn(fn, ios) \
|
||||
::Foam::Warning((fn), __FILE__, __LINE__, (ios))
|
||||
|
||||
/**
|
||||
* @def InfoIn(functionName)
|
||||
* Report a information message using Foam::Info for functionName in
|
||||
* file __FILE__ at line __LINE__
|
||||
*/
|
||||
#define InfoIn(fn) \
|
||||
::Foam::Info((fn), __FILE__, __LINE__)
|
||||
|
||||
/**
|
||||
* @def IOInfoIn(functionName, ios)
|
||||
* Report an IO information message using Foam::Info for functionName in
|
||||
* file __FILE__ at line __LINE__
|
||||
* for a particular IOstream
|
||||
*/
|
||||
#define IOInfoIn(fn, ios) \
|
||||
::Foam::Info((fn), __FILE__, __LINE__, (ios))
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
@ -43,7 +43,8 @@ Foam::SLList<Foam::string> Foam::argList::validArgs;
|
||||
Foam::HashTable<Foam::string> Foam::argList::validOptions;
|
||||
Foam::HashTable<Foam::string> Foam::argList::validParOptions;
|
||||
Foam::HashTable<Foam::string> Foam::argList::optionUsage;
|
||||
Foam::string::size_type Foam::argList::usageMin = 16;
|
||||
Foam::SLList<Foam::string> Foam::argList::notes;
|
||||
Foam::string::size_type Foam::argList::usageMin = 20;
|
||||
Foam::string::size_type Foam::argList::usageMax = 80;
|
||||
|
||||
|
||||
@ -51,7 +52,7 @@ Foam::argList::initValidTables::initValidTables()
|
||||
{
|
||||
argList::addOption
|
||||
(
|
||||
"case", "DIR",
|
||||
"case", "dir",
|
||||
"specify alternate case directory, default is the cwd"
|
||||
);
|
||||
argList::addBoolOption("parallel", "run in parallel");
|
||||
@ -108,6 +109,15 @@ void Foam::argList::addUsage
|
||||
}
|
||||
|
||||
|
||||
void Foam::argList::addNote(const string& note)
|
||||
{
|
||||
if (!note.empty())
|
||||
{
|
||||
notes.append(note);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::argList::removeOption(const word& opt)
|
||||
{
|
||||
validOptions.erase(opt);
|
||||
@ -765,12 +775,13 @@ void Foam::argList::printUsage() const
|
||||
|
||||
HashTable<string>::const_iterator iter = validOptions.find(optionName);
|
||||
Info<< " -" << optionName;
|
||||
label len = optionName.size() + 3; // include leading " -"
|
||||
label len = optionName.size() + 3; // length includes leading ' -'
|
||||
|
||||
if (iter().size())
|
||||
{
|
||||
len += iter().size() + 1; // include space between option and param
|
||||
Info<< ' ' << iter().c_str();
|
||||
// length includes space and between option/param and '<>'
|
||||
len += iter().size() + 3;
|
||||
Info<< " <" << iter().c_str() << '>';
|
||||
}
|
||||
|
||||
HashTable<string>::const_iterator usageIter =
|
||||
@ -814,6 +825,22 @@ void Foam::argList::printUsage() const
|
||||
"print the usage"
|
||||
);
|
||||
|
||||
|
||||
// output notes directly - no automatic text wrapping
|
||||
if (!notes.empty())
|
||||
{
|
||||
Info<< nl;
|
||||
for
|
||||
(
|
||||
SLList<string>::const_iterator iter = notes.begin();
|
||||
iter != notes.end();
|
||||
++iter
|
||||
)
|
||||
{
|
||||
Info<< iter().c_str() << nl;
|
||||
}
|
||||
}
|
||||
|
||||
Info<< nl
|
||||
<<"Using OpenFOAM-" << Foam::FOAMversion
|
||||
<<" (build: " << Foam::FOAMbuild << ") - see www.OpenFOAM.org"
|
||||
|
||||
@ -153,7 +153,10 @@ public:
|
||||
//- Short usage information for validOptions
|
||||
static HashTable<string> optionUsage;
|
||||
|
||||
//- Min offset for displaying usage (default: 16)
|
||||
//- Additional notes for usage
|
||||
static SLList<string> notes;
|
||||
|
||||
//- Min offset for displaying usage (default: 20)
|
||||
static string::size_type usageMin;
|
||||
|
||||
//- Max screen width for displaying usage (default: 80)
|
||||
@ -287,6 +290,10 @@ public:
|
||||
const string& usage
|
||||
);
|
||||
|
||||
//- Add extra notes for the usage information
|
||||
// This string is used "as-is" without additional formatting
|
||||
static void addNote(const string&);
|
||||
|
||||
//- Remove option from validOptions and from optionUsage
|
||||
static void removeOption(const word& opt);
|
||||
|
||||
|
||||
@ -60,7 +60,7 @@ word name(const Scalar val)
|
||||
Scalar readScalar(Istream& is)
|
||||
{
|
||||
Scalar rs;
|
||||
is >> rs;
|
||||
is >> rs;
|
||||
|
||||
return rs;
|
||||
}
|
||||
|
||||
@ -50,9 +50,9 @@ public:
|
||||
|
||||
enum
|
||||
{
|
||||
dim = 3, // Dimensionality of space
|
||||
rank = 0, // Rank of Scalar is 0
|
||||
nComponents = 1 // Number of components in Scalar is 1
|
||||
dim = 3, //!< Dimensionality of space
|
||||
rank = 0, //!< Rank of Scalar is 0
|
||||
nComponents = 1 //!< Number of components in Scalar is 1
|
||||
};
|
||||
|
||||
// Static data members
|
||||
@ -72,6 +72,7 @@ public:
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Conversion to a Scalar
|
||||
operator Scalar() const
|
||||
{
|
||||
return p_;
|
||||
|
||||
@ -86,8 +86,8 @@ public:
|
||||
|
||||
enum
|
||||
{
|
||||
dim = 3, // Dimensionality of space
|
||||
nComponents = nCmpt // Number of components in this vector space
|
||||
dim = 3, //!< Dimensionality of space
|
||||
nComponents = nCmpt //!< Number of components in this vector space
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -76,9 +76,9 @@ public:
|
||||
|
||||
enum
|
||||
{
|
||||
dim = 3, // Dimensionality of space
|
||||
rank = 0, // Rank of bool is 0
|
||||
nComponents = 1 // Number of components in bool is 1
|
||||
dim = 3, //!< Dimensionality of space
|
||||
rank = 0, //!< Rank of bool is 0
|
||||
nComponents = 1 //!< Number of components in bool is 1
|
||||
};
|
||||
|
||||
// Static data members
|
||||
@ -95,6 +95,7 @@ public:
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Conversion to a bool
|
||||
operator bool() const
|
||||
{
|
||||
return p_;
|
||||
|
||||
66
src/OpenFOAM/primitives/chars/wchar/wchar.H
Normal file
66
src/OpenFOAM/primitives/chars/wchar/wchar.H
Normal file
@ -0,0 +1,66 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2009-2009 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
|
||||
|
||||
Primitive
|
||||
wchar_t
|
||||
|
||||
Description
|
||||
A wide-character and a pointer to a wide-character string.
|
||||
|
||||
SourceFiles
|
||||
wcharIO.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef wchar_H
|
||||
#define wchar_H
|
||||
|
||||
#include <cwchar>
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
class Istream;
|
||||
class Ostream;
|
||||
|
||||
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
||||
|
||||
//- Output via a normal char
|
||||
Ostream& operator<<(Ostream&, const wchar_t);
|
||||
|
||||
//- Output string via normal char
|
||||
Ostream& operator<<(Ostream&, const wchar_t*);
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
62
src/OpenFOAM/primitives/chars/wchar/wcharIO.C
Normal file
62
src/OpenFOAM/primitives/chars/wchar/wcharIO.C
Normal file
@ -0,0 +1,62 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2009-2009 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
|
||||
|
||||
Description
|
||||
Reads a char from an input stream, for a given version
|
||||
number and File format. If an ascii File is being read, then the line
|
||||
numbers are counted and an erroneous read is reported.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "error.H"
|
||||
|
||||
#include "wchar.H"
|
||||
#include "IOstreams.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
||||
|
||||
Foam::Ostream& Foam::operator<<(Ostream& os, const wchar_t wc)
|
||||
{
|
||||
os.write(char(wc));
|
||||
|
||||
os.check("Ostream& operator<<(Ostream&, const wchar_t)");
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
Foam::Ostream& Foam::operator<<(Ostream& os, const wchar_t* ws)
|
||||
{
|
||||
if (ws)
|
||||
{
|
||||
for (const wchar_t* p = ws; *p; ++p)
|
||||
{
|
||||
os.write(char(*p));
|
||||
}
|
||||
}
|
||||
os.check("Ostream& operator<<(Ostream&, const wchar_t*)");
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -148,9 +148,9 @@ public:
|
||||
|
||||
enum
|
||||
{
|
||||
dim = 3, // Dimensionality of space
|
||||
rank = 0, // Rank of label is 0
|
||||
nComponents = 1 // Number of components in label is 1
|
||||
dim = 3, //!< Dimensionality of space
|
||||
rank = 0, //!< Rank of label is 0
|
||||
nComponents = 1 //!< Number of components in label is 1
|
||||
};
|
||||
|
||||
// Static data members
|
||||
@ -169,6 +169,7 @@ public:
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Conversion to a label
|
||||
operator label() const
|
||||
{
|
||||
return p_;
|
||||
|
||||
@ -132,9 +132,9 @@ public:
|
||||
|
||||
enum
|
||||
{
|
||||
dim = 3, // Dimensionality of space
|
||||
rank = 0, // Rank of uLabel is 0
|
||||
nComponents = 1 // Number of components in uLabel is 1
|
||||
dim = 3, //!< Dimensionality of space
|
||||
rank = 0, //!< Rank of uLabel is 0
|
||||
nComponents = 1 //!< Number of components in uLabel is 1
|
||||
};
|
||||
|
||||
// Static data members
|
||||
@ -154,6 +154,7 @@ public:
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Conversion to a uLabel
|
||||
operator uLabel() const
|
||||
{
|
||||
return p_;
|
||||
|
||||
@ -1,5 +1,26 @@
|
||||
edgeMesh.C
|
||||
edgeMeshIO.C
|
||||
featureEdgeMesh.C
|
||||
edgeMeshNew.C
|
||||
|
||||
edgeFormats = edgeFormats
|
||||
$(edgeFormats)/edgeFormatsCore.C
|
||||
|
||||
$(edgeFormats)/emesh/EMESHedgeFormat.C
|
||||
$(edgeFormats)/emesh/EMESHedgeFormatRunTime.C
|
||||
|
||||
$(edgeFormats)/nas/NASedgeFormat.C
|
||||
$(edgeFormats)/nas/NASedgeFormatRunTime.C
|
||||
|
||||
$(edgeFormats)/obj/OBJedgeFormat.C
|
||||
$(edgeFormats)/obj/OBJedgeFormatRunTime.C
|
||||
|
||||
$(edgeFormats)/starcd/STARCDedgeFormat.C
|
||||
$(edgeFormats)/starcd/STARCDedgeFormatRunTime.C
|
||||
|
||||
$(edgeFormats)/vtk/VTKedgeFormat.C
|
||||
$(edgeFormats)/vtk/VTKedgeFormatRunTime.C
|
||||
|
||||
featureEdgeMesh/featureEdgeMesh.C
|
||||
|
||||
|
||||
LIB = $(FOAM_LIBBIN)/libedgeMesh
|
||||
|
||||
200
src/edgeMesh/edgeFormats/edgeFormatsCore.C
Normal file
200
src/edgeMesh/edgeFormats/edgeFormatsCore.C
Normal file
@ -0,0 +1,200 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2009-2009 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 "edgeFormatsCore.H"
|
||||
|
||||
#include "Time.H"
|
||||
#include "IFstream.H"
|
||||
#include "OFstream.H"
|
||||
#include "edgeMesh.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
Foam::word Foam::fileFormats::edgeFormatsCore::nativeExt("eMesh");
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
Foam::string Foam::fileFormats::edgeFormatsCore::getLineNoComment
|
||||
(
|
||||
IFstream& is
|
||||
)
|
||||
{
|
||||
string line;
|
||||
do
|
||||
{
|
||||
is.getLine(line);
|
||||
}
|
||||
while ((line.empty() || line[0] == '#') && is.good());
|
||||
|
||||
return line;
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
Foam::fileName Foam::fileFormats::edgeFormatsCore::localMeshFileName
|
||||
(
|
||||
const word& meshName
|
||||
)
|
||||
{
|
||||
const word name(meshName.size() ? meshName : surfaceRegistry::defaultName);
|
||||
|
||||
return fileName
|
||||
(
|
||||
surfaceRegistry::prefix/name/surfMesh::meshSubDir
|
||||
/ name + "." + nativeExt
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Foam::fileName Foam::fileFormats::edgeFormatsCore::findMeshInstance
|
||||
(
|
||||
const Time& t,
|
||||
const word& meshName
|
||||
)
|
||||
{
|
||||
fileName localName = localMeshFileName(meshName);
|
||||
|
||||
// Search back through the time directories list to find the time
|
||||
// closest to and lower than current time
|
||||
|
||||
instantList ts = t.times();
|
||||
label instanceI;
|
||||
|
||||
for (instanceI = ts.size()-1; instanceI >= 0; --instanceI)
|
||||
{
|
||||
if (ts[instanceI].value() <= t.timeOutputValue())
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Noting that the current directory has already been searched
|
||||
// for mesh data, start searching from the previously stored time directory
|
||||
|
||||
if (instanceI >= 0)
|
||||
{
|
||||
for (label i = instanceI; i >= 0; --i)
|
||||
{
|
||||
if (isFile(t.path()/ts[i].name()/localName))
|
||||
{
|
||||
return ts[i].name();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return "constant";
|
||||
}
|
||||
|
||||
|
||||
Foam::fileName Foam::fileFormats::edgeFormatsCore::findMeshFile
|
||||
(
|
||||
const Time& t,
|
||||
const word& meshName
|
||||
)
|
||||
{
|
||||
fileName localName = localMeshFileName(meshName);
|
||||
|
||||
// Search back through the time directories list to find the time
|
||||
// closest to and lower than current time
|
||||
|
||||
instantList ts = t.times();
|
||||
label instanceI;
|
||||
|
||||
for (instanceI = ts.size()-1; instanceI >= 0; --instanceI)
|
||||
{
|
||||
if (ts[instanceI].value() <= t.timeOutputValue())
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Noting that the current directory has already been searched
|
||||
// for mesh data, start searching from the previously stored time directory
|
||||
|
||||
if (instanceI >= 0)
|
||||
{
|
||||
for (label i = instanceI; i >= 0; --i)
|
||||
{
|
||||
fileName testName(t.path()/ts[i].name()/localName);
|
||||
|
||||
if (isFile(testName))
|
||||
{
|
||||
return testName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// fallback to "constant"
|
||||
return t.path()/"constant"/localName;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
bool Foam::fileFormats::edgeFormatsCore::checkSupport
|
||||
(
|
||||
const wordHashSet& available,
|
||||
const word& ext,
|
||||
const bool verbose,
|
||||
const word& functionName
|
||||
)
|
||||
{
|
||||
if (available.found(ext))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (verbose)
|
||||
{
|
||||
wordList known = available.sortedToc();
|
||||
|
||||
Info<<"Unknown file extension for " << functionName
|
||||
<< " : " << ext << nl
|
||||
<<"Valid types: (";
|
||||
// compact output:
|
||||
forAll(known, i)
|
||||
{
|
||||
Info<<" " << known[i];
|
||||
}
|
||||
Info<<" )" << endl;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::fileFormats::edgeFormatsCore::edgeFormatsCore()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::fileFormats::edgeFormatsCore::~edgeFormatsCore()
|
||||
{}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
118
src/edgeMesh/edgeFormats/edgeFormatsCore.H
Normal file
118
src/edgeMesh/edgeFormats/edgeFormatsCore.H
Normal file
@ -0,0 +1,118 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2009-2009 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::fileFormats::edgeFormatsCore
|
||||
|
||||
Description
|
||||
A collection of helper functions for reading/writing edge formats.
|
||||
|
||||
SourceFiles
|
||||
edgeFormatsCore.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef edgeFormatsCore_H
|
||||
#define edgeFormatsCore_H
|
||||
|
||||
#include "Map.H"
|
||||
#include "HashSet.H"
|
||||
#include "labelList.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declaration of friend functions and operators
|
||||
|
||||
class IFstream;
|
||||
class Time;
|
||||
|
||||
namespace fileFormats
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class edgeFormatsCore Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class edgeFormatsCore
|
||||
{
|
||||
protected:
|
||||
|
||||
//- Read non-comment line
|
||||
static string getLineNoComment(IFstream&);
|
||||
|
||||
public:
|
||||
// Static Data
|
||||
|
||||
//- The file extension corresponding to 'native' edge format
|
||||
// Normally "eMesh" (edge-mesh)
|
||||
static word nativeExt;
|
||||
|
||||
// Static Member Functions
|
||||
|
||||
static bool checkSupport
|
||||
(
|
||||
const wordHashSet& available,
|
||||
const word& ext,
|
||||
const bool verbose,
|
||||
const word& functionName
|
||||
);
|
||||
|
||||
// //- Return the local file name (within time directory)
|
||||
// // NEEDS FIXING
|
||||
// static fileName localMeshFileName(const word& edgeName="");
|
||||
//
|
||||
// //- Find instance with edgeName
|
||||
// // NEEDS FIXING
|
||||
// static fileName findMeshInstance(const Time&, const word& edgeName="");
|
||||
//
|
||||
// //- Find mesh file with edgeName
|
||||
// // NEEDS FIXING
|
||||
// static fileName findMeshFile(const Time&, const word& edgeName="");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
edgeFormatsCore();
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~edgeFormatsCore();
|
||||
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace fileFormats
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
195
src/edgeMesh/edgeFormats/emesh/EMESHedgeFormat.C
Normal file
195
src/edgeMesh/edgeFormats/emesh/EMESHedgeFormat.C
Normal file
@ -0,0 +1,195 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2009-2009 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 "EMESHedgeFormat.H"
|
||||
#include "IOobject.H"
|
||||
#include "IFstream.H"
|
||||
#include "clock.H"
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::fileFormats::EMESHedgeFormat::EMESHedgeFormat
|
||||
(
|
||||
const fileName& filename
|
||||
)
|
||||
{
|
||||
read(filename);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::fileFormats::EMESHedgeFormat::read
|
||||
(
|
||||
const fileName& filename
|
||||
)
|
||||
{
|
||||
clear();
|
||||
|
||||
IFstream is(filename);
|
||||
if (!is.good())
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"fileFormats::EMESHedgeFormat::read(const fileName&)"
|
||||
)
|
||||
<< "Cannot read file " << filename
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
return read(is, this->storedPoints(), this->storedEdges());
|
||||
}
|
||||
|
||||
|
||||
bool Foam::fileFormats::EMESHedgeFormat::read
|
||||
(
|
||||
Istream& is,
|
||||
pointField& pointLst,
|
||||
edgeList& edgeLst
|
||||
)
|
||||
{
|
||||
if (!is.good())
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"fileFormats::EMESHedgeFormat::read"
|
||||
"(Istream&, pointField&, edgeList&)"
|
||||
)
|
||||
<< "read error "
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
token firstToken(is);
|
||||
|
||||
// swallow IOobject header
|
||||
if (!is.good())
|
||||
{
|
||||
FatalIOErrorIn
|
||||
(
|
||||
"fileFormats::EMESHedgeFormat::read"
|
||||
"(Istream&, pointField&, edgeList&)",
|
||||
is
|
||||
)
|
||||
<< "First token could not be read" << nl
|
||||
<< exit(FatalIOError);
|
||||
|
||||
return false;
|
||||
}
|
||||
else if (firstToken.isWord() && firstToken.wordToken() == "FoamFile")
|
||||
{
|
||||
// read and discard
|
||||
dictionary headerDict(is);
|
||||
}
|
||||
else
|
||||
{
|
||||
is.putBack(firstToken);
|
||||
}
|
||||
|
||||
// read points:
|
||||
is >> pointLst;
|
||||
|
||||
// read edges:
|
||||
is >> edgeLst;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Foam::Ostream&
|
||||
Foam::fileFormats::EMESHedgeFormat::write
|
||||
(
|
||||
Ostream& os,
|
||||
const pointField& pointLst,
|
||||
const edgeList& edgeLst
|
||||
)
|
||||
{
|
||||
if (!os.good())
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"fileFormats::EMESHedgeFormat::write"
|
||||
"(Ostream&, const fileName&, const edgeMesh&)"
|
||||
)
|
||||
<< "bad output stream " << os.name()
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
os << "\n// points:" << nl << pointLst << nl
|
||||
<< "\n// edges:" << nl << edgeLst << nl;
|
||||
|
||||
IOobject::writeDivider(os);
|
||||
|
||||
// Check state of Ostream
|
||||
os.check
|
||||
(
|
||||
"EMESHedgeFormat::write"
|
||||
"(Ostream&, const pointField&, const edgeList&)"
|
||||
);
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
void Foam::fileFormats::EMESHedgeFormat::write
|
||||
(
|
||||
const fileName& filename,
|
||||
const edgeMesh& mesh
|
||||
)
|
||||
{
|
||||
OFstream os(filename);
|
||||
if (!os.good())
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"fileFormats::EMESHedgeFormat::write"
|
||||
"(const fileName&, const edgeMesh&)"
|
||||
)
|
||||
<< "Cannot open file for writing " << filename
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
|
||||
// just emit some information until we get a nicer IOobject
|
||||
IOobject::writeBanner(os)
|
||||
<< "FoamFile\n{\n"
|
||||
<< " version " << os.version() << ";\n"
|
||||
<< " format " << os.format() << ";\n"
|
||||
<< " class " << "featureEdgeMesh" << ";\n"
|
||||
<< " note " << "written " + clock::dateTime() << nl
|
||||
<< " object " << filename.name() << ";\n"
|
||||
<< "}" << nl;
|
||||
|
||||
IOobject::writeDivider(os);
|
||||
|
||||
write(os, mesh.points(), mesh.edges());
|
||||
|
||||
// Check state of Ostream
|
||||
os.check("EMESHedgeFormat::write(Ostream&)");
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
148
src/edgeMesh/edgeFormats/emesh/EMESHedgeFormat.H
Normal file
148
src/edgeMesh/edgeFormats/emesh/EMESHedgeFormat.H
Normal file
@ -0,0 +1,148 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2009-2009 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::fileFormats::EMESHedgeFormat
|
||||
|
||||
Description
|
||||
Provide a means of reading/writing the single-file OpenFOAM edge format.
|
||||
|
||||
Note
|
||||
This class provides more methods than the regular edge format interface.
|
||||
|
||||
SourceFiles
|
||||
EMESHedgeFormat.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef EMESHedgeFormat_H
|
||||
#define EMESHedgeFormat_H
|
||||
|
||||
#include "edgeMesh.H"
|
||||
#include "Ostream.H"
|
||||
#include "OFstream.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace fileFormats
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class EMESHedgeFormat Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class EMESHedgeFormat
|
||||
:
|
||||
public edgeMesh
|
||||
{
|
||||
// Private Member Functions
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
EMESHedgeFormat(const EMESHedgeFormat&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const EMESHedgeFormat&);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- Write header information
|
||||
static void writeHeader
|
||||
(
|
||||
Ostream&,
|
||||
const pointField&,
|
||||
const edgeList&
|
||||
);
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from file name
|
||||
EMESHedgeFormat(const fileName&);
|
||||
|
||||
|
||||
// Selectors
|
||||
|
||||
//- Read file and return edgeMesh
|
||||
static autoPtr<edgeMesh> New(const fileName& name)
|
||||
{
|
||||
return autoPtr<edgeMesh>
|
||||
(
|
||||
new EMESHedgeFormat(name)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~EMESHedgeFormat()
|
||||
{}
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Read edgeMesh components from stream
|
||||
static bool read
|
||||
(
|
||||
Istream&,
|
||||
pointField&,
|
||||
edgeList&
|
||||
);
|
||||
|
||||
//- Write edgeMesh components to stream
|
||||
static Ostream& write
|
||||
(
|
||||
Ostream&,
|
||||
const pointField&,
|
||||
const edgeList&
|
||||
);
|
||||
|
||||
//- Write edgeMesh with a mimicked IOobject header
|
||||
static void write(const fileName&, const edgeMesh&);
|
||||
|
||||
//- Read from file
|
||||
virtual bool read(const fileName&);
|
||||
|
||||
//- Write object
|
||||
virtual void write(const fileName& name) const
|
||||
{
|
||||
write(name, *this);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace fileFormats
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
61
src/edgeMesh/edgeFormats/emesh/EMESHedgeFormatRunTime.C
Normal file
61
src/edgeMesh/edgeFormats/emesh/EMESHedgeFormatRunTime.C
Normal file
@ -0,0 +1,61 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2009-2009 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 "EMESHedgeFormat.H"
|
||||
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "addToMemberFunctionSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace fileFormats
|
||||
{
|
||||
|
||||
// read edgeMesh
|
||||
addNamedToRunTimeSelectionTable
|
||||
(
|
||||
edgeMesh,
|
||||
EMESHedgeFormat,
|
||||
fileExtension,
|
||||
eMesh
|
||||
);
|
||||
|
||||
// write edgeMesh
|
||||
addNamedToMemberFunctionSelectionTable
|
||||
(
|
||||
edgeMesh,
|
||||
EMESHedgeFormat,
|
||||
write,
|
||||
fileExtension,
|
||||
eMesh
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// ************************************************************************* //
|
||||
260
src/edgeMesh/edgeFormats/nas/NASedgeFormat.C
Normal file
260
src/edgeMesh/edgeFormats/nas/NASedgeFormat.C
Normal file
@ -0,0 +1,260 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2009-2009 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 "NASedgeFormat.H"
|
||||
#include "IFstream.H"
|
||||
#include "IStringStream.H"
|
||||
#include "PackedBoolList.H"
|
||||
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
|
||||
// Do weird things to extract a floating point number
|
||||
Foam::scalar Foam::fileFormats::NASedgeFormat::parseNASCoord
|
||||
(
|
||||
const string& s
|
||||
)
|
||||
{
|
||||
size_t expSign = s.find_last_of("+-");
|
||||
|
||||
if (expSign != string::npos && expSign > 0 && !isspace(s[expSign-1]))
|
||||
{
|
||||
scalar mantissa = readScalar(IStringStream(s.substr(0, expSign))());
|
||||
scalar exponent = readScalar(IStringStream(s.substr(expSign+1))());
|
||||
|
||||
if (s[expSign] == '-')
|
||||
{
|
||||
exponent = -exponent;
|
||||
}
|
||||
return mantissa * pow(10, exponent);
|
||||
}
|
||||
else
|
||||
{
|
||||
return readScalar(IStringStream(s)());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::fileFormats::NASedgeFormat::NASedgeFormat
|
||||
(
|
||||
const fileName& filename
|
||||
)
|
||||
{
|
||||
read(filename);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::fileFormats::NASedgeFormat::read
|
||||
(
|
||||
const fileName& filename
|
||||
)
|
||||
{
|
||||
clear();
|
||||
|
||||
IFstream is(filename);
|
||||
if (!is.good())
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"fileFormats::NASedgeFormat::read(const fileName&)"
|
||||
)
|
||||
<< "Cannot read file " << filename
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
DynamicList<point> dynPoints;
|
||||
DynamicList<edge> dynEdges;
|
||||
DynamicList<label> pointId; // Nastran index of points
|
||||
|
||||
while (is.good())
|
||||
{
|
||||
string line;
|
||||
is.getLine(line);
|
||||
|
||||
// Skip empty or comment
|
||||
if (line.empty() || line[0] == '$')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check if character 72 is continuation
|
||||
if (line.size() > 72 && line[72] == '+')
|
||||
{
|
||||
line = line.substr(0, 72);
|
||||
|
||||
while (true)
|
||||
{
|
||||
string buf;
|
||||
is.getLine(buf);
|
||||
|
||||
if (buf.size() > 72 && buf[72] == '+')
|
||||
{
|
||||
line += buf.substr(8, 64);
|
||||
}
|
||||
else
|
||||
{
|
||||
line += buf.substr(8, buf.size()-8);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Read first word
|
||||
IStringStream lineStream(line);
|
||||
word cmd;
|
||||
lineStream >> cmd;
|
||||
|
||||
if (cmd == "CBEAM" || cmd == "CROD")
|
||||
{
|
||||
edge e;
|
||||
|
||||
// label groupId = readLabel(IStringStream(line.substr(16,8))());
|
||||
e[0] = readLabel(IStringStream(line.substr(24,8))());
|
||||
e[1] = readLabel(IStringStream(line.substr(32,8))());
|
||||
|
||||
// discard groupID
|
||||
dynEdges.append(e);
|
||||
}
|
||||
else if (cmd == "GRID")
|
||||
{
|
||||
label index = readLabel(IStringStream(line.substr(8,8))());
|
||||
scalar x = parseNASCoord(line.substr(24, 8));
|
||||
scalar y = parseNASCoord(line.substr(32, 8));
|
||||
scalar z = parseNASCoord(line.substr(40, 8));
|
||||
|
||||
pointId.append(index);
|
||||
dynPoints.append(point(x, y, z));
|
||||
}
|
||||
else if (cmd == "GRID*")
|
||||
{
|
||||
// Long format is on two lines with '*' continuation symbol
|
||||
// on start of second line.
|
||||
// Typical line (spaces compacted)
|
||||
// GRID* 126 0 -5.55999875E+02 -5.68730474E+02
|
||||
// * 2.14897901E+02
|
||||
|
||||
label index = readLabel(IStringStream(line.substr(8,16))());
|
||||
scalar x = parseNASCoord(line.substr(40, 16));
|
||||
scalar y = parseNASCoord(line.substr(56, 16));
|
||||
|
||||
is.getLine(line);
|
||||
if (line[0] != '*')
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"fileFormats::NASedgeFormat::read(const fileName&)"
|
||||
)
|
||||
<< "Expected continuation symbol '*' when reading GRID*"
|
||||
<< " (double precision coordinate) format" << nl
|
||||
<< "Read:" << line << nl
|
||||
<< "File:" << is.name() << " line:" << is.lineNumber()
|
||||
<< exit(FatalError);
|
||||
}
|
||||
scalar z = parseNASCoord(line.substr(8, 16));
|
||||
|
||||
pointId.append(index);
|
||||
dynPoints.append(point(x, y, z));
|
||||
}
|
||||
}
|
||||
|
||||
// transfer to normal lists
|
||||
storedPoints().transfer(dynPoints);
|
||||
|
||||
pointId.shrink();
|
||||
dynEdges.shrink();
|
||||
|
||||
// Build inverse mapping (NASTRAN pointId -> index)
|
||||
Map<label> mapPointId(2*pointId.size());
|
||||
forAll(pointId, i)
|
||||
{
|
||||
mapPointId.insert(pointId[i], i);
|
||||
}
|
||||
|
||||
// note which points were really used and which can be culled
|
||||
PackedBoolList usedPoints(points().size());
|
||||
|
||||
|
||||
// Pass1: relabel edges
|
||||
// ~~~~~~~~~~~~~~~~~~~~
|
||||
forAll(dynEdges, i)
|
||||
{
|
||||
edge& e = dynEdges[i];
|
||||
e[0] = mapPointId[e[0]];
|
||||
e[1] = mapPointId[e[1]];
|
||||
|
||||
usedPoints.set(e[0]);
|
||||
usedPoints.set(e[1]);
|
||||
}
|
||||
pointId.clearStorage();
|
||||
mapPointId.clear();
|
||||
|
||||
// not all the points were used, cull them accordingly
|
||||
if (unsigned(points().size()) != usedPoints.count())
|
||||
{
|
||||
label nUsed = 0;
|
||||
|
||||
pointField& pts = storedPoints();
|
||||
forAll(pts, pointI)
|
||||
{
|
||||
if (usedPoints.get(pointI))
|
||||
{
|
||||
if (nUsed != pointI)
|
||||
{
|
||||
pts[nUsed] = pts[pointI];
|
||||
}
|
||||
|
||||
// map prev -> new id
|
||||
mapPointId[pointI] = nUsed;
|
||||
|
||||
++nUsed;
|
||||
}
|
||||
}
|
||||
|
||||
pts.setSize(nUsed);
|
||||
|
||||
// renumber edge vertices
|
||||
forAll(dynEdges, edgeI)
|
||||
{
|
||||
edge& e = dynEdges[edgeI];
|
||||
|
||||
e[0] = mapPointId[e[0]];
|
||||
e[1] = mapPointId[e[1]];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// transfer to normal lists
|
||||
storedEdges().transfer(dynEdges);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
113
src/edgeMesh/edgeFormats/nas/NASedgeFormat.H
Normal file
113
src/edgeMesh/edgeFormats/nas/NASedgeFormat.H
Normal file
@ -0,0 +1,113 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2009-2009 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::fileFormats::NASedgeFormat
|
||||
|
||||
Description
|
||||
Nastran edge reader.
|
||||
|
||||
SourceFiles
|
||||
NASedgeFormat.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef NASedgeFormat_H
|
||||
#define NASedgeFormat_H
|
||||
|
||||
#include "edgeMesh.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace fileFormats
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class NASedgeFormat Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class NASedgeFormat
|
||||
:
|
||||
public edgeMesh
|
||||
{
|
||||
// Private Member Functions
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
NASedgeFormat(const NASedgeFormat&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const NASedgeFormat&);
|
||||
|
||||
protected:
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- Do weird things to extract number
|
||||
static scalar parseNASCoord(const string&);
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from file name
|
||||
NASedgeFormat(const fileName&);
|
||||
|
||||
|
||||
// Selectors
|
||||
|
||||
//- Read file and return edge mesh
|
||||
static autoPtr<edgeMesh> New(const fileName& name)
|
||||
{
|
||||
return autoPtr<edgeMesh>
|
||||
(
|
||||
new NASedgeFormat(name)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// Destructor
|
||||
|
||||
virtual ~NASedgeFormat()
|
||||
{}
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Read from a file
|
||||
virtual bool read(const fileName&);
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace fileFormats
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
60
src/edgeMesh/edgeFormats/nas/NASedgeFormatRunTime.C
Normal file
60
src/edgeMesh/edgeFormats/nas/NASedgeFormatRunTime.C
Normal file
@ -0,0 +1,60 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2009-2009 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 "NASedgeFormat.H"
|
||||
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "addToMemberFunctionSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace fileFormats
|
||||
{
|
||||
|
||||
// read edgeMesh - .bdf (Bulk Data Format)
|
||||
addNamedToRunTimeSelectionTable
|
||||
(
|
||||
edgeMesh,
|
||||
NASedgeFormat,
|
||||
fileExtension,
|
||||
bdf
|
||||
);
|
||||
|
||||
// read edgeMesh - .nas (Nastran Data Format)
|
||||
addNamedToRunTimeSelectionTable
|
||||
(
|
||||
edgeMesh,
|
||||
NASedgeFormat,
|
||||
fileExtension,
|
||||
nas
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// ************************************************************************* //
|
||||
245
src/edgeMesh/edgeFormats/obj/OBJedgeFormat.C
Normal file
245
src/edgeMesh/edgeFormats/obj/OBJedgeFormat.C
Normal file
@ -0,0 +1,245 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2009-2009 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 "OBJedgeFormat.H"
|
||||
#include "clock.H"
|
||||
#include "IFstream.H"
|
||||
#include "IStringStream.H"
|
||||
#include "Ostream.H"
|
||||
#include "OFstream.H"
|
||||
#include "ListOps.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::fileFormats::OBJedgeFormat::OBJedgeFormat
|
||||
(
|
||||
const fileName& filename
|
||||
)
|
||||
{
|
||||
read(filename);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::fileFormats::OBJedgeFormat::read
|
||||
(
|
||||
const fileName& filename
|
||||
)
|
||||
{
|
||||
clear();
|
||||
|
||||
IFstream is(filename);
|
||||
if (!is.good())
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"fileFormats::OBJedgeFormat::read(const fileName&)"
|
||||
)
|
||||
<< "Cannot read file " << filename
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
DynamicList<point> dynPoints;
|
||||
DynamicList<edge> dynEdges;
|
||||
DynamicList<label> dynUsedPoints;
|
||||
|
||||
while (is.good())
|
||||
{
|
||||
string line = this->getLineNoComment(is);
|
||||
|
||||
// handle continuations
|
||||
if (line[line.size()-1] == '\\')
|
||||
{
|
||||
line.substr(0, line.size()-1);
|
||||
line += this->getLineNoComment(is);
|
||||
}
|
||||
|
||||
// Read first word
|
||||
IStringStream lineStream(line);
|
||||
word cmd;
|
||||
lineStream >> cmd;
|
||||
|
||||
if (cmd == "v")
|
||||
{
|
||||
scalar x, y, z;
|
||||
lineStream >> x >> y >> z;
|
||||
|
||||
dynPoints.append(point(x, y, z));
|
||||
dynUsedPoints.append(-1);
|
||||
}
|
||||
else if (cmd == "l")
|
||||
{
|
||||
edge edgeRead;
|
||||
|
||||
// Assume 'l' is followed by space.
|
||||
string::size_type endNum = 1;
|
||||
|
||||
int nVerts = 0;
|
||||
for (int count = 0; count < 2; ++count)
|
||||
{
|
||||
string::size_type startNum =
|
||||
line.find_first_not_of(' ', endNum);
|
||||
|
||||
if (startNum == string::npos)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
endNum = line.find(' ', startNum);
|
||||
|
||||
string vertexSpec;
|
||||
if (endNum != string::npos)
|
||||
{
|
||||
vertexSpec = line.substr(startNum, endNum-startNum);
|
||||
}
|
||||
else
|
||||
{
|
||||
vertexSpec = line.substr(startNum, line.size() - startNum);
|
||||
}
|
||||
|
||||
string::size_type slashPos = vertexSpec.find('/');
|
||||
|
||||
label vertI = 0;
|
||||
if (slashPos != string::npos)
|
||||
{
|
||||
IStringStream intStream(vertexSpec.substr(0, slashPos));
|
||||
|
||||
intStream >> vertI;
|
||||
}
|
||||
else
|
||||
{
|
||||
IStringStream intStream(vertexSpec);
|
||||
|
||||
intStream >> vertI;
|
||||
}
|
||||
|
||||
edgeRead[nVerts++] = (vertI - 1); // change to zero-offset
|
||||
}
|
||||
|
||||
if (nVerts >= 2)
|
||||
{
|
||||
dynUsedPoints[edgeRead[0]] = edgeRead[0];
|
||||
dynUsedPoints[edgeRead[1]] = edgeRead[1];
|
||||
|
||||
dynEdges.append(edgeRead);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// cull unused points
|
||||
label nUsed = 0;
|
||||
|
||||
forAll(dynPoints, pointI)
|
||||
{
|
||||
if (dynUsedPoints[pointI] >= 0)
|
||||
{
|
||||
if (nUsed != pointI)
|
||||
{
|
||||
dynPoints[nUsed] = dynPoints[pointI];
|
||||
dynUsedPoints[pointI] = nUsed; // new position
|
||||
}
|
||||
++nUsed;
|
||||
}
|
||||
}
|
||||
|
||||
dynPoints.setSize(nUsed);
|
||||
|
||||
// transfer to normal lists
|
||||
storedPoints().transfer(dynPoints);
|
||||
|
||||
// renumber edge vertices
|
||||
if (nUsed != dynUsedPoints.size())
|
||||
{
|
||||
forAll(dynEdges, edgeI)
|
||||
{
|
||||
edge& e = dynEdges[edgeI];
|
||||
|
||||
e[0] = dynUsedPoints[e[0]];
|
||||
e[1] = dynUsedPoints[e[1]];
|
||||
}
|
||||
}
|
||||
storedEdges().transfer(dynEdges);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void Foam::fileFormats::OBJedgeFormat::write
|
||||
(
|
||||
const fileName& filename,
|
||||
const edgeMesh& mesh
|
||||
)
|
||||
{
|
||||
const pointField& pointLst = mesh.points();
|
||||
const edgeList& edgeLst = mesh.edges();
|
||||
|
||||
OFstream os(filename);
|
||||
if (!os.good())
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"fileFormats::OBJedgeFormat::write"
|
||||
"(const fileName&, const edgeMesh&)"
|
||||
)
|
||||
<< "Cannot open file for writing " << filename
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
|
||||
os << "# Wavefront OBJ file written " << clock::dateTime().c_str() << nl
|
||||
<< "o " << os.name().lessExt().name() << nl
|
||||
<< nl
|
||||
<< "# points : " << pointLst.size() << nl
|
||||
<< "# lines : " << edgeLst.size() << nl;
|
||||
|
||||
os << nl
|
||||
<< "# <points count=\"" << pointLst.size() << "\">" << nl;
|
||||
|
||||
// Write vertex coords
|
||||
forAll(pointLst, ptI)
|
||||
{
|
||||
const point& p = pointLst[ptI];
|
||||
|
||||
os << "v " << p.x() << ' ' << p.y() << ' ' << p.z() << nl;
|
||||
}
|
||||
|
||||
os << "# </points>" << nl
|
||||
<< nl
|
||||
<< "# <edges count=\"" << edgeLst.size() << "\">" << endl;
|
||||
|
||||
// Write line connectivity
|
||||
forAll(edgeLst, edgeI)
|
||||
{
|
||||
const edge& e = edgeLst[edgeI];
|
||||
|
||||
os << "l " << (e[0] + 1) << " " << (e[1] + 1) << nl;
|
||||
}
|
||||
os << "# </edges>" << endl;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
121
src/edgeMesh/edgeFormats/obj/OBJedgeFormat.H
Normal file
121
src/edgeMesh/edgeFormats/obj/OBJedgeFormat.H
Normal file
@ -0,0 +1,121 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2009-2009 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::fileFormats::OBJedgeFormat
|
||||
|
||||
Description
|
||||
Provide a means of reading/writing Alias/Wavefront OBJ format.
|
||||
|
||||
Does not handle negative vertex indices.
|
||||
|
||||
SourceFiles
|
||||
OBJedgeFormat.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef OBJedgeFormat_H
|
||||
#define OBJedgeFormat_H
|
||||
|
||||
#include "edgeMesh.H"
|
||||
#include "IFstream.H"
|
||||
#include "Ostream.H"
|
||||
#include "OFstream.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace fileFormats
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class OBJedgeFormat Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class OBJedgeFormat
|
||||
:
|
||||
public edgeMesh
|
||||
{
|
||||
// Private Member Functions
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
OBJedgeFormat(const OBJedgeFormat&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const OBJedgeFormat&);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from file name
|
||||
OBJedgeFormat(const fileName&);
|
||||
|
||||
|
||||
// Selectors
|
||||
|
||||
//- Read file and return surface
|
||||
static autoPtr<edgeMesh> New(const fileName& name)
|
||||
{
|
||||
return autoPtr<edgeMesh>
|
||||
(
|
||||
new OBJedgeFormat(name)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// Destructor
|
||||
|
||||
virtual ~OBJedgeFormat()
|
||||
{}
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Write surface mesh components by proxy
|
||||
static void write(const fileName&, const edgeMesh&);
|
||||
|
||||
//- Read from file
|
||||
virtual bool read(const fileName&);
|
||||
|
||||
//- Write object file
|
||||
virtual void write(const fileName& name) const
|
||||
{
|
||||
write(name, *this);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace fileFormats
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
61
src/edgeMesh/edgeFormats/obj/OBJedgeFormatRunTime.C
Normal file
61
src/edgeMesh/edgeFormats/obj/OBJedgeFormatRunTime.C
Normal file
@ -0,0 +1,61 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2009-2009 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 "OBJedgeFormat.H"
|
||||
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "addToMemberFunctionSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace fileFormats
|
||||
{
|
||||
|
||||
// read edgeMesh
|
||||
addNamedToRunTimeSelectionTable
|
||||
(
|
||||
edgeMesh,
|
||||
OBJedgeFormat,
|
||||
fileExtension,
|
||||
obj
|
||||
);
|
||||
|
||||
// write edgeMesh
|
||||
addNamedToMemberFunctionSelectionTable
|
||||
(
|
||||
edgeMesh,
|
||||
OBJedgeFormat,
|
||||
write,
|
||||
fileExtension,
|
||||
obj
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// ************************************************************************* //
|
||||
387
src/edgeMesh/edgeFormats/starcd/STARCDedgeFormat.C
Normal file
387
src/edgeMesh/edgeFormats/starcd/STARCDedgeFormat.C
Normal file
@ -0,0 +1,387 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2009-2009 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 "STARCDedgeFormat.H"
|
||||
#include "ListOps.H"
|
||||
#include "clock.H"
|
||||
#include "PackedBoolList.H"
|
||||
#include "IStringStream.H"
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
inline void Foam::fileFormats::STARCDedgeFormat::writeLines
|
||||
(
|
||||
Ostream& os,
|
||||
const edgeList& edges
|
||||
)
|
||||
{
|
||||
writeHeader(os, "CELL");
|
||||
|
||||
forAll(edges, edgeI)
|
||||
{
|
||||
const edge& e = edges[edgeI];
|
||||
const label cellId = edgeI + 1;
|
||||
|
||||
os << cellId // includes 1 offset
|
||||
<< ' ' << starcdLineShape_ // 2(line) shape
|
||||
<< ' ' << e.size()
|
||||
<< ' ' << 401 // arbitrary value
|
||||
<< ' ' << starcdLineType_; // 5(line)
|
||||
|
||||
os << nl << " " << cellId << " "
|
||||
<< (e[0]+1) << " " << (e[1]+1) << nl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
bool Foam::fileFormats::STARCDedgeFormat::readHeader
|
||||
(
|
||||
IFstream& is,
|
||||
const word& signature
|
||||
)
|
||||
{
|
||||
if (!is.good())
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"fileFormats::STARCDedgeFormat::readHeader(...)"
|
||||
)
|
||||
<< "cannot read " << signature << " " << is.name()
|
||||
<< abort(FatalError);
|
||||
}
|
||||
|
||||
word header;
|
||||
label majorVersion;
|
||||
|
||||
string line;
|
||||
|
||||
is.getLine(line);
|
||||
IStringStream(line)() >> header;
|
||||
|
||||
is.getLine(line);
|
||||
IStringStream(line)() >> majorVersion;
|
||||
|
||||
// add other checks ...
|
||||
if (header != signature)
|
||||
{
|
||||
Info<< "header mismatch " << signature << " " << is.name()
|
||||
<< endl;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void Foam::fileFormats::STARCDedgeFormat::writeHeader
|
||||
(
|
||||
Ostream& os,
|
||||
const char* filetype
|
||||
)
|
||||
{
|
||||
os << "PROSTAR_" << filetype << nl
|
||||
<< 4000
|
||||
<< " " << 0
|
||||
<< " " << 0
|
||||
<< " " << 0
|
||||
<< " " << 0
|
||||
<< " " << 0
|
||||
<< " " << 0
|
||||
<< " " << 0
|
||||
<< endl;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::fileFormats::STARCDedgeFormat::readPoints
|
||||
(
|
||||
IFstream& is,
|
||||
pointField& points,
|
||||
labelList& ids
|
||||
)
|
||||
{
|
||||
//
|
||||
// read .vrt file
|
||||
// ~~~~~~~~~~~~~~
|
||||
|
||||
if (!is.good())
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"fileFormats::STARCDedgeFormat::readPoints(...)"
|
||||
)
|
||||
<< "Cannot read file " << is.name()
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
readHeader(is, "PROSTAR_VERTEX");
|
||||
|
||||
DynamicList<point> dynPoints;
|
||||
DynamicList<label> dynPointId; // STAR-CD index of points
|
||||
|
||||
label lineLabel;
|
||||
while ((is >> lineLabel).good())
|
||||
{
|
||||
scalar x, y, z;
|
||||
|
||||
is >> x >> y >> z;
|
||||
|
||||
dynPoints.append(point(x, y, z));
|
||||
dynPointId.append(lineLabel);
|
||||
}
|
||||
|
||||
points.transfer(dynPoints);
|
||||
ids.transfer(dynPointId);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Foam::fileFormats::STARCDedgeFormat::writePoints
|
||||
(
|
||||
Ostream& os,
|
||||
const pointField& pointLst
|
||||
)
|
||||
{
|
||||
writeHeader(os, "VERTEX");
|
||||
|
||||
// Set the precision of the points data to 10
|
||||
os.precision(10);
|
||||
|
||||
// force decimal point for Fortran input
|
||||
os.setf(std::ios::showpoint);
|
||||
|
||||
forAll(pointLst, ptI)
|
||||
{
|
||||
os
|
||||
<< ptI + 1 << " "
|
||||
<< pointLst[ptI].x() << " "
|
||||
<< pointLst[ptI].y() << " "
|
||||
<< pointLst[ptI].z() << nl;
|
||||
}
|
||||
os.flush();
|
||||
}
|
||||
|
||||
|
||||
void Foam::fileFormats::STARCDedgeFormat::writeCase
|
||||
(
|
||||
Ostream& os,
|
||||
const pointField& pointLst,
|
||||
const label nEdges
|
||||
)
|
||||
{
|
||||
word caseName = os.name().lessExt().name();
|
||||
|
||||
os << "! STAR-CD file written " << clock::dateTime().c_str() << nl
|
||||
<< "! " << pointLst.size() << " points, " << nEdges << " lines" << nl
|
||||
<< "! case " << caseName << nl
|
||||
<< "! ------------------------------" << nl;
|
||||
|
||||
// forAll(zoneLst, zoneI)
|
||||
// {
|
||||
// os << "ctable " << zoneI + 1 << " line" << nl
|
||||
// << "ctname " << zoneI + 1 << " "
|
||||
// << zoneLst[zoneI].name() << nl;
|
||||
// }
|
||||
|
||||
os << "! ------------------------------" << nl
|
||||
<< "*set icvo mxv - 1" << nl
|
||||
<< "vread " << caseName << ".vrt icvo,,,coded" << nl
|
||||
<< "cread " << caseName << ".cel icvo,,,add,coded" << nl
|
||||
<< "*set icvo" << nl
|
||||
<< "! end" << nl;
|
||||
|
||||
os.flush();
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::fileFormats::STARCDedgeFormat::STARCDedgeFormat
|
||||
(
|
||||
const fileName& filename
|
||||
)
|
||||
{
|
||||
read(filename);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::fileFormats::STARCDedgeFormat::read
|
||||
(
|
||||
const fileName& filename
|
||||
)
|
||||
{
|
||||
clear();
|
||||
|
||||
fileName baseName = filename.lessExt();
|
||||
|
||||
// STAR-CD index of points
|
||||
List<label> pointId;
|
||||
|
||||
// read points from .vrt file
|
||||
readPoints
|
||||
(
|
||||
IFstream(baseName + ".vrt")(),
|
||||
storedPoints(),
|
||||
pointId
|
||||
);
|
||||
|
||||
// Build inverse mapping (STAR-CD pointId -> index)
|
||||
Map<label> mapPointId(2*pointId.size());
|
||||
forAll(pointId, i)
|
||||
{
|
||||
mapPointId.insert(pointId[i], i);
|
||||
}
|
||||
pointId.clear();
|
||||
|
||||
// note which points were really used and which can be culled
|
||||
PackedBoolList usedPoints(points().size());
|
||||
|
||||
//
|
||||
// read .cel file
|
||||
// ~~~~~~~~~~~~~~
|
||||
IFstream is(baseName + ".cel");
|
||||
if (!is.good())
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"fileFormats::STARCDedgeFormat::read(const fileName&)"
|
||||
)
|
||||
<< "Cannot read file " << is.name()
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
readHeader(is, "PROSTAR_CELL");
|
||||
|
||||
DynamicList<edge> dynEdges;
|
||||
|
||||
label lineLabel, shapeId, nLabels, cellTableId, typeId;
|
||||
DynamicList<label> vertexLabels(64);
|
||||
|
||||
while ((is >> lineLabel).good())
|
||||
{
|
||||
is >> shapeId >> nLabels >> cellTableId >> typeId;
|
||||
|
||||
vertexLabels.clear();
|
||||
vertexLabels.reserve(nLabels);
|
||||
|
||||
// read indices - max 8 per line
|
||||
for (label i = 0; i < nLabels; ++i)
|
||||
{
|
||||
label vrtId;
|
||||
if ((i % 8) == 0)
|
||||
{
|
||||
is >> lineLabel;
|
||||
}
|
||||
is >> vrtId;
|
||||
|
||||
// convert original vertex id to point label
|
||||
vertexLabels.append(mapPointId[vrtId]);
|
||||
}
|
||||
|
||||
if (typeId == starcdLineType_)
|
||||
{
|
||||
if (vertexLabels.size() >= 2)
|
||||
{
|
||||
dynEdges.append(edge(vertexLabels[0], vertexLabels[1]));
|
||||
|
||||
usedPoints.set(vertexLabels[0]);
|
||||
usedPoints.set(vertexLabels[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mapPointId.clear();
|
||||
|
||||
// not all the points were used, cull them accordingly
|
||||
if (unsigned(points().size()) != usedPoints.count())
|
||||
{
|
||||
label nUsed = 0;
|
||||
|
||||
pointField& pts = storedPoints();
|
||||
forAll(pts, pointI)
|
||||
{
|
||||
if (usedPoints.get(pointI))
|
||||
{
|
||||
if (nUsed != pointI)
|
||||
{
|
||||
pts[nUsed] = pts[pointI];
|
||||
}
|
||||
|
||||
// map prev -> new id
|
||||
mapPointId.set(pointI, nUsed);
|
||||
|
||||
++nUsed;
|
||||
}
|
||||
}
|
||||
|
||||
pts.setSize(nUsed);
|
||||
|
||||
// renumber edge vertices
|
||||
forAll(dynEdges, edgeI)
|
||||
{
|
||||
edge& e = dynEdges[edgeI];
|
||||
|
||||
e[0] = mapPointId[e[0]];
|
||||
e[1] = mapPointId[e[1]];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
storedEdges().transfer(dynEdges);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void Foam::fileFormats::STARCDedgeFormat::write
|
||||
(
|
||||
const fileName& filename,
|
||||
const edgeMesh& mesh
|
||||
)
|
||||
{
|
||||
const pointField& pointLst = mesh.points();
|
||||
const edgeList& edgeLst = mesh.edges();
|
||||
|
||||
fileName baseName = filename.lessExt();
|
||||
|
||||
writePoints(OFstream(baseName + ".vrt")(), pointLst);
|
||||
writeLines(OFstream(baseName + ".cel")(), edgeLst);
|
||||
|
||||
// write a simple .inp file
|
||||
writeCase
|
||||
(
|
||||
OFstream(baseName + ".inp")(),
|
||||
pointLst,
|
||||
edgeLst.size()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
159
src/edgeMesh/edgeFormats/starcd/STARCDedgeFormat.H
Normal file
159
src/edgeMesh/edgeFormats/starcd/STARCDedgeFormat.H
Normal file
@ -0,0 +1,159 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2009-2009 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::fileFormats::STARCDedgeFormat
|
||||
|
||||
Description
|
||||
Read/write the lines from pro-STAR vrt/cel files.
|
||||
|
||||
Note
|
||||
Uses the extension @a .inp (input) to denote the format.
|
||||
|
||||
See Also
|
||||
Foam::meshReaders::STARCD
|
||||
|
||||
SourceFiles
|
||||
STARCDedgeFormat.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef STARCDedgeFormat_H
|
||||
#define STARCDedgeFormat_H
|
||||
|
||||
#include "edgeMesh.H"
|
||||
#include "IFstream.H"
|
||||
#include "Ostream.H"
|
||||
#include "OFstream.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace fileFormats
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class STARCDedgeFormat Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class STARCDedgeFormat
|
||||
:
|
||||
public edgeMesh
|
||||
{
|
||||
// Private Data
|
||||
|
||||
//- STAR-CD identifier for line shapes (1d elements)
|
||||
static const int starcdLineShape_ = 2;
|
||||
|
||||
//- STAR-CD identifier for line type
|
||||
static const int starcdLineType_ = 5;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
static inline void writeLines
|
||||
(
|
||||
Ostream&,
|
||||
const edgeList&
|
||||
);
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
STARCDedgeFormat(const STARCDedgeFormat&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const STARCDedgeFormat&);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
static bool readHeader(IFstream&, const word&);
|
||||
|
||||
static void writeHeader(Ostream&, const char* filetype);
|
||||
|
||||
static bool readPoints(IFstream&, pointField&, labelList& ids);
|
||||
|
||||
static void writePoints(Ostream&, const pointField&);
|
||||
|
||||
static void writeCase
|
||||
(
|
||||
Ostream&,
|
||||
const pointField&,
|
||||
const label nEdges
|
||||
);
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from file name
|
||||
STARCDedgeFormat(const fileName&);
|
||||
|
||||
|
||||
// Selectors
|
||||
|
||||
//- Read file and return edgeMesh
|
||||
static autoPtr<edgeMesh> New(const fileName& name)
|
||||
{
|
||||
return autoPtr<edgeMesh>
|
||||
(
|
||||
new STARCDedgeFormat(name)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~STARCDedgeFormat()
|
||||
{}
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Write edge mesh
|
||||
static void write(const fileName&, const edgeMesh&);
|
||||
|
||||
//- Read from file
|
||||
virtual bool read(const fileName&);
|
||||
|
||||
//- Write object
|
||||
virtual void write(const fileName& name) const
|
||||
{
|
||||
write(name, *this);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace fileFormats
|
||||
} // End namespace Foam
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
61
src/edgeMesh/edgeFormats/starcd/STARCDedgeFormatRunTime.C
Normal file
61
src/edgeMesh/edgeFormats/starcd/STARCDedgeFormatRunTime.C
Normal file
@ -0,0 +1,61 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2009-2009 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 "STARCDedgeFormat.H"
|
||||
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "addToMemberFunctionSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace fileFormats
|
||||
{
|
||||
|
||||
// read edgeMesh
|
||||
addNamedToRunTimeSelectionTable
|
||||
(
|
||||
edgeMesh,
|
||||
STARCDedgeFormat,
|
||||
fileExtension,
|
||||
inp
|
||||
);
|
||||
|
||||
// write edgeMesh
|
||||
addNamedToMemberFunctionSelectionTable
|
||||
(
|
||||
edgeMesh,
|
||||
STARCDedgeFormat,
|
||||
write,
|
||||
fileExtension,
|
||||
inp
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// ************************************************************************* //
|
||||
107
src/edgeMesh/edgeFormats/vtk/VTKedgeFormat.C
Normal file
107
src/edgeMesh/edgeFormats/vtk/VTKedgeFormat.C
Normal file
@ -0,0 +1,107 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2009-2009 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 "VTKedgeFormat.H"
|
||||
#include "OFstream.H"
|
||||
#include "clock.H"
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::fileFormats::VTKedgeFormat::writeHeader
|
||||
(
|
||||
Ostream& os,
|
||||
const pointField& pointLst
|
||||
)
|
||||
{
|
||||
// Write header
|
||||
os << "# vtk DataFile Version 2.0" << nl
|
||||
<< "featureEdgeMesh written " << clock::dateTime().c_str() << nl
|
||||
<< "ASCII" << nl
|
||||
<< nl
|
||||
<< "DATASET POLYDATA" << nl;
|
||||
|
||||
// Write vertex coords
|
||||
os << "POINTS " << pointLst.size() << " float" << nl;
|
||||
forAll(pointLst, ptI)
|
||||
{
|
||||
const point& pt = pointLst[ptI];
|
||||
|
||||
os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::fileFormats::VTKedgeFormat::writeEdges
|
||||
(
|
||||
Ostream& os,
|
||||
const UList<edge>& edgeLst
|
||||
)
|
||||
{
|
||||
os << "LINES " << edgeLst.size() << ' '
|
||||
<< 3*edgeLst.size() << nl;
|
||||
|
||||
forAll(edgeLst, edgeI)
|
||||
{
|
||||
const edge& e = edgeLst[edgeI];
|
||||
|
||||
os << "2 " << e[0] << ' ' << e[1] << nl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::fileFormats::VTKedgeFormat::VTKedgeFormat()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::fileFormats::VTKedgeFormat::write
|
||||
(
|
||||
const fileName& filename,
|
||||
const edgeMesh& eMesh
|
||||
)
|
||||
{
|
||||
OFstream os(filename);
|
||||
if (!os.good())
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"fileFormats::VTKedgeFormat::write"
|
||||
"(const fileName&, const edgeMesh&)"
|
||||
)
|
||||
<< "Cannot open file for writing " << filename
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
writeHeader(os, eMesh.points());
|
||||
writeEdges(os, eMesh.edges());
|
||||
}
|
||||
|
||||
// ************************************************************************* //
|
||||
116
src/edgeMesh/edgeFormats/vtk/VTKedgeFormat.H
Normal file
116
src/edgeMesh/edgeFormats/vtk/VTKedgeFormat.H
Normal file
@ -0,0 +1,116 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2009-2009 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::fileFormats::VTKedgeFormat
|
||||
|
||||
Description
|
||||
Provide a means of writing VTK legacy format.
|
||||
|
||||
SourceFiles
|
||||
VTKedgeFormat.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef VTKedgeFormat_H
|
||||
#define VTKedgeFormat_H
|
||||
|
||||
#include "edgeMesh.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace fileFormats
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class VTKedgeFormat Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class VTKedgeFormat
|
||||
:
|
||||
public edgeMesh
|
||||
{
|
||||
// Private Member Functions
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
VTKedgeFormat(const VTKedgeFormat&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const VTKedgeFormat&);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- Write header information with points
|
||||
static void writeHeader
|
||||
(
|
||||
Ostream&,
|
||||
const pointField&
|
||||
);
|
||||
|
||||
//- Write edges
|
||||
static void writeEdges(Ostream&, const UList<edge>&);
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
VTKedgeFormat();
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~VTKedgeFormat()
|
||||
{}
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
// Write
|
||||
|
||||
//- Write edgeMesh
|
||||
static void write(const fileName&, const edgeMesh&);
|
||||
|
||||
// //- Write object
|
||||
// virtual void write(Ostream& os) const
|
||||
// {
|
||||
// write(os, *this);
|
||||
// }
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace fileFormats
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
51
src/edgeMesh/edgeFormats/vtk/VTKedgeFormatRunTime.C
Normal file
51
src/edgeMesh/edgeFormats/vtk/VTKedgeFormatRunTime.C
Normal file
@ -0,0 +1,51 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2009-2009 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 "VTKedgeFormat.H"
|
||||
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "addToMemberFunctionSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace fileFormats
|
||||
{
|
||||
|
||||
addNamedToMemberFunctionSelectionTable
|
||||
(
|
||||
edgeMesh,
|
||||
VTKedgeFormat,
|
||||
write,
|
||||
fileExtension,
|
||||
vtk
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -26,6 +26,76 @@ License
|
||||
|
||||
#include "edgeMesh.H"
|
||||
#include "mergePoints.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "addToMemberFunctionSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
defineTypeNameAndDebug(edgeMesh, 0);
|
||||
defineRunTimeSelectionTable(edgeMesh, fileExtension);
|
||||
defineMemberFunctionSelectionTable(edgeMesh,write,fileExtension);
|
||||
}
|
||||
|
||||
Foam::wordHashSet Foam::edgeMesh::readTypes()
|
||||
{
|
||||
return wordHashSet(*fileExtensionConstructorTablePtr_);
|
||||
}
|
||||
|
||||
Foam::wordHashSet Foam::edgeMesh::writeTypes()
|
||||
{
|
||||
return wordHashSet(*writefileExtensionMemberFunctionTablePtr_);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::edgeMesh::canReadType
|
||||
(
|
||||
const word& ext,
|
||||
const bool verbose
|
||||
)
|
||||
{
|
||||
return checkSupport
|
||||
(
|
||||
readTypes(),
|
||||
ext,
|
||||
verbose,
|
||||
"reading"
|
||||
);
|
||||
}
|
||||
|
||||
bool Foam::edgeMesh::canWriteType
|
||||
(
|
||||
const word& ext,
|
||||
const bool verbose
|
||||
)
|
||||
{
|
||||
return checkSupport
|
||||
(
|
||||
writeTypes(),
|
||||
ext,
|
||||
verbose,
|
||||
"writing"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
bool Foam::edgeMesh::canRead
|
||||
(
|
||||
const fileName& name,
|
||||
const bool verbose
|
||||
)
|
||||
{
|
||||
word ext = name.ext();
|
||||
if (ext == "gz")
|
||||
{
|
||||
ext = name.lessExt().ext();
|
||||
}
|
||||
return canReadType(ext, verbose);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
@ -63,10 +133,10 @@ void Foam::edgeMesh::calcPointEdges() const
|
||||
forAll(edges_, edgeI)
|
||||
{
|
||||
const edge& e = edges_[edgeI];
|
||||
const label p0 = e[0];
|
||||
const label p1 = e[1];
|
||||
|
||||
label p0 = e[0];
|
||||
pointEdges[p0][nEdgesPerPoint[p0]++] = edgeI;
|
||||
label p1 = e[1];
|
||||
pointEdges[p1][nEdgesPerPoint[p1]++] = edgeI;
|
||||
}
|
||||
}
|
||||
@ -74,32 +144,102 @@ void Foam::edgeMesh::calcPointEdges() const
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
// construct from components
|
||||
Foam::edgeMesh::edgeMesh(const pointField& points, const edgeList& edges)
|
||||
Foam::edgeMesh::edgeMesh()
|
||||
:
|
||||
points_(points),
|
||||
edges_(edges)
|
||||
{}
|
||||
|
||||
|
||||
// construct as copy
|
||||
Foam::edgeMesh::edgeMesh(const edgeMesh& em)
|
||||
:
|
||||
points_(em.points_),
|
||||
edges_(em.edges_),
|
||||
points_(0),
|
||||
edges_(0),
|
||||
pointEdgesPtr_(NULL)
|
||||
{}
|
||||
|
||||
|
||||
Foam::edgeMesh::edgeMesh
|
||||
(
|
||||
const pointField& points,
|
||||
const edgeList& edges
|
||||
)
|
||||
:
|
||||
points_(points),
|
||||
edges_(edges),
|
||||
pointEdgesPtr_(NULL)
|
||||
{}
|
||||
|
||||
|
||||
Foam::edgeMesh::edgeMesh
|
||||
(
|
||||
const Xfer<pointField>& pointLst,
|
||||
const Xfer<edgeList>& edgeLst
|
||||
)
|
||||
:
|
||||
points_(0),
|
||||
edges_(0),
|
||||
pointEdgesPtr_(NULL)
|
||||
{
|
||||
points_.transfer(pointLst());
|
||||
edges_.transfer(edgeLst());
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::edgeMesh::~edgeMesh()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::edgeMesh::clear()
|
||||
{
|
||||
points_.clear();
|
||||
edges_.clear();
|
||||
pointEdgesPtr_.clear();
|
||||
}
|
||||
|
||||
|
||||
void Foam::edgeMesh::reset
|
||||
(
|
||||
const Xfer< pointField >& pointLst,
|
||||
const Xfer< edgeList >& edgeLst
|
||||
)
|
||||
{
|
||||
// Take over new primitive data.
|
||||
// Optimized to avoid overwriting data at all
|
||||
if (&pointLst)
|
||||
{
|
||||
points_.transfer(pointLst());
|
||||
}
|
||||
|
||||
if (&edgeLst)
|
||||
{
|
||||
edges_.transfer(edgeLst());
|
||||
|
||||
// connectivity likely changed
|
||||
pointEdgesPtr_.clear();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Foam::edgeMesh::transfer(edgeMesh& mesh)
|
||||
{
|
||||
points_.transfer(mesh.points_);
|
||||
edges_.transfer(mesh.edges_);
|
||||
pointEdgesPtr_ = mesh.pointEdgesPtr_;
|
||||
}
|
||||
|
||||
|
||||
Foam::Xfer< Foam::edgeMesh >
|
||||
Foam::edgeMesh::xfer()
|
||||
{
|
||||
return xferMove(*this);
|
||||
}
|
||||
|
||||
|
||||
Foam::label Foam::edgeMesh::regions(labelList& edgeRegion) const
|
||||
{
|
||||
edgeRegion.setSize(edges_.size());
|
||||
edgeRegion = -1;
|
||||
|
||||
label startEdgeI = 0;
|
||||
|
||||
label currentRegion = 0;
|
||||
|
||||
while (true)
|
||||
@ -159,6 +299,16 @@ Foam::label Foam::edgeMesh::regions(labelList& edgeRegion) const
|
||||
}
|
||||
|
||||
|
||||
void Foam::edgeMesh::scalePoints(const scalar scaleFactor)
|
||||
{
|
||||
// avoid bad scaling
|
||||
if (scaleFactor > 0 && scaleFactor != 1.0)
|
||||
{
|
||||
points_ *= scaleFactor;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::edgeMesh::mergePoints(const scalar mergeDist)
|
||||
{
|
||||
pointField newPoints;
|
||||
@ -180,7 +330,7 @@ void Foam::edgeMesh::mergePoints(const scalar mergeDist)
|
||||
|
||||
points_.transfer(newPoints);
|
||||
|
||||
// Renumber and make sure e[0] < e[1] (not really nessecary)
|
||||
// Renumber and make sure e[0] < e[1] (not really necessary)
|
||||
forAll(edges_, edgeI)
|
||||
{
|
||||
edge& e = edges_[edgeI];
|
||||
@ -243,7 +393,7 @@ void Foam::edgeMesh::operator=(const edgeMesh& rhs)
|
||||
{
|
||||
points_ = rhs.points_;
|
||||
edges_ = rhs.edges_;
|
||||
pointEdgesPtr_.reset(NULL);
|
||||
pointEdgesPtr_.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -26,7 +26,7 @@ Class
|
||||
Foam::edgeMesh
|
||||
|
||||
Description
|
||||
points connected by edges.
|
||||
Points connected by edges.
|
||||
|
||||
SourceFiles
|
||||
edgeMeshI.H
|
||||
@ -40,17 +40,33 @@ SourceFiles
|
||||
|
||||
#include "pointField.H"
|
||||
#include "edgeList.H"
|
||||
#include "edgeFormatsCore.H"
|
||||
#include "runTimeSelectionTables.H"
|
||||
#include "memberFunctionSelectionTables.H"
|
||||
#include "HashSet.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declaration of classes
|
||||
class Istream;
|
||||
class Ostream;
|
||||
|
||||
// Forward declaration of friend functions and operators
|
||||
class edgeMesh;
|
||||
Istream& operator>>(Istream&, edgeMesh&);
|
||||
Ostream& operator<<(Ostream&, const edgeMesh&);
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class edgeMesh Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class edgeMesh
|
||||
:
|
||||
public fileFormats::edgeFormatsCore
|
||||
{
|
||||
// Private data
|
||||
|
||||
@ -68,39 +84,179 @@ class edgeMesh
|
||||
//- Calculate point-edge addressing (inverse of edges)
|
||||
void calcPointEdges() const;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- Non-const access to global points
|
||||
inline pointField& storedPoints();
|
||||
|
||||
//- Non-const access to the edges
|
||||
inline edgeList& storedEdges();
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("edgeMesh");
|
||||
|
||||
// Static
|
||||
|
||||
//- Can we read this file format?
|
||||
static bool canRead(const fileName&, const bool verbose=false);
|
||||
|
||||
//- Can we read this file format?
|
||||
static bool canReadType(const word& ext, const bool verbose=false);
|
||||
|
||||
//- Can we write this file format type?
|
||||
static bool canWriteType(const word& ext, const bool verbose=false);
|
||||
|
||||
static wordHashSet readTypes();
|
||||
static wordHashSet writeTypes();
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
edgeMesh();
|
||||
|
||||
//- Construct from components
|
||||
edgeMesh(const pointField&, const edgeList&);
|
||||
|
||||
//- Construct from file
|
||||
edgeMesh(const fileName&);
|
||||
|
||||
//- Construct from Istream
|
||||
edgeMesh(Istream&);
|
||||
//- Construct by transferring components (points, edges).
|
||||
edgeMesh
|
||||
(
|
||||
const Xfer< pointField >&,
|
||||
const Xfer< edgeList >&
|
||||
);
|
||||
|
||||
//- Construct as copy
|
||||
edgeMesh(const edgeMesh&);
|
||||
|
||||
//- Construct from file name (uses extension to determine type)
|
||||
edgeMesh(const fileName&);
|
||||
|
||||
//- Construct from file name (uses extension to determine type)
|
||||
edgeMesh(const fileName&, const word& ext);
|
||||
|
||||
//- Construct from Istream
|
||||
edgeMesh(Istream&);
|
||||
|
||||
// Declare run-time constructor selection table
|
||||
|
||||
declareRunTimeSelectionTable
|
||||
(
|
||||
autoPtr,
|
||||
edgeMesh,
|
||||
fileExtension,
|
||||
(
|
||||
const fileName& name
|
||||
),
|
||||
(name)
|
||||
);
|
||||
|
||||
// Selectors
|
||||
|
||||
//- Select constructed from filename (explicit extension)
|
||||
static autoPtr<edgeMesh> New
|
||||
(
|
||||
const fileName&,
|
||||
const word& ext
|
||||
);
|
||||
|
||||
//- Select constructed from filename (implicit extension)
|
||||
static autoPtr<edgeMesh> New(const fileName&);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~edgeMesh();
|
||||
|
||||
|
||||
// Member Function Selectors
|
||||
|
||||
declareMemberFunctionSelectionTable
|
||||
(
|
||||
void,
|
||||
edgeMesh,
|
||||
write,
|
||||
fileExtension,
|
||||
(
|
||||
const fileName& name,
|
||||
const edgeMesh& mesh
|
||||
),
|
||||
(name, mesh)
|
||||
);
|
||||
|
||||
//- Write to file
|
||||
static void write(const fileName&, const edgeMesh&);
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Transfer the contents of the argument and annul the argument
|
||||
void transfer(edgeMesh&);
|
||||
|
||||
//- Transfer contents to the Xfer container
|
||||
Xfer< edgeMesh > xfer();
|
||||
|
||||
// Read
|
||||
|
||||
//- Read from file. Chooses reader based on explicit extension
|
||||
bool read(const fileName&, const word& ext);
|
||||
|
||||
//- Read from file. Chooses reader based on detected extension
|
||||
virtual bool read(const fileName&);
|
||||
|
||||
|
||||
// Access
|
||||
|
||||
//- Return points
|
||||
inline const pointField& points() const;
|
||||
|
||||
//- Return edges
|
||||
inline const edgeList& edges() const;
|
||||
|
||||
//- Return edges
|
||||
inline const labelListList& pointEdges() const;
|
||||
|
||||
//- Find connected regions. Set region number per edge.
|
||||
// Returns number of regions.
|
||||
label regions(labelList& edgeRegion) const;
|
||||
|
||||
|
||||
// Edit
|
||||
|
||||
//- Clear all storage
|
||||
virtual void clear();
|
||||
|
||||
//- Reset primitive data (points, edges)
|
||||
// Note, optimized to avoid overwriting data (with Xfer::null)
|
||||
virtual void reset
|
||||
(
|
||||
const Xfer< pointField >& points,
|
||||
const Xfer< edgeList >& edges
|
||||
);
|
||||
|
||||
//- Scale points. A non-positive factor is ignored
|
||||
virtual void scalePoints(const scalar);
|
||||
|
||||
//- Merge common points (points within mergeDist)
|
||||
void mergePoints(const scalar mergeDist);
|
||||
|
||||
|
||||
// Write
|
||||
|
||||
void writeStats(Ostream&) const;
|
||||
|
||||
// Write
|
||||
|
||||
//- Generic write routine. Chooses writer based on extension.
|
||||
virtual void write(const fileName& name) const
|
||||
{
|
||||
write(name, *this);
|
||||
}
|
||||
|
||||
|
||||
// Member Operators
|
||||
|
||||
inline void operator=(const edgeMesh&);
|
||||
@ -109,6 +265,7 @@ public:
|
||||
|
||||
friend Ostream& operator<<(Ostream&, const edgeMesh&);
|
||||
friend Istream& operator>>(Istream&, edgeMesh&);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -24,14 +24,14 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * //
|
||||
inline Foam::edgeMesh::edgeMesh(const edgeMesh& em)
|
||||
:
|
||||
points_(em.points_),
|
||||
edges_(em.edges_),
|
||||
pointEdgesPtr_(NULL)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
@ -58,15 +58,16 @@ inline const Foam::labelListList& Foam::edgeMesh::pointEdges() const
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
|
||||
inline Foam::pointField& Foam::edgeMesh::storedPoints()
|
||||
{
|
||||
return points_;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * * //
|
||||
inline Foam::edgeList& Foam::edgeMesh::storedEdges()
|
||||
{
|
||||
return edges_;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -25,42 +25,107 @@ License
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "edgeMesh.H"
|
||||
#include "IFstream.H"
|
||||
|
||||
#include "boundBox.H"
|
||||
#include "EMESHedgeFormat.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
// construct from file
|
||||
Foam::edgeMesh::edgeMesh(const fileName& fname)
|
||||
Foam::edgeMesh::edgeMesh
|
||||
(
|
||||
const fileName& name,
|
||||
const word& ext
|
||||
)
|
||||
:
|
||||
points_(0),
|
||||
edges_(0),
|
||||
pointEdgesPtr_(NULL)
|
||||
{
|
||||
IFstream is(fname);
|
||||
read(name, ext);
|
||||
}
|
||||
|
||||
if (is.good())
|
||||
|
||||
Foam::edgeMesh::edgeMesh(const fileName& name)
|
||||
:
|
||||
points_(0),
|
||||
edges_(0),
|
||||
pointEdgesPtr_(NULL)
|
||||
{
|
||||
read(name);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::edgeMesh::read(const fileName& name)
|
||||
{
|
||||
word ext = name.ext();
|
||||
if (ext == "gz")
|
||||
{
|
||||
is >> points_ >> edges_;
|
||||
fileName unzipName = name.lessExt();
|
||||
return read(unzipName, unzipName.ext());
|
||||
}
|
||||
else
|
||||
{
|
||||
FatalErrorIn("edgeMesh::edgeMesh(const fileName&)")
|
||||
<< "cannot open file " << fname
|
||||
<< abort(FatalError);
|
||||
return read(name, ext);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// construct from Istream
|
||||
Foam::edgeMesh::edgeMesh(Istream& is)
|
||||
:
|
||||
points_(is),
|
||||
edges_(is),
|
||||
pointEdgesPtr_(NULL)
|
||||
// Read from file in given format
|
||||
bool Foam::edgeMesh::read
|
||||
(
|
||||
const fileName& name,
|
||||
const word& ext
|
||||
)
|
||||
{
|
||||
// Check state of Istream
|
||||
is.check("edgeMesh::edgeMesh(Istream&)");
|
||||
// read via selector mechanism
|
||||
transfer(New(name, ext)());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void Foam::edgeMesh::write
|
||||
(
|
||||
const fileName& name,
|
||||
const edgeMesh& mesh
|
||||
)
|
||||
{
|
||||
if (debug)
|
||||
{
|
||||
Info<< "edgeMesh::write"
|
||||
"(const fileName&, const edgeMesh&) : "
|
||||
"writing to " << name
|
||||
<< endl;
|
||||
}
|
||||
|
||||
const word ext = name.ext();
|
||||
|
||||
writefileExtensionMemberFunctionTable::iterator mfIter =
|
||||
writefileExtensionMemberFunctionTablePtr_->find(ext);
|
||||
|
||||
if (mfIter == writefileExtensionMemberFunctionTablePtr_->end())
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"MeshedSurface::write"
|
||||
"(const fileName&, const MeshedSurface&)"
|
||||
) << "Unknown file extension " << ext << nl << nl
|
||||
<< "Valid types are :" << endl
|
||||
<< writefileExtensionMemberFunctionTablePtr_->sortedToc()
|
||||
<< exit(FatalError);
|
||||
}
|
||||
else
|
||||
{
|
||||
mfIter()(name, mesh);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::edgeMesh::writeStats(Ostream& os) const
|
||||
{
|
||||
os << "points : " << points().size() << nl;
|
||||
os << "edges : " << edges().size() << nl;
|
||||
os << "boundingBox : " << boundBox(this->points()) << endl;
|
||||
}
|
||||
|
||||
|
||||
@ -68,7 +133,7 @@ Foam::edgeMesh::edgeMesh(Istream& is)
|
||||
|
||||
Foam::Ostream& Foam::operator<<(Ostream& os, const edgeMesh& em)
|
||||
{
|
||||
os << em.points_ << nl << em.edges_ << endl;
|
||||
fileFormats::EMESHedgeFormat::write(os, em.points_, em.edges_);
|
||||
|
||||
// Check state of Ostream
|
||||
os.check("Ostream& operator<<(Ostream&, const edgeMesh&)");
|
||||
@ -79,7 +144,9 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const edgeMesh& em)
|
||||
|
||||
Foam::Istream& Foam::operator>>(Istream& is, edgeMesh& em)
|
||||
{
|
||||
is >> em.points_ >> em.edges_;
|
||||
fileFormats::EMESHedgeFormat::read(is, em.points_, em.edges_);
|
||||
|
||||
em.pointEdgesPtr_.clear();
|
||||
|
||||
// Check state of Istream
|
||||
is.check("Istream& operator>>(Istream&, edgeMesh&)");
|
||||
|
||||
65
src/edgeMesh/edgeMeshNew.C
Normal file
65
src/edgeMesh/edgeMeshNew.C
Normal file
@ -0,0 +1,65 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2009-2009 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 "edgeMesh.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
Foam::autoPtr< Foam::edgeMesh >
|
||||
Foam::edgeMesh::New(const fileName& name, const word& ext)
|
||||
{
|
||||
fileExtensionConstructorTable::iterator cstrIter =
|
||||
fileExtensionConstructorTablePtr_->find(ext);
|
||||
|
||||
if (cstrIter == fileExtensionConstructorTablePtr_->end())
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"edgeMesh<Face>::New(const fileName&, const word&) : "
|
||||
"constructing edgeMesh"
|
||||
) << "Unknown file extension " << ext << nl << nl
|
||||
<< "Valid types are :" << nl
|
||||
<< fileExtensionConstructorTablePtr_->sortedToc()
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
return autoPtr< edgeMesh >(cstrIter()(name));
|
||||
}
|
||||
|
||||
|
||||
Foam::autoPtr< Foam::edgeMesh >
|
||||
Foam::edgeMesh::New(const fileName& name)
|
||||
{
|
||||
word ext = name.ext();
|
||||
if (ext == "gz")
|
||||
{
|
||||
ext = name.lessExt().ext();
|
||||
}
|
||||
return New(name, ext);
|
||||
}
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -28,21 +28,7 @@ License
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
defineTypeNameAndDebug(featureEdgeMesh, 0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
|
||||
defineTypeNameAndDebug(Foam::featureEdgeMesh, 0);
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
@ -73,20 +59,6 @@ Foam::featureEdgeMesh::featureEdgeMesh(const IOobject& io)
|
||||
}
|
||||
|
||||
|
||||
//- Construct from components
|
||||
Foam::featureEdgeMesh::featureEdgeMesh
|
||||
(
|
||||
const IOobject& io,
|
||||
const pointField& points,
|
||||
const edgeList& edges
|
||||
)
|
||||
:
|
||||
regIOobject(io),
|
||||
edgeMesh(points, edges)
|
||||
{}
|
||||
|
||||
|
||||
// Construct as copy
|
||||
Foam::featureEdgeMesh::featureEdgeMesh
|
||||
(
|
||||
const IOobject& io,
|
||||
@ -98,24 +70,43 @@ Foam::featureEdgeMesh::featureEdgeMesh
|
||||
{}
|
||||
|
||||
|
||||
Foam::featureEdgeMesh::featureEdgeMesh
|
||||
(
|
||||
const IOobject& io,
|
||||
const Xfer< pointField >& pointLst,
|
||||
const Xfer< edgeList >& edgeLst
|
||||
)
|
||||
:
|
||||
regIOobject(io),
|
||||
edgeMesh(pointLst, edgeLst)
|
||||
{
|
||||
if
|
||||
(
|
||||
io.readOpt() == IOobject::MUST_READ
|
||||
|| (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
|
||||
)
|
||||
{
|
||||
readStream(typeName) >> *this;
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::featureEdgeMesh::readData(Istream& is)
|
||||
{
|
||||
is >> *this;
|
||||
is >> *this;
|
||||
return !is.bad();
|
||||
}
|
||||
|
||||
|
||||
bool Foam::featureEdgeMesh::writeData(Ostream& os) const
|
||||
{
|
||||
os << *this;
|
||||
os << *this;
|
||||
|
||||
return os.good();
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -45,7 +45,7 @@ namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class featureEdgeMesh Declaration
|
||||
Class featureEdgeMesh Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class featureEdgeMesh
|
||||
@ -56,25 +56,28 @@ class featureEdgeMesh
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("featureEdgeMesh");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct (read) given an IOobject
|
||||
featureEdgeMesh(const IOobject&);
|
||||
explicit featureEdgeMesh(const IOobject&);
|
||||
|
||||
//- Construct from featureEdgeMesh data
|
||||
//- Construct as copy
|
||||
explicit featureEdgeMesh(const IOobject&, const featureEdgeMesh&);
|
||||
|
||||
//- Construct by transferring components (points, edges)
|
||||
featureEdgeMesh
|
||||
(
|
||||
const IOobject&,
|
||||
const pointField&,
|
||||
const edgeList&
|
||||
const Xfer<pointField>&,
|
||||
const Xfer<edgeList>&
|
||||
);
|
||||
|
||||
//- Construct as copy
|
||||
featureEdgeMesh(const IOobject&, const featureEdgeMesh&);
|
||||
|
||||
//- Give precedence to the regIOobject write
|
||||
using regIOobject::write;
|
||||
|
||||
//- ReadData function required for regIOobject read operation
|
||||
virtual bool readData(Istream&);
|
||||
@ -34,6 +34,76 @@ License
|
||||
#include "PatchInteractionModel.H"
|
||||
#include "PostProcessingModel.H"
|
||||
|
||||
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
|
||||
|
||||
template<class ParcelType>
|
||||
void Foam::KinematicCloud<ParcelType>::preEvolve()
|
||||
{
|
||||
this->dispersion().cacheFields(true);
|
||||
forces_.cacheFields(true);
|
||||
}
|
||||
|
||||
|
||||
template<class ParcelType>
|
||||
void Foam::KinematicCloud<ParcelType>::evolveCloud()
|
||||
{
|
||||
autoPtr<interpolation<scalar> > rhoInterpolator =
|
||||
interpolation<scalar>::New
|
||||
(
|
||||
interpolationSchemes_,
|
||||
rho_
|
||||
);
|
||||
|
||||
autoPtr<interpolation<vector> > UInterpolator =
|
||||
interpolation<vector>::New
|
||||
(
|
||||
interpolationSchemes_,
|
||||
U_
|
||||
);
|
||||
|
||||
autoPtr<interpolation<scalar> > muInterpolator =
|
||||
interpolation<scalar>::New
|
||||
(
|
||||
interpolationSchemes_,
|
||||
mu_
|
||||
);
|
||||
|
||||
typename ParcelType::trackData td
|
||||
(
|
||||
*this,
|
||||
constProps_,
|
||||
rhoInterpolator(),
|
||||
UInterpolator(),
|
||||
muInterpolator(),
|
||||
g_.value()
|
||||
);
|
||||
|
||||
this->injection().inject(td);
|
||||
|
||||
if (coupled_)
|
||||
{
|
||||
resetSourceTerms();
|
||||
}
|
||||
|
||||
Cloud<ParcelType>::move(td);
|
||||
}
|
||||
|
||||
|
||||
template<class ParcelType>
|
||||
void Foam::KinematicCloud<ParcelType>::postEvolve()
|
||||
{
|
||||
if (debug)
|
||||
{
|
||||
this->writePositions();
|
||||
}
|
||||
|
||||
this->dispersion().cacheFields(false);
|
||||
forces_.cacheFields(false);
|
||||
|
||||
this->postProcessing().post();
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
template<class ParcelType>
|
||||
@ -62,6 +132,7 @@ Foam::KinematicCloud<ParcelType>::KinematicCloud
|
||||
)
|
||||
),
|
||||
constProps_(particleProperties_),
|
||||
active_(particleProperties_.lookup("active")),
|
||||
parcelTypeId_(readLabel(particleProperties_.lookup("parcelTypeId"))),
|
||||
coupled_(particleProperties_.lookup("coupled")),
|
||||
cellValueSourceCorrection_
|
||||
@ -179,75 +250,17 @@ void Foam::KinematicCloud<ParcelType>::resetSourceTerms()
|
||||
}
|
||||
|
||||
|
||||
template<class ParcelType>
|
||||
void Foam::KinematicCloud<ParcelType>::preEvolve()
|
||||
{
|
||||
this->dispersion().cacheFields(true);
|
||||
forces_.cacheFields(true);
|
||||
}
|
||||
|
||||
|
||||
template<class ParcelType>
|
||||
void Foam::KinematicCloud<ParcelType>::postEvolve()
|
||||
{
|
||||
if (debug)
|
||||
{
|
||||
this->writePositions();
|
||||
}
|
||||
|
||||
this->dispersion().cacheFields(false);
|
||||
forces_.cacheFields(false);
|
||||
|
||||
this->postProcessing().post();
|
||||
}
|
||||
|
||||
|
||||
template<class ParcelType>
|
||||
void Foam::KinematicCloud<ParcelType>::evolve()
|
||||
{
|
||||
preEvolve();
|
||||
|
||||
autoPtr<interpolation<scalar> > rhoInterpolator =
|
||||
interpolation<scalar>::New
|
||||
(
|
||||
interpolationSchemes_,
|
||||
rho_
|
||||
);
|
||||
|
||||
autoPtr<interpolation<vector> > UInterpolator =
|
||||
interpolation<vector>::New
|
||||
(
|
||||
interpolationSchemes_,
|
||||
U_
|
||||
);
|
||||
|
||||
autoPtr<interpolation<scalar> > muInterpolator =
|
||||
interpolation<scalar>::New
|
||||
(
|
||||
interpolationSchemes_,
|
||||
mu_
|
||||
);
|
||||
|
||||
typename ParcelType::trackData td
|
||||
(
|
||||
*this,
|
||||
constProps_,
|
||||
rhoInterpolator(),
|
||||
UInterpolator(),
|
||||
muInterpolator(),
|
||||
g_.value()
|
||||
);
|
||||
|
||||
this->injection().inject(td);
|
||||
|
||||
if (coupled_)
|
||||
if (active_)
|
||||
{
|
||||
resetSourceTerms();
|
||||
preEvolve();
|
||||
|
||||
evolveCloud();
|
||||
|
||||
postEvolve();
|
||||
}
|
||||
|
||||
Cloud<ParcelType>::move(td);
|
||||
|
||||
postEvolve();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -109,6 +109,9 @@ protected:
|
||||
//- Parcel constant properties
|
||||
typename ParcelType::constantProperties constProps_;
|
||||
|
||||
//- Cloud active flag
|
||||
const Switch active_;
|
||||
|
||||
//- Parcel type id - used to flag the type of parcels issued by this
|
||||
// cloud
|
||||
const label parcelTypeId_;
|
||||
@ -189,6 +192,9 @@ protected:
|
||||
//- Pre-evolve
|
||||
void preEvolve();
|
||||
|
||||
//- Evolve the cloud
|
||||
void evolveCloud();
|
||||
|
||||
//- Post-evolve
|
||||
void postEvolve();
|
||||
|
||||
@ -223,9 +229,6 @@ public:
|
||||
|
||||
// References to the mesh and databases
|
||||
|
||||
//- Return the parcel type id
|
||||
inline label parcelTypeId() const;
|
||||
|
||||
//- Return refernce to the mesh
|
||||
inline const fvMesh& mesh() const;
|
||||
|
||||
@ -237,14 +240,22 @@ public:
|
||||
constProps() const;
|
||||
|
||||
|
||||
//- Return coupled flag
|
||||
inline const Switch coupled() const;
|
||||
// Cloud data
|
||||
|
||||
//- Return cell value correction flag
|
||||
inline const Switch cellValueSourceCorrection() const;
|
||||
//- Return the active flag
|
||||
inline const Switch active() const;
|
||||
|
||||
//- Return refernce to the random object
|
||||
inline Random& rndGen();
|
||||
//- Return the parcel type id
|
||||
inline label parcelTypeId() const;
|
||||
|
||||
//- Return coupled flag
|
||||
inline const Switch coupled() const;
|
||||
|
||||
//- Return cell value correction flag
|
||||
inline const Switch cellValueSourceCorrection() const;
|
||||
|
||||
//- Return refernce to the random object
|
||||
inline Random& rndGen();
|
||||
|
||||
|
||||
// References to the carrier gas fields
|
||||
|
||||
@ -58,6 +58,13 @@ Foam::KinematicCloud<ParcelType>::constProps() const
|
||||
}
|
||||
|
||||
|
||||
template<class ParcelType>
|
||||
inline const Foam::Switch Foam::KinematicCloud<ParcelType>::active() const
|
||||
{
|
||||
return active_;
|
||||
}
|
||||
|
||||
|
||||
template<class ParcelType>
|
||||
inline const Foam::Switch Foam::KinematicCloud<ParcelType>::coupled() const
|
||||
{
|
||||
|
||||
@ -58,6 +58,87 @@ void Foam::ReactingCloud<ParcelType>::checkSuppliedComposition
|
||||
}
|
||||
|
||||
|
||||
template<class ParcelType>
|
||||
void Foam::ReactingCloud<ParcelType>::preEvolve()
|
||||
{
|
||||
ThermoCloud<ParcelType>::preEvolve();
|
||||
}
|
||||
|
||||
|
||||
template<class ParcelType>
|
||||
void Foam::ReactingCloud<ParcelType>::evolveCloud()
|
||||
{
|
||||
const volScalarField& T = this->carrierThermo().T();
|
||||
const volScalarField cp = this->carrierThermo().Cp();
|
||||
const volScalarField& p = this->carrierThermo().p();
|
||||
|
||||
autoPtr<interpolation<scalar> > rhoInterp = interpolation<scalar>::New
|
||||
(
|
||||
this->interpolationSchemes(),
|
||||
this->rho()
|
||||
);
|
||||
|
||||
autoPtr<interpolation<vector> > UInterp = interpolation<vector>::New
|
||||
(
|
||||
this->interpolationSchemes(),
|
||||
this->U()
|
||||
);
|
||||
|
||||
autoPtr<interpolation<scalar> > muInterp = interpolation<scalar>::New
|
||||
(
|
||||
this->interpolationSchemes(),
|
||||
this->mu()
|
||||
);
|
||||
|
||||
autoPtr<interpolation<scalar> > TInterp = interpolation<scalar>::New
|
||||
(
|
||||
this->interpolationSchemes(),
|
||||
T
|
||||
);
|
||||
|
||||
autoPtr<interpolation<scalar> > cpInterp = interpolation<scalar>::New
|
||||
(
|
||||
this->interpolationSchemes(),
|
||||
cp
|
||||
);
|
||||
|
||||
autoPtr<interpolation<scalar> > pInterp = interpolation<scalar>::New
|
||||
(
|
||||
this->interpolationSchemes(),
|
||||
p
|
||||
);
|
||||
|
||||
typename ParcelType::trackData td
|
||||
(
|
||||
*this,
|
||||
constProps_,
|
||||
rhoInterp(),
|
||||
UInterp(),
|
||||
muInterp(),
|
||||
TInterp(),
|
||||
cpInterp(),
|
||||
pInterp(),
|
||||
this->g().value()
|
||||
);
|
||||
|
||||
this->injection().inject(td);
|
||||
|
||||
if (this->coupled())
|
||||
{
|
||||
resetSourceTerms();
|
||||
}
|
||||
|
||||
Cloud<ParcelType>::move(td);
|
||||
}
|
||||
|
||||
|
||||
template<class ParcelType>
|
||||
void Foam::ReactingCloud<ParcelType>::postEvolve()
|
||||
{
|
||||
ThermoCloud<ParcelType>::postEvolve();
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
template<class ParcelType>
|
||||
@ -181,88 +262,17 @@ void Foam::ReactingCloud<ParcelType>::resetSourceTerms()
|
||||
}
|
||||
|
||||
|
||||
template<class ParcelType>
|
||||
void Foam::ReactingCloud<ParcelType>::preEvolve()
|
||||
{
|
||||
ThermoCloud<ParcelType>::preEvolve();
|
||||
}
|
||||
|
||||
|
||||
template<class ParcelType>
|
||||
void Foam::ReactingCloud<ParcelType>::postEvolve()
|
||||
{
|
||||
ThermoCloud<ParcelType>::postEvolve();
|
||||
}
|
||||
|
||||
|
||||
template<class ParcelType>
|
||||
void Foam::ReactingCloud<ParcelType>::evolve()
|
||||
{
|
||||
preEvolve();
|
||||
|
||||
const volScalarField& T = this->carrierThermo().T();
|
||||
const volScalarField cp = this->carrierThermo().Cp();
|
||||
const volScalarField& p = this->carrierThermo().p();
|
||||
|
||||
autoPtr<interpolation<scalar> > rhoInterp = interpolation<scalar>::New
|
||||
(
|
||||
this->interpolationSchemes(),
|
||||
this->rho()
|
||||
);
|
||||
|
||||
autoPtr<interpolation<vector> > UInterp = interpolation<vector>::New
|
||||
(
|
||||
this->interpolationSchemes(),
|
||||
this->U()
|
||||
);
|
||||
|
||||
autoPtr<interpolation<scalar> > muInterp = interpolation<scalar>::New
|
||||
(
|
||||
this->interpolationSchemes(),
|
||||
this->mu()
|
||||
);
|
||||
|
||||
autoPtr<interpolation<scalar> > TInterp = interpolation<scalar>::New
|
||||
(
|
||||
this->interpolationSchemes(),
|
||||
T
|
||||
);
|
||||
|
||||
autoPtr<interpolation<scalar> > cpInterp = interpolation<scalar>::New
|
||||
(
|
||||
this->interpolationSchemes(),
|
||||
cp
|
||||
);
|
||||
|
||||
autoPtr<interpolation<scalar> > pInterp = interpolation<scalar>::New
|
||||
(
|
||||
this->interpolationSchemes(),
|
||||
p
|
||||
);
|
||||
|
||||
typename ParcelType::trackData td
|
||||
(
|
||||
*this,
|
||||
constProps_,
|
||||
rhoInterp(),
|
||||
UInterp(),
|
||||
muInterp(),
|
||||
TInterp(),
|
||||
cpInterp(),
|
||||
pInterp(),
|
||||
this->g().value()
|
||||
);
|
||||
|
||||
this->injection().inject(td);
|
||||
|
||||
if (this->coupled())
|
||||
if (this->active())
|
||||
{
|
||||
resetSourceTerms();
|
||||
preEvolve();
|
||||
|
||||
evolveCloud();
|
||||
|
||||
postEvolve();
|
||||
}
|
||||
|
||||
Cloud<ParcelType>::move(td);
|
||||
|
||||
postEvolve();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -137,6 +137,9 @@ protected:
|
||||
//- Pre-evolve
|
||||
void preEvolve();
|
||||
|
||||
//- Evolve the cloud
|
||||
void evolveCloud();
|
||||
|
||||
//- Post-evolve
|
||||
void postEvolve();
|
||||
|
||||
|
||||
@ -29,6 +29,89 @@ License
|
||||
#include "DevolatilisationModel.H"
|
||||
#include "SurfaceReactionModel.H"
|
||||
|
||||
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
|
||||
|
||||
template<class ParcelType>
|
||||
void Foam::ReactingMultiphaseCloud<ParcelType>::preEvolve()
|
||||
{
|
||||
ReactingCloud<ParcelType>::preEvolve();
|
||||
}
|
||||
|
||||
|
||||
template<class ParcelType>
|
||||
void Foam::ReactingMultiphaseCloud<ParcelType>::evolveCloud()
|
||||
{
|
||||
const volScalarField& T = this->carrierThermo().T();
|
||||
const volScalarField cp = this->carrierThermo().Cp();
|
||||
const volScalarField& p = this->carrierThermo().p();
|
||||
|
||||
autoPtr<interpolation<scalar> > rhoInterp = interpolation<scalar>::New
|
||||
(
|
||||
this->interpolationSchemes(),
|
||||
this->rho()
|
||||
);
|
||||
|
||||
autoPtr<interpolation<vector> > UInterp = interpolation<vector>::New
|
||||
(
|
||||
this->interpolationSchemes(),
|
||||
this->U()
|
||||
);
|
||||
|
||||
autoPtr<interpolation<scalar> > muInterp = interpolation<scalar>::New
|
||||
(
|
||||
this->interpolationSchemes(),
|
||||
this->mu()
|
||||
);
|
||||
|
||||
autoPtr<interpolation<scalar> > TInterp = interpolation<scalar>::New
|
||||
(
|
||||
this->interpolationSchemes(),
|
||||
T
|
||||
);
|
||||
|
||||
autoPtr<interpolation<scalar> > cpInterp = interpolation<scalar>::New
|
||||
(
|
||||
this->interpolationSchemes(),
|
||||
cp
|
||||
);
|
||||
|
||||
autoPtr<interpolation<scalar> > pInterp = interpolation<scalar>::New
|
||||
(
|
||||
this->interpolationSchemes(),
|
||||
p
|
||||
);
|
||||
|
||||
typename ParcelType::trackData td
|
||||
(
|
||||
*this,
|
||||
constProps_,
|
||||
rhoInterp(),
|
||||
UInterp(),
|
||||
muInterp(),
|
||||
TInterp(),
|
||||
cpInterp(),
|
||||
pInterp(),
|
||||
this->g().value()
|
||||
);
|
||||
|
||||
this->injection().inject(td);
|
||||
|
||||
if (this->coupled())
|
||||
{
|
||||
resetSourceTerms();
|
||||
}
|
||||
|
||||
Cloud<ParcelType>::move(td);
|
||||
}
|
||||
|
||||
|
||||
template<class ParcelType>
|
||||
void Foam::ReactingMultiphaseCloud<ParcelType>::postEvolve()
|
||||
{
|
||||
ReactingCloud<ParcelType>::postEvolve();
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
template<class ParcelType>
|
||||
@ -135,88 +218,17 @@ void Foam::ReactingMultiphaseCloud<ParcelType>::resetSourceTerms()
|
||||
}
|
||||
|
||||
|
||||
template<class ParcelType>
|
||||
void Foam::ReactingMultiphaseCloud<ParcelType>::preEvolve()
|
||||
{
|
||||
ReactingCloud<ParcelType>::preEvolve();
|
||||
}
|
||||
|
||||
|
||||
template<class ParcelType>
|
||||
void Foam::ReactingMultiphaseCloud<ParcelType>::postEvolve()
|
||||
{
|
||||
ReactingCloud<ParcelType>::postEvolve();
|
||||
}
|
||||
|
||||
|
||||
template<class ParcelType>
|
||||
void Foam::ReactingMultiphaseCloud<ParcelType>::evolve()
|
||||
{
|
||||
preEvolve();
|
||||
|
||||
const volScalarField& T = this->carrierThermo().T();
|
||||
const volScalarField cp = this->carrierThermo().Cp();
|
||||
const volScalarField& p = this->carrierThermo().p();
|
||||
|
||||
autoPtr<interpolation<scalar> > rhoInterp = interpolation<scalar>::New
|
||||
(
|
||||
this->interpolationSchemes(),
|
||||
this->rho()
|
||||
);
|
||||
|
||||
autoPtr<interpolation<vector> > UInterp = interpolation<vector>::New
|
||||
(
|
||||
this->interpolationSchemes(),
|
||||
this->U()
|
||||
);
|
||||
|
||||
autoPtr<interpolation<scalar> > muInterp = interpolation<scalar>::New
|
||||
(
|
||||
this->interpolationSchemes(),
|
||||
this->mu()
|
||||
);
|
||||
|
||||
autoPtr<interpolation<scalar> > TInterp = interpolation<scalar>::New
|
||||
(
|
||||
this->interpolationSchemes(),
|
||||
T
|
||||
);
|
||||
|
||||
autoPtr<interpolation<scalar> > cpInterp = interpolation<scalar>::New
|
||||
(
|
||||
this->interpolationSchemes(),
|
||||
cp
|
||||
);
|
||||
|
||||
autoPtr<interpolation<scalar> > pInterp = interpolation<scalar>::New
|
||||
(
|
||||
this->interpolationSchemes(),
|
||||
p
|
||||
);
|
||||
|
||||
typename ParcelType::trackData td
|
||||
(
|
||||
*this,
|
||||
constProps_,
|
||||
rhoInterp(),
|
||||
UInterp(),
|
||||
muInterp(),
|
||||
TInterp(),
|
||||
cpInterp(),
|
||||
pInterp(),
|
||||
this->g().value()
|
||||
);
|
||||
|
||||
this->injection().inject(td);
|
||||
|
||||
if (this->coupled())
|
||||
if (this->active())
|
||||
{
|
||||
resetSourceTerms();
|
||||
preEvolve();
|
||||
|
||||
evolveCloud();
|
||||
|
||||
postEvolve();
|
||||
}
|
||||
|
||||
Cloud<ParcelType>::move(td);
|
||||
|
||||
postEvolve();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -119,6 +119,9 @@ protected:
|
||||
//- Pre-evolve
|
||||
void preEvolve();
|
||||
|
||||
//- Evolve the cloud
|
||||
void evolveCloud();
|
||||
|
||||
//- Post-evolve
|
||||
void postEvolve();
|
||||
|
||||
|
||||
@ -30,6 +30,81 @@ License
|
||||
|
||||
#include "HeatTransferModel.H"
|
||||
|
||||
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
|
||||
|
||||
template<class ParcelType>
|
||||
void Foam::ThermoCloud<ParcelType>::preEvolve()
|
||||
{
|
||||
KinematicCloud<ParcelType>::preEvolve();
|
||||
}
|
||||
|
||||
|
||||
template<class ParcelType>
|
||||
void Foam::ThermoCloud<ParcelType>::evolveCloud()
|
||||
{
|
||||
const volScalarField& T = carrierThermo_.T();
|
||||
const volScalarField cp = carrierThermo_.Cp();
|
||||
|
||||
autoPtr<interpolation<scalar> > rhoInterp = interpolation<scalar>::New
|
||||
(
|
||||
this->interpolationSchemes(),
|
||||
this->rho()
|
||||
);
|
||||
|
||||
autoPtr<interpolation<vector> > UInterp = interpolation<vector>::New
|
||||
(
|
||||
this->interpolationSchemes(),
|
||||
this->U()
|
||||
);
|
||||
|
||||
autoPtr<interpolation<scalar> > muInterp = interpolation<scalar>::New
|
||||
(
|
||||
this->interpolationSchemes(),
|
||||
this->mu()
|
||||
);
|
||||
|
||||
autoPtr<interpolation<scalar> > TInterp = interpolation<scalar>::New
|
||||
(
|
||||
this->interpolationSchemes(),
|
||||
T
|
||||
);
|
||||
|
||||
autoPtr<interpolation<scalar> > cpInterp = interpolation<scalar>::New
|
||||
(
|
||||
this->interpolationSchemes(),
|
||||
cp
|
||||
);
|
||||
|
||||
typename ParcelType::trackData td
|
||||
(
|
||||
*this,
|
||||
constProps_,
|
||||
rhoInterp(),
|
||||
UInterp(),
|
||||
muInterp(),
|
||||
TInterp(),
|
||||
cpInterp(),
|
||||
this->g().value()
|
||||
);
|
||||
|
||||
this->injection().inject(td);
|
||||
|
||||
if (this->coupled())
|
||||
{
|
||||
resetSourceTerms();
|
||||
}
|
||||
|
||||
Cloud<ParcelType>::move(td);
|
||||
}
|
||||
|
||||
|
||||
template<class ParcelType>
|
||||
void Foam::ThermoCloud<ParcelType>::postEvolve()
|
||||
{
|
||||
KinematicCloud<ParcelType>::postEvolve();
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
template<class ParcelType>
|
||||
@ -149,80 +224,17 @@ void Foam::ThermoCloud<ParcelType>::resetSourceTerms()
|
||||
}
|
||||
|
||||
|
||||
template<class ParcelType>
|
||||
void Foam::ThermoCloud<ParcelType>::preEvolve()
|
||||
{
|
||||
KinematicCloud<ParcelType>::preEvolve();
|
||||
}
|
||||
|
||||
|
||||
template<class ParcelType>
|
||||
void Foam::ThermoCloud<ParcelType>::postEvolve()
|
||||
{
|
||||
KinematicCloud<ParcelType>::postEvolve();
|
||||
}
|
||||
|
||||
|
||||
template<class ParcelType>
|
||||
void Foam::ThermoCloud<ParcelType>::evolve()
|
||||
{
|
||||
preEvolve();
|
||||
|
||||
const volScalarField& T = carrierThermo_.T();
|
||||
const volScalarField cp = carrierThermo_.Cp();
|
||||
|
||||
autoPtr<interpolation<scalar> > rhoInterp = interpolation<scalar>::New
|
||||
(
|
||||
this->interpolationSchemes(),
|
||||
this->rho()
|
||||
);
|
||||
|
||||
autoPtr<interpolation<vector> > UInterp = interpolation<vector>::New
|
||||
(
|
||||
this->interpolationSchemes(),
|
||||
this->U()
|
||||
);
|
||||
|
||||
autoPtr<interpolation<scalar> > muInterp = interpolation<scalar>::New
|
||||
(
|
||||
this->interpolationSchemes(),
|
||||
this->mu()
|
||||
);
|
||||
|
||||
autoPtr<interpolation<scalar> > TInterp = interpolation<scalar>::New
|
||||
(
|
||||
this->interpolationSchemes(),
|
||||
T
|
||||
);
|
||||
|
||||
autoPtr<interpolation<scalar> > cpInterp = interpolation<scalar>::New
|
||||
(
|
||||
this->interpolationSchemes(),
|
||||
cp
|
||||
);
|
||||
|
||||
typename ParcelType::trackData td
|
||||
(
|
||||
*this,
|
||||
constProps_,
|
||||
rhoInterp(),
|
||||
UInterp(),
|
||||
muInterp(),
|
||||
TInterp(),
|
||||
cpInterp(),
|
||||
this->g().value()
|
||||
);
|
||||
|
||||
this->injection().inject(td);
|
||||
|
||||
if (this->coupled())
|
||||
if (this->active())
|
||||
{
|
||||
resetSourceTerms();
|
||||
preEvolve();
|
||||
|
||||
evolveCloud();
|
||||
|
||||
postEvolve();
|
||||
}
|
||||
|
||||
Cloud<ParcelType>::move(td);
|
||||
|
||||
postEvolve();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -125,6 +125,9 @@ protected:
|
||||
//- Pre-evolve
|
||||
void preEvolve();
|
||||
|
||||
//- Evolve the cloud
|
||||
void evolveCloud();
|
||||
|
||||
//- Post-evolve
|
||||
void postEvolve();
|
||||
|
||||
|
||||
@ -110,9 +110,6 @@ private:
|
||||
//- Disable setSize with value
|
||||
void setSize(const label, const Face&);
|
||||
|
||||
//- Read OpenFOAM Surface format
|
||||
bool read(Istream&);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
@ -198,9 +195,6 @@ public:
|
||||
//- Construct from file name (uses extension to determine type)
|
||||
UnsortedMeshedSurface(const fileName&, const word&);
|
||||
|
||||
//- Construct from Istream
|
||||
UnsortedMeshedSurface(Istream&);
|
||||
|
||||
//- Construct from objectRegistry and a named surface
|
||||
UnsortedMeshedSurface(const Time&, const word& surfName="");
|
||||
|
||||
|
||||
@ -31,7 +31,7 @@ License
|
||||
|
||||
void Foam::surfMesh::setInstance(const fileName& inst)
|
||||
{
|
||||
if (debug or true)
|
||||
if (debug)
|
||||
{
|
||||
Info<< "void surfMesh::setInstance(const fileName& inst) : "
|
||||
<< "Resetting file instance to " << inst << endl;
|
||||
|
||||
@ -42,7 +42,7 @@ int Foam::chemkinReader::yyBufSize = YY_BUF_SIZE;
|
||||
//! @cond dummy
|
||||
int yyFlexLexer::yylex()
|
||||
{
|
||||
Foam::FatalErrorIn("yyFlexLexer::yylex()")
|
||||
FatalErrorIn("yyFlexLexer::yylex()")
|
||||
<< "should not have called this function"
|
||||
<< abort(Foam::FatalError);
|
||||
|
||||
|
||||
@ -15,6 +15,8 @@ FoamFile
|
||||
}
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
active true;
|
||||
|
||||
InjectionModel ManualInjection;
|
||||
|
||||
DragModel SphereDrag;
|
||||
|
||||
@ -15,6 +15,8 @@ FoamFile
|
||||
}
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
active true;
|
||||
|
||||
InjectionModel ManualInjection;
|
||||
|
||||
DragModel SphereDrag;
|
||||
|
||||
@ -15,6 +15,8 @@ FoamFile
|
||||
}
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
active true;
|
||||
|
||||
InjectionModel ReactingLookupTableInjection;
|
||||
|
||||
DragModel SphereDrag;
|
||||
|
||||
@ -15,6 +15,8 @@ FoamFile
|
||||
}
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
active true;
|
||||
|
||||
InjectionModel ManualInjection;
|
||||
|
||||
DragModel SphereDrag;
|
||||
|
||||
@ -15,6 +15,8 @@ FoamFile
|
||||
}
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
active true;
|
||||
|
||||
InjectionModel PatchInjection;
|
||||
|
||||
DragModel SphereDrag;
|
||||
|
||||
@ -15,6 +15,8 @@ FoamFile
|
||||
}
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
active true;
|
||||
|
||||
InjectionModel ManualInjection;
|
||||
|
||||
DragModel SphereDrag;
|
||||
|
||||
@ -15,6 +15,8 @@ FoamFile
|
||||
}
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
active true;
|
||||
|
||||
InjectionModel ManualInjection;
|
||||
|
||||
DragModel SphereDrag;
|
||||
|
||||
@ -15,6 +15,8 @@ FoamFile
|
||||
}
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
active true;
|
||||
|
||||
InjectionModel ManualInjection;
|
||||
|
||||
DragModel SphereDrag;
|
||||
|
||||
@ -0,0 +1,49 @@
|
||||
/*--------------------------------*- C++ -*----------------------------------*\
|
||||
| ========= | |
|
||||
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
|
||||
| \\ / O peration | Version: 1.6 |
|
||||
| \\ / A nd | Web: www.OpenFOAM.org |
|
||||
| \\/ M anipulation | |
|
||||
\*---------------------------------------------------------------------------*/
|
||||
FoamFile
|
||||
{
|
||||
version 2.0;
|
||||
format ascii;
|
||||
class volVectorField;
|
||||
location "0";
|
||||
object U;
|
||||
}
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
dimensions [0 1 -1 0 0];
|
||||
|
||||
internalField uniform (0 0 20);
|
||||
|
||||
boundaryField
|
||||
{
|
||||
inlet
|
||||
{
|
||||
type fixedValue;
|
||||
value $internalField;
|
||||
}
|
||||
|
||||
outlet
|
||||
{
|
||||
type pressureInletOutletVelocity;
|
||||
phi phi;
|
||||
value $internalField;
|
||||
}
|
||||
|
||||
walls
|
||||
{
|
||||
type symmetryPlane;
|
||||
}
|
||||
|
||||
bullet
|
||||
{
|
||||
type fixedValue;
|
||||
value uniform (0 0 0);
|
||||
}
|
||||
}
|
||||
|
||||
// ************************************************************************* //
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user