Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions include/GMGPolar/gmgpolar.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,6 @@ class GMGPolar : public IGMGPolar
/* Visualization */
public: // Public due to cuda restrictions
void writeToVTK(const std::filesystem::path& file_path, const PolarGrid& grid);

private:
void writeToVTK(const std::filesystem::path& file_path, const LevelType& level,
HostConstVector<double> grid_function);
};
Expand Down
26 changes: 19 additions & 7 deletions include/GMGPolar/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,10 @@ void GMGPolar<DomainGeometry, DensityProfileCoefficients>::writeToVTK(const std:
Fx(index) = domain_geometry.Fx(r, theta);
Fy(index) = domain_geometry.Fy(r, theta);
});
HostVector<double> Fx_h = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), Fx);
HostVector<double> Fy_h = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), Fy);
for (int index = 0; index < grid.numberOfNodes(); index++) {
file << Fx(index) << " " << Fy(index) << " " << 0 << "\n";
file << Fx_h(index) << " " << Fy_h(index) << " " << 0 << "\n";
}
file << "</DataArray>\n"
<< "</Points>\n";
Expand Down Expand Up @@ -280,13 +282,23 @@ void GMGPolar<DomainGeometry, DensityProfileCoefficients>::writeToVTK(const std:
// Write points
file << "<Points>\n"
<< "<DataArray type=\"Float64\" NumberOfComponents=\"3\" format=\"ascii\">\n";
int i_r, i_theta;
double r, theta;
Vector<double> Fx("Fx", grid.numberOfNodes());

@julianlitz julianlitz Aug 10, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

You could use
levels_[0].rhs() and levels_[0].residual() as temporary storage to avoid this vector allocation.

Note that rhs() is filled with correct values at the start of each gmgpolar.solve() call. Also rhs() is no longer used after this writeSolutionToVTK function.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
Vector<double> Fx("Fx", grid.numberOfNodes());
const int level_depth = 0;
Vector<double> Fx = levels_[level_depth].rhs();

Vector<double> Fy("Fy", grid.numberOfNodes());

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
Vector<double> Fy("Fy", grid.numberOfNodes());
Vector<double> Fy = levels_[level_depth].residual();

const DomainGeometry& domain_geometry = domain_geometry_;
Kokkos::parallel_for(
"collect Fx,Fy", Kokkos::RangePolicy<Kokkos::DefaultExecutionSpace>(0, grid.numberOfNodes()),
KOKKOS_LAMBDA(int index) {
int i_r, i_theta;
grid.multiIndex(index, i_r, i_theta);
double r = grid.radius(i_r);
double theta = grid.theta(i_theta);
Fx(index) = domain_geometry.Fx(r, theta);
Fy(index) = domain_geometry.Fy(r, theta);
});
HostVector<double> Fx_h = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), Fx);
HostVector<double> Fy_h = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), Fy);
for (int index = 0; index < grid.numberOfNodes(); index++) {
grid.multiIndex(index, i_r, i_theta);
r = grid.radius(i_r);
theta = grid.theta(i_theta);
file << domain_geometry_.Fx(r, theta) << " " << domain_geometry_.Fy(r, theta) << " " << 0 << "\n";
file << Fx_h(index) << " " << Fy_h(index) << " " << 0 << "\n";
}

file << "</DataArray>\n"
Expand Down
Loading