Commit 549da177 authored by Jouke's avatar Jouke
Browse files

Programmed graph writing module

parent 79701611
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ SOURCE_DIR := OpenSimRoot/src/
# Where to store objects as we build them?
RELEASE_BUILD_DIR := release_build/
NOPYTHON_BUILD_DIR := nopython_build/
GW_BUILD_DIR := graphWriting_build/
DEBUG_BUILD_DIR := debug_build/
WIN_BUILD_DIR := windows_build/

@@ -20,6 +21,7 @@ WIN_BUILD_DIR := windows_build/
# its name would conflict with the existing `OpenSimRoot/` subdir
RELEASE_BIN := $(RELEASE_BUILD_DIR)OpenSimRoot
NOPYTHON_BIN := $(NOPYTHON_BUILD_DIR)OpenSimRoot_noPython
GW_BIN := $(GW_BUILD_DIR)OpenSimRoot_graphWriting
DEBUG_BIN := $(DEBUG_BUILD_DIR)OpenSimRoot_debug
WIN_BIN := $(WIN_BUILD_DIR)OpenSimRoot.exe

@@ -76,11 +78,13 @@ SOURCES := $(call recursive_wildcard, $(SOURCE_DIR), *.cpp)
#	but necessary to keep from mixing compiled objects with and without debug symbols
DEPENDS_RELEASE := $(patsubst $(SOURCE_DIR)%.cpp, $(RELEASE_BUILD_DIR)%.d, $(SOURCES))
DEPENDS_NOPYTHON := $(patsubst $(SOURCE_DIR)%.cpp, $(NOPYTHON_BUILD_DIR)%.d, $(SOURCES))
DEPENDS_GW := $(patsubst $(SOURCE_DIR)%.cpp, $(GW_BUILD_DIR)%.d, $(SOURCES))
DEPENDS_WIN := $(patsubst $(SOURCE_DIR)%.cpp, $(WIN_BUILD_DIR)%.d, $(SOURCES))
DEPENDS_DEBUG := $(patsubst $(SOURCE_DIR)%.cpp, $(DEBUG_BUILD_DIR)%.d, $(SOURCES))

OBJECTS_RELEASE := $(patsubst $(SOURCE_DIR)%.cpp, $(RELEASE_BUILD_DIR)%.o, $(SOURCES))
OBJECTS_NOPYTHON := $(patsubst $(SOURCE_DIR)%.cpp, $(NOPYTHON_BUILD_DIR)%.o, $(SOURCES))
OBJECTS_GW := $(patsubst $(SOURCE_DIR)%.cpp, $(GW_BUILD_DIR)%.o, $(SOURCES))
OBJECTS_WIN := $(patsubst $(SOURCE_DIR)%.cpp, $(WIN_BUILD_DIR)%.o, $(SOURCES))
OBJECTS_DEBUG := $(patsubst $(SOURCE_DIR)%.cpp, $(DEBUG_BUILD_DIR)%.o, $(SOURCES))

@@ -89,6 +93,7 @@ BUILD_SUBDIRS := $(sort $(dir $(BUILD_SUBDIRS))) # sort is to drop duplicates

BUILD_TREE_RELEASE := $(addprefix $(RELEASE_BUILD_DIR), $(BUILD_SUBDIRS))
BUILD_TREE_NOPYTHON := $(addprefix $(NOPYTHON_BUILD_DIR), $(BUILD_SUBDIRS))
BUILD_TREE_GW := $(addprefix $(GW_BUILD_DIR), $(BUILD_SUBDIRS))
BUILD_TREE_WIN := $(addprefix $(WIN_BUILD_DIR), $(BUILD_SUBDIRS))
BUILD_TREE_DEBUG := $(addprefix $(DEBUG_BUILD_DIR), $(BUILD_SUBDIRS))

@@ -101,6 +106,8 @@ release: $(RELEASE_BIN)

nopython: $(NOPYTHON_BIN)

graphWriting: $(GW_BIN)

debug: $(DEBUG_BIN)

win: $(WIN_BIN)
@@ -113,6 +120,8 @@ $(BUILD_TREE_RELEASE):
	mkdir -p $@
$(BUILD_TREE_NOPYTHON):
	mkdir -p $@
$(BUILD_TREE_GW):
	mkdir -p $@
$(BUILD_TREE_WIN):
	mkdir -p $@
$(BUILD_TREE_DEBUG):
@@ -129,6 +138,8 @@ $(RELEASE_BUILD_DIR)%.o: $(SOURCE_DIR)%.cpp | $(BUILD_TREE_RELEASE)
	$(CXX) $(CXXFLAGS) $(DEPFLAGS) -o "$@" "$<"
$(NOPYTHON_BUILD_DIR)%.o: $(SOURCE_DIR)%.cpp | $(BUILD_TREE_NOPYTHON)
	$(CXX) $(CXXFLAGS) -DNOPYTHON $(DEPFLAGS)  -o "$@" "$<"
$(GW_BUILD_DIR)%.o: $(SOURCE_DIR)%.cpp | $(BUILD_TREE_GW)
	$(CXX) $(CXXFLAGS) -DNOPYTHON -DWRITEGRAPH $(DEPFLAGS)  -o "$@" "$<"
$(WIN_BUILD_DIR)%.o: $(SOURCE_DIR)%.cpp | $(BUILD_TREE_WIN)
	$(CXXWIN) $(CXXFLAGSWIN) $(DEPFLAGSWIN) -o "$@" "$<"
