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 common/vmec_indata/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ cc_test(
"//vmecpp/test_data:cth_like_free_bdy",
"//vmecpp_large_cpp_tests/test_data:solovev",
"//vmecpp_large_cpp_tests/test_data:solovev_analytical",
"//vmecpp_large_cpp_tests/test_data:solovev_free_bdy",
"//vmecpp_large_cpp_tests/test_data:solovev_no_axis",
"//vmecpp_large_cpp_tests/test_data:cth_like_fixed_bdy",
"//vmecpp_large_cpp_tests/test_data:cth_like_fixed_bdy_nzeta_37",
Expand Down
119 changes: 119 additions & 0 deletions common/vmec_indata/vmec_indata_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,125 @@ TEST(TestVmecINDATA, CheckParsingSolovevAnalytical) {
}
} // CheckParsingSolovevAnalytical


TEST(TestVmecINDATA, CheckParsingSolovevFreeBdy) {
absl::StatusOr<std::string> indata_json =
ReadFile("vmecpp_large_cpp_tests/test_data/solovev_free_bdy.json");
ASSERT_TRUE(indata_json.ok()) << indata_json.status().message();

const absl::StatusOr<VmecINDATA> vmec_indata =
VmecINDATA::FromJson(*indata_json);
ASSERT_TRUE(vmec_indata.ok());

// numerical resolution, symmetry assumption
EXPECT_EQ(vmec_indata->lasym, false);
EXPECT_EQ(vmec_indata->nfp, 1);
EXPECT_EQ(vmec_indata->mpol, 6);
EXPECT_EQ(vmec_indata->ntor, 0);
EXPECT_EQ(vmec_indata->ntheta, 0);
EXPECT_EQ(vmec_indata->nzeta, 1);

// multi-grid steps
EXPECT_THAT(vmec_indata->ns_array, ElementsAre(16, 32));
EXPECT_THAT(vmec_indata->ftol_array, ElementsAre(1.0e-10, 1.0e-14));
EXPECT_THAT(vmec_indata->niter_array, ElementsAre(10000, 20000));

// global physics parameters
EXPECT_EQ(vmec_indata->phiedge, 1.0);
EXPECT_EQ(vmec_indata->ncurr, 0);

// mass / pressure profile
EXPECT_EQ(vmec_indata->pmass_type, "power_series");
EXPECT_THAT(vmec_indata->am, ElementsAre(0.125, -0.125));
EXPECT_EQ(vmec_indata->am_aux_s.size(), 0);
EXPECT_EQ(vmec_indata->am_aux_f.size(), 0);
EXPECT_EQ(vmec_indata->pres_scale, 1.0);
EXPECT_EQ(vmec_indata->gamma, 0.0);
EXPECT_EQ(vmec_indata->spres_ped, 1.0);

// (initial guess for) iota profile
EXPECT_EQ(vmec_indata->piota_type, "power_series");
EXPECT_THAT(vmec_indata->ai, ElementsAre(0.49, -0.3));
EXPECT_EQ(vmec_indata->ai_aux_s.size(), 0);
EXPECT_EQ(vmec_indata->ai_aux_f.size(), 0);

// enclosed toroidal current profile
EXPECT_EQ(vmec_indata->pcurr_type, "power_series");
EXPECT_EQ(vmec_indata->ac.size(), 0);
EXPECT_EQ(vmec_indata->ac_aux_s.size(), 0);
EXPECT_EQ(vmec_indata->ac_aux_f.size(), 0);
EXPECT_EQ(vmec_indata->curtor, 0.0);
EXPECT_EQ(vmec_indata->bloat, 1.0);

// free-boundary parameters
EXPECT_EQ(vmec_indata->lfreeb, true);
EXPECT_EQ(vmec_indata->mgrid_file, "vmecpp_large_cpp_tests/test_data/mgrid_solovev.nc");
EXPECT_THAT(vmec_indata->extcur, ElementsAre(3884526.409876309,
-293557.7123737952,
-17348.51853677043,
60021.3701697316,
60025.40940490887,
-17349.93103183817,
-293553.153630851,
-356063.9108717275,
-65884.34719283084,
-11543.87774712987,
-11535.46510755219,
-65883.00858364606,
-356058.9388468855));
EXPECT_EQ(vmec_indata->nvacskip, 6);

// tweaking parameters
EXPECT_EQ(vmec_indata->nstep, 100);
EXPECT_THAT(vmec_indata->aphi, ElementsAre(1.0));
EXPECT_EQ(vmec_indata->delt, 0.9);
EXPECT_EQ(vmec_indata->tcon0, 1.0);
EXPECT_EQ(vmec_indata->lforbal, false);

// initial guess for magnetic axis
absl::StatusOr<std::string> axis_coefficients_csv =
ReadFile("vmecpp_large_cpp_tests/test_data/axis_coefficients_solovev_free_bdy.csv");
ASSERT_TRUE(axis_coefficients_csv.ok());

absl::StatusOr<CurveRZFourier> axis_coefficients =
CurveRZFourierFromCsv(*axis_coefficients_csv);
ASSERT_TRUE(axis_coefficients.ok());
EXPECT_THAT(vmec_indata->raxis_c,
ElementsAreArray(*CoefficientsRCos(*axis_coefficients)));
EXPECT_THAT(vmec_indata->zaxis_s,
ElementsAreArray(*CoefficientsZSin(*axis_coefficients)));
if (vmec_indata->lasym) {
EXPECT_THAT(*vmec_indata->raxis_s,
ElementsAreArray(*CoefficientsRSin(*axis_coefficients)));
EXPECT_THAT(*vmec_indata->zaxis_c,
ElementsAreArray(*CoefficientsZCos(*axis_coefficients)));
} else {
EXPECT_FALSE(vmec_indata->raxis_s.has_value());
EXPECT_FALSE(vmec_indata->zaxis_c.has_value());
}

// (initial guess for) boundary shape
absl::StatusOr<std::string> boundary_coefficients_csv =
ReadFile("vmecpp_large_cpp_tests/test_data/boundary_coefficients_solovev_free_bdy.csv");
ASSERT_TRUE(boundary_coefficients_csv.ok());
absl::StatusOr<SurfaceRZFourier> boundary_coefficients =
SurfaceRZFourierFromCsv(*boundary_coefficients_csv);
ASSERT_TRUE(boundary_coefficients.ok());
EXPECT_THAT(vmec_indata->rbc.transpose().reshaped(),
ElementsAreArray(*CoefficientsRCos(*boundary_coefficients)));
EXPECT_THAT(vmec_indata->zbs.transpose().reshaped(),
ElementsAreArray(*CoefficientsZSin(*boundary_coefficients)));
if (vmec_indata->lasym) {
EXPECT_THAT(vmec_indata->rbs->transpose().reshaped(),
ElementsAreArray(*CoefficientsRSin(*boundary_coefficients)));
EXPECT_THAT(vmec_indata->zbc->transpose().reshaped(),
ElementsAreArray(*CoefficientsZCos(*boundary_coefficients)));
} else {
EXPECT_FALSE(vmec_indata->rbs.has_value());
EXPECT_FALSE(vmec_indata->zbc.has_value());
}
} // CheckParsingSolovevFreeBdy

TEST(TestVmecINDATA, CheckParsingSolovevNoAxis) {
absl::StatusOr<std::string> indata_json =
ReadFile("vmecpp/test_data/solovev_no_axis.json");
Expand Down
28 changes: 28 additions & 0 deletions test_data/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ filegroup(
name = "solovev",
visibility = ["//visibility:public"],
srcs = [
"input.solovev",
"solovev.json",
"axis_coefficients_solovev.csv",
"boundary_coefficients_solovev.csv",
"jxbout_solovev.nc",
"mercier.solovev",
"threed1.solovev",
"wout_solovev.nc",
"solovev.out.h5",
] + glob(["solovev/**/*.json"]),
)
Expand All @@ -18,47 +21,59 @@ filegroup(
name = "solovev_analytical",
visibility = ["//visibility:public"],
srcs = [
"input.solovev_analytical",
"solovev_analytical.json",
"axis_coefficients_solovev_analytical.csv",
"boundary_coefficients_solovev_analytical.csv",
"jxbout_solovev_analytical.nc",
"mercier.solovev_analytical",
"threed1.solovev_analytical",
"wout_solovev_analytical.nc",
] + glob(["solovev_analytical/**/*.json"]),
)

filegroup(
name = "solovev_free_bdy",
visibility = ["//visibility:public"],
srcs = [
"input.solovev_free_bdy",
"solovev_free_bdy.json",
"axis_coefficients_solovev_free_bdy.csv",
"boundary_coefficients_solovev_free_bdy.csv",
"jxbout_solovev_free_bdy.nc",
"mercier.solovev_free_bdy",
"threed1.solovev_free_bdy",
"wout_solovev_free_bdy.nc",
] + glob(["solovev_free_bdy/**/*.json"]),
)

filegroup(
name = "solovev_no_axis",
visibility = ["//visibility:public"],
srcs = [
"input.solovev_no_axis",
"solovev_no_axis.json",
"axis_coefficients_solovev_no_axis.csv",
"boundary_coefficients_solovev_no_axis.csv",
"jxbout_solovev_no_axis.nc",
"mercier.solovev_no_axis",
"threed1.solovev_no_axis",
"wout_solovev_no_axis.nc",
] + glob(["solovev_no_axis/**/*.json"]),
)

filegroup(
name = "cth_like_fixed_bdy",
visibility = ["//visibility:public"],
srcs = [
"input.cth_like_fixed_bdy",
"cth_like_fixed_bdy.json",
"axis_coefficients_cth_like_fixed_bdy.csv",
"boundary_coefficients_cth_like_fixed_bdy.csv",
"jxbout_cth_like_fixed_bdy.nc",
"mercier.cth_like_fixed_bdy",
"threed1.cth_like_fixed_bdy",
"wout_cth_like_fixed_bdy.nc",
"cth_like_fixed_bdy.out.h5",
] + glob(["cth_like_fixed_bdy/**/*.json"]),
)
Expand All @@ -67,34 +82,47 @@ filegroup(
name = "cth_like_fixed_bdy_nzeta_37",
visibility = ["//visibility:public"],
srcs = [
"input.cth_like_fixed_bdy_nzeta_37",
"cth_like_fixed_bdy_nzeta_37.json",
"axis_coefficients_cth_like_fixed_bdy_nzeta_37.csv",
"boundary_coefficients_cth_like_fixed_bdy_nzeta_37.csv",
"jxbout_cth_like_fixed_bdy_nzeta_37.nc",
"mercier.cth_like_fixed_bdy_nzeta_37",
"threed1.cth_like_fixed_bdy_nzeta_37",
"wout_cth_like_fixed_bdy_nzeta_37.nc",
] + glob(["cth_like_fixed_bdy_nzeta_37/**/*.json"]),
)

filegroup(
name = "cma",
visibility = ["//visibility:public"],
srcs = [
"input.cma",
"cma.json",
"axis_coefficients_cma.csv",
"boundary_coefficients_cma.csv",
"jxbout_cma.nc",
"mercier.cma",
"threed1.cma",
"wout_cma.nc",
] + glob(["cma/**/*.json"]),
)

filegroup(
name = "cth_like_free_bdy",
visibility = ["//visibility:public"],
srcs = [
"coils.cth_like",
"makegrid_parameters_cth_like.json",
"mgrid_cth_like.nc",
"input.cth_like_free_bdy",
"cth_like_free_bdy.json",
"axis_coefficients_cth_like_free_bdy.csv",
"boundary_coefficients_cth_like_free_bdy.csv",
"jxbout_cth_like_free_bdy.nc",
"mercier.cth_like_free_bdy",
"threed1.cth_like_free_bdy",
"wout_cth_like_free_bdy.nc",
] + glob(["cth_like_free_bdy/**/*.json"]),
)

Expand Down