Line data Source code
1 : // SPDX-FileCopyrightText: 2024 Daniel Abele <daniel.abele@dlr.de> 2 : // 3 : // SPDX-License-Identifier: BSD-3-Clause 4 : 5 : #pragma once 6 : 7 : #include "issm-precice/enums.hpp" 8 : #include "shared/Enum/Enum.h" 9 : #include "mpi.h" 10 : #include <filesystem> 11 : #include <string> 12 : #include <unordered_map> 13 : #include <variant> 14 : #include <vector> 15 : 16 : namespace ipc 17 : { 18 : 19 : /** 20 : * Represents the direction of data flow in coupling. 21 : */ 22 : enum class DataDirection 23 : { 24 : Read, 25 : Write, 26 : }; 27 : 28 : /** 29 : * Represents optional attributes of the coupled variables. 30 : */ 31 : enum class VariableFlags 32 : { 33 : None = 0, 34 : DepthAverage = 0B1, //! depth average the variable before writing 35 : Extrude = 0B10, //! extrude the variable after reading 36 : Constraint = 0B100, //! the variable is a constraint, not a normal field 37 : }; 38 : 39 : // make VariableFlags usable as a typesafe flag type 40 : template<> 41 : struct EnumFlagTraits<VariableFlags> : std::true_type 42 : {}; 43 : 44 : /** 45 : * Defines a variable to be exchanged in coupling. 46 : */ 47 : struct VariableDefinition 48 : { 49 : //Input id of the variable. 50 25 : definitions id; 51 : 52 : //Direction of the coupling. 53 5 : DataDirection direction; 54 : 55 : //Name of the variable known to the coupling framework. 56 : //May not be the same name as in ISSM. 57 5 : std::string data_name; 58 : 59 : //Optional attributes of the variable. 60 5 : FlagType<VariableFlags> flags = VariableFlags::None; 61 : 62 25 : bool operator==(const VariableDefinition& other) const = default; 63 : }; 64 : 65 : /** 66 : * Definitions specific for a horizontal 2D mesh. 67 : */ 68 : struct Mesh2dDefinition 69 : { 70 : //layer of the 2d mesh 71 : //if positive: 0 = base, 1 = one layer above base, etc; 72 : //if negative: -1 = surface, -2 one layer below surface, etc (like numpy reverse indexing) 73 4 : int layer; 74 : 75 4 : bool operator==(const Mesh2dDefinition& other) const = default; 76 : }; 77 : 78 : /** 79 : * Definitions specific for a horizontal 3D mesh. 80 : */ 81 : struct Mesh3dDefinition 82 : { 83 0 : bool operator==(const Mesh3dDefinition& other) const = default; 84 : }; 85 : 86 : /** 87 : * Defines the mesh used in coupling. 88 : */ 89 : struct MeshDefinition 90 : { 91 : //name of the mesh as known to preCICE 92 3 : std::string name; 93 : 94 : //type of the mesh with specific settings 95 3 : std::variant<Mesh2dDefinition, Mesh3dDefinition> type; 96 : 97 3 : bool operator==(const MeshDefinition& other) const = default; 98 : }; 99 : 100 : /** 101 : * preCICE config. 102 : */ 103 : struct PreciceConfig 104 : { 105 : //path to the preCICE config file 106 : std::filesystem::path config_file; 107 : 108 : //name of the ISSM participant known to preCICE 109 : std::string solver_name; 110 : 111 : bool operator==(const PreciceConfig& other) const = default; 112 : }; 113 : 114 : /** 115 : * ISSM config. 116 : */ 117 : struct IssmConfig 118 : { 119 : //path to the directory containing the ISSM model files 120 : std::filesystem::path root_path; 121 : 122 : //name of the ISSM model 123 : std::string model_name; 124 : 125 : bool operator==(const IssmConfig& other) const = default; 126 : }; 127 : 128 : /** 129 : * Configuration of the issm-precice adapter. 130 : */ 131 : class Config 132 : { 133 : public: 134 : // 135 : PreciceConfig precice; 136 : 137 : // 138 : IssmConfig issm; 139 : 140 : //mesh used in coupling 141 : MeshDefinition mesh; 142 : 143 : //variables to be exchanged in coupling. 144 : std::vector<VariableDefinition> variables; 145 : 146 : bool operator==(const Config& other) const = default; 147 : }; 148 : 149 : /** 150 : * Read the config from the specified file. 151 : * @param file Path to the config file. 152 : * @returns Config read from the file. 153 : */ 154 : Config read_config(const std::filesystem::path& file, MPI_Comm comm); 155 : 156 : } // namespace ipc