ENH: polyMesh: read_if_present support

This commit is contained in:
mattijs
2013-10-02 12:51:13 +01:00
parent 9594197f41
commit 7338ddbb7e
3 changed files with 38 additions and 23 deletions

View File

@ -309,7 +309,7 @@ public:
//- Construct from IOobject
explicit polyMesh(const IOobject& io);
//- Construct without boundary from components.
//- Construct from IOobject or from components.
// Boundary is added using addPatches() member function
polyMesh
(

View File

@ -70,20 +70,8 @@ void Foam::ZoneMesh<ZoneType, MeshType>::calcZoneMap() const
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// Read constructor given IOobject and a MeshType reference
template<class ZoneType, class MeshType>
Foam::ZoneMesh<ZoneType, MeshType>::ZoneMesh
(
const IOobject& io,
const MeshType& mesh
)
:
PtrList<ZoneType>(),
regIOobject(io),
mesh_(mesh),
zoneMapPtr_(NULL)
bool Foam::ZoneMesh<ZoneType, MeshType>::read()
{
if
(
@ -137,15 +125,36 @@ Foam::ZoneMesh<ZoneType, MeshType>::ZoneMesh
);
close();
return true;
}
else
{
// No files found. Force a write of zero-sized zones
// write();
// Nothing read
return false;
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// Read constructor given IOobject and a MeshType reference
template<class ZoneType, class MeshType>
Foam::ZoneMesh<ZoneType, MeshType>::ZoneMesh
(
const IOobject& io,
const MeshType& mesh
)
:
PtrList<ZoneType>(),
regIOobject(io),
mesh_(mesh),
zoneMapPtr_(NULL)
{
read();
}
// Construct given size. Zones will be set later
template<class ZoneType, class MeshType>
Foam::ZoneMesh<ZoneType, MeshType>::ZoneMesh
@ -159,13 +168,16 @@ Foam::ZoneMesh<ZoneType, MeshType>::ZoneMesh
regIOobject(io),
mesh_(mesh),
zoneMapPtr_(NULL)
{}
{
// Optionally read contents, otherwise keep size
read();
}
template<class ZoneType, class MeshType>
Foam::ZoneMesh<ZoneType, MeshType>::ZoneMesh
(
const IOobject& io ,
const IOobject& io,
const MeshType& mesh,
const PtrList<ZoneType>& pzm
)
@ -175,10 +187,9 @@ Foam::ZoneMesh<ZoneType, MeshType>::ZoneMesh
mesh_(mesh),
zoneMapPtr_(NULL)
{
ZoneMesh<ZoneType, MeshType>(io, mesh);
if (this->size() == 0)
if (!read())
{
// Nothing read. Use supplied zones
PtrList<ZoneType>& zones = *this;
zones.setSize(pzm.size());
forAll (zones, zoneI)
@ -188,6 +199,7 @@ Foam::ZoneMesh<ZoneType, MeshType>::ZoneMesh
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class ZoneType, class MeshType>

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -37,7 +37,7 @@ SourceFiles
#include "List.H"
#include "regIOobject.H"
#include "pointFieldsFwd.H"
#include "pointField.H"
#include "Map.H"
#include "PackedBoolList.H"
@ -76,6 +76,9 @@ class ZoneMesh
// Private Member Functions
//- Read if IOobject flags set. Return true if read.
bool read();
//- Disallow construct as copy
ZoneMesh(const ZoneMesh&);