Skip to content

Commit

Permalink
refactor VCellStoch into separate lib/exe, add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
jcschaff committed Apr 25, 2023
1 parent cd19839 commit d550eec
Show file tree
Hide file tree
Showing 20 changed files with 213 additions and 166 deletions.
45 changes: 33 additions & 12 deletions Stochastic/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
project(Stochastic)

set (SRC_FILES
VCellStoch/Gibson.cpp
VCellStoch/IndexedTree.cpp
VCellStoch/Jump.cpp
VCellStoch/StochModel.cpp
VCellStoch/StochVar.cpp
VCellStoch/VCellStoch.cpp
cmake_minimum_required (VERSION 3.0)
project(Stochastic)

set (SRC_FILES
VCellStoch/src/Gibson.cpp
VCellStoch/src/IndexedTree.cpp
VCellStoch/src/Jump.cpp
VCellStoch/src/StochModel.cpp
VCellStoch/src/StochVar.cpp
)

set (SRC_MAIN_FILE VCellStoch/src/VCellStoch.cpp)

set (HEADER_FILES
VCellStoch/include/Gibson.h
VCellStoch/include/IndexedTree.h
VCellStoch/include/Jump.h
VCellStoch/include/StochModel.h
VCellStoch/include/StochVar.h
)

set(EXE_FILE VCellStoch)
Expand All @@ -33,8 +43,19 @@ if (DEFINED ENV{PETSC_ARCH})
link_directories("/usr/lib/x86_64-linux-gnu/hdf5/serial")
endif()

add_executable(${EXE_FILE} ${SRC_FILES})
add_library(VCellStochLib ${SRC_FILES} ${HEADER_FILES})
target_link_libraries(VCellStochLib ExpressionParser vcommons vcellmessaging hdf5)
target_include_directories(VCellStochLib PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/VCellStoch/include>
$<INSTALL_INTERFACE:VCellStoch/include> # <prefix>/VCellStoch/include
)


add_executable(${EXE_FILE} ${SRC_MAIN_FILE} ${SRC_FILES} ${HEADER_FILES})
#target_link_libraries(${EXE_FILE} ExpressionParser vcommons vcellmessaging ${CMAKE_SOURCE_DIR}/mylibs/libhdf5_serial.so.10)
target_link_libraries(${EXE_FILE} ExpressionParser vcommons vcellmessaging hdf5)
target_link_libraries(${EXE_FILE} VCellStochLib)
#add_dependencies(${EXE_FILE} ExpressionParser)
install(TARGETS ${EXE_FILE} RUNTIME DESTINATION ${OPTION_EXE_DIRECTORY})
install(TARGETS VCellStochLib ${EXE_FILE} RUNTIME DESTINATION ${OPTION_EXE_DIRECTORY})

enable_testing()
add_subdirectory(Tests)
26 changes: 26 additions & 0 deletions Stochastic/Tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
cmake_minimum_required (VERSION 3.0)
project(MovingBoundaryTest)
set (CMAKE_CXX_STANDARD 11)
cmake_policy(SET CMP0046 OLD)
enable_testing()

set(SRC_FILES
statstest.cpp
)

file(GLOB HDR_FILES *h)

set(EXE_FILE Test TestVCellStoch)

set_source_files_properties( ${SRC_FILES} PROPERTIES LANGUAGE CXX)

message(STATUS "HDF5 VERSION IS ${HDF5_VERSION}, LIBS = ${HDF5_LIBRARIES}, HL_LIBS = ${HDF5_HL_LIBRARIES}")

add_executable(TestVCellStoch ${SRC_FILES} ${HDR_FILES})
add_dependencies(TestVCellStoch VCellStochLib gtest)
target_link_libraries(TestVCellStoch VCellStochLib GTest::gtest_main)
install(TARGETS TestVCellStoch
RUNTIME DESTINATION bin)

include(GoogleTest)
gtest_discover_tests(TestVCellStoch)
82 changes: 82 additions & 0 deletions Stochastic/Tests/statstest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
//
// Created by Jim Schaff on 4/25/23.
//
#include <stdexcept>
#include "gtest/gtest.h"
#include "../VCellStoch/include/Gibson.h"
#include <iostream>
#include <cstdio>

const char* input_file_contents = R"INPUT_FILE(
<control>
STARTING_TIME 0.0
ENDING_TIME 20.0
TOLERANCE 1.0E-9
SAVE_PERIOD 0.02
MAX_SAVE_POINTS 1001.0
NUM_TRIAL 50000
SEED 566564762
BMULTIBUTNOTHISTO 1
</control>
<model>
<discreteVariables>
TotalVars 3
s0_Count 1
s1_Count 0
s2_Count 1
</discreteVariables>
<jumpProcesses>
TotalProcesses 2
r0
r0_reverse
</jumpProcesses>
<processDesc>
TotalDescriptions 2
JumpProcess r0
Propensity (0.9996443474639611 * s0_Count * s2_Count)
Effect 3
s0_Count inc -1.0
s2_Count inc -1.0
s1_Count inc 1.0
DependentProcesses 0
JumpProcess r0_reverse
Propensity 0.0
Effect 3
s0_Count inc 1.0
s2_Count inc 1.0
s1_Count inc -1.0
DependentProcesses 1
r0
</processDesc>
</model>
)INPUT_FILE";


TEST(statstest,test1) {
std::string temp_input_file_name = std::tmpnam(nullptr);
std::ofstream input_file (temp_input_file_name);
bool bWroteFile = false;
if (input_file.is_open()){
input_file << input_file_contents;
input_file.close();
bWroteFile = true;
}
ASSERT_TRUE(bWroteFile);

std::string temp_output_file_name = std::tmpnam(nullptr);

Gibson *gb= new Gibson(temp_input_file_name.c_str(), temp_output_file_name.c_str());
gb->march();
delete gb;
}
28 changes: 0 additions & 28 deletions Stochastic/VCellStoch/Makefile.linux

This file was deleted.

31 changes: 0 additions & 31 deletions Stochastic/VCellStoch/Makefile.mac

This file was deleted.

42 changes: 0 additions & 42 deletions Stochastic/VCellStoch/Makefile.win32

This file was deleted.

33 changes: 0 additions & 33 deletions Stochastic/VCellStoch/Makefile64.linux

This file was deleted.

2 changes: 0 additions & 2 deletions Stochastic/VCellStoch/Makefile_NoMessaging.Win32

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class IndexedTree;
class Gibson : public StochModel{
public:
Gibson();
Gibson(char*, char*);
Gibson(const char*, const char*);
~Gibson();
int core();
void march();
Expand All @@ -37,7 +37,7 @@ class Gibson : public StochModel{
IndexedTree *Tree; //the data structure(binary tree) to store all the processes and make each parent smaller than it's children.
double* currvals;//array of variable values to be used by expression parser. variables are stored in vector listOfVars.
ofstream outfile; //the output file stream where the results are saved.
char* outfilename;//the output file name.
const char* outfilename;//the output file name.
bool flag_savePeriod;//the flag for using save period.
int finalizeSampleRow(int,double);//central location to call to complete 1 output sample to file
int savedSampleCount; //saved sample counter that survives certain iterations to keep overall count
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <string>
#include <vector>
#include <SymbolTable.h>
#include "../../../ExpressionParser/SymbolTable.h"

using std::string;
using std::vector;
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//#define DEBUG //enable it when debug is needed.
#include <limits>
#include <stdexcept>
#include "Gibson.h"
#include "../include/Gibson.h"
#ifdef __APPLE__
#include "/usr/local/opt/[email protected]/include/hdf5.h"
#else
Expand Down Expand Up @@ -32,14 +32,14 @@ using namespace std;
#include <sys/types.h>
#include <sys/timeb.h>
#include <time.h>
#include "Jump.h"
#include "StochVar.h"
#include "IndexedTree.h"
#include "../include/Jump.h"
#include "../include/StochVar.h"
#include "../include/IndexedTree.h"

#ifdef USE_MESSAGING
#include <VCELL/SimulationMessaging.h>
#endif
#include <VCellException.h>
#include "VCellException.h"
const double double_infinity = numeric_limits<double>::infinity();
const double EPSILON = 1E-12;
const string Gibson::MY_T_STR = "t";
Expand All @@ -61,7 +61,7 @@ Gibson::Gibson()
*Input para: srting, the input file(name), where the model info. is read.
* string, the output file(name), where the results are saved.
*/
Gibson::Gibson(char* arg_infilename, char* arg_outfilename)
Gibson::Gibson(const char* arg_infilename, const char* arg_outfilename)
:StochModel(),
savedSampleCount(1),
lastTime (std::numeric_limits<long>::min( ))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <assert.h>
#include <math.h>
#include "IndexedTree.h"
#include "../include/IndexedTree.h"

/*
*The constructor of IndexedTree.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "Jump.h"
#include "../include/Jump.h"

#include <SimpleSymbolTable.h>
#include <Exception.h>
#include <Expression.h>
#include "SimpleSymbolTable.h"
#include "Exception.h"
#include "Expression.h"
using VCell::Exception;
using VCell::Expression;

Expand Down
Loading

0 comments on commit d550eec

Please sign in to comment.