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
1 change: 1 addition & 0 deletions src/pcms/field/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ if (PCMS_ENABLE_OMEGA_H)
uniform_grid_binary_field.h
evaluator/uniform_grid.h
evaluator/uniform_grid_spline.h
eqdsk_field.h
evaluator/mls_options.h
evaluator/mls_interpolation.hpp
evaluator/mls_interpolation_impl.hpp
Expand Down
76 changes: 76 additions & 0 deletions src/pcms/field/eqdsk_field.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#ifndef PCMS_EQDSK_FIELD_H
#define PCMS_EQDSK_FIELD_H

#include "pcms/utility/eqdsk.h"
#include "pcms/field/layout/uniform_grid.h"
#include "pcms/field/function_space/spline.h"

#include <string>

namespace pcms
{

struct EQDSKField

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.

Is there ever a time where we would have an eqdsk with no data associated with it?

@Sichao25 Sichao25 Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There will always be an EQDSKData, but it doesn't have to be created with the helper functions defined here. It can be constructed manually instead of loaded directly from a file. The struct defined here is just for return values.

{
SplineFunctionSpace space;
Field<Real> field;
};

// TODD: @jacobmerson replace with Function.
struct EQDSKFieldWithData
Comment thread
Sichao25 marked this conversation as resolved.
{
EQDSKData data;
SplineFunctionSpace space;
Field<Real> field;
};

/**
* @brief Create a SplineFunctionSpace and Field from EQDSKData, combining
* function space creation, field allocation, and DOF holder data population
* into a single call.
*
* Performs three steps:
* 1. Creates a SplineFunctionSpace from the EQDSK data
* 2. Creates a Field<Real> on that function space
* 3. Populates the field's DOF holder with the PSIZR flux data
*
* @param eqdsk_data The EQDSK equilibrium data containing the grid and flux
* values.
* @return EQDSKField A struct containing the function space and populated
* field, ready for evaluation.
*/
inline EQDSKField MakeEQDSKField(const EQDSKData& eqdsk_data)
{
auto space = SplineFunctionSpace::FromUniformGrid(
eqdsk_data.grid, CoordinateSystem::Cartesian);
auto field = space.CreateField<Real>();
field.GetData().SetDOFHolderData(Rank1View<const Real, DeviceMemorySpace>(
eqdsk_data.PSIZR.data(), eqdsk_data.PSIZR.extent(0)));
return {std::move(space), std::move(field)};
}

/**
* @brief Read an EQDSK file and construct a SplineFunctionSpace and Field from
* it, combining file I/O, function space creation, field allocation, and DOF
* holder data population into a single call.
*
* Performs four steps:
* 1. Reads the EQDSK file into an EQDSKData
* 2. Creates a SplineFunctionSpace from the data
* 3. Creates a Field<Real> on that function space
* 4. Populates the field's DOF holder with the PSIZR flux data
*
* @param filename Path to the EQDSK equilibrium file.
* @return EQDSKFieldWithData A struct containing the data, function space,
* and populated field, ready for evaluation.
*/
inline EQDSKFieldWithData MakeEQDSKField(const std::string& filename)

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.

@usmanriaz07 Are there potentially other fields in the EQDSK that may need to be evaluated later, or is the only field we evaluated in the eqdsk the psi field?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

We do use poloidal current value in the field line tracing. See the following piece of code:
https://github.com/SCOREC/STOMMS/blob/main/stomms_meshgen/src/eqdskData.cc#L197-L203

In ezfit.F90, the relevant function is: https://github.com/SCOREC/STOMMS/blob/main/stomms_meshgen/src/ezfit.F90#L562-L578

Other than poloidal current, we only need psi field.

Comment thread
Sichao25 marked this conversation as resolved.
{
auto eqdsk_data = EQDSKData(filename);
auto [space, field] = MakeEQDSKField(eqdsk_data);
return {std::move(eqdsk_data), std::move(space), std::move(field)};
}

} // namespace pcms

#endif // PCMS_EQDSK_FIELD_H
1 change: 1 addition & 0 deletions src/pcms/field/function_space/spline.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "pcms/field/out_of_bounds_policy.h"
#include "pcms/field/point_evaluator.h"
#include "pcms/utility/arrays.h"
#include "pcms/utility/eqdsk.h"
#include "pcms/utility/memory_spaces.h"
#include "pcms/utility/uniform_grid.h"

Expand Down
5 changes: 5 additions & 0 deletions src/pcms/utility/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set(
bounding_box.h
common.h
entity_types.h
eqdsk.h
mesh_geometry.h
memory_spaces.h
mpi_type.h
Expand All @@ -20,6 +21,7 @@ set(
set(
PCMS_UTILITY_SOURCES
assert.cpp
eqdsk.cpp
print.cpp
)
add_library(pcms_utility ${PCMS_UTILITY_SOURCES})
Expand All @@ -33,6 +35,9 @@ target_include_directories(
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/../..>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
target_link_libraries(pcms_utility PUBLIC Kokkos::kokkos perfstubs)
if(PCMS_ENABLE_OMEGA_H)
target_link_libraries(pcms_utility PUBLIC Omega_h::omega_h)
endif()
target_compile_features(pcms_utility PUBLIC cxx_std_20)

set_target_properties(
Expand Down
Loading
Loading