Loading include/Home.h +0 −8 Original line number Diff line number Diff line Loading @@ -84,14 +84,6 @@ typedef struct { int optPaired; } Option_t; typedef struct { double x,y,z; } Point_t; typedef struct { double x,y,z; } Line_t; typedef struct { vector<string> variables; vector<vector<double> > data; Loading include/Util.h +13 −0 Original line number Diff line number Diff line Loading @@ -19,9 +19,22 @@ #include <algorithm> #include <numeric> typedef struct { double x,y,z; } Point_t; typedef struct { vector<double> ax, ay, az; } Curve_t; void Fatal(const char *format, ...); vector<string> split(const string& str, const string& delim); void WashString(string &str); int GetValID(const vector<Var_t> &vals, const string &name); int GetColIDFromTable(const Table_t &table, const string &name); vector<double> GenerateSequence(double from, double to, double meshSize); void FoldBox(real8 boundMin[3], real8 boundMax[3], real8 *x, real8 *y, real8 *z); real8 LinearInterpolation(const Curve_t &curve, real8 x, real8 min = -1, real8 max = -1); #endif src/HandleExtendedDislocation.cpp +115 −8 Original line number Diff line number Diff line Loading @@ -7,23 +7,130 @@ using namespace std; bool cmp(Point_t p, Point_t q) { return(p.x < q.x); } void HandleExtendedDislocation(InArgs_t *inArgs) { Table_t table; real8 boundMin[3], boundMax[3], size = 10000; int index; string bound = "bound"; real8 cubel = 20000, boundMin[3], boundMax[3]; real8 remeshSize = 20.0, burgID1 = 7, burgID2 = 12; int index, i; int colX, colY, colBurgID; string cubelName = "cubel", burgIDName = "burgID", remeshSizeName = "rsize"; Point_t p; vector<Point_t> points1, points2; Curve_t curve1, curve2; vector<real8> seq; vector<vector<double> > data(3); if((index = GetValID(inArgs->priVars, cubelName)) < inArgs->priVars.size()){ cubel = stof(inArgs->priVars[index].vals[0]); } printf("The cubel size is %f\n", cubel); boundMin[0] = -0.5*cubel; boundMin[1] = -0.5*cubel; boundMin[2] = -0.5*cubel; boundMax[0] = 0.5*cubel; boundMax[1] = 0.5*cubel; boundMax[2] = 0.5*cubel; if((index = GetValID(inArgs->priVars, burgIDName)) < inArgs->priVars.size()){ if(inArgs->priVars[index].vals.size() == 2){ burgID1 = stoi(inArgs->priVars[index].vals[0]); burgID2 = stoi(inArgs->priVars[index].vals[1]); } } printf("The burgID of two partials are %2.0f %2.0f\n", burgID1, burgID2); if((index = GetValID(inArgs->priVars, remeshSizeName)) < inArgs->priVars.size()){ remeshSize = stof(inArgs->priVars[index].vals[0]); } printf("The remesh size is %f\n", remeshSize); ReadTecplotNormalData(inArgs->inpFiles[0], table); if((index = GetValID(inArgs->priVars, bound)) < inArgs->priVars.size()){ size = stof(inArgs->priVars[index].vals[0]); printf("size is %f\n", size); if(table.data.size() < 2)Fatal("the data size is %d", table.data.size()); colX = GetColIDFromTable(table, "X"); colY = GetColIDFromTable(table, "Y"); colBurgID = GetColIDFromTable(table, "burgID"); p.x = 1.0E10; p.y = 1.0E10; for(i=0; i<table.data.size(); i++){ if(p.x == table.data[i][colX] && p.y == table.data[i][colY])continue; p.x = table.data[i][colX]; p.y = table.data[i][colY]; if(burgID1 == table.data[i][colBurgID]){ points1.push_back(p); }else if(burgID2 == table.data[i][colBurgID]){ points2.push_back(p); }else{ continue; } } sort(points1.begin(), points1.end(), cmp); sort(points2.begin(), points2.end(), cmp); curve1.ax.resize(points1.size()); curve1.ay.resize(points1.size()); curve2.ax.resize(points2.size()); curve2.ay.resize(points2.size()); for(i=0; i<points1.size(); i++){ curve1.ax[i] = points1[i].x; curve1.ay[i] = points1[i].y; } for(i=0; i<points2.size(); i++){ curve2.ax[i] = points2[i].x; curve2.ay[i] = points2[i].y; } seq = GenerateSequence(boundMin[0], boundMax[0], remeshSize); data[0].assign(seq.begin(), seq.end()); for(i=0; i<seq.size(); i++){ data[1].push_back(LinearInterpolation(curve1, seq[i], boundMin[0], boundMax[0])); data[2].push_back(LinearInterpolation(curve2, seq[i], boundMin[0], boundMax[0])); } printf("variables = x, y1, y2\n"); for(i=0; i<seq.size(); i++){ printf("%f %f %f \n", data[0][i], data[1][i], data[2][i]); } return; } src/ReadData.cpp +10 −2 Original line number Diff line number Diff line Loading @@ -7,7 +7,7 @@ using namespace std; int ReadTecplotNormalData(string &file, Table_t &table) { int lineNo = 1, i; int lineNo = 1, i, j; string str; ifstream infile; Loading @@ -29,6 +29,13 @@ int ReadTecplotNormalData(string &file, Table_t &table) for(i=0; i<table.variables.size(); i++)WashString(table.variables[i]); col.resize(table.variables.size()); printf("Read in %s, variables are ", file.c_str()); for(i=0; i<table.variables.size(); i++){ printf("%s ", table.variables[i].c_str()); } printf("\n"); j = 0; while(getline(infile,str)) { lineNo++; Loading @@ -38,8 +45,9 @@ int ReadTecplotNormalData(string &file, Table_t &table) for(i=0; i<col.size(); i++){ col[i] = atof(line[i].c_str()); } table.data.push_back(col); j++; } printf("%d lines has been read.\n", j); return 1; } src/Util.cpp +114 −2 Original line number Diff line number Diff line Loading @@ -12,7 +12,7 @@ void Fatal(const char *format, ...) vsnprintf(msg, sizeof(msg)-1, format, args); msg[sizeof(msg)-1] = 0; va_end(args); printf("Fatal: %s\n", msg); printf("ERROR: %s\n", msg); exit(1); } Loading Loading @@ -46,7 +46,6 @@ void WashString(string &str) int GetValID(const vector<Var_t> &vals, const string &name) { vector<string> strs; int i; for(i=0; i<vals.size(); i++){ Loading @@ -56,12 +55,125 @@ int GetValID(const vector<Var_t> &vals, const string &name) return(i); } int GetColIDFromTable(const Table_t &table, const string &name) { int i; for(i=0; i<table.variables.size(); i++){ if(name == table.variables[i])break; } return(i); } vector<double> GenerateSequence(double from, double to, double meshSize) { double nums, sign; double i; nums = (to-from)/fabs(meshSize); sign = (nums >= 0) ? 1.0:-1.0; nums = fabs(nums); if(nums - floor(nums) != 0){ nums++; } vector<double> seq((int)(nums)); for(i=0; i<nums-1; i++){ seq[(int)i] = from + i*fabs(meshSize)*sign; } seq[(int)i] = to; return(seq); } void FoldBox(real8 boundMin[3], real8 boundMax[3], real8 *x, real8 *y, real8 *z) { real8 xc, yc, zc; real8 invLx, invLy, invLz, Lx, Ly, Lz; xc = (boundMin[0] + boundMax[0]) * 0.5; yc = (boundMin[1] + boundMax[1]) * 0.5; zc = (boundMin[2] + boundMax[2]) * 0.5; Lx = boundMax[0] - boundMin[0]; invLx = 1.0/Lx; Ly = boundMax[1] - boundMin[1]; invLy = 1.0/Ly; Lz = boundMax[2] - boundMin[2]; invLz = 1.0/Lz; *x -= rint((*x-xc)*invLx) * Lx; *y -= rint((*y-yc)*invLy) * Ly; *z -= rint((*z-zc)*invLz) * Lz; return; } real8 LinearInterpolation(const Curve_t &curve, real8 x, real8 min, real8 max) { real8 length, xc; real8 x0, y0, x1, y1, t, boundVal; int i; if(curve.ax.size()<2) Fatal("there is no engough data for interpolation"); if(curve.ax[0] == curve.ax.back()) Fatal("the range of line is zero in LineInterpolation"); if(min == max){ min = curve.ax[0]; max = curve.ax.back(); } length = max - min; if(length == 0)Fatal("the range of line is zero in LineInterpolation"); xc = 0.5*(min + max); x -= rint((x-xc)/length) * length; if(x>=curve.ax[0] && x<=curve.ax.back()){ for(i=1; i<curve.ax.size(); i++){ if(x<curve.ax[i])break; } x0 = curve.ax[i-1]; y0 = curve.ay[i-1]; x1 = curve.ax[i]; y1 = curve.ay[i]; }else{ x0 = curve.ax.back() - length; y0 = curve.ay.back(); x1 = curve.ax[0]; y1 = curve.ay[0]; boundVal = y0 + (y1-y0)*(x1-min)/(x1-x0); if(x < curve.ax[0]){ x0 = min; y0 = boundVal; x1 = curve.ax[0]; y1 = curve.ay[0]; }else{ x0 = curve.ax.back(); y0 = curve.ay.back(); x1 = max; y1 = boundVal; } } if(x<x0 || x>x1)Fatal("something wrong with linearInterpolation %f, %f, %f", x, x0, x1); return(y1+(y1-y0)*(x-x0)/(x1-x0)); } Loading Loading
include/Home.h +0 −8 Original line number Diff line number Diff line Loading @@ -84,14 +84,6 @@ typedef struct { int optPaired; } Option_t; typedef struct { double x,y,z; } Point_t; typedef struct { double x,y,z; } Line_t; typedef struct { vector<string> variables; vector<vector<double> > data; Loading
include/Util.h +13 −0 Original line number Diff line number Diff line Loading @@ -19,9 +19,22 @@ #include <algorithm> #include <numeric> typedef struct { double x,y,z; } Point_t; typedef struct { vector<double> ax, ay, az; } Curve_t; void Fatal(const char *format, ...); vector<string> split(const string& str, const string& delim); void WashString(string &str); int GetValID(const vector<Var_t> &vals, const string &name); int GetColIDFromTable(const Table_t &table, const string &name); vector<double> GenerateSequence(double from, double to, double meshSize); void FoldBox(real8 boundMin[3], real8 boundMax[3], real8 *x, real8 *y, real8 *z); real8 LinearInterpolation(const Curve_t &curve, real8 x, real8 min = -1, real8 max = -1); #endif
src/HandleExtendedDislocation.cpp +115 −8 Original line number Diff line number Diff line Loading @@ -7,23 +7,130 @@ using namespace std; bool cmp(Point_t p, Point_t q) { return(p.x < q.x); } void HandleExtendedDislocation(InArgs_t *inArgs) { Table_t table; real8 boundMin[3], boundMax[3], size = 10000; int index; string bound = "bound"; real8 cubel = 20000, boundMin[3], boundMax[3]; real8 remeshSize = 20.0, burgID1 = 7, burgID2 = 12; int index, i; int colX, colY, colBurgID; string cubelName = "cubel", burgIDName = "burgID", remeshSizeName = "rsize"; Point_t p; vector<Point_t> points1, points2; Curve_t curve1, curve2; vector<real8> seq; vector<vector<double> > data(3); if((index = GetValID(inArgs->priVars, cubelName)) < inArgs->priVars.size()){ cubel = stof(inArgs->priVars[index].vals[0]); } printf("The cubel size is %f\n", cubel); boundMin[0] = -0.5*cubel; boundMin[1] = -0.5*cubel; boundMin[2] = -0.5*cubel; boundMax[0] = 0.5*cubel; boundMax[1] = 0.5*cubel; boundMax[2] = 0.5*cubel; if((index = GetValID(inArgs->priVars, burgIDName)) < inArgs->priVars.size()){ if(inArgs->priVars[index].vals.size() == 2){ burgID1 = stoi(inArgs->priVars[index].vals[0]); burgID2 = stoi(inArgs->priVars[index].vals[1]); } } printf("The burgID of two partials are %2.0f %2.0f\n", burgID1, burgID2); if((index = GetValID(inArgs->priVars, remeshSizeName)) < inArgs->priVars.size()){ remeshSize = stof(inArgs->priVars[index].vals[0]); } printf("The remesh size is %f\n", remeshSize); ReadTecplotNormalData(inArgs->inpFiles[0], table); if((index = GetValID(inArgs->priVars, bound)) < inArgs->priVars.size()){ size = stof(inArgs->priVars[index].vals[0]); printf("size is %f\n", size); if(table.data.size() < 2)Fatal("the data size is %d", table.data.size()); colX = GetColIDFromTable(table, "X"); colY = GetColIDFromTable(table, "Y"); colBurgID = GetColIDFromTable(table, "burgID"); p.x = 1.0E10; p.y = 1.0E10; for(i=0; i<table.data.size(); i++){ if(p.x == table.data[i][colX] && p.y == table.data[i][colY])continue; p.x = table.data[i][colX]; p.y = table.data[i][colY]; if(burgID1 == table.data[i][colBurgID]){ points1.push_back(p); }else if(burgID2 == table.data[i][colBurgID]){ points2.push_back(p); }else{ continue; } } sort(points1.begin(), points1.end(), cmp); sort(points2.begin(), points2.end(), cmp); curve1.ax.resize(points1.size()); curve1.ay.resize(points1.size()); curve2.ax.resize(points2.size()); curve2.ay.resize(points2.size()); for(i=0; i<points1.size(); i++){ curve1.ax[i] = points1[i].x; curve1.ay[i] = points1[i].y; } for(i=0; i<points2.size(); i++){ curve2.ax[i] = points2[i].x; curve2.ay[i] = points2[i].y; } seq = GenerateSequence(boundMin[0], boundMax[0], remeshSize); data[0].assign(seq.begin(), seq.end()); for(i=0; i<seq.size(); i++){ data[1].push_back(LinearInterpolation(curve1, seq[i], boundMin[0], boundMax[0])); data[2].push_back(LinearInterpolation(curve2, seq[i], boundMin[0], boundMax[0])); } printf("variables = x, y1, y2\n"); for(i=0; i<seq.size(); i++){ printf("%f %f %f \n", data[0][i], data[1][i], data[2][i]); } return; }
src/ReadData.cpp +10 −2 Original line number Diff line number Diff line Loading @@ -7,7 +7,7 @@ using namespace std; int ReadTecplotNormalData(string &file, Table_t &table) { int lineNo = 1, i; int lineNo = 1, i, j; string str; ifstream infile; Loading @@ -29,6 +29,13 @@ int ReadTecplotNormalData(string &file, Table_t &table) for(i=0; i<table.variables.size(); i++)WashString(table.variables[i]); col.resize(table.variables.size()); printf("Read in %s, variables are ", file.c_str()); for(i=0; i<table.variables.size(); i++){ printf("%s ", table.variables[i].c_str()); } printf("\n"); j = 0; while(getline(infile,str)) { lineNo++; Loading @@ -38,8 +45,9 @@ int ReadTecplotNormalData(string &file, Table_t &table) for(i=0; i<col.size(); i++){ col[i] = atof(line[i].c_str()); } table.data.push_back(col); j++; } printf("%d lines has been read.\n", j); return 1; }
src/Util.cpp +114 −2 Original line number Diff line number Diff line Loading @@ -12,7 +12,7 @@ void Fatal(const char *format, ...) vsnprintf(msg, sizeof(msg)-1, format, args); msg[sizeof(msg)-1] = 0; va_end(args); printf("Fatal: %s\n", msg); printf("ERROR: %s\n", msg); exit(1); } Loading Loading @@ -46,7 +46,6 @@ void WashString(string &str) int GetValID(const vector<Var_t> &vals, const string &name) { vector<string> strs; int i; for(i=0; i<vals.size(); i++){ Loading @@ -56,12 +55,125 @@ int GetValID(const vector<Var_t> &vals, const string &name) return(i); } int GetColIDFromTable(const Table_t &table, const string &name) { int i; for(i=0; i<table.variables.size(); i++){ if(name == table.variables[i])break; } return(i); } vector<double> GenerateSequence(double from, double to, double meshSize) { double nums, sign; double i; nums = (to-from)/fabs(meshSize); sign = (nums >= 0) ? 1.0:-1.0; nums = fabs(nums); if(nums - floor(nums) != 0){ nums++; } vector<double> seq((int)(nums)); for(i=0; i<nums-1; i++){ seq[(int)i] = from + i*fabs(meshSize)*sign; } seq[(int)i] = to; return(seq); } void FoldBox(real8 boundMin[3], real8 boundMax[3], real8 *x, real8 *y, real8 *z) { real8 xc, yc, zc; real8 invLx, invLy, invLz, Lx, Ly, Lz; xc = (boundMin[0] + boundMax[0]) * 0.5; yc = (boundMin[1] + boundMax[1]) * 0.5; zc = (boundMin[2] + boundMax[2]) * 0.5; Lx = boundMax[0] - boundMin[0]; invLx = 1.0/Lx; Ly = boundMax[1] - boundMin[1]; invLy = 1.0/Ly; Lz = boundMax[2] - boundMin[2]; invLz = 1.0/Lz; *x -= rint((*x-xc)*invLx) * Lx; *y -= rint((*y-yc)*invLy) * Ly; *z -= rint((*z-zc)*invLz) * Lz; return; } real8 LinearInterpolation(const Curve_t &curve, real8 x, real8 min, real8 max) { real8 length, xc; real8 x0, y0, x1, y1, t, boundVal; int i; if(curve.ax.size()<2) Fatal("there is no engough data for interpolation"); if(curve.ax[0] == curve.ax.back()) Fatal("the range of line is zero in LineInterpolation"); if(min == max){ min = curve.ax[0]; max = curve.ax.back(); } length = max - min; if(length == 0)Fatal("the range of line is zero in LineInterpolation"); xc = 0.5*(min + max); x -= rint((x-xc)/length) * length; if(x>=curve.ax[0] && x<=curve.ax.back()){ for(i=1; i<curve.ax.size(); i++){ if(x<curve.ax[i])break; } x0 = curve.ax[i-1]; y0 = curve.ay[i-1]; x1 = curve.ax[i]; y1 = curve.ay[i]; }else{ x0 = curve.ax.back() - length; y0 = curve.ay.back(); x1 = curve.ax[0]; y1 = curve.ay[0]; boundVal = y0 + (y1-y0)*(x1-min)/(x1-x0); if(x < curve.ax[0]){ x0 = min; y0 = boundVal; x1 = curve.ax[0]; y1 = curve.ay[0]; }else{ x0 = curve.ax.back(); y0 = curve.ay.back(); x1 = max; y1 = boundVal; } } if(x<x0 || x>x1)Fatal("something wrong with linearInterpolation %f, %f, %f", x, x0, x1); return(y1+(y1-y0)*(x-x0)/(x1-x0)); } Loading