Oakfield API Documentation 1.0.0
Numerical core APIs
Loading...
Searching...
No Matches
gradient.h File Reference

Finite-difference gradient operator writing X/Y derivative fields. More...

#include "oakfield/operator_split.h"
#include <stdbool.h>
#include <stddef.h>
Include dependency graph for gradient.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  SimGradientOperatorConfig
 Configuration for writing finite-difference gradient components. More...
 

Macros

#define SIM_GRADIENT_AXIS_AUTO   ((size_t)SIZE_MAX)
 

Typedefs

typedef enum SimGradientStencil SimGradientStencil
 Finite-difference stencils available for gradient derivatives.
 
typedef struct SimGradientOperatorConfig SimGradientOperatorConfig
 Configuration for writing finite-difference gradient components.
 

Enumerations

enum  SimGradientStencil {
  SIM_GRADIENT_STENCIL_CENTRAL_2 = 0 , SIM_GRADIENT_STENCIL_CENTRAL_4 , SIM_GRADIENT_STENCIL_FORWARD_1 , SIM_GRADIENT_STENCIL_BACKWARD_1 ,
  SIM_GRADIENT_STENCIL_FORWARD_2 , SIM_GRADIENT_STENCIL_BACKWARD_2
}
 Finite-difference stencils available for gradient derivatives. More...
 

Functions

SimResult sim_add_gradient_operator (struct SimContext *context, const SimGradientOperatorConfig *config, size_t *out_index)
 Register a finite-difference gradient operator.
 
SimResult sim_gradient_config (struct SimContext *context, size_t operator_index, SimGradientOperatorConfig *out_config)
 Copy the current gradient configuration from a registered operator.
 
SimResult sim_gradient_update (struct SimContext *context, size_t operator_index, const SimGradientOperatorConfig *config)
 Replace the configuration of a registered gradient operator.
 

Detailed Description

Finite-difference gradient operator writing X/Y derivative fields.

Enumeration Type Documentation

◆ SimGradientStencil

Finite-difference stencils available for gradient derivatives.

Enumerator
SIM_GRADIENT_STENCIL_CENTRAL_2 

Second-order central difference.

SIM_GRADIENT_STENCIL_CENTRAL_4 

Fourth-order central difference.

SIM_GRADIENT_STENCIL_FORWARD_1 

First-order forward difference.

SIM_GRADIENT_STENCIL_BACKWARD_1 

First-order backward difference.

SIM_GRADIENT_STENCIL_FORWARD_2 

Second-order forward difference.

SIM_GRADIENT_STENCIL_BACKWARD_2 

Second-order backward difference.

Function Documentation

◆ sim_add_gradient_operator()

SimResult sim_add_gradient_operator ( struct SimContext context,
const SimGradientOperatorConfig config,
size_t *  out_index 
)

Register a finite-difference gradient operator.

Parameters
contextSimulation context that will own the operator.
configOptional gradient configuration; NULL selects normalized defaults.
[out]out_indexOptional destination for the registered operator index.
Returns
SIM_RESULT_OK on success, or an error code from argument validation, field compatibility checks, allocation, or split registration.

◆ sim_gradient_config()

SimResult sim_gradient_config ( struct SimContext context,
size_t  operator_index,
SimGradientOperatorConfig out_config 
)

Copy the current gradient configuration from a registered operator.

Parameters
contextSimulation context containing the operator.
operator_indexIndex returned by sim_add_gradient_operator().
[out]out_configReceives the normalized configuration.
Returns
SIM_RESULT_OK on success, SIM_RESULT_INVALID_ARGUMENT for NULL pointers, SIM_RESULT_NOT_FOUND for a missing operator, or SIM_RESULT_INVALID_STATE when the operator has no gradient state.

◆ sim_gradient_update()

SimResult sim_gradient_update ( struct SimContext context,
size_t  operator_index,
const SimGradientOperatorConfig config 
)

Replace the configuration of a registered gradient operator.

config is required. The replacement is normalized and field compatibility is checked before storing it.

Parameters
contextSimulation context containing the operator.
operator_indexIndex of the gradient operator to update.
configReplacement gradient configuration.
Returns
SIM_RESULT_OK on success, or an error code from argument validation, lookup, state validation, or field compatibility checks.