-
Notifications
You must be signed in to change notification settings - Fork 1
Add aerodynamics #6
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
Open
Stevenicc
wants to merge
6
commits into
main
Choose a base branch
from
AddAerodynamics
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
34d7f46
Add files via upload
Stevenicc cf364a0
main.cpp
Stevenicc 2ccd4d1
Update Aerodynamics.hpp
Stevenicc 48f49be
Add files via upload
Stevenicc 117859e
Update main.cpp
Stevenicc be38c19
Update DragFromFile.cpp
Stevenicc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Stevenicc marked this conversation as resolved.
Show resolved
Hide resolved
Stevenicc marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| #pragma once | ||
| #include "IAerodynamics.hpp" | ||
| #include "State.hpp" | ||
| #include <iostream> | ||
| #include <vector> | ||
| #include <string> | ||
| using namespace std; | ||
|
|
||
| class DragFromFile : public IAerodynamics { | ||
| private: | ||
| vector<double> mach; | ||
| vector<double> cd; | ||
| double MaxMach = 0.0; | ||
| double MinMach = 0.0; | ||
|
|
||
| void readTable(const string& filename); | ||
|
|
||
| double interpolateCD(double MachInput) const; | ||
|
|
||
| public: | ||
|
|
||
| DragFromFile(); | ||
|
|
||
| explicit DragFromFile(const string& filename); | ||
|
|
||
| double GetmaxMach() const; | ||
|
|
||
| double GetminMach() const; | ||
|
|
||
| double GetCd(const State& aerodynamicState) const override; | ||
|
|
||
| double getCdFromMach(double mach) const; | ||
|
|
||
| Eigen::Vector3d GetMomentCoefficients(const State& aerodynamicState) const override; | ||
| }; |
Stevenicc marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,37 @@ | ||
| #include "Aerodynamics.hpp" | ||
| #include "State.hpp" | ||
| #include <iostream> | ||
| #include <string> | ||
| #include <iomanip> | ||
| #include <stdexcept> | ||
| using namespace std; | ||
|
|
||
| int main() { | ||
| string input = " "; | ||
| double MachInput = 0.0; | ||
|
|
||
| DragFromFile aero("cd.csv"); | ||
| double MinMach = aero.GetminMach(); | ||
| double MaxMach = aero.GetmaxMach(); | ||
|
|
||
| try{ | ||
| cout << "enter a Mach Number(" << MinMach << "<= M <=" << MaxMach << "): "; | ||
| getline(cin, input); | ||
| MachInput = stod(input); | ||
| if (MachInput < 0.00 || MachInput > 3.00) throw logic_error (" Value of Mach number should be in the range"); | ||
| } | ||
| catch(const exception& e) | ||
| { | ||
| cout << "Error in the input" << e.what() << endl; | ||
| return 1; | ||
| } | ||
|
|
||
| State state(1); | ||
| state[0] = MachInput; | ||
|
|
||
| double cd = aero.GetCd(state); | ||
|
|
||
| cout << fixed << setprecision(5); | ||
| cout << "Drag coefficient: " << cd << endl; | ||
| return 0; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| #include "Aerodynamics.hpp" | ||
| #include <iostream> | ||
| #include <vector> | ||
| #include <string> | ||
| #include <fstream> | ||
| #include <algorithm> | ||
| #include <stdexcept> | ||
| using namespace std; | ||
|
|
||
| DragFromFile::DragFromFile() = default; | ||
|
|
||
| DragFromFile::DragFromFile(const string& filename) | ||
| { | ||
| readTable(filename); | ||
| } | ||
|
|
||
| void DragFromFile::readTable(const string& filename) | ||
| { | ||
| ifstream vMyFile(filename); | ||
| if (!vMyFile.good()) | ||
| { | ||
| throw runtime_error("Failed to open file: " + filename); | ||
| return; | ||
| } | ||
|
|
||
| mach.clear(); | ||
| cd.clear(); | ||
|
|
||
| double Mach_data; | ||
| double Cd_data; | ||
| char comma; | ||
|
|
||
| while (vMyFile >> Mach_data >> comma >> Cd_data) | ||
| { | ||
| mach.push_back(Mach_data); | ||
| cd.push_back(Cd_data); | ||
| } | ||
|
|
||
| auto range = minmax_element(mach.begin(), mach.end()); | ||
| MinMach = *range.first; | ||
| MaxMach = *range.second; | ||
| vMyFile.close(); | ||
| } | ||
|
|
||
| double DragFromFile::interpolateCD(double MachInput) const | ||
| { | ||
| if (mach.empty()) return 0.0; | ||
|
|
||
| for (size_t i = 0; i < mach.size() - 1; i++) | ||
| { | ||
| if (MachInput >= mach[i] && MachInput <= mach[i+1]) | ||
| { | ||
| return cd[i] + (cd[i+1] - cd[i]) * (MachInput - mach[i]) / (mach[i+1] - mach[i]); | ||
| } | ||
| } | ||
|
|
||
| return cd.back(); | ||
| } | ||
|
|
||
| double DragFromFile::GetmaxMach() const | ||
| { | ||
| return MaxMach; | ||
| } | ||
|
|
||
|
|
||
| double DragFromFile::GetminMach() const | ||
| { | ||
| return MinMach; | ||
| } | ||
|
|
||
| double DragFromFile::GetCd(const State& aerodynamicState) const | ||
| { | ||
| if (aerodynamicState.size() > 0) | ||
| { | ||
| double mach = aerodynamicState[0]; | ||
| if (mach >= MinMach && mach <= MaxMach) | ||
| { | ||
| return interpolateCD(mach); | ||
| } | ||
| else | ||
| { | ||
| throw out_of_range("Mach number out of range."); | ||
| } | ||
| } | ||
|
|
||
| throw std::invalid_argument("State is empty"); | ||
| } | ||
|
|
||
| double DragFromFile::getCdFromMach(double mach) const | ||
| { | ||
| return interpolateCD(mach); | ||
| } | ||
|
|
||
|
|
||
| Eigen::Vector3d DragFromFile::GetMomentCoefficients(const State&) const | ||
| { | ||
| return Eigen::Vector3d::Zero(); | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.