Commit e8e09730 by Christophe Geuzaine

basic gmsh, gmshOption and gmshModel API is ok

parent 083a6564
Pipeline #739 passed with stage
in 159 minutes 30 seconds
......@@ -341,37 +341,128 @@ int gmshModelSetMeshSize(int dim, int tag, double size)
int gmshModelSetTransfiniteLine(int tag, int nPoints, int type, double coef)
{
return 0;
GEdge *ge = GModel::current()->getEdgeByTag(tag);
if(ge){
ge->meshAttributes.method = MESH_TRANSFINITE;
ge->meshAttributes.nbPointsTransfinite = nPoints;
ge->meshAttributes.typeTransfinite = type;
ge->meshAttributes.coeffTransfinite = coef;
return 0;
}
return 1;
}
int gmshModelSetTransfiniteSurface(int tag, int arrangement,
const std::vector<int> &cornerTags)
{
return 0;
GFace *gf = GModel::current()->getFaceByTag(tag);
if(gf){
gf->meshAttributes.method = MESH_TRANSFINITE;
gf->meshAttributes.transfiniteArrangement = arrangement;
if(cornerTags.empty() || cornerTags.size() == 3 || cornerTags.size() == 4){
for(unsigned int j = 0; j < cornerTags.size(); j++){
GVertex *gv = GModel::current()->getVertexByTag(cornerTags[j]);
if(gv)
gf->meshAttributes.corners.push_back(gv);
}
}
return 0;
}
return 1;
}
int gmshModelSetTransfiniteVolume(int tag, const std::vector<int> &cornerTags)
{
return 0;
GRegion *gr = GModel::current()->getRegionByTag(tag);
if(gr){
gr->meshAttributes.method = MESH_TRANSFINITE;
if(cornerTags.empty() || cornerTags.size() == 6 || cornerTags.size() == 8){
for(unsigned int i = 0; i < cornerTags.size(); i++){
GVertex *gv = GModel::current()->getVertexByTag(cornerTags[i]);
if(gv)
gr->meshAttributes.corners.push_back(gv);
}
}
return 0;
}
return 1;
}
int gmshModelSetRecombine(int dim, int tag, double angle)
{
return 0;
GFace *gf = GModel::current()->getFaceByTag(tag);
if(gf){
gf->meshAttributes.recombine = 1;
gf->meshAttributes.recombineAngle = angle;
return 0;
}
return 1;
}
int gmshModelSetSmoothing(int tag, int val)
{
return 0;
GFace *gf = GModel::current()->getFaceByTag(tag);
if(gf){
gf->meshAttributes.transfiniteSmoothing = val;
return 0;
}
return 1;
}
int gmshModelSetReverseMesh(int dim, int tag)
{
if(dim == 1){
GEdge *ge = GModel::current()->getEdgeByTag(tag);
if(ge) ge->meshAttributes.reverseMesh = 1;
}
else if(dim == 2){
GFace *gf = GModel::current()->getFaceByTag(tag);
if(gf) gf->meshAttributes.reverseMesh = 1;
}
return 0;
}
int gmshModelAddEmbeddedVertex(int tag, int inDim, int inTag)
{
int gmshModelAddEmbedded(int dim, const std::vector<int> &tags, int toDim, int toTag)
{
if(toDim == 2){
GFace *gf = GModel::current()->getFaceByTag(toTag);
if(gf){
for(unsigned int i = 0; i < tags.size(); i++){
if(dim == 0){
GVertex *gv = GModel::current()->getVertexByTag(tags[i]);
if(gv)
gf->addEmbeddedVertex(gv);
}
else if(dim == 1){
GEdge *ge = GModel::current()->getEdgeByTag(tags[i]);
if(ge)
gf->addEmbeddedEdge(ge);
}
}
}
}
else if(toDim == 3){
GRegion *gr = GModel::current()->getRegionByTag(toTag);
if(gr){
for(unsigned int i = 0; i < tags.size(); i++){
if(dim == 0){
GVertex *gv = GModel::current()->getVertexByTag(tags[i]);
if(gv)
gr->addEmbeddedVertex(gv);
}
else if(dim == 1){
GEdge *ge = GModel::current()->getEdgeByTag(tags[i]);
if(ge)
gr->addEmbeddedEdge(ge);
}
else if(dim == 2){
GFace *gf = GModel::current()->getFaceByTag(tags[i]);
if(gf)
gr->addEmbeddedFace(gf);
}
}
}
}
return 0;
}
......
......@@ -78,7 +78,8 @@ GMSH_API gmshModelSetTransfiniteVolume(int tag, const std::vector<int> &cornerTa
GMSH_API gmshModelSetRecombine(int dim, int tag, double angle);
GMSH_API gmshModelSetSmoothing(int tag, int val);
GMSH_API gmshModelSetReverseMesh(int dim, int tag);
GMSH_API gmshModelAddEmbeddedVertex(int tag, int inDim, int inTag);
GMSH_API gmshModelAddEmbedded(int dim, const std::vector<int> &tags,
int toDim, int toTag);
// gmshModelGeo
GMSH_API gmshModelGeoAddVertex(int &tag, double x, double y, double z, double lc);
......
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
# TODO: Gmsh will should create a cmake file when installing the lib, so all the
# external dependencies can be obtained automatically
find_library(GMSH_LIB gmsh)
if(NOT GMSH_LIB)
message(FATAL_ERROR "Could not find libgmsh")
......@@ -17,5 +20,8 @@ endif(GMSH_LIB MATCHES ".a")
include_directories(${GMSH_INC})
add_executable(t0 t0.cpp)
target_link_libraries(t0 ${GMSH_LIB} ${LAPACK_LIB} ${BLAS_LIB})
add_executable(basic basic.cpp)
target_link_libraries(basic ${GMSH_LIB} ${LAPACK_LIB} ${BLAS_LIB})
add_executable(basic2 basic2.cpp)
target_link_libraries(basic2 ${GMSH_LIB} ${LAPACK_LIB} ${BLAS_LIB})
#include <iostream>
#include <gmsh.h>
int main(int argc, char **argv)
{
if(argc < 2){
std::cout << "Usage: " << argv[0] << " file.geo [options]" << std::endl;
return 1;
}
gmshInitialize();
gmshOptionSetNumber("General.Terminal", 1);
gmshOpen(argv[1]);
gmshModelMesh(3);
gmshExport("test.msh");
gmshFinalize();
return 0;
}
......@@ -4,26 +4,33 @@
int main(int argc, char **argv)
{
if(argc < 2){
std::cout << "Usage: " << argv[0] << " file.geo [options]\n";
std::cout << "Usage: " << argv[0] << " file.geo [options]" << std::endl;
return 1;
}
gmshInitialize();
gmshOptionSetNumber("General.Terminal", 1);
gmshOptionSetNumber("Mesh.Algorithm", 5);
gmshOpen(argv[1]);
gmshModelMesh(3);
// get all elementary entities in the model
std::vector<std::pair<int, int> > entities;
gmshModelGetEntities(entities);
for(unsigned int i = 0; i < entities.size(); i++){
// get the mesh vertices for each elementary entity
std::vector<int> vertexTags;
std::vector<double> vertexCoords;
int dim = entities[i].first, tag = entities[i].second;
gmshModelGetMeshVertices(dim, tag, vertexTags, vertexCoords);
// get the mesh elements for each elementary entity
std::vector<int> elemTypes;
std::vector<std::vector<int> > elemTags, elemVertexTags;
gmshModelGetMeshElements(dim, tag, elemTypes, elemTags, elemVertexTags);
// report some statistics
int numElem = 0;
for(unsigned int i = 0; i < elemTags.size(); i++)
numElem += elemTags[i].size();
......@@ -32,8 +39,6 @@ int main(int argc, char **argv)
<< dim << "," << tag << ")\n";
}
gmshExport("test.msh");
gmshExport("test.unv");
gmshFinalize();
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment