From 87c7d5c20e297ebc273bbb054436c4dfd6659130 Mon Sep 17 00:00:00 2001 From: vyaas Date: Sun, 7 Nov 2021 00:25:53 -0500 Subject: [PATCH] Added -n flag to skip solving BVP --- examples/BVP/methane_BVP.sh | 2 +- src/Makefile | 8 +++---- src/sensBVP.cpp | 45 ++++++++++++++++++++++--------------- src/sensBrute.cpp | 2 +- 4 files changed, 33 insertions(+), 24 deletions(-) diff --git a/examples/BVP/methane_BVP.sh b/examples/BVP/methane_BVP.sh index ec59ad3..be34e11 100755 --- a/examples/BVP/methane_BVP.sh +++ b/examples/BVP/methane_BVP.sh @@ -1 +1 @@ -sensBVP -r 1e-06 -a 1e-12 -f 1e-07 -T 900.0 -P 10.0 -m ./mech-FFCM1.cti -c CH4:0.0499002,O2:0.199601,N2:0.750499 -t 1 -s +sensBVP -r 1e-06 -a 1e-12 -f 1e-07 -T 900.0 -P 10.0 -m ffcm1.cti -c CH4:0.0499002,O2:0.199601,N2:0.750499 -t 1 -s -o diff --git a/src/Makefile b/src/Makefile index 8f4afdc..1db530b 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,10 +1,10 @@ compiler =g++ -CANTERA_DIR =/opt/scientific/cantera-2.4_gnu_blas -CVODE_DIR =/opt/scientific/sundials-5.1.0 -KINSOL_DIR =/opt/scientific/sundials-5.1.0 +CANTERA_DIR=/home/vyaas/.local +CVODE_DIR=/home/vyaas/.local +KINSOL_DIR=/home/vyaas/.local BVPEXE =sensBVP BRUTEEXE =sensBrute -DESTDIR =~/bin +DESTDIR =/home/vyaas/.local/bin CANTERA_INCLUDES=-I$(CANTERA_DIR)/include CVODE_INCLUDES =-I$(CVODE_DIR)/include diff --git a/src/sensBVP.cpp b/src/sensBVP.cpp index cf854c8..96f223c 100644 --- a/src/sensBVP.cpp +++ b/src/sensBVP.cpp @@ -24,7 +24,7 @@ Street, Fifth Floor, Boston, MA 02110-1301, USA. #include /*Cantera include files*/ -#include +#include "IdealGasMix.h" /*Sundials include files*/ #include /* prototypes for CVODE fcts., consts. */ @@ -140,6 +140,7 @@ typedef struct { bool IVPSuccess; bool BVPSuccess; bool sensSuccess; + bool solveBVP; //The BVP does not HAVE to be solved: use this flag to skip solving it! int nsp,neq,npts,nvar; //key quantities required in for loops: //nsp-> no: of chemical species //neq-> number of governing equations @@ -522,21 +523,23 @@ int main(int argc, char *argv[]) ier=KINSetPrintLevel(mem,2); /* Solve the BVP! */ - ier = KINSol(mem, /* KINSol memory block */ - yp, /* initial guess on input; solution vector */ - KIN_NONE,//KIN_LINESEARCH,/* global strategy choice */ - scale, /* scaling vector, for the variable cc */ - scale); /* scaling vector for function values fval */ - - if (check_flag(&ier, "KINSol", 1)){ - data->BVPSuccess=false; - }else{ - data->BVPSuccess=true; - /* Get scaled norm of the system function */ - ier = KINGetFuncNorm(mem, &data->ftol); - //ier = check_flag(&ier, "KINGetfuncNorm", 1); - printf("\nComputed solution (||F|| = %g):\n\n",data->ftol); - printf("KinSOL Ignition Delay: %15.6es\n", taup(1)); + if(data->solveBVP){ + ier = KINSol(mem, /* KINSol memory block */ + yp, /* initial guess on input; solution vector */ + KIN_NONE,//KIN_LINESEARCH,/* global strategy choice */ + scale, /* scaling vector, for the variable cc */ + scale); /* scaling vector for function values fval */ + + if (check_flag(&ier, "KINSol", 1)){ + data->BVPSuccess=false; + }else{ + data->BVPSuccess=true; + /* Get scaled norm of the system function */ + ier = KINGetFuncNorm(mem, &data->ftol); + //ier = check_flag(&ier, "KINGetfuncNorm", 1); + printf("\nComputed solution (||F|| = %g):\n\n",data->ftol); + printf("KinSOL Ignition Delay: %15.6es\n", taup(1)); + } } //ier=check_flag(&ier, "KINSol", 1); @@ -549,7 +552,7 @@ int main(int argc, char *argv[]) /********************************************************/ /*Begin sensitivity analysis here:*/ - if(data->BVPSuccess){ + if(data->BVPSuccess || !data->solveBVP){ /* Create banded SUNMatrix for use in linear solves; bandwidths * are dictated by the dependence of the solution at a given * time on one time-step ahead and one time-step behind:*/ @@ -777,6 +780,8 @@ static int parseInput(UserData data, int argc, char *argv[]){ data->TIgnFac=0.20; /*Sorting*/ data->sort=false; + /* Solve two-point BVP: */ + data->solveBVP=true; /*****************************************************/ int ier; @@ -785,7 +790,7 @@ static int parseInput(UserData data, int argc, char *argv[]){ char comp[BUFSIZE+1]; bool enteredT0, enteredP, enteredMech, enteredComp; enteredT0=enteredP=enteredMech=enteredComp=false; - while((opt=getopt(argc,argv,"a:r:f:T:P:m:c:t:q:vsod")) != -1){ + while((opt=getopt(argc,argv,"a:r:f:T:P:m:c:t:q:vsodn")) != -1){ switch(opt){ case 'a': data->atol=RCONST(atof(optarg)); @@ -834,6 +839,9 @@ static int parseInput(UserData data, int argc, char *argv[]){ case 'q': data->TIgnFac=RCONST(atof(optarg)); break; + case 'n': + data->solveBVP=false; + break; default: printInstructions(); return(-1); @@ -1484,6 +1492,7 @@ static void printInstructions(){ printf("\n-d :Enables manual dPdt entryspecies sensitivity output\n"); printf("\n-o :Enables sorting of ignition delay sensitivity output\n"); printf("\n-q :factor that determines ignition temperature (default: 0.2)\n"); + printf("\n-n :Disables the boundary value problem solver\n"); printf("\nexample: "); printf("-T 1200.0 -P 1.0 -m gri30.cti"); printf(" -c H2:1.0,N2:3.76,O2:1.0"); diff --git a/src/sensBrute.cpp b/src/sensBrute.cpp index cda0241..6b3f84d 100644 --- a/src/sensBrute.cpp +++ b/src/sensBrute.cpp @@ -25,7 +25,7 @@ Street, Fifth Floor, Boston, MA 02110-1301, USA. #include /*Cantera include files*/ -#include +#include "IdealGasMix.h" /*Sundials include files*/ #include /* prototypes for CVODE fcts., consts. */