You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Non-matching diffusive mass flux across mesh boundaries with refinement. #9051
I'm looking at mass fluxes across interpolated mesh boundaries. I'm having difficulties getting matching diffusive mass fluxes across mesh boundaries with refinement.
Add this piece of code in line 267 of divg.f90 to write out computed fluxes in one interpolated boundary face (4 faces fine side) as seen from the two meshes of the attached case.
N=1; RHO_D_DZDN=0._EB
DO K=0,KBAR
DO J=0,JBAR
DO I=0,IBAR
IF(NM==1 .AND. I==8 .AND. (J==3 .OR. J==4) .AND. (K==3 .OR. K==4)) THEN ! <- With Refinement
!IF(NM==1 .AND. I==4 .AND. J==2 .AND. K==2) THEN ! <- No Refinement
WRITE(LU_ERR,*) 'NM,N,I,J,K=',NM,N,I,J,K,' : RHO_D_DZDX=',RHO_D_DZDX(I,J,K,N)
RHO_D_DZDN=RHO_D_DZDN+RHO_D_DZDX(I,J,K,N)
ELSEIF(NM==2 .AND. I==0 .AND. J==2 .AND. K==2) THEN
WRITE(LU_ERR,*) 'NM,N,I,J,K=',NM,N,I,J,K,' : RHO_D_DZDX=',RHO_D_DZDX(I,J,K,N)
WRITE(LU_ERR,*) ' '; WRITE(LU_ERR,*) ' '
ENDIF
ENDDO
ENDDO
ENDDO
IF(NM==1) THEN ! <- With Refinement
WRITE(LU_ERR,*) ' '
WRITE(LU_ERR,*) 'Fine NM,N=',NM,N,' : Average RHO_D_DZDX=',1._EB/4._EB*RHO_D_DZDN ! Area average.
ENDIF
When commenting the lines with tag "With Refinement", uncommenting the "No refinement" line and using the 4x4x4 left mesh specified in the input file I get matching fluxes for the boundary face. I'm not seeing that for the case with refinement.
@marcosvanella
You've uncovered some dirty laundry. This has never been right. The good news is that we have dealt with something similar before and fixed it. If you look at the FDS Tech Guide, Special Topic: Vertical Mesh Coarsening in Atmospheric Flows, we do a special interpolation of the density to make sure the heat flux matches at a mesh interface. I think we would have to apply the same idea to RHO and ZZ in all directions if we have a mesh interface.
Yes, fluxes match now in the original case. I run diffuse_3d for 50 sec and the error picks up compared to the 10 sec run, but it is still < 10^-4 of the original mass. Also, velocity values increase in the refinement boundary.
Let me know if you want to close this or keep it open to deal here with heat fluxes.
@rmcdermo I had a go at the heat flux part of this one due to my application, and noted a few more things on the way.
Test. A sealed, adiabatic box (0.4 x 0.1 x 0.1 m) split into two meshes at x = 0.2 m, one gas with constant properties, no gravity, no radiation, and a 500 °C gas region (&INIT, x = 0.1-0.2 m) next to the mesh boundary. Heat only moves inside the box, so the total internal energy must stay constant. On master (b7dc77f), after 4 s:
Meshes
DNS
LES
VLES
same cells on both sides
0.000 %
+0.05 %
0.000 %
2:1, hot side fine
-1.6 %
-1.4 %
-1.5 %
2:1, hot side coarse
+2.0 %
+2.0 %
+1.8 %
3:1, hot side fine / coarse
-2.3 % / +3.1 %
-2.0 % / +3.0 %
only dx changes (2:1 in x, same dy and dz)
-1.7 %
-1.6 %
-1.5 %
It is the same with the boundary normal to y or z (DNS and LES) and with a 12 times smaller time step, and it goes away with k ≈ 0. In DNS and LES it also happens without refinement when k differs across the boundary: with the default air (k depends on T), two equal meshes lose 1.3 % (DNS) and 1.1 % (LES), against +0.004 % and +0.007 % on one mesh. The +0.05 % in the LES row is the same thing, because μ_t differs between the two cells.
A steady case with an exact answer: conduction between walls at 300 °C and 20 °C, L = 0.4 m, k = 0.5 + (T-20)/280 W/m/K, so q = 700 W/m² at both walls (values at 150 s).
In DNS and LES, BOUNDARY_LOOP copies the interior KP into every external ghost cell, including INTERPOLATED ones, so each mesh uses its own k at the shared face. (In VLES KP = MU*CPOPR and MU is exchanged, so this part is fine.)
Each mesh takes the gradient over its own ghost spacing, and the ghost cell has the size of the interior cell. Where the cell width normal to the boundary changes, the two meshes use different distances for the same face. If only the normal width changes, NIC=1 on both sides and nothing is matched (last rows above). The same holds for the species: an isothermal tracer crossing such a boundary loses 7.3-10 % of its mass in 4 s, DNS and LES.
And in the species matching (wall.f90, COARSE_MESH_IF):
PBAR_OTHER = EVALUATE_RAMP(MM%ZC(KKO),I_RAMP_P0_Z). With STRATIFICATION=F there is no pressure ramp (I_RAMP_P0_Z=0), so this returns 1 Pa, and D and μ of the fine cell are evaluated at about 0 K. A tracer whose D depends on T changes by -7.3 % (DNS) and -8.7 % (LES) in 4 s at a 2:1 boundary.
MU_DNS is never set in ghost cells and stays 0, so in LES the ghost cell's MU-MU_DNS includes the molecular viscosity: -1.9 % for the tracer in LES at 2:1, against -0.07 % in DNS. With a tracer whose viscosity differs from the background, this also gives +0.6 % on two equal meshes.
In LES, MU_DNS_G is evaluated with ZZ_GET, which holds the face composition for the first species and the last fine cell's composition after that, and MAX(0,·) is missing. A tracer with a different viscosity, no flow, 2:1: -1.0 % in 4 s with item 5 already fixed (-3.3 % on master, where item 5 adds to it).
Fine cells inside an obstruction are included in the sum. A tracer next to an obstruction that touches a 2:1 boundary, no flow: +2.5 %.
Change (diff attached):
New routine MATCH_HEAT_FLUX_AT_MESH_INTERFACE (divg.f90). On the coarse side of a refined boundary, k dT/dn is replaced by the area-weighted sum of the fine-side values, computed from the inputs the fine mesh uses, as for the species. Solid fine cells are left out.
In BOUNDARY_LOOP (DNS and LES), INTERPOLATED ghost cells get their own k from the ghost-cell state, so both meshes use ½(k₁+k₂).
Where the normal widths differ, both meshes use the distance between the two cell centres (CENTRE_DISTANCE_FACTOR), for heat and species, and the coarse side uses the same distance when it sums the fine faces. At a refined boundary the old rule (the fine-mesh spacing, which the species code used) was already conservative, but less accurate: in the 2:1 conduction case it gives 708 W/m², the centre distance 700.4.
Species items 4-7: PBAR_OTHER from the zone pressure (plus the ambient profile with STRATIFICATION=T), MU_DNS in INTERPOLATED ghost cells (velo.f90), and in the species sum MU_DNS_G = MU_DNS(IIG,JJG,KKG) with MAX(0,·) on each side and solid fine cells left out.
With GEOM (CC_IBM), items 1 and 3 are not applied, because the coarse mesh cannot see cut cells on the fine side. With TENSOR_DIFFUSIVITY=T, items 1 and 3 are not applied to the heat flux (the 2:1 LES box still changes by -1.6 %), and on cylindrical meshes item 1 is not applied. Items 2 and 4 apply in all cases.
With the change (same cases):
Sealed box, all single-gas cases (x, y and z for DNS and LES; x for VLES and for only dx; 1:1, 2:1 and 3:1; hot side fine or coarse): the total energy does not change in the 8 digits written to the devc file. The same with an obstruction on the fine side that leaves the coarse face open (master -0.84 %).
Two equal meshes with air: -0.008 % (DNS) and -0.005 % (LES), like one mesh.
Heat source next to the boundary on the coarse side, which raises the background pressure by 20 %: the energy rise is the same as on one mesh to 5 digits (master: 5 % larger), DNS and LES, STRATIFICATION T and F.
Steady conduction: table above.
Tracers with NOISE=F: 0.000 % at 2:1 and where only dx changes, for any STRATIFICATION; 0.000 % next to the obstruction; +0.02 % with a different viscosity in LES (it scales with the time step: +0.005 % at DT/4, see MU_DNS below). With the default initial velocity noise the 2:1 tracer changes by -0.09 % (DNS and LES); that is the noise carrying the tracer across the boundary, see below.
energy_budget_adiabatic_walls on other mesh layouts: where only dz changes, the energy error comes down to the equal-mesh level; in a refined layout the change removes a bit more than a third of it (details below).
In LES the coarse side recomputes MU_DNS of the fine cell at the end-of-stage temperature, as the existing species code does. In a buoyant LES box (2:1 in z) the energy changes by at most 1e-8, the same as on equal meshes; for the species it is the +0.02 % above. Sending MU_DNS with MU in exchanges 1 and 4 would make it exact.
Energy budget on other mesh layouts, and verification cases
two meshes split in z, 0.25 m below and 0.5 m above (only dz changes)
-0.95 %
-0.064 %
five meshes, 0.125 m around the fire, 0.25 m outside (2:1)
+0.92 %
+0.57 %
The rest in the refined layout is not there on equal meshes. What is still not matched at a refined boundary is the advective flux (below) and the enthalpy carried by species diffusion (h_α is taken at the coarse face temperature); I have not separated the two.
Verification cases, master and with the change on the same machine: 16 cases (multi-mesh, refined, GEOM, energy budget, species), all 35 active multi-mesh DNS/LES cases in FDS_Cases.sh (3 of them in the 16), and the commented-out ns2d_16_*_refinement cases and move_slug_left. All of them run to the end with both. Not run: sphere_Re200 (GEOM, long).
Bit for bit the same, apart from timing: all but the thirteen below.
Only the pressure-work term changes, by 1e-8 to 6e-6: ns2d_16_int_1to2_refinement and the five soborot_*_wave_128 cases (devc output identical).
Changed, and each still meets its own check: obst_coarse_fine_interface (ΔP at 10 s -1.47 Pa in both), duct_flow_uglmat_refine (1.000 m³/s in and out in both), dancing_eddies_uglmat_refine and dancing_eddies_embed (same pressure iterations; the energy terms change), mass_balance_reac and mass_balance_reac_2 (species mass errors as on master), obst_activation_default_gases (temperature stays at 20.00000 °C in both; tolerance 0.005 °C).
Four of the 16 (energy_budget_adiabatic_walls, energy_budget_dns_100, simple_duct, sphere_helium_conserve_3meshes) and the one-mesh layout above were run with the version just before the last two fixes, which do not act there (one mesh, or VLES/GEOM without obstructions).
Not fixed: mass at a refined boundary. Mass is still not conserved when gas flows from the coarse mesh into the fine one. In the box with the hot gas on the fine side, the hot gas cools and contracts and the cold coarse side pushes gas into the fine mesh. With the hot gas on the coarse side, or a heat source on the fine side, the flow goes the other way and the mass is conserved.
Case (4 s)
with the change
master
box, hot gas on the fine side: total mass
+0.16 %
+0.13 %
same with gravity, 2:1 boundary in z (DNS)
+0.62 %
+0.40 %
heat source on the coarse side next to the boundary
-0.11 %
-0.07 %
light tracer (MW 4) whose diffusion drives a flow across 2:1
-1.05 %
-1.03 % (DNS), -4.1 % (LES)
second gas in a box with two gases, 2:1
-1.49 %
-1.41 %
At a refined boundary the second ghost cell is a copy of the first, so the flux limiter is first order where the flow enters a mesh but not where it leaves. For flow from coarse to fine, the fine mesh takes the coarse density on every face while the coarse mesh sends a limited face value, so the two fluxes differ. I have not checked this in detail. Matching it would need the coarse mesh to use the sum of the fine-face fluxes, so I left it out of this change.
An older, separate limitation: when the first fine cell behind a coarse face is solid, init.f90 makes the whole coarse face a wall, so the open fine cells beside it exchange heat with a wall (-0.30 % with the change, -1.45 % on master, in the obstruction box).
The diff is against b7dc77f, and the inputs are attached. Items 1 and 3 change only cases where the cell size changes at a mesh boundary; item 2 multi-mesh DNS cases where k varies and nearly all multi-mesh LES cases; item 4 species diffusion at refined boundaries in DNS and LES, LES cases with mesh boundaries, and cases where an obstruction touches a refined boundary.
Thanks for the detailed analysis. I would prefer a diff as a PR, so that I can test on a branch.
On the mass conservation, I thought we had that working? Are you using UGLMAT pressure solver? This is required for mesh refinement interfaces, else we cannot expect mass conservation without an extremely tight velocity tolerance.
@rmcdermo Thanks. The changes are now in two PRs: #16743 (heat and species flux matching, the diff above on current master) and #16744 (mass). As far as I can tell, each applies to master on its own. What each one changes is in the PR descriptions; the results are below.
On the mass: my cases used the default FFT solver. With UGLMAT the drift seems to be practically the same (gravity box +0.45 % instead of +0.40 %, the other DNS boxes of that table within 0.01 %), although the normal velocities at the interface then agree to 2e-16 m/s. From what I can see, the difference comes from the advective face values at the refined boundary: the second ghost cell is a copy of the first, so each mesh is first order where gas flows into it, and the two meshes compute different face values of ρZ. #16744 makes both meshes use the same face values.
With FFT, #16744 does not move the velocity mismatch into the coarse cell. I tried that first (full refluxing), but with FFT the energy budget then seemed to get worse (energy_budget, refined layout, with #16743: +1.16 % at 60 s, against +0.185 % with the version in the PR). What is left with FFT appears to follow VELOCITY_TOLERANCE: gravity box -3.6e-5 at the default tolerance and -7.6e-8 with VELOCITY_TOLERANCE=1E-5 (two equal fine meshes: -4.9e-6 and -2.5e-8).
Sealed boxes, 2:1 and 3:1, 4 s (45 cases, DNS and LES, x/y/z), change of mass:
0 = no change in the 8 digits of the devc file, with 1 and 2 MPI processes. The rest in LES seems to come from the diffusive flux, which #16743 matches. With FFT, total mass: master up to +0.57 %, #16744 up to -3.6e-5.
Propane burner in a sealed box (2:1), 20 s, mass minus fuel injected, relative: UGLMAT master +2.55e-3, #16744 -2.96e-6, one fine mesh -2.94e-6; FFT master +2.5e-3, #16744 -2.9e-5.
Accuracy looks unchanged: a tracer pulse carried once through a coarse-fine-coarse channel has L1 error 0.0587 on master and with #16744 (one fine mesh 0.0387, one coarse mesh 0.0645); tracer mass +4.1e-4 on master, 0 with #16744.
energy_budget_adiabatic_walls (VLES), refined layout (5 meshes, 2:1 around the fire), ∫(Q_TOTAL-Q_ENTH)dt/∫HRR dt:
OK, thanks. As I commented in the PR conversation, I will check as soon as I can. In the meantime, can you please add to your results table a wall clock time and use some significant total number of cells so we can see if this new change makes a noticeable difference in computational cost. Thanks
@rmcdermo Wall clock times below, from one PC (i7-14700F, 8 P + 12 E cores, WSL2, 16 MPI processes, one run at a time; run 2 in the reverse order of run 1). Case: 2.0 million cells, 16 meshes, 5 cm around a 2 MW burner and 10 cm elsewhere, 2:1 at the interfaces. All builds take the same number of time steps, and for a given case the same number of pressure iterations (1398 for 400 steps; 7710 to 7711 for the 3 s run).
From what I can see, the differences between the builds are smaller than the scatter between repeated runs on this machine (master: 457 s and 608 s for the same 400 steps). In the _cpu.csv files, the extra time of #16744 seems to be mostly in COMM, about 0.02 to 0.05 s per time step with FFT (1 to 4 % of a step here), probably from the two added exchanges in each stage. In the 3 s run with both PRs I did not see it, so this is also close to the noise. With UGLMAT, where the pressure solve takes about 75 % of the step, I could not see a difference.
Input file (FFT; for UGLMAT add &PRES SOLVER='UGLMAT' /; T_END=0.3 for the 100 step runs; the 3 s run has T_END=3 and no LOCK_TIME_STEP)
Activity
rmcdermo commentedon Dec 10, 2020
Thanks, I'll take a look
rmcdermo commentedon Dec 10, 2020
@marcosvanella
You've uncovered some dirty laundry. This has never been right. The good news is that we have dealt with something similar before and fixed it. If you look at the FDS Tech Guide, Special Topic: Vertical Mesh Coarsening in Atmospheric Flows, we do a special interpolation of the density to make sure the heat flux matches at a mesh interface. I think we would have to apply the same idea to RHO and ZZ in all directions if we have a mesh interface.
rmcdermo commentedon Dec 14, 2020
@marcosvanella try the latest code (PR #9054) with your case and this one.
diffuse_3d.fds.txt
This case uses a MASS_FILE. The total HELIUM is pretty tight. I think the discrepancy is related to advection.
marcosvanella commentedon Dec 15, 2020
Yes, fluxes match now in the original case. I run diffuse_3d for 50 sec and the error picks up compared to the 10 sec run, but it is still < 10^-4 of the original mass. Also, velocity values increase in the refinement boundary.
Let me know if you want to close this or keep it open to deal here with heat fluxes.
rmcdermo commentedon Dec 15, 2020
Thanks. Let's keep it open to deal with heat fluxes.
At 50 s, does the mass actually start to leave the domain? I'll create a sealed case for verfication.
marcosvanella commentedon Dec 15, 2020
There's no difference in final mass using open or solid external boundaries.
drjfloyd commentedon Apr 13, 2023
@rmcdermo Does this still need to be open for heat flux that we should tag for 7?
rmcdermo commentedon Apr 13, 2023
Yes, I have not fixed the heat fluxes yet.
ghaffari-eng commentedon Nov 8, 2026
@rmcdermo I had a go at the heat flux part of this one due to my application, and noted a few more things on the way.
Test. A sealed, adiabatic box (0.4 x 0.1 x 0.1 m) split into two meshes at x = 0.2 m, one gas with constant properties, no gravity, no radiation, and a 500 °C gas region (
&INIT, x = 0.1-0.2 m) next to the mesh boundary. Heat only moves inside the box, so the total internal energy must stay constant. On master (b7dc77f), after 4 s:It is the same with the boundary normal to y or z (DNS and LES) and with a 12 times smaller time step, and it goes away with k ≈ 0. In DNS and LES it also happens without refinement when k differs across the boundary: with the default air (k depends on T), two equal meshes lose 1.3 % (DNS) and 1.1 % (LES), against +0.004 % and +0.007 % on one mesh. The +0.05 % in the LES row is the same thing, because μ_t differs between the two cells.
A steady case with an exact answer: conduction between walls at 300 °C and 20 °C, L = 0.4 m, k = 0.5 + (T-20)/280 W/m/K, so q = 700 W/m² at both walls (values at 150 s).
Possible cause. In
DIVERGENCE_PART_1(divg.f90):KDTDX/Y/Zare not matched at refined boundaries.CORRECTION_LOOPskipsINTERPOLATED_BOUNDARY, and there is nothing like theRHO_D_DZDXoverwrite from FDS Source: add flux matching for mass at refinement boundaries #9054.BOUNDARY_LOOPcopies the interiorKPinto every external ghost cell, includingINTERPOLATEDones, so each mesh uses its own k at the shared face. (In VLESKP = MU*CPOPRandMUis exchanged, so this part is fine.)NIC=1on both sides and nothing is matched (last rows above). The same holds for the species: an isothermal tracer crossing such a boundary loses 7.3-10 % of its mass in 4 s, DNS and LES.And in the species matching (wall.f90,
COARSE_MESH_IF):PBAR_OTHER = EVALUATE_RAMP(MM%ZC(KKO),I_RAMP_P0_Z). WithSTRATIFICATION=Fthere is no pressure ramp (I_RAMP_P0_Z=0), so this returns 1 Pa, and D and μ of the fine cell are evaluated at about 0 K. A tracer whose D depends on T changes by -7.3 % (DNS) and -8.7 % (LES) in 4 s at a 2:1 boundary.MU_DNSis never set in ghost cells and stays 0, so in LES the ghost cell'sMU-MU_DNSincludes the molecular viscosity: -1.9 % for the tracer in LES at 2:1, against -0.07 % in DNS. With a tracer whose viscosity differs from the background, this also gives +0.6 % on two equal meshes.MU_DNS_Gis evaluated withZZ_GET, which holds the face composition for the first species and the last fine cell's composition after that, andMAX(0,·)is missing. A tracer with a different viscosity, no flow, 2:1: -1.0 % in 4 s with item 5 already fixed (-3.3 % on master, where item 5 adds to it).Change (diff attached):
MATCH_HEAT_FLUX_AT_MESH_INTERFACE(divg.f90). On the coarse side of a refined boundary, k dT/dn is replaced by the area-weighted sum of the fine-side values, computed from the inputs the fine mesh uses, as for the species. Solid fine cells are left out.BOUNDARY_LOOP(DNS and LES),INTERPOLATEDghost cells get their own k from the ghost-cell state, so both meshes use ½(k₁+k₂).CENTRE_DISTANCE_FACTOR), for heat and species, and the coarse side uses the same distance when it sums the fine faces. At a refined boundary the old rule (the fine-mesh spacing, which the species code used) was already conservative, but less accurate: in the 2:1 conduction case it gives 708 W/m², the centre distance 700.4.PBAR_OTHERfrom the zone pressure (plus the ambient profile withSTRATIFICATION=T),MU_DNSinINTERPOLATEDghost cells (velo.f90), and in the species sumMU_DNS_G = MU_DNS(IIG,JJG,KKG)withMAX(0,·)on each side and solid fine cells left out.With GEOM (
CC_IBM), items 1 and 3 are not applied, because the coarse mesh cannot see cut cells on the fine side. WithTENSOR_DIFFUSIVITY=T, items 1 and 3 are not applied to the heat flux (the 2:1 LES box still changes by -1.6 %), and on cylindrical meshes item 1 is not applied. Items 2 and 4 apply in all cases.With the change (same cases):
STRATIFICATIONT and F.NOISE=F: 0.000 % at 2:1 and where only dx changes, for anySTRATIFICATION; 0.000 % next to the obstruction; +0.02 % with a different viscosity in LES (it scales with the time step: +0.005 % at DT/4, seeMU_DNSbelow). With the default initial velocity noise the 2:1 tracer changes by -0.09 % (DNS and LES); that is the noise carrying the tracer across the boundary, see below.energy_budget_adiabatic_wallson other mesh layouts: where only dz changes, the energy error comes down to the equal-mesh level; in a refined layout the change removes a bit more than a third of it (details below).In LES the coarse side recomputes
MU_DNSof the fine cell at the end-of-stage temperature, as the existing species code does. In a buoyant LES box (2:1 in z) the energy changes by at most 1e-8, the same as on equal meshes; for the species it is the +0.02 % above. SendingMU_DNSwithMUin exchanges 1 and 4 would make it exact.Energy budget on other mesh layouts, and verification cases
energy_budget_adiabatic_walls(VLES, 1.2 MW, 300 s), ∫(Q_TOTAL - Q_ENTH) dt / ∫HRR dt:The rest in the refined layout is not there on equal meshes. What is still not matched at a refined boundary is the advective flux (below) and the enthalpy carried by species diffusion (h_α is taken at the coarse face temperature); I have not separated the two.
Verification cases, master and with the change on the same machine: 16 cases (multi-mesh, refined, GEOM, energy budget, species), all 35 active multi-mesh DNS/LES cases in FDS_Cases.sh (3 of them in the 16), and the commented-out
ns2d_16_*_refinementcases andmove_slug_left. All of them run to the end with both. Not run:sphere_Re200(GEOM, long).ns2d_16_int_1to2_refinementand the fivesoborot_*_wave_128cases (devc output identical).obst_coarse_fine_interface(ΔP at 10 s -1.47 Pa in both),duct_flow_uglmat_refine(1.000 m³/s in and out in both),dancing_eddies_uglmat_refineanddancing_eddies_embed(same pressure iterations; the energy terms change),mass_balance_reacandmass_balance_reac_2(species mass errors as on master),obst_activation_default_gases(temperature stays at 20.00000 °C in both; tolerance 0.005 °C).energy_budget_adiabatic_walls,energy_budget_dns_100,simple_duct,sphere_helium_conserve_3meshes) and the one-mesh layout above were run with the version just before the last two fixes, which do not act there (one mesh, or VLES/GEOM without obstructions).Not fixed: mass at a refined boundary. Mass is still not conserved when gas flows from the coarse mesh into the fine one. In the box with the hot gas on the fine side, the hot gas cools and contracts and the cold coarse side pushes gas into the fine mesh. With the hot gas on the coarse side, or a heat source on the fine side, the flow goes the other way and the mass is conserved.
At a refined boundary the second ghost cell is a copy of the first, so the flux limiter is first order where the flow enters a mesh but not where it leaves. For flow from coarse to fine, the fine mesh takes the coarse density on every face while the coarse mesh sends a limited face value, so the two fluxes differ. I have not checked this in detail. Matching it would need the coarse mesh to use the sum of the fine-face fluxes, so I left it out of this change.
An older, separate limitation: when the first fine cell behind a coarse face is solid, init.f90 makes the whole coarse face a wall, so the open fine cells beside it exchange heat with a wall (-0.30 % with the change, -1.45 % on master, in the obstruction box).
The diff is against b7dc77f, and the inputs are attached. Items 1 and 3 change only cases where the cell size changes at a mesh boundary; item 2 multi-mesh DNS cases where k varies and nearly all multi-mesh LES cases; item 4 species diffusion at refined boundaries in DNS and LES, LES cases with mesh boundaries, and cases where an obstruction touches a refined boundary.
issue9051_diff.txt
issue9051_inputs.zip
rmcdermo commentedon Nov 8, 2026
Thanks for the detailed analysis. I would prefer a diff as a PR, so that I can test on a branch.
On the mass conservation, I thought we had that working? Are you using UGLMAT pressure solver? This is required for mesh refinement interfaces, else we cannot expect mass conservation without an extremely tight velocity tolerance.
ghaffari-eng commentedon Nov 9, 2026
@rmcdermo Thanks. The changes are now in two PRs: #16743 (heat and species flux matching, the diff above on current master) and #16744 (mass). As far as I can tell, each applies to master on its own. What each one changes is in the PR descriptions; the results are below.
On the mass: my cases used the default FFT solver. With UGLMAT the drift seems to be practically the same (gravity box +0.45 % instead of +0.40 %, the other DNS boxes of that table within 0.01 %), although the normal velocities at the interface then agree to 2e-16 m/s. From what I can see, the difference comes from the advective face values at the refined boundary: the second ghost cell is a copy of the first, so each mesh is first order where gas flows into it, and the two meshes compute different face values of ρZ. #16744 makes both meshes use the same face values.
With FFT, #16744 does not move the velocity mismatch into the coarse cell. I tried that first (full refluxing), but with FFT the energy budget then seemed to get worse (energy_budget, refined layout, with #16743: +1.16 % at 60 s, against +0.185 % with the version in the PR). What is left with FFT appears to follow VELOCITY_TOLERANCE: gravity box -3.6e-5 at the default tolerance and -7.6e-8 with
VELOCITY_TOLERANCE=1E-5(two equal fine meshes: -4.9e-6 and -2.5e-8).Sealed boxes, 2:1 and 3:1, 4 s (45 cases, DNS and LES, x/y/z), change of mass:
0 = no change in the 8 digits of the devc file, with 1 and 2 MPI processes. The rest in LES seems to come from the diffusive flux, which #16743 matches. With FFT, total mass: master up to +0.57 %, #16744 up to -3.6e-5.
Propane burner in a sealed box (2:1), 20 s, mass minus fuel injected, relative: UGLMAT master +2.55e-3, #16744 -2.96e-6, one fine mesh -2.94e-6; FFT master +2.5e-3, #16744 -2.9e-5.
Accuracy looks unchanged: a tracer pulse carried once through a coarse-fine-coarse channel has L1 error 0.0587 on master and with #16744 (one fine mesh 0.0387, one coarse mesh 0.0645); tracer mass +4.1e-4 on master, 0 with #16744.
energy_budget_adiabatic_walls (VLES), refined layout (5 meshes, 2:1 around the fire), ∫(Q_TOTAL-Q_ENTH)dt/∫HRR dt:
Inputs: issue9051_pr2_inputs.zip
rmcdermo commentedon Nov 9, 2026
OK, thanks. As I commented in the PR conversation, I will check as soon as I can. In the meantime, can you please add to your results table a wall clock time and use some significant total number of cells so we can see if this new change makes a noticeable difference in computational cost. Thanks
ghaffari-eng commentedon Nov 11, 2026
@rmcdermo Wall clock times below, from one PC (i7-14700F, 8 P + 12 E cores, WSL2, 16 MPI processes, one run at a time; run 2 in the reverse order of run 1). Case: 2.0 million cells, 16 meshes, 5 cm around a 2 MW burner and 10 cm elsewhere, 2:1 at the interfaces. All builds take the same number of time steps, and for a given case the same number of pressure iterations (1398 for 400 steps; 7710 to 7711 for the 3 s run).
From what I can see, the differences between the builds are smaller than the scatter between repeated runs on this machine (master: 457 s and 608 s for the same 400 steps). In the
_cpu.csvfiles, the extra time of #16744 seems to be mostly in COMM, about 0.02 to 0.05 s per time step with FFT (1 to 4 % of a step here), probably from the two added exchanges in each stage. In the 3 s run with both PRs I did not see it, so this is also close to the noise. With UGLMAT, where the pressure solve takes about 75 % of the step, I could not see a difference.Input file (FFT; for UGLMAT add
&PRES SOLVER='UGLMAT' /; T_END=0.3 for the 100 step runs; the 3 s run has T_END=3 and noLOCK_TIME_STEP)