-
Notifications
You must be signed in to change notification settings - Fork 10
Adds an spherical basis that is an exact deprojection of an exponential surface density #199
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
The9Cat
wants to merge
29
commits into
devel
Choose a base branch
from
SphericalExact
base: devel
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
29 commits
Select commit
Hold shift + click to select a range
69432d1
Added asymptotic form of the spherical deprojection of the exponentia…
6cde663
Added a more exact spherical deprojection implementation
e35905e
Add a cache check for spherical model type used in eof computation
6443ebf
Test routine for ExpDeproj class
2cbb4c2
Test routine for ExpDeproj class
420813e
Move deprojection flag parsing before EmpCylSL instantiation
5c44d30
Add an experimental bias factor for deprojected basis construction
0a507cd
Change from 'afac' to 'bias' to be a bit more descriptive
972c6f3
Remove stray character
e8ddbfd
Change defaults to ExpSphere in pyEXP
64ea348
Update exputil/ExpDeproj.cc
The9Cat 53d90b6
Initial plan
Copilot 0044833
Initial plan
Copilot 102d1fc
Initial plan
Copilot 62bde43
Rename ExpSphere to ExpDeproj for consistency
Copilot 2f09671
Complete naming alignment to ExpDeproj
Copilot 8d2a6e9
Remove CodeQL artifact
Copilot 97ada8c
Fix ngrid validation to prevent divide-by-zero
Copilot 0e42e6e
Add input validation for bias parameter
Copilot 861f48d
Complete fix for ngrid validation issue
Copilot 8d227a8
Remove codeql build artifacts and update gitignore
Copilot 31d44f3
Merge pull request #201 from EXP-code/copilot/sub-pr-199
The9Cat 4373a96
Complete bias validation implementation
Copilot 101b772
Remove build artifacts and update .gitignore
Copilot 7f723ba
Revert naming changes - ExpSphere is correct, not ExpDeproj
Copilot 8603c98
Complete revert to ExpSphere naming
Copilot 1e38d8b
Remove CodeQL artifact
Copilot d227415
Merge pull request #203 from EXP-code/copilot/sub-pr-199-another-one
The9Cat 490b46c
Merge pull request #202 from EXP-code/copilot/sub-pr-199-again
The9Cat 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
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
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 @@ | ||
| . |
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
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
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
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
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,85 @@ | ||
| #include "ExpDeproj.H" | ||
|
|
||
| #include <cmath> | ||
| #include <stdexcept> | ||
| #include <iostream> | ||
| #include <fstream> | ||
| #include <cassert> | ||
| #include <vector> | ||
| #include <algorithm> | ||
| #include <numeric> | ||
| #include <functional> | ||
|
|
||
| void ExpDeproj::initialize() | ||
| { | ||
| if (ngrid < 2) { | ||
| throw std::invalid_argument("n must be at least 2"); | ||
| } | ||
|
|
||
| rv.resize(ngrid); | ||
| mv.resize(ngrid); | ||
|
|
||
| std::vector<double> dv(ngrid); | ||
|
|
||
| double log_rmin = std::log(rmin); | ||
| double log_rmax = std::log(rmax); | ||
| double dlogr = (log_rmax - log_rmin)/static_cast<double>(ngrid - 1); | ||
|
|
||
| for (int i = 0; i < ngrid; ++i) { | ||
| rv[i] = std::exp(log_rmin + i*dlogr); | ||
| dv[i] = 4.0*M_PI*rv[i]*rv[i]*density(rv[i]); | ||
| } | ||
|
|
||
| mv[0] = 0.0; | ||
| for (int i=1; i<ngrid; i++) | ||
| mv[i] = mv[i-1] + 0.5*(dv[i] + dv[i-1])*(rv[i] - rv[i-1]); | ||
| } | ||
|
|
||
| double ExpDeproj::density(double R) | ||
| { | ||
| if (R < 0) { | ||
| throw std::invalid_argument("R must be non-negative"); | ||
| } | ||
| return 0.5*std::cyl_bessel_k(0.0, R)/(M_PI*M_PI); | ||
| } | ||
|
|
||
| double ExpDeproj::mass(double R) | ||
| { | ||
| // Initialize precomputed arrays? | ||
| if (mv.size() == 0) { | ||
| initialize(); | ||
| } | ||
|
|
||
| if (R < 0) { | ||
| throw std::invalid_argument("R must be non-negative"); | ||
| } | ||
|
|
||
| if (R < rmin) return 0.0; | ||
| if (R > rmax) return mv.back(); | ||
|
|
||
The9Cat marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| auto it = std::lower_bound(rv.begin(), rv.end(), R); | ||
| // If R is slightly larger than the largest grid point due to rounding, | ||
| // lower_bound may return rv.end(); in that case, use the last mass value. | ||
| if (it == rv.end()) { | ||
| return mv.back(); | ||
| } | ||
|
|
||
| std::size_t idx = static_cast<std::size_t>(std::distance(rv.begin(), it)); | ||
| if (idx >= rv.size()) { | ||
| // Defensive guard; should not happen after the it == rv.end() check. | ||
| return mv.back(); | ||
| } | ||
| if (rv[idx] == R) { | ||
| return mv[idx]; | ||
| } else { | ||
| // Ensure idx-1 is valid | ||
| if (idx == 0) idx++; | ||
| // Linear interpolation | ||
| double x0 = rv[idx-1]; | ||
| double x1 = rv[idx ]; | ||
| double y0 = mv[idx-1]; | ||
| double y1 = mv[idx ]; | ||
|
|
||
| return y0 + (y1 - y0)*(R - x0)/(x1 - x0); | ||
| } | ||
| } | ||
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
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,28 @@ | ||
| #pragma once | ||
|
|
||
| #include <vector> | ||
| #include <cmath> | ||
|
|
||
| class ExpDeproj | ||
| { | ||
| const double rmin = 1.0e-4; | ||
| const double rmax = 30.0; | ||
|
|
||
| // Precomputed radial grid | ||
| int ngrid; | ||
| std::vector<double> rv, mv; | ||
| void initialize(); | ||
|
|
||
| public: | ||
| //! Constructor | ||
| ExpDeproj(int n=4000) : ngrid(n) {} | ||
|
|
||
| //! Destructor | ||
| virtual ~ExpDeproj() {} | ||
|
|
||
| //! Density profile at radius R | ||
| double density(double R); | ||
|
|
||
| //! Enclosed mass at radius R | ||
| double mass(double R); | ||
| }; |
Oops, something went wrong.
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.