Commit 64f85d8f by Christophe Geuzaine

cleanup

parent c686b931
Pipeline #736 passed with stage
in 139 minutes 40 seconds
......@@ -17,5 +17,5 @@ endif(GMSH_LIB MATCHES ".a")
include_directories(${GMSH_INC})
add_executable(mainSimple mainSimple.cpp)
target_link_libraries(mainSimple ${GMSH_LIB} ${LAPACK_LIB} ${BLAS_LIB})
add_executable(t0 t0.cpp)
target_link_libraries(t0 ${GMSH_LIB} ${LAPACK_LIB} ${BLAS_LIB})
#include <cstring>
#include "Gmsh.h"
#include "elasticitySolver.h"
#include "PView.h"
#include "PViewData.h"
void Info (int i, char* c){
printf("%d %s\n",i,c);
}
/*
void InitializeOnelab(std::string sockName, std::string modelName) {
if (!sockName.size()) return;
loader = new onelab::remoteNetworkClient("loader", sockName);
std::vector<std::string> choices;
std::vector<onelab::string> ps;
loader->get(ps,"Elasticity/9Compute"); // ??
ps.resize(1);
ps[0].setName("Elasticity/9Compute");
ps[0].setValue("-solve -pos");
choices.push_back("-solve -pos");
choices.push_back("-pos");
choices.push_back("-solve");
ps[0].setChoices(choices);
loader->set(ps[0]);
ps.resize(1);
ps[0].setName("Elasticity/1ModelName");
ps[0].setValue(modelName);
loader->set(ps[0]);
}
void AddOnelabNumberChoice(std::string name, double val, std::string help)
{
std::vector<double> choices;
std::vector<onelab::number> ps;
loader->get(ps, name);
if(ps.size()){
choices = ps[0].getChoices();
}
else{
ps.resize(1);
ps[0].setName(name);
}
ps[0].setValue(val);
choices.push_back(val);
ps[0].setChoices(choices);
ps[0].setHelp(help);
ps[0].setShortHelp(help);
loader->set(ps[0]);
}
void AddOnelabMaterials (elasticitySolver &e) {
std::vector<onelab::number> ps;
for (int i=0;i<e.elasticFields.size();i++){
std::stringstream ss;//create a stringstream
ss << i;//add number to the stream
std::string mat = "Elasticity/LinearElasticMaterial "+ss.str()+"/Young/";
std::string help = "Young Modulus";
AddOnelabNumberChoice (mat,e.elasticFields[i]._E,help);
mat = "Elasticity/LinearElasticMaterial "+ss.str()+"/Poisson/";
help = "Poisson Ratio";
AddOnelabNumberChoice (mat,e.elasticFields[i]._nu,help);
}
}
void GetSetLoads (elasticitySolver &e) {
// todo
}
void GetSetFixations (elasticitySolver &e) {
// todo
}
*/
void WhatToDoNow(int argc, char *argv[], int &solve, std::string &fileName)
{
int i = 1;
solve = 1;
std::string sockName = "";
while (i < argc) {
if (argv[i][0] == '-') {
if (!strcmp(argv[i]+1, "solve") ||
!strcmp(argv[i]+1, "-solve")) {
solve = 1;
i++;
}
else if (!strcmp(argv[i]+1, "pos") ||
!strcmp(argv[i]+1, "-pos")) {
i++;
}
// else if (!strcmp(argv[i]+1, "onelab")) {
// i++;
// if (i<argc && argv[i][0]!='-') {
// printf("INITIALIZING SOCKET %s\n",argv[i]);
// sockName=argv[i];
// InitializeOnelab(sockName,modelName); i++;
// }
// else {
// printf("Error : Missing address of onelab server");
// }
// }
else if (!strcmp(argv[i]+1, "a")) {
i++;
exit(1);
}
else if (!strcmp(argv[i]+1, "help") || !strcmp(argv[i]+1, "h") ||
!strcmp(argv[i]+1, "-help") || !strcmp(argv[i]+1, "-h")) {
i++;
Info(0, argv[0]);
}
else if (!strcmp(argv[i]+1, "version") ||
!strcmp(argv[i]+1, "-version")) {
i++;
Info(1, argv[0]);
}
else if (!strcmp(argv[i]+1, "info") ||
!strcmp(argv[i]+1, "-info")) {
i++;
Info(2, argv[0]);
}
}
else {
std::string modelName = std::string(argv[i]);
fileName=modelName.substr(0,modelName.find_last_of(".")); // remove extension
// if (modelName)
// modelName = modelName + std::string(".fuk");
i++;
}
}
}
int main (int argc, char* argv[]){
char* a[10];
char name[245];
a[0] = name;
GmshInitialize(1, a);
GmshSetOption("General","Terminal",1.);
// for (int i=0;i<argc;i++)printf("%s\n",argv[i]);
printf("Welcome to the Simple Elasticity Program For Onelab\n");
int solve;
std::string pn;
WhatToDoNow (argc,argv, solve, pn);
elasticitySolver mySolver (1000);
mySolver.setMesh(std::string(pn+".msh").c_str());
mySolver.readInputFile(std::string(pn+".dat").c_str());
if (solve){
mySolver.solve();
PView *pvm = mySolver.buildVonMisesView("vonMises");
PView *pv = mySolver.buildDisplacementView("displacement");
// pv->getData()->writeMSH("disp.msh", false, false);
pv->getData()->writePOS("disp.pos");
pvm->getData()->writePOS("vonMises.pos");
delete pv;
}
return 0;
// solve the problem
// stop gmsh
}
//
// A simple example on how to build a GUI frontend to Gmsh using GLUT
//
#if defined(__APPLE__)
# include <GLUT/glut.h>
#else
# include <GL/glut.h>
#endif
#include "Gmsh.h"
#include "GModel.h"
#include "MElement.h"
#include "drawContext.h"
drawContext *ctx = 0;
class drawContextGlut : public drawContextGlobal{
public:
void draw(){ ctx->draw3d(); ctx->draw2d(); }
const char *getFontName(int index){ return "Helvetica"; }
int getFontSize(){ return 18; }
double getStringWidth(const char *str)
{
return glutBitmapLength(GLUT_BITMAP_HELVETICA_18, (const unsigned char*)str);
}
int getStringHeight(){ return 18; }
int getStringDescent(){ return 6; }
void drawString(const char *str)
{
for (int i = 0; i < strlen(str); i++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, str[i]);
}
};
// GLUT callbacks
void display()
{
glViewport(ctx->viewport[0], ctx->viewport[1],
ctx->viewport[2], ctx->viewport[3]);
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
drawContext::global()->draw();
glutSwapBuffers();
}
void reshape(int w, int h)
{
ctx->viewport[2] = w;
ctx->viewport[3] = h;
display();
}
void keyboard(unsigned char key, int x, int y)
{
switch(key){
case '1': GModel::current()->mesh(1); break;
case '2': GModel::current()->mesh(2); break;
case '3': GModel::current()->mesh(3); break;
}
display();
}
static int xprev = 0, yprev = 0, specialkey = 0;
void motion(int x, int y)
{
int w = ctx->viewport[2];
int h = ctx->viewport[3];
if(specialkey == GLUT_ACTIVE_SHIFT){
double dx = x - xprev;
double dy = y - yprev;
if(fabs(dy) > fabs(dx)) {
double fact = (4. * fabs(dy) + h) / (double)h;
ctx->s[0] *= ((dy > 0) ? fact : 1. / fact);
ctx->s[1] = ctx->s[0];
ctx->s[2] = ctx->s[0];
}
}
else{
ctx->addQuaternion((2. * xprev - w) / w, (h - 2. * yprev) / h,
(2. * x - w) / w, (h - 2. * y) / h);
}
xprev = x;
yprev = y;
display();
}
void mouse(int button, int state, int x, int y)
{
specialkey = glutGetModifiers();
xprev = x;
yprev = y;
}
int main(int argc, char **argv)
{
GmshInitialize(argc, argv);
GmshSetOption("General", "Terminal", 1.);
GmshSetOption("View", "IntervalsType", 1.);
GmshSetOption("View", "AdaptVisualizationGrid", 1.);
GmshSetOption("View", "TargetError", 0.00001);
GmshSetOption("View", "MaxRecursionLevel", 3.);
for(int i = 1; i < argc; i++) GmshMergeFile(argv[i]);
ctx = new drawContext();
drawContext::setGlobal(new drawContextGlut);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(ctx->viewport[2], ctx->viewport[3]);
glutInitWindowPosition(100, 100);
glutCreateWindow("GLUT Gmsh Viewer");
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMotionFunc(motion);
glutMouseFunc(mouse);
glutMainLoop();
GmshFinalize();
return 0;
}
// Gmsh - Copyright (C) 1997-2017 C. Geuzaine, J.-F. Remacle
//
// See the LICENSE.txt file for license information. Please report all
// bugs and problems to the public mailing list <gmsh@onelab.info>.
//
// Contributed by Matti Pellikka <matti.pellikka@tut.fi>.
//
#include <stdio.h>
#include <sstream>
#include "Gmsh.h"
#include "GModel.h"
#include "MElement.h"
#include "CellComplex.h"
#include "Homology.h"
int main(int argc, char **argv)
{
GmshInitialize(argc, argv);
GModel *m = new GModel();
m->readGEO("model.geo");
m->mesh(3);
// OR
// m->readMSH("model.msh");
// List of physical regions as domain for homology computation
// (relative to subdomain).
std::vector<int> domain;
std::vector<int> subdomain;
std::vector<int> physicalIm;
// initialize
Homology* homology = new Homology(m, domain, subdomain, physicalIm);
// find homology basis elements
homology->findHomologyBasis();
// find cohomology basis elements
homology->findCohomologyBasis();
// add 1 and 2 dimensional result chains to model
homology->addChainsToModel(1);
homology->addChainsToModel(2);
homology->addCochainsToModel(1);
homology->addCochainsToModel(2);
// write mesh with (co)homology computation result chains
m->writeMSH("model_hom.msh");
delete homology;
delete m;
GmshFinalize();
}
#include "Gmsh.h"
#include "GModel.h"
#include "MVertex.h"
#include "PView.h"
#include "PViewData.h"
#include "PluginManager.h"
int main(int argc, char **argv)
{
GmshInitialize(argc, argv);
GmshSetOption("General", "Terminal", 1.);
// load a geometry and mesh it
GModel *m = new GModel();
m->readGEO("../../tutorial/t1.geo");
m->mesh(2);
// create a node-based post-processing dataset
std::vector<GEntity*> entities;
m->getEntities(entities);
std::map<int, std::vector<double> > d;
for(unsigned int i = 0; i < entities.size(); i++){
for(unsigned int j = 0; j < entities[i]->getNumMeshVertices(); j++){
MVertex *v = entities[i]->getMeshVertex(j);
d[v->getNum()].push_back(v->x());
}
}
PView *p = new PView("f(x,y,z) = x", "NodeData", m, d);
p->getData()->writeMSH("f.msh");
// use a plugin on the dataset
PluginManager::instance()->setPluginOption("CutPlane", "A", 0.);
PluginManager::instance()->setPluginOption("CutPlane", "B", 1.);
PluginManager::instance()->setPluginOption("CutPlane", "C", 0.);
PluginManager::instance()->setPluginOption("CutPlane", "D", -0.05);
PluginManager::instance()->setPluginOption("CutPlane", "View", 0.);
PluginManager::instance()->action("CutPlane", "Run", 0);
PView::list.back()->getData()->writeMSH("fcut.msh");
GmshFinalize();
}
#include <stdio.h>
#include "Gmsh.h"
#include "GModel.h"
#include "MTetrahedron.h"
#include "MTriangle.h"
int main(int argc, char **argv)
{
GmshInitialize(argc, argv);
GModel *m = new GModel();
m->readMSH("../problem.msh");
for(GModel::riter it = m->firstRegion(); it != m->lastRegion(); ++it){
GRegion *r = *it;
for(unsigned int i = 0; i < r->tetrahedra.size(); i++)
printf(" tet %d: vertices %d %d %d %d\n", r->tetrahedra[i]->getNum(),
r->tetrahedra[i]->getVertex(0)->getNum(),
r->tetrahedra[i]->getVertex(1)->getNum(),
r->tetrahedra[i]->getVertex(2)->getNum(),
r->tetrahedra[i]->getVertex(3)->getNum());
}
for(GModel::fiter it = m->firstFace(); it != m->lastFace(); ++it){
GFace *f = *it;
for(unsigned int i = 0; i < f->triangles.size(); i++)
printf(" tri %d: vertices %d %d %d\n", f->triangles[i]->getNum(),
f->triangles[i]->getVertex(0)->getNum(),
f->triangles[i]->getVertex(1)->getNum(),
f->triangles[i]->getVertex(2)->getNum());
}
delete m;
GmshFinalize();
}
#include <stdio.h>
#include "Gmsh.h"
#include "GModel.h"
#include "MElement.h"
#include "discreteRegion.h"
int main(int argc, char **argv)
{
GmshInitialize(argc, argv);
GmshSetOption("General", "Terminal", 1.);
GmshSetOption("General", "Verbosity", 4.);
GmshSetOption("Mesh", "CharacteristicLengthExtendFromBoundary", 1.);
GmshSetOption("Mesh", "OldRefinement", 1.);
GmshSetOption("Mesh", "CharacteristicLengthMin", 0.1);
GmshSetOption("Mesh", "CharacteristicLengthMax", 0.1);
GmshSetOption("Mesh", "Optimize", 0.); // not yet: need boundary!
GModel *m = new GModel();
m->readMSH("cube.msh");
// discreteRegion *gr = new discreteRegion(m);
// MVertex *v0 = new MVertex(x, y, z, gr, tag);
// MVertex *v1 = new MVertex(x, y, z, gr, tag);
// ...
// gr->mesh_vertices.push_back(v0);
// ...
// MTetrahedron *t = new MTetrahedron(v0, v1, v2, v3, tag);
// gr->tetrahedra.push_back(t);
//MVertex *v2 = gr->mesh_vertices[2];
for(GModel::riter it = m->firstRegion(); it != m->lastRegion(); ++it){
discreteRegion *r = dynamic_cast<discreteRegion*>(*it);
if(r){
printf("found a discrete region (%d) with %d tetrahedra\n", r->tag(), r->tetrahedra.size());
r->remesh();
printf("after remeshing: %d tetrahedra\n", r->tetrahedra.size());
}
}
m->writeMSH("new.msh");
delete m;
GmshFinalize();
}
#include <stdio.h>
#include "Gmsh.h"
#include "GModel.h"
#include "MElement.h"
#include "VertexArray.h"
int main(int argc, char **argv)
{
GmshInitialize(argc, argv);
GmshSetOption("Mesh", "Algorithm", 5.);
GmshSetOption("General", "Terminal", 1.);
GModel *m = new GModel();
m->readMSH("bunny.msh");
m->fillVertexArrays();
std::vector<GEntity*> entities;
m->getEntities(entities);
for(unsigned int i = 0; i < entities.size(); i++){
GEntity *ge = entities[i];
printf("coucou entite %d (dimension %d)\n", ge->tag(), ge->dim());
if(ge->va_triangles)
printf(" j'ai un va de triangles: %d vertex\n", ge->va_triangles->getNumVertices());
if(ge->va_lines)
printf(" j'ai un va de lignes: %d vertex\n", ge->va_lines->getNumVertices());
}
delete m;
GmshFinalize();
}
onelab.number Material1.Create(1);
onelab.string Material.Add(Material1); Material.Add(Material2); Material.Add(Material3);
onelab.iftrue(Material1)
onelab.number E.Create(100.e9); Nu.Create(0.3);
onelab.endif
onelab.iftrue(Material2)
onelab.number E.Create(200.e9); Nu.Create(0.25);
onelab.endif
onelab.iftrue(Material3)
onelab.number E.Create(80.e9); Nu.Create(0.5);
onelab.endif
ElasticDomain 7 onelab.getValue(E) onelab.getValue(Nu);
EdgeDisplacement 8 0 0
EdgeDisplacement 8 1 0
EdgeDisplacement 8 2 0
EdgeForce 9 100e6 0 0
Mesh.RecombinationAlgorithm=1;
Mesh.Algorithm = 8;
unit = 1.0e-02 ;
DefineConstant[ H = {4.5 * unit, Min 1 *unit, Max 8.5 *unit, Step 1*unit,
Name "Parameters/Geometry/Beam Height"} ] ;
DefineConstant[ L = {20 * unit, Min 10 *unit, Max 200 *unit, Step 1*unit,
Name "Parameters/Geometry/Beam Width"} ] ;
DefineConstant[ lc = {2 * unit, Min .1 *unit, Max 10 *unit, Step .1*unit,
Name "Parameters/Geometry/Mesh Size"} ] ;
Point(1) = {0, 0, 0, lc};
Point(2) = {H, 0, 0, lc};
Point(3) = {H, L, 0, lc};
Point(4) = {0, L, 0, lc};
Line(1) = {4, 3};
Line(2) = {3, 2};
Line(3) = {2, 1};
Line(4) = {1, 4};
Line Loop(5) = {2, 3, 4, 1};
Plane Surface(6) = {5};
Physical Surface(7) = {6};
Physical Line(8) = {1};
Physical Line(9) = {3};
Recombine Surface {6};
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