diff --git a/doc/mathlink.dox b/doc/mathlink.dox index e545e26cc..c74cbcf3e 100644 --- a/doc/mathlink.dox +++ b/doc/mathlink.dox @@ -190,6 +190,39 @@ _Output_: Azero -> 0. } ~~~~~~~~~~~~~~~~~~~~ +\subsubsection FS_model_Set FSSet + +Using the `FSSet[]` function, the input parameters and settings +associated to a certain handle can be modified. The `FSSet[]` +function takes first as argument the handle, and as second argument +the replacement list of new parameters / settings. + +_Example_: + +~~~~~~~~~~~~~~~~~~~~{.m} +Get["models/CMSSM/CMSSM_librarylink.m"]; +handle = FSCMSSMOpenHandle[ + fsSettings -> { precisionGoal -> 1.*^-4 }, + fsSMParameters -> { Mt -> 173.3 }, + fsModelParameters -> { + m0 -> 125, m12 -> 500, TanBeta -> 10, SignMu -> 1, Azero -> 0 } +]; + +FSCMSSMGetInputParameters[handle] + +FSCMSSMSet[handle, TanBeta -> 20]; + +FSCMSSMGetInputParameters[handle] +~~~~~~~~~~~~~~~~~~~~ + +_Output_: + +~~~~~~~~~~~~~~~~~~~~{.m} +{m0 -> 125., m12 -> 500., TanBeta -> 10., SignMu -> 1, Azero -> 0.} + +{m0 -> 125., m12 -> 500., TanBeta -> 20., SignMu -> 1, Azero -> 0.} +~~~~~~~~~~~~~~~~~~~~ + \subsubsection FS_model_CalculateSpectrum FSCalculateSpectrum For each ``, the `FSCalculateSpectrum[handle]` function diff --git a/templates/librarylink.cpp.in b/templates/librarylink.cpp.in index 0ef0646ce..8c1d99575 100644 --- a/templates/librarylink.cpp.in +++ b/templates/librarylink.cpp.in @@ -627,6 +627,40 @@ DLLEXPORT int FS@ModelName@CloseHandle( /******************************************************************/ +DLLEXPORT int FS@ModelName@Set( + WolframLibraryData libData, mint Argc, MArgument* Args, MArgument /* Res */) +{ + if (Argc != 2) + return LIBRARY_TYPE_ERROR; + + const Handle_id hid = MArgument_getInteger(Args[0]); + MTensor pars = MArgument_getMTensor(Args[1]); + + if (libData->MTensor_getType(pars) != MType_Real || + libData->MTensor_getRank(pars) != 1) + return LIBRARY_TYPE_ERROR; + + const Handle_map::iterator handle = handles.find(hid); + + if (handle == handles.end()) { + std::cerr << "Error: FS@ModelName@Set: Unknown handle: " + << hid << std::endl; + return LIBRARY_FUNCTION_ERROR; + } + + try { + handle->second = fill(libData->MTensor_getRealData(pars), + libData->MTensor_getDimensions(pars)[0]); + } catch (const flexiblesusy::Error& e) { + std::cerr << e.what() << std::endl; + return LIBRARY_FUNCTION_ERROR; + } + + return LIBRARY_NO_ERROR; +} + +/******************************************************************/ + DLLEXPORT int FS@ModelName@CalculateSpectrum( WolframLibraryData /* libData */, MLINK link) { diff --git a/templates/librarylink.m.in b/templates/librarylink.m.in index c84feb35b..50154bbfd 100644 --- a/templates/librarylink.m.in +++ b/templates/librarylink.m.in @@ -7,6 +7,8 @@ FS@ModelName@GetInputParameters = LibraryFunctionLoad[lib@ModelName@, "FS@ModelN FS@ModelName@OpenHandleLib = LibraryFunctionLoad[lib@ModelName@, "FS@ModelName@OpenHandle", {{Real,1}}, Integer]; FS@ModelName@CloseHandle = LibraryFunctionLoad[lib@ModelName@, "FS@ModelName@CloseHandle", {Integer}, Void]; +FS@ModelName@SetLib = LibraryFunctionLoad[lib@ModelName@, "FS@ModelName@Set", {Integer, {Real,1}}, Void]; + FS@ModelName@CalculateSpectrum = LibraryFunctionLoad[lib@ModelName@, "FS@ModelName@CalculateSpectrum", LinkObject, LinkObject]; FS@ModelName@CalculateObservables = LibraryFunctionLoad[lib@ModelName@, "FS@ModelName@CalculateObservables", LinkObject, LinkObject]; @@ -141,3 +143,17 @@ FS@ModelName@OpenHandle[OptionsPattern[]] := @setInputParameterArguments@ } ]; + +Options[FS@ModelName@Set] = Options[FS@ModelName@OpenHandle]; + +FS@ModelName@Set[handle_Integer, a___, (fsSettings | fsSMParameters | fsModelParameters) -> s_List, r___] := + FS@ModelName@Set[a, Sequence @@ s, r]; + +FS@ModelName@Set[handle_Integer, p:OptionsPattern[]] := + FS@ModelName@SetLib[ + handle, + First /@ Options[FS@ModelName@Set] /. + { p } /. + FS@ModelName@GetSettings[handle] /. + FS@ModelName@GetSMInputParameters[handle] /. + FS@ModelName@GetInputParameters[handle]]; diff --git a/test/test_CMSSM_librarylink.m b/test/test_CMSSM_librarylink.m index 37aa6b0a2..d56a6b608 100644 --- a/test/test_CMSSM_librarylink.m +++ b/test/test_CMSSM_librarylink.m @@ -149,4 +149,35 @@ TestEquality[Mhh1, Mhh2]; +Print["Testing Set[] function"]; + +CalcMh[handle_] := + Module[{spec}, + spec = FSCMSSMCalculateSpectrum[handle]; + If[spec === $Failed, 0, + (Pole[M[hh]] /. spec)[[1]] + ] + ]; + +handle = FSCMSSMOpenHandle[ + fsSettings -> settings, + fsSMParameters -> smInputs, + fsModelParameters -> { + m0 -> 125, m12 -> 500, TanBeta -> 10, SignMu -> 1, Azero -> 0 } +]; + +Mhh1 = CalcMh[handle]; + +FSCMSSMSet[handle, TanBeta -> 10]; + +Mhh2 = CalcMh[handle]; + +TestEquality[Mhh1, Mhh2]; + +FSCMSSMSet[handle, TanBeta -> 20]; + +Mhh3 = CalcMh[handle]; + +TestNonEquality[Mhh1, Mhh3]; + PrintTestSummary[];