Skip to content

Instantly share code, notes, and snippets.

@cwsmith
Last active May 8, 2018 12:06
Show Gist options
  • Save cwsmith/99c95f1ec78389375ce3d32b3e234661 to your computer and use it in GitHub Desktop.
Save cwsmith/99c95f1ec78389375ce3d32b3e234661 to your computer and use it in GitHub Desktop.
gmodel for an airfoil
#include <gmodel.hpp>
#include <minidiff.hpp>
#include <vector>
#include <cassert>
#include <iostream>
#include <fstream>
#include <sstream>
bool readFileCoords(std::string filePath, std::vector<float>& buffer) {
std::ifstream file(filePath, std::ios::binary);
if (file.fail()) {
perror(filePath.c_str());
return false;
}
for(std::string line; std::getline(file, line); ) {
if(line.at(0) == '%')
continue;
std::istringstream in(line);
std::string type;
float x, y;
in >> x >> y;
buffer.push_back(x);
buffer.push_back(y);
}
file.close();
return true;
}
int main(int argc, char** argv)
{
assert(argc==3);
std::string in = std::string(argv[1]);
std::string geo = std::string(argv[2]) + ".geo";
std::string dmg = std::string(argv[2]) + ".dmg";
std::vector<float> xy;
bool read = readFileCoords(in, xy);
assert(read);
auto spline_pts = std::vector<gmod::PointPtr>();
auto first = gmod::new_point2(gmod::Vector{xy[0],xy[1],0});
spline_pts.push_back(first);
for(size_t i=2; i<xy.size(); i+=2) {
auto a = gmod::new_point2(gmod::Vector{xy[i],xy[i+1],0});
spline_pts.push_back(a);
}
//close the spline with the starting point object
spline_pts.push_back(first);
auto l = gmod::new_loop();
auto spline = gmod::new_spline2(spline_pts);
gmod::add_use(l, gmod::FORWARD, spline);
auto origin = gmod::Vector{-.5,-.5,0};
auto xlim = gmod::Vector{2,0,0};
auto ylim = gmod::Vector{0,1,0};
auto sq = gmod::new_square(origin,xlim,ylim);
gmod::add_hole_to_face(sq,l);
write_closure_to_geo(sq,geo.c_str());
write_closure_to_dmg(sq,dmg.c_str());
return 0;
}
% EPPLER 625 AIRFOIL from http://www.texample.net/tikz/examples/airfoil-profiles/
1.0000000 0.0000000
0.9900000 0.0012100
0.9800000 0.0024400
0.9700000 0.0036800
0.9500000 0.0061900
0.9250000 0.0094300
0.9000000 0.0128000
0.8750000 0.0163300
0.8500000 0.0199900
0.8250000 0.0238000
0.8000000 0.0277100
0.7750000 0.0317000
0.7500000 0.0357400
0.7250000 0.0398200
0.7000000 0.0439100
0.6750000 0.0479900
0.6500000 0.0520300
0.6000000 0.0599600
0.5500000 0.0674900
0.5000000 0.0744500
0.4500000 0.0806700
0.4000000 0.0859200
0.3500000 0.0899600
0.3000000 0.0924800
0.2750000 0.0930600
0.2500000 0.0930900
0.2250000 0.0925100
0.2000000 0.0911800
0.1750000 0.0889300
0.1500000 0.0855800
0.1250000 0.0808800
0.1000000 0.0745400
0.0750000 0.0660300
0.0500000 0.0544200
0.0350000 0.0452100
0.0250000 0.0376300
0.0200000 0.0332200
0.0150000 0.0282300
0.0125000 0.0254300
0.0100000 0.0223500
0.0075000 0.0188600
0.0050000 0.0147700
0.0040000 0.0129000
0.0030000 0.0108400
0.0025000 0.0097300
0.0020000 0.0085500
0.0015000 0.0072900
0.0010000 0.0058800
0.0005000 0.0041700
0.0000000 0.0002400
0.0005000 -.0033100
0.0010000 -.0046800
0.0015000 -.0057200
0.0020000 -.0065800
0.0025000 -.0073200
0.0030000 -.0079600
0.0040000 -.0090200
0.0050000 -.0098800
0.0075000 -.0114900
0.0100000 -.0126800
0.0125000 -.0136700
0.0150000 -.0145700
0.0200000 -.0162100
0.0250000 -.0176600
0.0350000 -.0200600
0.0500000 -.0227400
0.0750000 -.0258600
0.1000000 -.0280600
0.1250000 -.0297600
0.1500000 -.0311600
0.1750000 -.0323700
0.2000000 -.0334800
0.2250000 -.0345400
0.2500000 -.0355600
0.2750000 -.0365600
0.3000000 -.0375200
0.3500000 -.0393400
0.4000000 -.0408800
0.4500000 -.0420300
0.5000000 -.0427200
0.5500000 -.0428800
0.6000000 -.0424500
0.6500000 -.0413200
0.6750000 -.0404200
0.7000000 -.0392600
0.7250000 -.0378100
0.7500000 -.0360200
0.7750000 -.0338800
0.8000000 -.0313900
0.8250000 -.0285100
0.8500000 -.0252200
0.8750000 -.0215700
0.9000000 -.0176000
0.9250000 -.0134000
0.9500000 -.0090200
0.9700000 -.0054400
0.9800000 -.0036300
0.9900000 -.0018200
1.0000000 0.0000000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment