Function1: Made Table and Constant readable in multiple formats
A typical Function1 entry can be read in one of three ways; with the
parameters in the current dictionary, in a separate sub-dict, or with
the entry itself as the dictionary; e.g.,
// Current-dictionary form
<entryName> sine;
amplitude 0.1;
frequency 10;
level 0.2;
// Coeff-dictionary form
<entryName> sine;
<entryName>Coeffs
{
amplitude 0.1;
frequency 10;
level 0.2;
}
// Entry-as-dictionary form
<entryName>
{
type sine;
amplitude 0.1;
frequency 10;
level 0.2;
}
The latter two sub-dictionary forms are needed when there are multiple
Function1 entries of the same type in a dictionary. Enclosing the
parameters in a separate sub-dictionary prevents the keywords (in this
case "amplitude", "frequency" and "level") from being duplicated.
Table and constant Function1 entries are different in that they have
special formats which allow the data to be appended directly to the
entry name; e.g;
<entryName> table ((0 (1 0 0)) (1 (2 0 0)));
<entryName> constant (1 0 0);
// (constant can even have the "constant" keyword omitted)
<entryName> (1 0 0);
Table also has two optional additional controls; "outOfBounds" and
"interpolationScheme". In order for these to be written out in such a
way that the entries are not duplicated, table needs to be written out
(and therefore also read in) as one of the sub-dictionary forms. To that
effect, Table has been extended to additionally permit reading in the
three forms described previously, and to write in the coeff-dictionary
form.
// Current-dictionary form
<entryName> table;
values ((0 (1 0 0)) (1 (2 0 0)));
outOfBounds repeat;
interpolationScheme linear;
// Coeff-dictionary form
<entryName> sine;
<entryName>Coeffs
{
values ((0 (1 0 0)) (1 (2 0 0)));
outOfBounds repeat;
interpolationScheme linear;
}
// Entry-as-dictionary form
<entryName>
{
type table;
values ((0 (1 0 0)) (1 (2 0 0)));
outOfBounds repeat;
interpolationScheme linear;
}
For completeness and consistency, constant has also been modified so
that it can read in these forms. However, constant has no additional
control entries, which means writing a coeff-dictionary is unecessary,
so the output has not been changed.
This commit is contained in:
@ -48,11 +48,25 @@ Foam::Function1s::Constant<Type>::Constant
|
||||
:
|
||||
FieldFunction1<Type, Constant<Type>>(entryName),
|
||||
value_(Zero)
|
||||
{
|
||||
if (!dict.found(entryName))
|
||||
{
|
||||
dict.lookup("value") >> value_;
|
||||
}
|
||||
else
|
||||
{
|
||||
Istream& is(dict.lookup(entryName));
|
||||
word entryType(is);
|
||||
if (is.eof())
|
||||
{
|
||||
dict.lookup("value") >> value_;
|
||||
}
|
||||
else
|
||||
{
|
||||
is >> value_;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
|
||||
@ -35,10 +35,25 @@ Foam::Function1s::Table<Type>::Table
|
||||
)
|
||||
:
|
||||
TableBase<Type, Table<Type>>(entryName, dict)
|
||||
{
|
||||
if (!dict.found(entryName))
|
||||
{
|
||||
dict.lookup("values") >> this->table_;
|
||||
}
|
||||
else
|
||||
{
|
||||
Istream& is(dict.lookup(entryName));
|
||||
word entryType(is);
|
||||
if (is.eof())
|
||||
{
|
||||
dict.lookup("values") >> this->table_;
|
||||
}
|
||||
else
|
||||
{
|
||||
is >> this->table_;
|
||||
}
|
||||
}
|
||||
|
||||
TableBase<Type, Table<Type>>::check();
|
||||
}
|
||||
|
||||
@ -79,11 +94,12 @@ Foam::Function1s::Table<Type>::~Table()
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
void Foam::Function1s::Table<Type>::writeData(Ostream& os) const
|
||||
void Foam::Function1s::Table<Type>::writeEntries(Ostream& os) const
|
||||
{
|
||||
Function1<Type>::writeData(os);
|
||||
os << nl << indent << this->table_ << token::END_STATEMENT << nl;
|
||||
TableBase<Type, Table<Type>>::writeCoeffDict(os);
|
||||
TableBase<Type, Table<Type>>::writeEntries(os);
|
||||
|
||||
os << indent << "values" << this->table_
|
||||
<< token::END_STATEMENT << endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -96,8 +96,8 @@ public:
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Write all table data in dictionary format
|
||||
virtual void writeData(Ostream& os) const;
|
||||
//- Write entries only in dictionary format
|
||||
virtual void writeEntries(Ostream& os) const;
|
||||
|
||||
|
||||
// Member Operators
|
||||
|
||||
@ -323,25 +323,6 @@ void Foam::Function1s::TableBase<Type, Function1Type>::writeEntries
|
||||
}
|
||||
|
||||
|
||||
template<class Type, class Function1Type>
|
||||
void Foam::Function1s::TableBase<Type, Function1Type>::writeCoeffDict
|
||||
(
|
||||
Ostream& os
|
||||
) const
|
||||
{
|
||||
OStringStream oss;
|
||||
writeEntries(oss);
|
||||
|
||||
if (oss.str().size())
|
||||
{
|
||||
os << indent << word(this->name() + "Coeffs") << nl;
|
||||
os << indent << token::BEGIN_BLOCK << incrIndent << nl;
|
||||
writeEntries(os);
|
||||
os << decrIndent << indent << token::END_BLOCK << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class Type, class Function1Type>
|
||||
void Foam::Function1s::TableBase<Type, Function1Type>::writeData
|
||||
(
|
||||
@ -350,7 +331,11 @@ void Foam::Function1s::TableBase<Type, Function1Type>::writeData
|
||||
{
|
||||
Function1<Type>::writeData(os);
|
||||
os << token::END_STATEMENT << nl;
|
||||
writeCoeffDict(os);
|
||||
|
||||
os << indent << word(this->name() + "Coeffs") << nl;
|
||||
os << indent << token::BEGIN_BLOCK << incrIndent << nl;
|
||||
writeEntries(os);
|
||||
os << decrIndent << indent << token::END_BLOCK << endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -143,9 +143,6 @@ public:
|
||||
//- Write entries only in dictionary format
|
||||
virtual void writeEntries(Ostream& os) const;
|
||||
|
||||
//- Write the coeff dict in dictionary format
|
||||
virtual void writeCoeffDict(Ostream& os) const;
|
||||
|
||||
//- Write all table data in dictionary format
|
||||
virtual void writeData(Ostream& os) const;
|
||||
|
||||
|
||||
@ -77,6 +77,7 @@ template<class Type>
|
||||
void Foam::Function1s::TableFile<Type>::writeEntries(Ostream& os) const
|
||||
{
|
||||
TableBase<Type, TableFile<Type>>::writeEntries(os);
|
||||
|
||||
writeEntry(os, "file", fName_);
|
||||
writeEntry(os, "format", reader_->type());
|
||||
reader_->write(os);
|
||||
|
||||
Reference in New Issue
Block a user