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

Continuously Varying Material Tracking Method (CVMT) Implementation #1358

Open
wants to merge 16 commits into
base: develop
Choose a base branch
from

Conversation

rockfool
Copy link
Contributor

This PR is to add CVMT method in the particle tracking. It allows the nuclides number densities in Material class be expressed by the functional expansion. However, the functional expansion tallied nuclides number densities is not determined. Any comment will be appreciated. I am also preparing the testing cases for this implementaion.

include/openmc/math_functions.h Outdated Show resolved Hide resolved
include/openmc/math_functions.h Outdated Show resolved Hide resolved
@gridley
Copy link
Contributor

gridley commented Sep 25, 2019

Just wondering, how does this method generally perform compared to delta tracking?

@rockfool
Copy link
Contributor Author

Just wondering, how does this method generally perform compared to delta tracking?
This method was come up as the alternate way of delta-tracking to sample the particle flight path in the medium with continously varying cross sections. However, delta-tracking might meet with low sampling efficiency issue and the track-length estimator issue. This is a direct sampling method, and has the most compatibility with ray-tracking.
[1]. Brown, Forrest B., and William R. Martin. "Direct sampling of Monte Carlo flight paths in media with continuously varying cross-sections." In Proc. ANS Mathematics & Computation Topical Meeting, vol. 2. 2003.

@hanzhuoran
Copy link
Contributor

Just wondering, how does this method generally perform compared to delta tracking?
Delta-tracking could be faster than this direct sampling when XS doesn't vary too much in the domain. When both continuous number density and continuous XS sections are involved, it might be harder to evaluate maximum macroscopic XS.

@gridley
Copy link
Contributor

gridley commented Sep 25, 2019

Interesting, thanks for the replies guys. Has anyone tried making this hybrid with delta tracking, kind of like how Serpent does hybrid delta tracking and ray tracing?

@rockfool
Copy link
Contributor Author

Interesting, thanks for the replies guys. Has anyone tried making this hybrid with delta tracking, kind of like how Serpent does hybrid delta tracking and ray tracing?

As I know, none of us is working on the delta-tracking or hybrid with delta-tracking currently.

Copy link
Contributor

@paulromano paulromano left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @rockfool. This branch looks like it needs considerable clean-up before it would be ready for review. Please have a look at our C++ style guide and try to conform to it. I also do not see any tests or documentation which will be needed as well. Once this has been cleaned up and tests/docs added, ping me for a review again. Thanks!

include/openmc/constants.h Outdated Show resolved Hide resolved
include/openmc/material.h Outdated Show resolved Hide resolved
include/openmc/particle.h Outdated Show resolved Hide resolved
include/openmc/particle.h Outdated Show resolved Hide resolved
include/openmc/particle.h Outdated Show resolved Hide resolved
src/particle.cpp Outdated
d_collision = -std::log(prn()) / macro_xs_.total;

// cvmt: continuous varying materials tracking
if(model::materials[material_]->continuous_num_density_) d_collision = sampling_cvmt(this, boundary.distance);
Copy link
Contributor

Choose a reason for hiding this comment

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

Be cognizant of line length, try to keep lines under 80 or 90 characters wide

src/particle.cpp Outdated
Particle::copy_data(LocalCoord &to, LocalCoord from){
to.r = from.r ;
to.u = from.u ;
to.cell = from.cell ;
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't use extraneous whitespace between RHS and ;

src/particle.cpp Outdated
this -> coord_[this -> n_coord_-1].u[1-1],
this -> coord_[this -> n_coord_-1].u[2-1],
this -> coord_[this -> n_coord_-1].u[3-1],
this -> E_, ds);
Copy link
Contributor

Choose a reason for hiding this comment

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

All this debugging stuff should be removed

src/particle.cpp Outdated
this -> coord_[this -> n_coord_-1].r[1-1],
this -> coord_[this -> n_coord_-1].r[2-1],
this -> coord_[this -> n_coord_-1].r[3-1],
new_temp, xs_t[i-1]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Debugging stuff should be removed

src/particle.cpp Outdated
printf("delta_tau_hat = %15.7f", delta_tau_hat);
printf("index = %15d", index);
printf("ds*(index-1) = %15.7f", ds * (index-1));
printf("ds*(index) = %15.7f", ds * (index));
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove all these printfs

@rockfool
Copy link
Contributor Author

