qsimpcomp.h

来自「算断裂的」· C头文件 代码 · 共 348 行

H
348
字号
// ------------------------------------------------------------------// qsimpcomp.h//// This file contains the definitions of the class SimpComp and SimpComp_// Under_Construction, which are for simplicial complexes (meshes).// ------------------------------------------------------------------// Author: Stephen A. Vavasis// Copyright (c) 1999 by Cornell University.  All rights reserved.// // See the accompanying file 'Copyright' for authorship information,// the terms of the license governing this software, and disclaimers// concerning this software.// ------------------------------------------------------------------// This file is part of the QMG software.  // Version 2.0 of QMG, release date September 3, 1999.// ------------------------------------------------------------------#ifndef QSIMPCOMP_H#define QSIMPCOMP_H#include "qnamesp.h"extern "C" {#include "MshFmt2.h"}#include "qbrep.h"// ------------------------------------------------------------------// Class QMG::SimpComplex// Holds a mesh.  Is actually a wrapper around the C data structure// Cptc_MshDesc.class QMG::SimpComplex {public:  typedef int VertexOrdinalIndex;  typedef Cptc_Global_Node VertexGlobalIndex;protected:  // The mesh is here.  Cptc_MshDesc* mesh_;  // An aux data structure to map global to ordinal vertex indices.    typedef map<VertexGlobalIndex, VertexOrdinalIndex> GlobalToOrdinalMapType;  mutable GlobalToOrdinalMapType* global_to_ordinal_;  // Protected constructor makes a brep from pieces.  SimpComplex(Cptc_MshDesc* mesh,     GlobalToOrdinalMapType* global_to_ordinal) : mesh_(mesh),    global_to_ordinal_(global_to_ordinal) { }private:  //  no assignment.  void operator=(const SimpComplex&) { }  virtual void verify_global_to_ordinal_() const {    if (global_to_ordinal_) return;    throw_error("Missing global_to_ordinal");  }public:  static const char* io_header_code() {return "mesh_v2.01";}  // Copying just copies pointer    SimpComplex(const SimpComplex& other) : mesh_(other.mesh_),    global_to_ordinal_(other.global_to_ordinal_) {  }  // Member functions to return information about the mesh:  // intrinsic dimension, embedded dimension, number of nodes,  // number of elements, and the Global ID of the brep from  // which this mesh was created.  int gdim() const {return mesh_ -> intrinsic_dimension; }  int embedded_dim() const { return mesh_ -> embedded_dimension; }  int num_nodes() const { return mesh_ -> num_nodes; }  int num_elements() const { return mesh_ -> num_elems; }  int brep_levelsize(int level) const;  string lookup_prop_val(const string& prop) const;  int num_prop_val() const { return mesh_ -> num_prop_val;}  string prop(int i) const { return string(mesh_ -> props[i]);}  string val(int i) const {return string(mesh_ -> vals[i]); }private:  inline VertexOrdinalIndex process_ordinal_vnum_(VertexOrdinalIndex vnumo) const {    if (vnumo < 0 || vnumo >= mesh_ -> num_nodes) {      throw_error("Vertex ordinal index out of range");    }    return vnumo;  }public:  VertexOrdinalIndex global_to_ordinal(VertexGlobalIndex vnum) const {    verify_global_to_ordinal_();    GlobalToOrdinalMapType::const_iterator it =      global_to_ordinal_ -> find(vnum);    if (it == global_to_ordinal_ -> end())      throw_error("Global vertex index not in mesh");    return it -> second;  }    VertexOrdinalIndex global_to_ordinal_nothrow(VertexGlobalIndex vnum) const {    verify_global_to_ordinal_();    GlobalToOrdinalMapType::const_iterator it =      global_to_ordinal_ -> find(vnum);    if (it == global_to_ordinal_ -> end())      return -1;    return it -> second;  }  VertexGlobalIndex ordinal_to_global(VertexOrdinalIndex vnumo) const {#ifdef RANGECHECK    return mesh_ -> nodes[process_ordinal_vnum_(vnumo)].id;#else    return mesh_ -> nodes[vnumo].id;#endif  }  // Member functions to return info about the nodes: real coordinates,  // owning topological face, patch index, parametric coordinates.  Real real_coord_o(VertexOrdinalIndex vnumo, int jj) const;   Real real_coord(VertexGlobalIndex vnum, int jj) const {    return real_coord_o(global_to_ordinal(vnum), jj);  }private:  void check_fspec_(const Brep::Face_Spec& fspec) const;  void check_fspec2_(const Brep::Face_Spec& fspec) const;  void check_seqno_(const Brep::Face_Spec& fspec, int seqno) const;public:  // Member functions to look up nodes adjacent to a top. entity.  int num_node_on_face(const Brep::Face_Spec& fspec) const;  VertexGlobalIndex node_on_face(const Brep::Face_Spec& fspec, int seqno) const;  Brep::PatchIndex patchind_on_face(const Brep::Face_Spec& fspec, int seqno) const;  Real param_coord_on_face(const Brep::Face_Spec& fspec, int seqno, int jj) const;  // Member functions to return info about the elements: the vertices making  // up the element, and the topological faces owning the element's faces.  int num_meshface_on_face(const Brep::Face_Spec& fspec) const;  VertexGlobalIndex node_of_meshface_on_face(const Brep::Face_Spec& fspec,     int seqno,     int jj) const;  virtual ~SimpComplex() { }};// ------------------------------------------------------------------// A derived class that takes a pointer to the C-data structure// for a mesh and constructs the auxiliary data item. // class QMG::SimpComplex_From_FrontEnd : public QMG::SimpComplex {private:  void make_global_to_ordinal_() const;  virtual void verify_global_to_ordinal_() const {    if (!global_to_ordinal_) make_global_to_ordinal_();  }  public:  explicit SimpComplex_From_FrontEnd(Cptc_MshDesc* mesh) :  SimpComplex(mesh, 0) { }  ~SimpComplex_From_FrontEnd();  // Destructive copy & destructive copy using standard  // helper class.private:  class SimpComplex_From_FrontEnd_Returnval {  private:    friend class SimpComplex_From_FrontEnd;    SimpComplex_From_FrontEnd& sref_;    SimpComplex_From_FrontEnd_Returnval(SimpComplex_From_FrontEnd& s, int) :      sref_(s) { }  };public:  // destructive copy semantics (like auto_ptr)  SimpComplex_From_FrontEnd(SimpComplex_From_FrontEnd& other);  SimpComplex_From_FrontEnd(const SimpComplex_From_FrontEnd_Returnval& sucr);   operator SimpComplex_From_FrontEnd_Returnval() {    return SimpComplex_From_FrontEnd_Returnval(*this, 0);  }};// ------------------------------------------------------------------// Class QMG::SimpComplex_Under_Construction// Holds a mesh.  Is actually a wrapper around the C data structure// Cptc_MshDesc.  This routine allows the user to build a simplicial// complex node by node and element by element using member functions.// It maintains data about the present size of all the arrays so// that it can tell when a new malloc is needed.class QMG::SimpComplex_Under_Construction : public QMG::SimpComplex {private:  // These are the max sizes of the allocated arrays in the Cptc_MshDesc   // data structure.  int max_nodes_;  vector<int> max_lev_size_;  vector<int> max_node_edge_;  vector<int> max_edge_edge_;  vector<int> max_node_surf_;  vector<int> max_tri_surf_;  vector<int> max_tet_region_;  int max_prop_val_;  VertexGlobalIndex next_vnum_;  struct Vertex_Bdry_Inc_ {    VertexGlobalIndex vnum;    Brep::Face_Spec fspec;    bool operator<(const Vertex_Bdry_Inc_& other) const;  };  struct Vertex_Pos_ {    Brep::PatchIndex patchind;    double param[2];  };  typedef map<Vertex_Bdry_Inc_, Vertex_Pos_> Vert_Bdry_Lookup_;  Vert_Bdry_Lookup_* vertinclookup_;  struct Face_Bdry_Inc_ {    VertexGlobalIndex meshv[3];    bool operator<(const Face_Bdry_Inc_& other) const;  };  // A data structure to hold mesh entities (higher dim. than vertices)  // lying on a brep boundary.  typedef map<Face_Bdry_Inc_, Brep::Face_Spec> Face_Bdry_Lookup_;  Face_Bdry_Lookup_* faceinclookup_;  // Kills the data structure.  Used when transferring ownership.  void clobber_();  // no assignment  void operator=(const SimpComplex_Under_Construction&) { }  virtual void verify_global_to_ordinal_() const {}public:  // Routine to add a new vertex to the complex.  Need its real coordinates.  // Return its global index.  pair<VertexOrdinalIndex, VertexGlobalIndex>    add_vertex(const vector<Real>& realcoord);  VertexOrdinalIndex add_vertex(const vector<Real>& realcoord,     VertexGlobalIndex vnum);  // For adding records of vertices upon brep faces.  void add_vertex_bdryinc(VertexGlobalIndex vnum,    const Brep::Face_Spec& fspec,    Brep::PatchIndex patchind,    const vector<Real>& param);  Brep::PatchIndex retrieve_vertex_bdryinc_patchind(VertexGlobalIndex vnum,    const Brep::Face_Spec& fspec) const;  Point retrieve_vertex_bdryinc_param(VertexGlobalIndex vnum,    const Brep::Face_Spec& fspec) const;  // For adding faces of dim 1 or higher  void add_simplex_face(const vector<VertexGlobalIndex>& verts,    const Brep::Face_Spec& fspec);  // Constructor starts with an empty simplicial complex.  SimpComplex_Under_Construction(int intrinsic_dim,     int embedded_dim,    const vector<int>& level_size);  void add_fspec(const Brep::Face_Spec& fspec);  void add_prop_val(const string& prop, const string& val);    void remove_unused_vertices();  // Release returns the pointer to the implementation.  This works  // kind of like auto_ptr.  Cptc_MshDesc* release();  ~SimpComplex_Under_Construction();  // See brepstream.cpp for the next one.  This one reads a mesh from an istream  // in ascii format.  static SimpComplex_Under_Construction read_from_istream(istream& istr,     bool code_already_read,    int& line_count);   // Destructive copy & destructive copy using standard  // helper class.private:  class SimpComplex_Under_Construction_Returnval {  private:    friend class SimpComplex_Under_Construction;    SimpComplex_Under_Construction& sref_;    SimpComplex_Under_Construction_Returnval(SimpComplex_Under_Construction& s, int) :      sref_(s) { }  };public:  // destructive copy semantics (like auto_ptr)  SimpComplex_Under_Construction(SimpComplex_Under_Construction& other);  SimpComplex_Under_Construction(const SimpComplex_Under_Construction_Returnval& sucr);   operator SimpComplex_Under_Construction_Returnval() {    return SimpComplex_Under_Construction_Returnval(*this, 0);  }};extern QMG::ostream& operator<<(QMG::ostream& os, const QMG::SimpComplex& sc);#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?