Skip to content

Commit

Permalink
Added test for the aspect ratio computation
Browse files Browse the repository at this point in the history
I also made the code more const correct

Addresses #827
  • Loading branch information
rainman110 committed Nov 10, 2021
1 parent 8e1b13d commit b371465
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 23 deletions.
6 changes: 3 additions & 3 deletions src/geometry/CTiglAbstractGeometricComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Bnd_Box const& CTiglAbstractGeometricComponent::GetBoundingBox() const
return *bounding_box;
}

PNamedShape CTiglAbstractGeometricComponent::GetMirroredLoft()
PNamedShape CTiglAbstractGeometricComponent::GetMirroredLoft() const
{
const TiglSymmetryAxis& symmetryAxis = GetSymmetryAxis();
if (symmetryAxis == TIGL_NO_SYMMETRY) {
Expand Down Expand Up @@ -89,7 +89,7 @@ PNamedShape CTiglAbstractGeometricComponent::GetMirroredLoft()
return mirroredShape;
}

bool CTiglAbstractGeometricComponent::GetIsOn(const gp_Pnt& pnt)
bool CTiglAbstractGeometricComponent::GetIsOn(const gp_Pnt& pnt) const
{
const TopoDS_Shape segmentShape = GetLoft()->Shape();

Expand Down Expand Up @@ -120,7 +120,7 @@ bool CTiglAbstractGeometricComponent::GetIsOn(const gp_Pnt& pnt)
}
}

bool CTiglAbstractGeometricComponent::GetIsOnMirrored(const gp_Pnt& pnt)
bool CTiglAbstractGeometricComponent::GetIsOnMirrored(const gp_Pnt& pnt) const
{
const TiglSymmetryAxis& symmetryAxis = GetSymmetryAxis();
if (symmetryAxis == TIGL_NO_SYMMETRY) {
Expand Down
6 changes: 3 additions & 3 deletions src/geometry/CTiglAbstractGeometricComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ class CTiglAbstractGeometricComponent : public ITiglGeometricComponent
TIGL_EXPORT PNamedShape GetLoft() const override;

// Get the loft mirrored at the mirror plane
TIGL_EXPORT virtual PNamedShape GetMirroredLoft();
TIGL_EXPORT virtual PNamedShape GetMirroredLoft() const;

// return if pnt lies on the loft
TIGL_EXPORT virtual bool GetIsOn(const gp_Pnt &pnt);
TIGL_EXPORT virtual bool GetIsOn(const gp_Pnt &pnt) const;

// return if pnt lies on the mirrored loft
// if the loft as no symmetry, false is returned
TIGL_EXPORT bool GetIsOnMirrored(const gp_Pnt &pnt);
TIGL_EXPORT bool GetIsOnMirrored(const gp_Pnt &pnt) const;

// returns the bounding box of this component's loft
TIGL_EXPORT Bnd_Box const& GetBoundingBox() const;
Expand Down
16 changes: 8 additions & 8 deletions src/wing/CCPACSWing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ double CCPACSWing::GetSurfaceArea()

// Returns the reference area of the wing by taking account the quadrilateral portions
// of each wing segment by projecting the wing segments into the plane defined by the user
double CCPACSWing::GetReferenceArea(TiglSymmetryAxis symPlane)
double CCPACSWing::GetReferenceArea(TiglSymmetryAxis symPlane) const
{
double refArea = 0.0;

Expand All @@ -548,7 +548,7 @@ double CCPACSWing::GetReferenceArea(TiglSymmetryAxis symPlane)
}


double CCPACSWing::GetWettedArea(TopoDS_Shape parent)
double CCPACSWing::GetWettedArea(TopoDS_Shape parent) const
{
const TopoDS_Shape loft = GetLoft()->Shape();

Expand All @@ -573,7 +573,7 @@ Handle(Geom_Surface) CCPACSWing::GetUpperSegmentSurface(int index)
return m_segments.GetSegment(index).GetUpperSurface();
}

double CCPACSWing::GetWingspan()
double CCPACSWing::GetWingspan() const
{
Bnd_Box boundingBox;
if (GetSymmetryAxis() == TIGL_NO_SYMMETRY) {
Expand All @@ -591,7 +591,7 @@ double CCPACSWing::GetWingspan()
gp_XYZ cumulatedSpanDirection(0, 0, 0);
gp_XYZ cumulatedDepthDirection(0, 0, 0);
for (int i = 1; i <= GetSegmentCount(); ++i) {
CCPACSWingSegment& segment = m_segments.GetSegment(i);
const CCPACSWingSegment& segment = m_segments.GetSegment(i);
const TopoDS_Shape segmentShape = segment.GetLoft()->Shape();
BRepBndLib::Add(segmentShape, boundingBox);

Expand All @@ -602,7 +602,7 @@ double CCPACSWing::GetWingspan()
cumulatedSpanDirection += dirSpan;
cumulatedDepthDirection += dirDepth;
}
CCPACSWingSegment& outerSegment = m_segments.GetSegment(GetSegmentCount());
const CCPACSWingSegment& outerSegment = m_segments.GetSegment(GetSegmentCount());
gp_XYZ dirDepth = outerSegment.GetChordPoint(1,1).XYZ() - outerSegment.GetChordPoint(1,0).XYZ();
dirDepth = gp_XYZ(fabs(dirDepth.X()), fabs(dirDepth.Y()), fabs(dirDepth.Z()));
cumulatedDepthDirection += dirDepth;
Expand Down Expand Up @@ -632,7 +632,7 @@ double CCPACSWing::GetWingspan()
}
else {
for (int i = 1; i <= GetSegmentCount(); ++i) {
CCPACSWingSegment& segment = GetSegment(i);
const CCPACSWingSegment& segment = GetSegment(i);
TopoDS_Shape segmentShape = segment.GetLoft()->Shape();
BRepBndLib::Add(segmentShape, boundingBox);
TopoDS_Shape segmentMirroredShape = segment.GetMirroredLoft()->Shape();
Expand Down Expand Up @@ -661,7 +661,7 @@ double CCPACSWing::GetWingspan()
// Returns the aspect ratio of a wing: AR=b**2/A=((2s)**2)/(2A_half)
// b: full span; A: Reference area of full wing (wing + symmetrical wing)
// s: half span; A_half: Reference area of wing without symmetrical wing
double CCPACSWing::GetAspectRatio()
double CCPACSWing::GetAspectRatio() const
{
return 2.0*(pow_int(GetWingspan(),2)/GetReferenceArea(GetSymmetryAxis()));
}
Expand All @@ -674,7 +674,7 @@ double CCPACSWing::GetAspectRatio()
* But the effect of insidance angle is neglected. These values should coincide
* with the values found with tornado tool.
*/
void CCPACSWing::GetWingMAC(double& mac_chord, double& mac_x, double& mac_y, double& mac_z)
void CCPACSWing::GetWingMAC(double& mac_chord, double& mac_x, double& mac_y, double& mac_z) const
{
double A_sum = 0.;
double cc_mac_sum=0.;
Expand Down
10 changes: 5 additions & 5 deletions src/wing/CCPACSWing.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,19 @@ friend class CTiglWingBuilder;

// Returns the reference area of the wing by taking account the drilateral portions
// of each wing segment by projecting the wing segments into the plane defined by the user
TIGL_EXPORT double GetReferenceArea(TiglSymmetryAxis symPlane);
TIGL_EXPORT double GetReferenceArea(TiglSymmetryAxis symPlane) const;

// Returns wetted Area
TIGL_EXPORT double GetWettedArea(TopoDS_Shape parent);
TIGL_EXPORT double GetWettedArea(TopoDS_Shape parent) const;

// Returns the wingspan of the wing
TIGL_EXPORT double GetWingspan();
TIGL_EXPORT double GetWingspan() const;

// Returns the aspect ratio of the wing
TIGL_EXPORT double GetAspectRatio();
TIGL_EXPORT double GetAspectRatio() const;

// Returns the mean aerodynamic chord of the wing
TIGL_EXPORT void GetWingMAC(double& mac_chord, double& mac_x, double& mac_y, double& mac_z);
TIGL_EXPORT void GetWingMAC(double& mac_chord, double& mac_x, double& mac_y, double& mac_z) const;

// Calculates the segment coordinates from global (x,y,z) coordinates
// Returns the segment index of the according segment
Expand Down
2 changes: 1 addition & 1 deletion src/wing/CCPACSWingSegment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,7 @@ bool CCPACSWingSegment::GetIsOnTop(gp_Pnt pnt) const
}


bool CCPACSWingSegment::GetIsOn(const gp_Pnt& pnt)
bool CCPACSWingSegment::GetIsOn(const gp_Pnt& pnt) const
{
bool isOnLoft = CTiglAbstractSegment<CCPACSWingSegment>::GetIsOn(pnt);

Expand Down
2 changes: 1 addition & 1 deletion src/wing/CCPACSWingSegment.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class CCPACSWingSegment : public generated::CPACSWingSegment, public CTiglAbstra
TIGL_EXPORT bool GetIsOnTop(gp_Pnt pnt) const;

// return if pnt lies on the loft or on the segment chord face
TIGL_EXPORT bool GetIsOn(const gp_Pnt &pnt) override;
TIGL_EXPORT bool GetIsOn(const gp_Pnt &pnt) const override;

// Returns the reference area of the quadrilateral portion of the wing segment
// by projecting the wing segment into the plane defined by the user
Expand Down
17 changes: 15 additions & 2 deletions tests/unittests/tiglWing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "tigl.h"
#include <string.h>

#include <CCPACSConfigurationManager.h>

/******************************************************************************/

Expand Down Expand Up @@ -281,20 +282,32 @@ TEST_F(TiglWing, tiglWingGetSegmentIndex_nullPtr)
ASSERT_TRUE(tiglWingGetSegmentIndex(tiglHandle, "D150_VAMP_W1_Seg1", &segmentIndex, NULL) == TIGL_NULL_POINTER);
}

TEST_F(TiglWing, tiglWingGetSegmentIndex_wrongHandle){
TEST_F(TiglWing, tiglWingGetSegmentIndex_wrongHandle)
{
TiglCPACSConfigurationHandle myWrongHandle = -1234;
int segmentIndex = 0;
int wingIndex = 0;
ASSERT_TRUE(tiglWingGetSegmentIndex(myWrongHandle, "D150_VAMP_W1_Seg1", &segmentIndex, &wingIndex) == TIGL_NOT_FOUND);
}

TEST_F(TiglWing, tiglWingGetSpanVTP){
TEST_F(TiglWing, tiglWingGetSpanVTP)
{
double span = 0.;
tiglWingGetSpan(tiglHandle, "D150_VAMP_SL1", &span);
ASSERT_LT(span, 5.9);
ASSERT_GT(span, 5.8);
}

TEST_F(TiglWing, tiglGetAspectRatio)
{
tigl::CCPACSConfigurationManager& manager = tigl::CCPACSConfigurationManager::GetInstance();
tigl::CCPACSConfiguration& config = manager.GetConfiguration(tiglHandle);

const auto& wing = config.GetWing(1);
auto ar = wing.GetAspectRatio();
EXPECT_NEAR(9.4, ar, 0.1);
}


TEST_F(WingSimple, wingGetMAC_success)
{
Expand Down

0 comments on commit b371465

Please sign in to comment.