|
[Sponsors] |
January 29, 2019, 05:24 |
optimization of cell list
|
#1 |
Senior Member
krishna kant
Join Date: Feb 2016
Location: Hyderabad, India
Posts: 133
Rep Power: 10 |
Hello Foamers,
I have a list of cells in which I don't want to run my cell loop, how can I subtract this list from the cellList ? |
|
January 29, 2019, 06:27 |
|
#2 |
Senior Member
krishna kant
Join Date: Feb 2016
Location: Hyderabad, India
Posts: 133
Rep Power: 10 |
I have written this loop but I feel there is scope of optimizing this.
int nNew=0; int check=0; forAll(newMesh.cells(),cellI) { forAll(unrefCells,I) { if(cellI == unrefCells[I]) { check=1; break; } } if(check == 0) { nNew++; newCells.resize(nNew,cellI); } check=0; } |
|
January 30, 2019, 10:03 |
|
#3 |
Member
Join Date: Dec 2018
Location: Darmstadt, Germany
Posts: 87
Rep Power: 7 |
Hey,
here are some ideas that may improve perfomance : 1. Don't use a function call in your forAll macro. Maybe the compiler will optimize it but it is possible that the function gets called multiple times (when range checking is performed). Code:
const cellList& newMeshCells = newMesh.cells(); forAll(newMeshCells,cellI) // instead of // forAll(newMesh.cells(),cellI) 2. The optimization of your second for loop depends on what data is in newMeshCells and also whether the data is sorted or not. A Foam::List<T> should be fine. You could for example take advantage of a sorted container and perform a binary search on newMeshCells. This will enhance performance especially if the size of your container is big. Code:
#include<algorithm> ... forAll(unRefCells,I) { bool found=std::binary_search(newMeshCells.begin(),newMeshCells.end(),I); if(found) { break; ... } ... } Good luck with your task. Cheers RP |
|
February 7, 2019, 14:44 |
|
#4 | |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,714
Rep Power: 40 |
Quote:
I can't really follow what you are trying to do, but it is certainly more efficient and easier if you try to work at a higher level. For example (don't really know if this is what you are trying) Code:
bitSet unrefCells = ...; // Some selection coming from somewhere (your input?) // Those were the cells you want to ignore, so we need the opposite. labelList newCells; if (unrefCells.none()) { // Nothing ignored - take all cells newCells = identity(newMesh.nCells()); } else if (unrefCells.all()) { // All ignored - we don't have any new cells? } else { // Some ignored - get the other ones unrefCells.resize(newMesh.nCells()); // extra safety unrefCells.flip(); newCells = unrefCells.toc(); // or sortedToc() - same thing unrefCells.flip(); // return to original state } If it suits your requirement, you might also get some use out of subsetting too. Code:
bitSet unrefCells = ...; // Some selection coming from somewhere (your input?) scalarField inputValues = ...; // Subset of the 'off' values: scalarField values = subset(unrefCell, inputValue, true); Cheers, /mark |
||
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[swak4Foam] funkyDoCalc with OF2.3 massflow | NiFl | OpenFOAM Community Contributions | 14 | November 25, 2020 04:30 |
Purpose and Map of this forum | Tobi | OpenFOAM Community Contributions | 0 | September 19, 2017 06:52 |
How to use "translation" in solidBodyMotionFunction in OpenFOAM | rupesh_w | OpenFOAM Running, Solving & CFD | 5 | August 16, 2016 05:27 |
Help for the small implementation in turbulence model | shipman | OpenFOAM Programming & Development | 25 | March 19, 2014 11:08 |
[swak4Foam] funkySetFields compilation error | tayo | OpenFOAM Community Contributions | 39 | December 3, 2012 06:18 |