Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
cfba992
Added coords dumping to NSDFWriter, as static data
upibhalla Jan 29, 2022
77be6cd
Updates to version and change log for NSDFWriter
upibhalla Jan 31, 2022
7b7dbc5
Adding NSDF support to rdesigneur, and display capabilities for NSDF …
upibhalla Feb 4, 2022
964b082
Updates to NSDFWriter to handle model file inclusion. Fixes to ReadKkit.
upibhalla Feb 7, 2022
99b4166
Added NSDFWriter2 class to group data saves by object blocks rather t…
upibhalla Feb 15, 2022
dc05c8c
NSDFWriter2.cpp skeleton now working, much bug tracking later.
upibhalla Feb 17, 2022
c942da8
Further bugfixes to NSDFWriter2, and supporting code in rdesigneur.
upibhalla Feb 19, 2022
2709022
Merge branch 'zombie_gone' of https://github.com/BhallaLab/moose-core…
upibhalla Feb 19, 2022
842ac15
Embedded files now saved as datasets, rather than annotations. Handle…
upibhalla Feb 20, 2022
f8a9fd6
Fixed NSDFWriter2 bugs: reinit bug.
upibhalla Feb 22, 2022
1679662
Fix for Gsolve.cpp which was using reference to legacy ZombieBufPool.
upibhalla Feb 23, 2022
ffc5c52
Fixes for 3d viewer from nsdf and rdesigneur.
upibhalla Feb 24, 2022
7cdab81
Cosmetic fixes to moogul: merged views, timestamp display, frame spee…
upibhalla Feb 24, 2022
b397cee
Update NSDFWriter2 to handle maps for saving obj path for uniform and…
upibhalla Mar 2, 2022
793eb68
Moogul now uses the more feature-ful but slightly slower graphing in …
upibhalla Mar 7, 2022
9407bb5
Cleaned up syntax for nsdfview and for rdesigneur outputFileList spec…
upibhalla Mar 8, 2022
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
6 changes: 6 additions & 0 deletions basecode/Eref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ Eref::Eref()
;
}

Eref::Eref( const Eref& other )
: e_( other.e_ ), i_( other.i_ ), f_( other.f_ )
{
;
}

Eref::Eref( Element* e, unsigned int index, unsigned int field )
: e_( e ), i_( index ), f_( field )
{
Expand Down
1 change: 1 addition & 0 deletions basecode/Eref.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Eref

friend ostream& operator <<( ostream& s, const Eref& e );
Eref();
Eref( const Eref& other );
Eref( Element* e, unsigned int index, unsigned int field = 0 );

/**
Expand Down
6 changes: 6 additions & 0 deletions basecode/ObjId.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ class ObjId
;
}

ObjId( const ObjId& obj )
: id( obj.id ), dataIndex( obj.dataIndex ), fieldIndex( obj.fieldIndex )
{
;
}

/**
* Creates a ObjId using specified Id and DataIndex
*/
Expand Down
28 changes: 28 additions & 0 deletions biophysics/CompartmentBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,11 @@ const Cinfo* CompartmentBase::initCinfo()
&CompartmentBase::setZ,
&CompartmentBase::getZ
);
static ValueFinfo< CompartmentBase, vector< double > > coords( "coords",
"Vector with all coords: [x0 y0 z0 x y z dia]",
&CompartmentBase::setCoords,
&CompartmentBase::getCoords
);

//////////////////////////////////////////////////////////////////
// DestFinfo definitions
Expand Down Expand Up @@ -322,6 +327,7 @@ const Cinfo* CompartmentBase::initCinfo()
&x, // Value
&y, // Value
&z, // Value
&coords, // Value
&injectMsg, // DestFinfo
&randInject, // DestFinfo
&injectMsg, // DestFinfo
Expand Down Expand Up @@ -571,6 +577,28 @@ double CompartmentBase::getZ() const
return z_;
}

