Skip to content

Commit

Permalink
Fixed FluidProp and CoolProp on Windows and Linux
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.modelica.org/projects/ExternalMediaLibrary/trunk@7776 7ce873d0-865f-4ce7-a662-4bb36ea78beb
  • Loading branch information
jorrit committed Jun 30, 2014
1 parent 710fb19 commit 5e9ff3a
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 72 deletions.
31 changes: 21 additions & 10 deletions Projects/BuildLib-VS.bat
Expand Up @@ -16,15 +16,24 @@ set CP=..\externals\coolprop\trunk
set CPinc=%CP%\CoolProp
set INCLUDES=-I%CPinc%

REM echo "Copying coolpropsolver.cpp/h to Sources"
REM copy "%CP%\wrappers\Modelica\src\coolpropsolver.cpp" Sources
REM copy "%CP%\wrappers\Modelica\src\coolpropsolver.h" Sources

for /f "delims=" %%a in ('FINDSTR FLUIDPROP Sources\include.h') do set line=%%a
for /f "tokens=3" %%a in ("%line%") do set FLUIDP=%%a

for /f "delims=" %%a in ('FINDSTR COOLPROP Sources\include.h') do set line=%%a
for /f "tokens=3" %%a in ("%line%") do set COOLP=%%a
echo ' '
echo "Detecting supported solvers"
setlocal EnableDelayedExpansion
set i=0
for /f "delims=" %%a in ('FINDSTR FLUIDPROP Sources\include.h') do (
set line[!i!]=%%a
set /A i=i+1
)
for /f "tokens=3" %%a in ("%line[0]%") do set FLUIDP=%%a
echo "FluidProp support set to: %FLUIDP%"

set i=0
for /f "delims=" %%a in ('FINDSTR COOLPROP Sources\include.h') do (
set line[!i!]=%%a
set /A i=i+1
)
for /f "tokens=3" %%a in ("%line[0]%") do set COOLP=%%a
echo " CoolProp support set to: %COOLP%"


REM echo "Compiling sources"
Expand All @@ -35,4 +44,6 @@ REM ********** CoolProp sources *********
if "%COOLP%"=="1" cl %C_OPTS% /c %INCLUDES% %CP%\CoolProp\*.cpp

lib *.obj /OUT:ExternalMediaLib.lib
erase *.obj
erase *.obj

:End
6 changes: 1 addition & 5 deletions Projects/Sources/FluidProp_COM.h
Expand Up @@ -17,10 +17,8 @@

#ifndef FluidProp_COM_h
#define FluidProp_COM_h
#include "include.h"

#if defined(__ISWINDOWS__)

#include "include.h"
#include <comutil.h>


Expand Down Expand Up @@ -212,6 +210,4 @@ interface IFluidProp_COM : public IDispatch
virtual void __stdcall CalcProp ( ) = 0; // C++ interface not yet implemented
};

#endif //defined(__ISWINDOWS__)

#endif // FluidProp_COM_h
4 changes: 0 additions & 4 deletions Projects/Sources/FluidProp_IF.cpp
Expand Up @@ -24,8 +24,6 @@
#include <olectl.h>
#endif

#if defined(__ISWINDOWS__)

// Conversion of a binary string BSTR to a string.
static inline string ConvertBSTRToString(BSTR BString)
{
Expand Down Expand Up @@ -1146,6 +1144,4 @@ double* TFluidProp::FugaCoef_Deriv( string InputSpec, double Input1, double Inpu

return Output;
}
#endif // __ISWINDOWS__

//==================================================================================== EOF ===//
5 changes: 0 additions & 5 deletions Projects/Sources/FluidProp_IF.h
Expand Up @@ -20,7 +20,6 @@
#define FluidProp_IF_h

#include "include.h"
#if defined(__ISWINDOWS__)

#pragma comment(lib, "comsuppw.lib")

Expand All @@ -29,8 +28,6 @@ using std::string;

#include "FluidProp_COM.h"

#endif // __ISWINDOWS__


// The TFluidProp class
class TFluidProp
Expand Down Expand Up @@ -124,13 +121,11 @@ class TFluidProp
double* GibbsEnergy_Deriv( string InputSpec, double Input1, double Input2, string* ErrorMsg);
double* FugaCoef_Deriv ( string InputSpec, double Input1, double Input2, string* ErrorMsg);

#if defined(__ISWINDOWS__)
private:

IClassFactory* ClassFactory ; // Pointer to class factory
IFluidProp_COM* FluidProp_COM; // Pointer to FluidProp interface

#endif // __ISWINDOWS__
};

#endif // FluidProp_IF_h
4 changes: 0 additions & 4 deletions Projects/Sources/coolpropsolver.cpp
@@ -1,7 +1,5 @@
#include "coolpropsolver.h"

#if (COOLPROP == 1)

#include "CoolPropTools.h"
#include "CoolProp.h"
#include "CPState.h"
Expand Down Expand Up @@ -764,5 +762,3 @@ double CoolPropSolver::Tsat(ExternalSaturationProperties *const properties){
return NAN;
}


#endif // COOLPROP == 1
4 changes: 0 additions & 4 deletions Projects/Sources/coolpropsolver.h
Expand Up @@ -3,8 +3,6 @@

#include "basesolver.h"

#if (COOLPROP == 1)

//! CoolProp solver class
/*!
This class defines a solver that calls out to the open-source CoolProp
Expand Down Expand Up @@ -94,6 +92,4 @@ class CoolPropSolver : public BaseSolver{

};

#endif // COOLPROP == 1

#endif // COOLPROPSOLVER_H_
13 changes: 0 additions & 13 deletions Projects/Sources/fluidpropsolver.cpp
Expand Up @@ -8,9 +8,6 @@
#include "include.h"
#include "fluidpropsolver.h"
#include <iostream>
#include <exception>

#if (FLUIDPROP == 1)

#define _AFXDLL

Expand All @@ -24,15 +21,6 @@ FluidPropSolver::FluidPropSolver(const string &mediumName,
const string &substanceName)
: BaseSolver(mediumName, libraryName, substanceName){

#if !defined(__ISWINDOWS__)
std::string msg("FluidProp is only available on Windows, please avoid using it or disable it completely in the \"include.h\" file.");
char error[300];
sprintf(error, "FluidProp error: %s\n", msg.c_str());
errorMessage(error);
std::cout << msg.c_str() << std::endl;
//throw std::exception()
#endif

string ErrorMsg;
string Comp[20];
double Conc[20];
Expand Down Expand Up @@ -511,4 +499,3 @@ bool FluidPropSolver::licenseError(string ErrorMsg)
return false;
}

#endif // FLUIDPROP == 1
4 changes: 1 addition & 3 deletions Projects/Sources/fluidpropsolver.h
Expand Up @@ -38,8 +38,6 @@
#include "include.h"
#include "basesolver.h"

#if (FLUIDPROP == 1)

#include "FluidProp_IF.h"

class FluidPropSolver : public BaseSolver{
Expand Down Expand Up @@ -67,6 +65,6 @@ class FluidPropSolver : public BaseSolver{
bool licenseError(string ErrorMsg);
};

#endif // FLUIDPROP == 1


#endif /*FLUIDPROPSOLVER_H_*/
13 changes: 13 additions & 0 deletions Projects/Sources/include.h
Expand Up @@ -97,6 +97,19 @@ Portable definitions of the EXPORT macro
# endif
#endif

/*!
Overwrite FluidProp inclusion if not on Windows
*/
#if defined(__ISLINUX__)
# undef FLUIDPROP
# define FLUIDPROP 0
#elif defined(__ISAPPLE__)
# undef FLUIDPROP
# define FLUIDPROP 0
#endif



// General purpose includes
#include <map>
using std::map;
Expand Down
2 changes: 1 addition & 1 deletion Projects/Sources/mingw_gcc_comutil.cpp
Expand Up @@ -33,4 +33,4 @@ namespace _com_util
return bstr;
}
}
#endif
#endif //defined(__MINGW32__)
4 changes: 0 additions & 4 deletions Projects/Sources/solvermap.cpp
Expand Up @@ -4,9 +4,7 @@
#include "include.h"

#if (FLUIDPROP == 1)
#if defined(__ISWINDOWS__)
#include "fluidpropsolver.h"
#endif // defined(__ISWINDOWS__)
#endif // FLUIDPROP == 1

