Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
125 commits
Select commit Hold shift + click to select a range
220649b
basic conduction module
aditivijayan Mar 4, 2026
51b0e2d
basic problem with differnt T for x<0
aditivijayan Mar 4, 2026
b250367
hook to electron conduction
aditivijayan Mar 4, 2026
03216d7
add econduction
aditivijayan Mar 25, 2026
6eb4ce5
add 3D problems
aditivijayan Mar 25, 2026
b0ce11c
add econduction and remove spitzer and limiter for test
aditivijayan Mar 25, 2026
81138ab
add module purge
aditivijayan Mar 25, 2026
70110ab
comment out flux related params
aditivijayan Apr 1, 2026
52b2156
changes to Gaussian3d
aditivijayan Apr 1, 2026
e0e0169
add enableCondcution param and conductivity to estimate tcond
aditivijayan Apr 1, 2026
3760284
add conduction cfl
aditivijayan Apr 15, 2026
769ad08
add limiter
aditivijayan Apr 15, 2026
57285c6
add conduction cfl
aditivijayan Apr 15, 2026
d73dc40
add cloud-wind problem
aditivijayan Apr 15, 2026
875a5fa
print params of the problem
aditivijayan Apr 15, 2026
3f33fb3
print cs for sanity check
aditivijayan Apr 15, 2026
74d3eb8
remove cloud-wind problem
aditivijayan Apr 16, 2026
51c7506
estimate error for 1d problem
aditivijayan Apr 16, 2026
e571b74
remove limiter
aditivijayan Apr 16, 2026
d521372
fix analytical solution
aditivijayan Apr 16, 2026
993a0e2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 16, 2026
f36ea39
remove Emin
aditivijayan Apr 17, 2026
a597ece
remove ref to isothermal cs
aditivijayan Apr 17, 2026
a69be2a
set default conduction =0
aditivijayan Apr 17, 2026
5a09bb0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 17, 2026
d1ae1a1
read saturation factor from input
aditivijayan Apr 17, 2026
7fe825b
fix warning
aditivijayan Apr 17, 2026
759cc12
add input for test
aditivijayan Apr 17, 2026
e4935ec
fix ny nz
aditivijayan Apr 17, 2026
4e44bb9
fix cfl
aditivijayan Apr 17, 2026
8221a3b
add newlines
aditivijayan Apr 17, 2026
79e347a
add newlines
aditivijayan Apr 17, 2026
0809849
add newlines
aditivijayan Apr 17, 2026
0e49460
fix problo/problhi
aditivijayan Apr 17, 2026
38b9c7e
add periodic bc
aditivijayan Apr 17, 2026
ff32a81
use resampled cooling tables for temp and cs
aditivijayan Apr 20, 2026
acca305
remove extra file and add emag to etot
aditivijayan Apr 20, 2026
2ce86b5
abort when max_lev>0 for TC
aditivijayan Apr 20, 2026
470d960
reply to comments
aditivijayan Apr 20, 2026
31bf51b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 20, 2026
9464398
fix warnings
aditivijayan Apr 20, 2026
a8edbec
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 20, 2026
8ecc183
remove extra test
aditivijayan Apr 20, 2026
cdc4f94
remove vars and fix warnings
aditivijayan Apr 20, 2026
8acf2b3
fix warning
aditivijayan Apr 20, 2026
8ce8281
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 20, 2026
edc431a
fix bug
aditivijayan Apr 20, 2026
f2bfa7d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 20, 2026
137c023
fix warning tidy
aditivijayan Apr 20, 2026
0a8a3a0
read cooling tables
aditivijayan Apr 20, 2026
cb7b155
add bs
aditivijayan Apr 22, 2026
d263b49
set all state vars to zero
aditivijayan Apr 22, 2026
fbd7c6c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 22, 2026
685db3a
conduction temp floor identical to global tempFloor_
aditivijayan Apr 22, 2026
45e0e24
fix bc
aditivijayan Apr 22, 2026
c01642a
remove ref to tfloor
aditivijayan Apr 22, 2026
fb5c552
fix warning
aditivijayan Apr 22, 2026
9edbee3
priority to 100
aditivijayan Apr 22, 2026
9cc5d2d
add min temp as param
aditivijayan Apr 22, 2026
787d400
fix nfactor to nsubstep**2 in case of conduction
aditivijayan Apr 22, 2026
cdf53e7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 22, 2026
5130fc2
add richardson test
aditivijayan Apr 23, 2026
9b63609
add params and fix solution
aditivijayan Apr 30, 2026
b4ec2d6
resolve merge
aditivijayan Apr 30, 2026
90a7c79
read in flag for EOS, default is 1:read EOS
aditivijayan Apr 30, 2026
f92464a
remove comments
aditivijayan Apr 30, 2026
fbd2047
remove error estimation test
aditivijayan Apr 30, 2026
f1b0458
remove step function test problem
aditivijayan Apr 30, 2026
10d52e8
remove solution for step function
aditivijayan Apr 30, 2026
836f51a
add notes for the test problem
aditivijayan Apr 30, 2026
d3a89fb
remove unused var
aditivijayan Apr 30, 2026
fb2e67b
add info on params
aditivijayan Apr 30, 2026
63e5f8b
correct timestep based on cv and rho
aditivijayan Apr 30, 2026
eff8394
remove kb from prefactor
aditivijayan Apr 30, 2026
73d21e3
fix notes and adjust parameters for consistency
aditivijayan May 1, 2026
a6edb77
fix units of prefactor
aditivijayan May 1, 2026
47bb3c2
add params to input file
aditivijayan May 1, 2026
618457e
fix n_factor
aditivijayan May 1, 2026
c5d0750
Merge branch 'development' into av/thermalconduction-clean
aditivijayan May 1, 2026
ca52ea7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 1, 2026
79052f3
fix typo
aditivijayan May 1, 2026
722bf1a
duplicate cfl
aditivijayan May 1, 2026
7ed8f38
end of line
aditivijayan May 1, 2026
74a3bc8
fix for error
aditivijayan May 1, 2026
832ff2f
fix for error
aditivijayan May 1, 2026
ae7834d
add enableConduction to strangsources
aditivijayan May 1, 2026
a413d8d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 1, 2026
11023ec
fix toml
aditivijayan May 1, 2026
3418911
cs, Tgas initialised to NAN
aditivijayan May 1, 2026
e6f47a1
Tga-->Tgas
aditivijayan May 1, 2026
a68f83b
fix warning
aditivijayan May 1, 2026
16635e0
double -> const
aditivijayan May 1, 2026
02cfa08
remove tables
aditivijayan May 1, 2026
2d38401
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 1, 2026
2e867ee
fix warning
aditivijayan May 1, 2026
0f2a32b
fix warnings
aditivijayan May 1, 2026
92a57f7
fix gemini comments
aditivijayan May 3, 2026
e0ee560
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 3, 2026
04f5763
tables not needed if eosFlag=1
aditivijayan May 6, 2026
ff9cdb8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 6, 2026
6b71f76
hopeful fix for the GPU out of mem crash
aditivijayan May 6, 2026
3ee8dfa
fix for gpu crash
aditivijayan May 6, 2026
aff77a7
fix gpu mem crash
aditivijayan May 7, 2026
c572b38
change to 1024
aditivijayan May 7, 2026
10db8df
Merge development and resolve submodule conflicts
aditivijayan May 7, 2026
07d4894
Remove obsolete extern/fmt directory to match development
aditivijayan May 7, 2026
a5962d0
remove extra coolign tables
aditivijayan May 7, 2026
ff17b66
remove cooling table not in repo
aditivijayan May 7, 2026
53f832f
remove extra table
aditivijayan May 7, 2026
f38cb1f
remove grackle data files from extern
aditivijayan May 7, 2026
75ee561
add cooling file
aditivijayan May 8, 2026
41f9e0d
fix coolign table
aditivijayan May 8, 2026
3665505
out of mem error fix
aditivijayan May 8, 2026
40fb768
make it 1d problem
aditivijayan May 10, 2026
152e52f
input should have three comps
aditivijayan May 10, 2026
c9a21a4
fix azp error
aditivijayan May 11, 2026
298b877
fix nx
aditivijayan May 11, 2026
724efcc
fix blocking factor
aditivijayan May 11, 2026
bcacedc
fix units in comments
aditivijayan May 12, 2026
e748f9d
fix units in comments
aditivijayan May 12, 2026
e4ff90e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 12, 2026
18b0a98
restore changes
aditivijayan May 14, 2026
bfc0dc9
edit params to execute test at nx=64
aditivijayan May 14, 2026
0acc4ae
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 14, 2026
8aefc50
fix conductivity for new params
aditivijayan May 14, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
33 changes: 33 additions & 0 deletions inputs/ThermalConduction.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# *****************************************************************
# Problem size and geometry
# *****************************************************************
geometry.prob_lo = [-1.5428e18, -1.5428e18, -1.5428e18]
geometry.prob_hi = [1.5428e18, 1.5428e18, 1.5428e18]
quokka.bc = ["foextrap", "foextrap", "foextrap"]

