Gyselalib++
 
Loading...
Searching...
No Matches
input.hpp
1// SPDX-License-Identifier: MIT
2#pragma once
3#include <sstream>
4
5#include <ddc/ddc.hpp>
6
7#include <paraconf.h>
8#include <pdi.h>
9
10#include "ddc_aliases.hpp"
11#include "mesh_builder.hpp"
12#include "non_uniform_interpolation_points.hpp"
13#include "paraconfpp.hpp"
14#include "pdi_helper.hpp"
15
25void parse_executable_arguments(
26 PC_tree_t& conf_voicexx,
27 long int& iter_start,
28 int argc,
29 char** argv,
30 char const* const params_yaml);
31
41PC_tree_t parse_executable_arguments(int argc, char** argv, char const* const params_yaml);
42
43
61template <class Grid1D, class BSplines, class InterpPointInitMethod>
62inline IdxRange<Grid1D> init_spline_dependent_idx_range(
63 PC_tree_t const& conf_voicexx,
64 std::string const& mesh_identifier)
65{
66 using Dim = typename Grid1D::continuous_dimension_type;
67 using Coord1D = ddc::Coordinate<Dim>;
68
69 std::vector<Coord1D> breakpoints;
70
71 if constexpr (BSplines::is_uniform()) {
72 // If uniform BSplines are used and interpolation points are calculated from them
73 Coord1D min(PCpp_double(conf_voicexx, ".SplineMesh." + mesh_identifier + "_min"));
74 Coord1D max(PCpp_double(conf_voicexx, ".SplineMesh." + mesh_identifier + "_max"));
75 IdxStep<Grid1D> ncells(
76 PCpp_int(conf_voicexx, ".SplineMesh." + mesh_identifier + "_ncells"));
77 ddc::init_discrete_space<BSplines>(min, max, ncells);
78 } else if constexpr (!ddcHelper::is_non_uniform_interpolation_points_v<InterpPointInitMethod>) {
79 PDI_get_arrays("read_" + mesh_identifier, "breakpoints_" + mesh_identifier, breakpoints);
80 ddc::init_discrete_space<BSplines>(breakpoints);
81 }
82
83 if constexpr (ddcHelper::is_non_uniform_interpolation_points_v<InterpPointInitMethod>) {
84 // If uniform BSplines are used but the interpolation points are provided by the user
85 // This may be the case if you want to test a new choice of interpolation points or
86 // if you want to ensure that the interpolation points used match exactly the points
87 // used to initialise values passed into the simulation.
88 std::vector<Coord1D> mesh;
89 std::string grid_name = "grid_" + mesh_identifier;
90
91 if constexpr (BSplines::is_uniform()) {
92 PDI_get_arrays("read_" + mesh_identifier, grid_name, mesh);
93 } else {
94 std::string breakpoints_name = "breakpoints_" + mesh_identifier;
95 PDI_get_arrays(
96 "read_" + mesh_identifier,
97 breakpoints_name,
98 breakpoints,
99 grid_name,
100 mesh);
101 ddc::init_discrete_space<BSplines>(breakpoints);
102 }
103 ddc::init_discrete_space<Grid1D>(
104 InterpPointInitMethod::template get_sampling<Grid1D>(mesh));
105 } else {
106 ddc::init_discrete_space<Grid1D>(InterpPointInitMethod::template get_sampling<Grid1D>());
107 }
108 IdxRange<Grid1D> interpolation_idx_range(InterpPointInitMethod::template get_domain<Grid1D>());
109 return interpolation_idx_range;
110}
111
129template <class Grid1D, class BSplines, class InterpPointInitMethod>
130inline IdxRange<Grid1D> init_pseudo_uniform_spline_dependent_idx_range(
131 PC_tree_t const& conf_voicexx,
132 std::string const& mesh_identifier)
133{
134 static_assert(!BSplines::is_uniform());
135 using Dim = typename Grid1D::continuous_dimension_type;
136 using Coord1D = Coord<Dim>;
137
138 Coord1D min(PCpp_double(conf_voicexx, ".SplineMesh." + mesh_identifier + "_min"));
139 Coord1D max(PCpp_double(conf_voicexx, ".SplineMesh." + mesh_identifier + "_max"));
140 IdxStep<Grid1D> ncells(PCpp_int(conf_voicexx, ".SplineMesh." + mesh_identifier + "_ncells"));
141
142 std::vector<Coord1D> break_points = build_uniform_break_points(min, max, ncells);
143
144 ddc::init_discrete_space<BSplines>(break_points);
145 ddc::init_discrete_space<Grid1D>(InterpPointInitMethod::template get_sampling<Grid1D>());
146 IdxRange<Grid1D> interpolation_idx_range(InterpPointInitMethod::template get_domain<Grid1D>());
147 return interpolation_idx_range;
148}