Thanks for the PR @rockfool. This branch looks like it needs considerable clean-up before it would be ready for review. Please have a look at our C++ style guide and try to conform to it. I also do not see any tests or documentation which will be needed as well. Once this has been cleaned up and tests/docs added, ping me for a review again. Thanks!

Thanks for your comments. I am going to remove those stuff that does not conform to C++ style, and try to prepare a testing case and the documentation in docs/neutron_physics.rst.

@paulromano
Copy link
Contributor

Hi @rockfool. Just wanted to check in regarding this PR. If you'd like me to review this one again, please update it by merging the develop branch in order to resolve the existing merge conflicts.

@rockfool
Copy link
Contributor Author

Hi @rockfool. Just wanted to check in regarding this PR. If you'd like me to review this one again, please update it by merging the develop branch in order to resolve the existing merge conflicts.

OK. I will try to reovle this conflict ASAP.

Copy link
Contributor

@paulromano paulromano left a comment

Choose a reason for hiding this comment

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

@rockfool This pull request still needs a bit of work. A few general comments that apply throughout:

  • In many cases, you are declaring variables before you have a value to define them. This is a common source of uninitialized value bugs. Please move the variable declarations to the point of definition as well.
  • There are many places throughout your code that don't match our style guide. Rather than fixing one-by-one, what I'd suggest you do is to use clang-format along with the .clang-format file in the root directory of the repo to automatically apply formatting. That will save both of us the headache of addressing the minor style issues
  • It looks like the only polynomials that are supported are Zernike polynomials. I think to be considered a general capability, we would want to support the ability to set arbitrary polynomials in x, y, and z.
  • I don't see any support for this feature on the Python side; that will need to be added in order to be given full consideration for merging.

double radius_; //! the radius of the expansion
std::vector<double> coeffs_; //! coefficients for poly evaluation
std::vector<double> poly_norm_; //! polynomial norm available to property for efficiency
public:
Copy link
Contributor

Choose a reason for hiding this comment

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

NL.16: Put public members before private

poly_norm_.resize(n_coeffs_);
}

PolyProperty::~PolyProperty()
Copy link
Contributor

Choose a reason for hiding this comment

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

This destructor is not needed -- when the object is destructed, the memory from the vectors will be removed

return property;
}

PolyProperty::PolyProperty(int n_size)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would have the constructor be:

PolyProperty::PolyProperty(const std::string& type, const std::vector<double>& coeffs)

and then have all the members (n_coeffs_, coeffs_, order_, type_) be set directly in the constructor rather than have that logic spill into the Material constructor.

{
int c_index;
double rho, poly_val, property;
rho = std::sqrt(r.x * r.x + r.y * r.y) / coeffs_[0];
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't declare a variable until you have a suitable value for it:

Suggested change
rho = std::sqrt(r.x * r.x + r.y * r.y) / coeffs_[0];
double rho = std::sqrt(r.x * r.x + r.y * r.y) / coeffs_[0];

int c_index;
double rho, poly_val, property;
rho = std::sqrt(r.x * r.x + r.y * r.y) / coeffs_[0];
c_index = 2;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
c_index = 2;
int c_index = 2;

double ds, new_temp;
LocalCoord coord;

copy_data(coord, this->coord_[this->n_coord_ - 1]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Pretty sure the following will work:

LocalCoord coord = this->coord_[this->n_coord_ - 1];

and then remove the copy_data method

}

void
Particle::estimate_flight_distance(std::vector<double> xs_t, double distance, double tau_hat, double& s)
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like it doesn't need to be a method of Particle and can be a plain function instead. Also, why not just return a double instead of having that last parameter?

}

void
Particle::get_quadratic_root(double a, double b, double c, double lower_b, double upper_b, double& root)
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like it doesn't need to be a method of Particle and can be a plain function instead

}

void
Particle::get_cubic_root(double a, double b, double c, double d, \
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like it doesn't need to be a method of Particle and can be a plain function instead

void simpsons_path_integration(double& optical_depth, double distance, std::vector<double> &xs_t, bool dbg_file, int it_num);
void estimate_flight_distance(std::vector<double> xs_t, double distance, double tau_hat, double& s);
void get_quadratic_root(double a, double b, double c, double lower_b, double upper_b, double& root);
void get_cubic_root(double a, double b, double c, double d, double lower_b, double upper_b, double& root);
Copy link
Contributor

Choose a reason for hiding this comment

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

For all these functions/methods, you need to add Doxygen comments above describing what the parameters are

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants