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