MOOSE - Multiscale Object Oriented Simulation Environment
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
SaveModels.cpp File Reference
#include <fstream>
#include "header.h"
#include "Shell.h"
+ Include dependency graph for SaveModels.cpp:

Go to the source code of this file.

Functions

void writeCspace (Id model, const string &fname)
 
void writeKkit (Id model, const string &fname)
 

Function Documentation

void writeCspace ( Id  model,
const string &  fname 
)
void writeKkit ( Id  model,
const string &  fname 
)

Definition at line 525 of file WriteKkit.cpp.

References estimateDefaultVol(), estimateSimTimes(), Field< A >::get(), Id::path(), path, storeEnzMsgs(), storeFunctionMsgs(), storePlotMsgs(), storeReacMsgs(), wildcardFind(), writeEnz(), writeFooter(), writeGroup(), writeGui(), writeHeader(), writeMsgs(), writePlot(), writePool(), and writeReac().

Referenced by Shell::doSaveModel(), and testWriteKkit().

526 {
527  ofstream fout( fname.c_str(), ios::out );
528  vector< ObjId > chemCompt;
529  vector< string > msgs;
530  double simDt;
531  double plotDt;
532 
533  double runTime = estimateSimTimes( simDt, plotDt );
534  double defaultVol = estimateDefaultVol( model );
535  writeHeader( fout, simDt, plotDt, runTime, defaultVol );
536  string bg = "cyan";
537  string fg = "black";
538  double x = 0;
539  double y = 0;
540 
541  map < double, pair<Id, int> > compt_vol;
542 
543  unsigned int num = wildcardFind( model.path() + "/##[ISA=ChemCompt]", chemCompt );
544  if ( num == 0 )
545  {
546  cout << "Warning: writeKkit:: No model found on " << model <<
547  endl;
548  return;
549  }
550  for ( vector< ObjId >::iterator itr = chemCompt.begin(); itr != chemCompt.end(); itr++)
551  {
552  vector < unsigned int>dims;
553  unsigned int dims_size;
554  dims_size = 1;
555  unsigned index = 0;
556  string comptPath = Field<string>::get(*itr,"path");
557  string comptname = Field<string>::get(*itr,"name");
558  if (comptname != "kinetics")
559  {
560  fout << "simundump group /kinetics/" << comptname << " 0 " <<
561  "blue" << " " << "green" << " x 0 0 \"\" defaultfile \\\n";
562  fout << " defaultfile.g 0 0 0 " << rand() % 10 + 1 << " " << rand() % 10 + 1 << " 0\n";
563  }
564  double size = Field<double>::get(ObjId(*itr,index),"Volume");
565  unsigned int ndim = Field<unsigned int>::get(ObjId(*itr,index),"NumDimensions");
566  ostringstream geometry;
567  int vecIndex = itr-chemCompt.begin();
568  if (vecIndex > 0)
569  geometry << "simundump geometry /kinetics" << "/geometry[" << vecIndex <<"] 0 " << size << " " << ndim << " sphere " <<" \"\" white black 0 0 0\n";
570  else
571  geometry << "simundump geometry /kinetics" << "/geometry 0 " << size << " " << ndim << " sphere " <<" \"\" white black 0 0 0\n";
572  fout << geometry.str();
573  compt_vol.insert(make_pair(size,make_pair(*itr,vecIndex)));
574  } // compartmentclose
575  writeGroup(fout, model);
576  map<double, pair<Id, int> >::iterator compt;
577  for (compt = compt_vol.begin(); compt != compt_vol.end(); compt++)
578  {
579  string comptPath = Field<string>::get(compt->second.first,"path");
580  // Species
581  vector< ObjId > Compt_spe;
582  wildcardFind(comptPath+"/##[ISA=PoolBase]",Compt_spe);
583  int species_size = 1;
584  string objname;
585  for (vector <ObjId> :: iterator itrp = Compt_spe.begin(); itrp != Compt_spe.end(); itrp++)
586  {
587  string path = Field <string> :: get (*itrp,"path");
588  Id enzPoolparent = Field <ObjId> :: get(*itrp,"parent");
589  string enzpoolClass = Field <string> :: get(enzPoolparent,"className");
590  if (enzpoolClass != "ZombieEnz" or enzpoolClass != "Enz")
591  {
592  Id annotaId( path+"/info");
593  if ( annotaId != Id() )
594  {
595  double x = Field <double> :: get(annotaId,"x");
596  double y = Field <double> :: get(annotaId,"y");
597  string fg = Field <string> :: get(annotaId,"textColor");
598  string bg = Field <string> :: get(annotaId,"color");
599  writePool(fout, *itrp,bg,fg,x,y,compt->second.first,compt->second.second);
600  }
601  }
602  } //species is closed
603  vector< ObjId > Compt_Func;
604  wildcardFind(comptPath+"/##[ISA=Function]",Compt_Func);
605  for (vector <ObjId> :: iterator itrF= Compt_Func.begin(); itrF != Compt_Func.end(); itrF++)
606  {
607  storeFunctionMsgs( *itrF, msgs,compt_vol);
608  }
609  // Reaction
610  vector< ObjId > Compt_Reac;
611  wildcardFind(comptPath+"/##[ISA=ReacBase]",Compt_Reac);
612  for (vector <ObjId> :: iterator itrR= Compt_Reac.begin(); itrR != Compt_Reac.end(); itrR++)
613  {
614  string path = Field<string> :: get(*itrR,"path");
615  Id annotaId( path+"/info");
616  string noteClass = Field<string> :: get(annotaId,"className");
617  string notes;
618  double x = Field <double> :: get(annotaId,"x");
619  double y = Field <double> :: get(annotaId,"y");
620  string fg = Field <string> :: get(annotaId,"textColor");
621  string bg = Field <string> :: get(annotaId,"color");
622  writeReac( fout, *itrR, bg, fg, x, y, compt->second.first);
623  storeReacMsgs( *itrR, msgs, compt->second.first );
624  }// reaction
625  vector< ObjId > Compt_Enz;
626  wildcardFind(comptPath+"/##[ISA=EnzBase]",Compt_Enz);
627  for (vector <ObjId> :: iterator itrE= Compt_Enz.begin(); itrE != Compt_Enz.end(); itrE++)
628  {
629  string path = Field<string> :: get(*itrE,"path");
630  Id annotaId( path+"/info");
631  string noteClass = Field<string> :: get(annotaId,"className");
632  string notes;
633  double x = Field <double> :: get(annotaId,"x");
634  double y = Field <double> :: get(annotaId,"y");
635  string fg = Field <string> :: get(annotaId,"textColor");
636  string bg = Field <string> :: get(annotaId,"color");
637  writeEnz( fout, *itrE, bg, fg, x, y, compt->second.first);
638  storeEnzMsgs( *itrE, msgs, compt->second.first);
639  }// reaction
640 
641  } //compatment loop
642  writeGui ( fout);
643 
644  /* Table */
645 
646  vector< ObjId > table;
647  wildcardFind(model.path()+"/##[ISA=Table2]",table);
648  for (vector <ObjId> :: iterator itrT= table.begin(); itrT != table.end(); itrT++)
649  {
650  string tabPath = Field <string> :: get(*itrT,"path");
651  vector < Id > tabSrc = LookupField <string,vector < Id> >::get(*itrT, "neighbors","requestOut");
652  for (vector <Id> :: iterator tabItem= tabSrc.begin(); tabItem != tabSrc.end(); tabItem++)
653  {
654  string path = Field <string> :: get(*tabItem,"path");
655  double vol = Field < double> :: get (*tabItem,"Volume");
656  //Trying to find the compartment name via volume
657  //otherwise if we go via parent, sometimes it might
658  // get groupname so maped compartment Id and volume
659 
660  Id parentId = compt_vol[vol].first;
661  string parentname = Field <string> :: get(parentId,"name");
662  Id annotaId(path+"/info");
663  double x = Field <double> :: get(annotaId,"x");
664  double y = Field <double> :: get(annotaId,"y");
665  string bg = Field <string> :: get(annotaId,"textColor");
666  string fg = Field <string> :: get(annotaId,"color");
667  writePlot( fout, *itrT, bg, fg, x, y );
668  storePlotMsgs( *itrT, msgs,*tabItem,fg, parentId);
669 
670  }
671  }// table
672  writeMsgs( fout, msgs );
673  writeFooter( fout );
674 }
int wildcardFind(const string &path, vector< ObjId > &ret)
Definition: Wildcard.cpp:169
void writeMsgs(ofstream &fout, const vector< string > &msgs)
Definition: WriteKkit.cpp:500
double estimateSimTimes(double &simDt, double &plotDt)
Definition: WriteKkit.cpp:455
double estimateDefaultVol(Id model)
Returns an estimate of the default volume used in the model.
Definition: WriteKkit.cpp:477
void writeReac(ofstream &fout, Id id, string colour, string textcolour, double x, double y, Id comptid)
Definition: WriteKkit.cpp:188
std::string path(const std::string &separator="/") const
Definition: Id.cpp:76
Definition: SetGet.h:236
void writeGroup(ofstream &fout, Id model)
Definition: WriteKkit.cpp:506
Definition: ObjId.h:20
void writeFooter(ofstream &fout)
Definition: WriteKkit.cpp:317
void storeEnzMsgs(Id enz, vector< string > &msgs, Id comptid)
Definition: WriteKkit.cpp:381
void storeReacMsgs(Id reac, vector< string > &msgs, Id comptid)
Definition: WriteKkit.cpp:390
void writePool(ofstream &fout, Id id, string colour, string textcolour, double x, double y, Id comptid, int comptIndex)
Definition: WriteKkit.cpp:238
void storePlotMsgs(Id tab, vector< string > &msgs, Id pool, string bg, Id comptid)
Definition: WriteKkit.cpp:435
void writePlot(ofstream &fout, Id id, string colour, string textcolour, double x, double y)
Definition: WriteKkit.cpp:288
void writeEnz(ofstream &fout, Id id, string colour, string textcolour, double x, double y, Id comptid)
Definition: WriteKkit.cpp:131
void storeFunctionMsgs(Id func, vector< string > &msgs, map< double, pair< Id, int > > &compt_vol)
Definition: WriteKkit.cpp:413
Definition: Id.h:17
static A get(const ObjId &dest, const string &field)
Definition: SetGet.h:284
static char path[]
Definition: mfield.cpp:403
void writeGui(ofstream &fout)
Definition: WriteKkit.cpp:305
void writeHeader(ofstream &fout, double simdt, double plotdt, double maxtime, double defaultVol)
Definition: WriteKkit.cpp:28

+ Here is the call graph for this function:

+ Here is the caller graph for this function: