From 470705795810d42169b6d5956adb5580da9bffdc Mon Sep 17 00:00:00 2001 From: superwhiskers Date: Mon, 24 Aug 2026 14:12:37 -0400 Subject: [PATCH 1/2] make some changes necessary for larger problems to converge - assume a minimum of 50 nz per row in jacobian, hessian matrices in tcopflow - increase maxline so some files are not truncated - this should be replaced with a truncation check or streaming so it is easier to troubleshoot in the future --- include/constants.h | 12 +++++++----- src/tcopflow/interface/tcopflow.cpp | 10 ++++++---- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/include/constants.h b/include/constants.h index 621c955d..c3a26723 100644 --- a/include/constants.h +++ b/include/constants.h @@ -8,11 +8,13 @@ #include #define freq 60.0 /**< System frequency */ #define w_s (2.0 * PETSC_PI * freq) /**< Angular speed */ -#define MAXLINE 10000 /**< Max. number of characters in a line */ -#define ISOLATED_BUS 4 /**< Isolated bus */ -#define REF_BUS 3 /**< Reference bus (swing bus) */ -#define PV_BUS 2 /**< PV (voltage-controlled) bus */ -#define PQ_BUS 1 /**< PQ bus */ +// FIXME: either validate that a line fits within this buffer or replace the use +// of a fixed-size buffer +#define MAXLINE 1000000 /**< Max. number of characters in a line */ +#define ISOLATED_BUS 4 /**< Isolated bus */ +#define REF_BUS 3 /**< Reference bus (swing bus) */ +#define PV_BUS 2 /**< PV (voltage-controlled) bus */ +#define PQ_BUS 1 /**< PQ bus */ #define NGEN_AT_BUS_MAX \ 32 /**< Maximum number of generators allowed at a bus \ */ diff --git a/src/tcopflow/interface/tcopflow.cpp b/src/tcopflow/interface/tcopflow.cpp index 37d18449..1d184294 100644 --- a/src/tcopflow/interface/tcopflow.cpp +++ b/src/tcopflow/interface/tcopflow.cpp @@ -527,9 +527,10 @@ PetscErrorCode TCOPFLOWSetUp(TCOPFLOW tcopflow) { CHKERRQ(ierr); ierr = MatSetFromOptions(tcopflow->Jac); CHKERRQ(ierr); - /* Assume 10% sparsity */ + /* Assume 10% sparsity with a minimum of 50 nz per row */ + PetscInt jac_nz_per_row = PetscMin((PetscInt)(0.1 * tcopflow->Nx), 50); ierr = MatSeqAIJSetPreallocation(tcopflow->Jac, - (PetscInt)(0.1 * tcopflow->Nx), NULL); + jac_nz_per_row, NULL); CHKERRQ(ierr); ierr = MatSetOption(tcopflow->Jac, MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE); @@ -543,9 +544,10 @@ PetscErrorCode TCOPFLOWSetUp(TCOPFLOW tcopflow) { CHKERRQ(ierr); ierr = MatSetFromOptions(tcopflow->Hes); CHKERRQ(ierr); - /* Assume 10% sparsity */ + /* Assume 10% sparsity with a minimum of 50 nz per row */ + PetscInt hes_nz_per_row = PetscMin((PetscInt)(0.1 * tcopflow->Nx), 50); ierr = MatSeqAIJSetPreallocation(tcopflow->Hes, - (PetscInt)(0.1 * tcopflow->Nx), NULL); + hes_nz_per_row, NULL); CHKERRQ(ierr); ierr = MatSetOption(tcopflow->Hes, MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE); From cc332e1e9bfa9aa1486ecc11172ad3f2b8b39cd1 Mon Sep 17 00:00:00 2001 From: superwhiskers Date: Mon, 24 Aug 2026 18:18:34 +0000 Subject: [PATCH 2/2] Apply pre-commmit fixes --- src/tcopflow/interface/tcopflow.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/tcopflow/interface/tcopflow.cpp b/src/tcopflow/interface/tcopflow.cpp index 1d184294..bc0413fb 100644 --- a/src/tcopflow/interface/tcopflow.cpp +++ b/src/tcopflow/interface/tcopflow.cpp @@ -529,8 +529,7 @@ PetscErrorCode TCOPFLOWSetUp(TCOPFLOW tcopflow) { CHKERRQ(ierr); /* Assume 10% sparsity with a minimum of 50 nz per row */ PetscInt jac_nz_per_row = PetscMin((PetscInt)(0.1 * tcopflow->Nx), 50); - ierr = MatSeqAIJSetPreallocation(tcopflow->Jac, - jac_nz_per_row, NULL); + ierr = MatSeqAIJSetPreallocation(tcopflow->Jac, jac_nz_per_row, NULL); CHKERRQ(ierr); ierr = MatSetOption(tcopflow->Jac, MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE); @@ -546,8 +545,7 @@ PetscErrorCode TCOPFLOWSetUp(TCOPFLOW tcopflow) { CHKERRQ(ierr); /* Assume 10% sparsity with a minimum of 50 nz per row */ PetscInt hes_nz_per_row = PetscMin((PetscInt)(0.1 * tcopflow->Nx), 50); - ierr = MatSeqAIJSetPreallocation(tcopflow->Hes, - hes_nz_per_row, NULL); + ierr = MatSeqAIJSetPreallocation(tcopflow->Hes, hes_nz_per_row, NULL); CHKERRQ(ierr); ierr = MatSetOption(tcopflow->Hes, MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE);