Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit bb8f3d8

Browse files
Willi BraunOpenModelica-Hudson
authored andcommitted
[cRuntime] improve dump of the non-linear system solution
Belonging to [master]: - #2581 - OpenModelica/OpenModelica-testsuite#1005
1 parent 8fd8d3e commit bb8f3d8

File tree

5 files changed

+142
-98
lines changed

5 files changed

+142
-98
lines changed

SimulationRuntime/c/simulation/solver/kinsolSolver.c

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ void nlsKinsolJacSumDense(DlsMat mat)
606606
}
607607

608608
if (sum == 0.0){
609-
warningStreamPrint(LOG_NLS, 0, "sum of col %d of jacobian is zero!", i);
609+
warningStreamPrint(LOG_NLS_V, 0, "sum of col %d of jacobian is zero!", i);
610610
}else{
611611
infoStreamPrint(LOG_NLS_JAC, 0, "col %d jac sum = %g", i, sum);
612612
}
@@ -627,7 +627,7 @@ void nlsKinsolJacSumSparse(SlsMat mat)
627627
}
628628

629629
if (sum == 0.0){
630-
warningStreamPrint(LOG_NLS, 0, "sum of col %d of jacobian is zero!", i);
630+
warningStreamPrint(LOG_NLS_V, 0, "sum of col %d of jacobian is zero!", i);
631631
}else{
632632
infoStreamPrint(LOG_NLS_JAC, 0, "col %d jac sum = %g", i, sum);
633633
}
@@ -644,13 +644,13 @@ void nlsKinsolErrorPrint(int errorCode, const char *module, const char *function
644644
int sysNumber = kinsolData->userData.sysNumber;
645645
long eqSystemNumber = data->simulationInfo->nonlinearSystemData[sysNumber].equationIndex;
646646

647-
if (ACTIVE_STREAM(LOG_NLS))
647+
if (ACTIVE_STREAM(LOG_NLS_V))
648648
{
649-
warningStreamPrint(LOG_NLS, 1, "kinsol failed for %d", modelInfoGetEquation(&data->modelData->modelDataXml,eqSystemNumber).id);
650-
warningStreamPrint(LOG_NLS, 0, "[module] %s | [function] %s | [error_code] %d", module, function, errorCode);
651-
warningStreamPrint(LOG_NLS, 0, "%s", msg);
649+
warningStreamPrint(LOG_NLS_V, 1, "kinsol failed for %d", modelInfoGetEquation(&data->modelData->modelDataXml,eqSystemNumber).id);
650+
warningStreamPrint(LOG_NLS_V, 0, "[module] %s | [function] %s | [error_code] %d", module, function, errorCode);
651+
warningStreamPrint(LOG_NLS_V, 0, "%s", msg);
652652

653-
messageClose(LOG_NLS);
653+
messageClose(LOG_NLS_V);
654654
}
655655
}
656656

@@ -839,32 +839,32 @@ int nlsKinsolErrorHandler(int errorCode, DATA *data, NONLINEAR_SYSTEM_DATA *nlsD
839839
case KIN_MEM_NULL:
840840
case KIN_ILL_INPUT:
841841
case KIN_NO_MALLOC:
842-
errorStreamPrint(LOG_NLS, 0, "kinsol has a serious memory issue ERROR %d\n", errorCode);
842+
errorStreamPrint(LOG_NLS_V, 0, "kinsol has a serious memory issue ERROR %d\n", errorCode);
843843
return errorCode;
844844
break;
845845
/* just retry with new initial guess */
846846
case KIN_MXNEWT_5X_EXCEEDED:
847-
warningStreamPrint(LOG_NLS, 0, "Newton step exceed the maximum step size several times. Try again after increasing maximum step size.\n");
847+
warningStreamPrint(LOG_NLS_V, 0, "Newton step exceed the maximum step size several times. Try again after increasing maximum step size.\n");
848848
kinsolData->maxstepfactor *= 1e5;
849849
nlsKinsolSetMaxNewtonStep(kinsolData, kinsolData->maxstepfactor);
850850
return 1;
851851
break;
852852
/* just retry without line search */
853853
case KIN_LINESEARCH_NONCONV:
854-
warningStreamPrint(LOG_NLS, 0, "kinsols line search did not convergence. Try without.\n");
854+
warningStreamPrint(LOG_NLS_V, 0, "kinsols line search did not convergence. Try without.\n");
855855
kinsolData->kinsolStrategy = KIN_NONE;
856856
kinsolData->retries--;
857857
return 1;
858858
/* maybe happened because of an out-dated factorization, so just retry */
859859
case KIN_LSOLVE_FAIL:
860-
warningStreamPrint(LOG_NLS, 0, "kinsols matrix need new factorization. Try again.\n");
860+
warningStreamPrint(LOG_NLS_V, 0, "kinsols matrix need new factorization. Try again.\n");
861861
if (nlsData->isPatternAvailable){
862862
KINKLUReInit(kinsolData->kinsolMemory, kinsolData->size, kinsolData->nnz, 2);
863863
}
864864
return 1;
865865
case KIN_MAXITER_REACHED:
866866
case KIN_REPTD_SYSFUNC_ERR:
867-
warningStreamPrint(LOG_NLS, 0, "kinsols runs into issues retry with different configuration.\n");
867+
warningStreamPrint(LOG_NLS_V, 0, "kinsols runs into issues retry with different configuration.\n");
868868
retValue = 1;
869869
break;
870870
case KIN_LSETUP_FAIL:
@@ -883,7 +883,7 @@ int nlsKinsolErrorHandler(int errorCode, DATA *data, NONLINEAR_SYSTEM_DATA *nlsD
883883
break;
884884
case KIN_LINESEARCH_BCFAIL:
885885
KINGetNumBetaCondFails(kinsolData->kinsolMemory, &outL);
886-
warningStreamPrint(LOG_NLS, 0, "kinsols runs into issues with beta-condition fails: %ld\n", outL);
886+
warningStreamPrint(LOG_NLS_V, 0, "kinsols runs into issues with beta-condition fails: %ld\n", outL);
887887
retValue = 1;
888888
break;
889889
default:
@@ -896,14 +896,14 @@ int nlsKinsolErrorHandler(int errorCode, DATA *data, NONLINEAR_SYSTEM_DATA *nlsD
896896
KINGetFuncNorm(kinsolData->kinsolMemory, &fNorm);
897897
if (fNorm<FTOL_WITH_LESS_ACCURANCY)
898898
{
899-
warningStreamPrint(LOG_NLS, 0, "Move forward with a less accurate solution.");
899+
warningStreamPrint(LOG_NLS_V, 0, "Move forward with a less accurate solution.");
900900
KINSetFuncNormTol(kinsolData->kinsolMemory, FTOL_WITH_LESS_ACCURANCY);
901901
KINSetScaledStepTol(kinsolData->kinsolMemory, FTOL_WITH_LESS_ACCURANCY);
902902
retValue2 = 1;
903903
}
904904
else
905905
{
906-
warningStreamPrint(LOG_NLS, 0, "Current status of fx = %f", fNorm);
906+
warningStreamPrint(LOG_NLS_V, 0, "Current status of fx = %f", fNorm);
907907
}
908908

909909
/* reconfigure kinsol for an other try */
@@ -976,8 +976,7 @@ int nlsKinsolSolve(DATA *data, threadData_t *threadData, int sysNumber)
976976
/* reset configuration settings */
977977
nlsKinsolConfigSetup(kinsolData);
978978

979-
infoStreamPrint(LOG_NLS, 0, "------------------------------------------------------");
980-
infoStreamPrintWithEquationIndexes(LOG_NLS, 1, indexes, "Start solving non-linear system >>%ld<< using Kinsol solver at time %g", eqSystemNumber, data->localData[0]->timeValue);
979+
infoStreamPrintWithEquationIndexes(LOG_NLS_V, 1, indexes, "Start Kinsol solver at time %g", data->localData[0]->timeValue);
981980

982981
nlsKinsolResetInitial(data, kinsolData, nlsData, INITIAL_EXTRAPOLATION);
983982

@@ -1031,10 +1030,10 @@ int nlsKinsolSolve(DATA *data, threadData_t *threadData, int sysNumber)
10311030
N_VProd(kinsolData->fRes, kinsolData->fScale, kinsolData->fRes);
10321031
fNormValue = N_VWL2Norm(kinsolData->fRes, kinsolData->fRes);
10331032

1034-
infoStreamPrint(LOG_NLS, 0, "scaled Euclidean norm of F(u) = %e", fNormValue);
1033+
infoStreamPrint(LOG_NLS_V, 0, "scaled Euclidean norm of F(u) = %e", fNormValue);
10351034
if (FTOL_WITH_LESS_ACCURANCY<fNormValue)
10361035
{
1037-
warningStreamPrint(LOG_NLS, 0, "False positive solution. FNorm is not small enough.");
1036+
warningStreamPrint(LOG_NLS_V, 0, "False positive solution. FNorm is not small enough.");
10381037
success = 0;
10391038
}
10401039
else /* solved system for reuse linear solver information */
@@ -1043,19 +1042,9 @@ int nlsKinsolSolve(DATA *data, threadData_t *threadData, int sysNumber)
10431042
}
10441043
/* copy solution */
10451044
memcpy(nlsData->nlsx, xStart, nlsData->size*(sizeof(double)));
1046-
/* dump solution */
1047-
if(ACTIVE_STREAM(LOG_NLS))
1048-
{
1049-
infoStreamPrintWithEquationIndexes(LOG_NLS, 1, indexes, "solution for NLS %ld at t=%g", eqSystemNumber, kinsolData->userData.data->localData[0]->timeValue);
1050-
for(i=0; i<nlsData->size; ++i)
1051-
{
1052-
infoStreamPrintWithEquationIndexes(LOG_NLS, 0, indexes, "[%d] %s = %g", i+1, modelInfoGetEquation(&kinsolData->userData.data->modelData->modelDataXml,eqSystemNumber).vars[i], nlsData->nlsx[i]);
1053-
}
1054-
messageClose(LOG_NLS);
1055-
}
10561045
}
10571046

1058-
messageClose(LOG_NLS);
1047+
messageClose(LOG_NLS_V);
10591048

10601049
return success;
10611050
}

