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 #include <OpenFOAM/argList.H>
00052 #include <OpenFOAM/Time.H>
00053 #include <OpenFOAM/polyMesh.H>
00054 #include <meshTools/topoSetSource.H>
00055 #include <meshTools/pointSet.H>
00056
00057 using namespace Foam;
00058
00059
00060
00061
00062 void backup
00063 (
00064 const polyMesh& mesh,
00065 const word& fromName,
00066 const topoSet& fromSet,
00067 const word& toName
00068 )
00069 {
00070 Info<< "Backing up " << fromName << " into " << toName << endl;
00071
00072 topoSet backupSet(mesh, toName, fromSet);
00073
00074 backupSet.write();
00075 }
00076
00077
00078
00079 void backup
00080 (
00081 const polyMesh& mesh,
00082 const word& fromName,
00083 const word& toName
00084 )
00085 {
00086 topoSet fromSet(mesh, fromName, IOobject::READ_IF_PRESENT);
00087
00088 backup(mesh, fromName, fromSet, toName);
00089 }
00090
00091
00092
00093
00094 int main(int argc, char *argv[])
00095 {
00096 # include <OpenFOAM/setRootCase.H>
00097 # include <OpenFOAM/createTime.H>
00098 # include <OpenFOAM/createPolyMesh.H>
00099
00100 Info<< "Reading pointSetDict\n" << endl;
00101
00102 IOdictionary pointSetDict
00103 (
00104 IOobject
00105 (
00106 "pointSetDict",
00107 runTime.system(),
00108 mesh,
00109 IOobject::MUST_READ,
00110 IOobject::NO_WRITE
00111 )
00112 );
00113
00114
00115 word setName(pointSetDict.lookup("name"));
00116
00117 word actionName(pointSetDict.lookup("action"));
00118
00119 topoSetSource::setAction action = topoSetSource::toAction(actionName);
00120
00121
00122
00123 PtrList<topoSetSource> topoSetSources
00124 (
00125 pointSetDict.lookup("topoSetSources"),
00126 topoSetSource::iNew(mesh)
00127 );
00128
00129
00130
00131 autoPtr<topoSet> currentSetPtr(NULL);
00132 IOobject::readOption r;
00133
00134 if ((action == topoSetSource::NEW) || (action == topoSetSource::CLEAR))
00135 {
00136 r = IOobject::NO_READ;
00137
00138 backup(mesh, setName, setName + "_old");
00139
00140 currentSetPtr.reset
00141 (
00142 new pointSet
00143 (
00144 mesh,
00145 setName,
00146 mesh.nPoints()/10+1
00147 )
00148 );
00149 }
00150 else
00151 {
00152 r = IOobject::MUST_READ;
00153
00154 currentSetPtr.reset
00155 (
00156 new pointSet
00157 (
00158 mesh,
00159 setName,
00160 r
00161 )
00162 );
00163 }
00164
00165 topoSet& currentSet = currentSetPtr();
00166
00167 Info<< "Set:" << currentSet.name()
00168 << " Size:" << currentSet.size()
00169 << " Action:" << actionName
00170 << endl;
00171
00172 if ((r == IOobject::MUST_READ) && (action != topoSetSource::LIST))
00173 {
00174
00175 backup(mesh, setName, currentSet, setName + "_old");
00176 }
00177
00178 if (action == topoSetSource::CLEAR)
00179 {
00180
00181 }
00182 else if (action == topoSetSource::INVERT)
00183 {
00184 currentSet.invert(currentSet.maxSize(mesh));
00185 }
00186 else if (action == topoSetSource::LIST)
00187 {
00188 currentSet.writeDebug(Info, mesh, 100);
00189 Info<< endl;
00190 }
00191 else if (action == topoSetSource::SUBSET)
00192 {
00193
00194 forAll(topoSetSources, topoSetSourceI)
00195 {
00196
00197 topoSet oldSet(mesh, currentSet.name() + "_old2", currentSet);
00198
00199 currentSet.clear();
00200
00201 topoSetSources[topoSetSourceI].applyToSet
00202 (
00203 topoSetSource::NEW,
00204 currentSet
00205 );
00206
00207
00208 currentSet.subset(oldSet);
00209 }
00210 }
00211 else
00212 {
00213
00214 forAll(topoSetSources, topoSetSourceI)
00215 {
00216 topoSetSources[topoSetSourceI].applyToSet(action, currentSet);
00217 }
00218 }
00219
00220
00221 if (action != topoSetSource::LIST)
00222 {
00223
00224
00225
00226 currentSet.sync(mesh);
00227
00228 Info<< "Writing " << currentSet.name()
00229 << " (size " << currentSet.size() << ") to "
00230 << currentSet.instance()/currentSet.local()
00231 /currentSet.name()
00232 << endl << endl;
00233
00234 currentSet.write();
00235 }
00236
00237 Info << nl << "End" << endl;
00238
00239 return 0;
00240 }
00241
00242
00243