imitrichev's page

:)   Русская версия 

The Door to GitHub

C++ code for calculation of first cell size

This simple code can calculate the first cell size $h_1$ based on three inputs:

  • $N$, number of cells
  • $L$, length of edge being meshed
  • $k$, growth rate
The growth rate shows how much greater the next cell size is than the previous cell size (in the growth direction): $$k = h_2 / h_1 = {}... = h_{i+1} / h_i = h_N / h_{N-1}$$

Biased gridFigure 1. A grid with bias

Bias factor $r$, that is used in ANSYS Meshing as an input, is defined to be: $$r = h_N / h_1 $$ Then, because of $h_N = h_1 k^{N-1}$, $$r = k^{N-1}$$ At last, the length of edge being meshed equals to: $$L = \sum_{n=0}^{N-1}h_1 k^n$$ The code performs fitting of $h_1$ by bisection to obtain $L$ with predefined $N$ and $k$.

  1. Compile with g++ grid.cpp -o grid
  2. Run with ./grid
  3. Enter your $N$, $L$, $k$ subsequently.
  4. $h_1$ and $r$ are printed at the end of results.

Download source (.cpp)

no image