Skip to content
Draft
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
2 changes: 1 addition & 1 deletion include/trick/DRAscii.hh
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ namespace Trick {
@code <my_drg> = trick.DRAscii("<in_name>") @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
Expand Down
2 changes: 1 addition & 1 deletion include/trick/DRHDF5.hh
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ GROUP "/" {
@code <my_drg> = trick.DRHDF5("<in_name>") @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
Expand Down
209 changes: 209 additions & 0 deletions include/trick/IntegrationJobDataRecordGroup.hh
Original file line number Diff line number Diff line change
@@ -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<typename T> 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<DRBinary *>(this) != nullptr)
{
T::register_group_with_mm(this, "Trick::IntegJobDRBinary");
} else if(dynamic_cast<DRAscii *>(this) != nullptr)
{
T::register_group_with_mm(this, "Trick::IntegJobDRAscii");
}
#ifdef HDF5
else if(dynamic_cast<DRHDF5 *>(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<DRBinary>;
// %trick_cast_as(IntegJobDRBinary, IntegJobDRBinary)
%template (IntegJobDRAscii) IntegrationJobDataRecordGroupBase<DRAscii>;
// %trick_cast_as(IntegJobDRAscii, IntegJobDRAscii)
#ifdef HDF5
%template (IntegJobDRHDF5) IntegrationJobDataRecordGroupBase<DRHDF5>;
// %trick_cast_as(IntegJobDRHDF5, IntegJobDRHDF5)
#endif
#endif

typedef IntegrationJobDataRecordGroupBase<DRBinary> IntegJobDRBinary;
typedef IntegrationJobDataRecordGroupBase<DRAscii> IntegJobDRAscii;
#ifdef HDF5
typedef IntegrationJobDataRecordGroupBase<DRHDF5> IntegJobDRHDF5;
#endif

} // namespace Trick

#ifdef SWIG
%feature("compactdefaultargs","1") ;
#endif

#endif /* INTEGRATIONJOBDATARECORDGROUP_HH */
1 change: 1 addition & 0 deletions include/trick/files_to_ICG.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 3 additions & 2 deletions test/SIM_test_multidt/RUN_test/input.py
Original file line number Diff line number Diff line change
@@ -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) + "]"
Expand Down Expand Up @@ -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)

6 changes: 4 additions & 2 deletions trick_source/sim_services/DataRecord/DRAscii.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
6 changes: 4 additions & 2 deletions trick_source/sim_services/DataRecord/DRHDF5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
1 change: 1 addition & 0 deletions trick_source/trick_swig/sim_services.i
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading