This is an old revision of the document!
Declare the feedback view in views.samm:
fbview trackEU compare trackEU.v trackEU.t “Tracking Energy Use“ 20 0.001
where the line contains the following parameters:
type of view (= fbview)
view name
model scope
.v file name
.t file name
description
default number of iterations
convergence tolerance
Here is an example of the .v and .t files for a simple feedback view that modifies a model input until the model output matches some given “golden” value in the last time slice.
viewName.v:
varToAdjust F modelCalculatedVal U goldenValToTrackOn U
viewname.t:
creview varToAdjust[dims][] view modelCalculatedVal[dims][] view goldenValToTrackOn[dims][] ! $fbViewIteration ! $fbViewMaxIters ! $fbViewTolerance if $background == false say ("This view requires a background.") quit (-1) endif ! make sure to manually crate this directory string $persistence = $home + "/V3/cal/views/persistence/viewName" local goldenToModelRatio[dims] = goldenValToTrackOn[dims][1] / modelCalculatedVal[dims][1] if $fbViewIteration == 1 say ("Iteration: 1") ! Make your adjustment for the first iteration -- in this case we will decrease the value by some percent ...this is just an example local percentDecrease_bck[dims] = create (; dimFrom1=varToAdjust[dims][1], dim=SEQ;time:1981:2006:1;year, data=1) local percentDecrease_scn[dims] = copyshape (percentDecrease_bck[dims]) percentDecrease_scn[dims] = table (;with=percentDecrease_bck[dims], title="..enter required percent decrease..") varToAdjust[dims][2] = percentDecrease_scn[dims] / 100 * -1 + 1 * varToAdjust[dims][1] export (percentDecrease_scn[dims]; format=tool, file=$persistence/percentDecreaseScnLI) export (goldenToModelRatio[dims]; format=tool, file=$persistence/goldenToModelRatio) quit (1) else say ("Iteration: ", $fbViewIteration) ! pull in the data from the first iteration (and or the last iteration depending on how you save the data) local goldenToModelRatioOrig[dims] = copyshape (goldenToModelRatio[dims]) goldenToModelRatioOrig[dims] = import (; format=tool, dataFile=$persistence/goldenToModelRatio) local goldenToModelRatioLI[dims] = goldenToModelRatio[dims] local percentDecreaseScnLI[dims] = create (; dimFrom1=varToAdjust[dims][1], dim=SEQ;time:1981:2006:1; year, data=10) percentDecreaseScnLI[dims] = import (; format=tool, dataFile=$persistence/percentDecreaseScnLI) ! Calculate the adjusted variable value local ratioDiff[dims] = percentDecreaseScnLI[dims] - goldenToModelRatioOrig[dims] local percentDecrease_scn[dims] = 1 - goldenToModelRatioOrig[dims * percentDecreaseScnLI[dims] / ratioDiff[dims] varToAdjust[dims][2] = percentDecrease_scn[dims] / 100 * -1 + 1 * varToAdjust[dims][1] export (percentDecrease_scn[dims]; format=tool, file=$persistence/percentDecreaseScnLI) !check tolerances for convergence !**NOTE** this one only checks for convergence in the last year! local tol[] = create(; data=$fbViewTolerance) local numNotConv[] = sum (boolgt (abs (extract (goldenToModelRatio[dims]; time:-0, shrink=on) - 1), tol[])) integer $numNotConv getobjinfo(numNotConv[], $numNotConv; info=dataElement) if ($numNotConv == 0) or ($fbViewIteration == $fbViewMaxIters) if ( mumble (" numNotConv = ", $numNotConv, " at iteration ",$fbViewIteration, " stopping due to ") if ($numNotConv == 0) say ("convergence") else say ("maximum iterations") endif quit(0) else say (" numNotConv = ", $numNotConv, " at iteration ",$fbViewIteration, " continuing") quit (1) endif endif