Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Development
openfoam
Commits
9c694034
Commit
9c694034
authored
May 27, 2010
by
graham
Browse files
ENH. Adding IOFieldField and IOListList class and type definitions.
parent
2eee1666
Changes
24
Hide whitespace changes
Inline
Side-by-side
src/OpenFOAM/Make/files
View file @
9c694034
...
...
@@ -74,9 +74,13 @@ containers/LinkedLists/linkTypes/DLListBase/DLListBase.C
primitiveLists = primitives/Lists
$(primitiveLists)/boolList.C
$(primitiveLists)/labelIOList.C
$(primitiveLists)/labelListIOList.C
$(primitiveLists)/scalarList.C
$(primitiveLists)/scalarIOList.C
$(primitiveLists)/scalarListIOList.C
$(primitiveLists)/vectorList.C
$(primitiveLists)/vectorIOList.C
$(primitiveLists)/vectorListIOList.C
$(primitiveLists)/sphericalTensorList.C
$(primitiveLists)/symmTensorList.C
$(primitiveLists)/tensorList.C
...
...
@@ -486,9 +490,12 @@ $(Fields)/symmTensorField/symmTensorField.C
$(Fields)/tensorField/tensorField.C
$(Fields)/complexFields/complexFields.C
$(Fields)/labelField/labelIOField.C
$(Fields)/labelField/labelIOField.
$(Fields)/labelField/labelFieldIOField.C
$(Fields)/scalarField/scalarIOField.C
$(Fields)/scalarField/scalarFieldIOField.C
$(Fields)/vectorField/vectorIOField.C
$(Fields)/vectorField/vectorFieldIOField.C
$(Fields)/vector2DField/vector2DIOField.C
$(Fields)/sphericalTensorField/sphericalTensorIOField.C
$(Fields)/diagTensorField/diagTensorIOField.C
...
...
src/OpenFOAM/db/IOobjects/IOFieldField/IOFieldField.C
0 → 100644
View file @
9c694034
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2010-2010 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 3 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, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include
"IOFieldField.H"
#include
"labelList.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template
<
class
T
,
class
BaseType
>
void
Foam
::
IOFieldField
<
T
,
BaseType
>::
readFromStream
()
{
Istream
&
is
=
readStream
(
word
::
null
);
if
(
headerClassName
()
==
IOField
<
T
>::
typeName
)
{
is
>>
static_cast
<
Field
<
T
>&>
(
*
this
);
close
();
}
else
if
(
headerClassName
()
==
typeName
)
{
is
>>
*
this
;
close
();
}
else
{
FatalIOErrorIn
(
"IOFieldField<T, BaseType>::readFromStream()"
,
is
)
<<
"unexpected class name "
<<
headerClassName
()
<<
" expected "
<<
typeName
<<
" or "
<<
IOField
<
T
>::
typeName
<<
endl
<<
" while reading object "
<<
name
()
<<
exit
(
FatalIOError
);
}
}
// * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
template
<
class
T
,
class
BaseType
>
Foam
::
IOFieldField
<
T
,
BaseType
>::
IOFieldField
(
const
IOobject
&
io
)
:
regIOobject
(
io
)
{
if
(
io
.
readOpt
()
==
IOobject
::
MUST_READ
||
(
io
.
readOpt
()
==
IOobject
::
READ_IF_PRESENT
&&
headerOk
())
)
{
readFromStream
();
}
}
template
<
class
T
,
class
BaseType
>
Foam
::
IOFieldField
<
T
,
BaseType
>::
IOFieldField
(
const
IOobject
&
io
,
const
label
size
)
:
regIOobject
(
io
)
{
if
(
io
.
readOpt
()
==
IOobject
::
MUST_READ
||
(
io
.
readOpt
()
==
IOobject
::
READ_IF_PRESENT
&&
headerOk
())
)
{
readFromStream
();
}
else
{
Field
<
T
>::
setSize
(
size
);
}
}
template
<
class
T
,
class
BaseType
>
Foam
::
IOFieldField
<
T
,
BaseType
>::
IOFieldField
(
const
IOobject
&
io
,
const
Field
<
T
>&
list
)
:
regIOobject
(
io
)
{
if
(
io
.
readOpt
()
==
IOobject
::
MUST_READ
||
(
io
.
readOpt
()
==
IOobject
::
READ_IF_PRESENT
&&
headerOk
())
)
{
readFromStream
();
}
else
{
Field
<
T
>::
operator
=
(
list
);
}
}
template
<
class
T
,
class
BaseType
>
Foam
::
IOFieldField
<
T
,
BaseType
>::
IOFieldField
(
const
IOobject
&
io
,
const
Xfer
<
Field
<
T
>
>&
list
)
:
regIOobject
(
io
)
{
Field
<
T
>::
transfer
(
list
());
if
(
io
.
readOpt
()
==
IOobject
::
MUST_READ
||
(
io
.
readOpt
()
==
IOobject
::
READ_IF_PRESENT
&&
headerOk
())
)
{
readFromStream
();
}
}
// * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * //
template
<
class
T
,
class
BaseType
>
Foam
::
IOFieldField
<
T
,
BaseType
>::~
IOFieldField
()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template
<
class
T
,
class
BaseType
>
bool
Foam
::
IOFieldField
<
T
,
BaseType
>::
writeObject
(
IOstream
::
streamFormat
fmt
,
IOstream
::
versionNumber
ver
,
IOstream
::
compressionType
cmp
)
const
{
if
(
fmt
==
IOstream
::
ASCII
)
{
// Change type to be non-compact format type
const
word
oldTypeName
=
typeName
;
const_cast
<
word
&>
(
typeName
)
=
IOField
<
T
>::
typeName
;
bool
good
=
regIOobject
::
writeObject
(
fmt
,
ver
,
cmp
);
// Change type back
const_cast
<
word
&>
(
typeName
)
=
oldTypeName
;
return
good
;
}
else
{
return
regIOobject
::
writeObject
(
fmt
,
ver
,
cmp
);
}
}
template
<
class
T
,
class
BaseType
>
bool
Foam
::
IOFieldField
<
T
,
BaseType
>::
writeData
(
Ostream
&
os
)
const
{
return
(
os
<<
*
this
).
good
();
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template
<
class
T
,
class
BaseType
>
void
Foam
::
IOFieldField
<
T
,
BaseType
>::
operator
=
(
const
IOFieldField
<
T
,
BaseType
>&
rhs
)
{
Field
<
T
>::
operator
=
(
rhs
);
}
template
<
class
T
,
class
BaseType
>
void
Foam
::
IOFieldField
<
T
,
BaseType
>::
operator
=
(
const
Field
<
T
>&
rhs
)
{
Field
<
T
>::
operator
=
(
rhs
);
}
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
template
<
class
T
,
class
BaseType
>
Foam
::
Istream
&
Foam
::
operator
>>
(
Foam
::
Istream
&
is
,
Foam
::
IOFieldField
<
T
,
BaseType
>&
L
)
{
// Read compact
const
labelList
start
(
is
);
const
Field
<
BaseType
>
elems
(
is
);
// Convert
L
.
setSize
(
start
.
size
()
-
1
);
forAll
(
L
,
i
)
{
T
&
subField
=
L
[
i
];
label
index
=
start
[
i
];
subField
.
setSize
(
start
[
i
+
1
]
-
index
);
forAll
(
subField
,
j
)
{
subField
[
j
]
=
elems
[
index
++
];
}
}
return
is
;
}
template
<
class
T
,
class
BaseType
>
Foam
::
Ostream
&
Foam
::
operator
<<
(
Foam
::
Ostream
&
os
,
const
Foam
::
IOFieldField
<
T
,
BaseType
>&
L
)
{
// Keep ascii writing same.
if
(
os
.
format
()
==
IOstream
::
ASCII
)
{
os
<<
static_cast
<
const
Field
<
T
>&>
(
L
);
}
else
{
// Convert to compact format
labelList
start
(
L
.
size
()
+
1
);
start
[
0
]
=
0
;
for
(
label
i
=
1
;
i
<
start
.
size
();
i
++
)
{
start
[
i
]
=
start
[
i
-
1
]
+
L
[
i
-
1
].
size
();
}
Field
<
BaseType
>
elems
(
start
[
start
.
size
()
-
1
]);
label
elemI
=
0
;
forAll
(
L
,
i
)
{
const
T
&
subField
=
L
[
i
];
forAll
(
subField
,
j
)
{
elems
[
elemI
++
]
=
subField
[
j
];
}
}
os
<<
start
<<
elems
;
}
return
os
;
}
// ************************************************************************* //
src/OpenFOAM/db/IOobjects/IOFieldField/IOFieldField.H
0 → 100644
View file @
9c694034
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2010-2010 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 3 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, see <http://www.gnu.org/licenses/>.
Class
Foam::IOFieldField
Description
A Field of objects of type \<T\> with automated input and output.
SourceFiles
IOFieldField.C
\*---------------------------------------------------------------------------*/
#ifndef IOFieldField_H
#define IOFieldField_H
#include
"IOField.H"
#include
"regIOobject.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace
Foam
{
class
Istream
;
class
Ostream
;
// Forward declaration of friend functions and operators
template
<
class
T
,
class
BaseType
>
class
IOFieldField
;
template
<
class
T
,
class
BaseType
>
Istream
&
operator
>>
(
Istream
&
,
IOFieldField
<
T
,
BaseType
>&
);
template
<
class
T
,
class
BaseType
>
Ostream
&
operator
<<
(
Ostream
&
,
const
IOFieldField
<
T
,
BaseType
>&
);
/*---------------------------------------------------------------------------*\
Class IOFieldField Declaration
\*---------------------------------------------------------------------------*/
template
<
class
T
,
class
BaseType
>
class
IOFieldField
:
public
regIOobject
,
public
Field
<
T
>
{
// Private Member Functions
//- Read according to header type
void
readFromStream
();
public:
//- Runtime type information
TypeName
(
"FieldField"
);
// Constructors
//- Construct from IOobject
IOFieldField
(
const
IOobject
&
);
//- Construct from IOobject and size of IOFieldField
IOFieldField
(
const
IOobject
&
,
const
label
);
//- Construct from IOobject and a Field
IOFieldField
(
const
IOobject
&
,
const
Field
<
T
>&
);
//- Construct by transferring the Field contents
IOFieldField
(
const
IOobject
&
,
const
Xfer
<
Field
<
T
>
>&
);
// Destructor
virtual
~
IOFieldField
();
// Member functions
virtual
bool
writeObject
(
IOstream
::
streamFormat
,
IOstream
::
versionNumber
,
IOstream
::
compressionType
)
const
;
virtual
bool
writeData
(
Ostream
&
)
const
;
// Member operators
void
operator
=
(
const
IOFieldField
<
T
,
BaseType
>&
);
void
operator
=
(
const
Field
<
T
>&
);
// IOstream operators
//- Read Field from Istream, discarding contents of existing Field.
friend
Istream
&
operator
>>
<
T
,
BaseType
>
(
Istream
&
,
IOFieldField
<
T
,
BaseType
>&
);
// Write Field to Ostream.
friend
Ostream
&
operator
<<
<
T
,
BaseType
>
(
Ostream
&
,
const
IOFieldField
<
T
,
BaseType
>&
);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
}
// End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "IOFieldField.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
src/OpenFOAM/db/IOobjects/IOListList/IOListList.C
0 → 100644
View file @
9c694034
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2010-2010 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 3 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, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include
"IOListList.H"
#include
"labelList.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template
<
class
T
,
class
BaseType
>
void
Foam
::
IOListList
<
T
,
BaseType
>::
readFromStream
()
{
Istream
&
is
=
readStream
(
word
::
null
);
if
(
headerClassName
()
==
IOList
<
T
>::
typeName
)
{
is
>>
static_cast
<
List
<
T
>&>
(
*
this
);
close
();
}
else
if
(
headerClassName
()
==
typeName
)
{
is
>>
*
this
;
close
();
}
else
{
FatalIOErrorIn
(
"IOListList<T, BaseType>::readFromStream()"
,
is
)
<<
"unexpected class name "
<<
headerClassName
()
<<
" expected "
<<
typeName
<<
" or "
<<
IOList
<
T
>::
typeName
<<
endl
<<
" while reading object "
<<
name
()
<<
exit
(
FatalIOError
);
}
}
// * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
template
<
class
T
,
class
BaseType
>
Foam
::
IOListList
<
T
,
BaseType
>::
IOListList
(
const
IOobject
&
io
)
:
regIOobject
(
io
)
{
if
(
io
.
readOpt
()
==
IOobject
::
MUST_READ
||
(
io
.
readOpt
()
==
IOobject
::
READ_IF_PRESENT
&&
headerOk
())
)
{
readFromStream
();
}
}
template
<
class
T
,
class
BaseType
>
Foam
::
IOListList
<
T
,
BaseType
>::
IOListList
(
const
IOobject
&
io
,
const
label
size
)
:
regIOobject
(
io
)
{
if
(
io
.
readOpt
()
==
IOobject
::
MUST_READ
||
(
io
.
readOpt
()
==
IOobject
::
READ_IF_PRESENT
&&
headerOk
())
)
{
readFromStream
();
}
else
{
List
<
T
>::
setSize
(
size
);
}
}
template
<
class
T
,
class
BaseType
>
Foam
::
IOListList
<
T
,
BaseType
>::
IOListList
(
const
IOobject
&
io
,
const
List
<
T
>&
list
)
:
regIOobject
(
io
)
{
if
(
io
.
readOpt
()
==
IOobject
::
MUST_READ
||
(
io
.
readOpt
()
==
IOobject
::
READ_IF_PRESENT
&&
headerOk
())
)
{
readFromStream
();
}
else
{
List
<
T
>::
operator
=
(
list
);
}
}
template
<
class
T
,
class
BaseType
>
Foam
::
IOListList
<
T
,
BaseType
>::
IOListList
(
const
IOobject
&
io
,
const
Xfer
<
List
<
T
>
>&
list
)
:
regIOobject
(
io
)
{
List
<
T
>::
transfer
(
list
());
if
(
io
.
readOpt
()
==
IOobject
::
MUST_READ
||
(
io
.
readOpt
()
==
IOobject
::
READ_IF_PRESENT
&&
headerOk
())