- Thank you received: 3
Recent change to realcompile for CoefficientFunction?
2 years 9 months ago #4238
by ddrake
Recent change to realcompile for CoefficientFunction? was created by ddrake
Hi,
One of our scripts which worked with the source from a few weeks ago uses the 'realcompile' option when compiling some of the CoefficientFunctions. It's failing with a build from today's NGSolve source commit d4e8d53b0. This simplified script below reproduces the issue (I didn't seem to be able to attach and the code button strips indentation in this form so I'm just pasting it here).
from ngsolve import IfPos
import ngsolve as ng
from ngsolve.meshes import Make1DMesh
realcompile = False
N = 10
h = 1/N
p = 1
def ngabs(cf):
return IfPos(cf, cf, -cf)
def ngmax(cf1, cf2):
return IfPos(cf1-cf2, cf1, cf2)
def ngsgn(cf):
return IfPos(cf, 1, -1
mesh = Make1DMesh(N)
A = ng.L2(mesh, order=p, all_dofs_together=True)
alpha, beta = A.TnT()
drag = ngabs(alpha)
Ddrag = ngsgn(alpha)
tr = ngabs(Ddrag)
drago = ngabs(alpha.Other(bnd=0))
Ddrago = ngsgn(alpha.Other(bnd=0))
tro = ngabs(Ddrago)
c = 0.002 * ngmax(ngabs(tr), ngabs(tro))
n = ng.specialcf.normal(mesh.dim)
nf = 0.000002 * n * (drag + drago)
nf += 0.001 * c * (alpha.Other(bnd=0) - alpha)
if realcompile:
nf1 = nf.Compile(True, wait=True)
else:
nf1 = nf.Compile()
print(nf1)
If we set the 'realcompile' flag above to False, we can print the CoefficientFunction, and the code works correctly, but if 'realcompile' is True, we get this error:
/tmp/ngsolve_tmp_0_4_HftgJN/code_0.cpp:108:70: error: use of undeclared identifier 'var_0'
auto var_1 = (0x1.0c6f7a0b5ed8dp-19 /* (1.9999999999999999e-06) */ * var_0);
^
/tmp/ngsolve_tmp_0_4_HftgJN/code_0.cpp:300:70: error: use of undeclared identifier 'var_0'
auto var_1 = (0x1.0c6f7a0b5ed8dp-19 /* (1.9999999999999999e-06) */ * var_0);
^
/tmp/ngsolve_tmp_0_4_HftgJN/code_0.cpp:456:70: error: use of undeclared identifier 'var_0'
auto var_1 = (0x1.0c6f7a0b5ed8dp-19 /* (1.9999999999999999e-06) */ * var_0);
^
/tmp/ngsolve_tmp_0_4_HftgJN/code_0.cpp:652:70: error: use of undeclared identifier 'var_0'
auto var_1 = (0x1.0c6f7a0b5ed8dp-19 /* (1.9999999999999999e-06) */ * var_0);
^
/tmp/ngsolve_tmp_0_4_HftgJN/code_0.cpp:816:70: error: use of undeclared identifier 'var_0'
auto var_1 = (0x1.0c6f7a0b5ed8dp-19 /* (1.9999999999999999e-06) */ * var_0);
^
/tmp/ngsolve_tmp_0_4_HftgJN/code_0.cpp:1016:70: error: use of undeclared identifier 'var_0'
auto var_1 = (0x1.0c6f7a0b5ed8dp-19 /* (1.9999999999999999e-06) */ * var_0);
In case it helps, here is the output of print(nf1):
Compiled CF:
Step 0: normal vector
Step 1: scale 2e-06
input: 0
Step 2: trial-function diffop = Id
Step 3: scale -1
input: 2
Step 4: N5ngfem24IfPosCoefficientFunctionE
input: 2 2 3
Step 5: trial-function diffop = Id
Step 6: scale -1
input: 5
Step 7: N5ngfem24IfPosCoefficientFunctionE
input: 5 5 6
Step 8: binary operation '+'
input: 4 7
Step 9: binary operation '*'
input: 1 8
Step 10: 1
Step 11: -1
Step 12: N5ngfem24IfPosCoefficientFunctionE
input: 2 10 11
Step 13: scale -1
input: 12
Step 14: N5ngfem24IfPosCoefficientFunctionE
input: 12 12 13
Step 15: scale -1
input: 14
Step 16: N5ngfem24IfPosCoefficientFunctionE
input: 14 14 15
Step 17: trial-function diffop = Id
Step 18: 1
Step 19: -1
Step 20: N5ngfem24IfPosCoefficientFunctionE
input: 17 18 19
Step 21: scale -1
input: 20
Step 22: N5ngfem24IfPosCoefficientFunctionE
input: 20 20 21
Step 23: scale -1
input: 22
Step 24: N5ngfem24IfPosCoefficientFunctionE
input: 22 22 23
Step 25: binary operation '-'
input: 16 24
Step 26: N5ngfem24IfPosCoefficientFunctionE
input: 25 16 24
Step 27: scale 0.002
input: 26
Step 28: scale 0.001
input: 27
Step 29: trial-function diffop = Id
Step 30: binary operation '-'
input: 29 2
Step 31: binary operation '*'
input: 28 30
Step 32: binary operation '+'
input: 9 31
Thanks!
Dow
One of our scripts which worked with the source from a few weeks ago uses the 'realcompile' option when compiling some of the CoefficientFunctions. It's failing with a build from today's NGSolve source commit d4e8d53b0. This simplified script below reproduces the issue (I didn't seem to be able to attach and the code button strips indentation in this form so I'm just pasting it here).
from ngsolve import IfPos
import ngsolve as ng
from ngsolve.meshes import Make1DMesh
realcompile = False
N = 10
h = 1/N
p = 1
def ngabs(cf):
return IfPos(cf, cf, -cf)
def ngmax(cf1, cf2):
return IfPos(cf1-cf2, cf1, cf2)
def ngsgn(cf):
return IfPos(cf, 1, -1
mesh = Make1DMesh(N)
A = ng.L2(mesh, order=p, all_dofs_together=True)
alpha, beta = A.TnT()
drag = ngabs(alpha)
Ddrag = ngsgn(alpha)
tr = ngabs(Ddrag)
drago = ngabs(alpha.Other(bnd=0))
Ddrago = ngsgn(alpha.Other(bnd=0))
tro = ngabs(Ddrago)
c = 0.002 * ngmax(ngabs(tr), ngabs(tro))
n = ng.specialcf.normal(mesh.dim)
nf = 0.000002 * n * (drag + drago)
nf += 0.001 * c * (alpha.Other(bnd=0) - alpha)
if realcompile:
nf1 = nf.Compile(True, wait=True)
else:
nf1 = nf.Compile()
print(nf1)
If we set the 'realcompile' flag above to False, we can print the CoefficientFunction, and the code works correctly, but if 'realcompile' is True, we get this error:
/tmp/ngsolve_tmp_0_4_HftgJN/code_0.cpp:108:70: error: use of undeclared identifier 'var_0'
auto var_1 = (0x1.0c6f7a0b5ed8dp-19 /* (1.9999999999999999e-06) */ * var_0);
^
/tmp/ngsolve_tmp_0_4_HftgJN/code_0.cpp:300:70: error: use of undeclared identifier 'var_0'
auto var_1 = (0x1.0c6f7a0b5ed8dp-19 /* (1.9999999999999999e-06) */ * var_0);
^
/tmp/ngsolve_tmp_0_4_HftgJN/code_0.cpp:456:70: error: use of undeclared identifier 'var_0'
auto var_1 = (0x1.0c6f7a0b5ed8dp-19 /* (1.9999999999999999e-06) */ * var_0);
^
/tmp/ngsolve_tmp_0_4_HftgJN/code_0.cpp:652:70: error: use of undeclared identifier 'var_0'
auto var_1 = (0x1.0c6f7a0b5ed8dp-19 /* (1.9999999999999999e-06) */ * var_0);
^
/tmp/ngsolve_tmp_0_4_HftgJN/code_0.cpp:816:70: error: use of undeclared identifier 'var_0'
auto var_1 = (0x1.0c6f7a0b5ed8dp-19 /* (1.9999999999999999e-06) */ * var_0);
^
/tmp/ngsolve_tmp_0_4_HftgJN/code_0.cpp:1016:70: error: use of undeclared identifier 'var_0'
auto var_1 = (0x1.0c6f7a0b5ed8dp-19 /* (1.9999999999999999e-06) */ * var_0);
In case it helps, here is the output of print(nf1):
Compiled CF:
Step 0: normal vector
Step 1: scale 2e-06
input: 0
Step 2: trial-function diffop = Id
Step 3: scale -1
input: 2
Step 4: N5ngfem24IfPosCoefficientFunctionE
input: 2 2 3
Step 5: trial-function diffop = Id
Step 6: scale -1
input: 5
Step 7: N5ngfem24IfPosCoefficientFunctionE
input: 5 5 6
Step 8: binary operation '+'
input: 4 7
Step 9: binary operation '*'
input: 1 8
Step 10: 1
Step 11: -1
Step 12: N5ngfem24IfPosCoefficientFunctionE
input: 2 10 11
Step 13: scale -1
input: 12
Step 14: N5ngfem24IfPosCoefficientFunctionE
input: 12 12 13
Step 15: scale -1
input: 14
Step 16: N5ngfem24IfPosCoefficientFunctionE
input: 14 14 15
Step 17: trial-function diffop = Id
Step 18: 1
Step 19: -1
Step 20: N5ngfem24IfPosCoefficientFunctionE
input: 17 18 19
Step 21: scale -1
input: 20
Step 22: N5ngfem24IfPosCoefficientFunctionE
input: 20 20 21
Step 23: scale -1
input: 22
Step 24: N5ngfem24IfPosCoefficientFunctionE
input: 22 22 23
Step 25: binary operation '-'
input: 16 24
Step 26: N5ngfem24IfPosCoefficientFunctionE
input: 25 16 24
Step 27: scale 0.002
input: 26
Step 28: scale 0.001
input: 27
Step 29: trial-function diffop = Id
Step 30: binary operation '-'
input: 29 2
Step 31: binary operation '*'
input: 28 30
Step 32: binary operation '+'
input: 9 31
Thanks!
Dow
2 years 9 months ago #4239
by joachim
Replied by joachim on topic Recent change to realcompile for CoefficientFunction?
Hi Drake,
the code-generation distinguishes now between scalars, vectors, and higher order tensors.
The 1D normal vector was inconsistently treated as scalar, or as vector (of length 1) which confused the codegeneration.
It is fixed (to be a vector) and will be in the coming nightly release.
Thx for reporting,
Joachim
the code-generation distinguishes now between scalars, vectors, and higher order tensors.
The 1D normal vector was inconsistently treated as scalar, or as vector (of length 1) which confused the codegeneration.
It is fixed (to be a vector) and will be in the coming nightly release.
Thx for reporting,
Joachim
The following user(s) said Thank You: ddrake
Time to create page: 0.128 seconds