diff --git a/include/trick/DRAscii.hh b/include/trick/DRAscii.hh index 6da2c8390..4d13a7d17 100644 --- a/include/trick/DRAscii.hh +++ b/include/trick/DRAscii.hh @@ -69,7 +69,7 @@ namespace Trick { @code = trick.DRAscii("") @endcode @copydoc Trick::DataRecordGroup::DataRecordGroup(string in_name) */ - DRAscii( std::string in_name, Trick::DR_Type dr_type = Trick::DR_Type::DR_Type_Ascii ) ; + DRAscii( std::string in_name, bool register_group = true, Trick::DR_Type dr_type = Trick::DR_Type::DR_Type_Ascii ) ; /** @copybrief Trick::DataRecordGroup::format_specific_header diff --git a/include/trick/DRHDF5.hh b/include/trick/DRHDF5.hh index 3540da6c7..4223fb597 100644 --- a/include/trick/DRHDF5.hh +++ b/include/trick/DRHDF5.hh @@ -95,7 +95,7 @@ GROUP "/" { @code = trick.DRHDF5("") @endcode @copydoc Trick::DataRecordGroup::DataRecordGroup(string in_name) */ - DRHDF5( std::string in_name, Trick::DR_Type dr_type = Trick::DR_Type::DR_Type_HDF5) ; + DRHDF5( std::string in_name, bool register_group = true, Trick::DR_Type dr_type = Trick::DR_Type::DR_Type_HDF5) ; /** @copybrief Trick::DataRecordGroup::format_specific_header diff --git a/include/trick/IntegrationJobDataRecordGroup.hh b/include/trick/IntegrationJobDataRecordGroup.hh new file mode 100644 index 000000000..cf6ea790a --- /dev/null +++ b/include/trick/IntegrationJobDataRecordGroup.hh @@ -0,0 +1,209 @@ +/******************************************************************************* + + PURPOSE: + (DataRecordGroup class tailored to log all the intermediate_steps of the integration loop.) + + PROGRAMMERS: + (((Thomas Brain) (Metecs) (May 2024) (--))) + + *******************************************************************************/ + +#ifndef INTEGRATIONJOBDATARECORDGROUP_HH +#define INTEGRATIONJOBDATARECORDGROUP_HH + +#include "trick/DRAscii.hh" +#include "trick/DRBinary.hh" +#ifdef HDF5 +#include "trick/DRHDF5.hh" +#endif +#include "trick/IntegLoopScheduler.hh" +#include "trick/message_proto.h" +#include "trick/message_type.h" + +#ifdef SWIG +%feature("compactdefaultargs","0") ; +%define INTEG_DR_SHADOW(TYPE) +%feature("shadow") Trick::TYPE::TYPE(const std::string & in_name, Trick::IntegLoopScheduler & integSchedulerPtrIn) %{ + def __init__(self, *args): + this = $action(*args) + try: self.this.append(this) + except: self.this = this + this.own(0) + self.this.own(0) +%} +%enddef +#endif + +#ifdef SWIG +INTEG_DR_SHADOW(Trick::IntegJobDRBinary) +INTEG_DR_SHADOW(Trick::IntegJobDRAscii) +#ifdef HDF5 +INTEG_DR_SHADOW(Trick::IntegJobDRHDF5) +#endif +#endif + +namespace Trick +{ + +template class IntegrationJobDataRecordGroupBase : public T +{ +public: +#ifndef SWIG + IntegrationJobDataRecordGroupBase() : T() { + + } +#endif + + IntegrationJobDataRecordGroupBase(const std::string & in_name, + Trick::IntegLoopScheduler & integSchedulerRefIn) + : T(in_name, false), integSchedulerPtr(&integSchedulerRefIn) + { + T::set_job_class("integration"); + if(dynamic_cast(this) != nullptr) + { + T::register_group_with_mm(this, "Trick::IntegJobDRBinary"); + } else if(dynamic_cast(this) != nullptr) + { + T::register_group_with_mm(this, "Trick::IntegJobDRAscii"); + } + #ifdef HDF5 + else if(dynamic_cast(this) != nullptr) + { + T::register_group_with_mm(this, "Trick::IntegJobDRHDF5"); + } + #endif + } + + virtual ~IntegrationJobDataRecordGroupBase() = default; + + virtual int init(bool is_restart = false) override + { + if(integSchedulerPtr == nullptr) + { + message_publish( + MSG_ERROR, + "DataRecordGroup ERROR: IntegLoopScheduler pointer is NULL for group %s\n", + T::group_name.c_str()); + return -1; + } + if(!is_restart) { + integSchedulerPtr->add_sim_object(*this); + } + if(integSchedulerPtr->integ_ptr != nullptr && T::write_job->sup_class_data == nullptr) { + setIntegrator(*(integSchedulerPtr->integ_ptr)); + } + if(T::write_job->sup_class_data == nullptr) + { + message_publish( + MSG_ERROR, + "DataRecordGroup ERROR: Integrator pointer is NULL for group %s\n", + T::group_name.c_str()); + return -1; + } + if(!is_restart) + { + T::max_num *= MaxSteps; + } + return T::init(is_restart); + } + + virtual int data_record(double in_time) override + { + double integTime = integPtr->time_0; + double currLogTime; + if(integPtr->intermediate_step == 0 && std::abs(in_time - integPtr->time) < 1.0e-12) + { + currLogTime = in_time; + } + else + { + currLogTime = integTime + (integPtr->intermediate_step * (integPtr->dt / MaxSteps)); + } + + // Check if we want to log every integration cycle + T::data_record(currLogTime); + return integPtr->intermediate_step; + } + + virtual void setMaxSteps(const int MaxStepsIn) + { + MaxSteps = MaxStepsIn; + } + + virtual void setIntegrator(Trick::Integrator & integIn) + { + integPtr = &integIn; + Integrator_type integ_type = integIn.get_Integrator_type(); + switch(integ_type) + { + case Euler: + MaxSteps = 1; + break; + case Euler_Cromer: + MaxSteps = 1; + break; + case Nystrom_Lear_2: + MaxSteps = 2; + break; + case Runge_Kutta_2: + MaxSteps = 2; + break; + case Modified_Midpoint_4: + MaxSteps = 3; + break; + case Runge_Kutta_4: + MaxSteps = 4; + break; + case Runge_Kutta_Gill_4: + MaxSteps = 4; + break; + case Runge_Kutta_Fehlberg_45: + MaxSteps = 6; + break; + case Runge_Kutta_Fehlberg_78: + MaxSteps = 12; + break; + case ABM_Method: + MaxSteps = 4; + break; + case User_Defined: + MaxSteps = 1; + break; + default: + MaxSteps = 1; + break; + } + T::write_job->sup_class_data = &integPtr; + } + + Trick::IntegLoopScheduler * integSchedulerPtr{}; + +protected: + Trick::Integrator * integPtr{}; + int MaxSteps{4}; +}; + +#ifdef SWIG +%template (IntegJobDRBinary) IntegrationJobDataRecordGroupBase; +// %trick_cast_as(IntegJobDRBinary, IntegJobDRBinary) +%template (IntegJobDRAscii) IntegrationJobDataRecordGroupBase; +// %trick_cast_as(IntegJobDRAscii, IntegJobDRAscii) +#ifdef HDF5 +%template (IntegJobDRHDF5) IntegrationJobDataRecordGroupBase; +// %trick_cast_as(IntegJobDRHDF5, IntegJobDRHDF5) +#endif +#endif + +typedef IntegrationJobDataRecordGroupBase IntegJobDRBinary; +typedef IntegrationJobDataRecordGroupBase IntegJobDRAscii; +#ifdef HDF5 +typedef IntegrationJobDataRecordGroupBase IntegJobDRHDF5; +#endif + +} // namespace Trick + +#ifdef SWIG +%feature("compactdefaultargs","1") ; +#endif + +#endif /* INTEGRATIONJOBDATARECORDGROUP_HH */ diff --git a/include/trick/files_to_ICG.hh b/include/trick/files_to_ICG.hh index 39fcf2303..f510b6cd2 100644 --- a/include/trick/files_to_ICG.hh +++ b/include/trick/files_to_ICG.hh @@ -83,6 +83,7 @@ #include "trick/DRAscii.hh" #include "trick/DRBinary.hh" #include "trick/DRHDF5.hh" +#include "trick/IntegrationJobDataRecordGroup.hh" #include "trick/DebugPause.hh" #include "trick/EchoJobs.hh" #include "trick/FrameLog.hh" diff --git a/test/SIM_test_multidt/RUN_test/input.py b/test/SIM_test_multidt/RUN_test/input.py index 63e3d4947..da271a6ef 100644 --- a/test/SIM_test_multidt/RUN_test/input.py +++ b/test/SIM_test_multidt/RUN_test/input.py @@ -1,6 +1,7 @@ # Data recording test -drg0 = trick.DRBinary("Ball") +drg0 = trick.IntegJobDRBinary("Ball", my_integ_loop.integ_sched) +drg0.thisown = 0 for param in [ 'position' , 'velocity' , 'acceleration' , 'external_force' ] : for index in range(0,2) : var = "ball.output_" + param + "[" + str(index) + "]" @@ -45,5 +46,5 @@ read = 300.0 trick.add_read(read , """trick.checkpoint("chkpnt_300.0")""") -trick.exec_set_terminate_time(300.0) +trick.exec_set_terminate_time(30.0) diff --git a/trick_source/sim_services/DataRecord/DRAscii.cpp b/trick_source/sim_services/DataRecord/DRAscii.cpp index 5b1f5d902..c9e3f2a35 100644 --- a/trick_source/sim_services/DataRecord/DRAscii.cpp +++ b/trick_source/sim_services/DataRecord/DRAscii.cpp @@ -18,12 +18,14 @@ #include "trick/message_type.h" #include "trick/bitfield_proto.h" -Trick::DRAscii::DRAscii( std::string in_name, Trick::DR_Type dr_type ) : Trick::DataRecordGroup( in_name, dr_type ) { +Trick::DRAscii::DRAscii( std::string in_name, bool register_group, Trick::DR_Type dr_type ) : Trick::DataRecordGroup( in_name, dr_type ) { ascii_float_format = "%20.8g" ; ascii_double_format = "%20.16g" ; delimiter = ","; - register_group_with_mm(this, "Trick::DRAscii") ; + if ( register_group ) { + register_group_with_mm(this, "Trick::DRAscii") ; + } } int Trick::DRAscii::format_specific_header( std::fstream & out_st ) { diff --git a/trick_source/sim_services/DataRecord/DRHDF5.cpp b/trick_source/sim_services/DataRecord/DRHDF5.cpp index 24913b363..3a5ea3753 100644 --- a/trick_source/sim_services/DataRecord/DRHDF5.cpp +++ b/trick_source/sim_services/DataRecord/DRHDF5.cpp @@ -16,8 +16,10 @@ #include "trick/message_proto.h" #include "trick/bitfield_proto.h" -Trick::DRHDF5::DRHDF5( std::string in_name, Trick::DR_Type dr_type ) : Trick::DataRecordGroup(in_name, dr_type) { - register_group_with_mm(this, "Trick::DRHDF5") ; +Trick::DRHDF5::DRHDF5( std::string in_name, bool register_group, Trick::DR_Type dr_type ) : Trick::DataRecordGroup(in_name, dr_type) { + if ( register_group ) { + register_group_with_mm(this, "Trick::DRHDF5") ; + } } int Trick::DRHDF5::format_specific_header( std::fstream & out_stream ) { diff --git a/trick_source/trick_swig/sim_services.i b/trick_source/trick_swig/sim_services.i index 75b60427c..d11ab3230 100644 --- a/trick_source/trick_swig/sim_services.i +++ b/trick_source/trick_swig/sim_services.i @@ -57,6 +57,7 @@ #ifdef HDF5 #include "trick/DRHDF5.hh" #endif +#include "trick/IntegrationJobDataRecordGroup.hh" #include "trick/DataRecordDispatcher.hh" #include "trick/data_record_proto.h" #include "trick/DebugPause.hh"