LCOV - code coverage report
Current view: top level - issm-precice - confreader.hpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 90.9 % 11 10
Test Date: 2026-08-10 06:53:29 Functions: 75.0 % 4 3

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

Generated by: LCOV version 2.0-1