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..bc0413fb 100644 --- a/src/tcopflow/interface/tcopflow.cpp +++ b/src/tcopflow/interface/tcopflow.cpp @@ -527,9 +527,9 @@ PetscErrorCode TCOPFLOWSetUp(TCOPFLOW tcopflow) { CHKERRQ(ierr); ierr = MatSetFromOptions(tcopflow->Jac); CHKERRQ(ierr); - /* Assume 10% sparsity */ - ierr = MatSeqAIJSetPreallocation(tcopflow->Jac, - (PetscInt)(0.1 * tcopflow->Nx), NULL); + /* 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); CHKERRQ(ierr); ierr = MatSetOption(tcopflow->Jac, MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE); @@ -543,9 +543,9 @@ PetscErrorCode TCOPFLOWSetUp(TCOPFLOW tcopflow) { CHKERRQ(ierr); ierr = MatSetFromOptions(tcopflow->Hes); CHKERRQ(ierr); - /* Assume 10% sparsity */ - ierr = MatSeqAIJSetPreallocation(tcopflow->Hes, - (PetscInt)(0.1 * tcopflow->Nx), NULL); + /* 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); CHKERRQ(ierr); ierr = MatSetOption(tcopflow->Hes, MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE);