/*! \file mesh.hh \brief 2D triangular mesh with segmented boundary \date 30 April 2010 \author Clemens Pechstein Institute of Computational Mathematics Johannes Kepler University Linz, Austria Tutorials -- Numerical methods for elliptic PDEs summer semester 2010 */ #include "mesh.hh" #include #include #include using namespace std; void Mesh :: reserve (int nV, int nT, int nS) { nVerts = nV; nTrigs = nT; nSegments = nS; verts.resize (nVerts); trigs.resize (nTrigs); segments.resize (nSegments); bcSegments.resize (nSegments); bcVerts.resize (nVerts); for (int i=0; i MapType; typedef pair PairType; MapType edgeInfo; // map edge -> new vertex index MapType::iterator it; int count; PairType p; KeyType key; // generate the set of edges by inserting (duplicates won't be inserted twice!!!) for (int t=0; tsecond = count; ++count; } // reserve for new mesh mesh.reserve (count, 4*nTrigs, 2*nSegments); // copy old verts for (int i=0; isecond] = 0.5 * (verts[it->first[0]] + verts[it->first[1]]); mesh.bcVerts[it->second] = BC_INTERNAL; } // refine triangles int new01, new12, new20; count = 0; /* n[2] * / \ / \ n20 x-----x n12 / \ / \ / \ / \ *-----x-----* n[0] n01 n[1] */ for (int t=0; tsecond; key.set (trigs[t][1], trigs[t][2]); it = edgeInfo.find (key); new12 = it->second; key.set (trigs[t][2], trigs[t][0]); it = edgeInfo.find (key); new20 = it->second; mesh.trigs[count].set (trigs[t][0], new01, new20); ++count; mesh.trigs[count].set (trigs[t][1], new12, new01); ++count; mesh.trigs[count].set (trigs[t][2], new20, new12); ++count; mesh.trigs[count].set (new01, new12, new20); ++count; } count = 0; // refine segments for (int s=0; ssecond; mesh.segments[count].set (segments[s][0], new01); mesh.bcSegments[count] = bcSegments[s]; ++count; mesh.segments[count].set (new01, segments[s][1]); mesh.bcSegments[count] = bcSegments[s]; ++count; mesh.bcVerts[new01] = bcSegments[s]; } } // Mesh :: refineUniform void Mesh :: gmvOutput (const char* filename, const Vector& solution, bool z, const Vector& err) const { bool ok = ((int)solution.size () == nVerts); ofstream ofs; ofs.open (filename); ofs << "gmvinput ascii" << endl << endl; ofs << "nodev " << nVerts << endl; for (int i=0; i p; for (int t=0; t