|
| 1 | +// name: homotopy4 |
| 2 | +// keywords: initialization, homotopy |
| 3 | +// status: correct |
| 4 | +// cflags: |
| 5 | +// teardown_command: rm -rf initializationTests.homotopy4* _initializationTests.homotopy4* output.log |
| 6 | +// |
| 7 | +// case for homotopy |
| 8 | +// |
| 9 | + |
| 10 | +loadString(" |
| 11 | +within ; |
| 12 | +package initializationTests |
| 13 | + model homotopy4 |
| 14 | + Real x,y,z,x1,y1,z1,x2,y2,z2,x3,y3,z3,a,b,c,d,e,f; |
| 15 | + // Real x,y,z,x1,y1,z1,x2,y2,z2 annotation(tearingSelect=always),x3,y3,z3,a,b,c,d,e,f; |
| 16 | + parameter Real p1 = 10; |
| 17 | + |
| 18 | + equation |
| 19 | + // a = sin(p1* time + 1); |
| 20 | + a = sin(p1* time + 3.1415/2); |
| 21 | + |
| 22 | + x + 5 = z + a; |
| 23 | + -y + 10 = z + p1; |
| 24 | + x - y + 9 = z; |
| 25 | + |
| 26 | + b = sin(a*x); |
| 27 | + |
| 28 | + // ********** Beginning of homotopy iteration loop |
| 29 | + c = homotopy(b^2, b); |
| 30 | + |
| 31 | + x1 + 5 = z1 + c; |
| 32 | + -y1 + 10 = z1 + p1; |
| 33 | + x1 - y1 + 9 = z1; |
| 34 | + |
| 35 | + d = x1 + y1 + z1; |
| 36 | + |
| 37 | + homotopy(x2^2, x2) + 5 = z2 + 5; |
| 38 | + homotopy(y2^2, -d) + 10 = z2 + p1; |
| 39 | + x2 + y2 + 9 = z2; |
| 40 | + |
| 41 | + e = sin(d*x2); |
| 42 | + |
| 43 | + x3 + 5 = z3 + e; |
| 44 | + -y3 + 10 = z3*y3 + p1; |
| 45 | + x3 - y3 + 9 = z3; |
| 46 | + // ********** End of homotopy iteration loop |
| 47 | + |
| 48 | + f = x + y + z + a + b + c + d + e + x1 + y1 + z1 + x2 + y2 + z2 + x3 + y3 + z3; |
| 49 | + end homotopy4; |
| 50 | +end initializationTests; |
| 51 | +"); getErrorString(); |
| 52 | + |
| 53 | +sflags:="-homotopyOnFirstTry -homTauStart=0.4"; |
| 54 | + |
| 55 | +// setCommandLineOptions("--homotopyApproach=equidistantGlobal"); getErrorString(); |
| 56 | +// setCommandLineOptions("--homotopyApproach=equidistantGlobal --noTearingForComponent=4"); getErrorString(); |
| 57 | +// setCommandLineOptions("--homotopyApproach=adaptiveGlobal"); getErrorString(); |
| 58 | +setCommandLineOptions("--homotopyApproach=adaptiveGlobal --noTearingForComponent=4"); getErrorString(); |
| 59 | +// setCommandLineOptions("--homotopyApproach=adaptiveGlobal --noTearingForComponent=4 -d=-NLSanalyticJacobian"); getErrorString(); |
| 60 | +// setCommandLineOptions("--homotopyApproach=eqidistantLocal"); getErrorString(); |
| 61 | +// setCommandLineOptions("--homotopyApproach=eqidistantLocal --noTearingForComponent=4"); getErrorString(); |
| 62 | +// setCommandLineOptions("--homotopyApproach=adaptiveLocal"); getErrorString(); |
| 63 | +// setCommandLineOptions("--homotopyApproach=adaptiveLocal --noTearingForComponent=4"); getErrorString(); |
| 64 | +simulate(initializationTests.homotopy4, startTime=0.0, stopTime=0.0, simflags=sflags); getErrorString(); |
| 65 | +res := OpenModelica.Scripting.readSimulationResult("initializationTests.homotopy4_res.mat", {time, x,y,z,a,b,c,d,e,x1,y1,z1,x2,y2,z2,x3,y3,z3,f}, 2); getErrorString(); |
| 66 | + |
| 67 | +print("x="); |
| 68 | +val(x, 0.0); |
| 69 | + |
| 70 | +print("\ny="); |
| 71 | +val(y, 0.0); |
| 72 | + |
| 73 | +print("\nz="); |
| 74 | +val(z, 0.0); |
| 75 | + |
| 76 | +print("\nx1="); |
| 77 | +val(x1, 0.0); |
| 78 | + |
| 79 | +print("\ny1="); |
| 80 | +val(y1, 0.0); |
| 81 | + |
| 82 | +print("\nz1="); |
| 83 | +val(z1, 0.0); |
| 84 | + |
| 85 | +print("\nx2="); |
| 86 | +val(x2, 0.0); |
| 87 | + |
| 88 | +print("\ny2="); |
| 89 | +val(y2, 0.0); |
| 90 | + |
| 91 | +print("\nz2="); |
| 92 | +val(z2, 0.0); |
| 93 | + |
| 94 | +print("\nx3="); |
| 95 | +val(x3, 0.0); |
| 96 | + |
| 97 | +print("\ny3="); |
| 98 | +val(y3, 0.0); |
| 99 | + |
| 100 | +print("\nz3="); |
| 101 | +val(z3, 0.0); |
| 102 | + |
| 103 | +print("\na="); |
| 104 | +val(a, 0.0); |
| 105 | + |
| 106 | +print("\nb="); |
| 107 | +val(b, 0.0); |
| 108 | + |
| 109 | +print("\nc="); |
| 110 | +val(c, 0.0); |
| 111 | + |
| 112 | +print("\nd="); |
| 113 | +val(d, 0.0); |
| 114 | + |
| 115 | +print("\ne="); |
| 116 | +val(e, 0.0); |
| 117 | + |
| 118 | +print("\nf="); |
| 119 | +val(f, 0.0); |
| 120 | + |
| 121 | +// Result: |
| 122 | +// true |
| 123 | +// "" |
| 124 | +// "-homotopyOnFirstTry -homTauStart=0.4" |
| 125 | +// true |
| 126 | +// "" |
| 127 | +// record SimulationResult |
| 128 | +// resultFile = "initializationTests.homotopy4_res.mat", |
| 129 | +// simulationOptions = "startTime = 0.0, stopTime = 0.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'initializationTests.homotopy4', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = '-homotopyOnFirstTry -homTauStart=0.4'", |
| 130 | +// messages = "stdout | info | homotopy parameter homTauStart changed to 0.400000 |
| 131 | +// LOG_SUCCESS | info | The initialization finished successfully with 480 homotopy steps. |
| 132 | +// LOG_SUCCESS | info | The simulation finished successfully. |
| 133 | +// " |
| 134 | +// end SimulationResult; |
| 135 | +// "Notification: Tearing is skipped for strong component 4 because of activated compiler flag 'noTearingForComponent=4'. |
| 136 | +// Warning: There are iteration variables with default zero start attribute. For more information set -d=initialization. In OMEdit Tools->Options->Simulation->OMCFlags, in OMNotebook call setCommandLineOptions("-d=initialization"). |
| 137 | +// " |
| 138 | +// {{0.0,0.0},{-9.0,-9.0},{4.999999998926914,4.999999998926914},{-4.999999998926914,-4.999999998926914},{0.999999998926914,0.999999998926914},{-0.412118494041246,-0.412118494041246},{0.1698416531308245,0.1698416531308245},{-9.0,-9.0},{-0.956375928404503,-0.956375928404503},{-9.0,-9.0},{4.169841653130826,4.169841653130826},{-4.169841653130826,-4.169841653130826},{3.0,3.0},{-3.0,-3.0},{9.0,9.0},{-6.956375928404503,-6.956375928404503},{3.043624071595497,3.043624071595497},{-1.0,-1.0},{-23.11140462719703,-23.11140462719703}} |
| 139 | +// "" |
| 140 | +// x= |
| 141 | +// -9.0 |
| 142 | +// |
| 143 | +// y= |
| 144 | +// 4.999999998926914 |
| 145 | +// |
| 146 | +// z= |
| 147 | +// -4.999999998926914 |
| 148 | +// |
| 149 | +// x1= |
| 150 | +// -9.0 |
| 151 | +// |
| 152 | +// y1= |
| 153 | +// 4.169841653130826 |
| 154 | +// |
| 155 | +// z1= |
| 156 | +// -4.169841653130826 |
| 157 | +// |
| 158 | +// x2= |
| 159 | +// 3.0 |
| 160 | +// |
| 161 | +// y2= |
| 162 | +// -3.0 |
| 163 | +// |
| 164 | +// z2= |
| 165 | +// 9.0 |
| 166 | +// |
| 167 | +// x3= |
| 168 | +// -6.956375928404503 |
| 169 | +// |
| 170 | +// y3= |
| 171 | +// 3.043624071595497 |
| 172 | +// |
| 173 | +// z3= |
| 174 | +// -1.0 |
| 175 | +// |
| 176 | +// a= |
| 177 | +// 0.999999998926914 |
| 178 | +// |
| 179 | +// b= |
| 180 | +// -0.412118494041246 |
| 181 | +// |
| 182 | +// c= |
| 183 | +// 0.1698416531308245 |
| 184 | +// |
| 185 | +// d= |
| 186 | +// -9.0 |
| 187 | +// |
| 188 | +// e= |
| 189 | +// -0.956375928404503 |
| 190 | +// |
| 191 | +// f= |
| 192 | +// -23.11140462719703 |
| 193 | +// endResult |
0 commit comments