mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: make "file" property in functionObjects a relative path (issue #1125)
- partial solution for issue #1091 This generates file properties that are case-relative, Eg, plane0 { p { file "<case>/postProcessing/plane0/1/p_plane0.vtk"; } U { file "<case>/postProcessing/plane0/1/U_plane0.vtk"; } } This allows the case to be moved elsewhere and still find its files. This functionality was previously added for vtkCloud, but now also applies to streamLine, sampledSets and sampledSurfaces
This commit is contained in:
@ -783,7 +783,11 @@ bool Foam::functionObjects::streamLineBase::writeToFile()
|
|||||||
for (const word& fieldName : scalarNames_)
|
for (const word& fieldName : scalarNames_)
|
||||||
{
|
{
|
||||||
dictionary propsDict;
|
dictionary propsDict;
|
||||||
propsDict.add("file", scalarVtkFile);
|
propsDict.add
|
||||||
|
(
|
||||||
|
"file",
|
||||||
|
scalarVtkFile.relative(time_.globalPath(), true)
|
||||||
|
);
|
||||||
setProperty(fieldName, propsDict);
|
setProperty(fieldName, propsDict);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -791,7 +795,11 @@ bool Foam::functionObjects::streamLineBase::writeToFile()
|
|||||||
for (const word& fieldName : vectorNames_)
|
for (const word& fieldName : vectorNames_)
|
||||||
{
|
{
|
||||||
dictionary propsDict;
|
dictionary propsDict;
|
||||||
propsDict.add("file", vectorVtkFile);
|
propsDict.add
|
||||||
|
(
|
||||||
|
"file",
|
||||||
|
vectorVtkFile.relative(time_.globalPath(), true)
|
||||||
|
);
|
||||||
setProperty(fieldName, propsDict);
|
setProperty(fieldName, propsDict);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
|
\\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd.
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -41,26 +41,6 @@ namespace runTimePostPro
|
|||||||
|
|
||||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||||
|
|
||||||
bool Foam::functionObjects::runTimePostPro::functionObjectBase::removeFile
|
|
||||||
(
|
|
||||||
const word& keyword,
|
|
||||||
const word& subDictName
|
|
||||||
)
|
|
||||||
{
|
|
||||||
dictionary dict;
|
|
||||||
state_.getObjectDict(functionObjectName_, subDictName, dict);
|
|
||||||
|
|
||||||
fileName fName;
|
|
||||||
if (dict.readIfPresent(keyword, fName))
|
|
||||||
{
|
|
||||||
Foam::rm(fName);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Foam::fileName
|
Foam::fileName
|
||||||
Foam::functionObjects::runTimePostPro::functionObjectBase::getFileName
|
Foam::functionObjects::runTimePostPro::functionObjectBase::getFileName
|
||||||
(
|
(
|
||||||
@ -71,7 +51,25 @@ Foam::functionObjects::runTimePostPro::functionObjectBase::getFileName
|
|||||||
dictionary dict;
|
dictionary dict;
|
||||||
state_.getObjectDict(functionObjectName_, subDictName, dict);
|
state_.getObjectDict(functionObjectName_, subDictName, dict);
|
||||||
|
|
||||||
return dict.lookupOrDefault<fileName>(keyword, fileName::null);
|
fileName f;
|
||||||
|
if (dict.readIfPresent<fileName>(keyword, f))
|
||||||
|
{
|
||||||
|
f.expand();
|
||||||
|
}
|
||||||
|
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Foam::functionObjects::runTimePostPro::functionObjectBase::removeFile
|
||||||
|
(
|
||||||
|
const word& keyword,
|
||||||
|
const word& subDictName
|
||||||
|
)
|
||||||
|
{
|
||||||
|
// Foam::rm() ignores empty names etc.
|
||||||
|
|
||||||
|
return Foam::rm(getFileName(keyword, subDictName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -91,12 +89,6 @@ Foam::functionObjects::runTimePostPro::functionObjectBase::functionObjectBase
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
Foam::functionObjects::runTimePostPro::functionObjectBase::~functionObjectBase()
|
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
bool Foam::functionObjects::runTimePostPro::functionObjectBase::clear()
|
bool Foam::functionObjects::runTimePostPro::functionObjectBase::clear()
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
|
\\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd.
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -62,17 +62,6 @@ class functionObjectBase
|
|||||||
:
|
:
|
||||||
public fieldVisualisationBase
|
public fieldVisualisationBase
|
||||||
{
|
{
|
||||||
private:
|
|
||||||
|
|
||||||
// Private Member Functions
|
|
||||||
|
|
||||||
//- No copy construct
|
|
||||||
functionObjectBase(const functionObjectBase&) = delete;
|
|
||||||
|
|
||||||
//- No copy assignment
|
|
||||||
void operator=(const functionObjectBase&) = delete;
|
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
// Protected data
|
// Protected data
|
||||||
@ -100,11 +89,11 @@ protected:
|
|||||||
// \verbatim
|
// \verbatim
|
||||||
// T
|
// T
|
||||||
// {
|
// {
|
||||||
// file "path/T_object.vtk";
|
// file "<case>/relpath/T_object.vtk";
|
||||||
// }
|
// }
|
||||||
// defaultCloud
|
// defaultCloud
|
||||||
// {
|
// {
|
||||||
// file "path/cloud_0001.vtp";
|
// file "<case>/relpath/cloud_0001.vtp";
|
||||||
// fields (T U);
|
// fields (T U);
|
||||||
// }
|
// }
|
||||||
// \endverbatim
|
// \endverbatim
|
||||||
@ -121,6 +110,12 @@ protected:
|
|||||||
bool removeFile(const word& keyword, const word& subDictName);
|
bool removeFile(const word& keyword, const word& subDictName);
|
||||||
|
|
||||||
|
|
||||||
|
//- No copy construct
|
||||||
|
functionObjectBase(const functionObjectBase&) = delete;
|
||||||
|
|
||||||
|
//- No copy assignment
|
||||||
|
void operator=(const functionObjectBase&) = delete;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//- Run-time type information
|
//- Run-time type information
|
||||||
@ -139,7 +134,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
//- Destructor
|
//- Destructor
|
||||||
virtual ~functionObjectBase();
|
virtual ~functionObjectBase() = default;
|
||||||
|
|
||||||
|
|
||||||
// Member Functions
|
// Member Functions
|
||||||
|
|||||||
@ -318,20 +318,14 @@ bool Foam::functionObjects::vtkCloud::writeCloud
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
// Shorten file name to be case-local and use "<case>" shortcut
|
||||||
|
// to make the content relocatable
|
||||||
dictionary propsDict;
|
dictionary propsDict;
|
||||||
|
propsDict.add
|
||||||
// Use case-local filename and "<case>" shortcut for readable output
|
(
|
||||||
// and for possibly relocation of files
|
"file",
|
||||||
|
file.relative(time_.globalPath(), true)
|
||||||
fileName fName(file.relative(time_.globalPath()));
|
);
|
||||||
if (fName.isAbsolute())
|
|
||||||
{
|
|
||||||
propsDict.add("file", fName);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
propsDict.add("file", "<case>"/fName);
|
|
||||||
}
|
|
||||||
propsDict.add("fields", written);
|
propsDict.add("fields", written);
|
||||||
|
|
||||||
setObjectProperty(name(), cloudName, propsDict);
|
setObjectProperty(name(), cloudName, propsDict);
|
||||||
|
|||||||
@ -338,10 +338,18 @@ void Foam::sampledSets::sampleAndWrite(fieldGroup<Type>& fields)
|
|||||||
Pstream::scatter(sampleFile);
|
Pstream::scatter(sampleFile);
|
||||||
if (sampleFile.size())
|
if (sampleFile.size())
|
||||||
{
|
{
|
||||||
|
// Shorten file name to be case-local and use "<case>" shortcut
|
||||||
|
// to make the content relocatable
|
||||||
|
|
||||||
forAll(masterFields, fieldi)
|
forAll(masterFields, fieldi)
|
||||||
{
|
{
|
||||||
dictionary propsDict;
|
dictionary propsDict;
|
||||||
propsDict.add("file", sampleFile);
|
propsDict.add
|
||||||
|
(
|
||||||
|
"file",
|
||||||
|
sampleFile.relative(time_.globalPath(), true)
|
||||||
|
);
|
||||||
|
|
||||||
const word& fieldName = masterFields[fieldi].name();
|
const word& fieldName = masterFields[fieldi].name();
|
||||||
setProperty(fieldName, propsDict);
|
setProperty(fieldName, propsDict);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -95,8 +95,15 @@ void Foam::sampledSurfaces::writeSurface
|
|||||||
Pstream::scatter(sampleFile);
|
Pstream::scatter(sampleFile);
|
||||||
if (sampleFile.size())
|
if (sampleFile.size())
|
||||||
{
|
{
|
||||||
|
// Shorten file name to be case-local and use "<case>" shortcut
|
||||||
|
// to make the content relocatable
|
||||||
|
|
||||||
dictionary propsDict;
|
dictionary propsDict;
|
||||||
propsDict.add("file", sampleFile);
|
propsDict.add
|
||||||
|
(
|
||||||
|
"file",
|
||||||
|
sampleFile.relative(time_.globalPath(), true)
|
||||||
|
);
|
||||||
setProperty(fieldName, propsDict);
|
setProperty(fieldName, propsDict);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -116,8 +123,15 @@ void Foam::sampledSurfaces::writeSurface
|
|||||||
s.interpolate()
|
s.interpolate()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Case-local filename and "<case>" shortcut for readable output
|
||||||
|
// and for possibly relocation of files
|
||||||
|
|
||||||
dictionary propsDict;
|
dictionary propsDict;
|
||||||
propsDict.add("file", fName);
|
propsDict.add
|
||||||
|
(
|
||||||
|
"file",
|
||||||
|
fName.relative(time_.globalPath(), true)
|
||||||
|
);
|
||||||
setProperty(fieldName, propsDict);
|
setProperty(fieldName, propsDict);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user