本文整理汇总了C++中Time类的典型用法代码示例。如果您正苦于以下问题:C++ Time类的具体用法?C++ Time怎么用?C++ Time使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Time类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: Vector2i
void GameGraphics::updateWaterGraphics(Time elapsedTime)
{
WaterPoint* fromState = waterSourceSelector ? waterPoints1 : waterPoints2;
WaterPoint* toState = waterSourceSelector ? waterPoints2 : waterPoints1;
waterSourceSelector = !waterSourceSelector;
if (randomDisturbanceClock.getElapsedTime().asSeconds() > 0.05)
{
currentRandomWaterDisturbancePoint = Vector2i(rand() % RIPPLEMAP_WIDTH, rand() % RIPPLEMAP_HEIGHT);
randomDisturbanceClock.restart();
}
Vector2i raft1InRippleMap = (Vector2i)Vector2f(game->raft1.getPosition().x*RIPPLEMAP_WIDTH / game->map.getSize().x, game->raft1.getPosition().y*RIPPLEMAP_HEIGHT / game->map.getSize().y);
Vector2i raft2InRippleMap = (Vector2i)Vector2f(game->raft2.getPosition().x*RIPPLEMAP_WIDTH / game->map.getSize().x, game->raft2.getPosition().y*RIPPLEMAP_HEIGHT / game->map.getSize().y);
for (int y = 0; y < RIPPLEMAP_HEIGHT; y++)
{
for (int x = 0; x < RIPPLEMAP_WIDTH; x++)
{
int mapX = x*game->map.getSize().x / RIPPLEMAP_WIDTH;
int mapY = y*game->map.getSize().y / RIPPLEMAP_HEIGHT;
int index = y*RIPPLEMAP_WIDTH + x;
if (raft1InRippleMap == Vector2i(x, y) || raft2InRippleMap == Vector2i(x, y))
{
toState[index].height = -0.3f;
toState[index].velocity = 0.0;
}
else if (game->map.getTile(mapX, mapY)->type == TileType::Land)
{
toState[index].height = toState[index].velocity = 0;
}
else if(Vector2i(x,y)==currentRandomWaterDisturbancePoint)
{
toState[index].height = 0.4f;
toState[index].velocity = 0.0f;
}
else
{
float sum = 0;
int neighbourCount = 0;
for (int deltaY = -1; deltaY <= 1; deltaY++)
{
for (int deltaX = -1; deltaX <= 1; deltaX++)
{
int neighbourX = x + deltaX;
int neighbourY = y + deltaY;
int neighbour_mapPointX = neighbourX*game->map.getSize().x / RIPPLEMAP_WIDTH;
int neighbour_mapPointY = neighbourY*game->map.getSize().y / RIPPLEMAP_HEIGHT;
if (neighbourX < 0 || neighbourX >= RIPPLEMAP_WIDTH || neighbourY < 0 || neighbourY >= RIPPLEMAP_HEIGHT || (neighbourX == x && neighbourY == y)) continue;
sum += fromState[neighbourY * RIPPLEMAP_WIDTH + neighbourX].height;
neighbourCount++;
}
}
float average = sum / (float)neighbourCount;
float force = -450.0f*(fromState[index].height - average) - 0.13f*fromState[index].velocity;
toState[index].velocity = fromState[index].velocity + force*elapsedTime.asSeconds();
toState[index].height = fromState[index].height + toState[index].velocity*elapsedTime.asSeconds();
/*if (toState[index].height > 1) toState[index].height = 1;
if (toState[index].height<-1) toState[index].height = -1;*/
}
int max = 160;
int val = (int)(max / 2 + toState[index].height*max / 2);
if (val > max) val = max;
if (val < 0) val = 0;
waterImage.setPixel(x, y, Color((max - val) / 2, max - val, 255 - 150 * val / max, 255));
}
}
waterTexture.loadFromImage(waterImage);
waterSprite.setTexture(waterTexture);
}
开发者ID:nitral,项目名称:plAI-14,代码行数:74,代码来源:GameGraphics.cpp
示例2: assert
void
nest::poisson_generator_ps::event_hook( DSSpikeEvent& e )
{
// get port number
const port prt = e.get_port();
// we handle only one port here, get reference to vector elem
assert( 0 <= prt && static_cast< size_t >( prt ) < B_.next_spike_.size() );
// obtain rng
librandom::RngPtr rng = net_->get_rng( get_thread() );
// introduce nextspk as a shorthand
Buffers_::SpikeTime& nextspk = B_.next_spike_[ prt ];
if ( nextspk.first.is_neg_inf() )
{
// need to initialize relative to t_min_active_
// first spike is drawn from backward recurrence time to initialize the process in equilibrium.
// In the case of the Poisson process with dead time, this has two domains:
// one with uniform probability (t<dead_time) and one
// with exponential probability (t>=dead_time).
// First we draw a uniform number to choose the case according to the associated probability
// mass.
// If dead_time==0 we do not want to draw addtional random numbers (keeps old functionality).
double spike_offset = 0;
if ( P_.dead_time_ > 0 and rng->drand() < P_.dead_time_ * P_.rate_ / 1000.0 )
{
// uniform case: spike occurs with uniform probability in [0, dead_time].
spike_offset = rng->drand() * P_.dead_time_;
}
else
{
// exponential case: spike occurs with exponential probability in [dead_time, infinity]
spike_offset = V_.inv_rate_ms_ * V_.exp_dev_( rng ) + P_.dead_time_;
}
// spike_offset is now time from t_min_active_ til first spike.
// Split into stamp+offset, then add t_min_active.
nextspk.first = Time::ms_stamp( spike_offset );
nextspk.second = nextspk.first.get_ms() - spike_offset;
nextspk.first += V_.t_min_active_;
}
// as long as there are spikes in active period, emit and redraw
while ( nextspk.first <= V_.t_max_active_ )
{
// std::cerr << nextspk.first << '\t' << nextspk.second << '\n';
e.set_stamp( nextspk.first );
e.set_offset( nextspk.second );
e.get_receiver().handle( e );
// Draw time of next spike
// Time of spike relative to current nextspk.first stamp
const double new_offset =
-nextspk.second + V_.inv_rate_ms_ * V_.exp_dev_( rng ) + P_.dead_time_;
if ( new_offset < 0 ) // still in same stamp
nextspk.second = -new_offset; // stamps always 0 < stamp <= h
else
{
// split into stamp and offset, then add to old stamp
const Time delta_stamp = Time::ms_stamp( new_offset );
nextspk.first += delta_stamp;
nextspk.second = delta_stamp.get_ms() - new_offset;
}
}
// std::cerr << "********************************\n";
}
开发者ID:JanneM,项目名称:nest-simulator,代码行数:71,代码来源:poisson_generator_ps.cpp
示例3: NS_LOG_DEBUG
void
MinstrelWifiManager::UpdateStats (MinstrelWifiRemoteStation *station)
{
if (Simulator::Now () < station->m_nextStatsUpdate)
{
return;
}
if (!station->m_initialized)
{
return;
}
NS_LOG_DEBUG ("Updating stats=" << this);
station->m_nextStatsUpdate = Simulator::Now () + m_updateStats;
Time txTime;
uint32_t tempProb;
for (uint32_t i = 0; i < m_nsupported; i++)
{
/// calculate the perfect tx time for this rate
txTime = m_minstrelTable[i].perfectTxTime;
/// just for initialization
if (txTime.GetMicroSeconds () == 0)
{
txTime = Seconds (1);
}
NS_LOG_DEBUG ("m_txrate=" << station->m_txrate <<
"\t attempt=" << m_minstrelTable[i].numRateAttempt <<
"\t success=" << m_minstrelTable[i].numRateSuccess);
/// if we've attempted something
if (m_minstrelTable[i].numRateAttempt)
{
/**
* calculate the probability of success
* assume probability scales from 0 to 18000
*/
tempProb = (m_minstrelTable[i].numRateSuccess * 18000) / m_minstrelTable[i].numRateAttempt;
/// bookeeping
m_minstrelTable[i].successHist += m_minstrelTable[i].numRateSuccess;
m_minstrelTable[i].attemptHist += m_minstrelTable[i].numRateAttempt;
m_minstrelTable[i].prob = tempProb;
/// ewma probability (cast for gcc 3.4 compatibility)
tempProb = static_cast<uint32_t> (((tempProb * (100 - m_ewmaLevel)) + (m_minstrelTable[i].ewmaProb * m_ewmaLevel) ) / 100);
m_minstrelTable[i].ewmaProb = tempProb;
/// calculating throughput
m_minstrelTable[i].throughput = tempProb * (1000000 / txTime.GetMicroSeconds ());
}
/// bookeeping
m_minstrelTable[i].prevNumRateAttempt = m_minstrelTable[i].numRateAttempt;
m_minstrelTable[i].prevNumRateSuccess = m_minstrelTable[i].numRateSuccess;
m_minstrelTable[i].numRateSuccess = 0;
m_minstrelTable[i].numRateAttempt = 0;
/// Sample less often below 10% and above 95% of success
if ((m_minstrelTable[i].ewmaProb > 17100) || (m_minstrelTable[i].ewmaProb < 1800))
{
/**
* retry count denotes the number of retries permitted for each rate
* # retry_count/2
*/
m_minstrelTable[i].adjustedRetryCount = m_minstrelTable[i].retryCount >> 1;
if (m_minstrelTable[i].adjustedRetryCount > 2)
{
m_minstrelTable[i].adjustedRetryCount = 2;
}
}
else
{
开发者ID:shuiziliuBUPT,项目名称:HelloWorld,代码行数:80,代码来源:minstrel-wifi-manager.cpp
示例4: setPlayingOffset
void Sound::setPlayingOffset(Time timeOffset)
{
alCheck(alSourcef(m_source, AL_SEC_OFFSET, timeOffset.asSeconds()));
}
开发者ID:AdamFlores,项目名称:SFML,代码行数:4,代码来源:Sound.cpp
示例5: main
int
main(int argc, char* argv[]){
try{
if (argc==1) usage();
Options O = parse_options(&argc, &argv, options, 3);
if (O.exists("help")) { usage(); return 1;}
if (argc<2) {usage(); return 1;}
const char * ifile = argv[0];
const char * ofile = argv[1];
// create map
vmap::world W=vmap::read(ifile);
if (W.size()==0) throw Err() << "Error: empty map\n";
// set geometry if no --wgs_geom, --wgs_brd, --geom,
// --nom, --google option exists
if (O.exists("nobrd")) W.brd.clear();
if (!O.exists("geom") && !O.exists("wgs_geom") &&
!O.exists("nom") && !O.exists("google") &&
!O.exists("wgs_brd")){
if (W.brd.size()>2) O.put("wgs_brd", W.brd);
else O.put("wgs_geom", W.range());
}
if (!O.exists("rscale")) O.put("rscale", W.rscale);
g_map ref = mk_ref(O);
ref.comm=W.name;
// process other options
double dpi=O.get<double>("dpi", 300);
// set margins
int tm=0, bm=0, lm=0, rm=0;
if (O.get<int>("draw_name", 0) ||
O.get<int>("draw_date", 0) ||
(O.get<string>("draw_text") != "")) {
tm=dpi/3;
bm=lm=rm=dpi/6;
}
int grid_labels = O.get<int>("grid_labels", 0);
if (grid_labels){
bm+=dpi/6;
tm+=dpi/6;
rm+=dpi/6;
lm+=dpi/6;
}
// modify vmap
vmap::join_labels(W);
vmap::move_pics(W);
// calculate picture range, create Image
dRect rng = ref.border.range();
rng.x = rng.y = 0;
rng.w+=lm+rm; if (rng.w<0) rng.w=0;
rng.h+=tm+bm; if (rng.h<0) rng.h=0;
ref+=dPoint(lm,tm);
cerr
<< " scale = 1:" << int(W.rscale) << "\n"
<< " dpi = " << dpi << "\n"
<< " image = " << int(rng.w) << "x" << int(rng.h)<< "\n";
iImage img(rng.w, rng.h);
convs::map2wgs cnv(ref);
if (W.size() == 0) cerr << "warning: no objects\n";
GObjVMAP R(&W, O);
R.set_ref(ref);
R.draw(img, dPoint(0,0));
CairoWrapper cr(img);
if (O.get<int>("draw_name", 0))
cr->render_text(W.name.c_str(), dPoint(dpi/5,dpi/15), 0, 0, 18, 14, dpi, 0, 2);
if (O.get<int>("draw_date", 0)){
Time t; t.set_current();
cr->render_text(t.date_str().c_str(), dPoint(dpi/30,dpi), -M_PI/2, 0, 18, 10, dpi, 2, 2);
}
if (O.get<string>("draw_text") != ""){
cr->render_text(O.get<string>("draw_text").c_str(), dPoint(dpi/5,rng.h-dpi/30), 0, 0, 18, 10, dpi, 0, 0);
}
//*******************************
image_r::save(img, ofile);
string map = O.get<string>("map");
if (map!=""){
g_map M = ref;
M.file = ofile;
if (W.brd.size()>2) M.border=cnv.line_bck(W.brd);
M.border.push_back(*M.border.begin());
M.border=generalize(M.border,1,-1); // 1pt accuracy
M.border.resize(M.border.size()-1);
//.........这里部分代码省略.........
开发者ID:ushakov,项目名称:mapsoft,代码行数:101,代码来源:vmap_render.cpp
示例6: mesh_
// Construct from components
dsmcGeneralBoundary::dsmcGeneralBoundary
(
Time& t,
const polyMesh& mesh,
dsmcCloud& cloud,
const dictionary& dict
)
:
mesh_(refCast<const fvMesh>(mesh)),
cloud_(cloud),
boundaryDict_(dict.subDict("generalBoundaryProperties")),
// timeDict_(boundaryDict_.subDict("timeProperties")),
// time_(t, timeDict_),
patchName_(boundaryDict_.lookup("patchName")),
patchId_(0),
faces_(),
nFaces_(0),
patchSurfaceArea_(0.0),
cells_(),
density_(0.0),
velocity_(vector::zero),
temperature_(0.0),
densities_(),
velocities_(),
temperatures_(),
writeInTimeDir_(true),
writeInCase_(true)
{
//- confirm that the patch exists on the mesh
patchId_ = mesh_.boundaryMesh().findPatchID(patchName_);
if(patchId_ == -1)
{
FatalErrorIn("atomisticPatchBoundary::atomisticPatchBoundary()")
<< "Cannot find patch: " << patchName_ << nl << "in: "
<< t.system()/"boundariesDict"
<< exit(FatalError);
}
const polyPatch& patch = mesh.boundaryMesh()[patchId_];
// Pout << "patch name: " << patchName_ << ", patch size: " << patch.size() << endl;
//- initialise data members
faces_.setSize(patch.size());
cells_.setSize(patch.size());
//- loop through all faces and set the boundary cells
//- no conflict with parallelisation because the faces are unique
for(label i = 0; i < patch.size(); i++)
{
label globalFaceI = patch.start() + i;
faces_[i] = globalFaceI;
cells_[i] = patch.faceCells()[i];
nFaces_++;
patchSurfaceArea_ += mag(mesh_.faceAreas()[globalFaceI]);
}
if(Pstream::parRun())
{
reduce(patchSurfaceArea_, sumOp<scalar>());
}
}
开发者ID:BijanZarif,项目名称:OpenFOAM-2.4.0-MNF,代码行数:67,代码来源:dsmcGeneralBoundary.C
示例7: M
SparseMatrix3D *Application::transform(int xID,int yID)
{
bool useDelta=false;//true;
cout<<"transforming "<<taxonName[xID]<<":"<<taxonName[yID]<<endl;
Time timer;
timer.startCounting();
PhylogenyNode *x=nodes[xID], *y=nodes[yID];
if(x->getNodeType()!=LEAF_NODE || y->getNodeType()!=LEAF_NODE) return NULL;
int Lx=lengths[xID], Ly=lengths[yID];
Array3D<float> M(Lx+1,Ly+1,3);
M.setAllTo(LOG_0);
// Match states:
for(int i=1 ; i<=Lx ; ++i) {
Array1D< Vector<float> > sums(Ly+1);
for(int zID=0 ; zID<numLeaves ; ++zID) {
PhylogenyNode *z=nodes[zID];
int Lz=lengths[zID];
float delta=useDelta ?
tree->getSpannedDistance(x->getID(),y->getID(),z->getID()) : 0;
SparseMatrix3D &Mxz=*matrices[xID][zID], &Mzy=*matrices[zID][yID];
EntryList &row=Mxz(i,PHMM_MATCH);
EntryList::iterator cur=row.begin(), end=row.end();
for(; cur!=end ; ++cur) {
Entry &e1=*cur;
int k=e1.y;
float v1=e1.value;
EntryList &col=Mzy(k,PHMM_MATCH);
EntryList::iterator cur=col.begin(), end=col.end();
for(; cur!=end ; ++cur) {
Entry &e2=*cur;
int j=e2.y;
float v2=e2.value;
float product=v1+v2-delta;
sums[j].push_back(product);
}
}
}
for(int j=0 ; j<=Ly ; ++j)
M[i][j][PHMM_MATCH]=sumLogProbs(sums[j])-numLeaves;
}
//cout<<M<<endl;
// Insertion states:
for(int i=0 ; i<=Lx ; ++i) {
Array1D< Vector<float> > sums(Ly+1);
for(int zID=0 ; zID<numLeaves ; ++zID) {
PhylogenyNode *z=nodes[zID];
int Lz=lengths[zID];
float delta=useDelta ?
tree->getSpannedDistance(x->getID(),y->getID(),z->getID()) : 0;
SparseMatrix3D &Mxz=*matrices[xID][zID], &Mzy=*matrices[zID][yID];
EntryList &row=Mxz(i,PHMM_INSERT);
EntryList::iterator cur=row.begin(), end=row.end();
for(; cur!=end ; ++cur) {
Entry &e1=*cur;
int k=e1.y;
float v1=e1.value;
EntryList &col=Mzy(k,PHMM_MATCH);
EntryList::iterator cur=col.begin(), end=col.end();
for(; cur!=end ; ++cur) {
Entry &e2=*cur;
int j=e2.y;
float v2=e2.value;
float product=v1+v2-delta;
sums[j].push_back(product);
}
}
}
for(int j=0 ; j<=Ly ; ++j)
M[i][j][PHMM_INSERT]=sumLogProbs(sums[j])-numLeaves;
}
// Deletion states:
for(int i=0 ; i<=Lx ; ++i) {
Array1D< Vector<float> > sums(Ly+1);
for(int zID=0 ; zID<numLeaves ; ++zID) {
PhylogenyNode *z=nodes[zID];
int Lz=lengths[zID];
float delta=useDelta ?
tree->getSpannedDistance(x->getID(),y->getID(),z->getID()) : 0;
SparseMatrix3D &Mxz=*matrices[xID][zID], &Mzy=*matrices[zID][yID];
EntryList &row=Mxz(i,PHMM_MATCH);
EntryList::iterator cur=row.begin(), end=row.end();
for(; cur!=end ; ++cur) {
Entry &e1=*cur;
int k=e1.y;
float v1=e1.value;
EntryList &col=Mzy(k,PHMM_DELETE);
EntryList::iterator cur=col.begin(), end=col.end();
for(; cur!=end ; ++cur) {
Entry &e2=*cur;
int j=e2.y;
float v2=e2.value;
float product=v1+v2-delta;
sums[j].push_back(product);
}
}
}
for(int j=0 ; j<=Ly ; ++j)
//.........这里部分代码省略.........
开发者ID:bmajoros,项目名称:alignment,代码行数:101,代码来源:consistency.C
示例8:
friend bool operator==(const Time& lhs, const Time& rhs) { return lhs.value() == rhs.value(); }
开发者ID:kmurray,项目名称:esta,代码行数:1,代码来源:Time.hpp
示例9: WndProc
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc,hdcMem;
PAINTSTRUCT ps;
TCHAR buf[128];
//窗口的宽、高
static int cxClient,cyClient;
//显示器的宽和高
static int screenX,screenY;
//实例代号
static HINSTANCE hInstance;
//位图的相关句柄
static HBITMAP hOldmap,hBitmap1,hcloudBit,hcloudMakBit,hgameoverBit,hgameoverMask;
//位图的高和宽
static int cx,cy,cx1,cy1,cx2,cy2;
BITMAP bitmap;
int temp,temp1;
static boolean isPuase=false;
//两个变量来处理数字的变化
static int first=6,second=0;
static int count=60;
static boolean isStart=false,isEnd=false;
//画笔
static HPEN myPen;
//纪录跳的次数(最多可以连续3次)
static int jump_times=0;
switch (message)
{
//按键处理
case WM_KEYDOWN:
if (isStart)
{
hdc=GetDC(hwnd);
switch(wParam)
{
case VK_SPACE:
if (!isPuase)
{
GameManagement::pauseMyGame(hwnd);
isPuase=true;
}else{
myCurrentTime--;
GameManagement::startMyTimer(hwnd);
isPuase=false;
}
break;
case VK_LEFT:
marry.move(0);
marry.isMoved=true;
break;
case VK_RIGHT:
marry.move(2);
marry.isMoved=true;
break;
}
ReleaseDC(hwnd,hdc);
}
return 0;
case WM_KEYUP:
if (isStart)
{
switch(wParam)
{
case VK_LEFT:
case 0x61:
case 0x41:
//marry.isMoved=false;
marry.SetSpeed(0);
break;
/*case 0x77:
case 0x57:
//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:
示例10: Handle
void Airplane::Handle(ProcessEventArg arg) {
Time t = timer.GetElapsedTimeAndReset();
float dt = t.AsInt()/1000.0;
Matrix<3,3,float> rotM = box->GetRotationMatrix();
box->AddForce(rotM * Vector<3,float>(0,0,1*dt*trottle));
for (vector<Point*>::iterator itr = points.begin();
itr != points.end();
itr++) {
Point* p = *itr;
Vector<3,float> speedVec = box->GetSpeed();
float speed = speedVec.GetLength();
Vector<3,float> dragVec;
if (speed > 0.1)
dragVec = -speedVec/speed;
Vector<3,float> normal = Vector<3,float>(0,1,0);
Vector<3,float> liftVector = (dragVec % normal) % dragVec;
if (liftVector.IsZero())
return;
float liftLen = liftVector.GetLength();
liftVector.Normalize();
float dotP = dragVec * normal;
dotP = fmin(fmax(dotP, -1),1);
float attackAngel = asin(dotP);
float rho = 1.2f;
float area = 5*5;
float force = 0.5f * rho * speed * speed * area;
Vector<3,float> forceVec =
(liftVector * LiftCoefficient(attackAngel,0) +
dragVec * DragCoefficient(attackAngel,0)) * force;
//logger.info << forceVec << logger.end;
box->AddForce(rotM * forceVec, p->forceIdx );
}
//box->AddForce(Vector<3,float>(0,lift,0));
return;
// Matrix<3,3,float> rotM = box->GetRotationMatrix();
// //logger.info << speed << logger.end;
// //speed = rotM*speed;
// Quaternion<float> q = Quaternion<float>(rotM);
// Vector<3,float> angles = q.GetEulerAngles();
// float pitch = -angles[0];
// //logger.info << "pitch " << pitch << logger.end;
// float cl = 1;
// float lift = speedVec[2]*cl;
//logger.info << "cl " << cl << logger.end;
//logger.info << "lift " << lift << logger.end;
// Vector<3,float> old_pos;
// Quaternion<float> old_rot;
// node->GetAccumulatedTransformations(&old_pos, &old_rot);
// node->Move(0,0,0.01*dt*trottle);
// // calc lift
// Vector<3,float> angles = old_rot.GetEulerAngles();
// float pitch = -angles[0];
// float cl = pitch*0.08+0.5;
// float lift = speed.GetLengthSquared()*cl*.5*2000.0;
// node->Move(0,(lift-9.82)*dt,0);
// //logger.info << lift << logger.end;
// logger.info << "speed: " << speed.GetLengthSquared() <<
// " cl: " << cl <<
//.........这里部分代码省略.........
开发者ID:OpenEngineDK,项目名称:projects-FirstFlight,代码行数:101,代码来源:Airplane.cpp
示例11: Local
Time Time::Local()
{
Time ret;
ret.local_time();
return ret;
}
开发者ID:imace,项目名称:nnt,代码行数:6,代码来源:Time+NNT.cpp
示例12: rand
void Foam::calcTypes::randomise::calc
(
const argList& args,
const Time& runTime,
const fvMesh& mesh
)
{
const scalar pertMag = args.argRead<scalar>(2);
const word fieldName = args[3];
Random rand(1234567);
IOobject fieldHeader
(
fieldName,
runTime.timeName(),
mesh,
IOobject::MUST_READ
);
// Check field exists
if (fieldHeader.headerOk())
{
bool processed = false;
writeRandomField<vector>
(
fieldHeader,
pertMag,
rand,
mesh,
processed
);
writeRandomField<sphericalTensor>
(
fieldHeader,
pertMag,
rand,
mesh,
processed
);
writeRandomField<symmTensor>
(
fieldHeader,
pertMag,
rand,
mesh,
processed
);
writeRandomField<tensor>
(
fieldHeader,
pertMag,
rand,
mesh,
processed
);
if (!processed)
{
FatalError
<< "Unable to process " << fieldName << nl
<< "No call to randomise for fields of type "
<< fieldHeader.headerClassName() << nl << nl
<< exit(FatalError);
}
}
else
{
Info<< " No " << fieldName << endl;
}
}
开发者ID:0184561,项目名称:OpenFOAM-2.1.x,代码行数:72,代码来源:randomise.C
示例13: assert
void
aeif_cond_alpha_multisynapse::update( Time const& origin, const long_t from, const long_t to )
{
assert( to >= 0 && ( delay ) from < Scheduler::get_min_delay() );
assert( from < to );
assert( State_::V_M == 0 );
for ( long_t lag = from; lag < to; ++lag ) // proceed by stepsize B_.step_
{
double t = 0.0; // internal time of the integration period
if ( S_.r_ > 0 ) // decrease remaining refractory steps if non-zero
--S_.r_;
// numerical integration with adaptive step size control:
// ------------------------------------------------------
// The numerical integration of the model equations is performed by
// a Dormand-Prince method (5th order Runge-Kutta method with
// adaptive stepsize control) as desribed in William H. Press et
// al., “Adaptive Stepsize Control for Runge-Kutta”, Chapter 17.2
// in Numerical Recipes (3rd edition, 2007), 910-914. The solver
// itself performs only a single NUMERICAL integration step,
// starting from t and of size B_.IntegrationStep_ (bounded by
// step); the while-loop ensures integration over the whole
// SIMULATION step (0, step] of size B_.step_ if more than one
// integration step is needed due to a small integration stepsize;
// note that (t+IntegrationStep > step) leads to integration over
// (t, step] and afterwards setting t to step, but it does not
// enforce setting IntegrationStep to step-t; this is of advantage
// for a consistent and efficient integration across subsequent
// simulation intervals.
double_t& h = B_.IntegrationStep_; // numerical integration step
double_t& tend = B_.step_; // end of simulation step
const double_t& MAXERR = P_.MAXERR; // maximum error
const double_t& HMIN = P_.HMIN; // minimal integration step
double_t err;
double_t t_return = 0.0;
while ( t < B_.step_ ) // while not yet reached end of simulation step
{
bool done = false;
do
{
if ( tend - t < h ) // stop integration at end of simulation step
h = tend - t;
t_return = t + h; // update t
// k1 = f(told, y)
aeif_cond_alpha_multisynapse_dynamics( S_.y_, S_.k1 );
// k2 = f(told + h/5, y + h*k1 / 5)
for ( size_t i = 0; i < S_.y_.size(); ++i )
S_.yin[ i ] = S_.y_[ i ] + h * S_.k1[ i ] / 5.0;
aeif_cond_alpha_multisynapse_dynamics( S_.yin, S_.k2 );
// k3 = f(told + 3/10*h, y + 3/40*h*k1 + 9/40*h*k2)
for ( size_t i = 0; i < S_.y_.size(); ++i )
S_.yin[ i ] = S_.y_[ i ] + h * ( 3.0 / 40.0 * S_.k1[ i ] + 9.0 / 40.0 * S_.k2[ i ] );
aeif_cond_alpha_multisynapse_dynamics( S_.yin, S_.k3 );
// k4
for ( size_t i = 0; i < S_.y_.size(); ++i )
S_.yin[ i ] = S_.y_[ i ]
+ h * ( 44.0 / 45.0 * S_.k1[ i ] - 56.0 / 15.0 * S_.k2[ i ] + 32.0 / 9.0 * S_.k3[ i ] );
aeif_cond_alpha_multisynapse_dynamics( S_.yin, S_.k4 );
// k5
for ( size_t i = 0; i < S_.y_.size(); ++i )
S_.yin[ i ] = S_.y_[ i ]
+ h * ( 19372.0 / 6561.0 * S_.k1[ i ] - 25360.0 / 2187.0 * S_.k2[ i ]
+ 64448.0 / 6561.0 * S_.k3[ i ]
- 212.0 / 729.0 * S_.k4[ i ] );
aeif_cond_alpha_multisynapse_dynamics( S_.yin, S_.k5 );
// k6
for ( size_t i = 0; i < S_.y_.size(); ++i )
S_.yin[ i ] = S_.y_[ i ]
+ h * ( 9017.0 / 3168.0 * S_.k1[ i ] - 355.0 / 33.0 * S_.k2[ i ]
+ 46732.0 / 5247.0 * S_.k3[ i ]
+ 49.0 / 176.0 * S_.k4[ i ]
- 5103.0 / 18656.0 * S_.k5[ i ] );
aeif_cond_alpha_multisynapse_dynamics( S_.yin, S_.k6 );
// 5th order
for ( size_t i = 0; i < S_.y_.size(); ++i )
S_.ynew[ i ] = S_.y_[ i ]
+ h * ( 35.0 / 384.0 * S_.k1[ i ] + 500.0 / 1113.0 * S_.k3[ i ]
+ 125.0 / 192.0 * S_.k4[ i ]
- 2187.0 / 6784.0 * S_.k5[ i ]
+ 11.0 / 84.0 * S_.k6[ i ] );
aeif_cond_alpha_multisynapse_dynamics( S_.yin, S_.k7 );
// 4th order
for ( size_t i = 0; i < S_.y_.size(); ++i )
//.........这里部分代码省略.........
开发者ID:albada,项目名称:nest-simulator,代码行数:101,代码来源:aeif_cond_alpha_multisynapse.cpp
示例14: guardLocker
uint64 DamageOverTimeList::activateDots(CreatureObject* victim) {
uint64 states = 0;
uint64 statesBefore = 0;
Locker guardLocker(&guard);
for (int i = size() - 1; i >= 0 ; --i) {
Vector<DamageOverTime>* vector = &elementAt(i).getValue();
for (int j = vector->size() - 1; j >= 0 ; --j) {
DamageOverTime* dot = &vector->elementAt(j);
statesBefore |= dot->getType();
if (dot->nextTickPast()) {
//guard.unlock();
try {
dot->applyDot(victim);
} catch (...) {
//guard.wlock();
throw;
}
//guard.wlock();
}
Time nTime = dot->getNextTick();
if (nextTick.isPast() || (!dot->isPast() && (nTime.compareTo(nextTick) > 0)))
nextTick = nTime;
if (!dot->isPast()) {
states |= dot->getType();
} else {
if (vector->size() == 1) {
vector->remove(j);
remove(i);
} else {
vector->remove(j);
}
}
}
}
int statesRemoved = states ^ statesBefore;
if( statesRemoved & CreatureState::BLEEDING )
victim->clearState(CreatureState::BLEEDING);
if( statesRemoved & CreatureState::POISONED )
victim->clearState(CreatureState::POISONED);
if( statesRemoved & CreatureState::DISEASED )
victim->clearState(CreatureState::DISEASED);
if( statesRemoved & CreatureState::ONFIRE )
victim->clearState(CreatureState::ONFIRE);
if (nextTick.isPast()) {
dot = false;
removeAll();
states = 0;
}
return states;
}
开发者ID:Mesagoppinmypants,项目名称:mtgserver,代码行数:69,代码来源:DamageOverTimeList.cpp
示例15: waitTime
void VehicleControlDeviceImplementation::generateObject(CreatureObject* player) {
if (player->isDead() || player->isIncapacitated())
return;
if (!isASubChildOf(player))
return;
if (player->getParent() != NULL || player->isInCombat()) {
player->sendSystemMessage("@pet/pet_menu:cant_call_vehicle"); // You can only unpack vehicles while Outside and not in Combat.
return;
}
ManagedReference<TangibleObject*> controlledObject = this->controlledObject.get();
if (controlledObject == NULL)
return;
if (controlledObject->isInQuadTree())
return;
ManagedReference<TradeSession*> tradeContainer = player->getActiveSession(SessionFacadeType::TRADE).castTo<TradeSession*>();
if (tradeContainer != NULL) {
server->getZoneServer()->getPlayerManager()->handleAbortTradeMessage(player);
}
if(player->getPendingTask("call_mount") != NULL) {
StringIdChatParameter waitTime("pet/pet_menu", "call_delay_finish_vehicle");
Time nextExecution;
Core::getTaskManager()->getNextExecutionTime(player->getPendingTask("call_mount"), nextExecution);
int timeLeft = (nextExecution.getMiliTime() / 1000) - System::getTime();
waitTime.setDI(timeLeft);
player->sendSystemMessage(waitTime);
return;
}
ManagedReference<SceneObject*> datapad = player->getSlottedObject("datapad");
if (datapad == NULL)
return;
int currentlySpawned = 0;
for (int i = 0; i < datapad->getContainerObjectsSize(); ++i) {
ManagedReference<SceneObject*> object = datapad->getContainerObject(i);
if (object->isVehicleControlDevice()) {
VehicleControlDevice* device = cast<VehicleControlDevice*>( object.get());
ManagedReference<SceneObject*> vehicle = device->getControlledObject();
if (vehicle != NULL && vehicle->isInQuadTree()) {
if (++currentlySpawned > 2)
player->sendSystemMessage("@pet/pet_menu:has_max_vehicle");
return;
}
}
}
if(player->getCurrentCamp() == NULL && player->getCityRegion() == NULL) {
Reference<CallMountTask*> callMount = new CallMountTask(_this.getReferenceUnsafeStaticCast(), player, "call_mount");
StringIdChatParameter message("pet/pet_menu", "call_vehicle_delay");
message.setDI(15);
player->sendSystemMessage(message);
player->addPendingTask("call_mount", callMount, 15 * 1000);
if (vehicleControlObserver == NULL) {
vehicleControlObserver = new VehicleControlObserver(_this.getReferenceUnsafeStaticCast());
vehicleControlObserver->deploy();
}
player->registerObserver(ObserverEventType::STARTCOMBAT, vehicleControlObserver);
} else {
Locker clocker(controlledObject, player);
spawnObject(player);
}
}
开发者ID:Nifdoolb,项目名称:Server,代码行数:85,代码来源:VehicleControlDeviceImplementation.cpp
示例16: xferCopy
// Read mesh if available. Otherwise create empty mesh with same non-proc
// patches as proc0 mesh. Requires all processors to have all patches
// (and in same order).
autoPtr<fvMesh> createMesh
(
const Time& runTime,
const word& regionName,
const fileName& instDir,
const bool haveMesh
)
{
Pout<< "Create mesh for time = "
<< runTime.timeName() << nl << endl;
IOobject io
(
regionName,
instDir,
runTime,
IOobject::MUST_READ
);
if (!haveMesh)
{
// Create dummy mesh. Only used on procs that don't have mesh.
fvMesh dummyMesh
(
io,
xferCopy(pointField()),
xferCopy(faceList()),
xferCopy(labelList()),
xferCopy(labelList()),
false
);
Pout<< "Writing dummy mesh to " << dummyMesh.polyMesh::objectPath()
<< endl;
dummyMesh.write();
}
Pout<< "Reading mesh from " << io.objectPath() << endl;
autoPtr<fvMesh> meshPtr(new fvMesh(io));
fvMesh& mesh = meshPtr();
// Determine patches.
if (Pstream::master())
{
// Send patches
for
(
int slave=Pstream::firstSlave();
slave<=Pstream::lastSlave();
slave++
)
{
OPstream toSlave(Pstream::blocking, slave);
toSlave << mesh.boundaryMesh();
}
}
else
{
// Receive patches
IPstream fromMaster(Pstream::blocking, Pstream::masterNo());
PtrList<entry> patchEntries(fromMaster);
if (haveMesh)
{
// Check master names against mine
const polyBoundaryMesh& patches = mesh.boundaryMesh();
forAll(patchEntries, patchI)
{
const entry& e = patchEntries[patchI];
const word type(e.dict().lookup("type"));
const word& name = e.keyword();
if (type == processorPolyPatch::typeName)
{
break;
}
if (patchI >= patches.size())
{
FatalErrorIn
(
"createMesh(const Time&, const fileName&, const bool)"
) << "Non-processor patches not synchronised."
<< endl
<< "Processor " << Pstream::myProcNo()
<< " has only " << patches.size()
<< " patches, master has "
<< patchI
<< exit(FatalError);
}
if
(
type != patches[patchI].type()
|| name != patches[patchI].name()
//.........这里部分代码省略.........
开发者ID:Cescfangs,项目名称:OpenFOAM-1.7.x,代码行数:101,代码来源:redistributeMeshPar.C
示例17: assert
void
nest::aeif_cond_exp::update( const Time& origin,
const long from,
const long to )
{
assert(
to >= 0 && ( delay ) from < kernel().connection_manager.get_min_delay() );
assert( from < to );
assert( State_::V_M == 0 );
for ( long lag = from; lag < to; ++lag )
{
double t = 0.0;
if ( S_.r_ > 0 )
--S_.r_;
// numerical integration with adaptive step size control:
// ------------------------------------------------------
// gsl_odeiv_evolve_apply performs only a single numerical
// integration step, starting from t and bounded by step;
// the while-loop ensures integration over the whole simulation
// step (0, step] if more than one integration step is needed due
// to a small integration step size;
// note that (t+IntegrationStep > step) leads to integration over
// (t, step] and afterwards setting t to step, but it does not
// enforce setting IntegrationStep to step-t
while ( t < B_.step_ )
{
const int status = gsl_odeiv_evolve_apply( B_.e_,
B_.c_,
B_.s_,
&V_.sys_, // system of ODE
&t, // from t
B_.step_, // to t <= step
&B_.IntegrationStep_, // integration step size
S_.y_ ); // neuronal state
if ( status != GSL_SUCCESS )
throw GSLSolverFailure( get_name(), status );
// check for unreasonable values; we allow V_M to explode
if ( S_.y_[ State_::V_M ] < -1e3 || S_.y_[ State_::W ] < -1e6
|| S_.y_[ State_::W ] > 1e6 )
throw NumericalInstability( get_name() );
// spikes are handled inside the while-loop
// due to spike-driven adaptation
if ( S_.r_ > 0 )
S_.y_[ State_::V_M ] = P_.V_reset_;
else if ( S_.y_[ State_::V_M ] >= V_.V_peak )
{
S_.y_[ State_::V_M ] = P_.V_reset_;
S_.y_[ State_::W ] += P_.b; // spike-driven adaptation
S_.r_ = V_.refractory_counts_;
set_spiketime( Time::step( origin.get_steps() + lag + 1 ) );
SpikeEvent se;
kernel().event_delivery_manager.send( *this, se, lag );
}
}
S_.y_[ State_::G_EXC ] += B_.spike_exc_.get_value( lag );
S_.y_[ State_::G_INH ] += B_.spike_inh_.get_value( lag );
// set new input current
B_.I_stim_ = B_.currents_.get_value( lag );
// log state data
B_.logger_.record_data( origin.get_steps() + lag );
}
}
开发者ID:jschuecker,项目名称:nest-simulator,代码行数:71,代码来源:aeif_cond_exp.cpp
示例18: throw
void StaticPolicy::update () throw () {
try{
// aktive Spieler erfassen
unsigned int num_robots = REMBB.robot_state.size();
unsigned int num_active_players=0;
vector<bool> is_active_player (num_robots);
for (unsigned int i=0; i<num_robots; i++) {
// cerr << "i: " << i << " Robot" << REMBB.robot_state[i].id << ": " << REMBB.robot_state[i].playerrole << "/"
// << REMBB.robot_state[i].desired_playerrole << " active: " << (REMBB.robot_state[i].in_game && !REMBB.robot_state[i].comm_interrupted) << endl;
if (REMBB.robot_state[i].playertype==playertype && REMBB.robot_state[i].in_game && !REMBB.robot_state[i].comm_interrupted) {
if (REMBB.robot_state[i].playerrole != REMBB.robot_state[i].desired_playerrole) {
cerr << "StaticPolicy: Ein anderer Wechsel ist noch nicht ganz abgeschlossen. Mache nix." << endl;
return;
}
num_active_players++;
is_active_player[i]=true;
} else {
is_active_player[i]=false;
}
}
if (num_active_players>max_num_players)
num_active_players=max_num_players;
// Soll-Rollenverteilung erfassen
vector<string> target_roles (num_active_players);
for (unsigned int i=0; i<num_active_players; i++)
target_roles[i] = roles(num_active_players-1, i);
// aus der target_roles alle Rollen loeschen, die durch neu aktivierte Spieler belegt sind
Time now;
for (unsigned int i=0; i<num_robots; i++)
if (is_active_player[i] && now.diff_msec(robot_activation_time[i])<1000) {
vector<string>::iterator it = find (target_roles.begin(), target_roles.end(), REMBB.robot_state[i].playerrole
|
请发表评论