Program Listing for File TetMesh.h¶
↰ Return to documentation for file (include/gamer/TetMesh.h
)
// This file is part of the GAMer software.
// Copyright (C) 2016-2021
// by Christopher T. Lee and contributors
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, see <http://www.gnu.org/licenses/>
// or write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
// Boston, MA 02111-1307 USA
#pragma once
#include <memory>
#include <sstream>
#include <string>
#include <unordered_set>
#include <utility>
#include <gamer/gamer.h>
#define TETLIBRARY
#include <tetgen.h>
#include <casc/casc>
#include "gamer/SurfaceMesh.h"
#include "gamer/Vertex.h"
class tetgenio;
namespace gamer {
struct TMGlobal {
bool higher_order;
};
struct TMVertexProperties {
double error;
TMVertexProperties() : error(-1) {}
TMVertexProperties(double error) : error(error) {}
};
struct TMVertex : Vertex, TMVertexProperties {
TMVertex() : TMVertex(Vertex(), TMVertexProperties()) {}
template <typename... Args>
TMVertex(Args &&... args) : TMVertex(Vertex(std::forward<Args>(args)...)) {}
TMVertex(Vertex v) : TMVertex(v, TMVertexProperties(-1)) {}
TMVertex(Vertex v, TMVertexProperties p) : Vertex(v), TMVertexProperties(p) {}
friend std::ostream &operator<<(std::ostream &output, const TMVertex &v) {
output << "TMVertex(x:" << v[0] << ",y:" << v[1] << ",z:" << v[2]
<< ";m:" << v.marker << ";sel:" << v.selected << ";err:" << v.error
<< ")";
return output;
}
std::string to_string() const {
std::ostringstream output;
output << *this;
return output.str();
}
};
struct TMEdge : Vertex {
using Vertex::Vertex;
friend std::ostream &operator<<(std::ostream &output, const TMEdge &v) {
output << "TMEdge(x:" << v[0] << ",y:" << v[1] << ",z:" << v[2]
<< ";m:" << v.marker << ";sel:" << v.selected << ")";
return output;
}
std::string to_string() const {
std::ostringstream output;
output << *this;
return output.str();
}
};
struct TMFaceProperties {
int marker;
bool selected;
};
struct TMFace : TMFaceProperties {
TMFace() : TMFace(TMFaceProperties{-1, false}) {}
TMFace(int marker, bool selected)
: TMFace(TMFaceProperties{marker, selected}) {}
TMFace(TMFaceProperties prop) : TMFaceProperties(prop) {}
friend std::ostream &operator<<(std::ostream &output, const TMFace &f) {
output << "TMFace("
<< "m:" << f.marker << ";sel:" << f.selected << ")";
return output;
}
std::string to_string() const {
std::ostringstream output;
output << *this;
return output.str();
}
};
struct TMCellProperties {
int marker;
bool selected;
};
struct TMCell : casc::Orientable, TMCellProperties {
TMCell() : TMCell(-1, false) {}
TMCell(int marker, bool selected) : TMCell(0, marker, selected) {}
TMCell(int orient, int marker, bool selected)
: TMCell(Orientable{orient}, TMCellProperties{marker, selected}) {}
TMCell(Orientable orient, TMCellProperties prop)
: Orientable(orient), TMCellProperties(prop) {}
friend std::ostream &operator<<(std::ostream &output, const TMCell &c) {
output << "tetmesh::Cell("
<< "m:" << c.marker << ";sel:" << std::boolalpha << c.selected
<< ";o:" << c.orientation << ")";
return output;
}
std::string to_string() const {
std::ostringstream output;
output << *this;
return output.str();
}
};
namespace tetmesh_detail {
struct tetmesh_traits {
using KeyType = int;
using NodeTypes =
util::type_holder<TMGlobal, TMVertex, TMEdge, TMFace, TMCell>;
using EdgeTypes = util::type_holder<casc::Orientable, casc::Orientable,
casc::Orientable, casc::Orientable>;
};
} // end namespace tetmesh_detail
using TetMesh = casc::simplicial_complex<tetmesh_detail::tetmesh_traits>;
std::unique_ptr<TetMesh> tetgenioToTetMesh(tetgenio &tetio);
std::unique_ptr<TetMesh>
makeTetMesh(const std::vector<SurfaceMesh const *> &surfmeshes,
std::string tetgen_params);
std::unique_ptr<SurfaceMesh> extractSurface(const TetMesh &mesh);
void smoothMesh(TetMesh &mesh);
void writeVTK(const std::string &filename, const TetMesh &mesh);
void writeOFF(const std::string &filename, const TetMesh &mesh);
void writeDolfin(const std::string &filename, const TetMesh &mesh);
void writeComsol(const std::string &filename, const TetMesh &mesh);
void writeTriangle(const std::string &filename, const TetMesh &mesh);
// void writeMCSF(const std::string &filename, const TetMesh &mesh);
// void writeDiffPack
// void writeCARP
std::unique_ptr<TetMesh> readDolfin(const std::string &filename);
} // end namespace gamer