Skip to content

Commit 00c3da0

Browse files
authored
Merge pull request #294 from ashiklom/pkgdown
Hector documentation website with `pkgdown`
2 parents a1b73a3 + 78a733e commit 00c3da0

19 files changed

+667
-1
lines changed

.Rbuildignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,7 @@
2727
^src/testing$
2828
^misc$
2929
^data-raw$
30+
31+
# pkgdown config and output
32+
^inst/_pkgdown.yml
33+
^docs/

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,9 @@ R/batchrunner/*.csv
6464
.RData
6565
inst/doc
6666
vignettes/rsconnect
67+
68+
# pkgdown output
69+
/docs/
70+
71+
# vignette caches
72+
/vignettes/*_cache

.travis.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,12 @@ matrix:
7979
sources:
8080
- boost-latest
8181
cache: packages
82+
83+
# Automatically deploy Hector documentation on the gh-pages
84+
# branch. This is based on this guide from `pkgdown`:
85+
# https://pkgdown.r-lib.org/reference/deploy_site_github.html
86+
before_deploy: Rscript -e 'remotes::install_cran("pkgdown")'
87+
deploy:
88+
provider: script
89+
script: Rscript -e 'pkgdown::deploy_site_github()'
90+
skip_cleanup: true

inst/_pkgdown.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
navbar:
2+
structure:
3+
left:
4+
- home
5+
- manual
6+
- vignettes
7+
- reference
8+
- news
9+
right: github
10+
components:
11+
home:
12+
icon: fa-home fa-lg
13+
href: index.html
14+
reference:
15+
text: Reference
16+
href: reference/index.html
17+
manual:
18+
text: Manual
19+
href: articles/manual/index.html
20+
vignettes:
21+
text: Vignettes
22+
menu:
23+
- text: "A tour of the Hector R interface"
24+
href: articles/intro-to-hector.html
25+
- text: "Example: Using Hector to solve for an emissions pathway"
26+
href: articles/hector_apply.html
27+
articles: ~

vignettes/intro-to-hector.Rmd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ vignette: >
99
%\VignetteEncoding{UTF-8}
1010
---
1111

12+
```{r setup, include = FALSE}
13+
knitr::opts_chunk$set(cache = TRUE)
14+
```
15+
1216
This vignette provides a basic introduction for running Hector with R.
1317
First, it shows how to do a simple Hector run with one of Hector's built-in scenarios.
1418
Then, it shows how to modify Hector parameters from within R and uses this functionality to perform a simple sensitivity analysis of how the CO$_2$ fertilization parameter $\beta$ affects several Hector output variables.
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
---
2+
title: Adding a new component
3+
---
4+
Here are the steps to create a new component `X`.
5+
6+
Step one:
7+
-----------
8+
9+
Add two new files:
10+
* headers/core/X.hpp
11+
* source/core/X.cpp
12+
13+
It is best to copy and modify the corresponding files from an already constructed component.
14+
15+
Step two (within X.hpp):
16+
-----------
17+
Under `private` list the variables that are used in the component and their corresponding type. E.g.
18+
* `tseries<unitval> x` to create a [time series](TSeries.html).
19+
* `unitval x` to declare a [value with associated units](Unitvals.html).
20+
* `double x`
21+
22+
Step three (within X.cpp):
23+
---------
24+
Make sure that you `#include X.hpp`.
25+
26+
_In the constructor_
27+
If the variable is a tseries, add all of the variables allowing for interpolation and their corresponding names
28+
29+
XComponent::XComponent() {
30+
X_emissions.allowInterp( true );
31+
X_emissions.name = X_COMPONENT_NAME;
32+
33+
_In X::init_
34+
Inform the core what data the component can provide (*registerCapability*) and what data the component depends on (*registerDependency*)
35+
36+
core->registerCapability( D_ATMOSPHERIC_X, getComponentName() );
37+
core->registerDependency( D_LIFETIME_X, getComponentName() );
38+
39+
_In X::setData_
40+
Set the data that are used as inputs within this component, typically coming from the ini file. [[For examples of tseries vs. unitvals in setData|AddTSeries]].
41+
42+
_In X::prepareToRun_
43+
TODO: describe
44+
45+
_In X::run_
46+
The run method contains the equations and code used in this component. Here is where you would want a log statement, written out to the component's log.
47+
48+
`H_LOG( logger, Logger::DEBUG ) << "Year " << runToDate << " X concentration = " << X.get( runToDate ) << std::endl;`
49+
50+
TODO: mention spinup flag return.
51+
52+
53+
_In X::getData_
54+
These are data that the component can provide to another component, or the data that is being generated within the component. [[For examples of tseries vs. unitvals in getData|AddTSeries]].
55+
56+
_In X::shutDown_
57+
TODO: describe
58+
59+
Step four (Outside of X.cpp and X.hpp):
60+
----------------------------------------
61+
62+
_In avistor.hpp_
63+
Add class XComponent under the declarations of subclasses
64+
Add `virtual void visit( XComponent*c ) {}`
65+
66+
_In core.cpp_
67+
`#include "components/xcomponent.hpp" `
68+
Under init add:
69+
`temp = new XComponent();`
70+
`modelComponents[ temp-->getComponentName() ] = temp;`
71+
72+
_In component_names.hpp_
73+
Under component names:
74+
`#define X_COMPONENT_NAME “x”`
75+
76+
_In component_data.hpp_
77+
define the variables within the component
78+
`#define D_ATMOSPHERIC_X "X"`
79+
80+
_In csv_outputstream_visitor.cpp_
81+
`#include 'components/xcomponent.hpp' `
82+
83+
void CSVOutputStreamVisitor::visit( XComponent* c ) {
84+
if( !core->outputEnabled( c->getComponentName() ) && !in_spinup ) return;
85+
STREAM_MESSAGE_DATE( csvFile, c, D_X_COMPONENT, current_date );
86+
}
87+
88+
_In csv_outputsream_visitor.hpp_
89+
under public
90+
`virtual void visit( XComponent* c);`
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
title: Adding a new variable
3+
---
4+
5+
Adding a new variable to a method
6+
using getData to obtain the information defined in the ini file
7+
8+
In hector.ini under the corresponding component add variable
9+
Ex: SN = 42000;
10+
11+
12+
In hpp file of component add variable as tseries/unitval/double/etc.
13+
14+
In component_data.hpp define the variables that are being added
15+
Ex: #define D_ATMOSPHERIC_SO2 "SN"
16+
These names do *not* have to match internal component variables but
17+
the ini definition *has to* match what appears in quotes
18+
19+
In the component file .cpp
20+
under init, need to register the Capability
21+
core->registerCapability( D_ATMOSPHERIC_SO2, getComponentName() );
22+
23+
In cpp file of component, under getData and setData, add the new variables in before the Error message
24+
NOTE: see tseries documentation for more information on getData
25+
26+
(getData)
27+
else if( varName == D_ATMOSPHERIC_SO2 ) {
28+
29+
returnval = SN;
30+
31+
(setData)
32+
else if( varName == D_ATMOSPHERIC_SO2 ) {
33+
34+
H_ASSERT( data.date == Core::undefinedIndex(), "date not allowed" );
35+
36+
SN.set( lexical_cast<double>( value ), U_GG );
37+
}
38+
39+
40+
If this variable is called in another component.
41+
For example if adding in a variable within the focing component
42+
Ex: unitval SN = core->getData( D_ATMOSPHERIC_SO2, runToDate);
43+
44+
If this variable is a unitval, the new unitval needs to appear in the unitval.hpp file.

vignettes/manual/Backend.Rmd

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
title: Hector R backend
3+
---
4+
5+
A simple guide for reproducing the figures using R found with the Hartin et al., (2015) GMD study.
6+
7+
First
8+
-------
9+
We need 3 files that do not change:
10+
op.R, op_parser.R, and op_grapher.R
11+
12+
Second
13+
----------
14+
Make an experiment specific script that will process all of the Hector, CMIP5, and MAGICC data and save in a csv file.
15+
16+
For example:
17+
Specify the input files and the scenarios
18+
INFILES <- c("outputstream_rcp26.csv","outputstream_rcp45.csv","outputstream_rcp60.csv", "outputstream_rcp85.csv")
19+
20+
SCENARIOS <-c("rcp26","rcp45","rcp60", "rcp85")
21+
COMPARISON_DATA <- "/hector/output/comparison_data/GMD_2014/"
22+
23+
Call op.R which will read in the model results and any supplementary data
24+
source( "/hector/output/op.R" ) # read in data, etc.
25+
26+
Save the dataframe (d) in a large csv file to be used in figures.R
27+
write.table(d, file="hector_data.csv", row.names=F)
28+
29+
Third
30+
------
31+
Open figures_GMD2015.R and specify the location of the input file and the output directory at the top.
32+
Save and source the file. Figures will be generated along with correlation tables for each figure within the output directory.
33+
34+

vignettes/manual/BuildHector.Rmd

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
Installing and building - all platforms
2+
---------------------------------
3+
Hector relies on several libraries, all of which are freely available
4+
under a GPL or similar license. In order to build and run Hector, you
5+
will need to download and install these libraries on your system. These include:
6+
7+
* *REQUIRED*: Boost. Free peer-reviewed portable C++ source libraries, available at http://www.boost.org/.
8+
Hector uses only the parts of Boost that are implemented as header libraries (i.e., all of the code is
9+
contained in header files that are included and compiled with the Hector source). Therefore, all you need to
10+
do to set up Boost is to download and extract it. Hector requires Boost version ≥ 1_52_0.
11+
12+
* *REQUIRED*: Gnu Scientific Library. A numerical library for C and C++, available at http://www.gnu.org/software/gsl/. You will need to download and follow the Boost README instructions. You will need to compile and install the GSL. To do this, unpack the GSL tar file in the location of your choice. Follow the setup instructions in the GSL README file. Briefly, they comprise three steps: `./configure`, `make`, and `make install`. You will need to have root (superuser) privilege to perform the last step, unless you choose an install directory somewhere under your own home directory (see the GSL README for instructions on how to do this). Hector has been tested with, and is currently using, GSL version 1.16.
13+
14+
Installing and building - Mac OS X (Xcode)
15+
---------------------------------
16+
17+
These directions assume a basic familiarity with Xcode and Mac OS X software installation. (If you're going to use `make` and not Xcode, see Linux directions below.)
18+
19+
* Install [Xcode](https://developer.apple.com/xcode/downloads/) if necessary. Hector has been built and tested with Mac OS 10.8.5 ~~and 10.10 (Yosemite)~~. The project files are for Xcode 5.1.1.
20+
* Download and install Boost and GSL, following instructions above.
21+
* Download the [Hector zip file](https://github.com/JGCRI/hector/archive/master.zip) or check out the repository using Git.
22+
* From Xcode, open the project file in `project_files/Xcode/hector.cxodeproj`.
23+
* Build the project. See below if you encounter errors.
24+
* Change the current Scheme settings (Scheme->Edit Scheme) and add a command-line argument (*Arguments* tab, e.g. "input/hector_rcp45.ini").
25+
* Run!
26+
27+
Xcode Build Settings to check/change if you encounter build errors:
28+
* *Architectures-Base SDK*: OS X 10.8 [or OS X version on machine]
29+
* *Build Options-Compiler for C/C++/Objective-C*: Default compiler (Apple LLVM 5.1)
30+
* *Search Paths-Header Search Paths*: "/usr/local/include /usr/local/lib/boost_1_52_0/" [or other header directories]
31+
* *Search Paths-Library Search Paths*: "/usr/local/lib/" [or other library directories]
32+
* *LLVM-Language-C++-C++ Standard Library*: libc++ (LLVM C++ standard library with C++11 support)
33+
* *Linking-Other Linker Flags*: "-lgsl -lgslcblas -lm"
34+
* *User-Defined*: "GCC_MODEL_TUNING" defined as "G5"
35+
36+
37+
Installing and building - Windows
38+
---------------------------------
39+
* Install Visual Studio, if necessary.
40+
* Download and install *Boost* and *GSL*, following instructions above.
41+
* Download the [Hector zip file](https://github.com/JGCRI/hector/archive/master.zip) or check out the repository using Git.
42+
* TODO
43+
44+
Installing and building - Linux
45+
---------------------------------
46+
The Hector makefiles look for the required libraries (above) in certain default
47+
locations, but those defaults can be overridden by setting the
48+
environment variables described below.
49+
50+
**Boost**
51+
52+
Environment variables:
53+
54+
* BOOSTROOT (default `$(HOME)/src/boost_$(BOOSTVERSION)`).
55+
This variable should contain the full name of the directory created
56+
when you unpacked Boost. If you unpacked Boost in `$(HOME)/src`, then
57+
all you need to do is set the `BOOSTVERSION` variable (*q.v.* below) and leave this variable
58+
at its default value. If you unpacked Boost somewhere else, or if you changed the name
59+
of the directory that was created when you unpacked it, then you will
60+
need to set this variable explicitly.
61+
62+
* BOOSTVERSION (default: `1_52_0`). This variable should contain the
63+
version number of the version of Boost that you installed. The
64+
version number will appear in the name of the tar file you
65+
downloaded. The `BOOSTVERSION` variable is used in the default value of `BOOSTROOT` to determine the default installation
66+
directory. If you override the default value of `BOOSTROOT` you can ignore this variable.
67+
68+
**GNU Scientific Library (GSL)**
69+
70+
The default
71+
install location for GSL is /usr/local, and that is also the default for
72+
Hector. Therefore, if you use the GSL default installation procedure,
73+
you will not need to override the Hector defaults. If you choose to
74+
install GSL somewhere else, use the environment variable below to indicate
75+
where you installed it.
76+
77+
Environment variables:
78+
79+
* GSLROOT (default: `/usr/local`).
80+
Set this variable to the same install directory that you used when you
81+
configured GSL.
82+
83+
**Shared Library Search Path**
84+
85+
Some of the libraries used by Hector (such as the GSL) will be
86+
compiled into shared libraries that will loaded at run time. It is
87+
best if these libraries are in directories that are part of your
88+
system's shared library search path. On many systems `/usr/local` is
89+
already in that path. If you install the libraries somewhere else,
90+
you may need to add the installation directories to the list given in
91+
`/etc/ld.so.conf`. Whether or not you install the GSL libraries in the default location, when you compile and install them
92+
you may need to refresh the library cache by running
93+
`ldconfig` (which generally requires root privilege), or by rebooting your system
94+
(which does not).
95+
96+
If you are unable to add your library installation directory to the
97+
library search path, you will need to add the installation directory
98+
to the environment variable `LD_LIBRARY_PATH`. Try not to use this approach if you
99+
can help it because it can cause some conflicts with other software on your system.
100+
Instead, ask your system administrator if ldconfig is right for you.
101+
102+
**Building Hector**
103+
104+
Once the necessary libraries are installed, change to the top-level
105+
Hector directory and type `make hector`. The hector executable will
106+
be built in the `source/` subdirectory. If you ever need to rebuild,
107+
you can type `make clean` to clear away the executable and all of the
108+
intermediate files.
109+
110+
There are two additional environment variables that you can use to
111+
fine-tune the build process. The `CXXEXTRA` variable is passed to the
112+
C++ compiler. You can use this variable to pass extra options to the
113+
compiler without changing the Makefile. In particular, specifying
114+
optimization options in `CXXEXTRA` such as -O or -O0 will override the
115+
default value of -O3.
116+
117+
The `CXXPROF` variable is passed both to the compiler and the linker.
118+
It is intended to turn on performance profiling, which must be
119+
specified at both the compile and link stages of the build, so it
120+
generally should be either unset (for normal operation) or set to -pg
121+
(for profiling). Profiling slows the code down dramatically, so if you use it, be
122+
sure to unset `CXXPROF`, clean the build directories with `make clean`,
123+
and rebuild when you are ready to go back to
124+
production runs.
125+
126+
Installing and building - iOS/Android
127+
---------------------------------
128+
Not yet. ;)

vignettes/manual/ComponentAPI.Rmd

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
title: Hector component API
3+
---
4+
5+
**Constructor**
6+
* Assigning time series names and interpolation settings.
7+
* Assigning default values.
8+
9+
**init()**
10+
* Opening the log.
11+
* Storing pointer to the core (not available before then).
12+
* Registering dependencies (ditto).
13+
* Registering capabilities (ditto).
14+
15+
**prepareToRun()**
16+
* Any initialization that depends on user-input data.
17+
* Any initialization that depends on model start date.
18+
19+
**setData()**
20+
21+
**getData()**
22+
23+
**runSpinup()**
24+
25+
**run()**
26+
27+
**shutDown()**
28+
* Close the log.

0 commit comments

Comments
 (0)