surfaceMeshExport.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
00060
00061
00062 #include "argList.H"
00063 #include "timeSelector.H"
00064 #include "Time.H"
00065
00066 #include "MeshedSurfaces.H"
00067 #include "coordinateSystems.H"
00068
00069 using namespace Foam;
00070
00071
00072
00073
00074 int main(int argc, char *argv[])
00075 {
00076 argList::noParallel();
00077 argList::validArgs.append("outputFile");
00078 argList::validOptions.insert("name", "name");
00079 argList::validOptions.insert("clean", "");
00080 argList::validOptions.insert("scaleIn", "scale");
00081 argList::validOptions.insert("scaleOut", "scale");
00082 argList::validOptions.insert("dict", "coordinateSystemsDict");
00083 argList::validOptions.insert("from", "sourceCoordinateSystem");
00084 argList::validOptions.insert("to", "targetCoordinateSystem");
00085
00086 argList args(argc, argv);
00087 Time runTime(args.rootPath(), args.caseName());
00088 const stringList& params = args.additionalArgs();
00089
00090 fileName exportName(params[0]);
00091 word importName("default");
00092 args.optionReadIfPresent("name", importName);
00093
00094
00095 if (!MeshedSurface<face>::canWriteType(exportName.ext(), true))
00096 {
00097 return 1;
00098 }
00099
00100
00101
00102 autoPtr<coordinateSystem> fromCsys;
00103 autoPtr<coordinateSystem> toCsys;
00104
00105 if (args.optionFound("from") || args.optionFound("to"))
00106 {
00107 autoPtr<IOobject> ioPtr;
00108
00109 if (args.optionFound("dict"))
00110 {
00111 fileName dictPath(args.option("dict"));
00112
00113 ioPtr.set
00114 (
00115 new IOobject
00116 (
00117 (
00118 isDir(dictPath)
00119 ? dictPath/coordinateSystems::typeName
00120 : dictPath
00121 ),
00122 runTime,
00123 IOobject::MUST_READ,
00124 IOobject::NO_WRITE,
00125 false
00126 )
00127 );
00128 }
00129 else
00130 {
00131 ioPtr.set
00132 (
00133 new IOobject
00134 (
00135 coordinateSystems::typeName,
00136 runTime.constant(),
00137 runTime,
00138 IOobject::MUST_READ,
00139 IOobject::NO_WRITE,
00140 false
00141 )
00142 );
00143 }
00144
00145
00146 if (!ioPtr->headerOk())
00147 {
00148 FatalErrorIn(args.executable())
00149 << "Cannot open coordinateSystems file\n "
00150 << ioPtr->objectPath() << nl
00151 << exit(FatalError);
00152 }
00153
00154 coordinateSystems csLst(ioPtr());
00155
00156 if (args.optionFound("from"))
00157 {
00158 const word csName(args.option("from"));
00159
00160 label csId = csLst.find(csName);
00161 if (csId < 0)
00162 {
00163 FatalErrorIn(args.executable())
00164 << "Cannot find -from " << csName << nl
00165 << "available coordinateSystems: " << csLst.toc() << nl
00166 << exit(FatalError);
00167 }
00168
00169 fromCsys.reset(new coordinateSystem(csLst[csId]));
00170 }
00171
00172 if (args.optionFound("to"))
00173 {
00174 const word csName(args.option("to"));
00175
00176 label csId = csLst.find(csName);
00177 if (csId < 0)
00178 {
00179 FatalErrorIn(args.executable())
00180 << "Cannot find -to " << csName << nl
00181 << "available coordinateSystems: " << csLst.toc() << nl
00182 << exit(FatalError);
00183 }
00184
00185 toCsys.reset(new coordinateSystem(csLst[csId]));
00186 }
00187
00188
00189
00190 if (fromCsys.valid() && toCsys.valid())
00191 {
00192 FatalErrorIn(args.executable())
00193 << "Only allowed '-from' or '-to' option at the moment."
00194 << exit(FatalError);
00195 }
00196 }
00197
00198
00199 surfMesh smesh
00200 (
00201 IOobject
00202 (
00203 importName,
00204 runTime.constant(),
00205 runTime,
00206 IOobject::MUST_READ,
00207 IOobject::NO_WRITE
00208 )
00209 );
00210
00211 Info<< "read surfMesh:\n " << smesh.objectPath() << endl;
00212
00213
00214
00215
00216 MeshedSurface<face> surf(smesh);
00217
00218 if (args.optionFound("clean"))
00219 {
00220 surf.cleanup(true);
00221 }
00222
00223 scalar scaleIn = 0;
00224 if (args.optionReadIfPresent("scaleIn", scaleIn) && scaleIn > 0)
00225 {
00226 Info<< " -scaleIn " << scaleIn << endl;
00227 surf.scalePoints(scaleIn);
00228 }
00229
00230 if (fromCsys.valid())
00231 {
00232 Info<< " -from " << fromCsys().name() << endl;
00233 tmp<pointField> tpf = fromCsys().localPosition(surf.points());
00234 surf.movePoints(tpf());
00235 }
00236
00237 if (toCsys.valid())
00238 {
00239 Info<< " -to " << toCsys().name() << endl;
00240 tmp<pointField> tpf = toCsys().globalPosition(surf.points());
00241 surf.movePoints(tpf());
00242 }
00243
00244 scalar scaleOut = 0;
00245 if (args.optionReadIfPresent("scaleOut", scaleOut) && scaleOut > 0)
00246 {
00247 Info<< " -scaleOut " << scaleOut << endl;
00248 surf.scalePoints(scaleOut);
00249 }
00250
00251
00252 surf.writeStats(Info);
00253 Info<< endl;
00254
00255 Info<< "writing " << exportName << endl;
00256 surf.write(exportName);
00257
00258 Info<< "\nEnd\n" << endl;
00259
00260 return 0;
00261 }
00262
00263
Copyright © 2000-2009 OpenCFD Ltd