Skip to content

Improve greyscale simulator physics, reliability, and output support - #115

Draft
JoaoBentoNeto wants to merge 14 commits into
OPM:devfrom
poro-labcc:grey_fix
Draft

JoaoBentoNeto wants to merge 14 commits into
OPM:devfrom
poro-labcc:grey_fix

Conversation

@JoaoBentoNeto

Copy link
Copy Markdown

Summary

This Pull Request introduces improvements to the lbpm_greyscale_simulator routine, including bug fixes, corrections to the physical formulation, and new features.


Bug Fixes

The absolute permeability is calculated by:

$$\Large \begin{aligned} K = \frac{\langle u \rangle \nu}{g - \frac{\Delta p}{L}} \end{aligned}$$

where $\langle u\rangle$ is the domain-averaged Darcy velocity, $\nu$ is the kinematic viscosity, $g$ is the body force, $\Delta p$ is the pressure difference between the inlet and outlet, and $L$ is the domain length in the streamwise direction.

By definition, the Darcy velocity is obtained by averaging the local velocity over the total volume of the porous medium:

$$\Large \begin{aligned} \langle u \rangle &= \frac{1}{V_{\mathrm{total}}} \int_{V_{\mathrm{total}}} u ~\mathrm{d}V \\ &= \frac{1}{V_{\text{total}}} \sum_i^{N_{\text{total}}} \left(\int_{V_{\text{i}}} u ~\mathrm{d}V \right) \\ &= \frac{1}{V_{\mathrm{total}}} \sum_{i=1}^{N_{\mathrm{total}}} \left(\langle u\rangle_i V_{\mathrm{voxel}}\right)\\ &= \frac{1}{N_{\mathrm{total}}} \sum_{i=1}^{N_{\mathrm{total}}}\langle u\rangle_i \end{aligned}$$

where $\langle u\rangle_i$ is the voxel-averaged Darcy velocity, $V_{\mathrm{voxel}}$ is the voxel volume, and $N_{\mathrm{total}}$ is the total number of voxels.

The previous implementation attempted to calculate the Darcy velocity by averaging the voxel velocities over the pore voxels and subsequently multiplying the result by the total porosity:

$$\Large \begin{aligned} \langle u \rangle_{\mathrm{previous}} &= \left( \frac{1}{N_{\mathrm{pores}}} \sum_{i=1}^{N_{\mathrm{total}}}\langle u\rangle_i \right)\phi_{\mathrm{total}}\\ &= \left(\frac{1}{N_{\text{pores}}} \sum_i^{N_{\text{total}}} \langle u \rangle_i \right) \frac{\sum_i^{N_{\text{total}}} \phi_i}{N_{\text{total}}} \\ &= \left( \frac{1}{N_{\mathrm{total}}} \sum_{i=1}^{N_{\mathrm{total}}}\langle u\rangle_i \right) \left( \frac{\sum_{i=1}^{N_{\mathrm{total}}}\phi_i} {N_{\mathrm{pores}}} \right) \end{aligned}$$

This expression is equivalent to the volume-averaged definition only when all non-solid voxels have unit porosity ($\phi_i=1$). Therefore, the previous approach is generally incorrect for greyscale media, where voxels may have intermediate porosity values ($0<\phi_i\leq1$).

Therefore, the calculation has been replaced with the direct volume average of the voxel Darcy velocities, eliminating the incorrect porosity correction.

Features

Refactoring and Style

Formatted specific C++, CUDA, and HIP source files related to the greyscale fix to establish a clean baseline.
Differentiated 'idx' (voxel map index) from the new 'idx_labels' (label loop index). Both were previously named 'idx'.
- Combined length checks for ComponentLabels, PorosityList, and PermeabilityList into a single error handler at the beginning of the code.
- Moved porosity (0 < porosity <= 1) and permeability (permeability > 0) boundary checks from the main domain loop to a list evaluation loop.
Porosity and permeability were each assigned in a separate 'for' loop with the same structure. Unifying them improves both performance and readability.
Replaced raw array allocations with 'std::vector'. The previous implementation was more verbose to declare and caused a memory leak due to a missing 'delete[]' statement at the end of the scope. This change ensures automatic memory cleanup.
- Fixed porosity bug: Moved the 'label_count' increment inside the 'idx >= 0' check to properly exclude communication halo cells.
- Optimized performance: Moved the entire label lookup loop inside the 'idx >= 0' condition to avoid redundant searches for halo cells.
- Cleaned logic: Removed unnecessary temporary variables and replaced the 'idx_label = NLABELS' loop hack with a proper 'break' statement.
Added an explicit exception to handle voxels containing undeclared labels.
Replaced raw host array allocations ('new double[N]') with 'std::vector' to prevent memory leaks, aligning the implementation with the label-based assignment logic.
Added the missing lattice unit conversion for permeability read from files, ensuring consistency with the label-based assignment.
Updated the log statement to display the current timestep, convergence error, and absolute permeability in both square micrometers (um^2) and milliDarcys (mD).
- Corrected macroscopic velocity averaging: Replaced the dynamic 'count' variable with the total active domain size.
- Simplified permeability formulation: Removed the 'GreyPorosity' factor from the final absolute permeability equation.
- Physical context: Permeability calculation relies on Darcy velocity (volumetric average velocity over the entire domain, including pores and solids). The original method—dividing the velocity sum by pore count and later multiplying by total porosity—works for binary media but fails for greyscale, where pore volume depends on local partial porosities. Dividing the velocities directly by the total domain volume correctly yields the Darcy velocity in a single step, and removing the 'GreyPorosity' factor from the permeability calculation avoids redundant porosity scaling.
Introduced the 'Forchheimer' boolean flag to control the inclusion of the non-linear drag force, modeled based on the empirical Ergun equation, in the flow calculations.
- Introduced the 'ViscosityRatio' scalar float variable.
- Clarified viscosity nomenclature: 'viscosity'/'rlx'/'tau' represents the thermodynamic/original viscosity and is strictly used for force calculations (Darcy drag).
- Clarified effective viscosity nomenclature: 'viscosity_eff'/'rlx_eff'/'tau_eff' represents the Brinkman effective viscosity and is applied exclusively to viscous momentum diffusion.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants