#ifndef GRIDOXIDE_H
#define GRIDOXIDE_H
#define GRIDOXIDE_ABI_VERSION 1
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
typedef enum gridoxide_status {
GRIDOXIDE_STATUS_OK = 0,
GRIDOXIDE_STATUS_INVALID_ARGUMENT = 1,
GRIDOXIDE_STATUS_IO = 2,
GRIDOXIDE_STATUS_PARSE = 3,
GRIDOXIDE_STATUS_NOT_CONVERGED = 4,
GRIDOXIDE_STATUS_SINGULAR = 5,
GRIDOXIDE_STATUS_NO_ANSWER = 6,
GRIDOXIDE_STATUS_PANIC = 7,
GRIDOXIDE_STATUS_INTERNAL = 8,
} gridoxide_status;
typedef enum gridoxide_backend {
GRIDOXIDE_BACKEND_SCALAR = 0,
GRIDOXIDE_BACKEND_BLOCK = 1,
GRIDOXIDE_BACKEND_KLU = 2,
GRIDOXIDE_BACKEND_KLU_NATIVE = 3,
GRIDOXIDE_BACKEND_PARDISO = 4,
} gridoxide_backend;
typedef enum gridoxide_bus_type {
GRIDOXIDE_BUS_TYPE_SLACK = 0,
GRIDOXIDE_BUS_TYPE_PV = 1,
GRIDOXIDE_BUS_TYPE_PQ = 2,
} gridoxide_bus_type;
typedef enum gridoxide_island_status {
GRIDOXIDE_ISLAND_STATUS_CONVERGED = 0,
GRIDOXIDE_ISLAND_STATUS_MAX_ITERATIONS_REACHED = 1,
GRIDOXIDE_ISLAND_STATUS_SINGULAR = 2,
GRIDOXIDE_ISLAND_STATUS_NO_REFERENCE_BUS = 3,
GRIDOXIDE_ISLAND_STATUS_AMBIGUOUS_REFERENCE_BUS = 4,
} gridoxide_island_status;
typedef struct gridoxide_powerflow gridoxide_powerflow;
typedef struct gridoxide_options {
enum gridoxide_backend backend;
double tolerance;
size_t max_iterations;
double s_base_va;
double frequency_hz;
} gridoxide_options;
typedef struct gridoxide_bus {
enum gridoxide_bus_type bus_type;
double voltage_magnitude;
double voltage_angle;
double p_spec;
double q_spec;
double q_min;
double q_max;
double u_rated;
} gridoxide_bus;
typedef struct gridoxide_line {
size_t from;
size_t to;
double r;
double x;
double b_shunt;
double g_shunt;
} gridoxide_line;
typedef struct gridoxide_complex {
double re;
double im;
} gridoxide_complex;
typedef struct gridoxide_transformer {
size_t from;
size_t to;
uint8_t from_status;
uint8_t to_status;
struct gridoxide_complex y_series;
struct gridoxide_complex y_shunt;
struct gridoxide_complex tap;
} gridoxide_transformer;
typedef struct gridoxide_shunt {
size_t at;
struct gridoxide_complex y;
} gridoxide_shunt;
#ifdef __cplusplus
extern "C" {
#endif
const char *gridoxide_last_error_message(void);
uint32_t gridoxide_abi_version(void);
const char *gridoxide_version(void);
enum gridoxide_status gridoxide_powerflow_from_pgm_file(const char *path,
const struct gridoxide_options *options,
struct gridoxide_powerflow **out);
enum gridoxide_status gridoxide_powerflow_from_pgm_string(const char *json,
size_t len,
const struct gridoxide_options *options,
struct gridoxide_powerflow **out);
enum gridoxide_status gridoxide_powerflow_from_arrays(const struct gridoxide_bus *buses,
size_t n_buses,
const struct gridoxide_line *lines,
size_t n_lines,
const struct gridoxide_transformer *transformers,
size_t n_transformers,
const struct gridoxide_shunt *shunts,
size_t n_shunts,
const struct gridoxide_options *options,
struct gridoxide_powerflow **out);
void gridoxide_powerflow_free(struct gridoxide_powerflow *handle);
enum gridoxide_status gridoxide_powerflow_solve(struct gridoxide_powerflow *handle);
enum gridoxide_status gridoxide_powerflow_solve_enforcing_q_limits(struct gridoxide_powerflow *handle,
size_t max_outer_iterations);
enum gridoxide_status gridoxide_powerflow_solve_distributing_slack(struct gridoxide_powerflow *handle,
const double *factors,
size_t n_factors);
enum gridoxide_status gridoxide_powerflow_solve_with_controls(struct gridoxide_powerflow *handle,
int32_t enforce_q_limits,
int32_t distribute_slack,
const double *slack_factors,
size_t n_factors,
size_t max_outer_iterations);
size_t gridoxide_powerflow_bus_count(const struct gridoxide_powerflow *handle);
size_t gridoxide_powerflow_branch_count(const struct gridoxide_powerflow *handle);
enum gridoxide_status gridoxide_powerflow_voltage_magnitude(const struct gridoxide_powerflow *handle,
double *out,
size_t len);
enum gridoxide_status gridoxide_powerflow_voltage_angle(const struct gridoxide_powerflow *handle,
double *out,
size_t len);
enum gridoxide_status gridoxide_powerflow_branch_flow(const struct gridoxide_powerflow *handle,
int terminal,
double *p_out,
double *q_out,
size_t len);
enum gridoxide_status gridoxide_powerflow_slack_shift(const struct gridoxide_powerflow *handle,
double *out,
size_t len);
size_t gridoxide_powerflow_iterations(const struct gridoxide_powerflow *handle);
double gridoxide_powerflow_max_mismatch(const struct gridoxide_powerflow *handle);
size_t gridoxide_powerflow_island_count(const struct gridoxide_powerflow *handle);
enum gridoxide_status gridoxide_powerflow_island_status(const struct gridoxide_powerflow *handle,
size_t island,
enum gridoxide_island_status *out);
size_t gridoxide_powerflow_island_bus_count(const struct gridoxide_powerflow *handle,
size_t island);
enum gridoxide_status gridoxide_powerflow_island_buses(const struct gridoxide_powerflow *handle,
size_t island,
size_t *out,
size_t len);
void gridoxide_options_default(struct gridoxide_options *out);
#ifdef __cplusplus
} #endif
#endif