规范仿真模型库并完善前端交互
归档仿真模型并补充组件目录、建模规范与校验。 完善控制台、默认节点、视图适配及前端自动化测试。
This commit is contained in:
1 parent
f7f1078911
commit
bbc88a6bbb
71 files changed
+4574
-806
No files matched your search
@@ -0,0 +1,4 @@
|
||||
mytank.p: max_abs_error=134.960858, max_rel_error=0.006798%
|
||||
mytank.T: max_abs_error=0.035507, max_rel_error=0.009016%
|
||||
mycylinder.p: max_abs_error=1391.986349, max_rel_error=0.009447%
|
||||
mycylinder.T: max_abs_error=0.009069, max_rel_error=0.003870%
|
||||
@@ -0,0 +1,202 @@
|
||||
time_s,mytank.p,mytank.T,mycylinder.p,mycylinder.T
|
||||
0.0,99999.9999998181,299.9999999994543,35000000.0,300.0
|
||||
0.1,113767.94796194455,310.9637987101763,34857995.191961475,299.65190130981887
|
||||
0.2,127490.75529043324,320.1741038867186,34716455.97160761,299.3039342009557
|
||||
0.30000000000000004,141168.22832317703,327.9540327439692,34575384.336400226,298.9561065982938
|
||||
0.4,154800.2272891848,334.6028385113769,34434781.727959625,298.60842486666263
|
||||
0.5,168386.6833862148,340.3440160419025,34294648.85592305,298.26089368263627
|
||||
0.6000000000000001,181927.56886228317,345.34597934661645,34154986.006528884,297.9135169662631
|
||||
0.7000000000000001,195422.8867284584,349.7379443903134,34015793.14872051,297.5662980942661
|
||||
0.8,208872.67226727083,353.62071952544704,33877069.91858829,297.2192381374397
|
||||
0.9,222277.06297793236,357.0742683513725,33738814.897943415,296.8723276411647
|
||||
1.0,235635.98150118813,360.16219760966084,33601028.88468161,296.5255848498291
|
||||
1.1,248949.42783703818,362.9362624751423,33463711.878802836,296.1790180498007
|
||||
1.2000000000000002,262217.75812283135,365.43943715392686,33326860.20704978,295.8325994898035
|
||||
1.3,275440.80324992316,367.7064864598734,33190475.613635924,295.48635453607636
|
||||
1.4000000000000001,288618.55460473493,369.766650344722,33054558.187403098,295.14029246566224
|
||||
1.5,301751.3171281971,371.6448887937757,32919104.783141974,294.79439468638526
|
||||
1.6,314839.14341954247,373.36206261131525,32784114.858335685,294.44866485903736
|
||||
1.7000000000000002,327882.06907680153,374.93594217338176,32649588.04582047,294.10310819940065
|
||||
1.8,340880.20077679906,376.3818124575356,32515523.2453146,293.7577259967503
|
||||
1.9000000000000001,353833.6270518691,377.7128659999238,32381919.54368144,293.41251959012544
|
||||
2.0,366742.42291137256,378.94054912194076,32248776.16726251,293.06749036423287
|
||||
2.1,379606.6730674497,380.0748368029417,32116092.24232331,292.72263968200787
|
||||
2.2,392426.50707225554,381.12448095768656,31983866.432642274,292.37796667994184
|
||||
2.3000000000000003,405202.0671563814,382.0971825271288,31852097.271230437,292.03346983037886
|
||||
2.4000000000000004,417933.4155500976,382.9997115435689,31720784.11623488,291.6891515780112
|
||||
2.5,430620.6510589185,383.838081019396,31589925.948559783,291.3450125479824
|
||||
2.6,443263.883710829,384.61764092425494,31459521.633358993,291.0010529534012
|
||||
2.7,455863.2542884696,385.3431706778388,31329569.71857793,290.6572718762472
|
||||
2.8000000000000003,468418.84583467664,386.0189391423481,31200069.34769955,290.31367046787994
|
||||
2.9000000000000004,480930.76401047717,386.64878296917834,31071019.430919208,289.9702490545257
|
||||
3.0,493399.1147767602,387.2361564731079,30942418.8753394,289.627007973335
|
||||
3.1,505824.0120818939,387.7841699997202,30814266.50567852,289.283948167411
|
||||
3.2,518205.5585633492,388.29565044444143,30686561.263317347,288.9410696919777
|
||||
3.3000000000000003,530543.860941083,388.7731587646163,30559302.04752924,288.5983729053581
|
||||
3.4000000000000004,542839.025935053,389.21902406251183,30432487.75758757,288.2558581528899
|
||||
3.5,555091.1532282452,389.63535331051384,30306117.365346134,287.9135275289302
|
||||
3.6,567300.3523937837,390.0240928732544,30180189.74065028,287.5713806480376
|
||||
3.7,579466.730902255,390.3870196149787,30054703.77503127,287.2294176336731
|
||||
3.8000000000000003,591590.3951155862,390.7257605811333,29929658.371455234,286.88763887333175
|
||||
3.9000000000000004,603671.4513957056,391.0418105423231,29805052.432888325,286.5460447413264
|
||||
4.0,615710.0061045411,391.3365451815722,29680884.862296656,286.20463559857706
|
||||
4.1000000000000005,627706.1656040212,391.61123273483645,29557154.562646367,285.8634117923989
|
||||
4.2,639660.0356829006,391.86704273384044,29433860.4428154,285.5223738511199
|
||||
4.3,651571.716232906,392.1050410519721,29311001.472504564,285.1815242995298
|
||||
4.4,663441.3179459961,392.32624321858174,29188576.510019373,284.840861980108
|
||||
4.5,675268.9468771729,392.53157932311984,29066584.46149164,284.5003872946073
|
||||
4.6000000000000005,687054.7090814385,392.72191331429804,28945024.2330532,284.16010063101663
|
||||
4.7,698798.7106137947,392.8980487868277,28823894.730835862,283.8200023633402
|
||||
4.800000000000001,710501.057529244,393.06073417111315,28703194.86097143,283.48009285137505
|
||||
4.9,722161.8558827877,393.21066739655134,28582923.529591747,283.1403724404863
|
||||
5.0,733781.2088290841,393.3484951327475,28463079.672743235,282.8008422184954
|
||||
5.1000000000000005,745359.2175579917,393.47481852250473,28343662.24673756,282.4615037792963
|
||||
5.2,756895.9922909128,393.5902150621596,28224670.114733644,282.1223563449153
|
||||
5.300000000000001,768391.6386869826,393.6952183545109,28106102.186946325,281.78340031124986
|
||||
5.4,779846.2624053361,393.7903288312906,27987957.373590477,281.44463605959197
|
||||
5.5,791259.96910511,393.8760162992802,27870234.58488091,281.10606395639473
|
||||
5.6000000000000005,802632.8644454395,393.9527222554955,27752932.731032487,280.76768435303745
|
||||
5.7,813965.0540854601,394.02086199551263,27636050.72226007,280.4294975855874
|
||||
5.800000000000001,825256.6344365194,394.08081904264304,27519587.564161647,280.0915054160418
|
||||
5.9,836507.7093909897,394.13296077650165,27403542.18517475,279.75370843660113
|
||||
6.0,847718.3891245491,394.17763867488134,27287913.44892988,279.4161062418491
|
||||
6.1000000000000005,858888.7786008355,394.2151805066602,27172700.272815377,279.0786992215644
|
||||
6.2,870018.9827834871,394.2458959595685,27057901.57421954,278.7414877501898
|
||||
6.300000000000001,881109.1066361419,394.27007787647636,26943516.2705307,278.40447218658807
|
||||
6.4,892159.2551224378,394.2880033916485,26829543.279137183,278.0676528737956
|
||||
6.5,903169.5332060129,394.2999349762812,26715981.5174273,277.73103013877227
|
||||
6.6000000000000005,914139.9829839376,394.30609016406663,26602830.551205155,277.3946116451124
|
||||
6.7,925070.7482002805,394.30672506364067,26490088.897871558,277.0583932025842
|
||||
6.800000000000001,935961.9434794089,394.30206871636136,26377755.375172496,276.7223739769823
|
||||
6.9,946813.6729747849,394.2923336718555,26265828.9088526,276.3865543393284
|
||||
7.0,957626.040839869,394.2777219546483,26154308.424656466,276.05093464451556
|
||||
7.1000000000000005,968399.1512281233,394.2584257130283,26043192.84832872,275.7155152310525
|
||||
7.2,979133.1082930088,394.23462782052076,25932481.10561397,275.3802964208052
|
||||
7.300000000000001,989828.0161879869,394.2065024339623,25822172.12225682,275.04527851873627
|
||||
7.4,1000483.9790665191,394.17421551178546,25712264.824001882,274.71046181264023
|
||||
7.5,1011101.1010820667,394.13792529578427,25602758.136593778,274.3758465728772
|
||||
7.6000000000000005,1021679.4863880915,394.09778275932865,25493650.985777102,274.04143305210266
|
||||
7.7,1032219.239138054,394.0539320247227,25384942.297296483,273.707221484995
|
||||
7.800000000000001,1042720.4634854163,394.0065107521557,25276630.996896524,273.37321208797937
|
||||
7.9,1053183.2635836392,393.95565050247825,25168716.01032184,273.0394050589494
|
||||
8.0,1063607.7435861847,393.9014770758345,25061196.263317037,272.705800576985
|
||||
8.1,1073994.0076465139,393.8441108280058,24954070.681626726,272.3723988020679
|
||||
8.200000000000001,1084342.0075784405,393.78360959211744,24847339.76225091,272.03921728278755
|
||||
8.3,1094651.950514763,393.7201237653114,24741001.368788917,271.7062444960846
|
||||
8.4,1104923.9566483083,393.65376548392067,24635054.261552785,271.3734787513138
|
||||
8.5,1115158.1282653515,393.5846357175065,24529497.385545585,271.0409203804046
|
||||
8.6,1125354.567652169,393.5128313057523,24424329.685770374,270.7085696976142
|
||||
8.700000000000001,1135513.3770950353,393.43844517133164,24319550.10723021,270.37642699925055
|
||||
8.8,1145634.6588802272,393.3615665197664,24215157.594928175,270.0444925633909
|
||||
8.9,1155718.5152940191,393.2822810271899,24111151.093867306,269.712766649598
|
||||
9.0,1165765.0486226876,393.2006710168648,24007529.54905069,269.3812494986329
|
||||
9.1,1175774.361152508,393.11681562522904,23904291.90548136,269.04994133216485
|
||||
9.200000000000001,1185746.555169756,393.03079095819226,23801437.108162407,268.7188423524781
|
||||
9.3,1195681.732960707,392.94267023834027,23698964.10209688,268.3879527421748
|
||||
9.4,1205579.9968116365,392.8525239436615,23596871.83228785,268.05727266387584
|
||||
9.5,1215441.4490088206,392.7604199383583,23495159.243738372,267.72680225991735
|
||||
9.600000000000001,1225266.1918385345,392.66642359626576,23393825.281451505,267.39654165204473
|
||||
9.700000000000001,1235054.3275870536,392.57059791736026,23292868.89043032,267.0664909411029
|
||||
9.8,1244805.7424247153,392.47293675670085,23192291.244732097,266.7366751290975
|
||||
9.9,1254520.6963966596,392.3735487251935,23092089.662209835,266.40707625875064
|
||||
10.0,1264199.3049931854,392.2724947546991,22992262.951678198,266.07769289844276
|
||||
10.100000000000001,1273841.6679760527,392.1698289153906,22892810.0841785,265.74852540655036
|
||||
10.200000000000001,1283447.8851070204,392.0656034102887,22793730.030752078,265.41957412301247
|
||||
10.3,1293018.0561478487,391.9598686580462,22695021.76244025,265.0908393690368
|
||||
10.4,1302552.2808602974,391.8526733713811,22596684.250284337,264.76232144680336
|
||||
10.5,1312050.6590061258,391.7440646314241,22498716.465325654,264.4340206391643
|
||||
10.600000000000001,1321513.290347094,391.63408795822716,22401117.37860553,264.10593720934105
|
||||
10.700000000000001,1330940.2746449616,391.5227873776613,22303885.961165283,263.7780714006174
|
||||
10.8,1340331.711661488,391.41020548491883,22207021.184046242,263.4504234360302
|
||||
10.9,1349687.7011584332,391.29638350481804,22110522.01828973,263.1229935180553
|
||||
11.0,1359008.342897557,391.18136134909884,22014387.434937052,262.79578182829164
|
||||
11.100000000000001,1368293.7366406189,391.0651776708804,21918616.405029543,262.4687885271409
|
||||
11.200000000000001,1377543.9821493784,390.9478699164463,21823207.89960853,262.1420137534841
|
||||
11.3,1386759.1791855951,390.82947437450605,21728160.88971532,261.81545762435434
|
||||
11.4,1395939.2416852904,390.70997702085253,21633476.26302751,261.4891421257888
|
||||
11.5,1405084.4058089943,390.5894488404711,21539151.583747786,261.1630514204039
|
||||
11.600000000000001,1414194.7727817593,390.46792355037144,21445185.807824824,260.83718544108797
|
||||
11.700000000000001,1423270.4378832965,390.3454323238288,21351577.952528503,260.5115448028764
|
||||
11.8,1432311.4962235806,390.22200536933536,21258327.036879413,260.1861301247683
|
||||
11.9,1441318.042742851,390.0976719679259,21165432.0816488,259.86094202976824
|
||||
12.0,1450290.1722116095,389.97246050877925,21072892.1093586,259.5359811449295
|
||||
12.100000000000001,1459227.9792306225,389.84639852319333,20980706.14428146,259.2112481013979
|
||||
12.200000000000001,1468131.5582309205,389.71951271701596,20888873.212440677,258.88674353445447
|
||||
12.3,1477001.0034737969,389.59182900161403,20797392.34161027,258.5624680835606
|
||||
12.4,1485836.4090508097,389.46337252345796,20706262.561314918,258.23842239240224
|
||||
12.5,1494637.8688837802,389.3341676923915,20615482.902829994,257.9146071089349
|
||||
12.600000000000001,1503405.4767247946,389.20423820865625,20525052.399181567,257.5910228854296
|
||||
12.700000000000001,1512139.3261562001,389.07360708873284,20434970.085146382,257.26767037851835
|
||||
12.8,1520839.5105906113,388.94229669006046,20345234.997251876,256.9445502492407
|
||||
12.9,1529506.1233409408,388.81032876227204,20255846.173053782,256.62166315000906
|
||||
13.0,1538139.2687433015,388.67772882293264,20166802.53641284,256.2990076411302
|
||||
13.100000000000001,1546739.030251722,388.5445136335602,20078103.22657088,255.97658615427704
|
||||
13.200000000000001,1555305.5007360894,388.4107031827765,19989747.285653118,255.65439933992917
|
||||
13.3,1563838.7729005008,388.27631690939495,19901733.757494725,255.332447852161
|
||||
13.4,1572338.9392832702,388.14137372147235,19814061.687640797,255.0107323486784
|
||||
13.5,1580806.0922569225,388.0058920145713,19726730.123346385,254.68925349085504
|
||||
13.600000000000001,1589240.3240281995,387.86988968927403,19639738.113576483,254.36801194376957
|
||||
13.700000000000001,1597641.7266380545,387.73338416798015,19553084.709006038,254.04700837624307
|
||||
13.8,1606010.3919616563,387.59639241102605,19466768.962019928,253.72624346087662
|
||||
13.9,1614346.4117083861,387.458930932153,19380789.926712975,253.40571787408948
|
||||
14.0,1622649.8774218408,387.32101581335974,19295146.658889957,253.0854322961577
|
||||
14.100000000000001,1630920.8804798292,387.18266271916264,19209838.21606559,252.76538741125262
|
||||
14.200000000000001,1639159.5120943757,387.0438869102949,19124863.657464534,252.4455839074805
|
||||
14.3,1647365.8633117182,386.90470325686863,19040222.0440214,252.12602247692183
|
||||
14.4,1655540.0250123062,386.76512625102305,18955912.438380726,251.8067038156715
|
||||
14.5,1663682.087910807,386.6251700190859,18871933.904897016,251.48762862387906
|
||||
14.600000000000001,1671792.1425560997,386.4848483332645,18788285.509634707,251.16879760578948
|
||||
14.700000000000001,1679870.2793312764,386.3441746228917,18704966.320368182,250.85021146978437
|
||||
14.8,1687916.588453644,386.2031619852454,18621975.406581767,250.5318709284234
|
||||
14.9,1695931.1599747243,386.06182319595837,18539311.83946974,250.21377669848638
|
||||
15.0,1703914.0837802505,385.920170719039,18456974.691936314,249.8959295010154
|
||||
15.100000000000001,1711865.4494154856,385.77821670970445,18374963.040397402,249.57833006564294
|
||||
15.200000000000001,1719785.3379250832,385.6359727064743,18293276.048945524,249.26097933285033
|
||||
15.3,1727673.8459201432,385.4934505781353,18211912.721118417,248.94387786218365
|
||||
15.4,1735531.0625176337,385.3506616315768,18130872.137749474,248.6270263958575
|
||||
15.5,1743357.0766656764,385.2076169067951,18050153.381413613,248.31042568075102
|
||||
15.600000000000001,1751151.9771435438,385.06432718490083,17969755.53642727,247.99407646845765
|
||||
15.700000000000001,1758915.8525616606,384.9208029958382,17889677.688848406,247.67797951533504
|
||||
15.8,1766648.7913616048,384.77705462583015,17809918.926476505,247.36213558255577
|
||||
15.9,1774350.881816107,384.63309212455715,17730478.33885257,247.04654543615806
|
||||
16.0,1782022.2120290494,384.4889253120841,17651355.017259125,246.73120984709743
|
||||
16.1,1789662.8699354655,384.3445637855432,17572548.05472022,246.41612959129878
|
||||
16.2,1797272.9433015438,384.2000169255848,17494056.546001427,246.10130544970855
|
||||
16.3,1804852.5197246224,384.05529390260284,17415879.58760983,245.78673820834797
|
||||
16.400000000000002,1812401.6866331936,383.9104036827472,17338016.277794052,245.47242865836654
|
||||
16.5,1819920.5312869006,383.76535503372884,17260465.716544226,245.15837759609565
|
||||
16.6,1827409.1407765402,383.6201565304272,17183227.005592,244.84458582310356
|
||||
16.7,1834867.6020240602,383.47481656030743,17106299.24841057,244.53105414625009
|
||||
16.8,1842296.0017825624,383.32934332865534,17029681.550214626,244.2177833777421
|
||||
16.900000000000002,1849694.4266362996,383.1837448636361,16953373.017960392,243.9047743351897
|
||||
17.0,1857062.9630006768,383.03802902118434,16877372.76034562,243.59202784166294
|
||||
17.1,1864401.697122252,382.8922034897328,16801679.887809563,243.27954472574828
|
||||
17.2,1871710.7150787353,382.7462757947841,16726293.512533028,242.96732582160686
|
||||
17.3,1878990.1030524147,382.60025337999576,16651212.745618157,242.65537190477806
|
||||
17.400000000000002,1886239.954455942,382.4541455990818,16576436.623591991,242.343682012199
|
||||
17.5,1893460.3482686526,382.3079576538116,16501964.331849081,242.03225853722532
|
||||
17.6,1900651.3699906773,382.16169648335216,16427794.988527464,241.72110231102408
|
||||
17.7,1907813.104956132,382.0153688850827,16353927.713477474,241.41021416968596
|
||||
17.8,1914945.6383331183,381.86898151834066,16280361.628261749,241.09959495427398
|
||||
17.900000000000002,1922049.0551237254,381.7225409080495,16207095.856155202,240.78924551087363
|
||||
18.0,1929123.4401640275,381.57605344823065,16134129.522145053,240.47916669064318
|
||||
18.1,1936168.8781240864,381.4295254054061,16061461.752930798,240.16935934986387
|
||||
18.2,1943185.4535079484,381.28296292189384,15989091.67692425,239.8598243499916
|
||||
18.3,1950173.2506536485,381.1363720190009,15917018.424249483,239.55056255770802
|
||||
18.400000000000002,1957132.3537332045,380.98975860011734,15845241.126742886,239.24157484497272
|
||||
18.5,1964062.8467526236,380.84312845371574,15773758.917953137,238.93286208907583
|
||||
18.6,1970964.8135518986,380.6964872562572,15702570.933141202,238.6244251726908
|
||||
18.7,1977838.3378050062,380.54984057500997,15631676.309280336,238.31626498392774
|
||||
18.8,1984683.5030199126,380.4031938707821,15561074.185056096,238.00838241638746
|
||||
18.900000000000002,1991500.3925385692,380.25655250057133,15490763.700866321,237.7007783692156
|
||||
19.0,1998289.0895369116,380.10992172013556,15420743.998821149,237.39345374715774
|
||||
19.1,2005049.677024864,379.96330668648653,15351014.222743012,237.08640946061425
|
||||
19.200000000000003,2011782.237846337,379.81671246030885,15281573.518166626,236.77964642569634
|
||||
19.3,2018486.8546792252,379.67014400830794,15212421.032339014,236.47316556428217
|
||||
19.400000000000002,2025163.610035411,379.5236062054879,15143555.914219463,236.16696780407335
|
||||
19.5,2031812.5863479478,379.3771038539995,15074977.31358037,235.861054060844
|
||||
19.6,2038433.8680519294,379.2306420805889,15006684.359544702,235.55542481191287
|
||||
19.700000000000003,2045027.536485746,379.084225365391,14938676.213175347,235.25008113730536
|
||||
19.8,2051593.6739729291,378.9378583245209,14870952.025374293,234.9450238874766
|
||||
19.900000000000002,2058132.3627231135,378.79154550141357,14803510.948218277,234.64025390703284
|
||||
20.0,2064643.6848320398,378.64529136859073,14736352.134958768,234.33577203462033
|
||||
|
@@ -0,0 +1,86 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
import unittest
|
||||
|
||||
from app.main import get_component_catalog
|
||||
from app.simulation.registry import (
|
||||
COMPONENT_MODEL_REGISTRY,
|
||||
validate_component_registries,
|
||||
)
|
||||
|
||||
|
||||
class ComponentCatalogTests(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
self.catalog = get_component_catalog()
|
||||
self.library = self.catalog["libraries"][0]
|
||||
self.components = {
|
||||
component["modelType"]: component
|
||||
for component in self.library["components"]
|
||||
}
|
||||
|
||||
def test_experimental_library_is_exposed_as_temporary(self) -> None:
|
||||
self.assertEqual(self.catalog["schemaVersion"], 1)
|
||||
self.assertEqual(self.library["id"], "experimental")
|
||||
self.assertEqual(self.library["label"], "临时测试组件库")
|
||||
self.assertEqual(self.library["version"], "0.1.0")
|
||||
self.assertTrue(self.library["temporary"])
|
||||
self.assertEqual(
|
||||
self.library["sourcePackage"],
|
||||
"app.simulation.components.experimental",
|
||||
)
|
||||
self.assertEqual(
|
||||
[category["id"] for category in self.library["categories"]],
|
||||
["storage", "flow", "junctions"],
|
||||
)
|
||||
|
||||
def test_every_registered_component_is_in_the_catalog(self) -> None:
|
||||
self.assertEqual(
|
||||
set(self.components),
|
||||
set(COMPONENT_MODEL_REGISTRY),
|
||||
)
|
||||
|
||||
def test_catalog_reuses_model_parameter_contracts(self) -> None:
|
||||
cylinder = self.components["cylinder"]
|
||||
parameters = {
|
||||
parameter["name"]: parameter for parameter in cylinder["parameters"]
|
||||
}
|
||||
|
||||
self.assertEqual(cylinder["label"], "气瓶")
|
||||
self.assertEqual(cylinder["modelVersion"], "1.0.0")
|
||||
self.assertEqual(parameters["volume"]["default"], 0.01)
|
||||
self.assertEqual(parameters["volume"]["quantity"], "volume")
|
||||
self.assertEqual(parameters["p0"]["unit"], "Pa")
|
||||
self.assertTrue(parameters["p0"]["minimumExclusive"])
|
||||
|
||||
def test_catalog_adds_port_layout_without_changing_physical_contract(self) -> None:
|
||||
tee_ports = {
|
||||
port["name"]: port for port in self.components["tee"]["ports"]
|
||||
}
|
||||
|
||||
self.assertEqual(tee_ports["port_in"]["side"], "left")
|
||||
self.assertEqual(tee_ports["port_out1"]["side"], "right")
|
||||
self.assertEqual(tee_ports["port_out2"]["side"], "right")
|
||||
self.assertEqual(tee_ports["port_in"]["kind"], "physical")
|
||||
self.assertEqual(tee_ports["port_in"]["domain"], "pneumatic")
|
||||
self.assertEqual(tee_ports["port_in"]["nominalRole"], "bidirectional")
|
||||
|
||||
def test_registry_can_repeat_discovery_and_validation(self) -> None:
|
||||
validate_component_registries()
|
||||
|
||||
def test_catalog_schema_is_committed_and_targets_version_one(self) -> None:
|
||||
schema_path = (
|
||||
Path(__file__).resolve().parent.parent
|
||||
/ "schemas"
|
||||
/ "component-catalog-v1.schema.json"
|
||||
)
|
||||
schema = json.loads(schema_path.read_text(encoding="utf-8"))
|
||||
|
||||
self.assertEqual(schema["properties"]["schemaVersion"]["const"], 1)
|
||||
self.assertIn("modelVersion", schema["$defs"]["component"]["required"])
|
||||
self.assertIn("version", schema["$defs"]["library"]["required"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -3,14 +3,14 @@ from __future__ import annotations
|
||||
import unittest
|
||||
|
||||
from app.main import compile_reactflow_network
|
||||
from PythonModels.components.cylinder import Cylinder
|
||||
from PythonModels.components.tank import Tank
|
||||
from PythonModels.components.tee import Tee
|
||||
from PythonModels.core.base import Component
|
||||
from PythonModels.core.medium import IdealGasMedium
|
||||
from PythonModels.core.network import SimulationNetwork
|
||||
from PythonModels.core.ports import PortDefinition, PortState, PortVariableDefinition
|
||||
from PythonModels.systems.testmodel import TestModelSystem
|
||||
from app.simulation.components.experimental.junctions.tee import Tee
|
||||
from app.simulation.components.experimental.storage.cylinder import Cylinder
|
||||
from app.simulation.components.experimental.storage.tank import Tank
|
||||
from app.simulation.core.base import Component
|
||||
from app.simulation.core.medium import IdealGasMedium
|
||||
from app.simulation.core.ports import PortDefinition, PortState, PortVariableDefinition
|
||||
from app.simulation.examples.testmodel.system import TestModelSystem
|
||||
from app.simulation.systems.network import SimulationNetwork
|
||||
from tests.test_system_xml_protocol import physical_connection_project
|
||||
|
||||
|
||||
|
||||
@@ -2,15 +2,15 @@ from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
|
||||
from PythonModels.components.cylinder import Cylinder
|
||||
from PythonModels.components.orifice import Orifice
|
||||
from PythonModels.components.pipe import Pipe
|
||||
from PythonModels.components.resistive_pipe import ResistivePipe
|
||||
from PythonModels.components.tank import Tank
|
||||
from PythonModels.components.tee import Tee
|
||||
from PythonModels.core.medium import IdealGasMedium
|
||||
from PythonModels.core.ports import PortVariableDefinition
|
||||
from PythonModels.registry import COMPONENT_MODEL_REGISTRY
|
||||
from app.simulation.components.experimental.flow.orifice import Orifice
|
||||
from app.simulation.components.experimental.flow.resistive_pipe import ResistivePipe
|
||||
from app.simulation.components.experimental.junctions.tee import Tee
|
||||
from app.simulation.components.experimental.storage.cylinder import Cylinder
|
||||
from app.simulation.components.experimental.storage.tank import Tank
|
||||
from app.simulation.core.medium import IdealGasMedium
|
||||
from app.simulation.core.ports import PortVariableDefinition
|
||||
from app.simulation.examples.testmodel.dynamic_pipe import Pipe
|
||||
from app.simulation.registry import COMPONENT_MODEL_REGISTRY
|
||||
|
||||
|
||||
class ComponentMetadataTests(unittest.TestCase):
|
||||
@@ -32,12 +32,14 @@ class ComponentMetadataTests(unittest.TestCase):
|
||||
with self.subTest(component=component.name):
|
||||
for attribute in (
|
||||
"MODEL_TYPE",
|
||||
"MODEL_VERSION",
|
||||
"PORTS",
|
||||
"PARAMETERS",
|
||||
"RESULT_VARIABLES",
|
||||
):
|
||||
self.assertIn(attribute, type(component).__dict__)
|
||||
self.assertTrue(component.MODEL_TYPE)
|
||||
self.assertTrue(component.MODEL_VERSION)
|
||||
self.assertEqual(component.model_type, component.MODEL_TYPE)
|
||||
self.assertEqual(component.port_definitions, component.PORTS)
|
||||
self.assertEqual(
|
||||
@@ -63,8 +65,15 @@ class ComponentMetadataTests(unittest.TestCase):
|
||||
with self.subTest(model_type=model_type):
|
||||
spec = COMPONENT_MODEL_REGISTRY[model_type]
|
||||
self.assertEqual(spec.model_type, component_class.MODEL_TYPE)
|
||||
self.assertEqual(
|
||||
spec.model_version,
|
||||
component_class.MODEL_VERSION,
|
||||
)
|
||||
self.assertEqual(spec.ports, component_class.PORTS)
|
||||
self.assertEqual(spec.parameters, component_class.PARAMETERS)
|
||||
self.assertIs(spec.display, component_class.DISPLAY)
|
||||
self.assertIs(spec.component_class, component_class)
|
||||
self.assertIn("create", component_class.__dict__)
|
||||
component = spec.create(f"{model_type}_1", self.medium, {})
|
||||
self.assertEqual(
|
||||
component.parameter_values,
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
|
||||
from app.simulation.components.experimental.library import LIBRARY
|
||||
from app.simulation.core.base import AlgebraicComponent
|
||||
from app.simulation.core.catalog import ComponentDisplaySpec, PortDisplaySpec
|
||||
from app.simulation.core.medium import IdealGasMedium
|
||||
from app.simulation.core.ports import PortDefinition
|
||||
from app.simulation.registry import (
|
||||
COMPONENT_LIBRARY_REGISTRY,
|
||||
COMPONENT_MODEL_REGISTRY,
|
||||
discover_component_registries,
|
||||
validate_component_model_class,
|
||||
)
|
||||
|
||||
|
||||
class ComponentRegistryTests(unittest.TestCase):
|
||||
def test_manifest_is_the_only_public_model_source(self) -> None:
|
||||
libraries, models = discover_component_registries()
|
||||
|
||||
self.assertEqual(libraries, COMPONENT_LIBRARY_REGISTRY)
|
||||
self.assertEqual(models, COMPONENT_MODEL_REGISTRY)
|
||||
self.assertEqual(
|
||||
tuple(models),
|
||||
("cylinder", "tank", "pipe", "orifice", "tee"),
|
||||
)
|
||||
self.assertNotIn(
|
||||
"app.simulation.components.experimental.flow.pipe:Pipe",
|
||||
LIBRARY.models,
|
||||
)
|
||||
|
||||
def test_every_public_model_owns_its_catalog_contract(self) -> None:
|
||||
for model_type, spec in COMPONENT_MODEL_REGISTRY.items():
|
||||
with self.subTest(model_type=model_type):
|
||||
declarations = spec.component_class.__dict__
|
||||
self.assertIn("MODEL_VERSION", declarations)
|
||||
self.assertIn("DISPLAY", declarations)
|
||||
self.assertIn("create", declarations)
|
||||
self.assertEqual(spec.display.library_id, LIBRARY.id)
|
||||
self.assertIn(
|
||||
spec.display.category_id,
|
||||
LIBRARY.category_by_id,
|
||||
)
|
||||
|
||||
def test_display_ports_must_match_physical_ports(self) -> None:
|
||||
class BrokenDisplayComponent(AlgebraicComponent):
|
||||
MODEL_TYPE = "broken_display"
|
||||
MODEL_VERSION = "1.0.0"
|
||||
PORTS = (
|
||||
PortDefinition.pneumatic(
|
||||
"port_a",
|
||||
nominal_role="bidirectional",
|
||||
),
|
||||
)
|
||||
PARAMETERS = ()
|
||||
RESULT_VARIABLES = ()
|
||||
DISPLAY = ComponentDisplaySpec(
|
||||
label="错误显示模型",
|
||||
library_id="experimental",
|
||||
category_id="flow",
|
||||
symbol="generic",
|
||||
ports=(PortDisplaySpec("port_b", "right"),),
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def create(
|
||||
cls,
|
||||
*,
|
||||
name: str,
|
||||
medium: IdealGasMedium,
|
||||
parameters,
|
||||
):
|
||||
return cls(name)
|
||||
|
||||
with self.assertRaisesRegex(
|
||||
ValueError,
|
||||
"display ports must exactly match",
|
||||
):
|
||||
validate_component_model_class(
|
||||
BrokenDisplayComponent,
|
||||
library=LIBRARY,
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -23,9 +23,9 @@ from app.main import (
|
||||
simulation_event_stream,
|
||||
simulate_system_xml,
|
||||
)
|
||||
from PythonModels.components.resistive_pipe import ResistivePipe
|
||||
from PythonModels.core.solver import SolveIVPConfig
|
||||
from PythonModels.systems.generic import (
|
||||
from app.simulation.components.experimental.flow.resistive_pipe import ResistivePipe
|
||||
from app.simulation.solvers.solver import SolveIVPConfig
|
||||
from app.simulation.systems.generic import (
|
||||
GenericFluidSystem,
|
||||
SimulationPreparationError,
|
||||
)
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
|
||||
from app.simulation.examples.testmodel.run import prepare_testmodel_run
|
||||
from app.simulation.paths import (
|
||||
PROJECT_ROOT,
|
||||
SIMULATION_BASELINES_DIR,
|
||||
SIMULATION_RUNS_DIR,
|
||||
)
|
||||
|
||||
|
||||
class SimulationPathTests(unittest.TestCase):
|
||||
def test_default_run_paths_are_independent_of_module_depth(self) -> None:
|
||||
prepared = prepare_testmodel_run()
|
||||
|
||||
self.assertEqual(prepared.repo_root, PROJECT_ROOT)
|
||||
self.assertEqual(prepared.output_dir.parent, SIMULATION_RUNS_DIR)
|
||||
|
||||
def test_testmodel_baselines_live_with_the_test_assets(self) -> None:
|
||||
baseline_dir = SIMULATION_BASELINES_DIR / "testmodel"
|
||||
|
||||
self.assertTrue((baseline_dir / "testmodel_primary_series.csv").is_file())
|
||||
self.assertTrue(
|
||||
(
|
||||
baseline_dir / "testmodel_modelica_comparison_summary.txt"
|
||||
).is_file()
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user