# *****************************************************************
# VERBOSITY
# *****************************************************************
amr.v = 1 # verbosity in Amr

# *****************************************************************
# Resolution and refinement
# *****************************************************************
amr.n_cell = [128, 128, 128]
amr.max_level = 0 # number of levels = max_level + 1
amr.blocking_factor = 32 # grid size must be divisible by this

cfl = 0.3

cooling.enabled = 0
cooling.read_tables_even_if_disabled = 1
cooling.cooling_table_type = "resampled"
cooling.hdf5_data_file = "../extern/cooling/CloudyData_UVB=HM2012_resampled.h5"


conduction.enabled = 1
conduction.conductivity_prefactor = 0.6113916490935586e12
conduction.flux_limiter_phi = 1
conduction.saturation_factor = 1.2e20
conduction.conduction_cfl = 0.1
conduction.eos_flag = 1
3 changes: 2 additions & 1 deletion scripts/hpc_profiles/gadi_hopper.profile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module load gcc/12.2.0
module purge
module load gcc/14.2.0
module load cuda/12.9.0

module unload openmpi
Expand Down
33 changes: 33 additions & 0 deletions src/QuokkaSimulation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ namespace filesystem = experimental::filesystem;

#include "SimulationData.hpp"
#include "chemistry/Chemistry.hpp"
#include "conduction/ElectronConduction.hpp"
#include "cooling/ResampledCooling.hpp"
#include "dust/DustDrag.hpp"
#include "dust/dust_system.hpp"
Expand Down Expand Up @@ -141,6 +142,10 @@ template <typename problem_t> class QuokkaSimulation : public AMRSimulation<prob
using AMRSimulation<problem_t>::sfh_interval_;
using AMRSimulation<problem_t>::sfh_time_interval_;

using AMRSimulation<problem_t>::enableElectronConduction_;
using AMRSimulation<problem_t>::electronConductionKappa0_;
using AMRSimulation<problem_t>::conductionCFL;

#if AMREX_SPACEDIM == 3
using AMRSimulation<problem_t>::luminosityTables_;
#endif // AMREX_SPACEDIM == 3
Expand All @@ -167,6 +172,10 @@ template <typename problem_t> class QuokkaSimulation : public AMRSimulation<prob
std::string coolingTableType_;
std::string coolingTableFilename_;

amrex::Real electronConductionFluxLimiterPhi_ = 1.0;
amrex::Real electronConductionSaturationFactor_ = 5.0;
int eosFlagForElectronConduction_ = 1; // 1 == use quokka::EOS; 0 == use resampled cooling

std::map<std::string, std::string> turbParams_;

static constexpr int nvarTotal_cc_ = Physics_Indices<problem_t>::nvarTotal_cc;
Expand Down Expand Up @@ -616,6 +625,17 @@ template <typename problem_t> void QuokkaSimulation<problem_t>::readParmParse()
}
}

// set electron thermal conduction runtime parameters
{
amrex::ParmParse const hpp("conduction");
hpp.query("enabled", enableElectronConduction_);
hpp.query("conductivity_prefactor", electronConductionKappa0_);
hpp.query("conduction_cfl", conductionCFL);
hpp.query("flux_limiter_phi", electronConductionFluxLimiterPhi_);
hpp.query("saturation_factor", electronConductionSaturationFactor_);
hpp.query("eos_flag", eosFlagForElectronConduction_);
}

