int CalcPositionCosts (const INDEX & ind) const { int i = HashValue(ind); int costs = 1; for (;;) { if (hash.Get(i) == ind) return costs; if (hash.Get(i) == invalid) return costs; i++; if (i > hash.Size()) i = 1; costs++; } }
void referencetransform :: ToPlain (const Array<Point3d> & p, Array<Point3d> & pp) const { Vec3d v; int i; pp.SetSize (p.Size()); for (i = 1; i <= p.Size(); i++) { v = p.Get(i) - rp; pp.Elem(i).X() = (ex_h * v); pp.Elem(i).Y() = (ey_h * v); pp.Elem(i).Z() = (ez_h * v); } }
void DBOperationHelper_NonVO(Handle<Object> spec, KeyOperation & op) { HandleScope scope; Local<Value> v; Local<Object> o; setKeysInOp(spec, op); v = spec->Get(HELPER_ROW_BUFFER); if(! v->IsNull()) { o = v->ToObject(); op.row_buffer = V8BINDER_UNWRAP_BUFFER(o); } v = spec->Get(HELPER_ROW_RECORD); if(! v->IsNull()) { o = v->ToObject(); const Record * record = unwrapPointer<const Record *>(o); op.row_record = record; v = spec->Get(HELPER_BLOBS); if(v->IsObject()) { if(op.opcode == 1) { op.nblobs = op.createBlobReadHandles(record); } else { op.nblobs = op.createBlobWriteHandles(v->ToObject(), record); } } } v = spec->Get(HELPER_LOCK_MODE); if(! v->IsNull()) { int intLockMode = v->Int32Value(); op.lmode = static_cast<NdbOperation::LockMode>(intLockMode); } v = spec->Get(HELPER_COLUMN_MASK); if(! v->IsNull()) { Array *maskArray = Array::Cast(*v); for(unsigned int m = 0 ; m < maskArray->Length() ; m++) { Local<Value> colId = maskArray->Get(m); op.useColumn(colId->Int32Value()); } } DEBUG_PRINT("Non-VO %s -- mask: %u lobs: %d", op.getOperationName(), op.u.maskvalue, op.nblobs); }
Handle<Value> DBOperationHelper_NonVO(const Arguments &args) { HandleScope scope; Operation op; const Local<Object> spec = args[0]->ToObject(); Local<Value> v; Local<Object> o; setKeysInOp(spec, op); v = spec->Get(HELPER_ROW_BUFFER); if(! v->IsNull()) { o = v->ToObject(); op.row_buffer = V8BINDER_UNWRAP_BUFFER(o); } v = spec->Get(HELPER_ROW_RECORD); if(! v->IsNull()) { o = v->ToObject(); op.row_record = unwrapPointer<const Record *>(o); } v = spec->Get(HELPER_LOCK_MODE); if(! v->IsNull()) { int intLockMode = v->Int32Value(); op.lmode = static_cast<NdbOperation::LockMode>(intLockMode); } v = spec->Get(HELPER_COLUMN_MASK); if(! v->IsNull()) { Array *maskArray = Array::Cast(*v); for(unsigned int m = 0 ; m < maskArray->Length() ; m++) { Local<Value> colId = maskArray->Get(m); op.useColumn(colId->Int32Value()); } } int opcode = args[1]->Int32Value(); NdbTransaction *tx = unwrapPointer<NdbTransaction *>(args[2]->ToObject()); DEBUG_PRINT("Non-VO opcode: %d mask: %u", opcode, op.u.maskvalue); return scope.Close(buildNdbOperation(op, opcode, tx)); }
int Ng_GetPrimitiveData (ClientData clientData, Tcl_Interp * interp, int argc, tcl_const char *argv[]) { CSGeometry * geometry = dynamic_cast<CSGeometry*> (ng_geometry.get()); if (!geometry) { Tcl_SetResult (interp, err_needscsgeometry, TCL_STATIC); return TCL_ERROR; } tcl_const char * name = argv[1]; tcl_const char * classnamevar = argv[2]; tcl_const char * valuevar = argv[3]; const char * classname; Array<double> coeffs; geometry->GetSolid (name)->GetPrimitive()->GetPrimitiveData (classname, coeffs); ostringstream vst; for (int i = 1; i <= coeffs.Size(); i++) vst << coeffs.Get(i) << " "; cout << "GetPrimitiveData, name = " << name << ", classnamevar = " << classnamevar << ", classname = " << classname << endl << " valuevar = " << valuevar << ", values = " << vst.str() << endl; Tcl_SetVar (interp, classnamevar, (char*)classname, 0); Tcl_SetVar (interp, valuevar, (char*)vst.str().c_str(), 0); return TCL_OK; }
int _tmain(int argc, _TCHAR* argv[]) { cout << "7 LABOR WORK" << endl; Array<int> Ar1; Array<int> Ar2; Ar1.Set(1); Ar1.Set(2); Ar1.Set(3); Ar2.Set(4); Ar2.Set(5); Ar2.Set(6); cout << endl << "Size Ar1= " << Ar1.getSize() << endl; cout << "Size Ar2= " << Ar2.getSize() << endl; cout << "Get Ar1: "; Ar1.Get(); cout << "Get Ar2: "; Ar2.Get(); Array<double> Ar3; Array<double> Ar4; Ar3.Set(1.1); Ar3.Set(2.2); Ar3.Set(3.3); Ar4.Set(4.4); Ar4.Set(5.5); Ar4.Set(6.6); cout << "Size Ar3= " << Ar3.getSize() << endl; cout << "Size Ar4= " << Ar4.getSize() << endl; cout << "Get Ar3: "; Ar3.Get(); cout << "Get Ar4: "; Ar4.Get(); Array<Person> Ar5; Ar5.Set(Person("Ivan", 4)); Ar5.Set(Person("Petr", 5)); cout << "Size Ar5= " << Ar5.getSize() << endl; cout << "Get Ar5: "; Ar5.Get(); cout << endl; cout << "8 LABOR WORK" << endl; Array<int> oldArr; int k = 6; for (int i = 0; i < 5; i++) { oldArr.Set(k); k--; } oldArr.Get(); sortik(oldArr); oldArr.Get(); cout << endl; Array<double> oldArr1; double d = 6.6; for (int i = 0; i < 5; i++) { oldArr1.Set(d); d = d - 1.1; } oldArr1.Get(); sortik(oldArr1); oldArr1.Get(); cout << endl; Array<Person>oldArr2; oldArr2.Set(Person("Sidor", 10)); oldArr2.Set(Person("Viktor", 8)); oldArr2.Set(Person("Nikolay", 7)); oldArr2.Get(); sortik(oldArr2); oldArr2.Get(); return 0; }
void ADTree3Div :: GetIntersecting (const float * bmin, const float * bmax, Array<int> & pis) const { static Array<ADTreeNode3Div*> stack(1000); static Array<int> stackdir(1000); ADTreeNode3Div * node; int dir, i, stacks; stack.SetSize (1000); stackdir.SetSize(1000); pis.SetSize(0); stack.Elem(1) = root; stackdir.Elem(1) = 0; stacks = 1; while (stacks) { node = stack.Get(stacks); dir = stackdir.Get(stacks); stacks--; if (node->pi) { if (node->data[0] >= bmin[0] && node->data[0] <= bmax[0] && node->data[1] >= bmin[1] && node->data[1] <= bmax[1] && node->data[2] >= bmin[2] && node->data[2] <= bmax[2]) pis.Append (node->pi); } int ndir = dir+1; if (ndir == 3) ndir = 0; int mini = int ( (bmin[dir] - node->minx) / node->dist ); int maxi = int ( (bmax[dir] - node->minx) / node->dist ); // (*testout) << "get int, mini, maxi = " << mini << ", " << maxi << endl; if (mini < 0) mini = 0; if (maxi >= ADTN_DIV) maxi = ADTN_DIV-1; for (i = mini; i <= maxi; i++) if (node->childs[i]) { stacks++; stack.Elem(stacks) = node->childs[i]; stackdir.Elem(stacks) = ndir; } /* if (node->left && bmin[dir] <= node->sep) { stacks++; stack.Elem(stacks) = node->left; stackdir.Elem(stacks) = ndir; } if (node->right && bmax[dir] >= node->sep) { stacks++; stack.Elem(stacks) = node->right; stackdir.Elem(stacks) = ndir; } */ } }
int GetLineNP(int nr) const {return lines.Get(nr)->NP();}
STLLine* GetLine(int nr) const {return lines.Get(nr);}
int GetMarker(int i) const { return chartmark.Get(i); }
void VisualSceneSpecPoints :: DrawScene () { if (!mesh) { VisualScene::DrawScene(); return; } if (changeval != specpoints.Size()) BuildScene(); changeval = specpoints.Size(); glClearColor(backcolor, backcolor, backcolor, 1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable (GL_COLOR_MATERIAL); glColor3f (1.0f, 1.0f, 1.0f); glLineWidth (1.0f); glPushMatrix(); glMultMatrixd (transformationmat); // glEnable (GL_COLOR); // glDisable (GL_COLOR_MATERIAL); if (vispar.drawedtangents) { glColor3d (1, 0, 0); glBegin (GL_LINES); for (int i = 1; i <= specpoints.Size(); i++) { const Point3d p1 = specpoints.Get(i).p; const Point3d p2 = specpoints.Get(i).p + len * specpoints.Get(i).v; glVertex3d (p1.X(), p1.Y(), p1.Z()); glVertex3d (p2.X(), p2.Y(), p2.Z()); } glEnd(); } if (vispar.drawededges) { glColor3d (1, 0, 0); glBegin (GL_LINES); for (int i = 1; i <= mesh->GetNSeg(); i++) { const Segment & seg = mesh -> LineSegment (i); glVertex3dv ( (*mesh)[seg[0]] ); glVertex3dv ( (*mesh)[seg[1]] ); // glVertex3dv ( &(*mesh)[seg[0]].X() ); // glVertex3dv ( &(*mesh)[seg[1]].X() ); } glEnd(); } glColor3d (1, 0, 0); glBegin (GL_LINES); int edges[12][2] = { { 0, 1 }, { 2, 3 }, { 4, 5 }, { 6, 7 }, { 0, 2 }, { 1, 3 }, { 4, 6 }, { 5, 7 }, { 0, 4 }, { 1, 5 }, { 2, 6 }, { 3, 7 } }; for (int i = 0; i < boxes.Size(); i++) { for (int j = 0; j < 12; j++) { glVertex3dv ( boxes[i].GetPointNr(edges[j][0]) ); glVertex3dv ( boxes[i].GetPointNr(edges[j][1]) ); } /* glVertex3dv ( boxes[i].PMin() ); glVertex3dv ( boxes[i].PMax() ); */ } glEnd(); if (vispar.drawededgenrs) { glEnable (GL_COLOR_MATERIAL); GLfloat textcol[3] = { GLfloat(1 - backcolor), GLfloat(1 - backcolor), GLfloat(1 - backcolor) }; glColor3fv (textcol); glNormal3d (0, 0, 1); glPushAttrib (GL_LIST_BIT); // glListBase (fontbase); char buf[20]; for (int i = 1; i <= mesh->GetNSeg(); i++) { const Segment & seg = mesh -> LineSegment (i); const Point3d p1 = mesh -> Point (seg[0]); const Point3d p2 = mesh -> Point (seg[1]); const Point3d p = Center (p1, p2); glRasterPos3d (p.X(), p.Y(), p.Z()); sprintf (buf, "%d", seg.edgenr); // glCallLists (GLsizei(strlen (buf)), GL_UNSIGNED_BYTE, buf); MyOpenGLText (buf); } glPopAttrib (); glDisable (GL_COLOR_MATERIAL); } if (vispar.drawedpoints) { glColor3d (0, 0, 1); /* glPointSize( 3.0 ); float range[2]; glGetFloatv(GL_POINT_SIZE_RANGE, &range[0]); cout << "max ptsize = " << range[0] << "-" << range[1] << endl; glBegin( GL_POINTS ); for (int i = 1; i <= mesh -> GetNP(); i++) { const Point3d & p = mesh -> Point(i); if (i % 2) glVertex3f( p.X(), p.Y(), p.Z()); } glEnd(); */ static GLubyte knoedel[] = { 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, }; glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glDisable (GL_COLOR_MATERIAL); glDisable (GL_LIGHTING); glDisable (GL_CLIP_PLANE0); for (int i = 1; i <= mesh -> GetNP(); i++) { const Point3d & p = mesh -> Point(i); glRasterPos3d (p.X(), p.Y(), p.Z()); glBitmap (7, 7, 3, 3, 0, 0, &knoedel[0]); } } if (vispar.drawedpointnrs) { glEnable (GL_COLOR_MATERIAL); GLfloat textcol[3] = { GLfloat(1 - backcolor), GLfloat(1 - backcolor), GLfloat(1 - backcolor) }; glColor3fv (textcol); glNormal3d (0, 0, 1); glPushAttrib (GL_LIST_BIT); // glListBase (fontbase); char buf[20]; for (int i = 1; i <= mesh->GetNP(); i++) { const Point3d & p = mesh->Point(i); glRasterPos3d (p.X(), p.Y(), p.Z()); sprintf (buf, "%d", i); // glCallLists (GLsizei(strlen (buf)), GL_UNSIGNED_BYTE, buf); MyOpenGLText (buf); } glPopAttrib (); glDisable (GL_COLOR_MATERIAL); } glPopMatrix(); if (vispar.drawcoordinatecross) DrawCoordinateCross (); DrawNetgenLogo (); glFinish(); }
void GetMarkedSeg(int i, Point<3> & ap1, Point<3> & ap2) { ap1=markedsegs.Get(i*2-1); ap2=markedsegs.Get(i*2); }
int main(int argc, char ** argv) { #ifdef PARALLEL // parallel profiling #pragma pomp inst init MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &netgen::ntasks); MPI_Comm_rank(MPI_COMM_WORLD, &netgen::id); MPI_Group MPI_GROUP_WORLD; int n_ho = netgen::ntasks - 1; int * process_ranks = new int[netgen::ntasks-1]; for ( int i = 0; i < netgen::ntasks-1; i++ ) process_ranks[i] = i+1; MPI_Comm_group ( MPI_COMM_WORLD, &MPI_GROUP_WORLD); MPI_Group_incl ( MPI_GROUP_WORLD, n_ho, process_ranks, & netgen::MPI_HIGHORDER_WORLD); MPI_Comm_create ( MPI_COMM_WORLD, netgen::MPI_HIGHORDER_WORLD, & netgen::MPI_HIGHORDER_COMM); #pragma pomp inst begin(main) #endif if ( netgen::id == 0 ) { cout << "NETGEN-" << PACKAGE_VERSION << endl; cout << "Developed at RWTH Aachen University, Germany" << endl << "and Johannes Kepler University Linz, Austria" << endl; #ifdef OCCGEOMETRY cout << "Including OpenCascade geometry kernel" << endl; #endif #ifdef ACIS cout << "Including ACIS geometry kernel" << endl; #endif #ifdef LINUX //feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW); //feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW); //cout << "Handle Floating Point Exceptions: " << fegetexcept() << endl; #endif #ifdef DEBUG cout << "You are running the debug version !" << endl; #endif #ifdef USE_SUPERLU cout << "Including sparse direct solver SuperLU by Lawrence Berkeley National Laboratory" << endl; #endif #ifdef PARALLEL cout << "Including MPI " << endl; cout << "Using " << netgen::ntasks << " processor" << ((netgen::ntasks > 1) ? "s " : " ") << endl; #endif } else { ;// nodisplay = true; } // command line arguments: for (int i = 1; i < argc; i++) { if (argv[i][0] == '-') parameters.SetCommandLineFlag (argv[i]); else parameters.SetFlag ("geofile", argv[i]); } if (getenv ("NETGENDIR") && strlen (getenv ("NETGENDIR"))) ngdir = getenv ("NETGENDIR"); else ngdir = "."; verbose = parameters.GetDefineFlag ("V"); if (verbose) cout << "NETGENDIR = " << ngdir << endl; if ( netgen::id == 0 ) { if (parameters.StringFlagDefined ("testout")) netgen::testout = new ofstream (parameters.GetStringFlag ("testout", "test.out")); #ifdef SOCKETS Ng_ServerSocketManagerInit(static_cast<int>(parameters.GetNumFlag("serversocket",-1))); if(parameters.GetNumFlag("serversocket",-1) > 0 && !parameters.GetDefineFlag("display")) nodisplay = true; #endif if(parameters.GetDefineFlag("batchmode")) nodisplay = true; if(parameters.GetDefineFlag("shellmode")) { nodisplay = true; shellmode = true; } Tcl_FindExecutable(NULL); // initialize application Tcl_Interp * myinterp = Tcl_CreateInterp (); if (Tcl_AppInit (myinterp) == TCL_ERROR) { cerr << "Exit Netgen due to initialization problem" << endl; exit (1); } // parse tcl-script int errcode; bool internaltcl = false; if (shellmode) internaltcl = false; #ifdef PARALLEL internaltcl = false; #endif if (verbose) { cout << "Tcl header version = " << TCL_PATCH_LEVEL << endl; Tcl_Eval (myinterp, "puts \"Tcl runtime version = [info patchlevel] \";"); } if (parameters.GetDefineFlag ("internaltcl")) internaltcl=true; if (parameters.GetDefineFlag ("externaltcl")) internaltcl=false; if (internaltcl) { if (verbose) cout << "using internal Tcl-script" << endl; // connect to one string extern const char * ngscript[]; const char ** hcp = ngscript; int len = 0; while (*hcp) len += strlen (*hcp++); char * tr1 = new char[len+1]; *tr1 = 0; hcp = ngscript; char * tt1 = tr1; while (*hcp) { strcat (tt1, *hcp); tt1 += strlen (*hcp++); } errcode = Tcl_Eval (myinterp, tr1); delete [] tr1; } else { string startfile = ngdir + "/ng.tcl"; if (verbose) cout << "Load Tcl-script from " << startfile << endl; errcode = Tcl_EvalFile (myinterp, (char*)startfile.c_str()); } if (errcode) { cout << "Error in Tcl-Script:" << endl; // cout << "result = " << myinterp->result << endl; cout << "result = " << Tcl_GetStringResult (myinterp) << endl; // cout << "in line " << myinterp->errorLine << endl; cout << "\nMake sure to set environment variable NETGENDIR to directory containing ng.tcl" << endl; exit (1); } // lookup user file formats and insert into format list: Array<const char*> userformats; RegisterUserFormats (userformats); ostringstream fstr; for (int i = 1; i <= userformats.Size(); i++) fstr << ".ngmenu.file.filetype add radio -label \"" << userformats.Get(i) << "\" -variable exportfiletype\n"; Tcl_Eval (myinterp, (char*)fstr.str().c_str()); Tcl_SetVar (myinterp, "exportfiletype", "Neutral Format", 0); // For adding an application, parse the file here, // and call the init-procedure below // #define DEMOAPP #ifdef DEMOAPP Tcl_EvalFile (myinterp, "demoapp/demoapp.tcl"); #endif #ifdef ADDON Tcl_EvalFile (myinterp, "addon/addon.tcl"); #endif #ifdef SOCKETS Ng_ServerSocketManagerRun(); #endif // start event-loop Tk_MainLoop(); Tcl_DeleteInterp (myinterp); #ifdef PARALLEL #pragma pomp inst altend(main) // MPI beenden MPI_Barrier(MPI_COMM_WORLD); MPI_Finalize(); #endif Tcl_Exit(0); } #ifdef PARALLEL else { // main for parallel processors ParallelRun(); #pragma pomp inst end(main) // MPI beenden MPI_Barrier(MPI_COMM_WORLD); MPI_Finalize(); } #endif return 0; }
void WriteJCMFormat (const Mesh & mesh, const NetgenGeometry & geom, const string & filename) { if (mesh.GetDimension() != 3) { cout <<"\n Error: Dimension 3 only supported by this output format!"<<endl; return; } int bc_at_infinity = 0; int i, j, jj, ct(0), counter; double dx1, dx2, dx3, dy1, dy2, dy3, dz1, dz2, dz3, vol; // number of points int np = mesh.GetNP(); // Identic points Array<int,1> identmap1, identmap2, identmap3; mesh.GetIdentifications().GetMap(1, identmap1); mesh.GetIdentifications().GetMap(2, identmap2); mesh.GetIdentifications().GetMap(3, identmap3); // number of volume elements int ne = mesh.GetNE(); int ntets = 0; int nprisms = 0; for (i = 1; i <= ne; i++) { Element el = mesh.VolumeElement(i); if (el.GetNP() == 4) { ntets++; // Check that no two points on a tetrahedron are identified with each other for (j = 1; j <= 4; j++) for (jj = 1; jj <=4; jj++) { if (identmap1.Elem(el.PNum(j)) == el.PNum(jj)) { cout << "\n Error: two points on a tetrahedron identified (1) with each other" << "\n REFINE MESH !" << endl; return; } if (identmap2.Elem(el.PNum(j)) == el.PNum(jj)) { cout << "\n Error: two points on a tetrahedron identified (2) with each other" << "\n REFINE MESH !" << endl; return; } if (identmap3.Elem(el.PNum(j)) == el.PNum(jj)) { cout << "\n Error: two points on a tetrahedron identified (3) with each other" << "\n REFINE MESH !" << endl; return; } } } else if (el.GetNP() == 6) nprisms++; } if ( ne != (ntets+nprisms)) { cout<< "\n Error in determining number of volume elements!\n" << "\n Prisms and tetrahedra only implemented in the JCMwave format!\n"<<endl; return; } if (nprisms > 0) cout << " Please note: Boundaries at infinity have to carry the bc-attribute '-bc=" << bc_at_infinity <<"'."<<endl; // number of surface elements int nse = mesh.GetNSE(); // number of boundary triangles int nbtri = 0; // number of boundary quadrilaterals int nbquad = 0; // array with 1 if point on any tetra, 0 else // this is needed in order to arrange the prism points in the right order Array<int,1> pointsOnTetras; pointsOnTetras.SetSize (mesh.GetNP()); pointsOnTetras = 0; for (i = 1; i <= ne; i++) { Element el = mesh.VolumeElement(i); if (el.GetNP() == 4) { for (j = 1; j <= 4; j++) pointsOnTetras.Set(int (el.PNum(j)),1); } } // number of boundary triangles and boundary quadrilaterals for (i = 1; i <= nse; i++) { Element2d el = mesh.SurfaceElement(i); if (el.GetNP() == 3 && ( mesh.GetFaceDescriptor (el.GetIndex()).DomainIn()==0 || mesh.GetFaceDescriptor (el.GetIndex()).DomainOut()==0 ) ) nbtri++; else if (el.GetNP() == 4 && ( mesh.GetFaceDescriptor (el.GetIndex()).DomainIn()==0 || mesh.GetFaceDescriptor (el.GetIndex()).DomainOut()==0 ) ) nbquad++; } ofstream outfile (filename.c_str()); outfile.precision(6); outfile.setf (ios::fixed, ios::floatfield); outfile.setf (ios::showpoint); outfile << "/* <BLOBHead>\n"; outfile << "__BLOBTYPE__=Grid\n"; outfile << "__OWNER__=JCMwave\n"; outfile << "<I>SpaceDim=3\n"; outfile << "<I>ManifoldDim=3\n"; outfile << "<I>NRefinementSteps=0\n"; outfile << "<I>NPoints="<<np<<"\n"; outfile << "<I>NTetrahedra="<<ntets<<"\n"; outfile << "<I>NPrisms="<<nprisms<<"\n"; outfile << "<I>NBoundaryTriangles="<<nbtri<<"\n"; outfile << "<I>NBoundaryQuadrilaterals="<<nbquad<<"\n"; outfile << "*/\n"; outfile << "\n"; outfile << "# output from Netgen\n\n"; int nDomains=mesh.GetNDomains(); for (i=1; i<=nDomains; i++) { if (mesh.GetMaterial(i)) outfile << "#" << mesh.GetMaterial(i) << ": Material ID = " << i << "\n"; } outfile << "# Points\n"; cout << " Please note: The unit of length in the .geo file is assumed to be 'microns'."<<endl; for (i = 1; i <= np; i++) { const Point<3> & p = mesh.Point(i); outfile << i << "\n"; outfile << p(0) << "e-6\n"; outfile << p(1) << "e-6\n"; outfile << p(2) << "e-6\n\n"; } outfile << "\n"; outfile << "# Tetrahedra\n"; counter = 0; for (i = 1; i <= ne; i++) { Element el = mesh.VolumeElement(i); if (el.GetNP() == 4) { counter++; dx1 = mesh.Point(el.PNum(2))(0) - mesh.Point(el.PNum(1))(0); dx2 = mesh.Point(el.PNum(3))(0) - mesh.Point(el.PNum(1))(0); dx3 = mesh.Point(el.PNum(4))(0) - mesh.Point(el.PNum(1))(0); dy1 = mesh.Point(el.PNum(2))(1) - mesh.Point(el.PNum(1))(1); dy2 = mesh.Point(el.PNum(3))(1) - mesh.Point(el.PNum(1))(1); dy3 = mesh.Point(el.PNum(4))(1) - mesh.Point(el.PNum(1))(1); dz1 = mesh.Point(el.PNum(2))(2) - mesh.Point(el.PNum(1))(2); dz2 = mesh.Point(el.PNum(3))(2) - mesh.Point(el.PNum(1))(2); dz3 = mesh.Point(el.PNum(4))(2) - mesh.Point(el.PNum(1))(2); vol = (dy1*dz2-dz1*dy2)*dx3 + (dz1*dx2-dx1*dz2)*dy3 + (dx1*dy2-dy1*dx2)*dz3; if ( vol > 0 ) for (j = 1; j <= 4; j++) outfile << el.PNum(j)<<"\n"; else { for (j = 2; j >= 1; j--) outfile << el.PNum(j)<<"\n"; for (j = 3; j <= 4; j++) outfile << el.PNum(j)<<"\n"; } outfile << el.GetIndex() << "\n\n"; } } if ( counter != ntets) { cout<< "\n Error in determining number of tetras!\n"<<endl; return; } outfile << "\n"; outfile << "# Prisms\n"; counter = 0; for (i = 1; i <= ne; i++) { Element el = mesh.VolumeElement(i); if (el.GetNP() == 6) { counter++; dx1 = mesh.Point(el.PNum(2))(0) - mesh.Point(el.PNum(1))(0); dx2 = mesh.Point(el.PNum(3))(0) - mesh.Point(el.PNum(1))(0); dx3 = mesh.Point(el.PNum(4))(0) - mesh.Point(el.PNum(1))(0); dy1 = mesh.Point(el.PNum(2))(1) - mesh.Point(el.PNum(1))(1); dy2 = mesh.Point(el.PNum(3))(1) - mesh.Point(el.PNum(1))(1); dy3 = mesh.Point(el.PNum(4))(1) - mesh.Point(el.PNum(1))(1); dz1 = mesh.Point(el.PNum(2))(2) - mesh.Point(el.PNum(1))(2); dz2 = mesh.Point(el.PNum(3))(2) - mesh.Point(el.PNum(1))(2); dz3 = mesh.Point(el.PNum(4))(2) - mesh.Point(el.PNum(1))(2); vol = (dy1*dz2-dz1*dy2)*dx3 + (dz1*dx2-dx1*dz2)*dy3 + (dx1*dy2-dy1*dx2)*dz3; if (pointsOnTetras.Get(el.PNum(1)) && pointsOnTetras.Get(el.PNum(2)) && pointsOnTetras.Get(el.PNum(3))) { if (vol > 0) for (j = 1; j <= 6; j++) outfile << el.PNum(j)<<"\n"; else { for (j = 3; j >= 1; j--) outfile << el.PNum(j)<<"\n"; for (j = 6; j >= 4; j--) outfile << el.PNum(j)<<"\n"; } } else if ( pointsOnTetras.Get(el.PNum(4)) && pointsOnTetras.Get(el.PNum(5)) && pointsOnTetras.Get(el.PNum(6)) ) { if ( vol < 0 ) { for (j = 4; j <= 6; j++) outfile << el.PNum(j)<<"\n"; for (j = 1; j <= 3; j++) outfile << el.PNum(j)<<"\n"; } else { for (j = 6; j >= 4; j--) outfile << el.PNum(j)<<"\n"; for (j = 3; j >= 1; j--) outfile << el.PNum(j)<<"\n"; } } else { cout << "\n Error in determining prism point numbering!\n"<<endl; return; } outfile << el.GetIndex() << "\n\n"; } } if ( counter != nprisms) { cout<< "\n Error in determining number of prisms!\n"<<endl; return; } int npid1 = 0; int npid2 = 0; int npid3 = 0; for (i=1; i<=np; i++) { if (identmap1.Elem(i)) npid1++; if (identmap2.Elem(i)) npid2++; if (identmap3.Elem(i)) npid3++; } outfile << "\n"; outfile << "# Boundary triangles\n"; outfile << "# Number of identified points in 1-direction: " << npid1 << "\n"; outfile << "# Number of identified points in 2-direction: " << npid2 << "\n"; outfile << "# Number of identified points in 3-direction: " << npid3 << "\n"; for (i = 1; i <= nse; i++) { Element2d el = mesh.SurfaceElement(i); if (el.GetNP() == 3 && (mesh.GetFaceDescriptor (el.GetIndex()).DomainIn()==0 || mesh.GetFaceDescriptor (el.GetIndex()).DomainOut()==0)) { outfile <<"# T\n"; for (j = 1; j <= 3; j++) outfile << el.PNum(j)<<"\n"; if (mesh.GetFaceDescriptor (el.GetIndex()).BCProperty()==bc_at_infinity) outfile << 1000 << "\n"; else outfile << mesh.GetFaceDescriptor (el.GetIndex()).BCProperty() << "\n"; if (mesh.GetFaceDescriptor (el.GetIndex()).BCProperty() == bc_at_infinity) outfile << "-2\n\n"; else if (identmap1.Elem(el.PNum(1)) &&identmap1.Elem(el.PNum(2)) &&identmap1.Elem(el.PNum(3))) { outfile << "-1\n"; for (j = 1; j <= 3; j++) outfile << identmap1.Elem(el.PNum(j))<<"\n"; outfile << "\n"; } else if (identmap2.Elem(el.PNum(1)) &&identmap2.Elem(el.PNum(2)) &&identmap2.Elem(el.PNum(3))) { outfile << "-1\n"; for (j = 1; j <= 3; j++) outfile << identmap2.Elem(el.PNum(j))<<"\n"; outfile << "\n"; } else if (identmap3.Elem(el.PNum(1)) &&identmap3.Elem(el.PNum(2)) &&identmap3.Elem(el.PNum(3))) { outfile << "-1\n"; for (j = 1; j <= 3; j++) outfile << identmap3.Elem(el.PNum(j))<<"\n"; outfile << "\n"; } else outfile << "1\n\n"; } } outfile << "\n"; outfile << "# Boundary quadrilaterals\n"; for (i = 1; i <= nse; i++) { Element2d el = mesh.SurfaceElement(i); if (el.GetNP() == 4 && (mesh.GetFaceDescriptor (el.GetIndex()).DomainIn()==0 || mesh.GetFaceDescriptor (el.GetIndex()).DomainOut()==0)) { if (pointsOnTetras.Get(el.PNum(1)) && pointsOnTetras.Get(el.PNum(2))) ct = 0; else if (pointsOnTetras.Get(el.PNum(2)) && pointsOnTetras.Get(el.PNum(3))) ct = 1; else if (pointsOnTetras.Get(el.PNum(3)) && pointsOnTetras.Get(el.PNum(4))) ct = 2; else if (pointsOnTetras.Get(el.PNum(4)) && pointsOnTetras.Get(el.PNum(1))) ct = 3; else cout << "\nWarning: Quadrilateral with inconsistent points found!"<<endl; for (j = 1; j <= 4; j++) { jj = j + ct; if ( jj >= 5 ) jj = jj - 4; outfile << el.PNum(jj)<<"\n"; } outfile << mesh.GetFaceDescriptor (el.GetIndex()).BCProperty() << "\n"; if (mesh.GetFaceDescriptor (el.GetIndex()).BCProperty() == bc_at_infinity) { outfile << "-2\n\n"; cout << "\nWarning: Quadrilateral at infinity found (this should not occur)!"<<endl; } else if ( identmap1.Elem(el.PNum(1)) && identmap1.Elem(el.PNum(2)) && identmap1.Elem(el.PNum(3)) && identmap1.Elem(el.PNum(4)) ) { outfile << "-1\n"; for (j = 1; j <= 4; j++) { jj = j + ct; if ( jj >= 5 ) jj = jj - 4; outfile << identmap1.Elem(el.PNum(jj))<<"\n"; } outfile << "\n"; } else if ( identmap2.Elem(el.PNum(1)) && identmap2.Elem(el.PNum(2)) && identmap2.Elem(el.PNum(3)) && identmap2.Elem(el.PNum(4)) ) { outfile << "-1\n"; for (j = 1; j <= 4; j++) { jj = j + ct; if ( jj >= 5 ) jj = jj - 4; outfile << identmap2.Elem(el.PNum(jj))<<"\n"; } outfile << "\n"; } else if ( identmap3.Elem(el.PNum(1)) && identmap3.Elem(el.PNum(2)) && identmap3.Elem(el.PNum(3)) && identmap3.Elem(el.PNum(4)) ) { outfile << "-1\n"; for (j = 1; j <= 4; j++) { jj = j + ct; if ( jj >= 5 ) jj = jj - 4; outfile << identmap3.Elem(el.PNum(jj))<<"\n"; } outfile << "\n"; } else outfile << "1\n\n"; } } cout << " JCMwave grid file written." << endl; }
void WriteDiffPackFormat (const Mesh & mesh, const CSGeometry & geom, const string & filename) { // double scale = globflags.GetNumFlag ("scale", 1); double scale = 1; ofstream outfile(filename.c_str()); if (mesh.GetDimension() == 3) { // Output compatible to Diffpack grid format // Bartosz Sawicki <*****@*****.**> int np = mesh.GetNP(); int ne = mesh.GetNE(); int nse = mesh.GetNSE(); Array <int> BIname; Array <int> BCsinpoint; int i, j, k, l; outfile.precision(6); outfile.setf (ios::fixed, ios::floatfield); outfile.setf (ios::showpoint); const Element & eldummy = mesh.VolumeElement((int)1); outfile << "\n\n" "Finite element mesh (GridFE):\n\n" " Number of space dim. = 3\n" " Number of elements = " << ne << "\n" " Number of nodes = " << np << "\n\n" " All elements are of the same type : dpTRUE\n" " Max number of nodes in an element: "<< eldummy.GetNP() << "\n" " Only one subdomain : dpFALSE\n" " Lattice data ? 0\n\n\n\n"; for (i = 1; i <= nse; i++) { int BI=mesh.GetFaceDescriptor(mesh.SurfaceElement(i).GetIndex()).BCProperty(); int nbi=BIname.Size(); int found=0; for (j = 1; j <= nbi; j++) if(BI == BIname.Get(j)) found = 1; if( ! found ) BIname.Append(BI); } outfile << " " << BIname.Size() << " Boundary indicators: "; for (i =1 ; i <= BIname.Size(); i++) outfile << BIname.Get(i) << " "; outfile << "\n\n\n"; outfile << " Nodal coordinates and nodal boundary indicators,\n" " the columns contain:\n" " - node number\n" " - coordinates\n" " - no of boundary indicators that are set (ON)\n" " - the boundary indicators that are set (ON) if any.\n" "#\n"; for (i = 1; i <= np; i++) { const Point3d & p = mesh.Point(i); outfile.width(4); outfile << i << " ("; outfile.width(10); outfile << p.X()/scale << ", "; outfile.width(9); outfile << p.Y()/scale << ", "; outfile.width(9); outfile << p.Z()/scale << ") "; if(mesh[PointIndex(i)].Type() != INNERPOINT) { BCsinpoint.DeleteAll(); for (j = 1; j <= nse; j++) { for (k = 1; k <= mesh.SurfaceElement(j).GetNP(); k++) { if(mesh.SurfaceElement(j).PNum(k)==i) { int BC=mesh.GetFaceDescriptor(mesh.SurfaceElement(j).GetIndex()).BCProperty(); int nbcsp=BCsinpoint.Size(); int found = 0; for (l = 1; l <= nbcsp; l++) if(BC == BCsinpoint.Get(l)) found = 1; if( ! found ) BCsinpoint.Append(BC); } } } int nbcsp = BCsinpoint.Size(); outfile << "[" << nbcsp << "] "; for (j = 1; j <= nbcsp; j++) outfile << BCsinpoint.Get(j) << " "; outfile << "\n"; } else outfile << "[0]\n"; } outfile << "\n" " Element types and connectivity\n" " the columns contain:\n" " - element number\n" " - element type\n" " - subdomain number\n" " - the global node numbers of the nodes in the element.\n" "#\n"; for (i = 1; i <= ne; i++) { const Element & el = mesh.VolumeElement(i); outfile.width(5); if(el.GetNP()==4) outfile << i << " ElmT4n3D "; else outfile << i << " ElmT10n3D "; outfile.width(4); outfile << el.GetIndex() << " "; if(el.GetNP()==10) { outfile.width(8); outfile << el.PNum(1); outfile.width(8); outfile << el.PNum(3); outfile.width(8); outfile << el.PNum(2); outfile.width(8); outfile << el.PNum(4); outfile.width(8); outfile << el.PNum(6); outfile.width(8); outfile << el.PNum(8); outfile.width(8); outfile << el.PNum(5); outfile.width(8); outfile << el.PNum(7); outfile.width(8); outfile << el.PNum(10); outfile.width(8); outfile << el.PNum(9); } else { outfile.width(8); outfile << el.PNum(1); outfile.width(8); outfile << el.PNum(3); outfile.width(8); outfile << el.PNum(2); outfile.width(8); outfile << el.PNum(4); } outfile << "\n"; } } /* Diffpack */ else { // Output compatible to Diffpack grid format 2D int np = mesh.GetNP(); //int ne = mesh.GetNE(); int nse = mesh.GetNSE(); Array <int> BIname; Array <int> BCsinpoint; int i, j, k, l; outfile.precision(6); outfile.setf (ios::fixed, ios::floatfield); outfile.setf (ios::showpoint); outfile << "\n\n" "Finite element mesh (GridFE):\n\n" " Number of space dim. = 2\n" " Number of elements = " << nse << "\n" " Number of nodes = " << np << "\n\n" " All elements are of the same type : dpTRUE\n" " Max number of nodes in an element: 3\n" " Only one subdomain : dpFALSE\n" " Lattice data ? 0\n\n\n\n"; for (i = 1; i <= nse; i++) { int BI=mesh.GetFaceDescriptor(mesh.SurfaceElement(i).GetIndex()).BCProperty(); int nbi=BIname.Size(); int found=0; for (j = 1; j <= nbi; j++) if(BI == BIname.Get(j)) found = 1; if( ! found ) BIname.Append(BI); } outfile << " " << BIname.Size() << " Boundary indicators: "; for (i =1 ; i <= BIname.Size(); i++) outfile << BIname.Get(i) << " "; outfile << "\n\n\n"; outfile << " Nodal coordinates and nodal boundary indicators,\n" " the columns contain:\n" " - node number\n" " - coordinates\n" " - no of boundary indicators that are set (ON)\n" " - the boundary indicators that are set (ON) if any.\n" "#\n"; for (i = 1; i <= np; i++) { const Point3d & p = mesh.Point(i); outfile.width(4); outfile << i << " ("; outfile.width(10); outfile << p.X()/scale << ", "; outfile.width(9); outfile << p.Y()/scale << ", "; if(mesh[PointIndex(i)].Type() != INNERPOINT) { BCsinpoint.DeleteAll(); for (j = 1; j <= nse; j++) { for (k = 1; k <= 2; k++) { if(mesh.SurfaceElement(j).PNum(k)==i) { int BC=mesh.GetFaceDescriptor(mesh.SurfaceElement(j).GetIndex()).BCProperty(); int nbcsp=BCsinpoint.Size(); int found = 0; for (l = 1; l <= nbcsp; l++) if(BC == BCsinpoint.Get(l)) found = 1; if( ! found ) BCsinpoint.Append(BC); } } } int nbcsp = BCsinpoint.Size(); outfile << "[" << nbcsp << "] "; for (j = 1; j <= nbcsp; j++) outfile << BCsinpoint.Get(j) << " "; outfile << "\n"; } else outfile << "[0]\n"; } outfile << "\n" " Element types and connectivity\n" " the columns contain:\n" " - element number\n" " - element type\n" " - subdomain number\n" " - the global node numbers of the nodes in the element.\n" "#\n"; for (i = 1; i <= nse; i++) { const Element2d & el = mesh.SurfaceElement(i); outfile.width(5); outfile << i << " ElmT3n2D "; outfile.width(4); outfile << el.GetIndex() << " "; outfile.width(8); outfile << el.PNum(1); outfile.width(8); outfile << el.PNum(3); outfile.width(8); outfile << el.PNum(2); outfile << "\n"; } } }
void Meshing2 :: BlockFillLocalH (Mesh & mesh, const MeshingParameters & mp) { double filldist = mp.filldist; cout << "blockfill local h" << endl; cout << "rel filldist = " << filldist << endl; PrintMessage (3, "blockfill local h"); Array<Point<3> > npoints; // adfront -> CreateTrees(); Box<3> bbox ( Box<3>::EMPTY_BOX ); double maxh = 0; for (int i = 0; i < adfront->GetNFL(); i++) { const FrontLine & line = adfront->GetLine (i); const Point<3> & p1 = adfront->GetPoint(line.L().I1()); const Point<3> & p2 = adfront->GetPoint(line.L().I2()); double hi = Dist (p1, p2); if (hi > maxh) maxh = hi; bbox.Add (p1); bbox.Add (p2); } cout << "bbox = " << bbox << endl; // Point<3> mpc = bbox.Center(); bbox.Increase (bbox.Diam()/2); Box<3> meshbox = bbox; LocalH loch2 (bbox, 1); if (mp.maxh < maxh) maxh = mp.maxh; bool changed; do { mesh.LocalHFunction().ClearFlags(); for (int i = 0; i < adfront->GetNFL(); i++) { const FrontLine & line = adfront->GetLine(i); Box<3> bbox (adfront->GetPoint (line.L().I1())); bbox.Add (adfront->GetPoint (line.L().I2())); double filld = filldist * bbox.Diam(); bbox.Increase (filld); mesh.LocalHFunction().CutBoundary (bbox); } mesh.LocalHFunction().FindInnerBoxes (adfront, NULL); npoints.SetSize(0); mesh.LocalHFunction().GetInnerPoints (npoints); changed = false; for (int i = 0; i < npoints.Size(); i++) { if (mesh.LocalHFunction().GetH(npoints[i]) > 1.5 * maxh) { mesh.LocalHFunction().SetH (npoints[i], maxh); changed = true; } } } while (changed); if (debugparam.slowchecks) (*testout) << "Blockfill with points: " << endl; *testout << "loch = " << mesh.LocalHFunction() << endl; *testout << "npoints = " << endl << npoints << endl; for (int i = 1; i <= npoints.Size(); i++) { if (meshbox.IsIn (npoints.Get(i))) { PointIndex gpnum = mesh.AddPoint (npoints.Get(i)); adfront->AddPoint (npoints.Get(i), gpnum); if (debugparam.slowchecks) { (*testout) << npoints.Get(i) << endl; Point<2> p2d (npoints.Get(i)(0), npoints.Get(i)(1)); if (!adfront->Inside(p2d)) { cout << "add outside point" << endl; (*testout) << "outside" << endl; } } } } // find outer points loch2.ClearFlags(); for (int i = 0; i < adfront->GetNFL(); i++) { const FrontLine & line = adfront->GetLine(i); Box<3> bbox (adfront->GetPoint (line.L().I1())); bbox.Add (adfront->GetPoint (line.L().I2())); loch2.SetH (bbox.Center(), bbox.Diam()); } for (int i = 0; i < adfront->GetNFL(); i++) { const FrontLine & line = adfront->GetLine(i); Box<3> bbox (adfront->GetPoint (line.L().I1())); bbox.Add (adfront->GetPoint (line.L().I2())); bbox.Increase (filldist * bbox.Diam()); loch2.CutBoundary (bbox); } loch2.FindInnerBoxes (adfront, NULL); npoints.SetSize(0); loch2.GetOuterPoints (npoints); for (int i = 1; i <= npoints.Size(); i++) { if (meshbox.IsIn (npoints.Get(i))) { PointIndex gpnum = mesh.AddPoint (npoints.Get(i)); adfront->AddPoint (npoints.Get(i), gpnum); } } }
const MiniElement2d & GetFace (int i) const { return faces.Get(i).Face(); }
STLEdge GetEdge(int nr) {return edges.Get(nr);}
twoint GetExternalEdge(int i) const {return externaledges.Get(i);}
// extern double teterrpow; MESHING3_RESULT MeshVolume (MeshingParameters & mp, Mesh& mesh3d) { int oldne; int meshed; Array<INDEX_2> connectednodes; if (&mesh3d.LocalHFunction() == NULL) mesh3d.CalcLocalH(mp.grading); mesh3d.Compress(); // mesh3d.PrintMemInfo (cout); if (mp.checkoverlappingboundary) if (mesh3d.CheckOverlappingBoundary()) throw NgException ("Stop meshing since boundary mesh is overlapping"); int nonconsist = 0; for (int k = 1; k <= mesh3d.GetNDomains(); k++) { PrintMessage (3, "Check subdomain ", k, " / ", mesh3d.GetNDomains()); mesh3d.FindOpenElements(k); /* bool res = mesh3d.CheckOverlappingBoundary(); if (res) { PrintError ("Surface is overlapping !!"); nonconsist = 1; } */ bool res = (mesh3d.CheckConsistentBoundary() != 0); if (res) { PrintError ("Surface mesh not consistent"); nonconsist = 1; } } if (nonconsist) { PrintError ("Stop meshing since surface mesh not consistent"); throw NgException ("Stop meshing since surface mesh not consistent"); } double globmaxh = mp.maxh; for (int k = 1; k <= mesh3d.GetNDomains(); k++) { if (multithread.terminate) break; PrintMessage (2, ""); PrintMessage (1, "Meshing subdomain ", k, " of ", mesh3d.GetNDomains()); (*testout) << "Meshing subdomain " << k << endl; mp.maxh = min2 (globmaxh, mesh3d.MaxHDomain(k)); mesh3d.CalcSurfacesOfNode(); mesh3d.FindOpenElements(k); if (!mesh3d.GetNOpenElements()) continue; Box<3> domain_bbox( Box<3>::EMPTY_BOX ); for (SurfaceElementIndex sei = 0; sei < mesh3d.GetNSE(); sei++) { const Element2d & el = mesh3d[sei]; if (el.IsDeleted() ) continue; if (mesh3d.GetFaceDescriptor(el.GetIndex()).DomainIn() == k || mesh3d.GetFaceDescriptor(el.GetIndex()).DomainOut() == k) for (int j = 0; j < el.GetNP(); j++) domain_bbox.Add (mesh3d[el[j]]); } domain_bbox.Increase (0.01 * domain_bbox.Diam()); for (int qstep = 1; qstep <= 3; qstep++) { // cout << "openquads = " << mesh3d.HasOpenQuads() << endl; if (mesh3d.HasOpenQuads()) { string rulefile = ngdir; const char ** rulep = NULL; switch (qstep) { case 1: rulefile += "/rules/prisms2.rls"; rulep = prismrules2; break; case 2: // connect pyramid to triangle rulefile += "/rules/pyramids2.rls"; rulep = pyramidrules2; break; case 3: // connect to vis-a-vis point rulefile += "/rules/pyramids.rls"; rulep = pyramidrules; break; } // Meshing3 meshing(rulefile); Meshing3 meshing(rulep); MeshingParameters mpquad = mp; mpquad.giveuptol = 15; mpquad.baseelnp = 4; mpquad.starshapeclass = 1000; mpquad.check_impossible = qstep == 1; // for prisms only (air domain in trafo) for (PointIndex pi = mesh3d.Points().Begin(); pi < mesh3d.Points().End(); pi++) meshing.AddPoint (mesh3d[pi], pi); mesh3d.GetIdentifications().GetPairs (0, connectednodes); for (int i = 1; i <= connectednodes.Size(); i++) meshing.AddConnectedPair (connectednodes.Get(i)); for (int i = 1; i <= mesh3d.GetNOpenElements(); i++) { Element2d hel = mesh3d.OpenElement(i); meshing.AddBoundaryElement (hel); } oldne = mesh3d.GetNE(); meshing.GenerateMesh (mesh3d, mpquad); for (int i = oldne + 1; i <= mesh3d.GetNE(); i++) mesh3d.VolumeElement(i).SetIndex (k); (*testout) << "mesh has " << mesh3d.GetNE() << " prism/pyramid elements" << endl; mesh3d.FindOpenElements(k); } } if (mesh3d.HasOpenQuads()) { PrintSysError ("mesh has still open quads"); throw NgException ("Stop meshing since too many attempts"); // return MESHING3_GIVEUP; } if (mp.delaunay && mesh3d.GetNOpenElements()) { Meshing3 meshing((const char**)NULL); mesh3d.FindOpenElements(k); /* for (PointIndex pi = mesh3d.Points().Begin(); pi < mesh3d.Points().End(); pi++) meshing.AddPoint (mesh3d[pi], pi); */ for (PointIndex pi : mesh3d.Points().Range()) meshing.AddPoint (mesh3d[pi], pi); for (int i = 1; i <= mesh3d.GetNOpenElements(); i++) meshing.AddBoundaryElement (mesh3d.OpenElement(i)); oldne = mesh3d.GetNE(); meshing.Delaunay (mesh3d, k, mp); for (int i = oldne + 1; i <= mesh3d.GetNE(); i++) mesh3d.VolumeElement(i).SetIndex (k); PrintMessage (3, mesh3d.GetNP(), " points, ", mesh3d.GetNE(), " elements"); } int cntsteps = 0; if (mesh3d.GetNOpenElements()) do { if (multithread.terminate) break; mesh3d.FindOpenElements(k); PrintMessage (5, mesh3d.GetNOpenElements(), " open faces"); cntsteps++; if (cntsteps > mp.maxoutersteps) throw NgException ("Stop meshing since too many attempts"); string rulefile = ngdir + "/tetra.rls"; PrintMessage (1, "start tetmeshing"); // Meshing3 meshing(rulefile); Meshing3 meshing(tetrules); Array<int, PointIndex::BASE> glob2loc(mesh3d.GetNP()); glob2loc = -1; for (PointIndex pi = mesh3d.Points().Begin(); pi < mesh3d.Points().End(); pi++) if (domain_bbox.IsIn (mesh3d[pi])) glob2loc[pi] = meshing.AddPoint (mesh3d[pi], pi); for (int i = 1; i <= mesh3d.GetNOpenElements(); i++) { Element2d hel = mesh3d.OpenElement(i); for (int j = 0; j < hel.GetNP(); j++) hel[j] = glob2loc[hel[j]]; meshing.AddBoundaryElement (hel); // meshing.AddBoundaryElement (mesh3d.OpenElement(i)); } oldne = mesh3d.GetNE(); mp.giveuptol = 15 + 10 * cntsteps; mp.sloppy = 5; meshing.GenerateMesh (mesh3d, mp); for (ElementIndex ei = oldne; ei < mesh3d.GetNE(); ei++) mesh3d[ei].SetIndex (k); mesh3d.CalcSurfacesOfNode(); mesh3d.FindOpenElements(k); // teterrpow = 2; if (mesh3d.GetNOpenElements() != 0) { meshed = 0; PrintMessage (5, mesh3d.GetNOpenElements(), " open faces found"); MeshOptimize3d optmesh(mp); const char * optstr = "mcmstmcmstmcmstmcm"; for (size_t j = 1; j <= strlen(optstr); j++) { mesh3d.CalcSurfacesOfNode(); mesh3d.FreeOpenElementsEnvironment(2); mesh3d.CalcSurfacesOfNode(); switch (optstr[j-1]) { case 'c': optmesh.CombineImprove(mesh3d, OPT_REST); break; case 'd': optmesh.SplitImprove(mesh3d, OPT_REST); break; case 's': optmesh.SwapImprove(mesh3d, OPT_REST); break; case 't': optmesh.SwapImprove2(mesh3d, OPT_REST); break; case 'm': mesh3d.ImproveMesh(mp, OPT_REST); break; } } mesh3d.FindOpenElements(k); PrintMessage (3, "Call remove problem"); RemoveProblem (mesh3d, k); mesh3d.FindOpenElements(k); } else { meshed = 1; PrintMessage (1, "Success !"); } } while (!meshed); PrintMessage (1, mesh3d.GetNP(), " points, ", mesh3d.GetNE(), " elements"); } mp.maxh = globmaxh; MeshQuality3d (mesh3d); return MESHING3_OK; }
const Vec3d & GetNormal(int nr) const {return normals.Get(nr);}
const T & Get (const INDEX & ahash) const { int pos = Position (ahash); return cont.Get(pos); }
int GetSpiralPoint(int pn) const {return spiralpoints.Get(pn);};
void GetData (int pos, INDEX & ahash, T & acont) const { ahash = hash.Get(pos); acont = cont.Get(pos); }
STLChart& GetChart(int nr) {return *(atlas.Get(nr));};
void GetData (int pos, T & acont) const { acont = cont.Get(pos); }
int GetLineP(int lnr, int pnr) const {return lines.Get(lnr)->PNum(pnr);}
int UsedPos (int pos) const { return ! (hash.Get(pos).I1() == invalid); }
void WriteFile (int typ, const Mesh & mesh, const CSGeometry & geom, const char * filename, const char * geomfile, double h) { int inverttets = mparam.inverttets; int invertsurf = mparam.inverttrigs; if (typ == WRITE_EDGEELEMENT) { // write edge element file // Peter Harscher, ETHZ cout << "Write Edge-Element Format" << endl; ofstream outfile (filename); int i, j; int ned; // hash table representing edges; INDEX_2_HASHTABLE<int> edgeht(mesh.GetNP()); // list of edges Array<INDEX_2> edgelist; // edge (point) on boundary ? BitArray bedge, bpoint(mesh.GetNP()); static int eledges[6][2] = { { 1, 2 } , { 1, 3 } , { 1, 4 }, { 2, 3 } , { 2, 4 } , { 3, 4 } }; // fill hashtable (point1, point2) ----> edgenr for (i = 1; i <= mesh.GetNE(); i++) { const Element & el = mesh.VolumeElement (i); INDEX_2 edge; for (j = 1; j <= 6; j++) { edge.I1() = el.PNum (eledges[j-1][0]); edge.I2() = el.PNum (eledges[j-1][1]); edge.Sort(); if (!edgeht.Used (edge)) { edgelist.Append (edge); edgeht.Set (edge, edgelist.Size()); } } } // set bedges, bpoints bedge.SetSize (edgelist.Size()); bedge.Clear(); bpoint.Clear(); for (i = 1; i <= mesh.GetNSE(); i++) { const Element2d & sel = mesh.SurfaceElement(i); for (j = 1; j <= 3; j++) { bpoint.Set (sel.PNum(j)); INDEX_2 edge; edge.I1() = sel.PNum(j); edge.I2() = sel.PNum(j%3+1); edge.Sort(); bedge.Set (edgeht.Get (edge)); } } outfile << mesh.GetNE() << endl; // write element ---> point for (i = 1; i <= mesh.GetNE(); i++) { const Element & el = mesh.VolumeElement(i); outfile.width(8); outfile << i; for (j = 1; j <= 4; j++) { outfile.width(8); outfile << el.PNum(j); } outfile << endl; } // write element ---> edge for (i = 1; i <= mesh.GetNE(); i++) { const Element & el = mesh.VolumeElement (i); INDEX_2 edge; for (j = 1; j <= 6; j++) { edge.I1() = el.PNum (eledges[j-1][0]); edge.I2() = el.PNum (eledges[j-1][1]); edge.Sort(); outfile.width(8); outfile << edgeht.Get (edge); } outfile << endl; } // write points outfile << mesh.GetNP() << endl; outfile.precision (6); for (i = 1; i <= mesh.GetNP(); i++) { const Point3d & p = mesh.Point(i); for (j = 1; j <= 3; j++) { outfile.width(8); outfile << p.X(j); } outfile << " " << (bpoint.Test(i) ? "1" : 0) << endl; } // write edges outfile << edgelist.Size() << endl; for (i = 1; i <= edgelist.Size(); i++) { outfile.width(8); outfile << edgelist.Get(i).I1(); outfile.width(8); outfile << edgelist.Get(i).I2(); outfile << " " << (bedge.Test(i) ? "1" : "0") << endl; } } }
const T & GetData (int pos) { return cont.Get(pos); }