Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bsk 474/fix drag effector #479

Merged
merged 2 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/source/Support/bskKnownIssues.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Version |release|
issue has now been fixed in the current release.
- The :ref:`facetSRPDynamicEffector` module was double counting a cosine term in the SRP force calculation. This is
corrected in the current release.
- The :ref:`facetDragDynamicEffector` module was missing a negative sign in the drag torque calculation. This is
corrected in the current release.

Version 2.2.0
-------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import os

import numpy as np
import pytest

filename = inspect.getframeinfo(inspect.currentframe()).filename
path = os.path.dirname(os.path.abspath(filename))
Expand All @@ -52,46 +53,16 @@
from Basilisk.utilities import simIncludeGravBody


#print dir(exponentialAtmosphere)
test_drag = [([1.0, 1.0], np.array([2.0, 2.0]), [np.array([1, 0, 0]), np.array([0, 1, 0])], [np.array([0.1, 0, 0]), np.array([0, 0.1, 0])]),
([1.0, 1.0], np.array([2.0, 2.0]), [np.array([1, 0, 0]), np.array([0, 1, 0])], [np.array([0.3, 0, 0]), np.array([0, 0.3, 0])]),
([1.0, 2.0], np.array([2.0, 4.0]), [np.array([1, 0, 0]), np.array([0, 1, 0])], [np.array([0.1, 0, 0]), np.array([0, 0.1, 0])]),
([1.0, 1.0], np.array([2.0, 2.0]), [np.array([1, 0, 0]), np.array([0, 1, 0])], [np.array([0.1, 0, 0]), np.array([0, 0, 0.1])]),
([1.0, 1.0], np.array([2.0, 2.0]), [np.array([1, 0, 0]), np.array([0, 0, 1])], [np.array([0.1, 0, 0]), np.array([0, 0, 0.1])]),
([1.0, 1.0], np.array([2.0, 2.0]), [np.array([0, 0, -1]), np.array([0, -1, 0])], [np.array([0, 0, 0.1]), np.array([0, 0.1, 0])]),
]


def test_unitFacetDrag():
"""This function is called by the py.test environment."""
# each test method requires a single assert method to be called

testResults = []
testMessage = []

dragRes, dragMsg = TestDragCalculation()
testMessage.append(dragMsg)
testResults.append(dragRes)

shadowRes, shadowMsg = TestShadowCalculation()
testMessage.append(shadowMsg)
testResults.append(shadowRes)

testSum = sum(testResults)

snippetName = "unitTestPassFail"

if testSum == 0:
colorText = 'ForestGreen'
print("PASSED")
passedText = r'\textcolor{' + colorText + '}{' + "PASSED" + '}'
else:
colorText = 'Red'
print("Failed")
passedText = r'\textcolor{' + colorText + '}{' + "Failed" + '}'
unitTestSupport.writeTeXSnippet(snippetName, passedText, path)

assert testSum < 1, testMessage


def TestDragCalculation():

# Init test support variables
testFailCount = 0
testMessages = []
@pytest.mark.parametrize("scAreas, scCoeff, B_normals, B_locations", test_drag)
def test_DragCalculation(scAreas, scCoeff, B_normals, B_locations):

## Simulation initialization
simTaskName = "simTask"
Expand All @@ -118,17 +89,10 @@ def TestDragCalculation():
scObject.addDynamicEffector(newDrag)

try:
scAreas = [1.0, 1.0]
scCoeff = np.array([2.0, 2.0])
B_normals = [np.array([1, 0, 0]), np.array([0, 1, 0])]
B_locations = [np.array([0.1,0,0]), np.array([0,0.1,0])]

for i in range(0,len(scAreas)):
newDrag.addFacet(scAreas[i], scCoeff[i], B_normals[i], B_locations[i])
except:
testFailCount += 1
testMessages.append("ERROR: FacetDrag unit test failed while setting facet parameters.")
return testFailCount, testMessages
pytest.fail("ERROR: FacetDrag unit test failed while setting facet parameters.")

# clear prior gravitational body and SPICE setup definitions
gravFactory = simIncludeGravBody.gravBodyFactory()
Expand Down Expand Up @@ -211,35 +175,26 @@ def checkFacetDragForce(dens, area, coeff, facet_dir, sigma_BN, inertial_vel):


# Compare to expected values
accuracy = 1e-3
unitTestSupport.writeTeXSnippet("toleranceValue", str(accuracy), path)

test_val = np.zeros([3,])
test_val_force = np.zeros([3,])
test_val_torque = np.zeros([3,])
for i in range(len(scAreas)):
test_val += checkFacetDragForce(densData[i], scAreas[i], scCoeff[i], B_normals[i], attData[1], velData[1])
val_force_i = checkFacetDragForce(densData[i], scAreas[i], scCoeff[i], B_normals[i], attData[1], velData[1])
test_val_force += val_force_i
test_val_torque += np.cross(B_locations[i], val_force_i)

if len(densData) > 0:
if not unitTestSupport.isArrayEqualRelative(dragDataForce_B[1,1:4], test_val, 3,accuracy):
testFailCount += 1
testMessages.append(
"FAILED: FacetDragEffector failed force unit test at t=" + str(dragDataForce_B[1,0]* macros.NANO2SEC) + "sec with a value difference of "+str(dragDataForce_B[1,1:]-test_val))
else:
testFailCount += 1
testMessages.append("FAILED: ExpAtmo failed to pull any logged data")
assert len(densData) > 0, "FAILED: ExpAtmo failed to pull any logged data"
np.testing.assert_allclose(dragDataForce_B[1,1:4], test_val_force, atol = 1e-06)
np.testing.assert_allclose(dragTorqueData[1,1:4], test_val_torque, atol = 1e-06)

if testFailCount:
print(testMessages)
else:
print("PASSED")

return testFailCount, testMessages
test_shadow = [([1.0, 1.0], np.array([2.0, 2.0]), [np.array([0, 0, -1]), np.array([0, -1, 0])], [np.array([0, 0, 0.1]), np.array([0, 0.1, 0])]),
([1.0, 1.0], np.array([2.0, 4.0]), [np.array([0, 0, -1]), np.array([0, -1, 0])], [np.array([0, 0, 0.1]), np.array([0, 0.1, 0])]),
([1.0, 1.0], np.array([2.0, 2.0]), [np.array([0, 0, -1]), np.array([0, -1, 0])], [np.array([0, 0, 0.4]), np.array([0, 0.4, 0])]),
]


def TestShadowCalculation():

# Init test support variables
testFailCount = 0
testMessages = []
@pytest.mark.parametrize("scAreas, scCoeff, B_normals, B_locations", test_shadow)
def test_ShadowCalculation(scAreas, scCoeff, B_normals, B_locations):

## Simulation initialization
simTaskName = "simTask"
Expand Down Expand Up @@ -269,17 +224,10 @@ def TestShadowCalculation():
scObject.addDynamicEffector(newDrag)

try:
scAreas = [1.0, 1.0]
scCoeff = np.array([2.0, 2.0])
B_normals = [np.array([0, 0, -1]), np.array([0, -1, 0])]
B_locations = [np.array([0,0,0.1]), np.array([0,0.1,0])]

for ind in range(0,len(scAreas)):
newDrag.addFacet(scAreas[ind], scCoeff[ind], B_normals[ind], B_locations[ind])
except:
testFailCount += 1
testMessages.append("ERROR: FacetDrag unit test failed while setting facet parameters.")
return testFailCount, testMessages
pytest.fail("ERROR: FacetDrag unit test failed while setting facet parameters.")

# clear prior gravitational body and SPICE setup definitions
gravFactory = simIncludeGravBody.gravBodyFactory()
Expand Down Expand Up @@ -350,29 +298,15 @@ def TestShadowCalculation():
densData = atmoLog.neutralDensity
np.set_printoptions(precision=16)

# Compare to expected values
accuracy = 1e-9
#unitTestSupport.writeTeXSnippet("toleranceValue", str(accuracy), path)

if len(densData) > 0:
for ind in range(1,len(densData)):
if not unitTestSupport.isArrayZero(dragDataForce_B[ind, 1:], 3,accuracy):
testFailCount += 1
testMessages.append(
"FAILED: FacetDragEffector failed shadow unit test with a value difference of "
+ str(dragDataForce_B[ind,1:]))
else:
testFailCount += 1
testMessages.append("FAILED: ExpAtmo failed to pull any logged data")

if testFailCount:
print(testMessages)
else:
print("PASSED")

return testFailCount, testMessages
assert len(densData) > 0, "FAILED: ExpAtmo failed to pull any logged data"
for ind in range(1,len(densData)):
np.testing.assert_allclose(dragDataForce_B[ind,1:4], [0, 0, 0], atol = 1e-11)
np.testing.assert_allclose(dragTorqueData[ind,1:4], [0, 0, 0], atol = 1e-11)

if __name__=="__main__":
# test_unitFacetDrag()
TestShadowCalculation()
# TestDragCalculation()
scAreas = [1.0, 1.0]
scCoeff = np.array([2.0, 2.0])
B_normals = [np.array([0, 0, -1]), np.array([0, -1, 0])]
B_locations = [np.array([0, 0, 0.1]), np.array([0, 0.1, 0])]
test_DragCalculation(scAreas, scCoeff, B_normals, B_locations)
test_ShadowCalculation(scAreas, scCoeff, B_normals, B_locations)
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ void FacetDragDynamicEffector::plateDrag(){
projectedArea = this->scGeometry.facetAreas[i] * projectionTerm;
if(projectedArea > 0.0){
facetDragForce = 0.5 * pow(this->v_B.norm(), 2.0) * this->scGeometry.facetCoeffs[i] * projectedArea * this->atmoInData.neutralDensity * (-1.0)*this->v_hat_B;
facetDragTorque = facetDragForce.cross(this->scGeometry.facetLocations_B[i]);
facetDragTorque = (-1)*facetDragForce.cross(this->scGeometry.facetLocations_B[i]);
totalDragForce = totalDragForce + facetDragForce;
totalDragTorque = totalDragTorque + facetDragTorque;
}
Expand Down
Loading