ENH: provide conversion to/from ccm meshes (issue #204)

This commit is contained in:
Mark Olesen
2016-08-08 12:50:26 +02:00
parent d8abc128f9
commit 95962d7780
36 changed files with 10262 additions and 0 deletions

View File

@ -0,0 +1,17 @@
#!/bin/sh
cd ${0%/*} || exit 1 # Run from this directory
# Parse arguments for compilation (at least for error catching)
. $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments
# Only build if libraries already exist
if [ -e $FOAM_LIBBIN/libccm.so ]
then
echo "Building optional ccm conversion components."
wmake $targetType ccmToFoam
wmake $targetType foamToCcm
else
echo "Skipping optional ccm conversion components (no libccm.so)."
fi
#------------------------------------------------------------------------------

View File

@ -0,0 +1,3 @@
ccmToFoam.C
EXE = $(FOAM_APPBIN)/ccmToFoam

View File

@ -0,0 +1,12 @@
EXE_INC = \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/conversion/lnInclude \
-I$(LIB_SRC)/conversion/ccm/lnInclude \
-I$(LIB_SRC)/fileFormats/lnInclude
EXE_LIBS = \
-lfiniteVolume \
-lgenericPatchFields \
-lmeshTools \
-lconversion -lccm

View File

@ -0,0 +1,314 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 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/>.
Application
ccmToFoam
Group
grpMeshConversionUtilities
Description
Reads CCM files as written by PROSTAR/STARCCM and writes an
OPENFOAM polyMesh.
Usage
\b ccmToFoam [OPTION] ccmMesh
Options:
- \par -ascii
Write in ASCII format instead of binary
- \par -export
re-export mesh in CCM format for post-processing
- \par -list
List some information about the geometry
- \par -name \<name\>
Provide alternative base name for export. Default is <tt>meshExport</tt>.
- \par -combine
Combine identically named patches
- \par -noBaffles
Remove any baffles by merging the faces.
- \par -merge
Merge in-place interfaces
- \par -numbered
Use numbered patch/zone (not names) directly from ccm ids.
- \par -remap \<name\>
use specified remapping dictionary instead of <tt>constant/remapping</tt>
- \par -scale \<factor\>
Specify an alternative geometry scaling factor.
The default is \b 1 (no scaling).
- \par -solids
Treat any solid cells present just like fluid cells.
The default is to remove them.
Note
- sub-domains (fluid | solid | porosity) are stored as separate domains
within the CCM file. These are merged together to form a single mesh.
- baffles are written as interfaces for later use
See also
Foam::ccm::reader for more information about the File Locations
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "Time.H"
#include "ccm.H"
#include "regionSplit.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
int main(int argc, char *argv[])
{
argList::addNote
(
"Reads CCM files as written by PROSTAR/STARCCM and writes an"
" OPENFOAM polyMesh."
);
argList::noParallel();
argList::validArgs.append("ccmMesh");
argList::addBoolOption
(
"ascii",
"write in ASCII format instead of binary"
);
argList::addBoolOption
(
"export",
"re-export mesh in CCM format for post-processing"
);
argList::addBoolOption
(
"list",
"list some information about the geometry"
);
argList::addOption
(
"remap",
"name",
"use specified remapping dictionary instead of <constant/remapping>"
);
argList::addOption
(
"name",
"name",
"provide alternative base name when re-exporting (implies -export). "
"Default is <meshExport>."
);
argList::addBoolOption
(
"combine",
"combine identically named patches"
);
argList::addBoolOption
(
"noBaffles",
"remove any baffles by merging the faces"
);
argList::addBoolOption
(
"merge",
"merge in-place interfaces"
);
argList::addBoolOption
(
"numbered",
"use numbered names (eg, patch_0, zone_0) only"
);
argList::addOption
(
"scale",
"scale",
"geometry scaling factor - default is 1 (ie, no scaling)"
);
argList::addBoolOption
(
"withSolid",
"treat any solid cells present just like fluid cells. "
"the default is to remove them."
);
argList args(argc, argv);
Time runTime(args.rootPath(), args.caseName());
runTime.functionObjects().off();
const bool optList = args.optionFound("list");
// exportName only has a size when export is in effect
fileName exportName;
if (args.optionReadIfPresent("name", exportName))
{
const word ext = exportName.ext();
// strip erroneous extension (.ccm, .ccmg, .ccmp)
if (ext == "ccm" || ext == "ccmg" || ext == "ccmp")
{
exportName = exportName.lessExt();
}
}
else if (args.optionFound("export"))
{
exportName = ccm::writer::defaultMeshName;
if (args.optionFound("case"))
{
exportName += '-' + args.globalCaseName();
}
}
// By default, no scaling
const scalar scaleFactor = args.optionLookupOrDefault("scale", 1.0);
// Default to binary output, unless otherwise specified
const IOstream::streamFormat format =
(
args.optionFound("ascii")
? IOstream::ASCII
: IOstream::BINARY
);
// Increase the precision of the points data
IOstream::defaultPrecision(max(10u, IOstream::defaultPrecision()));
// Read control options
// ~~~~~~~~~~~~~~~~~~~~
ccm::reader::options rOpts;
rOpts.removeBaffles(args.optionFound("noBaffles"));
rOpts.mergeInterfaces(args.optionFound("merge"));
if (args.optionFound("numbered"))
{
rOpts.useNumberedNames(true);
}
else if (args.optionFound("combine"))
{
rOpts.combineBoundaries(true);
}
if (args.optionFound("solids"))
{
Info<< "treating solids like fluids" << endl;
rOpts.keepSolid(true);
}
else
{
rOpts.keepSolid(false);
}
// CCM reader for reading geometry/solution
ccm::reader reader(args[1], rOpts);
// list the geometry information
if (optList)
{
Info<< "mesh geometry information:" << endl;
if (reader.hasGeometry())
{
Info<< nl << "cellTable:" << reader.cellTableInfo()
<< nl << "boundaryRegion:" << reader.boundaryTableInfo()
<< nl << "interfaces:" << reader.interfaceDefinitionsInfo()
<< endl;
if
(
args.optionFound("remap")
? reader.remapMeshInfo(runTime, args["remap"])
: reader.remapMeshInfo(runTime)
)
{
Info<< nl
<< "Remapped cellTable:" << reader.cellTableInfo() << nl
<< "Remapped boundaryRegion:" << reader.boundaryTableInfo()
<< endl;
}
}
else
{
Info<< "NONE" << endl;
}
return 0;
}
else if (reader.readGeometry(scaleFactor))
{
autoPtr<polyMesh> mesh =
(
args.optionFound("remap")
? reader.mesh(runTime, args["remap"])
: reader.mesh(runTime)
);
// report mesh bounding box information
Info<< nl << "Bounding box size: " << mesh().bounds().span() << nl;
// check number of regions
regionSplit rs(mesh);
Info<< "Number of regions: " << rs.nRegions();
if (rs.nRegions() == 1)
{
Info<< " (OK)." << nl;
}
else
{
Info<< nl << nl
<< "**************************************************" << nl
<< "** WARNING: the mesh has disconnected regions **" << nl
<< "**************************************************" << nl;
}
Info<< endl;
reader.writeMesh(mesh, format);
// exportName only has a size when export is in effect
if (exportName.size())
{
const fileName geomName = exportName + ".ccmg";
Info<< nl << "Re-exporting geometry as " << geomName << nl;
ccm::writer(geomName, mesh).writeGeometry();
}
}
else
{
FatalErrorIn("ccmToFoam")
<< "could not read geometry"
<< exit(FatalError);
}
Info<< "\nEnd\n" << endl;
return 0;
}
// ************************************************************************* //

View File

@ -0,0 +1,3 @@
foamToCcm.C
EXE = $(FOAM_APPBIN)/foamToCcm

View File

@ -0,0 +1,10 @@
EXE_INC = \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/conversion/lnInclude \
-I$(LIB_SRC)/conversion/ccm/lnInclude \
-I$(LIB_SRC)/fileFormats/lnInclude
EXE_LIBS = \
-lfiniteVolume \
-lgenericPatchFields \
-lconversion -lccm

View File

@ -0,0 +1,272 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 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/>.
Application
foamToCcm
Group
grpMeshConversionUtilities
Description
Translates OPENFOAM mesh and/or results to CCM format
Usage
\b foamToCcm [OPTION]
Options:
- \par -mesh
convert mesh only to CCM format
- \par -name \<name\>
Provide alternative base name. Default is <tt>meshExport</tt>.
- \par -overwrite
No backup of existing output files.
- \par -remap \<name\>
use specified remapping dictionary instead of <tt>constant/remapping</tt>
- \par -results
convert results only to CCM format
Note
- No parallel data
- No Lagrangian elements
- the -noZero time option can be useful to avoid the often incomplete
initial conditions (missing useful calculated values)
See also
Foam::ccm::writer for information about the
<tt>constant/remapping</tt> file.
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "timeSelector.H"
#include "volFields.H"
#include "OFstream.H"
#include "IOobjectList.H"
#include "scalarIOField.H"
#include "tensorIOField.H"
#include "ccm.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
argList::addNote
(
"Translate OPENFOAM data to CCM format"
);
Foam::timeSelector::addOptions();
argList::noParallel();
argList::addBoolOption
(
"mesh",
"convert mesh only"
);
argList::addOption
(
"name",
"name",
"provide alternative base name. Default is <meshExport>."
);
argList::addBoolOption
(
"overwrite",
"no backup of existing output files"
);
argList::addOption
(
"remap",
"name",
"use specified remapping dictionary instead of <constant/remapping>"
);
argList::addBoolOption
(
"results",
"convert results only"
);
#include "setRootCase.H"
#include "createTime.H"
runTime.functionObjects().off();
// get times list
instantList timeDirs = Foam::timeSelector::select0(runTime, args);
const bool optMesh = args.optionFound("mesh");
const bool optResults = args.optionFound("results");
const bool optOverwrite = args.optionFound("overwrite");
fileName exportName = ccm::writer::defaultMeshName;
if (args.optionReadIfPresent("name", exportName))
{
const word ext = exportName.ext();
// strip erroneous extension (.ccm, .ccmg, .ccmp)
if (ext == "ccm" || ext == "ccmg" || ext == "ccmp")
{
exportName = exportName.lessExt();
}
}
else if (args.optionFound("case"))
{
exportName += '-' + args.globalCaseName();
}
if (optMesh && optResults)
{
Warning
<< "\n-mesh and -results options are mutually exclusive\n"
<< endl;
args.printUsage();
FatalError.exit();
}
// // skip over time=0, unless some other time option has been specified
// if
// (
// !args.optionFound("zeroTime")
// && !args.optionFound("time")
// && !args.optionFound("latestTime")
// && Times.size() > 2
// )
// {
// startTime = 2;
// }
//
// runTime.setTime(Times[startTime], startTime);
runTime.setTime(timeDirs[0], 0);
if (optMesh)
{
// convert mesh only
#include "createPolyMesh.H"
forAll(timeDirs, timeI)
{
runTime.setTime(timeDirs[timeI], timeI);
#include "getTimeIndex.H"
if (timeI == 0)
{
ccm::writer writer
(
exportName + ".ccmg",
mesh,
!optOverwrite
);
writer.writeGeometry();
}
else if (mesh.moving())
{
ccm::writer writer
(
exportName + ".ccmg_" + timeName,
mesh,
!optOverwrite
);
writer.writeGeometry();
}
}
}
else
{
// convert fields with or without converting mesh
#include "createMesh.H"
// #include "checkHasMovingMesh.H"
// #include "checkHasLagrangian.H"
IOobjectList objects(mesh, timeDirs[timeDirs.size()-1].name());
// IOobjectList sprayObjects(mesh, Times[Times.size()-1].name(), "lagrangian");
forAll(timeDirs, timeI)
{
runTime.setTime(timeDirs[timeI], timeI);
#include "getTimeIndex.H"
Info<< "has "
<< mesh.nCells() << " cells, "
<< mesh.nPoints() << " points, "
<< mesh.boundaryMesh().size() << " patches"
<< endl;
if (!optResults)
{
if (timeI == 0)
{
ccm::writer writer
(
exportName + ".ccmg",
mesh,
!optOverwrite
);
writer.writeGeometry();
}
else if (mesh.moving())
{
ccm::writer writer
(
exportName + ".ccmg_" + timeName,
mesh,
!optOverwrite
);
writer.writeGeometry();
}
}
ccm::writer writer
(
exportName + ".ccmp_" + timeName,
mesh,
!optOverwrite
);
// writer.setTopologyFile(exportName + ".ccmg");
Info<< "writing solution:";
if (args.optionFound("remap"))
{
writer.writeSolution(objects, args["remap"]);
}
else
{
writer.writeSolution(objects);
}
}
}
Info<< "\nEnd\n" << endl;
return 0;
}
// ************************************************************************* //

View File

@ -0,0 +1,49 @@
// Read time index from */uniform/time, but treat 0 and constant specially
word timeName = "0";
if
(
runTime.timeName() != runTime.constant()
&& runTime.timeName() != "0"
)
{
IOobject io
(
"time",
runTime.timeName(),
"uniform",
runTime,
IOobject::READ_IF_PRESENT,
IOobject::NO_WRITE,
false
);
if (io.typeHeaderOk<IOdictionary>(true))
{
IOdictionary timeObject
(
IOobject
(
"time",
runTime.timeName(),
"uniform",
runTime,
IOobject::MUST_READ,
IOobject::NO_WRITE,
false
)
);
label index;
timeObject.lookup("index") >> index;
timeName = Foam::name(index);
}
else
{
timeName = runTime.timeName();
}
}
Info<< "\nTime [" << timeName << "] = " << runTime.timeName() << nl;