mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: paraFoam: catch read errors. Fixes #798.
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -276,11 +276,33 @@ void Foam::vtkPVFoam::convertVolFields
|
||||
|
||||
if (ioobj.headerClassName() == FieldType::typeName)
|
||||
{
|
||||
// Load field
|
||||
FieldType fld(ioobj, mesh);
|
||||
// Throw FatalError, FatalIOError as exceptions
|
||||
const bool throwingError = FatalError.throwExceptions();
|
||||
const bool throwingIOerr = FatalIOError.throwExceptions();
|
||||
|
||||
// Convert
|
||||
convertVolField(patchInterpList, fld);
|
||||
try
|
||||
{
|
||||
// Load field
|
||||
FieldType fld(ioobj, mesh);
|
||||
|
||||
// Convert
|
||||
convertVolField(patchInterpList, fld);
|
||||
}
|
||||
catch (Foam::IOerror& ioErr)
|
||||
{
|
||||
ioErr.write(Warning, false);
|
||||
Info << nl << endl;
|
||||
}
|
||||
catch (Foam::error& err)
|
||||
{
|
||||
// Bit of trickery to get the original message
|
||||
err.write(Warning, false);
|
||||
Info << nl << endl;
|
||||
}
|
||||
|
||||
// Restore previous exception throwing state
|
||||
FatalError.throwExceptions(throwingError);
|
||||
FatalIOError.throwExceptions(throwingIOerr);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -307,40 +329,62 @@ void Foam::vtkPVFoam::convertDimFields
|
||||
continue;
|
||||
}
|
||||
|
||||
// Load field
|
||||
FieldType dimFld(ioobj, mesh);
|
||||
// Throw FatalError, FatalIOError as exceptions
|
||||
const bool throwingError = FatalError.throwExceptions();
|
||||
const bool throwingIOerr = FatalIOError.throwExceptions();
|
||||
|
||||
// Construct volField with zero-gradient patch fields
|
||||
|
||||
IOobject io(dimFld);
|
||||
io.readOpt() = IOobject::NO_READ;
|
||||
|
||||
PtrList<fvPatchField<Type>> patchFields(mesh.boundary().size());
|
||||
forAll(patchFields, patchI)
|
||||
try
|
||||
{
|
||||
patchFields.set
|
||||
(
|
||||
patchI,
|
||||
fvPatchField<Type>::New
|
||||
// Load field
|
||||
FieldType dimFld(ioobj, mesh);
|
||||
|
||||
// Construct volField with zero-gradient patch fields
|
||||
|
||||
IOobject io(dimFld);
|
||||
io.readOpt() = IOobject::NO_READ;
|
||||
|
||||
PtrList<fvPatchField<Type>> patchFields(mesh.boundary().size());
|
||||
forAll(patchFields, patchI)
|
||||
{
|
||||
patchFields.set
|
||||
(
|
||||
zeroGradientFvPatchField<Type>::typeName,
|
||||
mesh.boundary()[patchI],
|
||||
dimFld
|
||||
)
|
||||
patchI,
|
||||
fvPatchField<Type>::New
|
||||
(
|
||||
zeroGradientFvPatchField<Type>::typeName,
|
||||
mesh.boundary()[patchI],
|
||||
dimFld
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
VolFieldType volFld
|
||||
(
|
||||
io,
|
||||
dimFld.mesh(),
|
||||
dimFld.dimensions(),
|
||||
dimFld,
|
||||
patchFields
|
||||
);
|
||||
volFld.correctBoundaryConditions();
|
||||
|
||||
convertVolField(patchInterpList, volFld);
|
||||
}
|
||||
catch (Foam::IOerror& ioErr)
|
||||
{
|
||||
ioErr.write(Warning, false);
|
||||
Info << nl << endl;
|
||||
}
|
||||
catch (Foam::error& err)
|
||||
{
|
||||
// Bit of trickery to get the original message
|
||||
err.write(Warning, false);
|
||||
Info << nl << endl;
|
||||
}
|
||||
|
||||
VolFieldType volFld
|
||||
(
|
||||
io,
|
||||
dimFld.mesh(),
|
||||
dimFld.dimensions(),
|
||||
dimFld,
|
||||
patchFields
|
||||
);
|
||||
volFld.correctBoundaryConditions();
|
||||
|
||||
convertVolField(patchInterpList, volFld);
|
||||
// Restore previous exception throwing state
|
||||
FatalError.throwExceptions(throwingError);
|
||||
FatalIOError.throwExceptions(throwingIOerr);
|
||||
}
|
||||
}
|
||||
|
||||
@ -421,31 +465,54 @@ void Foam::vtkPVFoam::convertAreaFields
|
||||
|
||||
if (ioobj.headerClassName() == FieldType::typeName)
|
||||
{
|
||||
// Load field
|
||||
FieldType fld(ioobj, mesh);
|
||||
// Throw FatalError, FatalIOError as exceptions
|
||||
const bool throwingError = FatalError.throwExceptions();
|
||||
const bool throwingIOerr = FatalIOError.throwExceptions();
|
||||
|
||||
// Convert
|
||||
for (const auto partId : partIds)
|
||||
try
|
||||
{
|
||||
const auto& longName = selectedPartIds_[partId];
|
||||
// Load field
|
||||
FieldType fld(ioobj, mesh);
|
||||
|
||||
auto iter = cachedVtp_.find(longName);
|
||||
if (!iter.found() || !iter.object().dataset)
|
||||
// Convert
|
||||
for (const auto partId : partIds)
|
||||
{
|
||||
// Should not happen, but for safety require a vtk geometry
|
||||
continue;
|
||||
const auto& longName = selectedPartIds_[partId];
|
||||
|
||||
auto iter = cachedVtp_.find(longName);
|
||||
if (!iter.found() || !iter.object().dataset)
|
||||
{
|
||||
// Should not happen, but for safety require a vtk
|
||||
// geometry
|
||||
continue;
|
||||
}
|
||||
|
||||
foamVtpData& vtpData = iter.object();
|
||||
auto dataset = vtpData.dataset;
|
||||
|
||||
vtkSmartPointer<vtkFloatArray> cdata = convertFieldToVTK
|
||||
(
|
||||
fld.name(),
|
||||
fld
|
||||
);
|
||||
dataset->GetCellData()->AddArray(cdata);
|
||||
}
|
||||
|
||||
foamVtpData& vtpData = iter.object();
|
||||
auto dataset = vtpData.dataset;
|
||||
|
||||
vtkSmartPointer<vtkFloatArray> cdata = convertFieldToVTK
|
||||
(
|
||||
fld.name(),
|
||||
fld
|
||||
);
|
||||
dataset->GetCellData()->AddArray(cdata);
|
||||
}
|
||||
catch (Foam::IOerror& ioErr)
|
||||
{
|
||||
ioErr.write(Warning, false);
|
||||
Info << nl << endl;
|
||||
}
|
||||
catch (Foam::error& err)
|
||||
{
|
||||
// Bit of trickery to get the original message
|
||||
err.write(Warning, false);
|
||||
Info << nl << endl;
|
||||
}
|
||||
|
||||
// Restore previous exception throwing state
|
||||
FatalError.throwExceptions(throwingError);
|
||||
FatalIOError.throwExceptions(throwingIOerr);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -483,91 +550,113 @@ void Foam::vtkPVFoam::convertPointFields
|
||||
Info<< "convertPointFields : " << fieldName << nl;
|
||||
}
|
||||
|
||||
FieldType pfld(ioobj, pMesh);
|
||||
// Throw FatalError, FatalIOError as exceptions
|
||||
const bool throwingError = FatalError.throwExceptions();
|
||||
const bool throwingIOerr = FatalIOError.throwExceptions();
|
||||
|
||||
convertPointFieldBlock(pfld, rangeVolume_); // internalMesh
|
||||
convertPointFieldBlock(pfld, rangeCellZones_); // cellZones
|
||||
convertPointFieldBlock(pfld, rangeCellSets_); // cellSets
|
||||
|
||||
// Patches - currently skip field conversion for groups
|
||||
for
|
||||
(
|
||||
const auto partId
|
||||
: rangePatches_.intersection(selectedPartIds_)
|
||||
)
|
||||
try
|
||||
{
|
||||
const auto& longName = selectedPartIds_[partId];
|
||||
FieldType pfld(ioobj, pMesh);
|
||||
|
||||
auto iter = cachedVtp_.find(longName);
|
||||
if (!iter.found() || !iter.object().dataset)
|
||||
{
|
||||
// Should not happen, but for safety require a vtk geometry
|
||||
continue;
|
||||
}
|
||||
convertPointFieldBlock(pfld, rangeVolume_); // internalMesh
|
||||
convertPointFieldBlock(pfld, rangeCellZones_); // cellZones
|
||||
convertPointFieldBlock(pfld, rangeCellSets_); // cellSets
|
||||
|
||||
foamVtpData& vtpData = iter.object();
|
||||
auto dataset = vtpData.dataset;
|
||||
|
||||
const labelList& patchIds = vtpData.additionalIds();
|
||||
if (patchIds.size() != 1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
const label patchId = patchIds[0];
|
||||
|
||||
vtkSmartPointer<vtkFloatArray> pdata = convertFieldToVTK
|
||||
// Patches - currently skip field conversion for groups
|
||||
for
|
||||
(
|
||||
fieldName,
|
||||
pfld.boundaryField()[patchId].patchInternalField()()
|
||||
);
|
||||
|
||||
dataset->GetPointData()->AddArray(pdata);
|
||||
}
|
||||
|
||||
// Face Zones
|
||||
for
|
||||
(
|
||||
const auto partId
|
||||
: rangeFaceZones_.intersection(selectedPartIds_)
|
||||
)
|
||||
{
|
||||
const auto& longName = selectedPartIds_[partId];
|
||||
const word zoneName = getFoamName(longName);
|
||||
|
||||
auto iter = cachedVtp_.find(longName);
|
||||
if (!iter.found() || !iter.object().dataset)
|
||||
const auto partId
|
||||
: rangePatches_.intersection(selectedPartIds_)
|
||||
)
|
||||
{
|
||||
// Should not happen, but for safety require a vtk geometry
|
||||
continue;
|
||||
}
|
||||
const auto& longName = selectedPartIds_[partId];
|
||||
|
||||
foamVtpData& vtpData = iter.object();
|
||||
auto dataset = vtpData.dataset;
|
||||
auto iter = cachedVtp_.find(longName);
|
||||
if (!iter.found() || !iter.object().dataset)
|
||||
{
|
||||
// Should not happen, but for safety require a vtk geometry
|
||||
continue;
|
||||
}
|
||||
|
||||
const label zoneId = mesh.faceZones().findZoneID(zoneName);
|
||||
foamVtpData& vtpData = iter.object();
|
||||
auto dataset = vtpData.dataset;
|
||||
|
||||
if (zoneId < 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
const labelList& patchIds = vtpData.additionalIds();
|
||||
if (patchIds.size() != 1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Extract the field on the zone
|
||||
Field<Type> znfld
|
||||
(
|
||||
pfld.primitiveField(),
|
||||
mesh.faceZones()[zoneId]().meshPoints()
|
||||
);
|
||||
const label patchId = patchIds[0];
|
||||
|
||||
vtkSmartPointer<vtkFloatArray> pdata =
|
||||
convertFieldToVTK
|
||||
vtkSmartPointer<vtkFloatArray> pdata = convertFieldToVTK
|
||||
(
|
||||
fieldName,
|
||||
znfld
|
||||
pfld.boundaryField()[patchId].patchInternalField()()
|
||||
);
|
||||
|
||||
dataset->GetPointData()->AddArray(pdata);
|
||||
dataset->GetPointData()->AddArray(pdata);
|
||||
}
|
||||
|
||||
// Face Zones
|
||||
for
|
||||
(
|
||||
const auto partId
|
||||
: rangeFaceZones_.intersection(selectedPartIds_)
|
||||
)
|
||||
{
|
||||
const auto& longName = selectedPartIds_[partId];
|
||||
const word zoneName = getFoamName(longName);
|
||||
|
||||
auto iter = cachedVtp_.find(longName);
|
||||
if (!iter.found() || !iter.object().dataset)
|
||||
{
|
||||
// Should not happen, but for safety require a vtk geometry
|
||||
continue;
|
||||
}
|
||||
|
||||
foamVtpData& vtpData = iter.object();
|
||||
auto dataset = vtpData.dataset;
|
||||
|
||||
const label zoneId = mesh.faceZones().findZoneID(zoneName);
|
||||
|
||||
if (zoneId < 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Extract the field on the zone
|
||||
Field<Type> znfld
|
||||
(
|
||||
pfld.primitiveField(),
|
||||
mesh.faceZones()[zoneId]().meshPoints()
|
||||
);
|
||||
|
||||
vtkSmartPointer<vtkFloatArray> pdata =
|
||||
convertFieldToVTK
|
||||
(
|
||||
fieldName,
|
||||
znfld
|
||||
);
|
||||
|
||||
dataset->GetPointData()->AddArray(pdata);
|
||||
}
|
||||
}
|
||||
catch (Foam::IOerror& ioErr)
|
||||
{
|
||||
ioErr.write(Warning, false);
|
||||
Info << nl << endl;
|
||||
}
|
||||
catch (Foam::error& err)
|
||||
{
|
||||
// Bit of trickery to get the original message
|
||||
err.write(Warning, false);
|
||||
Info << nl << endl;
|
||||
}
|
||||
|
||||
// Restore previous exception throwing state
|
||||
FatalError.throwExceptions(throwingError);
|
||||
FatalIOError.throwExceptions(throwingIOerr);
|
||||
}
|
||||
}
|
||||
|
||||
@ -735,18 +824,40 @@ void Foam::vtkPVFoam::convertLagrangianFields
|
||||
|
||||
if (ioobj.headerClassName() == IOField<Type>::typeName)
|
||||
{
|
||||
IOField<Type> fld(ioobj);
|
||||
// Throw FatalError, FatalIOError as exceptions
|
||||
const bool throwingError = FatalError.throwExceptions();
|
||||
const bool throwingIOerr = FatalIOError.throwExceptions();
|
||||
|
||||
vtkSmartPointer<vtkFloatArray> data =
|
||||
convertFieldToVTK
|
||||
(
|
||||
ioobj.name(),
|
||||
fld
|
||||
);
|
||||
try
|
||||
{
|
||||
IOField<Type> fld(ioobj);
|
||||
|
||||
// Provide identical data as cell and as point data
|
||||
vtkmesh->GetCellData()->AddArray(data);
|
||||
vtkmesh->GetPointData()->AddArray(data);
|
||||
vtkSmartPointer<vtkFloatArray> data =
|
||||
convertFieldToVTK
|
||||
(
|
||||
ioobj.name(),
|
||||
fld
|
||||
);
|
||||
|
||||
// Provide identical data as cell and as point data
|
||||
vtkmesh->GetCellData()->AddArray(data);
|
||||
vtkmesh->GetPointData()->AddArray(data);
|
||||
}
|
||||
catch (Foam::IOerror& ioErr)
|
||||
{
|
||||
ioErr.write(Warning, false);
|
||||
Info << nl << endl;
|
||||
}
|
||||
catch (Foam::error& err)
|
||||
{
|
||||
// Bit of trickery to get the original message
|
||||
err.write(Warning, false);
|
||||
Info << nl << endl;
|
||||
}
|
||||
|
||||
// Restore previous exception throwing state
|
||||
FatalError.throwExceptions(throwingError);
|
||||
FatalIOError.throwExceptions(throwingIOerr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,7 +46,6 @@ wmake $targetType genericPatchFields
|
||||
conversion/Allwmake $targetType $*
|
||||
wmake $targetType mesh/extrudeModel
|
||||
wmake $targetType dynamicMesh
|
||||
wmake $targetType sampling
|
||||
wmake $targetType dynamicFvMesh
|
||||
wmake $targetType sampling
|
||||
wmake $targetType topoChangerFvMesh
|
||||
|
||||
@ -260,34 +260,43 @@ void Foam::IOerror::abort()
|
||||
}
|
||||
|
||||
|
||||
Foam::Ostream& Foam::operator<<(Ostream& os, const IOerror& err)
|
||||
void Foam::IOerror::write(Ostream& os, const bool includeTitle) const
|
||||
{
|
||||
if (!os.bad())
|
||||
{
|
||||
os << nl
|
||||
<< err.title().c_str() << nl
|
||||
<< err.message().c_str() << nl << endl;
|
||||
|
||||
os << "file: " << err.ioFileName().c_str();
|
||||
|
||||
if (err.ioStartLineNumber() >= 0 && err.ioEndLineNumber() >= 0)
|
||||
os << nl;
|
||||
if (includeTitle)
|
||||
{
|
||||
os << " from line " << err.ioStartLineNumber()
|
||||
<< " to line " << err.ioEndLineNumber() << '.';
|
||||
os << title().c_str() << nl;
|
||||
}
|
||||
else if (err.ioStartLineNumber() >= 0)
|
||||
os << message().c_str() << nl << endl;
|
||||
|
||||
os << "file: " << ioFileName().c_str();
|
||||
|
||||
if (ioStartLineNumber() >= 0 && ioEndLineNumber() >= 0)
|
||||
{
|
||||
os << " at line " << err.ioStartLineNumber() << '.';
|
||||
os << " from line " << ioStartLineNumber()
|
||||
<< " to line " << ioEndLineNumber() << '.';
|
||||
}
|
||||
else if (ioStartLineNumber() >= 0)
|
||||
{
|
||||
os << " at line " << ioStartLineNumber() << '.';
|
||||
}
|
||||
|
||||
if (IOerror::level >= 2 && err.sourceFileLineNumber())
|
||||
if (IOerror::level >= 2 && sourceFileLineNumber())
|
||||
{
|
||||
os << nl << nl
|
||||
<< " From function " << err.functionName().c_str() << endl
|
||||
<< " in file " << err.sourceFileName().c_str()
|
||||
<< " at line " << err.sourceFileLineNumber() << '.';
|
||||
<< " From function " << functionName().c_str() << endl
|
||||
<< " in file " << sourceFileName().c_str()
|
||||
<< " at line " << sourceFileLineNumber() << '.';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Foam::Ostream& Foam::operator<<(Ostream& os, const IOerror& err)
|
||||
{
|
||||
err.write(os);
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2015-2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -320,6 +320,9 @@ public:
|
||||
//- Abort : used to stop code for fatal errors
|
||||
void abort();
|
||||
|
||||
//- Print error message
|
||||
void write(Ostream& os, const bool includeTitle = true) const;
|
||||
|
||||
|
||||
// Ostream operator
|
||||
|
||||
|
||||
Reference in New Issue
Block a user