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

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

View File

@@ -0,0 +1,2 @@
grav2d_vectical_cylinder: vec_cyliner.cpp vec_cyliner.h
g++ vec_cyliner.cpp -o grav2d_vectical_cylinder

View 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",&para[0],&para[1],&para[2],&para[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;
}

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