int TwoNodeLink::update() { int errCode = 0; // get global trial response const Vector &dsp1 = theNodes[0]->getTrialDisp(); const Vector &dsp2 = theNodes[1]->getTrialDisp(); const Vector &vel1 = theNodes[0]->getTrialVel(); const Vector &vel2 = theNodes[1]->getTrialVel(); int numDOF2 = numDOF/2; Vector ug(numDOF), ugdot(numDOF), uldot(numDOF); for (int i=0; i<numDOF2; i++) { ug(i) = dsp1(i); ugdot(i) = vel1(i); ug(i+numDOF2) = dsp2(i); ugdot(i+numDOF2) = vel2(i); } // transform response from the global to the local system ul.addMatrixVector(0.0, Tgl, ug, 1.0); uldot.addMatrixVector(0.0, Tgl, ugdot, 1.0); // transform response from the local to the basic system ub.addMatrixVector(0.0, Tlb, ul, 1.0); ubdot.addMatrixVector(0.0, Tlb, uldot, 1.0); //ub = (Tlb*Tgl)*ug; //ubdot = (Tlb*Tgl)*ugdot; // set trial response for material models for (int i=0; i<numDir; i++) errCode += theMaterials[i]->setTrialStrain(ub(i),ubdot(i)); return errCode; }
// Paste text from either the clipboard or selection. void ScintillaQt::pasteFromClipboard(QClipboard::Mode mode) { int len; const char *s; bool rectangular; const QMimeData *source = QApplication::clipboard()->mimeData(mode); if (!source || !qsb->canInsertFromMimeData(source)) return; QByteArray text = qsb->fromMimeData(source, rectangular); len = text.length(); s = text.data(); s = Document::TransformLineEnds(&len, s, len, pdoc->eolMode); UndoGroup ug(pdoc); ClearSelection(); SelectionPosition start = sel.IsRectangular() ? sel.Rectangular().Start() : sel.Range(sel.Main()).Start(); if (rectangular) PasteRectangular(start, s, len); else InsertPaste(start, s, len); delete[] s; NotifyChange(); Redraw(); }
tempotest_UserGroup::tempotest_UserGroup(IdMsg *msg) { mainid = msg->id; CProxy_tempotest_UserGroup ug(thisgroup); ug[CkMyPe()].doSendRecv(); delete msg; }
bool dbdky::Condition::waitForSeconds(int seconds) { struct timespec abstime; clock_gettime(CLOCK_REALTIME, &abstime); abstime.tv_sec += seconds; MutexLock::UnassignGuard ug(mutex_); return ETIMEDOUT == pthread_cond_timedwait(&pcond_, mutex_.getPthreadMutex(), &abstime); }
static void insert_chars(document& doc, const wchar_t* chars, text_location location = text_location(0, 0)) { auto p = chars; undo_group ug(doc); while (*p) { location = doc.insert_text(ug, location, *p); p++; } }
int main() { Unigate ug("/tmp/foo"); if(ug.lock()) { printf("locked acquired\n"); sleep(5); ug.unlock(); printf("locked released\n"); sleep(5); return 0; } printf("failed\n"); return 0; }
static void ShouldCombineLine() { auto text = L"line \nof text"; auto expected = L"line of text"; document doc(null_view, text); { undo_group ug(doc); doc.delete_text(ug, text_location(0, 1)); should::Equal(expected, doc.str()); } doc.undo(); should::Equal(text, doc.str(), L"undo"); doc.redo(); should::Equal(expected, doc.str(), L"redo"); }
static void ShouldSplitLine() { auto text = L"line of text"; auto expected = L"line\n of text"; document doc(null_view, text); { undo_group ug(doc); doc.insert_text(ug, text_location(4, 0), L'\n'); should::Equal(expected, doc.str()); } doc.undo(); should::Equal(text, doc.str(), L"undo"); doc.redo(); should::Equal(expected, doc.str(), L"redo"); }
static void ShouldDelete2LineSelection() { auto text = L"one\ntwo\nthree"; auto expected = L"onree"; document doc(null_view, text); { undo_group ug(doc); doc.delete_text(ug, text_selection(2, 0, 2, 2)); should::Equal(expected, doc.str()); } doc.undo(); should::Equal(text, doc.str(), L"undo"); doc.redo(); should::Equal(expected, doc.str(), L"redo"); }
static void ShouldDeleteSelection() { auto text = L"line of text"; auto expected = L"lixt"; document doc(null_view, text); { undo_group ug(doc); doc.delete_text(ug, text_selection(2, 0, 10, 0)); should::Equal(expected, doc.str()); } doc.undo(); should::Equal(text, doc.str(), L"undo"); doc.redo(); should::Equal(expected, doc.str(), L"redo"); }
static void ShouldCutAndPaste() { auto text = L"one\ntwo\nthree"; auto expected = L"one\none\ntwo\nthreetwo\nthree"; document doc(null_view, text); { undo_group ug(doc); auto copy = Combine(doc.text()); doc.insert_text(ug, text_location(0, 1), copy); should::Equal(expected, doc.str()); } doc.undo(); should::Equal(text, doc.str(), L"undo"); doc.redo(); should::Equal(expected, doc.str(), L"redo"); }
static void ShouldInsertSelection() { auto text = L"line of text"; auto selection = L"one\ntwo\nthree"; auto expected = L"line oone\ntwo\nthreef text"; document doc(null_view, text); { undo_group ug(doc); doc.insert_text(ug, text_location(6, 0), selection); should::Equal(expected, doc.str()); } doc.undo(); should::Equal(text, doc.str(), L"undo"); doc.redo(); should::Equal(expected, doc.str(), L"redo"); }
//creates the ngramtable on demand from the sublm tables int mixture::get(ngram& ng,int n,int lev) { if (usefulltable) { return ngramtable::get(ng,n,lev); } //free current tree resetngramtable(); //get 1-word prefix from ng ngram ug(dict,1); *ug.wordp(1)=*ng.wordp(ng.size); //local ngram to upload entries ngram locng(dict,maxlevel()); //allocate subtrees from sublm for (int i=0; i<numslm; i++) { ngram subug(sublm[i]->dict,1); subug.trans(ug); if (sublm[i]->get(subug,1,1)) { ngram subng(sublm[i]->dict,maxlevel()); *subng.wordp(maxlevel())=*subug.wordp(1); sublm[i]->scan(subug.link,subug.info,1,subng,INIT,maxlevel()); while(sublm[i]->scan(subug.link,subug.info,1,subng,CONT,maxlevel())) { locng.trans(subng); put(locng); } } } return ngramtable::get(ng,n,lev); }
void print_graph(::std::vector<table_entry*> links, const map<unsigned long long, string> chains, map<unsigned long long, unsigned long long> mapping, char* graphML_out_file){ map<unsigned long long, string>::const_iterator ch_iter; map<unsigned long long, int> graph_nodes; long node_id = 0; #ifdef GDL_OUT //Alternative output string out_file_name = ""; string gdl_file_name = ""; if(graphML_out_file == NULL){ out_file_name = "RNA-seq-graph.txt"; gdl_file_name = "RNA-seq-graph.gdl"; }else{ out_file_name = graphML_out_file; out_file_name += ".txt"; gdl_file_name = graphML_out_file; gdl_file_name += ".gdl"; } //Out file ofstream out_file; out_file.open(out_file_name.c_str()); //GDL file ofstream gdl_file; gdl_file.open(gdl_file_name.c_str()); //GDL header gdl_file << "graph: {\n"; gdl_file << "\tnode.shape\t: circle\n"; //std::cout << "\tnode.color\t: blue\n"; gdl_file << "\tnode.height\t: 80\n"; gdl_file << "\tnode.width\t: 80\n"; #endif //GraphML typedef boost::property<boost::vertex_name_t, int, boost::property<boost::vertex_color_t, std::string> > VertexProperty; typedef boost::adjacency_list< boost::vecS, boost::vecS, boost::directedS, VertexProperty> Graph; std::vector<std::string> vertex_names; for(ch_iter = chains.begin(); ch_iter != chains.end(); ++ch_iter){ //Graphml nodes vertex_names.push_back(ch_iter->second); ++node_id; graph_nodes[ch_iter->first] = node_id; #ifdef GDL_OUT //GDL nodes gdl_file << "\t node: {\n"; gdl_file << "\t\t title: \"" << node_id << "\"\n"; gdl_file << "\t\t label: \"" << node_id << " - " << ch_iter->second.length() << "\"\n"; gdl_file << "\t\t //" << ch_iter->second << "\n"; gdl_file << "\t}\n"; //File output out_file << "node#" << node_id << " " << ch_iter->second << "\n"; #endif } //Graph Initialization //bool graph[node_id][node_id]; //for(long i=0; i<node_id; ++i){ // for(long j=0; j<node_id; ++j){ // graph[i][j] = 0; // } //} //Graphml graph Graph ug(node_id); //Adding edges int num_edges = 0; for(unsigned int i=0; i<links.size(); ++i){ //std::cout << i << " " << links[i].seq << std::endl; for(int j=0; j<links[i]->size_D_link(); ++j){ //std::cout << "j " << j << std::endl; //std::cout << links[i].D_delta[j] << std::endl; for(int k=0; k<links[i]->size_A_link(); ++k){ if(graph_nodes.find(mapping[links[i]->at_D_link(j)]) != graph_nodes.end() && graph_nodes.find(mapping[links[i]->at_A_link(k)]) != graph_nodes.end()){ if(graph_nodes[mapping[links[i]->at_D_link(j)]] != graph_nodes[mapping[links[i]->at_A_link(k)]]){ // && // graph[graph_nodes[mapping[links[i]->at_D_link(j)]]-1][graph_nodes[mapping[links[i]->at_A_link(k)]]-1] == 0){ //std::cout << "k " << k << std::endl; //std::cout << links[i].A_delta[k] << std::endl; //graph[graph_nodes[mapping[links[i]->at_D_link(j)]]-1][graph_nodes[mapping[links[i]->at_A_link(k)]]-1] = 1; #ifdef GDL_OUT //GDL output gdl_file << "\t edge: {\n"; gdl_file << "\t\t source: \"" << graph_nodes[mapping[links[i]->at_D_link(j)]] << "\"\n"; gdl_file << "\t\t target: \"" << graph_nodes[mapping[links[i]->at_A_link(k)]] << "\"\n"; gdl_file << "\t}\n"; #endif num_edges++; int source = graph_nodes[mapping[links[i]->at_D_link(j)]]; int target = graph_nodes[mapping[links[i]->at_A_link(k)]]; #ifdef GDL_OUT //File output out_file << "edge#" << num_edges << " "; out_file << graph_nodes[mapping[links[i]->at_D_link(j)]] << ";"; out_file << graph_nodes[mapping[links[i]->at_A_link(k)]] << "\n"; #endif //Graphml arcs ::boost::add_edge(source-1,target-1,ug); } } }//End_For }//End_For }//End_For //GDL end #ifdef GDL_OUT gdl_file << "}"; #endif //Graphml export ::boost::dynamic_properties dp; ::boost::graph_traits<Graph>::vertex_iterator v, v_end; for(tie(v,v_end) = vertices(ug); v!=v_end;++v){ put(::boost::vertex_name_t(), ug, *v, vertex_names[(*v)].length()); put(::boost::vertex_color_t(), ug, *v, vertex_names[(*v)]); } dp.property("length", get(::boost::vertex_name_t(), ug)); dp.property("seq", get(::boost::vertex_color_t(), ug)); if(graphML_out_file == NULL){ ::boost::write_graphml(::std::cout, ug, dp, true); }else{ if(::std::strstr(graphML_out_file, ".graphml") == NULL){ strcat(graphML_out_file, ".graphml"); } ::std::ofstream out_stream; out_stream.open(graphML_out_file); ::boost::write_graphml(out_stream, ug, dp, true); } #ifdef GDL_OUT out_file.close(); gdl_file.close(); #endif }//End_Method
ASMmxBase::VolumeVec ASMmxBase::establishBases(Go::SplineVolume* svol, MixedType type) { VolumeVec result(2); // With mixed methods we need two separate spline spaces if (type == FULL_CONT_RAISE_BASIS1 || type == FULL_CONT_RAISE_BASIS2) { // basis1 should be one degree higher than basis2 and C^p-1 continuous int ndim = svol->dimension(); Go::BsplineBasis b1 = svol->basis(0).extendedBasis(svol->order(0)+1); Go::BsplineBasis b2 = svol->basis(1).extendedBasis(svol->order(1)+1); Go::BsplineBasis b3 = svol->basis(2).extendedBasis(svol->order(2)+1); /* To lower order and regularity this can be used instead std::vector<double>::const_iterator first = ++surf->basis(0).begin(); std::vector<double>::const_iterator last = --surf->basis(0).end(); Go::BsplineBasis b1 = Go::BsplineBasis(surf->order_u()-1,first,last); first = ++surf->basis(1).begin(); last = --surf->basis(1).end(); Go::BsplineBasis b2 = Go::BsplineBasis(surf->order_v()-1,first,last); */ // Compute parameter values of the Greville points size_t i; RealArray ug(b1.numCoefs()), vg(b2.numCoefs()), wg(b3.numCoefs()); for (i = 0; i < ug.size(); i++) ug[i] = b1.grevilleParameter(i); for (i = 0; i < vg.size(); i++) vg[i] = b2.grevilleParameter(i); for (i = 0; i < wg.size(); i++) wg[i] = b3.grevilleParameter(i); if (svol->rational()) { std::vector<double> rCoefs(svol->rcoefs_begin(), svol->rcoefs_end()); // we normally would set coefs as (x*w, y*w, w) // however, gotools use this representation internally already. // instance a Bspline surface in ndim+1 Go::SplineVolume vol2(svol->basis(0), svol->basis(1), svol->basis(2), rCoefs.begin(), ndim+1, false); // interpolate the Bspline surface onto new basis RealArray XYZ((ndim+1)*ug.size()*vg.size()*wg.size()); vol2.gridEvaluator(XYZ,ug,vg,wg); std::unique_ptr<Go::SplineVolume> svol3(Go::VolumeInterpolator::regularInterpolation(b1,b2,b3,ug,vg,wg,XYZ,ndim+1,false,XYZ)); // new rational coefs are (x/w', y/w', w') // apparently gotools will rescale coeffs on surface creation. result[0].reset(new Go::SplineVolume(svol3->basis(0), svol3->basis(1), svol3->basis(2), svol3->coefs_begin(), ndim, true)); } else { RealArray XYZ(ndim*ug.size()*vg.size()*wg.size()); // Evaluate the spline surface at all points svol->gridEvaluator(ug,vg,wg,XYZ); // Project the coordinates onto the new basis (the 2nd XYZ is dummy here) result[0].reset(Go::VolumeInterpolator::regularInterpolation(b1,b2,b3, ug,vg,wg,XYZ,ndim, false,XYZ)); } result[1].reset(new Go::SplineVolume(*svol)); } else if (type == REDUCED_CONT_RAISE_BASIS1 || type == REDUCED_CONT_RAISE_BASIS2) { // Order-elevate basis1 such that it is of one degree higher than basis2 // but only C^p-2 continuous result[0].reset(new Go::SplineVolume(*svol)); result[0]->raiseOrder(1,1,1); result[1].reset(new Go::SplineVolume(*svol)); } else if (ASMmxBase::Type == ASMmxBase::DIV_COMPATIBLE) { result.resize(4); // basis1 should be one degree higher than basis2 and C^p-1 continuous int ndim = svol->dimension(); Go::BsplineBasis a1 = svol->basis(0); Go::BsplineBasis a2 = svol->basis(1); Go::BsplineBasis a3 = svol->basis(2); Go::BsplineBasis b1 = svol->basis(0).extendedBasis(svol->order(0)+1); Go::BsplineBasis b2 = svol->basis(1).extendedBasis(svol->order(1)+1); Go::BsplineBasis b3 = svol->basis(2).extendedBasis(svol->order(2)+1); // Compute parameter values of the Greville points size_t i; RealArray u0(a1.numCoefs()), v0(a2.numCoefs()), w0(a3.numCoefs()); for (i = 0; i < u0.size(); i++) u0[i] = a1.grevilleParameter(i); for (i = 0; i < v0.size(); i++) v0[i] = a2.grevilleParameter(i); for (i = 0; i < w0.size(); i++) w0[i] = a3.grevilleParameter(i); RealArray ug(b1.numCoefs()), vg(b2.numCoefs()), wg(b3.numCoefs()); for (i = 0; i < ug.size(); i++) ug[i] = b1.grevilleParameter(i); for (i = 0; i < vg.size(); i++) vg[i] = b2.grevilleParameter(i); for (i = 0; i < wg.size(); i++) wg[i] = b3.grevilleParameter(i); // Evaluate the spline surface at all points // Project the coordinates onto the new basis (the 2nd XYZ is dummy here) RealArray XYZ0(ndim*ug.size()*v0.size()*w0.size()), XYZ1(ndim*u0.size()*vg.size()*w0.size()), XYZ2(ndim*u0.size()*v0.size()*wg.size()); svol->gridEvaluator(ug,v0,w0,XYZ0); svol->gridEvaluator(u0,vg,w0,XYZ1); svol->gridEvaluator(u0,v0,wg,XYZ2); result[0].reset(Go::VolumeInterpolator::regularInterpolation(b1,a2,a3, ug,v0,w0,XYZ0,ndim, false,XYZ0)); result[1].reset(Go::VolumeInterpolator::regularInterpolation(a1,b2,a3, u0,vg,w0,XYZ1,ndim, false,XYZ1)); result[2].reset(Go::VolumeInterpolator::regularInterpolation(a1,a2,b3, u0,v0,wg,XYZ2,ndim, false,XYZ2)); result[3].reset(new Go::SplineVolume(*svol)); geoBasis = 4; } if (type == FULL_CONT_RAISE_BASIS2 || type == REDUCED_CONT_RAISE_BASIS2) std::swap(result[0], result[1]); return result; }