%% AMS-LaTeX Created with the Wolfram Language : www.wolfram.com

\documentclass{article}
\usepackage{amsmath, amssymb, graphics, setspace}

\newcommand{\mathsym}[1]{{}}
\newcommand{\unicode}[1]{{}}

\begin{document}

\title{Carbon Emission and Diffusion Simulation - Cloud-Ready Version}
\author{}
\date{}
\maketitle

\section*{1. Environment Setup and Documentation}

Clear environment and set options

\text{ClearAll}[\text{Global$\grave{ }$*}];\\
\text{SetOptions}[\text{$\$$FrontEnd}, \text{PrintingStyleEnvironment} \text{-$>$} \text{Working}];

Documentation and Metadata

Author: [Mingxin Zhao]

Date: [2025-04-09]

Version: 1.0

Description: A comprehensive carbon emission and atmospheric diffusion simulation system

Cloud Deployment: Compatible with Wolfram Cloud and other cloud platforms

\section*{2. Configuration and Parameters}

System Configuration\\
Units: All parameters with their respective units

\text{systemConfig} = <|\\
\text{  }\text{gridSize} \text{-$>$} <|\text{Nx} \text{-$>$} 50, \text{Ny} \text{-$>$} 50, \text{Nt} \text{-$>$} 120|>,\\
\text{  }\text{spatialRange} \text{-$>$} <|\text{XRange} \text{-$>$} \{0, 1000\}, \text{YRange} \text{-$>$} \{0, 1000\}|>,\\
\text{  }\text{timeRange} \text{-$>$} <|\text{TRange} \text{-$>$} \{0, 432000\}, \text{dt} \text{-$>$} 10|>,\\
\text{  }\text{decayRates} \text{-$>$} <|\text{kCO2} \text{-$>$} 0.001, \text{kVOC} \text{-$>$} 0.0005|>,\\
\text{  }\text{initialConcentrations} \text{-$>$} <|\text{CO2Background} \text{-$>$} 400, \text{VOCBackground} \text{-$>$} 15, \\
\text{                              }\text{CO2Source} \text{-$>$} 450, \text{VOCSource} \text{-$>$} 100|>,\\
\text{  }\text{sourceLocation} \text{-$>$} <|\text{x} \text{-$>$} 25, \text{y} \text{-$>$} 25|>,\\
\text{  }\text{sourceEmission} \text{-$>$} <|\text{CO2Increment} \text{-$>$} 10, \text{VOCIncrement} \text{-$>$} 5, \text{frequency} \text{-$>$}
10|>\\
|>;

Data Paths Configuration\\
Update these paths according to your cloud storage configuration

\text{dataPaths} = <|\\
\text{  }\text{windData} \text{-$>$} \text{data/windData.csv},\\
\text{  }\text{meteoData} \text{-$>$} \text{data/meteoData.csv},\\
\text{  }\text{pollutionData} \text{-$>$} \text{data/pollutionData.csv},\\
\text{  }\text{CO2Data} \text{-$>$} \text{data/CO2Data.csv}\\
|>;

\section*{3. Utility Functions}

Data Loading and Validation

\text{loadData}[\text{path$\_$}] \text{:=} \text{Module}[\{\text{data}\},\\
\text{  }\text{data} = \text{Import}[\text{path}, \text{CSV}];\\
\text{  }\text{If}[\text{Length}[\text{data}] < 2, \\
\text{    }\text{MessageDialog}[\text{Error: Data file } <> \text{path} <> \text{ is empty or invalid.}];\\
\text{    }\text{Return}[\{\}]\\
\text{  }];\\
\text{  }\text{Return}[\text{data}]\\
];

Grid Generation

\text{generateGrids}[\text{config$\_$}] \text{:=} \text{Module}[\{\},\\
\text{  }\text{XGrid} = \text{Subdivide}[\text{config}[\text{spatialRange}][\text{XRange}][[1]], \\
\text{                    }\text{config}[\text{spatialRange}][\text{XRange}][[2]], \\
\text{                    }\text{config}[\text{gridSize}][\text{Nx}]];\\
\text{  }\text{YGrid} = \text{Subdivide}[\text{config}[\text{spatialRange}][\text{YRange}][[1]], \\
\text{                    }\text{config}[\text{spatialRange}][\text{YRange}][[2]], \\
\text{                    }\text{config}[\text{gridSize}][\text{Ny}]];\\
\text{  }\text{TGrid} = \text{Subdivide}[\text{config}[\text{timeRange}][\text{TRange}][[1]], \\
\text{                    }\text{config}[\text{timeRange}][\text{TRange}][[2]], \\
\text{                    }\text{config}[\text{gridSize}][\text{Nt}]];\\
\text{  }\text{Return}[\{\text{XGrid}, \text{YGrid}, \text{TGrid}\}]\\
];

Interpolation with Error Handling

\text{createInterpolation}[\text{data$\_$}, \text{columns$\_$}, \text{order$\_$} : 1] \text{:=} \text{Module}[\{\},\\
\text{  }\text{If}[\text{Length}[\text{data}] < 2, \\
\text{    }\text{Return}[\text{Function}[t, 0]] \text{(*Return zero function if data is invalid*)}\\
\text{  }];\\
\text{  }\text{Return}[\text{Interpolation}[\text{data}[[2 \text{;;}, \text{columns}]], \\
\text{                      }\text{InterpolationOrder} \text{-$>$} \text{order},\\
\text{                      }\text{ExtrapolationHandler} \text{-$>$} \{\text{$\#$1} \&, \text{WarningMessage} \text{-$>$} \text{False}\}]]\\
];

\section*{4. Emission Calculation Module}

Total Emissions Calculation\\
Units: AnnualCarbonEmissionsPerPerson in tons CO$\unicode{2082}$/person/year\\
Units: avaragePopulation in thousands of people\\
Units: Result in tons CO$\unicode{2082}$/year

\text{totalEmissionsNow}[\text{AnnualCarbonEmissionsPerPerson$\_$}, \\
\text{   }\text{avaragePopulation$\_$}] \text{:=} \\
\text{  }\text{AnnualCarbonEmissionsPerPerson}*\text{avaragePopulation}*1000;

CO$\unicode{2082}$ Emission Function (Exponential Decay)\\
Units: t in years\\
Units: totalEmissionsNow in tons CO$\unicode{2082}$/year\\
Units: StartOfAction in years\\
Units: HalfTimeCO2Reduction in years\\
Units: Result in tons CO$\unicode{2082}$/year

\text{CO2EmissionFunction}[\text{t$\_$}, \text{totalEmissionsNow$\_$}, \text{StartOfAction$\_$}, \\
\text{   }\text{HalfTimeCO2Reduction$\_$}] \text{:=} \\
\text{  }\text{totalEmissionsNow}*\\
\text{   }\text{Exp}[-((t - \text{StartOfAction})/(\text{HalfTimeCO2Reduction}/\text{Log}[2]))];

Compensation Function\\
Units: t in years\\
Units: fractionOfCompensation in percentage\\
Units: baseCompensation in percentage\\
Units: CO2EmissionFunction in tons CO$\unicode{2082}$/year\\
Units: totalEmissionsNow in tons CO$\unicode{2082}$/year\\
Units: Result in tons CO$\unicode{2082}$/year

\text{Kompensationsfunktion}[\text{t$\_$}, \text{fractionOfCompensation$\_$}, \text{baseCompensation$\_$}, \\
\text{   }\text{CO2EmissionFunction$\_$}, \\
\text{   }\text{totalEmissionsNow$\_$}] \text{:=} (\text{fractionOfCompensation}/100)*\\
\text{    }\text{CO2EmissionFunction}[t] + (\text{baseCompensation}/100)*\text{totalEmissionsNow};

Effective Emissions Function\\
Units: t in years\\
Units: CO2EmissionFunction in tons CO$\unicode{2082}$/year\\
Units: Kompensationsfunktion in tons CO$\unicode{2082}$/year\\
Units: Result in tons CO$\unicode{2082}$/year

\text{EffectiveEmissionsFunction}[\text{t$\_$}, \text{CO2EmissionFunction$\_$}, \\
\text{   }\text{Kompensationsfunktion$\_$}] \text{:=} \\
\text{  }\text{CO2EmissionFunction}[t] - \text{Kompensationsfunktion}[t];

Net Zero Time Calculation\\
Units: effectiveFunc in tons CO$\unicode{2082}$/year\\
Units: startYear in years\\
Units: Result in years or {``}Not reached by 2100{''}

\text{NetZeroTime}[\text{effectiveFunc$\_$}, \text{startYear$\_$}] \text{:=} \\
\text{  }\text{Module}[\{t = \text{startYear}\}, \\
\text{   }\text{While}[\text{effectiveFunc}[t] > 0 \&\& t < 2100, t\text{++}]; \\
\text{   }\text{If}[t \text{$>$=} 2100, \text{Not reached by 2100}, t]];

Cumulative Emissions Calculation\\
Units: targetYear in years\\
Units: startYear in years\\
Units: effectiveFunc in tons CO$\unicode{2082}$/year\\
Units: Result in tons CO$\unicode{2082}$

\text{CumulativeEmissions}[\text{targetYear$\_$}, \text{startYear$\_$}, \text{effectiveFunc$\_$}] \text{:=} \\
\text{  }\text{NIntegrate}[\text{effectiveFunc}[t], \{t, \text{startYear}, \text{targetYear}\}];

Climate Budget Calculation\\
Units: budgetPerPerson in tons CO$\unicode{2082}$/person/year\\
Units: startYear in years\\
Units: population in thousands of people\\
Units: years in years\\
Units: Result in tons CO$\unicode{2082}$

\text{ClimateBudget}[\text{budgetPerPerson$\_$}, \text{startYear$\_$}, \text{population$\_$}, \text{years$\_$}] \text{:=} \\
\text{  }\text{budgetPerPerson} * \text{population} * \text{years};

Compensation Costs Calculation\\
Units: startYear in years\\
Units: compFunc in tons CO$\unicode{2082}$/year\\
Units: costPerTon in USD/ton CO$\unicode{2082}$\\
Units: Result in USD

\text{CompensationCosts}[\text{startYear$\_$}, \text{compFunc$\_$}, \text{costPerTon$\_$}] \text{:=} \\
\text{  }\text{NIntegrate}[\text{compFunc}[t] * \text{costPerTon}, \{t, \text{startYear}, 2050\}];

\section*{5. Diffusion Model Module}

Wind model correction with range checking\\
Units: t in seconds\\
Units: x, y in meters\\
Units: Result in m/s

\text{WindU}[\text{t$\_$}, \text{x$\_$}, \text{y$\_$}, \text{UInterp$\_$}] \text{:=} \\
\text{  }\text{Module}[\{\text{tVal} = \text{Clip}[t, \{0, 432000\}]\}, \text{UInterp}[\text{tVal}]];\\
\text{WindV}[\text{t$\_$}, \text{x$\_$}, \text{y$\_$}, \text{VInterp$\_$}] \text{:=} \\
\text{  }\text{Module}[\{\text{tVal} = \text{Clip}[t, \{0, 432000\}]\}, \text{VInterp}[\text{tVal}]];

External concentration models with range checking\\
Units: t in seconds\\
Units: x, y in meters\\
Units: ExternalCO2 result in ppm (parts per million)\\
Units: ExternalVOC result in ppb (parts per billion)

\text{ExternalCO2}[\text{t$\_$}, \text{x$\_$}, \text{y$\_$}, \text{CO2Interp$\_$}] \text{:=} \\
\text{  }\text{Module}[\{\text{tVal} = \text{Clip}[t, \{0, 432000\}]\}, \text{CO2Interp}[\text{tVal}]];\\
\text{ExternalVOC}[\text{t$\_$}, \text{x$\_$}, \text{y$\_$}, \text{VOCInterp$\_$}] \text{:=} \\
\text{  }\text{Module}[\{\text{tVal} = \text{Clip}[t, \{0, 432000\}]\}, \text{VOCInterp}[\text{tVal}]];

Pasquill-Gifford turbulence diffusion model\\
Units: x, y in meters\\
Units: Result in m$\unicode{00b2}$/s (diffusion coefficients)

\text{PasquillGifford}[\text{C}, \text{x$\_$}, \text{y$\_$}] \text{:=} \{0.11\text{  }(x/1000){}^{\wedge}0.5, \\
\text{  }0.08\text{  }(y/1000){}^{\wedge}0.6, 0.06\}

Diffusion-Advection calculation with improved stability\\
Units: C in ppm for CO2 or ppb for VOCs\\
Units: U, V in m/s\\
Units: sigmaX, sigmaY in m$\unicode{00b2}$/s\\
Units: dt in seconds\\
Units: Result in ppm/s for CO2 or ppb/s for VOCs

\text{DiffusionAdvection}[\text{C$\_$}, \text{U$\_$}, \text{V$\_$}, \text{sigmaX$\_$}, \text{sigmaY$\_$}, \text{dt$\_$}, \text{Nx$\_$}, \text{Ny$\_$}]
\text{:=} \\
 \text{Module}[\{\text{dC}, i, j\}, \text{dC} = \text{ConstantArray}[0, \{\text{Nx}, \text{Ny}\}];\\
\text{  }\text{For}[i = 2, i < \text{Nx}, i\text{++}, \\
\text{   }\text{For}[j = 2, j < \text{Ny}, j\text{++}, \\
\text{     }\text{dC}[[i, j]] = \\
\text{       }\text{dt}*(\text{sigmaX}[[i, \\
\text{            }j]]*(C[[i + 1, j]] - 2\text{  }C[[i, j]] + C[[i - 1, j]]) + \\
\text{          }\text{sigmaY}[[i, \\
\text{            }j]]*(C[[i, j + 1]] - 2\text{  }C[[i, j]] + C[[i, j - 1]]) - \\
\text{          }U[[i, j]]*(C[[i + 1, j]] - C[[i - 1, j]])/2 - \\
\text{          }V[[i, j]]*(C[[i, j + 1]] - C[[i, j - 1]])/2);];];\\
\text{  }\text{dC}]

\section*{6. Visualization Module}

Basic Emission Plot\\
Units: emissionFunc, compFunc, effectiveFunc in tons CO$\unicode{2082}$/year\\
Units: startYear, endYear in years

\text{EmissionPlot}[\text{emissionFunc$\_$}, \text{compFunc$\_$}, \text{effectiveFunc$\_$}, \text{startYear$\_$}, \\
\text{   }\text{endYear$\_$}] \text{:=} \\
\text{  }\text{Plot}[\{\text{emissionFunc}[t], \text{compFunc}[t], \text{effectiveFunc}[t]\}, \{t, \\
\text{    }\text{startYear}, \text{endYear}\}, \\
\text{   }\text{PlotStyle} \text{-$>$} \{\text{Directive}[\text{Blue}, \text{Thickness}[0.01]], \\
\text{     }\text{Directive}[\text{Green}, \text{Thickness}[0.01]], \\
\text{     }\text{Directive}[\text{Red}, \text{Thickness}[0.01]]\}, \\
\text{   }\text{PlotLegends} \text{-$>$} \{\text{Original Emissions}, \text{Compensation}, \\
\text{     }\text{Effective Emissions}\}, \\
\text{   }\text{AxesLabel} \text{-$>$} \{\text{Year}, \text{CO$\unicode{2082}$ Emissions (tons/year)}\}, \\
\text{   }\text{PlotLabel} \text{-$>$} \text{Carbon Emission Trends}, \text{GridLines} \text{-$>$} \text{Automatic}];

Diffusion Visualization with improved color scaling\\
Units: conc in ppm for CO2 or ppb for VOCs\\
Units: title in string

\text{DiffusionPlot}[\text{conc$\_$}, \text{title$\_$}, \text{Nx$\_$}, \text{Ny$\_$}] \text{:=} \\
\text{  }\text{DensityPlot}[\\
\text{   }\text{ListInterpolation}[\text{conc}, \{\{1, \text{Nx}\}, \{1, \text{Ny}\}\}][x, y], \{x, 1, \text{Nx}\}, \{y, \\
\text{    }1, \text{Ny}\}, \text{ColorFunction} \text{-$>$} \text{Rainbow}, \text{PlotLabel} \text{-$>$} \text{title}, \\
\text{   }\text{Frame} \text{-$>$} \text{True}, \text{PlotLegends} \text{-$>$} \text{Automatic},\\
\text{   }\text{PlotRange} \text{-$>$} \text{All}, \text{ColorFunctionScaling} \text{-$>$} \text{True}];

3D Diffusion Visualization with improved appearance\\
Units: conc in ppm for CO2 or ppb for VOCs\\
Units: title in string

\text{DiffusionPlot3D}[\text{conc$\_$}, \text{title$\_$}, \text{Nx$\_$}, \text{Ny$\_$}] \text{:=} \\
\text{  }\text{ListDensityPlot3D}[\\
\text{   }\text{Table}[\text{conc}[[i, j]], \{i, 1, \text{Nx}\}, \{j, 1, \text{Ny}\}, \{z, 1, 5\}], \\
\text{   }\text{ColorFunction} \text{-$>$} \text{Rainbow}, \text{PlotLabel} \text{-$>$} \text{title},\\
\text{   }\text{PlotRange} \text{-$>$} \text{All}, \text{ColorFunctionScaling} \text{-$>$} \text{True}];

Error Analysis and Visualization\\
Units: actualData, simulatedData in ppm for CO2 or ppb for VOCs\\
Units: Result in ppm for CO2 or ppb for VOCs

\text{ErrorAnalysis}[\text{actualData$\_$}, \text{simulatedData$\_$}, \text{TGrid$\_$}] \text{:=} \\
\text{  }\text{Module}[\{\text{rmseValues} = \\
\text{     }\text{Table}[\text{Sqrt}[\\
\text{       }\text{Mean}[(\text{actualData}[[1 \text{;;} t]] - \text{simulatedData}[[1 \text{;;} t]]){}^{\wedge}2]], \{t, \\
\text{       }\text{Length}[\text{TGrid}]\}]\}, \\
\text{   }\text{ListLinePlot}[\text{rmseValues}, \text{PlotStyle} \text{-$>$} \{\text{Thick}, \text{Red}\}, \\
\text{    }\text{AxesLabel} \text{-$>$} \{\text{Time Step}, \text{RMSE}\}, \\
\text{    }\text{PlotLabel} \text{-$>$} \text{RMSE Evolution Over Time}, \text{ImageSize} \text{-$>$} \text{Large}]];

\section*{7. Simulation Module}

Initialize pollutant concentrations

\text{initializeConcentrations}[\text{config$\_$}] \text{:=} \text{Module}[\{\},\\
\text{  }\text{CO2Conc} = \text{ConstantArray}[\text{config}[\text{initialConcentrations}][\text{CO2Background}], \\
\text{                         }\{\text{config}[\text{gridSize}][\text{Nx}], \text{config}[\text{gridSize}][\text{Ny}]\}];\\
\text{  }\text{VOCConc} = \text{ConstantArray}[\text{config}[\text{initialConcentrations}][\text{VOCBackground}], \\
\text{                         }\{\text{config}[\text{gridSize}][\text{Nx}], \text{config}[\text{gridSize}][\text{Ny}]\}];\\
\text{  }\\
\text{  }\text{(*Set source locations*)}\\
\text{  }\text{VOCConc}[[\text{config}[\text{sourceLocation}][\text{x}], \text{config}[\text{sourceLocation}][\text{y}]]] = \\
\text{    }\text{config}[\text{initialConcentrations}][\text{VOCSource}];\\
\text{  }\text{CO2Conc}[[\text{config}[\text{sourceLocation}][\text{x}], \text{config}[\text{sourceLocation}][\text{y}]]] = \\
\text{    }\text{config}[\text{initialConcentrations}][\text{CO2Source}];\\
\text{    }\\
\text{  }\text{Return}[\{\text{CO2Conc}, \text{VOCConc}\}]\\
];

Run diffusion simulation

\text{runDiffusionSimulation}[\text{config$\_$}, \text{UInterp$\_$}, \text{VInterp$\_$}, \text{XGrid$\_$}, \text{YGrid$\_$}, \text{TGrid$\_$}] \text{:=}
\\
\text{  }\text{Module}[\{\text{CO2Conc}, \text{VOCConc}, \text{sigma}, U, V, \text{dCO2}, \text{dVOC}, \\
\text{    }\text{sourceX} = \text{config}[\text{sourceLocation}][\text{x}], \\
\text{    }\text{sourceY} = \text{config}[\text{sourceLocation}][\text{y}],\\
\text{    }\text{sourceFreq} = \text{config}[\text{sourceEmission}][\text{frequency}],\\
\text{    }\text{CO2Increment} = \text{config}[\text{sourceEmission}][\text{CO2Increment}],\\
\text{    }\text{VOCIncrement} = \text{config}[\text{sourceEmission}][\text{VOCIncrement}]\},\\
\text{    }\\
\text{    }\text{(*Initialize concentrations*)}\\
\text{    }\{\text{CO2Conc}, \text{VOCConc}\} = \text{initializeConcentrations}[\text{config}];\\
\text{    }\\
\text{    }\text{(*Run simulation*)}\\
\text{    }\text{Monitor}[\text{For}[t = 1, t \text{$<$=} \text{Length}[\text{TGrid}], t\text{++}, \\
\text{      }\text{sigma} = \\
\text{       }\text{Table}[\text{PasquillGifford}[\text{C}, \text{XGrid}[[i]], \text{YGrid}[[j]]], \{i, \text{config}[\text{gridSize}][\text{Nx}]\},
\{j, \\
\text{         }\text{config}[\text{gridSize}][\text{Ny}]\}];\\
\text{      }U = \text{Table}[\\
\text{        }\text{WindU}[\text{TGrid}[[t]], \text{XGrid}[[i]], \text{YGrid}[[j]], \text{UInterp}], \{i, \text{config}[\text{gridSize}][\text{Nx}]\},
\{j, \text{config}[\text{gridSize}][\text{Ny}]\}];\\
\text{      }V = \text{Table}[\\
\text{        }\text{WindV}[\text{TGrid}[[t]], \text{XGrid}[[i]], \text{YGrid}[[j]], \text{VInterp}], \{i, \text{config}[\text{gridSize}][\text{Nx}]\},
\{j, \text{config}[\text{gridSize}][\text{Ny}]\}];\\
\text{      }\text{dCO2} = \\
\text{       }\text{DiffusionAdvection}[\text{CO2Conc}, U, V, \text{sigma}[[\text{All}, \text{All}, 1]], \\
\text{        }\text{sigma}[[\text{All}, \text{All}, 2]], \text{config}[\text{timeRange}][\text{dt}], \text{config}[\text{gridSize}][\text{Nx}],
\text{config}[\text{gridSize}][\text{Ny}]];\\
\text{      }\text{dVOC} = \\
\text{       }\text{DiffusionAdvection}[\text{VOCConc}, U, V, \text{sigma}[[\text{All}, \text{All}, 1]], \\
\text{        }\text{sigma}[[\text{All}, \text{All}, 2]], \text{config}[\text{timeRange}][\text{dt}], \text{config}[\text{gridSize}][\text{Nx}],
\text{config}[\text{gridSize}][\text{Ny}]];\\
\text{      }\text{CO2Conc} \text{+=} \text{dCO2} - \text{config}[\text{decayRates}][\text{kCO2}]*\text{CO2Conc};\\
\text{      }\text{VOCConc} \text{+=} \text{dVOC} - \text{config}[\text{decayRates}][\text{kVOC}]*\text{VOCConc};\\
\text{      }\\
\text{      }\text{(*Add external sources periodically*)}\\
\text{      }\text{If}[\text{Mod}[t, \text{sourceFreq}] \text{==} 0, \\
\text{       }\text{CO2Conc}[[\text{sourceX}, \text{sourceY}]] \text{+=} \text{CO2Increment};\text{  }\text{(*Add CO2 at source in ppm*)}\\
\text{       }\text{VOCConc}[[\text{sourceX}, \text{sourceY}]] \text{+=} \text{VOCIncrement};\text{   }\text{(*Add VOCs at source in ppb*)}\\
\text{      }];\\
\text{      }], \\
\text{     }\text{Row}[\{\text{Calculation Progress: }, \\
\text{       }\text{ProgressIndicator}[t, \{1, \text{Length}[\text{TGrid}]\}]\}]];\\
\text{      }\\
\text{    }\text{Return}[\{\text{CO2Conc}, \text{VOCConc}\}]\\
];

\section*{8. Dashboard Module}

Combined Dashboard\\
Units: params in various units as defined above

\text{CombinedDashboard}[\text{params$\_$}, \text{CO2Conc$\_$}, \text{VOCConc$\_$}, \text{config$\_$}] \text{:=} \\
\text{  }\text{Module}[\{\text{annualEmissions} = \text{params}[\text{annualEmissions}], \\
\text{    }\text{population} = \text{params}[\text{population}], \\
\text{    }\text{startYear} = \text{params}[\text{startYear}], \text{halfTime} = \text{params}[\text{halfTime}], \\
\text{    }\text{fractionComp} = \text{params}[\text{fractionComp}], \\
\text{    }\text{baseComp} = \text{params}[\text{baseComp}], \\
\text{    }\text{climateBudget} = \text{params}[\text{climateBudget}], \\
\text{    }\text{costPerTon} = \text{params}[\text{costPerTon}]\},\text{(*Calculate base values*)}\\
\text{   }\text{totalEm} = \text{totalEmissionsNow}[\text{annualEmissions}, \text{population}];\\
\text{   }\text{emissionFunc}[\text{t$\_$}] \text{:=} \\
\text{    }\text{CO2EmissionFunction}[t, \text{totalEm}, \text{startYear}, \text{halfTime}];\\
\text{   }\text{compFunc}[\text{t$\_$}] \text{:=} \\
\text{    }\text{Kompensationsfunktion}[t, \text{fractionComp}, \text{baseComp}, \text{emissionFunc}, \\
\text{     }\text{totalEm}];\\
\text{   }\text{effectiveFunc}[\text{t$\_$}] \text{:=} \\
\text{    }\text{EffectiveEmissionsFunction}[t, \text{emissionFunc}, \text{compFunc}];\\
\text{   }\text{(*Calculate metrics*)}\\
\text{   }\text{netZero} = \text{NetZeroTime}[\text{effectiveFunc}, \text{startYear}];\\
\text{   }\text{cumulative2030} = \\
\text{    }\text{CumulativeEmissions}[2030, \text{startYear}, \text{effectiveFunc}];\\
\text{   }\text{cumulative2040} = \\
\text{    }\text{CumulativeEmissions}[2040, \text{startYear}, \text{effectiveFunc}];\\
\text{   }\text{cumulative2050} = \\
\text{    }\text{CumulativeEmissions}[2050, \text{startYear}, \text{effectiveFunc}];\\
\text{   }\text{budget} = \text{ClimateBudget}[\text{climateBudget}, \text{startYear}, \text{population}, 1];\\
\text{   }\text{costs} = \text{CompensationCosts}[\text{startYear}, \text{compFunc}, \text{costPerTon}];\\
\text{   }\text{(*Create dashboard*)}\\
\text{   }\text{Grid}[\{\text{(*Emission plot*)}\{\text{EmissionPlot}[\text{emissionFunc}, \text{compFunc}, \\
\text{       }\text{effectiveFunc}, \text{startYear}, 2050], \\
\text{      }\text{SpanFromLeft}\},\text{(*Diffusion plots*)}\{\text{DiffusionPlot}[\text{CO2Conc}, \\
\text{       }\text{CO$\unicode{2082}$ Diffusion (ppm)}, \text{config}[\text{gridSize}][\text{Nx}], \text{config}[\text{gridSize}][\text{Ny}]], \\
\text{      }\text{DiffusionPlot}[\text{VOCConc}, \\
\text{       }\text{VOCs Diffusion (ppb)}, \text{config}[\text{gridSize}][\text{Nx}], \text{config}[\text{gridSize}][\text{Ny}]]\},\text{(*3D plots*)}\{\text{DiffusionPlot3D}[\text{CO2Conc},
\\
\text{       }\text{3D CO$\unicode{2082}$ Diffusion (ppm)}, \text{config}[\text{gridSize}][\text{Nx}], \text{config}[\text{gridSize}][\text{Ny}]],
\\
\text{      }\text{DiffusionPlot3D}[\text{VOCConc}, \\
\text{       }\text{3D VOCs Diffusion (ppb)}, \text{config}[\text{gridSize}][\text{Nx}], \text{config}[\text{gridSize}][\text{Ny}]]\},\text{(*}\text{Metrics}\text{*)}\{\text{Net
Zero Year:}, \\
\text{      }\text{netZero}\}, \{\text{Total Emissions 2030:}, \\
\text{      }\text{cumulative2030}\}, \{\text{Total Emissions 2040:}, \\
\text{      }\text{cumulative2040}\}, \{\text{Total Emissions 2050:}, \\
\text{      }\text{cumulative2050}\}, \{\text{Climate Budget:}, \\
\text{      }\text{budget}\}, \{\text{Total Compensation Costs:}, \text{costs}\}\}, \text{Frame} \text{-$>$} \text{All}, \\
\text{    }\text{Spacings} \text{-$>$} \{2, 2\}]];

\section*{9. Main Execution Module}

Main execution function

\text{runSimulation}[] \text{:=} \text{Module}[\{\},\\
\text{  }\text{(*Generate grids*)}\\
\text{  }\{\text{XGrid}, \text{YGrid}, \text{TGrid}\} = \text{generateGrids}[\text{systemConfig}];\\
\text{  }\\
\text{  }\text{(*Load data*)}\\
\text{  }\text{windData} = \text{loadData}[\text{dataPaths}[\text{windData}]];\\
\text{  }\text{meteoData} = \text{loadData}[\text{dataPaths}[\text{meteoData}]];\\
\text{  }\text{pollutionData} = \text{loadData}[\text{dataPaths}[\text{pollutionData}]];\\
\text{  }\text{CO2Data} = \text{loadData}[\text{dataPaths}[\text{CO2Data}]];\\
\text{  }\\
\text{  }\text{(*Create interpolation functions*)}\\
\text{  }\text{UInterp} = \text{createInterpolation}[\text{windData}, \{1, 2\}];\\
\text{  }\text{VInterp} = \text{createInterpolation}[\text{windData}, \{1, 3\}];\\
\text{  }\text{CO2Interp} = \text{createInterpolation}[\text{pollutionData}, \{1, 4\}];\\
\text{  }\text{VOCInterp} = \text{createInterpolation}[\text{CO2Data}, \{1, 4\}];\\
\text{  }\\
\text{  }\text{(*Run simulation*)}\\
\text{  }\{\text{CO2Conc}, \text{VOCConc}\} = \text{runDiffusionSimulation}[\text{systemConfig}, \text{UInterp}, \text{VInterp}, \text{XGrid}, \text{YGrid},
\text{TGrid}];\\
\text{  }\\
\text{  }\text{(*Return results*)}\\
\text{  }\text{Return}[<|\text{CO2Conc} \text{-$>$} \text{CO2Conc}, \text{VOCConc} \text{-$>$} \text{VOCConc}, \\
\text{           }\text{XGrid} \text{-$>$} \text{XGrid}, \text{YGrid} \text{-$>$} \text{YGrid}, \text{TGrid} \text{-$>$} \text{TGrid}|>]\\
];

\section*{10. Interactive Simulation}

Run this cell to start the interactive simulation\\
Units: annualEmissions in tons CO$\unicode{2082}$/person/year\\
Units: population in thousands of people\\
Units: startYear in years\\
Units: halfTime in years\\
Units: fractionComp, baseComp in percentage\\
Units: climateBudget in tons CO$\unicode{2082}$/person/year\\
Units: costPerTon in USD/ton CO$\unicode{2082}$

\text{Manipulate}[\\
 \text{Module}[\{\text{params} = <|\text{annualEmissions} \text{-$>$} \text{annualEmissions}, \\
\text{     }\text{population} \text{-$>$} \text{population}, \text{startYear} \text{-$>$} \text{startYear}, \\
\text{     }\text{halfTime} \text{-$>$} \text{halfTime}, \text{fractionComp} \text{-$>$} \text{fractionComp}, \\
\text{     }\text{baseComp} \text{-$>$} \text{baseComp}, \text{climateBudget} \text{-$>$} \text{climateBudget}, \\
\text{     }\text{costPerTon} \text{-$>$} \text{costPerTon}|>, \text{results}\},\\
\text{  }\\
\text{  }\text{(*Run simulation if not already run*)}\\
\text{  }\text{If}[!\text{ValueQ}[\text{simulationResults}], \\
\text{    }\text{simulationResults} = \text{runSimulation}[]];\\
\text{  }\\
\text{  }\text{(*Get results*)}\\
\text{  }\text{results} = \text{simulationResults};\\
\text{  }\\
\text{  }\text{(*Display dashboard*)}\\
\text{  }\text{CombinedDashboard}[\text{params}, \text{results}[\text{CO2Conc}], \text{results}[\text{VOCConc}], \text{systemConfig}]\\
 ], \\
 \{\{\text{annualEmissions}, 10, \text{Annual Emissions per Person (tons CO$\unicode{2082}$/person/year)}\}, 1, 20\}, \\
 \{\{\text{population}, 1000, \text{Population (thousands)}\}, 100, 10000\}, \\
 \{\{\text{startYear}, 2024, \text{Start Year}\}, 2020, 2030\}, \\
 \{\{\text{halfTime}, 10, \text{Half Time (years)}\}, 5, 30\}, \\
 \{\{\text{fractionComp}, 50, \text{Fraction Compensation ($\%$)}\}, 0, 100\}, \\
 \{\{\text{baseComp}, 20, \text{Base Compensation ($\%$)}\}, 0, 100\}, \\
 \{\{\text{climateBudget}, 2, \text{Climate Budget (tons CO$\unicode{2082}$/person/year)}\}, 0.5, 5\}, \\
 \{\{\text{costPerTon}, 100, \text{Cost per Ton CO$\unicode{2082}$ (USD)}\}, 50, 200\}]

\section*{11. Cloud Deployment Configuration}

Cloud deployment settings

\text{cloudConfig} = <|\\
\text{  }\text{platform} \text{-$>$} \text{Wolfram Cloud},\\
\text{  }\text{apiEndpoint} \text{-$>$} \text{https://api.wolframcloud.com/v1/},\\
\text{  }\text{authentication} \text{-$>$} \text{OAuth},\\
\text{  }\text{dataStorage} \text{-$>$} \text{Wolfram Data Drop},\\
\text{  }\text{computeResources} \text{-$>$} <|\\
\text{    }\text{cpu} \text{-$>$} \text{4 cores},\\
\text{    }\text{memory} \text{-$>$} \text{8 GB},\\
\text{    }\text{storage} \text{-$>$} \text{100 GB}\\
\text{  }|>\\
|>;

Export simulation results to cloud

\text{exportToCloud}[\text{results$\_$}, \text{filename$\_$}] \text{:=} \text{Module}[\{\},\\
\text{  }\text{(*Export results to a format suitable for cloud storage*)}\\
\text{  }\text{Export}[\text{filename} <> \text{.wdx}, \text{results}];\\
\text{  }\\
\text{  }\text{(*Return success message*)}\\
\text{  }\text{Return}[\text{Results exported to } <> \text{filename} <> \text{.wdx}]\\
];

Generate cloud deployment package

\text{generateCloudPackage}[] \text{:=} \text{Module}[\{\},\\
\text{  }\text{(*Create a deployment package*)}\\
\text{  }\text{CloudDeploy}[\text{Notebook}[\{\\
\text{    }\text{Cell}[\text{Carbon Emission and Diffusion Simulation}, \text{Title}],\\
\text{    }\text{Cell}[\text{BoxData}[\text{ToBoxes}[\text{runSimulation}[]]], \text{Input}],\\
\text{    }\text{Cell}[\text{BoxData}[\text{ToBoxes}[\text{Manipulate}[\text{(*Interactive simulation code*)}]]], \text{Input}]\\
\text{  }\}], \text{CarbonEmissionSimulation}, \\
\text{  }\text{Permissions} \text{-$>$} \text{Public}];\\
\text{  }\\
\text{  }\text{(*Return success message*)}\\
\text{  }\text{Return}[\text{Cloud deployment package generated successfully}]\\
];

\section*{12. Example Usage}

Run this cell to see an example visualization with default parameters

\text{Module}[\{\text{params} = <|\text{annualEmissions} \text{-$>$} 10, \text{population} \text{-$>$} 1000, \\
\text{    }\text{startYear} \text{-$>$} 2024, \text{halfTime} \text{-$>$} 10, \text{fractionComp} \text{-$>$} 50, \\
\text{    }\text{baseComp} \text{-$>$} 20, \text{climateBudget} \text{-$>$} 2, \text{costPerTon} \text{-$>$} 100|>, \text{results}\},\\
\text{  }\\
\text{  }\text{(*Run simulation if not already run*)}\\
\text{  }\text{If}[!\text{ValueQ}[\text{simulationResults}], \\
\text{    }\text{simulationResults} = \text{runSimulation}[]];\\
\text{  }\\
\text{  }\text{(*Get results*)}\\
\text{  }\text{results} = \text{simulationResults};\\
\text{  }\\
\text{  }\text{(*Display dashboard*)}\\
\text{  }\text{CombinedDashboard}[\text{params}, \text{results}[\text{CO2Conc}], \text{results}[\text{VOCConc}], \text{systemConfig}]\\
]\\
\\
\text{(*End of file*)}

\end{document}
