surfaceMeshImport.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("inputFile");
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 # include "setRootCase.H"
00087 # include "createTime.H"
00088
00089 const stringList& params = args.additionalArgs();
00090
00091
00092 instantList Times = runTime.times();
00093 if (Times.size())
00094 {
00095 label startTime = Times.size()-1;
00096 runTime.setTime(Times[startTime], startTime);
00097 }
00098 else
00099 {
00100 runTime.setTime(instant(0, runTime.constant()), 0);
00101 }
00102
00103
00104 fileName importName(params[0]);
00105 word exportName("default");
00106 args.optionReadIfPresent("name", exportName);
00107
00108
00109 if (!MeshedSurface<face>::canRead(importName, 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
00214 MeshedSurface<face> surf(importName);
00215
00216 if (args.optionFound("clean"))
00217 {
00218 surf.cleanup(true);
00219 }
00220
00221
00222 scalar scaleIn = 0;
00223 if (args.optionReadIfPresent("scaleIn", scaleIn) && scaleIn > 0)
00224 {
00225 Info<< " -scaleIn " << scaleIn << endl;
00226 surf.scalePoints(scaleIn);
00227 }
00228
00229 if (fromCsys.valid())
00230 {
00231 Info<< " -from " << fromCsys().name() << endl;
00232 tmp<pointField> tpf = fromCsys().localPosition(surf.points());
00233 surf.movePoints(tpf());
00234 }
00235
00236 if (toCsys.valid())
00237 {
00238 Info<< " -to " << toCsys().name() << endl;
00239 tmp<pointField> tpf = toCsys().globalPosition(surf.points());
00240 surf.movePoints(tpf());
00241 }
00242
00243 scalar scaleOut = 0;
00244 if (args.optionReadIfPresent("scaleOut", scaleOut) && scaleOut > 0)
00245 {
00246 Info<< " -scaleOut " << scaleOut << endl;
00247 surf.scalePoints(scaleOut);
00248 }
00249
00250 surfMesh smesh
00251 (
00252 IOobject
00253 (
00254 exportName,
00255 runTime.constant(),
00256 runTime
00257 ),
00258 surf.xfer()
00259 );
00260
00261
00262 Info<< "writing surfMesh:\n " << smesh.objectPath() << endl;
00263 smesh.write();
00264
00265 Info<< "\nEnd\n" << endl;
00266
00267 return 0;
00268 }
00269
00270
Copyright © 2000-2009 OpenCFD Ltd