initial upload
This commit is contained in:
25
gmshinfo/CMakeLists.txt
Normal file
25
gmshinfo/CMakeLists.txt
Normal file
@@ -0,0 +1,25 @@
|
||||
set(TOOL_NAME gmshinfo)
|
||||
set(BIN_DIR bin)
|
||||
set(INSTALL_DIR sbin)
|
||||
|
||||
find_package(GCTL REQUIRED)
|
||||
include_directories(${GCTL_INC_DIR})
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
|
||||
if(WIN32)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
|
||||
else()
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
|
||||
endif()
|
||||
|
||||
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/${BIN_DIR})
|
||||
|
||||
aux_source_directory(. TOOL_SRC)
|
||||
add_executable(${TOOL_NAME} ${TOOL_SRC})
|
||||
|
||||
set_target_properties(${TOOL_NAME} PROPERTIES INSTALL_RPATH /usr/local/lib)
|
||||
set_target_properties(${TOOL_NAME} PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
target_link_libraries(${TOOL_NAME} PUBLIC ${GCTL_LIB})
|
||||
|
||||
install(TARGETS ${TOOL_NAME} RUNTIME DESTINATION ${INSTALL_DIR})
|
68
gmshinfo/gmshinfo.cpp
Normal file
68
gmshinfo/gmshinfo.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. 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
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#include "gmshinfo.h"
|
||||
|
||||
void disp_help()
|
||||
{
|
||||
gctl::display_logo(std::clog);
|
||||
|
||||
std::clog << "gmshinfo 0.1 - inspect a Gmsh .msh file and show relative infomation" << std::endl << std::endl
|
||||
<< "syntax: gmshinfo <filename> [filename ...]" << std::endl
|
||||
<< "The program takes at least one filename for the input information, and it only support ASCII format." << std::endl;
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) try
|
||||
{
|
||||
|
||||
char* filename;
|
||||
|
||||
if (argc == 1)
|
||||
{
|
||||
disp_help();
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 1; i < argc; ++i)
|
||||
{
|
||||
MshInfo meshone;
|
||||
filename = argv[i];
|
||||
meshone.init();
|
||||
if(!meshone.readmsh(filename))
|
||||
{
|
||||
meshone.relese_node_id();
|
||||
meshone.showinfo();
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
598
gmshinfo/gmshinfo.h
Normal file
598
gmshinfo/gmshinfo.h
Normal file
@@ -0,0 +1,598 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. 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
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#ifndef _FUNC_H
|
||||
#define _FUNC_H
|
||||
#include "iostream"
|
||||
#include "fstream"
|
||||
#include "sstream"
|
||||
#include "stdio.h"
|
||||
#include "string.h"
|
||||
#include "iomanip"
|
||||
#include "list"
|
||||
#include "algorithm"
|
||||
#include "map"
|
||||
|
||||
#include "gctl/core.h"
|
||||
#include "gctl/utility.h"
|
||||
|
||||
#define MeshFormat "$MeshFormat"
|
||||
#define EndMeshFormat "$EndMeshFormat"
|
||||
#define PhysicalNames "$PhysicalNames"
|
||||
#define EndPhysicalNames "$EndPhysicalNames"
|
||||
#define Nodes "$Nodes"
|
||||
#define EndNodes "$EndNodes"
|
||||
#define Elements "$Elements"
|
||||
#define EndElements "$EndElements"
|
||||
#define NodeData "$NodeData"
|
||||
#define EndNodeData "$EndNodeData"
|
||||
#define ElementData "$ElementData"
|
||||
#define EndElementData "$EndElementData"
|
||||
#define Comments "$Comments"
|
||||
#define EndComments "$EndComments"
|
||||
|
||||
using namespace std;
|
||||
//test
|
||||
struct phys_str
|
||||
{
|
||||
int id;
|
||||
int dim;
|
||||
char name[1024];
|
||||
};
|
||||
|
||||
struct node_str
|
||||
{
|
||||
int id;
|
||||
double x,y,z;
|
||||
};
|
||||
|
||||
struct element_str
|
||||
{
|
||||
int id;
|
||||
int type;
|
||||
int tag_num;
|
||||
int tag[3];
|
||||
int* node_id;
|
||||
};
|
||||
|
||||
struct nodedata_str
|
||||
{
|
||||
int id;
|
||||
double value;
|
||||
};
|
||||
|
||||
struct nodedata_info
|
||||
{
|
||||
string name;
|
||||
int num;
|
||||
double min,max;
|
||||
};
|
||||
|
||||
struct elemdata_str
|
||||
{
|
||||
int id;
|
||||
double value;
|
||||
};
|
||||
|
||||
struct elemdata_info
|
||||
{
|
||||
string name;
|
||||
int num;
|
||||
double min,max;
|
||||
};
|
||||
|
||||
typedef list<int> ListELementType;
|
||||
typedef list<int> ListPhysical;
|
||||
typedef list<int> ListGeometry;
|
||||
typedef map<int,string> TypeMap;
|
||||
typedef map<string,int> CataMap;
|
||||
typedef map<int,string> PhysMap;
|
||||
typedef list<nodedata_info> ListNodedata_info;
|
||||
typedef list<elemdata_info> ListElemdata_info;
|
||||
|
||||
class MshInfo
|
||||
{
|
||||
public:
|
||||
MshInfo();
|
||||
~MshInfo();
|
||||
int init();
|
||||
int readmsh(char*);
|
||||
int showinfo();
|
||||
int relese_node_id();
|
||||
private:
|
||||
double version_num;
|
||||
int file_type;
|
||||
int data_size;
|
||||
|
||||
int node_num;
|
||||
node_str* node;
|
||||
|
||||
int elem_num;
|
||||
element_str* element;
|
||||
|
||||
int str_tag_num;
|
||||
string* str_tag;
|
||||
int real_tag_num;
|
||||
double* real_tag;
|
||||
int int_tag_num;
|
||||
int int_tag[3];
|
||||
int nodedata_num;
|
||||
nodedata_str* nodedata;
|
||||
double nodedata_max;
|
||||
double nodedata_min;
|
||||
|
||||
ListNodedata_info nodeinfo_list;
|
||||
ListNodedata_info::iterator in;
|
||||
ListElemdata_info eleminfo_list;
|
||||
ListElemdata_info::iterator ie;
|
||||
|
||||
int ele_str_tag_num;
|
||||
string* ele_str_tag;
|
||||
int ele_real_tag_num;
|
||||
double* ele_real_tag;
|
||||
int ele_int_tag_num;
|
||||
int ele_int_tag[3];
|
||||
int elemdata_num;
|
||||
elemdata_str* elemdata;
|
||||
double elemdata_max;
|
||||
double elemdata_min;
|
||||
|
||||
ListELementType type_list;
|
||||
ListELementType::iterator it;
|
||||
ListPhysical phys_list;
|
||||
ListPhysical::iterator ip;
|
||||
ListGeometry geom_list;
|
||||
ListGeometry::iterator ig;
|
||||
|
||||
TypeMap map_type;
|
||||
TypeMap::iterator im;
|
||||
CataMap map_cata;
|
||||
CataMap::iterator ic;
|
||||
PhysMap map_phys;
|
||||
PhysMap::iterator ih;
|
||||
int typeint[94];
|
||||
|
||||
char* inputname;
|
||||
};
|
||||
|
||||
MshInfo::MshInfo()
|
||||
{
|
||||
node = NULL;
|
||||
element = NULL;
|
||||
str_tag = NULL;
|
||||
real_tag = NULL;
|
||||
nodedata = NULL;
|
||||
ele_str_tag = NULL;
|
||||
ele_real_tag = NULL;
|
||||
elemdata = NULL;
|
||||
}
|
||||
|
||||
MshInfo::~MshInfo()
|
||||
{
|
||||
if(node!=NULL) delete[] node;
|
||||
if(element!=NULL) delete[] element;
|
||||
if(str_tag!=NULL) delete[] str_tag;
|
||||
if(real_tag!=NULL) delete[] real_tag;
|
||||
if(nodedata!=NULL) delete[] nodedata;
|
||||
if(ele_str_tag!=NULL) delete[] ele_str_tag;
|
||||
if(ele_real_tag!=NULL) delete[] ele_real_tag;
|
||||
if(elemdata!=NULL) delete[] elemdata;
|
||||
if(!type_list.empty()) type_list.clear();
|
||||
if(!phys_list.empty()) phys_list.clear();
|
||||
if(!geom_list.empty()) geom_list.clear();
|
||||
if(!map_type.empty()) map_type.clear();
|
||||
if(!map_cata.empty()) map_cata.clear();
|
||||
if(!map_phys.empty()) map_phys.clear();
|
||||
}
|
||||
|
||||
int MshInfo::init()
|
||||
{
|
||||
nodedata_max = -1e+30;
|
||||
nodedata_min = 1e+30;
|
||||
|
||||
elemdata_max = -1e+30;
|
||||
elemdata_min = 1e+30;
|
||||
|
||||
map_type[1] = "2-node line";
|
||||
map_type[2] = "3-node triangle";
|
||||
map_type[3] = "4-node quadrangle";
|
||||
map_type[4] = "4-node tetrahedron";
|
||||
map_type[5] = "8-node hexahedron";
|
||||
map_type[6] = "6-node prism";
|
||||
map_type[7] = "5-node pyramid";
|
||||
map_type[8] = "3-node second order line";
|
||||
map_type[9] = "6-ndoe second order line";
|
||||
map_type[10] = "9-node second order quadrangle";
|
||||
map_type[11] = "10-node second order tetrahedron";
|
||||
map_type[12] = "27-node second order hexahedron";
|
||||
map_type[13] = "18-node second order prism";
|
||||
map_type[14] = "14-node second order pyramid";
|
||||
map_type[15] = "1-node point";
|
||||
map_type[16] = "8-node second order quadrangle";
|
||||
map_type[17] = "20-ndoe second order hexahedron";
|
||||
map_type[18] = "15-node second order prism";
|
||||
map_type[19] = "13-node second order pyramid";
|
||||
map_type[20] = "9-node third order incomplete triangle";
|
||||
map_type[21] = "10-ndoe third order triangle";
|
||||
map_type[22] = "12-node fourth order incomplete triangle";
|
||||
map_type[23] = "15-node fourth order triangle";
|
||||
map_type[24] = "15-node fifth order complete triangle";
|
||||
map_type[25] = "21-node fifth order complete triangle";
|
||||
map_type[26] = "4-node third order edge";
|
||||
map_type[27] = "5-node fourth order edge";
|
||||
map_type[28] = "6-node fifth order edge";
|
||||
map_type[29] = "20-node third order tetrahedron";
|
||||
map_type[30] = "35-node fourth order tetrahedron";
|
||||
map_type[31] = "56-node fifith order tetrahedron";
|
||||
map_type[92] = "64-node third order hexahedron";
|
||||
map_type[93] = "125-node fourth order hexahedron";
|
||||
|
||||
typeint[1] = 2; typeint[2] = 3; typeint[3] = 4; typeint[4] = 4; typeint[5] = 8;
|
||||
typeint[6] = 6; typeint[7] = 5; typeint[8] = 3; typeint[9] = 6; typeint[10] = 6;
|
||||
typeint[11] = 10; typeint[12] = 27; typeint[13] = 18; typeint[14] = 14; typeint[15] = 1;
|
||||
typeint[16] = 8; typeint[17] = 20; typeint[18] = 15; typeint[19] = 13; typeint[20] = 9;
|
||||
typeint[21] = 10; typeint[22] = 12; typeint[23] = 15; typeint[24] = 15; typeint[25] = 21;
|
||||
typeint[26] = 4; typeint[27] = 5; typeint[28] = 6; typeint[29] = 20; typeint[30] = 35;
|
||||
typeint[31] = 56; typeint[92] = 64; typeint[93] = 125;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int MshInfo::readmsh(char* filename)
|
||||
{
|
||||
string curline;
|
||||
string strtemp,temp_head,temp_middle;
|
||||
stringstream stemp;
|
||||
nodedata_info temp_nodeinfo;
|
||||
elemdata_info temp_eleminfo;
|
||||
ifstream mshin(filename);
|
||||
if (!mshin)
|
||||
{
|
||||
cout<<filename<<" not found!"<<endl;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
inputname = filename;
|
||||
cout<<inputname<<endl;
|
||||
while(getline(mshin,curline))
|
||||
{
|
||||
if (curline==Comments)
|
||||
{
|
||||
while (getline(mshin,curline))
|
||||
{
|
||||
if (curline != EndComments)
|
||||
{
|
||||
cout << curline << endl;
|
||||
}
|
||||
else break;
|
||||
}
|
||||
}
|
||||
else if (curline==MeshFormat)
|
||||
{
|
||||
mshin>>version_num>>file_type>>data_size;
|
||||
if (file_type!=0)
|
||||
{
|
||||
cout<<filename<<" not supported!"<<endl;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else if (curline==EndMeshFormat) continue;
|
||||
else if (curline==PhysicalNames)
|
||||
{
|
||||
int phys_num;
|
||||
phys_str phys_temp;
|
||||
mshin>>phys_num;
|
||||
for (int i = 0; i < phys_num; ++i)
|
||||
{
|
||||
mshin>>phys_temp.dim>>phys_temp.id>>strtemp;
|
||||
sscanf(strtemp.c_str(),"\"%[0-9a-zA-Z]",phys_temp.name);
|
||||
map_phys[phys_temp.id] = phys_temp.name;
|
||||
}
|
||||
}
|
||||
else if (curline==EndPhysicalNames) continue;
|
||||
else if (curline==Nodes)
|
||||
{
|
||||
mshin>>node_num;
|
||||
node = new node_str [node_num];
|
||||
for (int i = 0; i < node_num; ++i)
|
||||
{
|
||||
mshin>>node[i].id>>node[i].x>>node[i].y>>node[i].z;
|
||||
}
|
||||
}
|
||||
else if (curline==EndNodes) continue;
|
||||
else if (curline==Elements)
|
||||
{
|
||||
mshin>>elem_num;
|
||||
element = new element_str [elem_num];
|
||||
for (int i = 0; i < elem_num; ++i)
|
||||
{
|
||||
element[i].node_id = NULL;
|
||||
for (int j = 0; j < 3; ++j)
|
||||
{
|
||||
element[i].tag[j] = 1e+5;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < elem_num; ++i)
|
||||
{
|
||||
mshin>>element[i].id>>element[i].type>>element[i].tag_num;
|
||||
im = map_type.find(element[i].type);
|
||||
if (im==map_type.end())
|
||||
{
|
||||
cout<<"unsupported element type!"<<endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (type_list.empty())
|
||||
{
|
||||
type_list.push_back(element[i].type);
|
||||
}
|
||||
else
|
||||
{
|
||||
it = find(type_list.begin(),type_list.end(),element[i].type);
|
||||
if (it==type_list.end()) type_list.push_back(element[i].type);
|
||||
}
|
||||
|
||||
for (int j = 0; j < element[i].tag_num; ++j)
|
||||
{
|
||||
mshin>>element[i].tag[j];
|
||||
}
|
||||
if (element[i].tag_num==1)
|
||||
{
|
||||
if (phys_list.empty())
|
||||
{
|
||||
phys_list.push_back(element[i].tag[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
ip = find(phys_list.begin(),phys_list.end(),element[i].tag[0]);
|
||||
if (ip==phys_list.end()) phys_list.push_back(element[i].tag[0]);
|
||||
}
|
||||
}
|
||||
else if (element[i].tag_num==2)
|
||||
{
|
||||
if (phys_list.empty())
|
||||
{
|
||||
phys_list.push_back(element[i].tag[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
ip = find(phys_list.begin(),phys_list.end(),element[i].tag[0]);
|
||||
if (ip==phys_list.end()) phys_list.push_back(element[i].tag[0]);
|
||||
}
|
||||
|
||||
if (geom_list.empty())
|
||||
{
|
||||
geom_list.push_back(element[i].tag[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
ig = find(geom_list.begin(),geom_list.end(),element[i].tag[1]);
|
||||
if (ig==geom_list.end()) geom_list.push_back(element[i].tag[1]);
|
||||
}
|
||||
}
|
||||
|
||||
element[i].node_id = new int [typeint[element[i].type]];
|
||||
for (int k = 0; k < typeint[element[i].type]; ++k)
|
||||
{
|
||||
mshin>>element[i].node_id[k];
|
||||
}
|
||||
|
||||
temp_head = "";
|
||||
stemp.clear();
|
||||
stemp<<element[i].type;
|
||||
stemp>>temp_head;
|
||||
for (int j = 0; j < element[i].tag_num; ++j)
|
||||
{
|
||||
stemp.clear();
|
||||
stemp<<element[i].tag[j];
|
||||
stemp>>temp_middle;
|
||||
temp_head = temp_head + " " + temp_middle;
|
||||
}
|
||||
ic = map_cata.find(temp_head);
|
||||
if (ic==map_cata.end()) map_cata[temp_head] = 1;
|
||||
else map_cata[temp_head] = ic->second + 1;
|
||||
}
|
||||
}
|
||||
else if (curline==EndElements) continue;
|
||||
else if (curline==NodeData)
|
||||
{
|
||||
mshin>>str_tag_num;
|
||||
str_tag = new string [str_tag_num];
|
||||
getline(mshin,strtemp);//这里加1是因为需要跳过一个上一行的换行符
|
||||
for (int i = 0; i < str_tag_num; ++i)
|
||||
{
|
||||
getline(mshin,strtemp);
|
||||
str_tag[i] = strtemp;
|
||||
}
|
||||
mshin>>real_tag_num;
|
||||
real_tag = new double [real_tag_num];
|
||||
for (int i = 0; i < real_tag_num; ++i)
|
||||
{
|
||||
mshin>>real_tag[i];
|
||||
}
|
||||
mshin>>int_tag_num;
|
||||
for (int i = 0; i < int_tag_num; ++i)
|
||||
{
|
||||
mshin>>int_tag[i];
|
||||
}
|
||||
nodedata_num = int_tag[int_tag_num-1];
|
||||
nodedata = new nodedata_str [nodedata_num];
|
||||
for (int i = 0; i < nodedata_num; ++i)
|
||||
{
|
||||
mshin>>nodedata[i].id>>nodedata[i].value;
|
||||
if (nodedata[i].value<nodedata_min) nodedata_min = nodedata[i].value;
|
||||
if (nodedata[i].value>nodedata_max) nodedata_max = nodedata[i].value;
|
||||
}
|
||||
temp_nodeinfo.name = str_tag[0];
|
||||
temp_nodeinfo.num = nodedata_num;
|
||||
temp_nodeinfo.min = nodedata_min;
|
||||
temp_nodeinfo.max = nodedata_max;
|
||||
nodeinfo_list.push_back(temp_nodeinfo);
|
||||
//重置参数
|
||||
nodedata_max = -1e+30;
|
||||
nodedata_min = 1e+30;
|
||||
if (str_tag != NULL)
|
||||
{
|
||||
delete[] str_tag;
|
||||
str_tag = NULL;
|
||||
}
|
||||
if (real_tag != NULL)
|
||||
{
|
||||
delete[] real_tag;
|
||||
real_tag = NULL;
|
||||
}
|
||||
if (nodedata != NULL)
|
||||
{
|
||||
delete[] nodedata;
|
||||
nodedata = NULL;
|
||||
}
|
||||
}
|
||||
else if (curline==EndNodeData) continue;
|
||||
else if (curline==ElementData)
|
||||
{
|
||||
mshin>>ele_str_tag_num;
|
||||
ele_str_tag = new string [ele_str_tag_num];
|
||||
getline(mshin,strtemp);//这里加1是因为需要跳过一个上一行的换行符
|
||||
for (int i = 0; i < ele_str_tag_num; ++i)
|
||||
{
|
||||
getline(mshin,strtemp);
|
||||
ele_str_tag[i] = strtemp;
|
||||
}
|
||||
mshin>>ele_real_tag_num;
|
||||
ele_real_tag = new double [ele_real_tag_num];
|
||||
for (int i = 0; i < ele_real_tag_num; ++i)
|
||||
{
|
||||
mshin>>ele_real_tag[i];
|
||||
}
|
||||
mshin>>ele_int_tag_num;
|
||||
for (int i = 0; i < ele_int_tag_num; ++i)
|
||||
{
|
||||
mshin>>ele_int_tag[i];
|
||||
}
|
||||
elemdata_num = ele_int_tag[ele_int_tag_num-1];
|
||||
elemdata = new elemdata_str [elemdata_num];
|
||||
for (int i = 0; i < elemdata_num; ++i)
|
||||
{
|
||||
mshin>>elemdata[i].id>>elemdata[i].value;
|
||||
if (elemdata[i].value<elemdata_min) elemdata_min = elemdata[i].value;
|
||||
if (elemdata[i].value>elemdata_max) elemdata_max = elemdata[i].value;
|
||||
}
|
||||
temp_eleminfo.name = ele_str_tag[0];
|
||||
temp_eleminfo.num = elemdata_num;
|
||||
temp_eleminfo.min = elemdata_min;
|
||||
temp_eleminfo.max = elemdata_max;
|
||||
eleminfo_list.push_back(temp_eleminfo);
|
||||
//重置参数
|
||||
elemdata_max = -1e+30;
|
||||
elemdata_min = 1e+30;
|
||||
if (ele_str_tag != NULL)
|
||||
{
|
||||
delete[] ele_str_tag;
|
||||
ele_str_tag = NULL;
|
||||
}
|
||||
if (ele_real_tag != NULL)
|
||||
{
|
||||
delete[] ele_real_tag;
|
||||
ele_real_tag = NULL;
|
||||
}
|
||||
if (elemdata != NULL)
|
||||
{
|
||||
delete[] elemdata;
|
||||
elemdata = NULL;
|
||||
}
|
||||
}
|
||||
else if (curline==EndElementData) continue;
|
||||
}
|
||||
mshin.close();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int MshInfo::showinfo()
|
||||
{
|
||||
int inttemp,temp_count;
|
||||
string strtemp;
|
||||
stringstream stemp;
|
||||
string iteam[4] = {"element type: ","physical group: ","geometrical group: ","mesh partition: "};
|
||||
//cout<<inputname<<endl;
|
||||
cout<<"version: "<<version_num<<", file_type: "<<file_type<<", data_size: "<<data_size<<endl;
|
||||
cout<<"number of nodes: "<<node_num<<", number of elements: "<<elem_num<<endl;
|
||||
for (ic=map_cata.begin();ic!=map_cata.end();++ic)
|
||||
{
|
||||
temp_count = 2;
|
||||
strtemp = ic->first;
|
||||
stemp.clear();
|
||||
stemp<<strtemp;
|
||||
stemp>>inttemp;
|
||||
im = map_type.find(inttemp);
|
||||
cout<<iteam[0]<<im->second<<", ";
|
||||
if (stemp>>inttemp)
|
||||
{
|
||||
if (!map_phys.empty())
|
||||
{
|
||||
ih = map_phys.find(inttemp);
|
||||
if (ih!=map_phys.end())
|
||||
{
|
||||
cout<<iteam[1]<<ih->first<<" \""<<ih->second<<"\", ";
|
||||
}
|
||||
else cout<<iteam[1]<<inttemp<<", ";
|
||||
}
|
||||
else cout<<iteam[1]<<inttemp<<", ";
|
||||
}
|
||||
while(stemp>>inttemp)
|
||||
{
|
||||
cout<<iteam[temp_count]<<inttemp<<", ";
|
||||
temp_count++;
|
||||
}
|
||||
cout<<"number of elements: "<<ic->second<<endl;
|
||||
}
|
||||
|
||||
nodedata_info temp_nodeinfo;
|
||||
elemdata_info temp_eleminfo;
|
||||
for (in=nodeinfo_list.begin();in!=nodeinfo_list.end();++in)
|
||||
{
|
||||
temp_nodeinfo = *in;
|
||||
cout << "nodedata: " << temp_nodeinfo.name << ", number: " << temp_nodeinfo.num << ", minimal value: " << temp_nodeinfo.min << ", maximal value: " << temp_nodeinfo.max << endl;
|
||||
}
|
||||
for (ie=eleminfo_list.begin();ie!=eleminfo_list.end();++ie)
|
||||
{
|
||||
temp_eleminfo = *ie;
|
||||
cout << "elementdata: " << temp_eleminfo.name << ", number: " << temp_eleminfo.num << ", minimal value: " << temp_eleminfo.min << ", maximal value: " << temp_eleminfo.max << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int MshInfo::relese_node_id()
|
||||
{
|
||||
for (int i = 0; i < elem_num; ++i)
|
||||
{
|
||||
if (element[i].node_id!=NULL) delete[] element[i].node_id;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
3
gmshinfo/readme.md
Normal file
3
gmshinfo/readme.md
Normal file
@@ -0,0 +1,3 @@
|
||||
### gmshinfo
|
||||
目的:读取gmsh程序网格文件.msh,然后返回文件信息
|
||||
语法:gmshinfo [filename]
|
Reference in New Issue
Block a user