Skip to content
Open
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
24 changes: 19 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,19 @@
set(pluginName Util)
set(SOURCES domain_util.cpp util_plugin.cpp)

set (CMAKE_CXX_STANDARD 17)
set (CMAKE_CXX_STANDARD 14)

# Note:
# In C++ 17, std::unary_function has been removed. Unfortunately, UG4's boost is outdated...
# FYI Starting with 1.76.0 Configure boost:
# https://www.boost.org/doc/libs/1_76_0/libs/config/doc/html/boost_config/boost_macro_reference.html
# set (CMAKE_CXX_STANDARD 17)
# add_compile_definitions(BOOST_NO_CXX98_FUNCTION_BASE)

################################################################################
# The code below doesn't have to be changed (usually)
################################################################################
cmake_minimum_required(VERSION 2.6)
# cmake_minimum_required(VERSION 2.6)

project(UG_PLUGIN_${pluginName})

Expand Down Expand Up @@ -74,12 +82,18 @@ if(USE_PYBIND11)
add_library(${pluginName} STATIC ${SOURCES})

SET(myPluginSources util_plugin_pybind.cpp)
# SET(myLibraries ug4 SuperLU6)
SET(myLibraries ${pluginName} ${targetLibraryName}) # targetLibraryName is either ug4 or ug4_s

# First argument must match module name in PYBIND11_MODULE call
python_add_library(pyutil MODULE ${myPluginSources} ${SOURCES} WITH_SOABI)
# ug4pybind_add_module(pyutil ${myPluginSources} ${myLibraries})
target_link_libraries (pyutil PRIVATE ${pluginName} ug4_s)
set_target_properties(pyutil PROPERTIES INSTALL_RPATH "$ORIGIN/..:$ORIGIN/../../../lib")
target_link_libraries (pyutil PRIVATE ${myLibraries})
if(APPLE)
set_target_properties(pyutil PROPERTIES
INSTALL_RPATH "@loader_path;@loader_path/../lib"
BUILD_WITH_INSTALL_RPATH TRUE)
elseif(LINUX AND NOT APPLE)
set_target_properties(pyutil PROPERTIES INSTALL_RPATH "$ORIGIN:$ORIGIN/../lib")
endif()
install(TARGETS pyutil LIBRARY DESTINATION ug4py COMPONENT pymodules)
endif(USE_PYBIND11)
11 changes: 8 additions & 3 deletions solver_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#ifndef UG4_SOLVER_UTIL_H
#define UG4_SOLVER_UTIL_H

#ifdef UG_USE_JSON


#include <nlohmann/json.hpp>

#include "common/common.h"
Expand Down Expand Up @@ -311,16 +314,16 @@ namespace Util {
//TODO:Tim create sgs
}
else if(type == "egs"){
// create egs
//TODO:Lukas
}
else if(type == "cgs"){
// create cgs
//TODO:Myrto
}
else if(type == "ssc"){
//TODO:Duy create ssc
}
else if(type == "gmg"){
// create gmg
//TODO: Julian
}
else if(type == "schur"){
//TODO:Duy create schur
Expand Down Expand Up @@ -438,4 +441,6 @@ class SolverUtilFunctionProvider{
};
} //namespace util
} //namespace ug

#endif // UG_USE_JSON
#endif //UG4_SOLVER_UTIL_H
54 changes: 30 additions & 24 deletions util_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ static void DomainAlgebra(TRegistry& reg, string grp)
string suffix = GetDomainAlgebraSuffix<TDomain,TAlgebra>();
string tag = GetDomainAlgebraTag<TDomain,TAlgebra>();


#ifdef UG_USE_JSON
{

typedef SolverUtilFunctionProvider<TDomain, TAlgebra> T;
Expand All @@ -150,6 +150,7 @@ static void DomainAlgebra(TRegistry& reg, string grp)
.set_construct_as_smart_pointer(true);
reg.add_class_to_group(name, "SolverUtilFunctionProvider", tag);
}
#endif
/*{
// This is more complicated, as the return type should be included in name.
std::string grpname = std::string("CreatePreconditioner");
Expand All @@ -163,6 +164,7 @@ static void DomainAlgebra(TRegistry& reg, string grp)
// reg.add_function(grpname.append(suffix),
// static_cast<SmartPtr<TDomain>(*)(const std::string&, int, const std::vector<std::string> &)>
// (&CreateDomain<TDomain>), grpname);
#ifdef UG_USE_JSON
{
//typedef Domain<dim> domain_type;
typedef SolverUtil<TDomain, TAlgebra> T;
Expand All @@ -173,6 +175,7 @@ static void DomainAlgebra(TRegistry& reg, string grp)
.set_construct_as_smart_pointer(true);
reg.add_class_to_group(name, "SolverUtil", tag);
}
#endif

}

Expand Down Expand Up @@ -251,23 +254,26 @@ static void Dimension(TRegistry& reg, string grp)
* @param reg registry
* @param parentGroup group for sorting of functionality
*/
template <typename TAlgebra>
static void Algebra(Registry& reg, string grp)
template <typename TAlgebra, typename TRegistry=ug::bridge::Registry>
static void Algebra(TRegistry& reg, string grp)
{
// useful defines
// useful defines
string suffix = GetAlgebraSuffix<TAlgebra>();
string tag = GetAlgebraTag<TAlgebra>();
typedef typename TAlgebra::vector_type vector_type;
{
// This is more complicated, as the return type should be included in name.
{
std::string grpname = std::string("CreateConvCheck");
reg.add_function(grpname.append(suffix),
static_cast<SmartPtr<StdConvCheck<vector_type>>(*)(nlohmann::json &)>
(&CreateConvCheck < TAlgebra > ), grpname);
}
typedef typename TAlgebra::vector_type vector_type;

}
#ifdef UG_USE_JSON
{
// This is more complicated, as the return type should be included in name.
{
std::string grpname = std::string("CreateConvCheck");
reg.add_function(grpname.append(suffix),
static_cast<SmartPtr<StdConvCheck<vector_type>>(*)(nlohmann::json &)>
(&CreateConvCheck < TAlgebra > ), grpname);
}

}
#endif

}

Expand Down Expand Up @@ -296,7 +302,7 @@ static void Common(Registry& reg, string grp)


template <typename TRegistry=ug::bridge::Registry>
void RegisterBridge_Util(TRegistry& reg, string grp)
void RegisterBridge_Util_(TRegistry* reg, string grp)
{
grp.append("/Util");
typedef Util::Functionality Functionality;
Expand All @@ -305,16 +311,16 @@ void RegisterBridge_Util(TRegistry& reg, string grp)
#ifndef UG_USE_PYBIND11
//RegisterCommon<Functionality>(*reg,grp);
//RegisterDimensionDependent<Functionality>(*reg,grp);
RegisterDomainAlgebraDependent<Functionality>(reg,grp);
RegisterDomainDependent<Functionality>(reg,grp);
RegisterAlgebraDependent<Functionality>(reg,grp);
RegisterDomainAlgebraDependent<Functionality>(*reg,grp);
RegisterDomainDependent<Functionality>(*reg,grp);
RegisterAlgebraDependent<Functionality>(*reg,grp);

#else
//RegisterCommon<Functionality, TRegistry>(*reg,grp);
//RegisterDimensionDependent<Functionality, TRegistry>(*reg,grp);
RegisterDomainDependent<Functionality, TRegistry>(reg,grp);
RegisterAlgebraDependent<Functionality>(*reg,grp);
RegisterDomainAlgebraDependent<Functionality>(*reg,grp);
RegisterDomainDependent<Functionality, TRegistry>(*reg,grp);
RegisterAlgebraDependent<Functionality, TRegistry>(*reg,grp);
RegisterDomainAlgebraDependent<Functionality, TRegistry>(*reg,grp);
#endif

}
Expand All @@ -328,7 +334,7 @@ void RegisterBridge_Util(TRegistry& reg, string grp)
extern "C" void
InitUGPlugin_Util(Registry* reg, string grp)
{
RegisterBridge_Util(*reg, grp);
RegisterBridge_Util_(reg, grp);
}

extern "C" UG_API void
Expand All @@ -337,10 +343,10 @@ FinalizeUGPlugin_Util()


#ifdef UG_USE_PYBIND11 // Expose for pybind11.
namespace UtilBridge{
namespace Util {
void InitUGPlugin(ug::pybind::Registry* reg, string grp)
{
RegisterBridge_Util<ug::pybind::Registry>(*reg, grp);
RegisterBridge_Util_<ug::pybind::Registry>(reg, grp);
}
}
#endif
Expand Down
4 changes: 1 addition & 3 deletions util_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ extern "C" void FinalizeUGPlugin_Util();
#include "bindings/pybind/ug_pybind.h"

namespace ug {
namespace bridge {
namespace UtilBridge{
namespace Util{
void InitUGPlugin(ug::pybind::Registry* reg, std::string grp);
}
}
}
#endif


Expand Down
2 changes: 1 addition & 1 deletion util_plugin_pybind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ PYBIND11_MODULE(pyutil, m)
ug::pybind::Registry registry(m);
std::string name("Utilities");

ug::bridge::UtilBridge::InitUGPlugin(&registry, name);
ug::Util::InitUGPlugin(&registry, name);
}

#endif