$(DEBUG_BUILD_DIR)%.o: $(SOURCE_DIR)%.cpp | $(BUILD_TREE_DEBUG)
@@ -142,6 +153,8 @@ $(RELEASE_BIN): $(OBJECTS_RELEASE) | $(RELEASE_BUILD_DIR)
	$(CXX) -o $@ $+ -lpython3.12 
$(NOPYTHON_BIN): $(OBJECTS_NOPYTHON) | $(NOPYTHON_BUILD_DIR)
	$(CXX) -o $@ $+ 
$(GW_BIN): $(OBJECTS_GW) | $(GW_BUILD_DIR)
	$(CXX) -o $@ $+ 
$(WIN_BIN): $(OBJECTS_WIN) | $(WIN_BUILD_DIR)
	$(CXXWIN) -o $@ $+ -lpsapi -lcomdlg32 -static-libstdc++ -static-libgcc 
$(DEBUG_BIN): $(OBJECTS_DEBUG) | $(DEBUG_BUILD_DIR)
@@ -151,6 +164,7 @@ $(DEBUG_BIN): $(OBJECTS_DEBUG) | $(DEBUG_BUILD_DIR)
# We include them here as if we'd typed them out for ourselves.
-include $(DEPENDS_RELEASE)
-include $(DEPENDS_NOPYTHON)
-include $(DEPENDS_GW)
-include $(DEPENDS_WIN)
-include $(DEPENDS_DEBUG)

@@ -161,6 +175,8 @@ clean-release:
	rm -rf $(OBJECTS_RELEASE) $(DEPENDS_RELEASE) $(RELEASE_BIN)
clean-nopython:
	rm -rf $(OBJECTS_NOPYTHON) $(DEPENDS_NOPYTHON) $(NOPYTHON_BIN)
clean-graphWriting:
	rm -rf $(OBJECTS_GW) $(DEPENDS_GW) $(GW_BIN)
clean-win:
	rm -rf $(OBJECTS_WIN) $(DEPENDS_WIN) $(WIN_BIN)
clean-debug:
+13 −0
Original line number Diff line number Diff line
@@ -206,6 +206,19 @@ You should have received the GNU GENERAL PUBLIC LICENSE v3 with this file in lic
					type="string"> rootLength, rootSurfaceArea
				</SimulaConstant>
			</SimulaBase>
			<SimulaBase name="GraphViz">
				<SimulaConstant
					name="run"
					type="bool"> 1</SimulaConstant>
				<SimulaConstant name="timeInterval" type="time"> 6.0	</SimulaConstant>
				<SimulaConstant name="startTime" type="time"> .0	</SimulaConstant>
				<SimulaConstant name="endTime" type="time"> 12	</SimulaConstant>
				<SimulaConstant
					name="skipTheseVariables"
					type="string"> plantCarbonBalance, addAnyThingYouDoNotWantInYourGraphHere
				</SimulaConstant>
			</SimulaBase>
			
		</SimulaBase>
	</SimulaBase>
</SimulationModelIncludeFile>
+23 −14
Original line number Diff line number Diff line
@@ -1088,12 +1088,16 @@ std::string SimulaBase::getPath()const{

//std::vector<SimulaBase*> SimulaBase::depGraph_;
//std::vector<std::string> SimulaBase::depGraphLab_;
bool SimulaBase::graphWritingModuleIsOn=true;
std::multimap<SimulaBase*,SimulaBase*> SimulaBase::gm_;
std::vector<SimulaBase*> SimulaBase::lv_;

void SimulaBase::addToDependencieGraph(){
    //depGraph_.push_back(p);
    //depGraphLab_.push_back(label);
	//std::cout<<std::endl<<"Adding to DependencieGraph "<<this->getName()<<std::endl;
	//todo, this graph get's large, but in the end, we only write unique names. As such, we could prune it here drastically?
	if(graphWritingModuleIsOn){
		if(!lv_.empty()){
			auto ret =gm_.equal_range(lv_.back());
			bool found=false;
@@ -1106,10 +1110,15 @@ void SimulaBase::addToDependencieGraph(){
			if(!found) gm_.insert(std::pair<SimulaBase*,SimulaBase*>(lv_.back(),this));
		}
		lv_.push_back(this);
	}
};
void SimulaBase::unwindDependencieGraph(){
	if(graphWritingModuleIsOn){
		if(lv_.back()!=this) msg::error("Error unwinding dependencie graph on "+ this->getType() + " and "+lv_.back()->getType());
    	lv_.pop_back();
	}else{
		lv_.clear();
	}
};
void SimulaBase::clearDependencieGraph(){
	if(lv_.size()) msg::error("Graph not properly unwound");
+1 −1
Original line number Diff line number Diff line
@@ -212,7 +212,7 @@ public:
	virtual void removeAfter(const double &x);

#ifdef WRITEGRAPH

    static bool graphWritingModuleIsOn;
	void addToDependencieGraph();
	void unwindDependencieGraph();
	void clearDependencieGraph();
+0 −6
Original line number Diff line number Diff line
@@ -214,9 +214,6 @@ public:
#endif
	}
	void getRate(const Colum1 &t, Colum2 &var){
#ifdef WRITEGRAPH
		addToDependencieGraph();
#endif
		//estimate it using finite difference
		//note that if the finite difference is too small we may get, because of numerical errors, 0
		Colum1 d1(MINTIMESTEP);
@@ -231,9 +228,6 @@ public:
		//if(t2>tb && t<=tb && table.size()>1 ) t2=tb;
		get(t2,r1);
		var=(r1-r0)/(t2-t1);
#ifdef WRITEGRAPH
		unwindDependencieGraph();
#endif
	}
	void get(const Time &t, const Coordinate & pos, Colum2 &y){
		//use t if column1 is time, but pos.y if column1 is state
Loading