Skip to content

Conversation

@emersonshands
Copy link

This merge adds in the Gauss-Chebyshev triangular quadrature set with lua calls for the set. Additionally it has methods for forming the D&M matrices seperately from the standard angular quadrature methods currently in the repository. This includes the standard Sn method, termed method 0, uses the standard full rank harmonics mapping and forms both the D&M seperately. The additional first and second Galerkin Quadrature methods are mentioned in Comparison of Two Galerkin Quadrature Methods, Morel 2017, Ref.. Both form the full range D or M matrices then invert them to obtain the accompanying matrix, which in the case of a lower range expansion requires that both matrices be cut down to the required expansion. The third method, GQ3, has not been published yet and is focused on building the D&M matrices up to the desired degree by use of the modified Gram-Schmidt method. All three GQ methods are purpose built for anisotropic problems and are agnostic to the quadrature set with appropriate harmonic choices.

Further verification is needed against an anisotropic benchmark problem from Ref..

@wdhawkins wdhawkins added the enhancement New feature or request label Apr 9, 2024
@wdhawkins
Copy link
Collaborator

Could you also add some regression tests to this PR? They don't need to be complicated. Just simple tests to verify that the methods are working correctly.

@emersonshands
Copy link
Author

Sure I have a 3d and 2d I can add-- I'll add them to the test/modules/LBS/transport_steady.

@andrsd
Copy link
Collaborator

andrsd commented Apr 9, 2024

You will need to do a few things first:

  1. Rebase your work on the current main. This is to remove those 2 merge commits. Do not do this when developing OpenSn.
  2. Then, you need to properly format your code via clang-format - we supply a clang-format settings that should be picked up by clang-format automatically as long as you do that from the repo directory. You can use interactive rebase and format individual patches as you go if you want to preserve the branch history. Do not create a clang-format patch!
  3. You are missing SPDX tags in your new files. This change happened this morning so you were not aware of it, see more info

@andrsd
Copy link
Collaborator

andrsd commented Apr 9, 2024

You still have 2 merge commits in your branch, so you did not rebase anything. You need to rebase on top of upstream main. You need to do something like this:

git fetch upstream main
git rebase --interactive upstream/main

upstream here is a remote that points to git@github.com:Open-Sn/opensn.git. If you don't have it (you can check that via git remote -v), then create it via git remote add upstream git@github.com:Open-Sn/opensn.git. This needs to happen before the fetch command.

When you do the 2nd command, you will see something like this in a text editor:

pick 8a7f719b Adding in triangular quadrature set to branch. New files added and Lua for quadratures modified.
pick 61c2abbc Changed the configure_dep python file to correctly work with folder structure by touching the local files.
pick 70949b9b Added in previous functionality to form a full 3d set that can be reduced to 2d using OptimizeForPolarSymmetry.
pick d120f1b3 Added in 3d formation for set and fixed harmonic mapping. Testing still required to verify against benchmark.
pick 33985015 Rebased and added SPX labeling.

Then, you will remove line 2 ("Changed the configure_dep"). This commit creates a conflict that you would have to resolve. However, you should not be modifying that script in your PR anyway. Your PR is about a quadrature. That's why you will get rid of it. If those changes are needed, then they can come in a separate PR. Save and quit the editor. Git will rebase your branch and then you will have to force push it into your fork.

I advised you to NOT create a clang-format patch, but you did that anyway, so 👎 .

Last advise for future. Do not develop on main branch. Create a feature branch (for example via git checkout -b my-feature-branch) and do all your work there. It will make your life much simpler.

@emersonshands emersonshands marked this pull request as draft April 9, 2024 19:55
@emersonshands emersonshands force-pushed the main branch 2 times, most recently from 49f2047 to cf7b2e5 Compare April 19, 2024 21:15
@emersonshands emersonshands marked this pull request as ready for review April 19, 2024 21:22
unsigned int sn_;
unsigned int moments_;

void TriangleInit();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check with @wdhawkins but we may need fo explicit names such as TriangleQuadratueInitialize

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just go with Initialize for right now.

Comment on lines +25 to +27
void BuildDiscreteToMomentOperator(unsigned int scattering_order, int dimension) override;

void BuildMomentToDiscreteOperator(unsigned int scattering_order, int dimension) override;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check with @wdhawkins if dim will remain int or not

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be fine for now. It may change later one, but we can leave it for this commit.

}

void
TriangleQuadrature::TriangleInit()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comment in .h file

const auto GAUSS_LEG_QUAD = GaussLegendreQuadrature(sn_);

// Formulate the triangular quadrature
VecDbl newZi, newWeights;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check with @wdhawkins if we should name this Zi (technically you meant Xi) or Mu (for consistency).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be mu.

@ragusa
Copy link
Contributor

ragusa commented Apr 27, 2024

@emersonshands also, the golden values for the tests are missing (see how to modify the .json file in the proper folder)

Emerson-Sh and others added 11 commits May 1, 2024 10:00
Need verification due to python errors.
Refactoring variable names for standards
Additional test for GQ3 added, along with associated Henyey-G.S. forward peaked cross section file.
Waiting for response and gold file values.
const auto GAUSS_LEG_QUAD = GaussLegendreQuadrature(sn_);

// Formulate the triangular quadrature
VecDbl newZi, newWeights;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing VecDbl is a typedef for std::vector<double>? If so, please use std::vector<double>.

{
log.Log0Error() << "TriangleQuarature: " << method_ << " is not a valid method.\n"
<< "Method must be 0, 1, 2, or 3." << std::endl;
Exit(510);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should throw an std::invalid_argument instead of Exit(510).


// Formulate the triangular quadrature
VecDbl newZi, newWeights;
newZi.reserve(GAUSS_LEG_QUAD.qpoints.size());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No caps in GAUSS_LEG_QUAD or at least not all caps.


int num_div = 1;
int weightPos = 0;
for (const auto& QUAD_POINT : GAUSS_LEG_QUAD.qpoints)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No all caps for QUAD_POINT.

for (int v = 0; v < num_div; ++v)
{
double new_z_value = abs(QUAD_POINT.x);
double phi = deltaVPhi / 2.0 + (double)v * deltaVPhi;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use static_cast<double>.

double phi = deltaVPhi / 2.0 + (double)v * deltaVPhi;
double theta = acos(new_z_value);
double sinTheta = sqrt(1 - new_z_value * new_z_value);
// double weightCurrent = GAUSS_LEG_QUAD.weights[weightPos] / (num_div);
Copy link
Collaborator

@wdhawkins wdhawkins May 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this commented line if it's not necessary.

new_omega.x = sinTheta * cos(phi);
new_omega.y = sinTheta * sin(phi);
new_omega.z = new_z_value;
weights_.push_back(GAUSS_LEG_QUAD.weights[weightPos] * (M_PI / (2.0 * num_div)));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you know the number of weights, omegas, and abscissae, reserve their size before the loop.

new_omega.x = omegas_[point].x; // omegas[l].x*xsign;
new_omega.y = omegas_[point].y; // omegas[l].y*ysign;
new_omega.z = -omegas_[point].z;
double new_z_value = -omegas_[point].z;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of declaring these new variables, you can use the expressions inline in the lines below.

// We need to fix the normalization to be 4*pi over the full sphere
double normal = 4.0 * M_PI;

const size_t NUM_DIRS = omegas_.size();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lower case for NUM_DIRS

// need to cut after the formation.
if (m2d_op_built_ and d2m_op_built_ and moments_ >= 0 and !m_to_ell_em_map_.empty())
{
int s_order = static_cast<int>(scattering_order);
Copy link
Collaborator

@wdhawkins wdhawkins May 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make the parameter an int and remove this cast.


auto m2d_transposed = m2d_op_;
m_to_ell_em_map_.resize(moments_to_keep);
std::vector<std::vector<double>> m2dworking;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reserve m2dworking and d2mworking since you know the size.

void
TriangleQuadrature::MakeHarmonicIndices(unsigned int scattering_order, int dimension)
{
int L = static_cast<int>(sn_);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the unsigned int's in the header to int's and remove these casts.

}

void
TriangleQuadrature::MakeHarmonicIndices(unsigned int scattering_order, int dimension)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change scattering_order to an int and remove the cast below.

{
d2m_op_.clear();

const size_t NUM_ANGLES = abscissae_.size();
Copy link
Collaborator

@wdhawkins wdhawkins May 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NUM_ANGLES -> num_angles. Remove caps throughout the file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants