Skip to content
Snippets Groups Projects
Commit c28c8726 authored by Sven Gundlach's avatar Sven Gundlach
Browse files

Merge branch 'Tim_bgc' into 'main'

Merge Tim_bgc into main

See merge request !9
parents ca9cf680 4f186cb8
No related branches found
No related tags found
1 merge request!9Merge Tim_bgc into main
Showing
with 1065 additions and 5 deletions
# src https://www.toptal.com/developers/gitignore/api/intellij
# src https://www.toptal.com/developers/gitignore/api/python
# src https://www.toptal.com/developers/gitignore/api/java,macos,maven,eclipse
# Project-specific generated files
docs/build/
......@@ -161,3 +162,14 @@ fabric.properties
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
### macOS ###
**/.DS_Store
**/.AppleDouble
**/.LSOverride
# Eclipse Gradle plugin generated files
# Eclipse Core
.project
# JDT-specific (Eclipse Java Development Tools)
.classpath
......@@ -26,6 +26,7 @@
"justMyCode": false,
"python": "${command:python.interpreterPath}",
"cwd": "${workspaceFolder}",
"preLaunchTask": "print workspaceFolder",
"env": {
"PYTHONPATH": "${workspaceFolder}:${workspaceFolder}/../antlrLib/"
}
......
"""SymbolTableVisitor module."""
"""This visitor collects variables and nodes in a SymbolTable."""
__author__ = 'sgu'
__author__ = 'stu90642'
# util imports
from typing import TypeVar, Generic, Dict, Optional, Callable, Any
......@@ -20,6 +20,8 @@ class SymbolTableVisitor( BgcDslVisitor, Generic[T] ):
def __init__(self, name: str = '', ):
super().__init__()
self._symbolTable = SymbolTable( name, SymbolTableOptions( False ) )
# TODO scope marker
# self._scope = self._symbolTable.addNewSymbolOfType( ScopedSymbol, None )
self._scope = None
@property
......@@ -29,6 +31,49 @@ class SymbolTableVisitor( BgcDslVisitor, Generic[T] ):
def defaultResult(self) -> SymbolTable:
return self._symbolTable
# 5 mal das gleiche; kann man das kürzer/eleganter schreiben?
def visitSubstanceDeclaration(self, ctx:BgcDslParser.SubstanceDeclarationContext):
# TODO
# save name, type
# save unit as node
self._symbolTable.addNewSymbolOfType( VariableSymbol, self._scope, ctx.name.text, ctx )
return self.visitChildren( ctx )
def visitParameterDeclaration(self, ctx:BgcDslParser.ParameterDeclarationContext):
# TODO
# save name, type
# save unit, expression as node
self._symbolTable.addNewSymbolOfType( VariableSymbol, self._scope, ctx.name.text, ctx )
return self.visitChildren( ctx )
def visitEnvironmentVariableDeclaration(self, ctx:BgcDslParser.EnvironmentVariableDeclarationContext):
# TODO
# save name, type
# save unit, expression as node
self._symbolTable.addNewSymbolOfType( VariableSymbol, self._scope, ctx.name.text, ctx )
return self.visitChildren( ctx )
# Visit a parse tree produced by BgcDslParser#compartment.
def visitCompartment(self, ctx:BgcDslParser.CompartmentContext):
# TODO
# save name
# save node as expression
self._symbolTable.addNewSymbolOfType( VariableSymbol, self._scope, ctx.name.text, ctx )
return self.visitChildren(ctx)
# Visit a parse tree produced by BgcDslParser#connection.
def visitConnection(self, ctx:BgcDslParser.ConnectionContext):
# TODO
# save name
# save node as expression
# the name needs to be more complex, here:
name = ctx.name.text + ' from ' + ctx.sourceCompartment.text + ' to ' + ctx.targetCompartment.text
self._symbolTable.addNewSymbolOfType( VariableSymbol, self._scope, name, ctx )
return self.visitChildren(ctx)
# def visitFuncExpr(self, ctx: TestGrammarParser.FuncExprContext):
# return self.withScope( ctx, RoutineSymbol, lambda: self.visitChildren( ctx ), ctx.ID().getText() )
def withScope(self, tree: ParseTree, t: type, action: Callable, *my_args: P.args or None,
**my_kwargs: P.kwargs or None) -> T:
scope = self._symbolTable.addNewSymbolOfType( t, self._scope, *my_args, **my_kwargs )
......
grammar BgcDsl;
import CommonLexerRules;
......
# Parses from a file (according to BgcDsl.g4)
# and saves its variables and nodes (context objects) in a SymbolTable.
import sys
from antlr4 import *
from BgcDslLexer import BgcDslLexer
from BgcDslParser import BgcDslParser
from My_SymbolTableVisitor import My_SymbolTableVisitor
from SymbolTable import ScopedSymbol, SymbolTable, P, T, VariableSymbol, Symbol, RoutineSymbol, SymbolTableOptions
def main(argv):
input_stream = FileStream('example2.bgc')
lexer = BgcDslLexer(input_stream)
stream = CommonTokenStream(lexer)
parser = BgcDslParser(stream) # returns object of class "Parser"
tree = parser.bgcModel() # tree ist ein ctx-objekt
symbolTable = My_SymbolTableVisitor('SymbolTableVisitor_1').visit(tree)
# shows the SymbolTable contents
for e in symbolTable.getAllSymbolsSync(Symbol):
print('#', e.name, '=', e.value)
main(sys.argv)
# altered, to react to bgc-file opening (not done, yet)
import asyncio
import json
import re
import time
import uuid
from json import JSONDecodeError
from typing import Optional
from antlr4 import InputStream, CommonTokenStream
from lsprotocol.types import (TEXT_DOCUMENT_COMPLETION, TEXT_DOCUMENT_DID_CHANGE,
TEXT_DOCUMENT_DID_CLOSE, TEXT_DOCUMENT_DID_OPEN,
TEXT_DOCUMENT_SEMANTIC_TOKENS_FULL)
from lsprotocol.types import (CompletionItem, CompletionList, CompletionOptions,
CompletionParams, ConfigurationItem,
Diagnostic,
DidChangeTextDocumentParams,
DidCloseTextDocumentParams,
DidOpenTextDocumentParams, MessageType, Position,
Range, Registration, RegistrationParams,
SemanticTokens, SemanticTokensLegend, SemanticTokensParams,
Unregistration, UnregistrationParams,
WorkDoneProgressBegin, WorkDoneProgressEnd,
WorkDoneProgressReport,
WorkspaceConfigurationParams)
from pygls.server import LanguageServer
COUNT_DOWN_START_IN_SECONDS = 10
COUNT_DOWN_SLEEP_IN_SECONDS = 1
class BgcDslLanguageServer(LanguageServer):
CMD_COUNT_DOWN_BLOCKING = 'countDownBlocking'
CMD_COUNT_DOWN_NON_BLOCKING = 'countDownNonBlocking'
CMD_PROGRESS = 'progress'
CMD_REGISTER_COMPLETIONS = 'registerCompletions'
CMD_SHOW_CONFIGURATION_ASYNC = 'showConfigurationAsync'
CMD_SHOW_CONFIGURATION_CALLBACK = 'showConfigurationCallback'
CMD_SHOW_CONFIGURATION_THREAD = 'showConfigurationThread'
CMD_UNREGISTER_COMPLETIONS = 'unregisterCompletions'
CONFIGURATION_SECTION = 'BgcDslServer'
def __init__(self, *args):
super().__init__(*args)
#######
def main():
print('###########test')
# a = BgcDslLanguageServer()
# _validate_bgc(a, params)
######
bgcDsl_server = BgcDslLanguageServer('pygls-BgcDsl-example', 'v0.1')
# ls steht für BgcDslLanguageServer (siehe main branch)
def _validate(ls, params):
ls.show_message_log('Validating bgc-file...')
text_doc = ls.workspace.get_document(params.text_document.uri)
source = text_doc.source
diagnostics = _validate_bgc(ls, source) if source else []
ls.publish_diagnostics(text_doc.uri, diagnostics)
# copied from example from main branch
def _validate_bgc(ls: BgcDslLanguageServer, source: str):
"""Validates file format."""
# get input stream of characters for lexer
input_stream: InputStream = InputStream( source )
# set the input stream and reset the lexer/parser/listener
ls.error_listener.reset()
ls.lexer.inputStream = input_stream
ls.tokenStream = CommonTokenStream( ls.lexer )
ls.parser.setInputStream( ls.tokenStream )
try:
# launch parser by invoking top-level rule
ls.parser.stat()
except OSError as err:
# TODO add exception
msg = err.filename.msg
ls.error_listener.diagnostics.append( msg )
# return diagnostics
return ls.error_listener.diagnostics
# def _validate_bgc(source):
# """Validates bgc-file."""
# diagnostics = []
# try:
# # hier muss noch an bgc angepasst werden, incl parser
# # alt: json.loads(source)
# # hinweis: ls.parser.stat()
# input_stream = InputStream(source) # old: FileStream('example2.bgc')
# lexer = BgcDslLexer(input_stream)
# stream = CommonTokenStream(lexer)
# parser = BgcDslParser(stream) # returns object of class "Parser"
# tree = parser.bgcModel() # tree ist ein ctx-objekt
# # symbolTable = My_SymbolTableVisitor('SymbolTableVisitor_1').visit(tree)
# # unnötig?
# except OSError as err:
# msg = err.msg
# col = err.colno
# line = err.lineno
# d = Diagnostic(
# range=Range(
# start=Position(line=line - 1, character=col - 1),
# end=Position(line=line - 1, character=col)
# ),
# message=msg,
# source=type(bgcDsl_server).__name__
# )
# diagnostics.append(d)
# return diagnostics
@bgcDsl_server.feature(TEXT_DOCUMENT_DID_CHANGE)
def did_change(ls, params: DidChangeTextDocumentParams):
"""Text document did change notification."""
_validate(ls, params)
@bgcDsl_server.feature(TEXT_DOCUMENT_DID_CLOSE)
def did_close(server: BgcDslLanguageServer, params: DidCloseTextDocumentParams):
"""Text document did close notification."""
server.show_message('Text Document Did Close')
@bgcDsl_server.feature(TEXT_DOCUMENT_DID_OPEN)
async def did_open(ls, params: DidOpenTextDocumentParams):
"""Text document did open notification."""
ls.show_message('Text Document Did Open')
_validate(ls, params)
main()
\ No newline at end of file
a = [1,2,3]
a = map(lambda x: x + 1, a)
b = list(a)
print(a)
print(b)
\ No newline at end of file
#
#
# # # an example to try PyTest
#
# import unittest
#
# #
# # def func(x):
# # return x + 1
# #
#
# class TestClass(unittest.TestCase): # wenn ich eine klasse verwende, dann muss ihr name mit "Test" beginnen.
#
# def test_1(self): # namen von test-funktionen müssen mit "test_" beginnen, oder auf "_test" enden.
# self.assertEqual(3, 11)
#
# # def test_answer(self):
# # assert func(3) == 5
from antlr4 import *
from BgcDslLexer import BgcDslLexer
from BgcDslParser import BgcDslParser
from My_SymbolTableVisitor import My_SymbolTableVisitor
from SymbolTable_copy import ScopedSymbol, SymbolTable, P, T, VariableSymbol, Symbol, RoutineSymbol, SymbolTableOptions
import unittest
# tests My_SymbolTableVisitor
def prepare():
input_stream = FileStream('example1_shortened.bgc')
lexer = BgcDslLexer(input_stream)
stream = CommonTokenStream(lexer)
parser = BgcDslParser(stream) # returns object of class "Parser"
tree = parser.bgcModel() # tree ist ein ctx-objekt
my_SymbolTableVisitor = My_SymbolTableVisitor('SymbolTableVisitor_1') # parse tree an My_SymbolTableVisitor übergeben
symbolTable = my_SymbolTableVisitor.visit(tree)
return symbolTable
# # tests SymbolTable
# def prepare():
# st1 = SymbolTable('SymbolTable_1', SymbolTableOptions( allowDuplicateSymbols = False ))
# st1.addNewSymbolOfType(VariableSymbol, None, 'A', 123)
# st1.addNewSymbolOfType(VariableSymbol, None, 'B', 111)
# return st1
class TestSTVisitor(unittest.TestCase): # wenn ich eine klasse verwende, dann muss ihr name mit "Test" beginnen.
def test_amount(self): # namen von test-funktionen müssen mit "test_" beginnen, oder auf "_test" enden.
symbolTable = prepare()
self.assertEqual(len(symbolTable.getAllSymbolsSync(Symbol)), 2)
# tests whether this variable is in the ST
def test_variable1(self):
symbolTable = prepare()
self.assertIsNotNone(symbolTable.resolveSync('N')) # resolveSync returns a VariableSymbol object
def test_variable2(self):
symbolTable = prepare()
self.assertIsNotNone(symbolTable.resolveSync('C')) # resolveSync returns a VariableSymbol object
# def test_variableC(self):
# symbolTable = prepare()
# self.assertIsNotNone(symbolTable.resolveSync('C'))
......@@ -61,7 +61,7 @@ function startLangServerTCP(addr: number): LanguageClient {
return new LanguageClient(
`tcp lang server (port ${addr})`,
serverOptions,
serverOptioMy_Sns,
getClientOptions()
);
}
......
// out-commented duplicate variables
model cnp_recom
substances
float N : mmol
float C : mmol
float P : mmol
float Chl : mmol
float DIN : mmol N m^-3
float DIP ::
float DIC ::
float _TA ::
parameters
float Q_r_C_N : mmol C (mmol N)^-1 = 5.5 //
float Q_r_N_P : mmol N (mmol P)^-1 = 16.0 //
float T_ref : K = 283.15
float sigma_N_C : (mmol N)^2 (mmol C)^-2 = 100.0
float sigma_P_N : (mmol P)^2 (mmol N)^-2 = 50.0
float g_max:: = 0.3
float T_f :: = 0
float epsilon :: = 0.78
float A_E :: = 0.75
float Omega :: = 0
float Q_1_N_C : mmol N (mmol C)^-1 = 0.043
float Q_2_N_C : mmol N (mmol C)^-1 = 0.171
float Q_1_P_N : mmol P (mmol N)^-1 = 0.02
float Q_2_P_N : mmol P (mmol N)^-1 = 0.2
float Q_u_N_C : mmol N (mmol C)^-1 = 0.171
float Q_u_P_N : mmol P (mmol N)^-1 = 0.014
float Zeta_DIN : mmol C (mmol N)^-1 = 2.3
float Zeta_N_2 : mmol C (mmol N)^-1 = 4.2
float Psi_max :: = 0.8
string criteria :: = option_a
diagnostics
float T_K : K = 0
float I : W m^-2
float q_C_P ::
float q_N_P ::
float q_C_N : mmol C (mmol N)^-1
float q_N_C : mmol N (mmol C)^-1
float q_P_N : mmol P (mmol N)^-1
compartment Phy {
states
Chl = 0
C = 0
N = 0
P = 0
parameters
float r_0 :: = 0.01
float Ar :: = 4000
float alpha : mmol C (mg Chl)^-1 m^2 W^-1 #d^-1 = 0.6
float my_max : #d^-1 = 2.6
float gamma_C : #d^-1 = 0.08
float gamma_Chl : #d^-1 = 0.01
float gamma : #d^-1 = 0.06
float Phi : m^3 (mmol N)^-1 #d^-1 = 0.02
float Theta_2_N : mg Chl (mmol N)^-1 = 2.4
diagnostics
float Theta_C : mg Chl (mmol C)^-1
float Theta_N : mg Chl (mmol N)^-1
calc Psi = max(0, Psi_max * ( 1 - q_N_C/Q_2_N_C))
calc R_P = 1 - Q_1_P_N / q_P_N
calc R_C = (1 + exp(-1 * sigma_N_C * (Q_2_N_C - q_N_C)))^-1
calc R_N = (1 + exp(-1 * sigma_P_N * (Q_2_P_N - q_P_N)))^-1
calc T_f = exp (-1*Ar * (T_K^-1 - T_K^-1))
calc phot_max = my_max * T_f * (q_N_C - Q_1_N_C)/(Q_2_N_C - Q_1_N_C)
calc phot_DIC = phot_max * (1 - exp( -1 * alpha * Theta_C * I / phot_max ))
calc assim_DIN = Q_u_N_C * my_max * T_f * R_P * R_C * Nutrients.DIN / (Nutrients.K_DIN + Nutrients.DIN)
calc assim_DIP = Q_u_P_N * my_max * T_f * R_N * Nutrients.DIP/(Nutrients.K_DIP + Nutrients.DIP)
calc degr_Chl = gamma_Chl
calc synth_Chl = assim_DIN * Theta_2_N * phot_DIC / (alpha * Theta_C * I)
update C = phot_DIC * C - (respiration + gamma_C + aggregation) * C - Phy>grazing * q_C_N
update N = assim_DIN * C - (r_0 * T_f + gamma + aggregation) * N - Phy>grazing
update P = assim_DIP * N - (r_0 * T_f + gamma + aggregation) * P - Phy>grazing * q_P_N
update Chl = synth_Chl * C - (degr_Chl + aggregation) * Chl - Phy>grazing * Theta_N
}
compartment N_2 {
states
N = 0
update N = 0
}
compartment Nutrients {
states
DIN = 0
DIP = 0
DIC = 0
_TA = 0
parameters
float K_DIP : mmol P m^-3 = 0
float K_DIN : mmol N m^-3 = 0
float rho_C :: = 0
float rho_N :: = 0
float rho_P :: = 0
update DIC = T_f * (rho_C * LDOM.C + MG.rho * MG.C)
+ respiration * Phy.C
+ respiration * Nif.C
+ (Het:respiration + epsilon * (1 - Omega) * Het:mortality) * Het.C
- Phy.phot_DIC * Phy.C - Nif.phot_DIC * Nif.C
update DIN = T_f * (rho_N * LDOM.N + MG.rho * MG.N)
+ Phy.r_0 * Phy.T_f * Phy.N
+ Nif.r_0 * Nif.T_f * Nif.N
+ epsilon * (Het:excretion.N + (1 - Omega) * Het:mortality) * Het.N
- Phy:assimilation - Nif.assim_DIN * Nif.C - denitrification
update DIP = T_f * rho_P * LDOM.P
+ Phy.r_0 * Phy.T_f * Phy.P
+ Nif.r_0 * Nif.T_f * Nif.P
+ epsilon * (Het:excretion.P + ( 1-Omega) * Het:mortality) * Het.P - Phy.assim_DIP * Phy.N - Nif.assim_DIP * Nif.N
update _TA = Phy.assim_DIN * Phy.C + Phy.assim_DIP * Phy.N
+ assimilation.C + assimilation.N
- Phy.r_0 * Phy.T_f * Phy.N - Nif.r_0 * Nif.T_f * Nif.N
- Phy.r_0 * Phy.T_f * Phy.P - Nif.r_0 * Nif.T_f * Nif.P
- epsilon * (Het:excretion.N + (1-Omega) * Het:mortality) * Het.N
- epsilon * (Het:excretion.P + (1-Omega) * Het:mortality) * Het.P
- T_f * (rho_N * LDOM.N - MG.rho * MG.N - rho_P * LDOM.P)
+ denitrification
}
compartment Het {
states
C = 0
N = 0
P = 0
parameters
float K_N : mmol N m^-3 = 1.0
//float r_0 : #d^-1 = 0.01 // duplicate variable
float tau : #d^-1 = 0.5
// float gamma : m^3 (mmol N)^-1 #d^-1 = 0.3 // dupl
update C = A_E * (Phy:grazing * q_C_N + Nif:grazing * q_C_N) - (respiration + mortality) * C
update N = A_E * (Phy:grazing + Nif:grazing) - (excretion.N + mortality) * N
update P = A_E * (Phy:grazing * q_P_N + Nif:grazing * q_P_N) - (excretion.P + mortality) * P
}
compartment Det {
states
C = 0
N = 0
P = 0
parameters
//float Phi : m^3 (mmol N)^-1 #d^-1 = 0.02
//float Omega :: = 0
calc omega_C = 0
calc omega_N = 0
calc omega_P = 0
// could add a sink
calc sedimentation_C = 0
calc sedimentation_N = 0
calc sedimentation_P = 0
update C = Phy:aggregation * Phy.C
+ aggregation * Nif.C
+ MG.Phi * N * MG.C
+ (1-A_E) * (Phy:grazing * q_C_N + Phy:grazing * q_C_N)
+ Omega * Het:mortality * Het.C - degradation.C - sedimentation_C
update N = Phy:aggregation * Phy.N
+ Nif:aggregation * Nif.N
+ MG.Phi * N * MG.N
+ (1-A_E) * (Phy:grazing + Nif:grazing) + Omega * Het:mortality * Het.N - degradation.N - sedimentation_N
update P = Phy:aggregation * Phy.P
+ Nif:aggregation * Nif.P
+ (1-A_E) * (Phy:grazing * q_P_N + Nif:grazing * q_P_N)
+ Omega * Het:mortality * Het.P - degradation.P - sedimentation_P
}
compartment dCCHO {
states C = 0
parameters
float Phi_TEPC :: = 0
//float Phi :: = 0
update C = Phy.Psi * Phy.gamma_C * Phy.C + Nif.Psi * Nif.gamma_C * Nif.C - coagulation * C
}
compartment MG {
states
C = 0
N = 0
parameters
//float Phi :: = 0
float rho :: = 0
float Xi :: = 0
update C = coagulation * dCCHO.C - aggregation * C
update N = Xi * C * LDOM.N - (rho * T_f + Phi * Det.N) * N
}
compartment LDOM {
states
C = 0
N = 0
P = 0
parameters
float omega_C :: = 0
float omega_N :: = 0
float omega_P :: = 0
//float Omega :: = 0
//float rho_C :: = 0
//float rho_N :: = 0
//float rho_P :: = 0
update C = degradation.C
+ (1 - Phy.Psi) * Phy.gamma_C * Phy.C
+ (1 - Nif.Psi) * Nif.gamma_C * Nif.C
+ (1-epsilon) * (1-Omega) * mortality * Het.C - rho_C * T_f * C
update N = degradation.N
+ Phy.gamma * Phy.N + Nif.gamma * Nif.N
+ (1-epsilon) * excretion.N * Het.N
+ (1-epsilon) * (1-Omega) * mortality * Het.N - (rho_N * T_f + MG.Xi * MG.C) * N
update P = degradation.P
- Phy.gamma * Phy.P + Nif.gamma * Nif.P
+ (1-epsilon) * (excretion.P + (1-Omega) * mortality) * Het.P - rho_P * T_f * P
}
compartment Nif {
states
Chl = 0
C = 0
N = 0
P = 0
parameters
//float Q_1_N_C : mmol N (mmol C)^-1 = 0.043
//float Q_2_N_C : mmol N (mmol C)^-1 = 0.171
//float Q_u_N_C : mmol N (mmol C)^-1 = 0.171
float Q_u2_N_C : mmol N (mmol C)^-1 = 0.09
//float Q_1_P_N : mmol P (mmol N)^-1 = 0.02
//float Q_2_P_N : mmol P (mmol N)^-1 = 0.2
//float Q_u_P_N : mmol P (mmol N)^-1 = 0.025
float theta_2_N : mg Chl (mmol N)^-1 = 1.2
//float alpha : mmol C (mg Chl)^-1 m^2 W^-1 #d^-1 = 0.6
// float r_0 : #d^-1 = 0.01 // duplicate variable
//float my_max : #d^-1 = 1.0 // d^-1
//float Ar :: = 1500 // -
//float gamma_C : #d^-1 = 0.08 // d^-1
//float gamma_Chl : #d^-1 = 0.01 // d^-1
//float gamma : #d^-1 = 0.06 // d^-1
//float Phi : m^3 (mmol N)^-1 #d^-1 = 0.002 // m^3 (mmol N)^-1 d^-1
diagnostics
float theta_C ::
float theta_N ::
calc Psi = max(0, Psi_max * (1 - q_N_C / Q_2_N_C))
calc phot_max = my_max * T_f * (q_N_C - Q_1_N_C)/(Q_2_N_C - Q_1_N_C)
calc phot_DIC = phot_max * (1 - exp ((-1*alpha * theta_C * I)/phot_max))
calc T_f = exp(-1 * Ar * (1/T_K - 1/T_ref))
calc gamma = 0
calc degr_Chl = 0
calc R_P = 1 - Q_1_P_N / q_P_N
calc R_C = (1 + exp(-1 * sigma_N_C * (Q_2_N_C - q_N_C)))^-1
calc R_N = (1 + exp(-1 *sigma_P_N * (Q_2_P_N - q_P_N)))^-1
calc assim_DIN = Q_u_N_C * (1 - f_N2) * my_max * T_f * R_P * R_C
calc assim_N_2 = Q_u2_N_C * f_N2 * my_max * T_f * R_P * R_C
calc assim_DIP = Q_u_P_N * my_max * T_f * R_N * Nutrients.DIP / (Nutrients.K_DIP + Nutrients.DIP)
calc f_N2 = 0
calc synth_Chl = (assim_DIN + assim_N_2) * theta_2_N * phot_DIC / (alpha * theta_C * I)
update C = phot_DIC * C - (respiration + gamma + aggregation) * C
update N = (assim_DIN + assim_N_2) * C - ( r_0 * T_f + gamma + aggregation) * N - Phy:grazing
update P = assim_DIP * N - (r_0 * T_f + gamma + aggregation) * P - Phy:grazing * q_P_N
update Chl = synth_Chl * C - (degr_Chl + aggregation) * Chl - Phy:grazing * theta_N
}
connection absorption from LDOM to MG = 0 // to MG
connection aggregation from Phy to Det = Phy.Phi * Phy.N + Det.Phi * Det.N
connection aggregation from MG to Det = (MG.rho * T_f + MG.Phi * Det.N) // to Det
connection aggregation from Nif to Det = Nif.Phi * Nif.N + Det.Phi * Det.N
connection assimilation from Nutrients to Phy = Phy.assim_DIN * Phy.C // to phy
connection assimilation(N,C) from Nutrients to Nif {
N = Nif.assim_DIP * Nif.N
C = Nif.assim_DIN * Nif.C
}
connection coagulation from dCCHO to MG = (dCCHO.Phi * dCCHO.C + dCCHO.Phi_TEPC * MG.C) // connection to MG
connection degradation(C,N,P) from Det to LDOM {
C = Det.omega_C * Det.C
N = Det.omega_N * Det.N
P = Det.omega_P * Det.P
}
connection denitrification from Nutrients to N_2 = 0
connection exudation from Phy to dCCHO = 0 // to dCCHO
connection exudation from Phy to LDOM = 0 // to LDOM
connection exudation from Nif to LDOM = 0 // to LDOM
connection excretion(N,P) from Het to LDOM {
N = Het.tau * (max(0, 1 - q_C_N/Q_r_C_N, 1 - Q_r_N_P/q_N_P))^2 // to LDOM
P = Het.tau * (max(0, 1 - q_C_P/(Q_r_C_N * Q_r_N_P), 1-q_N_P/Q_r_N_P)) // to LDOM
}
connection grazing from Phy to Het = g_max * Phy.T_f * Phy.N^2/(Het.K_N^2 + Nif.N^2+Nif.N^2) * Het.N
connection grazing from Nif to Het = g_max * T_f * (Nif.N^2 / (Het.K_N^2 + Phy.N^2 + Nif.N^2) * Het.N)
connection mortality from Het to Det = Het.gamma * Het.N // to Det
connection nitrification from N_2 to Nif = 0 // connection to Nif
connection remineralization from MG to Nutrients = 0 // to Nutrients
connection remineralization from LDOM to Nutrients = 0 // to Nutrients
connection respiration from Phy to Nutrients = Phy.r_0 * Phy.T_f + Zeta_DIN * Phy.assim_DIN
connection respiration from Het to Nutrients = T_f * Het.r_0
+ Het.tau * (max(0, 1 - Q_r_C_N/q_C_N, 1 - Q_r_C_N * Q_r_N_P / q_C_P))^2
connection respiration from Nif to Nutrients = Nif.r_0 * T_f + Zeta_DIN * Nif.assim_DIN + Zeta_N_2 * Nif.assim_N_2
File added
# Default ignored files
/shelf/
/workspace.xml
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/Tim_visitor.iml" filepath="$PROJECT_DIR$/.idea/Tim_visitor.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/../../.." vcs="Git" />
</component>
</project>
\ No newline at end of file
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": true
}
]
}
\ No newline at end of file
{
"python.defaultInterpreterPath": "./env/bin/python"
}
model cnp_recom
substances
float N : mmol
float C : mmol
float P : mmol
float Chl : mmol
float DIN : mmol N m^-3
float DIP ::
float DIC ::
float _TA ::
parameters
float Q_r_C_N : mmol C (mmol N)^-1 = 5.5 //
float Q_r_N_P : mmol N (mmol P)^-1 = 16.0 //
float T_ref : K = 283.15
float sigma_N_C : (mmol N)^2 (mmol C)^-2 = 100.0
float sigma_P_N : (mmol P)^2 (mmol N)^-2 = 50.0
float g_max:: = 0.3
float T_f :: = 0
float epsilon :: = 0.78
float A_E :: = 0.75
float Omega :: = 0
float Q_1_N_C : mmol N (mmol C)^-1 = 0.043
float Q_2_N_C : mmol N (mmol C)^-1 = 0.171
float Q_1_P_N : mmol P (mmol N)^-1 = 0.02
float Q_2_P_N : mmol P (mmol N)^-1 = 0.2
float Q_u_N_C : mmol N (mmol C)^-1 = 0.171
float Q_u_P_N : mmol P (mmol N)^-1 = 0.014
float Zeta_DIN : mmol C (mmol N)^-1 = 2.3
float Zeta_N_2 : mmol C (mmol N)^-1 = 4.2
float Psi_max :: = 0.8
string criteria :: = option_a
diagnostics
float T_K : K = 0
float I : W m^-2
float q_C_P ::
float q_N_P ::
float q_C_N : mmol C (mmol N)^-1
float q_N_C : mmol N (mmol C)^-1
float q_P_N : mmol P (mmol N)^-1
compartment Phy {
states
Chl = 0
C = 0
N = 0
P = 0
parameters
float r_0 :: = 0.01
float Ar :: = 4000
float alpha : mmol C (mg Chl)^-1 m^2 W^-1 #d^-1 = 0.6
float my_max : #d^-1 = 2.6
float gamma_C : #d^-1 = 0.08
float gamma_Chl : #d^-1 = 0.01
float gamma : #d^-1 = 0.06
float Phi : m^3 (mmol N)^-1 #d^-1 = 0.02
float Theta_2_N : mg Chl (mmol N)^-1 = 2.4
diagnostics
float Theta_C : mg Chl (mmol C)^-1
float Theta_N : mg Chl (mmol N)^-1
calc Psi = max(0, Psi_max * ( 1 - q_N_C/Q_2_N_C))
calc R_P = 1 - Q_1_P_N / q_P_N
calc R_C = (1 + exp(-1 * sigma_N_C * (Q_2_N_C - q_N_C)))^-1
calc R_N = (1 + exp(-1 * sigma_P_N * (Q_2_P_N - q_P_N)))^-1
calc T_f = exp (-1*Ar * (T_K^-1 - T_K^-1))
calc phot_max = my_max * T_f * (q_N_C - Q_1_N_C)/(Q_2_N_C - Q_1_N_C)
calc phot_DIC = phot_max * (1 - exp( -1 * alpha * Theta_C * I / phot_max ))
calc assim_DIN = Q_u_N_C * my_max * T_f * R_P * R_C * Nutrients.DIN / (Nutrients.K_DIN + Nutrients.DIN)
calc assim_DIP = Q_u_P_N * my_max * T_f * R_N * Nutrients.DIP/(Nutrients.K_DIP + Nutrients.DIP)
calc degr_Chl = gamma_Chl
calc synth_Chl = assim_DIN * Theta_2_N * phot_DIC / (alpha * Theta_C * I)
update C = phot_DIC * C - (respiration + gamma_C + aggregation) * C - Phy>grazing * q_C_N
update N = assim_DIN * C - (r_0 * T_f + gamma + aggregation) * N - Phy>grazing
update P = assim_DIP * N - (r_0 * T_f + gamma + aggregation) * P - Phy>grazing * q_P_N
update Chl = synth_Chl * C - (degr_Chl + aggregation) * Chl - Phy>grazing * Theta_N
}
compartment N_2 {
states
N = 0
update N = 0
}
compartment Nutrients {
states
DIN = 0
DIP = 0
DIC = 0
_TA = 0
parameters
float K_DIP : mmol P m^-3 = 0
float K_DIN : mmol N m^-3 = 0
float rho_C :: = 0
float rho_N :: = 0
float rho_P :: = 0
update DIC = T_f * (rho_C * LDOM.C + MG.rho * MG.C)
+ respiration * Phy.C
+ respiration * Nif.C
+ (Het:respiration + epsilon * (1 - Omega) * Het:mortality) * Het.C
- Phy.phot_DIC * Phy.C - Nif.phot_DIC * Nif.C
update DIN = T_f * (rho_N * LDOM.N + MG.rho * MG.N)
+ Phy.r_0 * Phy.T_f * Phy.N
+ Nif.r_0 * Nif.T_f * Nif.N
+ epsilon * (Het:excretion.N + (1 - Omega) * Het:mortality) * Het.N
- Phy:assimilation - Nif.assim_DIN * Nif.C - denitrification
update DIP = T_f * rho_P * LDOM.P
+ Phy.r_0 * Phy.T_f * Phy.P
+ Nif.r_0 * Nif.T_f * Nif.P
+ epsilon * (Het:excretion.P + ( 1-Omega) * Het:mortality) * Het.P - Phy.assim_DIP * Phy.N - Nif.assim_DIP * Nif.N
update _TA = Phy.assim_DIN * Phy.C + Phy.assim_DIP * Phy.N
+ assimilation.C + assimilation.N
- Phy.r_0 * Phy.T_f * Phy.N - Nif.r_0 * Nif.T_f * Nif.N
- Phy.r_0 * Phy.T_f * Phy.P - Nif.r_0 * Nif.T_f * Nif.P
- epsilon * (Het:excretion.N + (1-Omega) * Het:mortality) * Het.N
- epsilon * (Het:excretion.P + (1-Omega) * Het:mortality) * Het.P
- T_f * (rho_N * LDOM.N - MG.rho * MG.N - rho_P * LDOM.P)
+ denitrification
}
compartment Het {
states
C = 0
N = 0
P = 0
parameters
float K_N : mmol N m^-3 = 1.0
//float r_0 : #d^-1 = 0.01 // duplicate variable
float tau : #d^-1 = 0.5
// float gamma : m^3 (mmol N)^-1 #d^-1 = 0.3 // dupl
update C = A_E * (Phy:grazing * q_C_N + Nif:grazing * q_C_N) - (respiration + mortality) * C
update N = A_E * (Phy:grazing + Nif:grazing) - (excretion.N + mortality) * N
update P = A_E * (Phy:grazing * q_P_N + Nif:grazing * q_P_N) - (excretion.P + mortality) * P
}
compartment Det {
states
C = 0
N = 0
P = 0
parameters
//float Phi : m^3 (mmol N)^-1 #d^-1 = 0.02
//float Omega :: = 0
calc omega_C = 0
calc omega_N = 0
calc omega_P = 0
// could add a sink
calc sedimentation_C = 0
calc sedimentation_N = 0
calc sedimentation_P = 0
update C = Phy:aggregation * Phy.C
+ aggregation * Nif.C
+ MG.Phi * N * MG.C
+ (1-A_E) * (Phy:grazing * q_C_N + Phy:grazing * q_C_N)
+ Omega * Het:mortality * Het.C - degradation.C - sedimentation_C
update N = Phy:aggregation * Phy.N
+ Nif:aggregation * Nif.N
+ MG.Phi * N * MG.N
+ (1-A_E) * (Phy:grazing + Nif:grazing) + Omega * Het:mortality * Het.N - degradation.N - sedimentation_N
update P = Phy:aggregation * Phy.P
+ Nif:aggregation * Nif.P
+ (1-A_E) * (Phy:grazing * q_P_N + Nif:grazing * q_P_N)
+ Omega * Het:mortality * Het.P - degradation.P - sedimentation_P
}
compartment dCCHO {
states C = 0
parameters
float Phi_TEPC :: = 0
//float Phi :: = 0
update C = Phy.Psi * Phy.gamma_C * Phy.C + Nif.Psi * Nif.gamma_C * Nif.C - coagulation * C
}
compartment MG {
states
C = 0
N = 0
parameters
//float Phi :: = 0
float rho :: = 0
float Xi :: = 0
update C = coagulation * dCCHO.C - aggregation * C
update N = Xi * C * LDOM.N - (rho * T_f + Phi * Det.N) * N
}
compartment LDOM {
states
C = 0
N = 0
P = 0
parameters
float omega_C :: = 0
float omega_N :: = 0
float omega_P :: = 0
//float Omega :: = 0
//float rho_C :: = 0
//float rho_N :: = 0
//float rho_P :: = 0
update C = degradation.C
+ (1 - Phy.Psi) * Phy.gamma_C * Phy.C
+ (1 - Nif.Psi) * Nif.gamma_C * Nif.C
+ (1-epsilon) * (1-Omega) * mortality * Het.C - rho_C * T_f * C
update N = degradation.N
+ Phy.gamma * Phy.N + Nif.gamma * Nif.N
+ (1-epsilon) * excretion.N * Het.N
+ (1-epsilon) * (1-Omega) * mortality * Het.N - (rho_N * T_f + MG.Xi * MG.C) * N
update P = degradation.P
- Phy.gamma * Phy.P + Nif.gamma * Nif.P
+ (1-epsilon) * (excretion.P + (1-Omega) * mortality) * Het.P - rho_P * T_f * P
}
compartment Nif {
states
Chl = 0
C = 0
N = 0
P = 0
parameters
//float Q_1_N_C : mmol N (mmol C)^-1 = 0.043
//float Q_2_N_C : mmol N (mmol C)^-1 = 0.171
//float Q_u_N_C : mmol N (mmol C)^-1 = 0.171
float Q_u2_N_C : mmol N (mmol C)^-1 = 0.09
//float Q_1_P_N : mmol P (mmol N)^-1 = 0.02
//float Q_2_P_N : mmol P (mmol N)^-1 = 0.2
//float Q_u_P_N : mmol P (mmol N)^-1 = 0.025
float theta_2_N : mg Chl (mmol N)^-1 = 1.2
//float alpha : mmol C (mg Chl)^-1 m^2 W^-1 #d^-1 = 0.6
// float r_0 : #d^-1 = 0.01 // duplicate variable
//float my_max : #d^-1 = 1.0 // d^-1
//float Ar :: = 1500 // -
//float gamma_C : #d^-1 = 0.08 // d^-1
//float gamma_Chl : #d^-1 = 0.01 // d^-1
//float gamma : #d^-1 = 0.06 // d^-1
//float Phi : m^3 (mmol N)^-1 #d^-1 = 0.002 // m^3 (mmol N)^-1 d^-1
diagnostics
float theta_C ::
float theta_N ::
calc Psi = max(0, Psi_max * (1 - q_N_C / Q_2_N_C))
calc phot_max = my_max * T_f * (q_N_C - Q_1_N_C)/(Q_2_N_C - Q_1_N_C)
calc phot_DIC = phot_max * (1 - exp ((-1*alpha * theta_C * I)/phot_max))
calc T_f = exp(-1 * Ar * (1/T_K - 1/T_ref))
calc gamma = 0
calc degr_Chl = 0
calc R_P = 1 - Q_1_P_N / q_P_N
calc R_C = (1 + exp(-1 * sigma_N_C * (Q_2_N_C - q_N_C)))^-1
calc R_N = (1 + exp(-1 *sigma_P_N * (Q_2_P_N - q_P_N)))^-1
calc assim_DIN = Q_u_N_C * (1 - f_N2) * my_max * T_f * R_P * R_C
calc assim_N_2 = Q_u2_N_C * f_N2 * my_max * T_f * R_P * R_C
calc assim_DIP = Q_u_P_N * my_max * T_f * R_N * Nutrients.DIP / (Nutrients.K_DIP + Nutrients.DIP)
calc f_N2 = 0
calc synth_Chl = (assim_DIN + assim_N_2) * theta_2_N * phot_DIC / (alpha * theta_C * I)
update C = phot_DIC * C - (respiration + gamma + aggregation) * C
update N = (assim_DIN + assim_N_2) * C - ( r_0 * T_f + gamma + aggregation) * N - Phy:grazing
update P = assim_DIP * N - (r_0 * T_f + gamma + aggregation) * P - Phy:grazing * q_P_N
update Chl = synth_Chl * C - (degr_Chl + aggregation) * Chl - Phy:grazing * theta_N
}
connection absorption from LDOM to MG = 0 // to MG
connection aggregation from Phy to Det = Phy.Phi * Phy.N + Det.Phi * Det.N
connection aggregation from MG to Det = (MG.rho * T_f + MG.Phi * Det.N) // to Det
connection aggregation from Nif to Det = Nif.Phi * Nif.N + Det.Phi * Det.N
connection assimilation from Nutrients to Phy = Phy.assim_DIN * Phy.C // to phy
connection assimilation(N,C) from Nutrients to Nif {
N = Nif.assim_DIP * Nif.N
C = Nif.assim_DIN * Nif.C
}
connection coagulation from dCCHO to MG = (dCCHO.Phi * dCCHO.C + dCCHO.Phi_TEPC * MG.C) // connection to MG
connection degradation(C,N,P) from Det to LDOM {
C = Det.omega_C * Det.C
N = Det.omega_N * Det.N
P = Det.omega_P * Det.P
}
connection denitrification from Nutrients to N_2 = 0
connection exudation from Phy to dCCHO = 0 // to dCCHO
connection exudation from Phy to LDOM = 0 // to LDOM
connection exudation from Nif to LDOM = 0 // to LDOM
connection excretion(N,P) from Het to LDOM {
N = Het.tau * (max(0, 1 - q_C_N/Q_r_C_N, 1 - Q_r_N_P/q_N_P))^2 // to LDOM
P = Het.tau * (max(0, 1 - q_C_P/(Q_r_C_N * Q_r_N_P), 1-q_N_P/Q_r_N_P)) // to LDOM
}
connection grazing from Phy to Het = g_max * Phy.T_f * Phy.N^2/(Het.K_N^2 + Nif.N^2+Nif.N^2) * Het.N
connection grazing from Nif to Het = g_max * T_f * (Nif.N^2 / (Het.K_N^2 + Phy.N^2 + Nif.N^2) * Het.N)
connection mortality from Het to Det = Het.gamma * Het.N // to Det
connection nitrification from N_2 to Nif = 0 // connection to Nif
connection remineralization from MG to Nutrients = 0 // to Nutrients
connection remineralization from LDOM to Nutrients = 0 // to Nutrients
connection respiration from Phy to Nutrients = Phy.r_0 * Phy.T_f + Zeta_DIN * Phy.assim_DIN
connection respiration from Het to Nutrients = T_f * Het.r_0
+ Het.tau * (max(0, 1 - Q_r_C_N/q_C_N, 1 - Q_r_C_N * Q_r_N_P / q_C_P))^2
connection respiration from Nif to Nutrients = Nif.r_0 * T_f + Zeta_DIN * Nif.assim_DIN + Zeta_N_2 * Nif.assim_N_2
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment