diff --git a/.gitmodules b/.gitmodules index 0100d27af4..99536c4a77 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,7 +1,7 @@ [submodule "cvs/objects/climate/source/hector"] path = cvs/objects/climate/source/hector url = https://github.com/JGCRI/hector.git - branch = gcam-integration + branch = gcam-integrationv3 [submodule "output/modelinterface/modelinterface"] path = output/modelinterface/modelinterface url = https://github.com/JGCRI/modelinterface.git diff --git a/cvs/objects/build/linux/Makefile b/cvs/objects/build/linux/Makefile index 7fcb94c07e..e8da6c400b 100644 --- a/cvs/objects/build/linux/Makefile +++ b/cvs/objects/build/linux/Makefile @@ -77,6 +77,7 @@ varchk: clean : -$(RM) libgcam.a + -$(RM) libhector.a -$(RM) objs/*.o -$(MAKE) -C ../../containers/source clean -$(MAKE) -C ../../demographics/source clean diff --git a/cvs/objects/build/linux/configure.gcam b/cvs/objects/build/linux/configure.gcam index 3045c7f095..d10b827489 100644 --- a/cvs/objects/build/linux/configure.gcam +++ b/cvs/objects/build/linux/configure.gcam @@ -18,6 +18,16 @@ CXXBASEOPTS = $(CXXDEBUG) ARCH_FLAGS = ENVLIBS = +# only hector is using C++ 17 features and even then only to replace +# the need to link the Boost system and filesystem libraries +# however we can easily fall back to C++ 14 if needed (but then will need +# to link those Boost libraries) +ifeq ($(strip $(NO_CXX17)),) + CXXSTD = c++17 +else + CXXSTD = c++14 +endif + ## sets if we have Java which is required to GCAM output into a BaseX database ## should a user not be able to use Java they could concievably turn this off ## and set DEBUG_XML_DB in xml_db_outputter.ccp to just have the data written @@ -52,17 +62,22 @@ ifeq ($(USE_HECTOR),1) # hector Makefile is looking for slightly different names for BOOST # include and lib - BOOSTROOT=$(BOOST_INCLUDE) + BOOSTINC=$(BOOST_INCLUDE) BOOSTLIB=$(BOOST_LIB) - export BOOSTROOT BOOSTLIB + export BOOSTINC BOOSTLIB HECTOR_INCLUDE = -I../../climate/source/hector/headers - - ifeq ($(strip $(BOOST_LIB)),) - $(error Unable to detect Boost lib path, please set env variable BOOST_LIB) + # hector allows us to fall back to the C++ 14 standard if we do not have it + # however, we then need to link the Boost system and filesystem libraries + ifeq ($(strip $(NO_CXX17)),) + HECTOR_LIB = -lhector + else + ifeq ($(strip $(BOOST_LIB)),) + $(error Unable to detect Boost lib path, please set env variable BOOST_LIB) + endif + HECTOR_LIB = -L$(BOOST_LIB) -Wl,-rpath,$(BOOST_LIB) -lhector -lboost_system -lboost_filesystem endif - HECTOR_LIB = -L$(BOOST_LIB) -Wl,-rpath,$(BOOST_LIB) -lhector -lboost_system -lboost_filesystem endif # if(USE_HECTOR==1) # we may want to not use TBB in which case we have guard against empty -I or -L directives @@ -143,7 +158,7 @@ LIBDIR = -L/usr/local/lib -L$(BUILDPATH) $(JAVALIB) $(TBB_LIBRARY) ### The rest should be mostly compiler independent ## Note $(PROF) will be set as needed if we are building the gcam-prof target CPPFLAGS = $(INCLUDE) $(ARCH_FLAGS) $(JARSLIB) -DGCAM_PARALLEL_ENABLED=$(USE_GCAM_PARALLEL) -DUSE_HECTOR=$(USE_HECTOR) $(MKL_CFLAGS) -CXXFLAGS = $(CXXOPTIM) $(CXXBASEOPTS) $(PROF) -MMD -std=c++14 -Wno-deprecated +CXXFLAGS = $(CXXOPTIM) $(CXXBASEOPTS) $(PROF) -MMD -std=$(CXXSTD) -Wno-deprecated FCFLAGS = $(FCOPTIM) $(FCBASEOPTS) $(PROF) LD = $(CXX) $(PROF) LDFLAGS = $(CXXFLAGS) $(JAVA_RPATH) $(TBB_RPATH) $(MKL_LDFLAGS) diff --git a/cvs/objects/build/vc10/objects.vcxproj b/cvs/objects/build/vc10/objects.vcxproj index a04e58342a..ef7bcff13c 100644 --- a/cvs/objects/build/vc10/objects.vcxproj +++ b/cvs/objects/build/vc10/objects.vcxproj @@ -240,6 +240,7 @@ Level3 + stdcpp17 jvm.lib;%(AdditionalDependencies) @@ -381,6 +382,7 @@ Level3 ProgramDatabase false + stdcpp17 true diff --git a/cvs/objects/build/vc10/objects.vcxproj.filters b/cvs/objects/build/vc10/objects.vcxproj.filters index 12e66bfbc3..38bc67efec 100644 --- a/cvs/objects/build/vc10/objects.vcxproj.filters +++ b/cvs/objects/build/vc10/objects.vcxproj.filters @@ -1898,4 +1898,4 @@ Header Files\technologies - \ No newline at end of file + diff --git a/cvs/objects/build/xcode3/objects.xcodeproj/project.pbxproj b/cvs/objects/build/xcode3/objects.xcodeproj/project.pbxproj index eca095de54..a254cfa85a 100644 --- a/cvs/objects/build/xcode3/objects.xcodeproj/project.pbxproj +++ b/cvs/objects/build/xcode3/objects.xcodeproj/project.pbxproj @@ -35,6 +35,7 @@ CD1775072784866C00F8360F /* market_matches_solution_info_filter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD1775062784866C00F8360F /* market_matches_solution_info_filter.cpp */; }; CD177C3B159A0C5B000A996F /* cumulative_emissions_target.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD177C3A159A0C5B000A996F /* cumulative_emissions_target.cpp */; }; CD2420022162D2310071DB2B /* initialize_tech_vector_helper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD2420012162D2310071DB2B /* initialize_tech_vector_helper.cpp */; }; + CD3379E129CB9838005DD5D9 /* libhector-lib.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CD3379E029CB9838005DD5D9 /* libhector-lib.a */; }; CD3B52C61BFE0E2800179FDD /* hector_model.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD3B52C51BFE0E2800179FDD /* hector_model.cpp */; }; CD3CFCD8238DA5B800016CDB /* food_demand_input.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD3CFCD7238DA5B800016CDB /* food_demand_input.cpp */; }; CD3CFCDB238DC24100016CDB /* food_demand_function.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD3CFCDA238DC24100016CDB /* food_demand_function.cpp */; }; @@ -235,7 +236,6 @@ CD8DFFD91FA8D1F000CB3719 /* ctax_input.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD8DFFD81FA8D1F000CB3719 /* ctax_input.cpp */; }; CD8FDEC91C0647140099C752 /* pass_through_sector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD8FDEC81C0647140099C752 /* pass_through_sector.cpp */; }; CD8FDECC1C0647A20099C752 /* pass_through_technology.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD8FDECB1C0647A20099C752 /* pass_through_technology.cpp */; }; - CD966E751D92F1CD00A93938 /* libhector-lib.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CD966E721D92F1BB00A93938 /* libhector-lib.a */; }; CDA0C40D25A7B26200E84153 /* calc_base_price.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDA0C40C25A7B26200E84153 /* calc_base_price.cpp */; }; CDA481A525E6FC3E0046E143 /* fdjac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDA481A425E6FC3E0046E143 /* fdjac.cpp */; }; CDAACD88216C546D00D13FD6 /* supply_demand_curve_saver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDAACD87216C546D00D13FD6 /* supply_demand_curve_saver.cpp */; }; @@ -273,41 +273,36 @@ /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ - CD966E6D1D92F1BB00A93938 /* PBXContainerItemProxy */ = { + CD3379DF29CB9838005DD5D9 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = CD966E671D92F1BB00A93938 /* hector.xcodeproj */; proxyType = 2; - remoteGlobalIDString = 8DD76F6C0486A84900D96B5E; - remoteInfo = hector; + remoteGlobalIDString = CDD51F4529CB9695001E23D6; + remoteInfo = "hector-lib"; }; - CD966E711D92F1BB00A93938 /* PBXContainerItemProxy */ = { + CD605E442886FFBA0093079B /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = CD966E671D92F1BB00A93938 /* hector.xcodeproj */; proxyType = 2; - remoteGlobalIDString = CD97CE321BFBBF2E005689AD; - remoteInfo = "hector-lib"; + remoteGlobalIDString = 27A02A882615CBB800AF9BFA; + remoteInfo = "hector-tests"; }; - CD966E731D92F1C500A93938 /* PBXContainerItemProxy */ = { + CD966E6D1D92F1BB00A93938 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = CD966E671D92F1BB00A93938 /* hector.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = 8DD76F6C0486A84900D96B5E; + remoteInfo = hector; + }; + CDD448CD2A08F2390083FA1F /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = CD966E671D92F1BB00A93938 /* hector.xcodeproj */; proxyType = 1; - remoteGlobalIDString = CD97CE311BFBBF2E005689AD; + remoteGlobalIDString = CDD51F4429CB9695001E23D6; remoteInfo = "hector-lib"; }; /* End PBXContainerItemProxy section */ -/* Begin PBXCopyFilesBuildPhase section */ - 8DD76F690486A84900D96B5E /* CopyFiles */ = { - isa = PBXCopyFilesBuildPhase; - buildActionMask = 8; - dstPath = /usr/share/man/man1/; - dstSubfolderSpec = 0; - files = ( - ); - runOnlyForDeploymentPostprocessing = 1; - }; -/* End PBXCopyFilesBuildPhase section */ - /* Begin PBXFileReference section */ 0E052F511CB6C39600AFDDAC /* gcam_data_containers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = gcam_data_containers.h; sourceTree = ""; }; 0E05C9001E435B3600C73D94 /* gcam_fusion.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = gcam_fusion.cpp; sourceTree = ""; }; @@ -910,7 +905,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - CD966E751D92F1CD00A93938 /* libhector-lib.a in Frameworks */, + CD3379E129CB9838005DD5D9 /* libhector-lib.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -923,6 +918,7 @@ CD966E671D92F1BB00A93938 /* hector.xcodeproj */, CD488409122873C000F5A88A /* objects */, CD299E9711B9C11800E6D196 /* Products */, + CD3379DB29CB9838005DD5D9 /* Frameworks */, ); name = objects; sourceTree = ""; @@ -935,6 +931,13 @@ name = Products; sourceTree = ""; }; + CD3379DB29CB9838005DD5D9 /* Frameworks */ = { + isa = PBXGroup; + children = ( + ); + name = Frameworks; + sourceTree = ""; + }; CD488409122873C000F5A88A /* objects */ = { isa = PBXGroup; children = ( @@ -2067,7 +2070,8 @@ isa = PBXGroup; children = ( CD966E6E1D92F1BB00A93938 /* hector */, - CD966E721D92F1BB00A93938 /* libhector-lib.a */, + CD605E452886FFBA0093079B /* hector-tests */, + CD3379E029CB9838005DD5D9 /* libhector-lib.a */, ); name = Products; sourceTree = ""; @@ -2113,12 +2117,11 @@ buildPhases = ( 8DD76F640486A84900D96B5E /* Sources */, 8DD76F660486A84900D96B5E /* Frameworks */, - 8DD76F690486A84900D96B5E /* CopyFiles */, ); buildRules = ( ); dependencies = ( - CD966E741D92F1C500A93938 /* PBXTargetDependency */, + CDD448CE2A08F2390083FA1F /* PBXTargetDependency */, ); name = objects; productInstallPath = "$(HOME)/bin"; @@ -2161,18 +2164,25 @@ /* End PBXProject section */ /* Begin PBXReferenceProxy section */ - CD966E6E1D92F1BB00A93938 /* hector */ = { + CD3379E029CB9838005DD5D9 /* libhector-lib.a */ = { + isa = PBXReferenceProxy; + fileType = archive.ar; + path = "libhector-lib.a"; + remoteRef = CD3379DF29CB9838005DD5D9 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + CD605E452886FFBA0093079B /* hector-tests */ = { isa = PBXReferenceProxy; fileType = "compiled.mach-o.executable"; - path = hector; - remoteRef = CD966E6D1D92F1BB00A93938 /* PBXContainerItemProxy */; + path = "hector-tests"; + remoteRef = CD605E442886FFBA0093079B /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; - CD966E721D92F1BB00A93938 /* libhector-lib.a */ = { + CD966E6E1D92F1BB00A93938 /* hector */ = { isa = PBXReferenceProxy; - fileType = archive.ar; - path = "libhector-lib.a"; - remoteRef = CD966E711D92F1BB00A93938 /* PBXContainerItemProxy */; + fileType = "compiled.mach-o.executable"; + path = hector; + remoteRef = CD966E6D1D92F1BB00A93938 /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXReferenceProxy section */ @@ -2450,10 +2460,10 @@ /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ - CD966E741D92F1C500A93938 /* PBXTargetDependency */ = { + CDD448CE2A08F2390083FA1F /* PBXTargetDependency */ = { isa = PBXTargetDependency; name = "hector-lib"; - targetProxy = CD966E731D92F1C500A93938 /* PBXContainerItemProxy */; + targetProxy = CDD448CD2A08F2390083FA1F /* PBXContainerItemProxy */; }; /* End PBXTargetDependency section */ @@ -2462,15 +2472,14 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "c++14"; CLANG_CXX_LIBRARY = "libc++"; COPY_PHASE_STRIP = NO; GCC_DYNAMIC_NO_PIC = NO; GCC_ENABLE_FIX_AND_CONTINUE = YES; GCC_MODEL_TUNING = G5; GCC_OPTIMIZATION_LEVEL = 0; - INSTALL_PATH = /usr/local/bin; - MACOSX_DEPLOYMENT_TARGET = 10.15; + INSTALL_PATH = ./; + MACOSX_DEPLOYMENT_TARGET = 12.4; PRODUCT_NAME = gcam; }; name = Debug; @@ -2479,12 +2488,11 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "c++14"; CLANG_CXX_LIBRARY = "libc++"; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; GCC_MODEL_TUNING = G5; - INSTALL_PATH = /usr/local/bin; - MACOSX_DEPLOYMENT_TARGET = 10.15; + INSTALL_PATH = ./; + MACOSX_DEPLOYMENT_TARGET = 12.4; PRODUCT_NAME = gcam; }; name = Release; @@ -2492,6 +2500,9 @@ 1DEB923608733DC60010E9CD /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_CXX_LANGUAGE_STANDARD = "c++17"; + DEPLOYMENT_LOCATION = YES; + DSTROOT = ../../../../exe; ENABLE_TESTABILITY = YES; GCC_AUTO_VECTORIZATION = NO; GCC_C_LANGUAGE_STANDARD = gnu99; @@ -2513,21 +2524,18 @@ ../../../../libs/java/include/darwin, ../../../../libs/tbb/include, ); - LD_RUNPATH_SEARCH_PATHS = "../libs/java/lib ../libs/boost-lib/stage/lib ../libs ../libs/tbb/lib"; + INSTALL_PATH = ""; + LD_RUNPATH_SEARCH_PATHS = "../libs/java/lib ../libs ../libs/tbb/lib"; LIBRARY_SEARCH_PATHS = ( ../../../../libs/java/lib, - "../../../../libs/boost-lib/stage/lib", ../../../../libs/tbb/lib, ); + MACOSX_DEPLOYMENT_TARGET = 12.4; ONLY_ACTIVE_ARCH = YES; - OTHER_LDFLAGS = ( - "-ljvm", - "-lboost_system", - "-lboost_filesystem", - ); + OTHER_LDFLAGS = "-ljvm"; PREBINDING = NO; SDKROOT = ""; - SYMROOT = ../../../../exe; + SYMROOT = ../../../../exe/build; USER_HEADER_SEARCH_PATHS = "../.. ../../climate/source/hector/headers"; }; name = Debug; @@ -2535,6 +2543,9 @@ 1DEB923708733DC60010E9CD /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_CXX_LANGUAGE_STANDARD = "c++17"; + DEPLOYMENT_LOCATION = YES; + DSTROOT = ../../../../exe; GCC_AUTO_VECTORIZATION = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_ENABLE_SSE3_EXTENSIONS = YES; @@ -2559,24 +2570,23 @@ ../../../../libs/eigen, ../../../../libs/tbb/include, ); - LD_RUNPATH_SEARCH_PATHS = "../libs/java/lib ../libs/boost-lib/stage/lib ../libs ../libs/tbb/lib"; + INSTALL_PATH = ""; + LD_RUNPATH_SEARCH_PATHS = "../libs/java/lib ../libs ../libs/tbb/lib"; LIBRARY_SEARCH_PATHS = ( ../../../../libs/java/lib, - "../../../../libs/boost-lib/stage/lib", ../../../../libs/tbb/lib, ); + MACOSX_DEPLOYMENT_TARGET = 12.4; ONLY_ACTIVE_ARCH = YES; OTHER_LDFLAGS = ( "-ljvm", - "-lboost_system", - "-lboost_filesystem", "-ltbb", "-ltbbmalloc", "-ltbbmalloc_proxy", ); PREBINDING = NO; SDKROOT = ""; - SYMROOT = ../../../../exe; + SYMROOT = ../../../../exe/build; USER_HEADER_SEARCH_PATHS = "../.. ../../climate/source/hector/headers"; }; name = Release; diff --git a/cvs/objects/ccarbon_model/include/asimple_carbon_calc.h b/cvs/objects/ccarbon_model/include/asimple_carbon_calc.h index 14ba2682b7..114822ac51 100644 --- a/cvs/objects/ccarbon_model/include/asimple_carbon_calc.h +++ b/cvs/objects/ccarbon_model/include/asimple_carbon_calc.h @@ -81,6 +81,8 @@ class ASimpleCarbonCalc : public ICarbonCalc { virtual double getNetLandUseChangeEmissionAbove( const int aYear ) const; virtual double getNetLandUseChangeEmissionBelow( const int aYear ) const; + + virtual double getGrossPositiveLandUseChangeEmissionAbove( const int aYear ) const; virtual double getActualAboveGroundCarbonDensity( const int aYear ) const = 0; @@ -124,6 +126,10 @@ class ASimpleCarbonCalc : public ICarbonCalc { //! Above ground carbon stock DEFINE_VARIABLE( ARRAY | STATE | NOT_PARSABLE, "above-ground-carbon-stock", mCarbonStock, objects::YearVector ), + //! Track gross positive above ground emissions explicitly so we can partition the net emissions to gross + //! to report to the climate model + DEFINE_VARIABLE( ARRAY | NOT_PARSABLE, "gross-positive-above-ground-land-use-change-emissions", mPositiveEmissionsAbove, objects::YearVector ), + //! Time scale for soil carbon emissions DEFINE_VARIABLE( SIMPLE, "soil-time-scale", mSoilTimeScale, int ), @@ -173,11 +179,32 @@ class ASimpleCarbonCalc : public ICarbonCalc { //! expensive operations during calc. precalc_sigmoid_type precalc_sigmoid_diff; + + // Some boiler plate to be able to take advantage of boost::flyweight to share + // the precalc exp soil curve between instances that have the same soil timescale + struct precalc_expsoil_helper { + precalc_expsoil_helper( const int aSoilTimeScale ); + std::vector mData; + + const double& operator[]( const size_t aPos ) const { + return mData[ aPos ]; + } + }; + using precalc_expsoil_type = boost::flyweights::flyweight< + boost::flyweights::key_value, + boost::flyweights::no_tracking>; + + //! The difference in the exp soil curve by year offset + 1 - year offset. + //! This value get precomputed during initcalc to avoid doing the computationally + //! expensive operations during calc. + precalc_expsoil_type precalc_expsoil_diff; + //! Flag to ensure historical emissions are only calculated a single time //! since they can not be reset. bool mHasCalculatedHistoricEmiss; - void calcAboveGroundCarbonEmission(const double aPrevCarbonStock, + void calcAboveGroundCarbonEmission(const CarbonCalcMode aCalcMode, + const double aPrevCarbonStock, const double aPrevLandArea, const double aCurrLandArea, const double aPrevCarbonDensity, diff --git a/cvs/objects/ccarbon_model/include/icarbon_calc.h b/cvs/objects/ccarbon_model/include/icarbon_calc.h index 5a7f5513c8..729c11a5ec 100644 --- a/cvs/objects/ccarbon_model/include/icarbon_calc.h +++ b/cvs/objects/ccarbon_model/include/icarbon_calc.h @@ -188,6 +188,8 @@ class ICarbonCalc: public IVisitable, virtual double getNetLandUseChangeEmissionAbove( const int aYear ) const = 0; virtual double getNetLandUseChangeEmissionBelow( const int aYear ) const = 0; + + virtual double getGrossPositiveLandUseChangeEmissionAbove( const int aYear ) const = 0; virtual double getActualAboveGroundCarbonDensity( const int aYear ) const = 0; diff --git a/cvs/objects/ccarbon_model/source/asimple_carbon_calc.cpp b/cvs/objects/ccarbon_model/source/asimple_carbon_calc.cpp index 022ec50db2..b4f6540cfb 100644 --- a/cvs/objects/ccarbon_model/source/asimple_carbon_calc.cpp +++ b/cvs/objects/ccarbon_model/source/asimple_carbon_calc.cpp @@ -57,6 +57,7 @@ extern Scenario* scenario; ASimpleCarbonCalc::ASimpleCarbonCalc(): mTotalEmissionsAbove( CarbonModelUtils::getStartYear(), CarbonModelUtils::getEndYear() ), mTotalEmissionsBelow( CarbonModelUtils::getStartYear(), CarbonModelUtils::getEndYear() ), +mPositiveEmissionsAbove( CarbonModelUtils::getStartYear(), CarbonModelUtils::getEndYear() ), mCarbonStock( scenario->getModeltime()->getStartYear(), CarbonModelUtils::getEndYear() ) { int endYear = CarbonModelUtils::getEndYear(); @@ -64,7 +65,7 @@ mCarbonStock( scenario->getModeltime()->getStartYear(), CarbonModelUtils::getEnd mLandUseHistory = 0; mLandLeaf = 0; - mSoilTimeScale = CarbonModelUtils::getSoilTimeScale(); + setSoilTimeScale( CarbonModelUtils::getSoilTimeScale() ); mHasCalculatedHistoricEmiss = false; } @@ -106,7 +107,7 @@ double ASimpleCarbonCalc::calc( const int aPeriod, const int aEndYear, const Car for( int year = CarbonModelUtils::getStartYear(); year <= mLandUseHistory->getMaxYear(); ++year ) { double currLand = mLandUseHistory->getAllocation( year ); double landDifference = prevLand - currLand; - calcAboveGroundCarbonEmission( currCarbonStock, prevLand, currLand, aboveGroundCarbonDensity, year, aEndYear, mTotalEmissionsAbove ); + calcAboveGroundCarbonEmission( aCalcMode, currCarbonStock, prevLand, currLand, aboveGroundCarbonDensity, year, aEndYear, mTotalEmissionsAbove ); calcBelowGroundCarbonEmission( landDifference * belowGroundCarbonDensity, year, aEndYear, mTotalEmissionsBelow ); prevLand = currLand; currCarbonStock -= mTotalEmissionsAbove[ year ]; @@ -140,7 +141,7 @@ double ASimpleCarbonCalc::calc( const int aPeriod, const int aEndYear, const Car // we need to be careful about accessing the carbon stock from a previous timestep // when we are intending to calculate in eReverseCalc as the previous timestep may have // already calculated in eStoreResults - calcAboveGroundCarbonEmission( aCalcMode == eReverseCalc && (year - 1) == prevModelYear ? + calcAboveGroundCarbonEmission( aCalcMode, aCalcMode == eReverseCalc && (year - 1) == prevModelYear ? mSavedCarbonStock[ aPeriod - 1 ] : mCarbonStock[ year - 1 ], prevLand, currLand, getActualAboveGroundCarbonDensity( year ), year, aEndYear, currEmissionsAbove ); calcBelowGroundCarbonEmission( prevCarbonBelow - currCarbonBelow, year, aEndYear, currEmissionsBelow ); @@ -180,6 +181,8 @@ double ASimpleCarbonCalc::calc( const int aPeriod, const int aEndYear, const Car /*! * \brief Calculate the emission from above ground carbon for a given year. * \details Above ground carbon is emitted as a pulse, and will uptake over mature age. + * \param aCalcMode The "mode" in which to run the calculation, i.e. normal or reverse to back out + * previously calculated values when running target finder. * \param aPrevCarbonStock The carbon stock from the previous year. * \param aPrevLandArea The land area during the previous year. * \param aCurrLandArea The land area which will expand/contract to. @@ -188,8 +191,8 @@ double ASimpleCarbonCalc::calc( const int aPeriod, const int aEndYear, const Car * \param aEndYear The last future year to calculate to. * \param aEmissVector A vector to accumulate emissions into. */ -//template -void ASimpleCarbonCalc::calcAboveGroundCarbonEmission( const double aPrevCarbonStock, +void ASimpleCarbonCalc::calcAboveGroundCarbonEmission( const CarbonCalcMode aCalcMode, + const double aPrevCarbonStock, const double aPrevLandArea, const double aCurrLandArea, const double aPrevCarbonDensity, @@ -215,7 +218,13 @@ void ASimpleCarbonCalc::calcAboveGroundCarbonEmission( const double aPrevCarbonS // If this land category didn't exist before, and now it does, // then the calculation below will generate a NaN. Avoid that // by taking the appropriate limit here. - aEmissVector[ aYear ] -= aCurrLandArea * aPrevCarbonDensity; + aEmissVector[ aYear ] += carbonDiff; + if(aCalcMode == eStoreResults && carbonDiff > 0.0) { + mPositiveEmissionsAbove[ aYear ] += carbonDiff; + } + else if(aCalcMode == eReverseCalc) { + mPositiveEmissionsAbove[ aYear ] = 0.0; + } } else { // If carbon content decreases, then emissions have occurred. @@ -228,6 +237,12 @@ void ASimpleCarbonCalc::calcAboveGroundCarbonEmission( const double aPrevCarbonS // but you can show that the formula below just reduces to the // expression for carbonDiff at the top of the function.) aEmissVector[ aYear ] += ( aPrevCarbonStock / aPrevLandArea ) * ( aPrevLandArea - aCurrLandArea ); + if(aCalcMode == eStoreResults) { + mPositiveEmissionsAbove[ aYear ] += ( aPrevCarbonStock / aPrevLandArea ) * ( aPrevLandArea - aCurrLandArea ); + } + else if(aCalcMode == eReverseCalc) { + mPositiveEmissionsAbove[ aYear ] = 0.0; + } if( getMatureAge() > 1 ) { // Back out the pending future sequestration for the land // that has been converted (i.e., that sequestration will @@ -250,11 +265,11 @@ void ASimpleCarbonCalc::calcAboveGroundCarbonEmission( const double aPrevCarbonS * \brief Calculate the emission from below ground carbon for the given year. * \details Below ground, or soil carbon, is not emitted as a pulse but at a * exponential rate with a half-life computed from the soil time scale. + * \param aCarbonDiff Annual change in carbon for aYear * \param aYear Year. * \param aEndYear The last future year to calculate to. * \param aEmissVector A vector to accumulate emissions into. */ -//template void ASimpleCarbonCalc::calcBelowGroundCarbonEmission( const double aCarbonDiff, const int aYear, const int aEndYear, @@ -270,30 +285,19 @@ void ASimpleCarbonCalc::calcBelowGroundCarbonEmission( const double aCarbonDiff, // have occured, at twice the half-life 75% would have occurred, etc. // Note also that the aCarbonDiff is passed here as previous carbon minus current carbon // so a positive difference means that emissions will occur and a negative means uptake. - - const double halfLife = mSoilTimeScale / 10.0; - const double log2 = log( 2.0 ); - const double lambda = log2 / halfLife; - int yearCounter = 0; - double cumStockDiff_t1, cumStockDiff_t2; - cumStockDiff_t1 = 0.0; for( int currYear = aYear; currYear <= aEndYear; ++currYear ) { - yearCounter += 1; - cumStockDiff_t2 = aCarbonDiff * ( 1.0 - exp( -1.0 * lambda * yearCounter ) ); - aEmissVector[ currYear ] += cumStockDiff_t2 - cumStockDiff_t1; - cumStockDiff_t1 = cumStockDiff_t2; + aEmissVector[ currYear ] += precalc_expsoil_diff.get()[currYear - aYear] * aCarbonDiff; } } /*! * \brief Calculate the sigmoidal sequestration curve. * \details Called by calcAboveGroundCarbonEmission. - * \param carbonDifference Annual change in carbon for aYear + * \param aCarbonDiff Annual change in carbon for aYear * \param aYear Year. * \param aEndYear The last future year to calculate to. * \param aEmissVector A vector to accumulate emissions into. */ -//template void ASimpleCarbonCalc::calcSigmoidCurve( const double aCarbonDiff, const int aYear, const int aEndYear, @@ -390,6 +394,25 @@ double ASimpleCarbonCalc::getAboveGroundCarbonSubsidyDiscountFactor( ){ void ASimpleCarbonCalc::setSoilTimeScale( const int aTimeScale ) { mSoilTimeScale = aTimeScale; + + precalc_expsoil_diff = precalc_expsoil_type( aTimeScale ); +} + +ASimpleCarbonCalc::precalc_expsoil_helper::precalc_expsoil_helper( const int aSoilTimeScale ): +mData( CarbonModelUtils::getEndYear() - CarbonModelUtils::getStartYear() + 1 ) +{ + const double halfLife = aSoilTimeScale / 10.0; + const double log2 = log( 2.0 ); + const double lambda = log2 / halfLife; + int yearCounter = 0; + double cumStockDiff_t1, cumStockDiff_t2; + cumStockDiff_t1 = 0.0; + for( int currYear = CarbonModelUtils::getStartYear(); currYear <= CarbonModelUtils::getEndYear(); ++currYear ) { + yearCounter += 1; + cumStockDiff_t2 = ( 1.0 - exp( -1.0 * lambda * yearCounter ) ); + mData[ yearCounter - 1 ] = cumStockDiff_t2 - cumStockDiff_t1; + cumStockDiff_t1 = cumStockDiff_t2; + } } double ASimpleCarbonCalc::getAboveGroundCarbonStock( const int aYear ) const { @@ -401,3 +424,7 @@ double ASimpleCarbonCalc::getBelowGroundCarbonStock( const int aYear ) const { // TODO: decide what to do for carbon stock return 0;//mBelowGroundCarbonStock[ aYear ]; } + +double ASimpleCarbonCalc::getGrossPositiveLandUseChangeEmissionAbove( const int aYear ) const { + return mPositiveEmissionsAbove[ aYear ]; +} diff --git a/cvs/objects/ccarbon_model/source/node_carbon_calc.cpp b/cvs/objects/ccarbon_model/source/node_carbon_calc.cpp index 28fa85fb7a..ccff3a803c 100644 --- a/cvs/objects/ccarbon_model/source/node_carbon_calc.cpp +++ b/cvs/objects/ccarbon_model/source/node_carbon_calc.cpp @@ -186,7 +186,7 @@ void NodeCarbonCalc::calcLandUseHistory() diffLand[ i ] -= newDiff; diffLandTotal -= newDiff; assert( diffLand[ i ] == 0 || diffLandTotal == 0 ); - mCarbonCalcs[ i ]->calcAboveGroundCarbonEmission( carbonStock[ i ], prevLand[ i ], prevLand[ i ] + newDiff, + mCarbonCalcs[ i ]->calcAboveGroundCarbonEmission( ICarbonCalc::eStoreResults, carbonStock[ i ], prevLand[ i ], prevLand[ i ] + newDiff, aboveGroundCarbonDensity[ i ], year, CarbonModelUtils::getEndYear(), mCarbonCalcs[ i ]->mTotalEmissionsAbove ); mCarbonCalcs[ i ]->calcBelowGroundCarbonEmission( -1 * newDiff * belowGroundCarbonDensity[ i ], year, @@ -241,7 +241,7 @@ void NodeCarbonCalc::calcLandUseHistory() double currCarbonMove = fractionOfGain * carbonStockMoved; double carbonDiffAboveDensity = -1 * ( currCarbonMove / diffLand[ i ] - aboveGroundCarbonDensity[ i ] ); double carbonDiffBelow = -1 * ( diffLand[ i ] * belowGroundCarbonDensity[ i ] - fractionOfGain * carbonPrevBelow ); - mCarbonCalcs[ i ]->calcAboveGroundCarbonEmission( 0, 0, diffLand[ i ], carbonDiffAboveDensity, year, + mCarbonCalcs[ i ]->calcAboveGroundCarbonEmission( ICarbonCalc::eStoreResults, 0, 0, diffLand[ i ], carbonDiffAboveDensity, year, CarbonModelUtils::getEndYear(), mCarbonCalcs[ i ]->mTotalEmissionsAbove ); mCarbonCalcs[ i ]->calcBelowGroundCarbonEmission( carbonDiffBelow, year, CarbonModelUtils::getEndYear(), mCarbonCalcs[ i ]->mTotalEmissionsBelow ); @@ -399,7 +399,7 @@ void NodeCarbonCalc::calc( const int aPeriod, const int aEndYear, const ICarbonC // we need to be careful about accessing the carbon stock from a previous timestep // when we are intending to calculate in eReverseCalc as the previous timestep may have // already calculated in eStoreResults - mCarbonCalcs[ i ]->calcAboveGroundCarbonEmission( aCalcMode == ICarbonCalc::eReverseCalc && (year - 1) == prevModelYear ? + mCarbonCalcs[ i ]->calcAboveGroundCarbonEmission( aCalcMode, aCalcMode == ICarbonCalc::eReverseCalc && (year - 1) == prevModelYear ? mCarbonCalcs[ i ]->mSavedCarbonStock[ aPeriod - 1 ] : mCarbonCalcs[ i ]->mCarbonStock[ year - 1 ], prevLand[ i ], currLand[ i ], aboveGroundCarbonDensity[ i ], year, aEndYear, @@ -424,7 +424,7 @@ void NodeCarbonCalc::calc( const int aPeriod, const int aEndYear, const ICarbonC double carbonDiffAboveDensity = -1 * ( currCarbonMove / diffLandFromInternalByYear[ i ] - aboveGroundCarbonDensity[ i ] ); double carbonDiffBelow = -1 * ( diffLandFromInternalByYear[ i ] * belowGroundCarbonDensity[ i ] - fractionOfGain * totalInternalCarbonBelowMovedByYear ); - mCarbonCalcs[ i ]->calcAboveGroundCarbonEmission( 0, 0, diffLandFromInternalByYear[ i ], carbonDiffAboveDensity, + mCarbonCalcs[ i ]->calcAboveGroundCarbonEmission( aCalcMode, 0, 0, diffLandFromInternalByYear[ i ], carbonDiffAboveDensity, year, aEndYear, *currEmissionsAbove[ i ] ); mCarbonCalcs[ i ]->calcBelowGroundCarbonEmission( carbonDiffBelow, year, aEndYear, *currEmissionsBelow[ i ] ); // Adjust carbon stock to include the carbon being moved in minus any emissions because of moving diff --git a/cvs/objects/climate/include/hector_model.hpp b/cvs/objects/climate/include/hector_model.hpp index 4702a95af7..c8e0aa2f0b 100644 --- a/cvs/objects/climate/include/hector_model.hpp +++ b/cvs/objects/climate/include/hector_model.hpp @@ -97,7 +97,8 @@ class HectorModel: public IClimateModel { virtual runModelStatus runModel(); virtual runModelStatus runModel( const int aPeriod ); virtual double getConcentration( const std::string& aGasName, const int aYear ) const; - virtual double getTemperature( const int aYear ) const; + virtual double getTemperature( const int aYear, const bool aAdjHistoricalPeriod = false ) const; + virtual double getGmst( const int aYear, const bool aAdjHistoricalPeriod = false ) const; virtual double getForcing( const std::string& aGasName, const int aYear ) const; virtual double getTotalForcing( const int aYear ) const; virtual double getNetTerrestrialUptake( const int aYear ) const; @@ -164,6 +165,9 @@ class HectorModel: public IClimateModel { //! temperatures retrieved from Hector std::vector mTemperatureTable; + + //! surface temperatures retrieved from Hector + std::vector mGmstTable; //! land fluxes retrieved from Hector std::vector mLandFlux; @@ -176,18 +180,25 @@ class HectorModel: public IClimateModel { std::map mUnitConvFac; //! Hector core object - std::auto_ptr mHcore; + std::unique_ptr mHcore; //! file handle for the outputstream visitor - std::auto_ptr mOfile; + std::unique_ptr mOfile; //! output stream visitor - std::auto_ptr mHosv; + std::unique_ptr mHosv; // private functions //! reset the Hector GCAM component and the Hector model for a new run void reset( const int aPeriod ); + + //! test if a gas name is LUC related + bool isGasLUC( const std::string& aGasName ) const { + // simple at the moment but could have some additional logic + // if we wanted to be able to configure an NBP constraint + return aGasName == "CO2EmissionsLandUse" || aGasName == "CO2UptakeLandUse"; + } //! worker routine for setting emissions bool setEmissionsByYear( const std::string& aGasName, const int aYear, double aEmissions ); diff --git a/cvs/objects/climate/include/iclimate_model.h b/cvs/objects/climate/include/iclimate_model.h index 1c8d577f6f..f24fd74b60 100644 --- a/cvs/objects/climate/include/iclimate_model.h +++ b/cvs/objects/climate/include/iclimate_model.h @@ -201,10 +201,24 @@ class IClimateModel: public IVisitable, private boost::noncopyable { * and returns the value. If the climate model is unavailable the * value returned is -1. * \param aYear The year for which to return the temperature. + * \param aAdjHistoricalPeriod A flag if the climate model should adjust the temperature + * value to be relative to the mean from 1850 - 1900. * \return The temperature for the period, -1 if the climate model is * unavailable. */ - virtual double getTemperature( const int aYear ) const = 0; + virtual double getTemperature( const int aYear, const bool aAdjHistoricalPeriod = false ) const = 0; + + /*! \brief Returns the surface temperature in a given period from the climate model. + * \details Queries the climate model for the surface temperature for a given period + * and returns the value. If the climate model is unavailable the + * value returned is -1. + * \param aYear The year for which to return the surface temperature. + * \param aAdjHistoricalPeriod A flag if the climate model should adjust the temperature + * value to be relative to the mean from 1850 - 1900. + * \return The surface temperature for the period, -1 if the climate model is + * unavailable. + */ + virtual double getGmst( const int aYear, const bool aAdjHistoricalPeriod = false ) const = 0; /*! \brief Returns the forcing of a specific gas in a given period from the * climate model. diff --git a/cvs/objects/climate/include/magicc_model.h b/cvs/objects/climate/include/magicc_model.h index f5c9be711f..edcd073d3a 100644 --- a/cvs/objects/climate/include/magicc_model.h +++ b/cvs/objects/climate/include/magicc_model.h @@ -98,8 +98,10 @@ class MagiccModel: public IClimateModel { virtual double getConcentration( const std::string& aGasName, const int aYear ) const; - virtual double getTemperature( const int aYear ) const; + virtual double getTemperature( const int aYear, const bool aAdjHistoricalPeriod = false ) const; + virtual double getGmst( const int aYear, const bool aAdjHistoricalPeriod = false ) const; + virtual double getForcing( const std::string& aGasName, const int aYear ) const; diff --git a/cvs/objects/climate/include/no_climate_model.h b/cvs/objects/climate/include/no_climate_model.h index 1d6c62c145..e18079ab47 100644 --- a/cvs/objects/climate/include/no_climate_model.h +++ b/cvs/objects/climate/include/no_climate_model.h @@ -93,7 +93,9 @@ class NoClimateModel: public IClimateModel { virtual double getConcentration( const std::string& aGasName, const int aYear ) const; - virtual double getTemperature( const int aYear ) const; + virtual double getTemperature( const int aYear, const bool aAdjHistoricalPeriod = false ) const; + + virtual double getGmst( const int aYear, const bool aAdjHistoricalPeriod = false ) const; virtual double getForcing( const std::string& aGasName, const int aYear ) const; diff --git a/cvs/objects/climate/source/hector b/cvs/objects/climate/source/hector index ac4b909e52..3b83b46756 160000 --- a/cvs/objects/climate/source/hector +++ b/cvs/objects/climate/source/hector @@ -1 +1 @@ -Subproject commit ac4b909e521f5988b8cc81bf6f042e5bda94d209 +Subproject commit 3b83b467564e80231aaa070d0dcb3b7f891d3397 diff --git a/cvs/objects/climate/source/hector_model.cpp b/cvs/objects/climate/source/hector_model.cpp index 01ae7b7c20..e3466aa102 100644 --- a/cvs/objects/climate/source/hector_model.cpp +++ b/cvs/objects/climate/source/hector_model.cpp @@ -74,7 +74,7 @@ namespace { const double S_TO_SO2 = 2.0; // 2g SO2 has 1g of S // default values - const int def_end_year = 2300; + const int def_end_year = 2100; const int def_switch_year = 2005; const char *def_ini_file = "../input/climate/hector-gcam.ini"; @@ -155,66 +155,80 @@ void HectorModel::completeInit( const string& aScenarioName ) { } // Set up the name tables for each of the gases that GCAM and - // hector both know about. - mHectorEmissionsMsg["CO2"] = D_FFI_EMISSIONS; - mHectorEmissionsMsg["CO2NetLandUse"] = D_LUC_EMISSIONS; - mHectorEmissionsMsg["SO2tot"] = D_EMISSIONS_SO2; - mHectorEmissionsMsg["CF4"] = D_EMISSIONS_CF4; - mHectorEmissionsMsg["C2F6"] = D_EMISSIONS_C2F6; - mHectorEmissionsMsg["HFC23"] = D_EMISSIONS_HFC23; + // hector both know about. + mHectorEmissionsMsg["BC"] = D_EMISSIONS_BC; + mHectorEmissionsMsg["C2F6"] = D_EMISSIONS_C2F6; + mHectorEmissionsMsg["CF4"] = D_EMISSIONS_CF4; + mHectorEmissionsMsg["CH4"] = D_EMISSIONS_CH4; + mHectorEmissionsMsg["CO"] = D_EMISSIONS_CO; + mHectorEmissionsMsg["CO2FFIEmissions"] = D_FFI_EMISSIONS; + mHectorEmissionsMsg["CO2DACCCSUptake"] = D_DACCS_UPTAKE; + // TODO: put in switch for NBP constraint + //mHectorEmissionsMsg["CO2NetLandUse"] = D_NBP_CONSTRAIN; //D_LUC_EMISSIONS; + mHectorEmissionsMsg["CO2EmissionsLandUse"] = D_LUC_EMISSIONS; + mHectorEmissionsMsg["CO2UptakeLandUse"] = D_LUC_UPTAKE; mHectorEmissionsMsg["HFC125"] = D_EMISSIONS_HFC125; mHectorEmissionsMsg["HFC134a"] = D_EMISSIONS_HFC134a; mHectorEmissionsMsg["HFC143a"] = D_EMISSIONS_HFC143a; - mHectorEmissionsMsg["HFC227ea"] = D_EMISSIONS_HFC227ea; + mHectorEmissionsMsg["HFC227ea"] = D_EMISSIONS_HFC227ea; + mHectorEmissionsMsg["HFC23"] = D_EMISSIONS_HFC23; mHectorEmissionsMsg["HFC245fa"] = D_EMISSIONS_HFC245fa; - mHectorEmissionsMsg["SF6"] = D_EMISSIONS_SF6; - mHectorEmissionsMsg["BC"] = D_EMISSIONS_BC; - mHectorEmissionsMsg["OC"] = D_EMISSIONS_OC; + mHectorEmissionsMsg["HFC32"] = D_EMISSIONS_HFC32; + mHectorEmissionsMsg["N2O"] = D_EMISSIONS_N2O; + mHectorEmissionsMsg["NH3"] = D_EMISSIONS_NH3; + mHectorEmissionsMsg["NMVOCs"] = D_EMISSIONS_NMVOC; mHectorEmissionsMsg["NOx"] = D_EMISSIONS_NOX; - mHectorEmissionsMsg["CO"] = D_EMISSIONS_CO; - mHectorEmissionsMsg["NMVOCs"] = D_EMISSIONS_NMVOC; - - mHectorEmissionsMsg["CH4"] = D_EMISSIONS_CH4; - mHectorEmissionsMsg["N2O"] = D_EMISSIONS_N2O; - - // Not implemented in hector at all: regional SO2 (total - // SO2 is in) - - // Implemented in Hector, but not in GCAM: - // CFC11, CFC12, CFC113, CFC114, CFC115, - // CCl4, CH3CCl3, HCF22, HCF141b, HCF142b, halon1200, halon1301, - // halon2402, CH3Cl, CH3Br (default emissions will be used for - // these. - + mHectorEmissionsMsg["OC"] = D_EMISSIONS_OC; + mHectorEmissionsMsg["SF6"] = D_EMISSIONS_SF6; + mHectorEmissionsMsg["SO2tot"] = D_EMISSIONS_SO2; + + // Emissions modeled by GCAM but not implemented in Hector v 3.1 + // H2, HFC152a, HFC236fa, HFC365mfc, HFC43, PM + // Emissions for HFC152a, HFC236fa, HFC365mfc, HFC43 are + // converted into HFC equivalents modeled by Hector. + + // Emissions implemented in Hector v 3.1 but not in GCAM + // CCl4, CFC11, CFC113, CFC114, CFC115, CFC12 + // CH3Br, CH3CCl3, CH3Cl, halon1211, halon1301, halon2402 + // HCFC141b, HCFC142b, HCFC22, HFC365, HFC4310 + // (default emissions will be used for this provided in + // input/climate/default_emissions.csv) + + // Additional forcings used in Hector v 3.1 + // Albedo, and Volcanic SO2 (SV) + // Set up the message tables for components (mostly halocarbons) // that store their radiative forcing as a time series. - mHectorRFTseriesMsg["CF4"] = D_RF_CF4; - mHectorRFTseriesMsg["C2F6"] = D_RF_C2F6; - mHectorRFTseriesMsg["HFC23"] = D_RF_HFC23; - mHectorRFTseriesMsg["HFC125"] = D_RF_HFC125; - mHectorRFTseriesMsg["HFC134A"] = D_RF_HFC134a; - mHectorRFTseriesMsg["HFC143A"] = D_RF_HFC143a; - mHectorRFTseriesMsg["HFC227ea"] = D_RF_HFC227ea; - mHectorRFTseriesMsg["HFC245fa"] = D_RF_HFC245fa; - mHectorRFTseriesMsg["SF6"] = D_RF_SF6; - mHectorRFTseriesMsg["Albedo"] = D_RF_T_ALBEDO; - mHectorRFTseriesMsg["HFC32"] = D_RF_HFC32; - mHectorRFTseriesMsg["HFC4310"] = D_RF_HFC4310; + mHectorRFTseriesMsg["aci"] = D_RF_ACI; + mHectorRFTseriesMsg["Albedo"] = D_RF_T_ALBEDO; + mHectorRFTseriesMsg["C2F6"] = D_RF_C2F6; + mHectorRFTseriesMsg["CCl4"] = D_RF_CCl4; + mHectorRFTseriesMsg["CF4"] = D_RF_CF4; mHectorRFTseriesMsg["CFC11"] = D_RF_CFC11; - mHectorRFTseriesMsg["CFC12"] = D_RF_CFC12; mHectorRFTseriesMsg["CFC113"] = D_RF_CFC113; mHectorRFTseriesMsg["CFC114"] = D_RF_CFC114; mHectorRFTseriesMsg["CFC115"] = D_RF_CFC115; - mHectorRFTseriesMsg["CCl4"] = D_RF_CCl4; + mHectorRFTseriesMsg["CFC12"] = D_RF_CFC12; + mHectorRFTseriesMsg["CH3Br"] = D_RF_CH3Br; mHectorRFTseriesMsg["CH3CCl3"] = D_RF_CH3CCl3; - mHectorRFTseriesMsg["HCF22"] = D_RF_HCF22; - mHectorRFTseriesMsg["HCF141b"] = D_RF_HCF141b; - mHectorRFTseriesMsg["HCF142b"] = D_RF_HCF142b; + mHectorRFTseriesMsg["CH3Cl"] = D_RF_CH3Cl; mHectorRFTseriesMsg["halon1211"] = D_RF_halon1211; mHectorRFTseriesMsg["halon1301"] = D_RF_halon1301; mHectorRFTseriesMsg["halon2402"] = D_RF_halon2402; - mHectorRFTseriesMsg["CH3Cl"] = D_RF_CH3Cl; - mHectorRFTseriesMsg["CH3Br"] = D_RF_CH3Br; + mHectorRFTseriesMsg["HCF141b"] = D_RF_HCFC141b; + mHectorRFTseriesMsg["HCF142b"] = D_RF_HCFC142b; + mHectorRFTseriesMsg["HCF22"] = D_RF_HCFC22; + mHectorRFTseriesMsg["HFC125"] = D_RF_HFC125; + mHectorRFTseriesMsg["HFC134A"] = D_RF_HFC134a; + mHectorRFTseriesMsg["HFC143A"] = D_RF_HFC143a; + mHectorRFTseriesMsg["HFC227ea"] = D_RF_HFC227ea; + mHectorRFTseriesMsg["HFC23"] = D_RF_HFC23; + mHectorRFTseriesMsg["HFC245fa"] = D_RF_HFC245fa; + mHectorRFTseriesMsg["HFC32"] = D_RF_HFC32; + mHectorRFTseriesMsg["HFC4310"] = D_RF_HFC4310; + mHectorRFTseriesMsg["SF6"] = D_RF_SF6; + mHectorRFTseriesMsg["vol"] = D_RF_VOL; + // Set up the storage for GCAM emissions for each of the gasses we // know about. We need this data to report emissions when we are @@ -235,11 +249,14 @@ void HectorModel::completeInit( const string& aScenarioName ) { << it->second << endl; } // Land Use CO2 is special; it can be set each year, rather than each period. - mEmissionsTable["CO2NetLandUse"].resize( nrslt ); + //mEmissionsTable["CO2NetLandUse"].resize( nrslt ); + mEmissionsTable["CO2EmissionsLandUse"].resize( nrslt ); + mEmissionsTable["CO2UptakeLandUse"].resize( nrslt ); // tables for temperature and total forcing and land and ocean fluxes mTotRFTable.resize( nrslt ); mTemperatureTable.resize( nrslt ); + mGmstTable.resize( nrslt ); mLandFlux.resize( nrslt ); mOceanFlux.resize( nrslt ); // set up the other results tables @@ -248,19 +265,20 @@ void HectorModel::completeInit( const string& aScenarioName ) { // Set conversion factors for gasses that require them mUnitConvFac["SO2tot"] = TG_TO_GG / S_TO_SO2; // GCAM in Tg-SO2; Hector in Tg-S - mUnitConvFac["BC"] = GG_TO_TG; // GCAM produces BC/OC in Tg but converts - mUnitConvFac["OC"] = GG_TO_TG; // to Gg for MAGICC. Hector wants Tg. + mUnitConvFac["BC"] = GG_TO_TG; // GCAM produces BC/OC in Tg but converts + mUnitConvFac["OC"] = GG_TO_TG; // to Gg for MAGICC. Hector wants Tg. + // Already in correct units: // CO2 - produced in Mt C, but converted to Gt C before passing in, // CH4 - produced in Mt CH4, which is what Hector wants. // halocarbons - produced in Gg, which is what Hector wants. - // CO and NMVOC - produced in Tg of the relevant gas + // CO, NMVOC, and NH3 - produced in Tg of the relevant gas // NOx -- GCAM produces this in TgNOx, but it is converted to N by world::setEmissions // N2O -- GCAM produces this in TgN2O, but it is converted to N by world::setEmissions // set units for gasses that are not in Gg. These units are // defined in the Hector header files. - mHectorUnits["CO2"] = mHectorUnits["CO2NetLandUse"] = Hector::U_PGC_YR; + mHectorUnits["CO2FFIEmissions"] = mHectorUnits["CO2DACCCSUptake"] = /*mHectorUnits["CO2NetLandUse"] =*/ mHectorUnits["CO2EmissionsLandUse"] = mHectorUnits["CO2UptakeLandUse"] = Hector::U_PGC_YR; mHectorUnits["BC"] = mHectorUnits["OC"] = Hector::U_TG; mHectorUnits["NOx"] = Hector::U_TG_N; mHectorUnits["N2O"] = Hector::U_TG_N; @@ -268,7 +286,8 @@ void HectorModel::completeInit( const string& aScenarioName ) { mHectorUnits["NMVOCs"] = Hector::U_TG_NMVOC; mHectorUnits["CH4"] = Hector::U_TG_CH4; mHectorUnits["SO2tot"] = Hector::U_GG_S; - + mHectorUnits["NH3"] = Hector::U_TG; + // reset up to (but not including) period 1. reset( 1 ); } @@ -323,7 +342,7 @@ void HectorModel::reset( const int aPeriod ) { for( it = mEmissionsTable.begin(); it != mEmissionsTable.end(); ++it ) { const string& gas = it->first; vector& emissions = it->second; - if( gas != "CO2NetLandUse" ) { + if( !isGasLUC(gas) ) { // Replay emissions up to, and including, the aPeriod argument. // Note: We also skip period 0, since it's not a "real" period. for( int i = 1; i <= aPeriod; ++i ) { @@ -430,7 +449,14 @@ bool HectorModel::setEmissions( const string& aGasName, const int aPeriod, bool HectorModel::setLUCEmissions( const string& aGasName, const int aYear, double aEmissions ) { - if( aGasName != "CO2NetLandUse" ) { + if( aGasName == "CO2NetLandUse" ) { + ILogger& climatelog = ILogger::getLogger( "climate-log" ); + climatelog.setLevel (ILogger::DEBUG ); + climatelog << "Ignoring : " << aGasName << " . As " << getXMLNameStatic() + << " is now expecting seperate emissions and uptake." << endl; + return false; + } + else if( !isGasLUC(aGasName) ) { ILogger& climatelog = ILogger::getLogger( "climate-log" ); climatelog.setLevel (ILogger::ERROR ); climatelog << "Invalid LUC gas: " << aGasName @@ -515,9 +541,18 @@ IClimateModel::runModelStatus HectorModel::runModel( const int aYear ) { */ IClimateModel::runModelStatus HectorModel::runModel() { int year = mHcore->getEndDate(); - IClimateModel::runModelStatus stat = runModel( year ); + // check if a stop year/period was set in which case we shouldn't try + // to run Hector past that year otherwise we are liable to get an exception + // wrt to emissions not set + int finalGCAMPeriod = util::getConfigRunPeriod( "stop" ); + int finalGCAMYear = finalGCAMPeriod < 0 ? year : scenario->getModeltime()->getper_to_yr(finalGCAMPeriod); ILogger& climatelog = ILogger::getLogger( "climate-log" ); climatelog.setLevel( ILogger::NOTICE ); + if(finalGCAMYear < year) { + climatelog << "Reset final year as GCAM stop year is configured to " << finalGCAMYear < mHectorEndYear ) { climatelog.setLevel( ILogger::WARNING ); @@ -567,6 +602,38 @@ double HectorModel::getTemperature( const int aYear ) const { climatelog.setLevel( ILogger::DEBUG ); climatelog << "\tgetTemperature: year= " << aYear << " index= " << idx << "\ttemperature= " << tempval << endl; + if(aAdjHistoricalPeriod) { + // adjust temperature to be relative to the mean air temperature from 1850-1900 + // WARNING: this is set as a constant here but was derived from a particular + // set of Hector assumptions. And therefore should be sensitive to changing + // Hector parameters. Getting this value dynamically is issue JGCRI-469. + const double GMAT_ADJUST = -0.0411; + tempval -= GMAT_ADJUST; + } + return tempval; +} + +double HectorModel::getGmst(const int aYear, const bool aAdjHistoricalPeriod ) const { + // Global mean surface temperature + if( aYear > mHectorEndYear ) { + ILogger& climatelog = ILogger::getLogger( "climate-log" ); + climatelog.setLevel( ILogger::WARNING ); + climatelog << "getGmst(): invalid year: " << aYear + << " last hector year is " << mHectorEndYear << endl; + return 0.0; + } + + int idx = yearlyDataIndex( aYear ); + double tempval = mGmstTable[ idx ]; + + if(aAdjHistoricalPeriod) { + // adjust temperature to be relative to the mean surface temperature from 1850-1900 + // WARNING: this is set as a constant here but was derived from a particular + // set of Hector assumptions. And therefore should be sensitive to changing + // Hector parameters. Getting this value dynamically is issue JGCRI-469. + const double GMSAT_ADJUST = -0.0338; + tempval -= GMSAT_ADJUST; + } return tempval; } @@ -649,20 +716,12 @@ void HectorModel::storeConc( const int aYear, const bool aHadError ) { // No need to check the index because we checked it in runModel int i = yearlyDataIndex( aYear ); - // These are all of the atmospheric concentrations that Hector is - // set up to provide. + // These are all of the atmospheric concentrations that Hector v3.1 provides. Hector::message_data date( aYear ); - mConcTable["CH4"][i] = aHadError ? numeric_limits::quiet_NaN() : mHcore->sendMessage( M_GETDATA, D_ATMOSPHERIC_CH4,date ); - mConcTable["N2O"][i] = aHadError ? numeric_limits::quiet_NaN() : mHcore->sendMessage( M_GETDATA, D_ATMOSPHERIC_N2O,date ); + mConcTable["CH4"][i] = aHadError ? numeric_limits::quiet_NaN() : mHcore->sendMessage( M_GETDATA, D_CH4_CONC,date ); + mConcTable["N2O"][i] = aHadError ? numeric_limits::quiet_NaN() : mHcore->sendMessage( M_GETDATA, D_N2O_CONC,date ); mConcTable["O3"][i] = aHadError ? numeric_limits::quiet_NaN() : mHcore->sendMessage( M_GETDATA, D_ATMOSPHERIC_O3, date ); - mConcTable["CO2"][i] = aHadError ? numeric_limits::quiet_NaN() : mHcore->sendMessage( M_GETDATA, D_ATMOSPHERIC_CO2 ); - - // Hector doesn't actually compute concentrations for these - // gasses. (we use their emissions to compute O3 concentration, - // but don't compute the concentrations of the original gasses.) - // mConcTable["CO"][i] = mHcore->sendMessage(M_GETDATA, D_ATMOSPHERIC_CO); - // mConcTable["NOX"][i] = mHcore->sendMessage(M_GETDATA, D_ATMOSPHERIC_NOX); - // mConcTable["NMVOC"][i] = mHcore->sendMessage(M_GETDATA, D_ATMOSPHERIC_NMVOC); + mConcTable["CO2"][i] = aHadError ? numeric_limits::quiet_NaN() : mHcore->sendMessage( M_GETDATA, D_CO2_CONC, date ); // Log the concentrations we are seeing here climatelog.setLevel( ILogger::DEBUG ); @@ -688,20 +747,19 @@ void HectorModel::setupConcTbl() { void HectorModel::storeRF(const int aYear, const bool aHadError ) { ILogger& climatelog = ILogger::getLogger( "climate-log" ); int i = yearlyDataIndex( aYear ); - + Hector::message_data currDate(static_cast(aYear)); // total - mTotRFTable[i] = aHadError ? numeric_limits::quiet_NaN() : mHcore->sendMessage( M_GETDATA, D_RF_TOTAL ); + mTotRFTable[i] = aHadError ? numeric_limits::quiet_NaN() : mHcore->sendMessage( M_GETDATA, D_RF_TOTAL, currDate ); // misc gases requested by GCAM - mGasRFTable["CO2"][i] = aHadError ? numeric_limits::quiet_NaN() : mHcore->sendMessage( M_GETDATA, D_RF_CO2 ); - mGasRFTable["CH4"][i] = aHadError ? numeric_limits::quiet_NaN() : mHcore->sendMessage( M_GETDATA, D_RF_CH4 ); - mGasRFTable["N2O"][i] = aHadError ? numeric_limits::quiet_NaN() : mHcore->sendMessage( M_GETDATA, D_RF_N2O ); - mGasRFTable["BC"][i] = aHadError ? numeric_limits::quiet_NaN() : mHcore->sendMessage( M_GETDATA, D_RF_BC ); - mGasRFTable["OC"][i] = aHadError ? numeric_limits::quiet_NaN() : mHcore->sendMessage( M_GETDATA, D_RF_OC ); - mGasRFTable["SO2"][i] = aHadError ? numeric_limits::quiet_NaN() : mHcore->sendMessage( M_GETDATA, D_RF_SO2 ); - mGasRFTable["StratH2O"][i] = aHadError ? numeric_limits::quiet_NaN() : mHcore->sendMessage( M_GETDATA, D_RF_H2O ); - mGasRFTable["DirSO2"][i] = aHadError ? numeric_limits::quiet_NaN() : mHcore->sendMessage( M_GETDATA, D_RF_SO2d ); - mGasRFTable["TropO3"][i] = aHadError ? numeric_limits::quiet_NaN() : mHcore->sendMessage( M_GETDATA, D_RF_O3 ); + mGasRFTable["CO2"][i] = aHadError ? numeric_limits::quiet_NaN() : mHcore->sendMessage( M_GETDATA, D_RF_CO2, currDate ); + mGasRFTable["CH4"][i] = aHadError ? numeric_limits::quiet_NaN() : mHcore->sendMessage( M_GETDATA, D_RF_CH4, currDate ); + mGasRFTable["N2O"][i] = aHadError ? numeric_limits::quiet_NaN() : mHcore->sendMessage( M_GETDATA, D_RF_N2O, currDate ); + mGasRFTable["BC"][i] = aHadError ? numeric_limits::quiet_NaN() : mHcore->sendMessage( M_GETDATA, D_RF_BC, currDate ); + mGasRFTable["OC"][i] = aHadError ? numeric_limits::quiet_NaN() : mHcore->sendMessage( M_GETDATA, D_RF_OC, currDate ); + mGasRFTable["SO2"][i] = aHadError ? numeric_limits::quiet_NaN() : mHcore->sendMessage( M_GETDATA, D_RF_SO2, currDate ); + mGasRFTable["StratH2O"][i] = aHadError ? numeric_limits::quiet_NaN() : mHcore->sendMessage( M_GETDATA, D_RF_H2O_STRAT, currDate ); + mGasRFTable["TropO3"][i] = aHadError ? numeric_limits::quiet_NaN() : mHcore->sendMessage( M_GETDATA, D_RF_O3_TROP, currDate ); #if 0 // Forcings that hector can provide, but which are not currently @@ -710,10 +768,6 @@ void HectorModel::storeRF(const int aYear, const bool aHadError ) { // Remember, if you enable them here, then you also have to add // them in setupRFTbl below. - // Not added since can get from SO2 - SO2dir - mGasRFTable["SO2i"][i] = mHcore->sendMessage( M_GETDATA, D_RF_SO2i ); - - // Volcanoes! <- ? #endif @@ -736,7 +790,6 @@ void HectorModel::setupRFTbl() { mGasRFTable["BC"].resize( size ); mGasRFTable["OC"].resize( size ); mGasRFTable["SO2"].resize( size ); - mGasRFTable["DirSO2"].resize( size ); mGasRFTable["StratH2O"].resize( size ); mGasRFTable["TropO3"].resize( size ); } @@ -745,10 +798,12 @@ void HectorModel::setupRFTbl() { //! forcing, which gets stored in storeRF() void HectorModel::storeGlobals( const int aYear, const bool aHadError ) { int idx = yearlyDataIndex( aYear ); + Hector::message_data currDate(static_cast(aYear)); - mTemperatureTable[idx] = aHadError ? numeric_limits::quiet_NaN() : mHcore->sendMessage( M_GETDATA, D_GLOBAL_TEMP ); - mLandFlux[idx] = aHadError ? numeric_limits::quiet_NaN() : mHcore->sendMessage( M_GETDATA, D_LAND_CFLUX ); - mOceanFlux[idx] = aHadError ? numeric_limits::quiet_NaN() : mHcore->sendMessage( M_GETDATA, D_OCEAN_CFLUX ); + mTemperatureTable[idx] = aHadError ? numeric_limits::quiet_NaN() : mHcore->sendMessage( M_GETDATA, D_GLOBAL_TAS, currDate ); + mGmstTable[idx] = aHadError ? numeric_limits::quiet_NaN() : mHcore->sendMessage( M_GETDATA, D_GMST, currDate ); + mLandFlux[idx] = aHadError ? numeric_limits::quiet_NaN() : mHcore->sendMessage( M_GETDATA, D_NBP, currDate ); + mOceanFlux[idx] = aHadError ? numeric_limits::quiet_NaN() : mHcore->sendMessage( M_GETDATA, D_OCEAN_C_UPTAKE, currDate ); } @@ -772,7 +827,7 @@ double HectorModel::getEmissions( const string& aGasName, const int aYear ) cons const Modeltime* modeltime = scenario->getModeltime(); if( aYear <= modeltime->getEndYear() && aYear >= modeltime->getStartYear() ) { - if( aGasName == "CO2NetLandUse" ) { + if( isGasLUC(aGasName) ) { return (mEmissionsTable.find( aGasName )->second)[ yearlyDataIndex( aYear ) ]; } else { diff --git a/cvs/objects/climate/source/magicc_model.cpp b/cvs/objects/climate/source/magicc_model.cpp index be48d47212..f70f6c9c2e 100644 --- a/cvs/objects/climate/source/magicc_model.cpp +++ b/cvs/objects/climate/source/magicc_model.cpp @@ -660,7 +660,18 @@ double MagiccModel::getConcentration( const string& aGasName, return -1; } -double MagiccModel::getTemperature( const int aYear ) const { +double MagiccModel::getTemperature( const int aYear, const bool aAdjHistoricalPeriod ) const { + // Check if the climate model has been run and that valid year is passed in. + if( !mIsValid || !isValidClimateModelYear( aYear ) ){ + return -1; + } + + // Need to store the year locally so it can be passed by reference. + int year = aYear; + return GETGMTEMP( year ); +} + +double MagiccModel::getGmst(const int aYear, const bool aAdjHistoricalPeriod) const { // Check if the climate model has been run and that valid year is passed in. if( !mIsValid || !isValidClimateModelYear( aYear ) ){ return -1; diff --git a/cvs/objects/climate/source/no_climate_model.cpp b/cvs/objects/climate/source/no_climate_model.cpp index f9554a4b26..4ae493e081 100644 --- a/cvs/objects/climate/source/no_climate_model.cpp +++ b/cvs/objects/climate/source/no_climate_model.cpp @@ -107,7 +107,11 @@ double NoClimateModel::getConcentration( const string& aGasName, const int aYear return 0.0; } -double NoClimateModel::getTemperature( const int aYear ) const { +double NoClimateModel::getTemperature( const int aYear, const bool aAdjHistoricalPeriod ) const { + return 0.0; +} + +double NoClimateModel::getGmst( const int aYear, const bool aAdjHistoricalPeriod ) const { return 0.0; } diff --git a/cvs/objects/containers/include/batch_runner.h b/cvs/objects/containers/include/batch_runner.h index 70d86e92fe..dea10f88bc 100644 --- a/cvs/objects/containers/include/batch_runner.h +++ b/cvs/objects/containers/include/batch_runner.h @@ -207,10 +207,10 @@ class BatchRunner: public IScenarioRunner { */ class ParseHelper { public: - std::auto_ptr& getParsedScenarioRunner(); + std::unique_ptr& getParsedScenarioRunner(); private: //! The IScenarioRunner created by the XMLParse method. - std::auto_ptr mScenarioRunner; + std::unique_ptr mScenarioRunner; }; }; diff --git a/cvs/objects/containers/include/mac_generator_scenario_runner.h b/cvs/objects/containers/include/mac_generator_scenario_runner.h index 8dcb373b7e..a22d0446b9 100644 --- a/cvs/objects/containers/include/mac_generator_scenario_runner.h +++ b/cvs/objects/containers/include/mac_generator_scenario_runner.h @@ -86,10 +86,10 @@ class MACGeneratorScenarioRunner: public IScenarioRunner { private: //! The scenario runner which controls running the initial scenario, and all //! fixed taxed scenarios after. - std::auto_ptr mSingleScenario; + std::unique_ptr mSingleScenario; //! The delegate object which calculates total costs. - std::auto_ptr mPolicyCostCalculator; + std::unique_ptr mPolicyCostCalculator; // Not totally intuitive but this define data is here for XML parse of scenario // components and the contained scenario components don't get initialized from diff --git a/cvs/objects/containers/include/scenario_runner_factory.h b/cvs/objects/containers/include/scenario_runner_factory.h index 1972568d82..7c5fb1f9ac 100644 --- a/cvs/objects/containers/include/scenario_runner_factory.h +++ b/cvs/objects/containers/include/scenario_runner_factory.h @@ -63,9 +63,9 @@ class SingleScenarioRunner; class ScenarioRunnerFactory { public: static bool isOfType( const std::string& aType ); - static std::auto_ptr create( const std::string& aType ); - static std::auto_ptr createSingleScenarioRunner(); - static std::auto_ptr createDefault( const std::list& aExcludedTypes ); + static std::unique_ptr create( const std::string& aType ); + static std::unique_ptr createSingleScenarioRunner(); + static std::unique_ptr createDefault( const std::list& aExcludedTypes ); private: static bool isExcluded( const std::list& aExcludedTypes, const std::string& aType ); diff --git a/cvs/objects/containers/include/single_scenario_runner.h b/cvs/objects/containers/include/single_scenario_runner.h index 9fe0f4bea3..aacbaa2817 100644 --- a/cvs/objects/containers/include/single_scenario_runner.h +++ b/cvs/objects/containers/include/single_scenario_runner.h @@ -113,7 +113,7 @@ class SingleScenarioRunner: public IScenarioRunner { SingleScenarioRunner(); static const std::string& getXMLNameStatic(); //! The scenario which will be run. - std::auto_ptr mScenario; + std::unique_ptr mScenario; // Not totally intuitive but this define data is here for XML parse of scenario // components and the contained Scenario *doesn't* get initialized from diff --git a/cvs/objects/containers/include/tree_item.h b/cvs/objects/containers/include/tree_item.h index 20fb2f69f2..5ceb43d33e 100644 --- a/cvs/objects/containers/include/tree_item.h +++ b/cvs/objects/containers/include/tree_item.h @@ -37,7 +37,6 @@ */ - /*! * \file tree_item.h * \ingroup Objects @@ -70,8 +69,6 @@ template class TreeItem { public: - typedef typename std::unary_function MatchesFunction; - /*! \brief Get the number of children which the tree item has. * \details Returns the number of children which the tree item has. In the * case of a leaf in the tree this will be zero. These children diff --git a/cvs/objects/containers/source/batch_runner.cpp b/cvs/objects/containers/source/batch_runner.cpp index f3348108e0..036fa69877 100644 --- a/cvs/objects/containers/source/batch_runner.cpp +++ b/cvs/objects/containers/source/batch_runner.cpp @@ -460,6 +460,6 @@ const Scenario* BatchRunner::getInternalScenario() const { * \pre XMLParse has been called. * \return The parsed scenario runner. */ -auto_ptr& BatchRunner::ParseHelper::getParsedScenarioRunner(){ +unique_ptr& BatchRunner::ParseHelper::getParsedScenarioRunner(){ return mScenarioRunner; } diff --git a/cvs/objects/containers/source/info.cpp b/cvs/objects/containers/source/info.cpp index 7ae40f6ce0..44d102204b 100644 --- a/cvs/objects/containers/source/info.cpp +++ b/cvs/objects/containers/source/info.cpp @@ -64,7 +64,7 @@ mParentInfo( aParentInfo ) /*! \brief Destructor * \details The explicit destructor is needed to prevent it from being inlined * into the header file where the hashmap definition file would not have -* been seen yet. The auto_ptr will delete the hashmap automatically +* been seen yet. The unique_ptr will delete the hashmap automatically * here. */ Info::~Info(){ diff --git a/cvs/objects/containers/source/market_dependency_finder.cpp b/cvs/objects/containers/source/market_dependency_finder.cpp index 22a2eb237a..1de5641dd6 100644 --- a/cvs/objects/containers/source/market_dependency_finder.cpp +++ b/cvs/objects/containers/source/market_dependency_finder.cpp @@ -126,7 +126,7 @@ bool MarketDependencyFinder::addDependency( const string& aDependentName, const bool aCanBeBroken ) { // Find/create a DependencyItem entry for the dependent item - auto_ptr item( new DependencyItem( aDependentName, aDependentRegion ) ); + unique_ptr item( new DependencyItem( aDependentName, aDependentRegion ) ); ItemIterator dependentIter = mDependencyItems.find( item.get() ); if( dependentIter == mDependencyItems.end() ) { dependentIter = mDependencyItems.insert( item.release() ).first; @@ -171,7 +171,7 @@ void MarketDependencyFinder::resolveActivityToDependency( const string& aRegionN IActivity* aDemandActivity, IActivity* aPriceActivity ) { - auto_ptr item( new DependencyItem( aActivityName, aRegionName ) ); + unique_ptr item( new DependencyItem( aActivityName, aRegionName ) ); ItemIterator itemIter = mDependencyItems.find( item.get() ); if( itemIter == mDependencyItems.end() ){ // No dependencies have been added for this activity yet. They may get added @@ -208,7 +208,7 @@ const vector MarketDependencyFinder::getOrdering( const int aMarketN } else { // Find the entry points into the graph for the given market. - auto_ptr marketToDep( new MarketToDependencyItem( aMarketNumber ) ); + unique_ptr marketToDep( new MarketToDependencyItem( aMarketNumber ) ); CMarketToDepIterator mrktIter = mMarketsToDep.find( marketToDep.get() ); if( mrktIter == mMarketsToDep.end() ) { // Somehow this market was not linked to any entry points into the graph. @@ -281,7 +281,7 @@ GcamFlowGraph* MarketDependencyFinder::getFlowGraph( const int aMarketNumber ) { } else { // Find the entry points into the graph for the given market. - auto_ptr marketToDep( new MarketToDependencyItem( aMarketNumber ) ); + unique_ptr marketToDep( new MarketToDependencyItem( aMarketNumber ) ); CMarketToDepIterator mrktIter = mMarketsToDep.find( marketToDep.get() ); if( mrktIter == mMarketsToDep.end() ) { // Somehow this market was not linked to any entry points into the graph. @@ -367,7 +367,7 @@ void MarketDependencyFinder::createOrdering() { int marketNumber = mMarketplace->mMarketLocator->getMarketNumber( (*it)->mLocatedInRegion, (*it)->mName ); if( marketNumber != MarketLocator::MARKET_NOT_FOUND ) { // Find/create an entry for the market to dependency struct - auto_ptr marketToDep( new MarketToDependencyItem( marketNumber ) ); + unique_ptr marketToDep( new MarketToDependencyItem( marketNumber ) ); MarketToDepIterator mrktIter = mMarketsToDep.find( marketToDep.get() ); if( mrktIter == mMarketsToDep.end() ) { mrktIter = mMarketsToDep.insert( marketToDep.release() ).first; @@ -442,7 +442,7 @@ void MarketDependencyFinder::createOrdering() { // Connect the graph by setting the out edges. for( CItemIterator it = mDependencyItems.begin(); it != mDependencyItems.end(); ++it ) { if( (*it)->mIsSolved ) { - auto_ptr marketToDep( new MarketToDependencyItem( (*it)->mLinkedMarket ) ); + unique_ptr marketToDep( new MarketToDependencyItem( (*it)->mLinkedMarket ) ); MarketToDepIterator mrktIter = mMarketsToDep.find( marketToDep.get() ); assert( mrktIter != mMarketsToDep.end() ); if( !(*it)->mPriceVertices.empty() ) { @@ -860,7 +860,7 @@ void MarketDependencyFinder::createTrialsForItem( CItemIterator aItemToReset, Ca // Lookup/create the associated market linkages to the price and demand // vertices. - auto_ptr marketToDep( new MarketToDependencyItem( (*aItemToReset)->mLinkedMarket ) ); + unique_ptr marketToDep( new MarketToDependencyItem( (*aItemToReset)->mLinkedMarket ) ); MarketToDepIterator priceMrktIter = mMarketsToDep.find( marketToDep.get() ); assert( priceMrktIter != mMarketsToDep.end() ); MarketToDepIterator demandMrktIter = mMarketsToDep.insert( new MarketToDependencyItem( demandMrkt ) ).first; diff --git a/cvs/objects/containers/source/region.cpp b/cvs/objects/containers/source/region.cpp index 4877081f63..2fe240d8d6 100644 --- a/cvs/objects/containers/source/region.cpp +++ b/cvs/objects/containers/source/region.cpp @@ -289,7 +289,7 @@ const Curve* Region::getEmissionsQuantityCurve( const string& ghgName ) const { /*! \pre The run has been completed. */ const Modeltime* modeltime = scenario->getModeltime(); - auto_ptr emissionsPoints( new ExplicitPointSet() ); + unique_ptr emissionsPoints( new ExplicitPointSet() ); // Note the GroupedEmissionsSummer will update all years GroupedEmissionsSummer emissGroup; @@ -326,7 +326,7 @@ const Curve* Region::getEmissionsPriceCurve( const string& ghgName ) const { const Modeltime* modeltime = scenario->getModeltime(); const Marketplace* marketplace = scenario->getMarketplace(); - auto_ptr emissionsPoints( new ExplicitPointSet() ); + unique_ptr emissionsPoints( new ExplicitPointSet() ); for( int i = 0; i < modeltime->getmaxper(); i++ ) { XYDataPoint* currPoint = new XYDataPoint( modeltime->getper_to_yr( i ), marketplace->getPrice( ghgName, mName, i ) ); diff --git a/cvs/objects/containers/source/scenario_runner_factory.cpp b/cvs/objects/containers/source/scenario_runner_factory.cpp index d903b09d9f..f76a184222 100644 --- a/cvs/objects/containers/source/scenario_runner_factory.cpp +++ b/cvs/objects/containers/source/scenario_runner_factory.cpp @@ -70,37 +70,37 @@ bool ScenarioRunnerFactory::isOfType( const string& aType ) { /*! * \brief Return a new instance of a component of the requested type. * \param aType Type of IScenarioRunner to return. - * \return A newly created IScenarioRunner wrapped in an auto_ptr. The pointer + * \return A newly created IScenarioRunner wrapped in an unique_ptr. The pointer * is null if the type is unknown. */ -auto_ptr ScenarioRunnerFactory::create( const string& aType ) { +unique_ptr ScenarioRunnerFactory::create( const string& aType ) { // Search the list of known types. if( aType == SingleScenarioRunner::getXMLNameStatic() ){ - return auto_ptr( new SingleScenarioRunner ); + return unique_ptr( new SingleScenarioRunner ); } if( aType == MACGeneratorScenarioRunner::getXMLNameStatic() ){ - return auto_ptr( new MACGeneratorScenarioRunner ); + return unique_ptr( new MACGeneratorScenarioRunner ); } if( aType == BatchRunner::getXMLNameStatic() ){ - return auto_ptr( new BatchRunner ); + return unique_ptr( new BatchRunner ); } if( aType == PolicyTargetRunner::getXMLNameStatic() ){ - return auto_ptr( new PolicyTargetRunner ); + return unique_ptr( new PolicyTargetRunner ); } // Unknown type. ILogger& mainLog = ILogger::getLogger( "main_log" ); mainLog.setLevel( ILogger::ERROR ); mainLog << "Could not create Scenario Runner of type " << aType << "." << endl; - return auto_ptr(); + return unique_ptr(); } /*! * \brief Return a new instance of the SingleScenarioRunner. - * \return An auto_ptr with a newly created SingleScenarioRunner. + * \return An unique_ptr with a newly created SingleScenarioRunner. */ -auto_ptr ScenarioRunnerFactory::createSingleScenarioRunner() { - return auto_ptr( new SingleScenarioRunner ); +unique_ptr ScenarioRunnerFactory::createSingleScenarioRunner() { + return unique_ptr( new SingleScenarioRunner ); } /*! @@ -114,9 +114,9 @@ auto_ptr ScenarioRunnerFactory::createSingleScenarioRunner * \param aExcludedTypes A list of types that should not be created. * \return ISingleScenarioRunner type as defined by the configuration file. */ -auto_ptr ScenarioRunnerFactory::createDefault( const list& aExcludedTypes ){ +unique_ptr ScenarioRunnerFactory::createDefault( const list& aExcludedTypes ){ const Configuration* conf = Configuration::getInstance(); - auto_ptr defaultRunner; + unique_ptr defaultRunner; // Determine the correct type of ScenarioRunner to create. Note that this // ordering must be preserved because certain scenario runners can contain // other scenario runners. diff --git a/cvs/objects/containers/source/world.cpp b/cvs/objects/containers/source/world.cpp index a2a8277438..daa6117423 100644 --- a/cvs/objects/containers/source/world.cpp +++ b/cvs/objects/containers/source/world.cpp @@ -350,6 +350,10 @@ void World::setEmissions( int period ) { EmissionsSummer ocSummer( "OC" ); EmissionsSummer bcawbSummer( "BC_AWB" ); EmissionsSummer ocawbSummer( "OC_AWB" ); + EmissionsSummer nh3Summer( "NH3" ); + EmissionsSummer nh3agrSummer( "NH3_AGR" ); + EmissionsSummer nh3awbSummer( "NH3_AWB" ); + // Group the EmissionsSummer together for improved performance. GroupedEmissionsSummer allSummer; @@ -396,6 +400,10 @@ void World::setEmissions( int period ) { allSummer.addEmissionsSummer( &ocSummer ); allSummer.addEmissionsSummer( &bcawbSummer ); allSummer.addEmissionsSummer( &ocawbSummer ); + allSummer.addEmissionsSummer( &nh3Summer ); + allSummer.addEmissionsSummer( &nh3agrSummer ); + allSummer.addEmissionsSummer( &nh3awbSummer ); + const double TG_TO_PG = 1000; const double N_TO_N2O = 1.571132; @@ -416,19 +424,42 @@ void World::setEmissions( int period ) { // Only set emissions if they are valid. If these are not set // MAGICC will use the default values. if( co2Summer.areEmissionsSet( period ) ){ + // Note: a climate model will either take the net or gross +/- + // but not both, thus we make both available mClimateModel->setEmissions( "CO2", period, ( co2Summer.getEmissions( period ) + co2fugSummer.getEmissions( period ) ) / TG_TO_PG ); + mClimateModel->setEmissions( "CO2FFIEmissions", period, + ( co2Summer.getEmissionsPositive( period ) + + co2fugSummer.getEmissions( period ) ) + / TG_TO_PG ); + // the emissions summer will produce negative emissions + // however the climate model wants positive uptake so we apply the + // negate here + mClimateModel->setEmissions( "CO2DACCCSUptake", period, + -co2Summer.getEmissionsNegative( period ) + / TG_TO_PG ); } const int currYear = scenario->getModeltime()->getper_to_yr( period ); const int startYear = currYear - scenario->getModeltime()->gettimestep( period ) + 1; for ( int i = startYear; i <= currYear; i++ ) { if( co2LandUseSummer.areEmissionsSet( i ) ){ + // Note: a climate model will either take the net or gross +/- + // but not both, thus we make both available mClimateModel->setLUCEmissions( "CO2NetLandUse", i, co2LandUseSummer.getEmissions( i ) / TG_TO_PG ); + mClimateModel->setLUCEmissions( "CO2EmissionsLandUse", i, + co2LandUseSummer.getEmissionsPositive( i ) + / TG_TO_PG ); + // the emissions summer will produce negative emissions + // however the climate model wants positive uptake so we apply the + // negate here + mClimateModel->setLUCEmissions( "CO2UptakeLandUse", i, + -co2LandUseSummer.getEmissionsNegative( i ) + / TG_TO_PG ); } } @@ -540,9 +571,11 @@ void World::setEmissions( int period ) { // For models that need ktonnes of HFC245fa (no single model should implement both of these): mClimateModel->setEmissions("HFC245fa", period, hfc245faSummer.getEmissions(period)+ - hfc32Summer.getEmissions( period ) * HFC32_TO_245 + hfc365mfcSummer.getEmissions( period ) * HFC365_TO_245 + hfc152aSummer.getEmissions( period ) * HFC152_TO_245); + // hector will take HFC32 seperately + mClimateModel->setEmissions( "HFC32", period, + hfc32Summer.getEmissions( period )); } // MAGICC needs this in tons of VOC. Input is in TgC @@ -575,12 +608,24 @@ void World::setEmissions( int period ) { hfc227eaSummer.getEmissions( period ) ); } - if( hfc143aSummer.areEmissionsSet( period ) && hfc23Summer.areEmissionsSet( period ) && hfc236faSummer.areEmissionsSet( period ) ){ + if( hfc143aSummer.areEmissionsSet( period ) && hfc236faSummer.areEmissionsSet( period ) ){ mClimateModel->setEmissions( "HFC143a", period, hfc143aSummer.getEmissions( period ) + - hfc23Summer.getEmissions( period ) * HFC23_TO_143 + hfc236faSummer.getEmissions( period ) * HFC236_TO_143); } + + if( hfc23Summer.areEmissionsSet( period ) ){ + mClimateModel->setEmissions( "HFC23", period, + hfc23Summer.getEmissions( period ) ); + } + + if( nh3Summer.areEmissionsSet(period) ) { + mClimateModel->setEmissions( "NH3", + period, + nh3Summer.getEmissions( period ) + + nh3awbSummer.getEmissions( period ) + + nh3agrSummer.getEmissions( period ) ); + } } void World::runClimateModel() { diff --git a/cvs/objects/demographics/include/age_cohort.h b/cvs/objects/demographics/include/age_cohort.h index 9b6de4c9d8..b07f1f3905 100644 --- a/cvs/objects/demographics/include/age_cohort.h +++ b/cvs/objects/demographics/include/age_cohort.h @@ -84,8 +84,8 @@ class AgeCohort: public IVisitable { void accept( IVisitor* aVisitor, const int aPeriod ) const; protected: std::string ageGroup; //!< age group name - std::auto_ptr male; //!< male gender object - std::auto_ptr female; //!< male gender object + std::unique_ptr male; //!< male gender object + std::unique_ptr female; //!< male gender object private: mutable int mLowerAgeBound; mutable int mUpperAgeBound; diff --git a/cvs/objects/demographics/include/demographic.h b/cvs/objects/demographics/include/demographic.h index fca0d19e3c..958468aa96 100644 --- a/cvs/objects/demographics/include/demographic.h +++ b/cvs/objects/demographics/include/demographic.h @@ -105,7 +105,7 @@ class Demographic: public IVisitable, private boost::noncopyable { typedef std::vector::const_iterator CPopulationIterator; //! A binary functor to compare Population years so that they can be sorted. - struct YearComparator : public std::binary_function { + struct YearComparator { /*! * \brief Determine if the left hand operand is less than the right. * \param lhs The left hand side operand for the sort comparison. diff --git a/cvs/objects/demographics/source/age_cohort.cpp b/cvs/objects/demographics/source/age_cohort.cpp index 84fa4749c4..8ffa95924d 100644 --- a/cvs/objects/demographics/source/age_cohort.cpp +++ b/cvs/objects/demographics/source/age_cohort.cpp @@ -64,7 +64,7 @@ AgeCohort::AgeCohort() { mUpperAgeBound = -1; } -//! Default Destructor. Needed because we are using auto_ptr so that we avoid +//! Default Destructor. Needed because we are using unique_ptr so that we avoid //! destroying incomplete types. AgeCohort::~AgeCohort(){ } diff --git a/cvs/objects/doxygen/FAQ.txt b/cvs/objects/doxygen/FAQ.txt index 5d858abd23..d37a2295ae 100644 --- a/cvs/objects/doxygen/FAQ.txt +++ b/cvs/objects/doxygen/FAQ.txt @@ -79,13 +79,13 @@ there should be a copy constructor and assignment operator, as the three work in not be logical, then a private copy constructor and assignment operator should be defined to prevent a user or the compiler from accidentally calling the incorrect copy or assignment operator. -\subsection faqitem8 What is an auto_ptr and how do I use it? -An auto_ptr is a member of the standard library which is used to contain a pointer a dynamically allocated object. The purpose of an auto_ptr is to automatically +\subsection faqitem8 What is an unique_ptr and how do I use it? +An unique_ptr is a member of the standard library which is used to contain a pointer a dynamically allocated object. The purpose of an unique_ptr is to automatically handle the deallocation of memory when an object goes out of scope. This allows the use of dynamic memory, which is often advantagous, without having to remember to -deallocate the memory. To use an auto_ptr, you must include the file. Then declare an auto_ptr as auto_ptr( new Object ). If you need to declare the auto_ptr -prior to allocation, such as when using it as a member variable, you must use the auto_ptr's reset function to assign the new object to the auto_ptr. If you need to pass the object to -another function, use the get function of the auto_ptr. Do not pass the auto_ptr itself, as only one auto_ptr can have responsibility for an object, so copying an auto_ptr assigns -the memory to the auto_ptr you are copying into. auto_ptrs may not be used inside containers, such as vectors. This may compile, but will cause runtime errors. +deallocate the memory. To use an unique_ptr, you must include the file. Then declare an unique_ptr as unique_ptr( new Object ). If you need to declare the unique_ptr +prior to allocation, such as when using it as a member variable, you must use the unique_ptr's reset function to assign the new object to the unique_ptr. If you need to pass the object to +another function, use the get function of the unique_ptr. Do not pass the unique_ptr itself, as only one unique_ptr can have responsibility for an object, so copying an unique_ptr assigns +the memory to the unique_ptr you are copying into. unique_ptrs may not be used inside containers, such as vectors. This may compile, but will cause runtime errors. \subsection faqitem9 Why is iosfwd included in header files instead of iostream? iosfwd is the forward declared version of iostream. iostream is a very large file, and should not be included in a header file unless the class contains a member variable of an iostream type. @@ -102,4 +102,4 @@ and DemandMarket::addToSupply are also overridden so that DemandMarket::getDeman equal to the price. These are the functions used from outside the Marketplace, the Market also contains a set of functions with the word "Raw" in the name which return or set the true values of the Market::price, Market::supply and Market::demand variables. These are the functions used by the Solver to clear the markets. -*/ \ No newline at end of file +*/ diff --git a/cvs/objects/doxygen/STLDefs.txt b/cvs/objects/doxygen/STLDefs.txt index ba87ce79fd..6e324bb5c1 100644 --- a/cvs/objects/doxygen/STLDefs.txt +++ b/cvs/objects/doxygen/STLDefs.txt @@ -3,6 +3,6 @@ namespace std { template class vector { public: T element; }; //! A dummy definition of the stl map class which helps doxygen to produce better documentation. template class map { public: Key key; Value value; }; - //! A dummy definition of the stl auto_ptr class which helps doxygen to produce better documentation. - template class auto_ptr { public: P element; }; -} \ No newline at end of file + //! A dummy definition of the stl unique_ptr class which helps doxygen to produce better documentation. + template class unique_ptr { public: P element; }; +} diff --git a/cvs/objects/emissions/include/aghg.h b/cvs/objects/emissions/include/aghg.h index b5fb90d878..aa8a9a8084 100644 --- a/cvs/objects/emissions/include/aghg.h +++ b/cvs/objects/emissions/include/aghg.h @@ -208,7 +208,7 @@ class AGHG: public INamed, public IVisitable, private boost::noncopyable //! Pre-located market which has been cached from the marketplace to get the price //! of this ghg and add demands to the market. - std::auto_ptr mCachedMarket; + std::unique_ptr mCachedMarket; /*! * \brief XML debug output stream for derived classes diff --git a/cvs/objects/emissions/include/emissions_summer.h b/cvs/objects/emissions/include/emissions_summer.h index ae56ecba4f..87fe7a7412 100644 --- a/cvs/objects/emissions/include/emissions_summer.h +++ b/cvs/objects/emissions/include/emissions_summer.h @@ -64,6 +64,10 @@ class EmissionsSummer : public DefaultVisitor { // Non-IVisitor interface methods. double getEmissions( const int aPeriod ) const; + + double getEmissionsPositive( const int aPeriod ) const; + + double getEmissionsNegative( const int aPeriod ) const; double areEmissionsSet( const int aPeriod ) const; @@ -72,8 +76,11 @@ class EmissionsSummer : public DefaultVisitor { //! The name of the GHG being summed. const std::string mGHGName; - //! The current sum. - objects::PeriodVector mEmissionsByPeriod; + //! The gross positive sum of emissions + objects::PeriodVector mEmissionsByPeriodPositive; + + //! The gross negative sum of emissions + objects::PeriodVector mEmissionsByPeriodNegative; }; /*! diff --git a/cvs/objects/emissions/include/luc_emissions_summer.h b/cvs/objects/emissions/include/luc_emissions_summer.h index 4ba695cf44..2ee17874a2 100644 --- a/cvs/objects/emissions/include/luc_emissions_summer.h +++ b/cvs/objects/emissions/include/luc_emissions_summer.h @@ -64,14 +64,24 @@ class LUCEmissionsSummer : public DefaultVisitor { // Non-IVisitor interface methods. double getEmissions( const int aYear ) const; + + double getEmissionsPositive( const int aYear ) const; + + double getEmissionsNegative( const int aYear ) const; double areEmissionsSet( const int aYear ) const; private: //! The name of the GHG being summed. const std::string mGHGName; - //! The current sum. - objects::YearVector mEmissionsByYear; + //! The gross positive above ground LUC emissions + objects::YearVector mPositiveEmissionsByYear; + + //! The gross negative above ground LUC *emissions* (i.e. uptake however values contained are < 0) + objects::YearVector mNegativeEmissionsByYear; + + // The net below ground LUC emissions + objects::YearVector mBelowTotalEmissionsByYear; }; #endif // _LUC_EMISSIONS_SUMMER_H_ diff --git a/cvs/objects/emissions/source/emissions_summer.cpp b/cvs/objects/emissions/source/emissions_summer.cpp index 2c12feea92..437708bae7 100644 --- a/cvs/objects/emissions/source/emissions_summer.cpp +++ b/cvs/objects/emissions/source/emissions_summer.cpp @@ -60,28 +60,56 @@ mGHGName( aGHGName ){ */ void EmissionsSummer::startVisitGHG( const AGHG* aGHG, const int aPeriod ){ if( aGHG->getName() == mGHGName ){ - mEmissionsByPeriod[ aPeriod ] += aGHG->getEmission( aPeriod ); + double currEmissions = aGHG->getEmission( aPeriod ); + if(currEmissions >= 0) { + mEmissionsByPeriodPositive[ aPeriod ] += currEmissions; + } + else { + mEmissionsByPeriodNegative[ aPeriod ] += currEmissions; + } } } -/*! \brief Get the current emissions sum. -* \param aPeriod Model period for which to get emissions. -* \return The emissions sum. -*/ +/*! \brief Get the total net emissions sum. + * \param aPeriod Model period for which to get emissions. + * \return The emissions sum. + */ double EmissionsSummer::getEmissions( const int aPeriod ) const { // The value may not be initialized if there were no GHGs. // The default zero will be correct though. // The emissions sum may be negative if uptake is occurring. - return mEmissionsByPeriod[ aPeriod ]; + return mEmissionsByPeriodPositive[ aPeriod ] + mEmissionsByPeriodNegative[ aPeriod ]; +} + +/*! \brief Get the gross positive emissions sum. + * \param aPeriod Model period for which to get emissions. + * \return The emissions sum. + */ +double EmissionsSummer::getEmissionsPositive( const int aPeriod ) const { + // The value may not be initialized if there were no GHGs. + // The default zero will be correct though. + + return mEmissionsByPeriodPositive[ aPeriod ]; +} + +/*! \brief Get the gross negative emissions sum. + * \param aPeriod Model period for which to get emissions. + * \return The emissions sum. + */ +double EmissionsSummer::getEmissionsNegative( const int aPeriod ) const { + // The value may not be initialized if there were no GHGs. + // The default zero will be correct though. + + return mEmissionsByPeriodNegative[ aPeriod ]; } /*! \brief Return whether any emissions were set for the period. -* \param aPeriod Model period. -* \return Whether any emissions were set. -*/ + * \param aPeriod Model period. + * \return Whether any emissions were set. + */ double EmissionsSummer::areEmissionsSet( const int aPeriod ) const { - return mEmissionsByPeriod[ aPeriod ].isInited(); + return mEmissionsByPeriodPositive[ aPeriod ].isInited() || mEmissionsByPeriodNegative[ aPeriod ].isInited(); } /*! \brief Get the GHG name. diff --git a/cvs/objects/emissions/source/luc_emissions_summer.cpp b/cvs/objects/emissions/source/luc_emissions_summer.cpp index bfb6fcb53c..149ffbb10b 100644 --- a/cvs/objects/emissions/source/luc_emissions_summer.cpp +++ b/cvs/objects/emissions/source/luc_emissions_summer.cpp @@ -52,7 +52,10 @@ using namespace std; */ LUCEmissionsSummer::LUCEmissionsSummer( const string& aGHGName ): mGHGName( aGHGName ), - mEmissionsByYear( scenario->getModeltime()->getStartYear(), scenario->getModeltime()->getEndYear() ) + mPositiveEmissionsByYear( scenario->getModeltime()->getStartYear(), scenario->getModeltime()->getEndYear() ), + mNegativeEmissionsByYear( scenario->getModeltime()->getStartYear(), scenario->getModeltime()->getEndYear() ), + mBelowTotalEmissionsByYear( scenario->getModeltime()->getStartYear(), scenario->getModeltime()->getEndYear() ) + { } @@ -64,35 +67,63 @@ void LUCEmissionsSummer::startVisitCarbonCalc( const ICarbonCalc* aCarbonCalc, if( mGHGName == "CO2NetLandUse" ){ const int startYear = currYear - scenario->getModeltime()->gettimestep( aPeriod ) + 1; for ( int year = startYear; year <= currYear; year++ ) { - mEmissionsByYear[ year ] += aCarbonCalc->getNetLandUseChangeEmission( year ); - } - } - else if( mGHGName == MagiccModel::getnetDefor80sName() ){ - double netDef80s = 0; - for( int year = 1980; year < 1990; ++year){ - netDef80s += ( aCarbonCalc->getNetLandUseChangeEmission( year ) + - aCarbonCalc->getNetLandUseChangeEmission( year + 1 ) ) / 2; + // note that ICarbonCalc keeps track of net above LUC emissions + // and gross positive above LUC emissions + // thus we will back out the gross negative above from these + double netAboveLUC = aCarbonCalc->getNetLandUseChangeEmissionAbove( year ); + double belowLUC = aCarbonCalc->getNetLandUseChangeEmissionBelow( year ); + double grossPositiveAboveLUC = aCarbonCalc->getGrossPositiveLandUseChangeEmissionAbove( year ); + double grossNegativeAbove = netAboveLUC - grossPositiveAboveLUC; + mPositiveEmissionsByYear[ year ] += grossPositiveAboveLUC; + mNegativeEmissionsByYear[ year ] += grossNegativeAbove; + mBelowTotalEmissionsByYear[ year ] += belowLUC; } - mEmissionsByYear[ currYear ] += netDef80s / 10; // Return decadal average } } -/*! \brief Get the current emissions sum. -* \param aYear Model year for which to get emissions. -* \return The emissions sum. -*/ +/*! \brief Get the net LUC emissions sum. + * \param aYear Model year for which to get emissions. + * \return The emissions sum. + */ double LUCEmissionsSummer::getEmissions( const int aYear ) const { // The value may not be initialized if there were no GHGs, or no AgLU for // net land use change emissions. The default zero will be correct though. // The emissions sum may be negative if uptake is occurring. - return mEmissionsByYear[ aYear ]; + return mPositiveEmissionsByYear[ aYear ] + mNegativeEmissionsByYear[ aYear ] + mBelowTotalEmissionsByYear[ aYear ]; +} + +/*! \brief Get the gross positive LUC emissions sum. + * \param aYear Model year for which to get emissions. + * \return The positive emissions sum. + */ +double LUCEmissionsSummer::getEmissionsPositive( const int aYear ) const { + // The value may not be initialized if there were no GHGs, or no AgLU for + // net land use change emissions. The default zero will be correct though. + + // The emissions sum may be negative if uptake is occurring. + double belowPosEmiss = std::max(mBelowTotalEmissionsByYear[ aYear ].get(), 0.0); + return mPositiveEmissionsByYear[ aYear ] + belowPosEmiss; +} + +/*! \brief Get the gross negative LUC emissions sum. + * \details The value returned is akin to uptake but negative. + * \param aYear Model year for which to get emissions. + * \return The emissions sum. + */ +double LUCEmissionsSummer::getEmissionsNegative( const int aYear ) const { + // The value may not be initialized if there were no GHGs, or no AgLU for + // net land use change emissions. The default zero will be correct though. + + // The emissions sum may be negative if uptake is occurring. + double belowNegEmiss = std::min(mBelowTotalEmissionsByYear[ aYear ].get(), 0.0); + return mNegativeEmissionsByYear[ aYear ] + belowNegEmiss; } /*! \brief Return whether any emissions were set for the year. -* \param aYear Model year. -* \return Whether any emissions were set. -*/ + * \param aYear Model year. + * \return Whether any emissions were set. + */ double LUCEmissionsSummer::areEmissionsSet( const int aYear ) const { - return mEmissionsByYear[ aYear ].isInited(); + return mPositiveEmissionsByYear[ aYear ].isInited() || mNegativeEmissionsByYear[ aYear ].isInited(); } diff --git a/cvs/objects/emissions/source/nonco2_emissions.cpp b/cvs/objects/emissions/source/nonco2_emissions.cpp index 1b44e924bd..94b39ee048 100644 --- a/cvs/objects/emissions/source/nonco2_emissions.cpp +++ b/cvs/objects/emissions/source/nonco2_emissions.cpp @@ -92,7 +92,7 @@ void NonCO2Emissions::copy( const NonCO2Emissions& aOther ) { mEmissionsCoef = aOther.mEmissionsCoef; - // Deep copy the auto_ptr + // Deep copy the unique_ptr if( aOther.mEmissionsDriver ){ delete mEmissionsDriver; mEmissionsDriver = aOther.mEmissionsDriver->clone(); diff --git a/cvs/objects/functions/include/energy_input.h b/cvs/objects/functions/include/energy_input.h index d1cfbba53d..e7ad84a265 100644 --- a/cvs/objects/functions/include/energy_input.h +++ b/cvs/objects/functions/include/energy_input.h @@ -205,7 +205,7 @@ class EnergyInput: public MiniCAMInput //! A pre-located market which has been cahced from the marketplace to get //! the price and add demands to. - std::auto_ptr mCachedMarket; + std::unique_ptr mCachedMarket; private: const static std::string XML_REPORTING_NAME; //!< tag name for reporting xml db diff --git a/cvs/objects/functions/source/building_node_input.cpp b/cvs/objects/functions/source/building_node_input.cpp index e2ad89151d..40d7a0a332 100644 --- a/cvs/objects/functions/source/building_node_input.cpp +++ b/cvs/objects/functions/source/building_node_input.cpp @@ -82,7 +82,7 @@ void BuildingNodeInput::completeInit( const string& aRegionName, const string& a const IInfo* aTechInfo) { // create internal gains market for this type of building - auto_ptr internalGainsInfo( InfoFactory::constructInfo( aTechInfo, mInternalGainsMarketname ) ); + unique_ptr internalGainsInfo( InfoFactory::constructInfo( aTechInfo, mInternalGainsMarketname ) ); internalGainsInfo->setString( "output-unit", mInternalGainsUnit ); if( SectorUtils::createTrialSupplyMarket( aRegionName, mInternalGainsMarketname, internalGainsInfo.get() ) ){ // set initial trial supplies from the parsed vector @@ -100,7 +100,7 @@ void BuildingNodeInput::completeInit( const string& aRegionName, const string& a // we sort the child inputs now to make things easier on us when it comes time to merge // node inputs in copyParamsInto. - util::NameComparator comp; + util::NameComparator comp; sort( mNestedInputs.begin(), mNestedInputs.end(), comp ); // have all contained inputs do completeInit as well diff --git a/cvs/objects/functions/source/ctax_input.cpp b/cvs/objects/functions/source/ctax_input.cpp index a666d4151d..f0111519f5 100644 --- a/cvs/objects/functions/source/ctax_input.cpp +++ b/cvs/objects/functions/source/ctax_input.cpp @@ -95,7 +95,7 @@ CTaxInput::CTaxInput() * \brief Destructor. * \note An explicit constructor must be defined to avoid the compiler inlining * it in the header file before the header file for the type contained in - * the auto_ptr is included. + * the unique_ptr is included. */ CTaxInput::~CTaxInput() { } diff --git a/cvs/objects/functions/source/energy_input.cpp b/cvs/objects/functions/source/energy_input.cpp index dbcab67cbd..7d19944507 100644 --- a/cvs/objects/functions/source/energy_input.cpp +++ b/cvs/objects/functions/source/energy_input.cpp @@ -94,8 +94,7 @@ const string& EnergyInput::getXMLName() const{ } //! Constructor -EnergyInput::EnergyInput() : - mCachedMarket( 0 ) +EnergyInput::EnergyInput() { mCoefficient = 0; @@ -106,7 +105,7 @@ EnergyInput::EnergyInput() : * \brief Destructor. * \note An explicit constructor must be defined to avoid the compiler inlining * it in the header file before the header file for the type contained in - * the auto_ptr is included. + * the unique_ptr is included. */ EnergyInput::~EnergyInput() { delete mCoefficient; diff --git a/cvs/objects/functions/source/input_subsidy.cpp b/cvs/objects/functions/source/input_subsidy.cpp index d06f0ae9cd..c9c58d8854 100644 --- a/cvs/objects/functions/source/input_subsidy.cpp +++ b/cvs/objects/functions/source/input_subsidy.cpp @@ -103,7 +103,7 @@ InputSubsidy::InputSubsidy() * \brief Destructor. * \note An explicit constructor must be defined to avoid the compiler inlining * it in the header file before the header file for the type contained in - * the auto_ptr is included. + * the unique_ptr is included. */ InputSubsidy::~InputSubsidy() { } diff --git a/cvs/objects/functions/source/input_tax.cpp b/cvs/objects/functions/source/input_tax.cpp index a703775e8f..57b68a9fd1 100644 --- a/cvs/objects/functions/source/input_tax.cpp +++ b/cvs/objects/functions/source/input_tax.cpp @@ -103,7 +103,7 @@ InputTax::InputTax() * \brief Destructor. * \note An explicit constructor must be defined to avoid the compiler inlining * it in the header file before the header file for the type contained in - * the auto_ptr is included. + * the unique_ptr is included. */ InputTax::~InputTax() { } diff --git a/cvs/objects/functions/source/node_input.cpp b/cvs/objects/functions/source/node_input.cpp index 336dd896a1..d27014dc35 100644 --- a/cvs/objects/functions/source/node_input.cpp +++ b/cvs/objects/functions/source/node_input.cpp @@ -91,7 +91,7 @@ void NodeInput::completeInit( const string& aRegionName, // we sort the child inputs now to make things easier on us when it comes time to merge // node inputs in copyParamsInto. - util::NameComparator comp; + util::NameComparator comp; sort( mNestedInputs.begin(), mNestedInputs.end(), comp ); // have all contained inputs do completeInit as well diff --git a/cvs/objects/functions/source/relative_cost_logit.cpp b/cvs/objects/functions/source/relative_cost_logit.cpp index 1d5c322b82..9da96e04b8 100644 --- a/cvs/objects/functions/source/relative_cost_logit.cpp +++ b/cvs/objects/functions/source/relative_cost_logit.cpp @@ -89,7 +89,7 @@ void RelativeCostLogit::initCalc( const string& aRegionName, const string& aCont // Illegal value. For relative cost logit it will not affect sharing and // we can continue operating the model normally so just generate a warning ILogger &calibrationLog = ILogger::getLogger("calibration_log"); - ILogger::WarningLevel oldlvl = calibrationLog.setLevel(ILogger::WARNING); + ILogger::WarningLevel oldlvl = calibrationLog.setLevel(ILogger::DEBUG); calibrationLog << "In " << aRegionName << ", " << aContainerName<< ": invalid or uninitialized base value parameter " << mBaseValue << endl; calibrationLog.setLevel(oldlvl); diff --git a/cvs/objects/land_allocator/include/aland_allocator_item.h b/cvs/objects/land_allocator/include/aland_allocator_item.h index 4159b02a80..b43b5df76c 100644 --- a/cvs/objects/land_allocator/include/aland_allocator_item.h +++ b/cvs/objects/land_allocator/include/aland_allocator_item.h @@ -465,14 +465,12 @@ class ALandAllocatorItem : public TreeItem, ) }; -typedef std::unary_function SearchPredicate; - /*! * \brief SearchPredicate that finds an item with the desired type and name. * \details This predicate should be passed to TreeItem's findItem method. * It will be called on each item during the search. */ -struct MatchesTypeAndName : public SearchPredicate { +struct MatchesTypeAndName { /*! * \brief Enum that stores the desired type. diff --git a/cvs/objects/main/source/main.cpp b/cvs/objects/main/source/main.cpp index 3c52436f7b..09b7fcc13b 100644 --- a/cvs/objects/main/source/main.cpp +++ b/cvs/objects/main/source/main.cpp @@ -170,9 +170,9 @@ int main( int argc, char *argv[] ) { // created. list exclusionList; - // Create an auto_ptr to the scenario runner. This will automatically + // Create an unique_ptr to the scenario runner. This will automatically // deallocate memory. - auto_ptr runner = ScenarioRunnerFactory::createDefault( exclusionList ); + unique_ptr runner = ScenarioRunnerFactory::createDefault( exclusionList ); // Setup the scenario. success = runner->setupScenarios( timer ); diff --git a/cvs/objects/marketplace/include/market.h b/cvs/objects/marketplace/include/market.h index f9f5f5135d..baff52ff15 100644 --- a/cvs/objects/marketplace/include/market.h +++ b/cvs/objects/marketplace/include/market.h @@ -236,7 +236,7 @@ class Market: public IYeared, public IVisitable, private boost::noncopyable #endif //! Object containing information related to the market. - std::auto_ptr mMarketInfo; + std::unique_ptr mMarketInfo; //! Weak pointer to the container that hold this market. The container will //! keep shared market data such as name and contained regions so we hold a diff --git a/cvs/objects/marketplace/include/market_locator.h b/cvs/objects/marketplace/include/market_locator.h index cf5e31cfc8..89709f21fb 100644 --- a/cvs/objects/marketplace/include/market_locator.h +++ b/cvs/objects/marketplace/include/market_locator.h @@ -123,7 +123,7 @@ class MarketLocator typedef HashMap > SectorNodeList; //! A list of sectors contained by this market or region. - std::auto_ptr mSectorNodeList; + std::unique_ptr mSectorNodeList; //! The region or market area name. const std::string mName; @@ -141,11 +141,11 @@ class MarketLocator //! A list of market areas each containing a list of sectors contained by //! the market. - std::auto_ptr mMarketList; + std::unique_ptr mMarketList; //! A list of regions each containing a list of of sectors contained by the //! region. - std::auto_ptr mRegionList; + std::unique_ptr mRegionList; }; // Inline definitions. diff --git a/cvs/objects/marketplace/include/marketplace.h b/cvs/objects/marketplace/include/marketplace.h index d427b7222a..25820e9477 100644 --- a/cvs/objects/marketplace/include/marketplace.h +++ b/cvs/objects/marketplace/include/marketplace.h @@ -182,7 +182,7 @@ class Marketplace: public IVisitable, private boost::noncopyable IInfo* getMarketInfo( const std::string& aGoodName, const std::string& aRegionName, const int aPeriod, const bool aMustExist ); - std::auto_ptr locateMarket( const std::string& aGoodName, const std::string& aRegionName, + std::unique_ptr locateMarket( const std::string& aGoodName, const std::string& aRegionName, const int aPeriod ) const; void accept( IVisitor* aVisitor, const int aPeriod ) const; @@ -215,13 +215,13 @@ class Marketplace: public IVisitable, private boost::noncopyable ) //! An object which determines the correct market number. - std::auto_ptr mMarketLocator; + std::unique_ptr mMarketLocator; //! A gobal object which tracks dependencies between all of the model activities //! and their linkages to their respective markets. It can be used to create a //! sorted global ordering or get an inorder list of model activities that are //! affected by changing the price of a single market. - std::auto_ptr mDependencyFinder; + std::unique_ptr mDependencyFinder; //! Flag indicating whether the next call to world->calc() will be part of a partial derivative calculation static bool mIsDerivativeCalc; diff --git a/cvs/objects/marketplace/source/market.cpp b/cvs/objects/marketplace/source/market.cpp index f32e789fc3..c588fe78a5 100644 --- a/cvs/objects/marketplace/source/market.cpp +++ b/cvs/objects/marketplace/source/market.cpp @@ -113,7 +113,7 @@ mMarketInfo( InfoFactory::constructInfo( 0, aContainer->getName() ) ) mOriginal_price = 0.0; } -//! Destructor. This is needed because of the auto_ptr. +//! Destructor. This is needed because of the unique_ptr. Market::~Market(){ } diff --git a/cvs/objects/marketplace/source/marketplace.cpp b/cvs/objects/marketplace/source/marketplace.cpp index c71c03ec4a..98a98cbc8a 100644 --- a/cvs/objects/marketplace/source/marketplace.cpp +++ b/cvs/objects/marketplace/source/marketplace.cpp @@ -855,11 +855,11 @@ IInfo* Marketplace::getMarketInfo( const string& aGoodName, const string& aRegio * be a valid object regardless of if the market was not found. * \see CachedMarket */ -auto_ptr Marketplace::locateMarket( const string& aGoodName, const string& aRegionName, +unique_ptr Marketplace::locateMarket( const string& aGoodName, const string& aRegionName, const int aPeriod ) const { const int marketNumber = mMarketLocator->getMarketNumber( aRegionName, aGoodName ); - auto_ptr locatedMarket( new CachedMarket( aGoodName, aRegionName, aPeriod, + unique_ptr locatedMarket( new CachedMarket( aGoodName, aRegionName, aPeriod, marketNumber != MarketLocator::MARKET_NOT_FOUND ? mMarkets[ marketNumber ]->getMarket( aPeriod ) : 0 ) ); return locatedMarket; diff --git a/cvs/objects/parallel/source/gcam_parallel.cpp b/cvs/objects/parallel/source/gcam_parallel.cpp index a5dd4e41b9..48a45d6258 100644 --- a/cvs/objects/parallel/source/gcam_parallel.cpp +++ b/cvs/objects/parallel/source/gcam_parallel.cpp @@ -111,7 +111,7 @@ void GcamParallel::makeTBBFlowGraph( const MarketDependencyFinder& aDependencyFi tbb::flow::broadcast_node& head = aTBBGraph.mHead; ILogger& pgLog = ILogger::getLogger( "parallel-grain-log" ); - pgLog.setLevel( ILogger::NOTICE ); + pgLog.setLevel( ILogger::DEBUG ); // first read the information out of the dependency finder into an // adjacency matrix for easy as we are going to have to take multiple diff --git a/cvs/objects/reporting/include/xml_db_outputter.h b/cvs/objects/reporting/include/xml_db_outputter.h index 5abe752695..5848d4c4fd 100644 --- a/cvs/objects/reporting/include/xml_db_outputter.h +++ b/cvs/objects/reporting/include/xml_db_outputter.h @@ -218,8 +218,8 @@ class XMLDBOutputter : public DefaultVisitor { objects::PeriodVector mCurrIndirectEmissions; //! Tabs object. - std::auto_ptr mTabs; - + std::unique_ptr mTabs; + //! Weak pointer to the current technology object. const Technology* mCurrentTechnology; @@ -257,9 +257,9 @@ class XMLDBOutputter : public DefaultVisitor { //! An auto pointer to all the JNI data that needs to be maintained through out //! the like of the XMLDBOutputter. - const std::auto_ptr mJNIContainer; + const std::unique_ptr mJNIContainer; - static std::auto_ptr createContainer( const bool aTestingOnly ); + static std::unique_ptr createContainer( const bool aTestingOnly ); #endif static const std::string createContainerName( const std::string& aScenarioName ); diff --git a/cvs/objects/reporting/source/xml_db_outputter.cpp b/cvs/objects/reporting/source/xml_db_outputter.cpp index 39ea00c845..b6de1913e7 100644 --- a/cvs/objects/reporting/source/xml_db_outputter.cpp +++ b/cvs/objects/reporting/source/xml_db_outputter.cpp @@ -218,7 +218,7 @@ XMLDBOutputter::~XMLDBOutputter(){ */ bool XMLDBOutputter::checkJavaWorking() { #if( __HAVE_JAVA__ ) - auto_ptr testContainer = createContainer( true ); + unique_ptr testContainer = createContainer( true ); // if we get back a null container then some error occured // createContainer would have already print any error messages. return testContainer.get(); @@ -298,9 +298,9 @@ void XMLDBOutputter::finalizeAndClose() { * ready to accept data to write/alter to the database. If an error occurs * a null container will be returned. */ -auto_ptr XMLDBOutputter::createContainer( const bool aTestingOnly ) { +unique_ptr XMLDBOutputter::createContainer( const bool aTestingOnly ) { // Create a Java instance. - auto_ptr jniContainer( new JNIContainer ); + unique_ptr jniContainer( new JNIContainer ); // Ensure the user wants this output const Configuration* conf = Configuration::getInstance(); @@ -1501,12 +1501,39 @@ void XMLDBOutputter::startVisitClimateModel( const IClimateModel* aClimateModel, year ); } - // Global-mean temperature + // Global-mean air temperature for( int year = scenario->getModeltime()->getStartYear(); year <= endingYear; year += outputInterval ) { - writeItemUsingYear( "global-mean-temperature", "degreesC", - aClimateModel->getTemperature( year ), + writeItemUsingYear( "global-mean-air-temperature-native", "degreesC", + aClimateModel->getTemperature( year, false ), + year ); + } + + // Global-mean surface temperature + for( int year = scenario->getModeltime()->getStartYear(); + year <= endingYear; year += outputInterval ) + { + writeItemUsingYear( "global-mean-surface-temperature-native", "degreesC", + aClimateModel->getGmst( year, false ), + year ); + } + + // Global-mean air temperature relative to 1850-1900 mean + for( int year = scenario->getModeltime()->getStartYear(); + year <= endingYear; year += outputInterval ) + { + writeItemUsingYear( "global-mean-air-temperature", "degreesC", + aClimateModel->getTemperature( year, true ), + year ); + } + + // Global-mean surface temperature relative to 1850-1900 mean + for( int year = scenario->getModeltime()->getStartYear(); + year <= endingYear; year += outputInterval ) + { + writeItemUsingYear( "global-mean-surface-temperature", "degreesC", + aClimateModel->getGmst( year, true ), year ); } } @@ -1651,11 +1678,12 @@ void XMLDBOutputter::startVisitCarbonCalc( const ICarbonCalc* aCarbonCalc, const writeItemUsingYear( "land-use-change-emission", "MtC/yr", aCarbonCalc->getNetLandUseChangeEmission( aYear ), aYear ); writeItemUsingYear( "above-land-use-change-emission", "MtC/yr", aCarbonCalc->getNetLandUseChangeEmissionAbove( aYear ), aYear ); writeItemUsingYear( "below-land-use-change-emission", "MtC/yr", aCarbonCalc->getNetLandUseChangeEmissionBelow( aYear ), aYear ); - } + writeItemUsingYear( "above-gross-positive-luc", "MtC/yr", aCarbonCalc->getGrossPositiveLandUseChangeEmissionAbove( aYear ), aYear ); + } - for( int aYear = modeltime->getStartYear(); - aYear <= modeltime->getper_to_yr( modeltime->getmaxper() - 1 ) || aYear == modeltime->getper_to_yr( modeltime->getmaxper() - 1 ); - aYear += outputInterval ){ + { + // carbon densities are not actually changing over time + int aYear = modeltime->getStartYear(); XMLWriteElement( aCarbonCalc->getActualAboveGroundCarbonDensity( aYear ), "above-ground-carbon-density", mBuffer, mTabs.get(), aYear ); XMLWriteElement( aCarbonCalc->getActualBelowGroundCarbonDensity( aYear ), diff --git a/cvs/objects/resources/include/grade.h b/cvs/objects/resources/include/grade.h index 1cff4f47d4..acffd7842e 100644 --- a/cvs/objects/resources/include/grade.h +++ b/cvs/objects/resources/include/grade.h @@ -109,7 +109,7 @@ class Grade: public INamed, public IVisitable, private boost::noncopyable ) //! The Grade's information store. - std::auto_ptr mGradeInfo; + std::unique_ptr mGradeInfo; virtual const std::string& getXMLName() const; }; diff --git a/cvs/objects/resources/include/resource.h b/cvs/objects/resources/include/resource.h index 0b38581559..b7a36eb8c3 100644 --- a/cvs/objects/resources/include/resource.h +++ b/cvs/objects/resources/include/resource.h @@ -101,7 +101,7 @@ class Resource: public AResource { ) //! Pointer to the resource's information store. - std::auto_ptr mResourceInfo; + std::unique_ptr mResourceInfo; virtual const std::string& getXMLName() const; void setMarket( const std::string& aRegionName ); diff --git a/cvs/objects/resources/include/subresource.h b/cvs/objects/resources/include/subresource.h index 4d8f3c11ac..4cc7005233 100644 --- a/cvs/objects/resources/include/subresource.h +++ b/cvs/objects/resources/include/subresource.h @@ -145,7 +145,7 @@ class SubResource: public INamed, public IVisitable, private boost::noncopyable ) //!< The subsector's information store. - std::auto_ptr mSubresourceInfo; + std::unique_ptr mSubresourceInfo; }; #endif // _SUBRESOURCE_H_ diff --git a/cvs/objects/sectors/include/energy_final_demand.h b/cvs/objects/sectors/include/energy_final_demand.h index fbf79e26f8..b272b5f242 100644 --- a/cvs/objects/sectors/include/energy_final_demand.h +++ b/cvs/objects/sectors/include/energy_final_demand.h @@ -208,7 +208,7 @@ class EnergyFinalDemand: public AFinalDemand ) //! Demand function used to calculate unscaled demand. - std::auto_ptr mDemandFunction; + std::unique_ptr mDemandFunction; virtual double calcFinalDemand( const std::string& aRegionName, const Demographic* aDemographics, diff --git a/cvs/objects/sectors/include/sector.h b/cvs/objects/sectors/include/sector.h index c53996a07b..d1a7f61c9d 100644 --- a/cvs/objects/sectors/include/sector.h +++ b/cvs/objects/sectors/include/sector.h @@ -140,7 +140,7 @@ class Sector: public IVisitable, typedef std::vector::const_iterator CSubsectorIterator; //! Pointer to the sector's information store. - std::auto_ptr mSectorInfo; + std::unique_ptr mSectorInfo; typedef ObjECTS::TObjectMetaInfo object_meta_info_type; typedef std::vector object_meta_info_vector_type; diff --git a/cvs/objects/sectors/include/subsector.h b/cvs/objects/sectors/include/subsector.h index c7550c4666..7dd77ae72c 100644 --- a/cvs/objects/sectors/include/subsector.h +++ b/cvs/objects/sectors/include/subsector.h @@ -134,7 +134,7 @@ class Subsector: public INamed, // Some typedefs to make using interpolation rules more readable. typedef std::vector::const_iterator CInterpRuleIterator; - std::auto_ptr mSubsectorInfo; //!< The subsector's information store. + std::unique_ptr mSubsectorInfo; //!< The subsector's information store. virtual void interpolateShareWeights( const int aPeriod ); diff --git a/cvs/objects/solution/solvers/include/bisect_one.h b/cvs/objects/solution/solvers/include/bisect_one.h index 2b13c55925..9157e8d98d 100644 --- a/cvs/objects/solution/solvers/include/bisect_one.h +++ b/cvs/objects/solution/solvers/include/bisect_one.h @@ -81,7 +81,7 @@ class BisectOne: public SolverComponent { //! A filter which will be used to determine which SolutionInfos this solver component //! will look through to determine the worst off market to work on. - std::auto_ptr mSolutionInfoFilter; + std::unique_ptr mSolutionInfoFilter; }; #endif // _BISECT_ONE_H_ diff --git a/cvs/objects/solution/solvers/include/bisect_policy.h b/cvs/objects/solution/solvers/include/bisect_policy.h index 170cb7b99b..0275662311 100644 --- a/cvs/objects/solution/solvers/include/bisect_policy.h +++ b/cvs/objects/solution/solvers/include/bisect_policy.h @@ -81,7 +81,7 @@ class BisectPolicy: public SolverComponent { //! A filter which will be used to determine which SolutionInfos this solver component //! will look through to determine the worst off market to work on if no policy is found. - std::auto_ptr mSolutionInfoFilter; + std::unique_ptr mSolutionInfoFilter; }; #endif // _BISECT_POLICY_H_ diff --git a/cvs/objects/solution/solvers/include/bisect_policy_nr_solver.h b/cvs/objects/solution/solvers/include/bisect_policy_nr_solver.h index 74fe49187a..b5b9d9a55c 100644 --- a/cvs/objects/solution/solvers/include/bisect_policy_nr_solver.h +++ b/cvs/objects/solution/solvers/include/bisect_policy_nr_solver.h @@ -71,10 +71,10 @@ class BisectPolicyNRSolver: public Solver { virtual bool solve( const int aPeriod, const SolutionInfoParamParser* aSolutionInfoParamParser ); private: - std::auto_ptr mLogNewtonRaphson; //!< LogNewtonRaphson solver component. - std::auto_ptr mBisectAll; //!< BisectAll solver component. - std::auto_ptr mBisectOne; //!< BisectOne solver component. - std::auto_ptr mBisectPolicy; //!< BisectPolicy solver component. + std::unique_ptr mLogNewtonRaphson; //!< LogNewtonRaphson solver component. + std::unique_ptr mBisectAll; //!< BisectAll solver component. + std::unique_ptr mBisectOne; //!< BisectOne solver component. + std::unique_ptr mBisectPolicy; //!< BisectPolicy solver component. //! Default solution tolerance, this value may be overridden by at the SolutionInfo level double mDefaultSolutionTolerance; diff --git a/cvs/objects/solution/solvers/include/bisection_nr_solver.h b/cvs/objects/solution/solvers/include/bisection_nr_solver.h index 9ac718a4ff..6769debce8 100644 --- a/cvs/objects/solution/solvers/include/bisection_nr_solver.h +++ b/cvs/objects/solution/solvers/include/bisection_nr_solver.h @@ -70,9 +70,9 @@ class BisectionNRSolver: public Solver { virtual bool solve( const int aPeriod, const SolutionInfoParamParser* aSolutionInfoParamParser ); private: - std::auto_ptr mLogNewtonRaphson; //!< LogNewtonRaphson solver component. - std::auto_ptr mBisectAll; //!< BisectAll solver component. - std::auto_ptr mLogNewtonRaphsonSaveDeriv; //!< LogNewtonRaphsonSaveDerivatives solver component. + std::unique_ptr mLogNewtonRaphson; //!< LogNewtonRaphson solver component. + std::unique_ptr mBisectAll; //!< BisectAll solver component. + std::unique_ptr mLogNewtonRaphsonSaveDeriv; //!< LogNewtonRaphsonSaveDerivatives solver component. //! Default solution tolerance, this value may be overridden at the SolutionInfo level double mDefaultSolutionTolerance; diff --git a/cvs/objects/solution/solvers/include/log_newton_raphson.h b/cvs/objects/solution/solvers/include/log_newton_raphson.h index 2412e9a9a6..135fc29eeb 100644 --- a/cvs/objects/solution/solvers/include/log_newton_raphson.h +++ b/cvs/objects/solution/solvers/include/log_newton_raphson.h @@ -93,7 +93,7 @@ class LogNewtonRaphson: public SolverComponent { //! A filter which will be used to determine which SolutionInfos with solver component //! will work on. - std::auto_ptr mSolutionInfoFilter; + std::unique_ptr mSolutionInfoFilter; virtual ReturnCode calculateDerivatives( SolutionInfoSet& aSolutionSet, Matrix& JF, PermutationMatrix& aPermMatrix, int aPeriod ); diff --git a/cvs/objects/solution/util/include/solution_info.h b/cvs/objects/solution/util/include/solution_info.h index e232f6986f..0521cedd3e 100644 --- a/cvs/objects/solution/util/include/solution_info.h +++ b/cvs/objects/solution/util/include/solution_info.h @@ -150,7 +150,7 @@ class SolutionInfo { * \brief Binary function used to order SolutionInfo* pointers by decreasing relative excess demand. * \author Josh Lurz */ - struct GreaterRelativeED : public std::binary_function + struct GreaterRelativeED { //! Constructor GreaterRelativeED(){} diff --git a/cvs/objects/solution/util/include/solver_library.h b/cvs/objects/solution/util/include/solver_library.h index 2a462a7240..a476dd60f7 100644 --- a/cvs/objects/solution/util/include/solver_library.h +++ b/cvs/objects/solution/util/include/solver_library.h @@ -99,7 +99,7 @@ class SolverLibrary { private: //! A function object to compare to values and see if they are approximately equal. - struct ApproxEqual : public std::unary_function { + struct ApproxEqual { const double compareValue; //!< A value to compare the argument value against. const double tolerance; //!< The tolerance within which to return that the values are equal. ApproxEqual( double compareValueIn, double toleranceIn ): diff --git a/cvs/objects/target_finder/include/policy_target_runner.h b/cvs/objects/target_finder/include/policy_target_runner.h index 8f8456c63b..7d65626ef0 100644 --- a/cvs/objects/target_finder/include/policy_target_runner.h +++ b/cvs/objects/target_finder/include/policy_target_runner.h @@ -142,10 +142,10 @@ class PolicyTargetRunner: public IScenarioRunner { protected: //! The scenario runner which controls running the initial scenario, and all //! fixed taxed scenarios after. - std::auto_ptr mSingleScenario; + std::unique_ptr mSingleScenario; //! The delegate object which calculates total costs. - std::auto_ptr mPolicyCostCalculator; + std::unique_ptr mPolicyCostCalculator; DEFINE_DATA_WITH_PARENT( IScenarioRunner, diff --git a/cvs/objects/target_finder/include/target_factory.h b/cvs/objects/target_finder/include/target_factory.h index 97051f1d7b..3c246d4552 100644 --- a/cvs/objects/target_finder/include/target_factory.h +++ b/cvs/objects/target_finder/include/target_factory.h @@ -62,7 +62,7 @@ class Modeltime; class TargetFactory { public: static bool isOfType( const std::string& aType ); - static std::auto_ptr create( const std::string& aType, + static std::unique_ptr create( const std::string& aType, const IClimateModel* aClimateModel, double aTargetValue, int aFirstTaxYear ); diff --git a/cvs/objects/target_finder/source/policy_target_runner.cpp b/cvs/objects/target_finder/source/policy_target_runner.cpp index 23d44abe64..9cd0931702 100644 --- a/cvs/objects/target_finder/source/policy_target_runner.cpp +++ b/cvs/objects/target_finder/source/policy_target_runner.cpp @@ -216,7 +216,7 @@ bool PolicyTargetRunner::runScenarios( const int aSinglePeriod, } // Create the target object. - auto_ptr policyTarget = TargetFactory::create( mTargetType + "-target", + unique_ptr policyTarget = TargetFactory::create( mTargetType + "-target", getInternalScenario()->getClimateModel(), mTargetValue, mFirstTaxYear ); // Make sure we have a know target if( !policyTarget.get() ) { @@ -354,7 +354,7 @@ bool PolicyTargetRunner::solveInitialTarget( vector& aTaxes, // Increment is 1+ this number, which is used to increase the initial trial price const double INCREASE_INCREMENT = mInitialTaxGuess - 1; - auto_ptr solver; + unique_ptr solver; solver.reset( new Secanter( aPolicyTarget, aTolerance, @@ -474,7 +474,7 @@ bool PolicyTargetRunner::solveFutureTarget( vector& aTaxes, // Construct a solver which has an initial trial equal to the current tax. const Modeltime* modeltime = getInternalScenario()->getModeltime(); int currYear = modeltime->getper_to_yr( aPeriod ); - auto_ptr solver; + unique_ptr solver; /* Note that the following code is left commented out incase a user wanted to use the bisection routine rather then the secant. solver.reset( new Bisecter( aPolicyTarget, @@ -590,7 +590,7 @@ bool PolicyTargetRunner::skipFuturePeriod( vector& aTaxes, bool success = mSingleScenario->runScenarios( lastPeriodToCalc, false, aTimer ); // Construct a solver which has an initial trial equal to the current tax. - auto_ptr solver; + unique_ptr solver; /* Note that the following code is left commented out incase a user wanted to use the bisection routine rather then the secant. solver.reset( new Bisecter( aPolicyTarget, diff --git a/cvs/objects/target_finder/source/target_factory.cpp b/cvs/objects/target_finder/source/target_factory.cpp index e7aab713ad..ed07a9a2b1 100644 --- a/cvs/objects/target_finder/source/target_factory.cpp +++ b/cvs/objects/target_finder/source/target_factory.cpp @@ -78,48 +78,48 @@ bool TargetFactory::isOfType( const string& aType ) { * \param aClimateModel Scenario's climate model. * \param aTargetValue The target value. * \param aFirstTaxYear The first year in which the target could be checked. - * \return A newly created ITarget wrapped in an auto_ptr. The pointer + * \return A newly created ITarget wrapped in an unique_ptr. The pointer * is null if the type is unknown. */ -auto_ptr TargetFactory::create( const string& aType, +unique_ptr TargetFactory::create( const string& aType, const IClimateModel* aClimateModel, double aTargetValue, int aFirstTaxYear ) { // Search the list of known types. if( aType == ConcentrationTarget::getXMLNameStatic() ) { - return auto_ptr( new ConcentrationTarget( aClimateModel, + return unique_ptr( new ConcentrationTarget( aClimateModel, aTargetValue, aFirstTaxYear ) ); } if( aType == ForcingTarget::getXMLNameStatic() ){ - return auto_ptr( new ForcingTarget( aClimateModel, + return unique_ptr( new ForcingTarget( aClimateModel, aTargetValue, aFirstTaxYear ) ); } if( aType == RCPForcingTarget::getXMLNameStatic() ){ - return auto_ptr( new RCPForcingTarget( aClimateModel, + return unique_ptr( new RCPForcingTarget( aClimateModel, aTargetValue, aFirstTaxYear ) ); } if( aType == TemperatureTarget::getXMLNameStatic() ){ - return auto_ptr( new TemperatureTarget( aClimateModel, + return unique_ptr( new TemperatureTarget( aClimateModel, aTargetValue, aFirstTaxYear ) ); } if( aType == KyotoForcingTarget::getXMLNameStatic() ){ - return auto_ptr( new KyotoForcingTarget( aClimateModel, + return unique_ptr( new KyotoForcingTarget( aClimateModel, aTargetValue, aFirstTaxYear ) ); } if( aType == CumulativeEmissionsTarget::getXMLNameStatic() ){ - return auto_ptr( new CumulativeEmissionsTarget( aClimateModel, + return unique_ptr( new CumulativeEmissionsTarget( aClimateModel, aTargetValue, aFirstTaxYear ) ); } if( aType == EmissionsStabalizationTarget::getXMLNameStatic() ){ - return auto_ptr( new EmissionsStabalizationTarget( aClimateModel, + return unique_ptr( new EmissionsStabalizationTarget( aClimateModel, aTargetValue, aFirstTaxYear ) ); } @@ -131,5 +131,5 @@ auto_ptr TargetFactory::create( const string& aType, ILogger& mainLog = ILogger::getLogger( "main_log" ); mainLog.setLevel( ILogger::ERROR ); mainLog << "Could not create Target of type " << aType << "." << endl; - return auto_ptr(); + return unique_ptr(); } diff --git a/cvs/objects/target_finder/source/temperature_target.cpp b/cvs/objects/target_finder/source/temperature_target.cpp index a124b4682f..4b32ffb335 100644 --- a/cvs/objects/target_finder/source/temperature_target.cpp +++ b/cvs/objects/target_finder/source/temperature_target.cpp @@ -89,7 +89,7 @@ double TemperatureTarget::getStatus( const int aYear ) const { * ability to change the status in that year. */ assert( year >= mFirstTaxYear ); - const double currTemperature = mClimateModel->getTemperature( year ); + const double currTemperature = mClimateModel->getGmst( year, true ); // Determine how how far away from the target the current estimate is. double percentOff = ( currTemperature - mTargetValue ) / mTargetValue * 100; @@ -110,8 +110,8 @@ int TemperatureTarget::getYearOfMaxTargetValue() const { // Loop over possible year and find the max temp and the year it occurs in. for( int year = mFirstTaxYear; year <= finalYearToCheck; ++year ) { - if( maxTemp < mClimateModel->getTemperature( year ) ) { - maxTemp = mClimateModel->getTemperature( year ); + if( maxTemp < mClimateModel->getGmst( year, true ) ) { + maxTemp = mClimateModel->getGmst( year, true ); maxYear = year; } } diff --git a/cvs/objects/technologies/include/base_technology.h b/cvs/objects/technologies/include/base_technology.h index 37fc894c38..9ca662bc58 100644 --- a/cvs/objects/technologies/include/base_technology.h +++ b/cvs/objects/technologies/include/base_technology.h @@ -222,10 +222,10 @@ class BaseTechnology: public INamed, private boost::noncopyable mutable bool mPricePaidCached; //! A sequestration device to capture emissions - std::auto_ptr mSequestrationDevice; + std::unique_ptr mSequestrationDevice; //! Technology info store. - std::auto_ptr mTechInfo; + std::unique_ptr mTechInfo; private: void clear(); bool doCalibration; diff --git a/cvs/objects/technologies/include/intermittent_technology.h b/cvs/objects/technologies/include/intermittent_technology.h index a68d890a60..e7bb42cc2f 100644 --- a/cvs/objects/technologies/include/intermittent_technology.h +++ b/cvs/objects/technologies/include/intermittent_technology.h @@ -176,7 +176,7 @@ class IntermittentTechnology: public Technology { ) //! Info object used to pass parameter information into backup calculators. - std::auto_ptr mIntermittTechInfo; + std::unique_ptr mIntermittTechInfo; void copy( const IntermittentTechnology& aOther ); diff --git a/cvs/objects/technologies/include/primary_output.h b/cvs/objects/technologies/include/primary_output.h index 1d51517e69..bd9de0d41d 100644 --- a/cvs/objects/technologies/include/primary_output.h +++ b/cvs/objects/technologies/include/primary_output.h @@ -175,7 +175,7 @@ class PrimaryOutput : public IOutput { ) //! A pre-located market which has been cached from the marketplace to add supply to. - std::auto_ptr mCachedMarket; + std::unique_ptr mCachedMarket; void copy( const PrimaryOutput& aOther ); }; diff --git a/cvs/objects/technologies/include/production_state_factory.h b/cvs/objects/technologies/include/production_state_factory.h index 4800ccdb25..09c3d7d802 100644 --- a/cvs/objects/technologies/include/production_state_factory.h +++ b/cvs/objects/technologies/include/production_state_factory.h @@ -62,7 +62,7 @@ class IProductionState; */ class ProductionStateFactory { public: - static std::auto_ptr create( const int aInvestYear, + static std::unique_ptr create( const int aInvestYear, const int aLifetimeYears, const double aFixedOutput, const double aInitialOutput, diff --git a/cvs/objects/technologies/include/technology.h b/cvs/objects/technologies/include/technology.h index 15ad2a7d0c..cfa6472a8e 100644 --- a/cvs/objects/technologies/include/technology.h +++ b/cvs/objects/technologies/include/technology.h @@ -342,7 +342,7 @@ class Technology: public ITechnology ) //! The technology's information store. - std::auto_ptr mTechnologyInfo; + std::unique_ptr mTechnologyInfo; //! Production function for the technology. const IFunction* mProductionFunction; diff --git a/cvs/objects/technologies/source/base_technology.cpp b/cvs/objects/technologies/source/base_technology.cpp index e510278491..49b1489d8a 100644 --- a/cvs/objects/technologies/source/base_technology.cpp +++ b/cvs/objects/technologies/source/base_technology.cpp @@ -71,7 +71,6 @@ typedef vector::iterator GHGIterator; BaseTechnology::BaseTechnology(): mShareWeight( 1.0 ), mIsInitialYear( false ), - mSequestrationDevice( 0 ), doCalibration( false ) { mNestedInputRoot = 0 ; diff --git a/cvs/objects/technologies/source/global_technology_database.cpp b/cvs/objects/technologies/source/global_technology_database.cpp index 64135babef..1fa23b395d 100644 --- a/cvs/objects/technologies/source/global_technology_database.cpp +++ b/cvs/objects/technologies/source/global_technology_database.cpp @@ -149,14 +149,13 @@ const ITechnologyContainer* GlobalTechnologyDatabase::getTechnology( const strin const string& aTechnologyName ) const { const pair locationToFind( aSectorName, aSubsectorName ); - // functor to find a technology in a vector by name - util::NameEquals nameComparison( aTechnologyName ); CTechLocationIterator techLocationIter = mTechnologyList.find( locationToFind ); if( techLocationIter != mTechnologyList.end() ) { const vector& tempTechContainers = ( *techLocationIter ).second; - CTechListIterator techIter = find_if( tempTechContainers.begin(), tempTechContainers.end(), - nameComparison ); + CTechListIterator techIter = find_if(tempTechContainers.begin(), tempTechContainers.end(), [aTechnologyName](auto aCurrTech) -> bool { + return aCurrTech->getName() == aTechnologyName; + }); if( techIter != tempTechContainers.end() ) { return *techIter; } diff --git a/cvs/objects/technologies/source/production_state_factory.cpp b/cvs/objects/technologies/source/production_state_factory.cpp index c6138c7634..3edfd50a3c 100644 --- a/cvs/objects/technologies/source/production_state_factory.cpp +++ b/cvs/objects/technologies/source/production_state_factory.cpp @@ -77,14 +77,14 @@ using namespace std; * calculated. * \param aPeriod Model period. */ -auto_ptr ProductionStateFactory::create( const int aInvestYear, +unique_ptr ProductionStateFactory::create( const int aInvestYear, const int aLifetimeYears, const double aFixedOutput, const double aInitialOutput, const int aPeriod ) { // Initialize the production state. - auto_ptr newState; + unique_ptr newState; int currYear = scenario->getModeltime()->getper_to_yr( aPeriod ); if( aInvestYear == currYear ){ diff --git a/cvs/objects/technologies/source/technology.cpp b/cvs/objects/technologies/source/technology.cpp index 0af04662a5..45f0c8f464 100644 --- a/cvs/objects/technologies/source/technology.cpp +++ b/cvs/objects/technologies/source/technology.cpp @@ -1580,7 +1580,7 @@ void interpolateChildVector( std::vector aInterpolated, std::vector aPre // Sort each vector by name to help identify mismatches. // Note that the vectors are passed by value on purpose so that these sorts // do not mess with ordering. - util::NameComparator comp; + util::NameComparator comp; sort( aInterpolated.begin(), aInterpolated.end(), comp ); sort( aPrev.begin(), aPrev.end(), comp ); sort( aNext.begin(), aNext.end(), comp ); diff --git a/cvs/objects/util/base/include/atom_registry.h b/cvs/objects/util/base/include/atom_registry.h index 777e1f0d9a..1d31e17f5f 100644 --- a/cvs/objects/util/base/include/atom_registry.h +++ b/cvs/objects/util/base/include/atom_registry.h @@ -104,11 +104,11 @@ namespace objects { * can be forward declared to prevent excessive recompilation * when the internal hashmap class changes. The Atoms are stored * with a shared_ptr so that they are deallocated automatically. - * A standard auto_ptr is not used because that could cause an + * A standard unique_ptr is not used because that could cause an * Atom to be unintentionally deallocated during a hashmap * resize operation. */ - std::auto_ptr mAtoms; + std::unique_ptr mAtoms; }; } diff --git a/cvs/objects/util/base/include/configuration.h b/cvs/objects/util/base/include/configuration.h index 538018e778..7533aaf8b7 100644 --- a/cvs/objects/util/base/include/configuration.h +++ b/cvs/objects/util/base/include/configuration.h @@ -87,7 +87,7 @@ class Configuration { const std::list& getScenarioComponents() const; private: const std::string mLogFile; //!< The name of the log to use. - static std::auto_ptr gInstance; //!< The static instance of the Configuration class. + static std::unique_ptr gInstance; //!< The static instance of the Configuration class. std::map fileMap; //!< A map of the file names the program uses. //! Map file names to a flag if set indicates that the file should be written std::map mShouldWriteFileMap; diff --git a/cvs/objects/util/base/include/hash_map.h b/cvs/objects/util/base/include/hash_map.h index 29b757fe46..7be4de4ede 100644 --- a/cvs/objects/util/base/include/hash_map.h +++ b/cvs/objects/util/base/include/hash_map.h @@ -85,7 +85,7 @@ * iterate over the key-value set or remove keys from the map. * \note The Value type is required to implement the no-argument constructor. * This condition must be true for standard library containers as well. -* \note Do not use auto_ptrs as Values as they may be accidentally deleted during +* \note Do not use unique_ptrs as Values as they may be accidentally deleted during * resizes. This is true of standard library containers as well. * \author Josh Lurz */ diff --git a/cvs/objects/util/base/include/supply_demand_curve.h b/cvs/objects/util/base/include/supply_demand_curve.h index 7ed6e41c3a..bab3960878 100644 --- a/cvs/objects/util/base/include/supply_demand_curve.h +++ b/cvs/objects/util/base/include/supply_demand_curve.h @@ -101,7 +101,7 @@ class SupplyDemandPoint * \brief Binary comparison operator used for SavePoint pointers to order by increasing price. * \author Josh Lurz */ - struct LesserPrice : public std::binary_function + struct LesserPrice { //! Operator which performs comparison. bool operator()( const SupplyDemandPoint* lhs, const SupplyDemandPoint* rhs ) const diff --git a/cvs/objects/util/base/include/util.h b/cvs/objects/util/base/include/util.h index 2892033e40..83f24cd80f 100644 --- a/cvs/objects/util/base/include/util.h +++ b/cvs/objects/util/base/include/util.h @@ -153,70 +153,23 @@ namespace objects { return iter; } - template - struct InterfaceGetter { - public: - const U* operator()( const T& aObject ){ - return &aObject; - } - }; - - template - struct InterfaceGetter { - public: - const U* operator()( const T* aObject ){ - return aObject; - } - }; - - /*! - * \ingroup Objects - * \brief Helper struct which implements the equals operator for INamed pointers. - * \todo Is this worth a source file? - * \author Josh Lurz - */ - template - struct NameEquals: public std::unary_function { - NameEquals( const std::string& aName ); - bool operator()( const T& aObject ); - - //! Stored name to compare against. - const std::string mName; - }; - - /*! - * \brief Constructor for the operator which stores the name to compare against - * the name of another object. - * \param aName Name of the object which is being compared against. - */ - template - inline NameEquals::NameEquals( const std::string& aName ):mName( aName ){ - /*! \pre Object name is not empty. */ - assert( !mName.empty() ); + /*! \brief Returns whether a value with the given key exists. + * \details This function takes as its input a map and a key for which to + * search, and returns whether the key exists. + * \param aCurrMap The map within which to search for the value. + * \param aKey The key of which to check for the existance. + * \return Whether the key exists. + */ + template bool hasValue( const std::map& aCurrMap, const K& aKey ){ + return ( aCurrMap.find( aKey ) != aCurrMap.end() ); } - /*! \brief Equals operator which determines if the given object has the same - * name as another object. - * \param aObject Object to compare against. - * \return Whether the object is equal to the stored object. - */ - template - inline bool NameEquals::operator()( const T& aObject ){ - /*! \pre Object is non-null. */ - assert( aObject ); - /*! \pre Object name is not empty. */ - assert( !aObject->getName().empty() ); - - return InterfaceGetter()( aObject )->getName() == mName; - } - /*! * \brief A binary functor to compare named components by name so that they can be sorted. * \note If objects correctly inherited from the INamed interface this could * just use that as the template argument instead of templating NameComparator. */ - template - struct NameComparator : public std::binary_function { + struct NameComparator { /*! * \brief Determine if the left hand operand is less than the * right. @@ -224,116 +177,12 @@ namespace objects { * \param rhs The right hand side operand for the sort comparison. * \return True if lhs is less than rhs, false otherwise. */ - bool operator()( const T* lhs, const T* rhs ){ + template + bool operator()(const T* lhs, const T* rhs) { return lhs->getName() < rhs->getName(); } }; - /*! \brief Reorder a container based on an ordering of names. - * \details This function is used to reorder a a container using a supplied - * ordering. This function handles errors as follows: - *
    - *
  • - * If an object is not specified in the list, the function - * will output an error. - *
  • - *
  • - * If an object name in the ordering list is not an - * existing sector in the model, a debugging warning will - * be issued and the name will be skipped. - *
  • - *
- * \param aFirst An InputIterator pointing to the start of the container. - * \param aLast An InputIterator pointing to the end of the container. - * \param aOrderList A list of names in the order in which the objects in - * the container should be put. - * \return Whether all objects had orderings in the passed in order list. - * \warning This function requires that all the strings in aOrderList are - * unique. It's behavior is undefined if the vector contains - * duplicate strings. - */ - template - bool reorderContainer( InputIterator aFirst, - InputIterator aLast, - const std::vector& aOrderList ){ - bool success = true; - - if( aOrderList.empty() ){ - ILogger& mainLog = ILogger::getLogger( "main_log" ); - mainLog.setLevel( ILogger::NOTICE ); - mainLog << "Skipping object reordering due to an empty order list." - << std::endl; - return false; - } - - // Get the dependency finder logger. - ILogger& depFinderLog = ILogger::getLogger( "dependency_finder_log" ); - - // Construct a map of strings to bools that represent an object in the - // container NOT being mapped. The bool is irrelevant because mappings - // will be removed as they are ordered. - std::map isOrdered; - for( InputIterator containerIter = aFirst; - containerIter != aLast; ++containerIter ){ - isOrdered.insert( - std::make_pair( objects::InterfaceGetter()( *containerIter )->getName(), true ) ); - } - - // This loop functions much like insertion sort. aFirst initially - // points to the first location in the container. The loop iterates - // over the name list. During each iteration we attempt to find - // an iterator that points to object in the container that has the - // right name. If this iterator is found the values are swapped. Otherwise - // a warning is emitted. - typedef std::vector::const_iterator OrderIter; - for( OrderIter nameIter = aOrderList.begin(); - nameIter != aOrderList.end(); ++nameIter ){ - - // Note that find_if uses a predicate to find the appropriate item. - // Consult the NameEquals class and the STL documentation for details. - InputIterator containerIter = std::find_if( aFirst, - aLast, - NameEquals( *nameIter ) ); - if( containerIter != aLast ){ - std::swap( *aFirst, *containerIter ); - ++aFirst; - // Remove it from the isOrdered vector - isOrdered.erase( *nameIter ); - } - else { - // There was a name in the order that did not correspond to - // and object in the container. - depFinderLog.setLevel( ILogger::DEBUG ); - depFinderLog << *nameIter << " is not the name of an " - << "object in the container. " - << "It will not be included in the ordering." - << std::endl; - } - } - // Output an error if there was an item in the container that was not - // in the ordering. - for( std::map::iterator orderIter = isOrdered.begin(); - orderIter != isOrdered.end(); ++orderIter ){ - ILogger& mainLog = ILogger::getLogger( "main_log"); - mainLog.setLevel( ILogger::ERROR ); - mainLog << orderIter->first - << " was not assigned a position in the explicit ordering list." << std::endl; - success = false; - } - return success; - } - - /*! \brief Returns whether a value with the given key exists. - * \details This function takes as its input a map and a key for which to - * search, and returns whether the key exists. - * \param aCurrMap The map within which to search for the value. - * \param aKey The key of which to check for the existance. - * \return Whether the key exists. - */ - template bool hasValue( const std::map& aCurrMap, const K& aKey ){ - return ( aCurrMap.find( aKey ) != aCurrMap.end() ); - } - /*! \brief A function to determine the sign of a number. * \param number A templated parameter which must be comparable to 0. * \return Returns -1 if the number is less than 0, +1 otherwise. diff --git a/cvs/objects/util/base/source/configuration.cpp b/cvs/objects/util/base/source/configuration.cpp index 8c9245c28c..4f553e3d85 100644 --- a/cvs/objects/util/base/source/configuration.cpp +++ b/cvs/objects/util/base/source/configuration.cpp @@ -51,7 +51,7 @@ using namespace std; // Static initializations. -std::auto_ptr Configuration::gInstance; +std::unique_ptr Configuration::gInstance; //! Private constructor to prevent a programmer from creating a second object. Configuration::Configuration(): mLogFile( "main_log" ){ diff --git a/cvs/objects/util/curves/include/curve.h b/cvs/objects/util/curves/include/curve.h index 9c8371f77e..6eb148ea39 100644 --- a/cvs/objects/util/curves/include/curve.h +++ b/cvs/objects/util/curves/include/curve.h @@ -137,7 +137,7 @@ class Curve : private boost::noncopyable { * \brief Binary comparison operator which compares two Curves by least minimum X value. * \author Josh Lurz */ - struct LesserMinX: public std::binary_function + struct LesserMinX { //! Operator which performs comparison. bool operator()( const Curve* lhs, const Curve* rhs ) const @@ -149,7 +149,7 @@ class Curve : private boost::noncopyable { * \brief Binary comparison operator which compares two Curves by least minimum Y value. * \author Josh Lurz */ - struct LesserMinY: public std::binary_function + struct LesserMinY { //! Operator which performs comparison. bool operator()( const Curve* lhs, const Curve* rhs ) const @@ -161,7 +161,7 @@ class Curve : private boost::noncopyable { * \brief Binary comparison operator which compares two Curves by least maximum X value. * \author Josh Lurz */ - struct LesserMaxX: public std::binary_function + struct LesserMaxX { //! Operator which performs comparison. bool operator()( const Curve* lhs, const Curve* rhs ) const @@ -173,7 +173,7 @@ class Curve : private boost::noncopyable { * \brief Binary comparison operator which compares two Curves by least maximum Y value. * \author Josh Lurz */ - struct LesserMaxY: public std::binary_function + struct LesserMaxY { //! Operator which performs comparison. bool operator()( const Curve* lhs, const Curve* rhs ) const diff --git a/cvs/objects/util/curves/include/data_point.h b/cvs/objects/util/curves/include/data_point.h index 6de61234b4..6221a16416 100644 --- a/cvs/objects/util/curves/include/data_point.h +++ b/cvs/objects/util/curves/include/data_point.h @@ -92,7 +92,7 @@ class DataPoint : private boost::noncopyable { * \brief Binary comparison operator used for DataPoint pointers to order by increasing values. * \author Josh Lurz */ - struct Lesser : public std::binary_function + struct Lesser { //! Operator which performs comparison. bool operator()( const DataPoint* lhs, const DataPoint* rhs ) const @@ -104,7 +104,7 @@ class DataPoint : private boost::noncopyable { * \brief Binary comparison operator which compares two DataPoints by least X value. * \author Josh Lurz */ - struct LesserX : public std::binary_function + struct LesserX { //! Operator which performs comparison. bool operator()( const DataPoint* lhs, const DataPoint* rhs ) const @@ -116,7 +116,7 @@ class DataPoint : private boost::noncopyable { * \brief Binary comparison operator which compares two DataPoints by least Y value. * \author Josh Lurz */ - struct LesserY : public std::binary_function + struct LesserY { //! Operator which performs comparison. bool operator()( const DataPoint* lhs, const DataPoint* rhs ) const diff --git a/exe/XMLDBDriver.properties b/exe/XMLDBDriver.properties index 34bbb875e0..79e632583a 100644 --- a/exe/XMLDBDriver.properties +++ b/exe/XMLDBDriver.properties @@ -18,7 +18,7 @@ - +../output/queries/filters/default_filter.xml + + + + +