uint32 dp (uint32 dev, uint32 op, uint32 dat) { int32 diff; uint32 t, u; UNIT *uptr; if (dev == dp_dib.dno) /* controller? */ return dpc (dev, op, dat); u = (dev - dp_dib.dno - o_DP0) / o_DP0; /* get unit num */ uptr = dp_dev.units + u; /* get unit ptr */ switch (op) { /* case IO op */ case IO_ADR: /* select */ if (dp_sta & STC_IDL) /* idle? save unit */ dp_svun = dev; return BY; /* byte only */ case IO_WD: /* write data */ if (DEBUG_PRS (dp_dev)) fprintf (sim_deb, ">>DP%d WD = %02X, STA = %02X\n", u, dat, dp_sta); if (GET_DTYPE (uptr->flags) == TYPE_2315) /* 2.5MB drive? */ dp_cyl = dat & 0xFF; /* cyl is 8b */ else dp_cyl = ((dp_cyl << 8) | dat) & DMASK16; /* insert byte */ break; case IO_SS: /* status */ if (uptr->flags & UNIT_ATT) t = /* onl? */ ((uptr->flags & UNIT_WPRT)? STD_WRP: 0) | ((dp_sta & STC_IDL)? 0: STD_ILK) | (uptr->STD & STD_UST); else t = STD_MOV | STD_NRDY; /* off = X'09' */ if (t & SETD_EX) /* test for ex */ t = t | STA_EX; return t; case IO_OC: /* command */ if (DEBUG_PRS (dp_dev)) fprintf (sim_deb, ">>DP%d OC = %02X, STA = %02X\n", u, dat, dp_sta); dpd_arm[u] = int_chg (v_DPC + u + 1, dat, dpd_arm[u]); if (dat & CMD_SK) /* seek? get cyl */ t = dp_cyl; else if (dat & CMD_RST) /* rest? cyl 0 */ t = 0; else break; /* no action */ diff = t - uptr->CYL; if (diff < 0) /* ABS cyl diff */ diff = -diff; else if (diff == 0) /* must be nz */ diff = 1; uptr->STD = STD_MOV; /* stat = moving */ uptr->CYL = t; /* put on cyl */ sim_activate (uptr, diff * dp_stime); /* schedule */ break; } return 0; }
std::vector<ADB> BlackoilPropsAd::capPress(const ADB& sw, const ADB& so, const ADB& sg, const Cells& cells) const { const int numCells = cells.size(); const int numActivePhases = numPhases(); const int numBlocks = so.numBlocks(); Block activeSat(numCells, numActivePhases); if (pu_.phase_used[Water]) { assert(sw.value().size() == numCells); activeSat.col(pu_.phase_pos[Water]) = sw.value(); } if (pu_.phase_used[Oil]) { assert(so.value().size() == numCells); activeSat.col(pu_.phase_pos[Oil]) = so.value(); } else { OPM_THROW(std::runtime_error, "BlackoilPropsAdFromDeck::relperm() assumes oil phase is active."); } if (pu_.phase_used[Gas]) { assert(sg.value().size() == numCells); activeSat.col(pu_.phase_pos[Gas]) = sg.value(); } Block pc(numCells, numActivePhases); Block dpc(numCells, numActivePhases*numActivePhases); props_.capPress(numCells, activeSat.data(), cells.data(), pc.data(), dpc.data()); std::vector<ADB> adbCapPressures; adbCapPressures.reserve(3); const ADB* s[3] = { &sw, &so, &sg }; for (int phase1 = 0; phase1 < 3; ++phase1) { if (pu_.phase_used[phase1]) { const int phase1_pos = pu_.phase_pos[phase1]; std::vector<ADB::M> jacs(numBlocks); for (int block = 0; block < numBlocks; ++block) { jacs[block] = ADB::M(numCells, s[phase1]->derivative()[block].cols()); } for (int phase2 = 0; phase2 < 3; ++phase2) { if (!pu_.phase_used[phase2]) continue; const int phase2_pos = pu_.phase_pos[phase2]; // Assemble dpc1/ds2. const int column = phase1_pos + numActivePhases*phase2_pos; // Recall: Fortran ordering from props_.relperm() ADB::M dpc1_ds2_diag = spdiag(dpc.col(column)); for (int block = 0; block < numBlocks; ++block) { jacs[block] += dpc1_ds2_diag * s[phase2]->derivative()[block]; } } adbCapPressures.emplace_back(ADB::function(pc.col(phase1_pos), jacs)); } else { adbCapPressures.emplace_back(ADB::null()); } } return adbCapPressures; }
osg::ref_ptr<osg::Node> Group::exporta(MDagPath &dp) { osg::ref_ptr<osg::Group> osggroup; // Get the node of this path MObject node = dp.node(); // 1. Create the adequate type of node if( node.hasFn(MFn::kEmitter) ) { // Emitters are subclasses of Transform // We build the transform and then add the emitter as a child osggroup = Transform::exporta(node); osggroup->addChild( PointEmitter::exporta(node).get() ); } else if( node.hasFn(MFn::kTransform) ){ osggroup = Transform::exporta(node); } else { // Generic group (kWorld) osggroup = new osg::Group(); } // 2. Process and add children for(int i=0; i<dp.childCount(); i++){ // Add child to the path and recursively call the exportation function MDagPath dpc(dp); dpc.push(dp.child(i)); osg::ref_ptr<osg::Node> child = DAGNode::exporta(dpc); if(child.valid()){ // ** Check ** If any children is a LightSource, deactivate culling // for this group in order to apply the light even though it is not // directly visible if( dynamic_cast<osg::LightSource *>(child.get()) != NULL ) osggroup->setCullingActive(false); osggroup->addChild(child.get()); } } // 3. If there are no children, the node is ignored if( osggroup->getNumChildren() == 0 ){ // Buuuuuuut, if there is an animation, it is saved to disk // because it can be a useful camera animation osg::AnimationPathCallback *cb = dynamic_cast< osg::AnimationPathCallback * >(osggroup->getUpdateCallback()); if(cb){ MFnDependencyNode dn(node); std::cout << "EXPORTING CAMERA ANIMATION: " << dn.name().asChar() << std::endl; CameraAnimation::save(cb->getAnimationPath(), Config::instance()->getSceneFilePath().getDirectory() + "/" + Config::instance()->getSceneFilePath().getFileBaseName() + "_" + std::string(dn.name().asChar()) + ".path" ); } return NULL; } // Name the node (mesh) MFnDependencyNode dnodefn(node); osggroup->setName( dnodefn.name().asChar() ); return (osg::Node *)osggroup.get(); }
int minCut(string s) { const int n = s.size(); //vector<int> dpc(n + 1); vector<int> dpc(n); vector<vector<bool> > dpb(n, vector<bool>(n, false)); //dpc[n] = -1; // can not be cut for (int i = n-1; i >= 0; --i) { dpc[i] = n - 1 - i; // init, the worst case is cutting by each char for (int j = i; j < n; ++j) { dpb[i][j] = (s[i] == s[j]) && ((j-i < 2) || dpb[i+1][j-1]); if (dpb[i][j]) // can cut here dpc[i] = (j == n-1) ? 0 : min(dpc[i], dpc[j+1] + 1); // need not be cut } } return dpc[0]; }
main() { register char c; register int fd, lgt; char buf[512+1]; ini_mem(); if( ini_screen() < 0 ) exit( 0 ); dpo( увт ); if( (fd=open("/usr/minihelp/dtest",0)) > 0 ) { while( read(fd,buf,512) > 0 ) {buf[lgt]=0; dpc( buf );} close( fd ); } state = 0; radr=0177776; wadr=0177776; dpp( xr, yr-1 ); dpc( " READ" ); dpp( xr, yr ); dpo( '(' ); dpc( conv( radr, 6, 8, '0' ) ); dpc( ")=" ); dpc( conv( get(radr), 6, 8, '0' ) ); dpp( xw, yw-1 ); dpc( " WRITE" ); dpp( xw, yw ); dpo( '(' ); dpc( conv( wadr, 6, 8, '0' ) ); dpc( ")=" ); dpc( conv( wvalue, 6, 8, '0' ) ); dpp( x=xr+1, y=yr ); for(;;) { switch( state ) { case 0: c = getnumb( &radr, x-xr-1, 0177777, 0160000 ); break; case 1: c = getnumb( &wadr, x-xw-1, 0177777, 0160000 ); break; case 2: c = getnumb(&wvalue,x-xw-9, 0177777, 0000000 ); break; } rep: switch( c ) { case CTRL(D): end_screen(); exit(0); case 'r': case 'R': state=0; x=xr+1; dpp(x,y); break; case 'w': case 'W': state=1; x=xw+1; dpp(x,y); break; case 'v': case 'V': state=2; x=xw+9; dpp(x,y); break; case 'c': case 'C': if( state ) { wcycle = !wcycle; dpp(xw+8,yw-1); dpc( wcycle ? "(CYCLE)" : " " ); } else { rcycle = !rcycle; dpp(xr+8,yr-1); dpc( rcycle ? "(CYCLE)" : " " ); } dpp( x, y ); break; case CR: switch( state ) { case 0: rvalue = get( radr ); dpp( xr+9, yr ); dpc( conv(rvalue,6,8,'0') ); c='r'; goto rep; case 1: c='v'; goto rep; case 2: set( wadr, wvalue ); c='v'; goto rep; } } } }