#if (COOLPROP == 1)
Expand Down Expand Up @@ -36,11 +34,9 @@ BaseSolver *SolverMap::getSolver(const string &mediumName, const string &library
_solvers[solverKeyString] = new TestSolver(mediumName, libraryName, substanceName);

#if (FLUIDPROP == 1)
#if defined(__ISWINDOWS__)
// FluidProp solver
else if (libraryName.find("FluidProp") == 0)
_solvers[solverKeyString] = new FluidPropSolver(mediumName, libraryName, substanceName);
#endif // defined(__ISWINDOWS__)
#endif // FLUIDPROP == 1

#if (COOLPROP == 1)
Expand Down
37 changes: 18 additions & 19 deletions Projects/makefile-linux
Expand Up @@ -143,23 +143,31 @@ all : header library
############################################################
## Compile sources to static files
############################################################
# We cannot use := assignment for the ExternalMedia sources,
# the variable has to be evaluate at runtine to catch the
# copy operation of coolpropsolver.cpp
EXMECPP_FILES = $(wildcard $(SRCDIR)/*.cpp)
EXMEOBJ_FILES = $(addprefix $(BINDIR)/,$(notdir $(EXMECPP_FILES:.cpp=.o)))
EXMECPP_FILES := $(wildcard $(SRCDIR)/*.cpp)
EXMEOBJ_FILES := $(addprefix $(BINDIR)/,$(notdir $(EXMECPP_FILES:.cpp=.o)))
# Files do not change here, := assignments work.
USE_FLUIDPROP := $(shell grep FLUIDPROP $(SRCDIR)/include.h | cut -d " " -f3)
USE_COOLPROP := $(shell grep COOLPROP $(SRCDIR)/include.h | cut -d " " -f3)
USE_FLUIDPROP := $(shell grep FLUIDPROP $(SRCDIR)/include.h | head -n 1 | cut -d " " -f3)
USE_FLUIDPROP := 0
USE_COOLPROP := $(shell grep COOLPROP $(SRCDIR)/include.h | head -n 1 | cut -d " " -f3)


ifeq ($(USE_FLUIDPROP),1)

else
# Remove the FluidProp files, they are not available for Linux
EXMEOBJ_FILES := $(filter-out $(BINDIR)/FluidProp_IF.o, $(EXMEOBJ_FILES))
EXMEOBJ_FILES := $(filter-out $(BINDIR)/fluidpropsolver.o, $(EXMEOBJ_FILES))
endif


ifeq ($(USE_COOLPROP),1)
COOLCPP_FILES := $(wildcard $(COOLPROPDIR)/*.cpp)
COOLOBJ_FILES := $(addprefix $(BINDIR)/,$(notdir $(COOLCPP_FILES:.cpp=.o)))
else
COOLCPP_FILES :=
COOLOBJ_FILES :=
EXMEOBJ_FILES := $(filter-out $(BINDIR)/coolpropsolver.o, $(EXMEOBJ_FILES))
endif
COOLSOL_FILES := coolpropsolver.cpp coolpropsolver.h

# Define search path for prerequisite files and g++ include
# parameters to be used later.
Expand All @@ -186,32 +194,23 @@ $(BINDIR)/$(HEADERFILE)$(HEADEREXTENSION): $(SRCDIR)/$(HEADERFILE)$(HEADEREXTENS
$(CP) $(SRCDIR)/$(HEADERFILE)$(HEADEREXTENSION) $(BINDIR)

.PHONY : library
library : coolprop-obj $(BINDIR)/$(LIBRARY)$(LIBRARYEXTENSION)
library : $(COOLOBJ_FILES) $(BINDIR)/$(LIBRARY)$(LIBRARYEXTENSION)

$(BINDIR)/$(LIBRARY).so: coolprop-obj $(EXMEOBJ_FILES) #$(SRCDIR)/$(LIBFILE).o
$(BINDIR)/$(LIBRARY).so: $(COOLOBJ_FILES) $(EXMEOBJ_FILES) #$(SRCDIR)/$(LIBFILE).o
$(MK) $(BINDIR)
$(CPPC) $(LIBFLAGS) $(CPPFLAGS) -o $(BINDIR)/$(LIBRARY).so $(EXMEOBJ_FILES) #$(SRCDIR)/$(LIBFILE).o

$(BINDIR)/$(LIBRARY).a: $(COOLOBJ_FILES) $(EXMEOBJ_FILES) #$(SRCDIR)/$(LIBFILE).o
$(MK) $(BINDIR)
$(AR) $(BINDIR)/$(LIBRARY).a $^

.PHONY : coolprop-svn
coolprop-svn :
#$(SVN) up $(COOLPROPDIR)/..
#$(CP) $(foreach i,$(COOLSOL_FILES),$(COOLPROPDIR)/../wrappers/Modelica/src/$(i)) $(SRCDIR)

.PHONY : coolprop-obj
coolprop-obj : coolprop-svn $(COOLOBJ_FILES)


###########################################################
# General rulesets for compilation.
###########################################################
.PHONY: clean
clean:
$(RM) $(BINDIR)/*solver.o $(BINDIR)/*solver.obj $(BINDIR)/*xternal*
#($(CD) $(SRCDIR) && $(RM) $(COOLSOL_FILES))

.PHONY: very-clean
very-clean: clean
Expand Down

0 comments on commit 5e9ff3a

Please sign in to comment.