Commit 0e531a7e authored by Jorn Bruggeman's avatar Jorn Bruggeman
Browse files

bulk -> interior in python driver

parent 5cc66fb1
......@@ -89,8 +89,8 @@ fabm.link_list_finalize.argtypes = [ctypes.c_void_p]
fabm.link_list_finalize.restype = None
# Routines for sending pointers to state and dependency data.
fabm.link_bulk_state_data.argtypes = [ctypes.c_int,ctypes.POINTER(ctypes.c_double)]
fabm.link_bulk_state_data.restype = None
fabm.link_interior_state_data.argtypes = [ctypes.c_int,ctypes.POINTER(ctypes.c_double)]
fabm.link_interior_state_data.restype = None
fabm.link_surface_state_data.argtypes = [ctypes.c_int,ctypes.POINTER(ctypes.c_double)]
fabm.link_surface_state_data.restype = None
fabm.link_bottom_state_data.argtypes = [ctypes.c_int,ctypes.POINTER(ctypes.c_double)]
......@@ -99,8 +99,8 @@ fabm.link_dependency_data.argtypes = [ctypes.c_int,ctypes.POINTER(ctypes.c_doubl
fabm.link_dependency_data.restype = None
# Read access to diagnostic data.
fabm.get_bulk_diagnostic_data.argtypes = [ctypes.c_int,ctypes.POINTER(ctypes.POINTER(ctypes.c_double))]
fabm.get_bulk_diagnostic_data.restype = None
fabm.get_interior_diagnostic_data.argtypes = [ctypes.c_int,ctypes.POINTER(ctypes.POINTER(ctypes.c_double))]
fabm.get_interior_diagnostic_data.restype = None
fabm.get_horizontal_diagnostic_data.argtypes = [ctypes.c_int,ctypes.POINTER(ctypes.POINTER(ctypes.c_double))]
fabm.get_horizontal_diagnostic_data.restype = None
......@@ -115,10 +115,10 @@ fabm.get_rates.restype = None
fabm.get_version.argtypes = (ctypes.c_int,ctypes.c_char_p)
fabm.get_version.restype = None
BULK_STATE_VARIABLE = 1
INTERIOR_STATE_VARIABLE = 1
SURFACE_STATE_VARIABLE = 2
BOTTOM_STATE_VARIABLE = 3
BULK_DIAGNOSTIC_VARIABLE = 4
INTERIOR_DIAGNOSTIC_VARIABLE = 4
HORIZONTAL_DIAGNOSTIC_VARIABLE = 5
CONSERVED_QUANTITY = 6
ATTRIBUTE_LENGTH = 256
......@@ -251,7 +251,7 @@ class DiagnosticVariable(Variable):
if horizontal:
fabm.get_horizontal_diagnostic_data(index+1,ctypes.byref(pdata))
else:
fabm.get_bulk_diagnostic_data(index+1,ctypes.byref(pdata))
fabm.get_interior_diagnostic_data(index+1,ctypes.byref(pdata))
self.data = pdata.contents
def getValue(self):
......@@ -377,27 +377,27 @@ class Model(object):
def updateConfiguration(self,settings=None):
# Get number of model variables per category
nstate_bulk = ctypes.c_int()
nstate_interior = ctypes.c_int()
nstate_surface = ctypes.c_int()
nstate_bottom = ctypes.c_int()
ndiag_bulk = ctypes.c_int()
ndiag_interior = ctypes.c_int()
ndiag_horizontal = ctypes.c_int()
nconserved = ctypes.c_int()
ndependencies = ctypes.c_int()
nparameters = ctypes.c_int()
ncouplings = ctypes.c_int()
fabm.get_counts(ctypes.byref(nstate_bulk),ctypes.byref(nstate_surface),ctypes.byref(nstate_bottom),
ctypes.byref(ndiag_bulk),ctypes.byref(ndiag_horizontal),
fabm.get_counts(ctypes.byref(nstate_interior),ctypes.byref(nstate_surface),ctypes.byref(nstate_bottom),
ctypes.byref(ndiag_interior),ctypes.byref(ndiag_horizontal),
ctypes.byref(nconserved),ctypes.byref(ndependencies),ctypes.byref(nparameters),ctypes.byref(ncouplings))
# Allocate memory for state variable values, and send ctypes.pointer to this memory to FABM.
self.state = numpy.empty((nstate_bulk.value+nstate_surface.value+nstate_bottom.value,),dtype=float)
for i in range(nstate_bulk.value):
fabm.link_bulk_state_data(i+1,self.state[i:].ctypes.data_as(ctypes.POINTER(ctypes.c_double)))
self.state = numpy.empty((nstate_interior.value+nstate_surface.value+nstate_bottom.value,),dtype=float)
for i in range(nstate_interior.value):
fabm.link_interior_state_data(i+1,self.state[i:].ctypes.data_as(ctypes.POINTER(ctypes.c_double)))
for i in range(nstate_surface.value):
fabm.link_surface_state_data(i+1,self.state[i+nstate_bulk.value:].ctypes.data_as(ctypes.POINTER(ctypes.c_double)))
fabm.link_surface_state_data(i+1,self.state[i+nstate_interior.value:].ctypes.data_as(ctypes.POINTER(ctypes.c_double)))
for i in range(nstate_bottom.value):
fabm.link_bottom_state_data(i+1,self.state[i+nstate_bulk.value+nstate_surface.value:].ctypes.data_as(ctypes.POINTER(ctypes.c_double)))
fabm.link_bottom_state_data(i+1,self.state[i+nstate_interior.value+nstate_surface.value:].ctypes.data_as(ctypes.POINTER(ctypes.c_double)))
# Retrieve variable metadata
strname = ctypes.create_string_buffer(ATTRIBUTE_LENGTH)
......@@ -414,17 +414,17 @@ class Model(object):
self.conserved_quantities = []
self.parameters = []
self.dependencies = []
for i in range(nstate_bulk.value):
ptr = fabm.get_variable(BULK_STATE_VARIABLE,i+1)
for i in range(nstate_interior.value):
ptr = fabm.get_variable(INTERIOR_STATE_VARIABLE,i+1)
self.interior_state_variables.append(StateVariable(ptr,self.state,i))
for i in range(nstate_surface.value):
ptr = fabm.get_variable(SURFACE_STATE_VARIABLE,i+1)
self.surface_state_variables.append(StateVariable(ptr,self.state,nstate_bulk.value+i))
self.surface_state_variables.append(StateVariable(ptr,self.state,nstate_interior.value+i))
for i in range(nstate_bottom.value):
ptr = fabm.get_variable(BOTTOM_STATE_VARIABLE,i+1)
self.bottom_state_variables.append(StateVariable(ptr,self.state,nstate_bulk.value+nstate_surface.value+i))
for i in range(ndiag_bulk.value):
ptr = fabm.get_variable(BULK_DIAGNOSTIC_VARIABLE,i+1)
self.bottom_state_variables.append(StateVariable(ptr,self.state,nstate_interior.value+nstate_surface.value+i))
for i in range(ndiag_interior.value):
ptr = fabm.get_variable(INTERIOR_DIAGNOSTIC_VARIABLE,i+1)
self.interior_diagnostic_variables.append(DiagnosticVariable(ptr,i,False))
for i in range(ndiag_horizontal.value):
ptr = fabm.get_variable(HORIZONTAL_DIAGNOSTIC_VARIABLE,i+1)
......@@ -448,8 +448,8 @@ class Model(object):
if settings is not None: self.restoreSettings(settings)
# For backward compatibility
self.bulk_state_variables = self.interior_state_variables
self.bulk_diagnostic_variables = self.interior_diagnostic_variables
self.INTERIOR_STATE_VARIABLEs = self.interior_state_variables
self.INTERIOR_DIAGNOSTIC_VARIABLEs = self.interior_diagnostic_variables
def getRates(self, surface=True, bottom=True):
"""Returns the local rate of change in state variables,
......
......@@ -29,10 +29,10 @@
! !PUBLIC MEMBER FUNCTIONS:
public
integer,parameter :: BULK_STATE_VARIABLE = 1
integer,parameter :: INTERIOR_STATE_VARIABLE = 1
integer,parameter :: SURFACE_STATE_VARIABLE = 2
integer,parameter :: BOTTOM_STATE_VARIABLE = 3
integer,parameter :: BULK_DIAGNOSTIC_VARIABLE = 4
integer,parameter :: INTERIOR_DIAGNOSTIC_VARIABLE = 4
integer,parameter :: HORIZONTAL_DIAGNOSTIC_VARIABLE = 5
integer,parameter :: CONSERVED_QUANTITY = 6
......@@ -198,16 +198,16 @@
end do
end function model_count
subroutine get_counts(nstate_bulk,nstate_surface,nstate_bottom,ndiagnostic_bulk,ndiagnostic_horizontal,nconserved, &
subroutine get_counts(nstate_interior,nstate_surface,nstate_bottom,ndiagnostic_interior,ndiagnostic_horizontal,nconserved, &
ndependencies,nparameters,ncouplings) bind(c)
!DIR$ ATTRIBUTES DLLEXPORT :: get_counts
integer(c_int),intent(out) :: nstate_bulk,nstate_surface,nstate_bottom
integer(c_int),intent(out) :: ndiagnostic_bulk,ndiagnostic_horizontal
integer(c_int),intent(out) :: nstate_interior,nstate_surface,nstate_bottom
integer(c_int),intent(out) :: ndiagnostic_interior,ndiagnostic_horizontal
integer(c_int),intent(out) :: nconserved,ndependencies,nparameters,ncouplings
nstate_bulk = size(model%state_variables)
nstate_interior = size(model%state_variables)
nstate_surface = size(model%surface_state_variables)
nstate_bottom = size(model%bottom_state_variables)
ndiagnostic_bulk = size(model%diagnostic_variables)
ndiagnostic_interior = size(model%diagnostic_variables)
ndiagnostic_horizontal = size(model%horizontal_diagnostic_variables)
nconserved = size(model%conserved_quantities)
ndependencies = size(environment_names)
......@@ -224,13 +224,13 @@
! Get a pointer to the target variable
select case (category)
case (BULK_STATE_VARIABLE)
case (INTERIOR_STATE_VARIABLE)
variable => model%state_variables(index)
case (SURFACE_STATE_VARIABLE)
variable => model%surface_state_variables(index)
case (BOTTOM_STATE_VARIABLE)
variable => model%bottom_state_variables(index)
case (BULK_DIAGNOSTIC_VARIABLE)
case (INTERIOR_DIAGNOSTIC_VARIABLE)
variable => model%diagnostic_variables(index)
case (HORIZONTAL_DIAGNOSTIC_VARIABLE)
variable => model%horizontal_diagnostic_variables(index)
......@@ -252,13 +252,13 @@
! Get a pointer to the target variable
select case (category)
case (BULK_STATE_VARIABLE)
case (INTERIOR_STATE_VARIABLE)
variable => model%state_variables(index)%target
case (SURFACE_STATE_VARIABLE)
variable => model%surface_state_variables(index)%target
case (BOTTOM_STATE_VARIABLE)
variable => model%bottom_state_variables(index)%target
case (BULK_DIAGNOSTIC_VARIABLE)
case (INTERIOR_DIAGNOSTIC_VARIABLE)
variable => model%diagnostic_variables(index)%target
case (HORIZONTAL_DIAGNOSTIC_VARIABLE)
variable => model%horizontal_diagnostic_variables(index)%target
......@@ -353,20 +353,20 @@
integer(c_int),intent(in),value :: index
real(c_double),intent(in),target :: value
call fabm_link_bulk_data(model,environment_names(index),value)
call fabm_link_interior_data(model,environment_names(index),value)
call fabm_link_horizontal_data(model,environment_names(index),value)
call fabm_link_scalar_data(model,environment_names(index),value)
if (index==index_column_depth) column_depth => value
end subroutine link_dependency_data
subroutine link_bulk_state_data(index,value) bind(c)
!DIR$ ATTRIBUTES DLLEXPORT :: link_bulk_state_data
subroutine link_interior_state_data(index,value) bind(c)
!DIR$ ATTRIBUTES DLLEXPORT :: link_interior_state_data
integer(c_int),intent(in), value :: index
real(c_double),intent(inout),target :: value
value = model%state_variables(index)%initial_value
call fabm_link_bulk_state_data(model,index,value)
end subroutine link_bulk_state_data
call fabm_link_interior_state_data(model,index,value)
end subroutine link_interior_state_data
subroutine link_surface_state_data(index,value) bind(c)
!DIR$ ATTRIBUTES DLLEXPORT :: link_surface_state_data
......@@ -419,12 +419,12 @@
!where (abs_conserved_rates>0.0_rk) conserved_rates = conserved_rates/abs_conserved_rates
end subroutine get_rates
subroutine get_bulk_diagnostic_data(index,ptr) bind(c)
!DIR$ ATTRIBUTES DLLEXPORT :: get_bulk_diagnostic_data
subroutine get_interior_diagnostic_data(index,ptr) bind(c)
!DIR$ ATTRIBUTES DLLEXPORT :: get_interior_diagnostic_data
integer(c_int),intent(in),value :: index
type(c_ptr), intent(out) :: ptr
ptr = c_loc(fabm_get_bulk_diagnostic_data(model,index))
end subroutine get_bulk_diagnostic_data
ptr = c_loc(fabm_get_interior_diagnostic_data(model,index))
end subroutine get_interior_diagnostic_data
subroutine get_horizontal_diagnostic_data(index,ptr) bind(c)
!DIR$ ATTRIBUTES DLLEXPORT :: get_horizontal_diagnostic_data
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment