How can I create multiple volumes from stl files?
Hello.
I want to create a model which is like a combination of t5 and t13.
In other words, I want to...
- Using multiple stl files (one of which is to be used as bounding volume), create a surface loops for each of them.
- Create volumes as holes and a volume formed by surfaces of them and a surface surrounding them.
- Make 3D mesh for each volumes, like t5.
However, t13 method can only create one surface loop by merging stls.
How can I create surface loops per stl file, and accomplish this thing?
Although this is almost the same as t13, I post my own code below just in case.
(I'm a Japanese who wants to make a dll using gmsh, so please excuse my comments being in Japanese and using C++.)
Sincerely...
#include <gmsh.h>
int main(int argc, char** argv)
{
std::string obj = "../resource/OBJ.stl"; // ←This is the Hole!
std::string bound = "../resource/BB.stl"; // ←This is the Bounding Volume!
gmsh::initialize();
gmsh::model::add("TestModel");
// fileを開く
try
{
gmsh::merge(obj);
//gmsh::merge(bound);
}
catch (...)
{
gmsh::logger::write("Could not load STL mesh: bye!");
return false;
}
// メッシュに含まれるすべての離散的な曲線や曲面に対して、それぞれのパラメータを
// 計算して、ジオメトリを作成します
double sharpenAngle = 45.0;
bool includeBoundary = true;
bool forceParametrizablePatches = true;
double curveAngle = 180.0;
gmsh::model::mesh::classifySurfaces(
sharpenAngle * M_PI / 180.,
includeBoundary,
forceParametrizablePatches,
curveAngle * M_PI / 180.
);
gmsh::model::mesh::createGeometry();
// すべてのサーフェスからボリュームを作成します。
std::vector<std::pair<int, int>> surfaces;
gmsh::model::getEntities(surfaces, 2);
std::vector<int> surfaceLoop;
for (auto surf : surfaces) surfaceLoop.push_back(surf.second);
int l = gmsh::model::geo::addSurfaceLoop(surfaceLoop);
int v = gmsh::model::geo::addVolume({ l }); // ←これボリューム
gmsh::model::geo::synchronize();
// サイズフィールドで決められた要素のサイズを指定しています, just because we can :-)
int f = gmsh::model::mesh::field::add("MathEval");
gmsh::model::mesh::field::setString(f, "F", "12");
gmsh::model::mesh::field::setAsBackgroundMesh(f);
gmsh::model::mesh::generate(3);
// GUIを起動
std::set<std::string> args(argv, argv + argc);
if (!args.count("-nopopup"))
{
gmsh::fltk::run();
}
gmsh::finalize();
}
Ahh! I want to tell you another thing about Gmsh SDK!
You know that if you want to use SDK by Visual Studio, you have to rename gmsh.h to gmsh.h_original, and gmsh.h-cwrap to gmsh.h, and also you know how to set up VS project properties right?
There is one more thing you have to do. Change the content in "gmshc.h" like below.
#include <stddef.h>
#define GMSH_API_VERSION "4.8.0"
#define GMSH_API_VERSION_MAJOR 4
#define GMSH_API_VERSION_MINOR 8
#define GMSH_API_VERSION_PATCH 0
//#if defined(GMSH_DLL)
#if defined(GMSH_DLL_EXPORT)
#define GMSH_API __declspec(dllexport)
#else
#define GMSH_API __declspec(dllimport)
#endif
//#else
//define GMSH_API
//#endif
Comment out some macro sentences. Then you can use C++ in Visual Studio comfortably!