From 9588cbdc0c5f764f81f048b3802b49f541cbd986 Mon Sep 17 00:00:00 2001 From: Hrvoje Jasak Date: Wed, 18 Dec 2013 17:34:08 +0000 Subject: [PATCH 1/3] Release docs --- HowToContribute | 202 ++++----------------- ReleaseNotes-foam-extend-3.0 | 336 +++++++++++++++++++++++++++++++++++ 2 files changed, 367 insertions(+), 171 deletions(-) create mode 100644 ReleaseNotes-foam-extend-3.0 diff --git a/HowToContribute b/HowToContribute index 9c2f9f4b2..0f17f5b6c 100644 --- a/HowToContribute +++ b/HowToContribute @@ -1,185 +1,45 @@ -How to Contribute -~~~~~~~~~~~~~~~~~ +Guide to contribute code to OpenFOAM-extend project -Contacts: - -Release Committee: Hrvoje Jasak (h.jasak@wikki.co.uk) -SourceForge Accounts: Bernhard Gschaider (Bernhard.Gschaider@ice-sf.at) - Martin Beaudoin (beaudoin.martin@ireq.ca) -git Repository: Henrik Rusche (h.rusche@wikki.co.uk) - Martin Beaudoin (beaudoin.martin@ireq.ca) - -1. SourceForge Access - ~~~~~~~~~~~~~~~~~~ - - To make contributions to the -extend project, you should first obtain an - account at SourceForge.net. (SourceForge will suggest a username - of firstnamelastname, but a username of firstname_lastname may - be a better choice.) After you obtain your account at SourceForge, you will - still need to be granted specific access to the -extend project. Make a request - to the "SourceForge Accounts" contact at the top of this document for access to - the project. +You have developed a new top-level solver or utility. You have implemented a further turbulence model, interface to a material properties library or created a really useful boundary condition? This guide shows the ways to share this code with the OpenFOAM® communinity. -2. Access to the git Repository - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Why should I share my code? - For a read-only copy of the repository, use the following command: - + git clone git://openfoam-extend.git.sourceforge.net/gitroot/openfoam-extend/OpenFOAM-1.6-ext +Depending on your background, motivations for contributing code to OpenFOAM® via the FOAM-extend project will differ. - To obtain a copy of the repository with write access, use the following command: - + git clone ssh://username@openfoam-extend.git.sourceforge.net/gitroot/openfoam-extend/OpenFOAM-1.6-ext +With an industrial background you may find it a cost-advantage compared to keeping everything in-house. Code contributed to the source-core will be maintained along with the complete project source code. This saves you the cost of porting your code to each new release. Furthermore, your code will be reviewed by experts with relevant OpenFOAM® experience, who will be able to spot design improvements that lead to increased speed of execution, better convergence, improved robustness, stability or all of the above. If you plan to deploy your code to clients, the extend-bazaar gives you a unified platform that is simple to use, easy to access and gives you maximum freedom in presenting your code. - Also see: - http://openfoam-extend.git.sourceforge.net/git/gitweb.cgi?p=openfoam-extend +In academia, many OpenFOAM® developments are carried out within publicly funded projects, often as part of PhD studies. Unfortunately, much of this work is not re-used and developed further. A time-saving option to share this work is the extend-bazaar, where working code and example cases can be simply uploaded with a brief description. This can be expanded and may even form the base for a journal publication; a good example for this is the waves2Foam package by Niels Jacobsen LINK. Contributing gives the code visibility in the OpenFOAM® community and harvests public recognition long after the project has been completed. + +In both cases, the credit for your work, its authorship, and Copyright remains with you. We do not require contributors to give up the rights to their work. + +What is the difference between contibuting to source-core and to extend-bazaar? + +The \BOLD{source-core} of FOAM-extend meets the high quality standards of a software package that is deployed for production use. A contribution will be therefore reviewed by an experiened OpenFOAM®-extend maintainer. The code must adhere to OpenFOAM® coding style guideline LINK. The contribution procedure is: +* Check your code, especially regarding coding style and trailing whitespace +* Contact the maintainers of FOAM-extend repository to get write access , ???@???.org. +* Use git to make a local feature branch, move your contribution into this branch and push the branch to the repository. See details of the FOAM-extend branching model LINK and git usage LINK. +* Contact the maintainers and ask for review and merge of your code. Experience shows this involves a few iterative steps. +* Your code is merged and becomes part of FOAM-extend. You are added to the list of contributors FOAM-extend. +* Maintainance of your case is now part of the general development + +The \BOLD{extend-bazaar} has been created to minimize the effort for sharing your code. It is ideal for solvers and utilities that can live in the user-directory. The required steps are: + +* Create a user account on the OpenFOAM® Wiki. +* Go to the extend-bazaar page and find a category for your contribution. +* Create a new sub-page in the category and write a brief description/documentation for your contribution. Templates LINK exist that you can re-use. +* Upload your code. Options are: + * For small packages that will not change much in the future, you can upload a .tgz archive to your wiki page directly. + * For larger packages that contain for example big meshes, use a file-hoster and add a link to your wiki page. + * If your contribution is under active development, create a repository for example on sourceforge LINK or github LINK. Add a link to the repository on the wiki page. +* Implementing bug fixes, new features or ports to a new FOAM-extend release is at your discretion -3. git Commit Policies and Workflow (Introduction) - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - A formal procedure for contributions has been established for the project with - regard to branching and commits in the git repository. The workflow proposed - by Hrv Jasak and Henrik Rusche for contributing to the git repository is described - in the following document: - - http://nvie.com/posts/a-successful-git-branching-model/ - - The article listed above should be considered mandatory reading material - for those planning to make contributions to the repository. Some links about - the general usage of GIT can be found in Section 8. - - Please do not hesitate to ask one of the "git Repository" contacts at the top - of this document if you are not sure about specific operation relative to the git - repository. -4. git Commit Policies and Workflow (User Perspective) - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - The document listed in Section 3 above from nvie.com provides an excellent conceptual - description of the policies that will be used for the -extend repository. More - detailed instructions for users who wish to make contributions are spelled out in - this section. - - Before making any commits to the git repository, be sure to configure git with your - username and e-mail address, which helps to ensure that you receive proper credit - in the git repository for work you contribute. - - The author's name and e-mail address can be provided to git using commands such - as these: - - + git config --global user.name "John Doe" - + git config --global user.email john.doe@xxx.com - - Afterwards, the provided information will be contained in a file named .gitconfig - in the user's home directory. - - All contributions to the project repository will be contained in a new feature branch - created by the contributor. The recommended way of creating branches is to create one - branch for each new specific fix or feature using a command such as this: - - + git checkout -b my-feature-branch - - Feature branches should be named after the fix or feature that they contain, - *not* named after the author. There may be more than one author, after all, and - this information is recorded in the commit anyway. As an example, a bug fix - to the mesquite package should be committed to a branch named "hotfix/mesquite". - - Carefully organized commits and branches, clear commit messages, and well-chosen - branch names will make it easier for the release committee to review and merge - each contribution. - - When you have a feature branch that is ready to be merged, push it to the server - using a command such as this: - - + git push origin my-feature-branch - - Next, notify the "Release Committee" point-of-contact listed at the top of this - document that the feature branch has been pushed to the server and is ready to be - merged. A release committee member will review your contribution, merge your - branch, and then delete the branch from the server, as it is no longer needed once - it has been merged. - - If you need to delete the branch from the server or are requested to do so, the proper - command is - - + git push origin :my-feature-branch - - To delete the same branch from your local repository requires the command - - + git branch -d my-feature-branch - - Finally, to clean your local repository of tracking branches that have been deleted - from the server requires the command - - + git remote prune origin - -5. git Commit Policies and Workflow (Committee Perspective) - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - The -extend project "release committee" (initially comprised of Hrv Jasak) will be - solely responsible for merging user contributions into the master and nextRelease branches. - - User contributions will be contained in feature branches, with a new feature branch for - each new fix or feature, as described in Section 4 above. - - The feature branches provided by users will be merged by the release committee - into an integration branch called "nextRelease", and then both the local - and remote copy of the feature branch will be deleted. The merge will be performed - using a "git merge --no-ff" command, which forces the creation of a merge commit - even in the case where the merge could be accomplished by fast-forward. - Note that the automated test loop will be run off of this integration branch. - - When the next release is ready, the release committee will merge the - integration branch into the master branch, again using a "git merge --no-ff" command. - Consistent with the proposed workflow, the master branch will only contain releases - and hotfixes. - - Note that hotfixes should be branched off of the master branch and should be merged - twice - once into the integration branch and once into the master branch - in order to - guarantee that a merge of the integration branch into the master branch can be - accomplished by a fast-forward. -6. Specific Usage Instructions - ~~~~~~~~~~~~~~~~~~~~~~~~~~~ - In case you find out that something that should be a hotfix ended up in - your local feature branch, follow the steps below to ensure that the hotfix is - properly committed to the integration and master branches: - - a. Single out the SHA-1 of the commit that contains the hotfix (e.g. 13e5d2f) - - c. Create a new hotfix branch; e.g. - - + git checkout master - + git checkout -b hotfix/my-hotfix-topic - - b. Single out the commit and base it on the master branch; e.g. - - # The fix is in a single commit, but localBranch has advanced - + git cherry-pick commitID - - OR - - # The fix is small, but the commit contains other changes - + git checkout localBranch file - + git commit - - d. Contact the "Release Committee" point-of-contact at the top of this document - and request that the hotfix be merged into the integration and master branches. - - -7. Acknowledgements & Copyright - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - Your authorship is tracked by the version control system (git). You may also document - your authorship in the header of the files. Furthermore, the release committee will - update the list of contributors in the README file with every release. - - -8. Background Reading on git - ~~~~~~~~~~~~~~~~~~~~~~~~~ - - http://openfoamwiki.net/index.php/Starting_points_for_using_GIT + +http://www.openfoam.org/contrib/code-style.php diff --git a/ReleaseNotes-foam-extend-3.0 b/ReleaseNotes-foam-extend-3.0 new file mode 100644 index 000000000..d0ee9c512 --- /dev/null +++ b/ReleaseNotes-foam-extend-3.0 @@ -0,0 +1,336 @@ +# -*- mode: org; -*- +# +#+TITLE: *Release notes for foam-extend-3.0* +#+AUTHOR: Hrvoje Jasak. +#+DATE: 18 December 2013 +#+LINK: http://foam-extend.org +#+OPTIONS: author:nil + +################################################################################ + +Contents: +* Overview +* Installation +* Compatibility +* New features in foam-extend-3.0 +* Reporting bugs +* How to contribute +* List of Contributors + +################################################################################ + +* Overview + The foam-extend project is a fork of the OpenFOAM® open source library for + Computational Fluid Dynamics (CFD). It is an open project welcoming and + integrating contributions from all users and developers. Previously known as + OpenFOAM®-dev and OpenFOAM®-extend, it contains bug fixes and performance + improvements, as well as extensions and additional features provided + by community contributors (see list below), such as dynamic mesh and + topological change support, turbomachinery extensions including general grid + interpolation (GGI), cyclic GGI and mixing place, block-coupled matrix + support, finite area method, comprehensive mesh motion capability and GPU + support. For a full list, see below. + + Version 3.0, nicknamed "Jeju", is the current version of foam-extend. The + release now continues the tradition and spirit of the original FOAM code + developed by prof. Jasak and Mr. Weller during their time at + Imperial College and released as the general purpose CFD/CCM package by + Nabla Ltd. in 2000. In this spirit, we shall revert to original numbering + scheme (foam-2.3.2, 13 December 2004) as release number 3.0. + Visit http://foam-extend.org for more information. + + OPENFOAM® is a registered trademark of ESI Group. OpenFOAM-extend and + foam-extend are a community effort not endorsed by ESI Group. + +* Installation + foam-extend-3.0 can be compiled and runs on any linux system and + Apple Mac OS X. + + ** From source + Please refer to doc/buildInstructions/ for details. If you have + improvements or build instructions for a new system, please share them + with the community (see section "How to contribute", below). + + ** Binary packages + Binary packages are available for download at + http://sourceforge.net/projects/openfoam-extend/ + for the following systems: Ubuntu 12.04, Ubuntu 13.10 and Fedora 19 . + +* Compatibility + Upstream features from the OpenFOAM® code base are merged into foam-extend + on regular basis. The interface format of foam-extend-3.0 is largely + compatible to OpenFOAM-1.6-ext and OpenFOAM-1.7.x. In some cases, + the differences are caused by bug fixes and algorithmic improvements, + considered more important than inter-operability. + +* Main diferentiators + A large number of features has been lost within the release cycle of OpenFOAM + code; since version 1.3, the code base has shrunk by more than 40%. While + we understand the lack of technical ability of supporting advanced + CFD features, we feel that existing features and specifically large-scale + contributions should remain active and developed further. Below is a list + of main features of foam-extend-3.0 which are lost, deactivated or unusable + in ESI releases: + + ** Turbomachinery features, including General Grid Interface (GGI), + partial overlap GGI, cyclic GGI, with improvements in parallel scaling. + First full and validated release of a mixing plane stage interface + + ** Dynamic mesh with topological changes + sliding interfaces, mesh layering, attach-detach boundaries etc. + in foam-extend-3.0 full parallel support for topological changes + is released for the first time + + ** Finite Element Method with support for polyhedral meshes + This is mainly used in mesh deformation and over the last 15 years + it has proven vastly superior to all other dynamic mesh methods. + + ** Advanced mesh deformation technology + including tet FEM mesh deformation, Radial Basis Function (RBF) mesh + deformation, tetrahedral remeshing dynamic mesh support and solid body + motion functions. All of the above include parallelisation support + + ** Library of dynamic meshes with topological changes with full + second order FVM discretisation support on moving meshes with + topological changes + + ** Internal combustion engine-specific dynamic mesh classes such as + two-stroke engine and various forms of 4-stroke and multi-valve + dynamic mesh classes + + ** Finite Area Method providing support for FVM-like discretisation on + a curved surface in 3-D, with examples of liquid film modelling + + ** Block-coupled matrix support, allowing fully implicit multi-equation + solution of NxN equation sets, with full parallelisation support. + First release of a block-AMG linear equation solver + + ** Fully implicit conjugate-coupled solution framework, allowing implicit + solution fo multiple equations over multiple meshes, with parallelism + + ** Proper Orthogonal Decomposition data analysis tools, with applications + to FOAM field classes + + ** Equation reader classes and tutorials + + ** Multi-solver solution framework, allowing mutiple field models to be + solved in a coupled manner + + ** A major contribution is solid mechanics modelling, including linear + and non-linear materials, contact, self-contact and friction, with + updated Lagrangian or absolute Lagrangian formulation. Solution o + damage models and crack propagation in complex materials via + topological changes + + ** CUDA solver release, provided in full source and as an example of + coupling external linear equation solvers with FOAM + + ** Library-level support for Immersed Boundary Method and Overset Mesh + + ** Major improvements in accuracy and stability of FVM discretisation + with options on convection and diffusion discretisation, deferred + correction or explicit schemes + + ** Algebraic multigrid solver framerowk + + ** 190 tutorials with automated run scripts + + ** Automatic test harness + +* New features in foam-extend-3.0 + The list of features is a result of the work of numerous contributors. The + maintainers of foam-extend would formally like to thank them all. Features + listed below have are new with regard to OpenFOAM-1.6-ext. For a list of + extension features in OpenFOAM-1.6-ext, please refer to file + "ReleaseNotes-1.6-ext". + + ** Core library + + cudaSolvers + dynamicMesh + dynamicTopoFvMesh: + dynamicTopoFvMeshCoupled + convexSetAlgorithm + fieldMapping + meshOpsTemplates + msqAdditionalSrc + tetDecompositionMotionSolver + tetMotionSolver + multiTopoBodyFvMesh + engine + accordionValve + accordionEngineMesh + attachDetachFunctions + deformingEngineMesh + regionSide + twoStrokeEngine + equationReader + finiteArea: + faMeshMapper + faMeshUpdate.C + interpolation: + mapping + finitVolume: + mixingPlane + regionCouple + adjConvectionSchemes + backwardD2dt2Scheme + skewCorrectedSnGrad + singleCellFvMesh + harmonic + harmonicTemplates + magLongDelta.[HC] + multiSolver + OpenFOAM: + PriorityList + + IOReferencer + postfixedSubRegistry + + symmTensor4thOrder + VectorN + diagTensor + oscillatingFixedValue + + profiling + + MixingPlaneInterpolation + splineInterpolateXY + + BlockAmg solver + blockVectorN solver + BlockLduInterface + + mixingPlane (also with GAMG) + regionCouple (also with GAMG) + + BlockCoeffNorm + + postProcessing: + foamCalcFunctions: + scalarMult + componentsTurbo + domainIntegrate + functionObjects: + mixingPlaneCheck + maxFieldCell + solidModels + tetDecompositionFiniteElement + thermophysicalModels: + radiation: + viewFactor + turbulenceModels: + RWallFunctions + VectorN + + ** Solver applications + + conjugateHeatSimpleFoam + equationReaderDemo + MRFSimpleFoam + simpleSRFFoam + MRFInterFoam + multiSolver + solidMechanics: + elasticAcpSolidFoam + elasticIncrAcpSolidFoam + elasticIncrSolidFoam + elasticNonLinIncrTLSolidFoam + elasticNonLinTLSolidFoam + elasticNonLinULSolidFoam + elasticOrthoAcpSolidFoam + elasticOrthoNonLinULSolidFoam + elasticOrthoSolidFoam + elasticPlasticSolidFoam + elasticPlasticNonLinTLSolidFoam + elasticPlasticNonLinULSolidFoam + elasticSolidFoam + elasticThermalSolidFoam + icoFsiElasticNonLinULSolidFoam + viscoElasticSolidFoam + + ** Utilities + + foamMeshToAbaqus + multiSolver (postProcessing) + solidMechanics: + calculateCourantNumber + forceDisp + patchStressIntegrate + smoothMesh + surfaceTractions + + ** ThirdParty software + gcc compatibility up to 4.8.1 + Updated to: + Paraview 4.1 + openmpi 1.6.5 + cmake 2.8.12 + metis 5.1.0 + parmetis 4.0.3 + scotch 6.0.0 + zoltan 3.6 + +* Reporting bugs + To report bugs, please use the MantisBT bugtracker at + http://sourceforge.net/apps/mantisbt/openfoam-extend/my_view_page.php . + +* How to contribute + All your contributions are highly welcome: New solvers, utilities and + models; bug fixes; documentation. The many ways of contributing and the + contribution process are described in detail in the file "HowToContribute". + +* List of Contributors + (If your name is missing in the list, please contact the maintainers at + and it will be added asap.) + Henry Weller + Hrvoje Jasak + Mattijs Janssens + Zeljko Tukovic + Bernhard Gschaider + Tommaso Lucchini + Martin Beaudoin + Sandeep Menon + Niklas Nordin + Eugene De Villiers + Henrik Rusche + Ivor Clifford + Philiposse Rajan + Gavin Tabor + Jovani Favero + Frank Bos + David Hill + Niklas Wikstrom + Dubravko Matijasevic + Darrin Stephens + Christian Beck + Oliver Borm + James Criner + Hua Shan + David Boner + Pierre-Olivier Dallaire + Norman Del Puppo + Dennis Kingsley + Frank Albina + Flavio Galeazzo + Hannes Kroger + Olivier Petit + David Schmidt + Andreas Feymark + Luca Mangani + Daniel Schmode + Christoph Goniva + Takuya Oshima + Juho Peltola + Eric Paterson + Fabian Peng Karrholm + Aleksandar Karac + Maria Garcia Camprubi + Chris Greenshields + Mark Olesen + Hilary Spencer + Andy Heather + Dominik Christ + Peter Janas + Niels Linnemann + Nikola Kornev From edd149e316cb70ceb8e880c134dae13f5792b946 Mon Sep 17 00:00:00 2001 From: Hrvoje Jasak Date: Wed, 18 Dec 2013 17:34:44 +0000 Subject: [PATCH 2/3] Old release notes removed --- ContributionsForNextRelease.txt | 23 ----- ReleaseNotes-1.6-ext | 84 ---------------- buildInstructions.txt | 169 -------------------------------- 3 files changed, 276 deletions(-) delete mode 100644 ContributionsForNextRelease.txt delete mode 100644 ReleaseNotes-1.6-ext delete mode 100644 buildInstructions.txt diff --git a/ContributionsForNextRelease.txt b/ContributionsForNextRelease.txt deleted file mode 100644 index 6ec94b8b7..000000000 --- a/ContributionsForNextRelease.txt +++ /dev/null @@ -1,23 +0,0 @@ -Standard response: - -Your name and authorship will be preserved by the git system, but please put the author name for the classes you have written, or a note saying that yo have changed the code. - -Bug fixes: - -- Peter Janas: accordionEngineMesh and bug fixes - - -Contributions: - -- Niels Linnemann: Actuator disk -- Bernhard Gscheider: surfactantFoam clean-up; swakToFoam -- TU Braunschweig: real gas thermo -- Kornev, Rostock: inlet turbulence generator; locDynV2F hybrid turbulence model -- Christoph Goniva: and multi-mixer dynamic mesh class -- - - -- segregated pressure-based turbomachinery (Wikki) -- improvements to GGI -- mixing plane interface -- ??? Swig interface diff --git a/ReleaseNotes-1.6-ext b/ReleaseNotes-1.6-ext deleted file mode 100644 index ed1fb84b4..000000000 --- a/ReleaseNotes-1.6-ext +++ /dev/null @@ -1,84 +0,0 @@ -# -*- mode: org; -*- -# -#+TITLE: *OpenFOAM release notes for version 1.6-ext* -#+AUTHOR: Hrvoje Jasak. -#+DATE: 12 November 2010 -#+LINK: http://www.extend-project.de -#+OPTIONS: author:nil - -* Overview - OpenFOAM-1.6-ext is a formal release of the community developments in the - OpenFOAM software library, following the establishment of the -Extend Project - and web portal. - - This release includes many improvements, including an automatic test harness - which provides basic quality control by running OpenFOAM over a growing - suite of tutorials and test cases. - -* Compatibility - OpenFOAM-1.6-ext is compatible with the OpenFOAM-1.6.x and 1.7.1 versions - of the code and incorporate most developments and changes from above versions - and ensure top-level compatibility. In some cases, the differences are - caused by bug fixes and algorithmic improvements, considered more important - than inter-operability. - - The list of developments is a result of the work of numerous contributors. - The Extend Project Admins would formally like to thank all contributors; - the list will be updated with further code development - -* Fundamental developments - Improvements in accuracy and stability on tetrahedral and tet-dominant meshes - Implicit coupled multi-domain solver - Block-implicit multi-equation matrix support - Proper Orthogonal Decomposition (POD) data analysis tools - Rewrite of Ordinary Differential Equation (ODE) and ODE solver classes - Dynamic remeshing classes, based on tetrahedral edge swapping - Radial Basis Function interpolation and mesh motion classes - Turbomachinery features: GGI interface, cyclic GGI, partial overlap GGI - Parallelisation of topological change engine - Support for parallelisation and topological changes in the Finite Area Method - Library preparation for Python/Swig interface for OpenFOAM: VulaSHAKA project - (http://sourceforge.net/projects/vulashaka/) - Basic implementation of OpenMP wrapping for multi-core support - -* Ongoing developments - This section lists the applications that existed in versions of OpenFOAM - but were abandoned by OpenCFD due to lack of expertise. In some cases, code - may still be present but it is buggy or unusable. The -Extend project line - maintains, validates and develops the features in contact with original - authors and contributes new features and bug fixes. - - Working parallel point mesh and field tools, shared between interpolation - and FEM discretisation solvers - FEM-based automatic mesh motion solver, with working parallelisation - Dynamic mesh features and topological mesh changes - The Finite Area Method: parallelisation, volume-to-surface mapping - New generation of linear equation solvers, including accelerated AMG - -* Developments to solvers (applications) - Basic 6-degree-of-freedom (6-DOF) solver - POD solver tools: prototype - Demonstration solver for fully implicit block-matrix coupling - -* Developments to utilities - New parallel decomposition and reconstruction formulation, with support - for topologically changing meshes - Level-set support tools - -* Model development - Transport models and top-level solver for visco-elasto-plastic flows - Updates to internal combustion engine simulation tools - Updated version of free surface tracking tools for free surface flows - Updated fluid-structure interaction solver with parallelisation support - Updated stress analysis tools, new large deformation solver formulation - -* Quality Control - Integrated automatic and publicly available test harness with ~150 cases - http://openfoam-extend.sourceforge.net/CDash/index.php - Community-driven test-case base to enhance code quality and integrity. - Contributions under - http://www.extend-project.de/project-final/openfoam-extend-test-harness - -* Other - The number of cumulative bug fixes compared to OpenFOAM-1.6.x is over - 5000; we will stop counting. diff --git a/buildInstructions.txt b/buildInstructions.txt deleted file mode 100644 index b615324fc..000000000 --- a/buildInstructions.txt +++ /dev/null @@ -1,169 +0,0 @@ -1) Download files - -Get all files from the sources directory on the web site and put them into the linuxSrc directory - -2) Unpack OpenFOAM and set up the dot-files - -cd ~/OpenFOAM -tar xzf linuxSrc/OpenFOAM-1.4.1-dev_22_11_05.tgz -cp -r OpenFOAM-1.4.1-dev/.OpenFOAM-1.4.1-dev ~ - -set up dot files: - -put: - -source ~/.OpenFOAM-1.4.1-dev/cshrc - -into your .cshrc file. If you are using bash, add - -. ~/.OpenFOAM-1.4.1-dev/bashrc - -into ~/.bashrc - -Do: - -source ~/.cshrc - -For bash users, do - -. ~/.bashrc - -instead. - - -3) Build utilities - -3.1) gcc -tar xzf gcc-4.2.2.tgz -mkdir gcc-4.2.2-obj -cd gcc-4.2.2-obj - -../gcc-4.2.2/configure --prefix=/usr/tmp/gcc-4.2.2 --exec-prefix=/usr/tmp/gcc-4.2.2 --enable-languages=c,c++ --enable-shared - -gmake bootstrap -gmake -gmake install - -cd /usr/tmp/ -tar cvzf ~/OpenFOAM/linux/gcc-4.2.2.bin.tgz gcc-4.2.2 -cd ~/OpenFOAM/linux -tar xzf gcc-4.2.2.bin.tgz - -3.2) gdb - -cd ~/OpenFOAM/linuxSrc -tar xzf gdb-6.4.tar.gz -cd gdb-6.4 -./configure --prefix=~/OpenFOAM/linux/gdb-6.4 -gmake -gmake install - -3.3 cmake - -cd ~/OpenFOAM/linuxSrc -tar xzf cmake-2.4.7.tar.gz -cd cmake-2.4.7 -./configure --prefix=~/OpenFOAM/linux/cmake-2.4.7 -gmake -gmake install - -3.4 dx -cd ~/OpenFOAM/linuxSrc -tar xzf dx-4.4.4.tgz -cd dx-4.4.4 -./configure --prefix=~/OpenFOAM/linux/dx-4.4.4 --enable-shared -gmake -gmake install - -3.5 paraview -cd ~/OpenFOAM/linuxSrc -tar xvzf paraview-2.4.4.tgz -mkdir paraview-2.4.4-obj -cmake -i ../paraview-2.4.4 - -Change options: - -enable shared library: YES -prefix: ~/OpenFOAM/linux/paraview-2.4.4 - -gmake -gmake install - - -cd ~/OpenFOAM/linuxSrc - -mkdir ~/OpenFOAM/linux/paraview-2.4.4/include -cp ./paraview-2.4.4/VTK/Common/vtk* ~/OpenFOAM/linux/paraview-2.4.4/include/ -cp ./paraview-2.4.4/VTK/Filtering/vtk* ~/OpenFOAM/linux/paraview-2.4.4/include/ -cp ./paraview-2.4.4-obj/VTK/vtk* ~/OpenFOAM/linux/paraview-2.4.4/include/ -cp ./paraview-2.4.4-obj/ParaViewConfig.cmake ~/OpenFOAM/linux/paraview-2.4.4/lib/paraview-2.4/ - -linux64 copy commands - -mkdir ~/OpenFOAM/linux64/paraview-2.4.4/include -cp ./paraview-2.4.4/VTK/Common/vtk* ~/OpenFOAM/linux64/paraview-2.4.4/include/ -cp ./paraview-2.4.4/VTK/Filtering/vtk* ~/OpenFOAM/linux64/paraview-2.4.4/include/ -cp ./paraview-2.4.4-obj/VTK/vtk* ~/OpenFOAM/linux64/paraview-2.4.4/include/ -cp ./paraview-2.4.4-obj/ParaViewConfig.cmake ~/OpenFOAM/linux64/paraview-2.4.4/lib/paraview-2.4/ - - -4) build OpenFOAM - -foam -(this should take you to the ~/OpenFOAM/OpenFOAM-1.4.1-dev directory) - -./Allwmake - -This will build foam. - -5) check build - -source ~/.cshrc -icoFoam - -(this should run and report something like) - -wooster*101-> icoFoam -/*---------------------------------------------------------------------------*\ -| ========= | | -| \\ / F ield | foam-extend: Open Source CFD | -| \\ / O peration | Version: 1.4.1-dev | -| \\ / A nd | Web: http://www.openfoam.org | -| \\/ M anipulation | | -\*---------------------------------------------------------------------------*/ - -Exec : icoFoam -Date : Mar 06 2008 -Time : 17:25:53 -Host : wooster -PID : 8238 - -Usage: icoFoam [-parallel] - - ---> FOAM FATAL ERROR : Wrong number of arguments, expected 2 found 0 - - -FOAM exiting - - -SVN check-out command - -svn co https://openfoam-extend.svn.sourceforge.net/svnroot/openfoam-extend/trunk/Core/OpenFOAM-1.4.1-dev - - -SVK setup - -svk depotmap --init -svk mirror https://openfoam-extend.svn.sourceforge.net/svnroot/openfoam-extend/trunk/Core/OpenFOAM-1.4.1-dev //OpenFOAM-1.4.1-dev -svk sync //OpenFOAM-1.4.1-dev - -Ready to check-out - -Additional source packages: - - -http://www.lam-mpi.org/7.1/download.php -http://www.open-mpi.org/ -http://www.mico.org/ -http://www.zlib.net/ \ No newline at end of file From 6820387ef93bdbfd4adfdc23206495e718e04d0b Mon Sep 17 00:00:00 2001 From: Hrvoje Jasak Date: Thu, 2 Jan 2014 15:37:43 +0000 Subject: [PATCH 3/3] BUGFIX: Enabled sorted toc for swak compatibility --- src/foam/Make/files | 4 +- .../HashTables/HashPtrTable/HashPtrTable.C | 42 +- .../HashTables/HashPtrTable/HashPtrTable.H | 37 +- .../HashTables/HashPtrTable/HashPtrTableIO.C | 91 ++- .../containers/HashTables/HashSet/HashSet.C | 22 +- .../containers/HashTables/HashSet/HashSet.H | 18 +- .../HashTables/HashTable/HashTable.C | 240 ++++---- .../HashTables/HashTable/HashTable.H | 318 +++++++---- .../{HashTableName.C => HashTableCore.C} | 41 +- .../HashTables/HashTable/HashTableI.H | 537 +++++++++--------- .../HashTables/HashTable/HashTableIO.C | 17 +- .../StaticHashTable/StaticHashTable.C | 59 +- .../StaticHashTable/StaticHashTable.H | 40 +- ...cHashTableName.C => StaticHashTableCore.C} | 6 +- .../StaticHashTable/StaticHashTableI.H | 13 +- .../StaticHashTable/StaticHashTableIO.C | 6 +- 16 files changed, 824 insertions(+), 667 deletions(-) rename src/foam/containers/HashTables/HashTable/{HashTableName.C => HashTableCore.C} (65%) rename src/foam/containers/HashTables/StaticHashTable/{StaticHashTableName.C => StaticHashTableCore.C} (95%) diff --git a/src/foam/Make/files b/src/foam/Make/files index aa6d266f2..17a9e6590 100644 --- a/src/foam/Make/files +++ b/src/foam/Make/files @@ -81,8 +81,8 @@ coordinateSystems/coordinateRotation/axisCoordinateRotation.C primitives/random/Random.C -containers/HashTables/HashTable/HashTableName.C -containers/HashTables/StaticHashTable/StaticHashTableName.C +containers/HashTables/HashTable/HashTableCore.C +containers/HashTables/StaticHashTable/StaticHashTableCore.C containers/Lists/SortableList/ParSortableListName.C containers/Lists/PackedList/PackedListName.C containers/Lists/ListOps/ListOps.C diff --git a/src/foam/containers/HashTables/HashPtrTable/HashPtrTable.C b/src/foam/containers/HashTables/HashPtrTable/HashPtrTable.C index d51e828f8..eab7560b1 100644 --- a/src/foam/containers/HashTables/HashPtrTable/HashPtrTable.C +++ b/src/foam/containers/HashTables/HashPtrTable/HashPtrTable.C @@ -24,19 +24,13 @@ License \*---------------------------------------------------------------------------*/ #include "error.H" - #include "HashPtrTable.H" -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // Construct given initial table size template -HashPtrTable::HashPtrTable(label size) +Foam::HashPtrTable::HashPtrTable(const label size) : HashTable(size) {} @@ -44,14 +38,16 @@ HashPtrTable::HashPtrTable(label size) // Construct as copy template -HashPtrTable::HashPtrTable(const HashPtrTable& ht) +Foam::HashPtrTable::HashPtrTable +( + const HashPtrTable& ht +) : HashTable() { for (const_iterator iter = ht.begin(); iter != ht.end(); ++iter) { - // Bug fix, Microsoft port. HJ, 21/Mar/2011 - this->insert(iter.key(), iter()->clone().ptr()); + this->insert(iter.key(), new T(**iter)); } } @@ -59,7 +55,7 @@ HashPtrTable::HashPtrTable(const HashPtrTable& ht) // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // template -HashPtrTable::~HashPtrTable() +Foam::HashPtrTable::~HashPtrTable() { clear(); } @@ -68,7 +64,7 @@ HashPtrTable::~HashPtrTable() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template -T* HashPtrTable::remove(iterator& it) +T* Foam::HashPtrTable::remove(iterator& it) { T* elemPtr = *it; HashTable::erase(it); @@ -77,7 +73,7 @@ T* HashPtrTable::remove(iterator& it) template -bool HashPtrTable::erase(iterator& it) +bool Foam::HashPtrTable::erase(iterator& it) { T* elemPtr = *it; @@ -98,7 +94,7 @@ bool HashPtrTable::erase(iterator& it) template -void HashPtrTable::clear() +void Foam::HashPtrTable::clear() { for ( @@ -117,13 +113,13 @@ void HashPtrTable::clear() // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // template -void HashPtrTable::operator= +void Foam::HashPtrTable::operator= ( - const HashPtrTable& ht + const HashPtrTable& rhs ) { // Check for assignment to self - if (this == &ht) + if (this == &rhs) { FatalErrorIn ( @@ -133,20 +129,14 @@ void HashPtrTable::operator= << abort(FatalError); } - clear(); + this->clear(); - for(const_iterator iter = ht.begin(); iter != ht.end(); ++iter) + for (const_iterator iter = rhs.begin(); iter != rhs.end(); ++iter) { - // Bug fix, Microsoft port. HJ, 21/Mar/2011 - insert(iter.key(), iter()->clone().ptr()); + this->insert(iter.key(), new T(**iter)); } } - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * // #include "HashPtrTableIO.C" diff --git a/src/foam/containers/HashTables/HashPtrTable/HashPtrTable.H b/src/foam/containers/HashTables/HashPtrTable/HashPtrTable.H index fa710ef0f..53375a05a 100644 --- a/src/foam/containers/HashTables/HashPtrTable/HashPtrTable.H +++ b/src/foam/containers/HashTables/HashPtrTable/HashPtrTable.H @@ -50,34 +50,33 @@ class Ostream; template class HashPtrTable; -template Istream& operator>> -( - Istream&, - HashPtrTable& -); +template +Istream& operator>>(Istream&, HashPtrTable&); -template Ostream& operator<< -( - Ostream&, - const HashPtrTable& -); +template +Ostream& operator<<(Ostream&, const HashPtrTable&); /*---------------------------------------------------------------------------*\ Class HashPtrTable Declaration \*---------------------------------------------------------------------------*/ -template +template class HashPtrTable : public HashTable { - // Private member functions + // Private Member Functions //- Read from Istream using given Istream constructor class template void read(Istream&, const INew& inewt); + //- Read from dictionary using given dictionary constructor class + template + void read(const dictionary& dict, const INew& inewt); + + public: @@ -97,13 +96,16 @@ public: //- Construct from Istream using default Istream constructor class HashPtrTable(Istream&); + //- Construct from dictionary using default dictionary constructor + // class + HashPtrTable(const dictionary&); + //- Construct as copy HashPtrTable(const HashPtrTable&); - // Destructor - - ~HashPtrTable(); + //- Destructor + ~HashPtrTable(); // Member Functions @@ -119,6 +121,9 @@ public: //- Clear all entries from table void clear(); + //- Write + void write(Ostream& os) const; + // Member Operators @@ -127,7 +132,6 @@ public: // IOstream Operators -#ifndef SWIG friend Istream& operator>> ( Istream&, @@ -139,7 +143,6 @@ public: Ostream&, const HashPtrTable& ); -#endif }; diff --git a/src/foam/containers/HashTables/HashPtrTable/HashPtrTableIO.C b/src/foam/containers/HashTables/HashPtrTable/HashPtrTableIO.C index 819705e0f..f76464571 100644 --- a/src/foam/containers/HashTables/HashPtrTable/HashPtrTableIO.C +++ b/src/foam/containers/HashTables/HashPtrTable/HashPtrTableIO.C @@ -27,17 +27,13 @@ License #include "Istream.H" #include "Ostream.H" #include "INew.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ +#include "dictionary.H" // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * // template template -void HashPtrTable::read(Istream& is, const INew& inewt) +void Foam::HashPtrTable::read(Istream& is, const INew& inewt) { is.fatalCheck("HashPtrTable::read(Istream&, const INew&)"); @@ -54,7 +50,7 @@ void HashPtrTable::read(Istream& is, const INew& inewt) label s = firstToken.labelToken(); // Read beginning of contents - char listDelimiter = is.readBeginList("HashPtrTable"); + char delimiter = is.readBeginList("HashPtrTable"); if (s) { @@ -63,7 +59,7 @@ void HashPtrTable::read(Istream& is, const INew& inewt) this->resize(2*s); } - if (listDelimiter == token::BEGIN_LIST) + if (delimiter == token::BEGIN_LIST) { for (label i=0; i::read(Istream& is, const INew& inewt) } -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - template template -HashPtrTable::HashPtrTable(Istream& is, const INew& inewt) +void Foam::HashPtrTable::read +( + const dictionary& dict, + const INew& inewt +) { - read(is, inewt); + forAllConstIter(dictionary, dict, iter) + { + this->insert + ( + iter().keyword(), + inewt(dict.subDict(iter().keyword())).ptr() + ); + } } template -HashPtrTable::HashPtrTable(Istream& is) +void Foam::HashPtrTable::write(Ostream& os) const { - read(is, INew()); + + for + ( + typename HashPtrTable::const_iterator + iter = this->begin(); + iter != this->end(); + ++iter + ) + { + const T* ptr = iter(); + ptr->write(os); + } +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template +template +Foam::HashPtrTable::HashPtrTable(Istream& is, const INew& inewt) +{ + this->read(is, inewt); +} + + +template +Foam::HashPtrTable::HashPtrTable(Istream& is) +{ + this->read(is, INew()); +} + + +template +Foam::HashPtrTable::HashPtrTable(const dictionary& dict) +{ + this->read(dict, INew()); } // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // template -Istream& operator>>(Istream& is, HashPtrTable& L) +Foam::Istream& Foam::operator>>(Istream& is, HashPtrTable& L) { L.clear(); L.read(is, INew()); @@ -172,15 +212,16 @@ Istream& operator>>(Istream& is, HashPtrTable& L) template -Ostream& operator<<(Ostream& os, const HashPtrTable& L) +Foam::Ostream& Foam::operator<< +( + Ostream& os, + const HashPtrTable& L +) { - // Write size of HashPtrTable - os << nl << L.size(); + // Write size and start delimiter + os << nl << L.size() << nl << token::BEGIN_LIST << nl; - // Write beginning of contents - os << nl << token::BEGIN_LIST << nl; - - // Write HashPtrTable contents + // Write contents for ( typename HashPtrTable::const_iterator iter = L.begin(); @@ -191,7 +232,7 @@ Ostream& operator<<(Ostream& os, const HashPtrTable& L) os << iter.key() << token::SPACE << *iter() << nl; } - // Write end of contents + // Write end delimiter os << token::END_LIST; // Check state of IOstream @@ -201,8 +242,4 @@ Ostream& operator<<(Ostream& os, const HashPtrTable& L) } -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - // ************************************************************************* // diff --git a/src/foam/containers/HashTables/HashSet/HashSet.C b/src/foam/containers/HashTables/HashSet/HashSet.C index 6d327d68e..d701dd7ea 100644 --- a/src/foam/containers/HashTables/HashSet/HashSet.C +++ b/src/foam/containers/HashTables/HashSet/HashSet.C @@ -52,6 +52,24 @@ Foam::HashSet::HashSet } +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template +Foam::label Foam::HashSet::insert(const UList& lst) +{ + label count = 0; + forAll(lst, elemI) + { + if (this->insert(lst[elemI])) + { + ++count; + } + } + + return count; +} + + // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // template @@ -89,7 +107,7 @@ bool Foam::HashSet::operator==(const HashSet& rhs) const template bool Foam::HashSet::operator!=(const HashSet& rhs) const { - return !(this->operator==(rhs)); + return !(operator==(rhs)); } @@ -124,7 +142,7 @@ void Foam::HashSet::operator^=(const HashSet& rhs) // Add missed rhs elements, remove duplicate elements for (const_iterator iter = rhs.cbegin(); iter != rhs.cend(); ++iter) { - if (found(iter.key())) + if (this->found(iter.key())) { this->erase(iter.key()); } diff --git a/src/foam/containers/HashTables/HashSet/HashSet.H b/src/foam/containers/HashTables/HashSet/HashSet.H index bd9e5797e..fae9dbc91 100644 --- a/src/foam/containers/HashTables/HashSet/HashSet.H +++ b/src/foam/containers/HashTables/HashSet/HashSet.H @@ -128,10 +128,26 @@ public: return HashTable::insert(key, nil()); } + //- Insert keys from a UList of Key + // Return the number of new elements inserted + label insert(const UList&); + //- Same as insert (cannot overwrite nil content) bool set(const Key& key) { - return HashTable::insert(key, nil()); + return insert(key); + } + + //- Same as insert (cannot overwrite nil content) + label set(const UList& lst) + { + return insert(lst); + } + + //- Unset the specified key - same as erase + bool unset(const Key& key) + { + return HashTable::erase(key); } diff --git a/src/foam/containers/HashTables/HashTable/HashTable.C b/src/foam/containers/HashTables/HashTable/HashTable.C index 107aa5406..fd86ee0da 100644 --- a/src/foam/containers/HashTables/HashTable/HashTable.C +++ b/src/foam/containers/HashTables/HashTable/HashTable.C @@ -29,44 +29,15 @@ License #include "HashTable.H" #include "List.H" -// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * // - -template -Foam::label Foam::HashTable::canonicalSize(const label size) -{ - if (size < 1) - { - return 0; - } - - // enforce power of two - unsigned int goodSize = size; - - if (goodSize & (goodSize - 1)) - { - // brute-force is fast enough - goodSize = 1; - while (goodSize < unsigned(size)) - { - goodSize <<= 1; - } - } - - return goodSize; -} - - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template Foam::HashTable::HashTable(const label size) : - HashTableName(), + HashTableCore(), nElmts_(0), - tableSize_(canonicalSize(size)), - table_(NULL), - endIter_(*this, NULL, 0), - endConstIter_(*this, NULL, 0) + tableSize_(HashTableCore::canonicalSize(size)), + table_(NULL) { if (tableSize_) { @@ -83,12 +54,10 @@ Foam::HashTable::HashTable(const label size) template Foam::HashTable::HashTable(const HashTable& ht) : - HashTableName(), + HashTableCore(), nElmts_(0), tableSize_(ht.tableSize_), - table_(NULL), - endIter_(*this, NULL, 0), - endConstIter_(*this, NULL, 0) + table_(NULL) { if (tableSize_) { @@ -112,12 +81,10 @@ Foam::HashTable::HashTable const Xfer >& ht ) : - HashTableName(), + HashTableCore(), nElmts_(0), tableSize_(0), - table_(NULL), - endIter_(*this, NULL, 0), - endConstIter_(*this, NULL, 0) + table_(NULL) { transfer(ht()); } @@ -181,7 +148,7 @@ Foam::HashTable::find { if (key == ep->key_) { - return iterator(*this, ep, hashIdx); + return iterator(this, ep, hashIdx); } } } @@ -194,7 +161,7 @@ Foam::HashTable::find } # endif - return end(); + return iterator(); } @@ -213,7 +180,7 @@ Foam::HashTable::find { if (key == ep->key_) { - return const_iterator(*this, ep, hashIdx); + return const_iterator(this, ep, hashIdx); } } } @@ -226,23 +193,32 @@ Foam::HashTable::find } # endif - return cend(); + return const_iterator(); } -// Return the table of contents template Foam::List Foam::HashTable::toc() const { - List tofc(nElmts_); - label i = 0; + List keys(nElmts_); + label keyI = 0; for (const_iterator iter = cbegin(); iter != cend(); ++iter) { - tofc[i++] = iter.key(); + keys[keyI++] = iter.key(); } - return tofc; + return keys; +} + + +template +Foam::List Foam::HashTable::sortedToc() const +{ + List sortedLst = this->toc(); + sort(sortedLst); + + return sortedLst; } @@ -280,7 +256,7 @@ bool Foam::HashTable::set table_[hashIdx] = new hashedEntry(key, table_[hashIdx], newEntry); nElmts_++; - if (double(nElmts_)/tableSize_ > 0.8) + if (double(nElmts_)/tableSize_ > 0.8 && tableSize_ < maxTableSize) { # ifdef FULLDEBUG if (debug) @@ -332,18 +308,22 @@ bool Foam::HashTable::set template -bool Foam::HashTable::erase(const iterator& cit) +bool Foam::HashTable::iteratorBase::erase() { - if (cit.elmtPtr_) // note: endIter_ also has 0 elmtPtr_ + // note: entryPtr_ is NULL for end(), so this catches that too + if (entryPtr_) { - iterator& it = const_cast(cit); - - // Search element before elmtPtr_ + // Search element before entryPtr_ hashedEntry* prev = 0; - for (hashedEntry* ep = table_[it.hashIndex_]; ep; ep = ep->next_) + for + ( + hashedEntry* ep = hashTable_->table_[hashIndex_]; + ep; + ep = ep->next_ + ) { - if (ep == it.elmtPtr_) + if (ep == entryPtr_) { break; } @@ -352,98 +332,76 @@ bool Foam::HashTable::erase(const iterator& cit) if (prev) { - // Have element before elmtPtr - prev->next_ = it.elmtPtr_->next_; - delete it.elmtPtr_; - it.elmtPtr_ = prev; + // has an element before entryPtr - reposition to there + prev->next_ = entryPtr_->next_; + delete entryPtr_; + entryPtr_ = prev; } else { - // elmtPtr is first element on SLList - table_[it.hashIndex_] = it.elmtPtr_->next_; - delete it.elmtPtr_; + // entryPtr was first element on SLList + hashTable_->table_[hashIndex_] = entryPtr_->next_; + delete entryPtr_; - // Search back for previous non-zero table entry - while (--it.hashIndex_ >= 0 && !table_[it.hashIndex_]) - {} + // assign any non-NULL pointer value so it doesn't look + // like end()/cend() + entryPtr_ = reinterpret_cast(this); - if (it.hashIndex_ >= 0) - { - // In table entry search for last element - it.elmtPtr_ = table_[it.hashIndex_]; - - while (it.elmtPtr_ && it.elmtPtr_->next_) - { - it.elmtPtr_ = it.elmtPtr_->next_; - } - } - else - { - // No previous found. Mark with special value which is - // - not end()/cend() - // - handled by operator++ - it.elmtPtr_ = reinterpret_cast(this); - it.hashIndex_ = -1; - } + // Mark with special hashIndex value to signal it has been rewound. + // The next increment will bring it back to the present location. + // + // From the current position 'curPos', we wish to continue at + // prevPos='curPos-1', which we mark as markPos='-curPos-1'. + // The negative lets us notice it is special, the extra '-1' + // is needed to avoid ambiguity for position '0'. + // To retrieve prevPos, we would later use '-(markPos+1) - 1' + hashIndex_ = -hashIndex_ - 1; } - nElmts_--; - -# ifdef FULLDEBUG - if (debug) - { - Info<< "HashTable::erase(iterator&) : " - << "hashedEntry " << it.elmtPtr_->key_ << " removed.\n"; - } -# endif + hashTable_->nElmts_--; return true; } else { -# ifdef FULLDEBUG - if (debug) - { - Info<< "HashTable::erase(iterator&) : " - << "cannot remove hashedEntry from hash table\n"; - } -# endif - return false; } } + +// NOTE: +// We use (const iterator&) here, but manipulate its contents anyhow. +// The parameter should be (iterator&), but then the compiler doesn't find +// it correctly and tries to call as (iterator) instead. +// +template +bool Foam::HashTable::erase(const iterator& iter) +{ + // adjust iterator after erase + return const_cast(iter).erase(); +} + + template bool Foam::HashTable::erase(const Key& key) { - iterator fnd = find(key); - - if (fnd != end()) - { - return erase(fnd); - } - else - { - return false; - } + return erase(find(key)); } template Foam::label Foam::HashTable::erase(const UList& keys) { + const label nTotal = nElmts_; label count = 0; - // Remove listed keys from this table - if (this->size()) + // Remove listed keys from this table - terminates early if possible + for (label keyI = 0; count < nTotal && keyI < keys.size(); ++keyI) { - forAll(keys, keyI) + if (erase(keys[keyI])) { - if (erase(keys[keyI])) - { - count++; - } + count++; } } @@ -477,7 +435,7 @@ Foam::label Foam::HashTable::erase template void Foam::HashTable::resize(const label sz) { - label newSize = canonicalSize(sz); + label newSize = HashTableCore::canonicalSize(sz); if (newSize == tableSize_) { @@ -492,22 +450,22 @@ void Foam::HashTable::resize(const label sz) return; } - HashTable* newTable = new HashTable(newSize); + HashTable* tmpTable = new HashTable(newSize); for (const_iterator iter = cbegin(); iter != cend(); ++iter) { - newTable->insert(iter.key(), *iter); + tmpTable->insert(iter.key(), *iter); } - label oldTableSize = tableSize_; - tableSize_ = newTable->tableSize_; - newTable->tableSize_ = oldTableSize; + label oldSize = tableSize_; + tableSize_ = tmpTable->tableSize_; + tmpTable->tableSize_ = oldSize; hashedEntry** oldTable = table_; - table_ = newTable->table_; - newTable->table_ = oldTable; + table_ = tmpTable->table_; + tmpTable->table_ = oldTable; - delete newTable; + delete tmpTable; } @@ -543,6 +501,19 @@ void Foam::HashTable::clearStorage() } +template +void Foam::HashTable::shrink() +{ + const label newSize = HashTableCore::canonicalSize(nElmts_); + + if (newSize < tableSize_) + { + // avoid having the table disappear on us + resize(newSize ? newSize : 2); + } +} + + template void Foam::HashTable::transfer(HashTable& ht) { @@ -606,18 +577,12 @@ bool Foam::HashTable::operator== const HashTable& rhs ) const { - // Are all my elements in rhs? - for (const_iterator iter = cbegin(); iter != cend(); ++iter) + // sizes (number of keys) must match + if (size() != rhs.size()) { - const_iterator fnd = rhs.find(iter.key()); - - if (fnd == rhs.cend() || fnd() != iter()) - { - return false; - } + return false; } - // Are all rhs elements in me? for (const_iterator iter = rhs.cbegin(); iter != rhs.cend(); ++iter) { const_iterator fnd = find(iter.key()); @@ -627,6 +592,7 @@ bool Foam::HashTable::operator== return false; } } + return true; } diff --git a/src/foam/containers/HashTables/HashTable/HashTable.H b/src/foam/containers/HashTables/HashTable/HashTable.H index a62c35ab3..f90c2b03e 100644 --- a/src/foam/containers/HashTables/HashTable/HashTable.H +++ b/src/foam/containers/HashTables/HashTable/HashTable.H @@ -70,23 +70,59 @@ Ostream& operator<<(Ostream&, const HashTable&); /*---------------------------------------------------------------------------*\ - Class HashTableName Declaration + Class HashTableCore Declaration \*---------------------------------------------------------------------------*/ -TemplateName(HashTable); +//- Template-invariant bits for HashTable +struct HashTableCore +{ + //- Return a canonical (power-of-two) size + static label canonicalSize(const label); + + //- Maximum allowable table size + static const label maxTableSize; + + //- Construct null + HashTableCore() + {} + + //- Define template name and debug + ClassName("HashTable"); + + //- A zero-sized end iterator + struct iteratorEnd + { + //- Construct null + iteratorEnd() + {} + }; + + //- iteratorEnd set to beyond the end of any HashTable + inline static iteratorEnd cend() + { + return iteratorEnd(); + } + + //- iteratorEnd set to beyond the end of any HashTable + inline static iteratorEnd end() + { + return iteratorEnd(); + } +}; /*---------------------------------------------------------------------------*\ - Class HashTable Declaration + Class HashTable Declaration \*---------------------------------------------------------------------------*/ template class HashTable : - public HashTableName + public HashTableCore { // Private data type for table entries + //- Structure to hold a hashed entry with SLList for collisions struct hashedEntry { //- The lookup key @@ -98,18 +134,17 @@ class HashTable //- The data object T obj_; - //- Constructors + //- Construct from key, next pointer and object + inline hashedEntry(const Key&, hashedEntry* next, const T&); - //- Construct given key, next pointer and object - inline hashedEntry - ( - const Key&, - hashedEntry* next, - const T& newEntry - ); - //- Dissallow construction as copy - hashedEntry(const hashedEntry&); + private: + + //- Disallow default bitwise copy construct + hashedEntry(const hashedEntry&); + + //- Disallow default bitwise assignment + void operator=(const hashedEntry&); }; @@ -118,7 +153,7 @@ class HashTable //- The current number of elements in table label nElmts_; - //- Number of primary entries allocated in table (not necessarily used) + //- Number of primary entries allocated in table label tableSize_; //- The table of primary entries @@ -137,27 +172,32 @@ class HashTable //- Assign a new hashedEntry to a possibly already existing key bool set(const Key&, const T& newElmt, bool protect); - public: + // Forward declaration of iterators + + class iteratorBase; + class iterator; + class const_iterator; + //- Declare friendship with the HashPtrTable class template friend class HashPtrTable; + //- Declare friendship with the iteratorBase + friend class iteratorBase; - // Forward declaration of STL iterators - - class iterator; + //- Declare friendship with the iterator friend class iterator; - class const_iterator; + //- Declare friendship with the const_iterator friend class const_iterator; // Constructors //- Construct given initial table size - HashTable(const label size = 128); + explicit HashTable(const label size = 128); //- Construct from Istream HashTable(Istream&, const label size = 128); @@ -169,16 +209,18 @@ public: HashTable(const Xfer >&); - // Destructor - - ~HashTable(); + //- Destructor + ~HashTable(); // Member Functions // Access - //- Return number of elements in table. + //- The size of the underlying table + inline label capacity() const; + + //- Return number of elements in table inline label size() const; //- Return true if the hash table is empty @@ -198,9 +240,13 @@ public: //- Return the table of contents List toc() const; + //- Return the table of contents as a sorted list + List sortedToc() const; + //- Print information Ostream& printInfo(Ostream&) const; + // Edit //- Insert a new hashedEntry @@ -209,10 +255,11 @@ public: //- Assign a new hashedEntry, overwriting existing entries inline bool set(const Key&, const T& newElmt); - //- Erase an hashedEntry specified by given iterator + //- Erase a hashedEntry specified by given iterator + // This invalidates the iterator until the next operator++ bool erase(const iterator&); - //- Erase an hashedEntry specified by given key if in table + //- Erase a hashedEntry specified by the given key bool erase(const Key&); //- Remove entries given by the listed keys from this HashTable @@ -236,8 +283,11 @@ public: // Equivalent to clear() followed by resize(0) void clearStorage(); + //- Shrink the allocated table to approx. twice number of elements + void shrink(); + //- Transfer the contents of the argument table into this table - // and annull the argument table. + // and annul the argument table. void transfer(HashTable&); //- Transfer contents to the Xfer container @@ -246,27 +296,27 @@ public: // Member Operators - //- Find and return an hashedEntry + //- Find and return a hashedEntry inline T& operator[](const Key&); - //- Find and return an hashedEntry + //- Find and return a hashedEntry inline const T& operator[](const Key&) const; - //- Find and return an hashedEntry, create it null if not present. + //- Find and return a hashedEntry, create it null if not present inline T& operator()(const Key&); //- Assignment void operator=(const HashTable&); - //- Equality. Two hash tables are equal if all contents of first are - // also in second and vice versa. So does not depend on table size or - // order! + //- Equality. Hash tables are equal if the keys and values are equal. + // Independent of table storage size and table order. bool operator==(const HashTable&) const; //- The opposite of the equality operation. Takes linear time. bool operator!=(const HashTable&) const; + // STL type definitions //- Type of values the HashTable contains. @@ -285,138 +335,198 @@ public: typedef label size_type; - // STL iterator + // Iterators and helpers - //- An STL-conforming iterator - class iterator + //- The iterator base for HashTable + // Note: data and functions are protected, to allow reuse by iterator + // and prevent most external usage. + // iterator and const_iterator have the same size, allowing + // us to reinterpret_cast between them (if desired) + class iteratorBase { - friend class HashTable; - friend class const_iterator; + // Private Data - // Private data - - //- Reference to the HashTable this is an iterator for - HashTable& hashTable_; + //- Pointer to the HashTable for which this is an iterator + // This also lets us use the default bitwise copy/assignment + HashTable* hashTable_; //- Current element - hashedEntry* elmtPtr_; + hashedEntry* entryPtr_; //- Current hash index label hashIndex_; + + protected: + + // Constructors + + //- Construct null - equivalent to an 'end' position + inline iteratorBase(); + + //- Construct from hash table, moving to its 'begin' position + inline explicit iteratorBase + ( + const HashTable* curHashTable + ); + + //- Construct from hash table, element and hash index + inline explicit iteratorBase + ( + const HashTable* curHashTable, + const hashedEntry* elmt, + const label hashIndex + ); + + + // Protected Member Functions + + //- Increment to the next position + inline void increment(); + + //- Erase the HashTable element at the current position + bool erase(); + + //- Return non-const access to referenced object + inline T& object(); + + //- Return const access to referenced object + inline const T& cobject() const; + + + public: + + // Member operators + + // Access + + //- Return the Key corresponding to the iterator + inline const Key& key() const; + + //- Compare hashedEntry element pointers + inline bool operator==(const iteratorBase&) const; + inline bool operator!=(const iteratorBase&) const; + + //- Compare hashedEntry to iteratorEnd pointers + inline bool operator==(const iteratorEnd& unused) const; + inline bool operator!=(const iteratorEnd& unused) const; + }; + + + //- An STL-conforming iterator + class iterator + : + public iteratorBase + { + friend class HashTable; + + // Private Member Functions + + //- Construct from hash table, moving to its 'begin' position + inline explicit iterator + ( + HashTable* curHashTable + ); + + //- Construct from hash table, element and hash index + inline explicit iterator + ( + HashTable* curHashTable, + hashedEntry* elmt, + const label hashIndex + ); + + public: // Constructors - //- Construct from hash table, element and hash index - inline iterator - ( - HashTable& curHashTable, - hashedEntry* elmt, - label hashIndex - ); + //- Construct null (end iterator) + inline iterator(); + + //- Construct end iterator + inline iterator(const iteratorEnd& unused); + // Member operators - inline void operator=(const iterator&); - - inline bool operator==(const iterator&) const; - inline bool operator!=(const iterator&) const; - - inline bool operator==(const const_iterator&) const; - inline bool operator!=(const const_iterator&) const; - + //- Return referenced hash value inline T& operator*(); inline T& operator()(); + //- Return referenced hash value inline const T& operator*() const; inline const T& operator()() const; inline iterator& operator++(); inline iterator operator++(int); - - inline const Key& key() const; }; - - //- iterator set to the begining of the HashTable + //- iterator set to the beginning of the HashTable inline iterator begin(); - //- iterator set to beyond the end of the HashTable - inline const iterator& end(); - // STL const_iterator //- An STL-conforming const_iterator class const_iterator + : + public iteratorBase { - friend class iterator; + friend class HashTable; - // Private data + // Private Member Functions - //- Reference to the HashTable this is an iterator for - const HashTable& hashTable_; + //- Construct from hash table, moving to its 'begin' position + inline explicit const_iterator + ( + const HashTable* curHashTable + ); - //- Current element - const hashedEntry* elmtPtr_; - - //- Current hash index - label hashIndex_; + //- Construct from hash table, element and hash index + inline explicit const_iterator + ( + const HashTable* curHashTable, + const hashedEntry* elmt, + const label hashIndex + ); public: // Constructors - //- Construct from hash table, element and hash index - inline const_iterator - ( - const HashTable& curHashTable, - const hashedEntry* elmt, - label hashIndex - ); + //- Construct null (end iterator) + inline const_iterator(); - //- Construct from the non-const iterator + //- Construct from iterator inline const_iterator(const iterator&); + //- Construct end iterator + inline const_iterator(const iteratorEnd& unused); + // Member operators - inline void operator=(const const_iterator&); - - inline bool operator==(const const_iterator&) const; - inline bool operator!=(const const_iterator&) const; - - inline bool operator==(const iterator&) const; - inline bool operator!=(const iterator&) const; - + //- Return referenced hash value inline const T& operator*() const; inline const T& operator()() const; inline const_iterator& operator++(); inline const_iterator operator++(int); - inline const Key& key() const; }; //- const_iterator set to the beginning of the HashTable inline const_iterator cbegin() const; - //- const_iterator set to beyond the end of the HashTable - inline const const_iterator& cend() const; - //- const_iterator set to the beginning of the HashTable inline const_iterator begin() const; - //- const_iterator set to beyond the end of the HashTable - inline const const_iterator& end() const; - // IOstream Operator -#ifndef SWIG friend Istream& operator>> ( Istream&, @@ -428,16 +538,6 @@ public: Ostream&, const HashTable& ); -#endif - - -private: - - //- iterator returned by end() - iterator endIter_; - - //- const_iterator returned by end() - const_iterator endConstIter_; }; diff --git a/src/foam/containers/HashTables/HashTable/HashTableName.C b/src/foam/containers/HashTables/HashTable/HashTableCore.C similarity index 65% rename from src/foam/containers/HashTables/HashTable/HashTableName.C rename to src/foam/containers/HashTables/HashTable/HashTableCore.C index 03e95b0c3..c31bb5ba6 100644 --- a/src/foam/containers/HashTables/HashTable/HashTableName.C +++ b/src/foam/containers/HashTables/HashTable/HashTableCore.C @@ -24,9 +24,48 @@ License \*---------------------------------------------------------------------------*/ #include "HashTable.H" +#include "uLabel.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // -defineTypeNameAndDebug(Foam::HashTableName, 0); +namespace Foam +{ +defineTypeNameAndDebug(HashTableCore, 0); +} + +const Foam::label Foam::HashTableCore::maxTableSize +( + Foam::HashTableCore::canonicalSize + ( + Foam::labelMax/2 + ) +); + + +// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // + +Foam::label Foam::HashTableCore::canonicalSize(const label size) +{ + if (size < 1) + { + return 0; + } + + // enforce power of two + uLabel goodSize = size; + + if (goodSize & (goodSize - 1)) + { + // brute-force is fast enough + goodSize = 1; + while (goodSize < unsigned(size)) + { + goodSize <<= 1; + } + } + + return goodSize; +} + // ************************************************************************* // diff --git a/src/foam/containers/HashTables/HashTable/HashTableI.H b/src/foam/containers/HashTables/HashTable/HashTableI.H index 8aeaa5b8f..19bff973f 100644 --- a/src/foam/containers/HashTables/HashTable/HashTableI.H +++ b/src/foam/containers/HashTables/HashTable/HashTableI.H @@ -32,12 +32,12 @@ inline Foam::HashTable::hashedEntry::hashedEntry ( const Key& key, hashedEntry* next, - const T& newEntry + const T& obj ) : key_(key), next_(next), - obj_(newEntry) + obj_(obj) {} @@ -54,6 +54,13 @@ Foam::HashTable::hashKeyIndex(const Key& key) const // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +template +inline Foam::label Foam::HashTable::capacity() const +{ + return tableSize_; +} + + template inline Foam::label Foam::HashTable::size() const { @@ -75,7 +82,7 @@ inline bool Foam::HashTable::insert const T& newEntry ) { - return set(key, newEntry, true); + return this->set(key, newEntry, true); } @@ -86,7 +93,7 @@ inline bool Foam::HashTable::set const T& newEntry ) { - return set(key, newEntry, false); + return this->set(key, newEntry, false); } @@ -103,9 +110,9 @@ Foam::HashTable::xfer() template inline T& Foam::HashTable::operator[](const Key& key) { - iterator iter = find(key); + iterator iter = this->find(key); - if (iter == end()) + if (iter == this->end()) { FatalErrorIn("HashTable::operator[](const Key&)") << key << " not found in table. Valid entries: " @@ -120,9 +127,9 @@ inline T& Foam::HashTable::operator[](const Key& key) template inline const T& Foam::HashTable::operator[](const Key& key) const { - const_iterator iter = find(key); + const_iterator iter = this->find(key); - if (iter == cend()) + if (iter == this->cend()) { FatalErrorIn("HashTable::operator[](const Key&) const") << key << " not found in table. Valid entries: " @@ -137,11 +144,11 @@ inline const T& Foam::HashTable::operator[](const Key& key) const template inline T& Foam::HashTable::operator()(const Key& key) { - iterator iter = find(key); + iterator iter = this->find(key); - if (iter == end()) + if (iter == this->end()) { - insert(key, T()); + this->insert(key, T()); return *find(key); } else @@ -151,78 +158,215 @@ inline T& Foam::HashTable::operator()(const Key& key) } -// * * * * * * * * * * * * * * * * STL iterator * * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * * iterator base * * * * * * * * * * * * * * * // template -inline Foam::HashTable::iterator::iterator +inline Foam::HashTable::iteratorBase::iteratorBase() +: + hashTable_(0), + entryPtr_(0), + hashIndex_(0) +{} + + +template +inline Foam::HashTable::iteratorBase::iteratorBase ( - HashTable& hashTbl, - hashedEntry* elmt, - label hashIndex + const HashTable* hashTbl ) : - hashTable_(hashTbl), - elmtPtr_(elmt), + hashTable_(const_cast*>(hashTbl)), + entryPtr_(0), + hashIndex_(0) +{ + if (hashTable_->nElmts_) + { + // find first non-NULL table entry + while + ( + !(entryPtr_ = hashTable_->table_[hashIndex_]) + && ++hashIndex_ < hashTable_->tableSize_ + ) + {} + + if (hashIndex_ >= hashTable_->tableSize_) + { + // make into an end iterator + entryPtr_ = 0; + hashIndex_ = 0; + } + } +} + + +template +inline Foam::HashTable::iteratorBase::iteratorBase +( + const HashTable* hashTbl, + const hashedEntry* elmt, + const label hashIndex +) +: + hashTable_(const_cast*>(hashTbl)), + entryPtr_(const_cast(elmt)), hashIndex_(hashIndex) {} template -inline void Foam::HashTable::iterator::operator= +inline void +Foam::HashTable::iteratorBase::increment() +{ + // A negative index is a special value from erase + if (hashIndex_ < 0) + { + // the markPos='-curPos-1', but we wish to continue at 'curPos-1' + // thus use '-(markPos+1) -1' + hashIndex_ = -(hashIndex_+1) - 1; + } + else if (entryPtr_) + { + if (entryPtr_->next_) + { + // Move to next element on the SLList + entryPtr_ = entryPtr_->next_; + return; + } + } + // else + // { + // // if we reach here (entryPtr_ is NULL) it is already at the end() + // // we should probably stop + // } + + + // Step to the next table entry + while + ( + ++hashIndex_ < hashTable_->tableSize_ + && !(entryPtr_ = hashTable_->table_[hashIndex_]) + ) + {} + + if (hashIndex_ >= hashTable_->tableSize_) + { + // make into an end iterator + entryPtr_ = 0; + hashIndex_ = 0; + } +} + + +template +inline +const Key& Foam::HashTable::iteratorBase::key() const +{ + return entryPtr_->key_; +} + + +template +inline T& +Foam::HashTable::iteratorBase::object() +{ + return entryPtr_->obj_; +} + + +template +inline const T& +Foam::HashTable::iteratorBase::cobject() const +{ + return entryPtr_->obj_; +} + + +template +inline bool Foam::HashTable::iteratorBase::operator== ( - const iterator& iter + const iteratorBase& iter +) const +{ + return entryPtr_ == iter.entryPtr_; +} + + +template +inline bool Foam::HashTable::iteratorBase::operator!= +( + const iteratorBase& iter +) const +{ + return entryPtr_ != iter.entryPtr_; +} + + +template +inline bool Foam::HashTable::iteratorBase::operator== +( + const iteratorEnd& +) const +{ + return !entryPtr_; +} + + +template +inline bool Foam::HashTable::iteratorBase::operator!= +( + const iteratorEnd& +) const +{ + return entryPtr_; +} + + +// * * * * * * * * * * * * * * * * STL iterator * * * * * * * * * * * * * * // + +template +inline Foam::HashTable::iterator::iterator() +: + iteratorBase() +{} + + +template +inline Foam::HashTable::iterator::iterator +( + const iteratorEnd& ) -{ - elmtPtr_ = iter.elmtPtr_; - hashIndex_ = iter.hashIndex_; -} +: + iteratorBase() +{} template -inline bool Foam::HashTable::iterator::operator== +inline Foam::HashTable::iterator::iterator ( - const iterator& iter -) const -{ - return elmtPtr_ == iter.elmtPtr_; -} + HashTable* hashTbl +) +: + iteratorBase(hashTbl) +{} template -inline bool Foam::HashTable::iterator::operator!= +inline Foam::HashTable::iterator::iterator ( - const iterator& iter -) const -{ - return elmtPtr_ != iter.elmtPtr_; -} - - -template -inline bool Foam::HashTable::iterator::operator== -( - const const_iterator& iter -) const -{ - return elmtPtr_ == iter.elmtPtr_; -} - - -template -inline bool Foam::HashTable::iterator::operator!= -( - const const_iterator& iter -) const -{ - return elmtPtr_ != iter.elmtPtr_; -} + HashTable* hashTbl, + hashedEntry* elmt, + const label hashIndex +) +: + iteratorBase(hashTbl, elmt, hashIndex) +{} template inline T& Foam::HashTable::iterator::operator*() { - return elmtPtr_->obj_; + return this->object(); } @@ -230,7 +374,7 @@ template inline T& Foam::HashTable::iterator::operator()() { - return elmtPtr_->obj_; + return this->object(); } @@ -238,7 +382,7 @@ template inline const T& Foam::HashTable::iterator::operator*() const { - return elmtPtr_->obj_; + return this->cobject(); } @@ -246,7 +390,7 @@ template inline const T& Foam::HashTable::iterator::operator()() const { - return elmtPtr_->obj_; + return this->cobject(); } @@ -255,53 +399,18 @@ inline typename Foam::HashTable::iterator& Foam::HashTable::iterator::operator++() { - // Check for special value from erase. (sets hashIndex to -1) - if (hashIndex_ >= 0) - { - // Do we have additional elements on the SLList? - if (elmtPtr_ && elmtPtr_->next_) - { - elmtPtr_ = elmtPtr_->next_; - return *this; - } - } - - // Step to the next table entry - while - ( - ++hashIndex_ < hashTable_.tableSize_ - && !(elmtPtr_ = hashTable_.table_[hashIndex_]) - ) - {} - - if (hashIndex_ == hashTable_.tableSize_) - { - // make end iterator - elmtPtr_ = 0; - hashIndex_ = 0; - } + this->increment(); return *this; } template inline typename Foam::HashTable::iterator -Foam::HashTable::iterator::operator++ -( - int -) +Foam::HashTable::iterator::operator++(int) { - iterator tmp = *this; - ++*this; - return tmp; -} - - -template -inline -const Key& Foam::HashTable::iterator::key() const -{ - return elmtPtr_->key_; + iterator old = *this; + this->increment(); + return old; } @@ -309,135 +418,74 @@ template inline typename Foam::HashTable::iterator Foam::HashTable::begin() { - label i = 0; - - if (nElmts_) - { - while (table_ && !table_[i] && ++i < tableSize_) - {} - } - else - { - i = tableSize_; - } - - if (i == tableSize_) - { -# ifdef FULLDEBUG - if (debug) - { - Info<< "HashTable is empty\n"; - } -# endif - - return HashTable::endIter_; - } - else - { - return iterator(*this, table_[i], i); - } -} - - -template -inline const typename Foam::HashTable::iterator& -Foam::HashTable::end() -{ - return HashTable::endIter_; + return iterator(this); } // * * * * * * * * * * * * * * * STL const_iterator * * * * * * * * * * * * * // +template +inline Foam::HashTable::const_iterator::const_iterator() +: + iteratorBase() +{} + + template inline Foam::HashTable::const_iterator::const_iterator ( - const HashTable& hashTbl, + const HashTable::iterator& iter +) +: + iteratorBase(iter) +{} + + +template +inline Foam::HashTable::const_iterator::const_iterator +( + const iteratorEnd& +) +: + iteratorBase() +{} + + +template +inline Foam::HashTable::const_iterator::const_iterator +( + const HashTable* hashTbl +) +: + iteratorBase(hashTbl) +{} + + +template +inline Foam::HashTable::const_iterator::const_iterator +( + const HashTable* hashTbl, const hashedEntry* elmt, - label hashIndex + const label hashIndex ) : - hashTable_(hashTbl), - elmtPtr_(elmt), - hashIndex_(hashIndex) + iteratorBase(hashTbl, elmt, hashIndex) {} -template -inline Foam::HashTable::const_iterator::const_iterator -( - const iterator& iter -) -: - hashTable_(iter.hashTable_), - elmtPtr_(iter.elmtPtr_), - hashIndex_(iter.hashIndex_) -{} - - -template -inline void Foam::HashTable::const_iterator::operator= -( - const const_iterator& iter -) -{ - elmtPtr_ = iter.elmtPtr_; - hashIndex_ = iter.hashIndex_; -} - - -template -inline bool Foam::HashTable::const_iterator::operator== -( - const const_iterator& iter -) const -{ - return elmtPtr_ == iter.elmtPtr_; -} - - -template -inline bool Foam::HashTable::const_iterator::operator!= -( - const const_iterator& iter -) const -{ - return elmtPtr_ != iter.elmtPtr_; -} - - -template -inline bool Foam::HashTable::const_iterator::operator== -( - const iterator& iter -) const -{ - return elmtPtr_ == iter.elmtPtr_; -} - - -template -inline bool Foam::HashTable::const_iterator::operator!= -( - const iterator& iter -) const -{ - return elmtPtr_ != iter.elmtPtr_; -} - - template inline const T& Foam::HashTable::const_iterator::operator*() const { - return elmtPtr_->obj_; + return this->cobject(); } + template inline const T& Foam::HashTable::const_iterator::operator()() const { - return elmtPtr_->obj_; + return this->cobject(); } @@ -446,43 +494,18 @@ inline typename Foam::HashTable::const_iterator& Foam::HashTable::const_iterator::operator++() { - if - ( - !(elmtPtr_ = elmtPtr_->next_) - && ++hashIndex_ < hashTable_.tableSize_ - && !(elmtPtr_ = hashTable_.table_[hashIndex_]) - ) - { - while - ( - ++hashIndex_ < hashTable_.tableSize_ - && !(elmtPtr_ = hashTable_.table_[hashIndex_]) - ) - {} - } - + this->increment(); return *this; } template inline typename Foam::HashTable::const_iterator -Foam::HashTable::const_iterator::operator++ -( - int -) +Foam::HashTable::const_iterator::operator++(int) { - const_iterator tmp = *this; - ++*this; - return tmp; -} - - -template -inline -const Key& Foam::HashTable::const_iterator::key() const -{ - return elmtPtr_->key_; + const_iterator old = *this; + this->increment(); + return old; } @@ -490,41 +513,7 @@ template inline typename Foam::HashTable::const_iterator Foam::HashTable::cbegin() const { - label i = 0; - - if (nElmts_) - { - while (table_ && !table_[i] && ++i < tableSize_) - {} - } - else - { - i = tableSize_; - } - - if (i == tableSize_) - { -# ifdef FULLDEBUG - if (debug) - { - Info<< "HashTable is empty\n"; - } -# endif - - return HashTable::endConstIter_; - } - else - { - return const_iterator(*this, table_[i], i); - } -} - - -template -inline const typename Foam::HashTable::const_iterator& -Foam::HashTable::cend() const -{ - return HashTable::endConstIter_; + return const_iterator(this); } @@ -536,12 +525,4 @@ Foam::HashTable::begin() const } -template -inline const typename Foam::HashTable::const_iterator& -Foam::HashTable::end() const -{ - return HashTable::endConstIter_; -} - - // ************************************************************************* // diff --git a/src/foam/containers/HashTables/HashTable/HashTableIO.C b/src/foam/containers/HashTables/HashTable/HashTableIO.C index 04367c4ff..9c3bfee4a 100644 --- a/src/foam/containers/HashTables/HashTable/HashTableIO.C +++ b/src/foam/containers/HashTables/HashTable/HashTableIO.C @@ -32,16 +32,19 @@ License template Foam::HashTable::HashTable(Istream& is, const label size) : - HashTableName(), + HashTableCore(), nElmts_(0), - tableSize_(canonicalSize(size)), - table_(new hashedEntry*[tableSize_]), - endIter_(*this, NULL, 0), - endConstIter_(*this, NULL, 0) + tableSize_(HashTableCore::canonicalSize(size)), + table_(NULL) { - for (label hashIdx = 0; hashIdx < tableSize_; hashIdx++) + if (tableSize_) { - table_[hashIdx] = 0; + table_ = new hashedEntry*[tableSize_]; + + for (label hashIdx = 0; hashIdx < tableSize_; hashIdx++) + { + table_[hashIdx] = 0; + } } operator>>(is, *this); diff --git a/src/foam/containers/HashTables/StaticHashTable/StaticHashTable.C b/src/foam/containers/HashTables/StaticHashTable/StaticHashTable.C index 0dafd4dee..401f373bc 100644 --- a/src/foam/containers/HashTables/StaticHashTable/StaticHashTable.C +++ b/src/foam/containers/HashTables/StaticHashTable/StaticHashTable.C @@ -32,8 +32,7 @@ License // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * // -template -Foam::label Foam::StaticHashTable::canonicalSize(const label size) +Foam::label Foam::StaticHashTableCore::canonicalSize(const label size) { if (size < 1) { @@ -63,8 +62,8 @@ Foam::label Foam::StaticHashTable::canonicalSize(const label size) template Foam::StaticHashTable::StaticHashTable(const label size) : - StaticHashTableName(), - keys_(canonicalSize(size)), + StaticHashTableCore(), + keys_(StaticHashTableCore::canonicalSize(size)), objects_(keys_.size()), nElmts_(0), endIter_(*this, keys_.size(), 0), @@ -88,7 +87,7 @@ Foam::StaticHashTable::StaticHashTable const StaticHashTable& ht ) : - StaticHashTableName(), + StaticHashTableCore(), keys_(ht.keys_), objects_(ht.objects_), nElmts_(ht.nElmts_), @@ -97,14 +96,13 @@ Foam::StaticHashTable::StaticHashTable {} - template Foam::StaticHashTable::StaticHashTable ( - const Xfer< StaticHashTable >& ht + const Xfer >& ht ) : - StaticHashTableName(), + StaticHashTableCore(), keys_(0), objects_(0), nElmts_(0), @@ -223,15 +221,15 @@ Foam::StaticHashTable::find template Foam::List Foam::StaticHashTable::toc() const { - List tofc(nElmts_); - label i = 0; + List keys(nElmts_); + label keyI = 0; for (const_iterator iter = cbegin(); iter != cend(); ++iter) { - tofc[i++] = iter.key(); + keys[keyI++] = iter.key(); } - return tofc; + return keys; } @@ -318,24 +316,9 @@ bool Foam::StaticHashTable::erase(const iterator& cit) if (it.elemIndex_ < 0) { // No previous element in the local list - - // Search back for previous non-zero table entry - while (--it.hashIndex_ >= 0 && !objects_[it.hashIndex_].size()) - {} - - if (it.hashIndex_ >= 0) - { - // The last element in the local list - it.elemIndex_ = objects_[it.hashIndex_].size() - 1; - } - else - { - // No previous found. Mark with special value which is - // - not end() - // - handled by operator++ - it.hashIndex_ = -1; - it.elemIndex_ = 0; - } + // Mark with as special value (see notes in HashTable) + it.hashIndex_ = -it.hashIndex_ - 1; + it.elemIndex_ = 0; } nElmts_--; @@ -406,7 +389,7 @@ Foam::label Foam::StaticHashTable::erase template void Foam::StaticHashTable::resize(const label sz) { - label newSize = canonicalSize(sz); + label newSize = StaticHashTableCore::canonicalSize(sz); if (newSize == keys_.size()) { @@ -467,7 +450,6 @@ void Foam::StaticHashTable::clearStorage() } - template void Foam::StaticHashTable::transfer ( @@ -542,18 +524,8 @@ bool Foam::StaticHashTable::operator== const StaticHashTable& rhs ) const { - // Are all my elements in rhs? - for (const_iterator iter = cbegin(); iter != cend(); ++iter) - { - const_iterator fnd = rhs.find(iter.key()); + // sizes (number of keys) must match - if (fnd == rhs.cend() || fnd() != iter()) - { - return false; - } - } - - // Are all rhs elements in me? for (const_iterator iter = rhs.cbegin(); iter != rhs.cend(); ++iter) { const_iterator fnd = find(iter.key()); @@ -563,6 +535,7 @@ bool Foam::StaticHashTable::operator== return false; } } + return true; } diff --git a/src/foam/containers/HashTables/StaticHashTable/StaticHashTable.H b/src/foam/containers/HashTables/StaticHashTable/StaticHashTable.H index 0a2826ce9..77e2603d0 100644 --- a/src/foam/containers/HashTables/StaticHashTable/StaticHashTable.H +++ b/src/foam/containers/HashTables/StaticHashTable/StaticHashTable.H @@ -72,10 +72,31 @@ template Ostream& operator<< /*---------------------------------------------------------------------------*\ - Class StaticHashTableName Declaration + Class StaticHashTableCore Declaration \*---------------------------------------------------------------------------*/ -TemplateName(StaticHashTable); +//- Template-invariant bits for StaticHashTable +struct StaticHashTableCore +{ + //- Return a canonical (power-of-two) size + static label canonicalSize(const label); + + //- Construct null + StaticHashTableCore() + {} + + //- Define template name and debug + ClassName("StaticHashTable"); + + //- A zero-sized end iterator + struct iteratorEnd + { + //- Construct null + iteratorEnd() + {} + }; +}; + /*---------------------------------------------------------------------------*\ @@ -85,7 +106,7 @@ TemplateName(StaticHashTable); template class StaticHashTable : - public StaticHashTableName + public StaticHashTableCore { // Private data type for table entries @@ -108,6 +129,7 @@ class StaticHashTable //- Assign a new hashed entry to a possibly already existing key bool set(const Key&, const T& newElmt, bool protect); + public: @@ -156,11 +178,11 @@ public: StaticHashTable(const StaticHashTable&); //- Construct by transferring the parameter contents - StaticHashTable(const Xfer< StaticHashTable >&); + StaticHashTable(const Xfer >&); - // Destructor - ~StaticHashTable(); + //- Destructor + ~StaticHashTable(); // Member Functions @@ -220,11 +242,11 @@ public: void clearStorage(); //- Transfer the contents of the argument table into this table - // and annull the argument table. + // and annul the argument table. void transfer(StaticHashTable&); //- Transfer contents to the Xfer container - inline Xfer< StaticHashTable > xfer(); + inline Xfer > xfer(); // Member Operators @@ -248,6 +270,7 @@ public: //- The opposite of the equality operation. bool operator!=(const StaticHashTable&) const; + // STL type definitions //- Type of values the StaticHashTable contains. @@ -290,6 +313,7 @@ public: //- Index of current element at hashIndex label elemIndex_; + public: // Constructors diff --git a/src/foam/containers/HashTables/StaticHashTable/StaticHashTableName.C b/src/foam/containers/HashTables/StaticHashTable/StaticHashTableCore.C similarity index 95% rename from src/foam/containers/HashTables/StaticHashTable/StaticHashTableName.C rename to src/foam/containers/HashTables/StaticHashTable/StaticHashTableCore.C index 9ec16b7ca..9fabfe8e0 100644 --- a/src/foam/containers/HashTables/StaticHashTable/StaticHashTableName.C +++ b/src/foam/containers/HashTables/StaticHashTable/StaticHashTableCore.C @@ -27,6 +27,10 @@ License // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // -defineTypeNameAndDebug(Foam::StaticHashTableName, 0); +namespace Foam +{ +defineTypeNameAndDebug(StaticHashTableCore, 0); +} + // ************************************************************************* // diff --git a/src/foam/containers/HashTables/StaticHashTable/StaticHashTableI.H b/src/foam/containers/HashTables/StaticHashTable/StaticHashTableI.H index c7bbb38da..2c59db4ad 100644 --- a/src/foam/containers/HashTables/StaticHashTable/StaticHashTableI.H +++ b/src/foam/containers/HashTables/StaticHashTable/StaticHashTableI.H @@ -78,7 +78,7 @@ inline bool Foam::StaticHashTable::set template -inline Foam::Xfer< Foam::StaticHashTable > +inline Foam::Xfer > Foam::StaticHashTable::xfer() { return xferMove(*this); @@ -266,8 +266,13 @@ Foam::StaticHashTable::Iterator TableRef >::operator++() { - // Check for special value from erase. (sets hashIndex to -1) - if (hashIndex_ >= 0) + // A negative index is a special value from erase + // (see notes in HashTable) + if (hashIndex_ < 0) + { + hashIndex_ = -(hashIndex_+1) - 1; + } + else { // Try the next element on the local list elemIndex_++; @@ -411,6 +416,4 @@ Foam::StaticHashTable::end() const } -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - // ************************************************************************* // diff --git a/src/foam/containers/HashTables/StaticHashTable/StaticHashTableIO.C b/src/foam/containers/HashTables/StaticHashTable/StaticHashTableIO.C index e71184f84..6307d55e8 100644 --- a/src/foam/containers/HashTables/StaticHashTable/StaticHashTableIO.C +++ b/src/foam/containers/HashTables/StaticHashTable/StaticHashTableIO.C @@ -36,9 +36,9 @@ Foam::StaticHashTable::StaticHashTable const label size ) : - StaticHashTableName(), - keys_(size), - objects_(size), + StaticHashTableCore(), + keys_(StaticHashTableCore::canonicalSize(size)), + objects_(StaticHashTableCore::canonicalSize(size)), nElmts_(0), endIter_(*this, keys_.size(), 0), endConstIter_(*this, keys_.size(), 0)