initial upload
This commit is contained in:
259
archive/3dtools2msh/3dtools2msh.h
Normal file
259
archive/3dtools2msh/3dtools2msh.h
Normal file
@@ -0,0 +1,259 @@
|
||||
#ifndef _3DTOOLS2MSH_H
|
||||
#define _3DTOOLS2MSH_H
|
||||
#include "iostream"
|
||||
#include "fstream"
|
||||
#include "sstream"
|
||||
#include "string.h"
|
||||
#include "iomanip"
|
||||
#define MESH "-M"
|
||||
#define VALUE "-V"
|
||||
#define OUTFILE "-G"
|
||||
#define FILTER "-F"
|
||||
using namespace std;
|
||||
|
||||
string& replace_all(string& str,const string& old_value,const string& new_value,int &num) //替换str中所有lod_value为new_value,返回被替换的lod_value的个数
|
||||
{
|
||||
int count = 0;
|
||||
for(string::size_type pos(0);pos!=string::npos;pos+=new_value.length()){
|
||||
if((pos=str.find(old_value,pos))!=string::npos){
|
||||
str.replace(pos,old_value.length(),new_value);
|
||||
count++;
|
||||
}
|
||||
else break;
|
||||
}
|
||||
num = count;
|
||||
return str;
|
||||
}
|
||||
|
||||
int typeget(char *str, const char* str2,string &str3)//提出头端的子句
|
||||
{
|
||||
char* strp = strstr(str, str2); // 从字符串str中查找str2,
|
||||
if (strp == NULL)
|
||||
{
|
||||
return 0; // 如果没有找到,返回
|
||||
}
|
||||
string temp = str;
|
||||
str3=temp.substr(strlen(str2));//提出除str2外的子句
|
||||
return 1;
|
||||
}
|
||||
|
||||
int nameget(char *str, const char* str2,string &str3)//提出尾端的子句
|
||||
{
|
||||
char* strp = strstr(str, str2); // 从字符串str中查找str2,
|
||||
if (strp == NULL)
|
||||
{
|
||||
return 0; // 如果没有找到,返回
|
||||
}
|
||||
string temp = str;
|
||||
str3=temp.substr(0,strlen(str)-strlen(str2));//提出除str2外的子句
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct NODE
|
||||
{
|
||||
double x,y,z;
|
||||
};
|
||||
|
||||
struct CUBE
|
||||
{
|
||||
int index[8];
|
||||
double phys;
|
||||
};
|
||||
|
||||
class _3dtools2msh
|
||||
{
|
||||
public:
|
||||
_3dtools2msh();
|
||||
~_3dtools2msh();
|
||||
int meshin(string);
|
||||
int physin(string);
|
||||
int findindex();
|
||||
int mshout(string,double);
|
||||
private:
|
||||
double xst,yst,zst;
|
||||
int xnum,ynum,znum;
|
||||
double xinter,yinter,zinter;
|
||||
|
||||
NODE* node;
|
||||
CUBE* cube;
|
||||
int nodenum;
|
||||
int cubenum;
|
||||
};
|
||||
|
||||
_3dtools2msh::_3dtools2msh()
|
||||
{
|
||||
node = NULL;
|
||||
cube = NULL;
|
||||
}
|
||||
|
||||
_3dtools2msh::~_3dtools2msh()
|
||||
{
|
||||
if(node!=NULL) delete[] node;
|
||||
if(cube!=NULL) delete[] cube;
|
||||
}
|
||||
|
||||
int _3dtools2msh::meshin(string filename)
|
||||
{
|
||||
stringstream stemp;
|
||||
string temp;
|
||||
int space_num;
|
||||
int xnum_t,ynum_t,znum_t;
|
||||
const char* meshname = filename.c_str();
|
||||
ifstream inmesh;
|
||||
inmesh.open(meshname);
|
||||
if (!inmesh)
|
||||
{
|
||||
cout<<filename<<" not found!"<<endl;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
inmesh>>ynum>>xnum>>znum>>yst>>xst>>zst;
|
||||
inmesh>>temp;
|
||||
replace_all(temp,"*"," ",space_num);
|
||||
stemp.clear();
|
||||
stemp.str(temp);
|
||||
stemp>>ynum_t>>yinter;
|
||||
if (ynum!=ynum_t)
|
||||
{
|
||||
cout<<"syntax error: "<<filename<<endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
inmesh>>temp;
|
||||
replace_all(temp,"*"," ",space_num);
|
||||
stemp.clear();
|
||||
stemp.str(temp);
|
||||
stemp>>xnum_t>>xinter;
|
||||
if (xnum!=xnum_t)
|
||||
{
|
||||
cout<<"syntax error: "<<filename<<endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
inmesh>>temp;
|
||||
replace_all(temp,"*"," ",space_num);
|
||||
stemp.clear();
|
||||
stemp.str(temp);
|
||||
stemp>>znum_t>>zinter;
|
||||
if (znum!=znum_t)
|
||||
{
|
||||
cout<<"syntax error: "<<filename<<endl;
|
||||
return 1;
|
||||
}
|
||||
inmesh.close();
|
||||
|
||||
nodenum = (xnum+1)*(ynum+1)*(znum+1);
|
||||
node = new NODE [nodenum];
|
||||
for (int i = 0; i < nodenum; i++)
|
||||
{
|
||||
node[i].z = zst + zinter*(i%(znum+1));
|
||||
node[i].y = yst + yinter*((i/(znum+1))%(ynum+1));
|
||||
node[i].x = xst + xinter*(i/((znum+1)*(ynum+1)));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int _3dtools2msh::physin(string filename)
|
||||
{
|
||||
cubenum = xnum*ynum*znum;
|
||||
cube = new CUBE [cubenum];
|
||||
for (int i = 0; i < cubenum; i++)
|
||||
{
|
||||
cube[i].phys = 0.0;
|
||||
}
|
||||
|
||||
const char* cubename = filename.c_str();
|
||||
ifstream incube;
|
||||
incube.open(cubename);
|
||||
if (!incube)
|
||||
{
|
||||
cout<<filename<<" not found!"<<endl;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < cubenum; i++)
|
||||
{
|
||||
incube>>cube[i].phys;
|
||||
}
|
||||
incube.close();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int _3dtools2msh::findindex()
|
||||
{
|
||||
for (int i = 0; i < xnum; i++)
|
||||
{
|
||||
for (int j = 0; j < ynum; j++)
|
||||
{
|
||||
for (int k = 0; k < znum; k++)
|
||||
{
|
||||
cube[k+j*znum+i*ynum*znum].index[0]=k+j*(znum+1)+i*(ynum+1)*(znum+1);
|
||||
cube[k+j*znum+i*ynum*znum].index[1]=k+j*(znum+1)+i*(ynum+1)*(znum+1)+znum+1;
|
||||
cube[k+j*znum+i*ynum*znum].index[2]=k+j*(znum+1)+i*(ynum+1)*(znum+1)+znum+1+(ynum+1)*(znum+1);
|
||||
cube[k+j*znum+i*ynum*znum].index[3]=k+j*(znum+1)+i*(ynum+1)*(znum+1)+(ynum+1)*(znum+1);
|
||||
cube[k+j*znum+i*ynum*znum].index[4]=k+j*(znum+1)+i*(ynum+1)*(znum+1)+1;
|
||||
cube[k+j*znum+i*ynum*znum].index[5]=k+j*(znum+1)+i*(ynum+1)*(znum+1)+1+znum+1;
|
||||
cube[k+j*znum+i*ynum*znum].index[6]=k+j*(znum+1)+i*(ynum+1)*(znum+1)+1+znum+1+(ynum+1)*(znum+1);
|
||||
cube[k+j*znum+i*ynum*znum].index[7]=k+j*(znum+1)+i*(ynum+1)*(znum+1)+1+(ynum+1)*(znum+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _3dtools2msh::mshout(string filename,double filter)
|
||||
{
|
||||
const char* mshname = filename.c_str();
|
||||
ofstream outmsh;
|
||||
outmsh.open(mshname);
|
||||
if (!outmsh)
|
||||
{
|
||||
cout<<"fail to create "<<filename<<endl;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
outmsh<<"$MeshFormat"<<endl<<"2.2 0 8"<<endl<<"$EndMeshFormat"<<endl<<"$Nodes"<<endl<<nodenum<<endl;
|
||||
for (int i = 0; i < nodenum; i++)
|
||||
{
|
||||
outmsh<<i<<" "<<setprecision(16)<<node[i].x<<" "<<node[i].y<<" "<<node[i].z<<endl;
|
||||
}
|
||||
outmsh<<"$EndNodes"<<endl<<"$Elements"<<endl<<cubenum<<endl;
|
||||
for (int i = 0; i < cubenum; i++)
|
||||
{
|
||||
outmsh<<i<<" 5 2 5 1 "<<cube[i].index[0]<<" "
|
||||
<<cube[i].index[1]<<" "
|
||||
<<cube[i].index[2]<<" "
|
||||
<<cube[i].index[3]<<" "
|
||||
<<cube[i].index[4]<<" "
|
||||
<<cube[i].index[5]<<" "
|
||||
<<cube[i].index[6]<<" "
|
||||
<<cube[i].index[7]<<endl;
|
||||
}
|
||||
int eleNum = 0;
|
||||
for (int i = 0; i < cubenum; i++)
|
||||
{
|
||||
if (cube[i].phys != filter)
|
||||
{
|
||||
eleNum++;
|
||||
}
|
||||
}
|
||||
outmsh<<"$EndElements"<<endl<<"$ElementData"<<endl;
|
||||
outmsh<<1<<endl<<"\"Recovered model\""<<endl<<1<<endl<<0.0<<endl<<3<<endl<<0<<endl<<1<<endl<<eleNum<<endl;
|
||||
for (int i = 0; i < cubenum; i++)
|
||||
{
|
||||
if (cube[i].phys != filter)
|
||||
{
|
||||
outmsh<<i<<" "<<setprecision(16)<<cube[i].phys<<endl;
|
||||
}
|
||||
}
|
||||
outmsh<<"$EndElementData";
|
||||
outmsh.close();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
5
archive/3dtools2msh/CMakeLists.txt
Normal file
5
archive/3dtools2msh/CMakeLists.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
add_executable(3dtools2msh main.cpp)
|
||||
# 第二种方式指定目标文件的路径 这个方式目标文件夹中将只包含目标文件而没有中间文件
|
||||
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
|
||||
# 设置安装地址
|
||||
install(TARGETS 3dtools2msh RUNTIME DESTINATION selfpro)
|
||||
84
archive/3dtools2msh/main.cpp
Normal file
84
archive/3dtools2msh/main.cpp
Normal file
@@ -0,0 +1,84 @@
|
||||
#include "3dtools2msh.h"
|
||||
|
||||
void disp_help()
|
||||
{
|
||||
cout<<"3dtools2msh 0.1 - convert the files of Meshtools 3D to Gmsh .msh file"<<endl<<endl
|
||||
<<"syntax: 3dtools2msh -M<mesh-file> -V<model-file> [-F<filter-value>] [-G<output-file>]"<<endl
|
||||
<<" -M Meshtools 3D's mesh file"<<endl
|
||||
<<" -V Meshtools 3D's model file"<<endl
|
||||
<<" -F filter out value, the default is 9999"<<endl
|
||||
<<" -G specify output file's name, the input model file name will be used if -G is absent"<<endl
|
||||
<<"example: 3dtools2msh -Mexample.mesh -Vexample.model -Gexample.msh"<<endl;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
string _meshname="";
|
||||
string _modelname="";
|
||||
string _mshname="";
|
||||
string temp;
|
||||
double filterNum = 9999;
|
||||
if (argc==1)
|
||||
{
|
||||
disp_help();
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 1; i < argc; i++)
|
||||
{
|
||||
if (typeget(argv[i],MESH,temp))
|
||||
{
|
||||
if (temp=="")
|
||||
{
|
||||
cout<<"syntax error: "<<argv[i]<<endl;
|
||||
disp_help();
|
||||
return 0;
|
||||
}
|
||||
else _meshname=temp;
|
||||
}
|
||||
else if (typeget(argv[i],VALUE,temp))
|
||||
{
|
||||
if (temp=="")
|
||||
{
|
||||
cout<<"syntax error: "<<argv[i]<<endl;
|
||||
disp_help();
|
||||
return 0;
|
||||
}
|
||||
else _modelname=temp;
|
||||
}
|
||||
else if (typeget(argv[i],FILTER,temp))
|
||||
{
|
||||
if (temp=="")
|
||||
{
|
||||
cout<<"syntax error: "<<argv[i]<<endl;
|
||||
disp_help();
|
||||
return 0;
|
||||
}
|
||||
else filterNum=atof(temp.c_str());
|
||||
}
|
||||
else if (typeget(argv[i],OUTFILE,temp))
|
||||
{
|
||||
if (temp=="")
|
||||
{
|
||||
cout<<"syntax error: "<<argv[i]<<endl;
|
||||
disp_help();
|
||||
return 0;
|
||||
}
|
||||
else _mshname=temp;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout<<"unrecognized argument "<<argv[i]<<endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if(_mshname=="") _mshname=_modelname+"_convert_to.msh";
|
||||
_3dtools2msh testrun;
|
||||
testrun.meshin(_meshname);
|
||||
testrun.physin(_modelname);
|
||||
testrun.findindex();
|
||||
testrun.mshout(_mshname,filterNum);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
259
archive/3dtools2msh_spherical/3dtools2msh.h
Normal file
259
archive/3dtools2msh_spherical/3dtools2msh.h
Normal file
@@ -0,0 +1,259 @@
|
||||
#ifndef _3DTOOLS2MSH_H
|
||||
#define _3DTOOLS2MSH_H
|
||||
#include "iostream"
|
||||
#include "fstream"
|
||||
#include "sstream"
|
||||
#include "string.h"
|
||||
#include "iomanip"
|
||||
#define MESH "-M"
|
||||
#define VALUE "-V"
|
||||
#define OUTFILE "-G"
|
||||
#define FILTER "-F"
|
||||
using namespace std;
|
||||
|
||||
string& replace_all(string& str,const string& old_value,const string& new_value,int &num) //替换str中所有lod_value为new_value,返回被替换的lod_value的个数
|
||||
{
|
||||
int count = 0;
|
||||
for(string::size_type pos(0);pos!=string::npos;pos+=new_value.length()){
|
||||
if((pos=str.find(old_value,pos))!=string::npos){
|
||||
str.replace(pos,old_value.length(),new_value);
|
||||
count++;
|
||||
}
|
||||
else break;
|
||||
}
|
||||
num = count;
|
||||
return str;
|
||||
}
|
||||
|
||||
int typeget(char *str, const char* str2,string &str3)//提出头端的子句
|
||||
{
|
||||
char* strp = strstr(str, str2); // 从字符串str中查找str2,
|
||||
if (strp == NULL)
|
||||
{
|
||||
return 0; // 如果没有找到,返回
|
||||
}
|
||||
string temp = str;
|
||||
str3=temp.substr(strlen(str2));//提出除str2外的子句
|
||||
return 1;
|
||||
}
|
||||
|
||||
int nameget(char *str, const char* str2,string &str3)//提出尾端的子句
|
||||
{
|
||||
char* strp = strstr(str, str2); // 从字符串str中查找str2,
|
||||
if (strp == NULL)
|
||||
{
|
||||
return 0; // 如果没有找到,返回
|
||||
}
|
||||
string temp = str;
|
||||
str3=temp.substr(0,strlen(str)-strlen(str2));//提出除str2外的子句
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct NODE
|
||||
{
|
||||
double x,y,z;
|
||||
};
|
||||
|
||||
struct CUBE
|
||||
{
|
||||
int index[8];
|
||||
double phys;
|
||||
};
|
||||
|
||||
class _3dtools2msh
|
||||
{
|
||||
public:
|
||||
_3dtools2msh();
|
||||
~_3dtools2msh();
|
||||
int meshin(string);
|
||||
int physin(string);
|
||||
int findindex();
|
||||
int mshout(string,double);
|
||||
private:
|
||||
double xst,yst,zst;
|
||||
int xnum,ynum,znum;
|
||||
double xinter,yinter,zinter;
|
||||
|
||||
NODE* node;
|
||||
CUBE* cube;
|
||||
int nodenum;
|
||||
int cubenum;
|
||||
};
|
||||
|
||||
_3dtools2msh::_3dtools2msh()
|
||||
{
|
||||
node = NULL;
|
||||
cube = NULL;
|
||||
}
|
||||
|
||||
_3dtools2msh::~_3dtools2msh()
|
||||
{
|
||||
if(node!=NULL) delete[] node;
|
||||
if(cube!=NULL) delete[] cube;
|
||||
}
|
||||
|
||||
int _3dtools2msh::meshin(string filename)
|
||||
{
|
||||
stringstream stemp;
|
||||
string temp;
|
||||
int space_num;
|
||||
int xnum_t,ynum_t,znum_t;
|
||||
const char* meshname = filename.c_str();
|
||||
ifstream inmesh;
|
||||
inmesh.open(meshname);
|
||||
if (!inmesh)
|
||||
{
|
||||
cout<<filename<<" not found!"<<endl;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
inmesh>>ynum>>xnum>>znum>>yst>>xst>>zst;
|
||||
inmesh>>temp;
|
||||
replace_all(temp,"*"," ",space_num);
|
||||
stemp.clear();
|
||||
stemp.str(temp);
|
||||
stemp>>ynum_t>>yinter;
|
||||
if (ynum!=ynum_t)
|
||||
{
|
||||
cout<<"syntax error: "<<filename<<endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
inmesh>>temp;
|
||||
replace_all(temp,"*"," ",space_num);
|
||||
stemp.clear();
|
||||
stemp.str(temp);
|
||||
stemp>>xnum_t>>xinter;
|
||||
if (xnum!=xnum_t)
|
||||
{
|
||||
cout<<"syntax error: "<<filename<<endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
inmesh>>temp;
|
||||
replace_all(temp,"*"," ",space_num);
|
||||
stemp.clear();
|
||||
stemp.str(temp);
|
||||
stemp>>znum_t>>zinter;
|
||||
if (znum!=znum_t)
|
||||
{
|
||||
cout<<"syntax error: "<<filename<<endl;
|
||||
return 1;
|
||||
}
|
||||
inmesh.close();
|
||||
|
||||
nodenum = (xnum+1)*(ynum+1)*(znum+1);
|
||||
node = new NODE [nodenum];
|
||||
for (int i = 0; i < nodenum; i++)
|
||||
{
|
||||
node[i].z = zst + zinter*(i%(znum+1));
|
||||
node[i].y = yst + yinter*((i/(znum+1))%(ynum+1));
|
||||
node[i].x = xst + xinter*(i/((znum+1)*(ynum+1)));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int _3dtools2msh::physin(string filename)
|
||||
{
|
||||
cubenum = xnum*ynum*znum;
|
||||
cube = new CUBE [cubenum];
|
||||
for (int i = 0; i < cubenum; i++)
|
||||
{
|
||||
cube[i].phys = 0.0;
|
||||
}
|
||||
|
||||
const char* cubename = filename.c_str();
|
||||
ifstream incube;
|
||||
incube.open(cubename);
|
||||
if (!incube)
|
||||
{
|
||||
cout<<filename<<" not found!"<<endl;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < cubenum; i++)
|
||||
{
|
||||
incube>>cube[i].phys;
|
||||
}
|
||||
incube.close();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int _3dtools2msh::findindex()
|
||||
{
|
||||
for (int i = 0; i < xnum; i++)
|
||||
{
|
||||
for (int j = 0; j < ynum; j++)
|
||||
{
|
||||
for (int k = 0; k < znum; k++)
|
||||
{
|
||||
cube[k+j*znum+i*ynum*znum].index[0]=k+j*(znum+1)+i*(ynum+1)*(znum+1);
|
||||
cube[k+j*znum+i*ynum*znum].index[1]=k+j*(znum+1)+i*(ynum+1)*(znum+1)+znum+1;
|
||||
cube[k+j*znum+i*ynum*znum].index[2]=k+j*(znum+1)+i*(ynum+1)*(znum+1)+znum+1+(ynum+1)*(znum+1);
|
||||
cube[k+j*znum+i*ynum*znum].index[3]=k+j*(znum+1)+i*(ynum+1)*(znum+1)+(ynum+1)*(znum+1);
|
||||
cube[k+j*znum+i*ynum*znum].index[4]=k+j*(znum+1)+i*(ynum+1)*(znum+1)+1;
|
||||
cube[k+j*znum+i*ynum*znum].index[5]=k+j*(znum+1)+i*(ynum+1)*(znum+1)+1+znum+1;
|
||||
cube[k+j*znum+i*ynum*znum].index[6]=k+j*(znum+1)+i*(ynum+1)*(znum+1)+1+znum+1+(ynum+1)*(znum+1);
|
||||
cube[k+j*znum+i*ynum*znum].index[7]=k+j*(znum+1)+i*(ynum+1)*(znum+1)+1+(ynum+1)*(znum+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _3dtools2msh::mshout(string filename,double filter)
|
||||
{
|
||||
const char* mshname = filename.c_str();
|
||||
ofstream outmsh;
|
||||
outmsh.open(mshname);
|
||||
if (!outmsh)
|
||||
{
|
||||
cout<<"fail to create "<<filename<<endl;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
outmsh<<"$MeshFormat"<<endl<<"2.2 0 8"<<endl<<"$EndMeshFormat"<<endl<<"$Nodes"<<endl<<nodenum<<endl;
|
||||
for (int i = 0; i < nodenum; i++)
|
||||
{
|
||||
outmsh<<i<<" "<<setprecision(16)<<node[i].x<<" "<<node[i].y<<" "<<node[i].z<<endl;
|
||||
}
|
||||
outmsh<<"$EndNodes"<<endl<<"$Elements"<<endl<<cubenum<<endl;
|
||||
for (int i = 0; i < cubenum; i++)
|
||||
{
|
||||
outmsh<<i<<" 5 2 5 1 "<<cube[i].index[0]<<" "
|
||||
<<cube[i].index[1]<<" "
|
||||
<<cube[i].index[2]<<" "
|
||||
<<cube[i].index[3]<<" "
|
||||
<<cube[i].index[4]<<" "
|
||||
<<cube[i].index[5]<<" "
|
||||
<<cube[i].index[6]<<" "
|
||||
<<cube[i].index[7]<<endl;
|
||||
}
|
||||
int eleNum = 0;
|
||||
for (int i = 0; i < cubenum; i++)
|
||||
{
|
||||
if (cube[i].phys != filter)
|
||||
{
|
||||
eleNum++;
|
||||
}
|
||||
}
|
||||
outmsh<<"$EndElements"<<endl<<"$ElementData"<<endl;
|
||||
outmsh<<1<<endl<<"\"Recovered model\""<<endl<<1<<endl<<0.0<<endl<<3<<endl<<0<<endl<<1<<endl<<eleNum<<endl;
|
||||
for (int i = 0; i < cubenum; i++)
|
||||
{
|
||||
if (cube[i].phys != filter)
|
||||
{
|
||||
outmsh<<i<<" "<<setprecision(16)<<cube[i].phys<<endl;
|
||||
}
|
||||
}
|
||||
outmsh<<"$EndElementData";
|
||||
outmsh.close();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
5
archive/3dtools2msh_spherical/CMakeLists.txt
Normal file
5
archive/3dtools2msh_spherical/CMakeLists.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
add_executable(3dtools2msh_sph main.cpp)
|
||||
# 第二种方式指定目标文件的路径 这个方式目标文件夹中将只包含目标文件而没有中间文件
|
||||
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
|
||||
# 设置安装地址
|
||||
install(TARGETS 3dtools2msh_sph RUNTIME DESTINATION selfpro)
|
||||
84
archive/3dtools2msh_spherical/main.cpp
Normal file
84
archive/3dtools2msh_spherical/main.cpp
Normal file
@@ -0,0 +1,84 @@
|
||||
#include "3dtools2msh.h"
|
||||
|
||||
void disp_help()
|
||||
{
|
||||
cout<<"3dtools2msh 0.1 - convert the files of Meshtools 3D to Gmsh .msh file"<<endl<<endl
|
||||
<<"syntax: 3dtools2msh -M<mesh-file> -V<model-file> [-F<filter-value>] [-G<output-file>]"<<endl
|
||||
<<" -M Meshtools 3D's mesh file"<<endl
|
||||
<<" -V Meshtools 3D's model file"<<endl
|
||||
<<" -F filter out value, the default is 9999"<<endl
|
||||
<<" -G specify output file's name, the input model file name will be used if -G is absent"<<endl
|
||||
<<"example: 3dtools2msh -Mexample.mesh -Vexample.model -Gexample.msh"<<endl;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
string _meshname="";
|
||||
string _modelname="";
|
||||
string _mshname="";
|
||||
string temp;
|
||||
double filterNum = 9999;
|
||||
if (argc==1)
|
||||
{
|
||||
disp_help();
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 1; i < argc; i++)
|
||||
{
|
||||
if (typeget(argv[i],MESH,temp))
|
||||
{
|
||||
if (temp=="")
|
||||
{
|
||||
cout<<"syntax error: "<<argv[i]<<endl;
|
||||
disp_help();
|
||||
return 0;
|
||||
}
|
||||
else _meshname=temp;
|
||||
}
|
||||
else if (typeget(argv[i],VALUE,temp))
|
||||
{
|
||||
if (temp=="")
|
||||
{
|
||||
cout<<"syntax error: "<<argv[i]<<endl;
|
||||
disp_help();
|
||||
return 0;
|
||||
}
|
||||
else _modelname=temp;
|
||||
}
|
||||
else if (typeget(argv[i],FILTER,temp))
|
||||
{
|
||||
if (temp=="")
|
||||
{
|
||||
cout<<"syntax error: "<<argv[i]<<endl;
|
||||
disp_help();
|
||||
return 0;
|
||||
}
|
||||
else filterNum=atof(temp.c_str());
|
||||
}
|
||||
else if (typeget(argv[i],OUTFILE,temp))
|
||||
{
|
||||
if (temp=="")
|
||||
{
|
||||
cout<<"syntax error: "<<argv[i]<<endl;
|
||||
disp_help();
|
||||
return 0;
|
||||
}
|
||||
else _mshname=temp;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout<<"unrecognized argument "<<argv[i]<<endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if(_mshname=="") _mshname=_modelname+"_convert_to.msh";
|
||||
_3dtools2msh testrun;
|
||||
testrun.meshin(_meshname);
|
||||
testrun.physin(_modelname);
|
||||
testrun.findindex();
|
||||
testrun.mshout(_mshname,filterNum);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
152
archive/Tesseroid_creater/command.h
Normal file
152
archive/Tesseroid_creater/command.h
Normal file
@@ -0,0 +1,152 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "stdio.h"
|
||||
#include <iomanip>
|
||||
#include <cmath>
|
||||
#include "list"
|
||||
#define MAX 1e+30
|
||||
#define pi (4.0*atan(1.0))
|
||||
#define min(a,b)(((a) < (b)) ? (a) : (b))
|
||||
#define OUTPUT "-o"
|
||||
#define AFFECTION "-a"
|
||||
#define PARA "-p"
|
||||
#define BOLDRED "\033[1m\033[31m"
|
||||
#define RESET "\033[0m"
|
||||
|
||||
using namespace std;
|
||||
|
||||
struct Tess
|
||||
{
|
||||
char name[1024];
|
||||
int id;
|
||||
double xmin,xmax,ymin,ymax,r,R;
|
||||
};
|
||||
typedef list<Tess> TessList;
|
||||
|
||||
struct point3d
|
||||
{
|
||||
double x,y,z;
|
||||
};
|
||||
|
||||
point3d SCS2CCS(double thet,double phi,double radius)//球坐标转直角坐标
|
||||
{
|
||||
point3d v;
|
||||
v.x = radius*sin((0.5-thet/180.0)*pi)*cos((2.0+phi/180.0)*pi);
|
||||
v.y = radius*sin((0.5-thet/180.0)*pi)*sin((2.0+phi/180.0)*pi);
|
||||
v.z = radius*cos((0.5-thet/180.0)*pi);
|
||||
return v;
|
||||
}
|
||||
|
||||
void check(point3d &v)
|
||||
{
|
||||
if(abs(v.x)<1e-8){
|
||||
v.x=0;
|
||||
}
|
||||
if(abs(v.y)<1e-8){
|
||||
v.y=0;
|
||||
}
|
||||
if(abs(v.z)<1e-8){
|
||||
v.z=0;
|
||||
}
|
||||
}
|
||||
|
||||
void subrutine(int order,ofstream& outfile,double r,double R,double longi_min,double longi_max,double lati_min,double lati_max)
|
||||
{
|
||||
double affection;
|
||||
double c_length;
|
||||
double depth;
|
||||
double min_length=MAX;
|
||||
point3d posi;
|
||||
|
||||
depth = R - r;
|
||||
min_length = min(depth,min_length);
|
||||
c_length = (lati_max-lati_min)*pi*r/180;
|
||||
min_length = min(c_length,min_length);
|
||||
c_length = (longi_max-longi_min)*r*cos(lati_max*pi/180.0)*pi/180;
|
||||
min_length = min(c_length,min_length);
|
||||
affection = min_length/10;
|
||||
|
||||
//string meshsize_name = to_string(order);
|
||||
//outfile<<"lc"<<meshsize_name<<" = "<<affection<<";"<<endl;
|
||||
|
||||
posi = SCS2CCS(lati_min,longi_min,r);
|
||||
check(posi);
|
||||
outfile<<setprecision(16)<<"Point("<<order*12+2<<") = {"<<posi.x<<", "<<posi.y<<", "<<posi.z<<", lc*"<<affection<<"};"<<endl;
|
||||
outfile<<setprecision(16)<<"Point("<<order*12+3<<") = {"<<0.0<<", "<<0.0<<", "<<posi.z<<", lc*"<<affection<<"};"<<endl;
|
||||
posi = SCS2CCS(lati_min,longi_max,r);
|
||||
check(posi);
|
||||
outfile<<setprecision(16)<<"Point("<<order*12+4<<") = {"<<posi.x<<", "<<posi.y<<", "<<posi.z<<", lc*"<<affection<<"};"<<endl;
|
||||
posi = SCS2CCS(lati_min,longi_min,R);
|
||||
check(posi);
|
||||
outfile<<setprecision(16)<<"Point("<<order*12+5<<") = {"<<posi.x<<", "<<posi.y<<", "<<posi.z<<", lc*"<<affection<<"};"<<endl;
|
||||
outfile<<setprecision(16)<<"Point("<<order*12+6<<") = {"<<0.0<<", "<<0.0<<", "<<posi.z<<", lc*"<<affection<<"};"<<endl;
|
||||
posi = SCS2CCS(lati_min,longi_max,R);
|
||||
check(posi);
|
||||
outfile<<setprecision(16)<<"Point("<<order*12+7<<") = {"<<posi.x<<", "<<posi.y<<", "<<posi.z<<", lc*"<<affection<<"};"<<endl;
|
||||
posi = SCS2CCS(lati_max,longi_min,r);
|
||||
check(posi);
|
||||
outfile<<setprecision(16)<<"Point("<<order*12+8<<") = {"<<posi.x<<", "<<posi.y<<", "<<posi.z<<", lc*"<<affection<<"};"<<endl;
|
||||
outfile<<setprecision(16)<<"Point("<<order*12+9<<") = {"<<0.0<<", "<<0.0<<", "<<posi.z<<", lc*"<<affection<<"};"<<endl;
|
||||
posi = SCS2CCS(lati_max,longi_max,r);
|
||||
check(posi);
|
||||
outfile<<setprecision(16)<<"Point("<<order*12+10<<") = {"<<posi.x<<", "<<posi.y<<", "<<posi.z<<", lc*"<<affection<<"};"<<endl;
|
||||
posi = SCS2CCS(lati_max,longi_min,R);
|
||||
check(posi);
|
||||
outfile<<setprecision(16)<<"Point("<<order*12+11<<") = {"<<posi.x<<", "<<posi.y<<", "<<posi.z<<", lc*"<<affection<<"};"<<endl;
|
||||
outfile<<setprecision(16)<<"Point("<<order*12+12<<") = {"<<0.0<<", "<<0.0<<", "<<posi.z<<", lc*"<<affection<<"};"<<endl;
|
||||
posi = SCS2CCS(lati_max,longi_max,R);
|
||||
check(posi);
|
||||
outfile<<setprecision(16)<<"Point("<<order*12+13<<") = {"<<posi.x<<", "<<posi.y<<", "<<posi.z<<", lc*"<<affection<<"};"<<endl;
|
||||
|
||||
outfile<<"Circle("<<order*26+1<<") = {"<<order*12+13<<", "<<order*12+12<<", "<<order*12+11<<"};"<<endl;
|
||||
outfile<<"Circle("<<order*26+2<<") = {"<<order*12+10<<", "<<order*12+9<<", "<<order*12+8<<"};"<<endl;
|
||||
outfile<<"Circle("<<order*26+3<<") = {"<<order*12+7<<", "<<order*12+6<<", "<<order*12+5<<"};"<<endl;
|
||||
outfile<<"Circle("<<order*26+4<<") = {"<<order*12+4<<", "<<order*12+3<<", "<<order*12+2<<"};"<<endl;
|
||||
outfile<<"Circle("<<order*26+5<<") = {"<<order*12+8<<", 1, "<<order*12+2<<"};"<<endl;
|
||||
outfile<<"Circle("<<order*26+6<<") = {"<<order*12+11<<", 1, "<<order*12+5<<"};"<<endl;
|
||||
outfile<<"Circle("<<order*26+7<<") = {"<<order*12+10<<", 1, "<<order*12+4<<"};"<<endl;
|
||||
outfile<<"Circle("<<order*26+8<<") = {"<<order*12+13<<", 1, "<<order*12+7<<"};"<<endl;
|
||||
outfile<<"Line("<<order*26+9<<") = {"<<order*12+5<<", "<<order*12+2<<"};"<<endl;
|
||||
outfile<<"Line("<<order*26+10<<") = {"<<order*12+7<<", "<<order*12+4<<"};"<<endl;
|
||||
outfile<<"Line("<<order*26+11<<") = {"<<order*12+11<<", "<<order*12+8<<"};"<<endl;
|
||||
outfile<<"Line("<<order*26+12<<") = {"<<order*12+13<<", "<<order*12+10<<"};"<<endl;
|
||||
outfile<<"Line Loop("<<order*26+13<<") = {"<<order*26+1<<", "<<order*26+6<<", -"<<order*26+3<<", -"<<order*26+8<<"};"<<endl;
|
||||
outfile<<"Ruled Surface("<<order*26+14<<") = {"<<order*26+13<<"};"<<endl;
|
||||
outfile<<"Line Loop("<<order*26+15<<") = {"<<order*26+2<<", "<<order*26+5<<", -"<<order*26+4<<", -"<<order*26+7<<"};"<<endl;
|
||||
outfile<<"Ruled Surface("<<order*26+16<<") = {"<<order*26+15<<"};"<<endl;
|
||||
outfile<<"Line Loop("<<order*26+17<<") = {"<<order*26+1<<", "<<order*26+11<<", -"<<order*26+2<<", -"<<order*26+12<<"};"<<endl;
|
||||
outfile<<"Ruled Surface("<<order*26+18<<") = {"<<order*26+17<<"};"<<endl;
|
||||
outfile<<"Line Loop("<<order*26+19<<") = {"<<order*26+3<<", "<<order*26+9<<", -"<<order*26+4<<", -"<<order*26+10<<"};"<<endl;
|
||||
outfile<<"Ruled Surface("<<order*26+20<<") = {"<<order*26+19<<"};"<<endl;
|
||||
outfile<<"Line Loop("<<order*26+21<<") = {"<<order*26+6<<", "<<order*26+9<<", -"<<order*26+5<<", -"<<order*26+11<<"};"<<endl;
|
||||
outfile<<"Plane Surface("<<order*26+22<<") = {"<<order*26+21<<"};"<<endl;
|
||||
outfile<<"Line Loop("<<order*26+23<<") = {"<<order*26+8<<", "<<order*26+10<<", -"<<order*26+7<<", -"<<order*26+12<<"};"<<endl;
|
||||
outfile<<"Plane Surface("<<order*26+24<<") = {"<<order*26+23<<"};"<<endl;
|
||||
outfile<<"Surface Loop("<<order*26+25<<") = {"<<order*26+24<<", "<<order*26+18<<", "<<order*26+14<<", "<<order*26+22<<", "<<order*26+16<<", "<<order*26+20<<"};"<<endl;
|
||||
outfile<<"Volume("<<order*26+26<<") = {"<<order*26+25<<"};"<<endl;
|
||||
}
|
||||
|
||||
int run(int total_num,Tess* tesseroids,char* filename)
|
||||
{
|
||||
ofstream outfile(filename);
|
||||
if (!outfile)
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"Error: Can not create output file"<<endl;
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
outfile<<"//this file is created by Tesseroid_creater"<<endl;
|
||||
outfile<<"lc = 1.0;"<<endl;
|
||||
outfile<<"Point(1) = {"<<0.0<<", "<<0.0<<", "<<0.0<<", lc};"<<endl;
|
||||
for (int i = 0; i < total_num; i++)
|
||||
{
|
||||
subrutine(i,outfile,tesseroids[i].r,tesseroids[i].R,tesseroids[i].xmin,tesseroids[i].xmax,tesseroids[i].ymin,tesseroids[i].ymax);
|
||||
}
|
||||
outfile.close();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
100
archive/Tesseroid_creater/main.cpp
Normal file
100
archive/Tesseroid_creater/main.cpp
Normal file
@@ -0,0 +1,100 @@
|
||||
#include "command.h"
|
||||
|
||||
void disp_help()
|
||||
{
|
||||
cout<<"gmsh-tesseroid 1.1 - creater a tesseroid or a set of tesseroids in .geo file"<<endl<<endl
|
||||
<<"usage: gmsh-tesseroid -o<output-file> -p<name>/<id>/<xmin>/<xmax>/<ymin>/<ymax>/<radius>/<Radius> [-p<name>/<id>/<xmin>/<xmax>/<ymin>/<ymax>/<radius>/<Radius>]..."<<endl
|
||||
<<" 3-D ranges and physical groups of a tesseroid are defined by a string of statement. "
|
||||
<<"To create multiple tesseroids, just repeat the commond. xmin and xmax indicate the longitudal range of the tesseroid which are between [-180,180]. "
|
||||
<<"And ymin and ymax represent the latitudal range between [-90,90]. Then r and R are the inner and outter radiuses of the tesseroid. "
|
||||
<<"Different tesseroids are idenified by their names. While the id classify tesseroids into different physical groups which could be given different physical properities later."<<endl
|
||||
<<" -o specify output file's name"<<endl<<endl
|
||||
<<"example: gmsh-tesseroid -otest.geo -pTone/1/0/20/0/20/800/1000 -pTtwo/2/25/45/0/20/800/1000"<<endl;
|
||||
}
|
||||
|
||||
int main(int argc,const char* argv[])
|
||||
{
|
||||
char cmd_type[1024] = {0};
|
||||
char filename[1024] = {0};
|
||||
Tess onetess;
|
||||
Tess* alltess = NULL;
|
||||
TessList list_tess;
|
||||
TessList::iterator it;
|
||||
int tess_num;
|
||||
|
||||
if (argc==1)
|
||||
{
|
||||
disp_help();
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 1; i < argc; i++)
|
||||
{
|
||||
sscanf(argv[i],"%2s",cmd_type);
|
||||
if (!strcmp(cmd_type,PARA))
|
||||
{
|
||||
if (8!=sscanf(argv[i],"%*2s%[^/]/%d/%lf/%lf/%lf/%lf/%lf/%lf",&onetess.name,&onetess.id,&onetess.xmin,&onetess.xmax,
|
||||
&onetess.ymin,&onetess.ymax,&onetess.r,&onetess.R))
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<BOLDRED<<" ignored!"<<endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (onetess.xmin>=onetess.xmax
|
||||
||onetess.ymin>=onetess.ymax
|
||||
||onetess.r>=onetess.R
|
||||
||onetess.r<=0
|
||||
||onetess.xmin<-180.0
|
||||
||onetess.xmax>180.0
|
||||
||onetess.ymin<-90.0
|
||||
||onetess.ymax>90.0)
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<BOLDRED<<" ignored!"<<endl;
|
||||
}
|
||||
else list_tess.push_back(onetess);
|
||||
}
|
||||
}
|
||||
else if (!strcmp(cmd_type,OUTPUT))
|
||||
{
|
||||
if (-1==sscanf(argv[i],"%*2s%s",filename))
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (list_tess.empty())
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"Error: No tesseroid found"<<endl;
|
||||
return 0;
|
||||
}
|
||||
else if (!strcmp(filename,""))
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"Error: No filename found"<<endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
tess_num = list_tess.size();
|
||||
alltess = new Tess [tess_num];
|
||||
int count = 0;
|
||||
for (it = list_tess.begin(); it != list_tess.end(); ++it)
|
||||
{
|
||||
onetess = *it;
|
||||
alltess[count] = onetess;
|
||||
count++;
|
||||
}
|
||||
|
||||
|
||||
run(tess_num,alltess,filename);
|
||||
|
||||
if (alltess!=NULL) delete[] alltess;
|
||||
if (!list_tess.empty()) list_tess.clear();
|
||||
return 0;
|
||||
}
|
||||
15
archive/Tesseroid_creater/makefile
Normal file
15
archive/Tesseroid_creater/makefile
Normal file
@@ -0,0 +1,15 @@
|
||||
CC = g++-8
|
||||
PROM = /usr/local/sbin/gmsh-tesseroid
|
||||
CFLAGS = -I.
|
||||
DEPS = $(shell find . -name "*.h")
|
||||
SRC = $(shell find . -name "*.cpp")
|
||||
OBJ = $(SRC:%.cpp=%.o)
|
||||
|
||||
$(PROM): $(OBJ)
|
||||
$(CC) -o $(PROM) $(OBJ) $(CFLAGS)
|
||||
|
||||
%.o:%.cpp $(DEPS)
|
||||
$(CC) -c $< -o $@ $(CFLAGS)
|
||||
|
||||
clean:
|
||||
rm -rf $(OBJ)
|
||||
14
archive/TetraGM/Commond_Line.h
Normal file
14
archive/TetraGM/Commond_Line.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#define ForGC "-gc"//ֱ<><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>쳣<EFBFBD><ECB3A3><EFBFBD><EFBFBD>
|
||||
#define ForGS "-gs"//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>쳣<EFBFBD><ECB3A3><EFBFBD><EFBFBD>
|
||||
#define ForGGC "-ggc"//ֱ<><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݶ<EFBFBD><DDB6>쳣<EFBFBD><ECB3A3><EFBFBD><EFBFBD>
|
||||
#define ForGGS "-ggs"//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݶ<EFBFBD><DDB6>쳣<EFBFBD><ECB3A3><EFBFBD><EFBFBD>
|
||||
#define ForMC "-mc"//ֱ<><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD>µĴ<C2B5><C4B4>쳣<EFBFBD><ECB3A3><EFBFBD><EFBFBD>
|
||||
#define ForMS "-ms"//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD>µĴ<C2B5><C4B4>쳣<EFBFBD><ECB3A3><EFBFBD><EFBFBD>
|
||||
#define ForMGC "-mgc"//ֱ<><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD>µĴ<C2B5><C4B4>쳣<EFBFBD><ECB3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#define ForMGS "-mgs"//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD>µĴ<C2B5><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#define VolumeElement "-v"//<2F><>Ԫ<EFBFBD><D4AA><EFBFBD><EFBFBD>
|
||||
#define SurfaceElement "-s"//<2F><>Ԫ<EFBFBD><D4AA><EFBFBD><EFBFBD>
|
||||
#define FILE "-f"//<2F>۲<EFBFBD><DBB2><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
|
||||
#define MANUAL "-m"//<2F>۲<EFBFBD><DBB2><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6><EFBFBD>
|
||||
#define ATTRI "-a"//<2F><>Ԫ<EFBFBD><D4AA><EFBFBD><EFBFBD>ֵ
|
||||
#define OUTFILE "-o"//<2F><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
|
||||
281
archive/TetraGM/Data_Func.h
Normal file
281
archive/TetraGM/Data_Func.h
Normal file
@@ -0,0 +1,281 @@
|
||||
#ifndef _DATA_FUNC_H
|
||||
#define _DATA_FUNC_H
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <string.h>
|
||||
#include <cmath>
|
||||
#include <iomanip>
|
||||
#include <ctime>
|
||||
#include <list>
|
||||
#include <omp.h>
|
||||
#include <map>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#define G0 6.67191e-3
|
||||
#define pi 3.1415926535897932384626433832795
|
||||
#define T0 50000
|
||||
#define DBL_MAX 1e+36
|
||||
using namespace std;
|
||||
|
||||
// ∏¡øΩ·ππ”Î∫Ø ˝
|
||||
struct point3d //∂®“ ∏¡øΩ·ππÃÂ
|
||||
{
|
||||
double x,y,z;
|
||||
};
|
||||
|
||||
point3d operator -(point3d a, point3d b)//÷ÿ‘ÿºı∫≈≤Ÿ◊˜∑˚◊˜”√”⁄ ∏¡ø
|
||||
{
|
||||
point3d m;
|
||||
m.x=a.x-b.x;
|
||||
m.y=a.y-b.y;
|
||||
m.z=a.z-b.z;
|
||||
return m;
|
||||
}
|
||||
|
||||
point3d operator *(int sign,point3d b)//÷ÿ‘ÿ≥À∫≈≤Ÿ◊˜∑˚◊˜”√”⁄ ∏¡ø
|
||||
{
|
||||
point3d m;
|
||||
m.x=sign*b.x;
|
||||
m.y=sign*b.y;
|
||||
m.z=sign*b.z;
|
||||
return m;
|
||||
}
|
||||
|
||||
bool operator ==(point3d a, point3d b)//÷ÿ‘ÿ¬flº≠µ»≤Ÿ◊˜∑˚◊˜”√”⁄ ∏¡ø
|
||||
{
|
||||
if(a.x==b.x&&a.y==b.y&&a.z==b.z)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else return 0;
|
||||
}
|
||||
|
||||
point3d point3d_martix(point3d a,double *m)//∂®“ ∏¡ø«∞≥Àæÿ’Û
|
||||
{
|
||||
point3d v;
|
||||
double ma[3][3];
|
||||
for(int i=0;i<3;i++)
|
||||
{
|
||||
for(int j=0;j<3;j++)
|
||||
{
|
||||
ma[i][j] = *(m+i*3+j);
|
||||
}
|
||||
}
|
||||
v.x = a.x*ma[0][0]+a.y*ma[1][0]+a.z*ma[2][0];
|
||||
v.y = a.x*ma[0][1]+a.y*ma[1][1]+a.z*ma[2][1];
|
||||
v.z = a.x*ma[0][2]+a.y*ma[1][2]+a.z*ma[2][2];
|
||||
return v;
|
||||
}
|
||||
|
||||
point3d martix_point3d(point3d a,double *m)//∂®“ ∏¡ø∫Û≥Àæÿ’Û
|
||||
{
|
||||
point3d v;
|
||||
double ma[3][3];
|
||||
for(int i=0;i<3;i++)
|
||||
{
|
||||
for(int j=0;j<3;j++)
|
||||
{
|
||||
ma[i][j] = *(m+i*3+j);
|
||||
}
|
||||
}
|
||||
v.x = a.x*ma[0][0]+a.y*ma[0][1]+a.z*ma[0][2];
|
||||
v.y = a.x*ma[1][0]+a.y*ma[1][1]+a.z*ma[1][2];
|
||||
v.z = a.x*ma[2][0]+a.y*ma[2][1]+a.z*ma[2][2];
|
||||
return v;
|
||||
}
|
||||
|
||||
double dot(point3d a, point3d b)//∂®“ ∏¡øµ„≥À
|
||||
{
|
||||
return a.x*b.x+a.y*b.y+a.z*b.z;
|
||||
}
|
||||
|
||||
point3d cross(point3d a,point3d b)//∂®“ ∏¡ø≤Ê≥À
|
||||
{
|
||||
point3d v;
|
||||
v.x = a.y*b.z-a.z*b.y;
|
||||
v.y = a.z*b.x-a.x*b.z;
|
||||
v.z = a.x*b.y-a.y*b.x;
|
||||
return v;
|
||||
}
|
||||
|
||||
double* kron_v(point3d a,point3d b)//∂®“ ∏¡ø’≈¡øª˝
|
||||
{
|
||||
double t[3][3];
|
||||
t[0][0]=a.x*b.x; t[0][1]=a.x*b.y; t[0][2]=a.x*b.z;
|
||||
t[1][0]=a.y*b.x; t[1][1]=a.y*b.y; t[1][2]=a.y*b.z;
|
||||
t[2][0]=a.z*b.x; t[2][1]=a.z*b.y; t[2][2]=a.z*b.z;
|
||||
return t[0];
|
||||
}
|
||||
|
||||
double L_point3d(point3d v)//«Û ∏¡øæ‡◊¯±Í‘≠µ„懿Î
|
||||
{
|
||||
return sqrt(v.x*v.x+v.y*v.y+v.z*v.z);
|
||||
}
|
||||
|
||||
double Dis_point3d(point3d a,point3d b)//«Û¡Ω∏ˆ ∏¡ø÷’∂À懿Î
|
||||
{
|
||||
return sqrt(pow(a.x-b.x,2)+pow(a.y-b.y,2)+pow(a.z-b.z,2));
|
||||
}
|
||||
|
||||
point3d nor_point3d(point3d v)//º∆À„“ª∏ˆ ∏¡øµƒµ•Œª ∏¡ø
|
||||
{
|
||||
double Length;
|
||||
point3d nor_v;
|
||||
Length = sqrt(v.x*v.x+v.y*v.y+v.z*v.z);
|
||||
nor_v.x = v.x/Length;
|
||||
nor_v.y = v.y/Length;
|
||||
nor_v.z = v.z/Length;
|
||||
return nor_v;
|
||||
}
|
||||
//æÿ’Û∫Ø ˝
|
||||
double *martix_martix(double *a,double *b)//æÿ’Ûœ‡≥Àa*b
|
||||
{
|
||||
double m[3][3],t[3][3],r[3][3];
|
||||
int i,j;
|
||||
for(i=0;i<3;i++)
|
||||
{
|
||||
for(j=0;j<3;j++)
|
||||
{
|
||||
t[i][j] = *(a+i*3+j);
|
||||
r[i][j] = *(b+i*3+j);
|
||||
}
|
||||
}
|
||||
for(i=0;i<3;i++)
|
||||
{
|
||||
for(j=0;j<3;j++)
|
||||
{
|
||||
m[i][j] = t[i][0]*r[0][j]+t[i][1]*r[1][j]+t[i][2]*r[2][j];
|
||||
}
|
||||
}
|
||||
return m[0];
|
||||
}
|
||||
|
||||
double *martix_T(double *a)//æÿ’Û◊™÷√
|
||||
{
|
||||
double m[3][3],r[3][3];
|
||||
int i,j;
|
||||
for(i=0;i<3;i++)
|
||||
{
|
||||
for(j=0;j<3;j++)
|
||||
{
|
||||
r[i][j] = *(a+i*3+j);
|
||||
}
|
||||
}
|
||||
for(i=0;i<3;i++)
|
||||
{
|
||||
for(j=0;j<3;j++)
|
||||
{
|
||||
m[i][j] = r[j][i];
|
||||
}
|
||||
}
|
||||
return m[0];
|
||||
}
|
||||
|
||||
// ˝æ›Ω·ππ”Î≤Ÿ◊˜
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
struct F//√Ê’≈¡øª˝
|
||||
{
|
||||
double kron[3][3];
|
||||
};
|
||||
struct E//±fl’≈¡øª˝
|
||||
{
|
||||
double kron[3][3];
|
||||
};
|
||||
struct tetra //∂®“ÂÀƒ√ÊÃÂΩ·ππÃÂ
|
||||
{
|
||||
int No;//Àƒ√ÊÖÚ∫≈
|
||||
int ver[4];//œ‡”¶Àƒ√ÊÃÂ∂•µ„–Ú∫≈
|
||||
int ordered_ver[4][3];//≈≈–Ú∫ÛµƒÀƒ∏ˆ√ʵƒµ„À˜“˝∫≈
|
||||
double *attribute;//Àƒ√Êàٖ‘÷∏’Î
|
||||
F F_kron[4];//Àƒ√ÊÃÂ√Ê’≈¡øª˝
|
||||
E E_kron[6];//Àƒ√Êñfl’≈¡øª˝
|
||||
double E_len[6];//Àƒ√Êñfl≥§∂»
|
||||
};
|
||||
typedef list<tetra> tetra_list;
|
||||
|
||||
struct vertex //∂®“Â∂•µ„Ω·ππÃÂ
|
||||
{
|
||||
int No;//∂•µ„–Ú∫≈
|
||||
point3d vt;;//∂•µ„◊¯±Í
|
||||
};
|
||||
|
||||
struct edge
|
||||
{
|
||||
int No;
|
||||
int ver[2];
|
||||
int nature;
|
||||
double length;
|
||||
double E[3][3];
|
||||
};
|
||||
typedef list<edge> edge_list;
|
||||
|
||||
struct face
|
||||
{
|
||||
int No;
|
||||
int ver[3];
|
||||
int nature;
|
||||
double F[3][3];
|
||||
};
|
||||
typedef list<face> face_list;
|
||||
|
||||
struct sphere_point//«Ú◊¯±Íµ„Ω·ππÃÂ
|
||||
{
|
||||
double phi,thet,radius;
|
||||
};
|
||||
|
||||
point3d SCS2CCS(sphere_point p1)//«Ú◊¯±Í◊™÷±Ω«◊¯±Í
|
||||
{
|
||||
point3d v;
|
||||
v.x = p1.radius*sin((0.5-p1.thet/180.0)*pi)*cos((2.0+p1.phi/180.0)*pi);
|
||||
v.y = p1.radius*sin((0.5-p1.thet/180.0)*pi)*sin((2.0+p1.phi/180.0)*pi);
|
||||
v.z = p1.radius*cos((0.5-p1.thet/180.0)*pi);
|
||||
return v;
|
||||
}
|
||||
|
||||
void find_left(int &L1,int &L2,int e,int e2)
|
||||
{
|
||||
for(int i=0;i<4;i++)
|
||||
{
|
||||
for(int j=0;j<4;j++)
|
||||
{
|
||||
if(i!=j&&i!=e&&i!=e2&&j!=e&&j!=e2&&i<j)
|
||||
{
|
||||
L1=i;
|
||||
L2=j;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int re_order(point3d refer,point3d point1,point3d &point2,point3d &point3)
|
||||
{
|
||||
point3d v12=point2-point1;
|
||||
point3d v23=point3-point2;
|
||||
point3d v_ref=refer-point1;
|
||||
|
||||
point3d v_nor = cross(v12,v23);
|
||||
|
||||
if(dot(v_ref,v_nor)>0)
|
||||
{
|
||||
point3d temp;
|
||||
temp=point2;point2=point3;point3=temp;
|
||||
return 1;
|
||||
}
|
||||
else return 0;
|
||||
}
|
||||
|
||||
void re_order2(point3d v1,point3d v2,point3d &ref1,point3d &ref2)
|
||||
{
|
||||
point3d v12=v2-v1;
|
||||
point3d v1ref1=ref1-v1;
|
||||
point3d v1ref2=ref2-v1;
|
||||
point3d nor_v121ref1=cross(v12,v1ref1);
|
||||
if(dot(nor_v121ref1,v1ref2)>0)
|
||||
{
|
||||
point3d temp;
|
||||
temp=ref1;ref1=ref2;ref2=temp;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
1124
archive/TetraGM/Tetra_G.h
Normal file
1124
archive/TetraGM/Tetra_G.h
Normal file
File diff suppressed because it is too large
Load Diff
429
archive/TetraGM/main.cpp
Normal file
429
archive/TetraGM/main.cpp
Normal file
@@ -0,0 +1,429 @@
|
||||
/*
|
||||
TetraGM4.0 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
|
||||
2015/11/12
|
||||
Ϊ<><CEAA><EFBFBD><EFBFBD>֮ǰ<D6AE>汾<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̣<EFBFBD><CCA3><EFBFBD>4.0<EFBFBD>汾<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǽ<EFBFBD><EFBFBD>Գ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽṹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD><EFBFBD>
|
||||
ͨ<EFBFBD><EFBFBD>ģ<EFBFBD>ͶԱ<EFBFBD>ʵ<EFBFBD>飬<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬʱ4.0<EFBFBD>汾<EFBFBD><EFBFBD><EFBFBD>ʺ<EFBFBD><EFBFBD>벢<EFBFBD>м<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
<EFBFBD>ij<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ṹ<EFBFBD><EFBFBD>δ<EFBFBD>ﵽ<EFBFBD><EFBFBD><EFBFBD>Ż<EFBFBD>״̬<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ż<EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD>ÿһ<EFBFBD><EFBFBD><EFBFBD>ߵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ÿ
|
||||
һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.msh<73>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>Ѱ<EFBFBD><D1B0>ͻ<EFBFBD>ƿڡ<C6BF>
|
||||
2015/11/13
|
||||
<20><><EFBFBD><EFBFBD><EFBFBD>ڳ<EFBFBD><DAB3><EFBFBD><EFBFBD>м<EFBFBD><D0BC><EFBFBD><EFBFBD>˲<EFBFBD><CBB2><EFBFBD>ִ<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EEA3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD><EFBFBD>˽<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>i5<69><35>4G<34>ڴ<EFBFBD>ƽ̨<C6BD><CCA8>
|
||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԼΪԭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD>ʵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڸ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD><EFBFBD>ƽ̨<EFBFBD><EFBFBD>ȡ<EFBFBD>ø<EFBFBD><EFBFBD>õijɼ<EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽṹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽṹ<EFBFBD><EFBFBD><EFBFBD>¡<EFBFBD>
|
||||
point3d<33><64>ʸ<EFBFBD><CAB8><EFBFBD>ṹ<EFBFBD><E1B9B9><EFBFBD><EFBFBD>ʸ<EFBFBD><CAB8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>꣨x,y,z<><7A>
|
||||
sphere_point<6E><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>/<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ľ<EFBFBD>γֵ<CEB3><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>뾶
|
||||
vertex<65><78><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ṹ<EFBFBD><E1B9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ţ<EFBFBD><C5A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
edge<67><65><EFBFBD>߽ṹ<DFBD>壩<EFBFBD><E5A3A9><EFBFBD>ߵı<DFB5><C4B1>ţ<EFBFBD><C5A3>ߵĶ<DFB5><C4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ߵ<EFBFBD><DFB5><EFBFBD><EFBFBD>ԣ<EFBFBD><D4A3>ߵij<DFB5><C4B3>ȣ<EFBFBD><C8A3>ߵ<EFBFBD><DFB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>E
|
||||
face<63><65><EFBFBD><EFBFBD><EFBFBD>ṹ<EFBFBD>壩<EFBFBD><E5A3A9><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><C4B1>ţ<EFBFBD><C5A3><EFBFBD><EFBFBD>Ķ<EFBFBD><C4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԣ<EFBFBD><D4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>F
|
||||
tetra<72><61><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ṹ<EFBFBD>壩<EFBFBD><E5A3A9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>š<EFBFBD>
|
||||
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĸ<EFBFBD><C4B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>š<EFBFBD>
|
||||
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ε<EFBFBD><CEB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ţ<EFBFBD><C5A3><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD>ں<EFBFBD><DABA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD>⺯<EFBFBD><E2BAAF><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD>ã<EFBFBD>
|
||||
<20>ĸ<EFBFBD><C4B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>F<EFBFBD><46>
|
||||
<20><><EFBFBD><EFBFBD><EFBFBD>ߵ<EFBFBD><DFB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>E<EFBFBD><45><EFBFBD>ߵij<DFB5><C4B3>ȣ<EFBFBD>F<EFBFBD><46>E<EFBFBD><45><EFBFBD>߳<EFBFBD><DFB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǵĹ<C7B5><C4B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԣ<EFBFBD><D4A3><EFBFBD><EFBFBD>ȼ<EFBFBD><C8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>㣩
|
||||
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD>ṹ<EFBFBD><EFBFBD>Data_Func.h<>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫʹ<D2AA>õ<EFBFBD><C3B5><EFBFBD>ʸ<EFBFBD><CAB8><EFBFBD><EFBFBD><EFBFBD>㺯<EFBFBD><E3BAAF>
|
||||
Commond_Line.h<>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˳<EFBFBD><CBB3><EFBFBD><EFBFBD>й涨<D0B9><E6B6A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>в<EFBFBD><D0B2><EFBFBD><EFBFBD><EFBFBD>
|
||||
res_reg.h<>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˼<EFBFBD><CBBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD>д<EFBFBD><D0B4><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
|
||||
Tetra_G.h<>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
Tetra_M.h<>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˴ų<CBB4><C5B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
main.cppʶ<70><CAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EEA3AC>ȡ<EFBFBD><C8A1>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ
|
||||
*/
|
||||
|
||||
#include "Tetra_G.h"
|
||||
#include "Commond_Line.h"
|
||||
|
||||
int caltype = NULL;//<2F><><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF>
|
||||
int fietype = NULL;//<2F>۲<EFBFBD><DBB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
int attritype = NULL;//Ԫ<><D4AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
int elementtype = NULL;//<2F><><EFBFBD><EFBFBD>Ԫ<EFBFBD><D4AA><EFBFBD><EFBFBD>
|
||||
int space_num;//<2F>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>пո<D0BF><D5B8>ĸ<EFBFBD><C4B8><EFBFBD>
|
||||
double attri[3];//Ԫ<><D4AA><EFBFBD><EFBFBD>
|
||||
double ob_info[7];//<2F>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD>۲<EFBFBD><DBB2><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
||||
string _attri;
|
||||
string meshname;
|
||||
string fiename;
|
||||
string savename;
|
||||
stringstream stemp;
|
||||
|
||||
void disp_info()
|
||||
{
|
||||
cout<<"tetragm 0.5.0 - forward modeling of gravity and magnetic data and their gradient data based on unstructured grid"<<endl<<endl
|
||||
<<"usage: tetragm -gc|ggc|gs|ggs|mc|ms|mgc|mgs -a[<para1>/<para2>/<para3>/<para4>] -v<mesh-file>|s<mesh-file>"<<endl
|
||||
<<" -F<fie-file>|M[<xmin>/<dx>/<xmax>/<ymin>/<dy>/<ymax>/<altitude>][<lati_min>/<d_lati>/<lati_max>/"<<endl
|
||||
<<" <longi_min>/<d_longi>/<longi_max>/<radius>] -o<output-file>"<<endl
|
||||
<<" -gc forward modeling gravity data in Cartesian coordinate"<<endl
|
||||
<<" -ggc forward modeling gravity gradient data in Cartesian coordinate"<<endl
|
||||
<<" -gs forward modeling gravity data in spherical coordinate"<<endl
|
||||
<<" -ggs forward modeling gravity gradient data in spherical coordinate"<<endl
|
||||
<<" -mc forward modeling magnetic data in Cartesian coordinate"<<endl
|
||||
<<" -mgc forward modeling magnetic gradient data in Cartesian coordinate"<<endl
|
||||
<<" -ms forward modeling magnetic data in spherical coordinate"<<endl
|
||||
<<" -mgs forward modeling magnetic gradient data in spherical coordinate"<<endl
|
||||
<<" -a define cells' physical attributes. If no arguments are followed behind -a, it means that the cells'"<<endl
|
||||
<<" attributes are defined by the mesh-file individually. For forward modeling gravity and its gradient"<<endl
|
||||
<<" data, density is the only parameter the program need. In this case, you just need to specify 'para1'."<<endl
|
||||
<<" For example '1.0///'. For forward modeling magnetic and its gradient data. Parameters are as follow"<<endl
|
||||
<<" para1 "<<endl
|
||||
<<"-Vstring: use volume element, followed by mesh file's name"<<endl
|
||||
<<"-Sstring: use surface element, followed by mesh file's name"<<endl
|
||||
<<"-Fstring: read observation points from a .fie file, followed by file name"<<endl
|
||||
<<"-Mdouble/double/double/double/double/double/double: user defined observation points, format:"<<endl
|
||||
<<"xmin/dx/xmax/ymin/dy/ymax/altitude"<<endl
|
||||
<<"lati_min/d_lati/lati_max/longi_min/d_longi/longi_max/radius"<<endl
|
||||
<<"-Ostring: Output file, followed by file name"<<endl;
|
||||
}
|
||||
|
||||
int typeget(char *str, const char* str2,string &str3)
|
||||
{
|
||||
char* strp = strstr(str, str2); // <20><><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>str<74>в<EFBFBD><D0B2><EFBFBD>str2<72><32>
|
||||
if (strp == NULL)
|
||||
{
|
||||
return 0; // <20><><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
string temp = str;
|
||||
str3=temp.substr(strlen(str2));//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>str2<72><32><EFBFBD><EFBFBD><EFBFBD>Ӿ<EFBFBD>
|
||||
return 1;
|
||||
}
|
||||
|
||||
string& replace_all(string& str,const string& old_value,const string& new_value,int &num) //<2F>滻str<74><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD>lod_valueΪnew_value,<2C><><EFBFBD>ر<EFBFBD><D8B1>滻<EFBFBD><E6BBBB>lod_value<75>ĸ<EFBFBD><C4B8><EFBFBD>
|
||||
{
|
||||
int count = 0;
|
||||
for(string::size_type pos(0);pos!=string::npos;pos+=new_value.length()){
|
||||
if((pos=str.find(old_value,pos))!=string::npos){
|
||||
str.replace(pos,old_value.length(),new_value);
|
||||
count++;
|
||||
}
|
||||
else break;
|
||||
}
|
||||
num = count;
|
||||
return str;
|
||||
}
|
||||
|
||||
/*
|
||||
caltype -GC:1 -GGC:2 -GS:3 -GGS:4 -MC:5 -MGC:6 -MS:7 -MGS:8
|
||||
elementtype -V:1 -S:2
|
||||
attritype -F:1 -M:2
|
||||
*/
|
||||
struct Call_func
|
||||
{
|
||||
int callback_func(int caltype,int elementtype,string filename,string fiename,string savename)
|
||||
{
|
||||
switch (caltype)
|
||||
{
|
||||
case 1:{
|
||||
Tetra_G _Project;
|
||||
if(_Project.info_taker_run(caltype,filename,fiename,savename)) return 1;
|
||||
}break;
|
||||
case 2:{
|
||||
Tetra_G _Project;
|
||||
if(_Project.info_taker_run(caltype,filename,fiename,savename)) return 1;
|
||||
}break;
|
||||
case 3:{
|
||||
Tetra_G _Project;
|
||||
if(_Project.info_taker_run(caltype,filename,fiename,savename)) return 1;
|
||||
}break;
|
||||
case 4:{
|
||||
Tetra_G _Project;
|
||||
if(_Project.info_taker_run(caltype,filename,fiename,savename)) return 1;
|
||||
}break;
|
||||
case 5:{
|
||||
cout<<"Unfished!"<<endl;
|
||||
}break;
|
||||
case 6:{
|
||||
cout<<"Unfished!"<<endl;
|
||||
}break;
|
||||
case 7:{
|
||||
cout<<"Unfished!"<<endl;
|
||||
}break;
|
||||
case 8:{
|
||||
cout<<"Unfished!"<<endl;
|
||||
}break;
|
||||
default:{
|
||||
cout<<"An error picked at 'callback_func()', program stopped...";
|
||||
exit(0);
|
||||
}break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int callback_func(int caltype,int elementtype,string filename,double* ob_info,string savename)
|
||||
{
|
||||
switch (caltype)
|
||||
{
|
||||
case 1:{
|
||||
Tetra_G _Project;
|
||||
if(_Project.info_taker_run(caltype,filename,ob_info,savename)) return 1;
|
||||
}break;
|
||||
case 2:{
|
||||
Tetra_G _Project;
|
||||
if(_Project.info_taker_run(caltype,filename,ob_info,savename)) return 1;
|
||||
}break;
|
||||
case 3:{
|
||||
Tetra_G _Project;
|
||||
if(_Project.info_taker_run(caltype,filename,ob_info,savename)) return 1;
|
||||
}break;
|
||||
case 4:{
|
||||
Tetra_G _Project;
|
||||
if(_Project.info_taker_run(caltype,filename,ob_info,savename)) return 1;
|
||||
}break;
|
||||
case 5:{
|
||||
cout<<"Unfished!"<<endl;
|
||||
}break;
|
||||
case 6:{
|
||||
cout<<"Unfished!"<<endl;
|
||||
}break;
|
||||
case 7:{
|
||||
cout<<"Unfished!"<<endl;
|
||||
}break;
|
||||
case 8:{
|
||||
cout<<"Unfished!"<<endl;
|
||||
}break;
|
||||
default:{
|
||||
cout<<"An error picked at 'callback_func()', program stopped...";
|
||||
exit(0);
|
||||
}break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int callback_func(int caltype,int elementtype,string filename,string fiename,string savename,double* attri)
|
||||
{
|
||||
switch (caltype)
|
||||
{
|
||||
case 1:{
|
||||
Tetra_G _Project;
|
||||
if(_Project.info_taker_run(caltype,filename,fiename,savename,attri)) return 1;
|
||||
}break;
|
||||
case 2:{
|
||||
Tetra_G _Project;
|
||||
if(_Project.info_taker_run(caltype,filename,fiename,savename,attri)) return 1;
|
||||
}break;
|
||||
case 3:{
|
||||
Tetra_G _Project;
|
||||
if(_Project.info_taker_run(caltype,filename,fiename,savename,attri)) return 1;
|
||||
}break;
|
||||
case 4:{
|
||||
Tetra_G _Project;
|
||||
if(_Project.info_taker_run(caltype,filename,fiename,savename,attri)) return 1;
|
||||
}break;
|
||||
case 5:{
|
||||
cout<<"Unfished!"<<endl;
|
||||
}break;
|
||||
case 6:{
|
||||
cout<<"Unfished!"<<endl;
|
||||
}break;
|
||||
case 7:{
|
||||
cout<<"Unfished!"<<endl;
|
||||
}break;
|
||||
case 8:{
|
||||
cout<<"Unfished!"<<endl;
|
||||
}break;
|
||||
default:{
|
||||
cout<<"An error picked at 'callback_func()', program stopped...";
|
||||
exit(0);
|
||||
}break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int callback_func(int caltype,int elementtype,string filename,double* ob_info,string savename,double* attri)
|
||||
{
|
||||
switch (caltype)
|
||||
{
|
||||
case 1:{
|
||||
Tetra_G _Project;
|
||||
if(_Project.info_taker_run(caltype,filename,ob_info,savename,attri)) return 1;
|
||||
}break;
|
||||
case 2:{
|
||||
Tetra_G _Project;
|
||||
if(_Project.info_taker_run(caltype,filename,ob_info,savename,attri)) return 1;
|
||||
}break;
|
||||
case 3:{
|
||||
Tetra_G _Project;
|
||||
if(_Project.info_taker_run(caltype,filename,ob_info,savename,attri)) return 1;
|
||||
}break;
|
||||
case 4:{
|
||||
Tetra_G _Project;
|
||||
if(_Project.info_taker_run(caltype,filename,ob_info,savename,attri)) return 1;
|
||||
}break;
|
||||
case 5:{
|
||||
cout<<"Unfished!"<<endl;
|
||||
}break;
|
||||
case 6:{
|
||||
cout<<"Unfished!"<<endl;
|
||||
}break;
|
||||
case 7:{
|
||||
cout<<"Unfished!"<<endl;
|
||||
}break;
|
||||
case 8:{
|
||||
cout<<"Unfished!"<<endl;
|
||||
}break;
|
||||
default:{
|
||||
cout<<"An error picked at 'callback_func()', program stopped...";
|
||||
exit(0);
|
||||
}break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc,char* argv[])
|
||||
{
|
||||
if(argc==1){
|
||||
disp_info();
|
||||
}
|
||||
else{
|
||||
Call_func Call;
|
||||
|
||||
for(int i=1;i<=argc-1;i++){
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF>
|
||||
if(!strcmp(argv[i],ForGC)) caltype=1;
|
||||
else if(!strcmp(argv[i],ForGGC)) caltype=2;
|
||||
else if(!strcmp(argv[i],ForGS)) caltype=3;
|
||||
else if(!strcmp(argv[i],ForGGS)) caltype=4;
|
||||
else if(!strcmp(argv[i],ForMC)) caltype=5;
|
||||
else if(!strcmp(argv[i],ForMGC)) caltype=6;
|
||||
else if(!strcmp(argv[i],ForMS)) caltype=7;
|
||||
else if(!strcmp(argv[i],ForMGS)) caltype=8;
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>Ԫ<EFBFBD><D4AA><EFBFBD>ԣ<EFBFBD><D4A3><EFBFBD>Ҫ<EFBFBD>ͺ<EFBFBD>
|
||||
if(typeget(argv[i],ATTRI,_attri)){
|
||||
if(_attri!=""){
|
||||
attritype=2;
|
||||
replace_all(_attri,"/"," ",space_num);
|
||||
stemp.clear();
|
||||
stemp.str(_attri);
|
||||
if(space_num==3){
|
||||
for(int i=0;i<4;i++)
|
||||
{
|
||||
if(!(stemp>>attri[i])){
|
||||
attri[i]=DBL_MAX;
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
cout<<"Insufficient attributes information, program stoped...";//<2F>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD>۲<EFBFBD><DBB2><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹͣ
|
||||
system("pause");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
}
|
||||
else attritype=1;//<2F><><EFBFBD><EFBFBD><DEB8><EFBFBD>Ԫ<EFBFBD><D4AA>Ϣ
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>Ԫ<EFBFBD><D4AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
|
||||
if(typeget(argv[i],VolumeElement,meshname)){
|
||||
elementtype = 1;
|
||||
if(meshname==""){
|
||||
cout<<"No mesh file name, program stoped...";//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹͣ
|
||||
system("pause");
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
else if(typeget(argv[i],SurfaceElement,meshname)){
|
||||
elementtype = 2;
|
||||
if(meshname==""){
|
||||
cout<<"No mesh file name, program stoped...";//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹͣ
|
||||
system("pause");
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD>۲<EFBFBD><DBB2><EFBFBD>Ϣ
|
||||
if(typeget(argv[i],FILE,fiename)){
|
||||
fietype=1;
|
||||
if(fiename==""){
|
||||
cout<<"No observation points' information, program stoped...";//<2F>۲<DEB9><DBB2><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹͣ
|
||||
system("pause");
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
else if(typeget(argv[i],MANUAL,fiename)){
|
||||
fietype=2;
|
||||
if(fiename==""){
|
||||
cout<<"No observation points' information, program stoped...";//<2F><><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD>۲<EFBFBD><DBB2><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹͣ
|
||||
system("pause");
|
||||
exit(0);
|
||||
}
|
||||
else{
|
||||
replace_all(fiename,"/"," ",space_num);
|
||||
stemp.clear();
|
||||
stemp.str(fiename);
|
||||
if(space_num==6){
|
||||
for(int i=0;i<7;i++)
|
||||
{
|
||||
if(!(stemp>>ob_info[i])){
|
||||
ob_info[i]=DBL_MAX;
|
||||
}
|
||||
}
|
||||
for(int i=0;i<7;i++)
|
||||
{
|
||||
if(ob_info[i]==DBL_MAX){
|
||||
cout<<"Wrong observation points' information, program stoped...";//<2F>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD>۲<EFBFBD><DBB2><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹͣ
|
||||
system("pause");
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
if(ob_info[1]<0||ob_info[4]<0||ob_info[0]>ob_info[2]||ob_info[3]>ob_info[5]||(ob_info[0]+ob_info[1])>ob_info[2]||(ob_info[3]+ob_info[4])>ob_info[5]){
|
||||
cout<<"Wrong observation points' information, program stoped...";//<2F>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD>۲<EFBFBD><DBB2><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹͣ
|
||||
system("pause");
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
else{
|
||||
cout<<"Wrong observation points' information, program stoped...";//<2F>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD>۲<EFBFBD><DBB2><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹͣ
|
||||
system("pause");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
|
||||
if(typeget(argv[i],OUTFILE,savename)){
|
||||
if(savename==""){
|
||||
cout<<"No output file name, program stoped...";//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹͣ
|
||||
system("pause");
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(caltype==NULL||fietype==NULL||attritype==NULL||elementtype==NULL||savename==""){
|
||||
cout<<"Wrong commond line, program stoped...";
|
||||
system("pause");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if(fietype==1&&attritype==1){
|
||||
if(Call.callback_func(caltype,elementtype,meshname,fiename,savename)){
|
||||
system("pause");
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
else if(fietype==1&&attritype==2){
|
||||
if(Call.callback_func(caltype,elementtype,meshname,fiename,savename,attri)){
|
||||
system("pause");
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
else if(fietype==2&&attritype==1){
|
||||
if(Call.callback_func(caltype,elementtype,meshname,ob_info,savename)){
|
||||
system("pause");
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
else if(fietype==2&&attritype==2){
|
||||
if(Call.callback_func(caltype,elementtype,meshname,ob_info,savename,attri)){
|
||||
system("pause");
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
else{
|
||||
cout<<"A program error is detected, program stopped...";
|
||||
system("pause");
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
103
archive/TetraGM/res_reg.h
Normal file
103
archive/TetraGM/res_reg.h
Normal file
@@ -0,0 +1,103 @@
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD>м<EFBFBD><D0BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ռ<EFBFBD><D5BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#ifndef _RES_REG_H
|
||||
#define _RES_REG_H
|
||||
#include "Data_Func.h"
|
||||
|
||||
class res_reg
|
||||
{
|
||||
public:
|
||||
res_reg(int);
|
||||
~res_reg();
|
||||
int res_add(double *,int);
|
||||
int savedat(string,int,sphere_point *);
|
||||
int savedat(string,int,point3d *);
|
||||
int check(int);
|
||||
private:
|
||||
double *tempresult;
|
||||
};
|
||||
|
||||
res_reg::res_reg(int M)
|
||||
{
|
||||
tempresult = new double [M];
|
||||
for(int i=0;i<M;i++)
|
||||
{
|
||||
tempresult[i]=0;
|
||||
}
|
||||
}
|
||||
|
||||
res_reg::~res_reg()
|
||||
{
|
||||
if(tempresult) delete []tempresult;
|
||||
}
|
||||
|
||||
int res_reg::res_add(double *result,int M)
|
||||
{
|
||||
for(int i=0;i<M;i++)
|
||||
{
|
||||
tempresult[i]+=*(result+i);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int res_reg::savedat(string filename,int sum,sphere_point *fie)
|
||||
{
|
||||
ofstream fout;
|
||||
string tempname = filename + ".dat";
|
||||
const char* savename = tempname.c_str();
|
||||
fout.open(savename);
|
||||
if(!fout)
|
||||
{
|
||||
cout<<"can't create "<<savename<<endl;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout<<"saving "<<savename<<"..."<<endl;
|
||||
fout<<"Longitude(degree) Latitude(degree) Radius(m) Value"<<endl;
|
||||
for(int i=0;i<sum;i++)
|
||||
{
|
||||
fout<<setprecision(16)<<fie[i].phi<<" "<<fie[i].thet<<" "<<fie[i].radius<<" "<<tempresult[i]<<endl;
|
||||
}
|
||||
fout.close();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int res_reg::savedat(string filename,int sum,point3d *fie)
|
||||
{
|
||||
ofstream fout;
|
||||
string tempname = filename + ".dat";
|
||||
const char* savename = tempname.c_str();
|
||||
fout.open(savename);
|
||||
if(!fout)
|
||||
{
|
||||
cout<<"can't create "<<filename<<endl;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout<<"saving "<<filename<<"..."<<endl;
|
||||
//fout<<"X(m) Y(m) Z(m) Value"<<endl;
|
||||
for(int i=0;i<sum;i++)
|
||||
{
|
||||
//fout<<setprecision(16)<<fie[i].x<<" "<<fie[i].y<<" "<<fie[i].z<<" "<<tempresult[i]<<endl;
|
||||
fout<<setprecision(16)<<fie[i].x<<" "<<fie[i].y<<" "<<fie[i].z<<" "<<tempresult[i]<<endl;
|
||||
}
|
||||
fout.close();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int res_reg::check(int sum)
|
||||
{
|
||||
for(int i=0;i<sum;i++)
|
||||
{
|
||||
if(tempresult[i]!=tempresult[i])
|
||||
{
|
||||
cout<<"A non-numeric data is detected."<<endl;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
5
archive/addnoise/CMakeLists.txt
Normal file
5
archive/addnoise/CMakeLists.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
add_executable(addnoise main.cpp)
|
||||
# 第二种方式指定目标文件的路径 这个方式目标文件夹中将只包含目标文件而没有中间文件
|
||||
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
|
||||
# 设置安装地址
|
||||
install(TARGETS addnoise RUNTIME DESTINATION selfpro)
|
||||
125
archive/addnoise/addnoise.h
Normal file
125
archive/addnoise/addnoise.h
Normal file
@@ -0,0 +1,125 @@
|
||||
#include "head.h"
|
||||
|
||||
class addnoise
|
||||
{
|
||||
public:
|
||||
addnoise(){}
|
||||
~addnoise(){}
|
||||
int runtine(char*,char*,char*,char*);
|
||||
nodeArray readata(char*,char*);
|
||||
int addNoise(char*);
|
||||
int outRes(char*);
|
||||
private:
|
||||
nodeArray data;
|
||||
double noise_mean,noise_dev;
|
||||
};
|
||||
|
||||
int addnoise::runtine(char* ifile,char* ofile,char* nos,char* col)
|
||||
{
|
||||
data = readata(ifile,col);
|
||||
if(data.empty()) return -1;
|
||||
if (addNoise(nos)) return -1;
|
||||
if (outRes(ofile)) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
nodeArray addnoise::readata(char* filename,char* order)
|
||||
{
|
||||
int temp_int;
|
||||
double temp_d;
|
||||
nodeArray input_data;
|
||||
node temp_node;
|
||||
_1dArray tempRow;
|
||||
_1iArray orders;
|
||||
string temp_str;
|
||||
stringstream temp_ss;
|
||||
|
||||
temp_ss.str("");
|
||||
temp_ss.clear();
|
||||
temp_ss << order;
|
||||
temp_ss >> temp_str;
|
||||
temp_str = replace_all(temp_str,","," ",temp_int);
|
||||
temp_ss.str("");
|
||||
temp_ss.clear();
|
||||
temp_ss << temp_str;
|
||||
while (temp_ss >> temp_int)
|
||||
{
|
||||
orders.push_back(temp_int);
|
||||
}
|
||||
|
||||
//打开文件
|
||||
ifstream datain;
|
||||
if (open_infile(datain,filename)) return input_data;
|
||||
|
||||
//读入数据
|
||||
while (getline(datain,temp_str))
|
||||
{
|
||||
if (*(temp_str.begin()) == '#') continue;
|
||||
else
|
||||
{
|
||||
//读入行
|
||||
temp_ss.str("");
|
||||
temp_ss.clear();
|
||||
temp_ss.str(temp_str);
|
||||
//解析数据行
|
||||
if(!tempRow.empty()) tempRow.clear();
|
||||
while (temp_ss >> temp_d)
|
||||
{
|
||||
tempRow.push_back(temp_d);
|
||||
}
|
||||
if(!temp_node.val.empty()) temp_node.val.clear();
|
||||
for (int i = 0; i < orders.size(); i++)
|
||||
{
|
||||
temp_node.val.push_back(tempRow.at(orders.at(i)));
|
||||
}
|
||||
|
||||
input_data.push_back(temp_node);
|
||||
}
|
||||
}
|
||||
|
||||
datain.close();
|
||||
return input_data;
|
||||
}
|
||||
|
||||
int addnoise::addNoise(char* para)
|
||||
{
|
||||
double noise_value;
|
||||
if (2 != sscanf(para,"%lf/%lf",&noise_mean,&noise_dev))
|
||||
{
|
||||
cout << "error ==> wrong parameters: " << para << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
//添加高斯噪声值
|
||||
default_random_engine generator;
|
||||
normal_distribution<double> dist(noise_mean, noise_dev);
|
||||
|
||||
for (int i = 0; i < data.size(); i++)
|
||||
{
|
||||
noise_value = dist(generator);
|
||||
data.at(i).val.push_back(data.at(i).val.back()+noise_value);
|
||||
data.at(i).val.push_back(noise_value);
|
||||
data.at(i).val.push_back(noise_dev);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int addnoise::outRes(char* filename)
|
||||
{
|
||||
ofstream outfile;
|
||||
if (open_outfile(outfile,filename)) return -1;
|
||||
|
||||
outfile << "# noise-mean = " << noise_mean << endl;
|
||||
outfile << "# noise-deviation = " << noise_dev << endl;
|
||||
outfile << "# <-- copied data --> input+noise noise dev" << endl;
|
||||
for (int i = 0; i < data.size(); i++)
|
||||
{
|
||||
for (int j = 0; j < data.at(i).val.size(); j++)
|
||||
{
|
||||
outfile << data.at(i).val.at(j) << " ";
|
||||
}
|
||||
outfile << endl;
|
||||
}
|
||||
outfile.close();
|
||||
return 0;
|
||||
}
|
||||
68
archive/addnoise/head.h
Normal file
68
archive/addnoise/head.h
Normal file
@@ -0,0 +1,68 @@
|
||||
#ifndef _HEAD_H
|
||||
#define _HEAD_H
|
||||
#include "ctype.h"
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
#include "unistd.h"
|
||||
#include "iostream"
|
||||
#include "fstream"
|
||||
#include "sstream"
|
||||
#include "iomanip"
|
||||
#include "vector"
|
||||
#include "ctime"
|
||||
#include "cmath"
|
||||
#include "random"
|
||||
#include "string.h"
|
||||
|
||||
#define BOLDRED "\033[1m\033[31m"
|
||||
#define RESET "\033[0m"
|
||||
|
||||
using namespace std;
|
||||
|
||||
typedef vector<double> _1dArray;
|
||||
typedef vector<int> _1iArray;
|
||||
|
||||
int open_infile(ifstream &infile,char* filename)
|
||||
{
|
||||
infile.open(filename);
|
||||
if (!infile)
|
||||
{
|
||||
cout << BOLDRED << "error ==> " << RESET << "file not found: " << filename << endl;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int open_outfile(ofstream &outfile,char* filename)
|
||||
{
|
||||
outfile.open(filename);
|
||||
if (!outfile)
|
||||
{
|
||||
cout << BOLDRED << "error ==> " << RESET << "fail to create the file: " << filename << endl;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
string& replace_all(string& str,const string& old_value,const string& new_value,int &num) //替换str中所有lod_value为new_value,返回被替换的lod_value的个数
|
||||
{
|
||||
int count = 0;
|
||||
for(string::size_type pos(0);pos!=string::npos;pos+=new_value.length())
|
||||
{
|
||||
if((pos=str.find(old_value,pos))!=string::npos)
|
||||
{
|
||||
str.replace(pos,old_value.length(),new_value);
|
||||
count++;
|
||||
}
|
||||
else break;
|
||||
}
|
||||
num = count;
|
||||
return str;
|
||||
}
|
||||
|
||||
struct node
|
||||
{
|
||||
_1dArray val;
|
||||
};
|
||||
typedef vector<node> nodeArray;
|
||||
#endif
|
||||
89
archive/addnoise/main.cpp
Normal file
89
archive/addnoise/main.cpp
Normal file
@@ -0,0 +1,89 @@
|
||||
#include "addnoise.h"
|
||||
|
||||
void disp_help(char* proname)
|
||||
{
|
||||
cout << proname << " - 0.1 add Gaussian noise to a 1D, 2D or 3D data set" << endl
|
||||
<< "Author: zhangyi.cugwuhan@gmail.com" << endl << endl
|
||||
<< "usage: " << proname << " -i<input-file> -o<output-file> -n<mean>/<deviation> [-d<x-col>[,<y-col>,<z-col>],<val-col>] [-h]" << endl
|
||||
<< "-i\tinput file (ASCII)" << endl
|
||||
<< "-o\toutput file" << endl
|
||||
<< "-n\tnoise parameters, mean value and standard deviation of the Gaussian noise" << endl
|
||||
<< "-d\tdata columns, the default is 0,1,2 for a 2D data set. The program uses the last column as input data, all others will be simply copied to the output" << endl
|
||||
<< "-h\tshow this info" << endl;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
char infilename[1024] = "NULL";
|
||||
char outfilename[1024] = "NULL";
|
||||
char cols[1024] = "0,1,2";
|
||||
char noise[1024] = "NULL";
|
||||
|
||||
opterr = 0; //内置参数 若不为0则会在发生遭遇错误时输出一条信息到屏幕
|
||||
|
||||
if (argc == 1)
|
||||
{
|
||||
cout << "use -h option for help information" << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int curr;
|
||||
/*循环拾取参数 最后一个参数为-1 需要变量的参数后跟一个冒号 可有可无参数跟两个冒号*/
|
||||
while((curr = getopt(argc,argv,"hi:o:n:d:")) != -1)
|
||||
{
|
||||
/*匹配命令*/
|
||||
switch (curr)
|
||||
{
|
||||
case 'h': //显示帮助信息
|
||||
disp_help(argv[0]);
|
||||
break;
|
||||
case 'i':
|
||||
if (1!=sscanf(optarg,"%s",infilename))
|
||||
{
|
||||
cout << "error ==> wrong format of " << optarg << endl;
|
||||
}
|
||||
break;
|
||||
case 'o':
|
||||
if (1!=sscanf(optarg,"%s",outfilename))
|
||||
{
|
||||
cout << "error ==> wrong format of " << optarg << endl;
|
||||
}
|
||||
break;
|
||||
case 'n':
|
||||
if (1!=sscanf(optarg,"%s",noise))
|
||||
{
|
||||
cout << "error ==> wrong format of " << optarg << endl;
|
||||
}
|
||||
break;
|
||||
case 'd':
|
||||
if (1!=sscanf(optarg,"%s",cols))
|
||||
{
|
||||
cout << "error ==> wrong format of " << optarg << endl;
|
||||
}
|
||||
break;
|
||||
case '?': //处理未定义或错误参数
|
||||
if (optopt == 'i' || optopt == 'o' || optopt == 'n' || optopt == 'd')
|
||||
{
|
||||
fprintf (stderr, "Option -%c requires an argument.\n", optopt);
|
||||
return -1;
|
||||
}
|
||||
else if (isprint(optopt))
|
||||
{
|
||||
fprintf (stderr, "Unknown option `-%c'.\n", optopt);
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf (stderr,"Unknown option character `\\x%x'.\n",optopt);
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
addnoise as;
|
||||
as.runtine(infilename,outfilename,noise,cols);
|
||||
return 0;
|
||||
}
|
||||
33
archive/fractopo/.gitignore
vendored
Normal file
33
archive/fractopo/.gitignore
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
# Prerequisites
|
||||
*.d
|
||||
|
||||
# Compiled Object files
|
||||
*.slo
|
||||
*.lo
|
||||
*.o
|
||||
*.obj
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Compiled Dynamic libraries
|
||||
*.so
|
||||
*.dylib
|
||||
*.dll
|
||||
|
||||
# Fortran module files
|
||||
*.mod
|
||||
*.smod
|
||||
|
||||
# Compiled Static libraries
|
||||
*.lai
|
||||
*.la
|
||||
*.a
|
||||
*.lib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
*.ex
|
||||
525
archive/fractopo/FractalTopo.h
Normal file
525
archive/fractopo/FractalTopo.h
Normal file
@@ -0,0 +1,525 @@
|
||||
#ifndef _FRACTAL_TOPO_H
|
||||
#define _FRACTAL_TOPO_H
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include <ctime>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "ctime"
|
||||
#include "unistd.h"
|
||||
#include "ctype.h"
|
||||
|
||||
#define max(a,b) a>b?a:b;
|
||||
#define PARA "-p"
|
||||
#define RANGE "-r"
|
||||
#define PREDEFINED "-t"
|
||||
#define GAUSS "-g"
|
||||
#define OUTPUT "-o"
|
||||
#define BOLDRED "\033[1m\033[31m"
|
||||
#define RESET "\033[0m"
|
||||
#define pi (4.0*atan(1.0))
|
||||
|
||||
using namespace std;
|
||||
|
||||
struct posi
|
||||
{
|
||||
double x,y,v;
|
||||
};
|
||||
|
||||
//滤波器函数参数组
|
||||
struct elliFilter
|
||||
{
|
||||
double muX,muY,sigma,theta,Lx,Ly,magnify,rho;
|
||||
};
|
||||
|
||||
double sign(double input)
|
||||
{
|
||||
if (input >= 0.0) return 1.0;
|
||||
else return -1.0;
|
||||
}
|
||||
|
||||
double ElliFilter(int type,double x,double y,elliFilter elf)
|
||||
{
|
||||
double xd,yd,filter;
|
||||
xd = x - elf.muX; yd = y - elf.muY;
|
||||
|
||||
double xyModule = sqrt(pow(xd,2)+pow(yd,2)+1e-20);
|
||||
double t = sign(yd)*acos(xd/xyModule);
|
||||
double weight = sqrt(pow(elf.Lx*cos(t - elf.theta*pi/180.0),2) + pow(elf.Ly*sin(t - elf.theta*pi/180.0),2));
|
||||
if(type) //如果type为真则使用arctan构造加权函数
|
||||
{
|
||||
filter = pi - 2.0*atan(elf.rho*weight*xyModule - elf.rho*elf.sigma);
|
||||
filter = filter/(pi + 2.0*atan(elf.rho*elf.sigma));
|
||||
}
|
||||
//type为假则使用以e为底的幂函数构造加权函数
|
||||
else filter = elf.magnify*pow(2.0,-1.0*weight*weight*xyModule*xyModule/(elf.sigma*elf.sigma));
|
||||
return filter;
|
||||
}
|
||||
|
||||
class FracTopo
|
||||
{
|
||||
public:
|
||||
FracTopo();
|
||||
~FracTopo();
|
||||
|
||||
int topo_gener_regular();//生成随机地形
|
||||
int output_regular();//输出文件
|
||||
int gauss_filter_regular();
|
||||
int topo_gener_random();
|
||||
int output_random();
|
||||
int gauss_filter_random();
|
||||
int run(double*,double*,double*,double*,char*);
|
||||
private:
|
||||
double xmin,xmax,dx,ymin,ymax,dy;
|
||||
double ld,lu,rd,ru;
|
||||
int xnum,ynum,order_x,order_y,imax;
|
||||
double H;
|
||||
double randmax;
|
||||
elliFilter filter_N;
|
||||
|
||||
int ntotal;
|
||||
int random_num;
|
||||
double** topo;
|
||||
double** topo_range;
|
||||
posi* topo_random;
|
||||
|
||||
int ifarctan;
|
||||
};
|
||||
|
||||
FracTopo::FracTopo()
|
||||
{
|
||||
topo = NULL;
|
||||
topo_range = NULL;
|
||||
topo_random = NULL;
|
||||
}
|
||||
|
||||
FracTopo::~FracTopo()
|
||||
{
|
||||
if (topo!=NULL)
|
||||
{
|
||||
for(int j=0; j<ntotal; j++) delete[] topo[j];
|
||||
delete[] topo;
|
||||
}
|
||||
if (topo_range!=NULL)
|
||||
{
|
||||
for (int i = 0; i < xnum; i++) delete[] topo_range[i];
|
||||
delete[] topo_range;
|
||||
}
|
||||
if (topo_random!=NULL)
|
||||
{
|
||||
delete[] topo_random;
|
||||
}
|
||||
}
|
||||
|
||||
int FracTopo::topo_gener_regular()
|
||||
{
|
||||
int i,j,m,n,R,jmax;
|
||||
double temp = 1e10;
|
||||
double random;
|
||||
|
||||
xnum = (xmax-xmin)/dx+1;
|
||||
ynum = (ymax-ymin)/dy+1;
|
||||
|
||||
xmax = xmin+(xnum-1)*dx;
|
||||
ymax = ymin+(ynum-1)*dy;
|
||||
|
||||
order_x = ceil(log(xnum)/log(2));
|
||||
order_y = ceil(log(ynum)/log(2));
|
||||
imax = max(order_x,order_y);
|
||||
|
||||
ntotal = (int)pow(2.0,imax)+1; //总数据点数为2的imax次方加1
|
||||
|
||||
topo = new double* [ntotal];//开辟二维动态数组
|
||||
for(i=0; i<ntotal; i++) topo[i] = new double [ntotal];
|
||||
topo_range = new double* [xnum];
|
||||
for(i=0; i<xnum; i++) topo_range[i] = new double [ynum];
|
||||
|
||||
for (i=0; i<ntotal; i++)//设定地形数据初始值,角点数据必须给出
|
||||
{
|
||||
for (j=0; j<ntotal; j++)
|
||||
{
|
||||
if (i==0&&j==0)
|
||||
{
|
||||
topo[i][j]=ld;//角点初始值;
|
||||
}
|
||||
else if (i==ntotal-1&&j==0)
|
||||
{
|
||||
topo[i][j]=lu;//角点初始值;
|
||||
}
|
||||
else if (i==0&&j==ntotal-1)
|
||||
{
|
||||
topo[i][j]=rd;//角点初始值;
|
||||
}
|
||||
else if (i==ntotal-1&&j==ntotal-1)
|
||||
{
|
||||
topo[i][j]=ru;//角点初始值;
|
||||
}
|
||||
else
|
||||
{
|
||||
topo[i][j]=temp;//非角点数值初始化为1e10
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
srand((unsigned) time(NULL));
|
||||
|
||||
for (i=1; i<=imax; i++)//开始迭代,生成正方形区域随机地形
|
||||
{
|
||||
R=int(double(ntotal-1)/pow(2.0,i));
|
||||
|
||||
jmax=int(pow(4.0,i-1));
|
||||
|
||||
for (j=1; j<=jmax; j++)
|
||||
{
|
||||
random=2*randmax*rand()/RAND_MAX-randmax;
|
||||
|
||||
m=2*R*(j-(ceil((double)j/pow(2.0,i-1))-1) * pow(2.0,i-1))-R;
|
||||
n=2*R*(ceil((double)j/pow(2.0,i-1)))-R;
|
||||
topo[m][n]=(topo[m-R][n-R]+topo[m+R][n-R]+topo[m-R][n+R]+topo[m+R][n+R])/4+random;
|
||||
}
|
||||
|
||||
for (j=1; j<=jmax; j++)
|
||||
{
|
||||
m=2*R*(j-(ceil((double)j/pow(2.0,i-1))-1)* pow(2.0,i-1))-R;
|
||||
n=2*R*(ceil((double)j/pow(2.0,i-1)))-R;
|
||||
|
||||
if (topo[m][n-R]==temp)
|
||||
{
|
||||
random=2*randmax*rand()/RAND_MAX-randmax;
|
||||
|
||||
if ((n-R)!=0)
|
||||
{
|
||||
topo[m][n-R]=(topo[m][n-2*R]+topo[m-R][n-R]+topo[m+R][n-R]+topo[m][n])/4+random;
|
||||
}
|
||||
else
|
||||
{
|
||||
topo[m][n-R]=(topo[m-R][n-R]+topo[m+R][n-R]+topo[m][n])/3+random;
|
||||
}
|
||||
}
|
||||
|
||||
if (topo[m-R][n]==temp)
|
||||
{
|
||||
random=2*randmax*rand()/RAND_MAX-randmax;
|
||||
|
||||
if ((m-R)!=0)
|
||||
{
|
||||
topo[m-R][n]=(topo[m-R][n-R]+topo[m-2*R][n]+topo[m][n]+topo[m-R][n+R])/4+random;
|
||||
}
|
||||
else
|
||||
{
|
||||
topo[m-R][n]=(topo[m-R][n-R]+topo[m][n]+topo[m-R][n+R])/3+random;
|
||||
}
|
||||
}
|
||||
|
||||
if (topo[m+R][n]==temp)
|
||||
{
|
||||
random=2*randmax*rand()/RAND_MAX-randmax;
|
||||
|
||||
if ((m+R)!=(ntotal-1))
|
||||
{
|
||||
topo[m+R][n]=(topo[m+R][n-R]+topo[m][n]+topo[m+2*R][n]+topo[m+R][n+R])/4+random;
|
||||
}
|
||||
else
|
||||
{
|
||||
topo[m+R][n]=(topo[m+R][n-R]+topo[m][n]+topo[m+R][n+R])/3+random;
|
||||
}
|
||||
}
|
||||
|
||||
if (topo[m][n+R]==temp)
|
||||
{
|
||||
random=2*randmax*rand()/RAND_MAX-randmax;
|
||||
|
||||
if ((n+R)!=(ntotal-1))
|
||||
{
|
||||
topo[m][n+R]=(topo[m][n]+topo[m-R][n+R]+topo[m+R][n+R]+topo[m][n+2*R])/4+random;
|
||||
}
|
||||
else
|
||||
{
|
||||
topo[m][n+R]=(topo[m][n]+topo[m-R][n+R]+topo[m+R][n+R])/3+random;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
randmax=pow(2.0,-H)*randmax;
|
||||
}
|
||||
|
||||
for (int j=0; j<ntotal; j++)//按预设区域剪裁数组
|
||||
{
|
||||
for (int i=0; i<ntotal; i++)
|
||||
{
|
||||
if (i<xnum&&j<ynum)
|
||||
{
|
||||
topo_range[i][j]=topo[i][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int FracTopo::topo_gener_random()
|
||||
{
|
||||
int i,j,m,n,R,jmax;
|
||||
double temp = 1e+10;
|
||||
double random;
|
||||
|
||||
dx=dy=ceil(sqrt((xmax-xmin)*(ymax-ymin)/random_num));//按照随机点数预估节点步长
|
||||
|
||||
xnum = (xmax-xmin)/dx+1;
|
||||
ynum = (ymax-ymin)/dy+1;
|
||||
|
||||
xmax = xmin+(xnum-1)*dx;
|
||||
ymax = ymin+(ynum-1)*dy;
|
||||
|
||||
order_x = ceil(log(xnum)/log(2));
|
||||
order_y = ceil(log(ynum)/log(2));
|
||||
imax = max(order_x,order_y);
|
||||
|
||||
ntotal = (int)pow(2.0,imax)+1; //总数据点数为2的imax次方加1
|
||||
|
||||
topo = new double* [ntotal];//开辟二维动态数组
|
||||
for(i=0; i<ntotal; i++) topo[i] = new double [ntotal];
|
||||
topo_random = new posi [random_num];
|
||||
|
||||
for (i=0; i<ntotal; i++)//设定地形数据初始值,角点数据必须给出
|
||||
{
|
||||
for (j=0; j<ntotal; j++)
|
||||
{
|
||||
if (i==0&&j==0)
|
||||
{
|
||||
topo[i][j]=ld;//角点初始值;
|
||||
}
|
||||
else if (i==ntotal-1&&j==0)
|
||||
{
|
||||
topo[i][j]=lu;//角点初始值;
|
||||
}
|
||||
else if (i==0&&j==ntotal-1)
|
||||
{
|
||||
topo[i][j]=rd;//角点初始值;
|
||||
}
|
||||
else if (i==ntotal-1&&j==ntotal-1)
|
||||
{
|
||||
topo[i][j]=ru;//角点初始值;
|
||||
}
|
||||
else
|
||||
{
|
||||
topo[i][j]=temp;//非角点数值初始化为1e10
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
srand((unsigned) time(NULL));
|
||||
|
||||
for (i=1; i<=imax; i++)//开始迭代,生成正方形区域随机地形
|
||||
{
|
||||
R=int(double(ntotal-1)/pow(2.0,i));
|
||||
|
||||
jmax=int(pow(4.0,i-1));
|
||||
|
||||
for (j=1; j<=jmax; j++)
|
||||
{
|
||||
random=2*randmax*rand()/RAND_MAX-randmax;
|
||||
|
||||
m=2*R*(j-(ceil((double)j/pow(2.0,i-1))-1) * pow(2.0,i-1))-R;
|
||||
n=2*R*(ceil((double)j/pow(2.0,i-1)))-R;
|
||||
topo[m][n]=(topo[m-R][n-R]+topo[m+R][n-R]+topo[m-R][n+R]+topo[m+R][n+R])/4+random;
|
||||
}
|
||||
|
||||
for (j=1; j<=jmax; j++)
|
||||
{
|
||||
m=2*R*(j-(ceil((double)j/pow(2.0,i-1))-1)* pow(2.0,i-1))-R;
|
||||
n=2*R*(ceil((double)j/pow(2.0,i-1)))-R;
|
||||
|
||||
if (topo[m][n-R]==temp)
|
||||
{
|
||||
random=2*randmax*rand()/RAND_MAX-randmax;
|
||||
|
||||
if ((n-R)!=0)
|
||||
{
|
||||
topo[m][n-R]=(topo[m][n-2*R]+topo[m-R][n-R]+topo[m+R][n-R]+topo[m][n])/4+random;
|
||||
}
|
||||
else
|
||||
{
|
||||
topo[m][n-R]=(topo[m-R][n-R]+topo[m+R][n-R]+topo[m][n])/3+random;
|
||||
}
|
||||
}
|
||||
|
||||
if (topo[m-R][n]==temp)
|
||||
{
|
||||
random=2*randmax*rand()/RAND_MAX-randmax;
|
||||
|
||||
if ((m-R)!=0)
|
||||
{
|
||||
topo[m-R][n]=(topo[m-R][n-R]+topo[m-2*R][n]+topo[m][n]+topo[m-R][n+R])/4+random;
|
||||
}
|
||||
else
|
||||
{
|
||||
topo[m-R][n]=(topo[m-R][n-R]+topo[m][n]+topo[m-R][n+R])/3+random;
|
||||
}
|
||||
}
|
||||
|
||||
if (topo[m+R][n]==temp)
|
||||
{
|
||||
random=2*randmax*rand()/RAND_MAX-randmax;
|
||||
|
||||
if ((m+R)!=(ntotal-1))
|
||||
{
|
||||
topo[m+R][n]=(topo[m+R][n-R]+topo[m][n]+topo[m+2*R][n]+topo[m+R][n+R])/4+random;
|
||||
}
|
||||
else
|
||||
{
|
||||
topo[m+R][n]=(topo[m+R][n-R]+topo[m][n]+topo[m+R][n+R])/3+random;
|
||||
}
|
||||
}
|
||||
|
||||
if (topo[m][n+R]==temp)
|
||||
{
|
||||
random=2*randmax*rand()/RAND_MAX-randmax;
|
||||
|
||||
if ((n+R)!=(ntotal-1))
|
||||
{
|
||||
topo[m][n+R]=(topo[m][n]+topo[m-R][n+R]+topo[m+R][n+R]+topo[m][n+2*R])/4+random;
|
||||
}
|
||||
else
|
||||
{
|
||||
topo[m][n+R]=(topo[m][n]+topo[m-R][n+R]+topo[m+R][n+R])/3+random;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
randmax=pow(2.0,-H)*randmax;
|
||||
}
|
||||
|
||||
srand((unsigned) time(NULL));
|
||||
int temp_m,temp_n;
|
||||
double len_ld,len_lu,len_ru,len_rd;
|
||||
for (int i = 0; i < random_num; i++)
|
||||
{
|
||||
topo_random[i].x = (xmax-xmin)*rand()/RAND_MAX+xmin;
|
||||
topo_random[i].y = (ymax-ymin)*rand()/RAND_MAX+ymin;
|
||||
temp_m = floor((topo_random[i].x - xmin)/dx);
|
||||
temp_n = floor((topo_random[i].y - ymin)/dy);
|
||||
len_ld = sqrt(pow(xmin+dx*temp_m - topo_random[i].x,2)+pow(ymin+dy*temp_n - topo_random[i].y,2));
|
||||
len_lu = sqrt(pow(xmin+dx*temp_m - topo_random[i].x,2)+pow(ymin+dy*(temp_n+1) - topo_random[i].y,2));
|
||||
len_ru = sqrt(pow(xmin+dx*(temp_m+1) - topo_random[i].x,2)+pow(ymin+dy*(temp_n+1) - topo_random[i].y,2));
|
||||
len_rd = sqrt(pow(xmin+dx*(temp_m+1) - topo_random[i].x,2)+pow(ymin+dy*temp_n - topo_random[i].y,2));
|
||||
topo_random[i].v = (topo[temp_m][temp_n]*len_ld+topo[temp_m+1][temp_n]*len_rd+topo[temp_m+1][temp_n+1]*len_ru+topo[temp_m][temp_n+1]*len_lu)/(len_lu+len_ru+len_rd+len_ld);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int FracTopo::output_regular()
|
||||
{
|
||||
time_t now = time(0);
|
||||
char* dt = ctime(&now);
|
||||
|
||||
cout << "# A fractal terrain data generated by fractopo on " << dt;
|
||||
cout << "# For more information please connect zhangyi.cugwuhan@gmail.com" << endl;
|
||||
cout << "# use -h option to see help information" << endl;
|
||||
cout << "# range=" << xmin << "/" << dx << "/" << xmax << "/" << ymin << "/" << dy << "/" << ymax << endl;
|
||||
cout << "# x y elevation" << endl;
|
||||
for (int j=0; j<ynum; j++)
|
||||
{
|
||||
for (int i=0; i<xnum; i++)
|
||||
{
|
||||
cout<<xmin+i*dx<<" "<<ymin+j*dy<<" "<<topo_range[i][j]<<endl;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int FracTopo::output_random()
|
||||
{
|
||||
time_t now = time(0);
|
||||
char* dt = ctime(&now);
|
||||
|
||||
cout << "# A fractal terrain data generated by fractopo on " << dt;
|
||||
cout << "# For more information please connect zhangyi.cugwuhan@gmail.com" << endl;
|
||||
cout << "# use -h option to see help information" << endl;
|
||||
cout << "# x y elevation" << endl;
|
||||
for (int i = 0; i < random_num; i++)
|
||||
{
|
||||
cout<<topo_random[i].x<<" "<<topo_random[i].y<<" "<<topo_random[i].v<<endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int FracTopo::gauss_filter_regular()
|
||||
{
|
||||
for (int j=0; j<ynum; j++)
|
||||
{
|
||||
for (int i=0; i<xnum; i++)
|
||||
{
|
||||
topo_range[i][j] *= ElliFilter(ifarctan,xmin+i*dx,ymin+j*dy,filter_N);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int FracTopo::gauss_filter_random()
|
||||
{
|
||||
for (int i = 0; i < random_num; i++)
|
||||
{
|
||||
topo_random[i].v *= ElliFilter(ifarctan,topo_random[i].x,topo_random[i].y,filter_N);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int FracTopo::run(double* range,double* topo,double* para,double* gauss,char* filterType)
|
||||
{
|
||||
if (!strcmp(filterType,"pow"))
|
||||
ifarctan = 0;
|
||||
else if (!strcmp(filterType,"atan"))
|
||||
ifarctan = 1;
|
||||
|
||||
if (*(range+5)==1e+30)
|
||||
{
|
||||
xmin = *range; xmax = *(range+1);
|
||||
ymin = *(range+2); ymax = *(range+3);
|
||||
random_num = *(range+4);
|
||||
ld = *topo; lu = *(topo+1); ru = *(topo+2); rd = *(topo+3);
|
||||
H = *para; randmax = *(para+1);
|
||||
topo_gener_random();
|
||||
if (*gauss!=1e+30)
|
||||
{
|
||||
filter_N.muX = *gauss;
|
||||
filter_N.muY = *(gauss+1);
|
||||
filter_N.sigma = *(gauss+2);
|
||||
filter_N.theta = *(gauss+3);
|
||||
filter_N.Lx = *(gauss+4);
|
||||
filter_N.Ly = *(gauss+5);
|
||||
filter_N.magnify = *(gauss+6);
|
||||
filter_N.rho = *(gauss+7);
|
||||
gauss_filter_random();
|
||||
}
|
||||
output_random();
|
||||
}
|
||||
else
|
||||
{
|
||||
xmin = *range; xmax = *(range+1);
|
||||
ymin = *(range+2); ymax = *(range+3);
|
||||
dx = *(range+4); dy = *(range+5);
|
||||
ld = *topo; lu = *(topo+1); ru = *(topo+2); rd = *(topo+3);
|
||||
H = *para; randmax = *(para+1);
|
||||
topo_gener_regular();
|
||||
if (*gauss!=1e+30)
|
||||
{
|
||||
filter_N.muX = *gauss;
|
||||
filter_N.muY = *(gauss+1);
|
||||
filter_N.sigma = *(gauss+2);
|
||||
filter_N.theta = *(gauss+3);
|
||||
filter_N.Lx = *(gauss+4);
|
||||
filter_N.Ly = *(gauss+5);
|
||||
filter_N.magnify = *(gauss+6);
|
||||
filter_N.rho = *(gauss+7);
|
||||
gauss_filter_regular();
|
||||
}
|
||||
output_regular();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
384
archive/fractopo/dispHelp.h
Normal file
384
archive/fractopo/dispHelp.h
Normal file
@@ -0,0 +1,384 @@
|
||||
#ifndef _DISPHELP_H
|
||||
#define _DISPHELP_H
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <iomanip>
|
||||
#include <sys/ioctl.h>
|
||||
#include "vector"
|
||||
|
||||
using namespace std;
|
||||
|
||||
typedef vector<string> strArray;
|
||||
|
||||
struct option
|
||||
{
|
||||
string flag_s,flag_l;
|
||||
string message;
|
||||
strArray sec_message;
|
||||
option()
|
||||
{
|
||||
flag_s = flag_l = message = "";
|
||||
}
|
||||
};
|
||||
typedef vector<option> opArray;
|
||||
|
||||
class dispHelp
|
||||
{
|
||||
public:
|
||||
dispHelp(){
|
||||
front_space = 0;
|
||||
back_space = 10;
|
||||
ex_name = "Execuable";
|
||||
version = "0.0.1";
|
||||
descript = "Brief information about this command.";
|
||||
author = "Author's information.";
|
||||
}
|
||||
~dispHelp(){}
|
||||
void addHeadInfo(string,string,string,string);
|
||||
void addUsage(string);
|
||||
void addOption(string,string,string);
|
||||
void addOptionSec(string,int);
|
||||
void addExample(string);
|
||||
void changeLayerOut(int,int);
|
||||
void show();
|
||||
private:
|
||||
string ex_name,version,descript,author;
|
||||
int front_space,back_space;
|
||||
opArray options;
|
||||
strArray examples;
|
||||
strArray usages;
|
||||
};
|
||||
|
||||
void dispHelp::addHeadInfo(string s1,string s2,string s3,string s4)
|
||||
{
|
||||
ex_name = s1; version = s2; descript = s3; author = s4;
|
||||
return;
|
||||
}
|
||||
|
||||
void dispHelp::addUsage(string usg)
|
||||
{
|
||||
usages.push_back(usg);
|
||||
return;
|
||||
}
|
||||
|
||||
void dispHelp::addOption(string msg,string sflag,string lflag = "")
|
||||
{
|
||||
option tmp_option;
|
||||
tmp_option.message = msg; tmp_option.flag_s = sflag; tmp_option.flag_l = lflag;
|
||||
options.push_back(tmp_option);
|
||||
return;
|
||||
}
|
||||
|
||||
void dispHelp::addOptionSec(string msg,int index = -1)
|
||||
{
|
||||
if (index < 0)
|
||||
{
|
||||
options.back().sec_message.push_back(msg);
|
||||
}
|
||||
else options[index].sec_message.push_back(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
void dispHelp::addExample(string ex)
|
||||
{
|
||||
examples.push_back(ex);
|
||||
return;
|
||||
}
|
||||
|
||||
void dispHelp::changeLayerOut(int left,int right)
|
||||
{
|
||||
front_space = left; back_space = right;
|
||||
return;
|
||||
}
|
||||
|
||||
void dispHelp::show()
|
||||
{
|
||||
int line_length;
|
||||
string segment,full_message;
|
||||
stringstream ss_message;
|
||||
//获取终端窗口的行列数
|
||||
struct winsize w;
|
||||
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
|
||||
//显示头信息
|
||||
full_message = ex_name + " " + version + " - " + descript;
|
||||
ss_message.clear(); ss_message.str(full_message);
|
||||
|
||||
line_length = front_space + back_space;
|
||||
while(ss_message >> segment)
|
||||
{
|
||||
if ((line_length+segment.length()+1) <= w.ws_col)
|
||||
{
|
||||
if (line_length == (front_space + back_space))
|
||||
{
|
||||
for (int i = 0; i < front_space; i++) clog << " ";
|
||||
clog << segment << " ";
|
||||
line_length += (segment.length()+1);
|
||||
}
|
||||
else
|
||||
{
|
||||
clog << segment << " ";
|
||||
line_length += (segment.length()+1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
clog << endl;
|
||||
for (int i = 0; i < front_space+4; i++) clog << " ";
|
||||
clog << segment << " ";
|
||||
line_length = (segment.length()+9+front_space+back_space);
|
||||
}
|
||||
}
|
||||
clog << endl;
|
||||
|
||||
ss_message.clear(); ss_message.str(author);
|
||||
line_length = front_space + back_space;;
|
||||
while(ss_message >> segment)
|
||||
{
|
||||
if ((line_length+segment.length()+1) <= w.ws_col)
|
||||
{
|
||||
if (line_length == (front_space + back_space))
|
||||
{
|
||||
for (int i = 0; i < front_space; i++) clog << " ";
|
||||
clog << "Author: " << segment << " ";
|
||||
line_length += (segment.length()+9);
|
||||
}
|
||||
else
|
||||
{
|
||||
clog << segment << " ";
|
||||
line_length += (segment.length()+1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
clog << endl;
|
||||
for (int i = 0; i < front_space+4; i++) clog << " ";
|
||||
clog << segment << " ";
|
||||
line_length = (segment.length()+9+front_space+back_space);
|
||||
}
|
||||
}
|
||||
clog << endl;
|
||||
|
||||
if (!usages.empty())
|
||||
{
|
||||
for (int i = 0; i < front_space; i++) clog << " ";
|
||||
clog << "Usage:" << endl;
|
||||
for (int i = 0; i < usages.size(); i++)
|
||||
{
|
||||
ss_message.clear(); ss_message.str(usages[i]);
|
||||
|
||||
line_length = front_space + back_space + 4;
|
||||
while(ss_message >> segment)
|
||||
{
|
||||
if ((line_length+segment.length()+1) <= w.ws_col)
|
||||
{
|
||||
if (line_length == (front_space+back_space+4))
|
||||
{
|
||||
for (int i = 0; i < front_space+4; i++) clog << " ";
|
||||
clog << segment << " ";
|
||||
line_length += (segment.length()+1);
|
||||
}
|
||||
else
|
||||
{
|
||||
clog << segment << " ";
|
||||
line_length += (segment.length()+1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
clog << endl;
|
||||
for (int i = 0; i < front_space+9; i++) clog << " ";
|
||||
clog << segment << " ";
|
||||
line_length = (segment.length()+10+front_space+back_space);
|
||||
}
|
||||
}
|
||||
clog << endl;
|
||||
}
|
||||
}
|
||||
|
||||
if (!options.empty())
|
||||
{
|
||||
for (int i = 0; i < front_space; i++) clog << " ";
|
||||
clog << "Options:" << endl;
|
||||
for (int i = 0; i < options.size(); i++)
|
||||
{
|
||||
if (options[i].flag_l == "")
|
||||
{
|
||||
full_message = options[i].flag_s+" : "+options[i].message;
|
||||
ss_message.clear(); ss_message.str(full_message);
|
||||
|
||||
line_length = front_space + back_space + 4;
|
||||
while(ss_message >> segment)
|
||||
{
|
||||
if ((line_length+segment.length()+1) <= w.ws_col)
|
||||
{
|
||||
if (line_length == (front_space+back_space+4))
|
||||
{
|
||||
for (int i = 0; i < front_space+4; i++) clog << " ";
|
||||
clog << segment << " ";
|
||||
line_length += (segment.length()+1);
|
||||
}
|
||||
else
|
||||
{
|
||||
clog << segment << " ";
|
||||
line_length += (segment.length()+1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
clog << endl;
|
||||
for (int i = 0; i < front_space+9; i++) clog << " ";
|
||||
clog << segment << " ";
|
||||
line_length = (segment.length()+10+front_space+back_space);
|
||||
}
|
||||
}
|
||||
clog << endl;
|
||||
|
||||
if (!options[i].sec_message.empty())
|
||||
{
|
||||
for (int j = 0; j < options[i].sec_message.size(); j++)
|
||||
{
|
||||
ss_message.clear(); ss_message.str(options[i].sec_message[j]);
|
||||
|
||||
line_length = front_space + back_space + 9;
|
||||
while(ss_message >> segment)
|
||||
{
|
||||
if ((line_length+segment.length()+1) <= w.ws_col)
|
||||
{
|
||||
if (line_length == (front_space+back_space+9))
|
||||
{
|
||||
for (int i = 0; i < front_space+9; i++) clog << " ";
|
||||
clog << segment << " ";
|
||||
line_length += (segment.length()+1);
|
||||
}
|
||||
else
|
||||
{
|
||||
clog << segment << " ";
|
||||
line_length += (segment.length()+1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
clog << endl;
|
||||
for (int i = 0; i < front_space+13; i++) clog << " ";
|
||||
clog << segment << " ";
|
||||
line_length = (segment.length()+14+front_space+back_space);
|
||||
}
|
||||
}
|
||||
clog << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
full_message = options[i].flag_s+" | "+options[i].flag_l+" : "+options[i].message;
|
||||
ss_message.clear(); ss_message.str(full_message);
|
||||
|
||||
line_length = front_space + back_space + 4;
|
||||
while(ss_message >> segment)
|
||||
{
|
||||
if ((line_length+segment.length()+1) <= w.ws_col)
|
||||
{
|
||||
if (line_length == (front_space+back_space+4))
|
||||
{
|
||||
for (int i = 0; i < front_space+4; i++) clog << " ";
|
||||
clog << segment << " ";
|
||||
line_length += (segment.length()+1);
|
||||
}
|
||||
else
|
||||
{
|
||||
clog << segment << " ";
|
||||
line_length += (segment.length()+1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
clog << endl;
|
||||
for (int i = 0; i < front_space+9; i++) clog << " ";
|
||||
clog << segment << " ";
|
||||
line_length = (segment.length()+10+front_space+back_space);
|
||||
}
|
||||
}
|
||||
clog << endl;
|
||||
|
||||
if (!options[i].sec_message.empty())
|
||||
{
|
||||
for (int j = 0; j < options[i].sec_message.size(); j++)
|
||||
{
|
||||
ss_message.clear(); ss_message.str(options[i].sec_message[j]);
|
||||
|
||||
line_length = front_space + back_space + 9;
|
||||
while(ss_message >> segment)
|
||||
{
|
||||
if ((line_length+segment.length()+1) <= w.ws_col)
|
||||
{
|
||||
if (line_length == (front_space+back_space+9))
|
||||
{
|
||||
for (int i = 0; i < front_space+9; i++) clog << " ";
|
||||
clog << segment << " ";
|
||||
line_length += (segment.length()+1);
|
||||
}
|
||||
else
|
||||
{
|
||||
clog << segment << " ";
|
||||
line_length += (segment.length()+1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
clog << endl;
|
||||
for (int i = 0; i < front_space+13; i++) clog << " ";
|
||||
clog << segment << " ";
|
||||
line_length = (segment.length()+14+front_space+back_space);
|
||||
}
|
||||
}
|
||||
clog << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!examples.empty())
|
||||
{
|
||||
for (int i = 0; i < front_space; i++) clog << " ";
|
||||
clog << "Examples:" << endl;
|
||||
for (int i = 0; i < examples.size(); i++)
|
||||
{
|
||||
ss_message.clear(); ss_message.str(examples[i]);
|
||||
|
||||
line_length = front_space + back_space + 4;
|
||||
while(ss_message >> segment)
|
||||
{
|
||||
if ((line_length+segment.length()+1) <= w.ws_col)
|
||||
{
|
||||
if (line_length == (front_space+back_space+4))
|
||||
{
|
||||
for (int i = 0; i < front_space+4; i++) clog << " ";
|
||||
clog << segment << " ";
|
||||
line_length += (segment.length()+1);
|
||||
}
|
||||
else
|
||||
{
|
||||
clog << segment << " ";
|
||||
line_length += (segment.length()+1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
clog << endl;
|
||||
for (int i = 0; i < front_space+9; i++) clog << " ";
|
||||
clog << segment << " ";
|
||||
line_length = (segment.length()+10+front_space+back_space);
|
||||
}
|
||||
}
|
||||
clog << endl;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
167
archive/fractopo/main.cpp
Normal file
167
archive/fractopo/main.cpp
Normal file
@@ -0,0 +1,167 @@
|
||||
#include "dispHelp.h"
|
||||
#include "FractalTopo.h"
|
||||
|
||||
void disp_help(char* proname)
|
||||
{
|
||||
string exName = proname;
|
||||
string exUsage = proname;
|
||||
exUsage += " [-p<roughness>/<topo-range>] [-r<x-min>/<x-max>/<y-min>/<y-max>/[<d-x>/<d-y>|<point-num>]] [-t<lower-left-topo>/<upper-left-topo>/<upper-right-topo>/<lower-right-topo>] [-g<cx>/<cy>/<sigma>/<ang>/<Lx>/<Ly>/<magnify>[/rho]] [h] > output-file";
|
||||
dispHelp dh;
|
||||
dh.changeLayerOut(0,10);
|
||||
dh.addHeadInfo(exName,"1.4.1","fractal topography generater.","Yi Zhang (zhangyi.cugwuhan@gmail.com)");
|
||||
dh.addUsage(exUsage);
|
||||
dh.addOption("Roughness and maximal changing range of the output topography data. The defaults are 1.2/600","-p");
|
||||
dh.addOption("Calculation range, the program can output topography data under a rectangular grid or at random positions. The defaults are 0/1000/0/1000/10/10","-r");
|
||||
dh.addOption("Altitudes at four corner's positions. The defaults are 0/0/0/0","-t");
|
||||
dh.addOption("filter parameters","-g");
|
||||
dh.addOptionSec("cx/cy : center coordinates of the filter");
|
||||
dh.addOptionSec("sigma : radius of the shorter axis of the 0.5 filter amplitude");
|
||||
dh.addOptionSec("ang : angle between the shorter axis of the filter and the x-axis");
|
||||
dh.addOptionSec("Lx/Ly : length factor the long and short axises of the filter. usually we take Lx = 1 to ensure the radius of 0.5 filter amplitude equals \
|
||||
the distance given by sigma in the direction of the shorter axis of the filter. a bigger L value indicates faster changing rate in the corresponding \
|
||||
direction. For instance 1/0.5 yields an oval which flattening equals 2.0");
|
||||
dh.addOptionSec("magnify : filter amplitude at the center");
|
||||
dh.addOptionSec("rho : changing rate of the arctan function");
|
||||
dh.addOption("choose weight function type, input 'pow' for power function (default) and 'atan' for arctan function","-f");
|
||||
dh.addOption("print this information","-h");
|
||||
dh.addExample("fractopo > regular.xyz");
|
||||
dh.addExample("fractopo > -r0/1000/0/1000/5000 > random.xyz");
|
||||
dh.addExample("fractopo > -g500/500/100/45/1/0.6/1 > regular_gauss.xyz");
|
||||
dh.addExample("fractopo > -r0/1000/0/1000/5000 -g500/500/100/45/1/0.6/1 > random_gauss.xyz");
|
||||
dh.show();
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
double Para[2] = {1.2,600};
|
||||
double Range[6] = {0,1000,0,1000,10,10};
|
||||
double Topo[4] = {0,0,0,0};
|
||||
double Gauss[8] = {1e+30,1e+30,1e+30,1e+30,1e+30,1e+30,1e+30,1e+30};
|
||||
char flType[1024] = "pow";
|
||||
FracTopo FT;
|
||||
|
||||
opterr = 0;
|
||||
|
||||
int curr;
|
||||
/*循环拾取参数 最后一个参数为-1 需要变量的参数后跟一个冒号 可有可无参数跟两个冒号*/
|
||||
while((curr = getopt(argc,argv,"hf:p:r:t:g:")) != -1)
|
||||
{
|
||||
/*匹配命令*/
|
||||
switch (curr)
|
||||
{
|
||||
case 'h': //显示帮助信息
|
||||
disp_help(argv[0]);
|
||||
return 0;
|
||||
case 'f':
|
||||
if (1!=sscanf(optarg,"%s",flType)) //格式化读入参数
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<optarg<<endl;
|
||||
cout<<"use -h option to see help information" << endl;
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case 'p':
|
||||
if (2!=sscanf(optarg,"%lf/%lf",&Para[0],&Para[1])) //格式化读入参数
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<optarg<<endl;
|
||||
cout<<"use -h option to see help information" << endl;
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case 'r':
|
||||
if (6!=sscanf(optarg,"%lf/%lf/%lf/%lf/%lf/%lf",&Range[0],&Range[1],&Range[2],&Range[3],&Range[4],&Range[5]))
|
||||
{
|
||||
if (5!=sscanf(optarg,"%lf/%lf/%lf/%lf/%lf",&Range[0],&Range[1],&Range[2],&Range[3],&Range[4]))
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<optarg<<endl;
|
||||
cout<<"use -h option to see help information" << endl;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
//确定只有5个范围参数 将最后一个range参数设置为1e+30
|
||||
Range[5] = 1e+30;
|
||||
|
||||
if (Range[0]>Range[1])
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<optarg<<endl;
|
||||
cout<<"use -h option to see help information" << endl;
|
||||
return 0;
|
||||
}
|
||||
else if (Range[2]>Range[3])
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<optarg<<endl;
|
||||
cout<<"use -h option to see help information" << endl;
|
||||
return 0;
|
||||
}
|
||||
else if (Range[4]<=0)
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<optarg<<endl;
|
||||
cout<<"use -h option to see help information" << endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Range[0]>Range[1]||(Range[0]+2*Range[4])>Range[1])
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<optarg<<endl;
|
||||
cout<<"use -h option to see help information" << endl;
|
||||
return 0;
|
||||
}
|
||||
else if (Range[2]>Range[3]||(Range[2]+2*Range[5])>Range[3])
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<optarg<<endl;
|
||||
cout<<"use -h option to see help information" << endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 't':
|
||||
if (4!=sscanf(optarg,"%lf/%lf/%lf/%lf",&Topo[0],&Topo[1],&Topo[2],&Topo[3]))
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<optarg<<endl;
|
||||
cout<<"use -h option to see help information" << endl;
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case 'g':
|
||||
if (8!=sscanf(optarg,"%lf/%lf/%lf/%lf/%lf/%lf/%lf/%lf",&Gauss[0],&Gauss[1],&Gauss[2],&Gauss[3],&Gauss[4],&Gauss[5],&Gauss[6],&Gauss[7]))
|
||||
{
|
||||
if (7!=sscanf(optarg,"%lf/%lf/%lf/%lf/%lf/%lf/%lfs",&Gauss[0],&Gauss[1],&Gauss[2],&Gauss[3],&Gauss[4],&Gauss[5],&Gauss[6]))
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<optarg<<endl;
|
||||
cout<<"use -h option to see help information" << endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case '?': //处理未定义或错误参数
|
||||
if (optopt == 'p' || optopt == 'r' || optopt == 't' || optopt == 'g')
|
||||
{
|
||||
fprintf (stderr, "Option -%c requires an argument.\n", optopt);
|
||||
cout<<"use -h option to see help information" << endl;
|
||||
return 0;
|
||||
}
|
||||
else if (isprint(optopt))
|
||||
{
|
||||
fprintf (stderr, "Unknown option `-%c'.\n", optopt);
|
||||
cout<<"use -h option to see help information" << endl;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf (stderr,"Unknown option character `\\x%x'.\n",optopt);
|
||||
cout<<"use -h option to see help information" << endl;
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
FT.run(Range,Topo,Para,Gauss,flType);
|
||||
return 0;
|
||||
}
|
||||
15
archive/fractopo/makefile
Normal file
15
archive/fractopo/makefile
Normal file
@@ -0,0 +1,15 @@
|
||||
CC = g++-8
|
||||
PROM = /usr/local/sbin/fractopo
|
||||
CFLAGS = -I.
|
||||
DEPS = $(shell find . -name "*.h")
|
||||
SRC = $(shell find . -name "*.cpp")
|
||||
OBJ = $(SRC:%.cpp=%.o)
|
||||
|
||||
$(PROM): $(OBJ)
|
||||
$(CC) -o $(PROM) $(OBJ) $(CFLAGS)
|
||||
|
||||
%.o:%.cpp $(DEPS)
|
||||
$(CC) -c $< -o $@ $(CFLAGS)
|
||||
|
||||
clean:
|
||||
rm -rf $(OBJ)
|
||||
12
archive/g3d/CMakeLists.txt
Normal file
12
archive/g3d/CMakeLists.txt
Normal file
@@ -0,0 +1,12 @@
|
||||
#Uncomment the following two lines to compile the sources as an individual cmake porject. Change the <project_name> as you wanted.
|
||||
#cmake_minimum_required(VERSION 3.15.2)
|
||||
#project(<project_name>)
|
||||
|
||||
#Set executable name here
|
||||
set(name g3d)
|
||||
|
||||
aux_source_directory(. "${name}_src")
|
||||
add_executable(${name} ${${name}_src})
|
||||
set_target_properties(${name} PROPERTIES CXX_STANDARD 11)
|
||||
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
|
||||
install(TARGETS ${name} RUNTIME DESTINATION sbin)
|
||||
59
archive/g3d/datafunc.h
Normal file
59
archive/g3d/datafunc.h
Normal file
@@ -0,0 +1,59 @@
|
||||
#ifndef _DATAFUNC_H
|
||||
#define _DATAFUNC_H
|
||||
#include "iostream"
|
||||
#include "fstream"
|
||||
#include "string.h"
|
||||
#include "iomanip"
|
||||
#include "cmath"
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
#include "list"
|
||||
|
||||
#define G0 6.67259e-03
|
||||
#define pi (4.0*atan(1.0))
|
||||
#define MAX 1e+30
|
||||
|
||||
#define GRAV "-g"
|
||||
#define GRADX "-x"
|
||||
#define GRADY "-y"
|
||||
#define GRADZ "-z"
|
||||
#define RANGE "-r"
|
||||
#define INTERVAL "-i"
|
||||
#define PARAFILE "-f"
|
||||
#define SPHERE "-s"
|
||||
#define CUBE "-c"
|
||||
#define OUTPUT "-o"
|
||||
#define BOLDRED "\033[1m\033[31m"
|
||||
#define RESET "\033[0m"
|
||||
|
||||
using namespace std;
|
||||
|
||||
double arctg(double v)
|
||||
{
|
||||
double ang;
|
||||
if(v>=0)
|
||||
{
|
||||
ang=atan(v);
|
||||
}
|
||||
else if(v<0)
|
||||
{
|
||||
ang=atan(v)+pi;
|
||||
}
|
||||
return ang;
|
||||
}
|
||||
|
||||
struct sphere
|
||||
{
|
||||
double x,y,z,r;
|
||||
double density;
|
||||
};
|
||||
typedef list<sphere> SphereList;
|
||||
|
||||
struct cube
|
||||
{
|
||||
double x1,x2,y1,y2,z1,z2;
|
||||
double density;
|
||||
};
|
||||
typedef list<cube> CubeList;
|
||||
|
||||
#endif
|
||||
5
archive/g3d/example/example.txt
Normal file
5
archive/g3d/example/example.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
-c450/550/450/550/100/200/1.0
|
||||
-s300/300/100/50/1.0
|
||||
-s300/700/100/50/1.0
|
||||
-s700/700/100/50/1.0
|
||||
-s700/300/100/50/1.0
|
||||
260
archive/g3d/forward.h
Normal file
260
archive/g3d/forward.h
Normal file
@@ -0,0 +1,260 @@
|
||||
#include "datafunc.h"
|
||||
|
||||
class FD
|
||||
{
|
||||
public:
|
||||
FD();
|
||||
~FD();
|
||||
int init_res(double*,double*);
|
||||
int out_res(char*);
|
||||
void forward_sphere(sphere,int);
|
||||
void forward_cube(cube,int);
|
||||
private:
|
||||
double xmin,xmax,ymin,ymax,dx,dy;
|
||||
int M,N;
|
||||
double height;
|
||||
|
||||
double** res;
|
||||
};
|
||||
|
||||
FD::FD()
|
||||
{
|
||||
res = NULL;
|
||||
}
|
||||
|
||||
FD::~FD()
|
||||
{
|
||||
if(res!=NULL)
|
||||
{
|
||||
for (int i = 0; i < M; i++)
|
||||
delete[] res[i];
|
||||
delete[] res;
|
||||
}
|
||||
}
|
||||
|
||||
int FD::init_res(double* range,double* interval)
|
||||
{
|
||||
xmin = *range; xmax = *(range+1); ymin = *(range+2); ymax = *(range+3); height = *(range+4);
|
||||
height *= -1.0;
|
||||
dx = *interval; dy = *(interval+1);
|
||||
|
||||
M = int (xmax - xmin)/dx + 1;
|
||||
N = int (ymax - ymin)/dy + 1;
|
||||
|
||||
xmax = xmin + (M-1)*dx;
|
||||
ymax = ymin + (N-1)*dy;
|
||||
|
||||
res = new double* [M];
|
||||
for (int i=0;i<M;i++)
|
||||
res[i] = new double [N];
|
||||
|
||||
for (int i=0;i<M;i++)
|
||||
for (int j=0;j<N;j++)
|
||||
res[i][j] = 0.0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int FD::out_res(char* outname)
|
||||
{
|
||||
ofstream outfile(outname);
|
||||
if(!outfile)
|
||||
{
|
||||
cout<<"can not create file: "<<outname<<endl;
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < M; i++)
|
||||
{
|
||||
for (int j = 0; j < N; j++)
|
||||
{
|
||||
outfile<<xmin+dx*i<<" "<<ymin+dy*j<<" "<<-1.0*height<<" "<<setprecision(16)<<res[i][j]<<endl;
|
||||
}
|
||||
}
|
||||
outfile.close();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void FD::forward_sphere(sphere s1,int caltype)
|
||||
{
|
||||
switch(caltype)
|
||||
{
|
||||
case 1: //g
|
||||
{
|
||||
for (int i = 0; i < M; i++)
|
||||
{
|
||||
for (int j = 0; j < N; j++)
|
||||
{
|
||||
res[i][j] += G0*(4.0*s1.density*pow(s1.r,3)*pi/3.0)*(s1.z-height)/pow(pow(xmin+dx*i-s1.x,2)+pow(ymin+dy*j-s1.y,2)+pow(s1.z-height,2),1.5);
|
||||
}
|
||||
}
|
||||
}break;
|
||||
case 2: //gx
|
||||
{
|
||||
for (int i = 0; i < M; i++)
|
||||
{
|
||||
for (int j = 0; j < N; j++)
|
||||
{
|
||||
res[i][j] += -3e+4*G0*(4.0*s1.density*pow(s1.r,3)*pi/3.0)*(s1.z-height)*(xmin+dx*i-s1.x)/pow(pow(xmin+dx*i-s1.x,2)+pow(ymin+dy*j-s1.y,2)+pow(s1.z-height,2),2.5);
|
||||
}
|
||||
}
|
||||
}break;
|
||||
case 3: //gy
|
||||
{
|
||||
for (int i = 0; i < M; i++)
|
||||
{
|
||||
for (int j = 0; j < N; j++)
|
||||
{
|
||||
res[i][j] += -3e+4*G0*(4.0*s1.density*pow(s1.r,3)*pi/3.0)*(s1.z-height)*(ymin+dy*j-s1.y)/pow(pow(xmin+dx*i-s1.x,2)+pow(ymin+dy*j-s1.y,2)+pow(s1.z-height,2),2.5);
|
||||
}
|
||||
}
|
||||
}break;
|
||||
case 4: //gz
|
||||
{
|
||||
for (int i = 0; i < M; i++)
|
||||
{
|
||||
for (int j = 0; j < N; j++)
|
||||
{
|
||||
res[i][j] += 1e+4*G0*(4.0*s1.density*pow(s1.r,3)*pi/3.0)*(2.0*pow(s1.z-height,2)+pow(xmin+dx*i-s1.x,2)+pow(ymin+dy*j-s1.y,2))/pow(pow(xmin+dx*i-s1.x,2)+pow(ymin+dy*j-s1.y,2)+pow(s1.z-height,2),2.5);
|
||||
}
|
||||
}
|
||||
}break;
|
||||
}
|
||||
}
|
||||
|
||||
void FD::forward_cube(cube c1,int caltype)
|
||||
{
|
||||
double R222,R122,R212,R112,R221,R121,R211,R111;
|
||||
double G222,G122,G212,G112,G221,G121,G211,G111;
|
||||
double x,y;
|
||||
double z = height;
|
||||
switch(caltype)
|
||||
{
|
||||
case 1: //g
|
||||
{
|
||||
for (int i = 0; i < M; i++)
|
||||
{
|
||||
for (int j = 0; j < N; j++)
|
||||
{
|
||||
x = xmin + i*dx;
|
||||
y = ymin + j*dy;
|
||||
|
||||
R222=sqrt((c1.x2-x)*(c1.x2-x)+(c1.y2-y)*(c1.y2-y)+(c1.z2-z)*(c1.z2-z));
|
||||
R122=sqrt((c1.x1-x)*(c1.x1-x)+(c1.y2-y)*(c1.y2-y)+(c1.z2-z)*(c1.z2-z));
|
||||
R212=sqrt((c1.x2-x)*(c1.x2-x)+(c1.y1-y)*(c1.y1-y)+(c1.z2-z)*(c1.z2-z));
|
||||
R112=sqrt((c1.x1-x)*(c1.x1-x)+(c1.y1-y)*(c1.y1-y)+(c1.z2-z)*(c1.z2-z));
|
||||
R221=sqrt((c1.x2-x)*(c1.x2-x)+(c1.y2-y)*(c1.y2-y)+(c1.z1-z)*(c1.z1-z));
|
||||
R121=sqrt((c1.x1-x)*(c1.x1-x)+(c1.y2-y)*(c1.y2-y)+(c1.z1-z)*(c1.z1-z));
|
||||
R211=sqrt((c1.x2-x)*(c1.x2-x)+(c1.y1-y)*(c1.y1-y)+(c1.z1-z)*(c1.z1-z));
|
||||
R111=sqrt((c1.x1-x)*(c1.x1-x)+(c1.y1-y)*(c1.y1-y)+(c1.z1-z)*(c1.z1-z));
|
||||
|
||||
G222=(c1.x2-x)*log((c1.y2-y)+R222)+(c1.y2-y)*log((c1.x2-x)+R222)+(c1.z2-z)*arctg((c1.z2-z)*R222/(c1.x2-x)/(c1.y2-y));
|
||||
G122=(c1.x1-x)*log((c1.y2-y)+R122)+(c1.y2-y)*log((c1.x1-x)+R122)+(c1.z2-z)*arctg((c1.z2-z)*R122/(c1.x1-x)/(c1.y2-y));
|
||||
G212=(c1.x2-x)*log((c1.y1-y)+R212)+(c1.y1-y)*log((c1.x2-x)+R212)+(c1.z2-z)*arctg((c1.z2-z)*R212/(c1.x2-x)/(c1.y1-y));
|
||||
G112=(c1.x1-x)*log((c1.y1-y)+R112)+(c1.y1-y)*log((c1.x1-x)+R112)+(c1.z2-z)*arctg((c1.z2-z)*R112/(c1.x1-x)/(c1.y1-y));
|
||||
G221=(c1.x2-x)*log((c1.y2-y)+R221)+(c1.y2-y)*log((c1.x2-x)+R221)+(c1.z1-z)*arctg((c1.z1-z)*R221/(c1.x2-x)/(c1.y2-y));
|
||||
G121=(c1.x1-x)*log((c1.y2-y)+R121)+(c1.y2-y)*log((c1.x1-x)+R121)+(c1.z1-z)*arctg((c1.z1-z)*R121/(c1.x1-x)/(c1.y2-y));
|
||||
G211=(c1.x2-x)*log((c1.y1-y)+R211)+(c1.y1-y)*log((c1.x2-x)+R211)+(c1.z1-z)*arctg((c1.z1-z)*R211/(c1.x2-x)/(c1.y1-y));
|
||||
G111=(c1.x1-x)*log((c1.y1-y)+R111)+(c1.y1-y)*log((c1.x1-x)+R111)+(c1.z1-z)*arctg((c1.z1-z)*R111/(c1.x1-x)/(c1.y1-y));
|
||||
|
||||
res[i][j] +=-1.0*G0*(G222-G122-G212+G112-G221+G121+G211-G111)*c1.density;
|
||||
}
|
||||
}
|
||||
}break;
|
||||
case 2: //gx
|
||||
{
|
||||
for (int i = 0; i < M; i++)
|
||||
{
|
||||
for (int j = 0; j < N; j++)
|
||||
{
|
||||
x = xmin + i*dx;
|
||||
y = ymin + j*dy;
|
||||
|
||||
R222=sqrt((c1.x2-x)*(c1.x2-x)+(c1.y2-y)*(c1.y2-y)+(c1.z2-z)*(c1.z2-z));
|
||||
R122=sqrt((c1.x1-x)*(c1.x1-x)+(c1.y2-y)*(c1.y2-y)+(c1.z2-z)*(c1.z2-z));
|
||||
R212=sqrt((c1.x2-x)*(c1.x2-x)+(c1.y1-y)*(c1.y1-y)+(c1.z2-z)*(c1.z2-z));
|
||||
R112=sqrt((c1.x1-x)*(c1.x1-x)+(c1.y1-y)*(c1.y1-y)+(c1.z2-z)*(c1.z2-z));
|
||||
R221=sqrt((c1.x2-x)*(c1.x2-x)+(c1.y2-y)*(c1.y2-y)+(c1.z1-z)*(c1.z1-z));
|
||||
R121=sqrt((c1.x1-x)*(c1.x1-x)+(c1.y2-y)*(c1.y2-y)+(c1.z1-z)*(c1.z1-z));
|
||||
R211=sqrt((c1.x2-x)*(c1.x2-x)+(c1.y1-y)*(c1.y1-y)+(c1.z1-z)*(c1.z1-z));
|
||||
R111=sqrt((c1.x1-x)*(c1.x1-x)+(c1.y1-y)*(c1.y1-y)+(c1.z1-z)*(c1.z1-z));
|
||||
|
||||
G222=log((c1.y2-y)+R222);
|
||||
G122=log((c1.y2-y)+R122);
|
||||
G212=log((c1.y1-y)+R212);
|
||||
G112=log((c1.y1-y)+R112);
|
||||
G221=log((c1.y2-y)+R221);
|
||||
G121=log((c1.y2-y)+R121);
|
||||
G211=log((c1.y1-y)+R211);
|
||||
G111=log((c1.y1-y)+R111);
|
||||
|
||||
res[i][j] +=G0*(G222-G122-G212+G112-G221+G121+G211-G111)*c1.density*1e+4;
|
||||
}
|
||||
}
|
||||
}break;
|
||||
case 3: //gy
|
||||
{
|
||||
for (int i = 0; i < M; i++)
|
||||
{
|
||||
for (int j = 0; j < N; j++)
|
||||
{
|
||||
x = xmin + i*dx;
|
||||
y = ymin + j*dy;
|
||||
|
||||
R222=sqrt((c1.x2-x)*(c1.x2-x)+(c1.y2-y)*(c1.y2-y)+(c1.z2-z)*(c1.z2-z));
|
||||
R122=sqrt((c1.x1-x)*(c1.x1-x)+(c1.y2-y)*(c1.y2-y)+(c1.z2-z)*(c1.z2-z));
|
||||
R212=sqrt((c1.x2-x)*(c1.x2-x)+(c1.y1-y)*(c1.y1-y)+(c1.z2-z)*(c1.z2-z));
|
||||
R112=sqrt((c1.x1-x)*(c1.x1-x)+(c1.y1-y)*(c1.y1-y)+(c1.z2-z)*(c1.z2-z));
|
||||
R221=sqrt((c1.x2-x)*(c1.x2-x)+(c1.y2-y)*(c1.y2-y)+(c1.z1-z)*(c1.z1-z));
|
||||
R121=sqrt((c1.x1-x)*(c1.x1-x)+(c1.y2-y)*(c1.y2-y)+(c1.z1-z)*(c1.z1-z));
|
||||
R211=sqrt((c1.x2-x)*(c1.x2-x)+(c1.y1-y)*(c1.y1-y)+(c1.z1-z)*(c1.z1-z));
|
||||
R111=sqrt((c1.x1-x)*(c1.x1-x)+(c1.y1-y)*(c1.y1-y)+(c1.z1-z)*(c1.z1-z));
|
||||
|
||||
G222=log((c1.x2-x)+R222);
|
||||
G122=log((c1.x1-x)+R122);
|
||||
G212=log((c1.x2-x)+R212);
|
||||
G112=log((c1.x1-x)+R112);
|
||||
G221=log((c1.x2-x)+R221);
|
||||
G121=log((c1.x1-x)+R121);
|
||||
G211=log((c1.x2-x)+R211);
|
||||
G111=log((c1.x1-x)+R111);
|
||||
|
||||
res[i][j] +=G0*(G222-G122-G212+G112-G221+G121+G211-G111)*c1.density*1e+4;
|
||||
}
|
||||
}
|
||||
}break;
|
||||
case 4: //gz
|
||||
{
|
||||
for (int i = 0; i < M; i++)
|
||||
{
|
||||
for (int j = 0; j < N; j++)
|
||||
{
|
||||
x = xmin + i*dx;
|
||||
y = ymin + j*dy;
|
||||
|
||||
R222=sqrt((c1.x2-x)*(c1.x2-x)+(c1.y2-y)*(c1.y2-y)+(c1.z2-z)*(c1.z2-z));
|
||||
R122=sqrt((c1.x1-x)*(c1.x1-x)+(c1.y2-y)*(c1.y2-y)+(c1.z2-z)*(c1.z2-z));
|
||||
R212=sqrt((c1.x2-x)*(c1.x2-x)+(c1.y1-y)*(c1.y1-y)+(c1.z2-z)*(c1.z2-z));
|
||||
R112=sqrt((c1.x1-x)*(c1.x1-x)+(c1.y1-y)*(c1.y1-y)+(c1.z2-z)*(c1.z2-z));
|
||||
R221=sqrt((c1.x2-x)*(c1.x2-x)+(c1.y2-y)*(c1.y2-y)+(c1.z1-z)*(c1.z1-z));
|
||||
R121=sqrt((c1.x1-x)*(c1.x1-x)+(c1.y2-y)*(c1.y2-y)+(c1.z1-z)*(c1.z1-z));
|
||||
R211=sqrt((c1.x2-x)*(c1.x2-x)+(c1.y1-y)*(c1.y1-y)+(c1.z1-z)*(c1.z1-z));
|
||||
R111=sqrt((c1.x1-x)*(c1.x1-x)+(c1.y1-y)*(c1.y1-y)+(c1.z1-z)*(c1.z1-z));
|
||||
|
||||
G222=atan((c1.x2-x)*(c1.y2-y)/(R222*(c1.z2-z)));
|
||||
G122=atan((c1.x1-x)*(c1.y2-y)/(R122*(c1.z2-z)));
|
||||
G212=atan((c1.x2-x)*(c1.y1-y)/(R212*(c1.z2-z)));
|
||||
G112=atan((c1.x1-x)*(c1.y1-y)/(R112*(c1.z2-z)));
|
||||
G221=atan((c1.x2-x)*(c1.y2-y)/(R221*(c1.z1-z)));
|
||||
G121=atan((c1.x1-x)*(c1.y2-y)/(R121*(c1.z1-z)));
|
||||
G211=atan((c1.x2-x)*(c1.y1-y)/(R211*(c1.z1-z)));
|
||||
G111=atan((c1.x1-x)*(c1.y1-y)/(R111*(c1.z1-z)));
|
||||
|
||||
res[i][j] +=-1.0*G0*(G222-G122-G212+G112-G221+G121+G211-G111)*c1.density*1e+4;
|
||||
}
|
||||
}
|
||||
}break;
|
||||
}
|
||||
}
|
||||
181
archive/g3d/main.cpp
Normal file
181
archive/g3d/main.cpp
Normal file
@@ -0,0 +1,181 @@
|
||||
#include "datafunc.h"
|
||||
#include "forward.h"
|
||||
|
||||
void disp_help()
|
||||
{
|
||||
cout<<"g3d 1.0 - forward modeling of graviational field of 3D regular objects"<<endl<<endl
|
||||
<<"usage: g3d -g|-x|-y|-z -r<xmin>/<xmax>/<ymin>/<ymax>/<height> -i<dx>/<dy> [-s<posi-x>/<posi-y>/<posi-z>/<r>/<density>] [-c<posi-x1>/<posi-x2>/<posi-y1>/<posi-y2>/<posi-z1>/<posi-z2>/<density>] [-f<para-file>] -o<output-file>"<<endl
|
||||
<<" -g|-x|-y|-z"<<endl
|
||||
<<" -r specify calcualtion range"<<endl
|
||||
<<" -i specify calculation intervals"<<endl
|
||||
<<" -s sphere parameters"<<endl
|
||||
<<" -c cube parameters"<<endl
|
||||
<<" -f specify objects' parameters. you can use this to define a lot of objects instead of struggling with the command line"<<endl
|
||||
<<" -o specify output file's name"<<endl<<endl
|
||||
<<"example: g3d -g -r0/1000/0/1000/0 -i10/10 -s500/500/100/50/1.0 -oexample.xyz"<<endl;
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
int caltype = 0;
|
||||
char cmd_type[1024] = {0};
|
||||
char ob_type[1024] = {0};
|
||||
const char* oneline;
|
||||
string oneline_str;
|
||||
char filename[1024] = {0};
|
||||
char outname[1024] = {0};
|
||||
double interval[2];
|
||||
double range[5];
|
||||
|
||||
if (argc==1)
|
||||
{
|
||||
disp_help();
|
||||
}
|
||||
else
|
||||
{
|
||||
sphere s1;
|
||||
cube c1;
|
||||
SphereList list_s;
|
||||
SphereList::iterator is;
|
||||
CubeList list_c;
|
||||
CubeList::iterator ic;
|
||||
|
||||
interval[0]=interval[1]=MAX;
|
||||
range[0]=range[1]=range[2]=range[3]=range[4]=MAX;
|
||||
for (int i = 1; i < argc; i++)
|
||||
{
|
||||
sscanf(argv[i],"%2s",cmd_type);
|
||||
if (!strcmp(cmd_type,GRAV)) caltype = 1;
|
||||
else if (!strcmp(cmd_type,GRADX)) caltype = 2;
|
||||
else if (!strcmp(cmd_type,GRADY)) caltype = 3;
|
||||
else if (!strcmp(cmd_type,GRADZ)) caltype = 4;
|
||||
else if (!strcmp(cmd_type,RANGE))
|
||||
{
|
||||
if (5!=sscanf(argv[i],"%*2s%lf/%lf/%lf/%lf/%lf",&range[0],&range[1],&range[2],&range[3],&range[4]))
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (range[0]>range[1]||range[2]>range[3])
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!strcmp(cmd_type,INTERVAL))
|
||||
{
|
||||
if (2!=sscanf(argv[i],"%*2s%lf/%lf",&interval[0],&interval[1]))
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (interval[0]<=0||interval[1]<=0)
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!strcmp(cmd_type,PARAFILE))
|
||||
{
|
||||
if (-1==sscanf(argv[i],"%*2s%s",filename))
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
ifstream parain(filename);
|
||||
if (!parain)
|
||||
{
|
||||
cout<<"file not found: "<<filename<<endl;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
while(getline(parain,oneline_str))
|
||||
{
|
||||
oneline = oneline_str.c_str();
|
||||
sscanf(oneline,"%2s",ob_type);
|
||||
if (!strcmp(ob_type,SPHERE))
|
||||
{
|
||||
if (5!=sscanf(oneline,"%*2s%lf/%lf/%lf/%lf/%lf",&s1.x,&s1.y,&s1.z,&s1.r,&s1.density))
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax found in file: "<<oneline<<endl;
|
||||
}
|
||||
else list_s.push_back(s1);
|
||||
|
||||
}
|
||||
else if (!strcmp(ob_type,CUBE))
|
||||
{
|
||||
if (7!=sscanf(oneline,"%*2s%lf/%lf/%lf/%lf/%lf/%lf/%lf",&c1.x1,&c1.x2,&c1.y1,&c1.y2,&c1.z1,&c1.z2,&c1.density))
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax found in file: "<<oneline<<endl;
|
||||
}
|
||||
else list_c.push_back(c1);
|
||||
}
|
||||
}
|
||||
parain.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!strcmp(cmd_type,OUTPUT))
|
||||
{
|
||||
if (-1==sscanf(argv[i],"%*2s%s",outname))
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else if (!strcmp(cmd_type,SPHERE))
|
||||
{
|
||||
if (5!=sscanf(argv[i],"%*2s%lf/%lf/%lf/%lf/%lf",&s1.x,&s1.y,&s1.z,&s1.r,&s1.density))
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||||
}
|
||||
else list_s.push_back(s1);
|
||||
|
||||
}
|
||||
else if (!strcmp(cmd_type,CUBE))
|
||||
{
|
||||
if (7!=sscanf(argv[i],"%*2s%lf/%lf/%lf/%lf/%lf/%lf/%lf",&c1.x1,&c1.x2,&c1.y1,&c1.y2,&c1.z1,&c1.z2,&c1.density))
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||||
}
|
||||
else list_c.push_back(c1);
|
||||
}
|
||||
}
|
||||
|
||||
if (list_c.empty()&&list_s.empty())
|
||||
{
|
||||
cout<<"no objects found"<<endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
FD fd1;
|
||||
fd1.init_res(range,interval);
|
||||
if (!list_s.empty())
|
||||
{
|
||||
for (is=list_s.begin();is!=list_s.end();++is)
|
||||
{
|
||||
s1 = *is;
|
||||
fd1.forward_sphere(s1,caltype);
|
||||
}
|
||||
}
|
||||
if (!list_c.empty())
|
||||
{
|
||||
for (ic=list_c.begin();ic!=list_c.end();++ic)
|
||||
{
|
||||
c1 = *ic;
|
||||
fd1.forward_cube(c1,caltype);
|
||||
}
|
||||
}
|
||||
fd1.out_res(outname);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
568
archive/gmshinfo/func.h
Normal file
568
archive/gmshinfo/func.h
Normal file
@@ -0,0 +1,568 @@
|
||||
#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"
|
||||
|
||||
#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
|
||||
34
archive/gmshinfo/main.cpp
Normal file
34
archive/gmshinfo/main.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#include "func.h"
|
||||
void disp_help()
|
||||
{
|
||||
cout<<"gmshinfo 0.1 - inspect a Gmsh .msh file and show relative infomation"<<endl<<endl
|
||||
<<"syntax: gmshinfo <filename> [filename ...]"<<endl
|
||||
<<" The program takes at least one filename for the input information, and it only support ASCII format."<<endl;
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
|
||||
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;
|
||||
}
|
||||
15
archive/gmshinfo/makefile
Normal file
15
archive/gmshinfo/makefile
Normal file
@@ -0,0 +1,15 @@
|
||||
CC = g++-9
|
||||
PROM = /usr/local/sbin/gmshinfo
|
||||
CFLAGS = -I.
|
||||
DEPS = $(shell find . -name "*.h")
|
||||
SRC = $(shell find . -name "*.cpp")
|
||||
OBJ = $(SRC:%.cpp=%.o)
|
||||
|
||||
$(PROM): $(OBJ)
|
||||
$(CC) -o $(PROM) $(OBJ) $(CFLAGS) -O1
|
||||
|
||||
%.o:%.cpp $(DEPS)
|
||||
$(CC) -c $< -o $@ $(CFLAGS) -O1
|
||||
|
||||
clean:
|
||||
rm -rf $(OBJ)
|
||||
3
archive/gmshinfo/readme.md
Normal file
3
archive/gmshinfo/readme.md
Normal file
@@ -0,0 +1,3 @@
|
||||
### gmshinfo
|
||||
目的:读取gmsh程序网格文件.msh,然后返回文件信息
|
||||
语法:gmshinfo [filename]
|
||||
496
archive/gmshset/func.h
Normal file
496
archive/gmshset/func.h
Normal file
@@ -0,0 +1,496 @@
|
||||
#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"
|
||||
|
||||
#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"
|
||||
|
||||
using namespace std;
|
||||
|
||||
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 elemdata_str
|
||||
{
|
||||
int id;
|
||||
double value;
|
||||
};
|
||||
|
||||
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;
|
||||
|
||||
class MshSet
|
||||
{
|
||||
public:
|
||||
MshSet();
|
||||
~MshSet();
|
||||
int init();
|
||||
int readmsh(char*);
|
||||
int outmsh(char*,char*,int*,double*,int);
|
||||
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;
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
MshSet::MshSet()
|
||||
{
|
||||
node = NULL;
|
||||
element = NULL;
|
||||
str_tag = NULL;
|
||||
real_tag = NULL;
|
||||
nodedata = NULL;
|
||||
ele_str_tag = NULL;
|
||||
ele_real_tag = NULL;
|
||||
elemdata = NULL;
|
||||
}
|
||||
|
||||
MshSet::~MshSet()
|
||||
{
|
||||
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 MshSet::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 MshSet::readmsh(char* filename)
|
||||
{
|
||||
string curline;
|
||||
string strtemp,temp_head,temp_middle;
|
||||
stringstream stemp;
|
||||
ifstream mshin(filename);
|
||||
if (!mshin)
|
||||
{
|
||||
cout<<filename<<" not found!"<<endl;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
inputname = filename;
|
||||
while(getline(mshin,curline))
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
else if (curline==EndElementData) continue;
|
||||
}
|
||||
mshin.close();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int MshSet::outmsh(char* infilename,char* outfilename,int* input_type,double* input_value,int input_num)
|
||||
{
|
||||
int total_num = 0;
|
||||
int inttemp;
|
||||
string strtemp;
|
||||
stringstream stemp;
|
||||
ifstream mshin(infilename);
|
||||
ofstream mshout(outfilename);
|
||||
if (!mshout)
|
||||
{
|
||||
cout<<"can not create "<<outfilename<<endl;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
while(getline(mshin,strtemp))
|
||||
{
|
||||
mshout<<strtemp<<endl;
|
||||
}
|
||||
mshin.close();
|
||||
|
||||
for (int i = 0; i < input_num; ++i)
|
||||
{
|
||||
for (ic=map_cata.begin();ic!=map_cata.end();++ic)
|
||||
{
|
||||
strtemp = ic->first;
|
||||
stemp.clear();
|
||||
stemp<<strtemp;
|
||||
stemp>>inttemp>>inttemp;
|
||||
if (*(input_type+i)==inttemp)
|
||||
{
|
||||
//total_num += ic->second;
|
||||
total_num = ic->second;
|
||||
mshout<<ElementData<<endl;
|
||||
mshout<<1<<endl<<"\"PhysicGroup model " << i << "\"" <<endl<<1<<endl<<0<<endl<<3<<endl<<0<<endl<<1<<endl<<total_num<<endl;
|
||||
for (int j = 0; j < elem_num; ++j)
|
||||
{
|
||||
if (element[j].tag[0] == *(input_type+i))
|
||||
{
|
||||
mshout<<element[j].id<<" "<< *(input_value+i) <<endl;
|
||||
}
|
||||
}
|
||||
mshout<<EndElementData<<endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
mshout<<ElementData<<endl;
|
||||
mshout<<1<<endl<<"\"gmshset model\""<<endl<<1<<endl<<0<<endl<<3<<endl<<0<<endl<<1<<endl<<total_num<<endl;
|
||||
for (int j = 0; j < input_num; ++j)
|
||||
{
|
||||
for (int i = 0; i < elem_num; ++i)
|
||||
{
|
||||
if (element[i].tag[0] == *(input_type+j))
|
||||
{
|
||||
mshout<<element[i].id<<" "<< *(input_value+j) <<endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
mshout<<EndElementData;
|
||||
*/
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int MshSet::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
|
||||
48
archive/gmshset/main.cpp
Normal file
48
archive/gmshset/main.cpp
Normal file
@@ -0,0 +1,48 @@
|
||||
#include "func.h"
|
||||
|
||||
void disp_help()
|
||||
{
|
||||
cout<<"gmshset 0.1 - set Gmsh .msh file for physical modeling"<<endl<<endl
|
||||
<<"syntax: gmshset <filename> <output name> p<physical group>d<data value> [p<physical group>d<data value> ...]"<<endl;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
char* inputname;
|
||||
char* outputname;
|
||||
int* p_type = NULL;
|
||||
double* d_value = NULL;
|
||||
|
||||
if (argc <= 3)
|
||||
{
|
||||
disp_help();
|
||||
}
|
||||
else
|
||||
{
|
||||
inputname = argv[1];
|
||||
outputname = argv[2];
|
||||
p_type = new int [argc-3];
|
||||
d_value = new double [argc-3];
|
||||
for (int i = 0; i < argc - 3; ++i)
|
||||
{
|
||||
if(2!=sscanf(argv[i+3],"p%dd%lf",&p_type[i],&d_value[i]))
|
||||
{
|
||||
cout<<argv[i+3]<<" not recognized!"<<endl;
|
||||
if(p_type!=NULL) delete[] p_type;
|
||||
if(d_value!=NULL) delete[] d_value;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
MshSet meshone;
|
||||
meshone.init();
|
||||
if (!meshone.readmsh(inputname))
|
||||
{
|
||||
meshone.outmsh(inputname,outputname,p_type,d_value,argc-3);
|
||||
meshone.relese_node_id();
|
||||
}
|
||||
}
|
||||
if(p_type!=NULL) delete[] p_type;
|
||||
if(d_value!=NULL) delete[] d_value;
|
||||
return 0;
|
||||
}
|
||||
15
archive/gmshset/makefile
Normal file
15
archive/gmshset/makefile
Normal file
@@ -0,0 +1,15 @@
|
||||
CC = g++-8
|
||||
PROM = /usr/local/sbin/gmshset
|
||||
CFLAGS = -I.
|
||||
DEPS = $(shell find . -name "*.h")
|
||||
SRC = $(shell find . -name "*.cpp")
|
||||
OBJ = $(SRC:%.cpp=%.o)
|
||||
|
||||
$(PROM): $(OBJ)
|
||||
$(CC) -o $(PROM) $(OBJ) $(CFLAGS)
|
||||
|
||||
%.o:%.cpp $(DEPS)
|
||||
$(CC) -c $< -o $@ $(CFLAGS)
|
||||
|
||||
clean:
|
||||
rm -rf $(OBJ)
|
||||
274
archive/gmt2msh/func.h
Normal file
274
archive/gmt2msh/func.h
Normal file
@@ -0,0 +1,274 @@
|
||||
#include "iostream"
|
||||
#include "fstream"
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
#include "unistd.h"
|
||||
#include "sstream"
|
||||
#include "vector"
|
||||
#include "string.h"
|
||||
#include "cmath"
|
||||
#include "iomanip"
|
||||
#include "map"
|
||||
|
||||
#define WGS84_PoleRadius 6356752.3//WGS84椭球极半径
|
||||
#define WGS84_EquatorRadius 6378137//WGS84椭球长半径
|
||||
#define EarthRadius 6371008.8
|
||||
#define Pi (4.0*atan(1.0))
|
||||
#define BOLDRED "\033[1m\033[31m"
|
||||
#define RESET "\033[0m"
|
||||
#define MAX_DBL 1e+30
|
||||
#define ZERO 1e-20
|
||||
|
||||
using namespace std;
|
||||
|
||||
int open_infile(ifstream &infile,char* filename)
|
||||
{
|
||||
infile.open(filename);
|
||||
if (!infile)
|
||||
{
|
||||
cout << BOLDRED << "error ==> " << RESET << "file not found: " << filename << endl;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int open_outfile(ofstream &outfile,char* filename)
|
||||
{
|
||||
outfile.open(filename);
|
||||
if (!outfile)
|
||||
{
|
||||
cout << BOLDRED << "error ==> " << RESET << "fail to create the file: " << filename << endl;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//计算一个参考椭球或者参考球在纬度位置的半径
|
||||
double refRadius(double lati,double refr,double refR)
|
||||
{
|
||||
return refr*refR/sqrt(pow(refr,2)*pow(cos((double) lati*Pi/180.0),2)+pow(refR,2)*pow(sin((double) lati*Pi/180.0),2));
|
||||
}
|
||||
|
||||
//直角坐标系下的一个点
|
||||
struct cpoint
|
||||
{
|
||||
double x,y,z;
|
||||
cpoint() //初始化坐标值
|
||||
{
|
||||
x = y = z = MAX_DBL;
|
||||
}
|
||||
};
|
||||
|
||||
//球坐标系下的一个点
|
||||
struct spoint
|
||||
{
|
||||
double lon,lat,rad;
|
||||
spoint() //初始化坐标值
|
||||
{
|
||||
lon = lat = rad = MAX_DBL;
|
||||
}
|
||||
};
|
||||
|
||||
/*直角坐标与球坐标相互转换函数 注意这里使用的球坐标是地理坐标范围 即经度为-180~180 纬度为-90~90*/
|
||||
cpoint s2c(spoint s)
|
||||
{
|
||||
cpoint c;
|
||||
c.x = s.rad*sin((0.5 - s.lat/180.0)*Pi)*cos((2.0 + s.lon/180.0)*Pi);
|
||||
c.y = s.rad*sin((0.5 - s.lat/180.0)*Pi)*sin((2.0 + s.lon/180.0)*Pi);
|
||||
c.z = s.rad*cos((0.5 - s.lat/180.0)*Pi);
|
||||
return c;
|
||||
}
|
||||
|
||||
spoint c2s(cpoint c)
|
||||
{
|
||||
spoint s;
|
||||
s.rad = sqrt(pow(c.x,2)+pow(c.y,2)+pow(c.z,2));
|
||||
if (fabs(s.rad)<ZERO) //点距离原点极近 将点置于原点
|
||||
{
|
||||
s.lat = s.lon = 0.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
s.lat = 90.0 - acos(c.z/s.rad)*180.0/Pi;
|
||||
s.lon = atan2(c.y,c.x)*180.0/Pi;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
struct node
|
||||
{
|
||||
int id;
|
||||
cpoint posic; //直角坐标系位置
|
||||
spoint posis; //球坐标系位置
|
||||
void set(cpoint c) //从直角坐标位置初始化
|
||||
{
|
||||
posic.x = c.x; posic.y = c.y; posic.z = c.z;
|
||||
posis = c2s(posic);
|
||||
}
|
||||
void set(spoint s) //从球坐标位置初始化
|
||||
{
|
||||
posis.lon = s.lon; posis.lat = s.lat; posis.rad = s.rad;
|
||||
posic = s2c(posis);
|
||||
}
|
||||
};
|
||||
typedef vector<node> nodeArray;
|
||||
typedef map<string,int> strMap; //顶点位置映射 用于通过顶点位置寻找相应顶点
|
||||
|
||||
struct triangle
|
||||
{
|
||||
int id;
|
||||
int index[3];
|
||||
};
|
||||
typedef vector<triangle> triArray;
|
||||
|
||||
class gmt2msh
|
||||
{
|
||||
public:
|
||||
gmt2msh(){}
|
||||
~gmt2msh(){}
|
||||
int getRef(char*);
|
||||
int getNode(char*,double,double);
|
||||
int getNode(char*,double);
|
||||
int outMsh(char*);
|
||||
private:
|
||||
double refr,refR;
|
||||
nodeArray Nodes;
|
||||
strMap mapStr;
|
||||
strMap::iterator ivm;
|
||||
triArray Triangles;
|
||||
};
|
||||
|
||||
int gmt2msh::getRef(char* para)
|
||||
{
|
||||
//首先匹配预定义类型
|
||||
if (!strcmp(para,"WGS84"))
|
||||
{
|
||||
refr = WGS84_PoleRadius;
|
||||
refR = WGS84_EquatorRadius;
|
||||
}
|
||||
else if (!strcmp(para,"EarthRadius"))
|
||||
{
|
||||
refr = EarthRadius;
|
||||
refR = EarthRadius;
|
||||
}
|
||||
//匹配参数格式
|
||||
else if (2 == sscanf(para,"%lf/%lf",&refr,&refR))
|
||||
{
|
||||
if (refr <= 0 || refR <= 0)
|
||||
{
|
||||
cout << BOLDRED << "Error ==> " << RESET << "fail to initial reference system" << endl;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << BOLDRED << "Error ==> " << RESET << "fail to initial reference system" << endl;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int gmt2msh::getNode(char* filename,double refr,double refR)
|
||||
{
|
||||
ifstream infile;
|
||||
if (open_infile(infile,filename)) return -1;
|
||||
|
||||
string temp_str;
|
||||
stringstream temp_ss;
|
||||
node temp_node;
|
||||
triangle temp_tri;
|
||||
while (getline(infile,temp_str))
|
||||
{
|
||||
if (*(temp_str.begin()) == '#') continue;
|
||||
|
||||
if (1 == sscanf(temp_str.c_str(),"> Triangle: %d",&temp_tri.id))
|
||||
{
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
getline(infile,temp_str);
|
||||
temp_ss.str("");
|
||||
temp_ss.clear();
|
||||
temp_ss << temp_str;
|
||||
temp_ss >> temp_node.posis.lon >> temp_node.posis.lat;
|
||||
temp_node.posis.rad = refRadius(temp_node.posis.lat,refr,refR);
|
||||
temp_node.set(temp_node.posis);
|
||||
//查找映射表
|
||||
ivm = mapStr.find(temp_str);
|
||||
if (ivm == mapStr.end())
|
||||
{
|
||||
temp_node.id = Nodes.size();
|
||||
Nodes.push_back(temp_node);
|
||||
temp_tri.index[i] = temp_node.id;
|
||||
//添加映射
|
||||
mapStr[temp_str] = temp_node.id;
|
||||
}
|
||||
else temp_tri.index[i] = ivm->second;
|
||||
}
|
||||
}
|
||||
Triangles.push_back(temp_tri);
|
||||
}
|
||||
infile.close();
|
||||
}
|
||||
|
||||
int gmt2msh::getNode(char* filename,double alti)
|
||||
{
|
||||
ifstream infile;
|
||||
if (open_infile(infile,filename)) return -1;
|
||||
|
||||
string temp_str;
|
||||
stringstream temp_ss;
|
||||
node temp_node;
|
||||
triangle temp_tri;
|
||||
while (getline(infile,temp_str))
|
||||
{
|
||||
if (*(temp_str.begin()) == '#') continue;
|
||||
|
||||
if (sscanf(temp_str.c_str(),"> Triangle: %d",&temp_tri.id))
|
||||
{
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
getline(infile,temp_str);
|
||||
temp_ss.str("");
|
||||
temp_ss.clear();
|
||||
temp_ss << temp_str;
|
||||
temp_ss >> temp_node.posic.x >> temp_node.posic.y;
|
||||
temp_node.posic.z = alti;
|
||||
temp_node.set(temp_node.posic);
|
||||
//查找映射表
|
||||
ivm = mapStr.find(temp_str);
|
||||
if (ivm == mapStr.end())
|
||||
{
|
||||
temp_node.id = Nodes.size();
|
||||
Nodes.push_back(temp_node);
|
||||
temp_tri.index[i] = temp_node.id;
|
||||
//添加映射
|
||||
mapStr[temp_str] = temp_node.id;
|
||||
}
|
||||
else temp_tri.index[i] = ivm->second;
|
||||
}
|
||||
}
|
||||
Triangles.push_back(temp_tri);
|
||||
}
|
||||
infile.close();
|
||||
}
|
||||
|
||||
int gmt2msh::outMsh(char* filename)
|
||||
{
|
||||
ofstream outfile;
|
||||
if(open_outfile(outfile,filename)) return -1;
|
||||
|
||||
outfile<<"$MeshFormat"<<endl<<"2.2 0 8"<<endl<<"$EndMeshFormat"<<endl<<"$Nodes"<<endl<<Nodes.size()<<endl;
|
||||
for (int i = 0; i < Nodes.size(); i++)
|
||||
{
|
||||
outfile << Nodes.at(i).id << " " << setprecision(16) << Nodes.at(i).posic.x << " " << Nodes.at(i).posic.y << " " << Nodes.at(i).posic.z << endl;
|
||||
}
|
||||
outfile<<"$EndNodes"<<endl<<"$Elements"<<endl<<Triangles.size()<<endl;
|
||||
for (int i = 0; i < Triangles.size(); i++)
|
||||
{
|
||||
outfile<< Triangles.at(i).id <<" 2 1 0 " << Triangles.at(i).index[0] << " " << Triangles.at(i).index[1] << " " << Triangles.at(i).index[2] << endl;
|
||||
}
|
||||
outfile<<"$EndElements"<<endl;
|
||||
|
||||
outfile.close();
|
||||
return 0;
|
||||
}
|
||||
10
archive/gmt2msh/main.cpp
Normal file
10
archive/gmt2msh/main.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
#include "func.h"
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
gmt2msh gm;
|
||||
gm.getRef("1000/1000");
|
||||
gm.getNode("test.d",1000,1000);
|
||||
gm.outMsh("test.msh");
|
||||
return 0;
|
||||
}
|
||||
21
archive/grad1d/data_func.h
Normal file
21
archive/grad1d/data_func.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifndef _DATA_FUNC_H
|
||||
#define _DATA_FUNC_H
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <cmath>
|
||||
#include <iomanip>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <list>
|
||||
#include "fftw3.h"
|
||||
#define HORIZATION "-h"
|
||||
#define VERTICAL "-v"
|
||||
#define OUTPUT "-o"
|
||||
#define HELP "--help"
|
||||
#define pi (4.0*atan(1.0))
|
||||
using namespace std;
|
||||
typedef list<double> valuelist;
|
||||
valuelist::iterator iv;
|
||||
#endif
|
||||
88
archive/grad1d/grad1d.cpp
Normal file
88
archive/grad1d/grad1d.cpp
Normal file
@@ -0,0 +1,88 @@
|
||||
#include "data_func.h"
|
||||
#include "grad_h.h"
|
||||
#include "grad_v.h"
|
||||
|
||||
void disp_help()
|
||||
{
|
||||
cout<<"grad1d 0.0.1 - calculate horizontal and vertical gradient data for 1-D data"<<endl<<endl
|
||||
<<"usage: grad1d input-file -h|-v [-o output-file]"<<endl
|
||||
<<" -h calculate horizontal gradient"<<endl
|
||||
<<" -v calculate vertical gradient"<<endl
|
||||
<<" -o specify output-file's name. '_gradh|_gradv‘ will be attached at the end of the input"<<endl
|
||||
<<" file's name as an output name if -o is absent"<<endl<<endl
|
||||
<<"example: grad1d in.dat -h -o out.dat"<<endl;
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
if (argc==1)
|
||||
{
|
||||
disp_help();
|
||||
}
|
||||
else if (argc==2)
|
||||
{
|
||||
cout<<"unsufficient arguments, program stopped..."<<endl;
|
||||
return 0;
|
||||
}
|
||||
else if (argc==3)
|
||||
{
|
||||
if (!strcmp(argv[2],HORIZATION))
|
||||
{
|
||||
string temp = argv[1];
|
||||
temp+="_gradh.dat";
|
||||
const char* outname = temp.c_str();
|
||||
if(cal_1d_h(argv[1],outname)) return 0;
|
||||
}
|
||||
else if (!strcmp(argv[2],VERTICAL))
|
||||
{
|
||||
string temp = argv[1];
|
||||
temp+="_gradv.dat";
|
||||
const char* outname = temp.c_str();
|
||||
if(cal_1d_v(argv[1],outname)) return 0;
|
||||
}
|
||||
else cout<<argv[2]<<" not found, program stopped..."<<endl;
|
||||
}
|
||||
else if (argc==4&&!strcmp(argv[3],OUTPUT)&&!strcmp(argv[2],HORIZATION))
|
||||
{
|
||||
cout<<"No output name, program stopped..."<<endl;
|
||||
return 0;
|
||||
}
|
||||
else if (argc==4&&!strcmp(argv[3],OUTPUT)&&!strcmp(argv[2],VERTICAL))
|
||||
{
|
||||
cout<<"No output name, program stopped..."<<endl;
|
||||
return 0;
|
||||
}
|
||||
else if (argc==4)
|
||||
{
|
||||
if (!strcmp(argv[3],OUTPUT))
|
||||
{
|
||||
cout<<argv[2]<<" not found, program stopped..."<<endl;
|
||||
return 0;
|
||||
}
|
||||
else if (!strcmp(argv[2],HORIZATION)||!strcmp(argv[2],VERTICAL))
|
||||
{
|
||||
cout<<argv[3]<<" not found, program stopped..."<<endl;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout<<argv[2]<<" "<<argv[3]<<" not found, program stopped..."<<endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else if (argc>4)
|
||||
{
|
||||
if (!strcmp(argv[3],OUTPUT)&&!strcmp(argv[2],HORIZATION))
|
||||
{
|
||||
if(cal_1d_h(argv[1],argv[4])) return 0;
|
||||
}
|
||||
else if (!strcmp(argv[3],OUTPUT)&&!strcmp(argv[2],VERTICAL))
|
||||
{
|
||||
if(cal_1d_v(argv[1],argv[4])) return 0;
|
||||
}
|
||||
else if (!strcmp(argv[2],VERTICAL)||!strcmp(argv[2],HORIZATION)) cout<<argv[3]<<" not found, program stopped..."<<endl;
|
||||
else if (!strcmp(argv[3],OUTPUT)) cout<<argv[2]<<" not found, program stopped..."<<endl;
|
||||
else cout<<argv[2]<<" "<<argv[3]<<" not found, program stopped..."<<endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
145
archive/grad1d/grad_h.h
Normal file
145
archive/grad1d/grad_h.h
Normal file
@@ -0,0 +1,145 @@
|
||||
#include "data_func.h"
|
||||
|
||||
int cal_1d_h(const char* inname,const char* outname)
|
||||
{
|
||||
ifstream infile(inname);
|
||||
if (!infile)
|
||||
{
|
||||
cout<<inname<<" not found, program stopped..."<<endl;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
stringstream temp_xz;
|
||||
string templine;
|
||||
valuelist list_x;
|
||||
valuelist list_z;
|
||||
double temp_x,temp_z;
|
||||
int dnum,Dnum,Lnum,Rnum,half_Dnum;
|
||||
double endmean;
|
||||
double du;
|
||||
double dx;
|
||||
|
||||
while(getline(infile,templine))
|
||||
{
|
||||
if (templine!="")
|
||||
{
|
||||
temp_xz.clear();
|
||||
temp_xz.str(templine);
|
||||
temp_xz>>temp_x>>temp_z;
|
||||
list_x.push_back(temp_x);
|
||||
list_z.push_back(temp_z);
|
||||
}
|
||||
}
|
||||
infile.close();
|
||||
|
||||
dnum = list_x.size();
|
||||
double* array_x = new double [dnum];
|
||||
double* array_z = new double [dnum];
|
||||
|
||||
double tempvalue;
|
||||
int count = 0;
|
||||
for (iv=list_x.begin();iv!=list_x.end(); ++iv)
|
||||
{
|
||||
tempvalue = *iv;
|
||||
array_x[count]=tempvalue;
|
||||
count++;
|
||||
}
|
||||
count = 0;
|
||||
for (iv=list_z.begin();iv!=list_z.end(); ++iv)
|
||||
{
|
||||
tempvalue = *iv;
|
||||
array_z[count]=tempvalue;
|
||||
count++;
|
||||
}
|
||||
dx = abs(array_x[1]-array_x[0]);
|
||||
|
||||
//testing
|
||||
/*
|
||||
for (int i = 0; i < dnum; i++)
|
||||
{
|
||||
cout<<array_x[i]<<" "<<array_z[i]<<endl;
|
||||
}
|
||||
*/
|
||||
|
||||
Dnum = pow(2,ceil(log(dnum)/log(2))+1);//对数据进行扩边
|
||||
Lnum = floor((Dnum-dnum)/2.0);
|
||||
Rnum = ceil((Dnum-dnum)/2.0);
|
||||
double* Array_z = new double [Dnum];
|
||||
|
||||
endmean = (array_z[0]+array_z[dnum-1])/2.0;//求取扩边的端点值
|
||||
for (int i = 0; i < Lnum; i++)
|
||||
{
|
||||
Array_z[i] = endmean + (array_z[0]-endmean)*cos(-0.5*pi*(i-Lnum)/Lnum);
|
||||
}
|
||||
for (int i = 0; i < dnum; i++)
|
||||
{
|
||||
Array_z[Lnum+i] = array_z[i];
|
||||
}
|
||||
for (int i = 0; i < Rnum; i++)
|
||||
{
|
||||
Array_z[Lnum+dnum+i] = endmean + (array_z[dnum-1]-endmean)*cos(0.5*pi*(i+1)/Rnum);
|
||||
}
|
||||
half_Dnum = Dnum/2;
|
||||
du = pi*2/(Dnum*dx);
|
||||
|
||||
//testing
|
||||
/*
|
||||
for (int i = 0; i < Dnum; i++)
|
||||
{
|
||||
cout<<Array_z[i]<<endl;
|
||||
}
|
||||
*/
|
||||
|
||||
fftw_complex *in, *out, *after_out, *reout;
|
||||
fftw_plan p;
|
||||
in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * Dnum);
|
||||
out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * Dnum);
|
||||
after_out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * Dnum);
|
||||
reout = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * Dnum);
|
||||
|
||||
for (int i = 0; i < Dnum; i++)
|
||||
{
|
||||
in[i][0] = Array_z[i];
|
||||
in[i][1] = 0.0;
|
||||
}
|
||||
|
||||
p=fftw_plan_dft_1d(Dnum,in,out, FFTW_FORWARD, FFTW_ESTIMATE);
|
||||
fftw_execute(p); /* repeat as needed*/
|
||||
|
||||
double u;
|
||||
int k;
|
||||
for (int i = 0; i < half_Dnum; i++)
|
||||
{
|
||||
u = du*i;
|
||||
after_out[i][1] = out[i][0]*u;
|
||||
after_out[i][0] = -1*out[i][1]*u;
|
||||
if (i!=0&&i!=half_Dnum)
|
||||
{
|
||||
k = Dnum-i;
|
||||
after_out[k][1] = -1*out[k][0]*u;
|
||||
after_out[k][0] = out[k][1]*u;
|
||||
}
|
||||
}
|
||||
|
||||
p=fftw_plan_dft_1d(Dnum,after_out,reout, FFTW_BACKWARD, FFTW_ESTIMATE);
|
||||
fftw_execute(p);
|
||||
|
||||
ofstream outfile(outname);
|
||||
for (int i = 0; i < dnum; i++)
|
||||
{
|
||||
outfile<<array_x[i]<<" "<<1e+4*reout[i+Lnum][0]/Dnum<<endl;
|
||||
}
|
||||
outfile.close();
|
||||
|
||||
fftw_destroy_plan(p);
|
||||
fftw_free(in);
|
||||
fftw_free(out);
|
||||
fftw_free(after_out);
|
||||
fftw_free(reout);
|
||||
delete[] Array_z;
|
||||
delete[] array_x;
|
||||
delete[] array_z;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
137
archive/grad1d/grad_v.h
Normal file
137
archive/grad1d/grad_v.h
Normal file
@@ -0,0 +1,137 @@
|
||||
#include "data_func.h"
|
||||
|
||||
int cal_1d_v(const char* inname,const char* outname)
|
||||
{
|
||||
ifstream infile(inname);
|
||||
if (!infile)
|
||||
{
|
||||
cout<<inname<<" not found, program stopped..."<<endl;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
stringstream temp_xz;
|
||||
string templine;
|
||||
valuelist list_x;
|
||||
valuelist list_z;
|
||||
double temp_x,temp_z;
|
||||
int dnum,Dnum,Lnum,Rnum,half_Dnum;
|
||||
double endmean;
|
||||
double du;
|
||||
double dx;
|
||||
|
||||
while(getline(infile,templine))
|
||||
{
|
||||
if (templine!="")
|
||||
{
|
||||
temp_xz.clear();
|
||||
temp_xz.str(templine);
|
||||
temp_xz>>temp_x>>temp_z;
|
||||
list_x.push_back(temp_x);
|
||||
list_z.push_back(temp_z);
|
||||
}
|
||||
}
|
||||
infile.close();
|
||||
|
||||
dnum = list_x.size();
|
||||
double* array_x = new double [dnum];
|
||||
double* array_z = new double [dnum];
|
||||
|
||||
double tempvalue;
|
||||
int count = 0;
|
||||
for (iv=list_x.begin();iv!=list_x.end(); ++iv)
|
||||
{
|
||||
tempvalue = *iv;
|
||||
array_x[count]=tempvalue;
|
||||
count++;
|
||||
}
|
||||
count = 0;
|
||||
for (iv=list_z.begin();iv!=list_z.end(); ++iv)
|
||||
{
|
||||
tempvalue = *iv;
|
||||
array_z[count]=tempvalue;
|
||||
count++;
|
||||
}
|
||||
dx = abs(array_x[1]-array_x[0]);
|
||||
|
||||
//testing
|
||||
/*
|
||||
for (int i = 0; i < dnum; i++)
|
||||
{
|
||||
cout<<array_x[i]<<" "<<array_z[i]<<endl;
|
||||
}
|
||||
*/
|
||||
|
||||
Dnum = pow(2,ceil(log(dnum)/log(2))+1);//对数据进行余弦扩边
|
||||
Lnum = floor((Dnum-dnum)/2.0);
|
||||
Rnum = ceil((Dnum-dnum)/2.0);
|
||||
double* Array_z = new double [Dnum];
|
||||
|
||||
endmean = (array_z[0]+array_z[dnum-1])/2.0;//求取扩边的端点值
|
||||
for (int i = 0; i < Lnum; i++)
|
||||
{
|
||||
Array_z[i] = endmean + (array_z[0]-endmean)*cos(-0.5*pi*(i-Lnum)/Lnum);
|
||||
}
|
||||
for (int i = 0; i < dnum; i++)
|
||||
{
|
||||
Array_z[Lnum+i] = array_z[i];
|
||||
}
|
||||
for (int i = 0; i < Rnum; i++)
|
||||
{
|
||||
Array_z[Lnum+dnum+i] = endmean + (array_z[dnum-1]-endmean)*cos(0.5*pi*(i+1)/Rnum);
|
||||
}
|
||||
half_Dnum = Dnum/2;
|
||||
du = pi*2/(Dnum*dx);
|
||||
|
||||
fftw_complex *in, *out, *after_out, *reout;
|
||||
fftw_plan p;
|
||||
in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * Dnum);
|
||||
out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * Dnum);
|
||||
after_out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * Dnum);
|
||||
reout = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * Dnum);
|
||||
|
||||
for (int i = 0; i < Dnum; i++)
|
||||
{
|
||||
in[i][0] = Array_z[i];
|
||||
in[i][1] = 0.0;
|
||||
}
|
||||
|
||||
p=fftw_plan_dft_1d(Dnum,in,out, FFTW_FORWARD, FFTW_ESTIMATE);
|
||||
fftw_execute(p); /* repeat as needed*/
|
||||
|
||||
double u;
|
||||
int k;
|
||||
for (int i = 0; i < half_Dnum; i++)
|
||||
{
|
||||
u = du*i;
|
||||
after_out[i][1] = out[i][1]*u;
|
||||
after_out[i][0] = out[i][0]*u;
|
||||
if (i!=0&&i!=half_Dnum)
|
||||
{
|
||||
k = Dnum-i;
|
||||
after_out[k][1] = out[k][1]*u;
|
||||
after_out[k][0] = out[k][0]*u;
|
||||
}
|
||||
}
|
||||
|
||||
p=fftw_plan_dft_1d(Dnum,after_out,reout, FFTW_BACKWARD, FFTW_ESTIMATE);
|
||||
fftw_execute(p);
|
||||
|
||||
ofstream outfile(outname);
|
||||
for (int i = 0; i < dnum; i++)
|
||||
{
|
||||
outfile<<array_x[i]<<" "<<1e+4*reout[i+Lnum][0]/Dnum<<endl;
|
||||
}
|
||||
outfile.close();
|
||||
|
||||
fftw_destroy_plan(p);
|
||||
fftw_free(in);
|
||||
fftw_free(out);
|
||||
fftw_free(after_out);
|
||||
fftw_free(reout);
|
||||
delete[] Array_z;
|
||||
delete[] array_x;
|
||||
delete[] array_z;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
15
archive/grad1d/makefile
Normal file
15
archive/grad1d/makefile
Normal file
@@ -0,0 +1,15 @@
|
||||
CC = g++-8
|
||||
PROM = grad1d
|
||||
CFLAGS = /usr/local/Cellar/fftw/3.3.7_1/lib/libfftw3.3.dylib
|
||||
DEPS = $(shell find . -name "*.h")
|
||||
SRC = $(shell find . -name "*.cpp")
|
||||
OBJ = $(SRC:%.cpp=%.o)
|
||||
|
||||
$(PROM): $(OBJ)
|
||||
$(CC) -o $(PROM) $(OBJ) $(CFLAGS)
|
||||
|
||||
%.o:%.cpp $(DEPS)
|
||||
$(CC) -c $< -o $@
|
||||
|
||||
clean:
|
||||
rm -rf $(OBJ)
|
||||
33
archive/grad2d/datafunc.h
Normal file
33
archive/grad2d/datafunc.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#ifndef _DATAFUNC_H
|
||||
#define _DATAFUNC_H
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <cmath>
|
||||
#include <iomanip>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <list>
|
||||
#include "fftw3.h"
|
||||
#include "vector"
|
||||
|
||||
#define DATA "-t"
|
||||
#define COLS "-c"
|
||||
#define HORIZATION_X "-x"
|
||||
#define HORIZATION_Y "-y"
|
||||
#define VERTICAL "-z"
|
||||
#define RANGE "-r"
|
||||
#define INTERVAL "-i"
|
||||
#define OUTPUT "-o"
|
||||
#define POWER "-w"
|
||||
#define BOLDRED "\033[1m\033[31m"
|
||||
#define RESET "\033[0m"
|
||||
|
||||
#define pi (4.0*atan(1.0))
|
||||
|
||||
using namespace std;
|
||||
|
||||
typedef vector<double> _1dArray;
|
||||
|
||||
#endif
|
||||
190
archive/grad2d/grad_hx.h
Normal file
190
archive/grad2d/grad_hx.h
Normal file
@@ -0,0 +1,190 @@
|
||||
#include "datafunc.h"
|
||||
|
||||
int cal_2d_hx(char* inname,char* outname,char* colname,double* range,double* interval,int power)
|
||||
{
|
||||
ifstream infile(inname);
|
||||
if (!infile)
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"file not found: "<<inname<<endl;
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
string temp_str;
|
||||
stringstream temp_ss;
|
||||
double temp_x,temp_y,temp_z;
|
||||
|
||||
//添加数据列选项
|
||||
int cols[3];
|
||||
if (3 != sscanf(colname,"%d,%d,%d",&cols[0],&cols[1],&cols[2]))
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"wrong column parameters: "<<colname<<endl;
|
||||
return -1;
|
||||
}
|
||||
double temp_d;
|
||||
_1dArray tempRow;
|
||||
|
||||
|
||||
double xmin = *range; double xmax = *(range+1); double ymin = *(range+2); double ymax = *(range+3);
|
||||
double dx = *interval; double dy = *(interval+1);
|
||||
int M = floor((ymax-ymin)/dy) + 1;
|
||||
int N = floor((xmax-xmin)/dx) + 1;
|
||||
double** tabledata = new double* [M];
|
||||
for (int i = 0; i < M; i++)
|
||||
tabledata[i] = new double [N];
|
||||
|
||||
int M_ex = pow(2,ceil(log(M)/log(2))+1);
|
||||
int N_ex = pow(2,ceil(log(N)/log(2))+1);
|
||||
int M_ex_up = floor((M_ex - M)/2.0);
|
||||
int M_ex_down = ceil((M_ex - M)/2.0);
|
||||
int N_ex_left = floor((N_ex - N)/2.0);
|
||||
int N_ex_right = ceil((N_ex - N)/2.0);
|
||||
|
||||
double** tabledata_ex = new double* [M_ex];
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
tabledata_ex[i] = new double [N_ex];
|
||||
|
||||
double** V= new double* [M_ex];
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
V[i] = new double [N_ex];
|
||||
|
||||
double* endmean = new double [N];
|
||||
double* endmean2 = new double [M_ex];
|
||||
|
||||
while(getline(infile,temp_str))
|
||||
{
|
||||
if (*(temp_str.begin()) == '#') continue;
|
||||
else
|
||||
{
|
||||
temp_ss.str("");
|
||||
temp_ss.clear();
|
||||
temp_ss << temp_str;
|
||||
|
||||
if(!tempRow.empty()) tempRow.clear();
|
||||
while (temp_ss >> temp_d)
|
||||
{
|
||||
tempRow.push_back(temp_d);
|
||||
}
|
||||
|
||||
temp_x = tempRow.at(cols[0]);
|
||||
temp_y = tempRow.at(cols[1]);
|
||||
temp_z = tempRow.at(cols[2]);
|
||||
if (temp_x>=xmin&&temp_x<=xmax&&temp_y>=ymin&&temp_y<=ymax)
|
||||
{
|
||||
tabledata[int ((temp_y-ymin)/dy)][int ((temp_x-xmin)/dx)] = temp_z;
|
||||
}
|
||||
}
|
||||
}
|
||||
infile.close();
|
||||
|
||||
for (int i = 0; i < N; i++) endmean[i] = (tabledata[0][i]+tabledata[M-1][i])/2.0;
|
||||
for (int i = 0; i < N; i++)
|
||||
{
|
||||
for (int k = 0; k < M_ex_down; k++)
|
||||
{
|
||||
tabledata_ex[k][N_ex_left+i] = endmean[i] + (tabledata[0][i]-endmean[i])*cos(-0.5*pi*(k-M_ex_down)/M_ex_down);
|
||||
}
|
||||
for (int k = 0; k < M; k++)
|
||||
{
|
||||
tabledata_ex[M_ex_down+k][N_ex_left+i] = tabledata[k][i];
|
||||
}
|
||||
for (int k = 0; k < M_ex_up; k++)
|
||||
{
|
||||
tabledata_ex[M_ex_down+M+k][N_ex_left+i] = endmean[i] + (tabledata[M-1][i]-endmean[i])*cos(0.5*pi*(k+1)/M_ex_up);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < M_ex; i++) endmean2[i] = (tabledata_ex[i][N_ex_left]+tabledata_ex[i][N_ex_left+N-1])/2.0;
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
{
|
||||
for (int k = 0; k < N_ex_left; k++)
|
||||
{
|
||||
tabledata_ex[i][k] = endmean2[i] + (tabledata_ex[i][N_ex_left]-endmean2[i])*cos(-0.5*pi*(k-N_ex_left)/N_ex_left);
|
||||
}
|
||||
for (int k = 0; k < N_ex_right; k++)
|
||||
{
|
||||
tabledata_ex[i][N_ex_left+N+k] = endmean2[i] + (tabledata_ex[i][N_ex_left+N-1]-endmean2[i])*cos(0.5*pi*(k+1)/N_ex_right);
|
||||
}
|
||||
}
|
||||
|
||||
fftw_complex *in, *out, *after_out, *reout;
|
||||
fftw_plan p;
|
||||
in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * M_ex * N_ex);
|
||||
out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * M_ex * N_ex);
|
||||
after_out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * M_ex * N_ex);
|
||||
reout = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * M_ex * N_ex);
|
||||
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
{
|
||||
for (int j = 0; j < N_ex; j++)
|
||||
{
|
||||
in[i*N_ex+j][0] = tabledata_ex[i][j];
|
||||
in[i*N_ex+j][1] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
p=fftw_plan_dft_2d(M_ex, N_ex,in , out, FFTW_FORWARD, FFTW_ESTIMATE);
|
||||
fftw_execute(p);
|
||||
|
||||
int half_M_ex = M_ex/2;
|
||||
double du = 1.0/((M_ex-1)*dx);
|
||||
|
||||
int k;
|
||||
for (int i = 0; i < N_ex; i++)
|
||||
{
|
||||
for (int j = 0; j < half_M_ex; j++)
|
||||
{
|
||||
k = M_ex - 1 - j;
|
||||
V[j][i] = du*j;
|
||||
V[k][i] = -1*du*j;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
{
|
||||
for (int j = 0; j < N_ex; j++)
|
||||
{
|
||||
after_out[i*N_ex+j][0] = out[i*N_ex+j][1]*pow(2*pi*V[i][j],power);
|
||||
after_out[i*N_ex+j][1] = out[i*N_ex+j][0]*pow(2*pi*V[i][j],power);
|
||||
}
|
||||
}
|
||||
|
||||
p=fftw_plan_dft_2d(M_ex, N_ex, after_out, reout, FFTW_BACKWARD, FFTW_ESTIMATE);
|
||||
fftw_execute(p);
|
||||
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
{
|
||||
for (int j = 0; j < N_ex; j++)
|
||||
{
|
||||
tabledata_ex[i][j] = 0.1*reout[i*N_ex+j][0]/(M_ex*N_ex);
|
||||
}
|
||||
}
|
||||
|
||||
ofstream outfile(outname);
|
||||
for (int i = 0; i < M; i++)
|
||||
{
|
||||
for (int j = 0; j < N; j++)
|
||||
{
|
||||
outfile<<xmax-dx*j<<" "<<ymax-dy*i<<" "<<setprecision(16)<<tabledata_ex[M_ex_down+i][N_ex_left+j]<<endl;
|
||||
}
|
||||
}
|
||||
outfile.close();
|
||||
|
||||
fftw_destroy_plan(p);
|
||||
fftw_free(in);
|
||||
fftw_free(out);
|
||||
fftw_free(after_out);
|
||||
fftw_free(reout);
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
delete[] tabledata_ex[i];
|
||||
delete[] tabledata_ex;
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
delete[] V[i];
|
||||
delete[] V;
|
||||
for (int i = 0; i < M; i++)
|
||||
delete[] tabledata[i];
|
||||
delete[] tabledata;
|
||||
delete[] endmean;
|
||||
delete[] endmean2;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
189
archive/grad2d/grad_hy.h
Normal file
189
archive/grad2d/grad_hy.h
Normal file
@@ -0,0 +1,189 @@
|
||||
#include "datafunc.h"
|
||||
|
||||
int cal_2d_hy(char* inname,char* outname,char* colname,double* range,double* interval,int power)
|
||||
{
|
||||
ifstream infile(inname);
|
||||
if (!infile)
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"file not found: "<<inname<<endl;
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
string temp_str;
|
||||
stringstream temp_ss;
|
||||
double temp_x,temp_y,temp_z;
|
||||
|
||||
//添加数据列选项
|
||||
int cols[3];
|
||||
if (3 != sscanf(colname,"%d,%d,%d",&cols[0],&cols[1],&cols[2]))
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"wrong column parameters: "<<colname<<endl;
|
||||
return -1;
|
||||
}
|
||||
double temp_d;
|
||||
_1dArray tempRow;
|
||||
|
||||
double xmin = *range; double xmax = *(range+1); double ymin = *(range+2); double ymax = *(range+3);
|
||||
double dx = *interval; double dy = *(interval+1);
|
||||
int M = floor((ymax-ymin)/dy) + 1;
|
||||
int N = floor((xmax-xmin)/dx) + 1;
|
||||
double** tabledata = new double* [M];
|
||||
for (int i = 0; i < M; i++)
|
||||
tabledata[i] = new double [N];
|
||||
|
||||
int M_ex = pow(2,ceil(log(M)/log(2))+1);
|
||||
int N_ex = pow(2,ceil(log(N)/log(2))+1);
|
||||
int M_ex_up = floor((M_ex - M)/2.0);
|
||||
int M_ex_down = ceil((M_ex - M)/2.0);
|
||||
int N_ex_left = floor((N_ex - N)/2.0);
|
||||
int N_ex_right = ceil((N_ex - N)/2.0);
|
||||
|
||||
double** tabledata_ex = new double* [M_ex];
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
tabledata_ex[i] = new double [N_ex];
|
||||
|
||||
double** U= new double* [M_ex];
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
U[i] = new double [N_ex];
|
||||
|
||||
double* endmean = new double [N];
|
||||
double* endmean2 = new double [M_ex];
|
||||
|
||||
while(getline(infile,temp_str))
|
||||
{
|
||||
if (*(temp_str.begin()) == '#') continue;
|
||||
else
|
||||
{
|
||||
temp_ss.str("");
|
||||
temp_ss.clear();
|
||||
temp_ss << temp_str;
|
||||
|
||||
if(!tempRow.empty()) tempRow.clear();
|
||||
while (temp_ss >> temp_d)
|
||||
{
|
||||
tempRow.push_back(temp_d);
|
||||
}
|
||||
|
||||
temp_x = tempRow.at(cols[0]);
|
||||
temp_y = tempRow.at(cols[1]);
|
||||
temp_z = tempRow.at(cols[2]);
|
||||
if (temp_x>=xmin&&temp_x<=xmax&&temp_y>=ymin&&temp_y<=ymax)
|
||||
{
|
||||
tabledata[int ((temp_y-ymin)/dy)][int ((temp_x-xmin)/dx)] = temp_z;
|
||||
}
|
||||
}
|
||||
}
|
||||
infile.close();
|
||||
|
||||
for (int i = 0; i < N; i++) endmean[i] = (tabledata[0][i]+tabledata[M-1][i])/2.0;
|
||||
for (int i = 0; i < N; i++)
|
||||
{
|
||||
for (int k = 0; k < M_ex_down; k++)
|
||||
{
|
||||
tabledata_ex[k][N_ex_left+i] = endmean[i] + (tabledata[0][i]-endmean[i])*cos(-0.5*pi*(k-M_ex_down)/M_ex_down);
|
||||
}
|
||||
for (int k = 0; k < M; k++)
|
||||
{
|
||||
tabledata_ex[M_ex_down+k][N_ex_left+i] = tabledata[k][i];
|
||||
}
|
||||
for (int k = 0; k < M_ex_up; k++)
|
||||
{
|
||||
tabledata_ex[M_ex_down+M+k][N_ex_left+i] = endmean[i] + (tabledata[M-1][i]-endmean[i])*cos(0.5*pi*(k+1)/M_ex_up);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < M_ex; i++) endmean2[i] = (tabledata_ex[i][N_ex_left]+tabledata_ex[i][N_ex_left+N-1])/2.0;
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
{
|
||||
for (int k = 0; k < N_ex_left; k++)
|
||||
{
|
||||
tabledata_ex[i][k] = endmean2[i] + (tabledata_ex[i][N_ex_left]-endmean2[i])*cos(-0.5*pi*(k-N_ex_left)/N_ex_left);
|
||||
}
|
||||
for (int k = 0; k < N_ex_right; k++)
|
||||
{
|
||||
tabledata_ex[i][N_ex_left+N+k] = endmean2[i] + (tabledata_ex[i][N_ex_left+N-1]-endmean2[i])*cos(0.5*pi*(k+1)/N_ex_right);
|
||||
}
|
||||
}
|
||||
|
||||
fftw_complex *in, *out, *after_out, *reout;
|
||||
fftw_plan p;
|
||||
in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * M_ex * N_ex);
|
||||
out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * M_ex * N_ex);
|
||||
after_out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * M_ex * N_ex);
|
||||
reout = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * M_ex * N_ex);
|
||||
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
{
|
||||
for (int j = 0; j < N_ex; j++)
|
||||
{
|
||||
in[i*N_ex+j][0] = tabledata_ex[i][j];
|
||||
in[i*N_ex+j][1] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
p=fftw_plan_dft_2d(M_ex, N_ex,in , out, FFTW_FORWARD, FFTW_ESTIMATE);
|
||||
fftw_execute(p);
|
||||
|
||||
int half_N_ex = N_ex/2;
|
||||
double dv = 1.0/((N_ex-1)*dy);
|
||||
|
||||
int k;
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
{
|
||||
for (int j = 0; j < half_N_ex; j++)
|
||||
{
|
||||
k = N_ex - 1 - j;
|
||||
U[i][j] = dv*j;
|
||||
U[i][k] = -1*dv*j;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
{
|
||||
for (int j = 0; j < N_ex; j++)
|
||||
{
|
||||
after_out[i*N_ex+j][0] = out[i*N_ex+j][1]*pow(2*pi*U[i][j],power);
|
||||
after_out[i*N_ex+j][1] = out[i*N_ex+j][0]*pow(2*pi*U[i][j],power);
|
||||
}
|
||||
}
|
||||
|
||||
p=fftw_plan_dft_2d(M_ex, N_ex, after_out, reout, FFTW_BACKWARD, FFTW_ESTIMATE);
|
||||
fftw_execute(p);
|
||||
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
{
|
||||
for (int j = 0; j < N_ex; j++)
|
||||
{
|
||||
tabledata_ex[i][j] = 0.1*reout[i*N_ex+j][0]/(M_ex*N_ex);
|
||||
}
|
||||
}
|
||||
|
||||
ofstream outfile(outname);
|
||||
for (int i = 0; i < M; i++)
|
||||
{
|
||||
for (int j = 0; j < N; j++)
|
||||
{
|
||||
outfile<<xmax-dx*j<<" "<<ymax-dy*i<<" "<<setprecision(16)<<tabledata_ex[M_ex_down+i][N_ex_left+j]<<endl;
|
||||
}
|
||||
}
|
||||
outfile.close();
|
||||
|
||||
fftw_destroy_plan(p);
|
||||
fftw_free(in);
|
||||
fftw_free(out);
|
||||
fftw_free(after_out);
|
||||
fftw_free(reout);
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
delete[] tabledata_ex[i];
|
||||
delete[] tabledata_ex;
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
delete[] U[i];
|
||||
delete[] U;
|
||||
for (int i = 0; i < M; i++)
|
||||
delete[] tabledata[i];
|
||||
delete[] tabledata;
|
||||
delete[] endmean;
|
||||
delete[] endmean2;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
207
archive/grad2d/grad_z.h
Normal file
207
archive/grad2d/grad_z.h
Normal file
@@ -0,0 +1,207 @@
|
||||
#include "datafunc.h"
|
||||
|
||||
int cal_2d_z(char* inname,char* outname,char* colname,double* range,double* interval,int power)
|
||||
{
|
||||
ifstream infile(inname);
|
||||
if (!infile)
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"file not found: "<<inname<<endl;
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
string temp_str;
|
||||
stringstream temp_ss;
|
||||
double temp_x,temp_y,temp_z;
|
||||
|
||||
//添加数据列选项
|
||||
int cols[3];
|
||||
if (3 != sscanf(colname,"%d,%d,%d",&cols[0],&cols[1],&cols[2]))
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"wrong column parameters: "<<colname<<endl;
|
||||
return -1;
|
||||
}
|
||||
double temp_d;
|
||||
_1dArray tempRow;
|
||||
|
||||
double xmin = *range; double xmax = *(range+1); double ymin = *(range+2); double ymax = *(range+3);
|
||||
double dx = *interval; double dy = *(interval+1);
|
||||
int M = floor((ymax-ymin)/dy) + 1;
|
||||
int N = floor((xmax-xmin)/dx) + 1;
|
||||
double** tabledata = new double* [M];
|
||||
for (int i = 0; i < M; i++)
|
||||
tabledata[i] = new double [N];
|
||||
|
||||
int M_ex = pow(2,ceil(log(M)/log(2))+1);
|
||||
int N_ex = pow(2,ceil(log(N)/log(2))+1);
|
||||
int M_ex_up = floor((M_ex - M)/2.0);
|
||||
int M_ex_down = ceil((M_ex - M)/2.0);
|
||||
int N_ex_left = floor((N_ex - N)/2.0);
|
||||
int N_ex_right = ceil((N_ex - N)/2.0);
|
||||
|
||||
double** tabledata_ex = new double* [M_ex];
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
tabledata_ex[i] = new double [N_ex];
|
||||
|
||||
double** U= new double* [M_ex];
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
U[i] = new double [N_ex];
|
||||
|
||||
double** V= new double* [M_ex];
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
V[i] = new double [N_ex];
|
||||
|
||||
|
||||
double* endmean = new double [N];
|
||||
double* endmean2 = new double [M_ex];
|
||||
|
||||
while(getline(infile,temp_str))
|
||||
{
|
||||
if (*(temp_str.begin()) == '#') continue;
|
||||
else
|
||||
{
|
||||
temp_ss.str("");
|
||||
temp_ss.clear();
|
||||
temp_ss << temp_str;
|
||||
|
||||
if(!tempRow.empty()) tempRow.clear();
|
||||
while (temp_ss >> temp_d)
|
||||
{
|
||||
tempRow.push_back(temp_d);
|
||||
}
|
||||
|
||||
temp_x = tempRow.at(cols[0]);
|
||||
temp_y = tempRow.at(cols[1]);
|
||||
temp_z = tempRow.at(cols[2]);
|
||||
if (temp_x>=xmin&&temp_x<=xmax&&temp_y>=ymin&&temp_y<=ymax)
|
||||
{
|
||||
tabledata[int ((temp_y-ymin)/dy)][int ((temp_x-xmin)/dx)] = temp_z;
|
||||
}
|
||||
}
|
||||
}
|
||||
infile.close();
|
||||
|
||||
for (int i = 0; i < N; i++) endmean[i] = (tabledata[0][i]+tabledata[M-1][i])/2.0;
|
||||
for (int i = 0; i < N; i++)
|
||||
{
|
||||
for (int k = 0; k < M_ex_down; k++)
|
||||
{
|
||||
tabledata_ex[k][N_ex_left+i] = endmean[i] + (tabledata[0][i]-endmean[i])*cos(-0.5*pi*(k-M_ex_down)/M_ex_down);
|
||||
}
|
||||
for (int k = 0; k < M; k++)
|
||||
{
|
||||
tabledata_ex[M_ex_down+k][N_ex_left+i] = tabledata[k][i];
|
||||
}
|
||||
for (int k = 0; k < M_ex_up; k++)
|
||||
{
|
||||
tabledata_ex[M_ex_down+M+k][N_ex_left+i] = endmean[i] + (tabledata[M-1][i]-endmean[i])*cos(0.5*pi*(k+1)/M_ex_up);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < M_ex; i++) endmean2[i] = (tabledata_ex[i][N_ex_left]+tabledata_ex[i][N_ex_left+N-1])/2.0;
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
{
|
||||
for (int k = 0; k < N_ex_left; k++)
|
||||
{
|
||||
tabledata_ex[i][k] = endmean2[i] + (tabledata_ex[i][N_ex_left]-endmean2[i])*cos(-0.5*pi*(k-N_ex_left)/N_ex_left);
|
||||
}
|
||||
for (int k = 0; k < N_ex_right; k++)
|
||||
{
|
||||
tabledata_ex[i][N_ex_left+N+k] = endmean2[i] + (tabledata_ex[i][N_ex_left+N-1]-endmean2[i])*cos(0.5*pi*(k+1)/N_ex_right);
|
||||
}
|
||||
}
|
||||
|
||||
fftw_complex *in, *out, *after_out, *reout;
|
||||
fftw_plan p;
|
||||
in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * M_ex * N_ex);
|
||||
out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * M_ex * N_ex);
|
||||
after_out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * M_ex * N_ex);
|
||||
reout = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * M_ex * N_ex);
|
||||
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
{
|
||||
for (int j = 0; j < N_ex; j++)
|
||||
{
|
||||
in[i*N_ex+j][0] = tabledata_ex[i][j];
|
||||
in[i*N_ex+j][1] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
p=fftw_plan_dft_2d(M_ex, N_ex,in , out, FFTW_FORWARD, FFTW_ESTIMATE);
|
||||
fftw_execute(p);
|
||||
|
||||
int half_M_ex = M_ex/2;
|
||||
int half_N_ex = N_ex/2;
|
||||
double du = 1.0/((M_ex-1)*dx);
|
||||
double dv = 1.0/((N_ex-1)*dy);
|
||||
|
||||
int k;
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
{
|
||||
for (int j = 0; j < half_N_ex; j++)
|
||||
{
|
||||
k = N_ex - 1 - j;
|
||||
V[i][j] = V[i][k] = (dv*j)*(dv*j);
|
||||
}
|
||||
}
|
||||
double u;
|
||||
for (int i = 0; i < N_ex; i++)
|
||||
{
|
||||
for (int j = 0; j < half_M_ex; j++)
|
||||
{
|
||||
k = M_ex - 1 - j;
|
||||
U[j][i] = U[k][i] = (du*j)*(du*j);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
{
|
||||
for (int j = 0; j < N_ex; j++)
|
||||
{
|
||||
after_out[i*N_ex+j][0] = out[i*N_ex+j][0]*pow(2*pi*sqrt(U[i][j]+V[i][j]),power);
|
||||
after_out[i*N_ex+j][1] = out[i*N_ex+j][1]*pow(2*pi*sqrt(U[i][j]+V[i][j]),power);
|
||||
}
|
||||
}
|
||||
|
||||
p=fftw_plan_dft_2d(M_ex, N_ex, after_out, reout, FFTW_BACKWARD, FFTW_ESTIMATE);
|
||||
fftw_execute(p);
|
||||
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
{
|
||||
for (int j = 0; j < N_ex; j++)
|
||||
{
|
||||
tabledata_ex[i][j] = 0.1*reout[i*N_ex+j][0]/(M_ex*N_ex);
|
||||
}
|
||||
}
|
||||
|
||||
ofstream outfile(outname);
|
||||
for (int i = 0; i < M; i++)
|
||||
{
|
||||
for (int j = 0; j < N; j++)
|
||||
{
|
||||
outfile<<xmin+dx*j<<" "<<ymin+dy*i<<" "<<setprecision(16)<<tabledata_ex[M_ex_down+i][N_ex_left+j]<<endl;
|
||||
}
|
||||
}
|
||||
outfile.close();
|
||||
|
||||
fftw_destroy_plan(p);
|
||||
fftw_free(in);
|
||||
fftw_free(out);
|
||||
fftw_free(after_out);
|
||||
fftw_free(reout);
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
delete[] tabledata_ex[i];
|
||||
delete[] tabledata_ex;
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
delete[] U[i];
|
||||
delete[] U;
|
||||
for (int i = 0; i < M_ex; i++)
|
||||
delete[] V[i];
|
||||
delete[] V;
|
||||
for (int i = 0; i < M; i++)
|
||||
delete[] tabledata[i];
|
||||
delete[] tabledata;
|
||||
delete[] endmean;
|
||||
delete[] endmean2;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
156
archive/grad2d/main.cpp
Normal file
156
archive/grad2d/main.cpp
Normal file
@@ -0,0 +1,156 @@
|
||||
//计算二维平面数据的三方向导数,因为有很多方法可以得到xyz三列数据文件,所以数据类型为xyz的三列数据文件
|
||||
//数据排列方式: x坐标 y坐标 v数值
|
||||
//坐标方向: z轴向下的右旋坐标系
|
||||
#include "datafunc.h"
|
||||
#include "grad_z.h"
|
||||
#include "grad_hx.h"
|
||||
#include "grad_hy.h"
|
||||
void disp_help()
|
||||
{
|
||||
cout<<"grad2d 0.2 - calculate horizontal and vertical gradients for an equal-grid plane data set"<<endl<<endl
|
||||
<<"usage: grad2d -t<input-file> -x|-y|-z -r<xmin>/<xmax>/<ymin>/<ymax> -i<x-spacing>/<y-spacing> -w<power> [-c<col-x>,<col-y>,<col-val>] [-o<output-file>]"<<endl<<endl
|
||||
<<"syntax: " << endl << "-t\tinput table data. The program takes a three-columns table data file. The order of columns are \'x\', \'y\'' and \'point-value\'. lines starts with '#' will be skipped."<<endl
|
||||
<<"-x|-y|-z\tselect calculating objective. Only one objective can be chosen at a time."<<endl
|
||||
<<"-r\tspecify the range of calculating area."<<endl
|
||||
<<"-i\tspecify intervals of the input data."<<endl
|
||||
<<"-c\tset data columns, the default is 0,1,2."<<endl
|
||||
<<"-w\torders of output gradient data."<<endl
|
||||
<<"-o\tspecify output-file's name. \'_gradhx|_gradhy|_gradz\' will be attached at the end of the input-name if \'-o\' is absent."<<endl<<endl
|
||||
<<"example: grad2d -tin.dat -x -r0/100/0/100 -i10/10 -w1 -oout.dat"<<endl;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if (argc==1)
|
||||
{
|
||||
disp_help();
|
||||
}
|
||||
else
|
||||
{
|
||||
int caltype = 0;
|
||||
int power = 1;
|
||||
char cmd_type[1024] = {0};
|
||||
char filename[1024] = {0};
|
||||
char filetype[1024] = {0};
|
||||
char outname[1024] = {0};
|
||||
char colname[1024] = "0,1,2";
|
||||
double range[4] = {1e+30,1e+30,1e+30,1e+30};
|
||||
double interval[2] = {1e+30,1e+30};
|
||||
for (int i = 1; i < argc; i++)
|
||||
{
|
||||
sscanf(argv[i],"%2s",cmd_type);
|
||||
if (!strcmp(cmd_type,RANGE))
|
||||
{
|
||||
if (4!=sscanf(argv[i],"%*2s%lf/%lf/%lf/%lf",&range[0],&range[1],&range[2],&range[3]))
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (range[0]>range[1])
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||||
return 0;
|
||||
}
|
||||
else if (range[2]>range[3])
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!strcmp(cmd_type,DATA))
|
||||
{
|
||||
if (2!=sscanf(argv[i],"%*2s%[^.]%s",filename,filetype))
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else if (!strcmp(cmd_type,COLS))
|
||||
{
|
||||
if (1!=sscanf(argv[i],"%*2s%s",colname))
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else if (!strcmp(cmd_type,POWER))
|
||||
{
|
||||
if (1!=sscanf(argv[i],"%*2s%d",&power))
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else if (!strcmp(cmd_type,INTERVAL))
|
||||
{
|
||||
if (2!=sscanf(argv[i],"%*2s%lf/%lf",&interval[0],&interval[1]))
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (interval[0]<=0||interval[1]<=0)
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!strcmp(cmd_type,HORIZATION_X)) caltype = 1;
|
||||
else if (!strcmp(cmd_type,HORIZATION_Y)) caltype = 2;
|
||||
else if (!strcmp(cmd_type,VERTICAL)) caltype = 3;
|
||||
else if (!strcmp(cmd_type,OUTPUT))
|
||||
{
|
||||
if (-1==sscanf(argv[i],"%*2s%s",outname))
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch(caltype)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
if(!strcmp(outname,""))
|
||||
{
|
||||
strcat(outname,filename);
|
||||
strcat(outname,"_gradhx.xyz");
|
||||
}
|
||||
strcat(filename,filetype);
|
||||
cal_2d_hx(filename,outname,colname,range,interval,power);
|
||||
}break;
|
||||
case 2:
|
||||
{
|
||||
if(!strcmp(outname,""))
|
||||
{
|
||||
strcat(outname,filename);
|
||||
strcat(outname,"_gradhy.xyz");
|
||||
}
|
||||
strcat(filename,filetype);
|
||||
cal_2d_hy(filename,outname,colname,range,interval,power);
|
||||
}break;
|
||||
case 3:
|
||||
{
|
||||
if(!strcmp(outname,""))
|
||||
{
|
||||
strcat(outname,filename);
|
||||
strcat(outname,"_gradz.xyz");
|
||||
}
|
||||
strcat(filename,filetype);
|
||||
cal_2d_z(filename,outname,colname,range,interval,power);
|
||||
}break;
|
||||
default:
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad cal_type"<<endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
16
archive/grad2d/makefile
Normal file
16
archive/grad2d/makefile
Normal file
@@ -0,0 +1,16 @@
|
||||
CC = g++-8
|
||||
PROM = /usr/local/sbin/grad2d
|
||||
CFLAGS = -L /usr/local/Cellar/fftw/3.3.8/lib -lfftw3.3
|
||||
IFLAGS = -I /usr/local/Cellar/fftw/3.3.8/include
|
||||
DEPS = $(shell find . -name "*.h")
|
||||
SRC = $(shell find . -name "*.cpp")
|
||||
OBJ = $(SRC:%.cpp=%.o)
|
||||
|
||||
$(PROM): $(OBJ)
|
||||
$(CC) -o $(PROM) $(OBJ) $(CFLAGS) ${IFLAGS}
|
||||
|
||||
%.o:%.cpp $(DEPS)
|
||||
$(CC) -c $< -o $@ $(CFLAGS) ${IFLAGS}
|
||||
|
||||
clean:
|
||||
rm -rf $(OBJ)
|
||||
22
archive/grav1d_cylinder/data_func.h
Normal file
22
archive/grav1d_cylinder/data_func.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#ifndef _DATA_FUNC_H
|
||||
#define _DATA_FUNC_H
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <cmath>
|
||||
#include <iomanip>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#define HORIZATION "-h"
|
||||
#define VERTICAL "-v"
|
||||
#define ANOMOALY "-a"
|
||||
#define OUTPUT "-o"
|
||||
#define RANGE "-d"
|
||||
#define INTERVAL "-i"
|
||||
#define PARAMETER "-p"
|
||||
#define HELP "--help"
|
||||
#define pi 3.1415926535897932384626433832795
|
||||
#define G 6.67191e-3
|
||||
using namespace std;
|
||||
#endif
|
||||
160
archive/grav1d_cylinder/grav1d_cylinder.cpp
Normal file
160
archive/grav1d_cylinder/grav1d_cylinder.cpp
Normal file
@@ -0,0 +1,160 @@
|
||||
#include "grav1d_cylinder.h"
|
||||
|
||||
void disp_help()
|
||||
{
|
||||
cout<<"grav1d-cylinder 1.0 - forwad modeling gravity and its gradient data of a horizontal cylinder"<<endl<<endl
|
||||
<<"usage: grav1d-cylinder -p<para1>/<para2>/<para3>/<para4> -d<xmin>/<xmax> -i<x_interval> -a|-h|-v -o<output-file>"<<endl
|
||||
<<" -p geometrical and physical properties of the cylinder"<<endl
|
||||
<<" para1 central position (m) of the cylinder"<<endl
|
||||
<<" para2 central depth (m) of the cylinder"<<endl
|
||||
<<" para3 radius (m) of the cylinder"<<endl
|
||||
<<" para4 density (g/cm3) of the cylinder"<<endl
|
||||
<<" -d calculating range(m)"<<endl
|
||||
<<" -i calculating interval(m)"<<endl
|
||||
<<" -a forward modeling gravity data"<<endl
|
||||
<<" -h forward modeling horizontal gradient of gravity data"<<endl
|
||||
<<" -v forward modeling vertical gradient of gravity data"<<endl
|
||||
<<" -o specify output-file's name"<<endl<<endl
|
||||
<<"example: grav1d_cylinder -p0/100/50/1.0 -d-1000/1000 -i10 -a -otestout.dat"<<endl;
|
||||
}
|
||||
|
||||
int typeget(char *str, const char* str2,string &str3)
|
||||
{
|
||||
char* strp = strstr(str, str2); // 从字符串str中查找str2,
|
||||
if (strp == NULL)
|
||||
{
|
||||
return 0; // 如果没有找到,返回
|
||||
}
|
||||
string temp = str;
|
||||
str3=temp.substr(strlen(str2));//提出除str2外的子句
|
||||
return 1;
|
||||
}
|
||||
|
||||
string& replace_all(string& str,const string& old_value,const string& new_value,int &num) //替换str中所有lod_value为new_value,返回被替换的lod_value的个数
|
||||
{
|
||||
int count = 0;
|
||||
for(string::size_type pos(0);pos!=string::npos;pos+=new_value.length()){
|
||||
if((pos=str.find(old_value,pos))!=string::npos){
|
||||
str.replace(pos,old_value.length(),new_value);
|
||||
count++;
|
||||
}
|
||||
else break;
|
||||
}
|
||||
num = count;
|
||||
return str;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
string temp;
|
||||
stringstream stemp;
|
||||
double Para[4];
|
||||
double Range[3];
|
||||
int space_num;
|
||||
int cal_type = 0;
|
||||
string outname;
|
||||
|
||||
Para[0]=Para[1]=Para[2]=Para[3]=1e+20;
|
||||
Range[0]=Range[1]=Range[2]=1e+20;
|
||||
|
||||
if (argc==1)
|
||||
{
|
||||
disp_help();
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 1; i < argc; i++)
|
||||
{
|
||||
if (!strcmp(argv[i],ANOMOALY)) cal_type = 1;
|
||||
else if (!strcmp(argv[i],HORIZATION)) cal_type = 2;
|
||||
else if (!strcmp(argv[i],VERTICAL)) cal_type = 3;
|
||||
|
||||
if (typeget(argv[i],PARAMETER,temp))
|
||||
{
|
||||
replace_all(temp,"/"," ",space_num);
|
||||
stemp.clear();
|
||||
stemp.str(temp);
|
||||
if (space_num==3)
|
||||
{
|
||||
stemp>>Para[0]>>Para[1]>>Para[2]>>Para[3];
|
||||
if (Para[1]<Para[2])
|
||||
{
|
||||
cout<<"wrong geometrical properties, program stopped..."<<endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cout<<"insufficient attributes information, program stoped..."<<endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeget(argv[i],RANGE,temp))
|
||||
{
|
||||
replace_all(temp,"/"," ",space_num);
|
||||
stemp.clear();
|
||||
stemp.str(temp);
|
||||
if (space_num==1)
|
||||
{
|
||||
stemp>>Range[0]>>Range[2];
|
||||
}
|
||||
else
|
||||
{
|
||||
cout<<"wrong attributes information, program stoped..."<<endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeget(argv[i],INTERVAL,temp))
|
||||
{
|
||||
if (temp=="")
|
||||
{
|
||||
cout<<"wrong attributes information, program stoped..."<<endl;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
stemp.clear();
|
||||
stemp.str(temp);
|
||||
stemp>>Range[1];
|
||||
}
|
||||
}
|
||||
|
||||
if (typeget(argv[i],OUTPUT,temp))
|
||||
{
|
||||
if (temp=="")
|
||||
{
|
||||
cout<<"no output name, program stopped..."<<endl;
|
||||
return 0;
|
||||
}
|
||||
else outname = temp.c_str();
|
||||
}
|
||||
}
|
||||
|
||||
if (cal_type==0||Range[0]==1e+20||Para[0]==1e+20)
|
||||
{
|
||||
cout<<"wrong commond line, program stopped..."<<endl;
|
||||
return 0;
|
||||
}
|
||||
else if (Range[0]>Range[2]||(Range[0]+Range[1])>Range[2]||(Range[0]+2*Range[1])>Range[2])
|
||||
{
|
||||
cout<<"wrong range, program stopped..."<<endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (cal_type==1)
|
||||
{
|
||||
cylinder_a(Range,Para,outname);
|
||||
}
|
||||
else if (cal_type==2)
|
||||
{
|
||||
cylinder_h(Range,Para,outname);
|
||||
}
|
||||
else if (cal_type==3)
|
||||
{
|
||||
cylinder_v(Range,Para,outname);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
67
archive/grav1d_cylinder/grav1d_cylinder.h
Normal file
67
archive/grav1d_cylinder/grav1d_cylinder.h
Normal file
@@ -0,0 +1,67 @@
|
||||
#include "data_func.h"
|
||||
|
||||
void cylinder_a(double* Range,double* Para,string filename)
|
||||
{
|
||||
double xmin,xmax,dx;
|
||||
double D,r,S,density;
|
||||
double g;
|
||||
|
||||
xmin = *Range; dx = *(Range+1); xmax = *(Range+2);
|
||||
S = *Para; D = *(Para+1); r = *(Para+2); density = *(Para+3);
|
||||
const char* savename = filename.c_str();
|
||||
|
||||
int Num = (xmax-xmin)/dx+1;
|
||||
xmax = xmin + (Num-1)*dx;
|
||||
|
||||
ofstream outfile(savename);
|
||||
for (int i=0;i<Num;i++)
|
||||
{
|
||||
g=2*G*D*density*pi*r*r/((xmin+i*dx-S)*(xmin+i*dx-S)+D*D);
|
||||
outfile<<xmin+i*dx<<" "<<setprecision(16)<<g<<endl;
|
||||
}
|
||||
outfile.close();
|
||||
}
|
||||
|
||||
void cylinder_h(double* Range,double* Para,string filename)
|
||||
{
|
||||
double xmin,xmax,dx;
|
||||
double D,r,S,density;
|
||||
double g;
|
||||
|
||||
xmin = *Range; dx = *(Range+1); xmax = *(Range+2);
|
||||
S = *Para; D = *(Para+1); r = *(Para+2); density = *(Para+3);
|
||||
const char* savename = filename.c_str();
|
||||
|
||||
int Num = (xmax-xmin)/dx+1;
|
||||
xmax = xmin + (Num-1)*dx;
|
||||
|
||||
ofstream outfile(savename);
|
||||
for (int i=0;i<Num;i++)
|
||||
{
|
||||
g=-4*G*density*pi*r*r*D*(xmin+i*dx-S)/pow(((xmin+i*dx-S)*(xmin+i*dx-S)+D*D),2);
|
||||
outfile<<xmin+i*dx<<" "<<setprecision(16)<<g*1e+4<<endl;
|
||||
}
|
||||
outfile.close();
|
||||
}
|
||||
|
||||
void cylinder_v(double* Range,double* Para,string filename)
|
||||
{
|
||||
double xmin,xmax,dx;
|
||||
double D,r,S,density;
|
||||
double g;
|
||||
|
||||
xmin = *Range; dx = *(Range+1); xmax = *(Range+2);
|
||||
S = *Para; D = *(Para+1); r = *(Para+2); density = *(Para+3);
|
||||
const char* savename = filename.c_str();
|
||||
|
||||
int Num = (xmax-xmin)/dx+1;
|
||||
xmax = xmin + (Num-1)*dx;
|
||||
|
||||
ofstream outfile(savename);
|
||||
for (int i=0;i<Num;i++)
|
||||
{
|
||||
g=2*G*density*pi*r*r*(D*D-(xmin+i*dx-S)*(xmin+i*dx-S))/pow((xmin+i*dx-S)*(xmin+i*dx-S)+D*D,2);
|
||||
outfile<<xmin+i*dx<<" "<<setprecision(16)<<g*1e+4<<endl;
|
||||
}
|
||||
outfile.close();
|
||||
}
|
||||
384
archive/grav2d_cube/dispHelp.h
Normal file
384
archive/grav2d_cube/dispHelp.h
Normal file
@@ -0,0 +1,384 @@
|
||||
#ifndef _DISPHELP_H
|
||||
#define _DISPHELP_H
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <iomanip>
|
||||
#include <sys/ioctl.h>
|
||||
#include "vector"
|
||||
|
||||
using namespace std;
|
||||
|
||||
typedef vector<string> strArray;
|
||||
|
||||
struct option
|
||||
{
|
||||
string flag_s,flag_l;
|
||||
string message;
|
||||
strArray sec_message;
|
||||
option()
|
||||
{
|
||||
flag_s = flag_l = message = "";
|
||||
}
|
||||
};
|
||||
typedef vector<option> opArray;
|
||||
|
||||
class dispHelp
|
||||
{
|
||||
public:
|
||||
dispHelp(){
|
||||
front_space = 0;
|
||||
back_space = 10;
|
||||
ex_name = "Execuable";
|
||||
version = "0.0.1";
|
||||
descript = "Brief information about this command.";
|
||||
author = "Author's information.";
|
||||
}
|
||||
~dispHelp(){}
|
||||
void addHeadInfo(string,string,string,string);
|
||||
void addUsage(string);
|
||||
void addOption(string,string,string);
|
||||
void addOptionSec(string,int);
|
||||
void addExample(string);
|
||||
void changeLayerOut(int,int);
|
||||
void show();
|
||||
private:
|
||||
string ex_name,version,descript,author;
|
||||
int front_space,back_space;
|
||||
opArray options;
|
||||
strArray examples;
|
||||
strArray usages;
|
||||
};
|
||||
|
||||
void dispHelp::addHeadInfo(string s1,string s2,string s3,string s4)
|
||||
{
|
||||
ex_name = s1; version = s2; descript = s3; author = s4;
|
||||
return;
|
||||
}
|
||||
|
||||
void dispHelp::addUsage(string usg)
|
||||
{
|
||||
usages.push_back(usg);
|
||||
return;
|
||||
}
|
||||
|
||||
void dispHelp::addOption(string msg,string sflag,string lflag = "")
|
||||
{
|
||||
option tmp_option;
|
||||
tmp_option.message = msg; tmp_option.flag_s = sflag; tmp_option.flag_l = lflag;
|
||||
options.push_back(tmp_option);
|
||||
return;
|
||||
}
|
||||
|
||||
void dispHelp::addOptionSec(string msg,int index = -1)
|
||||
{
|
||||
if (index < 0)
|
||||
{
|
||||
options.back().sec_message.push_back(msg);
|
||||
}
|
||||
else options[index].sec_message.push_back(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
void dispHelp::addExample(string ex)
|
||||
{
|
||||
examples.push_back(ex);
|
||||
return;
|
||||
}
|
||||
|
||||
void dispHelp::changeLayerOut(int left,int right)
|
||||
{
|
||||
front_space = left; back_space = right;
|
||||
return;
|
||||
}
|
||||
|
||||
void dispHelp::show()
|
||||
{
|
||||
int line_length;
|
||||
string segment,full_message;
|
||||
stringstream ss_message;
|
||||
//获取终端窗口的行列数
|
||||
struct winsize w;
|
||||
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
|
||||
//显示头信息
|
||||
full_message = ex_name + " " + version + " - " + descript;
|
||||
ss_message.clear(); ss_message.str(full_message);
|
||||
|
||||
line_length = front_space + back_space;
|
||||
while(ss_message >> segment)
|
||||
{
|
||||
if ((line_length+segment.length()+1) <= w.ws_col)
|
||||
{
|
||||
if (line_length == (front_space + back_space))
|
||||
{
|
||||
for (int i = 0; i < front_space; i++) clog << " ";
|
||||
clog << segment << " ";
|
||||
line_length += (segment.length()+1);
|
||||
}
|
||||
else
|
||||
{
|
||||
clog << segment << " ";
|
||||
line_length += (segment.length()+1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
clog << endl;
|
||||
for (int i = 0; i < front_space+4; i++) clog << " ";
|
||||
clog << segment << " ";
|
||||
line_length = (segment.length()+9+front_space+back_space);
|
||||
}
|
||||
}
|
||||
clog << endl;
|
||||
|
||||
ss_message.clear(); ss_message.str(author);
|
||||
line_length = front_space + back_space;;
|
||||
while(ss_message >> segment)
|
||||
{
|
||||
if ((line_length+segment.length()+1) <= w.ws_col)
|
||||
{
|
||||
if (line_length == (front_space + back_space))
|
||||
{
|
||||
for (int i = 0; i < front_space; i++) clog << " ";
|
||||
clog << "Author: " << segment << " ";
|
||||
line_length += (segment.length()+9);
|
||||
}
|
||||
else
|
||||
{
|
||||
clog << segment << " ";
|
||||
line_length += (segment.length()+1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
clog << endl;
|
||||
for (int i = 0; i < front_space+4; i++) clog << " ";
|
||||
clog << segment << " ";
|
||||
line_length = (segment.length()+9+front_space+back_space);
|
||||
}
|
||||
}
|
||||
clog << endl;
|
||||
|
||||
if (!usages.empty())
|
||||
{
|
||||
for (int i = 0; i < front_space; i++) clog << " ";
|
||||
clog << "Usage:" << endl;
|
||||
for (int i = 0; i < usages.size(); i++)
|
||||
{
|
||||
ss_message.clear(); ss_message.str(usages[i]);
|
||||
|
||||
line_length = front_space + back_space + 4;
|
||||
while(ss_message >> segment)
|
||||
{
|
||||
if ((line_length+segment.length()+1) <= w.ws_col)
|
||||
{
|
||||
if (line_length == (front_space+back_space+4))
|
||||
{
|
||||
for (int i = 0; i < front_space+4; i++) clog << " ";
|
||||
clog << segment << " ";
|
||||
line_length += (segment.length()+1);
|
||||
}
|
||||
else
|
||||
{
|
||||
clog << segment << " ";
|
||||
line_length += (segment.length()+1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
clog << endl;
|
||||
for (int i = 0; i < front_space+9; i++) clog << " ";
|
||||
clog << segment << " ";
|
||||
line_length = (segment.length()+10+front_space+back_space);
|
||||
}
|
||||
}
|
||||
clog << endl;
|
||||
}
|
||||
}
|
||||
|
||||
if (!options.empty())
|
||||
{
|
||||
for (int i = 0; i < front_space; i++) clog << " ";
|
||||
clog << "Options:" << endl;
|
||||
for (int i = 0; i < options.size(); i++)
|
||||
{
|
||||
if (options[i].flag_l == "")
|
||||
{
|
||||
full_message = options[i].flag_s+" : "+options[i].message;
|
||||
ss_message.clear(); ss_message.str(full_message);
|
||||
|
||||
line_length = front_space + back_space + 4;
|
||||
while(ss_message >> segment)
|
||||
{
|
||||
if ((line_length+segment.length()+1) <= w.ws_col)
|
||||
{
|
||||
if (line_length == (front_space+back_space+4))
|
||||
{
|
||||
for (int i = 0; i < front_space+4; i++) clog << " ";
|
||||
clog << segment << " ";
|
||||
line_length += (segment.length()+1);
|
||||
}
|
||||
else
|
||||
{
|
||||
clog << segment << " ";
|
||||
line_length += (segment.length()+1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
clog << endl;
|
||||
for (int i = 0; i < front_space+9; i++) clog << " ";
|
||||
clog << segment << " ";
|
||||
line_length = (segment.length()+10+front_space+back_space);
|
||||
}
|
||||
}
|
||||
clog << endl;
|
||||
|
||||
if (!options[i].sec_message.empty())
|
||||
{
|
||||
for (int j = 0; j < options[i].sec_message.size(); j++)
|
||||
{
|
||||
ss_message.clear(); ss_message.str(options[i].sec_message[j]);
|
||||
|
||||
line_length = front_space + back_space + 9;
|
||||
while(ss_message >> segment)
|
||||
{
|
||||
if ((line_length+segment.length()+1) <= w.ws_col)
|
||||
{
|
||||
if (line_length == (front_space+back_space+9))
|
||||
{
|
||||
for (int i = 0; i < front_space+9; i++) clog << " ";
|
||||
clog << segment << " ";
|
||||
line_length += (segment.length()+1);
|
||||
}
|
||||
else
|
||||
{
|
||||
clog << segment << " ";
|
||||
line_length += (segment.length()+1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
clog << endl;
|
||||
for (int i = 0; i < front_space+13; i++) clog << " ";
|
||||
clog << segment << " ";
|
||||
line_length = (segment.length()+14+front_space+back_space);
|
||||
}
|
||||
}
|
||||
clog << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
full_message = options[i].flag_s+" | "+options[i].flag_l+" : "+options[i].message;
|
||||
ss_message.clear(); ss_message.str(full_message);
|
||||
|
||||
line_length = front_space + back_space + 4;
|
||||
while(ss_message >> segment)
|
||||
{
|
||||
if ((line_length+segment.length()+1) <= w.ws_col)
|
||||
{
|
||||
if (line_length == (front_space+back_space+4))
|
||||
{
|
||||
for (int i = 0; i < front_space+4; i++) clog << " ";
|
||||
clog << segment << " ";
|
||||
line_length += (segment.length()+1);
|
||||
}
|
||||
else
|
||||
{
|
||||
clog << segment << " ";
|
||||
line_length += (segment.length()+1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
clog << endl;
|
||||
for (int i = 0; i < front_space+9; i++) clog << " ";
|
||||
clog << segment << " ";
|
||||
line_length = (segment.length()+10+front_space+back_space);
|
||||
}
|
||||
}
|
||||
clog << endl;
|
||||
|
||||
if (!options[i].sec_message.empty())
|
||||
{
|
||||
for (int j = 0; j < options[i].sec_message.size(); j++)
|
||||
{
|
||||
ss_message.clear(); ss_message.str(options[i].sec_message[j]);
|
||||
|
||||
line_length = front_space + back_space + 9;
|
||||
while(ss_message >> segment)
|
||||
{
|
||||
if ((line_length+segment.length()+1) <= w.ws_col)
|
||||
{
|
||||
if (line_length == (front_space+back_space+9))
|
||||
{
|
||||
for (int i = 0; i < front_space+9; i++) clog << " ";
|
||||
clog << segment << " ";
|
||||
line_length += (segment.length()+1);
|
||||
}
|
||||
else
|
||||
{
|
||||
clog << segment << " ";
|
||||
line_length += (segment.length()+1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
clog << endl;
|
||||
for (int i = 0; i < front_space+13; i++) clog << " ";
|
||||
clog << segment << " ";
|
||||
line_length = (segment.length()+14+front_space+back_space);
|
||||
}
|
||||
}
|
||||
clog << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!examples.empty())
|
||||
{
|
||||
for (int i = 0; i < front_space; i++) clog << " ";
|
||||
clog << "Examples:" << endl;
|
||||
for (int i = 0; i < examples.size(); i++)
|
||||
{
|
||||
ss_message.clear(); ss_message.str(examples[i]);
|
||||
|
||||
line_length = front_space + back_space + 4;
|
||||
while(ss_message >> segment)
|
||||
{
|
||||
if ((line_length+segment.length()+1) <= w.ws_col)
|
||||
{
|
||||
if (line_length == (front_space+back_space+4))
|
||||
{
|
||||
for (int i = 0; i < front_space+4; i++) clog << " ";
|
||||
clog << segment << " ";
|
||||
line_length += (segment.length()+1);
|
||||
}
|
||||
else
|
||||
{
|
||||
clog << segment << " ";
|
||||
line_length += (segment.length()+1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
clog << endl;
|
||||
for (int i = 0; i < front_space+9; i++) clog << " ";
|
||||
clog << segment << " ";
|
||||
line_length = (segment.length()+10+front_space+back_space);
|
||||
}
|
||||
}
|
||||
clog << endl;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
318
archive/grav2d_cube/grav2d_cube.h
Normal file
318
archive/grav2d_cube/grav2d_cube.h
Normal file
@@ -0,0 +1,318 @@
|
||||
#include "includes.h"
|
||||
|
||||
class grav2d_cube
|
||||
{
|
||||
public:
|
||||
grav2d_cube(){}
|
||||
~grav2d_cube(){}
|
||||
int routine(char*,char*,char*);
|
||||
int initCubes(char*);
|
||||
int initObs(char*);
|
||||
void outObs();
|
||||
void calG();
|
||||
void calGx();
|
||||
void calGy();
|
||||
void calGz();
|
||||
private:
|
||||
int obsNum, cubeNum;
|
||||
cubeArray modCube;
|
||||
obspointArray obsPoint;
|
||||
};
|
||||
|
||||
int grav2d_cube::routine(char* calType,char* obsPara,char* modPara)
|
||||
{
|
||||
if (initCubes(modPara)) return -1;
|
||||
if (initObs(obsPara)) return -1;
|
||||
if (!strcmp(calType,"gravity")) calG();
|
||||
else if (!strcmp(calType,"gx")) calGx();
|
||||
else if (!strcmp(calType,"gy")) calGy();
|
||||
else if (!strcmp(calType,"gz")) calGz();
|
||||
else
|
||||
{
|
||||
cerr << BOLDRED << "error ==> " << RESET << "unknown calculation type: " << calType << endl;
|
||||
return -1;
|
||||
}
|
||||
outObs();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int grav2d_cube::initCubes(char* para)
|
||||
{
|
||||
cube temp_cube;
|
||||
string temp_str;
|
||||
stringstream temp_ss;
|
||||
|
||||
if (7 == sscanf(para,"%lf/%lf/%lf/%lf/%lf/%lf/%lf",
|
||||
&temp_cube.cen.x,&temp_cube.cen.y,&temp_cube.cen.z,&temp_cube.dx,&temp_cube.dy,&temp_cube.dz,&temp_cube.rho))
|
||||
{
|
||||
modCube.push_back(temp_cube);
|
||||
}
|
||||
else
|
||||
{
|
||||
ifstream infile;
|
||||
if (open_infile(infile,para)) return -1;
|
||||
|
||||
while(getline(infile,temp_str))
|
||||
{
|
||||
if (*(temp_str.begin()) == '#') continue;
|
||||
else
|
||||
{
|
||||
//按每行7个数据解析 初始化为用于正演的观测点
|
||||
if (7 == sscanf(temp_str.c_str(),"%lf/%lf/%lf/%lf/%lf/%lf/%lf",
|
||||
&temp_cube.cen.x,&temp_cube.cen.y,&temp_cube.cen.z,&temp_cube.dx,&temp_cube.dy,&temp_cube.dz,&temp_cube.rho))
|
||||
modCube.push_back(temp_cube);
|
||||
else
|
||||
{
|
||||
cerr << BOLDYELLOW << "ignored ==> " << RESET << "wrong input: " << temp_str << endl;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
infile.close();
|
||||
}
|
||||
|
||||
if (modCube.empty())
|
||||
{
|
||||
cerr << BOLDRED << "error ==> " << RESET << "fail to initial cubes with the parameter: " << para << endl;
|
||||
return -1;
|
||||
}
|
||||
else cubeNum = modCube.size();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int grav2d_cube::initObs(char* para)
|
||||
{
|
||||
obspoint temp_obs;
|
||||
string temp_str;
|
||||
stringstream temp_ss;
|
||||
double x,y;
|
||||
double xmin,xmax,ymin,ymax;
|
||||
double xs,xe,ys,ye,eleva,dx,dy;
|
||||
|
||||
//按格式解析参数 初始化观测位置 用于正演计算
|
||||
if (7 == sscanf(para,"%lf/%lf/%lf/%lf/%lf/%lf/%lf",&xs,&dx,&xe,&ys,&dy,&ye,&eleva))
|
||||
{
|
||||
xmin = MIN(xs,xe); xmax = MAX(xs,xe);
|
||||
ymin = MIN(ys,ye); ymax = MAX(ys,ye);
|
||||
|
||||
y = ys;
|
||||
while(y >= ymin && y <= ymax)
|
||||
{
|
||||
x = xs;
|
||||
while(x >= xmin && x <= xmax)
|
||||
{
|
||||
temp_obs.id = obsPoint.size();
|
||||
temp_obs.x = x; temp_obs.y = y; temp_obs.z = -1.0*eleva;
|
||||
temp_obs.val = 0.0;
|
||||
obsPoint.push_back(temp_obs);
|
||||
x += dx;
|
||||
}
|
||||
y += dy;
|
||||
}
|
||||
}
|
||||
//解析失败 按文件读入 用于反演使用或者正演计算
|
||||
else
|
||||
{
|
||||
ifstream infile;
|
||||
if (open_infile(infile,para)) return -1;
|
||||
|
||||
while(getline(infile,temp_str))
|
||||
{
|
||||
if (*(temp_str.begin()) == '#') continue;
|
||||
else
|
||||
{
|
||||
//按每行3个数据解析 初始化为用于正演的观测点
|
||||
if (3 == sscanf(temp_str.c_str(),"%lf %lf %lf",&temp_obs.x,&temp_obs.y,&temp_obs.z))
|
||||
{
|
||||
temp_obs.z *= -1.0;
|
||||
temp_obs.val = 0.0;
|
||||
temp_obs.id = obsPoint.size();
|
||||
obsPoint.push_back(temp_obs);
|
||||
}
|
||||
else
|
||||
{
|
||||
cerr << BOLDYELLOW << "ignored ==> " << RESET << "wrong input: " << temp_str << endl;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
infile.close();
|
||||
}
|
||||
|
||||
if (obsPoint.empty())
|
||||
{
|
||||
cerr << BOLDRED << "error ==> " << RESET << "fail to initial observations with the parameter: " << para << endl;
|
||||
return -1;
|
||||
}
|
||||
else obsNum = obsPoint.size();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void grav2d_cube::outObs()
|
||||
{
|
||||
cout << "# This file is generated by grav2d-cube. Use -h to see options" << endl;
|
||||
cout << "# x(m) y(m) ele(m) obs-val(mGal)" << endl;
|
||||
for (int i = 0; i < obsNum; i++)
|
||||
cout << obsPoint[i].x << " " << obsPoint[i].y << " " << -1.0*obsPoint[i].z << " " << setprecision(16) << obsPoint[i].val << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
void grav2d_cube::calG()
|
||||
{
|
||||
int i,j;
|
||||
double x1,x2,y1,y2,z1,z2;
|
||||
double R222,R122,R212,R112,R221,R121,R211,R111;
|
||||
double G222,G122,G212,G112,G221,G121,G211,G111;
|
||||
|
||||
for (j = 0; j < cubeNum; j++)
|
||||
{
|
||||
x1 = modCube[j].cen.x - 0.5*modCube[j].dx; x2 = modCube[j].cen.x + 0.5*modCube[j].dx;
|
||||
y1 = modCube[j].cen.y - 0.5*modCube[j].dy; y2 = modCube[j].cen.y + 0.5*modCube[j].dy;
|
||||
z1 = modCube[j].cen.z - 0.5*modCube[j].dz; z2 = modCube[j].cen.z + 0.5*modCube[j].dz;
|
||||
|
||||
#pragma omp parallel for private(i,R222,R122,R212,R112,R221,R121,R211,R111,G222,G122,G212,G112,G221,G121,G211,G111) shared(x1,x2,y1,y2,z1,z2) schedule(guided)
|
||||
for (i = 0; i < obsNum; i++)
|
||||
{
|
||||
R222=sqrt((x2-obsPoint[i].x)*(x2-obsPoint[i].x)+(y2-obsPoint[i].y)*(y2-obsPoint[i].y)+(z2-obsPoint[i].z)*(z2-obsPoint[i].z));
|
||||
R122=sqrt((x1-obsPoint[i].x)*(x1-obsPoint[i].x)+(y2-obsPoint[i].y)*(y2-obsPoint[i].y)+(z2-obsPoint[i].z)*(z2-obsPoint[i].z));
|
||||
R212=sqrt((x2-obsPoint[i].x)*(x2-obsPoint[i].x)+(y1-obsPoint[i].y)*(y1-obsPoint[i].y)+(z2-obsPoint[i].z)*(z2-obsPoint[i].z));
|
||||
R112=sqrt((x1-obsPoint[i].x)*(x1-obsPoint[i].x)+(y1-obsPoint[i].y)*(y1-obsPoint[i].y)+(z2-obsPoint[i].z)*(z2-obsPoint[i].z));
|
||||
R221=sqrt((x2-obsPoint[i].x)*(x2-obsPoint[i].x)+(y2-obsPoint[i].y)*(y2-obsPoint[i].y)+(z1-obsPoint[i].z)*(z1-obsPoint[i].z));
|
||||
R121=sqrt((x1-obsPoint[i].x)*(x1-obsPoint[i].x)+(y2-obsPoint[i].y)*(y2-obsPoint[i].y)+(z1-obsPoint[i].z)*(z1-obsPoint[i].z));
|
||||
R211=sqrt((x2-obsPoint[i].x)*(x2-obsPoint[i].x)+(y1-obsPoint[i].y)*(y1-obsPoint[i].y)+(z1-obsPoint[i].z)*(z1-obsPoint[i].z));
|
||||
R111=sqrt((x1-obsPoint[i].x)*(x1-obsPoint[i].x)+(y1-obsPoint[i].y)*(y1-obsPoint[i].y)+(z1-obsPoint[i].z)*(z1-obsPoint[i].z));
|
||||
|
||||
G222=(x2-obsPoint[i].x)*log((y2-obsPoint[i].y)+R222)+(y2-obsPoint[i].y)*log((x2-obsPoint[i].x)+R222)+(z2-obsPoint[i].z)*arctg((z2-obsPoint[i].z)*R222/(x2-obsPoint[i].x)/(y2-obsPoint[i].y));
|
||||
G122=(x1-obsPoint[i].x)*log((y2-obsPoint[i].y)+R122)+(y2-obsPoint[i].y)*log((x1-obsPoint[i].x)+R122)+(z2-obsPoint[i].z)*arctg((z2-obsPoint[i].z)*R122/(x1-obsPoint[i].x)/(y2-obsPoint[i].y));
|
||||
G212=(x2-obsPoint[i].x)*log((y1-obsPoint[i].y)+R212)+(y1-obsPoint[i].y)*log((x2-obsPoint[i].x)+R212)+(z2-obsPoint[i].z)*arctg((z2-obsPoint[i].z)*R212/(x2-obsPoint[i].x)/(y1-obsPoint[i].y));
|
||||
G112=(x1-obsPoint[i].x)*log((y1-obsPoint[i].y)+R112)+(y1-obsPoint[i].y)*log((x1-obsPoint[i].x)+R112)+(z2-obsPoint[i].z)*arctg((z2-obsPoint[i].z)*R112/(x1-obsPoint[i].x)/(y1-obsPoint[i].y));
|
||||
G221=(x2-obsPoint[i].x)*log((y2-obsPoint[i].y)+R221)+(y2-obsPoint[i].y)*log((x2-obsPoint[i].x)+R221)+(z1-obsPoint[i].z)*arctg((z1-obsPoint[i].z)*R221/(x2-obsPoint[i].x)/(y2-obsPoint[i].y));
|
||||
G121=(x1-obsPoint[i].x)*log((y2-obsPoint[i].y)+R121)+(y2-obsPoint[i].y)*log((x1-obsPoint[i].x)+R121)+(z1-obsPoint[i].z)*arctg((z1-obsPoint[i].z)*R121/(x1-obsPoint[i].x)/(y2-obsPoint[i].y));
|
||||
G211=(x2-obsPoint[i].x)*log((y1-obsPoint[i].y)+R211)+(y1-obsPoint[i].y)*log((x2-obsPoint[i].x)+R211)+(z1-obsPoint[i].z)*arctg((z1-obsPoint[i].z)*R211/(x2-obsPoint[i].x)/(y1-obsPoint[i].y));
|
||||
G111=(x1-obsPoint[i].x)*log((y1-obsPoint[i].y)+R111)+(y1-obsPoint[i].y)*log((x1-obsPoint[i].x)+R111)+(z1-obsPoint[i].z)*arctg((z1-obsPoint[i].z)*R111/(x1-obsPoint[i].x)/(y1-obsPoint[i].y));
|
||||
|
||||
obsPoint[i].val += -1.0*G0*(G222-G122-G212+G112-G221+G121+G211-G111)*modCube[j].rho;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void grav2d_cube::calGx()
|
||||
{
|
||||
int i,j;
|
||||
double x1,x2,y1,y2,z1,z2;
|
||||
double R222,R122,R212,R112,R221,R121,R211,R111;
|
||||
double G222,G122,G212,G112,G221,G121,G211,G111;
|
||||
|
||||
for (j = 0; j < cubeNum; j++)
|
||||
{
|
||||
x1 = modCube[j].cen.x - 0.5*modCube[j].dx; x2 = modCube[j].cen.x + 0.5*modCube[j].dx;
|
||||
y1 = modCube[j].cen.y - 0.5*modCube[j].dy; y2 = modCube[j].cen.y + 0.5*modCube[j].dy;
|
||||
z1 = modCube[j].cen.z - 0.5*modCube[j].dz; z2 = modCube[j].cen.z + 0.5*modCube[j].dz;
|
||||
|
||||
#pragma omp parallel for private(i,R222,R122,R212,R112,R221,R121,R211,R111,G222,G122,G212,G112,G221,G121,G211,G111) shared(x1,x2,y1,y2,z1,z2) schedule(guided)
|
||||
for (i = 0; i < obsNum; i++)
|
||||
{
|
||||
R222=sqrt((x2-obsPoint[i].x)*(x2-obsPoint[i].x)+(y2-obsPoint[i].y)*(y2-obsPoint[i].y)+(z2-obsPoint[i].z)*(z2-obsPoint[i].z));
|
||||
R122=sqrt((x1-obsPoint[i].x)*(x1-obsPoint[i].x)+(y2-obsPoint[i].y)*(y2-obsPoint[i].y)+(z2-obsPoint[i].z)*(z2-obsPoint[i].z));
|
||||
R212=sqrt((x2-obsPoint[i].x)*(x2-obsPoint[i].x)+(y1-obsPoint[i].y)*(y1-obsPoint[i].y)+(z2-obsPoint[i].z)*(z2-obsPoint[i].z));
|
||||
R112=sqrt((x1-obsPoint[i].x)*(x1-obsPoint[i].x)+(y1-obsPoint[i].y)*(y1-obsPoint[i].y)+(z2-obsPoint[i].z)*(z2-obsPoint[i].z));
|
||||
R221=sqrt((x2-obsPoint[i].x)*(x2-obsPoint[i].x)+(y2-obsPoint[i].y)*(y2-obsPoint[i].y)+(z1-obsPoint[i].z)*(z1-obsPoint[i].z));
|
||||
R121=sqrt((x1-obsPoint[i].x)*(x1-obsPoint[i].x)+(y2-obsPoint[i].y)*(y2-obsPoint[i].y)+(z1-obsPoint[i].z)*(z1-obsPoint[i].z));
|
||||
R211=sqrt((x2-obsPoint[i].x)*(x2-obsPoint[i].x)+(y1-obsPoint[i].y)*(y1-obsPoint[i].y)+(z1-obsPoint[i].z)*(z1-obsPoint[i].z));
|
||||
R111=sqrt((x1-obsPoint[i].x)*(x1-obsPoint[i].x)+(y1-obsPoint[i].y)*(y1-obsPoint[i].y)+(z1-obsPoint[i].z)*(z1-obsPoint[i].z));
|
||||
|
||||
G222=log((x2-obsPoint[i].x)+R222);
|
||||
G122=log((x1-obsPoint[i].x)+R122);
|
||||
G212=log((x2-obsPoint[i].x)+R212);
|
||||
G112=log((x1-obsPoint[i].x)+R112);
|
||||
G221=log((x2-obsPoint[i].x)+R221);
|
||||
G121=log((x1-obsPoint[i].x)+R121);
|
||||
G211=log((x2-obsPoint[i].x)+R211);
|
||||
G111=log((x1-obsPoint[i].x)+R111);
|
||||
|
||||
obsPoint[i].val += 1.0e+4*G0*(G222-G122-G212+G112-G221+G121+G211-G111)*modCube[j].rho;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void grav2d_cube::calGy()
|
||||
{
|
||||
int i,j;
|
||||
double x1,x2,y1,y2,z1,z2;
|
||||
double R222,R122,R212,R112,R221,R121,R211,R111;
|
||||
double G222,G122,G212,G112,G221,G121,G211,G111;
|
||||
|
||||
for (j = 0; j < cubeNum; j++)
|
||||
{
|
||||
x1 = modCube[j].cen.x - 0.5*modCube[j].dx; x2 = modCube[j].cen.x + 0.5*modCube[j].dx;
|
||||
y1 = modCube[j].cen.y - 0.5*modCube[j].dy; y2 = modCube[j].cen.y + 0.5*modCube[j].dy;
|
||||
z1 = modCube[j].cen.z - 0.5*modCube[j].dz; z2 = modCube[j].cen.z + 0.5*modCube[j].dz;
|
||||
|
||||
#pragma omp parallel for private(i,R222,R122,R212,R112,R221,R121,R211,R111,G222,G122,G212,G112,G221,G121,G211,G111) shared(x1,x2,y1,y2,z1,z2) schedule(guided)
|
||||
for (i = 0; i < obsNum; i++)
|
||||
{
|
||||
R222=sqrt((x2-obsPoint[i].x)*(x2-obsPoint[i].x)+(y2-obsPoint[i].y)*(y2-obsPoint[i].y)+(z2-obsPoint[i].z)*(z2-obsPoint[i].z));
|
||||
R122=sqrt((x1-obsPoint[i].x)*(x1-obsPoint[i].x)+(y2-obsPoint[i].y)*(y2-obsPoint[i].y)+(z2-obsPoint[i].z)*(z2-obsPoint[i].z));
|
||||
R212=sqrt((x2-obsPoint[i].x)*(x2-obsPoint[i].x)+(y1-obsPoint[i].y)*(y1-obsPoint[i].y)+(z2-obsPoint[i].z)*(z2-obsPoint[i].z));
|
||||
R112=sqrt((x1-obsPoint[i].x)*(x1-obsPoint[i].x)+(y1-obsPoint[i].y)*(y1-obsPoint[i].y)+(z2-obsPoint[i].z)*(z2-obsPoint[i].z));
|
||||
R221=sqrt((x2-obsPoint[i].x)*(x2-obsPoint[i].x)+(y2-obsPoint[i].y)*(y2-obsPoint[i].y)+(z1-obsPoint[i].z)*(z1-obsPoint[i].z));
|
||||
R121=sqrt((x1-obsPoint[i].x)*(x1-obsPoint[i].x)+(y2-obsPoint[i].y)*(y2-obsPoint[i].y)+(z1-obsPoint[i].z)*(z1-obsPoint[i].z));
|
||||
R211=sqrt((x2-obsPoint[i].x)*(x2-obsPoint[i].x)+(y1-obsPoint[i].y)*(y1-obsPoint[i].y)+(z1-obsPoint[i].z)*(z1-obsPoint[i].z));
|
||||
R111=sqrt((x1-obsPoint[i].x)*(x1-obsPoint[i].x)+(y1-obsPoint[i].y)*(y1-obsPoint[i].y)+(z1-obsPoint[i].z)*(z1-obsPoint[i].z));
|
||||
|
||||
G222=log((y2-obsPoint[i].y)+R222);
|
||||
G122=log((y2-obsPoint[i].y)+R122);
|
||||
G212=log((y1-obsPoint[i].y)+R212);
|
||||
G112=log((y1-obsPoint[i].y)+R112);
|
||||
G221=log((y2-obsPoint[i].y)+R221);
|
||||
G121=log((y2-obsPoint[i].y)+R121);
|
||||
G211=log((y1-obsPoint[i].y)+R211);
|
||||
G111=log((y1-obsPoint[i].y)+R111);
|
||||
|
||||
obsPoint[i].val += 1.0e+4*G0*(G222-G122-G212+G112-G221+G121+G211-G111)*modCube[j].rho;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void grav2d_cube::calGz()
|
||||
{
|
||||
int i,j;
|
||||
double x1,x2,y1,y2,z1,z2;
|
||||
double R222,R122,R212,R112,R221,R121,R211,R111;
|
||||
double G222,G122,G212,G112,G221,G121,G211,G111;
|
||||
|
||||
for (j = 0; j < cubeNum; j++)
|
||||
{
|
||||
x1 = modCube[j].cen.x - 0.5*modCube[j].dx; x2 = modCube[j].cen.x + 0.5*modCube[j].dx;
|
||||
y1 = modCube[j].cen.y - 0.5*modCube[j].dy; y2 = modCube[j].cen.y + 0.5*modCube[j].dy;
|
||||
z1 = modCube[j].cen.z - 0.5*modCube[j].dz; z2 = modCube[j].cen.z + 0.5*modCube[j].dz;
|
||||
|
||||
#pragma omp parallel for private(i,R222,R122,R212,R112,R221,R121,R211,R111,G222,G122,G212,G112,G221,G121,G211,G111) shared(x1,x2,y1,y2,z1,z2) schedule(guided)
|
||||
for (i = 0; i < obsNum; i++)
|
||||
{
|
||||
R222=sqrt((x2-obsPoint[i].x)*(x2-obsPoint[i].x)+(y2-obsPoint[i].y)*(y2-obsPoint[i].y)+(z2-obsPoint[i].z)*(z2-obsPoint[i].z));
|
||||
R122=sqrt((x1-obsPoint[i].x)*(x1-obsPoint[i].x)+(y2-obsPoint[i].y)*(y2-obsPoint[i].y)+(z2-obsPoint[i].z)*(z2-obsPoint[i].z));
|
||||
R212=sqrt((x2-obsPoint[i].x)*(x2-obsPoint[i].x)+(y1-obsPoint[i].y)*(y1-obsPoint[i].y)+(z2-obsPoint[i].z)*(z2-obsPoint[i].z));
|
||||
R112=sqrt((x1-obsPoint[i].x)*(x1-obsPoint[i].x)+(y1-obsPoint[i].y)*(y1-obsPoint[i].y)+(z2-obsPoint[i].z)*(z2-obsPoint[i].z));
|
||||
R221=sqrt((x2-obsPoint[i].x)*(x2-obsPoint[i].x)+(y2-obsPoint[i].y)*(y2-obsPoint[i].y)+(z1-obsPoint[i].z)*(z1-obsPoint[i].z));
|
||||
R121=sqrt((x1-obsPoint[i].x)*(x1-obsPoint[i].x)+(y2-obsPoint[i].y)*(y2-obsPoint[i].y)+(z1-obsPoint[i].z)*(z1-obsPoint[i].z));
|
||||
R211=sqrt((x2-obsPoint[i].x)*(x2-obsPoint[i].x)+(y1-obsPoint[i].y)*(y1-obsPoint[i].y)+(z1-obsPoint[i].z)*(z1-obsPoint[i].z));
|
||||
R111=sqrt((x1-obsPoint[i].x)*(x1-obsPoint[i].x)+(y1-obsPoint[i].y)*(y1-obsPoint[i].y)+(z1-obsPoint[i].z)*(z1-obsPoint[i].z));
|
||||
|
||||
G222=atan((x2-obsPoint[i].x)*(y2-obsPoint[i].y)/(R222*(z2-obsPoint[i].z)));
|
||||
G122=atan((x1-obsPoint[i].x)*(y2-obsPoint[i].y)/(R122*(z2-obsPoint[i].z)));
|
||||
G212=atan((x2-obsPoint[i].x)*(y1-obsPoint[i].y)/(R212*(z2-obsPoint[i].z)));
|
||||
G112=atan((x1-obsPoint[i].x)*(y1-obsPoint[i].y)/(R112*(z2-obsPoint[i].z)));
|
||||
G221=atan((x2-obsPoint[i].x)*(y2-obsPoint[i].y)/(R221*(z1-obsPoint[i].z)));
|
||||
G121=atan((x1-obsPoint[i].x)*(y2-obsPoint[i].y)/(R121*(z1-obsPoint[i].z)));
|
||||
G211=atan((x2-obsPoint[i].x)*(y1-obsPoint[i].y)/(R211*(z1-obsPoint[i].z)));
|
||||
G111=atan((x1-obsPoint[i].x)*(y1-obsPoint[i].y)/(R111*(z1-obsPoint[i].z)));
|
||||
|
||||
obsPoint[i].val += -1.0e+4*G0*(G222-G122-G212+G112-G221+G121+G211-G111)*modCube[j].rho;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
108
archive/grav2d_cube/includes.h
Normal file
108
archive/grav2d_cube/includes.h
Normal file
@@ -0,0 +1,108 @@
|
||||
#ifndef _INCLUDES_H
|
||||
#define _INCLUDES_H
|
||||
#include "iostream"
|
||||
#include "fstream"
|
||||
#include "sstream"
|
||||
#include "string.h"
|
||||
#include "cmath"
|
||||
#include "iomanip"
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
#include "unistd.h"
|
||||
#include "vector"
|
||||
#include "map"
|
||||
#include "algorithm"
|
||||
#include "ctime"
|
||||
#include "omp.h"
|
||||
#include "random"
|
||||
|
||||
using namespace std;
|
||||
|
||||
//数学常量
|
||||
#define BDL_MAX 1e+30
|
||||
#define BDL_MIN -1e+30
|
||||
#define ZERO 1e-20
|
||||
//物理常量
|
||||
#define Pi (4.0*atan(1.0))
|
||||
#define G0 6.67408e-3 //注意这里本来应该是e-11,考虑到单位转换,取维度单位为m,密度单位为g/cm^3,乘以G0则重力单位即为mGal
|
||||
//宏函数
|
||||
#define MAX(a,b) (a>b?a:b)
|
||||
#define MIN(a,b) (a<b?a:b)
|
||||
#define SetToBox(a,b,in) (MAX(a,MIN(b,in))) //如果in在a和b之间返回in 否则返回边界值
|
||||
//终端显示控制符
|
||||
#define BOLDRED "\033[1m\033[31m"
|
||||
#define BOLDGREEN "\033[1m\033[32m"
|
||||
#define BOLDYELLOW "\033[1m\033[33m"
|
||||
#define BOLDBLUE "\033[1m\033[34m"
|
||||
#define UNDERLINE "\033[1m\033[4m"
|
||||
#define RESET "\033[0m"
|
||||
#define MOVEUP(x) printf("\033[%dA", (x))
|
||||
#define MOVEDOWN(x) printf("\033[%dB", (x))
|
||||
#define MOVELEFT(x) printf("\033[%dD", (x))
|
||||
#define MOVERIGHT(x) printf("\033[%dC", (x))
|
||||
#define MOVETO(y,x) printf("\033[%d;%dH", (y), (x))
|
||||
#define CLEARLINE "\033[K"
|
||||
#define CLEARALL "\033[2J"
|
||||
//数据结构
|
||||
typedef vector<int> _1iArray;
|
||||
typedef vector<double> _1dArray;
|
||||
typedef vector<string> _1sArray;
|
||||
typedef vector<vector<int> > _2iArray;
|
||||
typedef vector<vector<double> > _2dArray;
|
||||
typedef map<int,int> _i2iMap;
|
||||
|
||||
struct cpoint
|
||||
{
|
||||
int id = -1;
|
||||
double x = BDL_MAX; double y = BDL_MAX; double z = BDL_MAX;
|
||||
};
|
||||
typedef vector<cpoint> cpointArray;
|
||||
|
||||
struct obspoint : public cpoint
|
||||
{
|
||||
double val = BDL_MAX; double dev = BDL_MAX;
|
||||
};
|
||||
typedef vector<obspoint> obspointArray;
|
||||
|
||||
struct cube
|
||||
{
|
||||
cpoint cen;
|
||||
double rho = 0.0;
|
||||
double dx = BDL_MAX; double dy = BDL_MAX; double dz = BDL_MAX;
|
||||
};
|
||||
typedef vector<cube> cubeArray;
|
||||
|
||||
/*************************全局函数********************************/
|
||||
//正负分离的atan函数 正数返回atan 负数返回atan+pi
|
||||
double arctg(double v)
|
||||
{
|
||||
double ang;
|
||||
if(v>=0) ang=atan(v);
|
||||
else if(v<0) ang=atan(v)+Pi;
|
||||
return ang;
|
||||
}
|
||||
//将string转换为stringstream
|
||||
stringstream str2ss(string s){
|
||||
stringstream sstr;
|
||||
sstr.str(""); sstr.clear(); sstr.str(s);
|
||||
return sstr;
|
||||
}
|
||||
//测试打开输入文件 如果成功则返回0并输出信息 否则返回1
|
||||
int open_infile(ifstream &infile,char* filename){
|
||||
infile.open(filename);
|
||||
if (!infile){
|
||||
cerr << BOLDRED << "error ==> " << RESET << "file not found: " << filename << endl;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
//测试打开输出文件 如果成功则返回0并输出信息 否则返回1
|
||||
int open_outfile(ofstream &outfile,char* filename){
|
||||
outfile.open(filename);
|
||||
if (!outfile){
|
||||
cerr << BOLDRED << "error ==> " << RESET << "fail to create the file: " << filename << endl;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
82
archive/grav2d_cube/main.cpp
Normal file
82
archive/grav2d_cube/main.cpp
Normal file
@@ -0,0 +1,82 @@
|
||||
#include "grav2d_cube.h"
|
||||
#include "dispHelp.h"
|
||||
|
||||
void disp_help(char* proname)
|
||||
{
|
||||
string exName = proname;
|
||||
string exUsage = proname;
|
||||
exUsage += " -r<x-start>/<x-step>/<x-end>/<y-start>/<y-step>/<y-end>/<elevation>|<filename> \
|
||||
-c<x-cen>/<y-cen>/<z-cen>/<dx>/<dy>/<dz>/<density>|<filename> -tgravity|gx|gy|gz > out-file";
|
||||
dispHelp dh;
|
||||
dh.changeLayerOut(0,10);
|
||||
dh.addHeadInfo(exName,"0.1","Forward calculation of gravitational data of cubes.","Yi Zhang (zhangyi.cugwuhan@gmail.com)");
|
||||
dh.addUsage(exUsage);
|
||||
dh.addOption("Range of calculation, which could get from parameters or a file contains x y z locations. Defaults are 0/10/1000/0/10/1000/0","-r");
|
||||
dh.addOption("Cube parameters, which could get from parameters (single) or a file (multiple). Defaults are 500/500/200/100/100/100/1.0","-c");
|
||||
dh.addOption("Calculation type equals gravity (default), gx, gy or gz.","-t");
|
||||
dh.show();
|
||||
return;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
grav2d_cube gc;
|
||||
char rangeChar[1024] = "0/10/1000/0/10/1000/0";
|
||||
char cubeChar[1024] = "500/500/200/100/100/100/1.0";
|
||||
char typeChar[1024] = "gravity";
|
||||
|
||||
opterr = 0; //内置参数 若不为0则会在发生遭遇错误时输出一条信息到屏幕
|
||||
|
||||
int curr;
|
||||
/*循环拾取参数 最后一个参数为-1 需要变量的参数后跟一个冒号 可有可无参数跟两个冒号*/
|
||||
while((curr = getopt(argc,argv,"hr:c:t:")) != -1)
|
||||
{
|
||||
/*匹配命令*/
|
||||
switch (curr)
|
||||
{
|
||||
case 'h': //显示帮助信息
|
||||
disp_help(argv[0]);
|
||||
return 0;
|
||||
case 'r':
|
||||
if (1!=sscanf(optarg,"%s",rangeChar))
|
||||
{
|
||||
cout << "error ==> wrong format of " << optarg << endl;
|
||||
}
|
||||
break;
|
||||
case 'c':
|
||||
if (1!=sscanf(optarg,"%s",cubeChar))
|
||||
{
|
||||
cout << "error ==> wrong format of " << optarg << endl;
|
||||
}
|
||||
break;
|
||||
case 't':
|
||||
if (1!=sscanf(optarg,"%s",typeChar))
|
||||
{
|
||||
cout << "error ==> wrong format of " << optarg << endl;
|
||||
}
|
||||
break;
|
||||
case '?': //处理未定义或错误参数
|
||||
if (optopt == 'r' || optopt == 'c' || optopt == 't')
|
||||
{
|
||||
fprintf (stderr, "Option -%c requires an argument.\n", optopt);
|
||||
return -1;
|
||||
}
|
||||
else if (isprint(optopt))
|
||||
{
|
||||
fprintf (stderr, "Unknown option `-%c'.\n", optopt);
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf (stderr,"Unknown option character `\\x%x'.\n",optopt);
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
gc.routine(typeChar,rangeChar,cubeChar);
|
||||
return 0;
|
||||
}
|
||||
15
archive/grav2d_cube/makefile
Normal file
15
archive/grav2d_cube/makefile
Normal file
@@ -0,0 +1,15 @@
|
||||
CC = g++-9
|
||||
PROM = /usr/local/sbin/grav2d-cube
|
||||
CFLAGS = -I.
|
||||
DEPS = $(shell find . -name "*.h")
|
||||
SRC = $(shell find . -name "*.cpp")
|
||||
OBJ = $(SRC:%.cpp=%.o)
|
||||
|
||||
$(PROM): $(OBJ)
|
||||
$(CC) -o $(PROM) $(OBJ) $(CFLAGS) -O2
|
||||
|
||||
%.o:%.cpp $(DEPS)
|
||||
$(CC) -c $< -o $@ $(CFLAGS) -O2
|
||||
|
||||
clean:
|
||||
rm -rf $(OBJ)
|
||||
59
archive/grav2d_regular/datafunc.h
Normal file
59
archive/grav2d_regular/datafunc.h
Normal file
@@ -0,0 +1,59 @@
|
||||
#ifndef _DATAFUNC_H
|
||||
#define _DATAFUNC_H
|
||||
#include "iostream"
|
||||
#include "fstream"
|
||||
#include "string.h"
|
||||
#include "iomanip"
|
||||
#include "cmath"
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
#include "list"
|
||||
|
||||
#define G0 6.67259e-03
|
||||
#define pi (4.0*atan(1.0))
|
||||
#define MAX 1e+30
|
||||
|
||||
#define GRAV "-g"
|
||||
#define GRADX "-x"
|
||||
#define GRADY "-y"
|
||||
#define GRADZ "-z"
|
||||
#define RANGE "-r"
|
||||
#define INTERVAL "-i"
|
||||
#define PARAFILE "-f"
|
||||
#define SPHERE "-s"
|
||||
#define CUBE "-c"
|
||||
#define OUTPUT "-o"
|
||||
#define BOLDRED "\033[1m\033[31m"
|
||||
#define RESET "\033[0m"
|
||||
|
||||
using namespace std;
|
||||
|
||||
double arctg(double v)
|
||||
{
|
||||
double ang;
|
||||
if(v>=0)
|
||||
{
|
||||
ang=atan(v);
|
||||
}
|
||||
else if(v<0)
|
||||
{
|
||||
ang=atan(v)+pi;
|
||||
}
|
||||
return ang;
|
||||
}
|
||||
|
||||
struct sphere
|
||||
{
|
||||
double x,y,z,r;
|
||||
double density;
|
||||
};
|
||||
typedef list<sphere> SphereList;
|
||||
|
||||
struct cube
|
||||
{
|
||||
double x1,x2,y1,y2,z1,z2;
|
||||
double density;
|
||||
};
|
||||
typedef list<cube> CubeList;
|
||||
|
||||
#endif
|
||||
260
archive/grav2d_regular/forward.h
Normal file
260
archive/grav2d_regular/forward.h
Normal file
@@ -0,0 +1,260 @@
|
||||
#include "datafunc.h"
|
||||
|
||||
class FD
|
||||
{
|
||||
public:
|
||||
FD();
|
||||
~FD();
|
||||
int init_res(double*,double*);
|
||||
int out_res(char*);
|
||||
void forward_sphere(sphere,int);
|
||||
void forward_cube(cube,int);
|
||||
private:
|
||||
double xmin,xmax,ymin,ymax,dx,dy;
|
||||
int M,N;
|
||||
double height;
|
||||
|
||||
double** res;
|
||||
};
|
||||
|
||||
FD::FD()
|
||||
{
|
||||
res = NULL;
|
||||
}
|
||||
|
||||
FD::~FD()
|
||||
{
|
||||
if(res!=NULL)
|
||||
{
|
||||
for (int i = 0; i < M; i++)
|
||||
delete[] res[i];
|
||||
delete[] res;
|
||||
}
|
||||
}
|
||||
|
||||
int FD::init_res(double* range,double* interval)
|
||||
{
|
||||
xmin = *range; xmax = *(range+1); ymin = *(range+2); ymax = *(range+3); height = *(range+4);
|
||||
height *= -1.0;
|
||||
dx = *interval; dy = *(interval+1);
|
||||
|
||||
M = int (xmax - xmin)/dx + 1;
|
||||
N = int (ymax - ymin)/dy + 1;
|
||||
|
||||
xmax = xmin + (M-1)*dx;
|
||||
ymax = ymin + (N-1)*dy;
|
||||
|
||||
res = new double* [M];
|
||||
for (int i=0;i<M;i++)
|
||||
res[i] = new double [N];
|
||||
|
||||
for (int i=0;i<M;i++)
|
||||
for (int j=0;j<N;j++)
|
||||
res[i][j] = 0.0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int FD::out_res(char* outname)
|
||||
{
|
||||
ofstream outfile(outname);
|
||||
if(!outfile)
|
||||
{
|
||||
cout<<"can not create file: "<<outname<<endl;
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < M; i++)
|
||||
{
|
||||
for (int j = 0; j < N; j++)
|
||||
{
|
||||
outfile<<xmin+dx*i<<" "<<ymin+dy*j<<" "<<-1.0*height<<" "<<setprecision(16)<<res[i][j]<<endl;
|
||||
}
|
||||
}
|
||||
outfile.close();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void FD::forward_sphere(sphere s1,int caltype)
|
||||
{
|
||||
switch(caltype)
|
||||
{
|
||||
case 1: //g
|
||||
{
|
||||
for (int i = 0; i < M; i++)
|
||||
{
|
||||
for (int j = 0; j < N; j++)
|
||||
{
|
||||
res[i][j] += G0*(4.0*s1.density*pow(s1.r,3)*pi/3.0)*(s1.z-height)/pow(pow(xmin+dx*i-s1.x,2)+pow(ymin+dy*j-s1.y,2)+pow(s1.z-height,2),1.5);
|
||||
}
|
||||
}
|
||||
}break;
|
||||
case 2: //gx
|
||||
{
|
||||
for (int i = 0; i < M; i++)
|
||||
{
|
||||
for (int j = 0; j < N; j++)
|
||||
{
|
||||
res[i][j] += -3e+4*G0*(4.0*s1.density*pow(s1.r,3)*pi/3.0)*(s1.z-height)*(xmin+dx*i-s1.x)/pow(pow(xmin+dx*i-s1.x,2)+pow(ymin+dy*j-s1.y,2)+pow(s1.z-height,2),2.5);
|
||||
}
|
||||
}
|
||||
}break;
|
||||
case 3: //gy
|
||||
{
|
||||
for (int i = 0; i < M; i++)
|
||||
{
|
||||
for (int j = 0; j < N; j++)
|
||||
{
|
||||
res[i][j] += -3e+4*G0*(4.0*s1.density*pow(s1.r,3)*pi/3.0)*(s1.z-height)*(ymin+dy*j-s1.y)/pow(pow(xmin+dx*i-s1.x,2)+pow(ymin+dy*j-s1.y,2)+pow(s1.z-height,2),2.5);
|
||||
}
|
||||
}
|
||||
}break;
|
||||
case 4: //gz
|
||||
{
|
||||
for (int i = 0; i < M; i++)
|
||||
{
|
||||
for (int j = 0; j < N; j++)
|
||||
{
|
||||
res[i][j] += 1e+4*G0*(4.0*s1.density*pow(s1.r,3)*pi/3.0)*(2.0*pow(s1.z-height,2)+pow(xmin+dx*i-s1.x,2)+pow(ymin+dy*j-s1.y,2))/pow(pow(xmin+dx*i-s1.x,2)+pow(ymin+dy*j-s1.y,2)+pow(s1.z-height,2),2.5);
|
||||
}
|
||||
}
|
||||
}break;
|
||||
}
|
||||
}
|
||||
|
||||
void FD::forward_cube(cube c1,int caltype)
|
||||
{
|
||||
double R222,R122,R212,R112,R221,R121,R211,R111;
|
||||
double G222,G122,G212,G112,G221,G121,G211,G111;
|
||||
double x,y;
|
||||
double z = height;
|
||||
switch(caltype)
|
||||
{
|
||||
case 1: //g
|
||||
{
|
||||
for (int i = 0; i < M; i++)
|
||||
{
|
||||
for (int j = 0; j < N; j++)
|
||||
{
|
||||
x = xmin + i*dx;
|
||||
y = ymin + j*dy;
|
||||
|
||||
R222=sqrt((c1.x2-x)*(c1.x2-x)+(c1.y2-y)*(c1.y2-y)+(c1.z2-z)*(c1.z2-z));
|
||||
R122=sqrt((c1.x1-x)*(c1.x1-x)+(c1.y2-y)*(c1.y2-y)+(c1.z2-z)*(c1.z2-z));
|
||||
R212=sqrt((c1.x2-x)*(c1.x2-x)+(c1.y1-y)*(c1.y1-y)+(c1.z2-z)*(c1.z2-z));
|
||||
R112=sqrt((c1.x1-x)*(c1.x1-x)+(c1.y1-y)*(c1.y1-y)+(c1.z2-z)*(c1.z2-z));
|
||||
R221=sqrt((c1.x2-x)*(c1.x2-x)+(c1.y2-y)*(c1.y2-y)+(c1.z1-z)*(c1.z1-z));
|
||||
R121=sqrt((c1.x1-x)*(c1.x1-x)+(c1.y2-y)*(c1.y2-y)+(c1.z1-z)*(c1.z1-z));
|
||||
R211=sqrt((c1.x2-x)*(c1.x2-x)+(c1.y1-y)*(c1.y1-y)+(c1.z1-z)*(c1.z1-z));
|
||||
R111=sqrt((c1.x1-x)*(c1.x1-x)+(c1.y1-y)*(c1.y1-y)+(c1.z1-z)*(c1.z1-z));
|
||||
|
||||
G222=(c1.x2-x)*log((c1.y2-y)+R222)+(c1.y2-y)*log((c1.x2-x)+R222)+(c1.z2-z)*arctg((c1.z2-z)*R222/(c1.x2-x)/(c1.y2-y));
|
||||
G122=(c1.x1-x)*log((c1.y2-y)+R122)+(c1.y2-y)*log((c1.x1-x)+R122)+(c1.z2-z)*arctg((c1.z2-z)*R122/(c1.x1-x)/(c1.y2-y));
|
||||
G212=(c1.x2-x)*log((c1.y1-y)+R212)+(c1.y1-y)*log((c1.x2-x)+R212)+(c1.z2-z)*arctg((c1.z2-z)*R212/(c1.x2-x)/(c1.y1-y));
|
||||
G112=(c1.x1-x)*log((c1.y1-y)+R112)+(c1.y1-y)*log((c1.x1-x)+R112)+(c1.z2-z)*arctg((c1.z2-z)*R112/(c1.x1-x)/(c1.y1-y));
|
||||
G221=(c1.x2-x)*log((c1.y2-y)+R221)+(c1.y2-y)*log((c1.x2-x)+R221)+(c1.z1-z)*arctg((c1.z1-z)*R221/(c1.x2-x)/(c1.y2-y));
|
||||
G121=(c1.x1-x)*log((c1.y2-y)+R121)+(c1.y2-y)*log((c1.x1-x)+R121)+(c1.z1-z)*arctg((c1.z1-z)*R121/(c1.x1-x)/(c1.y2-y));
|
||||
G211=(c1.x2-x)*log((c1.y1-y)+R211)+(c1.y1-y)*log((c1.x2-x)+R211)+(c1.z1-z)*arctg((c1.z1-z)*R211/(c1.x2-x)/(c1.y1-y));
|
||||
G111=(c1.x1-x)*log((c1.y1-y)+R111)+(c1.y1-y)*log((c1.x1-x)+R111)+(c1.z1-z)*arctg((c1.z1-z)*R111/(c1.x1-x)/(c1.y1-y));
|
||||
|
||||
res[i][j] +=-1.0*G0*(G222-G122-G212+G112-G221+G121+G211-G111)*c1.density;
|
||||
}
|
||||
}
|
||||
}break;
|
||||
case 2: //gx
|
||||
{
|
||||
for (int i = 0; i < M; i++)
|
||||
{
|
||||
for (int j = 0; j < N; j++)
|
||||
{
|
||||
x = xmin + i*dx;
|
||||
y = ymin + j*dy;
|
||||
|
||||
R222=sqrt((c1.x2-x)*(c1.x2-x)+(c1.y2-y)*(c1.y2-y)+(c1.z2-z)*(c1.z2-z));
|
||||
R122=sqrt((c1.x1-x)*(c1.x1-x)+(c1.y2-y)*(c1.y2-y)+(c1.z2-z)*(c1.z2-z));
|
||||
R212=sqrt((c1.x2-x)*(c1.x2-x)+(c1.y1-y)*(c1.y1-y)+(c1.z2-z)*(c1.z2-z));
|
||||
R112=sqrt((c1.x1-x)*(c1.x1-x)+(c1.y1-y)*(c1.y1-y)+(c1.z2-z)*(c1.z2-z));
|
||||
R221=sqrt((c1.x2-x)*(c1.x2-x)+(c1.y2-y)*(c1.y2-y)+(c1.z1-z)*(c1.z1-z));
|
||||
R121=sqrt((c1.x1-x)*(c1.x1-x)+(c1.y2-y)*(c1.y2-y)+(c1.z1-z)*(c1.z1-z));
|
||||
R211=sqrt((c1.x2-x)*(c1.x2-x)+(c1.y1-y)*(c1.y1-y)+(c1.z1-z)*(c1.z1-z));
|
||||
R111=sqrt((c1.x1-x)*(c1.x1-x)+(c1.y1-y)*(c1.y1-y)+(c1.z1-z)*(c1.z1-z));
|
||||
|
||||
G222=log((c1.y2-y)+R222);
|
||||
G122=log((c1.y2-y)+R122);
|
||||
G212=log((c1.y1-y)+R212);
|
||||
G112=log((c1.y1-y)+R112);
|
||||
G221=log((c1.y2-y)+R221);
|
||||
G121=log((c1.y2-y)+R121);
|
||||
G211=log((c1.y1-y)+R211);
|
||||
G111=log((c1.y1-y)+R111);
|
||||
|
||||
res[i][j] +=G0*(G222-G122-G212+G112-G221+G121+G211-G111)*c1.density*1e+4;
|
||||
}
|
||||
}
|
||||
}break;
|
||||
case 3: //gy
|
||||
{
|
||||
for (int i = 0; i < M; i++)
|
||||
{
|
||||
for (int j = 0; j < N; j++)
|
||||
{
|
||||
x = xmin + i*dx;
|
||||
y = ymin + j*dy;
|
||||
|
||||
R222=sqrt((c1.x2-x)*(c1.x2-x)+(c1.y2-y)*(c1.y2-y)+(c1.z2-z)*(c1.z2-z));
|
||||
R122=sqrt((c1.x1-x)*(c1.x1-x)+(c1.y2-y)*(c1.y2-y)+(c1.z2-z)*(c1.z2-z));
|
||||
R212=sqrt((c1.x2-x)*(c1.x2-x)+(c1.y1-y)*(c1.y1-y)+(c1.z2-z)*(c1.z2-z));
|
||||
R112=sqrt((c1.x1-x)*(c1.x1-x)+(c1.y1-y)*(c1.y1-y)+(c1.z2-z)*(c1.z2-z));
|
||||
R221=sqrt((c1.x2-x)*(c1.x2-x)+(c1.y2-y)*(c1.y2-y)+(c1.z1-z)*(c1.z1-z));
|
||||
R121=sqrt((c1.x1-x)*(c1.x1-x)+(c1.y2-y)*(c1.y2-y)+(c1.z1-z)*(c1.z1-z));
|
||||
R211=sqrt((c1.x2-x)*(c1.x2-x)+(c1.y1-y)*(c1.y1-y)+(c1.z1-z)*(c1.z1-z));
|
||||
R111=sqrt((c1.x1-x)*(c1.x1-x)+(c1.y1-y)*(c1.y1-y)+(c1.z1-z)*(c1.z1-z));
|
||||
|
||||
G222=log((c1.x2-x)+R222);
|
||||
G122=log((c1.x1-x)+R122);
|
||||
G212=log((c1.x2-x)+R212);
|
||||
G112=log((c1.x1-x)+R112);
|
||||
G221=log((c1.x2-x)+R221);
|
||||
G121=log((c1.x1-x)+R121);
|
||||
G211=log((c1.x2-x)+R211);
|
||||
G111=log((c1.x1-x)+R111);
|
||||
|
||||
res[i][j] +=G0*(G222-G122-G212+G112-G221+G121+G211-G111)*c1.density*1e+4;
|
||||
}
|
||||
}
|
||||
}break;
|
||||
case 4: //gz
|
||||
{
|
||||
for (int i = 0; i < M; i++)
|
||||
{
|
||||
for (int j = 0; j < N; j++)
|
||||
{
|
||||
x = xmin + i*dx;
|
||||
y = ymin + j*dy;
|
||||
|
||||
R222=sqrt((c1.x2-x)*(c1.x2-x)+(c1.y2-y)*(c1.y2-y)+(c1.z2-z)*(c1.z2-z));
|
||||
R122=sqrt((c1.x1-x)*(c1.x1-x)+(c1.y2-y)*(c1.y2-y)+(c1.z2-z)*(c1.z2-z));
|
||||
R212=sqrt((c1.x2-x)*(c1.x2-x)+(c1.y1-y)*(c1.y1-y)+(c1.z2-z)*(c1.z2-z));
|
||||
R112=sqrt((c1.x1-x)*(c1.x1-x)+(c1.y1-y)*(c1.y1-y)+(c1.z2-z)*(c1.z2-z));
|
||||
R221=sqrt((c1.x2-x)*(c1.x2-x)+(c1.y2-y)*(c1.y2-y)+(c1.z1-z)*(c1.z1-z));
|
||||
R121=sqrt((c1.x1-x)*(c1.x1-x)+(c1.y2-y)*(c1.y2-y)+(c1.z1-z)*(c1.z1-z));
|
||||
R211=sqrt((c1.x2-x)*(c1.x2-x)+(c1.y1-y)*(c1.y1-y)+(c1.z1-z)*(c1.z1-z));
|
||||
R111=sqrt((c1.x1-x)*(c1.x1-x)+(c1.y1-y)*(c1.y1-y)+(c1.z1-z)*(c1.z1-z));
|
||||
|
||||
G222=atan((c1.x2-x)*(c1.y2-y)/(R222*(c1.z2-z)));
|
||||
G122=atan((c1.x1-x)*(c1.y2-y)/(R122*(c1.z2-z)));
|
||||
G212=atan((c1.x2-x)*(c1.y1-y)/(R212*(c1.z2-z)));
|
||||
G112=atan((c1.x1-x)*(c1.y1-y)/(R112*(c1.z2-z)));
|
||||
G221=atan((c1.x2-x)*(c1.y2-y)/(R221*(c1.z1-z)));
|
||||
G121=atan((c1.x1-x)*(c1.y2-y)/(R121*(c1.z1-z)));
|
||||
G211=atan((c1.x2-x)*(c1.y1-y)/(R211*(c1.z1-z)));
|
||||
G111=atan((c1.x1-x)*(c1.y1-y)/(R111*(c1.z1-z)));
|
||||
|
||||
res[i][j] +=-1.0*G0*(G222-G122-G212+G112-G221+G121+G211-G111)*c1.density*1e+4;
|
||||
}
|
||||
}
|
||||
}break;
|
||||
}
|
||||
}
|
||||
181
archive/grav2d_regular/main.cpp
Normal file
181
archive/grav2d_regular/main.cpp
Normal file
@@ -0,0 +1,181 @@
|
||||
#include "datafunc.h"
|
||||
#include "forward.h"
|
||||
|
||||
void disp_help()
|
||||
{
|
||||
cout<<"grav2d_regular 0.1 - forward modeling of graviational field of regular objects"<<endl<<endl
|
||||
<<"usage: grav2d_regular -g|-x|-y|-z -r<xmin>/<xmax>/<ymin>/<ymax>/<height> -i<dx>/<dy> [-s<posi-x>/<posi-y>/<posi-z>/<r>/<density>] [-c<posi-x1>/<posi-x2>/<posi-y1>/<posi-y2>/<posi-z1>/<posi-z2>/<density>] [-f<para-file>] -o<output-file>"<<endl
|
||||
<<" -g|-x|-y|-z"<<endl
|
||||
<<" -r specify calcualtion range"<<endl
|
||||
<<" -i specify calculation intervals"<<endl
|
||||
<<" -s sphere parameters"<<endl
|
||||
<<" -c cube parameters"<<endl
|
||||
<<" -f specify objects' parameters. you can use this to define a lot of objects instead of struggling with the command line"<<endl
|
||||
<<" -o specify output file's name"<<endl<<endl
|
||||
<<"example: grav2d_regular -g -r0/1000/0/1000 -i10/10 -s500/500/100/50/1.0 -oexample.xyz"<<endl;
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
int caltype = 0;
|
||||
char cmd_type[1024] = {0};
|
||||
char ob_type[1024] = {0};
|
||||
const char* oneline;
|
||||
string oneline_str;
|
||||
char filename[1024] = {0};
|
||||
char outname[1024] = {0};
|
||||
double interval[2];
|
||||
double range[5];
|
||||
|
||||
if (argc==1)
|
||||
{
|
||||
disp_help();
|
||||
}
|
||||
else
|
||||
{
|
||||
sphere s1;
|
||||
cube c1;
|
||||
SphereList list_s;
|
||||
SphereList::iterator is;
|
||||
CubeList list_c;
|
||||
CubeList::iterator ic;
|
||||
|
||||
interval[0]=interval[1]=MAX;
|
||||
range[0]=range[1]=range[2]=range[3]=range[4]=MAX;
|
||||
for (int i = 1; i < argc; i++)
|
||||
{
|
||||
sscanf(argv[i],"%2s",cmd_type);
|
||||
if (!strcmp(cmd_type,GRAV)) caltype = 1;
|
||||
else if (!strcmp(cmd_type,GRADX)) caltype = 2;
|
||||
else if (!strcmp(cmd_type,GRADY)) caltype = 3;
|
||||
else if (!strcmp(cmd_type,GRADZ)) caltype = 4;
|
||||
else if (!strcmp(cmd_type,RANGE))
|
||||
{
|
||||
if (5!=sscanf(argv[i],"%*2s%lf/%lf/%lf/%lf/%lf",&range[0],&range[1],&range[2],&range[3],&range[4]))
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (range[0]>range[1]||range[2]>range[3])
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!strcmp(cmd_type,INTERVAL))
|
||||
{
|
||||
if (2!=sscanf(argv[i],"%*2s%lf/%lf",&interval[0],&interval[1]))
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (interval[0]<=0||interval[1]<=0)
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!strcmp(cmd_type,PARAFILE))
|
||||
{
|
||||
if (-1==sscanf(argv[i],"%*2s%s",filename))
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
ifstream parain(filename);
|
||||
if (!parain)
|
||||
{
|
||||
cout<<"file not found: "<<filename<<endl;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
while(getline(parain,oneline_str))
|
||||
{
|
||||
oneline = oneline_str.c_str();
|
||||
sscanf(oneline,"%2s",ob_type);
|
||||
if (!strcmp(ob_type,SPHERE))
|
||||
{
|
||||
if (5!=sscanf(oneline,"%*2s%lf/%lf/%lf/%lf/%lf",&s1.x,&s1.y,&s1.z,&s1.r,&s1.density))
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax found in file: "<<oneline<<endl;
|
||||
}
|
||||
else list_s.push_back(s1);
|
||||
|
||||
}
|
||||
else if (!strcmp(ob_type,CUBE))
|
||||
{
|
||||
if (7!=sscanf(oneline,"%*2s%lf/%lf/%lf/%lf/%lf/%lf/%lf",&c1.x1,&c1.x2,&c1.y1,&c1.y2,&c1.z1,&c1.z2,&c1.density))
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax found in file: "<<oneline<<endl;
|
||||
}
|
||||
else list_c.push_back(c1);
|
||||
}
|
||||
}
|
||||
parain.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!strcmp(cmd_type,OUTPUT))
|
||||
{
|
||||
if (-1==sscanf(argv[i],"%*2s%s",outname))
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else if (!strcmp(cmd_type,SPHERE))
|
||||
{
|
||||
if (5!=sscanf(argv[i],"%*2s%lf/%lf/%lf/%lf/%lf",&s1.x,&s1.y,&s1.z,&s1.r,&s1.density))
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||||
}
|
||||
else list_s.push_back(s1);
|
||||
|
||||
}
|
||||
else if (!strcmp(cmd_type,CUBE))
|
||||
{
|
||||
if (7!=sscanf(argv[i],"%*2s%lf/%lf/%lf/%lf/%lf/%lf/%lf",&c1.x1,&c1.x2,&c1.y1,&c1.y2,&c1.z1,&c1.z2,&c1.density))
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||||
}
|
||||
else list_c.push_back(c1);
|
||||
}
|
||||
}
|
||||
|
||||
if (list_c.empty()&&list_s.empty())
|
||||
{
|
||||
cout<<"no objects found"<<endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
FD fd1;
|
||||
fd1.init_res(range,interval);
|
||||
if (!list_s.empty())
|
||||
{
|
||||
for (is=list_s.begin();is!=list_s.end();++is)
|
||||
{
|
||||
s1 = *is;
|
||||
fd1.forward_sphere(s1,caltype);
|
||||
}
|
||||
}
|
||||
if (!list_c.empty())
|
||||
{
|
||||
for (ic=list_c.begin();ic!=list_c.end();++ic)
|
||||
{
|
||||
c1 = *ic;
|
||||
fd1.forward_cube(c1,caltype);
|
||||
}
|
||||
}
|
||||
fd1.out_res(outname);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
15
archive/grav2d_regular/makefile
Normal file
15
archive/grav2d_regular/makefile
Normal file
@@ -0,0 +1,15 @@
|
||||
CC = g++-8
|
||||
PROM = /usr/local/sbin/grav2d-regular
|
||||
CFLAGS = -I.
|
||||
DEPS = $(shell find . -name "*.h")
|
||||
SRC = $(shell find . -name "*.cpp")
|
||||
OBJ = $(SRC:%.cpp=%.o)
|
||||
|
||||
$(PROM): $(OBJ)
|
||||
$(CC) -o $(PROM) $(OBJ) $(CFLAGS)
|
||||
|
||||
%.o:%.cpp $(DEPS)
|
||||
$(CC) -c $< -o $@ $(CFLAGS)
|
||||
|
||||
clean:
|
||||
rm -rf $(OBJ)
|
||||
5
archive/grav2d_regular/test.para
Normal file
5
archive/grav2d_regular/test.para
Normal file
@@ -0,0 +1,5 @@
|
||||
-c450/550/450/550/100/200/1.0
|
||||
-s300/300/100/50/1.0
|
||||
-s300/700/100/50/1.0
|
||||
-s700/700/100/50/1.0
|
||||
-s700/300/100/50/1.0
|
||||
39
archive/grav2d_vectical_cylinder/archive/ffts.cpp
Normal file
39
archive/grav2d_vectical_cylinder/archive/ffts.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#include "iostream"
|
||||
#include "iomanip"
|
||||
#include "string.h"
|
||||
#include "cmath"
|
||||
using namespace std;
|
||||
|
||||
double func(double x)//积分函数
|
||||
{
|
||||
return pow(x,2);
|
||||
}
|
||||
|
||||
double integration (double a,double b,double eps)//执行变步长梯形求积法
|
||||
{
|
||||
int n,k;
|
||||
double fa,fb,h,t1,p,s,x,t;
|
||||
fa=func (a); fb=func (b);
|
||||
n=1; h=b-a;
|
||||
t1=h*(fa+fb)/2.0;
|
||||
p=eps+1.0;
|
||||
while (p>=eps)
|
||||
{
|
||||
s=0.0;
|
||||
for (k=0;k<=n-1;k++)
|
||||
{
|
||||
x=a+(k+0.5)*h;
|
||||
s=s+func (x);
|
||||
}
|
||||
t=(t1+h*s)/2.0;
|
||||
p=fabs(t1-t);
|
||||
t1=t; n=n+n; h=h/2.0;
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
cout<<integration(0,1,0.000001)<<endl;
|
||||
return 0;
|
||||
}
|
||||
131
archive/grav2d_vectical_cylinder/archive/main.cpp
Normal file
131
archive/grav2d_vectical_cylinder/archive/main.cpp
Normal file
@@ -0,0 +1,131 @@
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
#include <iomanip>
|
||||
#include <cmath>
|
||||
#include <fstream>
|
||||
using namespace std;
|
||||
FILE *fout;
|
||||
const double G=6.67191e-6; //万有引力常数
|
||||
double density=2e+3; //密度(千克每立方米)
|
||||
const double PI=3.1415926535897932;
|
||||
double R=20; //圆柱体半径
|
||||
double h=10; //圆柱体上顶埋深
|
||||
double H=60; //圆柱体下底埋深
|
||||
double x1,x2,y3,y2; //计算区域横坐标起始位置
|
||||
double d; //计算区域网格间距
|
||||
double x,y,X,l,M,N,L; //横,纵坐标,异常值
|
||||
double Xo,Yo;
|
||||
|
||||
class ffts
|
||||
{
|
||||
private:
|
||||
double a, b, eps, integ;
|
||||
public:
|
||||
ffts (double aa, double bb, double es)//顺序提供a,b,eps值的构造函数
|
||||
{ a = aa; b = bb; eps = es; }
|
||||
void integration (); //执行变步长梯形求积法
|
||||
void output (); //输出积分值到文件并显示
|
||||
double func (double); //计算被积函数值
|
||||
};
|
||||
|
||||
void ffts::integration () //执行变步长梯形求积法
|
||||
{
|
||||
int n,k;
|
||||
double fa,fb,h,t1,p,s,x,t;
|
||||
fa=func (a); fb=func (b);
|
||||
n=1; h=b-a;
|
||||
t1=h*(fa+fb)/2.0;
|
||||
p=eps+1.0;
|
||||
while (p>=eps)
|
||||
{
|
||||
s=0.0;
|
||||
for (k=0;k<=n-1;k++)
|
||||
{
|
||||
x=a+(k+0.5)*h;
|
||||
s=s+func (x);
|
||||
}
|
||||
t=(t1+h*s)/2.0;
|
||||
p=fabs(t1-t);
|
||||
t1=t; n=n+n; h=h/2.0;
|
||||
}
|
||||
integ = t;
|
||||
}
|
||||
|
||||
void ffts::output () //输出积分值到文件并显示
|
||||
{
|
||||
if((fout=fopen("yuanzhuti.dat","a"))==NULL)//可设置xls格式文件
|
||||
{
|
||||
cout<<"error!";
|
||||
return;
|
||||
}
|
||||
if(X>R)
|
||||
{
|
||||
fprintf(fout,"%lf %lf %lf\n",x,y,integ*G*density);
|
||||
printf("%lf %lf %lf\n",x,y,integ*G*density);//输出数据
|
||||
fclose(fout);
|
||||
}
|
||||
else if(X==R)
|
||||
{
|
||||
fprintf(fout,"%lf %lf %lf\n",x,y,integ*G*density);
|
||||
printf("%lf %lf %lf\n",x,y,integ*G*density);//输出数据
|
||||
fclose(fout);
|
||||
}
|
||||
else if(X>0&&X<R)
|
||||
{
|
||||
fprintf(fout,"%lf %lf %lf\n",x,y,(integ+L)*G*density);
|
||||
printf("%lf %lf %lf\n",x,y,(integ+L)*G*density);//输出数据
|
||||
fclose(fout);
|
||||
}
|
||||
else if(X==0)
|
||||
{
|
||||
fprintf(fout,"%lf %lf %lf\n",x,y,G*density*2*PI*(sqrt(R*R+h*h)-sqrt(R*R+H*H)+H-h));
|
||||
printf("%lf %lf %lf\n",x,y,G*density*2*PI*(sqrt(R*R+h*h)-sqrt(R*R+H*H)+H-h));//输出数据
|
||||
fclose(fout);
|
||||
}
|
||||
}
|
||||
|
||||
double ffts::func (double l)
|
||||
{
|
||||
M=(1/sqrt(l*l+h*h)-1/sqrt(l*l+H*H));
|
||||
N=2*l*acos((l*l+X*X-R*R)/(2*l*X));
|
||||
if(X>R) return N*M;
|
||||
else if(X==R) return (2*l*acos(l/(2*R)))*M;
|
||||
else if(X>0&&X<R) return N*M;
|
||||
return N*M;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
printf("\nPlease input the calculating region and grid space : ");
|
||||
scanf("%lf %lf %lf %lf %lf",&x1,&x2,&y3,&y2,&d);
|
||||
Xo=100;
|
||||
Yo=100;
|
||||
for(x=x1;x<=x2;x+=d)
|
||||
{
|
||||
for(y=y3;y<=y2;y+=d)
|
||||
{
|
||||
X=(int)sqrt((x-Xo)*(x-Xo)+(y-Yo)*(y-Yo));
|
||||
if(X>R)
|
||||
{
|
||||
ffts solution(X-R, X+R, 0.00001); //创建对象并顺序提供a, b, eps值
|
||||
solution.integration (); //执行变步长梯形求积法
|
||||
solution.output (); //输出积分值到文件并显示
|
||||
}
|
||||
else if(X==R)
|
||||
{
|
||||
ffts solution(0.0, 2*R, 0.00001); //创建对象并顺序提供a, b, eps值
|
||||
solution.integration (); //执行变步长梯形求积法
|
||||
solution.output (); //输出积分值到文件并显示
|
||||
}
|
||||
else if(X>0&&X<R)
|
||||
{
|
||||
L=2*PI*(sqrt((R-X)*(R-X)+h*h)-sqrt((R-X)*(R-X)+H*H)+H-h);
|
||||
ffts solution(R-X, X+R, 0.00001); //创建对象并顺序提供a, b, eps值
|
||||
solution.integration (); //执行变步长梯形求积法
|
||||
solution.output (); //输出积分值到文件并显示
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("\nCalculating completed!\n\nPlease press any key to exit ...");
|
||||
return 0;
|
||||
}
|
||||
2
archive/grav2d_vectical_cylinder/makefile
Normal file
2
archive/grav2d_vectical_cylinder/makefile
Normal file
@@ -0,0 +1,2 @@
|
||||
grav2d_vectical_cylinder: vec_cyliner.cpp vec_cyliner.h
|
||||
g++ vec_cyliner.cpp -o grav2d_vectical_cylinder
|
||||
104
archive/grav2d_vectical_cylinder/vec_cyliner.cpp
Normal file
104
archive/grav2d_vectical_cylinder/vec_cyliner.cpp
Normal file
@@ -0,0 +1,104 @@
|
||||
#include "vec_cyliner.h"
|
||||
|
||||
void disp_help()
|
||||
{
|
||||
cout<<"grav2d_vectical_cylinder 1.0 - forward modeling gravity data of a vectical cylinder"<<endl<<endl
|
||||
<<"syntax: grav2d_vectical_cylinder -p<top-depth>/<bottom-depth>/<radius>/<density> -l<x-center>/<y-center> -r<xmin>/<xmax>/<ymin>/<ymax> -i<x-interval>/<y-interval>[/integral-interval] -o<outfile-name>"<<endl
|
||||
<<" -p physical parameters of the cylinder. units are meter and g/cm^3"<<endl
|
||||
<<" -l centeral location of the cylinder"<<endl
|
||||
<<" -r range of calculation"<<endl
|
||||
<<" -i calculation spaces. the default integration interval is 1e-5 for all cases. Users can set customized value by applying a different value"<<endl
|
||||
<<" -o output file's name. The output format is .xyz ASSCI format, hence no surffix is needed nor can change the output format."<<endl<<endl
|
||||
<<"example: grav2d_vectical_cylinder -p10/60/20/2.0 -l100/100 -r0/200/0/200 -i5/5 -otestout.dat"<<endl;
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
int range_num;
|
||||
double para[4] = {MAX,MAX,MAX,MAX};
|
||||
double posi[2] = {MAX,MAX};
|
||||
double range[4] = {MAX,MAX,MAX,MAX};
|
||||
double interval[3] = {MIN,MIN,MIN};
|
||||
char filename[1024] = {0};
|
||||
char cmd_type[1024] = {0};
|
||||
if (argc==1)
|
||||
{
|
||||
disp_help();
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 1; i < argc; i++)
|
||||
{
|
||||
sscanf(argv[i],"%2s",cmd_type);
|
||||
if (!strcmp(cmd_type,PARA))
|
||||
{
|
||||
range_num = sscanf(argv[i],"%*2s%lf/%lf/%lf/%lf",¶[0],¶[1],¶[2],¶[3]);
|
||||
if (range_num==4)
|
||||
{
|
||||
if (para[0]>para[1]||para[0]<0||para[1]<0||para[2]<0||para[3]<0)
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!strcmp(cmd_type,POSI))
|
||||
{
|
||||
range_num = sscanf(argv[i],"%*2s%lf/%lf",&posi[0],&posi[1]);
|
||||
if (posi[0]==MAX||posi[1]==MAX)
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!strcmp(cmd_type,RANGE))
|
||||
{
|
||||
range_num = sscanf(argv[i],"%*2s%lf/%lf/%lf/%lf",&range[0],&range[1],&range[2],&range[3]);
|
||||
if (range_num==4)
|
||||
{
|
||||
if (range[0]>range[1]||range[2]>range[3])
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!strcmp(cmd_type,SPACE))
|
||||
{
|
||||
range_num = sscanf(argv[i],"%*2s%lf/%lf/%lf",&interval[0],&interval[1],&interval[2]);
|
||||
if (interval[0]<0||interval[1]<0)
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!strcmp(cmd_type,OUTFILE))
|
||||
{
|
||||
sscanf(argv[i],"%*2s%s",filename);//按格式读入文件名与扩展名
|
||||
if(!strcmp(filename,""))//检查文件名是否为空
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
vec_cy v1;
|
||||
v1.info_taker(para,posi,range,interval,filename);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
145
archive/grav2d_vectical_cylinder/vec_cyliner.h
Normal file
145
archive/grav2d_vectical_cylinder/vec_cyliner.h
Normal file
@@ -0,0 +1,145 @@
|
||||
#include "iostream"
|
||||
#include "fstream"
|
||||
#include "iomanip"
|
||||
#include "cmath"
|
||||
#include "stdio.h"
|
||||
#include "string.h"
|
||||
|
||||
#define G0 6.67191e-3
|
||||
#define pi (4.0*atan(1.0))
|
||||
#define MAX 1e+30
|
||||
#define MIN -1e+30
|
||||
|
||||
#define PARA "-p"
|
||||
#define POSI "-l"
|
||||
#define RANGE "-r"
|
||||
#define SPACE "-i"
|
||||
#define OUTFILE "-o"
|
||||
|
||||
#define BOLDRED "\033[1m\033[31m" /* Bold Red */
|
||||
#define RESET "\033[0m" /* reset */
|
||||
|
||||
using namespace std;
|
||||
|
||||
class vec_cy
|
||||
{
|
||||
public:
|
||||
vec_cy();
|
||||
~vec_cy();
|
||||
int info_taker(double*,double*,double*,double*,char*);
|
||||
double func(double);
|
||||
double integration(double,double,double);
|
||||
int calculate();
|
||||
int datout();
|
||||
private:
|
||||
double t_dep,b_dep,rad,den;
|
||||
double x_center,y_center;
|
||||
double xmin,xmax,ymin,ymax;
|
||||
double x_interval,y_interval,inte_interval;
|
||||
char* outfile_name;
|
||||
|
||||
int M,N;
|
||||
double* data;
|
||||
|
||||
double cal_radius;
|
||||
};
|
||||
|
||||
vec_cy::vec_cy()
|
||||
{
|
||||
data = NULL;
|
||||
inte_interval = 1e-5;
|
||||
outfile_name = NULL;
|
||||
}
|
||||
|
||||
vec_cy::~vec_cy()
|
||||
{
|
||||
if(data!=NULL) delete []data;
|
||||
}
|
||||
|
||||
int vec_cy::info_taker(double* para,double* posi,double* range,double* interval,char* filename)
|
||||
{
|
||||
t_dep = *para; b_dep = *(para+1); rad = *(para+2); den = *(para+3);
|
||||
x_center = *posi; y_center = *(posi+1);
|
||||
xmin = *range; xmax = *(range+1); ymin = *(range+2); ymax = *(range+3);
|
||||
x_interval = *interval; y_interval = *(interval+1);
|
||||
if (*(interval+2)>0)
|
||||
inte_interval = *(interval+2);
|
||||
outfile_name = filename;
|
||||
|
||||
M = int (ymax-ymin)/y_interval+1;
|
||||
N = int (xmax-xmin)/x_interval+1;
|
||||
|
||||
ymax = ymin + (M-1)*y_interval;
|
||||
xmax = xmin + (N-1)*x_interval;
|
||||
|
||||
calculate();
|
||||
datout();
|
||||
return 0;
|
||||
}
|
||||
|
||||
double vec_cy::func(double l)
|
||||
{
|
||||
double temp,temp1;
|
||||
temp=1.0/sqrt(l*l+t_dep*t_dep)-1.0/sqrt(l*l+b_dep*b_dep);
|
||||
temp1=2*l*acos((l*l+cal_radius*cal_radius-rad*rad)/(2*l*cal_radius));
|
||||
if (cal_radius==rad) return (2*l*acos(l/(2*rad)))*temp;
|
||||
else return temp*temp1;
|
||||
}
|
||||
|
||||
double vec_cy::integration(double a,double b,double eps)
|
||||
{
|
||||
int n,k;
|
||||
double fa,fb,h,t1,p,s,x,t;
|
||||
fa=func (a); fb=func (b);
|
||||
n=1; h=b-a;
|
||||
t1=h*(fa+fb)/2.0;
|
||||
p=eps+1.0;
|
||||
while (p>=eps)
|
||||
{
|
||||
s=0.0;
|
||||
for (k=0;k<=n-1;k++)
|
||||
{
|
||||
x=a+(k+0.5)*h;
|
||||
s=s+func (x);
|
||||
}
|
||||
t=(t1+h*s)/2.0;
|
||||
p=fabs(t1-t);
|
||||
t1=t; n=n+n; h=h/2.0;
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
int vec_cy::calculate()
|
||||
{
|
||||
double temp_res;
|
||||
data = new double [M*N];
|
||||
for (int i = 0; i < M*N; i++)
|
||||
{
|
||||
cal_radius = (int) sqrt(pow(xmin+x_interval*(i%N)-x_center,2)+pow(ymin+y_interval*(i/N)-y_center,2));
|
||||
if (cal_radius >= rad)
|
||||
{
|
||||
data[i] = G0*den*integration(cal_radius-rad,cal_radius+rad,inte_interval);
|
||||
}
|
||||
else if (cal_radius>0&&cal_radius<rad)
|
||||
{
|
||||
temp_res = 2*pi*(sqrt(pow(rad-cal_radius,2)+t_dep*t_dep)-sqrt(pow(rad-cal_radius,2)+b_dep*b_dep)+b_dep-t_dep);
|
||||
data[i] = G0*den*(temp_res+integration(rad-cal_radius,rad+cal_radius,inte_interval));
|
||||
}
|
||||
else if (cal_radius==0)
|
||||
{
|
||||
data[i] = G0*den*2*pi*(sqrt(rad*rad+t_dep*t_dep)-sqrt(rad*rad+b_dep*b_dep)+b_dep-t_dep);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int vec_cy::datout()
|
||||
{
|
||||
ofstream outfile(outfile_name);
|
||||
for (int i = 0; i < M*N; ++i)
|
||||
{
|
||||
outfile<<xmin+x_interval*(i%N)<<" "<<ymin+y_interval*(i/N)<<" "<<setprecision(16)<<data[i]<<endl;
|
||||
}
|
||||
outfile.close();
|
||||
return 0;
|
||||
}
|
||||
291
archive/grd2msh/func.h
Normal file
291
archive/grd2msh/func.h
Normal file
@@ -0,0 +1,291 @@
|
||||
#ifndef _FUNC_H
|
||||
#define _FUNC_H
|
||||
#include "struct.h"
|
||||
|
||||
class func
|
||||
{
|
||||
public:
|
||||
func();
|
||||
~func();
|
||||
int run(char*,char*,char*,double,int,double,double,int,int);
|
||||
int readgrd(char*);
|
||||
int readxyz(char*,double,double);
|
||||
int readxyz(char*);
|
||||
int changeToSph(char*);
|
||||
int outmsh(char*,double);
|
||||
private:
|
||||
posi* topo;
|
||||
int M,N;
|
||||
int posi_num;
|
||||
|
||||
PosiList list_posi;
|
||||
PosiList::iterator ip;
|
||||
};
|
||||
|
||||
func::func()
|
||||
{
|
||||
topo = NULL;
|
||||
}
|
||||
|
||||
func::~func()
|
||||
{
|
||||
if(topo!=NULL) delete[] topo;
|
||||
if(!list_posi.empty()) list_posi.clear();
|
||||
}
|
||||
|
||||
int func::run(char* filename,char* mshname,char* refsys,double factor,int type,double dx,double dy,int input_N,int input_M)
|
||||
{
|
||||
if (type == 1)
|
||||
{
|
||||
readgrd(filename);
|
||||
}
|
||||
else if (type == 2)
|
||||
{
|
||||
if (input_N==-1)
|
||||
{
|
||||
readxyz(filename,dx,dy);
|
||||
}
|
||||
else
|
||||
{
|
||||
readxyz(filename);
|
||||
M = input_M;
|
||||
N = input_N;
|
||||
}
|
||||
}
|
||||
if(strcmp(refsys,"NULL"))
|
||||
changeToSph(refsys);
|
||||
outmsh(mshname,factor);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int func::readgrd(char* inname)
|
||||
{
|
||||
double xmin,xmax,ymin,ymax,zmin,zmax;
|
||||
double dx,dy;
|
||||
string head_info = "";
|
||||
ifstream infile(inname);
|
||||
if (!infile)
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<inname<<" not found..."<<endl;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
infile>>head_info;
|
||||
if (head_info!="DSAA")
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"The format of "<<inname<<" is not supported..."<<endl;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
infile>>N>>M>>xmin>>xmax>>ymin>>ymax>>zmin>>zmax;
|
||||
dx = (xmax-xmin)/(N-1);
|
||||
dy = (ymax-ymin)/(M-1);
|
||||
posi_num = M*N;
|
||||
topo = new posi [posi_num];
|
||||
for (int i = 0; i < posi_num; ++i)
|
||||
{
|
||||
topo[i].id = i+1;
|
||||
infile>>topo[i].z;
|
||||
topo[i].alti = topo[i].z;
|
||||
topo[i].x = xmin + dx*(i%N);
|
||||
topo[i].y = ymin + dy*(i/N);
|
||||
}
|
||||
infile.close();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int func::readxyz(char* inname,double dx,double dy)
|
||||
{
|
||||
int count;
|
||||
posi temp_posi;
|
||||
string line;
|
||||
stringstream sline;
|
||||
double xmax,ymax;
|
||||
double xmin,ymin;
|
||||
|
||||
ifstream infile(inname);
|
||||
if (!infile)
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<inname<<" not found..."<<endl;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
xmax = ymax = -1e+30;
|
||||
xmin = ymin = 1e+30;
|
||||
count = 1;
|
||||
while(getline(infile,line))
|
||||
{
|
||||
if (*(line.begin()) == '#') continue;
|
||||
if (line!="")
|
||||
{
|
||||
sline.clear();
|
||||
sline.str(line);
|
||||
temp_posi.id = count;
|
||||
sline >> temp_posi.x >> temp_posi.y >> temp_posi.z;
|
||||
list_posi.push_back(temp_posi);
|
||||
count++;
|
||||
|
||||
if (temp_posi.x>xmax) xmax = temp_posi.x;
|
||||
if (temp_posi.y>ymax) ymax = temp_posi.y;
|
||||
if (temp_posi.x<xmin) xmin = temp_posi.x;
|
||||
if (temp_posi.y<ymin) ymin = temp_posi.y;
|
||||
}
|
||||
}
|
||||
infile.close();
|
||||
|
||||
M = (ymax-ymin)/dy+1;
|
||||
N = (xmax-xmin)/dx+1;
|
||||
|
||||
posi_num = list_posi.size();
|
||||
topo = new posi [posi_num];
|
||||
|
||||
count = 0;
|
||||
for(ip=list_posi.begin();ip!=list_posi.end();++ip)
|
||||
{
|
||||
temp_posi = *ip;
|
||||
topo[count].id = temp_posi.id;
|
||||
topo[count].x = temp_posi.x;
|
||||
topo[count].y = temp_posi.y;
|
||||
topo[count].z = temp_posi.z;
|
||||
topo[count].alti = topo[count].z;
|
||||
count++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int func::readxyz(char* inname)
|
||||
{
|
||||
int count;
|
||||
posi temp_posi;
|
||||
string line;
|
||||
stringstream sline;
|
||||
double xmax,ymax;
|
||||
double xmin,ymin;
|
||||
|
||||
ifstream infile(inname);
|
||||
if (!infile)
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<inname<<" not found..."<<endl;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
count = 1;
|
||||
while(getline(infile,line))
|
||||
{
|
||||
if (*(line.begin()) == '#') continue;
|
||||
if (line!="")
|
||||
{
|
||||
sline.clear();
|
||||
sline.str(line);
|
||||
temp_posi.id = count;
|
||||
sline >> temp_posi.x >> temp_posi.y >> temp_posi.z;
|
||||
list_posi.push_back(temp_posi);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
infile.close();
|
||||
|
||||
posi_num = list_posi.size();
|
||||
topo = new posi [posi_num];
|
||||
|
||||
count = 0;
|
||||
for(ip=list_posi.begin();ip!=list_posi.end();++ip)
|
||||
{
|
||||
temp_posi = *ip;
|
||||
topo[count].id = temp_posi.id;
|
||||
topo[count].x = temp_posi.x;
|
||||
topo[count].y = temp_posi.y;
|
||||
topo[count].z = temp_posi.z;
|
||||
topo[count].alti = topo[count].z;
|
||||
count++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int func::changeToSph(char* refer)
|
||||
{
|
||||
double refr,refR;
|
||||
if (!strcmp(refer,"WGS84"))
|
||||
{
|
||||
refr = WGS84_PoleRadius;
|
||||
refR = WGS84_EquatorRadius;
|
||||
}
|
||||
else if (!strcmp(refer,"EarthR"))
|
||||
{
|
||||
refr = EarthRadius;
|
||||
refR = EarthRadius;
|
||||
}
|
||||
else if (2 != sscanf(refer,"%lf/%lf",&refr,&refR))
|
||||
{
|
||||
cout << BOLDRED <<"==> "<< RESET <<" wrong reference system: "<<refer<<endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
double lon,lat,rad;
|
||||
for (int i = 0; i < posi_num; ++i)
|
||||
{
|
||||
lon = topo[i].x;
|
||||
lat = topo[i].y;
|
||||
rad = topo[i].z + refRadius(lat,refr,refR);
|
||||
|
||||
topo[i].x = rad*sin((0.5 - lat/180.0)*Pi)*cos((2.0 + lon/180.0)*Pi);
|
||||
topo[i].y = rad*sin((0.5 - lat/180.0)*Pi)*sin((2.0 + lon/180.0)*Pi);
|
||||
topo[i].z = rad*cos((0.5 - lat/180.0)*Pi);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int func::outmsh(char* outname,double magify)
|
||||
{
|
||||
ofstream outfile(outname);
|
||||
if (!outfile)
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"can not create "<<outname<<endl;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
outfile<<"$MeshFormat"<<endl<<"2.2 0 8"<<endl<<"$EndMeshFormat"<<endl<<"$Nodes"<<endl<<posi_num<<endl;
|
||||
for (int i = 0; i < posi_num; ++i)
|
||||
{
|
||||
outfile<<topo[i].id<<" "<<topo[i].x<<" "<<topo[i].y<<" "<<magify*topo[i].z<<endl;
|
||||
}
|
||||
outfile<<"$EndNodes"<<endl<<"$Elements"<<endl<<(M-1)*(N-1)*2<<endl;
|
||||
|
||||
int element_count = 1;
|
||||
for(int i=1;i<=M-1;i++)
|
||||
{
|
||||
for(int j=1;j<=N-1;j++)
|
||||
{
|
||||
outfile<<element_count<<" 2 1 10 "<<(i-1)*N+j<<" "<<(i-1)*N+j+1<<" "<<i*N+j+1<<endl;
|
||||
element_count++;
|
||||
}
|
||||
}
|
||||
for(int i=M;i>=2;i--)
|
||||
{
|
||||
for(int j=N;j>=2;j--)
|
||||
{
|
||||
outfile<<element_count<<" 2 1 10 "<<(i-1)*N+j<<" "<<(i-1)*N+j-1<<" "<<(i-2)*N+j-1<<endl;
|
||||
element_count++;
|
||||
}
|
||||
}
|
||||
outfile<<"$EndElements"<<endl<<"$NodeData"<<endl;
|
||||
outfile<<1<<endl<<"\"GRD TOPO\""<<endl<<1<<endl<<0.0<<endl<<3<<endl<<0<<endl<<1<<endl<<posi_num<<endl;
|
||||
for (int i = 0; i < posi_num; ++i)
|
||||
{
|
||||
outfile<<i+1<<" "<<setprecision(16)<<topo[i].alti<<endl;
|
||||
}
|
||||
outfile<<"$EndNodeData";
|
||||
outfile.close();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
139
archive/grd2msh/main.cpp
Normal file
139
archive/grd2msh/main.cpp
Normal file
@@ -0,0 +1,139 @@
|
||||
#include "func.h"
|
||||
|
||||
void disp_help()
|
||||
{
|
||||
cout
|
||||
<<"grd2msh 1.0 - convert a Surfer6's grd file or a xyz file into Gmsh .msh file for 3D Mapping"<<endl<<endl
|
||||
<<"syntax: grd2msh <grd_file>|{<xyz_file> -i<x_interval>/<y_interval>}|{<xyz_file> -I<N>/<M>} [-rWGS84|EarthR|<ref-r>/<ref-R>] [-m<magnify_factor>] [-o<msh_file>]"<<endl
|
||||
<<"-i\tintervals in x and y directions for the xyz file"<<endl
|
||||
<<"-I\tmartax number in x and y directions for the xyz file"<<endl
|
||||
<<"-r\treference system of the input file, the data will be taken as altitudes with respect to the reference system"<<endl
|
||||
<<"-m\tmagnify factor of z values of the grid data"<<endl
|
||||
<<"-o\tGmsh's mesh file name. The input filename will be used if -o is absent"<<endl<<endl
|
||||
<<"example: grd2msh test.grd -m1.0 -otest.msh"<<endl;
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
char command_type[1024] = {0};
|
||||
char inputname[1024] = {0};
|
||||
char mshname[1024] = {0};
|
||||
char nametype[1024] = {0};
|
||||
char refSystem[1024] = "NULL";
|
||||
double mg_factor = 1.0;
|
||||
double dx = 0,dy = 0;
|
||||
int n_num = -1, m_num = -1;
|
||||
int Run = 1;
|
||||
int filetype;
|
||||
|
||||
if (argc==1)
|
||||
{
|
||||
disp_help();
|
||||
}
|
||||
else
|
||||
{
|
||||
sscanf(argv[1],"%[^.]%s",inputname,nametype);//按格式读入文件名与扩展名
|
||||
if(!strcmp(inputname,""))//检查文件名是否为空
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[1]<<endl;
|
||||
Run = 0;
|
||||
}
|
||||
|
||||
if (!strcmp(nametype,".grd"))
|
||||
{
|
||||
filetype = 1;
|
||||
sscanf(argv[1],"%s",inputname);
|
||||
}
|
||||
else if (!strcmp(nametype,".dat")||!strcmp(nametype,".xyz"))
|
||||
{
|
||||
filetype = 2;
|
||||
sscanf(argv[1],"%s",inputname);
|
||||
}
|
||||
else
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"unrecognized file type: "<<nametype<<endl;
|
||||
Run = 0;
|
||||
}
|
||||
|
||||
for (int i = 2; i < argc; i++)
|
||||
{
|
||||
sscanf(argv[i],"%2s",command_type);
|
||||
if (!strcmp(command_type,MAGNIFY))
|
||||
{
|
||||
if (1!=sscanf(argv[i],"%*2s%lf",&mg_factor))
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||||
Run = 0;
|
||||
}
|
||||
}
|
||||
else if(!strcmp(command_type,OUTMSH))//命令为文件名设置符
|
||||
{
|
||||
sscanf(argv[i],"%*2s%s",mshname);//按格式读入文件名与扩展名
|
||||
if(!strcmp(mshname,""))//检查文件名是否为空
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||||
Run = 0;
|
||||
}
|
||||
}
|
||||
else if (!strcmp(command_type,INTERVAL))
|
||||
{
|
||||
if(2!=sscanf(argv[i],"%*2s%lf/%lf",&dx,&dy))
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||||
Run = 0;
|
||||
}
|
||||
}
|
||||
else if (!strcmp(command_type,HL))
|
||||
{
|
||||
if(2!=sscanf(argv[i],"%*2s%d/%d",&n_num,&m_num))
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||||
Run = 0;
|
||||
}
|
||||
}
|
||||
else if (!strcmp(command_type,REFER))
|
||||
{
|
||||
if(1!=sscanf(argv[i],"%*2s%s",refSystem))
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||||
Run = 0;
|
||||
}
|
||||
}
|
||||
else //未定义的命令符
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"unrecognized syntax: "<<argv[i]<<endl;
|
||||
Run = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!strcmp(inputname,""))
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"error: bad syntax"<<endl;
|
||||
Run = 0;
|
||||
}
|
||||
else if (!strcmp(mshname,""))
|
||||
{
|
||||
char temp[1024] = {0};
|
||||
char temp2[1024] = {0};
|
||||
sscanf(inputname,"%[^.]%s",temp,temp2);
|
||||
strcpy(mshname,temp);
|
||||
strcat(mshname,".msh");
|
||||
}
|
||||
|
||||
if ((filetype==2&&dx==0)||(filetype==2&&dy==0))
|
||||
{
|
||||
if ((filetype==2&&n_num==-1)||(filetype==2&&m_num==-1))
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"error: bad syntax"<<endl;
|
||||
Run = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (Run)
|
||||
{
|
||||
func F1;
|
||||
F1.run(inputname,mshname,refSystem,mg_factor,filetype,dx,dy,n_num,m_num);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
39
archive/grd2msh/struct.h
Normal file
39
archive/grd2msh/struct.h
Normal file
@@ -0,0 +1,39 @@
|
||||
#ifndef _STRUCT_H
|
||||
#define _STRUCT_H
|
||||
#include "stdio.h"
|
||||
#include "iostream"
|
||||
#include "iomanip"
|
||||
#include "fstream"
|
||||
#include "string.h"
|
||||
#include "sstream"
|
||||
#include "list"
|
||||
#include "cmath"
|
||||
#define RESET "\033[0m" /* reset */
|
||||
#define BOLDRED "\033[1m\033[31m" /* Bold Red */
|
||||
#define INTERVAL "-i"
|
||||
#define HL "-I"
|
||||
#define REFER "-r"
|
||||
#define OUTMSH "-o"
|
||||
#define MAGNIFY "-m"
|
||||
#define Pi (4.0*atan(1.0))
|
||||
#define WGS84_PoleRadius 6356752.3//WGS84椭球极半径
|
||||
#define WGS84_EquatorRadius 6378137//WGS84椭球长半径
|
||||
#define EarthRadius 6371008.8
|
||||
|
||||
using namespace std;
|
||||
|
||||
struct posi
|
||||
{
|
||||
int id;
|
||||
double x,y,z;
|
||||
double alti;
|
||||
};
|
||||
|
||||
typedef list<posi> PosiList;
|
||||
|
||||
//计算一个参考椭球或者参考球在纬度位置的半径
|
||||
double refRadius(double lati,double refr,double refR)
|
||||
{
|
||||
return refr*refR/sqrt(pow(refr,2)*pow(cos((double) lati*Pi/180.0),2)+pow(refR,2)*pow(sin((double) lati*Pi/180.0),2));
|
||||
}
|
||||
#endif
|
||||
35
archive/grid2xyz/datatype.h
Normal file
35
archive/grid2xyz/datatype.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#ifndef _DATATYPE_H
|
||||
#define _DATATYPE_H
|
||||
#include "headfile.h"
|
||||
|
||||
struct arcgis_txt
|
||||
{
|
||||
int ncols,nrows;
|
||||
double xllcorner,yllcorner,cellsize;
|
||||
int NODATA_value;
|
||||
double* data_table;
|
||||
|
||||
void init_data_table()
|
||||
{data_table = NULL;}
|
||||
void set_data_table()
|
||||
{data_table = new double [ncols*nrows];}
|
||||
void clear_data_table()
|
||||
{if(data_table!=NULL) delete[] data_table;}
|
||||
};
|
||||
|
||||
struct surfer_txt
|
||||
{
|
||||
string headstr;
|
||||
int nrows,ncols;
|
||||
double xmin,xmax,ymin,ymax,zmin,zmax;
|
||||
double* data_table;
|
||||
|
||||
void init_data_table()
|
||||
{data_table = NULL;}
|
||||
void set_data_table()
|
||||
{data_table = new double [ncols*nrows];}
|
||||
void clear_data_table()
|
||||
{if(data_table!=NULL) delete[] data_table;}
|
||||
};
|
||||
|
||||
#endif
|
||||
21
archive/grid2xyz/headfile.h
Normal file
21
archive/grid2xyz/headfile.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifndef _HEADFILE_H
|
||||
#define _HEADFILE_H
|
||||
#include "iostream"
|
||||
#include "sstream"
|
||||
#include "fstream"
|
||||
#include "math.h"
|
||||
#include "string.h"
|
||||
#include "stdlib.h"
|
||||
#include "stdio.h"
|
||||
|
||||
#define ARCGIS_TXT "-arcgis_txt"
|
||||
#define SURFER_TXT "-surfer_txt"
|
||||
#define NULLVALUE "-n"
|
||||
#define OUTPUT "-o"
|
||||
#define BOLDRED "\033[1m\033[31m"
|
||||
#define RESET "\033[0m"
|
||||
#define MAX 1e+30
|
||||
|
||||
using namespace std;
|
||||
|
||||
#endif
|
||||
196
archive/grid2xyz/main.cpp
Normal file
196
archive/grid2xyz/main.cpp
Normal file
@@ -0,0 +1,196 @@
|
||||
#include "headfile.h"
|
||||
#include "datatype.h"
|
||||
|
||||
void disp_help()
|
||||
{
|
||||
cout<<"grid2xyz 0.1 - convert various grid data into xyz file"<<endl<<endl
|
||||
<<"usage: grid2xyz <table-data> <data-format> [-n<nodata-value>] [-o<output-file>]"<<endl
|
||||
<<"data-format:"<<endl
|
||||
<<" 1. -arcgis_txt ArcGIS text grid"<<endl
|
||||
<<" 2. -surfer_txt Surfer text grid"<<endl
|
||||
<<" -n sign an alternative value for nodata point, default will put NaN for all nodata point"<<endl<<endl
|
||||
<<"example: data2xyz example.txt -arcgis_txt -n0.0 -oexample_out.xyz"<<endl;
|
||||
}
|
||||
int convert_arcgis_txt(char*,char*,double);
|
||||
int convert_surfer_txt(char*,char*);
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
char cmd_type[1024] = {0};
|
||||
char filename[1024] = {0};
|
||||
char out_filename[1024] = {0};
|
||||
char file_type[1024] = {0};
|
||||
double Nulldata = MAX;
|
||||
int table_type;
|
||||
|
||||
if (argc==1)
|
||||
{
|
||||
disp_help();
|
||||
}
|
||||
else
|
||||
{
|
||||
sscanf(argv[1],"%s",filename);
|
||||
//其他类型在此添加
|
||||
if(!strcmp(argv[2],ARCGIS_TXT)) table_type = 1;
|
||||
else if(!strcmp(argv[2],SURFER_TXT)) table_type = 2;
|
||||
else
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"no supported table format found "<<endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (int i = 3; i < argc; i++)
|
||||
{
|
||||
sscanf(argv[i],"%2s",cmd_type);
|
||||
if (!strcmp(cmd_type,NULLVALUE))
|
||||
{
|
||||
sscanf(argv[i],"%*2s%lf",&Nulldata);
|
||||
if (Nulldata == MAX)
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||||
cout<<"Nodata point set to default"<<endl;
|
||||
}
|
||||
}
|
||||
else if (!strcmp(cmd_type,OUTPUT))
|
||||
{
|
||||
if (-1==sscanf(argv[i],"%*2s%s",out_filename))
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else //未定义的命令符
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!strcmp(out_filename,""))
|
||||
{
|
||||
sscanf(argv[1],"%[^.]%s",out_filename,file_type);
|
||||
strcat(out_filename,".xyz");
|
||||
}
|
||||
|
||||
switch(table_type)
|
||||
{
|
||||
case 1: convert_arcgis_txt(filename,out_filename,Nulldata); break;
|
||||
case 2: convert_surfer_txt(filename,out_filename); break;
|
||||
default: cout<<BOLDRED<<"==> "<<RESET<<"table type outrange"<<endl; break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int convert_arcgis_txt(char* filename,char* outname,double Nullvalue)
|
||||
{
|
||||
ifstream filein(filename);
|
||||
if (!filein)
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"file not found: "<<filename<<endl;
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
arcgis_txt table1;
|
||||
string temp_str;
|
||||
|
||||
filein >> temp_str >> table1.ncols
|
||||
>> temp_str >> table1.nrows
|
||||
>> temp_str >> table1.xllcorner
|
||||
>> temp_str >> table1.yllcorner
|
||||
>> temp_str >> table1.cellsize
|
||||
>> temp_str >> table1.NODATA_value;
|
||||
table1.init_data_table();
|
||||
table1.set_data_table();
|
||||
for (int i = 0; i < table1.ncols*table1.nrows; i++)
|
||||
{
|
||||
filein >> table1.data_table[i];
|
||||
|
||||
}
|
||||
filein.close();
|
||||
|
||||
ofstream fileout(outname);
|
||||
for (int i = 0; i < table1.nrows; i++)
|
||||
{
|
||||
for (int j = 0; j < table1.ncols; j++)
|
||||
{
|
||||
if (table1.data_table[i*table1.ncols+j] == table1.NODATA_value)
|
||||
{
|
||||
if (Nullvalue == MAX)
|
||||
{
|
||||
fileout << table1.yllcorner + table1.nrows*table1.cellsize - i*table1.cellsize << " "
|
||||
<< table1.xllcorner + j*table1.cellsize << " "
|
||||
<< "NaN" << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
fileout << table1.yllcorner + table1.nrows*table1.cellsize - i*table1.cellsize << " "
|
||||
<< table1.xllcorner + j*table1.cellsize << " "
|
||||
<< Nullvalue << endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fileout << table1.yllcorner + table1.nrows*table1.cellsize - i*table1.cellsize << " "
|
||||
<< table1.xllcorner + j*table1.cellsize << " "
|
||||
<< table1.data_table[i*table1.ncols+j] << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
fileout.close();
|
||||
table1.clear_data_table();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int convert_surfer_txt(char* filename,char* outname)
|
||||
{
|
||||
double dx,dy,xtemp,ytemp;
|
||||
ifstream filein(filename);
|
||||
if (!filein)
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"file not found: "<<filename<<endl;
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
surfer_txt table1;
|
||||
string temp_str;
|
||||
|
||||
filein >> table1.headstr;
|
||||
if (table1.headstr != "DSAA")
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"file format is not correct: "<<filename<<endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
filein >> table1.ncols >> table1.nrows
|
||||
>> table1.xmin >> table1.xmax
|
||||
>> table1.ymin >> table1.ymax
|
||||
>> table1.zmin >> table1.zmax;
|
||||
table1.init_data_table();
|
||||
table1.set_data_table();
|
||||
for (int i = 0; i < table1.ncols*table1.nrows; i++)
|
||||
{
|
||||
filein >> table1.data_table[i];
|
||||
|
||||
}
|
||||
filein.close();
|
||||
|
||||
dx = (table1.xmax-table1.xmin)/table1.nrows+1;
|
||||
dy = (table1.ymax-table1.ymin)/table1.ncols+1;
|
||||
|
||||
ofstream fileout(outname);
|
||||
for (int i = 0; i < table1.ncols*table1.nrows; i++)
|
||||
{
|
||||
xtemp = (i%table1.ncols)*dx+table1.xmin;
|
||||
ytemp = (i/table1.ncols)*dy+table1.ymin;
|
||||
|
||||
fileout<<xtemp<<" "<<ytemp<<" "<<table1.data_table[i]<<endl;
|
||||
}
|
||||
fileout.close();
|
||||
table1.clear_data_table();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
245
archive/grid2xyz/surfer2dat/common.h
Normal file
245
archive/grid2xyz/surfer2dat/common.h
Normal file
@@ -0,0 +1,245 @@
|
||||
#ifndef _COMMOND_H
|
||||
#define _COMMOND_H
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#define ELE "-e"
|
||||
#define DAT "-d"
|
||||
#define FIE "-f"
|
||||
#define RANGE "-r"
|
||||
#define OUTPUT "-o"
|
||||
#define MAX 1e+20
|
||||
#define GRD ".grd"
|
||||
using namespace std;
|
||||
|
||||
int typeget(char *str, const char* str2,string &str3)
|
||||
{
|
||||
char* strp = strstr(str, str2); // 从字符串str中查找str2,
|
||||
if (strp == NULL)
|
||||
{
|
||||
return 0; // 如果没有找到,返回
|
||||
}
|
||||
string temp = str;
|
||||
str3=temp.substr(strlen(str2));//提出除str2外的子句
|
||||
return 1;
|
||||
}
|
||||
|
||||
string& replace_all(string& str,const string& old_value,const string& new_value,int &num) //替换str中所有lod_value为new_value,返回被替换的lod_value的个数
|
||||
{
|
||||
int count = 0;
|
||||
for(string::size_type pos(0);pos!=string::npos;pos+=new_value.length()){
|
||||
if((pos=str.find(old_value,pos))!=string::npos){
|
||||
str.replace(pos,old_value.length(),new_value);
|
||||
count++;
|
||||
}
|
||||
else break;
|
||||
}
|
||||
num = count;
|
||||
return str;
|
||||
}
|
||||
|
||||
int nameget(char *str, const char* str2,string &str3)//提出尾端的子句
|
||||
{
|
||||
char* strp = strstr(str, str2); // 从字符串str中查找str2,
|
||||
if (strp == NULL)
|
||||
{
|
||||
return 0; // 如果没有找到,返回
|
||||
}
|
||||
string temp = str;
|
||||
str3=temp.substr(0,strlen(str)-strlen(str2));//提出除str2外的子句
|
||||
return 1;
|
||||
}
|
||||
|
||||
class CON
|
||||
{
|
||||
public:
|
||||
CON();
|
||||
~CON();
|
||||
int run(string,string,string,int,double,double*);
|
||||
int readdata(string,string);
|
||||
int fie(double);
|
||||
int fileout(string,int,double*);
|
||||
private:
|
||||
int M,N;
|
||||
double xmin,xmax,ymin,ymax,zmin,zmax;
|
||||
double dx,dy;
|
||||
double* data;
|
||||
double* relief;
|
||||
};
|
||||
|
||||
CON::CON()
|
||||
{
|
||||
data = NULL;
|
||||
relief = NULL;
|
||||
}
|
||||
|
||||
CON::~CON()
|
||||
{
|
||||
if(data!=NULL) delete[] data;
|
||||
if(relief!=NULL) delete[] relief;
|
||||
}
|
||||
|
||||
int CON::run(string inname,string inname2,string outname,int type,double topo,double* range)
|
||||
{
|
||||
if(readdata(inname,inname2)) return 1;
|
||||
if (type==1&&inname2=="") fie(topo);
|
||||
fileout(outname,type,range);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CON::readdata(string inname,string inname2)
|
||||
{
|
||||
string head;
|
||||
int M2,N2;
|
||||
double xmin2,xmax2,ymin2,ymax2,zmin2,zmax2;
|
||||
|
||||
const char* name1 = inname.c_str();
|
||||
ifstream grdin(name1);
|
||||
if (!grdin)
|
||||
{
|
||||
cout<<inname<<" not found, program stopped..."<<endl;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
grdin>>head>>N>>M>>xmin>>xmax>>ymin>>ymax>>zmin>>zmax;
|
||||
dx = (xmax-xmin)/M+1;
|
||||
dy = (ymax-ymin)/N+1;
|
||||
data = new double [M*N];
|
||||
for (int i = 0; i < M*N; i++)
|
||||
{
|
||||
grdin>>data[i];
|
||||
}
|
||||
grdin.close();
|
||||
}
|
||||
|
||||
if (inname2=="")
|
||||
{
|
||||
relief = new double [M*N];
|
||||
for (int i = 0; i < M*N; i++)
|
||||
{
|
||||
relief[i]=0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
const char* name2 = inname2.c_str();
|
||||
ifstream grd2in(name2);
|
||||
if (!grd2in)
|
||||
{
|
||||
cout<<inname2<<" not found, program stopped..."<<endl;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
grd2in>>head>>N2>>M2>>xmin2>>xmax2>>ymin2>>ymax2>>zmin2>>zmax2;
|
||||
if (N!=N2||M!=M2)
|
||||
{
|
||||
cout<<"data martixs don't agree, program stopped..."<<endl;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
relief = new double [M*N];
|
||||
for (int i = 0; i < M*N; i++)
|
||||
{
|
||||
grd2in>>relief[i];
|
||||
}
|
||||
grd2in.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CON::fie(double topo)
|
||||
{
|
||||
for (int i = 0; i < M*N; i++)
|
||||
{
|
||||
relief[i]=topo;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CON::fileout(string outname,int type,double* range)
|
||||
{
|
||||
double xtemp,ytemp;
|
||||
if ((*range)!=MAX)
|
||||
{
|
||||
double xmin_r = *range;
|
||||
double xmax_r = *(range+1);
|
||||
double ymin_r = *(range+2);
|
||||
double ymax_r = *(range+3);
|
||||
if (type==1)
|
||||
{
|
||||
const char* name = (outname+".fie").c_str();
|
||||
ofstream outfile(name);
|
||||
int count=0;
|
||||
for (int i = 0; i < M*N; i++)
|
||||
{
|
||||
xtemp = (i%N)*dx+xmin;
|
||||
ytemp = (i/N)*dy+ymin;
|
||||
if (xtemp>=xmin_r&&xtemp<=xmax_r&&ytemp>=ymin_r&&ytemp<=ymax_r)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
outfile<<count<<endl;
|
||||
for (int i = 0; i < M*N; i++)
|
||||
{
|
||||
xtemp = (i%N)*dx+xmin;
|
||||
ytemp = (i/N)*dy+ymin;
|
||||
if (xtemp>=xmin_r&&xtemp<=xmax_r&&ytemp>=ymin_r&&ytemp<=ymax_r)
|
||||
{
|
||||
outfile<<setprecision(12)<<xtemp<<" "<<ytemp<<" "<<relief[i]<<" "<<data[i]<<endl;
|
||||
}
|
||||
}
|
||||
outfile.close();
|
||||
}
|
||||
else if (type==2)
|
||||
{
|
||||
const char* name = (outname+".dat").c_str();
|
||||
ofstream outfile(name);
|
||||
for (int i = 0; i < M*N; i++)
|
||||
{
|
||||
xtemp = (i%N)*dx+xmin;
|
||||
ytemp = (i/N)*dy+ymin;
|
||||
if (xtemp>=xmin_r&&xtemp<=xmax_r&&ytemp>=ymin_r&&ytemp<=ymax_r)
|
||||
{
|
||||
outfile<<setprecision(12)<<xtemp<<" "<<ytemp<<" "<<data[i]<<endl;
|
||||
}
|
||||
}
|
||||
outfile.close();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (type==1)
|
||||
{
|
||||
const char* name = (outname+".fie").c_str();
|
||||
ofstream outfile(name);
|
||||
outfile<<M*N<<endl;
|
||||
for (int i = 0; i < M*N; i++)
|
||||
{
|
||||
outfile<<setprecision(12)<<(i%N)*dx+xmin<<" "<<(i/N)*dy+ymin<<" "<<relief[i]<<" "<<data[i]<<endl;
|
||||
}
|
||||
outfile.close();
|
||||
}
|
||||
else if (type==2)
|
||||
{
|
||||
const char* name = (outname+".dat").c_str();
|
||||
ofstream outfile(name);
|
||||
for (int i = 0; i < M*N; i++)
|
||||
{
|
||||
outfile<<setprecision(12)<<(i%N)*dx+xmin<<" "<<(i/N)*dy+ymin<<" "<<data[i]<<endl;
|
||||
}
|
||||
outfile.close();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
120
archive/grid2xyz/surfer2dat/main.cpp
Normal file
120
archive/grid2xyz/surfer2dat/main.cpp
Normal file
@@ -0,0 +1,120 @@
|
||||
#include "common.h"
|
||||
|
||||
void disp_help()
|
||||
{
|
||||
cout<<"surfer2dat 0.5 - convert surfer's grid file into .dat & .fie files"<<endl<<endl
|
||||
<<"usage: surfer2dat input-file -e<input-file2>|-f<elevation|radius>|-d [-r<xmin>/<xmax>/<ymin>/<ymax>] [-o<output-file>]"<<endl
|
||||
<<" -e specify each point's elevation or radius by input-file2 which should be as the same size as input-file"<<endl
|
||||
<<" -f convert to .fie file, elevation or radius of the input data must be given"<<endl
|
||||
<<" -d convert to .dat file"<<endl
|
||||
<<" -r specify the interest area"<<endl
|
||||
<<" -o specify the ouput-name, the input-file's name will be used if -o is absent"<<endl<<endl
|
||||
<<"example: surfer2dat in.grd -d example_out"<<endl;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if (argc==1)
|
||||
{
|
||||
disp_help();
|
||||
}
|
||||
else if (argc==2)
|
||||
{
|
||||
cout<<"too few arguments, program stopped..."<<endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
CON c;
|
||||
int space_num;
|
||||
string temp = "";
|
||||
string input_name = "";
|
||||
string input_name2 = "";
|
||||
string output_name = "";
|
||||
stringstream stemp;
|
||||
int out_type = -1;
|
||||
double range[4] = {MAX,MAX,MAX,MAX};
|
||||
double topo = MAX;
|
||||
|
||||
input_name = argv[1];
|
||||
|
||||
for (int i = 2; i < argc; i++)
|
||||
{
|
||||
if (typeget(argv[i],OUTPUT,temp))//取得输出名
|
||||
{
|
||||
output_name = temp;
|
||||
temp = "";
|
||||
}
|
||||
|
||||
if (typeget(argv[i],ELE,temp))
|
||||
{
|
||||
if (temp=="")
|
||||
{
|
||||
cout<<"no input_name for '-e' command, program stopped..."<<endl;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
input_name2 = temp;
|
||||
temp = "";
|
||||
out_type = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeget(argv[i],FIE,temp))
|
||||
{
|
||||
if (temp=="")
|
||||
{
|
||||
cout<<"no input for '-f' command, program stopped..."<<endl;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
stemp.clear();
|
||||
stemp.str(temp);
|
||||
stemp>>topo;
|
||||
out_type = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!strcmp(argv[i],DAT)) out_type = 2;
|
||||
|
||||
if (typeget(argv[i],RANGE,temp))
|
||||
{
|
||||
replace_all(temp,"/"," ",space_num);
|
||||
stemp.clear();
|
||||
stemp.str(temp);
|
||||
if (space_num==3)
|
||||
{
|
||||
stemp>>range[0]>>range[1]>>range[2]>>range[3];
|
||||
if (range[0]>range[1])
|
||||
{
|
||||
cout<<"wrong x range, program stopped..."<<endl;
|
||||
return 0;
|
||||
}
|
||||
else if (range[2]>range[3])
|
||||
{
|
||||
cout<<"wrong y range, program stopped..."<<endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cout<<"insufficient attributes information, program stoped..."<<endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(output_name=="")
|
||||
{
|
||||
char* fullname;
|
||||
int len = input_name.length();
|
||||
fullname=(char *)malloc((len+1)*sizeof(char));
|
||||
input_name.copy(fullname,len,0);
|
||||
nameget(fullname,GRD,output_name);
|
||||
}
|
||||
if(c.run(input_name,input_name2,output_name,out_type,topo,range)) return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
33
archive/linearmap/.gitignore
vendored
Normal file
33
archive/linearmap/.gitignore
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
# Prerequisites
|
||||
*.d
|
||||
|
||||
# Compiled Object files
|
||||
*.slo
|
||||
*.lo
|
||||
*.o
|
||||
*.obj
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Compiled Dynamic libraries
|
||||
*.so
|
||||
*.dylib
|
||||
*.dll
|
||||
|
||||
# Fortran module files
|
||||
*.mod
|
||||
*.smod
|
||||
|
||||
# Compiled Static libraries
|
||||
*.lai
|
||||
*.la
|
||||
*.a
|
||||
*.lib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
*.ex
|
||||
1
archive/linearmap/README.md
Normal file
1
archive/linearmap/README.md
Normal file
@@ -0,0 +1 @@
|
||||
# 线性特征提取
|
||||
273
archive/linearmap/linearmap.h
Normal file
273
archive/linearmap/linearmap.h
Normal file
@@ -0,0 +1,273 @@
|
||||
#include "iostream"
|
||||
#include "fstream"
|
||||
#include "iomanip"
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
#include "unistd.h"
|
||||
#include "cmath"
|
||||
#include "string.h"
|
||||
#include "sstream"
|
||||
#include "vector"
|
||||
#include "string.h"
|
||||
|
||||
#define pi (atan(1.0)*4.0)
|
||||
#define BOLDRED "\033[1m\033[31m"
|
||||
#define RESET "\033[0m"
|
||||
|
||||
using namespace std;
|
||||
|
||||
struct dpoint
|
||||
{
|
||||
double x,y,val;
|
||||
dpoint()
|
||||
{
|
||||
x = y = val = 0.0;
|
||||
}
|
||||
};
|
||||
typedef vector<dpoint> _dpointArray;
|
||||
|
||||
typedef vector<double> _1dArray;
|
||||
|
||||
int open_infile(ifstream &infile,char* filename)
|
||||
{
|
||||
infile.open(filename);
|
||||
if (!infile)
|
||||
{
|
||||
cout << BOLDRED << "error ==> " << RESET << "file not found: " << filename << endl;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int open_outfile(ofstream &outfile,char* filename)
|
||||
{
|
||||
outfile.open(filename);
|
||||
if (!outfile)
|
||||
{
|
||||
cout << BOLDRED << "error ==> " << RESET << "fail to create the file: " << filename << endl;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
class linearmap
|
||||
{
|
||||
public:
|
||||
linearmap(){}
|
||||
~linearmap(){}
|
||||
_dpointArray readxyz(char*,char*,char*,char*);
|
||||
int outRes(char*);
|
||||
int thetaMap(char*,char*,char*,char*,char*,char*);
|
||||
int THDR(char*,char*,char*,char*,char*,char*);
|
||||
int ASA(char*,char*,char*,char*,char*,char*,char*);
|
||||
int TAHG(char*,char*,char*,char*,char*,char*,char*);
|
||||
private:
|
||||
_dpointArray gradx;
|
||||
_dpointArray grady;
|
||||
_dpointArray gradz;
|
||||
_dpointArray res;
|
||||
};
|
||||
|
||||
_dpointArray linearmap::readxyz(char* filename,char* range,char* interval,char* order)
|
||||
{
|
||||
_dpointArray input_data;
|
||||
_1dArray tempRow;
|
||||
double x,y,data,temp_d;
|
||||
double xmin,xmax,ymin,ymax;
|
||||
double dx,dy;
|
||||
int xnum,ynum;
|
||||
int orders[3];
|
||||
int data_index;
|
||||
string temp_str;
|
||||
stringstream temp_ss;
|
||||
|
||||
//解析数据范围
|
||||
if (4 != sscanf(range,"%lf/%lf/%lf/%lf",&xmin,&xmax,&ymin,&ymax))
|
||||
{
|
||||
cout << BOLDRED << "error ==> " << RESET << "wrong range parameters for the file: " << filename << endl;
|
||||
return input_data;
|
||||
}
|
||||
else if (2 != sscanf(interval,"%lf/%lf",&dx,&dy))
|
||||
{
|
||||
cout << BOLDRED << "error ==> " << RESET << "wrong interval parameters for the file: " << filename << endl;
|
||||
return input_data;
|
||||
}
|
||||
else if (3 != sscanf(order,"%d,%d,%d",&orders[0],&orders[1],&orders[2]))
|
||||
{
|
||||
cout << BOLDRED << "error ==> " << RESET << "wrong order parameters for the file: " << filename << endl;
|
||||
return input_data;
|
||||
}
|
||||
|
||||
//打开文件
|
||||
ifstream datain;
|
||||
if (open_infile(datain,filename)) return input_data;
|
||||
|
||||
//设置input_data大小
|
||||
xnum = round((xmax-xmin)/dx)+1;
|
||||
ynum = round((ymax-ymin)/dy)+1;
|
||||
input_data.resize(xnum*ynum);
|
||||
|
||||
//读入数据
|
||||
while (getline(datain,temp_str))
|
||||
{
|
||||
if (*(temp_str.begin()) == '#') continue;
|
||||
else
|
||||
{
|
||||
//读入行
|
||||
temp_ss.str("");
|
||||
temp_ss.clear();
|
||||
temp_ss.str(temp_str);
|
||||
//解析数据行
|
||||
if(!tempRow.empty()) tempRow.clear();
|
||||
while (temp_ss >> temp_d)
|
||||
{
|
||||
tempRow.push_back(temp_d);
|
||||
}
|
||||
//读入指定位置的数据
|
||||
x = tempRow.at(orders[0]);
|
||||
y = tempRow.at(orders[1]);
|
||||
data = tempRow.at(orders[2]);
|
||||
//存入input_data 从左下到右上
|
||||
data_index = round((x-xmin)/dx) + round((y-ymin)/dy)*xnum;
|
||||
input_data.at(data_index).x = x;
|
||||
input_data.at(data_index).y = y;
|
||||
input_data.at(data_index).val = data;
|
||||
}
|
||||
}
|
||||
|
||||
datain.close();
|
||||
return input_data;
|
||||
}
|
||||
|
||||
int linearmap::outRes(char* filename)
|
||||
{
|
||||
ofstream outfile;
|
||||
if (open_outfile(outfile,filename)) return -1;
|
||||
|
||||
for (int i = 0; i < res.size(); i++)
|
||||
{
|
||||
outfile << res.at(i).x << " " << res.at(i).y << " " << setprecision(16) << res.at(i).val << endl;
|
||||
}
|
||||
outfile.close();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int linearmap::thetaMap(char* xfile,char* zfile,char* ofile,char* ran,char* inter,char* col)
|
||||
{
|
||||
gradx = readxyz(xfile,ran,inter,col);
|
||||
if (gradx.empty()) return -1;
|
||||
|
||||
gradz = readxyz(zfile,ran,inter,col);
|
||||
if (gradz.empty()) return -1;
|
||||
|
||||
if (gradx.size() != gradz.size())
|
||||
{
|
||||
cout << BOLDRED << "error ==> " << RESET << "data amount does not match for thetaMap" << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
res.resize(gradx.size());
|
||||
for (int i = 0; i < res.size(); i++)
|
||||
{
|
||||
res.at(i).x = gradx.at(i).x;
|
||||
res.at(i).y = gradx.at(i).y;
|
||||
if (fabs(gradx.at(i).val) < 1e-20 && gradz.at(i).val > 0)
|
||||
{
|
||||
res.at(i).val = 0.5*pi;
|
||||
}
|
||||
else if (fabs(gradx.at(i).val) < 1e-20 && gradz.at(i).val < 0)
|
||||
{
|
||||
res.at(i).val = -0.5*pi;
|
||||
}
|
||||
else res.at(i).val = atan(gradz.at(i).val/gradx.at(i).val);
|
||||
//转换为度
|
||||
res.at(i).val = res.at(i).val*180.0/pi;
|
||||
}
|
||||
|
||||
if (outRes(ofile)) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int linearmap::THDR(char* xfile,char* yfile,char* ofile,char* ran,char* inter,char* col)
|
||||
{
|
||||
gradx = readxyz(xfile,ran,inter,col);
|
||||
if (gradx.empty()) return -1;
|
||||
|
||||
grady = readxyz(yfile,ran,inter,col);
|
||||
if (grady.empty()) return -1;
|
||||
|
||||
if (gradx.size() != grady.size())
|
||||
{
|
||||
cout << BOLDRED << "error ==> " << RESET << "data amount does not match for thetaMap" << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
res.resize(gradx.size());
|
||||
for (int i = 0; i < res.size(); i++)
|
||||
{
|
||||
res.at(i).x = gradx.at(i).x;
|
||||
res.at(i).y = gradx.at(i).y;
|
||||
res.at(i).val = sqrt(grady.at(i).val*grady.at(i).val + gradx.at(i).val*gradx.at(i).val);
|
||||
}
|
||||
|
||||
if (outRes(ofile)) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int linearmap::ASA(char* xfile,char* yfile,char* zfile,char* ofile,char* ran,char* inter,char* col)
|
||||
{
|
||||
gradx = readxyz(xfile,ran,inter,col);
|
||||
if (gradx.empty()) return -1;
|
||||
|
||||
grady = readxyz(yfile,ran,inter,col);
|
||||
if (grady.empty()) return -1;
|
||||
|
||||
gradz = readxyz(zfile,ran,inter,col);
|
||||
if (gradz.empty()) return -1;
|
||||
|
||||
if (gradx.size() != grady.size() || gradx.size() != gradz.size() || grady.size() != gradz.size())
|
||||
{
|
||||
cout << BOLDRED << "error ==> " << RESET << "data amount does not match for thetaMap" << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
res.resize(gradx.size());
|
||||
for (int i = 0; i < res.size(); i++)
|
||||
{
|
||||
res.at(i).x = gradx.at(i).x;
|
||||
res.at(i).y = gradx.at(i).y;
|
||||
res.at(i).val = sqrt(grady.at(i).val*grady.at(i).val + gradx.at(i).val*gradx.at(i).val + gradz.at(i).val*gradz.at(i).val);
|
||||
}
|
||||
|
||||
if (outRes(ofile)) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int linearmap::TAHG(char* xfile,char* yfile,char* zfile,char* ofile,char* ran,char* inter,char* col)
|
||||
{
|
||||
gradx = readxyz(xfile,ran,inter,col);
|
||||
if (gradx.empty()) return -1;
|
||||
|
||||
grady = readxyz(yfile,ran,inter,col);
|
||||
if (grady.empty()) return -1;
|
||||
|
||||
gradz = readxyz(zfile,ran,inter,col);
|
||||
if (gradz.empty()) return -1;
|
||||
|
||||
if (gradx.size() != grady.size() || gradx.size() != gradz.size() || grady.size() != gradz.size())
|
||||
{
|
||||
cout << BOLDRED << "error ==> " << RESET << "data amount does not match for thetaMap" << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
res.resize(gradx.size());
|
||||
for (int i = 0; i < res.size(); i++)
|
||||
{
|
||||
res.at(i).x = gradx.at(i).x;
|
||||
res.at(i).y = gradx.at(i).y;
|
||||
res.at(i).val = sqrt(gradz.at(i).val/sqrt(grady.at(i).val*grady.at(i).val + gradx.at(i).val*gradx.at(i).val));
|
||||
}
|
||||
|
||||
if (outRes(ofile)) return -1;
|
||||
return 0;
|
||||
}
|
||||
129
archive/linearmap/main.cpp
Normal file
129
archive/linearmap/main.cpp
Normal file
@@ -0,0 +1,129 @@
|
||||
#include "linearmap.h"
|
||||
|
||||
void disp_help()
|
||||
{
|
||||
cout << "linearmap - v0.1 plot linear structures using gravity gradient data" << endl
|
||||
<< "Author: zhangyi.cugwuhan@gmail.com" << endl
|
||||
<< "usage: linearmap [-x<grad-x>] [-y<grad-y>] [-z<grad-z>] -o<output-file> -t<type> -r<xmin>/<xmax>/<ymin>/<ymax> -i<interval-x>/<interval-y> [-d<x-col>,<y-col>,<z-col>] [-h]" << endl
|
||||
<< "-x\tgravity gradient data in x-direction" << endl
|
||||
<< "-y\tgravity gradient data in y-direction" << endl
|
||||
<< "-z\tgravity gradient data in z-direction" << endl
|
||||
<< "-o\toutput filename" << endl
|
||||
<< "-t\tcalculation type, available types are shown as bellow" << endl
|
||||
<< "\tthetaMap: Need gravity gradient data in x and z directions" << endl
|
||||
<< "\tTHDR: Need gravity gradient data in x and y directions" << endl
|
||||
<< "\tASA: Need gravity gradient data in x, y and z directions" << endl
|
||||
<< "\tTAHG: Need gradient data of the THDR in x, y and z directions" << endl
|
||||
<< "-r\tdata range of the input data" << endl
|
||||
<< "-i\tdata interval of the input data" << endl
|
||||
<< "-d\tdata columns of the input data, the default is 0,1,2" << endl
|
||||
<< "-h\tshow this info" << endl;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
linearmap lm;
|
||||
char gradxName[1024] = "NULL";
|
||||
char gradyName[1024] = "NULL";
|
||||
char gradzName[1024] = "NULL";
|
||||
char outName[1024] = "untitled.xyz";
|
||||
char runType[1024] = "NULL";
|
||||
char rangeName[1024] = "NULL";
|
||||
char intervalName[1024] = "NULL";
|
||||
char cols[1024] = "0,1,2";
|
||||
|
||||
opterr = 0; //内置参数 若不为0则会在发生遭遇错误时输出一条信息到屏幕
|
||||
|
||||
int curr;
|
||||
/*循环拾取参数 最后一个参数为-1 需要变量的参数后跟一个冒号 可有可无参数跟两个冒号*/
|
||||
while((curr = getopt(argc,argv,"hx:y:z:o:t:r:i:d:")) != -1)
|
||||
{
|
||||
/*匹配命令*/
|
||||
switch (curr)
|
||||
{
|
||||
case 'h': //显示帮助信息
|
||||
disp_help();
|
||||
break;
|
||||
case 'x':
|
||||
if (1!=sscanf(optarg,"%s",gradxName))
|
||||
{
|
||||
cout << "error ==> wrong format of " << optarg << endl;
|
||||
}
|
||||
break;
|
||||
case 'y':
|
||||
if (1!=sscanf(optarg,"%s",gradyName))
|
||||
{
|
||||
cout << "error ==> wrong format of " << optarg << endl;
|
||||
}
|
||||
break;
|
||||
case 'z':
|
||||
if (1!=sscanf(optarg,"%s",gradzName))
|
||||
{
|
||||
cout << "error ==> wrong format of " << optarg << endl;
|
||||
}
|
||||
break;
|
||||
case 'o':
|
||||
if (1!=sscanf(optarg,"%s",outName))
|
||||
{
|
||||
cout << "error ==> wrong format of " << optarg << endl;
|
||||
}
|
||||
break;
|
||||
case 't':
|
||||
if (1!=sscanf(optarg,"%s",runType))
|
||||
{
|
||||
cout << "error ==> wrong format of " << optarg << endl;
|
||||
}
|
||||
break;
|
||||
case 'r':
|
||||
if (1!=sscanf(optarg,"%s",rangeName))
|
||||
{
|
||||
cout << "error ==> wrong format of " << optarg << endl;
|
||||
}
|
||||
break;
|
||||
case 'i':
|
||||
if (1!=sscanf(optarg,"%s",intervalName))
|
||||
{
|
||||
cout << "error ==> wrong format of " << optarg << endl;
|
||||
}
|
||||
break;
|
||||
case 'd':
|
||||
if (1!=sscanf(optarg,"%s",cols))
|
||||
{
|
||||
cout << "error ==> wrong format of " << optarg << endl;
|
||||
}
|
||||
break;
|
||||
case '?': //处理未定义或错误参数
|
||||
if (optopt == 'x' || optopt == 'y' || optopt == 'z' || optopt == 'o'
|
||||
|| optopt == 't' || optopt == 'r' || optopt == 'i' || optopt == 'd')
|
||||
{
|
||||
fprintf (stderr, "Option -%c requires an argument.\n", optopt);
|
||||
return -1;
|
||||
}
|
||||
else if (isprint(optopt))
|
||||
{
|
||||
fprintf (stderr, "Unknown option `-%c'.\n", optopt);
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf (stderr,"Unknown option character `\\x%x'.\n",optopt);
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
if (!strcmp(runType,"thetaMap"))
|
||||
lm.thetaMap(gradxName,gradzName,outName,rangeName,intervalName,cols);
|
||||
else if (!strcmp(runType,"THDR"))
|
||||
lm.THDR(gradxName,gradyName,outName,rangeName,intervalName,cols);
|
||||
else if (!strcmp(runType,"ASA"))
|
||||
lm.ASA(gradxName,gradyName,gradzName,outName,rangeName,intervalName,cols);
|
||||
else if (!strcmp(runType,"TAHG"))
|
||||
lm.TAHG(gradxName,gradyName,gradzName,outName,rangeName,intervalName,cols);
|
||||
else
|
||||
cout << "unknown type: " << runType << endl << "use -h option to see help information" << endl;
|
||||
return 0;
|
||||
}
|
||||
15
archive/linearmap/makefile
Normal file
15
archive/linearmap/makefile
Normal file
@@ -0,0 +1,15 @@
|
||||
CC = g++-9
|
||||
PROM = /usr/local/sbin/linearmap
|
||||
CFLAGS = -I.
|
||||
DEPS = $(shell find . -name "*.h")
|
||||
SRC = $(shell find . -name "*.cpp")
|
||||
OBJ = $(SRC:%.cpp=%.o)
|
||||
|
||||
$(PROM): $(OBJ)
|
||||
$(CC) -o $(PROM) $(OBJ) $(CFLAGS)
|
||||
|
||||
%.o:%.cpp $(DEPS)
|
||||
$(CC) -c $< -o $@ $(CFLAGS)
|
||||
|
||||
clean:
|
||||
rm -rf $(OBJ)
|
||||
BIN
archive/msh2obj/examples/cube.fbx
Normal file
BIN
archive/msh2obj/examples/cube.fbx
Normal file
Binary file not shown.
13
archive/msh2obj/examples/cube.mtl
Normal file
13
archive/msh2obj/examples/cube.mtl
Normal file
@@ -0,0 +1,13 @@
|
||||
newmtl cube
|
||||
Ns 10.0000
|
||||
Ni 1.5000
|
||||
d 1.0000
|
||||
Tr 0.0000
|
||||
Tf 1.0000 1.0000 1.0000
|
||||
illum 2
|
||||
Ka 0.0000 0.0000 0.0000
|
||||
Kd 0.5880 0.5880 0.5880
|
||||
Ks 0.0000 0.0000 0.0000
|
||||
Ke 0.0000 0.0000 0.0000
|
||||
map_Ka cube.png
|
||||
map_Kd cube.png
|
||||
BIN
archive/msh2obj/examples/cube.png
Normal file
BIN
archive/msh2obj/examples/cube.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.7 KiB |
BIN
archive/msh2obj/examples/duck.fbx
Normal file
BIN
archive/msh2obj/examples/duck.fbx
Normal file
Binary file not shown.
13
archive/msh2obj/examples/duck.mtl
Normal file
13
archive/msh2obj/examples/duck.mtl
Normal file
@@ -0,0 +1,13 @@
|
||||
# Blender MTL File: 'None'
|
||||
# Material Count: 1
|
||||
|
||||
newmtl blinn3
|
||||
Ns 96.078431
|
||||
Ka 0.000000 0.000000 0.000000
|
||||
Kd 0.640000 0.640000 0.640000
|
||||
Ks 0.000000 0.000000 0.000000
|
||||
Ni 1.000000
|
||||
d 1.000000
|
||||
illum 2
|
||||
map_Ka duckCM.png
|
||||
map_Kd duckCM.png
|
||||
BIN
archive/msh2obj/examples/duckCM.png
Normal file
BIN
archive/msh2obj/examples/duckCM.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 32 KiB |
BIN
archive/msh2obj/materials/GMT_rainbow.png
Normal file
BIN
archive/msh2obj/materials/GMT_rainbow.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 945 B |
BIN
archive/msh2obj/materials/GMT_seis.png
Normal file
BIN
archive/msh2obj/materials/GMT_seis.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.0 KiB |
BIN
archive/msh2obj/materials/arctic.png
Normal file
BIN
archive/msh2obj/materials/arctic.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.3 KiB |
44
archive/msh2obj/materials/default.mtl
Normal file
44
archive/msh2obj/materials/default.mtl
Normal file
@@ -0,0 +1,44 @@
|
||||
# newmtl [name] 材质名称
|
||||
# Ns [0~1000] 反射高光度 值越高则高光越密集
|
||||
# Ni [0.001~10] 折射值 若取值为1.0 光在通过物体的时候不发生弯曲 玻璃的折射率为1.5
|
||||
# Ka [0~1] [0~1] [0~1] 材质的环境光 阴影色(ambient color)
|
||||
# Kd [0~1] [0~1] [0~1] 散射光 固有色(diffuse color)
|
||||
# Ks [0~1] [0~1] [0~1] 镜面光 高光色(specular color)
|
||||
# d [0~1] 渐隐指数描述 参数factor表示物体融入背景的数量 取值范围为0.0~1.0 取值为1.0表示完全不透明 取值为0.0时表示完全透明
|
||||
# illum 1
|
||||
# map_Ka [pic-file]
|
||||
# map_Kd [pic-file]
|
||||
# map_Ks [pic-file]
|
||||
|
||||
newmtl gmt_seis
|
||||
Ns 96.078431
|
||||
Ni 1.000000
|
||||
Ka 0.100000 0.100000 0.100000
|
||||
Kd 0.640000 0.640000 0.640000
|
||||
Ks 0.000000 0.000000 0.000000
|
||||
d 1.0
|
||||
illum 1
|
||||
map_Ka GMT_seis.png
|
||||
map_Kd GMT_seis.png
|
||||
|
||||
newmtl gmt_rainbow
|
||||
Ns 96.078431
|
||||
Ni 1.000000
|
||||
Ka 0.100000 0.100000 0.100000
|
||||
Kd 0.640000 0.640000 0.640000
|
||||
Ks 0.000000 0.000000 0.000000
|
||||
d 1.0
|
||||
illum 1
|
||||
map_Ka GMT_rainbow.png
|
||||
map_Kd GMT_rainbow.png
|
||||
|
||||
newmtl arctic
|
||||
Ns 96.078431
|
||||
Ni 1.000000
|
||||
Ka 0.100000 0.100000 0.100000
|
||||
Kd 0.640000 0.640000 0.640000
|
||||
Ks 0.000000 0.000000 0.000000
|
||||
d 1.0
|
||||
illum 1
|
||||
map_Ka arctic.png
|
||||
map_Kd arctic.png
|
||||
44
archive/msh2obj/oldfiles/GMT_colorPattern.mtl
Normal file
44
archive/msh2obj/oldfiles/GMT_colorPattern.mtl
Normal file
@@ -0,0 +1,44 @@
|
||||
# newmtl [name] 材质名称
|
||||
# Ns [0~1000] 反射高光度 值越高则高光越密集
|
||||
# Ni [0.001~10] 折射值 若取值为1.0 光在通过物体的时候不发生弯曲 玻璃的折射率为1.5
|
||||
# Ka [0~1] [0~1] [0~1] 材质的环境光 阴影色(ambient color)
|
||||
# Kd [0~1] [0~1] [0~1] 散射光 固有色(diffuse color)
|
||||
# Ks [0~1] [0~1] [0~1] 镜面光 高光色(specular color)
|
||||
# d [0~1] 渐隐指数描述 参数factor表示物体融入背景的数量 取值范围为0.0~1.0 取值为1.0表示完全不透明 取值为0.0时表示完全透明
|
||||
# illum 1
|
||||
# map_Ka [pic-file]
|
||||
# map_Kd [pic-file]
|
||||
# map_Ks [pic-file]
|
||||
|
||||
newmtl seis
|
||||
Ns 96.078431
|
||||
Ni 1.000000
|
||||
Ka 0.100000 0.100000 0.100000
|
||||
Kd 0.640000 0.640000 0.640000
|
||||
Ks 0.000000 0.000000 0.000000
|
||||
d 1.0
|
||||
illum 1
|
||||
map_Ka GMT_seis.png
|
||||
map_Kd GMT_seis.png
|
||||
|
||||
newmtl rainbow
|
||||
Ns 96.078431
|
||||
Ni 1.000000
|
||||
Ka 0.100000 0.100000 0.100000
|
||||
Kd 0.640000 0.640000 0.640000
|
||||
Ks 0.000000 0.000000 0.000000
|
||||
d 1.0
|
||||
illum 1
|
||||
map_Ka GMT_rainbow.png
|
||||
map_Kd GMT_rainbow.png
|
||||
|
||||
newmtl arctic
|
||||
Ns 96.078431
|
||||
Ni 1.000000
|
||||
Ka 0.100000 0.100000 0.100000
|
||||
Kd 0.640000 0.640000 0.640000
|
||||
Ks 0.000000 0.000000 0.000000
|
||||
d 1.0
|
||||
illum 1
|
||||
map_Ka arctic.png
|
||||
map_Kd arctic.png
|
||||
10263
archive/msh2obj/oldfiles/input.msh
Normal file
10263
archive/msh2obj/oldfiles/input.msh
Normal file
File diff suppressed because it is too large
Load Diff
3116
archive/msh2obj/oldfiles/input2.msh
Normal file
3116
archive/msh2obj/oldfiles/input2.msh
Normal file
File diff suppressed because it is too large
Load Diff
BIN
archive/msh2obj/oldfiles/msh2obj
Normal file
BIN
archive/msh2obj/oldfiles/msh2obj
Normal file
Binary file not shown.
168
archive/msh2obj/oldfiles/msh2obj.cpp
Normal file
168
archive/msh2obj/oldfiles/msh2obj.cpp
Normal file
@@ -0,0 +1,168 @@
|
||||
#include "iostream"
|
||||
#include "fstream"
|
||||
#include "sstream"
|
||||
#include "iomanip"
|
||||
#include "string.h"
|
||||
#include "cmath"
|
||||
#include "vector"
|
||||
|
||||
#define ZERO 1e-20
|
||||
#define Pi (4.0*atan(1.0))
|
||||
|
||||
using namespace std;
|
||||
|
||||
struct point{
|
||||
double x,y,z;
|
||||
};
|
||||
typedef vector<point> pointArray;
|
||||
|
||||
struct spoint
|
||||
{
|
||||
double lon,lat,rad;
|
||||
};
|
||||
typedef vector<spoint> spointArray;
|
||||
|
||||
struct vertex : public point{
|
||||
int id;
|
||||
double attri;
|
||||
};
|
||||
typedef vector<vertex> vertexArray;
|
||||
|
||||
struct face{
|
||||
int id;
|
||||
int vec[3] = {-1,-1,-1};
|
||||
point outNor;
|
||||
};
|
||||
typedef vector<face> faceArray;
|
||||
|
||||
point normal(point a){
|
||||
point out = a;
|
||||
double module = sqrt(a.x*a.x+a.y*a.y+a.z*a.z);
|
||||
out.x /= module; out.y /= module; out.z /= module;
|
||||
return out;
|
||||
}
|
||||
|
||||
point operator -(point a,point b){
|
||||
point out;
|
||||
out.x = a.x - b.x;
|
||||
out.y = a.y - b.y;
|
||||
out.z = a.z - b.z;
|
||||
return out;
|
||||
}
|
||||
|
||||
point operator -(vertex a,vertex b){
|
||||
point out;
|
||||
out.x = a.x - b.x;
|
||||
out.y = a.y - b.y;
|
||||
out.z = a.z - b.z;
|
||||
return out;
|
||||
}
|
||||
|
||||
point cross(point a,point b){
|
||||
point out;
|
||||
out.x = a.y*b.z-a.z*b.y;
|
||||
out.y = a.z*b.x-a.x*b.z;
|
||||
out.z = a.x*b.y-a.y*b.x;
|
||||
return out;
|
||||
}
|
||||
|
||||
spoint c2s(vertex c)
|
||||
{
|
||||
spoint s;
|
||||
s.rad = sqrt(c.x*c.x+c.y*c.y+c.z*c.z);
|
||||
if (fabs(s.rad)<ZERO) //点距离原点极近 将点置于原点
|
||||
{
|
||||
s.lat = s.lon = s.rad = 0.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
s.lat = 90.0 - acos(c.z/s.rad)*180.0/Pi;
|
||||
s.lon = atan2(c.y,c.x)*180.0/Pi;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[]){
|
||||
vertex node;
|
||||
face triangle;
|
||||
vertexArray nodes;
|
||||
faceArray triangles;
|
||||
|
||||
int temp_int,temp_int2;
|
||||
string temp_str;
|
||||
stringstream temp_ss;
|
||||
|
||||
double attriMax = -1e+30;
|
||||
double attriMin = 1e+30;
|
||||
ifstream mshin("input2.msh");
|
||||
while(getline(mshin,temp_str)){
|
||||
if (!strcmp(temp_str.c_str(),"$Nodes")){
|
||||
getline(mshin,temp_str);
|
||||
temp_ss.str(""); temp_ss.clear(); temp_ss.str(temp_str);
|
||||
temp_ss >> temp_int;
|
||||
for (int i = 0; i < temp_int; i++){
|
||||
getline(mshin,temp_str);
|
||||
temp_ss.str(""); temp_ss.clear(); temp_ss.str(temp_str);
|
||||
temp_ss >> node.id >> node.x >> node.y >> node.z;
|
||||
nodes.push_back(node);
|
||||
}
|
||||
}
|
||||
else if (!strcmp(temp_str.c_str(),"$Elements")){
|
||||
getline(mshin,temp_str);
|
||||
temp_ss.str(""); temp_ss.clear(); temp_ss.str(temp_str);
|
||||
temp_ss >> temp_int;
|
||||
for (int i = 0; i < temp_int; i++){
|
||||
getline(mshin,temp_str);
|
||||
temp_ss.str(""); temp_ss.clear(); temp_ss.str(temp_str);
|
||||
temp_ss >> triangle.id >> temp_int2 >> temp_int2 >> temp_int2
|
||||
>> triangle.vec[0] >> triangle.vec[1] >> triangle.vec[2];
|
||||
//triangle.vec[0] += 1; triangle.vec[1] += 1; triangle.vec[2] += 1;
|
||||
triangle.id += 1;
|
||||
triangles.push_back(triangle);
|
||||
}
|
||||
}
|
||||
else if (!strcmp(temp_str.c_str(),"$NodeData")){
|
||||
for (int i = 0; i < 8; i++)
|
||||
getline(mshin,temp_str);
|
||||
temp_ss.str(""); temp_ss.clear(); temp_ss.str(temp_str);
|
||||
temp_ss >> temp_int;
|
||||
for (int i = 0; i < temp_int; i++){
|
||||
getline(mshin,temp_str);
|
||||
temp_ss.str(""); temp_ss.clear(); temp_ss.str(temp_str);
|
||||
temp_ss >> temp_int2 >> nodes[i].attri;
|
||||
if(nodes[i].attri > attriMax) attriMax = nodes[i].attri;
|
||||
if(nodes[i].attri < attriMin) attriMin = nodes[i].attri;
|
||||
}
|
||||
}
|
||||
else continue;
|
||||
}
|
||||
mshin.close();
|
||||
|
||||
for (int i = 0; i < nodes.size(); i++)
|
||||
nodes[i].attri = (nodes[i].attri - attriMin)/(attriMax - attriMin);
|
||||
|
||||
for (int i = 0; i < triangles.size(); i++){
|
||||
triangles[i].outNor = normal(cross(nodes[triangles[i].vec[1]-1]-nodes[triangles[i].vec[0]-1],
|
||||
nodes[triangles[i].vec[2]-1]-nodes[triangles[i].vec[0]-1]));
|
||||
}
|
||||
|
||||
ofstream objout("sphere.obj");
|
||||
objout << "mtllib global_topography.mtl" << endl << "o sphere" << endl;
|
||||
for (int i = 0; i < nodes.size(); i++){
|
||||
objout << "v " << setprecision(16) << nodes[i].x << " " << nodes[i].y << " " << nodes[i].z << endl;
|
||||
}
|
||||
for (int i = 0; i < nodes.size(); i++){
|
||||
objout << "vt " << setprecision(16) << nodes[i].attri << " 0.5" << endl;
|
||||
}
|
||||
for (int i = 0; i < triangles.size(); i++){
|
||||
objout << "vn " << setprecision(16) << triangles[i].outNor.x << " " << triangles[i].outNor.y << " " << triangles[i].outNor.z << endl;
|
||||
}
|
||||
objout << "usemtl earth-topo" << endl << "g model1" << endl << "s 1" << endl;
|
||||
for (int i = 0; i < triangles.size(); i++){
|
||||
objout << "f " << triangles[i].vec[0] << "/" << triangles[i].vec[0] << "/" << i+1 << " "
|
||||
<< triangles[i].vec[1] << "/" << triangles[i].vec[1] << "/" << i+1 << " "
|
||||
<< triangles[i].vec[2] << "/" << triangles[i].vec[2] << "/" << i+1 << endl;
|
||||
}
|
||||
objout.close();
|
||||
return 0;
|
||||
}
|
||||
5
archive/msh2vtk/CMakeLists.txt
Normal file
5
archive/msh2vtk/CMakeLists.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
add_executable(msh2vtk main.cpp)
|
||||
# 第二种方式指定目标文件的路径 这个方式目标文件夹中将只包含目标文件而没有中间文件
|
||||
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
|
||||
# 设置安装地址
|
||||
install(TARGETS msh2vtk RUNTIME DESTINATION selfpro)
|
||||
256
archive/msh2vtk/func_msh2vtk.h
Normal file
256
archive/msh2vtk/func_msh2vtk.h
Normal file
@@ -0,0 +1,256 @@
|
||||
#ifndef _FUNC_MSH2VTK_H
|
||||
#define _FUNC_MSH2VTK_H
|
||||
#include "sysDefine_msh2vtk.h"
|
||||
|
||||
class mshvtk
|
||||
{
|
||||
private:
|
||||
nodeArray nArray;
|
||||
elementArray eArray;
|
||||
nodeDataArray ndArray;
|
||||
elementDataArray edArray;
|
||||
typesMap msh2vtk_type;
|
||||
typesMap type_nodenum;
|
||||
typesMap::iterator itm;
|
||||
int nodenum;
|
||||
int elenum;
|
||||
|
||||
strArray outNames;
|
||||
public:
|
||||
mshvtk(){
|
||||
msh2vtk_type[1] = 3;
|
||||
msh2vtk_type[2] = 5;
|
||||
msh2vtk_type[3] = 9;
|
||||
msh2vtk_type[4] = 10;
|
||||
msh2vtk_type[5] = 12;
|
||||
msh2vtk_type[6] = 13; //注意三棱柱顶点序列gmsh和vtk貌似有点区别 上下底面的三角形顶点排序刚好相反
|
||||
|
||||
type_nodenum[1] = 2;
|
||||
type_nodenum[2] = 3;
|
||||
type_nodenum[3] = 4;
|
||||
type_nodenum[4] = 4;
|
||||
type_nodenum[5] = 8;
|
||||
type_nodenum[6] = 6;
|
||||
}
|
||||
~mshvtk(){}
|
||||
int runtine(char*);
|
||||
int addname(char*);
|
||||
int readmsh(char*); //注意这里的文件名都是不带.msh后缀的
|
||||
int writevtk(char*); //注意这里的文件名需要添加.vtk后缀
|
||||
};
|
||||
|
||||
int mshvtk::runtine(char* parachar)
|
||||
{
|
||||
if(readmsh(parachar)) return -1;
|
||||
if(writevtk(parachar)) return -1;
|
||||
nArray.clear();
|
||||
ndArray.clear();
|
||||
eArray.clear();
|
||||
edArray.clear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mshvtk::addname(char* onename)
|
||||
{
|
||||
string s = onename;
|
||||
s = "\""+s+"\"";
|
||||
outNames.push_back(s);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mshvtk::readmsh(char* inname)
|
||||
{
|
||||
int temp_int,ele_num;
|
||||
node temp_node;
|
||||
element temp_element;
|
||||
nodeData temp_node_data;
|
||||
elementData temp_element_data;
|
||||
string temp_str;
|
||||
stringstream temp_ss;
|
||||
char filename[1024];
|
||||
|
||||
strcpy(filename,inname);
|
||||
strcat(filename,".msh");
|
||||
ifstream infile;
|
||||
if(open_infile(infile,filename)) return -1;
|
||||
|
||||
while(getline(infile,temp_str))
|
||||
{
|
||||
if (temp_str == "$Nodes")
|
||||
{
|
||||
getline(infile,temp_str);
|
||||
temp_ss.clear(); temp_ss.str(""); temp_ss << temp_str;
|
||||
temp_ss >> nodenum;
|
||||
for (int i = 0; i < nodenum; i++)
|
||||
{
|
||||
getline(infile,temp_str);
|
||||
temp_ss.clear();
|
||||
temp_ss << temp_str;
|
||||
temp_ss >> temp_node.id >> temp_node.x >> temp_node.y >> temp_node.z;
|
||||
nArray.push_back(temp_node);
|
||||
}
|
||||
}
|
||||
else if (temp_str == "$Elements")
|
||||
{
|
||||
getline(infile,temp_str);
|
||||
temp_ss.clear(); temp_ss.str(""); temp_ss << temp_str;
|
||||
temp_ss >> ele_num;
|
||||
for (int i = 0; i < ele_num; i++)
|
||||
{
|
||||
temp_element.msh_info.clear();
|
||||
temp_element.nodes_index.clear();
|
||||
getline(infile,temp_str);
|
||||
temp_ss.clear(); temp_ss.str(""); temp_ss << temp_str;
|
||||
temp_ss >> temp_element.id >> temp_element.msh_type >> temp_element.msh_info_num;
|
||||
for (int j = 0; j < temp_element.msh_info_num; j++)
|
||||
{
|
||||
temp_ss >> temp_int;
|
||||
temp_element.msh_info.push_back(temp_int);
|
||||
}
|
||||
for (int j = 0; j < type_nodenum[temp_element.msh_type]; j++)
|
||||
{
|
||||
temp_ss >> temp_int;
|
||||
if (nArray[0].id == 1)
|
||||
{
|
||||
temp_element.nodes_index.push_back(temp_int-1);
|
||||
}
|
||||
else temp_element.nodes_index.push_back(temp_int);
|
||||
}
|
||||
temp_element.vtk_type = msh2vtk_type[temp_element.msh_type];
|
||||
eArray.push_back(temp_element);
|
||||
}
|
||||
}
|
||||
else if (temp_str == "$ElementData")
|
||||
{
|
||||
temp_element_data.ids.clear();
|
||||
temp_element_data.val.clear();
|
||||
|
||||
getline(infile,temp_str);
|
||||
temp_ss.clear(); temp_ss.str(""); temp_ss << temp_str;
|
||||
temp_ss >> temp_int;
|
||||
for (int i = 0; i < temp_int; i++)
|
||||
{
|
||||
getline(infile,temp_str);
|
||||
temp_element_data.name = temp_str;
|
||||
}
|
||||
//跳过6行
|
||||
for (int i = 0; i < 6; i++)
|
||||
getline(infile,temp_str);
|
||||
temp_ss.clear(); temp_ss.str(""); temp_ss << temp_str;
|
||||
temp_ss >> temp_int;
|
||||
|
||||
temp_element_data.ids.resize(temp_int);
|
||||
temp_element_data.val.resize(temp_int);
|
||||
for (int i = 0; i < temp_int; i++)
|
||||
{
|
||||
getline(infile,temp_str);
|
||||
temp_ss.clear(); temp_ss.str(""); temp_ss << temp_str;
|
||||
temp_ss >> temp_element_data.ids[i] >> temp_element_data.val[i];
|
||||
}
|
||||
edArray.push_back(temp_element_data);
|
||||
}
|
||||
else if (temp_str == "$NodeData")
|
||||
{
|
||||
temp_node_data.ids.clear();
|
||||
temp_node_data.val.clear();
|
||||
|
||||
getline(infile,temp_str);
|
||||
temp_ss.clear(); temp_ss.str(""); temp_ss << temp_str;
|
||||
temp_ss >> temp_int;
|
||||
for (int i = 0; i < temp_int; i++)
|
||||
{
|
||||
getline(infile,temp_str);
|
||||
temp_node_data.name = temp_str;
|
||||
}
|
||||
//跳过6行
|
||||
for (int i = 0; i < 6; i++)
|
||||
getline(infile,temp_str);
|
||||
temp_ss.clear(); temp_ss.str(""); temp_ss << temp_str;
|
||||
temp_ss >> temp_int;
|
||||
|
||||
temp_node_data.ids.resize(temp_int);
|
||||
temp_node_data.val.resize(temp_int);
|
||||
for (int i = 0; i < temp_int; i++)
|
||||
{
|
||||
getline(infile,temp_str);
|
||||
temp_ss.clear(); temp_ss.str(""); temp_ss << temp_str;
|
||||
temp_ss >> temp_node_data.ids[i] >> temp_node_data.val[i];
|
||||
}
|
||||
ndArray.push_back(temp_node_data);
|
||||
}
|
||||
}
|
||||
infile.close();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mshvtk::writevtk(char* inname)
|
||||
{
|
||||
int temp_int;
|
||||
string temp_dataName;
|
||||
int totalCellNum = 0;
|
||||
char filename[1024];
|
||||
strcpy(filename,inname);
|
||||
strcat(filename,".vtk");
|
||||
ofstream outfile;
|
||||
if(open_outfile(outfile,filename)) return -1;
|
||||
|
||||
outfile<<"# vtk DataFile Version 2.0"<<endl<<"Generated by msh2vtk"<<endl<<"ASCII"<<endl<<"DATASET UNSTRUCTURED_GRID"<<endl<<"POINTS "<<nArray.size()<<" FLOAT"<<endl;
|
||||
for (int i = 0; i < nArray.size(); i++)
|
||||
{
|
||||
outfile << setprecision(16) << nArray.at(i).x << " " << nArray.at(i).y << " " << nArray.at(i).z << endl;
|
||||
}
|
||||
//计算一下CELLS的总长 注意类型名算一个 所以要加1
|
||||
for (int i = 0; i < eArray.size(); i++)
|
||||
{
|
||||
totalCellNum += type_nodenum[eArray.at(i).msh_type] + 1;
|
||||
}
|
||||
outfile<<"CELLS "<<eArray.size()<<" "<<totalCellNum<<endl;
|
||||
for (int i = 0; i < eArray.size(); i++)
|
||||
{
|
||||
outfile << type_nodenum[eArray.at(i).msh_type] << " ";
|
||||
for (int j = 0; j < eArray.at(i).nodes_index.size(); j++)
|
||||
{
|
||||
outfile << eArray.at(i).nodes_index.at(j) << " ";
|
||||
}
|
||||
outfile << endl;
|
||||
}
|
||||
outfile << "CELL_TYPES " << eArray.size() << endl;
|
||||
for (int i = 0; i < eArray.size(); i++)
|
||||
{
|
||||
outfile << eArray.at(i).vtk_type << " ";
|
||||
}
|
||||
outfile << endl;
|
||||
for (int i = 0; i < ndArray.size(); i++)
|
||||
{
|
||||
for (int n = 0; n < outNames.size(); n++)
|
||||
{
|
||||
if (outNames[n] == ndArray[i].name)
|
||||
{
|
||||
temp_dataName = replace_all(ndArray[i].name," ","_",temp_int);
|
||||
outfile<<"POINT_DATA "<<ndArray[i].val.size()<<endl<<"SCALARS " << temp_dataName << " FLOAT"<<endl<<"LOOKUP_TABLE default"<<endl;
|
||||
for (int j = 0; j < ndArray[i].val.size(); j++)
|
||||
{
|
||||
outfile<<setprecision(16)<<ndArray[i].val[j]<<endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < edArray.size(); i++)
|
||||
{
|
||||
for (int n = 0; n < outNames.size(); n++)
|
||||
{
|
||||
if (outNames[n] == edArray[i].name)
|
||||
{
|
||||
temp_dataName = replace_all(edArray[i].name," ","_",temp_int);
|
||||
outfile<<"CELL_DATA "<<edArray[i].val.size()<<endl<<"SCALARS " << temp_dataName << " FLOAT"<<endl<<"LOOKUP_TABLE default"<<endl;
|
||||
for (int j = 0; j < edArray[i].val.size(); j++)
|
||||
{
|
||||
outfile<<setprecision(16)<<edArray[i].val[j]<<endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
outfile.close();
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
25
archive/msh2vtk/main.cpp
Normal file
25
archive/msh2vtk/main.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#include "func_msh2vtk.h"
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
mshvtk mv;
|
||||
char mshname[1024];
|
||||
char dataname[1024];
|
||||
if (argc == 1)
|
||||
{
|
||||
cout << "msh2vtk <msh-file> <data-name> [<data-name> ...]" << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
sscanf(argv[1],"%[^.]",mshname);
|
||||
|
||||
for (int i = 2; i < argc; i++)
|
||||
{
|
||||
sscanf(argv[i],"%[^\0]",dataname);
|
||||
mv.addname(dataname);
|
||||
}
|
||||
|
||||
mv.runtine(mshname);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
15
archive/msh2vtk/makefile
Normal file
15
archive/msh2vtk/makefile
Normal file
@@ -0,0 +1,15 @@
|
||||
CC = g++-8
|
||||
PROM = /usr/local/sbin/msh2vtk
|
||||
CFLAGS = -I.
|
||||
DEPS = $(shell find . -name "*.h")
|
||||
SRC = $(shell find . -name "*.cpp")
|
||||
OBJ = $(SRC:%.cpp=%.o)
|
||||
|
||||
$(PROM): $(OBJ)
|
||||
$(CC) -o $(PROM) $(OBJ) $(CFLAGS) -O2
|
||||
|
||||
%.o:%.cpp $(DEPS)
|
||||
$(CC) -c $< -o $@ $(CFLAGS) -O2
|
||||
|
||||
clean:
|
||||
rm -rf $(OBJ)
|
||||
97
archive/msh2vtk/sysDefine_msh2vtk.h
Normal file
97
archive/msh2vtk/sysDefine_msh2vtk.h
Normal file
@@ -0,0 +1,97 @@
|
||||
#ifndef _SYSDEFINE_MSH2VTK_H
|
||||
#define _SYSDEFINE_MSH2VTK_H
|
||||
#include "iostream"
|
||||
#include "fstream"
|
||||
#include "string.h"
|
||||
#include "sstream"
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
#include "iomanip"
|
||||
#include "cmath"
|
||||
#include "vector"
|
||||
#include "map"
|
||||
|
||||
#define BOLDRED "\033[1m\033[31m"
|
||||
#define RESET "\033[0m"
|
||||
|
||||
using namespace std;
|
||||
|
||||
typedef vector<int> _1iArray;
|
||||
typedef vector<double> _1dArray;
|
||||
typedef vector<string> strArray;
|
||||
typedef map<int,int> typesMap;
|
||||
|
||||
struct node
|
||||
{
|
||||
int id;
|
||||
double x, y, z;
|
||||
};
|
||||
typedef vector<node> nodeArray;
|
||||
|
||||
struct element
|
||||
{
|
||||
int id;
|
||||
int msh_type;
|
||||
int vtk_type;
|
||||
int msh_info_num;
|
||||
_1iArray msh_info;
|
||||
_1iArray nodes_index;
|
||||
};
|
||||
typedef vector<element> elementArray;
|
||||
|
||||
struct elementData
|
||||
{
|
||||
_1iArray ids;
|
||||
string name;
|
||||
_1dArray val;
|
||||
};
|
||||
typedef vector<elementData> elementDataArray;
|
||||
|
||||
struct nodeData
|
||||
{
|
||||
_1iArray ids;
|
||||
string name;
|
||||
_1dArray val;
|
||||
};
|
||||
typedef vector<nodeData> nodeDataArray;
|
||||
|
||||
//全局函数
|
||||
int open_infile(ifstream &infile,char* filename)
|
||||
{
|
||||
infile.open(filename);
|
||||
if (!infile)
|
||||
{
|
||||
cout << BOLDRED << "error ==> " << RESET << "file not found: " << filename << endl;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int open_outfile(ofstream &outfile,char* filename)
|
||||
{
|
||||
outfile.open(filename);
|
||||
if (!outfile)
|
||||
{
|
||||
cout << BOLDRED << "error ==> " << RESET << "fail to create the file: " << filename << endl;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//替换str中所有lod_value为new_value,返回被替换的old_value的个数
|
||||
string& replace_all(string& str,const string& old_value,const string& new_value,int &num)
|
||||
{
|
||||
int count = 0;
|
||||
for(string::size_type pos(0);pos!=string::npos;pos+=new_value.length())
|
||||
{
|
||||
if((pos=str.find(old_value,pos))!=string::npos)
|
||||
{
|
||||
str.replace(pos,old_value.length(),new_value);
|
||||
count++;
|
||||
}
|
||||
else break;
|
||||
}
|
||||
num = count;
|
||||
return str;
|
||||
}
|
||||
#endif
|
||||
163863
archive/msh2vtk/test/relief-v3-withUSGSdata.msh
Executable file
163863
archive/msh2vtk/test/relief-v3-withUSGSdata.msh
Executable file
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user