Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add isotropic viscosity and resistivity #89

Merged
merged 68 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from 64 commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
b5baf67
Add simple anisotropic step function test
pgrete Oct 3, 2021
e9ac8f6
Separate FillDerived and EstimateTimestep in driver in prep for STS list
pgrete Oct 3, 2021
2b30fca
Add diffflux parameter
pgrete Oct 3, 2021
db63255
Add RKL2 STS task list
pgrete Oct 3, 2021
a968fd8
Add calc of RKL2 stages
pgrete Oct 3, 2021
0e0986b
Remove unncessary register for rkl2
pgrete Oct 4, 2021
6da6766
Adopt STS RKL2 variable naming
pgrete Oct 4, 2021
d25abb3
Move calc of dt_diff into PreStep
pgrete Oct 4, 2021
b4dfdd9
Make tlim an argument for diff step test
pgrete Oct 6, 2021
5f20625
Adjust RKL2 conv test to gaussian profile
pgrete Oct 6, 2021
b75b496
Add conv panel to conv plot
pgrete Oct 6, 2021
3473da8
auto-format
pgrete Oct 6, 2021
3d26c40
rename diffusion integrator parameter
pgrete Oct 6, 2021
61a9c93
Add isotropic thermal conduction
pgrete Oct 6, 2021
647490d
Add isotropic cond to conv test
pgrete Oct 6, 2021
4e03d38
Add RKL2 conv test
pgrete Oct 6, 2021
a235952
Add new dt max ratio for rkl2 param
pgrete Oct 11, 2021
991d353
Add prolongation and fluxcorrect to RKL2 task list
pgrete Oct 11, 2021
7fd557d
Use base container as active STS container (workaround some AMR bug f…
pgrete Oct 12, 2021
755e06b
Merge branch 'pgrete/dt-fixes' into pgrete/sts
pgrete Oct 23, 2021
c2acc9e
Merge branch 'main' into pgrete/sts
pgrete Dec 8, 2021
1f9cf68
Add isotropic Spitzer thermal conduction timestep
pgrete Dec 8, 2021
1b9a797
Calc isotropic, non-const thermal diff
pgrete Dec 8, 2021
16ad2ca
Merge branch 'pgrete/cooling-hotfix' into pgrete/sts
pgrete Apr 12, 2022
c9f1dfb
Fix calc of saturated heat flux
pgrete Apr 12, 2022
8599682
Add LimO3 limiter
pgrete May 13, 2022
4ebb5d6
Add limo3 convergence
pgrete May 13, 2022
8800b51
Fix LimO3 recon
pgrete May 14, 2022
b416ce0
Merge branch 'pgrete/limo3' into pgrete/sts
pgrete May 16, 2022
3986cee
Merge branch 'main' into pgrete/sts
pgrete Jun 7, 2022
3f071d4
Fix saturated conduction prefactor
pgrete Jun 7, 2022
9582764
Remove calc of saturated conduction from cond coeff
pgrete Jun 7, 2022
115285d
Add upwinded saturated conduction in x-dir
pgrete Jun 7, 2022
51dca4f
Add saturated conduction prefactor
pgrete Jun 8, 2022
8194e97
Add x2 and x3 sat cond fluxes
pgrete Jun 8, 2022
ca3c397
Increase default rkl2 ratio to 400 and allow flux correction for all …
pgrete Jun 8, 2022
6494ab2
Remove parabolic timestep constraint for saturated conduction limit r…
pgrete Aug 9, 2022
6df018f
Add perturb to cloud pgen
pgrete Aug 10, 2022
1d0cb19
Add perturb to B (knowing this is not great...)
pgrete Aug 12, 2022
300c6a0
Revert "Add perturb to B (knowing this is not great...)"
pgrete Sep 24, 2022
9205e56
Revert "Add perturb to cloud pgen"
pgrete Sep 24, 2022
1749bb8
Limit cooling to upper bound of TFloor and cooling table cutoff
pgrete Sep 24, 2022
2bc56f8
Add oblique B field
pgrete Sep 24, 2022
3b6ac2e
Merge branch 'main' into pgrete/sts
pgrete Sep 25, 2023
b0bd7ca
Update coords and driver
pgrete Sep 25, 2023
4ab8834
Fix test cases and add success check
pgrete Sep 25, 2023
3199c6a
Merge branch 'main' into pgrete/sts
pgrete Sep 28, 2023
42f9f3c
Add isotropic shear viscosity
pgrete Sep 28, 2023
1c51435
Add viscosity test problem
pgrete Sep 28, 2023
5fea712
Add viscosity convergence test
pgrete Sep 28, 2023
2cd1e60
Add Ohmic resistivity
pgrete Oct 4, 2023
93fa27f
Remove visc pgen and move to diffusion pgen
pgrete Oct 4, 2023
bd3834f
Add resis. conv test to diffusion one
pgrete Oct 4, 2023
6e0151e
Add linwave3d decay diffusion test and fix parabolic dt
pgrete Oct 5, 2023
98f2f1f
Fix test thresholds
pgrete Oct 5, 2023
17f5a69
Merge branch 'main' into pgrete/diffusion
pgrete Aug 22, 2024
3f788ad
Add changelog and readme
pgrete Aug 22, 2024
3e18c25
Cleanup leftover code
pgrete Aug 22, 2024
406ec30
Add doc
pgrete Aug 22, 2024
07fc229
Merge branch 'main' into pgrete/diffusion
pgrete Sep 2, 2024
5319ff3
Merge branch 'main' into pgrete/diffusion
pgrete Sep 9, 2024
45165ff
Fix interface
pgrete Sep 9, 2024
3ab1c95
Fix more interface
pgrete Sep 9, 2024
8e1910e
Fix even more interfaces
pgrete Sep 9, 2024
a9e5203
And fixing a typo
pgrete Sep 9, 2024
3be0a24
Merge remote-tracking branch 'origin/main' into pgrete/diffusion
pgrete Sep 10, 2024
043a028
Increase ctest timeout
pgrete Sep 10, 2024
4e41e6d
Address BWO review comments
pgrete Sep 10, 2024
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
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ jobs:
build/tst/regression/outputs/cluster_tabular_cooling/convergence.png
build/tst/regression/outputs/aniso_therm_cond_ring_conv/ring_convergence.png
build/tst/regression/outputs/aniso_therm_cond_gauss_conv/cond.png
build/tst/regression/outputs/diffusion/ohm.png
build/tst/regression/outputs/diffusion/visc.png
build/tst/regression/outputs/field_loop/field_loop.png
build/tst/regression/outputs/riemann_hydro/shock_tube.png
build/tst/regression/outputs/turbulence/parthenon.out1.hst
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Current develop (i.e., `main` branch)

### Added (new features/APIs/variables/...)
- [[PR 89]](https://github.com/parthenon-hpc-lab/athenapk/pull/89) Add viscosity and resistivity
- [[PR 1]](https://github.com/parthenon-hpc-lab/athenapk/pull/1) Add isotropic thermal conduction and RKL2 supertimestepping

### Changed (changing behavior/API/variables/...)
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ Current features include
- HLLE (hydro and MHD), HLLC (hydro), and HLLD (MHD) Riemann solvers
- adiabatic equation of state
- MHD based on hyperbolic divergence cleaning following Dedner+ 2002
- isotropic and anisotropic thermal conduction
- operator-split, second-order RKL2 supertimestepping for diffusive terms
- diffusion processes
- isotropic and anisotropic thermal conduction
- viscosity
- resistivity
- diffusion integrator
- unsplit
- operator-split, second-order RKL2 supertimestepping
- optically thin cooling based on tabulated cooling tables with either Townsend 2009 exact integration or operator-split subcycling
- static and adaptive mesh refinement
- problem generators for
Expand Down
79 changes: 79 additions & 0 deletions docs/input.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,62 @@ conserved to primitive conversion if both are defined.

#### Diffusive processes

Diffusive processes in AthenaPK can be configured in the `<diffusion>` block of the input file.
```
<diffusion>
integrator = unsplit # alternatively: rkl2
#rkl2_max_dt_ratio = 100.0 # limits the ratio between the parabolic and hyperbolic timesteps
pgrete marked this conversation as resolved.
Show resolved Hide resolved
#cfl = 1.0 # Additional safety factor applied to diffusive timestep constraint. Default to hyperbolic cfl.
Copy link

Choose a reason for hiding this comment

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

again, for rkl2/operator split integrator (the main point here is that there are a lot of knobs to turn and it'd help to avoid confusion in this regard)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually this applies to both. I adjusted the comment accordingly.


conduction = anisotropic # none (disabled), or isotropic, or anisotropic
conduction_coeff = fixed # alternative: spitzer
thermal_diff_coeff_code = 0.01 # fixed coefficent in code units
Copy link

Choose a reason for hiding this comment

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

A general comment about coefficients - based on conversations with my current grad students, they would really appreciate if the units of the viscosity and resistivity were mentioned in the documentation, and perhaps a reference (even to a Shu or Spitzer textbook section) where they can figure out some details about the physics so they can set numbers appropriately.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just added the info on the units itself.
Regarding text book references, I'm happy if any student who does a deep dive intro opens a PR to extend the documentation accordingly.

#spitzer_cond_in_erg_by_s_K_cm = 4.6e7 # spitzer coefficient in cgs units (requires definition of a unit system)
#conduction_sat_phi = 0.3 # fudge factor to account for uncertainties in saturated fluxes


viscosity = none # none (disabled) or isotropic
viscosity_coeff = fixed
mom_diff_coeff_code = 0.25 # fixed coefficent in code units

resistivity = none # none (disabled) or ohmic
resistivity_coeff = fixed
ohm_diff_coeff_code = 0.25 # fixed coefficent in code units
```
(An)isotropic thermal conduction (with fixed or Spitzer coefficient), and isotropic viscosity and
resistivity with fixed coefficient are currently implemented.
They can be integrated in an unsplit manner or operator split using a second-order accurate RKL2
supertimestepping algorithm.
More details are described in the following.

#### Integrators

Diffusive processes can be integrated in either an unsplit
fashion (`diffusion/integrator=unsplit`) or operator split using a second-order accurate
RKL2 super timestepping algorithm (`diffusion/integrator=rkl2`) following [^M+14].

In the unsplit case, the diffusive processes are included at the end of every stage in
the main integration loop and the global timestep is limited accordingly.
A separate CFL can be set for the diffusive processes via `diffusion/cfl=...`, which
defaults to the hyperbolic value if not set.

In the RKL2 case, the global timestep is not limited by the diffusive processes by default.
However, as reported by [^V+17] a large number of stages
($`s \approx \sqrt(\Delta t_{hyp}/\Delta t_{par}) \geq 20`$) in the supertimestepping
(in combination with anisotropic, limited diffusion) may lead to a loss in accuracy, which
is why the difference between hyperbolic and parabolic timesteps can be limited by
`diffusion/rkl2_max_dt_ratio=...` and a warning is shown if the ratio is above 400.
Note that if this limit is enforced the `dt=` shown on the terminal might not be the actual
`dt` taken in the code as the limit is currently enforced only after the output
has been printed.

[^M+14]:
C. D. Meyer, D. S. Balsara, and T. D. Aslam, “A stabilized Runge–Kutta–Legendre method for explicit super-time-stepping of parabolic and mixed equations,” Journal of Computational Physics, vol. 257, pp. 594–626, 2014, doi: https://doi.org/10.1016/j.jcp.2013.08.021.

[^V+17]:
B. Vaidya, D. Prasad, A. Mignone, P. Sharma, and L. Rickler, “Scalable explicit implementation of anisotropic diffusion with Runge–Kutta–Legendre super-time stepping,” Monthly Notices of the Royal Astronomical Society, vol. 472, no. 3, pp. 3147–3160, 2017, doi: 10.1093/mnras/stx2176.


##### Isotropic (hydro and MHD) and anisotropic thermal conduction (only MHD)
In the presence of magnetic fields thermal conduction is becoming anisotropic with the flux along
the local magnetic field direction typically being much stronger than the flux perpendicular to the magnetic field.
Expand Down Expand Up @@ -140,6 +196,29 @@ Default value corresponds to the typical value used in literature and goes back
[^BM82]:
S. A. Balbus and C. F. McKee, “The evaporation of spherical clouds in a hot gas. III - Suprathermal evaporation,” , vol. 252, pp. 529–552, Jan. 1982, doi: https://doi.org/10.1086/159581

#### Viscosity/Momentum diffusion

Only isotropic viscosity with a (spatially and temporally) fixed coefficient in code units
is currently implemented.
Copy link

Choose a reason for hiding this comment

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

this would be a helpful place to mention the units of viscosity, even if it's only available in code units (this would help students who are trying to figure out what values are reasonable based on other simulation settings). Same thing applies for the resistivity subsection below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added info both here and in the overview block above.

To enable set (in the `<diffusion>` block)
```
viscosity = isotropic
viscosity_coeff = fixed
mom_diff_coeff_code = 0.25 # fixed coefficent in code units
```

#### Resistivity/Ohmic diffusion

Only resistivity with a (spatially and temporally) fixed coefficient in code units
is currently implemented.
To enable set (in the `<diffusion>` block)
```
resistivity = ohmic
resistivity_coeff = fixed
ohm_diff_coeff_code = 0.25 # fixed coefficent in code units
```


### Additional MHD options in `<hydro>` block

Parameter: `glmmhd_source` (string)
Expand Down
14 changes: 10 additions & 4 deletions inputs/diffusion.in
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# AthenaPK - a performance portable block structured AMR MHD code
# Copyright (c) 2021, Athena Parthenon Collaboration. All rights reserved.
# Copyright (c) 2021-2023, Athena Parthenon Collaboration. All rights reserved.
pgrete marked this conversation as resolved.
Show resolved Hide resolved
# Licensed under the BSD 3-Clause License (the "LICENSE");

<comment>
problem = Thermal diffusion setup
problem = Diffusion setup (for thermal, momentum and Ohmic diffusion tests)

<job>
problem_id = diffusion
Expand Down Expand Up @@ -60,11 +60,17 @@ reconstruction = dc
gamma = 2.0

<diffusion>
integrator = unsplit
integrator = rkl2
conduction = anisotropic
conduction_coeff = fixed
thermal_diff_coeff_code = 0.01
rkl2_max_dt_ratio = 400.0
viscosity = none # none (disabled), isotropic, or anisotropic
viscosity_coeff = fixed
mom_diff_coeff_code = 0.25
resistivity = none # none (disabled) or ohmic
resistivity_coeff = fixed
ohm_diff_coeff_code = 0.25
rkl2_max_dt_ratio = 100.0

<parthenon/output0>
file_type = hdf5
Expand Down
4 changes: 3 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ add_executable(
eos/adiabatic_glmmhd.cpp
units.hpp
eos/adiabatic_hydro.cpp
hydro/diffusion/conduction.cpp
hydro/diffusion/diffusion.cpp
hydro/diffusion/diffusion.hpp
hydro/diffusion/conduction.cpp
hydro/diffusion/resistivity.cpp
hydro/diffusion/viscosity.cpp
hydro/hydro_driver.cpp
hydro/hydro.cpp
hydro/glmmhd/dedner_source.cpp
Expand Down
4 changes: 2 additions & 2 deletions src/hydro/diffusion/conduction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ Real EstimateConductionTimestep(MeshData<Real> *md) {
},
Kokkos::Min<Real>(min_dt_cond));
}

return fac * min_dt_cond;
const auto &cfl_diff = hydro_pkg->Param<Real>("cfl_diff");
return cfl_diff * fac * min_dt_cond;
}

//---------------------------------------------------------------------------------------
Expand Down
24 changes: 23 additions & 1 deletion src/hydro/diffusion/diffusion.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//========================================================================================
// AthenaPK - a performance portable block structured AMR astrophysical MHD code.
// Copyright (c) 2021, Athena-Parthenon Collaboration. All rights reserved.
// Copyright (c) 2021-2023, Athena-Parthenon Collaboration. All rights reserved.
pgrete marked this conversation as resolved.
Show resolved Hide resolved
// Licensed under the 3-clause BSD License, see LICENSE file for details
//========================================================================================
//! \file diffusion.cpp
Expand All @@ -27,5 +27,27 @@ TaskStatus CalcDiffFluxes(StateDescriptor *hydro_pkg, MeshData<Real> *md) {
ThermalFluxGeneral(md);
}
}
const auto &viscosity = hydro_pkg->Param<Viscosity>("viscosity");
if (viscosity != Viscosity::none) {
const auto &mom_diff = hydro_pkg->Param<MomentumDiffusivity>("mom_diff");

if (viscosity == Viscosity::isotropic &&
mom_diff.GetCoeffType() == ViscosityCoeff::fixed) {
MomentumDiffFluxIsoFixed(md);
} else {
MomentumDiffFluxGeneral(md);
}
}
const auto &resistivity = hydro_pkg->Param<Resistivity>("resistivity");
if (resistivity != Resistivity::none) {
const auto &ohm_diff = hydro_pkg->Param<OhmicDiffusivity>("ohm_diff");

if (resistivity == Resistivity::ohmic &&
ohm_diff.GetCoeffType() == ResistivityCoeff::fixed) {
OhmicDiffFluxIsoFixed(md);
} else {
OhmicDiffFluxGeneral(md);
}
}
return TaskStatus::complete;
}
65 changes: 65 additions & 0 deletions src/hydro/diffusion/diffusion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,71 @@ void ThermalFluxIsoFixed(MeshData<Real> *md);
//! Calculate thermal conduction (general case incl. anisotropic and saturated)
void ThermalFluxGeneral(MeshData<Real> *md);

struct MomentumDiffusivity {
private:
Real mbar_, me_, kb_;
Viscosity viscosity_;
ViscosityCoeff viscosity_coeff_type_;
// "free" coefficient/prefactor. Value depends on viscosity set in the constructor.
Real coeff_;

public:
KOKKOS_INLINE_FUNCTION
MomentumDiffusivity(Viscosity viscosity, ViscosityCoeff viscosity_coeff_type,
Real coeff, Real mbar, Real me, Real kb)
: viscosity_(viscosity), viscosity_coeff_type_(viscosity_coeff_type), coeff_(coeff),
mbar_(mbar), me_(me), kb_(kb) {}

KOKKOS_INLINE_FUNCTION
Real Get(const Real pres, const Real rho) const;

KOKKOS_INLINE_FUNCTION
Viscosity GetType() const { return viscosity_; }

KOKKOS_INLINE_FUNCTION
ViscosityCoeff GetCoeffType() const { return viscosity_coeff_type_; }
};

Real EstimateViscosityTimestep(MeshData<Real> *md);

//! Calculate isotropic viscosity with fixed coefficient
void MomentumDiffFluxIsoFixed(MeshData<Real> *md);
//! Calculate viscosity (general case incl. anisotropic)
void MomentumDiffFluxGeneral(MeshData<Real> *md);

