Skip to content

Commit

Permalink
fixed names and types in get_value function, refs #19 #20
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroCamphuijsen committed Nov 7, 2019
1 parent a7c16fa commit 2a97c73
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 28 deletions.
51 changes: 28 additions & 23 deletions BMI/lib/marrmotBMI_oct.m
Original file line number Diff line number Diff line change
Expand Up @@ -127,19 +127,22 @@ function finalize()
case 'Ep'
output = obj.forcing.pet;
case 'S(t)'
output = obj.store_cur;
case 'mod'
output = obj.model_name;
output = [obj.store_cur];
case 'par'
output = obj.parameters;
case 'sol'
output = obj.solver;
case 'flux_out'
output = obj.output_externalFluxes;
case 'flux_in'
output = obj.output_internalFluxes;
output = [obj.parameters];
case 'sol_resnorm_tolerance'
output = [obj.solver.resnorm_tolerance];
case 'sol_resnorm_maxiter'
output = [obj.solver.resnorm_maxiter];
case 'flux_out_Q'
output = [obj.output_externalFluxes.Q];
case 'flux_out_Ea'
output = [obj.output_externalFluxes.Ea];
% TODO: this model has no internal fluxes, to be implemented for other models
% case 'flux_in_tmp'
% output = [obj.output_internalFluxes.tmp];
case 'wb'
output = obj.output_waterBalance;
output = [obj.output_waterBalance];
otherwise
error('unkown variable');
end
Expand All @@ -163,19 +166,21 @@ function set_value(obj,long_var_name, src)
case 'Ep'
obj.forcing.pet = src;
case 'S(t)'
obj.store_cur = src;
case 'mod'
obj.model_name = src;
obj.store_cur = src(1);
case 'par'
obj.parameters = src;
case 'sol'
obj.solver = src;
case 'flux_out'
obj.output_externalFluxes = src;
case 'flux_in'
obj.output_internalFluxes = src;
obj.parameters = src(1);
case 'sol_tolerance'
obj.solver.resnorm_tolerance = src(1);
case 'sol_maxiter'
obj.solver.resnorm_maxiter = src(1);
case 'Q'
obj.output_externalFluxes.Q = src(1);
case 'Ea'
obj.output_externalFluxes.Ea = src(1);
case 'tmp'
obj.output_internalFluxes.tmp = src(1);
case 'wb'
obj.output_waterBalance = src;
obj.output_waterBalance = src(1);
otherwise
error('unkown variable');
end
Expand Down Expand Up @@ -212,7 +217,7 @@ function set_value_at_indices(obj,long_var_name, inds, src)

% Model components
function output = get_component_name(obj)
output=['BMI implemented for MARRMoT models, currently running ',obj.model_name];
output=["MARRMoT ", obj.model_name, " ", obj.solver.name];
end

%% Time functions
Expand Down
13 changes: 8 additions & 5 deletions BMI/python/MARRMoTPythonBMI.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,15 @@ def get_time_step(self):

def get_value(self, varName):
commandString = 'model.get_value("' + varName + '")'
return octave.eval(commandString)

value = octave.eval(commandString)
if type(value) is np.ndarray:
return value
else:
return np.array([value])

def get_value_ptr(self, varName):
commandString = 'model.get_value_ptr("' + varName + '")'
return octave.eval(commandString)

raise NotImplementedError("Reference cannot be transmitted from Octave to Python")

def get_value_at_indices(self, varName, indices):
# temporary fix since get_value_at_indices doesn't work with indices input and MARRMoT do not have grids
if str(indices) != '[0, 0]':
Expand Down

0 comments on commit 2a97c73

Please sign in to comment.