Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#
# LASAM (aka lgar-c, CASAM) CMakeLists.txt
#

cmake_minimum_required(VERSION 3.10)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_C_COMPILER $ENV{CC})
Expand Down Expand Up @@ -69,13 +73,13 @@ ENDIF((NOT ${NGEN}) AND (NOT ${STANDALONE}))

if(STANDALONE)
add_executable(${exe_name} ./src/bmi_main_lgar.cxx ./src/bmi_lgar.cxx ./src/lgar.cxx ./src/soil_funcs.cxx
./src/linked_list.cxx ./src/mem_funcs.cxx ./src/util_funcs.cxx ./src/aet.cxx ./src/Logger.cpp ./include/Logger.hpp
./src/linked_list.cxx ./src/mem_funcs.cxx ./src/util_funcs.cxx ./src/aet.cxx
./giuh/giuh.h ./giuh/giuh.c)
target_link_libraries(${exe_name} PRIVATE m)
target_link_libraries(${exe_name} PRIVATE Boost::serialization)
elseif(UNITTEST)
add_executable(${exe_name} ./tests/main_unit_test_bmi.cxx ./src/bmi_lgar.cxx ./src/lgar.cxx ./src/soil_funcs.cxx
./src/linked_list.cxx ./src/mem_funcs.cxx ./src/util_funcs.cxx ./src/aet.cxx ./src/Logger.cpp ./include/Logger.hpp ./giuh/giuh.h
./src/linked_list.cxx ./src/mem_funcs.cxx ./src/util_funcs.cxx ./src/aet.cxx ./giuh/giuh.h
./giuh/giuh.c)
target_link_libraries(${exe_name} PRIVATE m)
target_link_libraries(${exe_name} PRIVATE Boost::serialization)
Expand All @@ -91,10 +95,10 @@ add_compile_definitions(BMI_ACTIVE)

if(WIN32)
add_library(lasambmi SHARED src/bmi_lgar.cxx src/lgar.cxx ./src/soil_funcs.cxx ./src/linked_list.cxx ./src/mem_funcs.cxx
./src/util_funcs.cxx ./src/aet.cxx ./src/Logger.cpp ./include/Logger.hpp ./giuh/giuh.c include/all.hxx ./giuh/giuh.h)
./src/util_funcs.cxx ./src/aet.cxx ./giuh/giuh.c include/all.hxx ./giuh/giuh.h)
else()
add_library(lasambmi SHARED src/bmi_lgar.cxx src/lgar.cxx ./src/soil_funcs.cxx ./src/linked_list.cxx ./src/mem_funcs.cxx
./src/util_funcs.cxx ./src/aet.cxx ./src/Logger.cpp ./include/Logger.hpp ./giuh/giuh.c include/all.hxx ./giuh/giuh.h)
./src/util_funcs.cxx ./src/aet.cxx ./giuh/giuh.c include/all.hxx ./giuh/giuh.h)
endif()


Expand All @@ -106,6 +110,17 @@ set_target_properties(lasambmi PROPERTIES PUBLIC_HEADER ./include/bmi_lgar.hxx)

target_link_libraries(lasambmi PRIVATE Boost::serialization)

# --- EWTS (installed from nwm-ewts) ---
find_package(ewts CONFIG REQUIRED)

# Always use EWTS runtime logger for CPP
target_link_libraries(lasambmi PRIVATE ewts::ewts_cpp)

# Built with ngen bridge
target_link_libraries(lasambmi PRIVATE
"-Wl,--no-as-needed" ewts::ewts_ngen_bridge "-Wl,--as-needed")
target_compile_definitions(lasambmi PRIVATE EWTS_HAVE_NGEN_BRIDGE)

include(GNUInstallDirs)

install(TARGETS lasambmi
Expand Down
71 changes: 9 additions & 62 deletions include/Logger.hpp
Original file line number Diff line number Diff line change
@@ -1,66 +1,13 @@
#ifndef LOGGER_HPP
#define LOGGER_HPP
#ifndef LASAM_LOGGER_HPP
#define LASAM_LOGGER_HPP

#include <ctime>
#include <fstream>
#include <iostream>
#include <memory>
#include <sstream>
#include <stdlib.h>
#include <string>
#include "ewts/logger.hpp"
#include "ewts/module_constants.hpp"

#define LOG Logger::Log
using ewts::EwtsInit;
using ewts::LogLevel;

enum class LogLevel {
NONE = 0,
DEBUG = 1,
INFO = 2,
WARNING = 3,
SEVERE = 4,
FATAL = 5,
};
// Provide the constant in the global namespace:
inline constexpr const char* EWTS_ID_LASAM = ewts::modules::EWTS_ID_LASAM;

/**
* Logger Class Used to Output Details of Current Application Flow
All methods and variables are static so instantiating an object is unnecessary.
*/
class Logger {
public:
// Methods
static void Log(LogLevel messageLevel, const char* message, ...);
static void Log(LogLevel messageLevel, std::string message);
static void Log(std::string message, LogLevel messageLevel = LogLevel::INFO);
static bool IsLoggingEnabled(void);
static LogLevel GetLogLevel(void);

private:
// Methods
static std::string CreateDateString(void);
static std::string CreateTimestamp(bool appendMS = true, bool iso = true);
static bool CreateDirectory(const std::string& path);
static std::string ConvertLogLevelToString(LogLevel level);
static LogLevel ConvertStringToLogLevel(const std::string& logLevel);
static bool DirectoryExists(const std::string& path);
static std::string GetLogFilePath(void);
static bool LogFileReady(bool appendMode=true);
static void SetLogFilePath(void);
static void SetLoggingFlag(void);
static void SetLogLevel(void);
static void SetLogModuleName(void);
static void SetLogPreferences(void);
static std::string ToUpper(const std::string& input);
static std::string TrimString(const std::string& str);

// Variables
// Declaring these static so they exist in the class without needing to instantiate it.
static bool loggerInitialized;
static std::string logFilePath;
static bool loggingEnabled;
static std::fstream logFile;
static LogLevel logLevel;
static std::string moduleName;

static std::shared_ptr<Logger> loggerInstance;
};

#endif
#endif /* LASAM_LOGGER_HPP */
8 changes: 6 additions & 2 deletions include/bmi_lgar.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public:
this->output_var_names[13] = "groundwater_to_stream_recharge";
this->output_var_names[14] = "mass_balance";
this->output_var_names[15] = NWM_PONDED_DEPTH_OUT_VAR;
this->output_var_names[16] = "precipitation_rate_out";
this->output_var_names[17] = "groundwater_to_stream_recharge_m3_per_s";

/*
this->output_var_names[13] = "cum_precipitation";
Expand Down Expand Up @@ -145,7 +147,7 @@ private:
void realloc_soil();
struct model_state* state;
static const int input_var_name_count = 3;
static const int output_var_name_count = 16;
static const int output_var_name_count = 18;
static const int calib_var_name_count = 7;

std::string input_var_names[input_var_name_count];
Expand Down Expand Up @@ -174,6 +176,8 @@ private:
double volQ_gw_timestep_m;
double volPET_timestep_m;
double mass_balance_m;
double volQ_gw_timestep_m3_per_s;
double catchment_area_m2;
};

struct bmi_unit_conversion bmi_unit_conv;
Expand All @@ -184,7 +188,7 @@ private:
void serialize_wetting_front_list(Archive &ar, wetting_front **head, int &count);

void new_serialized();
void load_serialized(const char* data);
void load_serialized(char* data);
void free_serialized();
};

Expand Down
12 changes: 11 additions & 1 deletion include/vecbuf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@ class vecbuf : public std::basic_streambuf<CharT> {
// Forwarder for std::vector::clear()
constexpr void clear() { vector_.clear(); }

// Forwarder for std::vector::resize(size)
constexpr void resize(size_type size) { vector_.resize(size); }

// Forwarder for std::vector::reserve
constexpr void reserve(size_type capacity) { vector_.reserve(capacity); setp_from_vector(); }

// Increase the capacity of the buffer by reserving the current_size + additional_capacity
constexpr void reserve_additional(size_type additional_capacity) { reserve(size() + additional_capacity); }

// Forwarder for std::vector::data
constexpr const value_type* data() const { return vector_.data(); }
constexpr value_type* data() { return vector_.data(); }

// Forwarder for std::vector::size
constexpr size_type size() const { return vector_.size(); }
Expand Down Expand Up @@ -112,4 +115,11 @@ class vecbuf : public std::basic_streambuf<CharT> {

};

class membuf : public std::streambuf {
public:
membuf(char *begin, size_t size) {
this->setg(begin, begin, begin + size);
}
};

#endif
1 change: 1 addition & 0 deletions realizations/realization_config_lasam.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"main_output_variable": "total_discharge",
"output_variables" : [
"precipitation",
"precipitation_rate_out",
"potential_evapotranspiration",
"actual_evapotranspiration",
"surface_runoff",
Expand Down
1 change: 1 addition & 0 deletions realizations/realization_config_lasam_sft.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"main_output_variable": "total_discharge",
"output_variables" : [
"precipitation",
"precipitation_rate_out",
"potential_evapotranspiration",
"actual_evapotranspiration",
"surface_runoff",
Expand Down
1 change: 1 addition & 0 deletions realizations/realization_config_lasam_smp.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"main_output_variable": "total_discharge",
"output_variables" : [
"precipitation",
"precipitation_rate_out",
"potential_evapotranspiration",
"actual_evapotranspiration",
"surface_runoff",
Expand Down
Loading
Loading