forked from OpenSees/OpenSees
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
42a05ef
commit 5b8b453
Showing
4 changed files
with
308 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,211 @@ | ||
/* ****************************************************************** ** | ||
** OpenSees - Open System for Earthquake Engineering Simulation ** | ||
** Pacific Earthquake Engineering Research Center ** | ||
** ** | ||
** ** | ||
** (C) Copyright 1999, The Regents of the University of California ** | ||
** All Rights Reserved. ** | ||
** ** | ||
** Commercial use of this program without express permission of the ** | ||
** University of California, Berkeley, is strictly prohibited. See ** | ||
** file 'COPYRIGHT' in main directory for information on usage and ** | ||
** redistribution, and for a DISCLAIMER OF ALL WARRANTIES. ** | ||
** ** | ||
** Developed by: ** | ||
** Frank McKenna (fmckenna@ce.berkeley.edu) ** | ||
** Gregory L. Fenves (fenves@ce.berkeley.edu) ** | ||
** Filip C. Filippou (filippou@ce.berkeley.edu) ** | ||
** ** | ||
** ****************************************************************** */ | ||
|
||
// Written: Andreas Schellenberg (andreas.schellenberg@gmail.com) | ||
// Created: 03/23 | ||
// Revision: A | ||
// | ||
// Description: This file contains the class definition for SocketSeries. | ||
// SocketSeries is a concrete class. A SocketSeries object provides | ||
// a time series by receiving factors through a socket. | ||
|
||
#include <SocketSeries.h> | ||
|
||
#include <Vector.h> | ||
#include <Channel.h> | ||
#include <TCP_Socket.h> | ||
#include <UDP_Socket.h> | ||
|
||
#include <elementAPI.h> | ||
|
||
|
||
void* OPS_SocketSeries() | ||
{ | ||
// pointer to the time series that will be returned | ||
TimeSeries* theSeries = 0; | ||
|
||
if (OPS_GetNumRemainingInputArgs() < 2) { | ||
opserr << "WARNING invalid number of arguments\n"; | ||
opserr << "Want: timeSeries Socket tag port " | ||
<< "<-udp> <-dt> <-factor f)\n"; | ||
return 0; | ||
} | ||
|
||
// get tag | ||
int tag; | ||
int numdata = 1; | ||
if (OPS_GetIntInput(&numdata, &tag) != 0) { | ||
opserr << "WARNING invalid timeSeries Socket tag\n"; | ||
return 0; | ||
} | ||
|
||
// get the port | ||
int ipPort; | ||
if (OPS_GetIntInput(&numdata, &ipPort) != 0) { | ||
opserr << "WARNING invalid ipPort \n"; | ||
opserr << "timeSeries Socket series: " << tag << endln; | ||
return 0; | ||
} | ||
|
||
// optional parameters | ||
const char* type; | ||
bool udp = false; | ||
bool checkEndianness = false; | ||
double dt = 1.0; | ||
double cFactor = 1.0; | ||
while (OPS_GetNumRemainingInputArgs() > 0) { | ||
type = OPS_GetString(); | ||
// udp socket | ||
if (strcmp(type, "-udp") == 0 || | ||
strcmp(type, "-UDP") == 0) { | ||
udp = true; | ||
} | ||
// dt | ||
else if (strcmp(type, "-dt") == 0 || | ||
strcmp(type, "-dT") == 0) { | ||
if (OPS_GetDoubleInput(&numdata, &dt) < 0) { | ||
opserr << "WARNING: invalid -dt value\n"; | ||
opserr << "timeSeries Socket series: " << tag << endln; | ||
return 0; | ||
} | ||
} | ||
// factor | ||
else if (strcmp(type, "-factor") == 0) { | ||
if (OPS_GetDoubleInput(&numdata, &cFactor) < 0) { | ||
opserr << "WARNING: invalid -cFactor value\n"; | ||
opserr << "timeSeries Socket series: " << tag << endln; | ||
return 0; | ||
} | ||
} | ||
} | ||
|
||
// now create the time series | ||
theSeries = new SocketSeries(tag, (unsigned int)ipPort, udp, | ||
checkEndianness, dt, cFactor); | ||
if (theSeries == 0) { | ||
opserr << "WARNING ran out of memory creating time series\n"; | ||
opserr << "timeSeries Socket series: " << tag << endln; | ||
return 0; | ||
} | ||
|
||
return theSeries; | ||
} | ||
|
||
|
||
SocketSeries::SocketSeries(int tag, | ||
unsigned int port, bool udp, bool checkEndianness, | ||
double theTimeIncr, double theFactor) | ||
: TimeSeries(tag, TSERIES_TAG_SocketSeries), | ||
socketTimeIncr(theTimeIncr), cFactor(theFactor), | ||
recvSize(1), newFactor(1), theChannel(0), | ||
previousTime(0.0), previousFactor(0.0) | ||
{ | ||
// setup the connection | ||
if (udp) | ||
theChannel = new UDP_Socket(port, checkEndianness); | ||
else | ||
theChannel = new TCP_Socket(port, checkEndianness); | ||
|
||
if (theChannel != 0) { | ||
opserr << "\nChannel successfully created: " | ||
<< "Waiting for client to send time series values...\n"; | ||
} else { | ||
opserr << "SocketSeries::SocketSeries() " | ||
<< "- failed to create channel\n"; | ||
exit(-1); | ||
} | ||
if (theChannel->setUpConnection() != 0) { | ||
opserr << "SocketSeries::SocketSeries() " | ||
<< "- failed to setup connection\n"; | ||
delete theChannel; | ||
theChannel = 0; | ||
} | ||
} | ||
|
||
|
||
SocketSeries::SocketSeries() | ||
: TimeSeries(TSERIES_TAG_SocketSeries), | ||
socketTimeIncr(0.0), cFactor(1.0), | ||
recvSize(1), newFactor(1), theChannel(0), | ||
previousTime(0.0), previousFactor(0.0) | ||
{ | ||
// does nothing | ||
} | ||
|
||
|
||
SocketSeries::~SocketSeries() | ||
{ | ||
if (theChannel != 0) | ||
delete theChannel; | ||
} | ||
|
||
|
||
TimeSeries* SocketSeries::getCopy() | ||
{ | ||
return new SocketSeries(*this); | ||
} | ||
|
||
|
||
double SocketSeries::getFactor(double pseudoTime) | ||
{ | ||
double factor; | ||
|
||
// get new factor if time has advanced by >= dt | ||
if (pseudoTime >= previousTime + socketTimeIncr) { | ||
if (theChannel->recvVector(0, 0, newFactor) < 0) { | ||
opserr << "SocketSeries::getFactor() " | ||
<< "- failed to receive data\n"; | ||
return -1; | ||
} | ||
previousTime += socketTimeIncr; | ||
} | ||
// in case time is at zero get the first factor | ||
else if (pseudoTime == 0.0) { | ||
if (theChannel->recvVector(0, 0, newFactor) < 0) { | ||
opserr << "SocketSeries::getFactor() " | ||
<< "- failed to receive data\n"; | ||
return -1; | ||
} | ||
} | ||
|
||
factor = cFactor*newFactor(0); | ||
|
||
return factor; | ||
} | ||
|
||
|
||
int SocketSeries::sendSelf(int commitTag, Channel& theChannel) | ||
{ | ||
return -1; | ||
} | ||
|
||
|
||
int SocketSeries::recvSelf(int commitTag, Channel& theChannel, | ||
FEM_ObjectBroker& theBroker) | ||
{ | ||
return -1; | ||
} | ||
|
||
|
||
void SocketSeries::Print(OPS_Stream& s, int flag) | ||
{ | ||
s << "Socket Time Series" << endln; | ||
s << "\tFactor: " << cFactor << endln; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* ****************************************************************** ** | ||
** OpenSees - Open System for Earthquake Engineering Simulation ** | ||
** Pacific Earthquake Engineering Research Center ** | ||
** ** | ||
** ** | ||
** (C) Copyright 1999, The Regents of the University of California ** | ||
** All Rights Reserved. ** | ||
** ** | ||
** Commercial use of this program without express permission of the ** | ||
** University of California, Berkeley, is strictly prohibited. See ** | ||
** file 'COPYRIGHT' in main directory for information on usage and ** | ||
** redistribution, and for a DISCLAIMER OF ALL WARRANTIES. ** | ||
** ** | ||
** Developed by: ** | ||
** Frank McKenna (fmckenna@ce.berkeley.edu) ** | ||
** Gregory L. Fenves (fenves@ce.berkeley.edu) ** | ||
** Filip C. Filippou (filippou@ce.berkeley.edu) ** | ||
** ** | ||
** ****************************************************************** */ | ||
|
||
#ifndef SocketSeries_h | ||
#define SocketSeries_h | ||
|
||
// Written: Andreas Schellenberg (andreas.schellenberg@gmail.com) | ||
// Created: 03/23 | ||
// Revision: A | ||
// | ||
// Description: This file contains the class definition for SocketSeries. | ||
// SocketSeries is a concrete class. A SocketSeries object provides | ||
// a time series by receiving factors through a socket. | ||
|
||
#include <TimeSeries.h> | ||
#include <Vector.h> | ||
|
||
class Channel; | ||
|
||
|
||
class SocketSeries : public TimeSeries | ||
{ | ||
public: | ||
// constructors | ||
SocketSeries(int tag, | ||
unsigned int port, | ||
bool udp = false, | ||
bool checkEndianness = false, | ||
double socketTimeIncr = 1.0, | ||
double cFactor = 1.0); | ||
SocketSeries(); | ||
|
||
// destructor | ||
~SocketSeries(); | ||
|
||
TimeSeries* getCopy(); | ||
|
||
// method to get load factor | ||
double getFactor(double pseudoTime); | ||
|
||
// none of the following functions should be invoked on this type of object | ||
double getDuration() { return 0.0; } // dummy function | ||
double getPeakFactor() { return cFactor; } // dummy function | ||
double getTimeIncr(double pseudoTime) { return socketTimeIncr; } | ||
|
||
// methods for output | ||
int sendSelf(int commitTag, Channel& theChannel); | ||
int recvSelf(int commitTag, Channel& theChannel, | ||
FEM_ObjectBroker& theBroker); | ||
|
||
void Print(OPS_Stream& s, int flag = 0); | ||
|
||
protected: | ||
|
||
private: | ||
double cFactor; | ||
double socketTimeIncr; | ||
|
||
int recvSize; | ||
Vector newFactor; | ||
Channel* theChannel; | ||
double previousTime; | ||
double previousFactor; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters