forked from IDAES/idaes-ext
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprinting.c
92 lines (82 loc) · 3.05 KB
/
printing.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*###############################################################################
# The Institute for the Design of Advanced Energy Systems Integrated Platform
# Framework (IDAES IP) was produced under the DOE Institute for the
# Design of Advanced Energy Systems (IDAES), and is copyright (c) 2018-2021
# by the software owners: The Regents of the University of California, through
# Lawrence Berkeley National Laboratory, National Technology & Engineering
# Solutions of Sandia, LLC, Carnegie Mellon University, West Virginia University
# Research Corporation, et al. All rights reserved.
#
# Please see the files COPYRIGHT.md and LICENSE.md for full copyright and
# license information.
###############################################################################*/
// AMPL solver interface for PETSc, diagnostic printing functions.
// Author: John Eslick
#include"petsc.h"
void print_commandline(const char* msg, int argc, char **argv){
/* print command line arguments */
int i=0;
PetscPrintf(PETSC_COMM_SELF, msg);
for(i=0; i<argc; ++i) PetscPrintf(PETSC_COMM_SELF, "%s ", argv[i]);
PetscPrintf(PETSC_COMM_SELF, "\n");
}
void print_init_diagnostic(Solver_ctx *sol_ctx){
if(sol_ctx->opt.show_jac){
print_jac_asl(sol_ctx->asl);
}
if(sol_ctx->opt.show_init){
print_x_asl(sol_ctx->asl);
}
if(sol_ctx->opt.show_scale_factors){
print_var_scale_factors_asl(sol_ctx->asl);
print_con_scale_factors_asl(sol_ctx->asl);
}
}
void print_x_asl(ASL *asl){
int i=0;
PetscPrintf(PETSC_COMM_SELF, "Initial Values (scaled)\n");
for (i=0;i<n_var;++i){
PetscPrintf(PETSC_COMM_SELF, "v%d: %e <= %e <= %e\n", i, LUv[i], X0[i], Uvx[i]);
}
}
void print_var_scale_factors_asl(ASL *asl){
int i;
PetscPrintf(PETSC_COMM_SELF, "Variable Scale Factors:\n");
if(asl->i.vscale!=NULL){
for(i=0;i<n_var;++i) PetscPrintf(PETSC_COMM_SELF, " v%d: %f\n", i, asl->i.vscale[i]);
}
else{
PetscPrintf(PETSC_COMM_SELF, " None\n");
}
}
void print_con_scale_factors_asl(ASL *asl){
int i;
PetscPrintf(PETSC_COMM_SELF, "Constraint Scale Factors:\n");
if(asl->i.cscale!=NULL){
for(i=0;i<n_con;++i) PetscPrintf(PETSC_COMM_SELF, " c%d: %f\n", i, asl->i.cscale[i]);
}
else{
PetscPrintf(PETSC_COMM_SELF, " None\n");
}
}
void print_jac_asl(ASL *asl){
/* Print sparse Jacobian highlight elements over u or under l*/
cgrad *cg; /* sparse jacobian elements*/
real *Jac; /* ASL test Jacobian */
int err; /* Error code from ASL fulctions */
int i=0;
Jac = (real *)Malloc(nzc*sizeof(real)); /* Jacobian space */
jacval(X0, Jac, &err); /*calculate jacobian */
PetscPrintf(PETSC_COMM_SELF, "Computed Jacobian, err = %d\n", err);
PetscPrintf(PETSC_COMM_SELF, "Computed Jacobian values (scaled):\n");
for(i=n_conjac[0];i<n_conjac[1]; ++i){ /*i is constraint index */
cg = Cgrad[i];
PetscPrintf(PETSC_COMM_SELF, "c%d", i);
while(cg!=NULL){
PetscPrintf(PETSC_COMM_SELF, " v%d(%e)", cg->varno, Jac[cg->goff]);
cg=cg->next;
}
PetscPrintf(PETSC_COMM_SELF, "\n");
}
free(Jac);
}