Ejemplo n.º 1
0
	/// Appends element to end of buffer growing its size if necessary
	void append(const T &v, double growFactor=2){
		if(size() >= capacity()){	// double array size if too small
			mElems.resize((size() ? size() : 4)*growFactor);
		}
		super::construct(elems()+size(), v);
		mPos=mSize;
		++mSize;
	}
	void expand(){
		size(size()*n);
		const int Nd = dup ? n : 1;
		for(int i=size()/n-1; i>=0; --i){
			const T& v = (*this)[i];
			for(int j=0; j<Nd; ++j) Alloc::construct(elems()+n*i+j, v);
		}
	}
Foam::labelList Foam::polyBoundaryMesh::ident(const label len)
{
    labelList elems(len);
    forAll(elems, elemI)
    {
        elems[elemI] = elemI;
    }
    return elems;
}
Ejemplo n.º 4
0
 vector<Element> Group::elements() const {
  vector<Element> elems(table.size(), identity());
  vector<Element>::iterator iter = elems.begin();
  int i=0;
  for (iter++, i++; iter != elems.end(); iter++, i++) {
   *iter = Element(this, i);
  }
  return elems;
 }
Ejemplo n.º 5
0
pstring ppreprocessor::replace_macros(const pstring &line)
{
	std::vector<pstring> elems(psplit(line, m_expr_sep));
	pstring ret("");
	for (auto & elem : elems)
	{
		define_t *def = get_define(elem);
		ret += (def != nullptr) ? def->m_replace : elem;
	}
	return ret;
}
Ejemplo n.º 6
0
template <typename Traits> inline void
detector_impl<Traits>::parse(xmlDocPtr doc)
{
	xmlNodePtr root = xmlDocGetRootElement(doc);
	if (0 == root) {
		throw error("got empty browser.xml");
	}
	xml_elems elems(root, "branch");
	for (xml_elems::iterator i = elems.begin(), end = elems.end(); i != end; ++i) {
		root_->add_child(parse_branch(*i));
	}
}
Ejemplo n.º 7
0
int main(int argc, char* argv[])
{
    boost::scoped_ptr<test::element<int> > elem(new test::element<int>(10));
    std::cout << *elem << '\n';
    elem.reset(new test::element<int>(20));
    std::cout << *elem << '\n';
    boost::scoped_array<test::element<int> > elems(new test::element<int>[3]);
    elems[0] = test::element<int>(1);
    elems[1] = test::element<int>(2);
    elems[2] = test::element<int>(3);
    std::cout << elems[0] << ' ' << elems[1] << ' ' << elems[2] << '\n';
}
Ejemplo n.º 8
0
void Graph::toAdjList(int *&adjStart,int *&adjList)
{
	int e,i;
	adjStart=new int[nelems+1];
	adjStart[0]=0;
	for (e=0;e<nelems;e++)
		adjStart[e+1]=adjStart[e]+elems(e);
	adjList=new int[adjStart[nelems]];
	int *adjOut=adjList;
	for (e=0;e<nelems;e++)
		for (i=nbrs[e].getnn()-1;i>=0;i--)
			*(adjOut++)=nbrs[e].getelt(i);
}
Ejemplo n.º 9
0
pstring ppreprocessor::replace_macros(const pstring &line)
{
	pstring_vector_t elems(line, m_expr_sep);
	pstringbuffer ret = "";
	for (auto & elem : elems)
	{
		define_t *def = get_define(elem);
		if (def != nullptr)
			ret.cat(def->m_replace);
		else
			ret.cat(elem);
	}
	return ret;
}
Ejemplo n.º 10
0
Element::Group <const VolR> Unstructured::getAdjacentRegion(
        const Element::Group<const VolR>& region) const {
    std::vector<Element::Face> outer = getExternalBorder(region);
    std::size_t nOut = outer.size();
    // Removes repeated.
    Math::Matrix::Dynamic<std::size_t> aux(nOut,1);
    for (std::size_t i = 0; i < nOut; i++) {
        aux(i,0) = outer[i].first->getId().toInt();
    }
    aux.sortAndRemoveRepeatedRows_omp();
    // Prepares result.
    Element::Group<ElemR> res;
    for (std::size_t i = 0; i < aux.nRows(); i++) {
        res.add(elems().getId(ElemId(aux(i,0)))->cloneTo<ElemR>());
    }
    return res;
}
Ejemplo n.º 11
0
    lex_sense parse_lexsn(const string& lexsn_str) {
        // lex_sense ::= ss_type:lex_filenum:lex_id:head_word:head_id
        pos_t pos;
        size_t filenum, lex_id, head_id;
        string head_word;

        stringstream ss(lexsn_str);
        string item;
        vector<string> elems(5);
        auto i = 0;
        while (getline(ss, item, ':') && i<5) {
            elems[i++] = item;
        }

        pos = static_cast<pos_t>(atoi(elems[0].c_str()));
        filenum = atoi(elems[1].c_str());
        lex_id = atoi(elems[2].c_str());
        head_word = elems[3].c_str();
        head_id = atoi(elems[4].c_str());
        return make_tuple(pos, filenum, lex_id, head_word, head_id);
    }