struct OhmicDiffusivity {
private:
Real mbar_, me_, kb_;
Resistivity resistivity_;
ResistivityCoeff resistivity_coeff_type_;
// "free" coefficient/prefactor. Value depends on resistivity set in the constructor.
Real coeff_;

public:
KOKKOS_INLINE_FUNCTION
OhmicDiffusivity(Resistivity resistivity, ResistivityCoeff resistivity_coeff_type,
Real coeff, Real mbar, Real me, Real kb)
: resistivity_(resistivity), resistivity_coeff_type_(resistivity_coeff_type),
coeff_(coeff), mbar_(mbar), me_(me), kb_(kb) {}

KOKKOS_INLINE_FUNCTION
Real Get(const Real pres, const Real rho) const;

KOKKOS_INLINE_FUNCTION
Resistivity GetType() const { return resistivity_; }

KOKKOS_INLINE_FUNCTION
ResistivityCoeff GetCoeffType() const { return resistivity_coeff_type_; }
};

Real EstimateResistivityTimestep(MeshData<Real> *md);

//! Calculate isotropic resistivity with fixed coefficient
void OhmicDiffFluxIsoFixed(MeshData<Real> *md);

//! Calculate resistivity (general case incl. Spitzer)
void OhmicDiffFluxGeneral(MeshData<Real> *md);

// Calculate all diffusion fluxes, i.e., update the .flux views in md
TaskStatus CalcDiffFluxes(StateDescriptor *hydro_pkg, MeshData<Real> *md);

Expand Down
Loading
Loading