Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonRohou committed Feb 19, 2021
2 parents 0c3242f + 1fc32db commit b664d83
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
4 changes: 2 additions & 2 deletions python/src/core/variables/trajectory/codac_py_Trajectory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ void export_Trajectory(py::module& m)
TRAJECTORY_CONSTTRAJECTORY_DIFF)

.def("finite_diff", &Trajectory::finite_diff,
TRAJECTORY_DOUBLE_FINITE_DIFF_DOUBLE,
"t"_a)
TRAJECTORY_DOUBLE_FINITE_DIFF_DOUBLE_DOUBLE,
"t"_a, "h"_a)

// Assignments operators

Expand Down
18 changes: 14 additions & 4 deletions src/core/variables/trajectory/codac_Trajectory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,13 +494,24 @@ namespace codac
break;

case TrajDefnType::MAP_OF_VALUES: // finite difference computation
{
assert(m_map_values.size() > 1);

double prev_t = m_map_values.begin()->first;
for(map<double,double>::const_iterator it = m_map_values.begin() ; it != m_map_values.end() ; it++)
d.set(finite_diff(it->first), it->first);
{
double h = it->first - prev_t;

if(h == 0.) // first value
h = next(m_map_values.begin())->first - prev_t;

d.set(finite_diff(it->first, h), it->first);
prev_t = it->first;
}

assert(d.tdomain() == tdomain());
break;
}

default:
assert(false && "unhandled case");
Expand All @@ -509,14 +520,13 @@ namespace codac
return d;
}

double Trajectory::finite_diff(double t) const
double Trajectory::finite_diff(double t, double h) const
{
// todo: improve this with h not symmetric?
assert(m_traj_def_type == TrajDefnType::MAP_OF_VALUES);
assert(m_map_values.find(t) != m_map_values.end()); // key exists
assert(m_map_values.size() > 2);

double h = next(m_map_values.begin())->first - m_map_values.begin()->first;

vector<double> fwd;
map<double,double>::const_iterator it_fwd = m_map_values.find(t);
double x = it_fwd->second;
Expand Down
3 changes: 2 additions & 1 deletion src/core/variables/trajectory/codac_Trajectory.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,10 @@ namespace codac
* \note A uniform grid spacing is assumed.
*
* \param t the temporal key (double, must belong to the trajectory's tdomain)
* \param h temporal timestep around t
* \return a derivative trajectory
*/
double finite_diff(double t) const;
double finite_diff(double t, double h) const;

/// @}
/// \name Assignments operators
Expand Down
2 changes: 2 additions & 0 deletions src/core/variables/trajectory/codac_TrajectoryVector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ namespace codac
assert(!list_t.empty());
assert(list_t.size() == list_x.size());

#ifdef DEBUG
int n = list_x.begin()->size();
#endif

list<double>::const_iterator it_t = list_t.begin();
list<Vector>::const_iterator it_x = list_x.begin();
Expand Down

0 comments on commit b664d83

Please sign in to comment.