Commit 4a623001 authored by Michael Turner's avatar Michael Turner
Browse files

internal naca generator, nearly finished

parent 5833f3ed
......@@ -53,16 +53,29 @@ bool CADSystemOCE::LoadCAD()
{
cout << "trying " << m_name << endl;
// Takes step file and makes OpenCascade shape
STEPControl_Reader reader;
reader = STEPControl_Reader();
reader.ReadFile(m_name.c_str());
reader.NbRootsForTransfer();
reader.TransferRoots();
shape = reader.OneShape();
if (shape.IsNull())
if (m_name.find('.') != std::string::npos)
{
return false;
// Takes step file and makes OpenCascade shape
STEPControl_Reader reader;
reader = STEPControl_Reader();
reader.ReadFile(m_name.c_str());
reader.NbRootsForTransfer();
reader.TransferRoots();
shape = reader.OneShape();
if (shape.IsNull())
{
return false;
}
}
else
{
cout << "assuming " << m_name << " is a 4 digit naca code" << endl;
shape = BuildNACA(m_name);
STEPControl_Writer writer;
writer.Transfer(shape,STEPControl_ShellBasedSurfaceModel);
writer.Write("test.stp");
exit(-1);
}
// faces and verts can be extracted straight from shape
......@@ -351,5 +364,104 @@ Array<OneD, NekDouble> CADSystemOCE::GetBoundingBox()
return bound;
}
TopoDS_Shape CADSystemOCE::BuildNACA(string naca)
{
ASSERTL0(naca.length() == 4, "not a 4 digit code");
int n = boost::lexical_cast<int>(naca);
NekDouble T = (n%100) / 100.0;
n/=100;
NekDouble P = (n%10)/10.0;
n/=10;
NekDouble M = (n%10)/100.0;
Array<OneD, NekDouble> xc(100);
NekDouble dtheta = M_PI/99;
for(int i = 0; i < 100; i++)
{
xc[i] = (1.0 - cos(i*dtheta)) / 2.0;
}
Array<OneD, NekDouble> yc(100), dyc(100);
for(int i = 0; i < 100; i++)
{
if(xc[i] < P)
{
yc[i] = M / P / P * (2.0 * P * xc[i] - xc[i] * xc[i]);
dyc[i] = 2.0 * M / P / P * (P - xc[i]);
}
else
{
yc[i] = M / (1.0 - P) / (1.0 - P) * (1.0 - 2.0 * P + 2.0 * P * xc[i] - xc[i] * xc[i]);
dyc[i] = 2.0 * M / (1.0 - P) / (1.0 - P) * (P - xc[i]);
}
}
Array<OneD, NekDouble> yt(100);
for(int i = 0; i < 100; i++)
{
yt[i] = T / 0.2 * ( 0.2969 * sqrt(xc[i])
-0.1260 * xc[i]
-0.3516 * xc[i] * xc[i]
+0.2843 * xc[i] * xc[i] * xc[i]
-0.1015 * xc[i] * xc[i] * xc[i] * xc[i]);
}
Array<OneD, NekDouble> x(199), y(199);
int l = 0;
for(int i = 99; i >= 0; i--, l++)
{
NekDouble theta = atan(dyc[i]);
x[l] = xc[i] - yt[i] * sin(theta);
y[l] = yc[i] + yt[i] * cos(theta);
}
for(int i = 1; i < 100; i++)
{
NekDouble theta = atan(dyc[i]);
x[i+99] = xc[i] + yt[i] * sin(theta);
y[i+99] = yc[i] - yt[i] * cos(theta);
}
Handle(TColgp_HArray1OfPnt) pointArray = new TColgp_HArray1OfPnt(0,198);
for(int i = 0; i < 199; i++)
{
pointArray->SetValue(i,gp_Pnt(x[i],y[i],0.0));
}
TopLoc_Location loc;
GeomAPI_Interpolate spline(pointArray,false,1e-8);
Handle(Geom_BSplineCurve) curve = spline.Curve();
BRepBuilderAPI_MakeEdge areoEdgeBuilder(curve);
TopoDS_Edge aeroEdge = areoEdgeBuilder.Edge();
BRepBuilderAPI_MakeEdge aeroTEBuilder(gp_Pnt(x[0],y[0],0.0), gp_Pnt(x[198],y[198],0.0));
TopoDS_Edge TeEdge = aeroTEBuilder.Edge();
BRepBuilderAPI_MakeWire aeroWireBuilder(aeroEdge, TeEdge);
TopoDS_Wire aeroWire = aeroWireBuilder.Wire();
BRepBuilderAPI_MakeEdge domInlBuilder(gp_Pnt(-2.0,-2.0,0.0), gp_Pnt(-2.0,2.0,0.0));
TopoDS_Edge inlEdge = domInlBuilder.Edge();
BRepBuilderAPI_MakeEdge domTopBuilder(gp_Pnt(-2.0,2.0,0.0), gp_Pnt(5.0,2.0,0.0));
TopoDS_Edge topEdge = domTopBuilder.Edge();
BRepBuilderAPI_MakeEdge domOutBuilder(gp_Pnt(5.0,2.0,0.0), gp_Pnt(5.0,-2.0,0.0));
TopoDS_Edge outEdge = domOutBuilder.Edge();
BRepBuilderAPI_MakeEdge domBotBuilder(gp_Pnt(5.0,-2.0,0.0), gp_Pnt(-2.0,-2.0,0.0));
TopoDS_Edge botEdge = domBotBuilder.Edge();
BRepBuilderAPI_MakeWire domWireBuilder(inlEdge, topEdge, outEdge, botEdge);
TopoDS_Wire domWire = domWireBuilder.Wire();
BRepBuilderAPI_MakeFace face(domWire, true);
face.Add(aeroWire);
return face.Face();
}
}
}
......@@ -72,6 +72,8 @@ private:
void AddCurve(int i, TopoDS_Shape in, int fv, int lv);
/// Function to add surface to CADSystem::m_surfs.
void AddSurf(int i, TopoDS_Shape in, std::vector<EdgeLoop> ein);
TopoDS_Shape BuildNACA(std::string naca);
/// OCC master object
TopoDS_Shape shape;
};
......
......@@ -70,4 +70,11 @@
#include <ShapeAnalysis_Curve.hxx>
#include <Standard_Macro.hxx>
#include <GeomAPI_Interpolate.hxx>
#include <TColgp_HArray1OfPnt.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <STEPControl_Writer.hxx>
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment