Esempio n. 1
0
// ============================================================================
// DrawBox::draw()                                                             
// convert particles from 3D space to 2D screen coordinates                    
// compute blending values for particles and texture                           
void DrawBox::draw( GLBox * glbox, const ParticlesData * part_data, 
		    const ParticlesSelectVector * _psv, const GlobalOptions * _store_options,
		    QString shot_name)
{
  const double * mProj    = glbox->getProjMatrix();
  double * mMod     = const_cast<double*> 
	(glbox->getModelMatrix());
  // get data pointers
  viewport      = glbox->getViewPort();
  store_options = _store_options;
  psv           = _psv;
#define MP(row,col)  mProj[col*4+row]
#define MM(row,col)  mMod[col*4+row]

  // get windows size 
  width = viewport[2];
  height= viewport[3];
  // set windows size
  setGeometry(viewport[0],viewport[1],viewport[2],viewport[3]);
  
  //QPainter paint(this);
  //paint.eraseRect(viewport[0],viewport[1],viewport[2],viewport[3]);
  clearBuffer();
  
  if (psv->size()) {
    // Zoom is located in ModelView matrix at coordinates MM(2,3)
    // loop on all object
    for (int i=0; i< (int ) psv->size(); i++ ) {
      // loop on all visible object selected particles  
      //std::cerr << "----------\n";  
      if ((*psv)[i].vps->is_visible ) {
	for (int j  = 0; 
	     j  <  (*psv)[i].vps->ni_index;
	     j ++) {
	  int jndex= (*psv)[i].vps->index_tab[j];      
          float 
              x=part_data->pos[jndex*3  ],
	      y=part_data->pos[jndex*3+1],
	      z=part_data->pos[jndex*3+2],
	      w=1;   
          // do the product Mmodel X point = mxyzw
          float myzw0 = MM(0,1)*y + MM(0,2)*z + MM(0,3)*w;
          float mx = MM(0,0)*x  + myzw0;
          float mx1= mx + store_options->texture_size/2.; // move X from half a texture
          
          float myzw1 = MM(1,1)*y + MM(1,2)*z + MM(1,3)*w;
          float my = MM(1,0)*x  + myzw1;
          
          float MmzG = MM(2,1)*y + MM(2,2)*z;
          float Mmz = MM(2,0)*x  + MmzG;
          
          float mz = Mmz  + MM(2,3)*w;
          
          float mwG= MM(3,1)*y + MM(3,2)*z + MM(3,3)*w;
          float mw = MM(3,0)*x  + mwG;
          
          // do the product Mproj X mxyzw  = pxyzw
          float Ppx = MP(0,0)*mx + MP(0,1)*my + MP(0,3)*mw;
          float px  = Ppx + MP(0,2)*mz;
          float px1 = MP(0,0)*mx1 + MP(0,1)*my + MP(0,3)*mw + MP(0,2)*mz;
          
          float Ppy= MP(1,0)*mx + MP(1,1)*my + MP(1,3)*mw;
          float py = Ppy + MP(1,2)*mz;
          
          float Ppz= MP(2,0)*mx + MP(2,1)*my + MP(2,3)*mw;
          float pz = Ppz + MP(2,2)*mz;
          
          float Ppw= MP(3,0)*mx + MP(3,1)*my + MP(3,3)*mw;
          float pw = Ppw + MP(3,2)*mz;
          
          float pw1 = MP(3,0)*mx1 + MP(3,1)*my + MP(3,3)*mw + MP(3,2)*mz;
          // normalyze
	  //std::cerr << px << " " << py << " " << pz << "\n";
          px /= pw;
          px1/= pw1;
          py /= pw;
	  pz /= pw;
	  //std::cerr << px << " " << py << " " << pz << "\n";
          // compute screen coordinates
          float winx =viewport[0] + (1 + px)  * viewport[2] / 2;
          float winx1=viewport[0] + (1 + px1) * viewport[2] / 2;
          float winy =viewport[1] + (1 + py)  * viewport[3] / 2;
          // paint particles
	  //paint.setPen(red);
	  //paint.drawPoint((int) (winx), viewport[3]-(int) (winy));

          #define MMAX(A,B) ((A)>(B)?(A):(B))
          #define MMIN(A,B) ((A)<(B)?(A):(B))

          //if (winx >= 0. && winy >= 0 && winx < 1024 && winy < 1024) {
	  if (winx >= 0. && winy >= 0 && winx < width && winy < height && pz<1.0) {
	    float size_texture = (int) fabs(winx1-winx);
            //std::cerr << "x=" << winx << "  x1=" << winx1 << " size="<<size_texture<< "\n";
	    
	    //color_rgba[(int) (winx)][(int) (winy)].blend(psv[i].vps->col,(float) (alpha)/255.);
	    if (store_options->show_part) {
	      //color_rgba[(int) (winx)][viewport[3]-1-(int) (winy)].blend((*psv)[i].vps->col,
	      //(float) (store_options->particles_alpha)/255.);
	      filterPoint( winx,winy,(*psv)[i].vps->col,(float) (store_options->particles_alpha)/255.);
	    }
	  //paint.drawPoint((int) (winx), (int) (winy));
	    if (store_options->show_poly) {
	      float s4 = size_texture*4.;
	      float ratio_texture =  s4 - floor(s4);
	      float ceil_texture  = ceil(s4);
	      texture->draw(this,psv,i,winx,winy,(int)(ceil_texture), ratio_texture); 
	    }
          }
	}
      }
    }
  }
  
  paintBuffer(shot_name);
}
Esempio n. 2
0
File: MP.cpp Progetto: hleclerc/Soca
MP MP::new_ptr( MP model ) {
    return MP( 0, new Ptr( (qint64)model.m ) );
}
Esempio n. 3
0
File: MP.cpp Progetto: hleclerc/Soca
MP MP::operator[]( int index ) const {
    return MP( c, m and not p.size() ? m->attr( index ) : 0 );
}
Esempio n. 4
0
File: MP.cpp Progetto: hleclerc/Soca
MP MP::new_obj( QString type ) {
    return MP( 0, new ModelWithAttrAndName( type ) );
}
Esempio n. 5
0
File: MP.cpp Progetto: hleclerc/Soca
MP MP::new_lst() {
    return MP( 0, new Lst );
}
Esempio n. 6
0
// 起点开始搜索
int dfs_large(int id, bool inload[], int cnt, int &best_cost, bool flag = false)
{
	//cout << "dfs(" << id << "," << cnt << ")" << endl;
	if(id == eid)
	{
		best_cost = update_ans(ans_sum,ans);
		//update_good(ans_sum,ans);
		return FIND_SOLVE;	
	}
	
	if(is_timeout())
	{
		return TIME_OUT; // time out
	}

	// start bfs
	
	int (&last)[MAX_NODE_NUM] = g_last[cnt];
	int (&w)[MAX_NODE_NUM] = g_w[cnt];
	int (&dis)[MAX_NODE_NUM] = g_dis[cnt];
	
	for(int i=0;i<node_size;i++)
	{
		last[i] = w[i] = dis[i] = -1;
	}	

	int (&que)[MAX_NODE_NUM] = g_que[cnt];
	int front = 0;
	int rear = 0;
	int find_cnt = 0;
	int find_cnt_limit = find_cnt_up;
	if(cnt == must_node_cnt)
		find_cnt_limit = 3;
	if(cnt == 1)
		find_cnt_limit = node_size*8;
	w[id] = 0;
	dis[id] = 0;
	que[rear++] = id;
	
	// 只剩下最后一个节点 , spfa
	if(cnt == 0)
	{
		int que_tag[MAX_NODE_NUM] = {0};
		que_tag[id] = true;
		while(front != rear)
		{
			
			int now_id = que[front++];
			if(front == MAX_NODE_NUM)
				front = 0;
			for(int i=0; i<node_next[now_id].size(); i++)
			{
				int r_node = edge_set[node_next[now_id][i]].r;
				if(inload[r_node])
					continue;
				if(w[r_node] == -1 || w[now_id] + edge_set[node_next[now_id][i]].cost < w[r_node])
				{
					w[r_node] = w[now_id] + edge_set[node_next[now_id][i]].cost;
					last[r_node] = now_id;
					if(!que_tag[r_node])
					{
						que_tag[r_node] = true;
						que[rear++] = r_node;
						if(rear==MAX_NODE_NUM)
							rear = 0;
					}
				}
			}
			que_tag[now_id] = false;
		
		}
		
		if(w[eid] == -1)
			return cnt+1;

		int t_ans_sum = ans_sum;
		vector<int> load_nodes;
		load_nodes.push_back(eid);
		int tmp_id = eid;

		while(last[tmp_id] != -1)
		{
			tmp_id = last[tmp_id];
			load_nodes.push_back(tmp_id);				
		}
				
		reverse(load_nodes.begin(),load_nodes.end());
		for(int i=0;i<load_nodes.size();i++)
		{
			//inload[load_nodes[i]] = true;
			if(i < load_nodes.size() - 1)
			{
				add_edge(load_nodes[i],load_nodes[i+1],ans_sum,ans);
			}
		}

		best_cost = update_ans(ans_sum,ans);
		//update_good(ans_sum,ans);

		ans_sum =  t_ans_sum;
				
		return FIND_SOLVE;
	}

	int fin_res = cnt;
	int t_best_cost = 2000000;
	
	while(front < rear && find_cnt < find_cnt_limit)
	{

		
		if(cnt >= must_node_cnt - 5 && front > 0 && w[que[front]] != w[que[front-1]])
		{
			vector<pair<int,int> > pp;
			for(int i=front;i<rear;i++)
				pp.push_back(MP(dis[que[i]],que[i]));
			sort(pp.begin(),pp.end());
			for(int i=front;i<rear;i++)
				que[i] = pp[i-front].second;
		}

		int now_id = que[front++];
		for(int i=0; i<node_next[now_id].size(); i++)
		{
			int r_node = edge_set[node_next[now_id][i]].r;
			if(inload[r_node] || w[r_node] != -1)
				continue;
			
			if(must_node[r_node] || (cnt == 0 && r_node == eid) )
			{
				int t_ans_sum = ans_sum;
				//vector<int> load_nodes;
				vector<int> edge_nodes;
				//load_nodes.push_back(r_node);
				//load_nodes.push_back(now_id);
				edge_nodes.push_back(node_next[now_id][i]);
				int tmp_id = now_id;

				while(last[tmp_id] != -1)
				{
					tmp_id = last[tmp_id];
					//load_nodes.push_back(tmp_id);				
					edge_nodes.push_back(tmp_id);
					tmp_id = edge_set[tmp_id].l;				
				}
				
				reverse(edge_nodes.begin(),edge_nodes.end());
				for(int i=0;i<edge_nodes.size();i++)
				{
					//inload[load_nodes[i]] = true;
					inload[edge_set[edge_nodes[i]].r] = true;
					/*					
					if(i < load_nodes.size() - 1)
					{
						add_edge(load_nodes[i],load_nodes[i+1],ans_sum,ans);
					}
					*/
					ans[ans_sum++] = edge_nodes[i];
				}

				find_cnt ++;
				int t_t_best_cost = 2000000;
				int res = dfs_large(r_node, inload, cnt - 1, t_t_best_cost, flag);
				//find_cnt --;
				t_best_cost = min(t_best_cost,t_t_best_cost);
				best_cost = min(t_best_cost,best_cost);

				ans_sum =  t_ans_sum;
				
				for(int i=0;i<edge_nodes.size();i++)
				{
					inload[edge_set[edge_nodes[i]].r] = false;
				}
				if(res == END_OUT)
					return res;

				fin_res = min(res, fin_res);
				int min_l = 8;
				int min_g = 8;
				if(!flag)
				{
					if(good_cost < INF_COST)
					{
						min_l = 5;
						min_g = 13;
					}
					if(cnt > min_l && cnt < must_node_cnt - min_g)
						return fin_res;
//else if((cnt > min_l) && cnt < must_node_cnt - min_g + 3 && (fin_res > 0 || t_best_cost - 20 > good_cost))					
else if(cnt > min_l - 1 && cnt < must_node_cnt - min_g + 5 && (fin_res > 0 || t_best_cost - 3 > good_cost))
						return fin_res;
				}
				else
				{
					min_l = 6;
					min_g = 10;
					if(must_node_cnt > 22)
					{
						min_l = 8;
						min_g = 10;
					}
					if(good_cost < INF_COST)
					{
						if(node_size >= 300)
						{				
							min_l = 6;
							min_g = 12;
						}
						else
						{
							min_l = 6;
							min_g = 10;
						}
						if(must_node_cnt > 22)
						{
							min_l = 8;
							min_g = 6;
						}
					}
					if(cnt > min_l && cnt < must_node_cnt - min_g )//&& t_best_cost > good_cost)
						return fin_res;
					else if(cnt < must_node_cnt - min_g - 2 && (t_best_cost - 3  > good_cost || cnt > 0) )
						return fin_res;
				}
				

			} 
			else 
			{
				w[r_node] = w[now_id] + 1;
				dis[r_node] = dis[now_id] + edge_set[node_next[now_id][i]].cost;
				//last[r_node] = now_id;
				last[r_node] = node_next[now_id][i];
				que[rear++] = r_node;
			}
			
		}
	}
	return fin_res;

}
 void addEdge(int u, int v, int id) {
     //cout << u << "<->" << v << endl;
     graph[u].PB(MP(v, id));
     graph[v].PB(MP(u, id));
 }
LL cross(PII a,PII b, PII c){
    PII ab = MP(b.first-a.first,b.second-a.second);
    PII ac = MP(c.first-a.first,c.second-a.second);
    return ab.first*ac.second - ab.second*ac.first;
}
Esempio n. 9
0
int
ProcessShowIml(
    PINSTALLATION_MODIFICATION_LOGFILE pIml
    )
{
    PIML_FILE_RECORD pFile;
    PIML_FILE_RECORD_CONTENTS pOldFile;
    PIML_FILE_RECORD_CONTENTS pNewFile;
    PIML_KEY_RECORD pKey;
    PIML_VALUE_RECORD pValue;
    PIML_VALUE_RECORD_CONTENTS pOldValue;
    PIML_VALUE_RECORD_CONTENTS pNewValue;
    PIML_INI_RECORD pIni;
    PIML_INISECTION_RECORD pSection;
    PIML_INIVARIABLE_RECORD pVariable;
    BOOLEAN FileNameShown;
    BOOLEAN SectionNameShown;

    if (pIml->NumberOfFileRecords > 0) {
        printf( "File Modifications:\n" );
        pFile = MP( PIML_FILE_RECORD, pIml, pIml->FileRecords );
        while (pFile != NULL) {
            pOldFile = MP( PIML_FILE_RECORD_CONTENTS, pIml, pFile->OldFile );
            pNewFile = MP( PIML_FILE_RECORD_CONTENTS, pIml, pFile->NewFile );
            printf( "    %ws - ", MP( PWSTR, pIml, pFile->Name ) );
            switch( pFile->Action ) {
                case CreateNewFile:
                    printf( "created\n" );
                    break;

                case ModifyOldFile:
                    printf( "overwritten\n" );
                    if (pOldFile != NULL) {
                        printf( "        Old size is %u bytes\n", pOldFile->FileSize );
                        }
                    break;

                case DeleteOldFile:
                    printf( "deleted\n" );
                    if (pOldFile != NULL) {
                        printf( "        Old size is %u bytes\n", pOldFile->FileSize );
                        }
                    break;

                case ModifyFileDateTime:
                    printf( "date/time modified\n" );
                    break;

                case ModifyFileAttributes:
                    printf( "attributes modified\n" );
                    break;
                }

            pFile = MP( PIML_FILE_RECORD, pIml, pFile->Next );
            }

        printf( "\n" );
        }

    if (pIml->NumberOfKeyRecords > 0) {
        printf( "Registry Modifications:\n" );
        pKey = MP( PIML_KEY_RECORD, pIml, pIml->KeyRecords );
        while (pKey != NULL) {
            printf( "    %ws - ", MP( PWSTR, pIml, pKey->Name ) );
            switch( pKey->Action ) {
                case CreateNewKey:
                    printf( "created\n" );
                    break;

                case DeleteOldKey:
                    printf( "deleted\n" );
                    break;


                case ModifyKeyValues:
                    printf( "modified\n" );
                    break;

                }

            pValue = MP( PIML_VALUE_RECORD, pIml, pKey->Values );
            while (pValue != NULL) {
                pOldValue = MP( PIML_VALUE_RECORD_CONTENTS, pIml, pValue->OldValue );
                pNewValue = MP( PIML_VALUE_RECORD_CONTENTS, pIml, pValue->NewValue );
                printf( "        %ws - ", MP( PWSTR, pIml, pValue->Name ) );
                if (pValue->Action != DeleteOldValue) {
                    printf( "%s [%x]",
                            FormatEnumType( 0, ValueDataTypeNames, pNewValue->Type, FALSE ),
                            pNewValue->Length
                          );
                    if (pNewValue->Type == REG_SZ ||
                        pNewValue->Type == REG_EXPAND_SZ
                       ) {
                        printf( " '%ws'", MP( PWSTR, pIml, pNewValue->Data ) );
                        }
                    else
                    if (pNewValue->Type == REG_DWORD) {
                        printf( " 0x%x", *MP( PULONG, pIml, pNewValue->Data ) );
                        }
                    }

                if (pValue->Action == CreateNewValue) {
                    printf( " (created)\n" );
                    }
                else  {
                    if (pValue->Action == DeleteOldValue) {
                        printf( " (deleted" );
                        }
                    else {
                        printf( " (modified" );
                        }

                    printf( " - was %s [%x]",
                            FormatEnumType( 0, ValueDataTypeNames, pOldValue->Type, FALSE ),
                            pOldValue->Length
                          );
                    if (pOldValue->Type == REG_SZ ||
                        pOldValue->Type == REG_EXPAND_SZ
                       ) {
                        printf( " '%ws'", MP( PWSTR, pIml, pOldValue->Data ) );
                        }
                    else
                    if (pOldValue->Type == REG_DWORD) {
                        printf( " 0x%x", *MP( PULONG, pIml, pOldValue->Data ) );
                        }

                    printf( " )\n" );
                    }

                pValue = MP( PIML_VALUE_RECORD, pIml, pValue->Next );
                }

            pKey = MP( PIML_KEY_RECORD, pIml, pKey->Next );
            }

        printf( "\n" );
        }

    if (pIml->NumberOfIniRecords > 0) {
        printf( ".INI File modifications:\n" );
        pIni = MP( PIML_INI_RECORD, pIml, pIml->IniRecords );
        while (pIni != NULL) {
            FileNameShown = FALSE;
            pSection = MP( PIML_INISECTION_RECORD, pIml, pIni->Sections );
            while (pSection != NULL) {
                SectionNameShown = FALSE;
                pVariable = MP( PIML_INIVARIABLE_RECORD, pIml, pSection->Variables );
                while (pVariable != NULL) {
                    if (!FileNameShown) {
                        printf( "%ws", MP( PWSTR, pIml, pIni->Name ) );
                        if (pIni->Action == CreateNewIniFile) {
                            printf( " (created)" );
                            }
                        printf( "\n" );
                        FileNameShown = TRUE;
                        }

                    if (!SectionNameShown) {
                        printf( "    [%ws]", MP( PWSTR, pIml, pSection->Name ) );
                        if (pSection->Action == CreateNewSection) {
                            printf( " (created)" );
                            }
                        else
                        if (pSection->Action == DeleteOldSection) {
                            printf( " (deleted)" );
                            }
                        printf( "\n" );

                        SectionNameShown = TRUE;
                        }

                    printf( "        %ws = ", MP( PWSTR, pIml, pVariable->Name ) );
                    if (pVariable->Action == CreateNewVariable) {
                        printf( "'%ws' (created)\n", MP( PWSTR, pIml, pVariable->NewValue ) );
                        }
                    else
                    if (pVariable->Action == DeleteOldVariable) {
                        printf( " (deleted - was '%ws')\n", MP( PWSTR, pIml, pVariable->OldValue ) );
                        }
                    else {
                        printf( "'%ws' (modified - was '%ws')\n",
                                MP( PWSTR, pIml, pVariable->NewValue ),
                                MP( PWSTR, pIml, pVariable->OldValue )
                              );
                        }

                    pVariable = MP( PIML_INIVARIABLE_RECORD, pIml, pVariable->Next );
                    }

                pSection = MP( PIML_INISECTION_RECORD, pIml, pSection->Next );
                }

            if (FileNameShown) {
                printf( "\n" );
                }

            pIni = MP( PIML_INI_RECORD, pIml, pIni->Next );
            }
        }

    return 0;
}
Esempio n. 10
0
inline void Trace::commit_memory(Clnum clnum, Address a, uint8_t d) {
  pair<map<Address, MemoryCell>::iterator, bool> ret = memory_.insert(MP(a, MemoryCell()));
  ret.first->second[clnum] = d;
}
Esempio n. 11
0
		pair<float,float> getCentre(){
			return MP(cx,cy);
		}
Esempio n. 12
0
void Trace::process() {
  MUTEX_LOCK(backing_mutex_);
  EntryNumber entry_count = *((EntryNumber*)backing_);  // don't let this change under me
  MUTEX_UNLOCK(backing_mutex_);

  if (entries_done_ >= entry_count) return;       // handle the > case better

  remap_backing(sizeof(struct change)*entry_count); // what if this fails?

  printf("on %u going from %u to %u...", trace_index_, entries_done_, entry_count);
  fflush(stdout);

#ifndef _WIN32
  struct timeval tv_start, tv_end;
  gettimeofday(&tv_start, NULL);
#endif

  // clamping
  if ((entries_done_ + 1000000) < entry_count) {
    entry_count = entries_done_ + 1000000;
  }

  while (entries_done_ != entry_count) {
    // no need to lock this here, because this is the only thread that changes it
    const struct change *c = &backing_[entries_done_];
    char type = get_type_from_flags(c->flags);

    RWLOCK_WRLOCK(db_lock_);
    // clnum_to_entry_number_, instruction_pages_
    if (type == 'I') {
      if (clnum_to_entry_number_.size() < c->clnum) {
        // there really shouldn't be holes
        clnum_to_entry_number_.resize(c->clnum);
      }
      clnum_to_entry_number_.push_back(entries_done_);
      pages_[c->address & PAGE_MASK] |= PAGE_INSTRUCTION;
    }

    // addresstype_to_clnums_
    // ** this is 75% of the perf, real unordered_map should improve, but c++11 is hard to build
    pair<unordered_map<pair<Address, char>, set<Clnum> >::iterator, bool> ret =
      addresstype_to_clnums_.insert(MP(MP(c->address, type), set<Clnum>()));
    ret.first->second.insert(c->clnum);

    // registers_
    if (type == 'W' && (c->address < (unsigned int)(register_size_ * register_count_))) {
      registers_[c->address / register_size_][c->clnum] = c->data;
    }

    // memory_, data_pages_
    if (type == 'L' || type == 'S') {
      if (type == 'L') {
        pages_[c->address & PAGE_MASK] |= PAGE_READ;
      }
      if (type == 'S') {
        pages_[c->address & PAGE_MASK] |= PAGE_WRITE;
      }

      // no harm in doing the memory commit every time there's a load, right?
      int byte_count = (c->flags&SIZE_MASK)/8;
      uint64_t data = c->data;
      if (is_big_endian_) {
        for (int i = byte_count-1; i >= 0; --i) {
          commit_memory(c->clnum, c->address+i, data&0xFF);
          data >>= 8;
        }
      } else {
        // little endian
        for (int i = 0; i < byte_count; i++) {
          commit_memory(c->clnum, c->address+i, data&0xFF);
          data >>= 8;
        }
      }
    }
    RWLOCK_WRUNLOCK(db_lock_);

    // max_clnum_
    if (max_clnum_ < c->clnum && c->clnum != INVALID_CLNUM) {
      max_clnum_ = c->clnum;
    }

    if (min_clnum_ == INVALID_CLNUM || c->clnum < min_clnum_) {
      min_clnum_ = c->clnum;
    }
    
    entries_done_++;
  }
Esempio n. 13
0
static int
big_bitp(object x, ufixnum p)
{
  return mpz_tstbit(MP(x),p);
}
Esempio n. 14
0
static object
integer_log_op2(fixnum op,object x,enum type tx,object y,enum type ty) {

  object u=big_fixnum1;
  object ux=tx==t_bignum ? x : (mpz_set_si(MP(big_fixnum2),fix(x)), big_fixnum2);
  object uy=ty==t_bignum ? y : (mpz_set_si(MP(big_fixnum3),fix(y)), big_fixnum3);
  
  switch(op) {
  case BOOLCLR:	 mpz_set_si(MP(u),0);break;
  case BOOLSET:	 mpz_set_si(MP(u),-1);break;
  case BOOL1:	 mpz_set(MP(u),MP(ux));break;
  case BOOL2:	 mpz_set(MP(u),MP(uy));break;
  case BOOLC1:	 mpz_com(MP(u),MP(ux));break;
  case BOOLC2:	 mpz_com(MP(u),MP(uy));break;
  case BOOLAND:	 mpz_and(MP(u),MP(ux),MP(uy));break;
  case BOOLIOR:	 mpz_ior(MP(u),MP(ux),MP(uy));break;
  case BOOLXOR:	 mpz_xor(MP(u),MP(ux),MP(uy));break;
  case BOOLEQV:	 mpz_xor(MP(u),MP(ux),MP(uy));mpz_com(MP(u),MP(u));break;
  case BOOLNAND: mpz_and(MP(u),MP(ux),MP(uy));mpz_com(MP(u),MP(u));break;
  case BOOLNOR:	 mpz_ior(MP(u),MP(ux),MP(uy));mpz_com(MP(u),MP(u));break;
  case BOOLANDC1:mpz_com(MP(u),MP(ux));mpz_and(MP(u),MP(u),MP(uy));break;
  case BOOLANDC2:mpz_com(MP(u),MP(uy));mpz_and(MP(u),MP(ux),MP(u));break;
  case BOOLORC1: mpz_com(MP(u),MP(ux));mpz_ior(MP(u),MP(u),MP(uy));break;
  case BOOLORC2: mpz_com(MP(u),MP(uy));mpz_ior(MP(u),MP(ux),MP(u));break;
  default:break;/*FIXME error*/
  }
    
  return u;

}
Esempio n. 15
0
pLL operator * (pLL a,pLL b) {return MP(a.X*b.Y-a.Y*b.X,a.X*b.X+a.Y*b.Y);}
Esempio n. 16
0
PDD at(PDD & a, PDD & b, double t) {
	return MP(a.F * t + b.F * (1 - t), a.S * t + b.S * (1 - t));
}
Esempio n. 17
0
int main(int argc, char * argv[])
{
	try
	{
		libmaus2::util::ArgInfo const arginfo(argc,argv);
		// free list for alignments
		libmaus2::util::GrowingFreeList<libmaus2::bambam::BamAlignment> BAFL;
		// insert size
		int64_t const insertsize = arginfo.getValue<int64_t>("insertsize",800);
		// container for bam decoders
		DecoderContainer deccont;
		
		while ( std::cin )
		{
			// eof?
			if ( std::cin.peek() < 0 )
				break;
		
			// get next instance line
			InstanceLine IS(&deccont,std::cin);
			std::cout << IS << '\n';
			
			uint64_t ilow = 0;
			while ( ilow != IS.size() )
			{
				uint64_t ihigh = ilow;
				
				// get interval for one type of instance
				while ( ihigh != IS.size() && IS.instances[ihigh].type == IS.instances[ilow].type )
					++ihigh;
				
				// if type is split, improper or samestrand
				if ( 
					IS.instances[ilow].type == Instance::instance_type_split
					||
					IS.instances[ilow].type == Instance::instance_type_improper
					||
					IS.instances[ilow].type == Instance::instance_type_samestrand
				)
				{
					// key is maxcnt,num
					std::map<SubInstKey, std::vector<std::string>, std::greater<SubInstKey> > subinst;
				
					for ( uint64_t i = ilow; i < ihigh; ++i )
					{
						std::vector<libmaus2::bambam::BamAlignment *> retlist;
						
						// map from read name to vector of alignments
						std::map<std::string, std::vector<libmaus2::bambam::BamAlignment *> > amap;
						
						libmaus2::bambam::BamHeader::unique_ptr_type uheader;
					
						// get alignments from A file marked with gene A
						{
							libmaus2::bambam::BamAlignmentDecoder & deca = IS.getInstanceDecoderA(i);
							libmaus2::bambam::BamAlignment & algna = deca.getAlignment();
							libmaus2::bambam::BamHeader const & headera = deca.getHeader();

							libmaus2::bambam::BamHeader::unique_ptr_type theader(headera.uclone());
							uheader = UNIQUE_PTR_MOVE(theader);
							
							while ( deca.readAlignment() )
								if ( algna.isMapped() && hasGeneComment(&algna,IS.geneA.name) )
								{
									// std::cerr << algna.formatAlignment(headera) << std::endl;
									libmaus2::bambam::BamAlignment * palgn = BAFL.get();
									retlist.push_back(palgn);
									amap[algna.getName()].push_back(palgn);
									palgn->swap(algna);
								}
						}

						// get alignments from B file marked with gene B
						{
							libmaus2::bambam::BamAlignmentDecoder & decb = IS.getInstanceDecoderB(i);
							libmaus2::bambam::BamAlignment & algnb = decb.getAlignment();
							// libmaus2::bambam::BamHeader const & headerb = decb->getHeader();
							
							while ( decb.readAlignment() )
								if ( algnb.isMapped() && hasGeneComment(&algnb,IS.geneB.name) )
								{
									// std::cerr << algna.formatAlignment(headera) << std::endl;
									libmaus2::bambam::BamAlignment * palgn = BAFL.get();
									retlist.push_back(palgn);
									amap[algnb.getName()].push_back(palgn);
									palgn->swap(algnb);
								}
						}
						
						// pair map intervals
						std::vector<MappedPair> pairs;
						// count read pairs for gene pair
						uint64_t cnt = 0;
						// iterate over names
						for ( std::map<std::string, std::vector<libmaus2::bambam::BamAlignment *> >::iterator ita = amap.begin(); ita != amap.end(); ++ita )
						{
							// get vector of alignments for name
							std::vector<libmaus2::bambam::BamAlignment *> & V = ita->second;
							// sort by (refid,pos,read1)
							std::sort(V.begin(),V.end(),PosComparator());
							
							// remove multiple copies of same alignment
							uint64_t o = 0;
							uint64_t rcnt[2] = {0,0};
							for ( uint64_t l = 0; l < V.size(); )
							{
								// skip over multiple copies of same alignment
								uint64_t h = l;
								while ( h != V.size() && sameAlignment(V[l],V[h]) )
									++h;

								// count read 1
								if ( V[l]->isRead1() )
									rcnt[0]++;
								// count read 2
								if ( V[l]->isRead2() )
									rcnt[1]++;
								
								// copy alignment pointer
								if ( V[l]->isRead1() || V[l]->isRead2() )
									V[o++] = V[l];							
									
								l = h;
							}
														
							V.resize(o);
							
							// if we have read1 and read2
							if ( V.size() > 1 && rcnt[0] && rcnt[1] )
							{
								// iterate over read 1
								for ( uint64_t r1 = 0; r1 < rcnt[0]; ++r1 )
									// iterate over read 2
									for ( uint64_t r2 = rcnt[0]; r2 < o; ++r2 )
									{
										// get alignment for read 1
										libmaus2::bambam::BamAlignment const * algn1 = V[r1];
										// get alignment for read 2
										libmaus2::bambam::BamAlignment const * algn2 = V[r2];

										// if pair is marked with gene pair we are looking for
										if ( 
											(
												hasGeneComment(algn1,IS.geneA.name)
												&&
												hasGeneComment(algn2,IS.geneB.name)
											)
											||
											(											
												hasGeneComment(algn1,IS.geneB.name)
												&&
												hasGeneComment(algn2,IS.geneA.name)
											)
										)
										{
											#if 0
											std::cerr << "\n --- \n";
											std::cerr << algn1->formatAlignment(*uheader) << std::endl;
											std::cerr << algn2->formatAlignment(*uheader) << std::endl;
											++cnt;
											std::cerr << "subcnt=" << V.size() << std::endl;
											#endif
											
											// increment number of read pairs found
											cnt += 1;
											
											// determine smaller and larger alignment (by position)
											bool const smal1 = PosComparator::compare(algn1,algn2);
											libmaus2::bambam::BamAlignment const * algnl = smal1 ? algn1 : algn2;
											libmaus2::bambam::BamAlignment const * algnr = smal1 ? algn2 : algn1;

											// "left" interval
											libmaus2::math::IntegerInterval<int64_t> intl(
												algnl->getPos(),
												algnl->getAlignmentEnd()
											);

											// "right" interval
											libmaus2::math::IntegerInterval<int64_t> intr(
												algnr->getPos(),
												algnr->getAlignmentEnd()
											);
											
											// construct mapped pair of aligned intervals
											MappedPair MP(intl,intr);
								
											// see if this interval (modulo insert size) already exists			
											bool existing = false;
											for ( uint64_t i = 0; (!existing) && i < pairs.size(); ++i )
												// already seen?
												if ( MappedPair::isInsertSizeOverlap(pairs[i],MP,insertsize) )
												{
													// update from for left
													pairs[i].first.from = std::min(
														MP.first.from,
														pairs[i].first.from
													);
													// update to for left
													pairs[i].first.to = std::max(
														MP.first.to,
														pairs[i].first.to
													);

													// update from for right
													pairs[i].second.from = std::min(
														MP.second.from,
														pairs[i].second.from
													);
													// update to for right
													pairs[i].second.to = std::max(
														MP.second.to,
														pairs[i].second.to
													);
													
													// update number of supporting pair for this "break point"
													pairs[i].cnt += 1;
												
													// note that this break point already existed
													existing = true;
												}
												#if 0
												else
												{
													std::cerr << "no overlap" << std::endl;
													std::cerr << MP << std::endl;
													std::cerr << pairs[i] << std::endl;
												}
												#endif
											
											// push new pair if break point did not exist yet
											if ( ! existing )
												pairs.push_back(MP);
										}
									}
							
							}
						}

						// std::cerr << IS.instances[i] << " gcnt=" << cnt << ((IS.instances[i].num != cnt) ? "___" : "") << std::endl;

						std::ostringstream ostr;						
						ostr << "\t" << IS.instances[i];
						// sort by number of supporting read pairs
						std::sort(pairs.begin(),pairs.end(),MappedPairCountComparator());
						// maximum count
						uint64_t const maxcnt =  pairs.size() ? pairs.front().cnt : 0;
						ostr << "\t" << maxcnt;
						// output break points
						for ( uint64_t j = 0; j < pairs.size();++j )
							ostr << "\t" << pairs[j];
						
						// sub instances map ordered by number of read pairs supporting break point
						subinst[SubInstKey(maxcnt,IS.instances[i].num)].push_back(ostr.str());

						// return alignment to free list
						for ( uint64_t i = 0; i < retlist.size(); ++i )
							BAFL.put(retlist[i]);
					}

					// output instance lines
					for ( 
						std::map<SubInstKey, std::vector<std::string>, std::greater<SubInstKey> >::const_iterator ita = subinst.begin();
							ita != subinst.end(); ++ita 
					)
					{
						std::vector<std::string> const & V = ita->second;
						for ( uint64_t i = 0; i < V.size(); ++i )
							std::cout << V[i] << "\n";
					}
				}

				ilow = ihigh;
			}
		}			
	}
	catch(std::exception const & ex)
	{
		std::cerr << ex.what() << std::endl;
		return EXIT_FAILURE;
	}
}
Esempio n. 18
0
File: o.c Progetto: PlanetAPL/a-plus
I rk(I f,A r,A a,A w)
{
  A z=0,*p=0;
  if(w)ND2 else ND1;
  {
    XA;
    C *pp=0,*ap,*wp;
    I wt=0,wr=0,wn=0,*wd=0;
    I n=0,t=0,i,j,k,d[9],rw,ra,ri,ir,iw=0,ia=0,ii=0,
    e=!w&&f==MP(9),h=QP(f)&&f!=MP(71)&&!e;
    Q(!QA(r),9);
    Q(r->t,6);
    Q(r->n<1||r->n>3,8);
    ar-=ra=raw(ar,*r->p);
    if(!w) mv(d,ad,ra),ir=tr(ra,ad),ad+=ra;
    else 
    {
      wt=w->t,wr=w->r,wd=w->d;
      wr-=rw=raw(wr,r->p[r->n>1]),ri=r->n>2?r->p[2]:9;
      Q(ri<0,9);
      if(ri>ra)ri=ra;
      if(ri>rw)ri=rw;
      mv(d,ad,ra-=ri);
      ia=tr(ra,ad),mv(d+ra,wd,rw),iw=tr(rw-=ri,wd);
      Q(cm(ad+=ra,wd+=rw,ri),11);
      ii=tr(ri,ad),ra+=rw+ri,ir=ia*iw*ii,wn=tr(wr,wd+=ri),ad+=ri;
      if(h&&ir>iw&&(f==MP(21)||f==MP(25)||f==MP(26)||f==MP(32)||f==MP(33)))
	h=0;
    } 
    an=tr(ar,ad);
    if(h)
    {
      g=0;
      aw_c[0]=a->c;
      aw_c[1]=w&&w->c;
      r=(A)fa(f,gC(at,ar,an,ad,a->n?a->p:0),w?gC(wt,wr,wn,wd,w->n?w->p:0):0);
      aw_c[0]=aw_c[1]=1;
      if(!r)R 0;
      r=un(&r);
      mv(d+ra,r->d,j=r->r);
      if((j+=ra)>MAXR)R q=13,(I)r;
      n=r->n;t=r->t;
      if(ir<2) R mv(r->d,d,r->r=j),r->n*=ir,(I)r;
      dc(r);
      if(g==(I (*)())rsh) R rsh(w?w:a,j,d);
      if(!g){h=0;}
      else
      {
	if(at=atOnExit,w) wt=wtOnExit;
	if(at!=a->t&&!(a=at?ep_cf(1):ci(1))) R 0;
	if(w&&wt!=w->t&&!(w=wt?ep_cf(2):ci(2))) R 0;
	OF(i,ir,n);
	W(ga(t,j,i,d));
	pp=(C*)z->p;
      }
    }
    if(!h) 
    {
      W(ga(Et,ra,ir,d));
      *--Y=zr(z),p=(A*)z->p;
    }
    if(!w)
    {
      for(ap=(C*)a->p;ir--;ap+=Tt(at,an))
	if(h) (*(I(*)(C*,C*,I))g)(pp,ap,an),pp+=Tt(t,n);
	else a=gc(at,ar,an,ad,(I*)ap),*p++=e?a:(A)fa(f,(I)a,0);
    } 
    else
    {
      for(i=0;i<ia;++i)for(j=0;j<iw;++j)
	for(k=0;k<ii;++k){
	  ap=(C*)a->p+Tt(at,(i*ii+k)*an);
	  wp=(C*)w->p+Tt(wt,(j*ii+k)*wn);
	  if(h)
	  {
	    (*(I(*)(C*,C*,C*,I))g)(pp,ap,wp,n),pp+=Tt(t,n);
	    if(q==1)*--Y=(I)z,aplus_err(q,(A)Y[1]),++Y;
	  } 
	  else
	  { 
	    *p++=(A)fa(f,(I)gc(at,ar,an,ad,(I*)ap),(I)gc(wt,wr,wn,wd,(I*)wp));
	  }
	}
    }
    if(h)R(I)z;
    if(!e)z=(A)dis(r=z),dc(r);
    R ++Y,(I)z;
  }
}
Esempio n. 19
0
int BlockDACG::reSolve(int numEigen, Epetra_MultiVector &Q, double *lambda, int startingEV) {

  // Computes the smallest eigenvalues and the corresponding eigenvectors
  // of the generalized eigenvalue problem
  // 
  //      K X = M X Lambda
  // 
  // using a Block Deflation Accelerated Conjugate Gradient algorithm.
  //
  // Note that if M is not specified, then  K X = X Lambda is solved.
  //
  // Ref: P. Arbenz & R. Lehoucq, "A comparison of algorithms for modal analysis in the
  // absence of a sparse direct method", SNL, Technical Report SAND2003-1028J
  // With the notations of this report, the coefficient beta is defined as 
  //                 diag( H^T_{k} G_{k} ) / diag( H^T_{k-1} G_{k-1} )
  // 
  // Input variables:
  // 
  // numEigen  (integer) = Number of eigenmodes requested
  // 
  // Q (Epetra_MultiVector) = Converged eigenvectors
  //                   The number of columns of Q must be equal to numEigen + blockSize.
  //                   The rows of Q are distributed across processors.
  //                   At exit, the first numEigen columns contain the eigenvectors requested.
  // 
  // lambda (array of doubles) = Converged eigenvalues
  //                   At input, it must be of size numEigen + blockSize.
  //                   At exit, the first numEigen locations contain the eigenvalues requested.
  //
  // startingEV (integer) = Number of existing converged eigenmodes
  //
  // Return information on status of computation
  // 
  // info >=   0 >> Number of converged eigenpairs at the end of computation
  // 
  // // Failure due to input arguments
  // 
  // info = -  1 >> The stiffness matrix K has not been specified.
  // info = -  2 >> The maps for the matrix K and the matrix M differ.
  // info = -  3 >> The maps for the matrix K and the preconditioner P differ.
  // info = -  4 >> The maps for the vectors and the matrix K differ.
  // info = -  5 >> Q is too small for the number of eigenvalues requested.
  // info = -  6 >> Q is too small for the computation parameters.
  //
  // info = - 10 >> Failure during the mass orthonormalization
  // 
  // info = - 20 >> Error in LAPACK during the local eigensolve
  //
  // info = - 30 >> MEMORY
  //

  // Check the input parameters
  
  if (numEigen <= startingEV) {
    return startingEV;
  }

  int info = myVerify.inputArguments(numEigen, K, M, Prec, Q, numEigen + blockSize);
  if (info < 0)
    return info;

  int myPid = MyComm.MyPID();

  // Get the weight for approximating the M-inverse norm
  Epetra_Vector *vectWeight = 0;
  if (normWeight) {
    vectWeight = new Epetra_Vector(View, Q.Map(), normWeight);
  }

  int knownEV = startingEV;
  int localVerbose = verbose*(myPid==0);

  // Define local block vectors
  //
  // MX = Working vectors (storing M*X if M is specified, else pointing to X)
  // KX = Working vectors (storing K*X)
  //
  // R = Residuals
  //
  // H = Preconditioned residuals
  //
  // P = Search directions
  // MP = Working vectors (storing M*P if M is specified, else pointing to P)
  // KP = Working vectors (storing K*P)

  int xr = Q.MyLength();
  Epetra_MultiVector X(View, Q, numEigen, blockSize);
  X.Random();

  int tmp;
  tmp = (M == 0) ? 5*blockSize*xr : 7*blockSize*xr;

  double *work1 = new (nothrow) double[tmp]; 
  if (work1 == 0) {
    if (vectWeight)
      delete vectWeight;
    info = -30;
    return info;
  }
  memRequested += sizeof(double)*tmp/(1024.0*1024.0);

  highMem = (highMem > currentSize()) ? highMem : currentSize();

  double *tmpD = work1;

  Epetra_MultiVector KX(View, Q.Map(), tmpD, xr, blockSize);
  tmpD = tmpD + xr*blockSize;

  Epetra_MultiVector MX(View, Q.Map(), (M) ? tmpD : X.Values(), xr, blockSize);
  tmpD = (M) ? tmpD + xr*blockSize : tmpD;

  Epetra_MultiVector R(View, Q.Map(), tmpD, xr, blockSize);
  tmpD = tmpD + xr*blockSize;

  Epetra_MultiVector H(View, Q.Map(), tmpD, xr, blockSize);
  tmpD = tmpD + xr*blockSize;

  Epetra_MultiVector P(View, Q.Map(), tmpD, xr, blockSize);
  tmpD = tmpD + xr*blockSize;

  Epetra_MultiVector KP(View, Q.Map(), tmpD, xr, blockSize);
  tmpD = tmpD + xr*blockSize;

  Epetra_MultiVector MP(View, Q.Map(), (M) ? tmpD : P.Values(), xr, blockSize);

  // Define arrays
  //
  // theta = Store the local eigenvalues (size: 2*blockSize)
  // normR = Store the norm of residuals (size: blockSize)
  //
  // oldHtR = Store the previous H_i^T*R_i    (size: blockSize)
  // currentHtR = Store the current H_i^T*R_i (size: blockSize)
  //
  // MM = Local mass matrix              (size: 2*blockSize x 2*blockSize)
  // KK = Local stiffness matrix         (size: 2*blockSize x 2*blockSize)
  //
  // S = Local eigenvectors              (size: 2*blockSize x 2*blockSize)

  int lwork2;
  lwork2 = 5*blockSize + 12*blockSize*blockSize;
  double *work2 = new (nothrow) double[lwork2];
  if (work2 == 0) {
    if (vectWeight)
      delete vectWeight;
    delete[] work1;
    info = -30;
    return info;
  }

  highMem = (highMem > currentSize()) ? highMem : currentSize();

  tmpD = work2;

  double *theta = tmpD;
  tmpD = tmpD + 2*blockSize;

  double *normR = tmpD;
  tmpD = tmpD + blockSize;

  double *oldHtR = tmpD;
  tmpD = tmpD + blockSize;
  
  double *currentHtR = tmpD;
  tmpD = tmpD + blockSize;
  memset(currentHtR, 0, blockSize*sizeof(double));
  
  double *MM = tmpD;
  tmpD = tmpD + 4*blockSize*blockSize;

  double *KK = tmpD;
  tmpD = tmpD + 4*blockSize*blockSize;

  double *S = tmpD;

  memRequested += sizeof(double)*lwork2/(1024.0*1024.0);

  // Define an array to store the residuals history
  if (localVerbose > 2) {
    resHistory = new (nothrow) double[maxIterEigenSolve*blockSize];
    if (resHistory == 0) {
      if (vectWeight)
        delete vectWeight;
      delete[] work1;
      delete[] work2;
      info = -30;
      return info;
    }
    historyCount = 0;
  }

  // Miscellaneous definitions

  bool reStart = false;
  numRestart = 0;

  int localSize;
  int twoBlocks = 2*blockSize;
  int nFound = blockSize;
  int i, j;

  if (localVerbose > 0) {
    cout << endl;
    cout << " *|* Problem: ";
    if (M) 
      cout << "K*Q = M*Q D ";
    else
      cout << "K*Q = Q D ";
    if (Prec)
      cout << " with preconditioner";
    cout << endl;
    cout << " *|* Algorithm = DACG (block version)" << endl;
    cout << " *|* Size of blocks = " << blockSize << endl;
    cout << " *|* Number of requested eigenvalues = " << numEigen << endl;
    cout.precision(2);
    cout.setf(ios::scientific, ios::floatfield);
    cout << " *|* Tolerance for convergence = " << tolEigenSolve << endl;
    cout << " *|* Norm used for convergence: ";
    if (normWeight)
      cout << "weighted L2-norm with user-provided weights" << endl;
    else
      cout << "L^2-norm" << endl;
    if (startingEV > 0)
      cout << " *|* Input converged eigenvectors = " << startingEV << endl;
    cout << "\n -- Start iterations -- \n";
  }

  timeOuterLoop -= MyWatch.WallTime();
  for (outerIter = 1; outerIter <= maxIterEigenSolve; ++outerIter) {

    highMem = (highMem > currentSize()) ? highMem : currentSize();

    if ((outerIter == 1) || (reStart == true)) {

      reStart = false;
      localSize = blockSize;

      if (nFound > 0) {

        Epetra_MultiVector X2(View, X, blockSize-nFound, nFound);
        Epetra_MultiVector MX2(View, MX, blockSize-nFound, nFound);
        Epetra_MultiVector KX2(View, KX, blockSize-nFound, nFound);

        // Apply the mass matrix to X
        timeMassOp -= MyWatch.WallTime();
        if (M)
          M->Apply(X2, MX2);
        timeMassOp += MyWatch.WallTime();
        massOp += nFound;

        if (knownEV > 0) {
          // Orthonormalize X against the known eigenvectors with Gram-Schmidt
          // Note: Use R as a temporary work space
          Epetra_MultiVector copyQ(View, Q, 0, knownEV);
          timeOrtho -= MyWatch.WallTime();
          info = modalTool.massOrthonormalize(X, MX, M, copyQ, nFound, 0, R.Values());
          timeOrtho += MyWatch.WallTime();
          // Exit the code if the orthogonalization did not succeed
          if (info < 0) {
            info = -10;
            delete[] work1;
            delete[] work2;
            if (vectWeight)
              delete vectWeight;
            return info;
          }
        }

        // Apply the stiffness matrix to X
        timeStifOp -= MyWatch.WallTime();
        K->Apply(X2, KX2);
        timeStifOp += MyWatch.WallTime();
        stifOp += nFound;

      } // if (nFound > 0)

    } // if ((outerIter == 1) || (reStart == true))
    else {

      // Apply the preconditioner on the residuals
      if (Prec != 0) {
        timePrecOp -= MyWatch.WallTime();
        Prec->ApplyInverse(R, H);
        timePrecOp += MyWatch.WallTime();
        precOp += blockSize;
      }
      else {
        memcpy(H.Values(), R.Values(), xr*blockSize*sizeof(double));
      }

      // Compute the product H^T*R
      timeSearchP -= MyWatch.WallTime();      
      memcpy(oldHtR, currentHtR, blockSize*sizeof(double));
      H.Dot(R, currentHtR);
      // Define the new search directions
      if (localSize == blockSize) {
        P.Scale(-1.0, H);
        localSize = twoBlocks;
      } // if (localSize == blockSize)
      else {
        bool hasZeroDot = false;
        for (j = 0; j < blockSize; ++j) {
          if (oldHtR[j] == 0.0) {
            hasZeroDot = true;
            break; 
          }
          callBLAS.SCAL(xr, currentHtR[j]/oldHtR[j], P.Values() + j*xr);
        }
        if (hasZeroDot == true) {
          // Restart the computation when there is a null dot product
          if (localVerbose > 0) {
            cout << endl;
            cout << " !! Null dot product -- Restart the search space !!\n";
            cout << endl;
          }
          if (blockSize == 1) {
            X.Random();
            nFound = blockSize;
          }
          else {
            Epetra_MultiVector Xinit(View, X, j, blockSize-j);
            Xinit.Random();
            nFound = blockSize - j;
          } // if (blockSize == 1)
          reStart = true;
          numRestart += 1;
          info = 0;
          continue;
        }
        callBLAS.AXPY(xr*blockSize, -1.0, H.Values(), P.Values());
      } // if (localSize == blockSize)
      timeSearchP += MyWatch.WallTime();

      // Apply the mass matrix on P
      timeMassOp -= MyWatch.WallTime();
      if (M)
        M->Apply(P, MP);
      timeMassOp += MyWatch.WallTime();
      massOp += blockSize;

      if (knownEV > 0) {
        // Orthogonalize P against the known eigenvectors
        // Note: Use R as a temporary work space
        Epetra_MultiVector copyQ(View, Q, 0, knownEV);
        timeOrtho -= MyWatch.WallTime();
        modalTool.massOrthonormalize(P, MP, M, copyQ, blockSize, 1, R.Values());
        timeOrtho += MyWatch.WallTime();
      }

      // Apply the stiffness matrix to P
      timeStifOp -= MyWatch.WallTime();
      K->Apply(P, KP);
      timeStifOp += MyWatch.WallTime();
      stifOp += blockSize;

    } // if ((outerIter == 1) || (reStart == true))

    // Form "local" mass and stiffness matrices
    // Note: Use S as a temporary workspace
    timeLocalProj -= MyWatch.WallTime();
    modalTool.localProjection(blockSize, blockSize, xr, X.Values(), xr, KX.Values(), xr,
                    KK, localSize, S);
    modalTool.localProjection(blockSize, blockSize, xr, X.Values(), xr, MX.Values(), xr,
                    MM, localSize, S);
    if (localSize > blockSize) {
      modalTool.localProjection(blockSize, blockSize, xr, X.Values(), xr, KP.Values(), xr,
                      KK + blockSize*localSize, localSize, S);
      modalTool.localProjection(blockSize, blockSize, xr, P.Values(), xr, KP.Values(), xr,
                      KK + blockSize*localSize + blockSize, localSize, S);
      modalTool.localProjection(blockSize, blockSize, xr, X.Values(), xr, MP.Values(), xr,
                      MM + blockSize*localSize, localSize, S);
      modalTool.localProjection(blockSize, blockSize, xr, P.Values(), xr, MP.Values(), xr,
                      MM + blockSize*localSize + blockSize, localSize, S);
    } // if (localSize > blockSize)
    timeLocalProj += MyWatch.WallTime();

    // Perform a spectral decomposition
    timeLocalSolve -= MyWatch.WallTime();
    int nevLocal = localSize;
    info = modalTool.directSolver(localSize, KK, localSize, MM, localSize, nevLocal,
                                  S, localSize, theta, localVerbose,
                                  (blockSize == 1) ? 1: 0);
    timeLocalSolve += MyWatch.WallTime();

    if (info < 0) {
      // Stop when spectral decomposition has a critical failure
      break;
    }

    // Check for restarting
    if ((theta[0] < 0.0) || (nevLocal < blockSize)) {
      if (localVerbose > 0) {
        cout << " Iteration " << outerIter;
        cout << "- Failure for spectral decomposition - RESTART with new random search\n";
      }
      if (blockSize == 1) {
        X.Random();
        nFound = blockSize;
      }
      else {
        Epetra_MultiVector Xinit(View, X, 1, blockSize-1);
        Xinit.Random();
        nFound = blockSize - 1;
      } // if (blockSize == 1)
      reStart = true;
      numRestart += 1;
      info = 0;
      continue;
    } // if ((theta[0] < 0.0) || (nevLocal < blockSize))

    if ((localSize == twoBlocks) && (nevLocal == blockSize)) {
      for (j = 0; j < nevLocal; ++j)
        memcpy(S + j*blockSize, S + j*twoBlocks, blockSize*sizeof(double));
      localSize = blockSize;
    }

    // Check the direction of eigenvectors
    // Note: This sign check is important for convergence
    for (j = 0; j < nevLocal; ++j) {
      double coeff = S[j + j*localSize];
      if (coeff < 0.0)
        callBLAS.SCAL(localSize, -1.0, S + j*localSize);
    }

    // Compute the residuals
    timeResidual -= MyWatch.WallTime();
    callBLAS.GEMM('N', 'N', xr, blockSize, blockSize, 1.0, KX.Values(), xr,
                  S, localSize, 0.0, R.Values(), xr);
    if (localSize == twoBlocks) {
      callBLAS.GEMM('N', 'N', xr, blockSize, blockSize, 1.0, KP.Values(), xr,
                    S + blockSize, localSize, 1.0, R.Values(), xr);
    }
    for (j = 0; j < blockSize; ++j)
      callBLAS.SCAL(localSize, theta[j], S + j*localSize);
    callBLAS.GEMM('N', 'N', xr, blockSize, blockSize, -1.0, MX.Values(), xr,
                  S, localSize, 1.0, R.Values(), xr);
    if (localSize == twoBlocks) {
      callBLAS.GEMM('N', 'N', xr, blockSize, blockSize, -1.0, MP.Values(), xr,
                  S + blockSize, localSize, 1.0, R.Values(), xr);
    }
    for (j = 0; j < blockSize; ++j)
      callBLAS.SCAL(localSize, 1.0/theta[j], S + j*localSize);
    timeResidual += MyWatch.WallTime();
    
    // Compute the norms of the residuals
    timeNorm -= MyWatch.WallTime();
    if (vectWeight)
      R.NormWeighted(*vectWeight, normR);
    else
      R.Norm2(normR);
    // Scale the norms of residuals with the eigenvalues
    // Count the converged eigenvectors
    nFound = 0;
    for (j = 0; j < blockSize; ++j) {
      normR[j] = (theta[j] == 0.0) ? normR[j] : normR[j]/theta[j];
      if (normR[j] < tolEigenSolve) 
        nFound += 1;
    }
    timeNorm += MyWatch.WallTime();

    // Store the residual history
    if (localVerbose > 2) {
      memcpy(resHistory + historyCount*blockSize, normR, blockSize*sizeof(double));
      historyCount += 1;
    }

    // Print information on current iteration
    if (localVerbose > 0) {
      cout << " Iteration " << outerIter << " - Number of converged eigenvectors ";
      cout << knownEV + nFound << endl;
    }

    if (localVerbose > 1) {
      cout << endl;
      cout.precision(2);
      cout.setf(ios::scientific, ios::floatfield);
      for (i=0; i<blockSize; ++i) {
        cout << " Iteration " << outerIter << " - Scaled Norm of Residual " << i;
        cout << " = " << normR[i] << endl;
      }
      cout << endl;
      cout.precision(2);
      for (i=0; i<blockSize; ++i) {
        cout << " Iteration " << outerIter << " - Ritz eigenvalue " << i;
        cout.setf((fabs(theta[i]) < 0.01) ? ios::scientific : ios::fixed, ios::floatfield);
        cout << " = " << theta[i] << endl;
      }
      cout << endl;
    }

    if (nFound == 0) {
      // Update the spaces
      // Note: Use H as a temporary work space
      timeLocalUpdate -= MyWatch.WallTime();
      memcpy(H.Values(), X.Values(), xr*blockSize*sizeof(double));
      callBLAS.GEMM('N', 'N', xr, blockSize, blockSize, 1.0, H.Values(), xr, S, localSize,
                    0.0, X.Values(), xr);
      memcpy(H.Values(), KX.Values(), xr*blockSize*sizeof(double));
      callBLAS.GEMM('N', 'N', xr, blockSize, blockSize, 1.0, H.Values(), xr, S, localSize,
                    0.0, KX.Values(), xr);
      if (M) {
        memcpy(H.Values(), MX.Values(), xr*blockSize*sizeof(double));
        callBLAS.GEMM('N', 'N', xr, blockSize, blockSize, 1.0, H.Values(), xr, S, localSize,
                      0.0, MX.Values(), xr);
      }
      if (localSize == twoBlocks) {
        callBLAS.GEMM('N', 'N', xr, blockSize, blockSize, 1.0, P.Values(), xr,
                      S + blockSize, localSize, 1.0, X.Values(), xr);
        callBLAS.GEMM('N', 'N', xr, blockSize, blockSize, 1.0, KP.Values(), xr,
                      S + blockSize, localSize, 1.0, KX.Values(), xr);
        if (M) {
          callBLAS.GEMM('N', 'N', xr, blockSize, blockSize, 1.0, MP.Values(), xr,
                      S + blockSize, localSize, 1.0, MX.Values(), xr);
        }
      } // if (localSize == twoBlocks)
      timeLocalUpdate += MyWatch.WallTime();
      // When required, monitor some orthogonalities
      if (verbose > 2) {
        if (knownEV == 0) {
          accuracyCheck(&X, &MX, &R, 0, (localSize>blockSize) ? &P : 0);
        }
        else {
          Epetra_MultiVector copyQ(View, Q, 0, knownEV);
          accuracyCheck(&X, &MX, &R, &copyQ, (localSize>blockSize) ? &P : 0);
        }
      } // if (verbose > 2)
      continue;
    } // if (nFound == 0)

    // Order the Ritz eigenvectors by putting the converged vectors at the beginning
    int firstIndex = blockSize;
    for (j = 0; j < blockSize; ++j) {
      if (normR[j] >= tolEigenSolve) {
        firstIndex = j;
        break;
      }
    } // for (j = 0; j < blockSize; ++j)
    while (firstIndex < nFound) {
      for (j = firstIndex; j < blockSize; ++j) {
        if (normR[j] < tolEigenSolve) {
          // Swap the j-th and firstIndex-th position
          callFortran.SWAP(localSize, S + j*localSize, 1, S + firstIndex*localSize, 1);
          callFortran.SWAP(1, theta + j, 1, theta + firstIndex, 1);
          callFortran.SWAP(1, normR + j, 1, normR + firstIndex, 1);
          break;
        }
      } // for (j = firstIndex; j < blockSize; ++j)
      for (j = 0; j < blockSize; ++j) {
        if (normR[j] >= tolEigenSolve) {
          firstIndex = j;
          break;
        }
      } // for (j = 0; j < blockSize; ++j)
    } // while (firstIndex < nFound)

    // Copy the converged eigenvalues
    memcpy(lambda + knownEV, theta, nFound*sizeof(double));

    // Convergence test
    if (knownEV + nFound >= numEigen) {
      callBLAS.GEMM('N', 'N', xr, nFound, blockSize, 1.0, X.Values(), xr,
                    S, localSize, 0.0, R.Values(), xr);
      if (localSize > blockSize) {
        callBLAS.GEMM('N', 'N', xr, nFound, blockSize, 1.0, P.Values(), xr,
                      S + blockSize, localSize, 1.0, R.Values(), xr);
      }
      memcpy(Q.Values() + knownEV*xr, R.Values(), nFound*xr*sizeof(double));
      knownEV += nFound;
      if (localVerbose == 1) {
        cout << endl;
        cout.precision(2);
        cout.setf(ios::scientific, ios::floatfield);
        for (i=0; i<blockSize; ++i) {
          cout << " Iteration " << outerIter << " - Scaled Norm of Residual " << i;
          cout << " = " << normR[i] << endl;
        }
        cout << endl;
      }
      break;
    }

    // Store the converged eigenvalues and eigenvectors
    callBLAS.GEMM('N', 'N', xr, nFound, blockSize, 1.0, X.Values(), xr,
                  S, localSize, 0.0, Q.Values() + knownEV*xr, xr);
    if (localSize == twoBlocks) {
      callBLAS.GEMM('N', 'N', xr, nFound, blockSize, 1.0, P.Values(), xr,
                    S + blockSize, localSize, 1.0, Q.Values() + knownEV*xr, xr);
    }
    knownEV += nFound;

    // Define the restarting vectors
    timeRestart -= MyWatch.WallTime();
    int leftOver = (nevLocal < blockSize + nFound) ? nevLocal - nFound : blockSize;
    double *Snew = S + nFound*localSize;
    memcpy(H.Values(), X.Values(), blockSize*xr*sizeof(double));
    callBLAS.GEMM('N', 'N', xr, leftOver, blockSize, 1.0, H.Values(), xr,
                  Snew, localSize, 0.0, X.Values(), xr);
    memcpy(H.Values(), KX.Values(), blockSize*xr*sizeof(double));
    callBLAS.GEMM('N', 'N', xr, leftOver, blockSize, 1.0, H.Values(), xr,
                  Snew, localSize, 0.0, KX.Values(), xr);
    if (M) {
      memcpy(H.Values(), MX.Values(), blockSize*xr*sizeof(double));
      callBLAS.GEMM('N', 'N', xr, leftOver, blockSize, 1.0, H.Values(), xr,
                    Snew, localSize, 0.0, MX.Values(), xr);
    }
    if (localSize == twoBlocks) {
      callBLAS.GEMM('N', 'N', xr, leftOver, blockSize, 1.0, P.Values(), xr,
                    Snew+blockSize, localSize, 1.0, X.Values(), xr);
      callBLAS.GEMM('N', 'N', xr, leftOver, blockSize, 1.0, KP.Values(), xr,
                    Snew+blockSize, localSize, 1.0, KX.Values(), xr);
      if (M) {
        callBLAS.GEMM('N', 'N', xr, leftOver, blockSize, 1.0, MP.Values(), xr,
                      Snew+blockSize, localSize, 1.0, MX.Values(), xr);
      }
    } // if (localSize == twoBlocks)
    if (nevLocal < blockSize + nFound) {
      // Put new random vectors at the end of the block
      Epetra_MultiVector Xtmp(View, X, leftOver, blockSize - leftOver);
      Xtmp.Random();
    }
    else {
      nFound = 0;
    } // if (nevLocal < blockSize + nFound)
    reStart = true;
    timeRestart += MyWatch.WallTime();

  } // for (outerIter = 1; outerIter <= maxIterEigenSolve; ++outerIter)
  timeOuterLoop += MyWatch.WallTime();
  highMem = (highMem > currentSize()) ? highMem : currentSize();

  // Clean memory
  delete[] work1;
  delete[] work2;
  if (vectWeight)
    delete vectWeight;

  // Sort the eigenpairs
  timePostProce -= MyWatch.WallTime();
  if ((info == 0) && (knownEV > 0)) {
    mySort.sortScalars_Vectors(knownEV, lambda, Q.Values(), Q.MyLength());
  }
  timePostProce += MyWatch.WallTime();

  return (info == 0) ? knownEV : info;

}
Esempio n. 20
0
pii getpos(int x)
{
    return MP(x/len,x%len);
}
Esempio n. 21
0
TEST_F(VirtualTableTests, test_constraints_stacking) {
  // Add two testing tables to the registry.
  Registry::add<pTablePlugin>("table", "p");
  Registry::add<kTablePlugin>("table", "k");
  auto dbc = SQLiteDBManager::get();

  {
    // To simplify the attach, just access the column definition directly.
    auto p = std::make_shared<pTablePlugin>();
    attachTableInternal("p", p->columnDefinition(), dbc->db());
    auto k = std::make_shared<kTablePlugin>();
    attachTableInternal("k", k->columnDefinition(), dbc->db());
  }

  QueryData results;
  std::string statement;
  std::map<std::string, std::string> expected;

  std::vector<std::pair<std::string, QueryData> > constraint_tests = {
      MP("select k.x from p, k", makeResult("x", {"1", "2", "1", "2"})),
      MP("select k.x from (select * from k) k2, p, k where k.x = p.x",
         makeResult("k.x", {"1", "1", "2", "2"})),
      MP("select k.x from (select * from k where z = 1) k2, p, k where k.x = "
         "p.x",
         makeResult("k.x", {"1", "2"})),
      MP("select k.x from k k1, (select * from p) p1, k where k.x = p1.x",
         makeResult("k.x", {"1", "1", "2", "2"})),
      MP("select k.x from (select * from p) p1, k, (select * from k) k2 where "
         "k.x = p1.x",
         makeResult("k.x", {"1", "1", "2", "2"})),
      MP("select k.x from (select * from p) p1, k, (select * from k where z = "
         "2) k2 where k.x = p1.x",
         makeResult("k.x", {"1", "2"})),
      MP("select k.x from k, (select * from p) p1, k k2, (select * from k "
         "where z = 1) k3 where k.x = p1.x",
         makeResult("k.x", {"1", "1", "2", "2"})),
      MP("select p.x from (select * from k where z = 1) k1, (select * from k "
         "where z != 1) k2, p where p.x = k2.x",
         makeResult("p.x", {"1"})),
      MP("select p.x from (select * from k, (select x as xx from k where x = "
         "1) k2 where z = 1) k1, (select * from k where z != 1) k2, p, k as k3 "
         "where p.x = k2.x",
         makeResult("p.x", {"1", "1"})),
  };

  for (const auto& test : constraint_tests) {
    QueryData results;
    queryInternal(test.first, results, dbc->db());
    EXPECT_EQ(results, test.second);
  }

  std::vector<QueryData> union_results = {
      makeResult("x", {"1", "2"}),   makeResult("k.x", {"1", "2"}),
      makeResult("k.x", {"1", "2"}), makeResult("k.x", {"1", "2"}),
      makeResult("k.x", {"1", "2"}), makeResult("k.x", {"1", "2"}),
      makeResult("k.x", {"1", "2"}), makeResult("p.x", {"1"}),
      makeResult("p.x", {"1"}),
  };

  size_t index = 0;
  for (const auto& test : constraint_tests) {
    QueryData results;
    queryInternal(test.first + " union " + test.first, results, dbc->db());
    EXPECT_EQ(results, union_results[index++]);
  }
}
Esempio n. 22
0
void set_levels()
{
  loop(i,1,11)  loop(j,1,11) level[0].board[i][j]=1;
  level[0].start = MP(3,3);
  level[0].des = MP(8,8);
  loop(i,0,50) loop(j,0,50) level[1].board[i][j]=0;
  loop(i,0,50) loop(j,0,50) level[2].board[i][j]=0;
  loop(i,1,4) level[1].board[1][i]=1;
  loop(i,1,7) level[1].board[2][i]=1;
  loop(i,1,10) level[1].board[3][i]=1;
  loop(i,2,11) level[1].board[4][i]=1;
  loop(i,6,11) level[1].board[5][i]=1;
  loop(i,7,10) level[1].board[6][i]=1;
  level[1].start = MP(2,2);
  level[1].des = MP(5,8);
  loop(i,7,14) level[2].board[1][i]=1;
  loop(i,1,5) level[2].board[2][i]=1; loop(i,7,14) level[2].board[2][i]=1;
  loop(i,1,10) level[2].board[3][i]=1; loop(i,12,16) level[2].board[3][i]=1;
  loop(i,1,5) level[2].board[4][i]=1; loop(i,12,16) level[2].board[4][i]=1;
  loop(i,1,5) level[2].board[5][i]=1; loop(i,12,16) level[2].board[5][i]=1;
  loop(i,13,16) level[2].board[6][i]=1;
  level[2].start = MP(4,2);
  level[2].des = MP(4,14);
  loop(i,2,7) loop(j,1,5) level[3].board[i][j]=1;
  loop(i,1,7) loop(j,7,11) level[3].board[i][j]=1;
  loop(i,1,6) loop(j,13,16) level[3].board[i][j]=1;
  level[3].start = MP(4,2);
  level[3].des = MP(2,14);
  level[3].hbridge.pb(MP(3,3)); level[3].vbridge.pb(MP(2,9));
  vector< pair<int,int> > temp; temp.pb(MP(5,5)); temp.pb(MP(5,6)); level[3].hbridge_value.pb(temp);
  temp.clear(); temp.pb(MP(5,11)); temp.pb(MP(5,12)); level[3].vbridge_value.pb(temp);

  loop(i,1,4) loop(j,12,16) level[4].board[i][j]=1;
  loop(j,2,6) level[4].board[2][j]=1; loop(j,8,12) level[4].board[2][j]=1;
  loop(i,3,6) loop(j,2,6) level[4].board[i][j]=1;
  loop(i,6,7) loop(j,4,14) level[4].board[i][j]=1;
  loop(i,7,10) loop(j,11,14) level[4].board[i][j]=1;
  loop(i,7,9) loop(j,14,16) level[4].board[i][j]=1;
  loop(j,8,12) level[4].board[9][j]=1;loop(j,5,6) level[4].board[9][j]=1;
  loop(i,8,11) loop(j,1,4) level[4].board[i][j]=1; level[4].board[9][4]=1; level[4].board[10][4]=1;
  level[4].start = MP(2,14); level[4].des = MP(9,2);
  level[4].hbridge.pb(MP(2,9)); level[4].hbridge.pb(MP(7,15));
  temp.clear(); temp.pb(MP(2,6)); temp.pb(MP(2,7)); level[4].hbridge_value.pb(temp);
  temp.clear(); temp.pb(MP(9,6)) ; temp.pb(MP(9,7)); level[4].hbridge_value.pb(temp);

  level[5].start = MP(6,2); level[5].des = MP(8,8);
  loop(i,3,8) loop(j,1,4) level[5].board[i][j]=1; level[5].board[3][4]=1;
  level[5].board[3][11]=1; loop(i,3,6) loop(j,12,14) level[5].board[i][j]=1;
  level[5].board[6][10]=1; level[5].board[7][10]=1; level[5].board_light[6][11]=1; level[5].board_light[7][11]=1;
  loop(i,6,10) loop(j,7,10) level[5].board[i][j]=1;
  loop(i,1,3) loop(j,4,12) level[5].board_light[i][j]=1;
  loop(i,6,10) loop(j,12,16) level[5].board_light[i][j]=1; level[5].board_light[8][14]=0; level[5].board[8][14]=1;
}
Esempio n. 23
0
File: MP.cpp Progetto: hleclerc/Soca
MP MP::new_lst( QString type ) {
    return MP( 0, new LstWithType( type ) );
}
Esempio n. 24
0
int main(int argc, char **argv)
{
    //  first build our error handler
    g3ErrorHandler = new ConsoleErrorHandler();

    //
    //	now create a domain and a modelbuilder
    //  and build the model
    //

//    Domain *theDomain = new Domain();

    MapOfTaggedObjects theStorage;
//    ArrayOfTaggedObjects theStorage(32);
    Domain *theDomain = new Domain(theStorage);

    // create the nodes using constructor:
    //		Node(tag, ndof, crd1, crd2)
    // and then add them to the domain

    Node *node1 = new Node(1, 3, 1.0, 1.0, 0.0 );
    Node *node2 = new Node(2, 3, 0.0, 1.0, 0.0 );
    Node *node3 = new Node(3, 3, 0.0, 0.0, 0.0 );
    Node *node4 = new Node(4, 3, 1.0, 0.0, 0.0 );
    Node *node5 = new Node(5, 3, 1.0, 1.0, 1.0 );
    Node *node6 = new Node(6, 3, 0.0, 1.0, 1.0 );
    Node *node7 = new Node(7, 3, 0.0, 0.0, 1.0 );
    Node *node8 = new Node(8, 3, 1.0, 0.0, 1.0 );

    theDomain->addNode(node1);
    theDomain->addNode(node2);
    theDomain->addNode(node3);
    theDomain->addNode(node4);
    theDomain->addNode(node5);
    theDomain->addNode(node6);
    theDomain->addNode(node7);
    theDomain->addNode(node8);

    // create an elastic material using constriuctor:
    //		ElasticMaterialModel(tag, E)

    //UniaxialMaterial *theMaterial = new ElasticMaterial(1, 3000);

    double PIo3 = PI/3.0;
    PIo3 = 0.0;

    //Drucker-Prager Model
    DPYieldSurface DP_YS;
    DPPotentialSurface DP_PS(0.05);
    //EvolutionLaw_NL_Eeq DP_ELS1;
    EvolutionLaw_L_Eeq DP_ELS1(10.0);
    EvolutionLaw_T DP_ELT;
    double scalars[] = {0.3, 0.0};  //alfa1, k
    double NOS = 2; //Number of scalar vars
    double NOT = 1; //Number of tensorial vars

    stresstensor startstress;
    straintensor startstrain, otherstrain;
    startstrain = startstrain.pqtheta2strain( 0.000, 0.0000, 0.0);
    otherstrain = otherstrain.pqtheta2strain( 0.000, 0.0000, 0.0);

    stresstensor *tensors = new stresstensor[1];

    EPState EPS(3000.0, 3000.0, 0.3, 0.0, startstress, otherstrain,
                otherstrain, otherstrain, NOS, scalars, NOT, tensors);

    Template3Dep MP(1, &DP_YS, &DP_PS, &EPS, &DP_ELS1, &DP_ELT);

    NDMaterial *theMaterial = &MP;
    //NDMaterial *theMaterial = new ElasticIsotropic3D(1, 3000, 0.3);

    // create the truss elements using constructor:
    //		Truss(tag, dim, nd1, nd2, Material &,A)
    // and then add them to the domain

    //Truss *truss1 = new Truss(1, 2, 1, 4, *theMaterial, 10.0);
    //Truss *truss2 = new Truss(2, 2, 2, 4, *theMaterial,  5.0);

    //EPState *eps = 0;

    EightNodeBrick *brick = new EightNodeBrick(1, 5, 6, 7, 8, 1, 2, 3, 4,
            theMaterial, "Template3Dep",
            0.0, 0.0, 0.0, 1.8, &EPS);

    //theDomain->addElement(truss1);
    //theDomain->addElement(truss2);
    theDomain->addElement( brick );

    // create the single-point constraint objects using constructor:
    //		SP_Constraint(tag, nodeTag, dofID, value)
    // and then add them to the domain

    SP_Constraint *sp1  = new SP_Constraint(1,  1, 0,  0.0259999);
    SP_Constraint *sp2  = new SP_Constraint(2,  1, 1,  0.0259999);
    SP_Constraint *sp3  = new SP_Constraint(3,  1, 2, -0.1213350);
    SP_Constraint *sp4  = new SP_Constraint(4,  2, 0, -0.0259999);
    SP_Constraint *sp5  = new SP_Constraint(5,  2, 1,  0.0259999);
    SP_Constraint *sp6  = new SP_Constraint(6,  2, 2, -0.1213350);
    SP_Constraint *sp7  = new SP_Constraint(7,  3, 0, -0.0259999);
    SP_Constraint *sp8  = new SP_Constraint(8,  3, 1, -0.0259999);
    SP_Constraint *sp9  = new SP_Constraint(9,  3, 2, -0.1213350);
    SP_Constraint *sp10 = new SP_Constraint(10, 4, 0,  0.0259999);
    SP_Constraint *sp11 = new SP_Constraint(11, 4, 1, -0.0259999);
    SP_Constraint *sp12 = new SP_Constraint(12, 4, 2, -0.1213350);

    SP_Constraint *sp13 = new SP_Constraint(13, 5, 0,  0.0);
    SP_Constraint *sp14 = new SP_Constraint(14, 5, 1,  0.0);
    SP_Constraint *sp15 = new SP_Constraint(15, 5, 2,  0.0);
    SP_Constraint *sp16 = new SP_Constraint(16, 6, 0,  0.0);
    SP_Constraint *sp17 = new SP_Constraint(17, 6, 1,  0.0);
    SP_Constraint *sp18 = new SP_Constraint(18, 6, 2,  0.0);
    SP_Constraint *sp19 = new SP_Constraint(19, 7, 0,  0.0);
    SP_Constraint *sp20 = new SP_Constraint(20, 7, 1,  0.0);
    SP_Constraint *sp21 = new SP_Constraint(21, 7, 2,  0.0);
    SP_Constraint *sp22 = new SP_Constraint(22, 8, 0,  0.0);
    SP_Constraint *sp23 = new SP_Constraint(23, 8, 1,  0.0);
    SP_Constraint *sp24 = new SP_Constraint(24, 8, 2,  0.0);


    //Add penalty constraint
    theDomain->addSP_Constraint(sp1 );
    theDomain->addSP_Constraint(sp2 );
    theDomain->addSP_Constraint(sp3 );
    theDomain->addSP_Constraint(sp4 );
    theDomain->addSP_Constraint(sp5 );
    theDomain->addSP_Constraint(sp6 );
    theDomain->addSP_Constraint(sp7 );
    theDomain->addSP_Constraint(sp8 );
    theDomain->addSP_Constraint(sp9 );
    theDomain->addSP_Constraint(sp10);
    theDomain->addSP_Constraint(sp11);
    theDomain->addSP_Constraint(sp12);

    theDomain->addSP_Constraint(sp13);
    theDomain->addSP_Constraint(sp14);
    theDomain->addSP_Constraint(sp15);
    theDomain->addSP_Constraint(sp16);
    theDomain->addSP_Constraint(sp17);
    theDomain->addSP_Constraint(sp18);
    theDomain->addSP_Constraint(sp19);
    theDomain->addSP_Constraint(sp20);
    theDomain->addSP_Constraint(sp21);
    theDomain->addSP_Constraint(sp22);
    theDomain->addSP_Constraint(sp23);
    theDomain->addSP_Constraint(sp24);

    // construct a linear time series object using constructor:
    //		LinearSeries()

    TimeSeries *theSeries = new LinearSeries();

    // construct a load pattren using constructor:
    //		LoadPattern(tag)
    // and then set it's TimeSeries and add it to the domain

    LoadPattern *theLoadPattern = new LoadPattern(1);
    theLoadPattern->setTimeSeries(theSeries);
    theDomain->addLoadPattern(theLoadPattern);

    // construct a nodal load using constructor:
    //		NodalLoad(tag, nodeID, Vector &)
    // first construct a Vector of size 2 and set the values NOTE C INDEXING
    // then construct the load and add it to the domain

    Vector theLoadValues(3);
    theLoadValues(0) = 0.0;
    theLoadValues(1) = 0.0;
    //theLoadValues(2) = -100.0;
    theLoadValues(2) = 0.0;
    NodalLoad *theLoad = new NodalLoad(1, 5, theLoadValues);
    theDomain->addNodalLoad(theLoad, 1);

    theLoad = new NodalLoad(2, 6, theLoadValues);
    theDomain->addNodalLoad(theLoad, 1);

    theLoad = new NodalLoad(3, 7, theLoadValues);
    theDomain->addNodalLoad(theLoad, 1);

    theLoad = new NodalLoad(4, 8, theLoadValues);
    theDomain->addNodalLoad(theLoad, 1);

    // create an Analysis object to perform a static analysis of the model
    //  - constructs:
    //    AnalysisModel of type AnalysisModel,
    //	  EquiSolnAlgo of type Linear
    //	  StaticIntegrator of type LoadControl
    //	  ConstraintHandler of type Penalty
    //    DOF_Numberer which uses RCM
    //    LinearSOE of type Band SPD
    // and then the StaticAnalysis object

    AnalysisModel     *theModel = new AnalysisModel();
    EquiSolnAlgo      *theSolnAlgo = new Linear();
    StaticIntegrator  *theIntegrator = new LoadControl(1.0, 1.0, 1.0, 1.0);
    ConstraintHandler *theHandler = new PenaltyConstraintHandler(1.0e8,1.0e8);
    RCM               *theRCM = new RCM();
    DOF_Numberer      *theNumberer = new DOF_Numberer(*theRCM);
    BandSPDLinSolver  *theSolver = new BandSPDLinLapackSolver();
    LinearSOE         *theSOE = new BandSPDLinSOE(*theSolver);

    StaticAnalysis    theAnalysis(*theDomain,
                                  *theHandler,
                                  *theNumberer,
                                  *theModel,
                                  *theSolnAlgo,
                                  *theSOE,
                                  *theIntegrator);

    // perform the analysis & print out the results for the domain
    int numSteps = 1;
    theAnalysis.analyze(numSteps);
    cerr << *theDomain;

    //brick->displaySelf();

    exit(0);
}
Esempio n. 25
0
File: MP.cpp Progetto: hleclerc/Soca
MP MP::new_path( QString filename ) {
    return MP( 0, new Path( filename ) );
}
Esempio n. 26
0
pii operator -( const pii & a,const pii & b){
 return MP(a.X-b.X,a.Y-b.Y);
}
Esempio n. 27
0
File: MP.cpp Progetto: hleclerc/Soca
MP MP::new_typed_array_qint32() {
    return MP( 0, new TypedArray<qint32> );
}
Esempio n. 28
0
pLL operator - (pLL a,pLL b) {return MP(a.X-b.X,a.Y-b.Y);}
Esempio n. 29
0
TEST(ARRAY, Capacity) {
  EXPECT_TRUE(kPackedCapCodeThreshold == 0x10000);

#define MP(a, b) std::make_pair(a, b)
  // Update the numbers if we change kPackedCapCodeThreshold
#if (LG_SMART_SIZES_PER_DOUBLING == 1)
  std::pair<uint32_t, uint32_t> caps [] = {
    MP(3, 0),
    MP(4, 5),
    MP(5, 0),
    MP(6, 7),
    MP(7, 0),
    MP(8, 11),
    MP(12, 15),
    MP(127, 0),
    MP(128, 191),
    MP(0xFFFF, 0),
    MP(0x10000, 0x17F00),
    MP(0x10001, 0)
  };
#elif (LG_SMART_SIZES_PER_DOUBLING == 2)
  std::pair<uint32_t, uint32_t> caps [] = {
    MP(3, 0),
    MP(4, 0),
    MP(5, 0),
    MP(6, 0),
    MP(7, 0),
    MP(8, 9),
    MP(12, 13),
    MP(127, 0),
    MP(128, 159),
    MP(0xFFFF, 0),
    MP(0x10000, 0x13F00),
    MP(0x10001, 0)
  };
#else
#error Unknown LG_SMART_SIZES_PER_DOUBLING
#endif
#undef MP

  for (size_t i = 0; i != sizeof(caps) / sizeof(caps[0]); ++i) {
    EXPECT_TRUE(PackedArray::getMaxCapInPlaceFast(caps[i].first) ==
                caps[i].second);
  }
}
Esempio n. 30
0
        POINT3D normal=((p[v[i].t[1]]-p[v[i].t[0]])^(p[v[i].t[2]]-p[v[i].t[0]]));
        LL il=(normal*(p[x]-p[v[i].t[0]]));
        vis[i]=0;
        if (il>0) vis[i]=1;
        else if (il==0){
            if ((normal*((p[v[i].t[1]]-p[v[i].t[0]])^(p[x]-p[v[i].t[0]]))>=0
                        && normal*((p[v[i].t[2]]-p[v[i].t[1]])^(p[x]-p[v[i].t[1]]))>=0
                        && normal*((p[v[i].t[0]]-p[v[i].t[2]])^(p[x]-p[v[i].t[2]]))>=0))
                return; /*ODKOMENTUJ*/
            vis[i]=1;
        }
    } 
    int ile=SZ(v);
    REP(i,ile) if (vis[i])
        REP(j,3) if (!vis[t[v[i].t[(j+1)%3]][v[i].t[j]]])
        pom.PB(MP(v[i].t[j],v[i].t[(j+1)%3]));
    REP(i,ile) if (vis[i]){
        swap(v[i],v.back());
        v.pop_back();
        REP(j,3) t[v[i].t[j]][v[i].t[(j+1)%3]]=i;
        vis[i--]=vis[--ile]; 
    }  
    FORE(it,pom){
        t[it->X][it->Y]=t[it->Y][x]=t[x][it->X]=SZ(v);
        v.PB(sciana(it->X,it->Y,x));
    }
}
void CH3D(){ //n>=3, oblicza wektor trojkatnych scian v (mozliwe powtorzenia)
    int i=2;
    POINT3D normal;
    while (i<n && (normal=((p[1]-p[0])^(p[i]-p[0])))==POINT3D(0,0,0)) i++;