SimulationRuntime/c/simulation/solver/nonlinearSolverHomotopy.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,9 +1122,9 @@ int solveSystemWithTotalPivotSearch(int n, double* x, double* A, int* indRow, in
11221122
getIndicesOfPivotElement(&n, &nPivot, &i, A, indRow, indCol, &pRow, &pCol, &absMax);
11231123
if (absMax<DBL_EPSILON) {
11241124
*rank = i;
1125-
warningStreamPrint(LOG_NLS, 0, "Matrix singular!");
1126-
debugInt(LOG_NLS,"rank = ", *rank);
1127-
debugInt(LOG_NLS,"position = ", *pos);
1125+
warningStreamPrint(LOG_NLS_V, 0, "Matrix singular!");
1126+
debugInt(LOG_NLS_V,"rank = ", *rank);
1127+
debugInt(LOG_NLS_V,"position = ", *pos);
11281128
break;
11291129
}
11301130
/* swap row indices */
@@ -1155,7 +1155,7 @@ int solveSystemWithTotalPivotSearch(int n, double* x, double* A, int* indRow, in
11551155
debugMatrixPermutedDouble(LOG_NLS_JAC,"Linear System Matrix [Jac res] after decomposition",A, n, m, indRow, indCol);
11561156
debugDouble(LOG_NLS_JAC,"Determinant = ", detJac);
11571157
if (isnan(detJac)){
1158-
warningStreamPrint(LOG_NLS, 0, "Jacobian determinant is NaN.");
1158+
warningStreamPrint(LOG_NLS_V, 0, "Jacobian determinant is NaN.");
11591159
return -1;
11601160
}
11611161
else if (fabs(detJac) < 1e-9 && casualTearingSet)
@@ -1169,7 +1169,7 @@ int solveSystemWithTotalPivotSearch(int n, double* x, double* A, int* indRow, in
11691169
if (i>=*rank) {
11701170
/* this criteria should be evaluated and may be improved in future */
11711171
if (fabs(A[indRow[i] + indCol[n]*n])>1e-6) {
1172-
warningStreamPrint(LOG_NLS, 0, "under-determined linear system not solvable!");
1172+
warningStreamPrint(LOG_NLS_V, 0, "under-determined linear system not solvable!");
11731173
return -1;
11741174
} else {
11751175
x[indCol[i]] = 0.0;
@@ -1319,7 +1319,7 @@ static int newtonAlgorithm(DATA_HOMOTOPY* solverData, double* x)
13191319
debugString(LOG_NLS_V, "******************************************************");
13201320
debugInt(LOG_NLS_V, "NEWTON SOLVER STARTED! equation number: ",solverData->eqSystemNumber);
13211321
debugInt(LOG_NLS_V, "maximum number of function evaluation: ", solverData->maxNumberOfIterations);
1322-
printUnknowns(LOG_NLS, solverData);
1322+
printUnknowns(LOG_NLS_V, solverData);
13231323

13241324
/* set default solver message */
13251325
solverData->info = 0;
@@ -1393,7 +1393,7 @@ static int newtonAlgorithm(DATA_HOMOTOPY* solverData, double* x)
13931393

13941394
if (lambda1 < lambdaMin)
13951395
{
1396-
debugDouble(LOG_NLS,"UPS! MUST HANDLE A PROBLEM (Newton method), time : ", solverData->timeValue);
1396+
debugDouble(LOG_NLS_V,"UPS! MUST HANDLE A PROBLEM (Newton method), time : ", solverData->timeValue);
13971397
solverData->info = -1;
13981398
break;
13991399
}
@@ -1439,7 +1439,7 @@ static int newtonAlgorithm(DATA_HOMOTOPY* solverData, double* x)
14391439
#endif
14401440
if (assert)
14411441
{
1442-
debugDouble(LOG_NLS,"UPS! MUST HANDLE A PROBLEM (Newton method), time : ", solverData->timeValue);
1442+
debugDouble(LOG_NLS_V,"UPS! MUST HANDLE A PROBLEM (Newton method), time : ", solverData->timeValue);
14431443
solverData->info = -1;
14441444
break;
14451445
}
@@ -1487,7 +1487,7 @@ static int newtonAlgorithm(DATA_HOMOTOPY* solverData, double* x)
14871487
#endif
14881488
if (assert)
14891489
{
1490-
debugDouble(LOG_NLS,"UPS! MUST HANDLE A PROBLEM (Newton method), time : ", solverData->timeValue);
1490+
debugDouble(LOG_NLS_V,"UPS! MUST HANDLE A PROBLEM (Newton method), time : ", solverData->timeValue);
14911491
solverData->info = -1;
14921492
break;
14931493
}
@@ -1693,7 +1693,7 @@ static int homotopyAlgorithm(DATA_HOMOTOPY* solverData, double *x)
16931693

16941694
vecConst(solverData->n, 0.0, solverData->dy2);
16951695
solverData->dy2[solverData->n]= solverData->startDirection;
1696-
printHomotopyUnknowns(LOG_NLS, solverData);
1696+
printHomotopyUnknowns(LOG_NLS_V, solverData);
16971697
assert = 1;
16981698
#ifndef OMC_EMCC
16991699
MMC_TRY_INTERNAL(simulationJumpBuffer)
@@ -2299,7 +2299,7 @@ int solveHomotopy(DATA *data, threadData_t *threadData, int sysNumber)
22992299

23002300
// If this is the casual tearing set (only exists for dynamic tearing), break after first try
23012301
if (solverData->info == -1 && solverData->casualTearingSet){
2302-
infoStreamPrint(LOG_NLS, 0, "### No Solution for the casual tearing set at the first try! ###");
2302+
infoStreamPrint(LOG_NLS_V, 0, "### No Solution for the casual tearing set at the first try! ###");
23032303
break;
23042304
}
23052305

@@ -2353,7 +2353,7 @@ int solveHomotopy(DATA *data, threadData_t *threadData, int sysNumber)
23532353

23542354
pos = solverData->n;
23552355
solveSystemWithTotalPivotSearch(solverData->n, solverData->dy0, solverData->fJac, solverData->indRow, solverData->indCol, &pos, &rank, solverData->casualTearingSet);
2356-
debugDouble(LOG_NLS,"solve mixed system at time : ", solverData->timeValue);
2356+
debugDouble(LOG_NLS_V,"solve mixed system at time : ", solverData->timeValue);
23572357
continue;
23582358
}
23592359
}
@@ -2362,7 +2362,7 @@ int solveHomotopy(DATA *data, threadData_t *threadData, int sysNumber)
23622362
debugString(LOG_NLS_V,"SYSTEM SOLVED");
23632363
debugInt(LOG_NLS_V, "homotopy method: ",runHomotopy);
23642364
debugInt(LOG_NLS_V, "number of function calls: ",solverData->numberOfFunctionEvaluations-numberOfFunctionEvaluationsOld);
2365-
printUnknowns(LOG_NLS, solverData);
2365+
printUnknowns(LOG_NLS_V, solverData);
23662366
debugString(LOG_NLS_V, "------------------------------------------------------");
23672367
/* take the solution */
23682368
vecCopy(solverData->n, solverData->x, systemData->nlsx);

0 commit comments

Comments
 (0)