Program Listing for File pybind11KModel.h

Program Listing for File pybind11KModel.h#

Return to documentation for file (include/Karana/SOADyn/pybind11KModel.h)

/*
*Copyright(c)2024-2026KaranaDynamicsPtyLtd.Allrightsreserved.
*
*NOTICETOUSER:
*
*Thissourcecodeand/ordocumentation(the"LicensedMaterials")is
*theconfidentialandproprietaryinformationofKaranaDynamicsInc.
*UseoftheseLicensedMaterialsisgovernedbythetermsandconditions
*ofaseparatesoftwarelicenseagreementbetweenKaranaDynamicsandthe
*Licensee("LicenseAgreement").Unlessexpresslypermittedunderthat
*agreement,anyreproduction,modification,distribution,ordisclosure
*oftheLicensedMaterials,inwholeorinpart,toanythirdparty
*withoutthepriorwrittenconsentofKaranaDynamicsisstrictlyprohibited.
*
*THELICENSEDMATERIALSAREPROVIDED"ASIS"WITHOUTWARRANTYOFANYKIND.
*KARANADYNAMICSDISCLAIMSALLWARRANTIES,EXPRESSORIMPLIED,INCLUDING
*BUTNOTLIMITEDTOWARRANTIESOFMERCHANTABILITY,NON-INFRINGEMENT,AND
*FITNESSFORAPARTICULARPURPOSE.
*
*INNOEVENTSHALLKARANADYNAMICSBELIABLEFORANYDAMAGESWHATSOEVER,
*INCLUDINGBUTNOTLIMITEDTOLOSSOFPROFITS,DATA,ORUSE,EVENIF
*ADVISEDOFTHEPOSSIBILITYOFSUCHDAMAGES,WHETHERINCONTRACT,TORT,
*OROTHERWISEARISINGOUTOFORINCONNECTIONWITHTHELICENSEDMATERIALS.
*
*U.S.GovernmentEndUsers:TheLicensedMaterialsarea"commercialitem"
*asdefinedat48C.F.R.2.101,andareprovidedtotheU.S.Government
*onlyasacommercialenditemunderthetermsofthislicense.
*
*AnyuseoftheLicensedMaterialsinindividualorcommercialsoftwaremust
*include,intheuserdocumentationandinternalsourcecodecomments,
*thisNotice,Disclaimer,andU.S.GovernmentUseProvision.
*/


#include"Karana/KCore/pybind11_chrono_numpy.h"
#include"Karana/SOADyn/KModel.h"
#include<pybind11/pybind11.h>
#include<pybind11/stl.h>

namespacepy=pybind11;

namespaceKarana::Models{

template<classT,
classP=NoParams,
classSc=NoScratch,
classS=NoDiscreteStates,
classC=NoContinuousStates>
autoKModelPybind11(//NOLINT(readability-identifier-naming)
conststd::string&class_name,
py::module&m){
autoPyKModelClass=
py::class_<KModel<T,P,Sc,S,C>,BaseKModel,kc::ks_ptr<KModel<T, P, Sc, S, C>>>(
m,class_name.c_str())
.def("getNextModelStepTime",
&KModel<T, P, Sc, S, C>::getNextModelStepTime,
py::arg("t"),
R"raw(
Getthenextsteptimeassumingtheprovidedtime`t`isatimethemodelhasastepat.

Parameters
----------
t:Ktime
Atimethemodelhasastepat.

Returns
-------
Ktime
Thenextmodelsteptime.
)raw")

.def("getPeriod",
&KModel<T, P, Sc, S, C>::getPeriod,
R"raw(
Gettheperiodofthemodel.

Ifa`nextModelStepTime`methodexists,thisreturnsawarning.Amodelperiodand
`nextModelStepTime`cannotbothbedefinedforamodel.

Returns
-------
Ktime
Themodel'speriod.
)raw")

.def("setPeriod",
&KModel<T, P, Sc, S, C>::setPeriod,
py::arg("t"),
R"raw(
Setthemodelperiod.

Themodelperioddefinestheperiodatwhichthemodelruns.Thereareafewcasestoconsider:

1.Theperiodis0andno`nextModelStepTime`methodisdefined.Inthiscase,the
`preModelStep`/`postModelStep`methodswillruneverytimeasimulationhophappens.
2.Theperiodisnon-zero.Inthiscase,thosemethodswillrunatthespecifiedperiod.
3.Theperiodis0anda`nextModelStepTime`methodisdefined.Then,thatmethoddefineswhenthe
stepswillrun.

Amodelperiodand`nextModelStepTime`cannotbothbedefinedforamodel.Anerrorwillbe
thrownifamodelwith`nextModelStepTime`hasitsperiodset.

Parameters
----------
t:Ktime
Thenewmodelperiod.
)raw")

.def("isReady",
&KModel<T, P, Sc, S, C>::isReady,
R"raw(
Checkswhetherthemodelisready.

Returns
-------
bool:
Returnsfalseiftheparamspointerisemptyoriftheparametersarenotfinalize.Returnstrueotherwise.
)raw")

.def_readwrite("model_manager",&KModel<T, P, Sc, S, C>::model_manager)
.def_readwrite("debug_model",&KModel<T, P, Sc, S, C>::debug_model);

//Addparamsifaparamsclassisdefined
ifconstexpr(notstd::is_same_v<NoParams,P>){
PyKModelClass.def_readwrite("params",&KModel<T, P, Sc, S, C>::params);
}

//Addscratchifascratchclassisdefined
ifconstexpr(notstd::is_same_v<NoScratch,Sc>){
PyKModelClass.def_readwrite("scratch",&KModel<T, P, Sc, S, C>::scratch);
}

//Adddiscretestatesifadiscretestatesclassisdefined
ifconstexpr(notstd::is_same_v<NoDiscreteStates,S>){
PyKModelClass.def_readwrite("discrete_states",
&KModel<T, P, Sc, S, C>::discrete_states);
}

//Addcontinuous_statesifacontinuous_statesclassisdefined
ifconstexpr(notstd::is_same_v<NoContinuousStates,C>){
PyKModelClass.def_readwrite("continuous_states",
&KModel<T, P, Sc, S, C>::continuous_states);
}

returnPyKModelClass;
}

}//namespaceKarana::Models