From 76782dd2d9c2b1337e6afc3114f63a70442142ff Mon Sep 17 00:00:00 2001 From: Vincent BLAIN Date: Tue, 23 Aug 2022 11:11:39 +0200 Subject: [PATCH] [98] Functions modifications Replace \u2200 and \u2208 caracters by 'forall' and 'in'. Replace \u2192, \u00D7 caracters by changing the function/reduction syntaxes. Bug: https://github.com/cea-hpc/NabLab/issues/98 Signed-off-by: Vincent BLAIN --- ...teFunctionInTypeDeclaration_inArgs_Arg.gif | Bin 0 -> 223 bytes ...tionInTypeDeclaration_inTypes_BaseType.gif | Bin 0 -> 223 bytes ...urnTypeDeclaration_returnType_BaseType.gif | Bin 0 -> 223 bytes .../CreateFunction_inTypes_BaseType.gif | Bin 0 -> 223 bytes ...sDeclaration_FunctionInTypeDeclaration.gif | Bin 0 -> 223 bytes ...laration_FunctionReturnTypeDeclaration.gif | Bin 0 -> 223 bytes .../CreateFunction_returnType_BaseType.gif | Bin 0 -> 223 bytes .../ctool16/CreateReduction_inArgs_Arg.gif | Bin 0 -> 223 bytes .../full/obj16/FunctionInTypeDeclaration.gif | Bin 0 -> 129 bytes .../obj16/FunctionReturnTypeDeclaration.gif | Bin 0 -> 129 bytes plugins/fr.cea.nabla.edit/plugin.properties | 10 + .../ExplicitHeatEquation.n | 20 +- .../NabLabExamples/src/glace2d/Glace2d.n | 68 ++-- .../src/heatequation/HeatEquation.n | 14 +- .../ImplicitHeatEquation.n | 18 +- .../IterativeHeatEquation.n | 24 +- .../ui/wizards/NewNablaProjectWizard.xtend | 2 +- .../fr.cea.nabla/model/generated/Nabla.ecore | 24 +- .../model/generated/Nabla.genmodel | 19 +- plugins/fr.cea.nabla/nablalib/Assert.n | 12 +- .../fr.cea.nabla/nablalib/CartesianMesh2D.n | 44 +-- plugins/fr.cea.nabla/nablalib/LinearAlgebra.n | 16 +- plugins/fr.cea.nabla/nablalib/Math.n | 64 ++-- .../src/fr/cea/nabla/ArgOrVarExtensions.xtend | 2 +- .../src/fr/cea/nabla/LabelServices.xtend | 320 +++++++++--------- .../src/fr/cea/nabla/LatexLabelServices.xtend | 16 +- .../src/fr/cea/nabla/LinearAlgebraUtils.xtend | 6 +- .../fr.cea.nabla/src/fr/cea/nabla/Nabla.xtext | 15 +- .../generator/ir/IrFunctionFactory.xtend | 223 ++++++------ .../ir/IrItemIndexDefinitionFactory.xtend | 6 +- .../generator/ir/IrItemIndexFactory.xtend | 6 +- .../src/fr/cea/nabla/hover/HoverHelper.xtend | 4 +- .../overloading/DeclarationBuilder.xtend | 8 +- .../overloading/DeclarationProvider.xtend | 4 +- .../nabla/scoping/NablaScopeProvider.xtend | 5 +- .../validation/ArgOrVarRefValidator.xtend | 50 +-- .../cea/nabla/validation/BasicValidator.xtend | 6 +- .../FunctionOrReductionValidator.xtend | 45 +-- .../validation/UniqueNameValidator.xtend | 73 ++-- tests/BathyLib/src/bathylib/BathyLib.n | 10 +- tests/DepthInit/src/depthinit/DepthInit.n | 4 +- .../sauv/gmds/ParallelWhiteheatKmds.cpp | 4 +- .../sauv/gmds/ParallelWhiteheatKokkos.cpp | 4 +- tests/NabLabDrafts/src/reduction/Reduction.n | 6 +- tests/NabLabTests/src/hydroremap/Hydro.n | 24 +- tests/NabLabTests/src/hydroremap/Remap.n | 4 +- tests/NabLabTests/src/iteration/Iteration.n | 18 +- tests/NabLabTests/src/variables/Variables.n | 8 +- .../nabla/tests/ConstExprServicesTest.xtend | 10 +- .../nabla/tests/DeclarationProviderTest.xtend | 40 +-- .../nabla/tests/IteratorExtensionsTest.xtend | 18 +- .../nabla/tests/NablaScopeProviderTest.xtend | 74 ++-- .../tests/NablagenScopeProviderTest.xtend | 10 +- .../AbstractExpressionInterpreterTest.xtend | 26 +- .../AbstractInstructionInterpreterTest.xtend | 22 +- .../AbstractJobInterpreterTest.xtend | 2 +- .../ReplaceAffectationsTest.xtend | 4 +- .../ReplaceOptionsByLocalVariablesTest.xtend | 2 +- .../ArgOrVarTypeProviderTest.xtend | 19 +- .../ExpressionTypeProviderTest.xtend | 14 +- .../validation/ArgOrVarRefValidatorTest.xtend | 14 +- .../tests/validation/BasicValidatorTest.xtend | 48 +-- .../validation/ExpressionValidatorTest.xtend | 28 +- .../FunctionOrReductionValidatorTest.xtend | 99 ++---- .../validation/InstructionValidatorTest.xtend | 14 +- .../validation/NablagenValidatorTest.xtend | 18 +- .../validation/UniqueNameValidatorTest.xtend | 20 +- .../validation/UnusedValidatorTest.xtend | 16 +- 68 files changed, 858 insertions(+), 846 deletions(-) create mode 100644 plugins/fr.cea.nabla.edit/icons/full/ctool16/CreateFunctionInTypeDeclaration_inArgs_Arg.gif create mode 100644 plugins/fr.cea.nabla.edit/icons/full/ctool16/CreateFunctionInTypeDeclaration_inTypes_BaseType.gif create mode 100644 plugins/fr.cea.nabla.edit/icons/full/ctool16/CreateFunctionReturnTypeDeclaration_returnType_BaseType.gif create mode 100644 plugins/fr.cea.nabla.edit/icons/full/ctool16/CreateFunction_inTypes_BaseType.gif create mode 100644 plugins/fr.cea.nabla.edit/icons/full/ctool16/CreateFunction_intypesDeclaration_FunctionInTypeDeclaration.gif create mode 100644 plugins/fr.cea.nabla.edit/icons/full/ctool16/CreateFunction_returnTypeDeclaration_FunctionReturnTypeDeclaration.gif create mode 100644 plugins/fr.cea.nabla.edit/icons/full/ctool16/CreateFunction_returnType_BaseType.gif create mode 100644 plugins/fr.cea.nabla.edit/icons/full/ctool16/CreateReduction_inArgs_Arg.gif create mode 100644 plugins/fr.cea.nabla.edit/icons/full/obj16/FunctionInTypeDeclaration.gif create mode 100644 plugins/fr.cea.nabla.edit/icons/full/obj16/FunctionReturnTypeDeclaration.gif diff --git a/plugins/fr.cea.nabla.edit/icons/full/ctool16/CreateFunctionInTypeDeclaration_inArgs_Arg.gif b/plugins/fr.cea.nabla.edit/icons/full/ctool16/CreateFunctionInTypeDeclaration_inArgs_Arg.gif new file mode 100644 index 0000000000000000000000000000000000000000..3f70d4d1aa9e157155a0d3abe83724cc8013ab6c GIT binary patch literal 223 zcmZ?wbhEHb6krfwIKsg2|NsB{_xIb|$1^Z6G&Nld4nAgSxkg8)?f?Jy`SJGu@7p&t zG#of^V9uO5mo8O0I5_N@t_DO~Cn>M%l3&^+HLp@^W{L2>zwd$Q@8|PC^ym5F-*=mV zra^$>PZmZHO9w=N>||h#QBdehiL_H=n0fZ_lnYxY^*8rTD)BV_Y|?Wrdy=M@dcRb1 zrgNai?ByreMf$YnoI2@d#h{~h-`mAPAgE#Xi-Zr0PPQ{GOmLIG(Nc3eSL^i4^n8Y# Onx@porfgM325SH?MPIQ1 literal 0 HcmV?d00001 diff --git a/plugins/fr.cea.nabla.edit/icons/full/ctool16/CreateFunctionInTypeDeclaration_inTypes_BaseType.gif b/plugins/fr.cea.nabla.edit/icons/full/ctool16/CreateFunctionInTypeDeclaration_inTypes_BaseType.gif new file mode 100644 index 0000000000000000000000000000000000000000..b52b0e49a6be7a80d719242daa45a57157c4eabb GIT binary patch literal 223 zcmZ?wbhEHb6krfwIKsg2|NsB{_xIb|$1^Z695`@b&YU?74GqD^j{W~1KR@37|9yKP z7b1S?Ql*1~!>;LSK(uv|^13ehrA<=vD#d1&2><*09*F*aJ`Y5Ho-h7=w;5;}1StMw zVFa;sKm^E62G$q_g}#(XJ2i%xXAe)guys;@bKj&APvg%fJ=d})X^N@$OC@JI2Wre- zeu7=3PixMplWtZFI%@a5T`UBG8fL#p_^{|?JJZ4hH~AYaHMeuMPQOggXUM5(N^NY) JR#jxM1_0EZVd4M) literal 0 HcmV?d00001 diff --git a/plugins/fr.cea.nabla.edit/icons/full/ctool16/CreateFunctionReturnTypeDeclaration_returnType_BaseType.gif b/plugins/fr.cea.nabla.edit/icons/full/ctool16/CreateFunctionReturnTypeDeclaration_returnType_BaseType.gif new file mode 100644 index 0000000000000000000000000000000000000000..618a818c271a6128b11df6bf543ecd14257cb927 GIT binary patch literal 223 zcmZ?wbhEHb6krfwIKsg2|NsB{_xIb|$1^Z695`@b&YU?74GqD^j{W~1KR@37|9yKP z_tJ|!n{M{ZJd@UNz+u;PH6YqLNqJqD{L&_=d6i-_ON9UZeGf!`Kc5GpKhGEczS|5m z4FVK@vM_>JIv@gMCj)DYfrlb&nYlQhND`=ydI zodY#yFF(O9(x)}&)JZoh1|7Bg-YymbK@GECBz#zOvYlyRf}8w}mYUnSTBl#8=QHHg OG^I8+WvePOSOWlSfMUr2 literal 0 HcmV?d00001 diff --git a/plugins/fr.cea.nabla.edit/icons/full/ctool16/CreateFunction_inTypes_BaseType.gif b/plugins/fr.cea.nabla.edit/icons/full/ctool16/CreateFunction_inTypes_BaseType.gif new file mode 100644 index 0000000000000000000000000000000000000000..0d5af181e232ef7011b1ae9e5850fa2ba69d5bf7 GIT binary patch literal 223 zcmZ?wbhEHb6krfwIKsg2|NsB{_xIb|$1^Z695`@b&YU?74GqD^j{W~1KR@37|9yKP z_xJCwZ{8fee}Dd^OO?B(s{zs0Ny_WG_ja)m2x^%9BH_cLlkH3k6Wru)wA9?r)jIt$J)a?` OrYW_tDO**M!5RS9g=F&p literal 0 HcmV?d00001 diff --git a/plugins/fr.cea.nabla.edit/icons/full/ctool16/CreateFunction_intypesDeclaration_FunctionInTypeDeclaration.gif b/plugins/fr.cea.nabla.edit/icons/full/ctool16/CreateFunction_intypesDeclaration_FunctionInTypeDeclaration.gif new file mode 100644 index 0000000000000000000000000000000000000000..912c2bf00e2e8dae2262822482a784f3df49c8a7 GIT binary patch literal 223 zcmZ?wbhEHb6krfwIKsg2|NsB{_xIb|$1^Z695`@b&YU@yE>$`>IQ;(~KR@37|9$(0 zhKAq2zrJ~M^#1+%K&f5R)qrU0B;|Eo@=Kef=2eQ#ED`?q_dO8({d^vX{ybm&`))JP zGzd`q$-)R?>3|53oeZoo3JQHGk#=efGtVBLa$)PF{^q_(C7#BgO?s|nPtp`q@0Uu> zbPm**z5E2bNT1f6QzzZ57*B$#$lN32yQ?T54|RYMp+Wp3jg| O)0EoSl&z}BU=09zuw-!n literal 0 HcmV?d00001 diff --git a/plugins/fr.cea.nabla.edit/icons/full/ctool16/CreateFunction_returnTypeDeclaration_FunctionReturnTypeDeclaration.gif b/plugins/fr.cea.nabla.edit/icons/full/ctool16/CreateFunction_returnTypeDeclaration_FunctionReturnTypeDeclaration.gif new file mode 100644 index 0000000000000000000000000000000000000000..834778fb99e61afa2303a42ca431fd7d21a9283c GIT binary patch literal 223 zcmZ?wbhEHb6krfwIKsg2|NsB{_xIb|$1^Z6Tzau*)6JflXVMxDIQ;(~KR@37|9$(0 zhKAq2zrJ~M^#1+%mo8QAnyv;!TPG>6>ylsEBsH&6Y-Wk@zrXK+=_ja)m2x^%9BH_cLlkH3k6Wru)wA9?r)jIt$J)a?` OrYW_tDO**M!5RS9g=F&p literal 0 HcmV?d00001 diff --git a/plugins/fr.cea.nabla.edit/icons/full/ctool16/CreateReduction_inArgs_Arg.gif b/plugins/fr.cea.nabla.edit/icons/full/ctool16/CreateReduction_inArgs_Arg.gif new file mode 100644 index 0000000000000000000000000000000000000000..7c7384ee85c9b7f4dd7c4bf3d098aa29450bcc5b GIT binary patch literal 223 zcmZ?wbhEHb6krfwIKsg2|NsB{_xIb|$1^Z6G&Nld4nAgSxkg8)?f?Jy`SJGu@7p&t zG#of^Ani;Vkm2Cquxq*+5N(~Lysk@rX_M5vO0k(G!vFrh2co~9&jZn)=Zk;eZ3dbK z0g69a7(px@5CO82fi*@!p)V!UPK{ya*~3#VY@O8K+&8Jj)A+MV&$aAHnqunxQpuUl zff}=ypI{g1)0%VYq?;9kj@o^17Yl))hS@I?J}f%f&a^PWP5wqp&Fx&R(=XHW8FFfx MQX8AHRTUYm0il{+*Z=?k literal 0 HcmV?d00001 diff --git a/plugins/fr.cea.nabla.edit/icons/full/obj16/FunctionInTypeDeclaration.gif b/plugins/fr.cea.nabla.edit/icons/full/obj16/FunctionInTypeDeclaration.gif new file mode 100644 index 0000000000000000000000000000000000000000..53500daf98e17bc98acd04b14eb7b16938ceb4dd GIT binary patch literal 129 zcmZ?wbhEHb6krfw*vtS14M4Jip`qcxfddT<4GjN*-2XuK|Nmgte-L}loH>^+RXR90 zDE?$&WMJTA&;jWLnZdxKXK>PU^?Adg)XXcr- zh64_YKUo+V7&sYpKsrHYFtF$uob+71*W&e;Zz}u`3thLHvffHb@LI6&tBu~rX=+!^ W%6nF7^6M^V>~uRaQAn7P!5RPwrZD0F literal 0 HcmV?d00001 diff --git a/plugins/fr.cea.nabla.edit/plugin.properties b/plugins/fr.cea.nabla.edit/plugin.properties index a4e07adea..72150a11e 100644 --- a/plugins/fr.cea.nabla.edit/plugin.properties +++ b/plugins/fr.cea.nabla.edit/plugin.properties @@ -308,3 +308,13 @@ _UI_ConnectivityCall_group_feature = Group _UI_TargetType_ArcaneSequential_literal = ArcaneSequential _UI_TargetType_ArcaneAccelerator_literal = ArcaneAccelerator _UI_TargetType_ArcaneThread_literal = ArcaneThread +_UI_Function_returnType_feature = Return Type +_UI_Function_inTypes_feature = In Types +_UI_FunctionReturnTypeDeclaration_type = Function Return Type Declaration +_UI_FunctionInTypeDeclaration_type = Function In Type Declaration +_UI_Function_returnTypeDeclaration_feature = Return Type Declaration +_UI_Function_intypesDeclaration_feature = Intypes Declaration +_UI_FunctionReturnTypeDeclaration_returnType_feature = Return Type +_UI_FunctionInTypeDeclaration_inTypes_feature = In Types +_UI_Reduction_inArgs_feature = In Args +_UI_FunctionInTypeDeclaration_inArgs_feature = In Args diff --git a/plugins/fr.cea.nabla.ui/examples/NabLabExamples/src/explicitheatequation/ExplicitHeatEquation.n b/plugins/fr.cea.nabla.ui/examples/NabLabExamples/src/explicitheatequation/ExplicitHeatEquation.n index 82033edcc..07752f39e 100644 --- a/plugins/fr.cea.nabla.ui/examples/NabLabExamples/src/explicitheatequation/ExplicitHeatEquation.n +++ b/plugins/fr.cea.nabla.ui/examples/NabLabExamples/src/explicitheatequation/ExplicitHeatEquation.n @@ -31,25 +31,25 @@ iterate n while (t^{n+1} < stopTime && n+1 < maxIterations); InitTime: t^{n=0} = 0.0; -InitXc: ∀c∈cells(), Xc{c} = 0.25 * sum{p∈nodesOfCell(c)}(X{p}); // Only valid on parallelograms +InitXc: forall c in cells(), Xc{c} = 0.25 * sum{p in nodesOfCell(c)}(X{p}); // Only valid on parallelograms -InitU: ∀c∈cells(), +InitU: forall c in cells(), if (norm(Xc{c} - vectOne) < 0.5) u^{n}{c} = u0; else u^{n}{c} = 0.0; // Initial circle in the center with value u0 -InitD: ∀c∈cells(), D{c} = 1.0; +InitD: forall c in cells(), D{c} = 1.0; -ComputeDeltaTn: delta_t = Min{c∈cells()}(V{c}/D{c}) * 0.24; -ComputeV: ∀c∈cells(), V{c} = 0.5 * sum{p∈nodesOfCell(c)}(det(X{p}, X{p+1})); -ComputeFaceLength: ∀f∈faces(), faceLength{f} = 0.5 * sum{p∈nodesOfFace(f)}(norm(X{p} - X{p+1})); -ComputeFaceConductivity: ∀f∈faces(), faceConductivity{f} = 2.0 * prod{c1∈cellsOfFace(f)}(D{c1}) / sum{c2∈cellsOfFace(f)}(D{c2}); +ComputeDeltaTn: delta_t = Min{c in cells()}(V{c}/D{c}) * 0.24; +ComputeV: forall c in cells(), V{c} = 0.5 * sum{p in nodesOfCell(c)}(det(X{p}, X{p+1})); +ComputeFaceLength: forall f in faces(), faceLength{f} = 0.5 * sum{p in nodesOfFace(f)}(norm(X{p} - X{p+1})); +ComputeFaceConductivity: forall f in faces(), faceConductivity{f} = 2.0 * prod{c1 in cellsOfFace(f)}(D{c1}) / sum{c2 in cellsOfFace(f)}(D{c2}); // Assembling of the diffusion matrix -ComputeAlphaCoeff: ∀c∈cells(), { +ComputeAlphaCoeff: forall c in cells(), { let real alpha_Diag = 0.0; - ∀d∈neighbourCells(c), ∀f∈commonFace(c,d), { + forall d in neighbourCells(c), forall f in commonFace(c,d), { let real alpha_ExtraDiag = delta_t / V{c} * (faceLength{f} * faceConductivity{f}) / norm(Xc{c} - Xc{d}); alpha{c, d} = alpha_ExtraDiag; alpha_Diag = alpha_Diag + alpha_ExtraDiag; @@ -57,5 +57,5 @@ ComputeAlphaCoeff: ∀c∈cells(), { alpha{c, c} = 1 - alpha_Diag; } -UpdateU: ∀c∈cells(), u^{n+1}{c} = alpha{c, c} * u^{n}{c} + sum{d∈neighbourCells(c)} (alpha{c, d} * u^{n}{d}); +UpdateU: forall c in cells(), u^{n+1}{c} = alpha{c, c} * u^{n}{c} + sum{d in neighbourCells(c)} (alpha{c, d} * u^{n}{d}); ComputeTn: t^{n+1} = t^{n} + delta_t; diff --git a/plugins/fr.cea.nabla.ui/examples/NabLabExamples/src/glace2d/Glace2d.n b/plugins/fr.cea.nabla.ui/examples/NabLabExamples/src/glace2d/Glace2d.n index 682ca4a51..f9f321eb4 100644 --- a/plugins/fr.cea.nabla.ui/examples/NabLabExamples/src/glace2d/Glace2d.n +++ b/plugins/fr.cea.nabla.ui/examples/NabLabExamples/src/glace2d/Glace2d.n @@ -13,24 +13,24 @@ with Math.*; with CartesianMesh2D.*; // Only for 2D vectors -def perp: real[2] → real[2], (a) → return [ a[1], -a[0] ]; +def real[2] perp(real[2] a) return [ a[1], -a[0] ]; -def trace: l | real[l,l] → real, (a) → { +def real trace(real[l,l] a) { let real result = 0.0; - ∀ ia ∈ [0;l[, result = result + a[ia, ia]; + forall ia in [0;l[, result = result + a[ia, ia]; return result; } -def tensProduct: l | real[l] × real[l] → real[l,l], (a, b) → { +def real[l,l] tensProduct(real[l] a, real[l] b) { real[l,l] result; - ∀ ia ∈ [0;l[, - ∀ ib ∈ [0;l[, + forall ia in [0;l[, + forall ib in [0;l[, result[ia,ib] = a[ia]*b[ib]; return result; } // Only for 2x2 matrices -def inverse: real[2,2] → real[2,2], (a) → { +def real[2,2] inverse(real[2,2] a) { let real alpha = 1.0 / det(a); return [[ a[1,1] * alpha, -a[0,1] * alpha ], [-a[1,0] * alpha, a[0,0] * alpha ]]; @@ -64,12 +64,12 @@ iterate n while (t^{n+1} < stopTime && n+1 < maxIterations); // * Initialization // ************************************************************* IniTime: t^{n=0} = 0.0; -IniCjrIc: ∀j∈cells(), ∀r∈nodesOfCell(j), +IniCjrIc: forall j in cells(), forall r in nodesOfCell(j), Cjr_ic{j,r} = 0.5 * perp(X^{n=0}{r+1} - X^{n=0}{r-1}); -Initialize: ∀j∈cells(), { +Initialize: forall j in cells(), { real rho_ic, p_ic; - let real[2] center = 0.25 * sum{r∈nodesOfCell(j)}(X^{n=0}{r}); + let real[2] center = 0.25 * sum{r in nodesOfCell(j)}(X^{n=0}{r}); if (center[0] < xInterface) { rho_ic = rho_IniZg; p_ic = pIniZg; @@ -77,7 +77,7 @@ Initialize: ∀j∈cells(), { rho_ic = rho_IniZd; p_ic = pIniZd; } - let real V_ic = 0.5 * sum{r∈nodesOfCell(j)}(dot(Cjr_ic{j,r}, X^{n=0}{r})); + let real V_ic = 0.5 * sum{r in nodesOfCell(j)}(dot(Cjr_ic{j,r}, X^{n=0}{r})); m{j} = rho_ic * V_ic; // m is a constant p{j} = p_ic; rho{j} = rho_ic; @@ -88,40 +88,40 @@ Initialize: ∀j∈cells(), { // ************************************************************* // * C{j,r} and dependent variables computation // ************************************************************* -ComputeCjr: ∀j∈cells(), ∀r∈nodesOfCell(j), C{j,r} = 0.5 * perp(X^{n}{r+1} - X^{n}{r-1}); -ComputeLjr: ∀j∈cells(), ∀r∈nodesOfCell(j), l{j,r} = norm(C{j,r}); -Computedeltatj: ∀j∈cells(), delta_tj{j} = 2.0 * V{j} / (c{j} * sum{r∈nodesOfCell(j)}(l{j,r})); +ComputeCjr: forall j in cells(), forall r in nodesOfCell(j), C{j,r} = 0.5 * perp(X^{n}{r+1} - X^{n}{r-1}); +ComputeLjr: forall j in cells(), forall r in nodesOfCell(j), l{j,r} = norm(C{j,r}); +Computedeltatj: forall j in cells(), delta_tj{j} = 2.0 * V{j} / (c{j} * sum{r in nodesOfCell(j)}(l{j,r})); // ************************************************************* // * Standard EOS rules: m, rho, c, p, e // ************************************************************* -ComputeDensity: ∀j∈cells(), rho{j} = m{j} / V{j}; -ComputeEOSp: ∀j∈cells(), p{j} = (gamma-1.0) * rho{j} * e{j}; -ComputeInternalEnergy: ∀j∈cells(), e{j} = E^{n}{j} - 0.5 * dot(uj^{n}{j}, uj^{n}{j}); -ComputeEOSc: ∀j∈cells(), c{j} = sqrt(gamma * p{j} / rho{j}); +ComputeDensity: forall j in cells(), rho{j} = m{j} / V{j}; +ComputeEOSp: forall j in cells(), p{j} = (gamma-1.0) * rho{j} * e{j}; +ComputeInternalEnergy: forall j in cells(), e{j} = E^{n}{j} - 0.5 * dot(uj^{n}{j}, uj^{n}{j}); +ComputeEOSc: forall j in cells(), c{j} = sqrt(gamma * p{j} / rho{j}); // ************************************************************* // * Cell-centered Godunov Scheme for Lagragian gas dynamics // ************************************************************* -ComputeAjr: ∀j∈cells(), ∀r∈nodesOfCell(j), Ajr{j,r} = ((rho{j} * c{j}) / l{j,r}) * tensProduct(C{j,r}, C{j,r}); -ComputeFjr: ∀j∈cells(), ∀r∈nodesOfCell(j), F{j,r} = p{j} * C{j,r} + matVectProduct(Ajr{j,r}, (uj^{n}{j}-ur{r})); -ComputeAr: ∀r∈nodes(), Ar{r} = sum{j∈cellsOfNode(r)}(Ajr{j,r}); -ComputeBr: ∀r∈nodes(), b{r} = sum{j∈cellsOfNode(r)}(p{j} * C{j,r} + matVectProduct(Ajr{j,r}, uj^{n}{j})); -ComputeMt: ∀r∈nodes("InnerNodes"), Mt{r} = Ar{r}; -ComputeBt: ∀r∈nodes("InnerNodes"), bt{r} = b{r}; +ComputeAjr: forall j in cells(), forall r in nodesOfCell(j), Ajr{j,r} = ((rho{j} * c{j}) / l{j,r}) * tensProduct(C{j,r}, C{j,r}); +ComputeFjr: forall j in cells(), forall r in nodesOfCell(j), F{j,r} = p{j} * C{j,r} + matVectProduct(Ajr{j,r}, (uj^{n}{j}-ur{r})); +ComputeAr: forall r in nodes(), Ar{r} = sum{j in cellsOfNode(r)}(Ajr{j,r}); +ComputeBr: forall r in nodes(), b{r} = sum{j in cellsOfNode(r)}(p{j} * C{j,r} + matVectProduct(Ajr{j,r}, uj^{n}{j})); +ComputeMt: forall r in nodes("InnerNodes"), Mt{r} = Ar{r}; +ComputeBt: forall r in nodes("InnerNodes"), bt{r} = b{r}; ComputeBoundaryConditions: { let real[2,2] I = [ [1.0, 0.0], [0.0, 1.0] ]; // Y boundary conditions (must be done before X) - ∀r∈nodes("TopNodes"), { + forall r in nodes("TopNodes"), { let real[2] N = [0.0, 1.0]; let real[2,2] NxN = tensProduct(N,N); let real[2,2] IcP = I - NxN; bt{r} = matVectProduct(IcP, b{r}); Mt{r} = IcP * (Ar{r} * IcP) + NxN*trace(Ar{r}); } - ∀r∈nodes("BottomNodes"), { + forall r in nodes("BottomNodes"), { let real[2] N = [0.0, -1.0]; let real[2,2] NxN = tensProduct(N,N); let real[2,2] IcP = I - NxN; @@ -130,24 +130,24 @@ ComputeBoundaryConditions: { } // X boundary conditions - ∀r∈nodes("LeftNodes"),{ + forall r in nodes("LeftNodes"),{ Mt{r} = I; bt{r} = [0.0, 0.0]; } - ∀r∈nodes("RightNodes"),{ + forall r in nodes("RightNodes"),{ Mt{r} = I; bt{r} = [0.0, 0.0]; } } -ComputeU: ∀r∈nodes(), ur{r} = matVectProduct(inverse(Mt{r}), bt{r}); -ComputeV: ∀j∈cells(), V{j} = 0.5 * sum{r∈nodesOfCell(j)}(dot(C{j,r}, X^{n}{r})); +ComputeU: forall r in nodes(), ur{r} = matVectProduct(inverse(Mt{r}), bt{r}); +ComputeV: forall j in cells(), V{j} = 0.5 * sum{r in nodesOfCell(j)}(dot(C{j,r}, X^{n}{r})); // ************************************************************* // * Loop iteration (n) // ************************************************************* -ComputeXn: ∀r∈nodes(), X^{n+1}{r} = X^{n}{r} + delta_t * ur{r}; -ComputeUn: ∀j∈cells(), uj^{n+1}{j} = uj^{n}{j} - (delta_t/m{j}) * sum{r∈nodesOfCell(j)}(F{j,r}); -ComputeEn: ∀j∈cells(), E^{n+1}{j} = E^{n}{j} - (delta_t / m{j}) * sum{r∈nodesOfCell(j)}(dot(F{j,r}, ur{r})); -ComputeDt: delta_t = min((delta_tCfl * Min{j∈cells()}(delta_tj{j})), (stopTime-t^{n})); +ComputeXn: forall r in nodes(), X^{n+1}{r} = X^{n}{r} + delta_t * ur{r}; +ComputeUn: forall j in cells(), uj^{n+1}{j} = uj^{n}{j} - (delta_t/m{j}) * sum{r in nodesOfCell(j)}(F{j,r}); +ComputeEn: forall j in cells(), E^{n+1}{j} = E^{n}{j} - (delta_t / m{j}) * sum{r in nodesOfCell(j)}(dot(F{j,r}, ur{r})); +ComputeDt: delta_t = min((delta_tCfl * Min{j in cells()}(delta_tj{j})), (stopTime-t^{n})); ComputeTn: t^{n+1} = t^{n} + delta_t; diff --git a/plugins/fr.cea.nabla.ui/examples/NabLabExamples/src/heatequation/HeatEquation.n b/plugins/fr.cea.nabla.ui/examples/NabLabExamples/src/heatequation/HeatEquation.n index 42bb3ba19..3afbe19c3 100644 --- a/plugins/fr.cea.nabla.ui/examples/NabLabExamples/src/heatequation/HeatEquation.n +++ b/plugins/fr.cea.nabla.ui/examples/NabLabExamples/src/heatequation/HeatEquation.n @@ -26,11 +26,11 @@ real u{cells}, V{cells}, f{cells}, outgoingFlux{cells}, surface{faces}; iterate n while (t^{n+1} < stopTime && n+1 < maxIterations); IniTime: t^{n=0} = 0.0; -IniF: ∀j∈cells(), f{j} = 0.0; -IniCenter: ∀j∈cells(), center{j} = 0.25 * sum{r∈nodesOfCell(j)}(X{r}); // only on parallelograms -IniUn: ∀j∈cells(), u^{n}{j} = cos(2 * PI * alpha * center{j}[0]); -ComputeV: ∀j∈cells(), V{j} = 0.5 * sum{r∈nodesOfCell(j)}(det(X{r}, X{r+1})); -ComputeSurface: ∀f∈faces(), surface{f} = 0.5 * sum{r∈nodesOfFace(f)}(norm(X{r}-X{r+1})); -ComputeOutgoingFlux: ∀j1∈cells(), outgoingFlux{j1} = delta_t/V{j1} * sum{j2∈neighbourCells(j1)}(sum{cf∈commonFace(j1,j2)}( (u^{n}{j2}-u^{n}{j1}) / norm(center{j2}-center{j1}) * surface{cf})); -ComputeUn: ∀j∈cells(), u^{n+1}{j} = f{j} * delta_t + u^{n}{j} + outgoingFlux{j}; +IniF: forall j in cells(), f{j} = 0.0; +IniCenter: forall j in cells(), center{j} = 0.25 * sum{r in nodesOfCell(j)}(X{r}); // only on parallelograms +IniUn: forall j in cells(), u^{n}{j} = cos(2 * PI * alpha * center{j}[0]); +ComputeV: forall j in cells(), V{j} = 0.5 * sum{r in nodesOfCell(j)}(det(X{r}, X{r+1})); +ComputeSurface: forall f in faces(), surface{f} = 0.5 * sum{r in nodesOfFace(f)}(norm(X{r}-X{r+1})); +ComputeOutgoingFlux: forall j1 in cells(), outgoingFlux{j1} = delta_t/V{j1} * sum{j2 in neighbourCells(j1)}(sum{cf in commonFace(j1,j2)}( (u^{n}{j2}-u^{n}{j1}) / norm(center{j2}-center{j1}) * surface{cf})); +ComputeUn: forall j in cells(), u^{n+1}{j} = f{j} * delta_t + u^{n}{j} + outgoingFlux{j}; ComputeTn: t^{n+1} = t^{n} + delta_t; diff --git a/plugins/fr.cea.nabla.ui/examples/NabLabExamples/src/implicitheatequation/ImplicitHeatEquation.n b/plugins/fr.cea.nabla.ui/examples/NabLabExamples/src/implicitheatequation/ImplicitHeatEquation.n index 174db9611..f40280600 100644 --- a/plugins/fr.cea.nabla.ui/examples/NabLabExamples/src/implicitheatequation/ImplicitHeatEquation.n +++ b/plugins/fr.cea.nabla.ui/examples/NabLabExamples/src/implicitheatequation/ImplicitHeatEquation.n @@ -32,25 +32,25 @@ iterate n while (t^{n+1} < stopTime && n+1 < maxIterations); InitTime: t^{n=0} = 0.0; -InitXc: ∀c∈cells(), Xc{c} = 0.25 * sum{p∈nodesOfCell(c)}(X{p}); // Only valid on parallelograms +InitXc: forall c in cells(), Xc{c} = 0.25 * sum{p in nodesOfCell(c)}(X{p}); // Only valid on parallelograms -InitU: ∀c∈cells(), +InitU: forall c in cells(), if (norm(Xc{c} - vectOne) < 0.5) u^{n}{c} = u0; else u^{n}{c} = 0.0; // Initial circle in the center with value u0 -InitD: ∀c∈cells(), D{c} = 1.0; +InitD: forall c in cells(), D{c} = 1.0; -ComputeDeltaTn: delta_t = Min{c∈cells()}(V{c}/D{c}) * 0.24; -ComputeV: ∀j∈cells(), V{j} = 0.5 * sum{p∈nodesOfCell(j)}(det(X{p}, X{p+1})); -ComputeFaceLength: ∀f∈faces(), faceLength{f} = 0.5 * sum{p∈nodesOfFace(f)}(norm(X{p} - X{p+1})); -ComputeFaceConductivity: ∀f∈faces(), faceConductivity{f} = 2.0 * prod{c1∈cellsOfFace(f)}(D{c1}) / sum{c2∈cellsOfFace(f)}(D{c2}); +ComputeDeltaTn: delta_t = Min{c in cells()}(V{c}/D{c}) * 0.24; +ComputeV: forall j in cells(), V{j} = 0.5 * sum{p in nodesOfCell(j)}(det(X{p}, X{p+1})); +ComputeFaceLength: forall f in faces(), faceLength{f} = 0.5 * sum{p in nodesOfFace(f)}(norm(X{p} - X{p+1})); +ComputeFaceConductivity: forall f in faces(), faceConductivity{f} = 2.0 * prod{c1 in cellsOfFace(f)}(D{c1}) / sum{c2 in cellsOfFace(f)}(D{c2}); // Assembling of the diffusion matrix -ComputeAlphaCoeff: ∀c∈cells(), { +ComputeAlphaCoeff: forall c in cells(), { let real alpha_Diag = 0.0; - ∀d∈neighbourCells(c), ∀f∈commonFace(c,d), { + forall d in neighbourCells(c), forall f in commonFace(c,d), { let real alpha_ExtraDiag = - delta_t / V{c} * (faceLength{f} * faceConductivity{f}) / norm(Xc{c} - Xc{d}); alpha{c, d} = alpha_ExtraDiag; alpha_Diag = alpha_Diag + alpha_ExtraDiag; diff --git a/plugins/fr.cea.nabla.ui/examples/NabLabExamples/src/iterativeheatequation/IterativeHeatEquation.n b/plugins/fr.cea.nabla.ui/examples/NabLabExamples/src/iterativeheatequation/IterativeHeatEquation.n index 58161fe6a..aeeb30560 100644 --- a/plugins/fr.cea.nabla.ui/examples/NabLabExamples/src/iterativeheatequation/IterativeHeatEquation.n +++ b/plugins/fr.cea.nabla.ui/examples/NabLabExamples/src/iterativeheatequation/IterativeHeatEquation.n @@ -12,7 +12,7 @@ module IterativeHeatEquation; with Math.*; with CartesianMesh2D.*; -def check: bool → bool, (a) → if (a) return true; else exit "Assertion failed"; +def bool check(bool a) if (a) return true; else exit "Assertion failed"; // Simulation options real stopTime; @@ -37,25 +37,25 @@ iterate n while (t^{n+1} < stopTime && n+1 < maxIterations), InitTime: t^{n=0} = 0.0; -InitXc: ∀c∈cells(), Xc{c} = 0.25 * sum{p∈nodesOfCell(c)}(X{p}); // Only valid on parallelograms +InitXc: forall c in cells(), Xc{c} = 0.25 * sum{p in nodesOfCell(c)}(X{p}); // Only valid on parallelograms -InitU: ∀c∈cells(), +InitU: forall c in cells(), if (norm(Xc{c} - vectOne) < 0.5) u^{n}{c} = u0; else u^{n}{c} = 0.0; // Initial circle in the center with value u0 -InitD: ∀c∈cells(), D{c} = 1.0; +InitD: forall c in cells(), D{c} = 1.0; -ComputeDeltaTn: delta_t = Min{c∈cells()}(V{c}/D{c}) * 0.1; -ComputeV: ∀j∈cells(), V{j} = 0.5 * sum{p∈nodesOfCell(j)}(det(X{p}, X{p+1})); -ComputeFaceLength: ∀f∈faces(), faceLength{f} = 0.5 * sum{p∈nodesOfFace(f)}(norm(X{p} - X{p+1})); -ComputeFaceConductivity: ∀f∈faces(), faceConductivity{f} = 2.0 * prod{c1∈cellsOfFace(f)}(D{c1}) / sum{c2∈cellsOfFace(f)}(D{c2}); +ComputeDeltaTn: delta_t = Min{c in cells()}(V{c}/D{c}) * 0.1; +ComputeV: forall j in cells(), V{j} = 0.5 * sum{p in nodesOfCell(j)}(det(X{p}, X{p+1})); +ComputeFaceLength: forall f in faces(), faceLength{f} = 0.5 * sum{p in nodesOfFace(f)}(norm(X{p} - X{p+1})); +ComputeFaceConductivity: forall f in faces(), faceConductivity{f} = 2.0 * prod{c1 in cellsOfFace(f)}(D{c1}) / sum{c2 in cellsOfFace(f)}(D{c2}); // Assembling of the diffusion matrix -ComputeAlphaCoeff: ∀c∈cells(), { +ComputeAlphaCoeff: forall c in cells(), { let real alpha_Diag = 0.0; - ∀d∈neighbourCells(c), ∀f∈commonFace(c,d), { + forall d in neighbourCells(c), forall f in commonFace(c,d), { let real alpha_ExtraDiag = delta_t / V{c} * (faceLength{f} * faceConductivity{f}) / norm(Xc{c} - Xc{d}); alpha{c, d} = alpha_ExtraDiag; alpha_Diag = alpha_Diag + alpha_ExtraDiag; @@ -63,6 +63,6 @@ ComputeAlphaCoeff: ∀c∈cells(), { alpha{c, c} = -alpha_Diag; } -UpdateU: ∀c∈cells(), u^{n+1, k+1}{c} = u^{n}{c} + alpha{c, c} * u^{n+1, k}{c} + sum{d∈neighbourCells(c)} (alpha{c, d} * u^{n+1, k}{d}); -ComputeResidual: residual = Max{j ∈ cells()}(abs(u^{n+1,k+1}{j} - u^{n+1,k}{j})); +UpdateU: forall c in cells(), u^{n+1, k+1}{c} = u^{n}{c} + alpha{c, c} * u^{n+1, k}{c} + sum{d in neighbourCells(c)} (alpha{c, d} * u^{n+1, k}{d}); +ComputeResidual: residual = Max{j in cells()}(abs(u^{n+1,k+1}{j} - u^{n+1,k}{j})); ComputeTn: t^{n+1} = t^{n} + delta_t; diff --git a/plugins/fr.cea.nabla.ui/src/fr/cea/nabla/ui/wizards/NewNablaProjectWizard.xtend b/plugins/fr.cea.nabla.ui/src/fr/cea/nabla/ui/wizards/NewNablaProjectWizard.xtend index 2f615c5ac..891bf07df 100644 --- a/plugins/fr.cea.nabla.ui/src/fr/cea/nabla/ui/wizards/NewNablaProjectWizard.xtend +++ b/plugins/fr.cea.nabla.ui/src/fr/cea/nabla/ui/wizards/NewNablaProjectWizard.xtend @@ -270,7 +270,7 @@ class NewNablaProjectWizard extends Wizard implements INewWizard ''' extension «extensionName»; - def myMatVectProduct: x, y | real[x,y] × real[y] → real[x]; + def myMatVectProduct: x, y | real[x,y] , real[y] : real[x]; ''' private def getManifestContent() diff --git a/plugins/fr.cea.nabla/model/generated/Nabla.ecore b/plugins/fr.cea.nabla/model/generated/Nabla.ecore index debfa634e..d97fba52c 100644 --- a/plugins/fr.cea.nabla/model/generated/Nabla.ecore +++ b/plugins/fr.cea.nabla/model/generated/Nabla.ecore @@ -41,11 +41,11 @@ + + - - @@ -176,31 +176,35 @@ upperBound="-1" eType="#//Connectivity"/> - + - + + - + - - + + + + diff --git a/plugins/fr.cea.nabla/model/generated/Nabla.genmodel b/plugins/fr.cea.nabla/model/generated/Nabla.genmodel index 2127431c2..a5539c769 100644 --- a/plugins/fr.cea.nabla/model/generated/Nabla.genmodel +++ b/plugins/fr.cea.nabla/model/generated/Nabla.genmodel @@ -42,10 +42,10 @@ - - + + @@ -149,22 +149,25 @@ - + - + + - + + + + - - - + + diff --git a/plugins/fr.cea.nabla/nablalib/Assert.n b/plugins/fr.cea.nabla/nablalib/Assert.n index e55505ba9..b0cb8873a 100644 --- a/plugins/fr.cea.nabla/nablalib/Assert.n +++ b/plugins/fr.cea.nabla/nablalib/Assert.n @@ -9,31 +9,31 @@ *******************************************************************************/ extension Assert; -def assertEquals: int × int → bool, (expected, actual) → +def bool assertEquals(int expected, int actual) { let bool ret = (expected == actual); if (!ret) exit "** Assertion failed"; return ret; } -def assertEquals: real × real → bool, (expected, actual) → +def bool assertEquals(real expected, real actual) { let bool ret = (expected == actual); if (!ret) exit "** Assertion failed"; return ret; } -def assertEquals: x | int[x] × int[x] → bool, (expected, actual) → +def bool assertEquals(int[x] expected, int[x] actual) { - ∀i∈[0;x[, + forall i in [0;x[, if (expected[i] != actual[i]) exit "** Assertion failed"; return true; } -def assertEquals: x | real[x] × real[x] → bool, (expected, actual) → +def bool assertEquals(real[x] expected, real[x] actual) { - ∀i∈[0;x[, + forall i in [0;x[, if (expected[i] != actual[i]) exit "** Assertion failed"; return true; diff --git a/plugins/fr.cea.nabla/nablalib/CartesianMesh2D.n b/plugins/fr.cea.nabla/nablalib/CartesianMesh2D.n index f5fca775b..796f84032 100644 --- a/plugins/fr.cea.nabla/nablalib/CartesianMesh2D.n +++ b/plugins/fr.cea.nabla/nablalib/CartesianMesh2D.n @@ -11,30 +11,30 @@ mesh extension CartesianMesh2D; itemtypes { node, cell, face } -connectivity nodes: → {node}; -connectivity cells: → {cell}; -connectivity faces: → {face}; +connectivity {node} nodes(); +connectivity {cell} cells(); +connectivity {face} faces(); -connectivity nodesOfCell: cell → {node}; -connectivity nodesOfFace: face → {node}; -connectivity firstNodeOfFace: face → node; -connectivity secondNodeOfFace: face → node; +connectivity {node} nodesOfCell(cell); +connectivity {node} nodesOfFace(face); +connectivity node firstNodeOfFace(face); +connectivity node secondNodeOfFace(face); -connectivity cellsOfNode: node → {cell}; -connectivity cellsOfFace: face → {cell}; -connectivity neighbourCells: cell → {cell}; -connectivity commonFace: cell × cell → face; -connectivity backCell: face → cell; -connectivity frontCell: face → cell; +connectivity {cell} cellsOfNode(node); +connectivity {cell} cellsOfFace(face); +connectivity {cell} neighbourCells(cell); +connectivity face commonFace(cell , cell); +connectivity cell backCell(face); +connectivity cell frontCell(face); -connectivity topCell: cell → cell; -connectivity bottomCell: cell → cell; -connectivity leftCell: cell → cell; -connectivity rightCell: cell → cell; +connectivity cell topCell(cell); +connectivity cell bottomCell(cell); +connectivity cell leftCell(cell); +connectivity cell rightCell(cell); -connectivity facesOfCell: cell → {face}; -connectivity topFaceOfCell: cell → face; -connectivity bottomFaceOfCell: cell → face; -connectivity leftFaceOfCell: cell → face; -connectivity rightFaceOfCell: cell → face; +connectivity {face} facesOfCell(cell); +connectivity face topFaceOfCell(cell); +connectivity face bottomFaceOfCell(cell); +connectivity face leftFaceOfCell(cell); +connectivity face rightFaceOfCell(cell); diff --git a/plugins/fr.cea.nabla/nablalib/LinearAlgebra.n b/plugins/fr.cea.nabla/nablalib/LinearAlgebra.n index 170016fd4..5530edc5e 100644 --- a/plugins/fr.cea.nabla/nablalib/LinearAlgebra.n +++ b/plugins/fr.cea.nabla/nablalib/LinearAlgebra.n @@ -13,25 +13,25 @@ linearalgebra extension LinearAlgebra; * Initial guess API is not provided for JAVA backend */ // Solves Ax=b -def solveLinearSystem: x | real[x, x] × real[x] → real[x]; +def real[x] solveLinearSystem(real[x, x] A, real[x] b); // Solves Ax=b, given x0 -def solveLinearSystem: x | real[x, x] × real[x] × real[x] → real[x]; +def real[x] solveLinearSystem(real[x, x] A, real[x] b, real[x] x0); // Solves C^-1(Ax)=C^-1 b -def solveLinearSystem: x | real[x, x] × real[x] × real[x, x] → real[x]; +def real[x] solveLinearSystem(real[x, x] A, real[x] b, real[x, x] C); // Solves Ax=b, given x0 with iterations threshold -def solveLinearSystem: x | real[x, x] × real[x] × real[x] × int → real[x]; +def real[x] solveLinearSystem(real[x, x] A, real[x] b, real[x] x0, int maxIterations); // Solves C^-1(Ax)=C^-1 b, given x0 -def solveLinearSystem: x | real[x, x] × real[x] × real[x, x] × real[x] → real[x]; +def real[x] solveLinearSystem(real[x, x] A, real[x] b, real[x, x] C, real[x] x0); // Solves Ax=b, given x0 with iterations and tolerance thresholds -def solveLinearSystem: x | real[x, x] × real[x] × real[x] × int × real → real[x]; +def real[x] solveLinearSystem(real[x, x] A, real[x] b, real[x] x0, int maxIterations , real tolerance); // Solves C^-1(Ax)=C^-1 b, given x0 with iterations threshold -def solveLinearSystem: x | real[x, x] × real[x] × real[x, x] × real[x] × int → real[x]; +def real[x] solveLinearSystem(real[x, x] A, real[x] b, real[x, x] C, real[x] x0, int maxIterations ); // Solves C^-1(Ax)=C^-1 b, given x0 with iterations and tolerance thresholds -def solveLinearSystem: x | real[x, x] × real[x] × real[x, x] × real[x] × int × real → real[x]; +def real[x] solveLinearSystem(real[x, x] A, real[x] b, real[x, x] C, real[x] x0, int maxIterations , real tolerance); diff --git a/plugins/fr.cea.nabla/nablalib/Math.n b/plugins/fr.cea.nabla/nablalib/Math.n index a07515d9a..d3cfad13a 100644 --- a/plugins/fr.cea.nabla/nablalib/Math.n +++ b/plugins/fr.cea.nabla/nablalib/Math.n @@ -10,61 +10,61 @@ extension Math; // ***** REDUCTIONS ***** -def sum, 0.0: real, (a, b) → return a + b; -def sum, 0.0: x | real[x], (a, b) → return a + b; -def sum, 0.0: x | real[x, x], (a, b) → return a + b; +red real sum(0.0) (a, b) : return a + b; +red real[x] sum(0.0) (a, b) : return a + b; +red real[x, x] sum(0.0) (a, b) : return a + b; -def prod, 1.0: real, (a, b) → return a * b; -def prod, 1.0: x | real[x], (a, b) → return a * b; -def prod, 1.0: x | real[x, x], (a, b) → return a * b; +red real prod(1.0) (a, b) : return a * b; +red real[x] prod(1.0) (a, b) : return a * b; +red real[x, x] prod(1.0) (a, b) : return a * b; -def Min, real.MaxValue: real, (a, b) → return min(a, b); -def Max, real.MinValue: real, (a, b) → return max(a, b); +red real Min(real.MaxValue) (a, b) : return min(a, b); +red real Max(real.MinValue) (a, b) : return max(a, b); // ***** FUNCTIONS ***** -def abs: real → real; -def min: real × real → real; -def max: real × real → real; +def real abs(real a); +def real min(real a, real b); +def real max(real a, real b); -def cos: real → real; -def sin: real → real; -def tan: real → real; -def acos: real → real; -def asin: real → real; -def atan: real → real; -def atan2: real × real → real; +def real cos(real a); +def real sin(real a); +def real tan(real a); +def real acos(real a); +def real asin(real a); +def real atan(real a); +def real atan2(real a, real b); -def exp: real → real; -def log: real → real; -def log10: real → real; -def erf: real → real; +def real exp(real a); +def real log(real a); +def real log10(real a); +def real erf(real a); -def pow: real × real → real; -def sqrt: real → real; +def real pow(real a, real b); +def real sqrt(real a); -def matVectProduct: x, y | real[x,y] × real[y] → real[x], (a, b) → +def real[x] matVectProduct(real[x,y] a, real[y] b) { real[x] result; - ∀ ix ∈ [0;x[, + forall ix in [0;x[, { real[y] tmp; - ∀ iy ∈ [0;y[, tmp[iy] = a[ix, iy]; + forall iy in [0;y[, tmp[iy] = a[ix, iy]; result[ix] = dot(tmp, b); } return result; } // scalar product -def dot: x | real[x] × real[x] → real, (a, b) → +def real dot(real[x] a, real[x] b) { let real result = 0.0; - ∀ i ∈ [0;x[, + forall i in [0;x[, result = result + a[i]*b[i]; return result; } // 2D cross products -def det: real[2] × real[2] → real, (a, b) → return (a[0]*b[1] - a[1]*b[0]); -def det: real[2,2] → real, (a) → return a[0,0] * a[1,1] - a[0,1] * a[1,0]; +def real det(real[2] a, real[2] b) return (a[0]*b[1] - a[1]*b[0]); +def real det(real[2,2] a) return a[0,0] * a[1,1] - a[0,1] * a[1,0]; -def norm: x | real[x] → real, (a) → return sqrt(dot(a,a)); +def real norm(real[x] a) return sqrt(dot(a,a)); \ No newline at end of file diff --git a/plugins/fr.cea.nabla/src/fr/cea/nabla/ArgOrVarExtensions.xtend b/plugins/fr.cea.nabla/src/fr/cea/nabla/ArgOrVarExtensions.xtend index 0a3dd4fea..099f8e1e2 100644 --- a/plugins/fr.cea.nabla/src/fr/cea/nabla/ArgOrVarExtensions.xtend +++ b/plugins/fr.cea.nabla/src/fr/cea/nabla/ArgOrVarExtensions.xtend @@ -45,7 +45,7 @@ class ArgOrVarExtensions Function: { val i = fOrR.inArgs.indexOf(it) - fOrR.typeDeclaration.inTypes.get(i) + fOrR.intypesDeclaration.get(i).inTypes } Reduction: fOrR.typeDeclaration.type diff --git a/plugins/fr.cea.nabla/src/fr/cea/nabla/LabelServices.xtend b/plugins/fr.cea.nabla/src/fr/cea/nabla/LabelServices.xtend index a4773d936..d3d77977b 100644 --- a/plugins/fr.cea.nabla/src/fr/cea/nabla/LabelServices.xtend +++ b/plugins/fr.cea.nabla/src/fr/cea/nabla/LabelServices.xtend @@ -1,145 +1,149 @@ -/******************************************************************************* - * Copyright (c) 2022 CEA - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - * Contributors: see AUTHORS file - *******************************************************************************/ -package fr.cea.nabla - -import fr.cea.nabla.ir.IrUtils -import fr.cea.nabla.nabla.Affectation -import fr.cea.nabla.nabla.And -import fr.cea.nabla.nabla.ArgOrVarRef -import fr.cea.nabla.nabla.BaseType -import fr.cea.nabla.nabla.BaseTypeConstant -import fr.cea.nabla.nabla.BoolConstant -import fr.cea.nabla.nabla.Cardinality -import fr.cea.nabla.nabla.Comparison -import fr.cea.nabla.nabla.ConnectivityCall -import fr.cea.nabla.nabla.ContractedIf -import fr.cea.nabla.nabla.CurrentTimeIteratorRef -import fr.cea.nabla.nabla.Div -import fr.cea.nabla.nabla.Equality -import fr.cea.nabla.nabla.Exit -import fr.cea.nabla.nabla.Expression -import fr.cea.nabla.nabla.Function -import fr.cea.nabla.nabla.FunctionCall -import fr.cea.nabla.nabla.FunctionTypeDeclaration -import fr.cea.nabla.nabla.If -import fr.cea.nabla.nabla.InitTimeIteratorRef -import fr.cea.nabla.nabla.InstructionBlock -import fr.cea.nabla.nabla.IntConstant -import fr.cea.nabla.nabla.Interval -import fr.cea.nabla.nabla.ItemSet -import fr.cea.nabla.nabla.ItemSetRef -import fr.cea.nabla.nabla.Job -import fr.cea.nabla.nabla.Loop -import fr.cea.nabla.nabla.MaxConstant -import fr.cea.nabla.nabla.MinConstant -import fr.cea.nabla.nabla.Minus -import fr.cea.nabla.nabla.Modulo -import fr.cea.nabla.nabla.Mul -import fr.cea.nabla.nabla.NextTimeIteratorRef -import fr.cea.nabla.nabla.Not -import fr.cea.nabla.nabla.Or -import fr.cea.nabla.nabla.Parenthesis -import fr.cea.nabla.nabla.Plus -import fr.cea.nabla.nabla.RealConstant -import fr.cea.nabla.nabla.Reduction -import fr.cea.nabla.nabla.ReductionCall -import fr.cea.nabla.nabla.ReductionTypeDeclaration -import fr.cea.nabla.nabla.Return -import fr.cea.nabla.nabla.SimpleVar -import fr.cea.nabla.nabla.SimpleVarDeclaration -import fr.cea.nabla.nabla.SpaceIterator -import fr.cea.nabla.nabla.SpaceIteratorRef -import fr.cea.nabla.nabla.UnaryMinus -import fr.cea.nabla.nabla.VarGroupDeclaration -import fr.cea.nabla.nabla.VectorConstant -import java.util.List - +/******************************************************************************* + * Copyright (c) 2022 CEA + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + * Contributors: see AUTHORS file + *******************************************************************************/ +package fr.cea.nabla + +import fr.cea.nabla.ir.IrUtils +import fr.cea.nabla.nabla.Affectation +import fr.cea.nabla.nabla.And +import fr.cea.nabla.nabla.ArgOrVarRef +import fr.cea.nabla.nabla.BaseType +import fr.cea.nabla.nabla.BaseTypeConstant +import fr.cea.nabla.nabla.BoolConstant +import fr.cea.nabla.nabla.Cardinality +import fr.cea.nabla.nabla.Comparison +import fr.cea.nabla.nabla.ConnectivityCall +import fr.cea.nabla.nabla.ContractedIf +import fr.cea.nabla.nabla.CurrentTimeIteratorRef +import fr.cea.nabla.nabla.Div +import fr.cea.nabla.nabla.Equality +import fr.cea.nabla.nabla.Exit +import fr.cea.nabla.nabla.Expression +import fr.cea.nabla.nabla.Function +import fr.cea.nabla.nabla.FunctionCall +import fr.cea.nabla.nabla.FunctionInTypeDeclaration +import fr.cea.nabla.nabla.FunctionReturnTypeDeclaration +import fr.cea.nabla.nabla.If +import fr.cea.nabla.nabla.InitTimeIteratorRef +import fr.cea.nabla.nabla.InstructionBlock +import fr.cea.nabla.nabla.IntConstant +import fr.cea.nabla.nabla.Interval +import fr.cea.nabla.nabla.ItemSet +import fr.cea.nabla.nabla.ItemSetRef +import fr.cea.nabla.nabla.Job +import fr.cea.nabla.nabla.Loop +import fr.cea.nabla.nabla.MaxConstant +import fr.cea.nabla.nabla.MinConstant +import fr.cea.nabla.nabla.Minus +import fr.cea.nabla.nabla.Modulo +import fr.cea.nabla.nabla.Mul +import fr.cea.nabla.nabla.NextTimeIteratorRef +import fr.cea.nabla.nabla.Not +import fr.cea.nabla.nabla.Or +import fr.cea.nabla.nabla.Parenthesis +import fr.cea.nabla.nabla.Plus +import fr.cea.nabla.nabla.RealConstant +import fr.cea.nabla.nabla.Reduction +import fr.cea.nabla.nabla.ReductionCall +import fr.cea.nabla.nabla.ReductionTypeDeclaration +import fr.cea.nabla.nabla.Return +import fr.cea.nabla.nabla.SimpleVar +import fr.cea.nabla.nabla.SimpleVarDeclaration +import fr.cea.nabla.nabla.SpaceIterator +import fr.cea.nabla.nabla.SpaceIteratorRef +import fr.cea.nabla.nabla.UnaryMinus +import fr.cea.nabla.nabla.VarGroupDeclaration +import fr.cea.nabla.nabla.VectorConstant +import java.util.List + class LabelServices { - /* JOBS & INSTRUCTIONS ***********************************/ - static def dispatch String getLabel(Job it) { name + ' : ' + instruction?.label } + /* JOBS & INSTRUCTIONS ***********************************/ + static def dispatch String getLabel(Job it) { name + ' : ' + instruction?.label } static def dispatch String getLabel(SimpleVarDeclaration it) { if (value === null) variable?.name else variable?.name + '=' + value.label } static def dispatch String getLabel(VarGroupDeclaration it) { type?.label + ' ' + variables?.map[x|x?.name].join(', ') } - static def dispatch String getLabel(InstructionBlock it) { '{ ... }' } - static def dispatch String getLabel(Loop it) { '\u2200 ' + iterationBlock?.label + ', ' + body?.label } + static def dispatch String getLabel(InstructionBlock it) { '{ ... }' } + static def dispatch String getLabel(Loop it) { 'forall ' + iterationBlock?.label + ', ' + body?.label } static def dispatch String getLabel(Affectation it) { left?.label + ' = ' + right?.label } static def dispatch String getLabel(If it) - { - var txt = 'if ' + condition?.label - if (^else !== null) txt += ' else ' + ^else.label - return txt - } - static def dispatch String getLabel(ItemSet it) { 'set ' + name + '=' + value?.label } - static def dispatch String getLabel(Return it) { 'return ' + expression?.label } - static def dispatch String getLabel(Exit it) { 'Exit "' + message + '"'} - - /* ITERATEURS ********************************************/ - static def dispatch String getLabel(SpaceIterator it) { name + '\u2208 ' + container?.label } - static def dispatch String getLabel(Interval it) { index?.name + '\u2208' + nbElems?.label } - static def dispatch String getLabel(ItemSetRef it) { target?.name } - static def dispatch String getLabel(ConnectivityCall it) - { - if (group === null) - if (args.empty) - connectivity?.name - else - connectivity?.name + '(' + args?.map[label].join(',') + ')' - else - group - } + { + var txt = 'if ' + condition?.label + if (^else !== null) txt += ' else ' + ^else.label + return txt + } + static def dispatch String getLabel(ItemSet it) { 'set ' + name + '=' + value?.label } + static def dispatch String getLabel(Return it) { 'return ' + expression?.label } + static def dispatch String getLabel(Exit it) { 'Exit "' + message + '"'} + + /* ITERATEURS ********************************************/ + static def dispatch String getLabel(SpaceIterator it) { name + 'in' + container?.label } + static def dispatch String getLabel(Interval it) { index?.name + 'in' + nbElems?.label } + static def dispatch String getLabel(ItemSetRef it) { target?.name } + static def dispatch String getLabel(ConnectivityCall it) + { + if (group === null) + if (args.empty) + connectivity?.name + else + connectivity?.name + '(' + args?.map[label].join(',') + ')' + else + group + } static def dispatch String getLabel(SpaceIteratorRef it) { if (inc > 0) target?.name + '+' + inc else if (dec > 0) target?.name + '-' + dec else target?.name } - - static def dispatch String getLabel(CurrentTimeIteratorRef it) { target?.name } - static def dispatch String getLabel(InitTimeIteratorRef it) { target?.name + '=' + value } - static def dispatch String getLabel(NextTimeIteratorRef it) { target?.name + '+' + value } - - /* FONCTIONS / REDUCTIONS ********************************/ - static def dispatch String getLabel(Function it) { 'def ' + name + ' : ' + getLabel(variables, typeDeclaration) } - static def dispatch String getLabel(Reduction it) { 'def ' + name + ', ' + seed?.label + ' : ' + getLabel(variables, typeDeclaration) } - - private static def String getLabel(List vars, FunctionTypeDeclaration td) - { - var ret = '' - if (vars !== null) - { - ret += vars.map[name].join(', ') - if (!vars.empty) ret += ' | ' - } - if (td !== null) - { - ret += td.inTypes?.map[label].join(' \u00D7 ') - ret += ' \u2192 ' + td.returnType?.label - } - return ret - } - - private static def String getLabel(List vars, ReductionTypeDeclaration td) - { - var ret = '' - if (vars !== null) - { - ret += vars.map[name].join(', ') - if (!vars.empty) ret += ' | ' - } - if (td !== null) - ret += td.type?.label - return ret - } - - /* EXPRESSIONS ******************************************/ - static def dispatch String getLabel(ContractedIf it) { condition?.label + ' ? ' + then?.label + ' : ' + ^else?.label } + + static def dispatch String getLabel(CurrentTimeIteratorRef it) { target?.name } + static def dispatch String getLabel(InitTimeIteratorRef it) { target?.name + '=' + value } + static def dispatch String getLabel(NextTimeIteratorRef it) { target?.name + '+' + value } + + /* FONCTIONS / REDUCTIONS ********************************/ + static def dispatch String getLabel(Function it) { 'def ' + name + ' : ' + getLabel(variables, it.intypesDeclaration, it.returnTypeDeclaration) } + static def dispatch String getLabel(Reduction it) { 'red ' + name + ', ' + seed?.label + ' : ' + getLabel(variables, typeDeclaration) } + + private static def String getLabel(List vars, List itd, FunctionReturnTypeDeclaration rtd) + { + var ret = '' + if (vars !== null) + { + ret += vars.map[name].join(', ') + if (!vars.empty) ret += ' | ' + } + if (itd !== null && itd.size > 0) + { + ret += itd.map[inTypes.label].join(' \u00D7 ') + } + if (rtd !== null) + { + ret += ' \u2192 ' + rtd.returnType?.label + } + return ret + } + + private static def String getLabel(List vars, ReductionTypeDeclaration td) + { + var ret = '' + if (vars !== null) + { + ret += vars.map[name].join(', ') + if (!vars.empty) ret += ' | ' + } + if (td !== null) + ret += td.type?.label + return ret + } + + /* EXPRESSIONS ******************************************/ + static def dispatch String getLabel(ContractedIf it) { condition?.label + ' ? ' + then?.label + ' : ' + ^else?.label } static def dispatch String getLabel(Or it) { getLabel(left, op, right) } static def dispatch String getLabel(And it) { getLabel(left, op, right) } static def dispatch String getLabel(Equality it) { getLabel(left, op, right) } @@ -147,8 +151,8 @@ class LabelServices static def dispatch String getLabel(Plus it) { getLabel(left, op, right) } static def dispatch String getLabel(Minus it) { getLabel(left, op, right) } static def dispatch String getLabel(Mul it) { getLabel(left, op, right) } - static def dispatch String getLabel(Div it) { getLabel(left, op, right) } - static def dispatch String getLabel(Modulo it) { getLabel(left, op, right) } + static def dispatch String getLabel(Div it) { getLabel(left, op, right) } + static def dispatch String getLabel(Modulo it) { getLabel(left, op, right) } static def dispatch String getLabel(Parenthesis it) { '(' + expression?.label + ')' } static def dispatch String getLabel(UnaryMinus it) { '-' + expression?.label } static def dispatch String getLabel(Not it) { '!' + expression?.label } @@ -159,31 +163,31 @@ class LabelServices static def dispatch String getLabel(MaxConstant it) { '-\u221E' } static def dispatch String getLabel(FunctionCall it) { function.name + '(' + args.map[label].join(',') + ')' } static def dispatch String getLabel(ReductionCall it) { reduction.name + '{' + iterationBlock?.label + '}(' + arg?.label + ')' } - static def dispatch String getLabel(BaseTypeConstant it) { type?.label + '(' + value?.label + ')' } - static def dispatch String getLabel(VectorConstant it) { '[' + values.map[label].join(',') + ']' } - static def dispatch String getLabel(Cardinality it) { 'card(' + container?.label + ')' } - static def dispatch String getLabel(ArgOrVarRef it) - { - var label = target.name - if (!timeIterators.empty) label += '^{' + timeIterators.map[x | x?.label].join(', ') + '}' - if (!spaceIterators.empty) label += '{' + spaceIterators.map[x | x?.label].join(',') + '}' - if (!indices.empty) label += '[' + indices.map[x | x?.label].join(',') + ']' - return label - } - - private static def String getLabel(Expression left, String op, Expression right) - { - left?.label + ' ' + op + ' ' + right?.label + static def dispatch String getLabel(BaseTypeConstant it) { type?.label + '(' + value?.label + ')' } + static def dispatch String getLabel(VectorConstant it) { '[' + values.map[label].join(',') + ']' } + static def dispatch String getLabel(Cardinality it) { 'card(' + container?.label + ')' } + static def dispatch String getLabel(ArgOrVarRef it) + { + var label = target.name + if (!timeIterators.empty) label += '^{' + timeIterators.map[x | x?.label].join(', ') + '}' + if (!spaceIterators.empty) label += '{' + spaceIterators.map[x | x?.label].join(',') + '}' + if (!indices.empty) label += '[' + indices.map[x | x?.label].join(',') + ']' + return label + } + + private static def String getLabel(Expression left, String op, Expression right) + { + left?.label + ' ' + op + ' ' + right?.label + } + + /* TYPES *************************************************/ + static def dispatch String getLabel(BaseType it) + { + if (sizes.empty) + primitive.literal + else if (sizes.forall[x | x instanceof IntConstant]) + primitive.literal + sizes.map[x | IrUtils.getUtfExponent((x as IntConstant).value)].join('\u02E3') + else + primitive.literal + '[' + sizes.map[label].join(',') + ']' } - - /* TYPES *************************************************/ - static def dispatch String getLabel(BaseType it) - { - if (sizes.empty) - primitive.literal - else if (sizes.forall[x | x instanceof IntConstant]) - primitive.literal + sizes.map[x | IrUtils.getUtfExponent((x as IntConstant).value)].join('\u02E3') - else - primitive.literal + '[' + sizes.map[label].join(',') + ']' - } } \ No newline at end of file diff --git a/plugins/fr.cea.nabla/src/fr/cea/nabla/LatexLabelServices.xtend b/plugins/fr.cea.nabla/src/fr/cea/nabla/LatexLabelServices.xtend index 4989ddca4..13d50b545 100644 --- a/plugins/fr.cea.nabla/src/fr/cea/nabla/LatexLabelServices.xtend +++ b/plugins/fr.cea.nabla/src/fr/cea/nabla/LatexLabelServices.xtend @@ -26,7 +26,8 @@ import fr.cea.nabla.nabla.Exit import fr.cea.nabla.nabla.Expression import fr.cea.nabla.nabla.Function import fr.cea.nabla.nabla.FunctionCall -import fr.cea.nabla.nabla.FunctionTypeDeclaration +import fr.cea.nabla.nabla.FunctionInTypeDeclaration +import fr.cea.nabla.nabla.FunctionReturnTypeDeclaration import fr.cea.nabla.nabla.If import fr.cea.nabla.nabla.InitTimeIteratorRef import fr.cea.nabla.nabla.Instruction @@ -112,8 +113,8 @@ class LatexLabelServices static def dispatch String getLatex(NextTimeIteratorRef it) { target?.name.transformString + '+' + value } /* FONCTIONS / REDUCTIONS ********************************/ - static def dispatch String getLatex(Function it) { 'def~ ' + name.transformString + '~:~' + getLatex(variables, typeDeclaration) } - static def dispatch String getLatex(Reduction it) { 'def~ ' + name.transformString + ',~' + seed?.latex + '~:~' + getLatex(variables, typeDeclaration) } + static def dispatch String getLatex(Function it) { 'def~ ' + name.transformString + '~:~' + getLatex(variables, it.intypesDeclaration, it.returnTypeDeclaration) } + static def dispatch String getLatex(Reduction it) { 'red~ ' + name.transformString + ',~' + seed?.latex + '~:~' + getLatex(variables, typeDeclaration) } private static def String getLatex(List vars, FunctionTypeDeclaration td) { @@ -123,10 +124,13 @@ class LatexLabelServices ret += vars.map[name.transformString].join(', ') if (!vars.empty) ret += '~|~' } - if (td !== null) + if (itd !== null && itd.size > 0) + { + ret += itd.map[inTypes.latex].join(' \\times ') + } + if (rtd !== null) { - ret += td.inTypes?.map[latex].join(' \\times ') - ret += ' \\rightarrow ' + td.returnType?.latex + ret += ' \\rightarrow ' + rtd.returnType?.latex } return ret } diff --git a/plugins/fr.cea.nabla/src/fr/cea/nabla/LinearAlgebraUtils.xtend b/plugins/fr.cea.nabla/src/fr/cea/nabla/LinearAlgebraUtils.xtend index 374839f0d..1a5d369b5 100644 --- a/plugins/fr.cea.nabla/src/fr/cea/nabla/LinearAlgebraUtils.xtend +++ b/plugins/fr.cea.nabla/src/fr/cea/nabla/LinearAlgebraUtils.xtend @@ -18,7 +18,8 @@ import fr.cea.nabla.nabla.ConnectivityVar import fr.cea.nabla.nabla.DefaultExtension import fr.cea.nabla.nabla.Function import fr.cea.nabla.nabla.FunctionCall -import fr.cea.nabla.nabla.FunctionTypeDeclaration +import fr.cea.nabla.nabla.FunctionInTypeDeclaration +import fr.cea.nabla.nabla.FunctionReturnTypeDeclaration import fr.cea.nabla.nabla.NablaRoot import fr.cea.nabla.nabla.PrimitiveType import fr.cea.nabla.nabla.SimpleVar @@ -56,7 +57,8 @@ class LinearAlgebraUtils } Arg case o.linearAlgebraEligible: return o.eContainer.linearAlgebraExtension BaseType case o.linearAlgebraEligible: return o.eContainer.linearAlgebraExtension - FunctionTypeDeclaration: return o.eContainer.linearAlgebraExtension + FunctionInTypeDeclaration: return o.eContainer.linearAlgebraExtension + FunctionReturnTypeDeclaration: return o.eContainer.linearAlgebraExtension default: return null } } diff --git a/plugins/fr.cea.nabla/src/fr/cea/nabla/Nabla.xtext b/plugins/fr.cea.nabla/src/fr/cea/nabla/Nabla.xtext index d9589ed02..4b5a72ad5 100644 --- a/plugins/fr.cea.nabla/src/fr/cea/nabla/Nabla.xtext +++ b/plugins/fr.cea.nabla/src/fr/cea/nabla/Nabla.xtext @@ -45,7 +45,7 @@ Import: 'with' importedNamespace=QualifiedNameWithWildcard ';'; /* ITEMS & CONNECTIVITES *********************************/ ItemType: name=ID; -Connectivity: 'connectivity' name=ID ':' (inTypes+=[ItemType|QualifiedName] ('\u00D7' inTypes+=[ItemType|QualifiedName])*)? '\u2192' ((multiple?='{' returnType=[ItemType|QualifiedName] '}') | returnType=[ItemType|QualifiedName]) ';'; +Connectivity: 'connectivity' ((multiple?='{' returnType=[ItemType|QualifiedName] '}') | returnType=[ItemType|QualifiedName]) name=ID '(' (inTypes+=[ItemType|QualifiedName] (',' inTypes+=[ItemType|QualifiedName])*)? ')' ';'; /* JOBS & INSTRUCTIONS ***********************************/ Job: name=ID ':' instruction=Instruction; @@ -56,7 +56,7 @@ Instruction: VarDeclaration | InstructionBlock | Loop | Affectation | If | ItemS SimpleVarDeclaration: 'let' type=BaseType variable=SimpleVar '=' value=Expression ';'; VarGroupDeclaration: type=BaseType variables+=Var (',' variables+=Var)* ';'; InstructionBlock: '{' instructions+=Instruction+ '}'; -Loop: '\u2200' iterationBlock=IterationBlock ',' body=Instruction; +Loop: 'forall' iterationBlock=IterationBlock ',' body=Instruction; Affectation: left=ArgOrVarRef '=' right=Expression ';'; If: 'if' '(' condition=Expression ')' then=Instruction (=>'else' else=Instruction)?; ItemSet: 'set' name=ID '=' value=ConnectivityCall ';'; @@ -69,8 +69,8 @@ Exit: 'exit' message=STRING ';'; IterationBlock: SpaceIterator | Interval; Container: ItemSetRef | ConnectivityCall; ItemSetRef: target=[ItemSet]; -SpaceIterator: name=ID (',' counter=SimpleVar)? '\u2208' container=Container; -Interval: index=SimpleVar '\u2208' '[' from=INT ';' nbElems=Expression '['; // from forced to 0 for the moment +SpaceIterator: name=ID (',' counter=SimpleVar)? 'in' container=Container; +Interval: index=SimpleVar 'in' '[' from=INT ';' nbElems=Expression '['; // from forced to 0 for the moment ConnectivityCall: connectivity=[Connectivity|QualifiedName] '('(group=STRING | args+=SpaceIteratorRef (',' args+=SpaceIteratorRef)* )?')'; SpaceIteratorRef: target=[SpaceIterator] (('+' inc=INT) | ('-' dec=INT))?; @@ -93,9 +93,10 @@ ConnectivityVar: name=ID '{' supports+=[Connectivity|QualifiedName] (',' support /* FONCTIONS / REDUCTIONS ********************************/ FunctionOrReduction: Function | Reduction; -Function: 'def' name=ID ':' (variables+=SimpleVar (',' variables+=SimpleVar)* '|')? typeDeclaration=FunctionTypeDeclaration ((',' '(' (inArgs+=Arg (',' inArgs+=Arg)*)? ')' '\u2192' body=Instruction) | external?=';'); -Reduction: 'def' name=ID ',' seed=Expression ':' (variables+=SimpleVar (',' variables+=SimpleVar)* '|')? typeDeclaration=ReductionTypeDeclaration ',' '(' inArgs+=Arg ',' inArgs+=Arg ')' '\u2192' body=Instruction; -FunctionTypeDeclaration: (inTypes+=BaseType ('\u00D7' inTypes+=BaseType)*)? '\u2192' returnType=BaseType; +Function: 'def' ('<'variables+=SimpleVar (',' variables+=SimpleVar)* '>')? returnTypeDeclaration=FunctionReturnTypeDeclaration name=ID '('(intypesDeclaration+=FunctionInTypeDeclaration inArgs+=Arg (',' intypesDeclaration+=FunctionInTypeDeclaration inArgs+=Arg)*)?')' (body=Instruction | external?=';'); +Reduction: 'red' ('<'variables+=SimpleVar (',' variables+=SimpleVar)* '>')? typeDeclaration=ReductionTypeDeclaration name=ID '(' seed=Expression ')' ('(' inArgs+=Arg (',' inArgs+=Arg)* ')')? ':' body=Instruction; +FunctionReturnTypeDeclaration: returnType=BaseType; +FunctionInTypeDeclaration: inTypes=BaseType; ReductionTypeDeclaration: type=BaseType; Arg: name=ID; diff --git a/plugins/fr.cea.nabla/src/fr/cea/nabla/generator/ir/IrFunctionFactory.xtend b/plugins/fr.cea.nabla/src/fr/cea/nabla/generator/ir/IrFunctionFactory.xtend index 5d5e8afe3..4cbeb5cfd 100644 --- a/plugins/fr.cea.nabla/src/fr/cea/nabla/generator/ir/IrFunctionFactory.xtend +++ b/plugins/fr.cea.nabla/src/fr/cea/nabla/generator/ir/IrFunctionFactory.xtend @@ -1,120 +1,121 @@ -/******************************************************************************* - * Copyright (c) 2022 CEA - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - * Contributors: see AUTHORS file - *******************************************************************************/ -package fr.cea.nabla.generator.ir - -import com.google.inject.Inject -import com.google.inject.Singleton -import fr.cea.nabla.BaseTypeSizeEvaluator -import fr.cea.nabla.ConstExprServices -import fr.cea.nabla.LinearAlgebraUtils -import fr.cea.nabla.ir.ir.IrFactory -import fr.cea.nabla.nabla.DefaultExtension -import fr.cea.nabla.nabla.Function -import fr.cea.nabla.nabla.NablaModule -import fr.cea.nabla.nabla.Reduction -import org.eclipse.xtext.EcoreUtil2 - +/******************************************************************************* + * Copyright (c) 2022 CEA + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + * Contributors: see AUTHORS file + *******************************************************************************/ +package fr.cea.nabla.generator.ir + +import com.google.inject.Inject +import com.google.inject.Singleton +import fr.cea.nabla.BaseTypeSizeEvaluator +import fr.cea.nabla.ConstExprServices +import fr.cea.nabla.LinearAlgebraUtils +import fr.cea.nabla.ir.ir.IrFactory +import fr.cea.nabla.nabla.DefaultExtension +import fr.cea.nabla.nabla.Function +import fr.cea.nabla.nabla.FunctionReturnTypeDeclaration +import fr.cea.nabla.nabla.NablaModule +import fr.cea.nabla.nabla.Reduction +import org.eclipse.xtext.EcoreUtil2 + @Singleton class IrFunctionFactory { @Inject extension NabLabFileAnnotationFactory - @Inject extension IrBasicFactory - @Inject extension IrArgOrVarFactory - @Inject extension IrInstructionFactory - @Inject extension IrExpressionFactory - @Inject extension LinearAlgebraUtils - @Inject extension BaseTypeSizeEvaluator - @Inject extension IrExtensionProviderFactory - @Inject ConstExprServices constExprServices - - def toIrFunction(Function f) - { - if (f.external) f.toIrExternFunction - else f.toIrInternFunction - } + @Inject extension IrBasicFactory + @Inject extension IrArgOrVarFactory + @Inject extension IrInstructionFactory + @Inject extension IrExpressionFactory + @Inject extension LinearAlgebraUtils + @Inject extension BaseTypeSizeEvaluator + @Inject extension IrExtensionProviderFactory + @Inject ConstExprServices constExprServices + + def toIrFunction(Function f) + { + if (f.external) f.toIrExternFunction + else f.toIrInternFunction + } def create IrFactory::eINSTANCE.createInternFunction toIrFunction(Reduction f) - { + { val t = f.typeDeclaration.type - annotations += f.toNabLabFileAnnotation - // build a unique name with name and type - name = f.name.toFirstLower + t.primitive.getName().charAt(0) + t.sizes.size - f.variables.forEach[x | variables += x.toIrVariable] - f.inArgs.forEach[x | inArgs += toIrArg(x)] - returnType = t.toIrBaseType - body = f.body.toIrInstruction - constExpr = false + annotations += f.toNabLabFileAnnotation + // build a unique name with name and type + name = f.name.toFirstLower + t.primitive.getName().charAt(0) + t.sizes.size + f.variables.forEach[x | variables += x.toIrVariable] + f.inArgs.forEach[x | inArgs += toIrArg(x)] + returnType = t.toIrBaseType + body = f.body.toIrInstruction + constExpr = false indexInName = 0 - } - - def create IrFactory::eINSTANCE.createInternFunction toIrInternFunction(Function f) - { - annotations += f.toNabLabFileAnnotation - name = f.name - f.variables.forEach[x | variables += x.toIrVariable] - // f is internal, it has a inArgs and a body - f.inArgs.forEach[x | inArgs += toIrArg(x)] - body = f.body.toIrInstruction - returnType = f.toIrReturnType - constExpr = constExprServices.isConstExpr(f) - indexInName = f.indexInName - } - - def create IrFactory::eINSTANCE.createExternFunction toIrExternFunction(Function f) - { - annotations += f.toNabLabFileAnnotation - name = f.name - val ext = EcoreUtil2.getContainerOfType(f, DefaultExtension) - provider = ext.toIrDefaultExtensionProvider - f.variables.forEach[x | variables += x.toIrVariable] - // f is external. No inArgs only inArgTypes - for (i : 0.. - [ - provider = la.toIrDefaultExtensionProvider - for (s : f.typeDeclaration.returnType.sizes) - { - sizes += s.toIrExpression - intSizes += getIntSizeFor(s) - } - isStatic = intSizes.forall[x | x != -1] - ] - } - } - - /** - * The indexInName attribute is used by generator for target not supporting function overloading. - * For this kind of targets, functions with an index != 1 have their name suffixed with the indexInName. - */ - private def getIndexInName(Function f) - { - val c = f.eContainer - switch c - { - case null: 0 - DefaultExtension: c.functions.filter[x | x.name == f.name].toList.indexOf(f) - NablaModule: c.functions.filter[x | x.name == f.name].toList.indexOf(f) - } - } + } + + def create IrFactory::eINSTANCE.createInternFunction toIrInternFunction(Function f) + { + annotations += f.toNabLabFileAnnotation + name = f.name + f.variables.forEach[x | variables += x.toIrVariable] + // f is internal, it has a inArgs and a body + f.inArgs.forEach[x | inArgs += toIrArg(x)] + body = f.body.toIrInstruction + returnType = f.returnTypeDeclaration.toIrReturnType + constExpr = constExprServices.isConstExpr(f) + indexInName = f.indexInName + } + + def create IrFactory::eINSTANCE.createExternFunction toIrExternFunction(Function f) + { + annotations += f.toNabLabFileAnnotation + name = f.name + val ext = EcoreUtil2.getContainerOfType(f, DefaultExtension) + provider = ext.toIrDefaultExtensionProvider + f.variables.forEach[x | variables += x.toIrVariable] + // f is external. No inArgs only inArgTypes + for (i : 0.. + [ + provider = la.toIrDefaultExtensionProvider + for (s : rtd.returnType.sizes) + { + sizes += s.toIrExpression + intSizes += getIntSizeFor(s) + } + isStatic = intSizes.forall[x | x != -1] + ] + } + } + + /** + * The indexInName attribute is used by generator for target not supporting function overloading. + * For this kind of targets, functions with an index != 1 have their name suffixed with the indexInName. + */ + private def getIndexInName(Function f) + { + val c = f.eContainer + switch c + { + case null: 0 + DefaultExtension: c.functions.filter[x | x.name == f.name].toList.indexOf(f) + NablaModule: c.functions.filter[x | x.name == f.name].toList.indexOf(f) + } + } } \ No newline at end of file diff --git a/plugins/fr.cea.nabla/src/fr/cea/nabla/generator/ir/IrItemIndexDefinitionFactory.xtend b/plugins/fr.cea.nabla/src/fr/cea/nabla/generator/ir/IrItemIndexDefinitionFactory.xtend index cd5db7c9c..51d9fe5eb 100644 --- a/plugins/fr.cea.nabla/src/fr/cea/nabla/generator/ir/IrItemIndexDefinitionFactory.xtend +++ b/plugins/fr.cea.nabla/src/fr/cea/nabla/generator/ir/IrItemIndexDefinitionFactory.xtend @@ -42,15 +42,15 @@ class IrItemIndexDefinitionFactory * Return the list of needed ItemIndexDefinition instructions for 'item'. * * An index must be declare when an ItemRef instance references 'item', - * - directly, for instance rNodes in ∀r∈nodes(), X{nodes}. - * - by its arguments, for instance : ∀r∈nodes(), ∀j∈cellsOfNode(r), Cjr{j,r} + * - directly, for instance rNodes in forall r in nodes(), X{nodes}. + * - by its arguments, for instance : forall r in nodes(), forall j in cellsOfNode(r), Cjr{j,r} * rNodesOfCellJ can not be created after r iterator declaration because * its value depends of j which is not yet defined. Consequently, rNodesOfCellJ * has to be defined when j is declared because the arguments needed to get * its value depends on j, i.e. rNodesOfCellJ = mesh.getNodesOfCell(jId). * * The indexExists lambda is used when createIndexDefinitions is called from iterator. - * For instance, in ∀r∈nodes(), X{nodes}, rNodes index is needed because + * For instance, in forall r in nodes(), X{nodes}, rNodes index is needed because * it is referenced by X but rNodes is automatically created by r iterator. * indexExists will then return true to prevent from creating the index two times. */ diff --git a/plugins/fr.cea.nabla/src/fr/cea/nabla/generator/ir/IrItemIndexFactory.xtend b/plugins/fr.cea.nabla/src/fr/cea/nabla/generator/ir/IrItemIndexFactory.xtend index b79b89d0d..7c8da183c 100644 --- a/plugins/fr.cea.nabla/src/fr/cea/nabla/generator/ir/IrItemIndexFactory.xtend +++ b/plugins/fr.cea.nabla/src/fr/cea/nabla/generator/ir/IrItemIndexFactory.xtend @@ -46,9 +46,9 @@ class IrItemIndexFactory /** * The 3 arguments of this method compose the primary key of the index. * Dependant items are needed. In the following example: - * computeGradients: ∀c∈cells(), { - * gradpi{c} = sum{p∈nodesOfCell(c)}(Fi{p,c}); - * gradpe{c} = sum{p∈nodesOfCell(c)}(Fe{p,c}); + * computeGradients: forall c in cells(), { + * gradpi{c} = sum{p in nodesOfCell(c)}(Fi{p,c}); + * gradpe{c} = sum{p in nodesOfCell(c)}(Fe{p,c}); * } * If Fi and Fe are defined {nodes, cellsOfNode}, the two reductions * need an index cCellsOfNodeP on the same item c. But it is not the diff --git a/plugins/fr.cea.nabla/src/fr/cea/nabla/hover/HoverHelper.xtend b/plugins/fr.cea.nabla/src/fr/cea/nabla/hover/HoverHelper.xtend index 5ffb6d3f9..897bff889 100644 --- a/plugins/fr.cea.nabla/src/fr/cea/nabla/hover/HoverHelper.xtend +++ b/plugins/fr.cea.nabla/src/fr/cea/nabla/hover/HoverHelper.xtend @@ -59,7 +59,7 @@ class HoverHelper { Expression: LabelServices.getLabel(o) ArgOrVar: o.name - Function: o.name + '(' + o.typeDeclaration.inTypes.map[typeText].join(', ') + ')' + Function: o.name + '(' + o.intypesDeclaration.map[inTypes.typeText].join(', ') + ')' } } @@ -69,7 +69,7 @@ class HoverHelper { Expression: o.typeFor?.label ArgOrVar: o.typeFor?.label - Function: o.typeDeclaration?.returnType?.typeFor?.label + Function: o.returnTypeDeclaration.returnType?.typeFor?.label BaseType: o.typeFor?.label } } diff --git a/plugins/fr.cea.nabla/src/fr/cea/nabla/overloading/DeclarationBuilder.xtend b/plugins/fr.cea.nabla/src/fr/cea/nabla/overloading/DeclarationBuilder.xtend index 884f20acb..870b9ba01 100644 --- a/plugins/fr.cea.nabla/src/fr/cea/nabla/overloading/DeclarationBuilder.xtend +++ b/plugins/fr.cea.nabla/src/fr/cea/nabla/overloading/DeclarationBuilder.xtend @@ -56,16 +56,16 @@ class DeclarationBuilder def FunctionDeclaration tryToBuildDeclaration(Function f, Iterable callerInTypes) { - for (i : 0.. - for (inType : inTypes) + for (inType : it.intypesDeclaration.map[inTypes]) for (dim : EcoreUtil2.getAllContentsOfType(inType, ArgOrVarRef)) if (dim.target !== null && !dim.target.eIsProxy && dim.target instanceof SimpleVar) inTypeVars += dim.target as SimpleVar val returnTypeVars = new HashSet - for (dim : EcoreUtil2.getAllContentsOfType(returnType, ArgOrVarRef)) + for (dim : EcoreUtil2.getAllContentsOfType(rtd.returnType, ArgOrVarRef)) if (dim.target !== null && !dim.target.eIsProxy && dim.target instanceof SimpleVar) returnTypeVars += dim.target as SimpleVar val x = returnTypeVars.findFirst[x | !inTypeVars.contains(x)] if (x !== null) - error(getFunctionReturnTypeVarMsg(x.name), NablaPackage.Literals::FUNCTION_TYPE_DECLARATION__RETURN_TYPE, FUNCTION_RETURN_TYPE_VAR) + error(getFunctionReturnTypeDeclarationVarMsg(x.name), NablaPackage.Literals::FUNCTION_RETURN_TYPE_DECLARATION__RETURN_TYPE, FUNCTION_RETURN_TYPE_VAR) } @Check(CheckType.NORMAL) @@ -197,7 +200,7 @@ class FunctionOrReductionValidator extends BasicValidator val seedType = seed?.typeFor // Seed must be scalar and Seed rootType must be the same as Return rootType // If type is Array, the reduction Seed will be used as many times as Array size - // Ex (int.MaxValue, real])→int[2]; -> we will use (int.MaxValue, int.MaxValue) as reduction seed + // Ex (int.MaxValue, real]) int[2]; -> we will use (int.MaxValue, int.MaxValue) as reduction seed if (seedType !== null) { val rType = typeDeclaration.type.primitive @@ -212,13 +215,13 @@ class FunctionOrReductionValidator extends BasicValidator * Returns true if a and b can be declared together, false otherwise. * For example, false for R[2]->R and R[n]->R */ - private def areCompatible(FunctionTypeDeclaration a, FunctionTypeDeclaration b) + private def areCompatible(List a, List b) { - if (a.inTypes.size != b.inTypes.size) + if (a.size != b.size) return true - for (i : 0.. real nextDepth1(real a, real[x] b); +def real nextDepth2(real a, real[x, y] b); +def real[x] nextDepth3(real[x] a); +def real[x, y] nextDepth4(real[x, y] a); diff --git a/tests/DepthInit/src/depthinit/DepthInit.n b/tests/DepthInit/src/depthinit/DepthInit.n index e22f4bab9..748accc17 100644 --- a/tests/DepthInit/src/depthinit/DepthInit.n +++ b/tests/DepthInit/src/depthinit/DepthInit.n @@ -12,7 +12,7 @@ module DepthInit; with BathyLib.*; with CartesianMesh2D.*; -def two: → real, () → return 2.0; +def real two() return 2.0; let real t = 0.0; int maxIter; @@ -21,4 +21,4 @@ real maxTime, delta_t; real[2] X{nodes}; real nu{cells}; -InitFromFile: ∀j∈cells(), nu{j} = two() * nextWaveHeight(); +InitFromFile: forall j in cells(), nu{j} = two() * nextWaveHeight(); diff --git a/tests/NabLabDrafts/sauv/gmds/ParallelWhiteheatKmds.cpp b/tests/NabLabDrafts/sauv/gmds/ParallelWhiteheatKmds.cpp index 88561d89f..2d733c818 100644 --- a/tests/NabLabDrafts/sauv/gmds/ParallelWhiteheatKmds.cpp +++ b/tests/NabLabDrafts/sauv/gmds/ParallelWhiteheatKmds.cpp @@ -144,7 +144,7 @@ class ParallelWhiteheatKmds }); } - // delta_t = 1/4 * ∑{j∈cells()}(V{j}) + // delta_t = 1/4 * ∑{j in cells()}(V{j}) void bidonVolume() { // kmds::GrowingView cells("CELLS", mesh.getNbFaces()); @@ -157,7 +157,7 @@ class ParallelWhiteheatKmds double bidon = 1/4 * sum; } - // ∀j∈cells(),∀r∈nodesOfCell(j), C_ic{j,r} = 0.5 * norm(X{r}); + // forall j in cells(),forall r in nodesOfCell(j), C_ic{j,r} = 0.5 * norm(X{r}); void bidonDoubleBoucle() { // kmds::GrowingView cells("CELLS", mesh.getNbFaces()); diff --git a/tests/NabLabDrafts/sauv/gmds/ParallelWhiteheatKokkos.cpp b/tests/NabLabDrafts/sauv/gmds/ParallelWhiteheatKokkos.cpp index 10f868ef0..3c0ff773d 100644 --- a/tests/NabLabDrafts/sauv/gmds/ParallelWhiteheatKokkos.cpp +++ b/tests/NabLabDrafts/sauv/gmds/ParallelWhiteheatKokkos.cpp @@ -91,7 +91,7 @@ class ParallelWhiteheatKokkos }); } - // delta_t = 1/4 * ∑{j∈cells()}(V{j}) + // delta_t = 1/4 * ∑{j in cells()}(V{j}) void bidonVolume() { double sum = 0.0; @@ -102,7 +102,7 @@ class ParallelWhiteheatKokkos double bidon = 1/4 * sum; } - // ∀j∈cells(),∀r∈nodesOfCell(j), C_ic{j,r} = 0.5 * norm(X{r}); + // forall j in cells(),forall r in nodesOfCell(j), C_ic{j,r} = 0.5 * norm(X{r}); void bidonDoubleBoucle() { Kokkos::parallel_for(nbCells, KOKKOS_LAMBDA(const int jCells) diff --git a/tests/NabLabDrafts/src/reduction/Reduction.n b/tests/NabLabDrafts/src/reduction/Reduction.n index 52416ec8e..b4d656b0a 100644 --- a/tests/NabLabDrafts/src/reduction/Reduction.n +++ b/tests/NabLabDrafts/src/reduction/Reduction.n @@ -13,7 +13,7 @@ with Math.*; with CartesianMesh2D.*; -def nodeVelocityBoundaryConditionCorner: int × real[2] × int × real[2] × real[2,2] × real[2] × real[2] → real[2], (BC1, BCValue1, BC2, BCValue2, Mp, Gp, lp_np)→ { +def real[2] nodeVelocityBoundaryConditionCorner(int BC1, real[2] BCValue1, int BC2, real[2] BCValue2, real[2,2] Mp, real[2] Gp, real[2] lp_np) { return [0., 0.]; } @@ -29,8 +29,8 @@ real[2] lpc_n{nodes, cellsOfNode}; // Corner normal --> "lpc npc" iterate n while (n <= 2); -ComputeGeometry: ∀c∈cells(), ∀p∈nodesOfCell(c), lpc_n{p,c} = [1.0, 1.0]; +ComputeGeometry: forall c in cells(), forall p in nodesOfCell(c), lpc_n{p,c} = [1.0, 1.0]; -ComputeBoundaryNodeVelocities: ∀p∈nodes("TopLeftNode"), Vnode^{n+1}{p} = nodeVelocityBoundaryConditionCorner(1, [0., 0.], 1, [0., 0.], [[1., 1.],[1., 1.]], [1., 1.], sum{c ∈ cellsOfNode(p)}(lpc_n{p,c})); +ComputeBoundaryNodeVelocities: forall p in nodes("TopLeftNode"), Vnode^{n+1}{p} = nodeVelocityBoundaryConditionCorner(1, [0., 0.], 1, [0., 0.], [[1., 1.],[1., 1.]], [1., 1.], sum{c in cellsOfNode(p)}(lpc_n{p,c})); UpdateTime: t^{n+1} = t^{n}+delta_t; diff --git a/tests/NabLabTests/src/hydroremap/Hydro.n b/tests/NabLabTests/src/hydroremap/Hydro.n index d7792fc5f..ea8d8fdcd 100644 --- a/tests/NabLabTests/src/hydroremap/Hydro.n +++ b/tests/NabLabTests/src/hydroremap/Hydro.n @@ -18,17 +18,17 @@ let real t = 0.0; real[2] X{nodes}; real hv1{cells}, hv2{cells}, hv3{cells}, hv4{cells}, hv5{cells}, hv6{cells}, hv7{cells}; -IniHv1: ∀c∈cells(), hv1{c} = 2.0; -IniHv2: ∀c∈cells(), hv2{c} = 0.0; +IniHv1: forall c in cells(), hv1{c} = 2.0; +IniHv2: forall c in cells(), hv2{c} = 0.0; -Hj1: ∀c∈cells(), hv3{c} = hv2{c} + 1.0; -Hj2: ∀c∈cells(), hv5{c} = hv3{c} + 2.0; -Hj3: ∀c∈cells(), hv7{c} = hv4{c} + hv5{c} + hv6{c}; +Hj1: forall c in cells(), hv3{c} = hv2{c} + 1.0; +Hj2: forall c in cells(), hv5{c} = hv3{c} + 2.0; +Hj3: forall c in cells(), hv7{c} = hv4{c} + hv5{c} + hv6{c}; -OracleHv1: ∀c∈cells(), let bool testHv1 = assertEquals(2.0, hv1{c}); -OracleHv2: ∀c∈cells(), let bool testHv2 = assertEquals(0.0, hv2{c}); -OracleHv3: ∀c∈cells(), let bool testHv3 = assertEquals(1.0, hv3{c}); -OracleHv4: ∀c∈cells(), let bool testHv4 = assertEquals(4.0, hv4{c}); -OracleHv5: ∀c∈cells(), let bool testHv5 = assertEquals(3.0, hv5{c}); -OracleHv6: ∀c∈cells(), let bool testHv6 = assertEquals(6.0, hv6{c}); -OracleHv7: ∀c∈cells(), let bool testHv7 = assertEquals(13.0, hv7{c}); +OracleHv1: forall c in cells(), let bool testHv1 = assertEquals(2.0, hv1{c}); +OracleHv2: forall c in cells(), let bool testHv2 = assertEquals(0.0, hv2{c}); +OracleHv3: forall c in cells(), let bool testHv3 = assertEquals(1.0, hv3{c}); +OracleHv4: forall c in cells(), let bool testHv4 = assertEquals(4.0, hv4{c}); +OracleHv5: forall c in cells(), let bool testHv5 = assertEquals(3.0, hv5{c}); +OracleHv6: forall c in cells(), let bool testHv6 = assertEquals(6.0, hv6{c}); +OracleHv7: forall c in cells(), let bool testHv7 = assertEquals(13.0, hv7{c}); diff --git a/tests/NabLabTests/src/hydroremap/Remap.n b/tests/NabLabTests/src/hydroremap/Remap.n index a40d96d5b..6b8ff3a91 100644 --- a/tests/NabLabTests/src/hydroremap/Remap.n +++ b/tests/NabLabTests/src/hydroremap/Remap.n @@ -13,5 +13,5 @@ with CartesianMesh2D.*; real rv1{cells}, rv2{cells}, rv3{cells}; -Rj1: ∀c∈cells(), rv2{c} = rv1{c} * 2.0; -Rj2: ∀c∈cells(), rv3{c} = rv2{c} * 3.0; +Rj1: forall c in cells(), rv2{c} = rv1{c} * 2.0; +Rj2: forall c in cells(), rv3{c} = rv2{c} * 3.0; diff --git a/tests/NabLabTests/src/iteration/Iteration.n b/tests/NabLabTests/src/iteration/Iteration.n index 8fd09efca..30a00eca6 100644 --- a/tests/NabLabTests/src/iteration/Iteration.n +++ b/tests/NabLabTests/src/iteration/Iteration.n @@ -31,17 +31,17 @@ iterate n while (n < maxIterN), { IniTime: t^{n=0} = 0.0; -IniVn: ∀j∈cells(), vn^{n=0}{j} = 0.0; -UpdateVn: ∀j∈cells(), vn^{n+1}{j} = vn^{n}{j} + vl^{n+1}{j} * 2; +IniVn: forall j in cells(), vn^{n=0}{j} = 0.0; +UpdateVn: forall j in cells(), vn^{n+1}{j} = vn^{n}{j} + vl^{n+1}{j} * 2; -IniVk: ∀j∈cells(), vk^{n+1, k=0}{j} = 0.0; -UpdateVk: ∀j∈cells(), vk^{n+1, k+1}{j} = vk^{n+1, k}{j} + 2; -OracleVk: ∀j∈cells(), let bool testVk = assertEquals(12.0, vk^{n+1}{j}); +IniVk: forall j in cells(), vk^{n+1, k=0}{j} = 0.0; +UpdateVk: forall j in cells(), vk^{n+1, k+1}{j} = vk^{n+1, k}{j} + 2; +OracleVk: forall j in cells(), let bool testVk = assertEquals(12.0, vk^{n+1}{j}); -IniVl: ∀j∈cells(), vl^{n+1, l=0}{j} = vk^{n+1}{j} + 8; -UpdateVl: ∀j∈cells(), vl^{n+1, l+1}{j} = vl^{n+1, l}{j} + 1; -OracleVl: ∀j∈cells(), let bool testVl = assertEquals(27.0, vl^{n+1}{j}); +IniVl: forall j in cells(), vl^{n+1, l=0}{j} = vk^{n+1}{j} + 8; +UpdateVl: forall j in cells(), vl^{n+1, l+1}{j} = vl^{n+1, l}{j} + 1; +OracleVl: forall j in cells(), let bool testVl = assertEquals(27.0, vl^{n+1}{j}); -OracleVn: ∀j∈cells(), let bool testVn = assertEquals(54.0*n, vn^{n+1}{j}); +OracleVn: forall j in cells(), let bool testVn = assertEquals(54.0*n, vn^{n+1}{j}); ComputeTn: t^{n+1} = t^{n} + delta_t; diff --git a/tests/NabLabTests/src/variables/Variables.n b/tests/NabLabTests/src/variables/Variables.n index 34f37fdc2..6737e31e6 100644 --- a/tests/NabLabTests/src/variables/Variables.n +++ b/tests/NabLabTests/src/variables/Variables.n @@ -40,8 +40,8 @@ DynamicVecInitialization: { let int cpt = 0; // two loops to check the first one is multithread - ∀i∈[0;optDim[, dynamicVec[i] = 3.3; - ∀i∈[0;optDim[, cpt = cpt + 1; + forall i in [0;optDim[, dynamicVec[i] = 3.3; + forall i in [0;optDim[, cpt = cpt + 1; checkDynamicDim = cpt; } @@ -67,11 +67,11 @@ Oracle: // NOT YET IMPLEMENTED : BaseTypeConstants on a dynamic size // let bool testDynamicVec = assertEquals(dynamicVec, real[optDim](3.3)); - ∀i∈[0;optDim[, + forall i in [0;optDim[, let bool testDynamicVec = assertEquals(3.3, dynamicVec[i]); // local variables -// ∀ r∈nodes(), +// forall r in nodes(), // { // let int localNbCells = card(cellsOfNode(r)); // let real[localNbCells] tmp = real[localNbCells](0.0); diff --git a/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/ConstExprServicesTest.xtend b/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/ConstExprServicesTest.xtend index 28cc6b9ce..8e3810d91 100644 --- a/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/ConstExprServicesTest.xtend +++ b/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/ConstExprServicesTest.xtend @@ -89,20 +89,20 @@ class ConstExprServicesTest val model = ''' «emptyTestModule» - def f: x,y | real[x] × real[y] → real[x+y], (a, b) → + def real[x+y] f(real[x] a, real[y] b) { let real[x+y] c = 2.0; c = a * 2.0; return c + 4.0; } - def g: → real, () → + def real g() { real[4] n; real[4, 2] m; - ∀ i∈[0;4[, + forall i in [0;4[, { n[i] = 4.0; - ∀ j∈[0;2[, m[i,j] = 3.0; + forall j in [0;2[, m[i,j] = 3.0; } return 4.0; } @@ -138,7 +138,7 @@ class ConstExprServicesTest Assert.assertTrue(constExprServices.isConstExpr(f_a2_type_simple.size)) Assert.assertTrue(constExprServices.isConstExpr(f_y)) - val f_return_type = f.typeDeclaration.returnType.typeFor + val f_return_type = f.returnTypeDeclaration.returnType.typeFor Assert.assertTrue(f_return_type instanceof NSTRealArray1D) val f_return_type_simple = f_return_type as NSTRealArray1D Assert.assertTrue(constExprServices.isConstExpr(f_return_type_simple.size)) diff --git a/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/DeclarationProviderTest.xtend b/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/DeclarationProviderTest.xtend index 41e65605f..e6fe5f967 100644 --- a/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/DeclarationProviderTest.xtend +++ b/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/DeclarationProviderTest.xtend @@ -54,16 +54,16 @@ class DeclarationProviderTest ''' extension MyLibOfFunctions; - def f: → int; - def f: int → int; - def f: real → real; - def f: real[2] → real[2]; + def int f(); + def int f(int a); + def real f(real a); + def real[2] f(real[2] a); - def g: a | real[a] → real[a]; - def g: a, b | real[a, b] → real[a*b]; - def g: a, b | real[a] × real[b] → real[a+b]; + def real[a] g(real[a] x); + def real[a*b] g(real[a, b] x); + def real[a+b] g(real[a] x, real[b] y); - def h: a | real[a] × real[a] → real[a]; + def real[a] h(real[a] x, real[a] y); ''' val nablaModel = @@ -177,21 +177,21 @@ class DeclarationProviderTest ''' extension Test; - def f: real → real, (a) → return a; - def f: real[2] → real[2], (a) → return a; - def g: x | real[x] → real[x], (a) → return a; + def real f(real a) return a; + def real[2] f(real[2] a) return a; + def real[x] g(real[x] a) return a; - def h: real[2] → real[2], (a) → { + def real[2] h(real[2] a) { return f(a) + g(a); } - def i: a | real[a] → real[a], (x) → { + def real[a] i(real[a] x) { return f(x); // Wrong f only on real[2] } - def j: a | real[a] → real[a], (x) → { + def real[a] j(real[a] x) { let real[a] y = g(x); - ∀i∈[0;a[, y[i] = f(x[i]); + forall i in [0;a[, y[i] = f(x[i]); return y; } ''' @@ -224,17 +224,17 @@ class DeclarationProviderTest with CartesianMesh2D.*; - def f, 0.0: real, (a , b) → return a; - def f, 0.0: x | real[x], (a , b) → return a; + red real f(0.0) (a , b) : return a; + red real[x] f(0.0) (a , b) : return a; real u{cells}; real[2] u2{cells}; int bidon{cells}; // --- TEST DE F --- - J0: { let real x = f{j ∈ cells()}(u{j}); } - J1: { let real[2] x = f{j ∈ cells()}(u2{j}); } - J2: { let real x = f{j ∈ cells()}(bidon{j}); } // Wrong arguments : int + J0: { let real x = f{j in cells()}(u{j}); } + J1: { let real[2] x = f{j in cells()}(u2{j}); } + J2: { let real x = f{j in cells()}(bidon{j}); } // Wrong arguments : int ''' val rs = resourceSetProvider.get diff --git a/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/IteratorExtensionsTest.xtend b/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/IteratorExtensionsTest.xtend index 81691c04b..e3cbf7afe 100644 --- a/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/IteratorExtensionsTest.xtend +++ b/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/IteratorExtensionsTest.xtend @@ -55,9 +55,9 @@ class IteratorExtensionsTest with CartesianMesh2D.*; - def sum, 0.0: real, (a, b) → return a + b; - def sum, 0.0: x | real[x], (a, b) → return a + b; - def sum, 0.0: x | real[x, x], (a, b) → return a + b; + red real sum(0.0) (a, b) return a + b; + red real[x] sum(0.0) (a, b) return a + b; + red real[x, x] sum(0.0) (a, b) return a + b; «simulationVariables» @@ -66,12 +66,12 @@ class IteratorExtensionsTest real surface{faces}; real a; - J1: ∀j∈cells(), x{j} = 2.0; - J2: ∀j∈cells(), ∀r∈nodesOfCell(j), Cjr{j,r} = 3.0; - J3: ∀r∈nodes(), ∀j∈cellsOfNode(r), Cjr{j,r} = 1.0; - J4: ∀j∈cells(), u{j} = 0.5 * sum{r∈nodesOfCell(j)}(X{r} - X{r+1}); - J5: ∀j1∈cells(), f{j1} = a * sum{j2∈neighbourCells(j1)}(sum{cf∈commonFace(j1,j2)}((x{j2}-x{j1}) / surface{cf})); - J6: ∀j1∈cells(), ∀j2∈neighbourCells(j1), ∀cf∈commonFace(j1,j2), let real bidon = (x{j2}-x{j1}) / surface{cf}); + J1: forall j in cells(), x{j} = 2.0; + J2: forall j in cells(), forall r in nodesOfCell(j), Cjr{j,r} = 3.0; + J3: forall r in nodes(), forall j in cellsOfNode(r), Cjr{j,r} = 1.0; + J4: forall j in cells(), u{j} = 0.5 * sum{r in nodesOfCell(j)}(X{r} - X{r+1}); + J5: forall j1 in cells(), f{j1} = a * sum{j2 in neighbourCells(j1)}(sum{cf in commonFace(j1,j2)}((x{j2}-x{j1}) / surface{cf})); + J6: forall j1 in cells(), forall j2 in neighbourCells(j1), forall cf in commonFace(j1,j2), let real bidon = (x{j2}-x{j1}) / surface{cf}); ''' val rs = resourceSetProvider.get diff --git a/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/NablaScopeProviderTest.xtend b/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/NablaScopeProviderTest.xtend index 2945841f2..d772b5270 100644 --- a/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/NablaScopeProviderTest.xtend +++ b/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/NablaScopeProviderTest.xtend @@ -52,15 +52,15 @@ class NablaScopeProviderTest real a{cells}, b{cells, nodesOfCell}, c{cells}; real d{nodes}; - j1 : ∀j ∈ cells(), a{j} = 0.0; - j2 : ∀j ∈ cells(), c{j} = 0.25 * sum{r ∈ nodes()}(d{r}); - j3 : ∀j ∈ cells(), ∀r ∈ nodesOfCell(j), b{j,r} = 0.; - j4 : ∀j ∈ cells(), a{j} = sum{r∈nodesOfCell(j)}(b{j, r}); - j5 : let real z = sum{j∈cells()}(sum{r∈nodesOfCell(j)}(X{r})); - j6 : ∀j ∈ cells(), ∀ rj ∈ rightCell(j), ∀ lj ∈ leftCell(j), c{j} = a{rj}; - j7 : ∀j ∈ cells(), { + j1 : forall j in cells(), a{j} = 0.0; + j2 : forall j in cells(), c{j} = 0.25 * sum{r in nodes()}(d{r}); + j3 : forall j in cells(), forall r in nodesOfCell(j), b{j,r} = 0.; + j4 : forall j in cells(), a{j} = sum{r in nodesOfCell(j)}(b{j, r}); + j5 : let real z = sum{j in cells()}(sum{r in nodesOfCell(j)}(X{r})); + j6 : forall j in cells(), forall rj in rightCell(j), forall lj in leftCell(j), c{j} = a{rj}; + j7 : forall j in cells(), { set rjset = rightCell(j); - ∀ rj ∈ rjset, c{j} = a{rj}; + forall rj in rjset, c{j} = a{rj}; } ''' val rs = resourceSetProvider.get @@ -113,14 +113,14 @@ class NablaScopeProviderTest real a{cells}, b{cells, nodesOfCell}, c{cells}; real d{nodes}; - j1 : ∀j ∈ cells(), a{j} = 0.0; - j2 : ∀j ∈ cells(), c{j} = 0.25 * sum{r ∈ nodes()}(d{r}); - j3 : ∀j ∈ cells(), ∀r ∈ nodesOfCell(j), b{j,r} = 0.; - j4 : ∀j ∈ cells(), a{j} = sum{r∈nodesOfCell(j)}(b{j, r}); - j5 : ∀j ∈ cells(), ∀ rj ∈ rightCell(j), ∀ lj ∈ leftCell(j), c{j} = a{rj} + a{lj}; - j6 : ∀j ∈ cells(), { + j1 : forall j in cells(), a{j} = 0.0; + j2 : forall j in cells(), c{j} = 0.25 * sum{r in nodes()}(d{r}); + j3 : forall j in cells(), forall r in nodesOfCell(j), b{j,r} = 0.; + j4 : forall j in cells(), a{j} = sum{r in nodesOfCell(j)}(b{j, r}); + j5 : forall j in cells(), forall rj in rightCell(j), forall lj in leftCell(j), c{j} = a{rj} + a{lj}; + j6 : forall j in cells(), { set rjset = rightCell(j); - ∀ rj ∈ rjset, c{j} = a{rj}; + forall rj in rjset, c{j} = a{rj}; } ''' @@ -200,14 +200,14 @@ class NablaScopeProviderTest «testModule» real a{cells}, b{cells, nodesOfCell}; - j1 : ∀j ∈ cells(), a{j} = 0.0; + j1 : forall j in cells(), a{j} = 0.0; j2 : { set myCells = cells(); - ∀j ∈ myCells, a{j} = 0.0; + forall j in myCells, a{j} = 0.0; } - j3 : ∀j ∈ cells(), { + j3 : forall j in cells(), { set nOfCells = nodesOfCell(j); - a{j} = sum{r∈nOfCells}(b{j, r}); + a{j} = sum{r in nOfCells}(b{j, r}); } ''' val rs = resourceSetProvider.get @@ -243,11 +243,11 @@ class NablaScopeProviderTest iterate n while (n > 4), k while (n > 4 && k < 2); - j1: ∀ j∈cells(), { + j1: forall j in cells(), { c1{j} = a * 2; let real d = 6.0; c2{j} = 2 * d; - ∀ r, countr ∈ nodesOfCell(j), { + forall r, countr in nodesOfCell(j), { let real e = 3.3; real f; f = e + 1.0; @@ -257,15 +257,15 @@ class NablaScopeProviderTest j2: { real[4] o; real[4, 2] p; - ∀ i∈[0;4[, + forall i in [0;4[, { o[i] = 4.0; - ∀ j∈[0;2[, p[i,j] = 3.0; + forall j in [0;2[, p[i,j] = 3.0; } } j3: { - let real z = sum{j∈cells()}(sum{r∈nodesOfCell(j)}(sum{i∈[0;2[}(X{r}[i]))); + let real z = sum{j in cells()}(sum{r in nodesOfCell(j)}(sum{i in [0;2[}(X{r}[i]))); z = z + 1; } ''' @@ -321,7 +321,7 @@ class NablaScopeProviderTest val model = ''' «emptyTestModule» - def reduceMin, real.MaxValue: real, (a, b) → return min(a, b); + red real reduceMin(real.MaxValue) (a, b) : return min(a, b); ''' val module = parseHelper.parse(model) Assert.assertNotNull(module) @@ -339,20 +339,20 @@ class NablaScopeProviderTest val model = ''' «emptyTestModule» - def f: x,y | real[x] × real[y] → real[x+y], (a, b) → + def real[x+y] f(real[x] a, real[y] b) { let real c = 2.0; c = a * 2.0; return c + 4.0; } - def g: → real, () → + def real g() { real[4] n; real[4, 2] m; - ∀ i∈[0;4[, + forall i in [0;4[, { n[i] = 4.0; - ∀ j∈[0;2[, m[i,j] = 3.0; + forall j in [0;2[, m[i,j] = 3.0; } return 4.0; } @@ -392,22 +392,22 @@ class NablaScopeProviderTest real[2] X{nodes}; real c1 {cells}; - j1: ∀ j∈cells(), { + j1: forall j in cells(), { c1{j} = 2.0; } j2: { real[4] n; real[4, 2] m; - ∀ i∈[0;4[, + forall i in [0;4[, { n[i] = 4.0; - ∀ j∈[0;2[, m[i,j] = 3.0; + forall j in [0;2[, m[i,j] = 3.0; } } j3: { - let real z = sum{j∈cells()}(sum{r∈nodesOfCell(j)}(sum{k∈[0;1[}(X{r}[k+1]))); + let real z = sum{j in cells()}(sum{r in nodesOfCell(j)}(sum{k in [0;1[}(X{r}[k+1]))); z = z + 1; } ''' @@ -448,19 +448,19 @@ class NablaScopeProviderTest val model = ''' «emptyTestModule» - def f: x,y | real[x] × real[y] → real[x+y], (a, b) → + def real[x+y] f(real[x] a, real[y] b) { real[x,y] c; return c; } - def g: → real, () → + def real g() { real[4] n; real[4, 2] m; - ∀ i∈[0;4[, + forall i in [0;4[, { n[i] = 4.0; - ∀ j∈[0;2[, m[i,j] = 3.0; + forall j in [0;2[, m[i,j] = 3.0; } return 4.0; } diff --git a/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/NablagenScopeProviderTest.xtend b/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/NablagenScopeProviderTest.xtend index f7a4233c3..68563bb67 100644 --- a/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/NablagenScopeProviderTest.xtend +++ b/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/NablagenScopeProviderTest.xtend @@ -55,9 +55,9 @@ class NablagenScopeProviderTest iterate n while (n+1 < maxIter && t^{n+1} < maxTime); - hj1: ∀c∈cells(), hv3{c} = hv2{c}; - hj2: ∀c∈cells(), hv5{c} = hv3{c}; - hj3: ∀c∈cells(), hv7{c} = hv4{c} + hv5{c} + hv6{c}; + hj1: forall c in cells(), hv3{c} = hv2{c}; + hj2: forall c in cells(), hv5{c} = hv3{c}; + hj3: forall c in cells(), hv7{c} = hv4{c} + hv5{c} + hv6{c}; ''' val nablaRemapModel = @@ -69,8 +69,8 @@ class NablagenScopeProviderTest real[2] X{nodes}; real rv1{cells}, rv2{cells}, rv3{cells}; - rj1: ∀c∈cells(), rv2{c} = rv1{c}; - rj2: ∀c∈cells(), rv3{c} = rv2{c}; + rj1: forall c in cells(), rv2{c} = rv1{c}; + rj2: forall c in cells(), rv3{c} = rv2{c}; ''' val ngenModel = diff --git a/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/ir/interpreter/AbstractExpressionInterpreterTest.xtend b/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/ir/interpreter/AbstractExpressionInterpreterTest.xtend index e4a209af3..d885b0888 100644 --- a/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/ir/interpreter/AbstractExpressionInterpreterTest.xtend +++ b/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/ir/interpreter/AbstractExpressionInterpreterTest.xtend @@ -233,14 +233,14 @@ abstract class AbstractExpressionInterpreterTest «emptyTestModule» with CartesianMesh2D.*; - def getOne: → int, () → return 1; - def addOne: int → int, (a) → return a + 1; - def addOne: real → real, (a) → return a + 1.0; - def add: int × int → int, (a, b) → return a + b; - def add: real × int → real, (a, b) → return a + b; - def add: real × real → real, (a, b) → return a + b; - def add: x | real[x] × real[x] → real[x], (a, b) → return a + b; - def add: x,y | real[x,y] × real[x,y] → real[x,y], (a, b) → return a + b; + def int getOne() return 1; + def int addOne(int a) return a + 1; + def real addOne(real a) return a + 1.0; + def int add(int a, int b) return a + b; + def real add(real a, int b) return a + b; + def real add(real a, real b) return a + b; + def real[x] add(real[x] a, real[x] b) return a + b; + def real[x,y] add(real[x,y] a, real[x,y] b) return a + b; «simulationVariables» let int n0 = 0; @@ -281,19 +281,19 @@ abstract class AbstractExpressionInterpreterTest with CartesianMesh2D.*; - def h: real[2] → real[2], (a) → return 2 * a; + def real[2] h(real[2] a) return 2 * a; - def i: a | real[a] → real[a], (x) → { + def real[a] i(real[a] x) { return 2 * x; } - def j: a | real[a] → real[a], (x) → { + def real[a] j(real[a] x) { real[a] y; - ∀i∈[0;a[, y[i] = 2 * x[i]; + forall i in [0;a[, y[i] = 2 * x[i]; return y; } - def k: b | real[b] → real[b], (x) → return j(x); + def real[b] k(real[b] x) return j(x); «simulationVariables» let real[2] u = [0.0, 0.1]; diff --git a/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/ir/interpreter/AbstractInstructionInterpreterTest.xtend b/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/ir/interpreter/AbstractInstructionInterpreterTest.xtend index 7f737075a..f55f61739 100644 --- a/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/ir/interpreter/AbstractInstructionInterpreterTest.xtend +++ b/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/ir/interpreter/AbstractInstructionInterpreterTest.xtend @@ -76,30 +76,30 @@ abstract class AbstractInstructionInterpreterTest iterate n while (n+1 < maxIter && t^{n+1} < maxTime); InitTime: t^{n=0} = 0.0; - InitU : ∀r∈cells(), U{r} = 1.0; - ComputeCjr: ∀j∈ cells(), { + InitU : forall r in cells(), U{r} = 1.0; + ComputeCjr: forall j in cells(), { set rCellsJ = nodesOfCell(j); let int cardRCellsJ = card(rCellsJ); real[cardRCellsJ] tmp; - ∀r, countr ∈ rCellsJ, { + forall r, countr in rCellsJ, { tmp[countr] = 0.5; // stupid but test countr C{j,r} = tmp[countr] * (X{r+1} - X{r-1}); } } - InitB: ∀r∈nodes(), + InitB: forall r in nodes(), { B^{n=0}{r}[0] = -X{r}[0]; B^{n=0}{r}[1] = -X{r}[1]; } - ComputeB: ∀r∈nodes(), B^{n+1}{r} = B^{n}{r} / 2; + ComputeB: forall r in nodes(), B^{n+1}{r} = B^{n}{r} / 2; // reductions - ComputeBmin: Bmin = Min{r∈nodes()}(B^{n}{r}[0]); - ComputeBmax: Bmax = Max{r∈nodes()}(B^{n}{r}[0]); + ComputeBmin: Bmin = Min{r in nodes()}(B^{n}{r}[0]); + ComputeBmax: Bmax = Max{r in nodes()}(B^{n}{r}[0]); // loop on interval - InitTab: ∀i∈[0;size[, tab[i] = 2.3; + InitTab: forall i in [0;size[, tab[i] = 2.3; InitT: t^{n=0} = 0.0; ComputeTn: t^{n+1} = t^{n} + delta_t; @@ -118,7 +118,7 @@ abstract class AbstractInstructionInterpreterTest real[2] X{nodes}; InitT: t=0.0; - InitU : ∀r, countr ∈ cells(), { + InitU : forall r, countr in cells(), { if (countr % 2 == 0) U{r} = 0.0; else @@ -141,7 +141,7 @@ abstract class AbstractInstructionInterpreterTest InitU : { let int i = 0; while (i<3) { - ∀r ∈ cells(), U{r} = 1.0 * i; + forall r in cells(), U{r} = 1.0 * i; i = i +1; } } @@ -162,7 +162,7 @@ abstract class AbstractInstructionInterpreterTest InitT: t=0.0; InitU : { set myCells = cells(); - ∀r∈myCells, U{r} = 1.0; + forall r in myCells, U{r} = 1.0; } ''' assertInterpreteSetDefinition(model, 100, 100) diff --git a/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/ir/interpreter/AbstractJobInterpreterTest.xtend b/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/ir/interpreter/AbstractJobInterpreterTest.xtend index 7c6ddd2e0..fe0164e29 100644 --- a/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/ir/interpreter/AbstractJobInterpreterTest.xtend +++ b/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/ir/interpreter/AbstractJobInterpreterTest.xtend @@ -70,7 +70,7 @@ abstract class AbstractJobInterpreterTest InitTime: t^{n=0} = 0.0; IniU : u^{n=0} = 4.0; - IniCenter: ∀j∈cells(), center{j} = 0.25 * sum{r∈nodesOfCell(j)}(X^{n=0}{r}); + IniCenter: forall j in cells(), center{j} = 0.25 * sum{r in nodesOfCell(j)}(X^{n=0}{r}); UpdateU: u^{n+1} = u^{n} + 1; ''' assertInterpreteTimeLoopCopyJob(model) diff --git a/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/ir/transformers/ReplaceAffectationsTest.xtend b/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/ir/transformers/ReplaceAffectationsTest.xtend index dcf044dd5..aebcbd4b3 100644 --- a/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/ir/transformers/ReplaceAffectationsTest.xtend +++ b/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/ir/transformers/ReplaceAffectationsTest.xtend @@ -54,10 +54,10 @@ class ReplaceAffectationsTest J2: a = b; // Connectivity variable. Un = Un+1 at the end of time loop => replace by loop - J3: ∀j∈cells(), u^{n+1}{j} = u^{n}{j} + 1.0; + J3: forall j in cells(), u^{n+1}{j} = u^{n}{j} + 1.0; // Connectivity array variable. Vn = Vn+1 at the end of time loop => replace by loop - J4: ∀j∈cells(), v^{n+1}{j} = v^{n}{j} + 1.0; + J4: forall j in cells(), v^{n+1}{j} = v^{n}{j} + 1.0; ''' val ir = compilationHelper.getRawIr(model, testGenModel) diff --git a/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/ir/transformers/ReplaceOptionsByLocalVariablesTest.xtend b/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/ir/transformers/ReplaceOptionsByLocalVariablesTest.xtend index 2d04943be..1897faf81 100644 --- a/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/ir/transformers/ReplaceOptionsByLocalVariablesTest.xtend +++ b/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/ir/transformers/ReplaceOptionsByLocalVariablesTest.xtend @@ -48,7 +48,7 @@ class ReplaceOptionsByLocalVariablesTest iterate n while (n < 2); // A job with a loop and an option - J1: ∀j∈cells(), u^{n+1}{j} = u^{n}{j} + my_opt; + J1: forall j in cells(), u^{n+1}{j} = u^{n}{j} + my_opt; ''' val ir = compilationHelper.getRawIr(model, testGenModel) diff --git a/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/typeprovider/ArgOrVarTypeProviderTest.xtend b/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/typeprovider/ArgOrVarTypeProviderTest.xtend index 361169f4d..bc5c44f44 100644 --- a/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/typeprovider/ArgOrVarTypeProviderTest.xtend +++ b/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/typeprovider/ArgOrVarTypeProviderTest.xtend @@ -42,6 +42,7 @@ import org.eclipse.xtext.testing.validation.ValidationTestHelper import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith +import org.eclipse.xtext.validation.Issue /** * Test ArgOrVarTypeProvider class. @@ -66,7 +67,7 @@ class ArgOrVarTypeProviderTest ''' linearalgebra extension LinearAlgebra; - def solveLinearSystem: x | real[x, x] × real[x] → real[x], (a, b) → return b; + def real[x] solveLinearSystem(real[x, x] a, real[x] b) return b; ''' val nablaModel = @@ -76,7 +77,7 @@ class ArgOrVarTypeProviderTest with LinearAlgebra.*; with CartesianMesh2D.*; - def norm: x | real[x] → real, (a) → return 1.0; + def real norm(real[x] a) return 1.0; // bool scalar bool b; @@ -138,14 +139,14 @@ class ArgOrVarTypeProviderTest UpdateU: u^{n+1} = solveLinearSystem(alpha, u^{n}); // local variable - ComputeX: ∀ j∈cells(), { + ComputeX: forall j in cells(), { let real ee = 1.0; u^{n}{j} = ee * 4; - ∀r∈nodesOfCell(j), Cjr{j,r} = norm(w{j,r}); + forall r in nodesOfCell(j), Cjr{j,r} = norm(w{j,r}); } - TestSpaceIteratorIndex: ∀r, spaceIteratorIndex ∈ nodes(), X{r}[spaceIteratorIndex] = 0.0; - TestIntervalIndex: ∀r∈nodes(), ∀intervalIndex∈[0;2[, X{r}[intervalIndex] = 0.0; + TestSpaceIteratorIndex: forall r, spaceIteratorIndex in nodes(), X{r}[spaceIteratorIndex] = 0.0; + TestIntervalIndex: forall r in nodes(), forall intervalIndex in [0;2[, X{r}[intervalIndex] = 0.0; ''' val rs = resourceSetProvider.get @@ -153,6 +154,12 @@ class ArgOrVarTypeProviderTest val linearAlgebraExt = parseHelper.parse(lightLinearAlgebraModel, rs) as DefaultExtension val module = parseHelper.parse(nablaModel, rs) as NablaModule Assert.assertNotNull(module) + for(Issue iss : module.validate){ + if(iss.severity == Severity.ERROR) + println( + iss.toString + ) + } Assert.assertEquals(0, module.validate.filter(i | i.severity == Severity.ERROR).size) // bool scalar diff --git a/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/typeprovider/ExpressionTypeProviderTest.xtend b/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/typeprovider/ExpressionTypeProviderTest.xtend index 614621457..32c3a1974 100644 --- a/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/typeprovider/ExpressionTypeProviderTest.xtend +++ b/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/typeprovider/ExpressionTypeProviderTest.xtend @@ -60,7 +60,7 @@ class ExpressionTypeProviderTest ''' linearalgebra extension LinearAlgebra; - def solveLinearSystem: x | real[x, x] × real[x] → real[x], (a, b) → return b; + def real[x] solveLinearSystem(real[x, x] a, real[x] b) return b; ''' val nablaModel = @@ -70,10 +70,10 @@ class ExpressionTypeProviderTest with LinearAlgebra.*; with CartesianMesh2D.*; - def reduceMin, real.MaxValue: real, (a, b) → return a; + red real reduceMin(real.MaxValue) (a, b) : return a; - def perp: real[2] → real[2], (a) → return a; - def norm: x | real[x] → real, (a) → return 1.0; + def real[2] perp(real[2] a) return a; + def real norm(real[x] a) return 1.0; let real X_EDGE_LENGTH = 1.; let real Y_EDGE_LENGTH = X_EDGE_LENGTH; @@ -131,12 +131,12 @@ class ExpressionTypeProviderTest UpdateU: u^{n+1} = solveLinearSystem(alpha, u^{n}); - ComputeV: ∀j∈cells(), v{j} = reduceMin{r∈nodesOfCell(j)}(x{j,r} + s{j}); + ComputeV: forall j in cells(), v{j} = reduceMin{r in nodesOfCell(j)}(x{j,r} + s{j}); - ComputeX: ∀ j∈cells(), { + ComputeX: forall j in cells(), { let real ee = 1.0; u^{n}{j} = ee * 4; - ∀r∈nodesOfCell(j), x{j,r} = norm(w{j,r}); + forall r in nodesOfCell(j), x{j,r} = norm(w{j,r}); } ''' diff --git a/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/validation/ArgOrVarRefValidatorTest.xtend b/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/validation/ArgOrVarRefValidatorTest.xtend index b4d545c45..fa01dad57 100644 --- a/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/validation/ArgOrVarRefValidatorTest.xtend +++ b/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/validation/ArgOrVarRefValidatorTest.xtend @@ -77,9 +77,9 @@ class ArgOrVarRefValidatorTest ''' «testModule» real u{cells}, v{cells, nodesOfCell}, w{nodes}; - ComputeU: ∀ j∈cells(), ∀r∈nodesOfCell(j), u{j,r} = 1.; - ComputeV: ∀ j∈cells(), ∀r∈nodesOfCell(j), v{j} = 1.; - ComputeW: ∀ j∈cells(), w{j} = 1.; + ComputeU: forall j in cells(), forall r in nodesOfCell(j), u{j,r} = 1.; + ComputeV: forall j in cells(), forall r in nodesOfCell(j), v{j} = 1.; + ComputeW: forall j in cells(), w{j} = 1.; ''', rs) Assert.assertNotNull(moduleKo) @@ -99,9 +99,9 @@ class ArgOrVarRefValidatorTest ''' «testModule» real u{cells}, v{cells, nodesOfCell}, w{nodes}; - ComputeU: ∀ j∈cells(), ∀r∈nodesOfCell(j), u{j} = 1.; - ComputeV: ∀ j∈cells(), ∀r∈nodesOfCell(j), v{j,r} = 1.; - ComputeW: ∀ j∈nodes(), w{j} = 1.; + ComputeU: forall j in cells(), forall r in nodesOfCell(j), u{j} = 1.; + ComputeV: forall j in cells(), forall r in nodesOfCell(j), v{j,r} = 1.; + ComputeW: forall j in nodes(), w{j} = 1.; ''', rs) Assert.assertNotNull(moduleOk) moduleOk.assertNoErrors @@ -261,7 +261,7 @@ class ArgOrVarRefValidatorTest «testModule» real[2] X{nodes}; real y{nodes}; - InitY : ∀r ∈nodes(), y{r} = X{r}[1]; + InitY : forall r in nodes(), y{r} = X{r}[1]; ''', rs) Assert.assertNotNull(moduleOk) moduleOk.assertNoErrors diff --git a/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/validation/BasicValidatorTest.xtend b/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/validation/BasicValidatorTest.xtend index d21e60629..3266356ee 100644 --- a/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/validation/BasicValidatorTest.xtend +++ b/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/validation/BasicValidatorTest.xtend @@ -50,7 +50,7 @@ class BasicValidatorTest itemtypes { node } - connectivity nodes: → {node}; + connectivity {node} nodes(); ''', rs) val moduleKo = parseHelper.parse( @@ -85,10 +85,10 @@ class BasicValidatorTest val moduleKo = parseHelper.parse( ''' extension Test; - def g: → real, () → + def real g() { real[4] n; - ∀ i∈[1;3[, n[i] = 0.0; + forall i in [1;3[, n[i] = 0.0; return 4.0; } ''') @@ -99,10 +99,10 @@ class BasicValidatorTest val moduleOk = parseHelper.parse( ''' extension Test; - def g: → real, () → + def real g() { real[4] n; - ∀ i∈[0;3[, n[i] = 0.0; + forall i in [0;3[, n[i] = 0.0; return 4.0; } ''') @@ -116,10 +116,10 @@ class BasicValidatorTest val moduleKo1 = parseHelper.parse( ''' extension Test; - def g: → real, () → + def real g() { real[4] n; - ∀ i∈[0;3.2[, n[i] = 0.0; + forall i in [0;3.2[, n[i] = 0.0; return 4.0; } ''') @@ -130,11 +130,11 @@ class BasicValidatorTest val moduleKo2 = parseHelper.parse( ''' extension Test; - def g: → real, () → + def real g() { let real x = 6.7; real[4] n; - ∀ i∈[0;x[, n[i] = 0.0; + forall i in [0;x[, n[i] = 0.0; return 4.0; } ''') @@ -146,10 +146,10 @@ class BasicValidatorTest val moduleOk = parseHelper.parse( ''' extension Test; - def g: → real, () → + def real g() { real[4] n; - ∀ i∈[0;4[, n[i] = 0.0; + forall i in [0;4[, n[i] = 0.0; return 4.0; } ''') @@ -225,11 +225,11 @@ class BasicValidatorTest val moduleKo = parseHelper.parse( ''' extension Test; - def sum, 0.0: real, (a, b) → return a + b; - def G: → real, () → + red real sum(0.0) (a, b) : return a + b; + def real G() { real[4] n; - ∀ i∈[0;3[, n[i] = 0.0; + forall i in [0;3[, n[i] = 0.0; return 4.0; } ''') @@ -241,11 +241,11 @@ class BasicValidatorTest val moduleOk = parseHelper.parse( ''' extension Test; - def sum, 0.0: real, (a, b) → return a + b; - def g: → real, () → + red real sum(0.0) (a, b) : return a + b; + def real g() { real[4] n; - ∀ i∈[0;3[, n[i] = 0.0; + forall i in [0;3[, n[i] = 0.0; return 4.0; } ''') @@ -319,7 +319,7 @@ class BasicValidatorTest ''' «emptyTestModule» real[3] x; - iterate n while(sum{x∈[0;3[}(x[i]])); + iterate n while(sum{x in [0;3[}(x[i]])); ''') Assert.assertNotNull(moduleKo1) moduleKo1.assertError(NablaPackage.eINSTANCE.timeIterator, @@ -482,8 +482,8 @@ class BasicValidatorTest «testModule» let orig = [0.0 , 0.0] ; real[2] X{nodes}; - IniX1: ∀j∈cells(), ∀r∈nodes(j), X{r} = orig; - IniX2: ∀r∈nodes(), ∀j∈nodesOfCell(r), X{r} = orig; + IniX1: forall j in cells(), forall r in nodes(j), X{r} = orig; + IniX2: forall r in nodes(), forall j in nodesOfCell(r), X{r} = orig; ''', rs) as NablaModule Assert.assertNotNull(moduleKo) @@ -500,8 +500,8 @@ class BasicValidatorTest «testModule» let real[2] orig = [0.0 , 0.0]; real[2] X{nodes}; - IniX1: ∀j∈cells(), ∀r∈nodes(), X{r} = orig; - IniX2: ∀j∈cells(), ∀r∈nodesOfCell(j), X{r} = orig; + IniX1: forall j in cells(), forall r in nodes(), X{r} = orig; + IniX2: forall j in cells(), forall r in nodesOfCell(j), X{r} = orig; ''', rs) Assert.assertNotNull(moduleOk) moduleOk.assertNoErrors @@ -568,7 +568,7 @@ class BasicValidatorTest ''' «testModule» real[2] X{cells}; - UpdateX: ∀j1∈cells(), ∀j2∈leftCell(j1), X{j2} = X{j2-1} - 1; + UpdateX: forall j1 in cells(), forall j2 in leftCell(j1), X{j2} = X{j2-1} - 1; ''', rs) Assert.assertNotNull(moduleKo) @@ -580,7 +580,7 @@ class BasicValidatorTest ''' «testModule» real[2] X{cells}; - UpdateX: ∀j1∈cells(), ∀j2∈leftCell(j1), X{j2} = X{j1-1} - 1; + UpdateX: forall j1 in cells(), forall j2 in leftCell(j1), X{j2} = X{j1-1} - 1; ''', rs) Assert.assertNotNull(moduleOk) moduleOk.assertNoErrors diff --git a/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/validation/ExpressionValidatorTest.xtend b/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/validation/ExpressionValidatorTest.xtend index ff07e4ce2..7669a8e6d 100644 --- a/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/validation/ExpressionValidatorTest.xtend +++ b/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/validation/ExpressionValidatorTest.xtend @@ -98,7 +98,7 @@ class ExpressionValidatorTest ''' «emptyTestModule» with CartesianMesh2D.*; - def test: bool × real × real[2] → real, (a, b, c) → return b; + def real test(bool a, real b, real[2] c) return b; let real[2] opt = [0., 1.]; let int count = 1; real alpha{cells}; @@ -137,11 +137,11 @@ class ExpressionValidatorTest ''' «emptyTestModule» with CartesianMesh2D.*; - def sum, 0.0: real, (a, b) → return a + b; + red real sum(0.0) (a, b) : return a + b; real D{cells}; real[2] E{cells}; - ComputeU: let real u = sum{c∈cells()}(D); - ComputeV: let real[2] v = sum{c∈cells()}(E{c}); + ComputeU: let real u = sum{c in cells()}(D); + ComputeV: let real[2] v = sum{c in cells()}(E{c}); ''', rs) Assert.assertNotNull(moduleKo) Assert.assertEquals(2, moduleKo.validate.filter(i | i.severity == Severity.ERROR).size) @@ -158,12 +158,12 @@ class ExpressionValidatorTest ''' «emptyTestModule» with CartesianMesh2D.*; - def sum, 0.0: real, (a,b) → return a + b; - def sum, 0.0: x | real[x], (a,b) → return a + b; + red real sum(0.0) (a,b) : return a + b; + red real[x] sum(0.0) (a,b) : return a + b; real D{cells}; real[2] E{cells}; - ComputeU: let real u = sum{c∈cells()}(D{c}); - ComputeV: let real[2] v = sum{c∈cells()}(E{c}); + ComputeU: let real u = sum{c in cells()}(D{c}); + ComputeV: let real[2] v = sum{c in cells()}(E{c}); ''', rs) Assert.assertNotNull(moduleOk) moduleOk.assertNoErrors @@ -570,11 +570,11 @@ class ExpressionValidatorTest val extensionKo = parseHelper.parse( ''' extension Test; - def f: → real; - def g: → real, () → + def real f(); + def real g() { real[4] n; - ∀ i∈[0;4[, n[i] = 0.0; + forall i in [0;4[, n[i] = 0.0; return f(); } ''') @@ -588,11 +588,11 @@ class ExpressionValidatorTest val extensionOk = parseHelper.parse( ''' extension Test; - def f: → real; - def g: → real, () → + def real f(); + def real g() { real[4] n; - ∀ i∈[0;4[, n[i] = 0.0; + forall i in [0;4[, n[i] = 0.0; return 4.0; } ''') diff --git a/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/validation/FunctionOrReductionValidatorTest.xtend b/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/validation/FunctionOrReductionValidatorTest.xtend index bc628cf6e..f093608f6 100644 --- a/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/validation/FunctionOrReductionValidatorTest.xtend +++ b/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/validation/FunctionOrReductionValidatorTest.xtend @@ -45,7 +45,7 @@ class FunctionOrReductionValidatorTest ''' module Test; - def f: real → real; + def real f(real a); ''') Assert.assertNotNull(moduleKo) moduleKo.assertError(NablaPackage.eINSTANCE.functionOrReduction, @@ -56,7 +56,7 @@ class FunctionOrReductionValidatorTest ''' module Test; - def f: real → real, (a) → { return 1.0; } + def real f(real a) { return 1.0; } ''') Assert.assertNotNull(moduleOk) } @@ -70,7 +70,7 @@ class FunctionOrReductionValidatorTest ''' «testModule» int U{cells}; - ComputeU: ∀ j∈cells(), { + ComputeU: forall j in cells(), { let int e = 1; U{j} = e * 4; return e; @@ -85,7 +85,7 @@ class FunctionOrReductionValidatorTest ''' «testModule» int U{cells}; - ComputeU: ∀ j∈cells(), { + ComputeU: forall j in cells(), { let int e = 1; U{j} = e * 4; } @@ -101,7 +101,7 @@ class FunctionOrReductionValidatorTest ''' module Test; - def f: real → real, (a) → { let x = 1; } + def real f(real a) { let x = 1; } ''') Assert.assertNotNull(moduleKo) moduleKo.assertError(NablaPackage.eINSTANCE.functionOrReduction, @@ -112,7 +112,7 @@ class FunctionOrReductionValidatorTest ''' module Test; - def f: real → real, (a) → { return 1.0; } + def real f(real a) { return 1.0; } ''') Assert.assertNotNull(moduleOk) } @@ -124,7 +124,7 @@ class FunctionOrReductionValidatorTest ''' module Test; - def f: real → real, (a) → + def real f(real a) { return 1.0; let int x = 1; @@ -139,7 +139,7 @@ class FunctionOrReductionValidatorTest ''' module Test; - def f: real → real, (a) → + def real f(real a) { return 1.0; } @@ -153,7 +153,7 @@ class FunctionOrReductionValidatorTest val modulekO = parseHelper.parse( ''' extension Test; - def f: x | real[x+1] → real[x]; + def real[x] f(real[x+1] a); ''') Assert.assertNotNull(modulekO) @@ -164,7 +164,7 @@ class FunctionOrReductionValidatorTest val moduleOk = parseHelper.parse( ''' extension Test; - def f: x | real[x] → real[x+1]; + def real[x+1] f(real[x] a); ''') Assert.assertNotNull(moduleOk) moduleOk.assertNoErrors @@ -176,7 +176,7 @@ class FunctionOrReductionValidatorTest val modulekO = parseHelper.parse( ''' extension Test; - def sum, 0.0: x,y | real[x+y], (a,b) → return a + b; + red real[x+y] sum(0.0) (a,b) : return a + b; ''') Assert.assertNotNull(modulekO) @@ -187,49 +187,20 @@ class FunctionOrReductionValidatorTest val moduleOk = parseHelper.parse( ''' extension Test; - def sum, 0.0: x | real[x], (a,b) → return a + b; + red real[x] sum(0.0) (a,b) : return a + b; ''') Assert.assertNotNull(moduleOk) moduleOk.assertNoErrors } - @Test - def void testCheckFunctionInvalidArgNumber() - { - val moduleKo = parseHelper.parse( - ''' - module Test; - - def f: real → real, (a, b) → - { - return 1.0; - } - ''') - Assert.assertNotNull(moduleKo) - moduleKo.assertError(NablaPackage.eINSTANCE.functionOrReduction, - FunctionOrReductionValidator::FUNCTION_INVALID_ARG_NUMBER, - FunctionOrReductionValidator::getFunctionInvalidArgNumberMsg()) - - val moduleOk = parseHelper.parse( - ''' - module Test; - - def f: real → real, (a) → - { - return 1.0; - } - ''') - Assert.assertNotNull(moduleOk) - } - @Test def void testCheckFunctionIncompatibleInTypes() { val modulekO = parseHelper.parse( ''' extension Test; - def g: real[2] → real; - def g: x | real[x] → real; + def real g(real[2] a); + def real g(real[x] a); ''') Assert.assertNotNull(modulekO) @@ -240,48 +211,48 @@ class FunctionOrReductionValidatorTest val moduleOk = parseHelper.parse( ''' extension Test; - def g: real → real; - def g: x | real[x] → real; + def real g(real a); + def real g(real[x] a); ''') Assert.assertNotNull(moduleOk) moduleOk.assertNoErrors } @Test - def void testFunctionReturnType() + def void testFunctionReturnTypeDeclaration() { val model = ''' extension Test; - def f: real → real, (a) → { return 1; } - def g: real → real, (a) → { return 1.0; } + def real f(real a) { return 1; } + def real g(real a) { return 1.0; } ''' val module = parseHelper.parse(model) Assert.assertNotNull(module) Assert.assertEquals(1, module.validate.filter(i | i.severity == Severity.ERROR).size) - module.assertError(NablaPackage.eINSTANCE.functionTypeDeclaration, FunctionOrReductionValidator::FUNCTION_RETURN_TYPE, getTypeMsg("int", "real")) + module.assertError(NablaPackage.eINSTANCE.functionReturnTypeDeclaration, FunctionOrReductionValidator::FUNCTION_RETURN_TYPE, getTypeMsg("int", "real")) } @Test - def void testCheckFunctionReturnTypeVar() + def void testCheckFunctionReturnTypeDeclarationVar() { val modulekO = parseHelper.parse( ''' extension Test; - def f: x | real → real[x]; + def real[x] f(real a); ''') Assert.assertNotNull(modulekO) - modulekO.assertError(NablaPackage.eINSTANCE.functionTypeDeclaration, + modulekO.assertError(NablaPackage.eINSTANCE.functionReturnTypeDeclaration, FunctionOrReductionValidator::FUNCTION_RETURN_TYPE_VAR, - FunctionOrReductionValidator::getFunctionReturnTypeVarMsg("x")) + FunctionOrReductionValidator::getFunctionReturnTypeDeclarationVarMsg("x")) val moduleOk = parseHelper.parse( ''' extension Test; - def f: x | real[x] → real[x]; - def g: y | real[y] → real[x, y]; + def real[x] f(real[x] a); + def real[x, y] g(real[y] a); ''') Assert.assertNotNull(moduleOk) - moduleOk.assertNoErrors(NablaPackage.eINSTANCE.functionTypeDeclaration, FunctionOrReductionValidator::FUNCTION_RETURN_TYPE_VAR) + moduleOk.assertNoErrors(NablaPackage.eINSTANCE.functionReturnTypeDeclaration, FunctionOrReductionValidator::FUNCTION_RETURN_TYPE_VAR) } @Test @@ -290,8 +261,8 @@ class FunctionOrReductionValidatorTest val modulekO = parseHelper.parse( ''' extension Test; - def g, 0.0: real[2], (a, b) → return a; - def g, 0.0: x | real[x], (a, b) → return a; + red real[2] g(0.0) (a, b) : return a; + red real[x] g(0.0) (a, b) : return a; ''') Assert.assertNotNull(modulekO) modulekO.assertError(NablaPackage.eINSTANCE.reduction, @@ -301,8 +272,8 @@ class FunctionOrReductionValidatorTest val moduleOk = parseHelper.parse( ''' extension Test; - def g, 0.0: real, (a, b) → return a; - def g, 0.0: x | real[x], (a, b) → return a; + red real g(0.0) (a, b) : return a; + red real[x] g(0.0) (a, b) : return a; ''') Assert.assertNotNull(moduleOk) moduleOk.assertNoErrors @@ -314,8 +285,8 @@ class FunctionOrReductionValidatorTest val moduleKo = parseHelper.parse( ''' extension Test; - def sum1, [0.0, 0.0]: real[2], (a, b) → return a + b; - def sum1, 0.0: int, (a, b) → return a + b; + red real[2] sum1([0.0, 0.0]) (a, b) : return a + b; + red int sum1(0.0) (a, b) : return a + b; ''') Assert.assertNotNull(moduleKo) @@ -330,8 +301,8 @@ class FunctionOrReductionValidatorTest val moduleOk = parseHelper.parse( ''' extension Test; - def sum1, 0.0: real[2], (a, b) → return a + b; - def sum1, 0: int, (a, b) → return a + b; + red real[2] sum1(0.0) (a, b) : return a + b; + red int sum1(0) (a, b) : return a + b; ''') Assert.assertNotNull(moduleOk) moduleOk.assertNoErrors diff --git a/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/validation/InstructionValidatorTest.xtend b/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/validation/InstructionValidatorTest.xtend index 180bcb4f9..04a384421 100644 --- a/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/validation/InstructionValidatorTest.xtend +++ b/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/validation/InstructionValidatorTest.xtend @@ -88,7 +88,7 @@ class InstructionValidatorTest UpdateX: { real[2] a{nodes}; - ∀r∈nodes(), X{r} = a{r}; + forall r in nodes(), X{r} = a{r}; } ''', rs) Assert.assertNotNull(moduleKo) @@ -103,7 +103,7 @@ class InstructionValidatorTest UpdateX: { real[2] a; - ∀r∈nodes(), X{r} = a; + forall r in nodes(), X{r} = a; } ''', rs) Assert.assertNotNull(moduleOk) @@ -120,7 +120,7 @@ class InstructionValidatorTest «testModule» int U{cells}; int V{nodes}; - ComputeU: ∀ j∈cells(), { + ComputeU: forall j in cells(), { let real e = 1.0; U{j} = e * 4; } @@ -143,11 +143,11 @@ class InstructionValidatorTest «testModule» int U{cells}; int V{cells}; - ComputeU: ∀ j∈cells(), { + ComputeU: forall j in cells(), { let int e = 1; U{j} = e * 4; } - ComputeV: ∀ j∈cells(), V{j} = U{j}; + ComputeV: forall j in cells(), V{j} = U{j}; ''', rs) Assert.assertNotNull(moduleOk) moduleOk.assertNoErrors @@ -221,9 +221,9 @@ class InstructionValidatorTest val moduleKo2 = parseHelper.parse( ''' «emptyTestModule» - def mySum, 0: int, (a, b) → return a + b; + red mySum(0) (a, b) : return a + b; let int[3] coef = [2, 3, 4]; - let int c = mySum{k∈[0;3[}(coef[k]); + let int c = mySum{k in [0;3[}(coef[k]); ''') Assert.assertNotNull(moduleKo2) moduleKo2.assertError(NablaPackage.eINSTANCE.simpleVarDeclaration, diff --git a/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/validation/NablagenValidatorTest.xtend b/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/validation/NablagenValidatorTest.xtend index 59786dd03..a02baecaa 100644 --- a/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/validation/NablagenValidatorTest.xtend +++ b/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/validation/NablagenValidatorTest.xtend @@ -53,9 +53,9 @@ class NablagenValidatorTest iterate n while (n+1 < maxIter && t^{n+1} < maxTime); - Hj1: ∀c∈cells(), hv3{c} = hv2{c}; - Hj2: ∀c∈cells(), hv5{c} = hv3{c}; - Hj3: ∀c∈cells(), hv7{c} = hv4{c} + hv5{c} + hv6{c}; + Hj1: forall c in cells(), hv3{c} = hv2{c}; + Hj2: forall c in cells(), hv5{c} = hv3{c}; + Hj3: forall c in cells(), hv7{c} = hv4{c} + hv5{c} + hv6{c}; ''' val nablaRemapModel = @@ -67,8 +67,8 @@ class NablagenValidatorTest real[2] X{nodes}; real rv1{cells}, rv2{cells}, rv3{cells}; - Rj1: ∀c∈cells(), rv2{c} = rv1{c}; - Rj2: ∀c∈cells(), rv3{c} = rv2{c}; + Rj1: forall c in cells(), rv2{c} = rv1{c}; + Rj2: forall c in cells(), rv3{c} = rv2{c}; ''' val ngenModel = @@ -210,7 +210,7 @@ class NablagenValidatorTest val batiLibModel = ''' extension BatiLib; - def nextWaveHeight: → real; + def real nextWaveHeight(); ''' val depthInitModel = ''' @@ -226,7 +226,7 @@ class NablagenValidatorTest real[2] X{nodes}; real nu{cells}; - InitFromFile: ∀j∈cells(), nu{j} = nextWaveHeight(); + InitFromFile: forall j in cells(), nu{j} = nextWaveHeight(); ''' val appNgenModel = ''' @@ -283,8 +283,8 @@ class NablagenValidatorTest itemtypes { node, cell } - connectivity nodes: → {node}; - connectivity cells: → {cell}; + connectivity {node} nodes(); + connectivity {cell} cells(); ''' val rs = resourceSetProvider.get diff --git a/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/validation/UniqueNameValidatorTest.xtend b/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/validation/UniqueNameValidatorTest.xtend index c57024955..12fc8ccfa 100644 --- a/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/validation/UniqueNameValidatorTest.xtend +++ b/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/validation/UniqueNameValidatorTest.xtend @@ -40,7 +40,7 @@ class UniqueNameValidatorTest val rootKo = parseHelper.parse( ''' extension Test; - def f: int × int → int, (a, a) → { return a; } + def int f(int a, int a) { return a; } ''') Assert.assertNotNull(rootKo) rootKo.assertError(NablaPackage.eINSTANCE.arg, @@ -50,7 +50,7 @@ class UniqueNameValidatorTest val rootOk = parseHelper.parse( ''' extension Test; - def f: int × int → int, (a, b) → { return a; } + def int f(int a, int b) { return a; } ''') Assert.assertNotNull(rootOk) rootOk.assertNoErrors @@ -114,7 +114,7 @@ class UniqueNameValidatorTest val rootKo1 = parseHelper.parse( ''' «model» - J1: ∀r∈nodes(), ∀r∈nodes(), let d = XXX{r, r} * 2.0; + J1: forall r in nodes(), forall r in nodes(), let d = XXX{r, r} * 2.0; ''', rs) Assert.assertNotNull(rootKo1) rootKo1.assertError(NablaPackage.eINSTANCE.spaceIterator, @@ -124,7 +124,7 @@ class UniqueNameValidatorTest val rootOk = parseHelper.parse( ''' «model» - J1: ∀r1∈nodes(), ∀r2∈nodes(), let real d = XXX{r1, r2} * 2.0; + J1: forall r1 in nodes(), forall r2 in nodes(), let real d = XXX{r1, r2} * 2.0; ''', rs) Assert.assertNotNull(rootOk) rootOk.assertNoErrors @@ -154,7 +154,7 @@ class UniqueNameValidatorTest real X{nodes, nodes}; J1: { set myNodes = nodes(); - ∀r1∈myNodes, ∀r2∈myNodes, let real d = X{r1, r2} * 2.0; + forall r1 in myNodes, forall r2 in myNodes, let real d = X{r1, r2} * 2.0; } ''', rs) Assert.assertNotNull(rootOk) @@ -168,7 +168,7 @@ class UniqueNameValidatorTest ''' mesh extension Test; itemtypes { node, node } - connectivity nodes: → {node}; + connectivity {node} nodes(); ''') Assert.assertNotNull(rootKo) rootKo.assertError(NablaPackage.eINSTANCE.itemType, @@ -179,7 +179,7 @@ class UniqueNameValidatorTest ''' mesh extension Test; itemtypes { node } - connectivity nodes: → {node}; + connectivity {node} nodes(); ''') Assert.assertNotNull(rootOk) rootOk.assertNoErrors @@ -192,8 +192,8 @@ class UniqueNameValidatorTest ''' mesh extension Test; itemtypes { node } - connectivity nodes: → {node}; - connectivity nodes: → {node}; + connectivity {node} nodes(); + connectivity {node} nodes(); ''') Assert.assertNotNull(rootKo) rootKo.assertError(NablaPackage.eINSTANCE.connectivity, @@ -204,7 +204,7 @@ class UniqueNameValidatorTest ''' mesh extension Test; itemtypes { node } - connectivity nodes: → {node}; + connectivity {node} nodes(); ''') Assert.assertNotNull(rootOk) rootOk.assertNoErrors diff --git a/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/validation/UnusedValidatorTest.xtend b/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/validation/UnusedValidatorTest.xtend index e0be718e7..ae399f078 100644 --- a/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/validation/UnusedValidatorTest.xtend +++ b/tests/fr.cea.nabla.tests/src/fr/cea/nabla/tests/validation/UnusedValidatorTest.xtend @@ -93,7 +93,7 @@ class UnusedValidatorTest ''' «emptyTestModule» with CartesianMesh2D.*; - UpdateX: ∀r1∈nodes(), ∀r2∈nodes(), X{r1} = X{r1} + 1; + UpdateX: forall r1 in nodes(), forall r2 in nodes(), X{r1} = X{r1} + 1; ''', rs) Assert.assertNotNull(moduleKo1) moduleKo1.assertWarning(NablaPackage.eINSTANCE.spaceIterator, @@ -105,7 +105,7 @@ class UnusedValidatorTest «emptyTestModule» with CartesianMesh2D.*; real[2] X{nodes}; - UpdateX: ∀r1∈nodes(), ∀r2∈topLeftNode(), X{r1} = X{r1} + 1; + UpdateX: forall r1 in nodes(), forall r2 in topLeftNode(), X{r1} = X{r1} + 1; ''', rs) Assert.assertNotNull(moduleKo1) moduleKo2.assertWarning(NablaPackage.eINSTANCE.spaceIterator, @@ -117,7 +117,7 @@ class UnusedValidatorTest «emptyTestModule» with CartesianMesh2D.*; real[2] X{nodes}; - UpdateX: ∀r1∈nodes(), X{r1} = X{r1} + 1; + UpdateX: forall r1 in nodes(), X{r1} = X{r1} + 1; ''', rs) Assert.assertNotNull(moduleOk) moduleOk.assertNoIssues @@ -139,7 +139,7 @@ class UnusedValidatorTest «model» UpdateX: { set myNodes = nodes(); - ∀r1∈nodes(), X{r1} = X{r1} + 1; + forall r1 in nodes(), X{r1} = X{r1} + 1; } ''', rs) Assert.assertNotNull(moduleKo) @@ -152,7 +152,7 @@ class UnusedValidatorTest «model» UpdateX: { set myNodes = nodes(); - ∀r1∈myNodes, X{r1} = X{r1} + 1; + forall r1 in myNodes, X{r1} = X{r1} + 1; } ''', rs) Assert.assertNotNull(moduleOk) @@ -165,7 +165,7 @@ class UnusedValidatorTest val modelKo = ''' «emptyTestModule» - def f: x | real[x] → real, (a) → return 1.0; + def real f(real[x] a) return 1.0; let real[2] orig = [0.0 , 0.0]; ''' val moduleKo = parseHelper.parse(modelKo) @@ -196,7 +196,7 @@ class UnusedValidatorTest ''' «emptyTestModule» with CartesianMesh2D.*; - def sum, 0.0: real[2], (a, b) → return a+b; + red real[2] sum(0.0) (a, b) : return a+b; let real[2] orig = [0.0 , 0.0]; real[2] X{nodes}; ''' @@ -212,7 +212,7 @@ class UnusedValidatorTest val moduleOk = parseHelper.parse( ''' «modelKo» - ComputeU: orig = sum{r∈nodes()}(X{r}); + ComputeU: orig = sum{r in nodes()}(X{r}); ''', rs) Assert.assertNotNull(moduleOk) moduleOk.assertNoIssues