# PhasicFlow: src/phasicFlow/repository/systemControl/dynamicLinkLibs.cpp Source File
PhasicFlow is an open-source parallel DEM (discrete element method) package for simulating granular flow. It is developed in C++ and can be exectued on both GPU (like CUDA) and CPU.

dynamicLinkLibs.cpp
Go to the documentation of this file.
/*------------------------------- phasicFlow ---------------------------------
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-----------------------------------------------------------------------------*/
#include <dlfcn.h>
#include "dynamicLinkLibs.hpp"
#include "List.hpp"
#include "streams.hpp"
pFlow::dynamicLinkLibs::dynamicLinkLibs(
const dictionary &dict,
word libList)
{
wordList libNames;
if(dict.containsDataEntry(libList))
{
libNames = dict.getVal<wordList>(libList);
}
REPORT(1)<< "libs are "<< Green_Text(libNames)<<END_REPORT;
for(auto libName:libNames)
{
auto* hndl = open(libName);
if(hndl)
{
libs_.insertIf(libName, hndl);
}
else
{
fatalExit;
}
}
}
pFlow::dynamicLinkLibs::~dynamicLinkLibs()
{
for(auto &lib:libs_)
{
if( lib.second && dlclose(lib.second) != 0)
{
warningInFunction<< "could not close lib "<<lib.first<<endl;
}
}
}
void* pFlow::dynamicLinkLibs::open(word libName)
{
REPORT(2)<<"Loading "<< Green_Text(libName)<<END_REPORT;
void* handle = dlopen(libName.c_str(), RTLD_LAZY|RTLD_GLOBAL);
if(!handle)
{
warningInFunction<< "could not open lib "<< libName<<endl;
return nullptr;
}
return handle;
}
Green_Text
#define Green_Text(text)
Definition: iOstream.hpp:42
pFlow::List< word >
pFlow::dynamicLinkLibs::dynamicLinkLibs
dynamicLinkLibs(const dictionary &dict, word libList="libs")
Definition: dynamicLinkLibs.cpp:28
fatalExit
#define fatalExit
Fatal exit.
Definition: error.hpp:98
pFlow::dynamicLinkLibs::libs_
wordHashMap< void * > libs_
Definition: dynamicLinkLibs.hpp:36
REPORT
#define REPORT(n)
Definition: streams.hpp:39
warningInFunction
#define warningInFunction
Report a warning.
Definition: error.hpp:95
List.hpp
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
pFlow::endl
iOstream & endl(iOstream &os)
Add newline and flush stream.
Definition: iOstream.hpp:341
pFlow::dictionary::containsDataEntry
bool containsDataEntry(const word &name) const
check if a data entry exist
Definition: dictionary.cpp:761
pFlow::dynamicLinkLibs::open
void * open(word libName)
Definition: dynamicLinkLibs.cpp:69
END_REPORT
#define END_REPORT
Definition: streams.hpp:40
streams.hpp
pFlow::dictionary::getVal
T getVal(const word &keyword) const
get the value of data entry
Definition: dictionary.hpp:379
pFlow::dynamicLinkLibs::~dynamicLinkLibs
~dynamicLinkLibs()
Definition: dynamicLinkLibs.cpp:58
dynamicLinkLibs.hpp
pFlow::dictionary
Dictionary holds a set of data entries or sub-dictionaries that are enclosed in a curely braces or ar...
Definition: dictionary.hpp:67