Skip to content

Commit

Permalink
#34: Move R_e calculation to meteostation and make R_e part of Weather
Browse files Browse the repository at this point in the history
  • Loading branch information
philippkraft committed Mar 22, 2019
1 parent c9e529c commit 8cac9fd
Show file tree
Hide file tree
Showing 5 changed files with 29,609 additions and 8,948 deletions.
2 changes: 1 addition & 1 deletion cmf/cmf_core_src/atmosphere/Weather.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace cmf {
- If sub daily: \f$ R_a = \frac{12\ 24\ 60}{\pi}G_{sc}\ d_r \left(\left(\omega^+ -\omega^-\right) \sin\phi \sin\delta + \cos\phi \cos\delta \left(\sin\omega^+ - \sin\omega^-\right)\right) \f$
- \f$ \omega^+,\omega^- = \omega \pm\frac{\pi}{24} \f$
**/
double extraterrestrial_radiation(cmf::math::Time t, double longitude=8, double latitude=51, double time_zone=1, bool daily=false);
double extraterrestrial_radiation(cmf::math::Time t, double longitude=8, double latitude=51, double time_zone=1, bool daily=0);

///
/** @brief Calculates the global radiation in MJ/(m2 day) from the sun position and the sunshine fraction
Expand Down
5 changes: 2 additions & 3 deletions cmf/cmf_core_src/atmosphere/meteorology.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "../math/num_array.h"
#include "../upslope/cell.h"
#include "../project.h"
#include "Weather.h"
#include <fstream>
#define min(a,get_b) ((a)<(get_b)) ? (a) : (get_b)
#define max(a,get_b) ((a)>(get_b)) ? (a) : (get_b)
Expand All @@ -33,7 +32,7 @@ using namespace cmf::math;
using namespace cmf::geometry;


cmf::atmosphere::Weather cmf::atmosphere::MeteoStation::get_data( cmf::math::Time t,double height ) const
cmf::atmosphere::Weather cmf::atmosphere::MeteoStation::get_data( cmf::math::Time t, double height ) const
{
Weather A;
if (Tmax.is_empty())
Expand Down Expand Up @@ -71,7 +70,7 @@ cmf::atmosphere::Weather cmf::atmosphere::MeteoStation::get_data( cmf::math::Tim
else // no humidity data available, assume Tmin=Tdew
A.e_a=vapour_pressure(A.Tmin);
A.sunshine=Sunshine.is_empty() ? 0.5 : Sunshine[t];
A.Ra = cmf::atmosphere::extraterrestrial_radiation(t, Longitude, Latitude, Timezone, daily);
A.Ra = extraterrestrial_radiation(t, Longitude, Latitude, Timezone, daily);
if (Rs.is_empty())
A.Rs=global_radiation(A.Ra, height, A.sunshine);
else
Expand Down
273 changes: 141 additions & 132 deletions cmf/cmf_core_src/cmf.i
Original file line number Diff line number Diff line change
@@ -1,132 +1,141 @@
// Copyright 2010 by Philipp Kraft
// This file is part of cmf.
//
// cmf is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// cmf is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with cmf. If not, see <http://www.gnu.org/licenses/>.
//
// Get Documentation

%feature("compactdefaultargs");
%include "docstrings.i"
%feature("autodoc","1");

// Usage for automated downcast
%include "factory.i"

// Include typemaps for STL
%include "std_string.i"

// enable exception support
%include "exception.i"
%exception {
try {
$action
} catch (const std::out_of_range& e) {
SWIG_exception(SWIG_IndexError, e.what());
} catch (const std::exception& e) {
SWIG_exception(SWIG_RuntimeError, e.what());
}

}
%include "attribute.i"

/* #define SWIG_SHARED_PTR_SUBNAMESPACE */
%include <std_shared_ptr.i>
%{
#include "cmfmemory.h"
%}
%include "cmf_swiglib.i"

%{
std::string pyrepr(PyObject* o) {
PyObject* s = PyObject_Repr(o);
#if PY_MAJOR_VERSION < 3
std::string res = PyString_AsString(s);
#else
std::string res = PyUnicode_AsUTF8(s);
#endif
Py_XDECREF(s);
return res;
}
%}

// Start my Module
%module cmf_core
%include "math/num_array.i"
%include "geometry/geometry.i"
%include "math/time.i"
%include "math/ODEsystem.i"
%include "water/water.i"
%include "atmosphere/meteorology.i"
%include "upslope/cell.i"
%include "upslope/Layer.i"
%include "reach/Reach.i"

///////////////////////////
// Surfacewater
//////////////////////////

%shared_ptr(cmf::upslope::SurfaceWater);
%attribute(cmf::upslope::SurfaceWater,real,puddledepth,get_puddledepth,set_puddledepth);
%attribute(cmf::upslope::SurfaceWater,real,nManning,get_nManning,set_nManning);

%include "upslope/surfacewater.h"
%extend__repr__(cmf::upslope::SurfaceWater)

/////////////////////////////
%{
#include "upslope/groundwater.h"
#include "upslope/connections/subsurfacefluxes.h"
#include "upslope/connections/surfacefluxes.h"
#include "upslope/connections/AtmosphericFluxes.h"
#include "upslope/connections/infiltration.h"
#include "upslope/connections/Percolation.h"
#include "upslope/vegetation/ET.h"
#include "upslope/vegetation/ShuttleworthWallace.h"
// Include river model
#include "reach/ManningConnection.h"
%}

%shared_ptr(cmf::upslope::aquifer);
%attribute(cmf::upslope::aquifer,double,base_height,get_base_height);
%attribute(cmf::upslope::aquifer,double,top_height,get_top_height);
%include "upslope/groundwater.h"
%extend__repr__(cmf::upslope::aquifer)

%include "upslope/connections/subsurfacefluxes.h"
%include "reach/ManningConnection.h"

%include "upslope/connections/surfacefluxes.h"
%include "upslope/connections/AtmosphericFluxes.h"
%include "upslope/connections/infiltration.h"
%include "upslope/connections/Percolation.h"
%include "upslope/vegetation/waterstress.h"

%include "upslope/vegetation/ET.h"

%shared_ptr(cmf::upslope::ET::ShuttleworthWallace);
%include "upslope/vegetation/ShuttleworthWallace.h"

%include "project.i"

%include "math/integrator.i"


%pythoncode {
ConstantFlux = TechnicalFlux
ConstantStateFlux = statecontrol_connection
WaterBalanceFlux = waterbalance_connection
ConceptualInfiltration = SimpleInfiltration
}


// Copyright 2010 by Philipp Kraft
// This file is part of cmf.
//
// cmf is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// cmf is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with cmf. If not, see <http://www.gnu.org/licenses/>.
//
// Get Documentation

%feature("compactdefaultargs");
%include "docstrings.i"
%feature("autodoc","1");

// Usage for automated downcast
%include "factory.i"

// Include typemaps for STL
%include "std_string.i"
%include "std_vector.i"

namespace std {
%template(vector_int) vector<int>;
%template(vector_double) vector<double>;
%template(vector_size_t) vector<size_t>;
};

// enable exception support
%include "exception.i"
%exception {
try {
$action
} catch (const std::out_of_range& e) {
SWIG_exception(SWIG_IndexError, e.what());
} catch (const std::exception& e) {
SWIG_exception(SWIG_RuntimeError, e.what());
}

}
%include "attribute.i"

/* #define SWIG_SHARED_PTR_SUBNAMESPACE */
%include <std_shared_ptr.i>
%{
#include "cmfmemory.h"
%}
%include "cmf_swiglib.i"

%{
std::string pyrepr(PyObject* o) {
PyObject* s = PyObject_Repr(o);
#if PY_MAJOR_VERSION < 3
std::string res = PyString_AsString(s);
#else
std::string res = PyUnicode_AsUTF8(s);
#endif
Py_XDECREF(s);
return res;
}
%}

// Start my Module
%module cmf_core
%include "math/num_array.i"
%include "geometry/geometry.i"
%include "math/time.i"

%include "math/ODEsystem.i"

%include "water/water.i"
%include "atmosphere/meteorology.i"
%include "upslope/cell.i"
%include "upslope/Layer.i"
%include "reach/Reach.i"

///////////////////////////
// Surfacewater
//////////////////////////

%shared_ptr(cmf::upslope::SurfaceWater);
%attribute(cmf::upslope::SurfaceWater,real,puddledepth,get_puddledepth,set_puddledepth);
%attribute(cmf::upslope::SurfaceWater,real,nManning,get_nManning,set_nManning);

%include "upslope/surfacewater.h"
%extend__repr__(cmf::upslope::SurfaceWater)

/////////////////////////////
%{
#include "upslope/groundwater.h"
#include "upslope/connections/subsurfacefluxes.h"
#include "upslope/connections/surfacefluxes.h"
#include "upslope/connections/AtmosphericFluxes.h"
#include "upslope/connections/infiltration.h"
#include "upslope/connections/Percolation.h"
#include "upslope/vegetation/ET.h"
#include "upslope/vegetation/ShuttleworthWallace.h"
// Include river model
#include "reach/ManningConnection.h"
%}

%shared_ptr(cmf::upslope::aquifer);
%attribute(cmf::upslope::aquifer,double,base_height,get_base_height);
%attribute(cmf::upslope::aquifer,double,top_height,get_top_height);
%include "upslope/groundwater.h"
%extend__repr__(cmf::upslope::aquifer)

%include "upslope/connections/subsurfacefluxes.h"
%include "reach/ManningConnection.h"

%include "upslope/connections/surfacefluxes.h"
%include "upslope/connections/AtmosphericFluxes.h"
%include "upslope/connections/infiltration.h"
%include "upslope/connections/Percolation.h"
%include "upslope/vegetation/waterstress.h"

%include "upslope/vegetation/ET.h"

%shared_ptr(cmf::upslope::ET::ShuttleworthWallace);
%include "upslope/vegetation/ShuttleworthWallace.h"

%include "project.i"

%include "math/integrator.i"


%pythoncode {
ConstantFlux = TechnicalFlux
ConstantStateFlux = statecontrol_connection
WaterBalanceFlux = waterbalance_connection
ConceptualInfiltration = SimpleInfiltration
}


Loading

0 comments on commit 8cac9fd

Please sign in to comment.