// set turbulence runtime parameters
{
amrex::ParmParse const hpp("turbulence");
Expand Down Expand Up @@ -1032,6 +1052,19 @@ auto QuokkaSimulation<problem_t>::addStrangSplitSourcesWithBuiltin(amrex::MultiF
}
};

if (enableElectronConduction_ == 1) {
if (max_level > 0) {
amrex::Abort("Electron conduction not implemented for > 0 levels.");
}
fillBoundaryConditions(state, state, lev, time, quokka::centering::cc, quokka::direction::na, PreInterpState, PostInterpState);
const quokka::conduction::ElectronConductionParams conduction_params{.conductivity_prefactor = electronConductionKappa0_,
.flux_limiter_phi = electronConductionFluxLimiterPhi_,
.saturation_factor = electronConductionSaturationFactor_,
.min_temperature = tempFloor_,
.eos_flag = eosFlagForElectronConduction_};
quokka::conduction::ElectronConduction<problem_t>::ComputeExplicit(state, state_fc, geom[lev], dt, conduction_params, resampledTables_);
}

auto const applyUserSources = [&]() {
// compute user-specified sources
addStrangSplitSources(state, lev, time, dt);
Expand Down
214 changes: 214 additions & 0 deletions src/conduction/ElectronConduction.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
#ifndef ELECTRON_CONDUCTION_HPP_ // NOLINT
#define ELECTRON_CONDUCTION_HPP_

//==============================================================================
// TwoMomentRad - a radiation transport library for patch-based AMR codes
// Copyright 2020 Benjamin Wibking.
// Released under the MIT license. See LICENSE file included in the GitHub repo.
//==============================================================================
/// \file ElectronConduction.hpp
/// \brief Explicit flux-limited electron thermal conduction update.

#include <array>
#include <cmath>
#include <limits>

#include "AMReX_Array4.H"
#include "AMReX_Geometry.H"
#include "AMReX_GpuQualifiers.H"
#include "AMReX_MultiFab.H"
#include "AMReX_REAL.H"
#include "AMReX_SPACE.H"
#include "AMReX_Vector.H"
#include "cooling/ResampledCooling.hpp"
#include "hydro/hydro_system.hpp"

namespace quokka::conduction
{

struct ElectronConductionParams {
amrex::Real conductivity_prefactor = 3.e34; // units of erg cm^-1 s^-1 K^-1
amrex::Real flux_limiter_phi = 0.1;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you provide a reference for the value you used here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been chosen arbitrarily since it is not being used for now. PLUTO manual suggests phi<1.

amrex::Real saturation_factor = 5.0; // refer to equation 8 of Cowee & McKee 1977
amrex::Real min_temperature = 0.0; // default value will be overwritten by tempFloor_ during initialization
int eos_flag = 1; // 1 == use quokka::EOS; 0 == use resampled cooling
};

template <typename problem_t> class ElectronConduction
{
public:
static void ComputeExplicit(amrex::MultiFab &state, std::array<amrex::MultiFab, AMREX_SPACEDIM> const &state_fc, amrex::Geometry const &geom,
amrex::Real dt, ElectronConductionParams const &params, const quokka::ResampledCooling::resampled_tables &tables)
{
static_assert(Physics_Traits<problem_t>::is_hydro_enabled, "Electron conduction requires hydro to be enabled.");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A check should be added here to ensure that the simulation only has a single level and is not using AMR, since it doesn't fully support AMR yet.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check has been add to QuokkaSimulation.hpp.


if ((dt <= 0.0) || (params.conductivity_prefactor <= 0.0)) {
return;
}

if constexpr (HydroSystem<problem_t>::is_eos_isothermal()) {
amrex::ignore_unused(state_fc, geom, params);
return;
}

AMREX_ALWAYS_ASSERT_WITH_MESSAGE(state.nGrow() >= 1, "Electron conduction requires at least 1 ghost cell.");

const auto dx = geom.CellSizeArray();
const amrex::Real flux_limiter_phi = params.flux_limiter_phi;
const amrex::Real saturation_factor = params.saturation_factor;
const amrex::Real t_min = params.min_temperature;
const amrex::Real small = std::numeric_limits<amrex::Real>::min();

amrex::MultiFab temperature(state.boxArray(), state.DistributionMap(), 1, state.nGrow());
temperature.setVal(0.0);
amrex::MultiFab conductivity(state.boxArray(), state.DistributionMap(), 1, state.nGrow());
conductivity.setVal(0.0);
amrex::MultiFab saturated_flux(state.boxArray(), state.DistributionMap(), 1, state.nGrow());
saturated_flux.setVal(0.0);
Comment thread
BenWibking marked this conversation as resolved.

auto const &state_x0 = state.const_arrays();
auto const &state_fc_x0 = state_fc[0].const_arrays();
#if AMREX_SPACEDIM >= 2
auto const &state_fc_x1 = state_fc[1].const_arrays();
#endif
#if AMREX_SPACEDIM == 3
auto const &state_fc_x2 = state_fc[2].const_arrays();
#endif
auto temperature_arr = temperature.arrays();
auto conductivity_arr = conductivity.arrays();
auto saturated_flux_arr = saturated_flux.arrays();
amrex::IntVect ng = amrex::IntVect(AMREX_D_DECL(2, 2, 2));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The number of ghost cells to iterate over (ng) is hardcoded to 2, but the MultiFab state is only guaranteed to have at least 1 ghost cell (per the assertion on line 54). If state.nGrow() is 1, this ParallelFor will result in out-of-bounds memory access.

Since the gradient calculation only requires 1 ghost cell, ng should be set to 1, or it should be dynamically determined based on state.nGrow().

		amrex::IntVect ng = amrex::IntVect(AMREX_D_DECL(1, 1, 1));

std::optional<decltype(tables.const_tables())> tables_dev;
Copy link
Copy Markdown

@augmentcode augmentcode Bot May 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/conduction/ElectronConduction.hpp:81: std::optional (and dereferencing it) is captured/used inside an AMREX_GPU_DEVICE lambda; that’s often not device-compatible and this repo even has src/util/Optional.hpp for GPU-safe optionals. Consider restructuring so the device lambda captures a plain tables object (or a GPU-safe optional) rather than std::optional.

Severity: high

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

if (params.eos_flag == 0) {
tables_dev = tables.const_tables();
} else if (params.eos_flag != 0 && params.eos_flag != 1) {
amrex::Abort("Invalid eos_flag value in ElectronConduction. Must be 0 (resampled cooling) or 1 (quokka::EOS).");
}

amrex::ParallelFor(state, ng, [=] AMREX_GPU_DEVICE(int bx, int i, int j, int k) noexcept {
std::array<amrex::Array4<const amrex::Real>, AMREX_SPACEDIM> local_state_fc{};
if (Physics_Traits<problem_t>::is_mhd_enabled) {
local_state_fc[0] = state_fc_x0[bx];
#if AMREX_SPACEDIM >= 2
local_state_fc[1] = state_fc_x1[bx];
#endif
#if AMREX_SPACEDIM == 3
local_state_fc[2] = state_fc_x2[bx];
#endif
}

auto const &cons = state_x0[bx];
const amrex::Real rho = cons(i, j, k, HydroSystem<problem_t>::density_index);
const amrex::Real Eint = HydroSystem<problem_t>::ComputeInternalEnergy(cons, i, j, k, &local_state_fc);
amrex::Real Tgas = NAN;
amrex::Real cs = NAN;
if (params.eos_flag == 0) {
Tgas = quokka::ResampledCooling::ComputeTgasFromEgas(rho, Eint, *tables_dev);
cs = quokka::ResampledCooling::ComputeSoundSpeedFromRhoEint(rho, Eint, *tables_dev);
} else if (params.eos_flag == 1) {
Tgas = quokka::EOS<problem_t>::ComputeTgasFromEint(rho, Eint);
amrex::Real Pgas = quokka::EOS<problem_t>::ComputePressure(rho, Eint);
cs = quokka::EOS<problem_t>::ComputeSoundSpeed(rho, Pgas);
}

const amrex::Real Tuse = amrex::max(Tgas, t_min);
const amrex::Real kappa = params.conductivity_prefactor;
const amrex::Real qsat = amrex::max(saturation_factor * flux_limiter_phi * rho * cs * cs * cs, small);

temperature_arr[bx](i, j, k) = Tuse;
conductivity_arr[bx](i, j, k) = kappa;
saturated_flux_arr[bx](i, j, k) = qsat;
});

std::array<amrex::MultiFab, AMREX_SPACEDIM> heat_flux;
for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
amrex::BoxArray const ba_face = amrex::convert(state.boxArray(), amrex::IntVect::TheDimensionVector(idim));
heat_flux[idim].define(ba_face, state.DistributionMap(), 1, 0);
heat_flux[idim].setVal(0.0);
}

auto const &temp = temperature.const_arrays();
auto const &kappa = conductivity.const_arrays();
auto const &qsat = saturated_flux.const_arrays();
auto flux_x = heat_flux[0].arrays();
amrex::ParallelFor(heat_flux[0], [=] AMREX_GPU_DEVICE(int bx, int i, int j, int k) noexcept {
const amrex::Real gradT = (temp[bx](i, j, k) - temp[bx](i - 1, j, k)) / dx[0];
const amrex::Real kappa_face = 0.5 * (kappa[bx](i, j, k) + kappa[bx](i - 1, j, k));
const amrex::Real q_classical = -kappa_face * gradT;
const amrex::Real q_sat_face = 0.5 * (qsat[bx](i, j, k) + qsat[bx](i - 1, j, k));
const amrex::Real limiter = 1.0 + std::abs(q_classical) / amrex::max(q_sat_face, small);
Comment on lines +138 to +139
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The flux limiter is calculated but not applied to the heat flux. While the PR notes mention a preference for classical flux for now, calculating the limiter without using it is inefficient. If the limiter is intended for future use, it should be applied to q_classical to ensure stability in high-gradient regions, or the calculation should be removed to avoid redundant operations.

const amrex::Real limiter = 1.0 + std::abs(q_classical) / amrex::max(q_sat_face, small);
			flux_x[bx](i, j, k) = q_classical / limiter;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've re-added the limiter and set it to a large value in the input file in order to obviate its use.

flux_x[bx](i, j, k) = q_classical / limiter;
});

#if AMREX_SPACEDIM >= 2
auto flux_y = heat_flux[1].arrays();
amrex::ParallelFor(heat_flux[1], [=] AMREX_GPU_DEVICE(int bx, int i, int j, int k) noexcept {
const amrex::Real gradT = (temp[bx](i, j, k) - temp[bx](i, j - 1, k)) / dx[1];
const amrex::Real kappa_face = 0.5 * (kappa[bx](i, j, k) + kappa[bx](i, j - 1, k));
const amrex::Real q_classical = -kappa_face * gradT;
const amrex::Real q_sat_face = 0.5 * (qsat[bx](i, j, k) + qsat[bx](i, j - 1, k));
const amrex::Real limiter = 1.0 + std::abs(q_classical) / amrex::max(q_sat_face, small);
flux_y[bx](i, j, k) = q_classical / limiter;
});
#endif

#if AMREX_SPACEDIM == 3
auto flux_z = heat_flux[2].arrays();
amrex::ParallelFor(heat_flux[2], [=] AMREX_GPU_DEVICE(int bx, int i, int j, int k) noexcept {
const amrex::Real gradT = (temp[bx](i, j, k) - temp[bx](i, j, k - 1)) / dx[2];
const amrex::Real kappa_face = 0.5 * (kappa[bx](i, j, k) + kappa[bx](i, j, k - 1));
const amrex::Real q_classical = -kappa_face * gradT;
const amrex::Real q_sat_face = 0.5 * (qsat[bx](i, j, k) + qsat[bx](i, j, k - 1));
const amrex::Real limiter = 1.0 + std::abs(q_classical) / amrex::max(q_sat_face, small);
flux_z[bx](i, j, k) = q_classical / limiter;
});
#endif

auto state_out = state.arrays();
auto const &flux_x_const = heat_flux[0].const_arrays();
#if AMREX_SPACEDIM >= 2
auto const &flux_y_const = heat_flux[1].const_arrays();
#endif
#if AMREX_SPACEDIM == 3
auto const &flux_z_const = heat_flux[2].const_arrays();
#endif

amrex::ParallelFor(state, [=] AMREX_GPU_DEVICE(int bx, int i, int j, int k) noexcept {
std::array<amrex::Array4<const amrex::Real>, AMREX_SPACEDIM> local_state_fc{};
if (Physics_Traits<problem_t>::is_mhd_enabled) {
local_state_fc[0] = state_fc_x0[bx];
#if AMREX_SPACEDIM >= 2
local_state_fc[1] = state_fc_x1[bx];
#endif
#if AMREX_SPACEDIM == 3
local_state_fc[2] = state_fc_x2[bx];
#endif
}

const amrex::Real rho = state_out[bx](i, j, k, HydroSystem<problem_t>::density_index);
const amrex::Real px = state_out[bx](i, j, k, HydroSystem<problem_t>::x1Momentum_index);
const amrex::Real py = state_out[bx](i, j, k, HydroSystem<problem_t>::x2Momentum_index);
const amrex::Real pz = state_out[bx](i, j, k, HydroSystem<problem_t>::x3Momentum_index);

const amrex::Real Ekin = 0.5 * (px * px + py * py + pz * pz) / rho;
const amrex::Real Eint_old = HydroSystem<problem_t>::ComputeInternalEnergy(state_out[bx], i, j, k, &local_state_fc);
const amrex::Real Emag = HydroSystem<problem_t>::ComputeMagneticEnergy(i, j, k, &local_state_fc);
amrex::Real div_flux = (flux_x_const[bx](i + 1, j, k) - flux_x_const[bx](i, j, k)) / dx[0];
#if AMREX_SPACEDIM >= 2
div_flux += (flux_y_const[bx](i, j + 1, k) - flux_y_const[bx](i, j, k)) / dx[1];
#endif
#if AMREX_SPACEDIM == 3
div_flux += (flux_z_const[bx](i, j, k + 1) - flux_z_const[bx](i, j, k)) / dx[2];
#endif

amrex::Real Eint_new = Eint_old - dt * div_flux;
Comment thread
BenWibking marked this conversation as resolved.

state_out[bx](i, j, k, HydroSystem<problem_t>::energy_index) = Eint_new + Ekin + Emag;
state_out[bx](i, j, k, HydroSystem<problem_t>::internalEnergy_index) = Eint_new;
Comment thread
BenWibking marked this conversation as resolved.
});
}
};

} // namespace quokka::conduction

#endif // ELECTRON_CONDUCTION_HPP_
1 change: 1 addition & 0 deletions src/problems/ThermalConduction/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
quokka_add_problem(JOB_NAME ThermalConduction PRIORITY 100)
Loading
Loading