Repository navigation
Improve greyscale simulator physics, reliability, and output support - #115
Draft
JoaoBentoNeto wants to merge 14 commits into
Draft
JoaoBentoNeto wants to merge 14 commits into
JoaoBentoNeto wants to merge 14 commits into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This Pull Request introduces improvements to the
lbpm_greyscale_simulatorroutine, including bug fixes, corrections to the physical formulation, and new features.Bug Fixes
The absolute permeability is calculated by:
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:
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:
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.
fix: corrected the 'GreyPorosity' calculation: Excluded communication halo cells from the porosity calculation by moving the relevant operations inside the conditional statement that checks whether a voxel doesn't belongs to the halo. Also removed unnecessary variables.
fix: corrected the permeability unit for the raw input file: Added a unit conversion for permeability values read from raw input files, ensuring consistency with the label-based property assignment. Both input methods now uses permeability in squared micrometers.
fix: resolve memory leak
fix: replace raw arrays with std::vector for file assignments: Replaced raw arrays with
std::vectorfor file-based property assignments to be consistent with the modifiction used to solve the memory leak..Features
feature: add boolean toggle for Forchheimer non-linear drag term: Introduced a Boolean
Forchheimerflag to control the inclusion of the non-linear drag force in the flow calculations.feature: add VTK (.vti/.pvti) output support
improvement: add exception for undeclared voxel labels: Added an exception to handle voxels containing labels that have not been declared in the input configuration.
improvement: enhanced log output: Enhanced the simulation log to display the current time step, convergence error, and absolute permeability in both square micrometers (µm²) and millidarcies (mD).
feature: add ViscosityRatio parameter: Clarified the nomenclature of viscosity-related variables, distinguishing the parameters associated with the Darcy drag term (
viscosity,rlx, andtau) from those associated with the Brinkman effective viscosity (viscosity_eff,rlx_eff, andtau_eff). Introduced the floating-point parameterViscosityRatioto control the ratio between effective and dynamic viscosities.Refactoring and Style
refactor: enhance error handling and validation checks: Consolidated the length checks for$0<\phi\leq1$ and $k>0$ ) from the main domain loop to the input-list processing loop.
ComponentLabels,PorosityList, andPermeabilityListinto a single validation block at the beginning of the routine. Moved the physical property validation checks (refactor: unify porosity and permeability assignment loops: Combined the porosity and permeability assignment loops into a single loop to improve readability and reduce redundant iterations.
style: apply clang-format to greyscale files: Applied the project's C/C++ formatting configuration using
clang-formatto ensure consistency with the rest of the codebase.