/******************************************************* * * DESCRIPTION: QBG Gyrator class (effort input) * * AUTHOR: Mariana C. D'Abreu * * EMAIL: mdabreu@dc.uba.ar * ********************************************************/ #include "qbg_gyrator_ei.h" #include "ini.h" #include "message.h" #include "mainsimu.h" #include "defaults.h" const RealValue QBGGyratorEffortIn::DefaultGyrationConductance = 1; /******************************************************************* * Function Name: QBGGyratorEffortIn * Description: constructor ********************************************************************/ QBGGyratorEffortIn::QBGGyratorEffortIn( const string &name ) : Atomic( name ) , e1p( addInputPort( "e1p" ) ) , e2p( addInputPort( "e2p" ) ) , f1p( addOutputPort( "f1p" ) ) , f2p( addOutputPort( "f2p" ) ) { try { try { // gyration conductance string g( MainSimulator::Instance().getParameter( description(), "G" ) ); G = atof( g.data() ); } catch ( MException &exc ) { G = DefaultGyrationConductance; } if ( G == 0 ) { throw MException( "Invalid gyration conductance value : " + Value2StrReal( G ) ); } // out file try { outFileName = MainSimulator::Instance().getParameter( description(), "outputFile" ); } catch ( MException &e ) { outFileName = DEFAULT_QBG_OUTFILENAME; } } catch ( MException &e ) { e.print( cerr ); MTHROW( e ) ; } } /******************************************************************* * Function Name: ~QBGGyratorEffortIn * Destructor ********************************************************************/ QBGGyratorEffortIn::~QBGGyratorEffortIn() { outFile.close(); } /******************************************************************* * Function Name: initFunction ********************************************************************/ Model &QBGGyratorEffortIn::initFunction() { e1 = e2 = 0; f1 = f2 = 0; // out file outFile.open( outFileName.c_str() ); outFile << "\nTime,Flow1, Effort1, Flow2, Effort2"; passivate(); return *this ; } /******************************************************************* * Function Name: externalFunction ********************************************************************/ Model &QBGGyratorEffortIn::externalFunction( const ExternalMessage &msg ) { RealValue value = msg.value(); if ( msg.port() == e1p ) { e1 = value; } else if( msg.port() == e2p ) { e2 = value; } calculateValues(); holdIn( active, Time::Zero ); return *this; } /******************************************************************* * Function Name: internalFunction ********************************************************************/ Model &QBGGyratorEffortIn::internalFunction( const InternalMessage & ) { passivate(); return *this ; } /******************************************************************* * Function Name: outputFunction ********************************************************************/ Model &QBGGyratorEffortIn::outputFunction( const InternalMessage &msg ) { sendOutput( msg.time(), f1p, f1 ); sendOutput( msg.time(), f2p, f2 ); outFile << "\n" << msg.time().asMsecs() << "," << f1 << "," << e1 << "," << f2 << "," << e2; return *this ; } /******************************************************************* * Function Name: calculateValues ********************************************************************/ QBGGyratorEffortIn &QBGGyratorEffortIn::calculateValues() { MASSERT( G != 0 ); f1 = G * e2; f2 = -1 * G * e1; return *this; }