void CompartmentBase::setCoords( vector< double > value )
{
if (value.size() < 7 ) {
cout << "Warning: CompartmentBase:setCoords. Vector size = " << value.size() << ", require 7 = [ x0 y0 z0 x y z dia ] \n";
return;
}
x0_ = value[0];
y0_ = value[1];
z0_ = value[2];
x_ = value[3];
y_ = value[4];
z_ = value[5];
diameter_ = value[6];
updateLength();
}

vector< double > CompartmentBase::getCoords() const
{
vector< double > ret = { x0_, y0_, z0_, x_, y_, z_, diameter_ };
return ret;
}

//////////////////////////////////////////////////////////////////
// CompartmentBase::Dest function definitions.
//////////////////////////////////////////////////////////////////
Expand Down
2 changes: 2 additions & 0 deletions biophysics/CompartmentBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class CompartmentBase
double getY() const;
void setZ( double value );
double getZ() const;
void setCoords( vector< double > value );
vector< double > getCoords() const;

// Dest function definitions.
/**
Expand Down
1 change: 1 addition & 0 deletions builtins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ if(WITH_NSDF AND HDF5_FOUND)
list(APPEND SRCS
HDF5WriterBase.cpp
NSDFWriter.cpp
NSDFWriter2.cpp
HDF5DataWriter.cpp
SpikeStats.cpp
testBuiltins.cpp
Expand Down
15 changes: 11 additions & 4 deletions builtins/InputVariable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include "hdf5.h"

#include "NSDFWriter.h"
#include "NSDFWriter2.h"
#include "InputVariable.h"


Expand Down Expand Up @@ -81,7 +82,7 @@ const Cinfo * InputVariable::initCinfo()

static const Cinfo *InputVariableCinfo = InputVariable::initCinfo();

InputVariable::InputVariable(): owner_(0)
InputVariable::InputVariable(): owner_(0), owner2_(0)
{
;
}
Expand All @@ -96,12 +97,18 @@ void InputVariable::setOwner( NSDFWriter * owner)
owner_ = owner;
}

void InputVariable::setOwner( NSDFWriter2 * owner)
{
owner2_ = owner;
}

void InputVariable::epSetValue( const Eref& eref, double value)
{
if (owner_)
{
if (owner_) {
owner_->setInput(eref.fieldIndex(), value);
}
} else if ( owner2_ ) {
owner2_->setInput(eref.fieldIndex(), value);
}
}
#endif

Expand Down
3 changes: 3 additions & 0 deletions builtins/InputVariable.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#include "Variable.h"

class NSDFWriter;
class NSDFWriter2;

/**
This class is for collecting data and updating a handler object
Expand All @@ -65,9 +66,11 @@ class InputVariable: public Variable
~InputVariable();
void epSetValue(const Eref &eref, double value);
void setOwner(NSDFWriter * owner);
void setOwner(NSDFWriter2 * owner);
static const Cinfo * initCinfo();
protected:
NSDFWriter * owner_;
NSDFWriter2 * owner2_;
};

#endif
Expand Down
140 changes: 128 additions & 12 deletions builtins/NSDFWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
// Maintainer:
// Created: Thu Jun 18 23:16:11 2015 (-0400)
// Version:
// Last-Updated: Sun Dec 20 23:20:19 2015 (-0500)
// By: subha
// Update #: 49
// Last-Updated: Sat Jan 29 2022
// By: bhalla
// Update #: 50
// URL:
// Keywords:
// Compatibility:
Expand All @@ -22,7 +22,7 @@
//

// Change log:
//
// Jan 2022: Many changes added
//
//
//
Expand All @@ -49,9 +49,9 @@
#include "hdf5.h"
#include "hdf5_hl.h"

#include <fstream>
#include <ctime>
#include <deque>

#include "../basecode/header.h"
#include "../utility/utility.h"
#include "../utility/strutil.h"
Expand All @@ -67,8 +67,11 @@ extern template herr_t writeScalarAttr(hid_t file_id, string path, double value)

const char* const EVENTPATH = "/data/event";
const char* const UNIFORMPATH = "/data/uniform";
const char* const STATICPATH = "/data/static";
const char* const MODELTREEPATH = "/model/modeltree";
const char* const MODELFILEPATH = "/model/modelfile";
const char* const MAPUNIFORMSRC = "/map/uniform";
const char* const MAPSTATICSRC = "/map/static";
const char* const MAPEVENTSRC = "/map/event";

string iso_time(time_t * t)
Expand Down Expand Up @@ -99,10 +102,16 @@ const Cinfo * NSDFWriter::initCinfo()

static ValueFinfo <NSDFWriter, string > modelRoot(
"modelRoot",
"The moose element tree root to be saved under /model/modeltree",
"The moose element tree root to be saved under /model/modeltree. If blank, nothing is saved. Default: root object, '/'",
&NSDFWriter::setModelRoot,
&NSDFWriter::getModelRoot);

static ValueFinfo <NSDFWriter, string > modelFileNames(
"modelFileNames",
"Comma separated list of model files to save into the NSDF file.",
&NSDFWriter::setModelFiles,
&NSDFWriter::getModelFiles);

static DestFinfo process(
"process",
"Handle process calls. Collects data in buffer and if number of steps"
Expand All @@ -125,7 +134,8 @@ const Cinfo * NSDFWriter::initCinfo()
processShared, sizeof( processShared ) / sizeof( Finfo* ));

static Finfo * finfos[] = {
&eventInputFinfo,
&eventInputFinfo, // FieldElementFinfo
&modelFileNames, // ValueFinfo
&proc,
};

Expand Down Expand Up @@ -267,19 +277,37 @@ void NSDFWriter::openUniformData(const Eref &eref)
create the DS for uniform data.
*/
void NSDFWriter::createUniformMap()
{
innerCreateMaps( MAPUNIFORMSRC );
}

/**
create the DS for static data.
*/
void NSDFWriter::createStaticMap()
{
innerCreateMaps( MAPSTATICSRC );
}


/**
Generic call for create the DS for static/uniform data
*/
void NSDFWriter::innerCreateMaps( const char* const mapSrcStr )
{
// Create the container for all the DS
// TODO: make a common function like `mkdir -p` to avoid repeating this
htri_t exists;
herr_t status;
hid_t uniformMapContainer = require_group(filehandle_, MAPUNIFORMSRC);
hid_t uniformMapContainer = require_group(filehandle_, mapSrcStr );
// Create the DS themselves
for (map< string, vector < unsigned int > >::iterator ii = classFieldToSrcIndex_.begin();
ii != classFieldToSrcIndex_.end(); ++ii){
vector < string > pathTokens;
moose::tokenize(ii->first, "/", pathTokens);
string className = pathTokens[0];
string fieldName = pathTokens[1];
if (mapSrcStr == MAPSTATICSRC ) //Hack. for now only static field is coords
fieldName = "coords";
hid_t container = require_group(uniformMapContainer, className);
char ** sources = (char **)calloc(ii->second.size(), sizeof(char*));
for (unsigned int jj = 0; jj < ii->second.size(); ++jj){
Expand All @@ -291,9 +319,6 @@ void NSDFWriter::createUniformMap()
status = H5Tset_size(memtype, H5T_VARIABLE);
assert(status >= 0);
status = H5Dwrite(ds, memtype, H5S_ALL, H5S_ALL, H5P_DEFAULT, sources);
#ifndef NDEBUG
cout << "Write dataset: status=" << status << endl;
#endif
assert(status >= 0);
for (unsigned int jj = 0; jj < ii->second.size(); ++jj){
free(sources[jj]);
Expand Down Expand Up @@ -534,9 +559,12 @@ void NSDFWriter::reinit(const Eref& eref, const ProcPtr proc)
writeScalarAttr< double >(it->second, "dt", proc->dt);
}
openEventData(eref);
writeModelFiles();
writeModelTree();
createUniformMap();
createStaticMap();
createEventMap();
writeStaticCoords();
steps_ = 0;
}

Expand Down Expand Up @@ -627,9 +655,97 @@ string NSDFWriter::getModelRoot() const
return modelRoot_;
}

void NSDFWriter::setModelFiles(string value)
{
modelFileNames_.clear();
moose::tokenize( value, ", ", modelFileNames_);
}

string NSDFWriter::getModelFiles() const
{
string ret = "";
string spacer = "";
for( auto s = modelFileNames_.begin(); s!= modelFileNames_.end(); ++s) {
ret += spacer + *s;
spacer = ",";
}
return ret;
}

void NSDFWriter::writeStaticCoords()
{
hid_t staticObjContainer = require_group(filehandle_, STATICPATH );
for (map< string, vector < unsigned int > >::iterator ii = classFieldToSrcIndex_.begin(); ii != classFieldToSrcIndex_.end(); ++ii){
vector < string > pathTokens;
moose::tokenize(ii->first, "/", pathTokens);
string className = pathTokens[0];
string fieldName = "coords"; // pathTokens[1] is not relevant.
hid_t container = require_group(staticObjContainer, className);
double * buffer = (double*)calloc(ii->second.size() * 7, sizeof(double));
// Ugly class checking stuff here: Both have a coord field
if ( className.find( "Pool" ) != string::npos ||
className.find( "Compartment" ) != string::npos ) {
for (unsigned int jj = 0; jj < ii->second.size(); ++jj) {
vector< double > coords = Field< vector< double > >::get( src_[ii->second[jj]], fieldName.c_str() );
if ( coords.size() == 11 ) { // For SpineMesh
for ( unsigned int kk = 0; kk < 6; ++kk) {
buffer[jj * 7 + kk] = coords[kk];
}
buffer[jj * 7 + 6] = coords[9]; // head Dia
} else if ( coords.size() == 4 ) { // for EndoMesh
for ( unsigned int kk = 0; kk < 3; ++kk) {
buffer[jj * 7 + kk] = coords[kk];
buffer[jj * 7 + kk+3] = coords[kk];
}
buffer[jj * 7 + 6] = coords[3];
} else if ( coords.size() >= 7 ) { // For NeuroMesh
for ( unsigned int kk = 0; kk < 7; ++kk) {
buffer[jj * 7 + kk] = coords[kk];
}
}
}
} else { // Want to check for things like Ca in an elec compt...
for (unsigned int jj = 0; jj < ii->second.size(); ++jj) {
for ( unsigned int kk = 0; kk < 7; ++kk) {
buffer[jj * 7 + kk] = 0.0;
}
}
}
hsize_t dims[2];
dims[0] = ii->second.size();
dims[1] = 7;
hid_t memspace = H5Screate_simple(2, dims, NULL);
hid_t dataspace = H5Screate_simple(2, dims, NULL);
hid_t dataset = H5Dcreate2(container, fieldName.c_str(), H5T_NATIVE_DOUBLE, dataspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
hid_t filespace = H5Dget_space(dataset);
herr_t status = H5Dwrite(dataset, H5T_NATIVE_DOUBLE, memspace, filespace, H5P_DEFAULT, buffer);
if ( status < 0 ) {
cout << "Error: Failed to write coords as static entry\n";
}
}
}

void NSDFWriter::writeModelFiles()
{
for ( const string& fName : modelFileNames_ ) {
// string fPath = MODELFILEPATH + string("/") + fName;
string fPath = MODELFILEPATH;
std::ifstream f( fName );
auto ss = ostringstream{};
if ( f.is_open() ) {
ss << f.rdbuf();
hid_t fGroup = require_group(filehandle_, fPath);
writeScalarAttr<string>(fGroup, fName, ss.str());
} else {
cout << "Warning: NSDFWriter::writeModelFiles Could not open file '" << fName << "'/n";
}
}
}

void NSDFWriter::writeModelTree()
{
if (modelRoot_ == "")
return;
vector< string > tokens;
ObjId mRoot(modelRoot_);
string rootPath = MODELTREEPATH + string("/") + mRoot.element()->getName();
Expand Down
Loading