surfaceMeshConvert.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 #include "argList.H"
00060 #include "timeSelector.H"
00061 #include "Time.H"
00062
00063 #include "MeshedSurfaces.H"
00064 #include "coordinateSystems.H"
00065
00066 using namespace Foam;
00067
00068
00069
00070
00071 int main(int argc, char *argv[])
00072 {
00073 argList::noParallel();
00074 argList::validArgs.append("inputFile");
00075 argList::validArgs.append("outputFile");
00076 argList::validOptions.insert("clean", "");
00077 argList::validOptions.insert("scaleIn", "scale");
00078 argList::validOptions.insert("scaleOut", "scale");
00079 argList::validOptions.insert("dict", "coordinateSystemsDict");
00080 argList::validOptions.insert("from", "sourceCoordinateSystem");
00081 argList::validOptions.insert("to", "targetCoordinateSystem");
00082
00083 argList args(argc, argv);
00084 Time runTime(args.rootPath(), args.caseName());
00085 const stringList& params = args.additionalArgs();
00086
00087 fileName importName(params[0]);
00088 fileName exportName(params[1]);
00089
00090
00091 if (importName == exportName)
00092 {
00093 FatalErrorIn(args.executable())
00094 << "Output file " << exportName << " would overwrite input file."
00095 << exit(FatalError);
00096 }
00097
00098
00099 if
00100 (
00101 !MeshedSurface<face>::canRead(importName, true)
00102 || !MeshedSurface<face>::canWriteType(exportName.ext(), true)
00103 )
00104 {
00105 return 1;
00106 }
00107
00108
00109
00110 autoPtr<coordinateSystem> fromCsys;
00111 autoPtr<coordinateSystem> toCsys;
00112
00113 if (args.optionFound("from") || args.optionFound("to"))
00114 {
00115 autoPtr<IOobject> csDictIoPtr;
00116
00117 if (args.optionFound("dict"))
00118 {
00119 fileName dictPath(args.option("dict"));
00120
00121 csDictIoPtr.set
00122 (
00123 new IOobject
00124 (
00125 (
00126 isDir(dictPath)
00127 ? dictPath/coordinateSystems::typeName
00128 : dictPath
00129 ),
00130 runTime,
00131 IOobject::MUST_READ,
00132 IOobject::NO_WRITE,
00133 false
00134 )
00135 );
00136 }
00137 else
00138 {
00139 csDictIoPtr.set
00140 (
00141 new IOobject
00142 (
00143 coordinateSystems::typeName,
00144 runTime.constant(),
00145 runTime,
00146 IOobject::MUST_READ,
00147 IOobject::NO_WRITE,
00148 false
00149 )
00150 );
00151 }
00152
00153
00154 if (!csDictIoPtr->headerOk())
00155 {
00156 FatalErrorIn(args.executable())
00157 << "Cannot open coordinateSystems file\n "
00158 << csDictIoPtr->objectPath() << nl
00159 << exit(FatalError);
00160 }
00161
00162 coordinateSystems csLst(csDictIoPtr());
00163
00164 if (args.optionFound("from"))
00165 {
00166 const word csName(args.option("from"));
00167
00168 label csId = csLst.find(csName);
00169 if (csId < 0)
00170 {
00171 FatalErrorIn(args.executable())
00172 << "Cannot find -from " << csName << nl
00173 << "available coordinateSystems: " << csLst.toc() << nl
00174 << exit(FatalError);
00175 }
00176
00177 fromCsys.reset(new coordinateSystem(csLst[csId]));
00178 }
00179
00180 if (args.optionFound("to"))
00181 {
00182 const word csName(args.option("to"));
00183
00184 label csId = csLst.find(csName);
00185 if (csId < 0)
00186 {
00187 FatalErrorIn(args.executable())
00188 << "Cannot find -to " << csName << nl
00189 << "available coordinateSystems: " << csLst.toc() << nl
00190 << exit(FatalError);
00191 }
00192
00193 toCsys.reset(new coordinateSystem(csLst[csId]));
00194 }
00195
00196
00197
00198 if (fromCsys.valid() && toCsys.valid())
00199 {
00200 FatalErrorIn(args.executable())
00201 << "Only allowed '-from' or '-to' option at the moment."
00202 << exit(FatalError);
00203 }
00204 }
00205
00206
00207 {
00208 MeshedSurface<face> surf(importName);
00209
00210 if (args.optionFound("clean"))
00211 {
00212 surf.cleanup(true);
00213 }
00214
00215 scalar scaleIn = 0;
00216 if (args.optionReadIfPresent("scaleIn", scaleIn) && scaleIn > 0)
00217 {
00218 Info<< " -scaleIn " << scaleIn << endl;
00219 surf.scalePoints(scaleIn);
00220 }
00221
00222
00223 if (fromCsys.valid())
00224 {
00225 Info<< " -from " << fromCsys().name() << endl;
00226 tmp<pointField> tpf = fromCsys().localPosition(surf.points());
00227 surf.movePoints(tpf());
00228 }
00229
00230 if (toCsys.valid())
00231 {
00232 Info<< " -to " << toCsys().name() << endl;
00233 tmp<pointField> tpf = toCsys().globalPosition(surf.points());
00234 surf.movePoints(tpf());
00235 }
00236
00237 scalar scaleOut = 0;
00238 if (args.optionReadIfPresent("scaleOut", scaleOut) && scaleOut > 0)
00239 {
00240 Info<< " -scaleOut " << scaleOut << endl;
00241 surf.scalePoints(scaleOut);
00242 }
00243
00244 Info<< "writing " << exportName;
00245 surf.write(exportName);
00246 }
00247
00248 Info<< "\nEnd\n" << endl;
00249
00250 return 0;
00251 }
00252
00253
Copyright © 2000-2009 OpenCFD Ltd