Ejemplo n.º 12
0
template <typename Traits> inline shared_ptr<typename detector_impl<Traits>::branch_type>
detector_impl<Traits>::parse_branch(xmlNodePtr node) const {
	
	shared_ptr<branch_type> result(new branch_type());
	for (xmlNodePtr n = xmlFirstElementChild(node); 0 != n; n = xmlNextElementSibling(n)) {
		if (disabled(n)) {
			continue;
		}
		else if (xmlStrncasecmp(n->name, (xmlChar const*) "match", sizeof("match")) == 0) {
			xml_elems elems(n, "pattern");
			for (xml_elems::iterator i = elems.begin(), end = elems.end(); i != end; ++i) {
				if (disabled(*i)) {
					continue;
				}
				char const *type = xml_attr_text(*i, "type");
				if (strncasecmp(type, "string", sizeof("string")) == 0) {
					result->add_match(xml_node_text(*i));
				}
				else if (strncasecmp(type, "regex", sizeof("regex")) == 0) {
					result->add_regex_match(xml_node_text(*i));
				}
				else {
					resource<xmlChar*, xml_string_traits> path(xmlGetNodePath(*i));
					throw error("unknown pattern type %s in [%s]", type, (char const*) path.get());
				}
			}
		}
		else if (xmlStrncasecmp(n->name, (xmlChar const*) "branch", sizeof("branch")) == 0) {
			result->add_child(parse_branch(n));
		}
		else if (xmlStrncasecmp(n->name, (xmlChar const*) "define", sizeof("definition")) == 0) {
			result->add_definition(parse_definition(n));
		}
	}
	return result;
}
Ejemplo n.º 13
0
    NodePtr fullelem()
    {
        if (tryConsumeToken(XTT_beginelem)) {
            Node_Element *e = new Node_Element();
            NodePtr r(e);
            {
                const std::string& s = getPreviewToken().value;
                ElemTagSyntax::Parser(s.substr(1, s.size() - 2), e->tag, e->attris);
            } 

            elems(e->children);

            consumeToken(XTT_endelem);
            {
                const std::string& s = getPreviewToken().value;
                std::string tag;
                AttriMap m;
                ElemTagSyntax::Parser(s.substr(2, s.size() - 3), tag, m);
                PARSE_ASSERT(tag == e->tag && m.empty());
            }
            return r;
        }
        return NodePtr();
    }
