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 12, 2021
1 parent 8b010ea commit 053d616
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 24 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 @@ -536,7 +536,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 @@ -547,7 +547,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 @@ -572,7 +572,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 @@ -590,7 +590,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 @@ -601,7 +601,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 @@ -631,7 +631,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 @@ -660,7 +660,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 @@ -673,7 +673,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
18 changes: 15 additions & 3 deletions tests/unittests/tiglWing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include <string.h>
#include <CCPACSConfigurationManager.h>


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

class TiglWing : public ::testing::Test
Expand Down Expand Up @@ -282,14 +281,16 @@ 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);
Expand All @@ -301,6 +302,7 @@ TEST_F(TiglWing, tiglWingGetSpanVTP){
* behaviour while invalidating the wing
*/
TEST_F(TiglWing, bug849)

{
tigl::CCPACSConfigurationManager& manager = tigl::CCPACSConfigurationManager::GetInstance();
tigl::CCPACSConfiguration& config = manager.GetConfiguration(tiglHandle);
Expand All @@ -320,6 +322,16 @@ TEST_F(TiglWing, bug849)
EXPECT_NEAR(5.9, span, 0.1); // the reported wing span is 0.62 instead of 5.4
}

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 053d616

Please sign in to comment.