Ken Webb 2010-06-06T18:47:48Z
This page describes the Java (BeanShell) version of the Carbon Bathtub Xholon model.
<CarbonBathtub implName="lang:beanshell:inline:"><![CDATA[
package org.primordion.user.app.Chameleon.CarbonBathtub;
import org.primordion.xholon.app.Application;
import org.primordion.xholon.base.IMessage;
import org.primordion.xholon.base.Xholon;
public class CarbonBathtub extends Xholon {
private boolean acting = false;
private int startYear = 2008;
private int endYear = 2070;
private int currentYear = 0;
public void act() {
if (acting) {
currentYear++;
if (currentYear == endYear) {
((Application)getApp()).invokeDataPlotter();
((Application)getApp()).setUseDataPlotter("none");
acting = false;
}
super.act();
}
}
private static final String start = "Start";
private String[] actions = {start};
public String[] getActionList() {
return actions;
}
public void setActionList(String[] actionList) {
actions = actionList;
}
public void doAction(String action) {
if (start.equals(action)) {
start();
}
}
public void processReceivedMessage(IMessage msg) {
doAction((String)msg.getData());
}
protected void start() {
if (!acting) {
if (currentYear == endYear) {
// this is a restart
getFirstChild().reconfigure();
}
currentYear = startYear;
getApp().setTimeStep(startYear);
generateDataPlotter();
acting = true;
}
}
protected void generateDataPlotter() {
Application app = (Application)getApp();
app.setUseDataPlotter("JFreeChart"); // or "google"
app.setDataPlotterParams("CO2 in the Atmosphere,Year,MTons CO2,./statistics/,stats,1,WRITE_AS_LONG");
app.createChart();
}
public boolean isActing() {
return acting;
}
public void setActing(boolean acting) {
this.acting = acting;
}
public int getStartYear() {
return startYear;
}
public void setStartYear(int startYear) {
this.startYear = startYear;
}
public int getEndYear() {
return endYear;
}
public void setEndYear(int endYear) {
this.endYear = endYear;
}
public int getCurrentYear() {
return currentYear;
}
public void setCurrentYear(int currentYear) {
this.currentYear = currentYear;
}
}
new CarbonBathtub();
]]></CarbonBathtub>
<_-.carbonbathtub>
<Atmosphere implName="lang:beanshell:inline:"><![CDATA[
import org.primordion.xholon.base.Xholon;
import org.primordion.xholon.base.IXholonClass;
public class Atmosphere extends Xholon
{
private static final double INITIAL_CARBON_MTONS = 820000000000.0;
private double carbonMTons = INITIAL_CARBON_MTONS; // 2008 average
public void reconfigure() {
carbonMTons = INITIAL_CARBON_MTONS;
super.reconfigure();
}
public double getVal() {
return carbonMTons;
}
public void setVal(Double val) {
this.carbonMTons = val;
}
public int getXhType() {
return IXholonClass.XhtypePurePassiveObject;
}
}
new Atmosphere();
]]></Atmosphere>
<InAllHumanMadeCo2 implName="lang:beanshell:inline:"><![CDATA[
import org.primordion.xholon.base.IXholon;
import org.primordion.xholon.base.Xholon;
public class InAllHumanMadeCo2 extends Xholon {
private static final double INITIAL_CARBON_PERYEAR = 9100000000.0;
private double carbonPerYear = INITIAL_CARBON_PERYEAR; // rate
private double rateChange = 1.02; // 1.01 is +1%, 1.00 is steady, 0.99 is -1%
private IXholon atmosphere = null;
public void reconfigure() {
carbonPerYear = INITIAL_CARBON_PERYEAR;
rateChange -= 0.01;
super.reconfigure();
}
public void act() {
if (atmosphere == null) {
atmosphere = getXPath().evaluate("../Atmosphere", this);
}
double newVal = atmosphere.getVal() + carbonPerYear;
carbonPerYear *= rateChange;
atmosphere.setVal(new Double(newVal));
super.act();
}
public IXholon getAtmosphere() {return atmosphere;}
public void setAtmosphere(IXholon atmosphere) {this.atmosphere = atmosphere;}
public double getRateChange() {return rateChange;}
public void setRateChange(double rateChange) {this.rateChange = rateChange;}
}
new InAllHumanMadeCo2();
]]></InAllHumanMadeCo2>
<OutAbsorbedByPlantsAndSoils implName="lang:beanshell:inline:"><![CDATA[
import org.primordion.xholon.base.IXholon;
import org.primordion.xholon.base.Xholon;
public class OutAbsorbedByPlantsAndSoils extends Xholon {
private double carbonPerYear = 9100000000.0 * 0.3;
private IXholon atmosphere = null;
public void act() {
if (atmosphere == null) {
atmosphere = getXPath().evaluate("../Atmosphere", this);
}
double newVal = atmosphere.getVal() - carbonPerYear;
atmosphere.setVal(new Double(newVal));
super.act();
}
public IXholon getAtmosphere() {return atmosphere;}
public void setAtmosphere(IXholon atmosphere) {this.atmosphere = atmosphere;}
}
new OutAbsorbedByPlantsAndSoils();
]]></OutAbsorbedByPlantsAndSoils>
<OutAbsorbedByOceans implName="lang:beanshell:inline:"><![CDATA[
import org.primordion.xholon.base.IXholon;
import org.primordion.xholon.base.Xholon;
public class OutAbsorbedByOceans extends Xholon {
private double carbonPerYear = 9100000000.0 * 0.25;
private IXholon atmosphere = null;
public void act() {
if (atmosphere == null) {
atmosphere = getXPath().evaluate("../Atmosphere", this);
}
double newVal = atmosphere.getVal() - carbonPerYear;
atmosphere.setVal(new Double(newVal));
super.act();
}
public IXholon getAtmosphere() {return atmosphere;}
public void setAtmosphere(IXholon atmosphere) {this.atmosphere = atmosphere;}
}
new OutAbsorbedByOceans();
]]></OutAbsorbedByOceans>
<OutAbsorbedBySedimentsAndRocks implName="lang:beanshell:inline:"><![CDATA[
import org.primordion.xholon.base.IXholon;
import org.primordion.xholon.base.Xholon;
public class OutAbsorbedBySedimentsAndRocks extends Xholon {
private double carbonPerYear = 9100000000.0 * 0.009;
private IXholon atmosphere = null;
public void act() {
if (atmosphere == null) {
atmosphere = getXPath().evaluate("../Atmosphere", this);
}
double newVal = atmosphere.getVal() - carbonPerYear;
atmosphere.setVal(new Double(newVal));
super.act();
}
public IXholon getAtmosphere() {return atmosphere;}
public void setAtmosphere(IXholon atmosphere) {this.atmosphere = atmosphere;}
}
new OutAbsorbedBySedimentsAndRocks();
]]></OutAbsorbedBySedimentsAndRocks>
</pre>
<pre>
</_-.carbonbathtub>