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("inputFile");
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 # include <OpenFOAM/setRootCase.H>
00101 # include <OpenFOAM/createTime.H>
00102
00103 const stringList& params = args.additionalArgs();
00104
00105
00106 instantList Times = runTime.times();
00107 if (Times.size())
00108 {
00109 label startTime = Times.size()-1;
00110 runTime.setTime(Times[startTime], startTime);
00111 }
00112 else
00113 {
00114 runTime.setTime(instant(0, runTime.constant()), 0);
00115 }
00116
00117
00118 fileName importName(params[0]);
00119 word exportName("default");
00120 args.optionReadIfPresent("name", exportName);
00121
00122
00123 if (!MeshedSurface<face>::canRead(importName, true))
00124 {
00125 return 1;
00126 }
00127
00128
00129
00130 autoPtr<coordinateSystem> fromCsys;
00131 autoPtr<coordinateSystem> toCsys;
00132
00133 if (args.optionFound("from") || args.optionFound("to"))
00134 {
00135 autoPtr<IOobject> ioPtr;
00136
00137 if (args.optionFound("dict"))
00138 {
00139 fileName dictPath(args.option("dict"));
00140
00141 ioPtr.set
00142 (
00143 new IOobject
00144 (
00145 (
00146 isDir(dictPath)
00147 ? dictPath/coordinateSystems::typeName
00148 : dictPath
00149 ),
00150 runTime,
00151 IOobject::MUST_READ,
00152 IOobject::NO_WRITE,
00153 false
00154 )
00155 );
00156 }
00157 else
00158 {
00159 ioPtr.set
00160 (
00161 new IOobject
00162 (
00163 coordinateSystems::typeName,
00164 runTime.constant(),
00165 runTime,
00166 IOobject::MUST_READ,
00167 IOobject::NO_WRITE,
00168 false
00169 )
00170 );
00171 }
00172
00173
00174 if (!ioPtr->headerOk())
00175 {
00176 FatalErrorIn(args.executable())
00177 << "Cannot open coordinateSystems file\n "
00178 << ioPtr->objectPath() << nl
00179 << exit(FatalError);
00180 }
00181
00182 coordinateSystems csLst(ioPtr());
00183
00184 if (args.optionFound("from"))
00185 {
00186 const word csName(args.option("from"));
00187
00188 label csId = csLst.find(csName);
00189 if (csId < 0)
00190 {
00191 FatalErrorIn(args.executable())
00192 << "Cannot find -from " << csName << nl
00193 << "available coordinateSystems: " << csLst.toc() << nl
00194 << exit(FatalError);
00195 }
00196
00197 fromCsys.reset(new coordinateSystem(csLst[csId]));
00198 }
00199
00200 if (args.optionFound("to"))
00201 {
00202 const word csName(args.option("to"));
00203
00204 label csId = csLst.find(csName);
00205 if (csId < 0)
00206 {
00207 FatalErrorIn(args.executable())
00208 << "Cannot find -to " << csName << nl
00209 << "available coordinateSystems: " << csLst.toc() << nl
00210 << exit(FatalError);
00211 }
00212
00213 toCsys.reset(new coordinateSystem(csLst[csId]));
00214 }
00215
00216
00217
00218 if (fromCsys.valid() && toCsys.valid())
00219 {
00220 FatalErrorIn(args.executable())
00221 << "Only allowed '-from' or '-to' option at the moment."
00222 << exit(FatalError);
00223 }
00224 }
00225
00226
00227
00228 MeshedSurface<face> surf(importName);
00229
00230 if (args.optionFound("clean"))
00231 {
00232 surf.cleanup(true);
00233 }
00234
00235
00236 scalar scaleIn = 0;
00237 if (args.optionReadIfPresent("scaleIn", scaleIn) && scaleIn > 0)
00238 {
00239 Info<< " -scaleIn " << scaleIn << endl;
00240 surf.scalePoints(scaleIn);
00241 }
00242
00243 if (fromCsys.valid())
00244 {
00245 Info<< " -from " << fromCsys().name() << endl;
00246 tmp<pointField> tpf = fromCsys().localPosition(surf.points());
00247 surf.movePoints(tpf());
00248 }
00249
00250 if (toCsys.valid())
00251 {
00252 Info<< " -to " << toCsys().name() << endl;
00253 tmp<pointField> tpf = toCsys().globalPosition(surf.points());
00254 surf.movePoints(tpf());
00255 }
00256
00257 scalar scaleOut = 0;
00258 if (args.optionReadIfPresent("scaleOut", scaleOut) && scaleOut > 0)
00259 {
00260 Info<< " -scaleOut " << scaleOut << endl;
00261 surf.scalePoints(scaleOut);
00262 }
00263
00264 surfMesh smesh
00265 (
00266 IOobject
00267 (
00268 exportName,
00269 runTime.constant(),
00270 runTime
00271 ),
00272 surf.xfer()
00273 );
00274
00275
00276 Info<< "writing surfMesh:\n " << smesh.objectPath() << endl;
00277 smesh.write();
00278
00279 Info<< "\nEnd\n" << endl;
00280
00281 return 0;
00282 }
00283
00284