Commit a43df3bd authored by Mark Olesen's avatar Mark Olesen
Browse files

added surfMesh, reworked MeshedSurface

- renamed surface regions (formerly patches or groups) to surfZone.

- added surfMesh, but without any of the patch information needed to make it
  useful for finiteArea.

- promoted coordinateSystem transformation to surfaceMeshConvert and moved
  old to surfaceMeshConvertTesting.
parent bf691545
surfaceCoordinateSystemTransform.C
EXE = $(FOAM_APPBIN)/surfaceCoordinateSystemTransform
EXE_INC = \
-I$(LIB_SRC)/triSurface/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/surfMesh/lnInclude
EXE_LIBS = -lsurfMesh
EXE_LIBS = -lmeshTools -lsurfMesh
......@@ -26,25 +26,30 @@ Application
surfaceMeshConvert
Description
Converts from one surface mesh format to another
Convert between surface formats with optional scaling or
transformations (rotate/translate) on a coordinateSystem.
Usage
- surfaceMeshConvert inputFile outputFile [OPTION]
@param -clean \n
Perform some surface checking/cleanup on the input surface
Perform some surface checking/cleanup on the input surface.
@param -scaleIn \<scale\> \n
Specify a scaling factor when reading files.
@param -orient \n
Check face orientation on the input surface
@param -scaleOut \<scale\> \n
Specify a scaling factor when writing files.
@param -scale \<scale\> \n
Specify a scaling factor for writing the files
@param -dict \<dictionary\> \n
Specify an alternative dictionary for constant/coordinateSystems.
@param -triSurface \n
Use triSurface library for input/output
@param -from \<coordinateSystem\> \n
Specify a coordinate System when reading files.
@param -keyed \n
Use keyedSurface for input/output
@param -to \<coordinateSystem\> \n
Specify a coordinate System when writing files.
Note
The filename extensions are used to determine the file format type.
......@@ -54,12 +59,9 @@ Note
#include "argList.H"
#include "timeSelector.H"
#include "Time.H"
#include "polyMesh.H"
#include "triSurface.H"
#include "PackedBoolList.H"
#include "MeshedSurfaces.H"
#include "UnsortedMeshedSurfaces.H"
#include "coordinateSystems.H"
using namespace Foam;
......@@ -71,24 +73,21 @@ int main(int argc, char *argv[])
argList::noParallel();
argList::validArgs.append("inputFile");
argList::validArgs.append("outputFile");
argList::validOptions.insert("clean", "");
argList::validOptions.insert("orient", "");
argList::validOptions.insert("scale", "scale");
argList::validOptions.insert("triSurface", "");
argList::validOptions.insert("unsorted", "");
argList::validOptions.insert("triFace", "");
# include "setRootCase.H"
argList::validOptions.insert("clean", "scale");
argList::validOptions.insert("scaleIn", "scale");
argList::validOptions.insert("scaleOut", "scale");
argList::validOptions.insert("dict", "coordinateSystemsDict");
argList::validOptions.insert("from", "sourceCoordinateSystem");
argList::validOptions.insert("to", "targetCoordinateSystem");
argList args(argc, argv);
Time runTime(args.rootPath(), args.caseName());
const stringList& params = args.additionalArgs();
scalar scaleFactor = 0;
if (args.options().found("scale"))
{
IStringStream(args.options()["scale"])() >> scaleFactor;
}
fileName importName(params[0]);
fileName exportName(params[1]);
// disable inplace editing
if (importName == exportName)
{
FatalErrorIn(args.executable())
......@@ -96,165 +95,157 @@ int main(int argc, char *argv[])
<< exit(FatalError);
}
// check that reading/writing is supported
if
(
!meshedSurface::canRead(importName, true)
|| !meshedSurface::canWriteType(exportName.ext(), true)
!MeshedSurface<face>::canRead(importName, true)
|| !MeshedSurface<face>::canWriteType(exportName.ext(), true)
)
{
return 1;
}
if (args.options().found("triSurface"))
{
triSurface surf(importName);
Info<< "Read surface:" << endl;
surf.writeStats(Info);
Info<< endl;
// get the coordinate transformations
autoPtr<coordinateSystem> fromCsys;
autoPtr<coordinateSystem> toCsys;
if (args.options().found("orient"))
{
Info<< "Checking surface orientation" << endl;
PatchTools::checkOrientation(surf, true);
Info<< endl;
}
if (args.options().found("clean"))
{
Info<< "Cleaning up surface" << endl;
surf.cleanup(true);
surf.writeStats(Info);
Info<< endl;
}
if (args.options().found("from") || args.options().found("to"))
{
autoPtr<IOobject> csDictIoPtr;
Info<< "writing " << exportName;
if (scaleFactor <= 0)
if (args.options().found("dict"))
{
Info<< " without scaling" << endl;
fileName dictPath(args.options()["dict"]);
csDictIoPtr.set
(
new IOobject
(
( dictPath.isDir() ? dictPath/coordinateSystems::typeName : dictPath ),
runTime,
IOobject::MUST_READ,
IOobject::NO_WRITE,
false
)
);
}
else
{
Info<< " with scaling " << scaleFactor << endl;
surf.scalePoints(scaleFactor);
surf.writeStats(Info);
Info<< endl;
csDictIoPtr.set
(
new IOobject
(
coordinateSystems::typeName,
runTime.constant(),
runTime,
IOobject::MUST_READ,
IOobject::NO_WRITE,
false
)
);
}
// write sorted by region
surf.write(exportName, true);
}
else if (args.options().found("unsorted"))
{
UnsortedMeshedSurface<face> surf(importName);
Info<< "Read surface:" << endl;
surf.writeStats(Info);
Info<< endl;
if (args.options().found("orient"))
if (!csDictIoPtr->headerOk())
{
Info<< "Checking surface orientation" << endl;
PatchTools::checkOrientation(surf, true);
Info<< endl;
FatalErrorIn(args.executable())
<< "Cannot open coordinateSystems file\n "
<< csDictIoPtr->objectPath() << nl
<< exit(FatalError);
}
if (args.options().found("clean"))
coordinateSystems csLst(csDictIoPtr());
if (args.options().found("from"))
{
Info<< "Cleaning up surface" << endl;
surf.cleanup(true);
surf.writeStats(Info);
Info<< endl;
const word csName(args.options()["from"]);
label csId = csLst.find(csName);
if (csId < 0)
{
FatalErrorIn(args.executable())
<< "Cannot find -from " << csName << nl
<< "available coordinateSystems: " << csLst.toc() << nl
<< exit(FatalError);
}
fromCsys.reset(new coordinateSystem(csLst[csId]));
}
Info<< "writing " << exportName;
if (scaleFactor <= 0)
if (args.options().found("to"))
{
Info<< " without scaling" << endl;
const word csName(args.options()["to"]);
label csId = csLst.find(csName);
if (csId < 0)
{
FatalErrorIn(args.executable())
<< "Cannot find -to " << csName << nl
<< "available coordinateSystems: " << csLst.toc() << nl
<< exit(FatalError);
}
toCsys.reset(new coordinateSystem(csLst[csId]));
}
else
// maybe fix this later
if (fromCsys.valid() && toCsys.valid())
{
Info<< " with scaling " << scaleFactor << endl;
surf.scalePoints(scaleFactor);
surf.writeStats(Info);
Info<< endl;
FatalErrorIn(args.executable())
<< "Only allowed '-from' or '-to' option at the moment."
<< exit(FatalError);
}
surf.write(exportName);
}
#if 1
else if (args.options().found("triFace"))
scalar scaleIn = 0;
scalar scaleOut = 0;
if (args.options().found("scaleIn"))
{
IStringStream(args.options()["scaleIn"])() >> scaleIn;
}
if (args.options().found("scaleOut"))
{
MeshedSurface<triFace> surf(importName);
IStringStream(args.options()["scaleOut"])() >> scaleOut;
}
Info<< "Read surface:" << endl;
surf.writeStats(Info);
Info<< endl;
if (args.options().found("orient"))
{
Info<< "Checking surface orientation" << endl;
PatchTools::checkOrientation(surf, true);
Info<< endl;
}
{
MeshedSurface<face> surf(importName);
if (args.options().found("clean"))
{
Info<< "Cleaning up surface" << endl;
surf.cleanup(true);
surf.writeStats(Info);
Info<< endl;
}
Info<< "writing " << exportName;
if (scaleFactor <= 0)
if (scaleIn > 0)
{
Info<< " without scaling" << endl;
Info<< " -scaleIn " << scaleIn << endl;
surf.scalePoints(scaleIn);
}
else
if (fromCsys.valid())
{
Info<< " with scaling " << scaleFactor << endl;
surf.scalePoints(scaleFactor);
surf.writeStats(Info);
Info<< endl;
Info<< " -from " << fromCsys().name() << endl;
tmp<pointField> tpf = fromCsys().localPosition(surf.points());
surf.movePoints(tpf());
}
surf.write(exportName);
}
#endif
else
{
MeshedSurface<face> surf(importName);
Info<< "Read surface:" << endl;
surf.writeStats(Info);
Info<< endl;
if (args.options().found("orient"))
if (toCsys.valid())
{
Info<< "Checking surface orientation" << endl;
PatchTools::checkOrientation(surf, true);
Info<< endl;
Info<< " -to " << toCsys().name() << endl;
tmp<pointField> tpf = toCsys().globalPosition(surf.points());
surf.movePoints(tpf());
}
if (args.options().found("clean"))
if (scaleOut > 0)
{
Info<< "Cleaning up surface" << endl;
surf.cleanup(true);
surf.writeStats(Info);
Info<< endl;
Info<< " -scaleOut " << scaleOut << endl;
surf.scalePoints(scaleOut);
}
Info<< "writing " << exportName;
if (scaleFactor <= 0)
{
Info<< " without scaling" << endl;
}
else
{
Info<< " with scaling " << scaleFactor << endl;
surf.scalePoints(scaleFactor);
surf.writeStats(Info);
Info<< endl;
}
surf.write(exportName);
}
......
surfaceMeshConvertTesting.C
EXE = $(FOAM_APPBIN)/surfaceMeshConvertTesting
EXE_INC = \
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/triSurface/lnInclude \
-I$(LIB_SRC)/surfMesh/lnInclude
EXE_LIBS = -lmeshTools -lsurfMesh
EXE_LIBS = -lsurfMesh
......@@ -23,33 +23,29 @@ License
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Application
surfaceMeshCoordinateSystemTransform
surfaceMeshConvertTesting
Description
Transform (scale/rotate/translate) a surface based on
a coordinateSystem.
Converts from one surface mesh format to another, but primarily
used for testing functionality.
Usage
- surfaceMeshCoordinateSystemTransform inputFile outputFile [OPTION]
- surfaceMeshConvertTesting inputFile outputFile [OPTION]
@param -clean \n
Perform some surface checking/cleanup on the input surface.
@param -scaleIn \<scale\> \n
Specify a scaling factor when reading files.
Perform some surface checking/cleanup on the input surface
@param -scaleOut \<scale\> \n
Specify a scaling factor when writing files.
@param -orient \n
Check face orientation on the input surface
@param -dict \<dictionary\> \n
Specify an alternative dictionary for coordinateSystems.
@param -scale \<scale\> \n
Specify a scaling factor for writing the files
@param -from \<coordinateSystem\> \n
Specify a coordinate System when reading files.
@param -triSurface \n
Use triSurface library for input/output
@param -to \<coordinateSystem\> \n
Specify a coordinate System when writing files.
@param -keyed \n
Use keyedSurface for input/output
Note
The filename extensions are used to determine the file format type.
......@@ -59,9 +55,14 @@ Note
#include "argList.H"
#include "timeSelector.H"
#include "Time.H"
#include "polyMesh.H"
#include "triSurface.H"
#include "surfMesh.H"
#include "surfFields.H"
#include "PackedBoolList.H"
#include "MeshedSurfaces.H"
#include "coordinateSystems.H"
#include "UnsortedMeshedSurfaces.H"
using namespace Foam;
......@@ -73,21 +74,25 @@ int main(int argc, char *argv[])
argList::noParallel();
argList::validArgs.append("inputFile");
argList::validArgs.append("outputFile");
argList::validOptions.insert("clean", "scale");
argList::validOptions.insert("scaleIn", "scale");
argList::validOptions.insert("scaleOut", "scale");
argList::validOptions.insert("dict", "coordinateSystemsDict");
argList::validOptions.insert("from", "sourceCoordinateSystem");
argList::validOptions.insert("to", "targetCoordinateSystem");
argList args(argc, argv);
Time runTime(args.rootPath(), args.caseName());
argList::validOptions.insert("clean", "");
argList::validOptions.insert("orient", "");
argList::validOptions.insert("surfMesh", "");
argList::validOptions.insert("scale", "scale");
argList::validOptions.insert("triSurface", "");
argList::validOptions.insert("unsorted", "");
argList::validOptions.insert("triFace", "");
# include "setRootCase.H"
const stringList& params = args.additionalArgs();
scalar scaleFactor = 0;
if (args.options().found("scale"))
{
IStringStream(args.options()["scale"])() >> scaleFactor;
}
fileName importName(params[0]);
fileName exportName(params[1]);
// disable inplace editing
if (importName == exportName)
{
FatalErrorIn(args.executable())
......@@ -95,158 +100,219 @@ int main(int argc, char *argv[])
<< exit(FatalError);
}
// check that reading/writing is supported
if
(
!MeshedSurface<face>::canRead(importName, true)
|| !MeshedSurface<face>::canWriteType(exportName.ext(), true)
!meshedSurface::canRead(importName, true)
|| !meshedSurface::canWriteType(exportName.ext(), true)
)
{
return 1;
}
if (args.options().found("triSurface"))
{
triSurface surf(importName);
// get the coordinate transformations
autoPtr<coordinateSystem> fromCsys;
autoPtr<coordinateSystem> toCsys;
Info<< "Read surface:" << endl;
surf.writeStats(Info);
Info<< endl;
if (args.options().found("from") || args.options().found("to"))
{
autoPtr<IOobject> csDictIoPtr;
if (args.options().found("orient"))
{
Info<< "Checking surface orientation" << endl;
PatchTools::checkOrientation(surf, true);
Info<< endl;
}
if (args.options().found("dict"))
if (args.options().found("clean"))
{
fileName dictPath(args.options()["dict"]);
Info<< "Cleaning up surface" << endl;
surf.cleanup(true);
surf.writeStats(Info);
Info<< endl;
}
csDictIoPtr.set
(
new IOobject
(
( dictPath.isDir() ? dictPath/coordinateSystems::typeName : dictPath ),
runTime,
IOobject::MUST_READ,
IOobject::NO_WRITE,
false
)
);
Info<< "writing " << exportName;
if (scaleFactor <= 0)
{
Info<< " without scaling" << endl;
}
else
{
csDictIoPtr.set
(
new IOobject
(
coordinateSystems::typeName,
runTime.constant(),
runTime,
IOobject::MUST_READ,
IOobject::NO_WRITE,
false
)
);
Info<< " with scaling " << scaleFactor << endl;
surf.scalePoints(scaleFactor);
surf.writeStats(Info);
Info<< endl;
}
// write sorted by region
surf.write(exportName, true);
}
else if (args.options().found("unsorted"))
{
UnsortedMeshedSurface<face> surf(importName);
Info<< "Read surface:" << endl;
surf.writeStats(Info);
Info<< endl;
if (!csDictIoPtr->headerOk())