OpenModelica cannot run FMU? - modelica

I have created a model in OpenModelica using some simple blocks and equations:
block ZapuniInterpolation
// ----------------------------------------------------------------------------- //
Modelica.Blocks.Interfaces.RealInput tableInput(start=190) annotation(
Placement(visible = true, transformation(origin = {-68, 20}, extent = {{-20, -20}, {20, 20}}, rotation = 0), iconTransformation(origin = {-68, 20}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
Modelica.Blocks.Interfaces.RealInput sineGainInput(start=1) annotation(
Placement(visible = true, transformation(origin = {-68, -20}, extent = {{-20, -20}, {20, 20}}, rotation = 0), iconTransformation(origin = {-68, -20}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
Modelica.Blocks.Interfaces.RealOutput output1 annotation(
Placement(visible = true, transformation(origin = {22, 20}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {22, 20}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Blocks.Interfaces.RealOutput output2 annotation(
Placement(visible = true, transformation(origin = {42, 20}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {42, 20}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Blocks.Interfaces.RealOutput output3 annotation(
Placement(visible = true, transformation(origin = {62, 20}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {62, 20}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Blocks.Interfaces.RealInput alpha(start=0) annotation(
Placement(visible = true, transformation(origin = {-8,-20}, extent = {{-20, -20}, {20, 20}}, rotation = 0), iconTransformation(origin = {-8,-20}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
Modelica.Blocks.Interfaces.RealInput beta(start=0) annotation(
Placement(visible = true, transformation(origin = {22, -20}, extent = {{-20, -20}, {20, 20}}, rotation = 0), iconTransformation(origin = {22, -20}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
Modelica.Blocks.Interfaces.RealInput gamma(start=0) annotation(
Placement(visible = true, transformation(origin = {52, -20}, extent = {{-20, -20}, {20, 20}}, rotation = 0), iconTransformation(origin = {52, -20}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
Modelica.Blocks.Interfaces.RealInput sineFrequency(start = 1) annotation(
Placement(visible = true, transformation(origin = {-38, -20}, extent = {{-20, -20}, {20, 20}}, rotation = 0), iconTransformation(origin = {-38, -20}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
// ----------------------------------------------------------------------------- //
protected
// ----------------------------------------------------------------------------- //
import PI = Modelica.Constants.pi;
// -------------
Modelica.Blocks.Tables.CombiTable1Ds modelDef(table = [180.0, 0.0, 0.125639618, 0.122496368, 0.152595123, 1.30134654, 7.03518772, 10.1638193, 11.777113, 12.5243101, 21.683424, 27.5360508, 34.4655838, 34.1353836, -0.000156808334, 0.000567958435, -6.16513252e-06, 5.07716331e-05, 0.000295116516, -0.00226303029, 1.72715359e-05, -2.76345825e-05, -0.000384722595, -1.60172176e-05, 2.38217144e-05, 8.43528748e-06, 2.26263523e-05, -0.0392020416, -0.0412239838, 0.000444312775, -0.00735736036, 0.083243988, 0.00416324186, 0.00528137589, -0.012360487, 1.24845228e-05, -0.196934738, 6.53376694e-05, -7.1772345e-07, -0.047993618;
182.5, 0.0, 0.12338031, 0.121614441, 0.152516403, 1.28446889, 7.03372765, 10.160368, 11.7592869, 12.5243101, 24.4601326, 27.5334625, 34.4655838, 32.8034935, -0.000155028641, 0.000569061768, -1.06752777e-05, 4.43576736e-05, 0.000292540131, -0.00226327395, 1.87270737e-05, -2.94425335e-05, -0.000384721771, -1.95333481e-05, 2.38186722e-05, 8.43502998e-06, 2.18605156e-05, -0.038757122, -0.0399122047, 0.000745555359, -0.00661621618, 0.080380722, 0.00384176278, 0.00474613094, -0.010696907, 1.03946018e-05, -0.187355469, 0.000304825897, -3.04758026e-07, -0.0856405334;
185.0, 0.0, 0.121165268, 0.120708992, 0.152441833, 1.26705885, 7.03220701, 10.1565781, 11.7394562, 12.5243101, 26.2911625, 27.5308762, 34.4655838, 33.3992195, -0.000153284882, 0.000568685425, -4.0209774e-05, 3.89236832e-05, 0.000290123566, -0.00226349735, 2.0346014e-05, -3.14919395e-05, -0.000384720856, -2.75364189e-05, 2.39696522e-05, 8.43503952e-06, 1.46955872e-05, -0.0383211823, -0.0385091896, 0.00271969485, -0.00597921848, 0.0775424423, 0.00357709074, 0.00436138248, -0.00955755329, 8.97015572e-06, -0.137678406, 0.000970456665, -8.64766174e-07, -0.156308731;
187.5, 0.0, 0.118988342, 0.119786552, 0.152369507, 1.24918771, 7.0306282, 10.1524391, 11.7177658, 12.5243092, 26.049839, 27.5282478, 34.4655838, 37.3313332, -0.000151576111, 0.000570432922, 2.22414017e-05, 3.42602654e-05, 0.000287870667, -0.00226369929, 2.21327553e-05, -3.37703247e-05, -0.000384719849, -3.28333435e-05, 2.40614624e-05, 8.43494415e-06, 6.49287128e-06, -0.0378939934, -0.0372608452, -0.00145591199, -0.00542455482, 0.074719574, 0.00335672474, 0.00408232164, -0.00875357533, 7.95372009e-06, -0.080245285, 0.000683899231, 4.3715094e-07, -0.196699677;
190.0, 0.0, 0.116858894, 0.118837822, 0.152297958, 1.23091626, 7.02899122, 10.1479139, 11.6941319, 12.5243092, 24.9532948, 27.5255089, 34.4655838, 43.7087631, -0.000149901413, 0.000571410095, 8.67566872e-06, 3.02129364e-05, 0.000285783508, -0.00226387715, 2.41047344e-05, -3.62895241e-05, -0.000384718781, -3.62359619e-05, 2.40104408e-05, 8.43495083e-06, 3.14631987e-06, -0.0374753189, -0.0359707489, -0.000549157532, -0.0049361062, 0.0719031982, 0.00317143512, 0.00388165021, -0.00817939949, 7.20596743e-06, -0.0537428932, 0.000341564392, 1.62058945e-07, -0.2088992;
195.0, 0.0, 0.112727142, 0.116876053, 0.152152176, 1.19337523, 7.02551937, 10.1374197, 11.639926, 12.5243092, 22.4547005, 27.5198441, 34.4655838, 63.5006485, -0.000146650772, 0.000572308289, 3.85471559e-06, 2.35291004e-05, 0.000282106537, -0.00226414824, 2.87340622e-05, -4.21810608e-05, -0.00038471637, -4.2829483e-05, 2.39550076e-05, 8.43493652e-06, 1.15650666e-06, -0.0366626587, -0.0333576317, -0.00022747081, -0.0041120615, 0.0662582474, 0.0028797617, 0.00365292263, -0.00749141979, 6.22078133e-06, -0.0335395622, 0.00014459668, 7.19030685e-08, -0.2181745;
200.0, 0.0, 0.10876281, 0.114828865, 0.151995438, 1.15478432, 7.02172279, 10.1242056, 11.5731678, 12.5243082, 20.1688595, 27.5138836, 34.4655838, 97.7778931, -0.000143526184, 0.000572750549, 2.4388926e-06, 1.82274666e-05, 0.000279082581, -0.00226427436, 3.46423569e-05, -4.95841827e-05, -0.000384713623, -5.03695107e-05, 2.39311123e-05, 8.4349184e-06, 1.23468935e-06, -0.0358815079, -0.030764555, -0.000133495087, -0.00343931985, 0.0605537033, 0.00266271996, 0.00360132694, -0.00721686459, 5.66029549e-06, -0.0255758495, 8.98340149e-05, 4.8260746e-08, -0.220523834]) annotation(
Placement(visible = true, transformation(origin = {-18, 20}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
// ----------------------------------------------------------------------------- //
Real[13] omega2 = {modelDef.y[1], modelDef.y[2], modelDef.y[3], modelDef.y[4], modelDef.y[5], modelDef.y[6], modelDef.y[7], modelDef.y[8], modelDef.y[9], modelDef.y[10], modelDef.y[11], modelDef.y[12], modelDef.y[13]};
// -------------
Real[13] Ba = {modelDef.y[14], modelDef.y[15], modelDef.y[16], modelDef.y[17], modelDef.y[18], modelDef.y[19], modelDef.y[20], modelDef.y[21], modelDef.y[22], modelDef.y[23], modelDef.y[24], modelDef.y[25], modelDef.y[26]};
// -------------
Real[13] Ca = {modelDef.y[27], modelDef.y[28], modelDef.y[29], modelDef.y[30], modelDef.y[31], modelDef.y[32], modelDef.y[33], modelDef.y[34], modelDef.y[35], modelDef.y[36], modelDef.y[37], modelDef.y[38], modelDef.y[39]};
// -------------
Real[13] damping = beta * omega2 + gamma * sqrt(omega2) .+ alpha;
// ----------------------------------------------------------------------------- //
Real [1] ssu "input vector";
Real [3] ssy = {output1, output2, output3}"output vector";
Real [26] ssx "state vector";
// ----------------------------------------------------------------------------- //
// -------------
Real[26, 26] ssA = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0;
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0;
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0;
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0;
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0;
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0;
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0;
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0;
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0;
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1;
-omega2[1], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -damping[1], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
0, -omega2[2], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -damping[2], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
0, 0, -omega2[3], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -damping[3], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
0, 0, 0, -omega2[4], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -damping[4], 0, 0, 0, 0, 0, 0, 0, 0, 0;
0, 0, 0, 0, -omega2[5], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -damping[5], 0, 0, 0, 0, 0, 0, 0, 0;
0, 0, 0, 0, 0, -omega2[6], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -damping[6], 0, 0, 0, 0, 0, 0, 0;
0, 0, 0, 0, 0, 0, -omega2[7], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -damping[7], 0, 0, 0, 0, 0, 0;
0, 0, 0, 0, 0, 0, 0, -omega2[8], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -damping[8], 0, 0, 0, 0, 0;
0, 0, 0, 0, 0, 0, 0, 0, -omega2[9], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -damping[9], 0, 0, 0, 0;
0, 0, 0, 0, 0, 0, 0, 0, 0, -omega2[10], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -damping[10], 0, 0, 0;
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -omega2[11], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -damping[11], 0, 0;
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -omega2[12], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -damping[12], 0;
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -omega2[13], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -damping[13]];
// ------------
Real[26, 1] ssB = [0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; Ba[1]; Ba[2]; Ba[3]; Ba[4]; Ba[5]; Ba[6]; Ba[7]; Ba[8]; Ba[9]; Ba[10]; Ba[11]; Ba[12]; Ba[13]];
// ------------
Real[3, 26] ssC = [Ca[1], Ca[2], Ca[3], Ca[4], Ca[5], Ca[6], Ca[7], Ca[8], Ca[9], Ca[10], Ca[11], Ca[12], Ca[13], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
Ba[1], Ba[2], Ba[3], Ba[4], Ba[5], Ba[6], Ba[7], Ba[8], Ba[9], Ba[10], Ba[11], Ba[12], Ba[13], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, Ba[1], Ba[2], Ba[3], Ba[4], Ba[5], Ba[6], Ba[7], Ba[8], Ba[9], Ba[10], Ba[11], Ba[12], Ba[13]];
// -----------
Real[3, 1] ssD = [0; 0; 0];
// ----------------------------------------------------------------------------- //
initial equation
ssx = fill(0, 26);
// ----------------------------------------------------------------------------- //
equation
// ----------------------------------------------------------------------------- //
connect(modelDef.u, tableInput) annotation(
Line(points = {{-30, 20}, {-68, 20}}, color = {0, 0, 127}));
der(ssx) = ssA * ssx + ssB * ssu;
ssy = ssC * ssx + ssD * ssu;
ssu = {sineGainInput *sin(2*PI*sineFrequency*time)};
// ----------------------------------------------------------------------------- //
annotation(
uses(Modelica(version = "3.2.3")));
end ZapuniInterpolation;
Now I exported the model to an FMU using OpenModelica, using version 2.0 and Model Exchange - Co Simulation. When I import this FMU in another model and attach simple inputs and outputs, like:
model importZapuniFMUtest
Modelica.Blocks.Interfaces.RealInput alpha(start=0) annotation(
Placement(visible = true, transformation(origin = {-80, 80}, extent = {{-20, -20}, {20, 20}}, rotation = 0), iconTransformation(origin = {-80, 80}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
Modelica.Blocks.Interfaces.RealInput beta(start=0) annotation(
Placement(visible = true, transformation(origin = {-80, 50}, extent = {{-20, -20}, {20, 20}}, rotation = 0), iconTransformation(origin = {-80, 50}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
Modelica.Blocks.Interfaces.RealInput gamma(start=0) annotation(
Placement(visible = true, transformation(origin = {-80, 20}, extent = {{-20, -20}, {20, 20}}, rotation = 0), iconTransformation(origin = {-80, 20}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
Modelica.Blocks.Interfaces.RealInput Length(start=190) annotation(
Placement(visible = true, transformation(origin = {-80, -80}, extent = {{-20, -20}, {20, 20}}, rotation = 0), iconTransformation(origin = {-80, -80}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
Modelica.Blocks.Interfaces.RealInput Amplitude(start=1) annotation(
Placement(visible = true, transformation(origin = {-80, -50}, extent = {{-20, -20}, {20, 20}}, rotation = 0), iconTransformation(origin = {-80, -50}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
Modelica.Blocks.Interfaces.RealInput Frequency(start=1) annotation(
Placement(visible = true, transformation(origin = {-80, -20}, extent = {{-20, -20}, {20, 20}}, rotation = 0), iconTransformation(origin = {-80, -20}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
Modelica.Blocks.Interfaces.RealOutput Y1 annotation(
Placement(visible = true, transformation(origin = {70, 50}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {70, 50}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Blocks.Interfaces.RealOutput Y2 annotation(
Placement(visible = true, transformation(origin = {70, 30}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {70, 30}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Blocks.Interfaces.RealOutput Y3 annotation(
Placement(visible = true, transformation(origin = {70, 10}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {70, 10}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
ZapuniInterpolation_me_FMU zapuniInterpolation annotation(
Placement(visible = true, transformation(origin = {10, 10}, extent = {{-30, -30}, {30, 30}}, rotation = 0)));
equation
connect(zapuniInterpolation.alpha, alpha) annotation(
Line(points = {{-24, 32}, {-30, 32}, {-30, 80}, {-80, 80}, {-80, 80}}, color = {0, 0, 127}));
connect(zapuniInterpolation.beta, beta) annotation(
Line(points = {{-24, 24}, {-40, 24}, {-40, 50}, {-80, 50}, {-80, 50}}, color = {0, 0, 127}));
connect(zapuniInterpolation.gamma, gamma) annotation(
Line(points = {{-24, 16}, {-50, 16}, {-50, 20}, {-80, 20}, {-80, 20}}, color = {0, 0, 127}));
connect(zapuniInterpolation.sineFrequency, Frequency) annotation(
Line(points = {{-24, 8}, {-50, 8}, {-50, -20}, {-80, -20}, {-80, -20}}, color = {0, 0, 127}));
connect(zapuniInterpolation.sineGainInput, Amplitude) annotation(
Line(points = {{-24, 0}, {-40, 0}, {-40, -50}, {-80, -50}, {-80, -50}}, color = {0, 0, 127}));
connect(zapuniInterpolation.tableInput, Length) annotation(
Line(points = {{-24, -6}, {-30, -6}, {-30, -80}, {-80, -80}, {-80, -80}}, color = {0, 0, 127}));
connect(zapuniInterpolation.output1, Y1) annotation(
Line(points = {{44, 32}, {50, 32}, {50, 50}, {70, 50}, {70, 50}}, color = {0, 0, 127}));
connect(zapuniInterpolation.output2, Y2) annotation(
Line(points = {{44, 24}, {52, 24}, {52, 30}, {70, 30}, {70, 30}}, color = {0, 0, 127}));
connect(zapuniInterpolation.output3, Y3) annotation(
Line(points = {{44, 16}, {50, 16}, {50, 10}, {70, 10}, {70, 10}}, color = {0, 0, 127}));
annotation(
uses(Modelica(version = "3.2.3")));
end importZapuniFMUtest;
I get the following error:
[1] 13:28:34 Translation Error [ZapuniInterpolation_me_FMU: 1360:7-1360:39]: Operator reinit may only be used in the body of a when equation.
I have no idea what I have done wrong, since the initial model runs just fine in OpenModelica, I can change all of the inputs etc but the exported model does not work.

Related

about nodelist in triadic_census for netwrokx

I want to get triadic_census in a single node, this is the code example:
import netwrokx as nx
G = nx.DiGraph([("b", "a"), ("b","c")])
print(nx.triadic_census(G))
print(nx.triadic_census(G,nodelist=["c"]))
But the result is different from what I think. this is the result of code:
{'003': 0, '012': 0, '102': 0, '021D': 1, '021U': 0, '021C': 0, '111D': 0, '111U': 0, '030T': 0, '030C': 0, '201': 0, '120D': 0, '120U': 0, '120C': 0, '210': 0, '300': 0}
{'003': 0, '012': 0, '102': 0, '021D': 0, '021U': 0, '021C': 0, '111D': 0, '111U': 0, '030T': 0, '030C': 0, '201': 0, '120D': 0, '120U': 0, '120C': 0, '210': 0, '300': 0}
I think Node C should also be part of 021D, i want to know whether the parameters I have entered are not right?
The problem has been fixed networkx pr

Save a string to a h5py dataset using type "array of 8-bit integers (80)"

I wish to create a h5py "string" dataset (for example "A"), using the data type "array of 8-bit integers (80)" (as shown in HDFView, see here). Each integer of this array of length 80 is in fact ord(x) of the corresponding character of this string. So for instance Top is stored as 84 111 112 0 0 0 ..., with in total 80 int8.
The desired dataset should look like this
DATASET "NOM" {
DATATYPE H5T_ARRAY { [80] H5T_STD_I8LE }
DATASPACE SIMPLE { ( 1 ) / ( 1 ) }
DATA {
(0): [ 84, 111, 112, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
}
However I'm unable to create this dataset using h5py. Using a standard numpy array gives this
DATASET "NOM" {
DATATYPE H5T_STD_I8LE
DATASPACE SIMPLE { ( 1, 80 ) / ( 1, 80 ) }
DATA {
(0,0): 84, 111, 112, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
(0,15): 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
(0,31): 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
(0,47): 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
(0,63): 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
(0,79): 0
}
}
So what is data and dtype needed, if my string, say, is "Top".
.create_dataset("NOM", data=data, dtype=dtype)
According to https://github.com/h5py/h5py/issues/955, maybe I need to use a lower level interface...?
Thanks!
Solution
The problem is that if we create the numpy dataset data before writing it by using .create_dataset("NOM", data=data), internally numpy will always interpret my 80int8 data type as a 1d array of int8
dtype = np.dtype("80int8")
x = np.array(2, dtype=dtype)
# x.dtype = dtype('int8')
The solution is thus to declare the data set with the desired dtype first, then fill in the data.
dataset = gro.create_dataset("NOM", (len(nom),), dtype="80int8")
for i in range(len(nom)):
nom_80 = nom[i] + "\x00" * (80 - len(nom[i])) # make nom 80 characters
dataset[i] = [ord(x) for x in nom_80]
# dataset.dtype = dtype(('i1', (80,)))
Make a uint8 array of right size and content:
In [417]: x = np.zeros(80, dtype='uint8')
In [419]: x[:3]=[ord(i) for i in 'Top']
In [421]: ds1=hf.create_dataset('other4', data=x)
A structured array approach:
In [486]: dt = np.dtype([('f0','80int8')])
In [487]: dt
Out[487]: dtype([('f0', 'i1', (80,))])
In [488]: x = np.zeros(1, dt)
In [489]: x['f0'][0][:3]=[ord(i) for i in 'Top']
In [490]: x
Out[490]:
array([([ 84, 111, 112, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],)],
dtype=[('f0', 'i1', (80,))])
In [491]: ds1=hf.create_dataset('st1', data=x)
In [492]: ds1
Out[492]: <HDF5 dataset "st1": shape (1,), type "|V80">
produces
DATASET "st1" {
DATATYPE H5T_COMPOUND {
H5T_ARRAY { [80] H5T_STD_I8LE } "f0";
}
DATASPACE SIMPLE { ( 1 ) / ( 1 ) }
DATA {
(0): {
[ 84, 111, 112, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
}
}
}

Wrong layout of tiles

I create a level an array of int's. This is the code:
using UnityEngine;
using System.Collections;
public class Level1 : MonoBehaviour
{
int[][] level = new int[][]
{
new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 83, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 83, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 83, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 83, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 83, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 83, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 83, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 83, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 83, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 83, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 83, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
new int[] { 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16}
};
public Transform tile00;
public Transform tile16;
public Transform tile38;
int rows = 12;
int cols = 32;
void Start ()
{
BuildLevel ();
}
void BuildLevel(){
int i, j;
GameObject dynamicParent = GameObject.Find ("DynamicObjects");
for(i=0; i<rows; i++)
{
for(j=0; j<cols; j++)
{
Transform toCreate = null;
Debug.Log (i + " , " + j + " " + level[i][j]);
if (level[i][j] == 0)
toCreate = tile00;
if (level[i][j] == 83)
toCreate = tile38;;
if (level[i][j] == 16)
toCreate = tile16;
Vector3 v3 = new Vector3(16-j, 6-i, 0);
Transform newObject = Instantiate(toCreate, v3, Quaternion.identity) as Transform;
newObject.parent = dynamicParent.transform;
}
}
}
}
The output screen is like that:
The tiles are 50 X 50. I changed the dimensions of tiles, I changed the positions on X and Y. I tried everything but I found no solution.Could you give me an ideea, please ?
For the horizontal tiles the layout I want to obtain is (the image is processed with paint) :
The most likely answer is because of this line
Vector3 v3 = new Vector3(16-j, 6-i, 0);
You say that your images are 50 x 50 px each. Assuming that you haven't changed the pixels to units property of your sprite, this would make each of these image occupy a space of 0.5 Unity units on both the X & Y axes.
Now, in your calculation, here's what is happening.
Iteration 1 - (i = 0, j = 0). Position = Vector3(16, 6, 0)
Iteration 2 - (i = 0, j = 1). Position = Vector3(15, 6, 0)...
Iteration 33 -(i = 1, j = 0). Position = Vector3(16, 5, 0)
Now, the difference in the X values between Iteration 1 & Iteration 2 is 1 Unity unit. We've already established earlier that these Sprites will occupy only 0.5 Unity unit due to their size.
Same thing along the Y axis for Iteration 1 & Iteration 33. A difference of 1 unit, with each image occupying only 0.5 units.
So, either change the image to be 100 x 100 px, or change the pixels to units

Avoid the exception java.lang.OutOfMemoryError without growing the heap space?

I met a problem with the Java heap space in which I try to group the consecutive elements of one array in order to create a matrix for computing his transposed. I have a lot of values in the array (26726400) and I try to have buckets of size 29. But when I tested the following code, I get the exception java.lang.OutOfMemoryError: Java heap space
val arr = new Array[Int](256 * 3600 * 29)
arr: Array[Int] = Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,...
scala> arr.grouped(29).toArray
java.lang.OutOfMemoryError: Java heap space
My purpose is to transpose the matrix. If I run sbt -mem 2048, this code works but is it an another way to do this task without growing the heap space ?
This may not save much memory, though it is surely more efficient than grouped, which does a couple of copies between buffers internally.
scala> val arr = new Array[Int](256 * 3600 * 29)
arr: Array[Int] = Array(0, 0, 0,...
scala> Array.tabulate(256 * 3600, 29)((i,j) => arr(i * 29 + j))
res0: Array[Array[Int]] = Array(Array(0, 0, 0,...
It's noticeably faster in my scientific trial.
You could also use 1-dim tabulate, allocate Array.ofDim(29) and Array.copy.
Well, the default memory for a JVM instance on machines with >1Gb of RAM is RAM/4. So, add more memory to your computer, and you won't have to pass that parameter to sbt.
Joking aside, you have at least 3 copies of the data here. First is the original arr instance, then the result of grouped operation, then the result of toArray call. And it could even be more, I'm not sure about the implicit conversion to ArrayOps, which is required by calling the grouped method (it's not defined on the Array class, actually).
Given your data size and type, one copy takes ~101Mb of memory, excluding any overhead associated with storage. To solve the problem, reduce the amount of copies you make. For example, I don't really understand why you need the last toArray call.
As a side note, if it's not a homework, consider using some existing libraries for matrix operations, like jBLAS.

Print whole result in interactive Scala console

When I type something into the Scala interactive console, the console prints the result of the statement. If the result is too long, the console crops it (scroll right to see it):
scala> Array.fill[Byte](5)(0)
res1: Array[Byte] = Array(0, 0, 0, 0, 0)
scala> Array.fill[Byte](500)(0)
res2: Array[Byte] = Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...
scala> "a"*5000
res3: String = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
How can I print the same or equivalent output, for any given object (not just a collection or array) without the cropping occurring?
The result is not "cropped", simply println is invoking java.lang.Arrays.toString() (since scala.Array is a Java array).
Specifically, Arrays defines a toString overload that works with Object, which calls the toString implementation of java.lang.Object on every element. Such implementation prints the reference of the object, so you end up with
[Lscala.Tuple2;#4de71ca9
which is an Array containing the reference 4de71ca9 to a scala.Tuple2 object.
That has been discussed in this ticket years ago.
In the specific case of arrays, you can simply do
println(x.mkString("\n"))
or
x foreach println
or
println(x.deep)
Update
To answer your last edit, you can set the maximum lenght of the strings printed by the REPL
scala> :power
** Power User mode enabled - BEEP WHIR GYVE **
** :phase has been set to 'typer'. **
** scala.tools.nsc._ has been imported **
** global._, definitions._ also imported **
** Try :help, :vals, power.<tab> **
scala> vals.isettings.maxPrintString = Int.MaxValue
vals.isettings.maxPrintString: Int = 2147483647
try this
scala> :power
Power mode enabled. :phase is at typer.
import scala.tools.nsc._, intp.global._, definitions._
Try :help or completions for vals._ and power._
scala> vals.isettings.maxPrintString
res9: Int = 800
scala> vals.isettings.maxPrintString = 10000
vals.isettings.maxPrintString: Int = 10000
try
x map println
or
x foreach println