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

MeshFilter rotation - solution to issue #3166 #3176

Open
wants to merge 13 commits into
base: develop
Choose a base branch
from
Prev Previous commit
Next Next commit
position.h added
  • Loading branch information
zoeprieto committed Oct 14, 2024
commit 3afb6d5f618f078cc32a312e6aae7700a348d9f3
6 changes: 3 additions & 3 deletions include/openmc/tallies/filter_mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ class MeshFilter : public Filter {

virtual void set_rotation(const vector<double>& rotation);

//virtual void set_rotation(const double rotation[3]);
//virtual void set_rotation(const vector<double>& rot);

//virtual const vector<double>& rotation() const { return rotation_; }
virtual const vector<double>& rotation() const { return rotation_; }

//virtual bool rotated() const { return rotated_; }
virtual bool rotated() const { return rotated_; }

protected:
//----------------------------------------------------------------------------
Expand Down
26 changes: 15 additions & 11 deletions src/tallies/filter_mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "openmc/constants.h"
#include "openmc/error.h"
#include "openmc/mesh.h"
#include "openmc/position.h"
#include "openmc/xml_interface.h"

namespace openmc {
Expand Down Expand Up @@ -51,9 +52,9 @@ void MeshFilter::get_all_bins(
r -= translation();
}
// apply rotation if present
if (rotated_) {
last_r.rotate(rotation());
r.rotate(rotation());
if (!rotation_.empty()) {
last_r.rotate(rotation_);
r.rotate(rotation_);
}

if (estimator != TallyEstimator::TRACKLENGTH) {
Expand Down Expand Up @@ -111,9 +112,9 @@ void MeshFilter::set_rotation(const vector<double>& rot)
//rotated_ = true;
rotation_.clear();

if (rot.size() != 3 && rot.size() != 9) {
fatal_error(fmt::format("Non-3D rotation vector applied to mesh filter {}", id_));
}
//if (rot.size() != 3 && rot.size() != 9) {
// fatal_error(fmt::format("Non-3D rotation vector applied to mesh filter {}", id_));
//}

// Compute and store the rotation matrix.
rotation_.clear();
Expand Down Expand Up @@ -267,9 +268,10 @@ extern "C" int openmc_mesh_filter_get_rotation(
set_errmsg("Tried to get a rotation from a non-mesh filter.");
return OPENMC_E_INVALID_TYPE;
}

*n = cell->rotation_.size();
std::memcpy(rot, cell->rotation_.data(), *n * sizeof(cell->rotation_[0]));
// Get rotation from the mesh filter and set value
auto mesh_filter = dynamic_cast<MeshFilter*>(filter.get());
*n = mesh_filter->rotation().size();
std::memcpy(rot, mesh_filter->rotation().data(), *n * sizeof(mesh_filter->rotation()[0]));
return 0;

//// Get rotation from the mesh filter and set value
Expand All @@ -278,7 +280,7 @@ extern "C" int openmc_mesh_filter_get_rotation(
//for (int i = 0; i < 3; i++) {
// rotation[i] = r[i];
//}

//mesh_filter->set_rotation();
//return 0;
}

Expand All @@ -297,8 +299,10 @@ extern "C" int openmc_mesh_filter_set_rotation(
return OPENMC_E_INVALID_TYPE;
}

// Get a pointer to the filter and downcast
auto mesh_filter = dynamic_cast<MeshFilter*>(filter.get());
std::vector<double> vec_rot(rot, rot + rot_len);
model::cells[index]->set_rotation(vec_rot);
mesh_filter->set_rotation(vec_rot);
return 0;
//// Get a pointer to the filter and downcast
//auto mesh_filter = dynamic_cast<MeshFilter*>(filter.get());
Expand Down