Ken Webb 2010-06-14T20:34:44Z
This page describes the Ruby (JRuby) version of the Carbon Bathtub Xholon model.
<CarbonBathtub implName="lang:jruby:inline:"><![CDATA[ require 'java' import org.primordion.xholon.app.Application import org.primordion.xholon.base.IMessage import org.primordion.xholon.base.Xholon class CarbonBathtub < Xholon def initialize() super() @acting = false @startYear = 2008 @endYear = 2070 @currentYear = 0 @actionList = ['Start'] end def act if @acting == true @currentYear += 1 if @currentYear.equal?(@endYear) getApp.invokeDataPlotter getApp.setUseDataPlotter('none') @acting = false end super end end def getActionList @actionList.to_java :String end def setActionList(actionList) @actionList = actionList end def doAction(action) if action == 'Start' start end end def processReceivedMessage(msg) doAction(msg.getData) end def start if @acting == false if @currentYear == @endYear # this is a restart getFirstChild.reconfigure end @currentYear = @startYear getApp.setTimeStep(@startYear) generateDataPlotter @acting = true end end def generateDataPlotter app = getApp app.setUseDataPlotter('JFreeChart') # or "google" app.setDataPlotterParams("CO2 in the Atmosphere,Year,MTons CO2,./statistics/,stats,1,WRITE_AS_LONG") app.createChart end def isActing @acting end def setActing(acting) @acting = acting end def getStartYear @startYear end def setStartYear(startYear) @startYear = startYear end def getEndYear @endYear end def setEndYear(endYear) @endYear = endYear end def getCurrentYear @currentYear end def setCurrentYear(currentYear) @currentYear = currentYear end end CarbonBathtub.new ]]></CarbonBathtub>
<_-.carbonbathtub>
<Atmosphere implName="lang:jruby:inline:"><![CDATA[ require 'java' import org.primordion.xholon.base.Xholon import org.primordion.xholon.base.IXholonClass class Atmosphere < Xholon def initialize super() #puts "initialize" @carbonMTons = 820000000000.0 #puts @carbonMTons end def reconfigure @carbonMTons = 820000000000.0 super end def getVal @carbonMTons end def setVal(val) @carbonMTons = val end def getXhType IXholonClass.XhtypePurePassiveObject end end Atmosphere.new ]]></Atmosphere>
<InAllHumanMadeCo2 implName="lang:jruby:inline:"><![CDATA[ require 'java' import org.primordion.xholon.base.IXholon import org.primordion.xholon.base.Xholon class InAllHumanMadeCo2 < Xholon def initialize super() @carbonPerYear = 9100000000.0 @rateChange = 1.02 # 1.01 is +1%, 1.00 is steady, 0.99 is -1% @atmosphere = nil end def reconfigure @carbonPerYear = 9100000000.0 @rateChange -= 0.01 super end def act if @atmosphere.equal?(nil) @atmosphere = getParentNode.getFirstChild end newVal = @atmosphere.getVal + @carbonPerYear @carbonPerYear *= @rateChange @atmosphere.setVal(newVal) super end def getAtmosphere @atmosphere end def setAtmosphere(atmosphere) @atmosphere = atmosphere end def getRateChange @rateChange end def setRateChange(rateChange) @rateChange = rateChange end end InAllHumanMadeCo2.new ]]></InAllHumanMadeCo2>
<OutAbsorbedByPlantsAndSoils implName="lang:jruby:inline:"><![CDATA[ require 'java' import org.primordion.xholon.base.IXholon import org.primordion.xholon.base.Xholon class OutAbsorbedByPlantsAndSoils < Xholon def initialize super() @carbonPerYear = 9100000000.0 * 0.3 @atmosphere = nil end def act if @atmosphere.equal?(nil) @atmosphere = getParentNode.getFirstChild end newVal = @atmosphere.getVal - @carbonPerYear @atmosphere.setVal(newVal) super end def getAtmosphere @atmosphere end def setAtmosphere(atmosphere) @atmosphere = atmosphere end end OutAbsorbedByPlantsAndSoils.new ]]></OutAbsorbedByPlantsAndSoils>
<OutAbsorbedByOceans implName="lang:jruby:inline:"><![CDATA[ require 'java' import org.primordion.xholon.base.IXholon import org.primordion.xholon.base.Xholon class OutAbsorbedByOceans < Xholon def initialize super() @carbonPerYear = 9100000000.0 * 0.25 @atmosphere = nil end def act if @atmosphere.equal?(nil) @atmosphere = getParentNode.getFirstChild end newVal = @atmosphere.getVal - @carbonPerYear @atmosphere.setVal(newVal) super end def getAtmosphere @atmosphere end def setAtmosphere(atmosphere) @atmosphere = atmosphere end end OutAbsorbedByOceans.new ]]></OutAbsorbedByOceans>
<OutAbsorbedBySedimentsAndRocks implName="lang:jruby:inline:"><![CDATA[ require 'java' import org.primordion.xholon.base.IXholon import org.primordion.xholon.base.Xholon class OutAbsorbedBySedimentsAndRocks < Xholon def initialize super() @carbonPerYear = 9100000000.0 * 0.009 @atmosphere = nil end def act if @atmosphere.equal?(nil) @atmosphere = getParentNode.getFirstChild end newVal = @atmosphere.getVal - @carbonPerYear @atmosphere.setVal(newVal) super end def getAtmosphere @atmosphere end def setAtmosphere(atmosphere) @atmosphere = atmosphere end end OutAbsorbedBySedimentsAndRocks.new ]]></OutAbsorbedBySedimentsAndRocks>
</_-.carbonbathtub>