initial upload

This commit is contained in:
2024-09-10 20:25:18 +08:00
parent b8de03ee4f
commit f1cc876972
377 changed files with 2721267 additions and 34 deletions

View 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;
}
}

View 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;
}

View 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)