/******************************************************* * * DESCRIPTION: QBG Gyrator class (flow input) * * AUTHOR: Mariana C. D'Abreu * * EMAIL: mdabreu@dc.uba.ar * ********************************************************/ #include "qbg_gyrator_fi.h" #include "ini.h" #include "message.h" #include "mainsimu.h" #include "defaults.h" const RealValue QBGGyratorFlowIn::DefaultGyrationConductance = 1; /******************************************************************* * Function Name: QBGGyratorFlowIn * Description: constructor ********************************************************************/ QBGGyratorFlowIn::QBGGyratorFlowIn( const string &name ) : Atomic( name ) , f1p( addInputPort( "f1p" ) ) , f2p( addInputPort( "f2p" ) ) , e1p( addOutputPort( "e1p" ) ) , e2p( addOutputPort( "e2p" ) ) { 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: ~QBGGyratorFlowIn * Destructor ********************************************************************/ QBGGyratorFlowIn::~QBGGyratorFlowIn() { outFile.close(); } /******************************************************************* * Function Name: initFunction ********************************************************************/ Model &QBGGyratorFlowIn::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 &QBGGyratorFlowIn::externalFunction( const ExternalMessage &msg ) { RealValue value = msg.value(); if ( msg.port() == f1p ) { f1 = value; } else if( msg.port() == f2p ) { f2 = value; } calculateValues(); holdIn( active, Time::Zero ); return *this; } /******************************************************************* * Function Name: internalFunction ********************************************************************/ Model &QBGGyratorFlowIn::internalFunction( const InternalMessage & ) { passivate(); return *this ; } /******************************************************************* * Function Name: outputFunction ********************************************************************/ Model &QBGGyratorFlowIn::outputFunction( const InternalMessage &msg ) { sendOutput( msg.time(), e1p, e1 ); sendOutput( msg.time(), e2p, e2 ); outFile << "\n" << msg.time() << "," << f1 << "," << e1 << "," << f2 << "," << e2; return *this ; } /******************************************************************* * Function Name: calculateValues ********************************************************************/ QBGGyratorFlowIn &QBGGyratorFlowIn::calculateValues() { MASSERT( G != 0 ); // f1 = G * e2; // f2 = -G * e1; e2 = f1 / G; e1 = f2 / G * -1; return *this; }