Ejemplo n.º 14
0
BoxR3 Unstructured::getBoundingBox() const {
    return elems().getBound();
}
Ejemplo n.º 15
0
Element::Group<const SurfR> Unstructured::getMaterialBoundary(
        const MatId matId,
        const LayerId layId) const {

    return elems().getMatLayerId(matId, layId).getOf<SurfR>();
}
Ejemplo n.º 16
0
void TuplePtrn::bind(NameSema& sema) const {
    for (auto&& elem : elems()) {
        elem->bind(sema);
    }
}
Ejemplo n.º 17
0
vector<vector<Geometry::ElemId>> Volume::getPartitionsIds(
        const size_t nDivisions,
        const vector<pair<Geometry::ElemId,int>> idWgt,
        const Math::Real* taskPower) const {
    // Metis v5 manual:
    // [...] take as input the element-node array of the mesh and
    // compute a k-way partitioning for both its elements and its nodes
    // idWgt contains id and weight pairs.
    vector<vector<Geometry::ElemId>> res;
    res.resize(nDivisions, vector<Geometry::ElemId>());
    // Accounts for the one partition case.
    if (nDivisions == 1) {
        Geometry::ConstElemRGroup physVol = elems();
        physVol.removeMatId(MatId(0));
        const size_t nK = physVol.sizeOf<Geometry::VolR>();
        res[0].resize(nK, Geometry::ElemId(0));
        for (size_t i = 0; i < nK; i++) {
            res[0][i] = (elems())(i)->getId();
        }
        return res;
    }
#ifdef MESH_ALLOW_PARTITIONING
    // Prepares mesh info.
    cout << " - Preparing mesh info... " << flush;
    idx_t ne = elems().sizeOf<Geometry::VolR>();
    idx_t *eptr, *eind;
    eptr = new idx_t[ne+1];
    eind = new idx_t[ne*4];
    size_t counter = 0;
    eptr[0] = counter;
    for (idx_t i = 0; i < ne; i++) {
        const Geometry::VolR* vol = elem_.tet[i];
        for (size_t j = 0; j < vol->numberOfVertices(); j++) {
            eind[counter++] = vol->getVertex(j)->id - 1;
        }
        eptr[i+1] = counter;
    }
    cout << "OK" << endl;
    // Relabels ids, needed by quadratic or linearized meshes.
    cout << " - Relabeling... " << flush;
    DynMatrix<Math::Int> id(ne*4,3);
    for (Math::Int i = 0; i < ne*4; i++) {
        id(i,0) = i;
        id(i,1) = eind[i];
        id(i,2) = 0;
    }
    id.sortRows_omp(1,1);
    Math::Int label = 0;
    for (Math::Int i = 1; i < ne*4; i++) {
        if (id(i,1) == id(i-1,1)) {
            id(i,2) = label;
        } else {
            id(i,2) = ++label;
        }
    }
    id.sortRows_omp(0,0);
    for (Math::Int i = 0; i < ne*4; i++) {
        eind[i] = id(i,2);
    }
    idx_t nn = label+1; // Number of vertices.
    cout << "OK" << endl;
    // Copies weights.
    cout << " - Copying weights... " << flush;
    idx_t *vwgt;
    if (idWgt.size() == 0) {
        vwgt = NULL;
    } else {
        vwgt = new idx_t[ne];
        for (Math::Int e = 0; e < ne; e++) {
            vwgt[e] = idWgt[e].second;
        }
    }
    idx_t *vsize = NULL;
    idx_t nparts = nDivisions;
    idx_t objval;
    idx_t *epart;
    epart = new idx_t[ne];
    idx_t *npart;
    npart = new idx_t[nn];
    cout << "OK" << endl;
    // Computes task computational powers.
    real_t *tpwgts = NULL;
    if (taskPower != NULL) {
        tpwgts = new real_t[nDivisions];
        real_t sum = 0.0;
        for (size_t i = 0; i < nDivisions; i++) {
            tpwgts[i] = taskPower[i];
            sum += tpwgts[i];
        }
        assert(std::abs(sum) - 1.0e-16 < 1.0);
    }
    // METIS options.
    cout << " - Setting Options... " << flush;
    idx_t options[METIS_NOPTIONS];
    Math::Int status;
    status = METIS_SetDefaultOptions(options);
    options[METIS_OPTION_PTYPE] = METIS_PTYPE_KWAY;
    options[METIS_OPTION_OBJTYPE] = METIS_OBJTYPE_CUT;
    options[METIS_OPTION_SEED] = (idx_t) 0;
    //	options[METIS_OPTION_OBJTYPE] = METIS_OBJTYPE_VOL;
    // c numbering. Starts from 0.
    options[METIS_OPTION_NUMBERING] = 0;
    cout << "OK" << endl;
    // Calls METIS partition function for meshes.
    idx_t ncommon = 3; // Number of common vertices per element.
    cout << " - Calling Part Mesh Dual... " << flush;
    status = METIS_PartMeshDual(
            &ne, &nn, eptr, eind, vwgt, vsize, &ncommon, &nparts,
            tpwgts, options, &objval, epart, npart);
    if (status != METIS_OK) {
        throw Error("METIS_PartMeshDual fn failed with error: " + status);
    }
    cout << "OK" << endl;
    // Converts result.
    for (size_t i = 0; i < nDivisions; i++) {
        res[i].reserve(ne);
    }
    for (Math::Int i = 0; i < ne; i++) {
        size_t id = elem_.tet[i]->getId();
        res[epart[i]].push_back(id);
    }
    // Frees memory.
    delete vwgt;
    delete epart;
    delete npart;
    delete eptr;
    delete eind;
    // Returns result.
    return res;
#else
    throw logic_error("Mesh partitioning is not allowed.");
#endif
}
Ejemplo n.º 18
0
int main(int argc, char *argv[])
{
    int numProcs, myRank;
    /***********************************************************************************************
     *  Pre-processing stage: 
     * Read input files, allocate and initialize arrays, etc.
     **********************************************************************************************/
    MPI_Init(&argc, &argv);
    double time = MPI_Wtime();

    MPI_Comm_size(MPI_COMM_WORLD, &numProcs);
    MPI_Comm_rank(MPI_COMM_WORLD, &myRank);

    setting stngs;              // A setting object is createad.
    stngs.readSettings();       // settings.in file and minf file are read.
    stngs.setProcs(numProcs);
    stngs.setRank(myRank);
     
     
    /**********************************************************************************************/
    size_t nnc, mnc;
    mnc = nnc = (stngs.getNn() - 1)/numProcs + 1;
    if ((myRank + 1)*mnc > stngs.getNn())
        nnc = stngs.getNn() - mnc*myRank; 
    if (mnc*myRank > stngs.getNn())
        nnc = 0;
   
    // printf("Proc # %d from # %d procs with nnLocal = ", myRank, numProcs);
    // cout << nnLocal << "\n";
    node nodes(nnc); // We create a node object
    nodes.createNodes(&stngs); // and read nodal data from file.

    /**********************************************************************************************/
    size_t nec, mec;
    mec = nec = (stngs.getNe() - 1)/numProcs + 1;
    if ((myRank + 1)*mec > stngs.getNe())
        nec = stngs.getNe() - mec*myRank;
    if (mec*myRank > stngs.getNe())
        nec = 0;    

    element elems(nec, nenTri, nefTri, 7);     // We create an element object.
    // printf("Before\n");
    elems.createElements(&stngs, &nodes);                // and read element data from file
    // printf("After\n");
    /**********************************************************************************************/
    // Moreover solution independent calculations are made: Jacobian determinant, shape funct.
    // derivatives as well as element matrices are calculated.

    
    
   
    /***********************************************************************************************
     * Solution stage: 
     * Element matrices are calculated, boundary conditions are applied and system is solved.
     **********************************************************************************************/
    femSolver solver(&stngs, &nodes, &elems);   // We create an femSolver object.
    solver.solve();                             // and solve the equation system

    time = MPI_Wtime() - time;
    MPI_Allreduce(MPI_IN_PLACE, &time, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD);
    if (stngs.getRank() == 0) cout << time << endl;
    /***********************************************************************************************
     * Post-Processing Stage
     * Create the output files / visualize the reuslts.
     **********************************************************************************************/
//    if(!myRank)
//    {
        postProcessor  postP;
        postP.postProcessorControl(&stngs, &nodes, &elems);
//    }
    MPI_Barrier(MPI_COMM_WORLD);
//    cout << "# " << myRank << "Ciao :)" << endl; 

    MPI_Finalize();


    return 0;
}
Ejemplo n.º 19
0
	/// Write new element to ring buffer
	void write(const T& v){
		++mPos; if(pos() == size()){ mPos=0; }
		Alloc::construct(elems()+pos(), v);
		if(fill() < size()) ++mFill; 
	}
Ejemplo n.º 20
0
	/// Set element at index with no bounds checking
	T& operator[](int i){ return elems()[i];}
Ejemplo n.º 21
0
 void root()
 {
     elems(m_root);
 }
Ejemplo n.º 22
0
void YumMailJob::process(){try{
	int index;
	state=JOB_STATE_OK;

	for(index=0;index<elems(mails);index++){
		if(mails[index].mail==number) break;
	}

	TASSUME(index!=elems(mails),QString("There is no mail file with number %1 in archive").arg(number));

	int count=mails[index].count;
	index=mails[index].index;

	QByteArray bytes;
	QList<int> records;

	QRegExp record("^##(.*)");
	QString line;
	while(!(line=file->readline()).isNull()){
		QChar c;
		line=chomp(line);

		QByteArray arr;
		if(record.indexIn(line)!=-1){
			records.append(bytes.count());
			arr=line.toAscii();
		} else{
			QString errstr;
			arr=text_encode_control_length(line,26,&errstr);
			if(!errstr.isEmpty()){
				state=JOB_STATE_WARNINGS;
				output+=QString("line %1: could not encode text: %2")
					.arg(file->line())
					.arg(errstr);
			}
		}

		bytes.append(arr);
		bytes.append("\r\n",2);
	}

	TASSUME(records.count()==count,QString("Not enough ## entries in file. Need %1 have %2").arg(records.count()).arg(count));

	QString head=QString("//VERSION=1\n//RECORD_NUM=%1\n").arg(count);
	QByteArray records_data=head.toAscii();

	for(int i=0;i<count;i++){
		QString s=QString("//RECORD_POS=%1\n").arg(records.at(i));
		QByteArray a=s.toAscii();
		records_data.append(a);
	}

//	rwfile rw("res.txt");
//	rw.write(records_data.data(),records_data.count());

	Yum y(isofile,number);
	TASSUME(y.issue.isEmpty(),y.issue);

	y.spit(bytes.data(),bytes.size());
	TASSUME(y.issue.isEmpty(),y.issue);

	Yum yy(isofile,index);
	TASSUME(yy.issue.isEmpty(),QString("Mail index file (%1) - %2").arg(index).arg(yy.issue));

	yy.spit(records_data.data(),records_data.size());
	TASSUME(yy.issue.isEmpty(),QString("Mail index file (%1) - %2").arg(index).arg(yy.issue));

} catch(QString ss){
	state=JOB_STATE_FAILED;
}}
Ejemplo n.º 23
0
void StructExpr::bind(NameSema& sema) const {
    ast_type_app()->bind(sema);
    for (auto&& elem : elems())
        elem->expr()->bind(sema);
}
Ejemplo n.º 24
0
// =============================================================================
Teuchos::RCP<VIO::EpetraMesh::Mesh>
VIO::EpetraMesh::Reader::
extractMeshData_( const vtkSmartPointer<vtkUnstructuredGrid> & vtkMesh,
                  const Teuchos::RCP<const Epetra_Comm>      & comm
                ) const
{

  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  // create the maps based on the number of points
  int numPoints = vtkMesh->GetNumberOfPoints();
  Teuchos::RCP<Epetra_Map> nodesMap = Teuchos::rcp( new Epetra_Map( numPoints, 0, *comm ) );
  Teuchos::RCP<Epetra_Map> complexValuesMap = createComplexValuesMap_ ( *nodesMap );
  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  Teuchos::RCP<Mesh> mesh = Teuchos::rcp( new Mesh( nodesMap,
                                                    complexValuesMap
                                                  )
                                        );
  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  // get points
  Teuchos::ArrayRCP<Point> points( numPoints );
  for ( unsigned int k=0; k<numPoints; k++ )
      vtkMesh->GetPoint( k, points[k].getRawPtr() );

  mesh->setNodes( points );


//   for ( int k=0; k<points.size(); k++ )
//       std::cout << points[k] << std::endl;
//   std::cout << "VVV" << std::endl;
//   vtkMesh->Print( std::cout );

  // determine the boundary points
  // transform vtkMesh into vtkPolyData
  vtkSmartPointer<vtkDataSetSurfaceFilter> surfaceFilter =
      vtkSmartPointer<vtkDataSetSurfaceFilter>::New();
  surfaceFilter->SetInput(vtkMesh);
  surfaceFilter->Update();
//   vtkPolyData* polydata = surfaceFilter->GetOutput();

  // filter out the boundary edges
  vtkFeatureEdges * pEdges = vtkFeatureEdges::New();
  pEdges->SetInput( surfaceFilter->GetOutput() );
  pEdges->BoundaryEdgesOn();
  pEdges->FeatureEdgesOff();
  pEdges->NonManifoldEdgesOff();
  pEdges->ManifoldEdgesOff();
  pEdges->Update();

  vtkPolyData * poly = pEdges->GetOutput();

//   pEdges->ColoringOff();
// //   pEdges->GetOutput()->BuildCells();
//
//   std::cout << "V1" << std::endl;
//   std::cout << pEdges->GetOutput()->GetNumberOfCells() << std::endl;
//   std::cout << pEdges->GetOutput()->GetNumberOfLines() << std::endl;
//   std::cout << pEdges->GetOutput()->GetNumberOfPieces() << std::endl;
//   std::cout << pEdges->GetOutput()->GetNumberOfPolys() << std::endl;
//   std::cout << pEdges->GetOutput()->GetNumberOfStrips() << std::endl;
//   std::cout << pEdges->GetOutput()->GetNumberOfVerts() << std::endl;
//   std::cout << pEdges->GetOutput()->GetNumberOfPoints() << std::endl;
// //   std::cout << pEdges->GetOutput()->GetNumberOfElements() << std::endl;
//
// //   pEdges->GetOutput()->GetLines()->GetCell(0)->Print( std::cout );
//
// //   pEdges->GetOutput()->BuildCells();
//   TEUCHOS_ASSERT_EQUALITY( 0, pEdges->GetErrorCode() );
//
//   std::cout << "W-1" << std::endl;
//   int numLines = poly->GetNumberOfLines();
//   vtkIdType * pts;
// //   vtkIdList * pts2;
//   for ( vtkIdType lineId=0; lineId<numLines; lineId++ )
//   {
//       vtkIdType numPoints;
//       pEdges->GetOutput()->GetLines()->GetCell( lineId, numPoints, pts );
// //       pEdges->GetOutput()->GetCellPoints( cellId, pts2 );
//
//       if ( numPoints!=2 )
//       {
//         std::cout << "AAAAAAAAH!" << std::endl;
//         continue;
//       }
//       // make sure we're dealing with an actual *edge* here.
//       TEUCHOS_ASSERT_EQUALITY( numPoints, 2 );
//       std::cout << pts[0] << " " << pts[1] << std::endl;
//   }

//   std::cout << "W0" << std::endl;
//   poly->GetLines()->Print( std::cout );
//
//   std::cout << "W1" << std::endl;
//   poly->GetPoints()->Print( std::cout );
//
//   std::cout << "W2" << std::endl;

  double x[3];
//   Teuchos::ArrayRCP<bool> boundaryPoints( numPoints, false );
  Teuchos::ArrayRCP<bool> isBoundaryNodes( numPoints );
  for ( int k=0; k<poly->GetNumberOfPoints(); k++ )
  {
      poly->GetPoint( k, x );
      vtkIdType ptId = vtkMesh->FindPoint( x );
      isBoundaryNodes[ ptId ] = true;
  }
  mesh->setBoundaryNodes( isBoundaryNodes );

//   for ( int k=0; k<boundaryPoints.size(); k++ )
//     std::cout << boundaryPoints[k] << std::endl;

//   std::cout << "WWW" << std::endl;
//   poly->Print( std::cout );
//   vtkCellArray * verts = poly->GetVerts();
//   verts->Print( std::cout );

//   std::cout << "XXX" << std::endl;
//   poly->GetData()->Print( std::cout );

//   int numBoundaryPoints = poly->GetNumberOfPoints();
//   Teuchos::ArrayRCP<Teuchos::Tuple<double,3> > boundaryPoints( numBoundaryPoints );
//   for ( unsigned int k=0; k<numBoundaryPoints; k++ )
//       poly->GetPoint( k, boundaryPoints[k].getRawPtr() );
//   mesh->setBoundaryNodes( boundaryPoints );

//   for ( int k=0; k<points.size(); k++ )
//       std::cout << boundaryPoints[k] << std::endl;
  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  // get cells
  int globalNumElems = vtkMesh->GetNumberOfCells();

  // create an appropriate map
  Teuchos::RCP<const Epetra_Map> elemsMap =
      Teuchos::rcp ( new Epetra_Map ( globalNumElems, 0, *comm ) );

  int localNumElems = elemsMap->NumMyElements();

  Teuchos::ArrayRCP<Teuchos::ArrayRCP<int> > elems( localNumElems );
  Teuchos::ArrayRCP<Mesh::ElementType>       elemTypes( localNumElems );

  for ( unsigned int k=0; k<localNumElems; k++ )
  {
      // set the connectivity table
      vtkCell * cell = vtkMesh->GetCell( elemsMap->GID(k) );
      int numPoints = cell->GetNumberOfPoints();
      elems[k] = Teuchos::ArrayRCP<int>( numPoints );
      for ( unsigned int l=0; l<numPoints; l++ )
          elems[k][l] = cell->GetPointId( l );

      // set the element type
      switch( cell->GetCellType() )
      {
          case VTK_LINE:
                  elemTypes[k] = Mesh::EDGE2;
                  break;
          case VTK_QUADRATIC_EDGE:
                  elemTypes[k] = Mesh::EDGE3;
                  break;
          case VTK_TRIANGLE:
                  elemTypes[k] = Mesh::TRI3;
                  break;
          case VTK_QUADRATIC_TRIANGLE:
                  elemTypes[k] = Mesh::TRI6;
                  break;
          case VTK_QUAD:
                  elemTypes[k] = Mesh::QUAD4;
                  break;
          case VTK_QUADRATIC_QUAD:
                  elemTypes[k] = Mesh::QUAD8;
                  break;
          case VTK_BIQUADRATIC_QUAD:
                  elemTypes[k] = Mesh::QUAD9;
                  break;
          case VTK_TETRA:
                  elemTypes[k] = Mesh::TET4;
                  break;
          case VTK_QUADRATIC_TETRA:
                  elemTypes[k] = Mesh::TET10;
                  break;
          case VTK_HEXAHEDRON:
                  elemTypes[k] = Mesh::HEX8;
                  break;
          case VTK_QUADRATIC_HEXAHEDRON:
                  elemTypes[k] = Mesh::HEX20;
                  break;
          case VTK_WEDGE:
                  elemTypes[k] = Mesh::PRISM6;
                  break;
          case VTK_HIGHER_ORDER_WEDGE:
                  elemTypes[k] = Mesh::PRISM15;
                  break;
          case VTK_PYRAMID:
                  elemTypes[k] = Mesh::PYRAMID5;
                  break;
          default:
              TEST_FOR_EXCEPTION( true,
                                  std::logic_error,
                                  "Unknown type \""<< cell->GetCellType()  <<"\"." );
      }
  }
  mesh->setElems( elems );

  mesh->setElemTypes( elemTypes );
  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

  return mesh;
}
Ejemplo n.º 25
0
	/// Get element at index with no bounds checking
	const T& operator[](int i) const { return elems()[i]; }