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