Skip to content
This repository was archived by the owner on Mar 20, 2023. It is now read-only.

Commit cbeb991

Browse files
jorblancoasergiorg-hpc
authored andcommitted
Take into account IClamp for the lfp calculation
1 parent f8540ed commit cbeb991

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

coreneuron/io/reports/report_event.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ void ReportEvent::lfp_calc(NrnThread* nt) {
8080
if (step > 0 && (static_cast<int>(step) % reporting_period) == 0) {
8181
auto* mapinfo = static_cast<NrnThreadMappingInfo*>(nt->mapping);
8282
double* fast_imem_rhs = nt->nrn_fast_imem->nrn_sav_rhs;
83-
83+
auto& summation_report = nt->summation_report_handler_->summation_reports_[report_path];
8484
for (const auto& kv: vars_to_report) {
8585
int gid = kv.first;
8686
const auto& to_report = kv.second;
@@ -94,7 +94,13 @@ void ReportEvent::lfp_calc(NrnThread* nt) {
9494
if(std::isnan(factor)) {
9595
factor = 0.0;
9696
}
97-
sum += fast_imem_rhs[segment_id] * factor;
97+
double iclamp = 0.0;
98+
for (const auto& value: summation_report.currents_[segment_id]) {
99+
double current_value = *value.first;
100+
int scale = value.second;
101+
iclamp += current_value * scale;
102+
}
103+
sum += (fast_imem_rhs[segment_id] + iclamp) * factor;
98104
count++;
99105
}
100106
*(to_report.front().var_value) = sum;
@@ -107,8 +113,10 @@ void ReportEvent::deliver(double t, NetCvode* nc, NrnThread* nt) {
107113
/* reportinglib is not thread safe */
108114
#pragma omp critical
109115
{
110-
summation_alu(nt);
111-
if (report_type == ReportType::LFPReport) {
116+
if (report_type == ReportType::SummationReport) {
117+
summation_alu(nt);
118+
}
119+
else if (report_type == ReportType::LFPReport) {
112120
lfp_calc(nt);
113121
}
114122
// each thread needs to know its own step

coreneuron/io/reports/report_handler.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void ReportHandler::create_report(double dt, double tstop, double delay) {
6262
case LFPReport:
6363
// 1 lfp value per gid
6464
mapinfo->_lfp.resize(nt.ncell);
65-
vars_to_report = get_lfp_vars_to_report(nt, m_report_config, mapinfo->_lfp.data());
65+
vars_to_report = get_lfp_vars_to_report(nt, m_report_config, mapinfo->_lfp.data(), nodes_to_gid);
6666
is_soma_target = m_report_config.section_type == SectionType::Soma ||
6767
m_report_config.section_type == SectionType::Cell;
6868
register_section_report(nt, m_report_config, vars_to_report, is_soma_target);
@@ -353,14 +353,25 @@ VarsToReport ReportHandler::get_synapse_vars_to_report(
353353

354354
VarsToReport ReportHandler::get_lfp_vars_to_report(const NrnThread& nt,
355355
ReportConfiguration& report,
356-
double* report_variable) const {
356+
double* report_variable,
357+
const std::vector<int>& nodes_to_gids) const {
358+
auto& summation_report = nt.summation_report_handler_->summation_reports_[report.output_path];
357359
VarsToReport vars_to_report;
358360
for (int i = 0; i < nt.ncell; i++) {
359361
int gid = nt.presyns[i].gid_;
360362
if (report.target.find(gid) == report.target.end()) {
361363
continue;
362364
}
363-
365+
// IClamp is needed for the LFP calculation
366+
auto mech_id = nrn_get_mechtype("IClamp");
367+
Memb_list* ml = nt._ml_list[mech_id];
368+
for (int j = 0; j < ml->nodecount; j++) {
369+
auto segment_id = ml->nodeindices[j];
370+
if ((nodes_to_gids[segment_id] == gid)) {
371+
double* var_value = get_var_location_from_var_name(mech_id, "i", ml, j);
372+
summation_report.currents_[segment_id].push_back(std::make_pair(var_value, -1));
373+
}
374+
}
364375
std::vector<VarWithMapping> to_report;
365376
double* variable = report_variable + i;
366377
to_report.push_back(VarWithMapping(i, variable));

coreneuron/io/reports/report_handler.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ class ReportHandler {
4646
const std::vector<int>& nodes_to_gids) const;
4747
VarsToReport get_lfp_vars_to_report(const NrnThread& nt,
4848
ReportConfiguration& report,
49-
double* report_variable) const;
49+
double* report_variable,
50+
const std::vector<int>& nodes_to_gids) const;
5051
std::vector<int> map_gids(const NrnThread& nt) const;
5152
#endif // defined(ENABLE_BIN_REPORTS) || defined(ENABLE_SONATA_REPORTS)
5253
protected:

0 commit comments

Comments
 (0)