-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
14,218 additions
and
18 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
""" | ||
File contains dynamic variables related to the CBOD module | ||
""" | ||
|
||
import clearwater_modules.shared.processes as shared_processes | ||
from clearwater_modules import base | ||
from clearwater_modules.nsm1.model import NutrientBudget | ||
import clearwater_modules.nsm1.CBOD.processes as processes | ||
|
||
|
||
@base.register_variable(models=NutrientBudget) | ||
class Variable(base.Variable): | ||
... | ||
|
||
|
||
Variable( | ||
name='kbod_tc', | ||
long_name='Temperature adjusted oxidation rate', | ||
units='1/d', | ||
description='Temperature adjusted oxidation rate', | ||
use='dynamic', | ||
process=processes.kbod_tc | ||
) | ||
|
||
Variable( | ||
name='ksbod_tc', | ||
long_name='Temperature adjusted sedimentation rate', | ||
units='m/d', | ||
description='Temperature adjusted sedimentation rate', | ||
use='dynamic', | ||
process=processes.ksbod_tc | ||
) | ||
|
||
Variable( | ||
name='CBOD_oxidation', | ||
long_name='CBOD oxidation', | ||
units='mg/L/d', | ||
description='CBOD oxidation', | ||
use='dynamic', | ||
process=processes.CBOD_oxidation | ||
) | ||
|
||
Variable( | ||
name='CBOD_sedimentation', | ||
long_name='CBOD sedimentation', | ||
units='mg/L/d', | ||
description='CBOD sedimentation', | ||
use='dynamic', | ||
process=processes.CBOD_sedimentation | ||
) | ||
|
||
Variable( | ||
name='dCBODdt', | ||
long_name='Change in CBOD concentration for the given timestep', | ||
units='mg/L/d', | ||
description='Change in CBOD concentration for the given timestep', | ||
use='dynamic', | ||
process=processes.dCBODdt | ||
) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
""" | ||
File contains process to calculate new CBOD concentration and associated dependent variables | ||
""" | ||
|
||
import numba | ||
import xarray as xr | ||
from clearwater_modules.shared.processes import arrhenius_correction | ||
import math | ||
|
||
@numba.njit | ||
def kbod_tc( | ||
TwaterC: xr.DataArray, | ||
kbod_20: xr.DataArray, | ||
) -> xr.DataArray: | ||
"""Calculate the temperature adjusted CBOD oxidation rate (1/d) | ||
Args: | ||
TwaterC: water temperature in Celsius | ||
kbod_20: CBOD oxidation rate at 20 degrees Celsius (1/d) | ||
""" | ||
|
||
kbod_tc = arrhenius_correction(TwaterC, kbod_20, 1.047) | ||
return kbod_tc | ||
|
||
|
||
@numba.njit | ||
def ksbod_tc( | ||
TwaterC: xr.DataArray, | ||
ksbod_20: xr.DataArray, | ||
) -> xr.DataArray: | ||
"""Calculate the temperature adjusted CBOD sedimentation rate (m/d) | ||
Args: | ||
TwaterC: water temperature in Celsius | ||
ksbod_20: CBOD sedimentation rate at 20 degrees Celsius (m/d) | ||
""" | ||
|
||
ksbod_tc = arrhenius_correction(TwaterC, ksbod_20, 1.024) | ||
return ksbod_tc | ||
|
||
|
||
|
||
def CBOD_oxidation( | ||
DOX: xr.DataArray, | ||
CBOD: xr.DataArray, | ||
kbod_tc: xr.DataArray, | ||
KsOxbod: xr.DataArray, | ||
use_DOX: xr.DataArray | ||
) -> xr.DataArray: | ||
"""Calculates CBOD oxidation | ||
Args: | ||
DOX: Dissolved oxygen concentration (mg-O2/L) | ||
CBOD: Carbonaceous biochemical oxygen demand (mg-O2/L) | ||
kbod_tc: Temperature adjusted CBOD oxidation rate (1/d) | ||
KsOxbod: Half-saturation oxygen attenuation for CBOD oxidation (mg-O2/L) | ||
use_DOX: Option to consider DOX concentration in calculation of CBOD oxidation | ||
""" | ||
da: xr.DataArray = xr.where(use_DOX == True, (DOX / (KsOxbod + DOX)) * kbod_tc * CBOD, kbod_tc * CBOD) | ||
|
||
return da | ||
|
||
|
||
@numba.njit | ||
def CBOD_sedimentation( | ||
CBOD: xr.DataArray, | ||
ksbod_tc: xr.DataArray | ||
) -> xr.DataArray: | ||
"""Calculates CBOD sedimentation for each group | ||
Args: | ||
CBOD: CBOD concentration (mg-O2/L) | ||
ksbod_tc: Temperature adjusted sedimentation rate (m/d) | ||
""" | ||
|
||
CBOD_sedimentation = CBOD * ksbod_tc | ||
return CBOD_sedimentation | ||
|
||
|
||
@numba.njit | ||
def dCBODdt( | ||
CBOD_oxidation: xr.DataArray, | ||
CBOD_sedimentation: xr.DataArray | ||
) -> xr.DataArray: | ||
"""Computes change in each CBOD group for a given timestep | ||
Args: | ||
CBOD_oxidation: CBOD concentration change due to oxidation (mg/L/d) | ||
CBOD_sedimentation: CBOD concentration change due to sedimentation (mg/L/d) | ||
""" | ||
return - CBOD_oxidation - CBOD_sedimentation | ||
|
||
|
||
@numba.njit | ||
def CBOD( | ||
CBOD: xr.DataArray, | ||
dCBODdt: xr.DataArray, | ||
timestep: xr.DataArray | ||
) -> xr.DataArray: | ||
"""Calculates new CBOD concentration for next timestep | ||
Args: | ||
CBOD: CBOD concentration from previous timestep (mg/L) | ||
dCBODdt: CBOD concentration change for current timestep (mg/L/d) | ||
timestep: current iteration timestep (d) | ||
""" | ||
return CBOD + dCBODdt * timestep |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
""" | ||
File contains static variables related to the CBOD module | ||
""" | ||
|
||
import clearwater_modules.base as base | ||
from clearwater_modules.nsm1.model import NutrientBudget | ||
|
||
|
||
@base.register_variable(models=NutrientBudget) | ||
class Variable(base.Variable): | ||
... | ||
|
||
|
||
Variable( | ||
name='kbod_20', | ||
long_name='CBOD oxidation rate at 20C', | ||
units='1/d', | ||
description='CBOD oxidation rate at 20C', | ||
use='static' | ||
) | ||
|
||
Variable( | ||
name='ksbod_20', | ||
long_name='CBOD sedimentation rate at 20C', | ||
units='m/d', | ||
description='CBOD sedimentation rate at 20C', | ||
use='static' | ||
) | ||
|
||
Variable( | ||
name='KsOxbod', | ||
long_name='Half saturation oxygen attenuation constant for CBOD oxidation', | ||
units='mg-O2/L', | ||
description='Half saturation oxygen attenuation constant for CBOD oxidation', | ||
use='static' | ||
) | ||
|
132 changes: 132 additions & 0 deletions
132
src/clearwater_modules/nsm1/old/DOX/dynamic_variables.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
# TODO: figure out imports | ||
|
||
import clearwater_modules.shared.processes as shared_processes | ||
from clearwater_modules import base | ||
from clearwater_modules.nsm1.model import NutrientBudget | ||
import clearwater_modules.nsm1.DOX.processes as processes | ||
|
||
|
||
@base.register_variable(models=NutrientBudget) | ||
class Variable(base.Variable): | ||
... | ||
|
||
|
||
Variable( | ||
name='DOX_sat', | ||
long_name='DO saturation concentration', | ||
units='mg/L', | ||
description='DO saturation concentration in water as a function of water temperature (K)', | ||
use='dynamic', | ||
process=processes.DOX_sat | ||
) | ||
|
||
Variable( | ||
name='pwv', | ||
long_name='Partial pressure of water vapor', | ||
units='atm', | ||
description='Partial pressure of water vapor', | ||
use='dynamic', | ||
process=processes.pwv | ||
) | ||
|
||
Variable( | ||
name='DOs_atm_alpha', | ||
long_name='DO saturation atmospheric correction coefficient', | ||
units='unitless', | ||
description='DO saturation atmospheric correction coefficient', | ||
use='dynamic', | ||
process=processes.DOs_atm_alpha | ||
) | ||
|
||
Variable( | ||
name='Atm_O2_reaeration', | ||
long_name='Atmospheric oxygen reaeration', | ||
units='mg/L/d', | ||
description='Atmospheric oxygen reaeration, can fluctuate both in and out of waterbody', | ||
use='dynamic', | ||
process=processes.Atm_O2_reaeration | ||
) | ||
|
||
# TODO: UPDATE BASED ON FORTRAN | ||
Variable( | ||
name='DOX_ApGrowth', | ||
long_name='Dissolved oxygen flux due to algal photosynthesis', | ||
units='mg/L/d', | ||
description='Dissolved oxygen flux due to algal photosynthesis', | ||
use='dynamics', | ||
process=processes.DOX_ApGrowth | ||
) | ||
|
||
# TODO: UPDATE BASED ON FORTRAN | ||
Variable( | ||
name='DOX_algal_respiration', | ||
long_name='Dissolved oxygen flux due to algal respiration', | ||
units='mg/L/d', | ||
description='Dissolved oxygen flux due to algal respiration', | ||
use='dynamic', | ||
process=processes.DOX_ApRespiration | ||
) | ||
|
||
Variable( | ||
name='DOX_Nitrification', | ||
long_name='Dissolved oxygen flux due to nitrification', | ||
units='mg/L/d', | ||
description='Dissolved oxygen flux due to nitrification', | ||
use='dynamic', | ||
process=processes.DOX_Nitrification | ||
) | ||
|
||
Variable( | ||
name='DOX_DOC_Oxidation', | ||
long_name='Dissolved oxygen flux due to DOC oxidation', | ||
units='mg/L/d', | ||
description='Dissolved oxygen flux due to DOC oxidation', | ||
use='dynamic', | ||
process=processes.DOX_DOC_Oxidation | ||
) | ||
|
||
Variable( | ||
name='DOX_CBOD_Oxidation', | ||
long_name='Dissolved oxygen flux due to CBOD oxidation', | ||
units='mg/L/d', | ||
description='Dissolved oxygen flux due to CBOD oxidation', | ||
use='dynamic', | ||
process=processes.DOX_CBOD_Oxidation | ||
) | ||
|
||
Variable( | ||
name='DOX_AbGrowth', | ||
long_name='Dissolved oxygen flux due to benthic algae photosynthesis', | ||
units='mg/L/d', | ||
description='Dissolved oxygen flux due to benthic algae photosynthesis', | ||
use='dynamics', | ||
process=processes.DOX_AbGrowth | ||
) | ||
|
||
Variable( | ||
name='DOX_AbRespiration', | ||
long_name='Dissolved oxygen flux due to benthic algae respiration', | ||
units='mg/L/d', | ||
description='Dissolved oxygen flux due to benthic algae respiration', | ||
use='dynamic', | ||
process=processes.DOX_AbRespiration | ||
) | ||
|
||
|
||
Variable( | ||
name='DOX_SOD', | ||
long_name='Dissolved oxygen flux due to sediment oxygen demand', | ||
units='mg/L/d', | ||
description='Dissolved oxygen flux due to sediment oxygen demand', | ||
use='dynamic', | ||
process=processes.DOX_SOD | ||
) | ||
|
||
Variable( | ||
name='dDOXdt', | ||
long_name='Change in dissolved oxygen concentration for one timestep', | ||
units='mg/L/d', | ||
description='Change in dissolved oxygen concentration for one timestep', | ||
use='dynamic', | ||
process=processes.dDOXdt | ||
) |
Oops, something went wrong.