Commit 82f02dc7 authored by Anthony Royer's avatar Anthony Royer

Start implementation

parent 04b24a0d
Pipeline #1874 failed with stage
in 1 minute and 14 seconds
......@@ -5,18 +5,21 @@
#include <string.h>
#include <math.h>
#include <vector>
#include "GeoData.h"
#include "ProData.h"
#include "Pos_Search.h"
#include "MallocUtils.h"
#include "Message.h"
#include "OS.h"
#include "gmsh.h"
#define SQU(a) ((a)*(a))
extern double Flag_ORDER ;
FILE * File_GEO ;
char *name;
struct GeoData * CurrentGeoData ;
......@@ -156,6 +159,7 @@ void Geo_SetCurrentGeoData(struct GeoData * GeoData_P)
void Geo_OpenFile(char * Name, const char * Mode)
{
File_GEO = FOpen(Name, Mode) ;
name = Name;
if (!File_GEO) Message::Error("Unable to open file '%s'", Name);
}
......@@ -413,6 +417,120 @@ static std::string ExtractDoubleQuotedString(const char *str, int len)
return ret;
}
static void Geo_ReadFileWithGmsh(struct GeoData * GeoData_P)
{
gmsh::option::setNumber("General.Terminal", 1);
gmsh::open(name);
/* N O D E S */
struct Geo_Node Geo_Node ;
std::vector<int> nodeTags;
std::vector<double> coord;
std::vector<double> parametricCoord;
gmsh::model::mesh::getNodes(nodeTags, coord, parametricCoord, -1, -1);
if(GeoData_P->Nodes == NULL)
GeoData_P->Nodes = List_Create(nodeTags.size(), 1000, sizeof(struct Geo_Node)) ;
for(unsigned int i = 0; i < nodeTags.size(); i++){
Geo_Node.Num = nodeTags[i];
Geo_Node.x = coord[3*i + 0];
Geo_Node.y = coord[3*i + 1];
Geo_Node.z = coord[3*i + 2];
List_Add(GeoData_P->Nodes, &Geo_Node) ;
if(!i){
GeoData_P->Xmin = GeoData_P->Xmax = Geo_Node.x;
GeoData_P->Ymin = GeoData_P->Ymax = Geo_Node.y;
GeoData_P->Zmin = GeoData_P->Zmax = Geo_Node.z;
}
else{
GeoData_P->Xmin = std::min(GeoData_P->Xmin, Geo_Node.x);
GeoData_P->Xmax = std::max(GeoData_P->Xmax, Geo_Node.x);
GeoData_P->Ymin = std::min(GeoData_P->Ymin, Geo_Node.y);
GeoData_P->Ymax = std::max(GeoData_P->Ymax, Geo_Node.y);
GeoData_P->Zmin = std::min(GeoData_P->Zmin, Geo_Node.z);
GeoData_P->Zmax = std::max(GeoData_P->Zmax, Geo_Node.z);
}
}
if(GeoData_P->Xmin != GeoData_P->Xmax &&
GeoData_P->Ymin != GeoData_P->Ymax &&
GeoData_P->Zmin != GeoData_P->Zmax)
GeoData_P->Dimension = _3D;
else if(GeoData_P->Xmin != GeoData_P->Xmax && GeoData_P->Ymin != GeoData_P->Ymax)
GeoData_P->Dimension = _2D;
else if(GeoData_P->Xmin != GeoData_P->Xmax && GeoData_P->Zmin != GeoData_P->Zmax)
GeoData_P->Dimension = _2D;
else if(GeoData_P->Ymin != GeoData_P->Ymax && GeoData_P->Zmin != GeoData_P->Zmax)
GeoData_P->Dimension = _2D;
else if(GeoData_P->Xmin != GeoData_P->Xmax)
GeoData_P->Dimension = _1D;
else if(GeoData_P->Ymin != GeoData_P->Ymax)
GeoData_P->Dimension = _1D;
else if(GeoData_P->Zmin != GeoData_P->Zmax)
GeoData_P->Dimension = _1D;
else
GeoData_P->Dimension = _0D;
GeoData_P->CharacteristicLength =
sqrt(SQU(GeoData_P->Xmax - GeoData_P->Xmin) +
SQU(GeoData_P->Ymax - GeoData_P->Ymin) +
SQU(GeoData_P->Zmax - GeoData_P->Zmin));
if(!GeoData_P->CharacteristicLength)
GeoData_P->CharacteristicLength = 1.;
coord.clear();
parametricCoord.clear();
/* E L E M E N T S */
struct Geo_Element Geo_Element ;
std::vector<int> elementTypes;
std::vector< std::vector<int> > elementTags;
std::vector< std::vector<int> > elementNodeTags;
gmsh::model::mesh::getElements(elementTypes, elementTags, elementNodeTags, -1, -1);
int nbr = 0;
for(unsigned int i = 0; i < elementTypes.size(); i++){
nbr += elementTags[i].size();
}
if (GeoData_P->Elements == NULL)
GeoData_P->Elements = List_Create(nbr, 1000, sizeof(struct Geo_Element)) ;
Geo_Element.NbrEdges = Geo_Element.NbrFacets = 0 ;
Geo_Element.NumEdges = Geo_Element.NumFacets = NULL ;
gmsh::vectorpair dimTags;
gmsh::model::getEntities(dimTags, -1);
for(unsigned int entity = 0; entity < dimTags.size(); entity++){
gmsh::model::mesh::getElements(elementTypes, elementTags, elementNodeTags, dimTags[entity].first, dimTags[entity].second);
std::vector<int> physicalsTags;
gmsh::model::getPhysicalGroupsForEntity(dimTags[entity].first, dimTags[entity].second, physicalsTags);
if(physicalsTags.size() == 0) continue;
for(unsigned int i = 0; i < elementTypes.size(); i++){
Geo_Element.Type = Geo_GetElementType(FORMAT_GMSH, elementTypes[i]) ;
Geo_Element.NbrNodes = elementNodeTags[i].size()/elementTags[i].size();
for(unsigned int j = 0; j < elementTags[i].size(); j++){
Geo_Element.Num = elementTags[i][j];
Geo_Element.Region = physicalsTags[0];
Geo_Element.ElementaryRegion = dimTags[i].second;
Geo_Element.NumNodes = (int *)Malloc(Geo_Element.NbrNodes * sizeof(int)) ;
for (unsigned int k = 0; k < Geo_Element.NbrNodes; k++)
Geo_Element.NumNodes[k] = elementNodeTags[i][Geo_Element.NbrNodes*j + k];
List_Sort(GeoData_P->Elements, fcmp_Elm) ;
}
}
}
}
void Geo_ReadFile(struct GeoData * GeoData_P)
{
int Nbr, i, j, Type, iDummy, Format, Size, NbTags ;
......@@ -439,10 +557,14 @@ void Geo_ReadFile(struct GeoData * GeoData_P)
if(!fgets(String, sizeof(String), File_GEO)) return;
if(sscanf(String, "%lf %d %d", &Version, &Format, &Size) != 3) return;
if(Version < 2.0 || Version >= 3.1){
if(Version < 2.0){
Message::Error("Unsupported or unknown mesh file version (%g)", Version);
return;
}
else if(Version > 3.1){
Geo_ReadFileWithGmsh(GeoData_P);
return;
}
if(Format){
binary = 1;
......
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