Update stored cell numbers using map. Do in two passes to prevent allocation if nothing changed.
| 135 | // Update stored cell numbers using map. |
| 136 | // Do in two passes to prevent allocation if nothing changed. |
| 137 | void Foam::topoSet::updateLabels(const labelList& map) |
| 138 | { |
| 139 | // Iterate over map to see if anything changed |
| 140 | bool changed = false; |
| 141 | |
| 142 | forAllConstIter(labelHashSet, *this, iter) |
| 143 | { |
| 144 | if ((iter.key() < 0) || (iter.key() > map.size())) |
| 145 | { |
| 146 | FatalErrorInFunction |
| 147 | << "Illegal content " << iter.key() << " of set:" << name() |
| 148 | << " of type " << type() << endl |
| 149 | << "Value should be between 0 and " << map.size()-1 |
| 150 | << abort(FatalError); |
| 151 | } |
| 152 | |
| 153 | const label newCelli = map[iter.key()]; |
| 154 | |
| 155 | if (newCelli != iter.key()) |
| 156 | { |
| 157 | changed = true; |
| 158 | |
| 159 | break; |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | // Relabel (use second Map to prevent overlapping) |
| 164 | if (changed) |
| 165 | { |
| 166 | labelHashSet newSet(2*size()); |
| 167 | |
| 168 | forAllConstIter(labelHashSet, *this, iter) |
| 169 | { |
| 170 | const label newCelli = map[iter.key()]; |
| 171 | |
| 172 | if (newCelli >= 0) |
| 173 | { |
| 174 | newSet.insert(newCelli); |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | transfer(newSet); |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | |
| 183 | void Foam::topoSet::check(const label maxLabel) |