PageRenderTime 42ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/src/OpenFOAM/meshes/polyMesh/polyMeshIO.C

https://gitlab.com/johnvarv/OpenFOAM-3.0.x
C | 511 lines | 339 code | 76 blank | 96 comment | 29 complexity | 642204caec54533aa890e63496ac6a60 MD5 | raw file
  1. /*---------------------------------------------------------------------------*\
  2. ========= |
  3. \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
  4. \\ / O peration |
  5. \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
  6. \\/ M anipulation |
  7. -------------------------------------------------------------------------------
  8. License
  9. This file is part of OpenFOAM.
  10. OpenFOAM is free software: you can redistribute it and/or modify it
  11. under the terms of the GNU General Public License as published by
  12. the Free Software Foundation, either version 3 of the License, or
  13. (at your option) any later version.
  14. OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
  15. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  16. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  17. for more details.
  18. You should have received a copy of the GNU General Public License
  19. along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
  20. \*---------------------------------------------------------------------------*/
  21. #include "polyMesh.H"
  22. #include "Time.H"
  23. #include "cellIOList.H"
  24. // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
  25. void Foam::polyMesh::setInstance(const fileName& inst)
  26. {
  27. if (debug)
  28. {
  29. Info<< "void polyMesh::setInstance(const fileName& inst) : "
  30. << "Resetting file instance to " << inst << endl;
  31. }
  32. points_.writeOpt() = IOobject::AUTO_WRITE;
  33. points_.instance() = inst;
  34. faces_.writeOpt() = IOobject::AUTO_WRITE;
  35. faces_.instance() = inst;
  36. owner_.writeOpt() = IOobject::AUTO_WRITE;
  37. owner_.instance() = inst;
  38. neighbour_.writeOpt() = IOobject::AUTO_WRITE;
  39. neighbour_.instance() = inst;
  40. boundary_.writeOpt() = IOobject::AUTO_WRITE;
  41. boundary_.instance() = inst;
  42. pointZones_.writeOpt() = IOobject::AUTO_WRITE;
  43. pointZones_.instance() = inst;
  44. faceZones_.writeOpt() = IOobject::AUTO_WRITE;
  45. faceZones_.instance() = inst;
  46. cellZones_.writeOpt() = IOobject::AUTO_WRITE;
  47. cellZones_.instance() = inst;
  48. }
  49. Foam::polyMesh::readUpdateState Foam::polyMesh::readUpdate()
  50. {
  51. if (debug)
  52. {
  53. Info<< "polyMesh::readUpdateState polyMesh::readUpdate() : "
  54. << "Updating mesh based on saved data." << endl;
  55. }
  56. // Find the point and cell instance
  57. fileName pointsInst(time().findInstance(meshDir(), "points"));
  58. fileName facesInst(time().findInstance(meshDir(), "faces"));
  59. //fileName boundaryInst(time().findInstance(meshDir(), "boundary"));
  60. if (debug)
  61. {
  62. Info<< "Faces instance: old = " << facesInstance()
  63. << " new = " << facesInst << nl
  64. //<< "Boundary instance: old = " << boundary_.instance()
  65. //<< " new = " << boundaryInst << nl
  66. << "Points instance: old = " << pointsInstance()
  67. << " new = " << pointsInst << endl;
  68. }
  69. if (facesInst != facesInstance())
  70. {
  71. // Topological change
  72. if (debug)
  73. {
  74. Info<< "Topological change" << endl;
  75. }
  76. clearOut();
  77. // Set instance to new instance. Note that points instance can differ
  78. // from from faces instance.
  79. setInstance(facesInst);
  80. points_.instance() = pointsInst;
  81. points_ = pointIOField
  82. (
  83. IOobject
  84. (
  85. "points",
  86. pointsInst,
  87. meshSubDir,
  88. *this,
  89. IOobject::MUST_READ,
  90. IOobject::NO_WRITE,
  91. false
  92. )
  93. );
  94. faces_ = faceCompactIOList
  95. (
  96. IOobject
  97. (
  98. "faces",
  99. facesInst,
  100. meshSubDir,
  101. *this,
  102. IOobject::MUST_READ,
  103. IOobject::NO_WRITE,
  104. false
  105. )
  106. );
  107. owner_ = labelIOList
  108. (
  109. IOobject
  110. (
  111. "owner",
  112. facesInst,
  113. meshSubDir,
  114. *this,
  115. IOobject::READ_IF_PRESENT,
  116. IOobject::NO_WRITE,
  117. false
  118. )
  119. );
  120. neighbour_ = labelIOList
  121. (
  122. IOobject
  123. (
  124. "neighbour",
  125. facesInst,
  126. meshSubDir,
  127. *this,
  128. IOobject::READ_IF_PRESENT,
  129. IOobject::NO_WRITE,
  130. false
  131. )
  132. );
  133. // Reset the boundary patches
  134. polyBoundaryMesh newBoundary
  135. (
  136. IOobject
  137. (
  138. "boundary",
  139. facesInst,
  140. meshSubDir,
  141. *this,
  142. IOobject::MUST_READ,
  143. IOobject::NO_WRITE,
  144. false
  145. ),
  146. *this
  147. );
  148. // Check that patch types and names are unchanged
  149. bool boundaryChanged = false;
  150. if (newBoundary.size() != boundary_.size())
  151. {
  152. boundaryChanged = true;
  153. }
  154. else
  155. {
  156. wordList newTypes = newBoundary.types();
  157. wordList newNames = newBoundary.names();
  158. wordList oldTypes = boundary_.types();
  159. wordList oldNames = boundary_.names();
  160. forAll(oldTypes, patchI)
  161. {
  162. if
  163. (
  164. oldTypes[patchI] != newTypes[patchI]
  165. || oldNames[patchI] != newNames[patchI]
  166. )
  167. {
  168. boundaryChanged = true;
  169. break;
  170. }
  171. }
  172. }
  173. if (boundaryChanged)
  174. {
  175. WarningIn("polyMesh::readUpdateState polyMesh::readUpdate()")
  176. << "Number of patches has changed. This may have "
  177. << "unexpected consequences. Proceed with care." << endl;
  178. boundary_.clear();
  179. boundary_.setSize(newBoundary.size());
  180. forAll(newBoundary, patchI)
  181. {
  182. boundary_.set(patchI, newBoundary[patchI].clone(boundary_));
  183. }
  184. }
  185. else
  186. {
  187. forAll(boundary_, patchI)
  188. {
  189. boundary_[patchI] = polyPatch
  190. (
  191. newBoundary[patchI].name(),
  192. newBoundary[patchI].size(),
  193. newBoundary[patchI].start(),
  194. patchI,
  195. boundary_,
  196. newBoundary[patchI].type()
  197. );
  198. }
  199. }
  200. // Boundary is set so can use initMesh now (uses boundary_ to
  201. // determine internal and active faces)
  202. if (exists(owner_.objectPath()))
  203. {
  204. initMesh();
  205. }
  206. else
  207. {
  208. cellCompactIOList cells
  209. (
  210. IOobject
  211. (
  212. "cells",
  213. facesInst,
  214. meshSubDir,
  215. *this,
  216. IOobject::MUST_READ,
  217. IOobject::NO_WRITE,
  218. false
  219. )
  220. );
  221. // Recalculate the owner/neighbour addressing and reset the
  222. // primitiveMesh
  223. initMesh(cells);
  224. }
  225. // Even if number of patches stayed same still recalculate boundary
  226. // data.
  227. // Calculate topology for the patches (processor-processor comms etc.)
  228. boundary_.updateMesh();
  229. // Calculate the geometry for the patches (transformation tensors etc.)
  230. boundary_.calcGeometry();
  231. // Derived info
  232. bounds_ = boundBox(points_);
  233. geometricD_ = Vector<label>::zero;
  234. solutionD_ = Vector<label>::zero;
  235. // Zones
  236. pointZoneMesh newPointZones
  237. (
  238. IOobject
  239. (
  240. "pointZones",
  241. facesInst,
  242. meshSubDir,
  243. *this,
  244. IOobject::READ_IF_PRESENT,
  245. IOobject::NO_WRITE,
  246. false
  247. ),
  248. *this
  249. );
  250. label oldSize = pointZones_.size();
  251. if (newPointZones.size() <= pointZones_.size())
  252. {
  253. pointZones_.setSize(newPointZones.size());
  254. }
  255. // Reset existing ones
  256. forAll(pointZones_, czI)
  257. {
  258. pointZones_[czI] = newPointZones[czI];
  259. }
  260. // Extend with extra ones
  261. pointZones_.setSize(newPointZones.size());
  262. for (label czI = oldSize; czI < newPointZones.size(); czI++)
  263. {
  264. pointZones_.set(czI, newPointZones[czI].clone(pointZones_));
  265. }
  266. faceZoneMesh newFaceZones
  267. (
  268. IOobject
  269. (
  270. "faceZones",
  271. facesInst,
  272. meshSubDir,
  273. *this,
  274. IOobject::READ_IF_PRESENT,
  275. IOobject::NO_WRITE,
  276. false
  277. ),
  278. *this
  279. );
  280. oldSize = faceZones_.size();
  281. if (newFaceZones.size() <= faceZones_.size())
  282. {
  283. faceZones_.setSize(newFaceZones.size());
  284. }
  285. // Reset existing ones
  286. forAll(faceZones_, fzI)
  287. {
  288. faceZones_[fzI].resetAddressing
  289. (
  290. newFaceZones[fzI],
  291. newFaceZones[fzI].flipMap()
  292. );
  293. }
  294. // Extend with extra ones
  295. faceZones_.setSize(newFaceZones.size());
  296. for (label fzI = oldSize; fzI < newFaceZones.size(); fzI++)
  297. {
  298. faceZones_.set(fzI, newFaceZones[fzI].clone(faceZones_));
  299. }
  300. cellZoneMesh newCellZones
  301. (
  302. IOobject
  303. (
  304. "cellZones",
  305. facesInst,
  306. meshSubDir,
  307. *this,
  308. IOobject::READ_IF_PRESENT,
  309. IOobject::NO_WRITE,
  310. false
  311. ),
  312. *this
  313. );
  314. oldSize = cellZones_.size();
  315. if (newCellZones.size() <= cellZones_.size())
  316. {
  317. cellZones_.setSize(newCellZones.size());
  318. }
  319. // Reset existing ones
  320. forAll(cellZones_, czI)
  321. {
  322. cellZones_[czI] = newCellZones[czI];
  323. }
  324. // Extend with extra ones
  325. cellZones_.setSize(newCellZones.size());
  326. for (label czI = oldSize; czI < newCellZones.size(); czI++)
  327. {
  328. cellZones_.set(czI, newCellZones[czI].clone(cellZones_));
  329. }
  330. if (boundaryChanged)
  331. {
  332. return polyMesh::TOPO_PATCH_CHANGE;
  333. }
  334. else
  335. {
  336. return polyMesh::TOPO_CHANGE;
  337. }
  338. }
  339. else if (pointsInst != pointsInstance())
  340. {
  341. // Points moved
  342. if (debug)
  343. {
  344. Info<< "Point motion" << endl;
  345. }
  346. clearGeom();
  347. label nOldPoints = points_.size();
  348. points_.clear();
  349. pointIOField newPoints
  350. (
  351. IOobject
  352. (
  353. "points",
  354. pointsInst,
  355. meshSubDir,
  356. *this,
  357. IOobject::MUST_READ,
  358. IOobject::NO_WRITE,
  359. false
  360. )
  361. );
  362. if (nOldPoints != 0 && nOldPoints != newPoints.size())
  363. {
  364. FatalErrorIn("polyMesh::readUpdate()")
  365. << "Point motion detected but number of points "
  366. << newPoints.size() << " in "
  367. << newPoints.objectPath() << " does not correspond to "
  368. << " current " << nOldPoints
  369. << exit(FatalError);
  370. }
  371. points_.transfer(newPoints);
  372. points_.instance() = pointsInst;
  373. // Derived info
  374. bounds_ = boundBox(points_);
  375. // Rotation can cause direction vector to change
  376. geometricD_ = Vector<label>::zero;
  377. solutionD_ = Vector<label>::zero;
  378. //if (boundaryInst != boundary_.instance())
  379. //{
  380. // // Boundary file but no topology change
  381. // if (debug)
  382. // {
  383. // Info<< "Boundary state change" << endl;
  384. // }
  385. //
  386. // // Reset the boundary patches
  387. // polyBoundaryMesh newBoundary
  388. // (
  389. // IOobject
  390. // (
  391. // "boundary",
  392. // facesInst,
  393. // meshSubDir,
  394. // *this,
  395. // IOobject::MUST_READ,
  396. // IOobject::NO_WRITE,
  397. // false
  398. // ),
  399. // *this
  400. // );
  401. //
  402. //
  403. //
  404. //
  405. // boundary_.clear();
  406. // boundary_.setSize(newBoundary.size());
  407. //
  408. // forAll(newBoundary, patchI)
  409. // {
  410. // boundary_.set(patchI, newBoundary[patchI].clone(boundary_));
  411. // }
  412. // // Calculate topology for the patches (processor-processor comms
  413. // // etc.)
  414. // boundary_.updateMesh();
  415. //
  416. // // Calculate the geometry for the patches (transformation tensors
  417. // // etc.)
  418. // boundary_.calcGeometry();
  419. //}
  420. return polyMesh::POINTS_MOVED;
  421. }
  422. else
  423. {
  424. if (debug)
  425. {
  426. Info<< "No change" << endl;
  427. }
  428. return polyMesh::UNCHANGED;
  429. }
  430. }
  431. // ************************************************************************* //