/******************************************************* * * DESCRIPTION: Bond Graph components classes * * AUTHOR: Mariana C. D'Abreu * * EMAIL: mdabreu@dc.uba.ar * ********************************************************/ #include "bgcomps.h" //****************************************************** // // Class BGEdgeData // //****************************************************** /******************************************************************* * Function Name: *******************************************************************/ BGEdgeData &BGEdgeData::operator == ( const BGEdgeData &data ) { id = data.id; powerDirDest = data.powerDirDest; causalityDest = data.causalityDest; return *this; } //****************************************************** // // Class BGComp // //****************************************************** /******************************************************************* * Function Name: *******************************************************************/ BGComp::BGComp( const Id &id ) { this->id = id; causalityType = VarCausality; allowedCausality = Any; powerDir = NullP; lastBondAssigned = 1; } /******************************************************************* * Function Name: *******************************************************************/ BGComp::BGComp( const Id &id, const CausalityType &causalityType ) { this->id = id; this->causalityType = causalityType; this->allowedCausality = Any; this->powerDir = NullP; lastBondAssigned = 1; } /******************************************************************* * Function Name: *******************************************************************/ BGComp::BGComp( const Id &id, const CausalityType &causalityType, const Causality &allowedCaus, const PowerDir &powerDir ) { this->id = id; this->causalityType = causalityType; this->allowedCausality = allowedCaus; this->powerDir = powerDir; lastBondAssigned = 1; } /******************************************************************* * Function Name: *******************************************************************/ BGComp &BGComp::operator = ( const BGComp &comp ) { this->id = comp.id; this->causalityType = comp.causalityType; this->allowedCausality = comp.allowedCausality; this->powerDir = comp.powerDir; this->lastBondAssigned = comp.lastBondAssigned; return *this; } int BGSerialJunction::count = 0; int BGParallelJunction::count = 0; int BGEdgeData::count = 0; //****************************************************** // // Class BGCapacitor // //****************************************************** /******************************************************************* * Function Name: *******************************************************************/ string BGCapacitor::getVarsAsString() const { string vars; vars = BGComp::getVarsAsString(); vars += "C : " + Value2StrReal( C ); vars += "\ninitialLoad : " + Value2StrReal( initialLoad ); return vars; } //****************************************************** // // Class BGInductor // //****************************************************** /******************************************************************* * Function Name: *******************************************************************/ string BGInductor::getVarsAsString() const { string vars; vars = BGComp::getVarsAsString(); vars += "I : " + Value2StrReal( I ); vars += "\ninitialLoad : " + Value2StrReal( initialLoad ); return vars; } //****************************************************** // // Class BGSourceEffort // //****************************************************** /******************************************************************* * Function Name: *******************************************************************/ string BGSourceEffort::getVarsAsString() const { string aret; aret = string( "signal : " ) + signal->name() + "\n"; aret += string( "offset : " ) + signal->getOffset() + "\n"; aret += string( "startTime : " ) + signal->getStartTime(); for( int i=1; i <= signal->paramCount(); i++ ) { aret += "\n" + signal->paramName( i ) + " : " + signal->paramValue( i ); } return aret; } //****************************************************** // // Class BGSourceFlow // //****************************************************** /******************************************************************* * Function Name: *******************************************************************/ string BGSourceFlow::getVarsAsString() const { string aret; aret = string( "signal : " ) + signal->name() + "\n"; aret += string( "offset : " ) + signal->getOffset() + "\n"; aret += string( "startTime : " ) + signal->getStartTime(); for( int i=1; i <= signal->paramCount(); i++ ) { aret += "\n" + signal->paramName( i ) + " : " + signal->paramValue( i ); } return aret; } //****************************************************** // // Class BGSerialJunction // //****************************************************** /******************************************************************* * Function Name: *******************************************************************/ void BGSerialJunction::setPowerDirToEdge( BGEdgeData &edge, const BGComp &comp ) const { if ( comp.isJunction() ) { if ( edge.getId() == NEGATIVE_ID ) edge.setPowerDirDest( comp.getId() ); else edge.setPowerDirDest( id ); } else if ( comp.className() == "BGTransformer" || comp.className() == "BGGyrator" ) edge.setPowerDirDest( comp.getId() ); else comp.setPowerDirToEdge( edge, *this ); } /******************************************************************* * Function Name: *******************************************************************/ int BGSerialJunction::generateBondId( const BGEdgeData & edge ) { int aret; // para el unico flow de entrada uso el id 1 if ( !edge.isCausalityDest( id ) ) { aret = 1; } else { aret = lastBondAssigned; lastBondAssigned++; } return aret; } //****************************************************** // // Class BGParallelJunction // //****************************************************** /******************************************************************* * Function Name: *******************************************************************/ void BGParallelJunction::setPowerDirToEdge( BGEdgeData &edge, const BGComp &comp ) const { if ( comp.isJunction() ) { if ( edge.getId() == POSITIVE_ID ) edge.setPowerDirDest( comp.getId() ); else edge.setPowerDirDest( id ); } else if ( comp.className() == "BGTransformer" || comp.className() == "BGGyrator" ) edge.setPowerDirDest( comp.getId() ); else comp.setPowerDirToEdge( edge, *this ); } /******************************************************************* * Function Name: *******************************************************************/ int BGParallelJunction::generateBondId( const BGEdgeData & edge ) { int aret; // para el unico effort de entrada uso el id 1 if ( edge.isCausalityDest( id ) ) { aret = 1; } else { aret = lastBondAssigned; lastBondAssigned++; } return aret; }