Skip to content

Commit 9ede420

Browse files
authored
[GeoMechanicsApplication] Attempt several variants of function name 'User_Mod' when loading a UDSM (#13530)
When loading function `User_Mod` from a UDSM shared library account for the fact that several casing variants may have been used: `User_Mod`, `User_mod`, `USER_MOD`, and `user_mod`.
1 parent 7a7947f commit 9ede420

2 files changed

Lines changed: 40 additions & 20 deletions

File tree

applications/GeoMechanicsApplication/custom_constitutive/small_strain_udsm_law.cpp

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,28 @@ array_1d<double, props_size> MakePropsVector(const Vector& rUMatParameters)
5050
return result;
5151
}
5252

53+
std::vector<std::string> GFortranNamesOf(const std::vector<std::string>& rFunctionNames)
54+
{
55+
auto result = std::vector<std::string>{};
56+
result.reserve(rFunctionNames.size());
57+
auto append_underscore = [](const auto& rFunctionName) { return rFunctionName + '_'; };
58+
std::transform(rFunctionNames.begin(), rFunctionNames.end(), std::back_inserter(result), append_underscore);
59+
return result;
60+
}
61+
62+
const std::vector<std::string>& UserModFunctionNames()
63+
{
64+
auto generate_names = []() {
65+
using namespace std::string_literals;
66+
auto result = std::vector<std::string>{"User_Mod"s, "User_mod"s, "USER_MOD"s, "user_mod"s};
67+
const auto gfortran_names = GFortranNamesOf(result);
68+
result.insert(result.end(), gfortran_names.begin(), gfortran_names.end());
69+
return result;
70+
};
71+
static const auto result = generate_names();
72+
return result;
73+
}
74+
5375
} // namespace
5476

5577
namespace Kratos
@@ -471,16 +493,15 @@ bool SmallStrainUDSMLaw::loadUDSMLinux(const Properties& rMaterialProperties)
471493
// resolve function GetStateVarCount address
472494
mpGetStateVarCount = (f_GetStateVarCount)dlsym(lib_handle, "getstatevarcount");
473495

474-
mpUserMod = (f_UserMod)dlsym(lib_handle, "user_mod");
496+
for (const auto& r_function_name : UserModFunctionNames()) {
497+
mpUserMod = (f_UserMod)dlsym(lib_handle, r_function_name.c_str());
498+
499+
if (mpUserMod) break;
500+
}
501+
475502
if (!mpUserMod) {
476-
mpUserMod = (f_UserMod)dlsym(lib_handle, "user_mod_");
477-
if (!mpUserMod) {
478-
KRATOS_INFO("Error in loadUDSMLinux")
479-
<< "cannot load function User_Mod in the specified UDSM: " << rMaterialProperties[UDSM_NAME]
480-
<< std::endl;
481-
KRATOS_ERROR << "cannot load function User_Mod in the specified UDSM "
482-
<< rMaterialProperties[UDSM_NAME] << std::endl;
483-
}
503+
KRATOS_ERROR << "Cannot load function 'User_Mod' in the specified UDSM "
504+
<< rMaterialProperties[UDSM_NAME] << std::endl;
484505
}
485506

486507
return true;
@@ -533,18 +554,17 @@ bool SmallStrainUDSMLaw::loadUDSMWindows(const Properties& rMaterialProperties)
533554
// resolve function GetStateVarCount address
534555
mpGetStateVarCount = (f_GetStateVarCount)GetProcAddress(hGetProcIDDLL, "getstatevarcount");
535556

536-
mpUserMod = (f_UserMod)GetProcAddress(hGetProcIDDLL, "user_mod");
557+
for (const auto& r_function_name : UserModFunctionNames()) {
558+
mpUserMod = (f_UserMod)GetProcAddress(hGetProcIDDLL, r_function_name.c_str());
559+
560+
if (mpUserMod) break;
561+
}
562+
537563
if (!mpUserMod) {
538-
// check if the dll is compiled with gfortran
539-
mpUserMod = (f_UserMod)GetProcAddress(hGetProcIDDLL, "user_mod_");
540-
if (!mpUserMod) {
541-
KRATOS_INFO("Error in loadUDSMWindows")
542-
<< "cannot load function User_Mod in the specified UDSM: " << rMaterialProperties[UDSM_NAME]
543-
<< std::endl;
544-
KRATOS_ERROR << "cannot load function User_Mod in the specified UDSM "
545-
<< rMaterialProperties[UDSM_NAME] << std::endl;
546-
}
564+
KRATOS_ERROR << "Cannot load function 'User_Mod' in the specified UDSM "
565+
<< rMaterialProperties[UDSM_NAME] << std::endl;
547566
}
567+
548568
return true;
549569
#else
550570
KRATOS_ERROR << "loadUDSMWindows should be called in Windows applications"

applications/GeoMechanicsApplication/custom_constitutive/small_strain_udsm_law.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) SmallStrainUDSMLaw : public Constitu
9898

9999
// This constitutive law cannot be moved using the default semantics provided by the compiler
100100
// due to the C-style multidimensional array. We'll disable the move operations for now.
101-
SmallStrainUDSMLaw(SmallStrainUDSMLaw&&) noexcept = delete;
101+
SmallStrainUDSMLaw(SmallStrainUDSMLaw&&) noexcept = delete;
102102
SmallStrainUDSMLaw& operator=(SmallStrainUDSMLaw&&) noexcept = delete;
103103

104104
[[nodiscard]] ConstitutiveLaw::Pointer Clone() const override;

0 commit comments

Comments
 (0)