Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
176 changes: 0 additions & 176 deletions GridKit/AutomaticDifferentiation/Enzyme/DfDwb.hpp

This file was deleted.

107 changes: 0 additions & 107 deletions GridKit/AutomaticDifferentiation/Enzyme/DfDws.hpp

This file was deleted.

79 changes: 3 additions & 76 deletions GridKit/AutomaticDifferentiation/Enzyme/DfDy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace GridKit
* @param[in] var_indices - Global variable indices
* @param[in] y - Internal variables
* @param[in] yp - Internal variable derivatives
* @param[in] wb - Bus variables
* @param[in] y_ext - External variables
* @param[out] rows - Row indices
* @param[out] cols - Column indices
* @param[out] vals - Values
Expand All @@ -50,7 +50,7 @@ namespace GridKit
const IdxT* var_indices,
const ScalarT* y,
const ScalarT* yp,
const ScalarT* wb,
const ScalarT* y_ext,
IdxT* rows,
IdxT* cols,
RealT* vals,
Expand Down Expand Up @@ -90,80 +90,7 @@ namespace GridKit
enzyme_const,
yp,
enzyme_const,
wb,
enzyme_dupnoneed,
elementary_v.data(),
d_output);
}
}
}

/**
* @param[in] model - Pointer to the model to be differentiated
* @param[in] n_res - Number of residual functions
* @param[in] n_var - Number of independent variables
* @param[in] res_indices - Map from local residual indices to global indices
* @param[in] var_indices - Map from local variable indices to global indices
* @param[in] y - Internal variables
* @param[in] yp - Internal variable derivatives
* @param[in] wb - Bus variables
* @param[in] ws - Signal variables
* @param[out] rows - Row indices
* @param[out] cols - Column indices
* @param[out] vals - Values
* @param[out] nnz - Number of nonzeros
*/
static void eval(ModelT* model,
const size_t n_res,
const size_t n_var,
const IdxT* res_indices,
const IdxT* var_indices,
const ScalarT* y,
const ScalarT* yp,
const ScalarT* wb,
const ScalarT* ws,
IdxT* rows,
IdxT* cols,
RealT* vals,
IdxT& nnz)
{
if (n_res > 0 && n_var > 0)
{
std::vector<ScalarT> elementary_v(n_var);
for (size_t var_i = 0; var_i < n_var; ++var_i)
{
// Sparse storage. @see LowerSparseStorage.hpp
ScalarT* output = __enzyme_todense<ScalarT*>((void*) ident_load<ScalarT, IdxT>,
(void*) ident_store<ScalarT, IdxT>,
var_i);
ScalarT* d_output = __enzyme_todense<ScalarT*>((void*) sparse_load<ScalarT, IdxT>,
(void*) sparse_store<ScalarT, IdxT>,
var_i,
1.0, // value scaling
res_indices,
var_indices,
rows,
cols,
vals,
&nnz);

// Elementary vector for Jacobian-vector product
std::ranges::fill(elementary_v, 0.0);
elementary_v[var_i] = 1.0;

// Core automatic differentiation intrinsic that will be replaced by a derivative
__enzyme_fwddiff<void>((void*) ModelWrapper<ModelT, function>::eval,
enzyme_const,
model,
enzyme_dup,
y,
output,
enzyme_const,
yp,
enzyme_const,
wb,
enzyme_const,
ws,
y_ext,
enzyme_dupnoneed,
elementary_v.data(),
d_output);
Expand Down
Loading
Loading