print code gen report option, multiple argument function call, masked fsd terms

This commit is contained in:
ignis 2019-06-13 20:52:33 +09:00
parent 091a902965
commit a0a87baeb8
5 changed files with 3231 additions and 259 deletions

View file

@ -6,6 +6,7 @@ import argparse
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("term_file", help="name of file containing postprocessing term spec") parser.add_argument("term_file", help="name of file containing postprocessing term spec")
parser.add_argument("-b", "--build-info", action="store_true", help="print build_info instead of code") parser.add_argument("-b", "--build-info", action="store_true", help="print build_info instead of code")
parser.add_argument("-p", "--print_report", action="store_true", help="print code generation report instead of code")
args = parser.parse_args() args = parser.parse_args()
from lark import Lark, Visitor, Transformer, v_args, Token from lark import Lark, Visitor, Transformer, v_args, Token
@ -38,7 +39,7 @@ calc_grammar = """
| "$" NAME -> env | "$" NAME -> env
| "(" sum ")" | "(" sum ")"
| inlinefunc "(" sum ")" -> icall | inlinefunc "(" sum ")" -> icall
| mathfunc "(" sum ")" -> fcall | mathfunc "(" sum ("," sum)* ")" -> fcall
| derivative "(" NAME ")" -> dnx | derivative "(" NAME ")" -> dnx
avg: "avg" [NAME] avg: "avg" [NAME]
@ -106,7 +107,7 @@ class VersionInfo(object):
def test(terms_raw): def test(terms_raw, report=False):
tree = Lark(calc_grammar, parser='lalr' ).parse(terms_raw) tree = Lark(calc_grammar, parser='lalr' ).parse(terms_raw)
@ -120,9 +121,10 @@ def test(terms_raw):
cdict = ir4.print_program() cdict = ir4.print_program()
print mod_form.format( cdict ) if not report:
print mod_form.format( cdict )
# ir4.save_ir() else:
ir4.save_ir()
@ -142,4 +144,4 @@ if __name__ == '__main__':
if args.build_info: if args.build_info:
build_info(terms_raw) build_info(terms_raw)
else: else:
test(terms_raw) test(terms_raw, args.print_report)

View file

@ -106,7 +106,9 @@ class ExpToCode(Transformer):
fcode = "({0})".format(b) fcode = "({0})".format(b)
return fcode return fcode
def fcall (self, a, b): def fcall (self, *args):
a = args[0]
b = ", ".join(args[1:])
fcode = "( {} ( {} ) )".format(a, b) fcode = "( {} ( {} ) )".format(a, b)
return fcode return fcode

View file

@ -3,10 +3,30 @@
c = 1.0 - y c = 1.0 - y
wrate = rxn_rate(c) wrate = rxn_rate(c)
mask = $threshold_min_max(c) mask1 = $threshold_min_max(c, 0.05, 0.15)
mask2 = $threshold_min_max(c, 0.15, 0.25)
mask3 = $threshold_min_max(c, 0.25, 0.35)
mask4 = $threshold_min_max(c, 0.35, 0.45)
mask5 = $threshold_min_max(c, 0.45, 0.55)
mask6 = $threshold_min_max(c, 0.55, 0.65)
mask7 = $threshold_min_max(c, 0.65, 0.75)
mask8 = $threshold_min_max(c, 0.75, 0.85)
mask9 = $threshold_min_max(c, 0.85, 0.95)
fsd_orig = sqrt (sqr(ddx(c)) + sqr(ddy(c)) + sqr(ddz(c))) fsd_orig = sqrt (sqr(ddx(c)) + sqr(ddy(c)) + sqr(ddz(c)))
fsd = fsd_orig * mask fsd = fsd_orig * mask
fsd1 = fsd_orig * mask1
fsd2 = fsd_orig * mask2
fsd3 = fsd_orig * mask3
fsd4 = fsd_orig * mask4
fsd5 = fsd_orig * mask5
fsd6 = fsd_orig * mask6
fsd7 = fsd_orig * mask7
fsd8 = fsd_orig * mask8
fsd9 = fsd_orig * mask9
sd = ((d2dx(c) + d2dy(c) + d2dz(c)) * $rod + wrate) / fsd_orig sd = ((d2dx(c) + d2dy(c) + d2dz(c)) * $rod + wrate) / fsd_orig
nx = - ddx(c) / fsd_orig nx = - ddx(c) / fsd_orig
@ -37,6 +57,16 @@ t7 = sqr(divn')
t8 = sqr(absk') t8 = sqr(absk')
avg { c, u, v, w, fsd, lapc, ddx_c, ddy_c, ddz_c, d2dx_c, d2dy_c, d2dz_c } avg { c, u, v, w, fsd1, fsd2, fsd3, fsd4, fsd5, fsd6, fsd7, fsd8, fsd9, lapc, ddx_c, ddy_c, ddz_c, d2dx_c, d2dy_c, d2dz_c }
avg fsd1 { nx, ny, nz, t1, t2, t3, t4, t5, t6, t7, t8, absk, divn, sd }
avg fsd2 { nx, ny, nz, t1, t2, t3, t4, t5, t6, t7, t8, absk, divn, sd }
avg fsd3 { nx, ny, nz, t1, t2, t3, t4, t5, t6, t7, t8, absk, divn, sd }
avg fsd4 { nx, ny, nz, t1, t2, t3, t4, t5, t6, t7, t8, absk, divn, sd }
avg fsd5 { nx, ny, nz, t1, t2, t3, t4, t5, t6, t7, t8, absk, divn, sd }
avg fsd6 { nx, ny, nz, t1, t2, t3, t4, t5, t6, t7, t8, absk, divn, sd }
avg fsd7 { nx, ny, nz, t1, t2, t3, t4, t5, t6, t7, t8, absk, divn, sd }
avg fsd8 { nx, ny, nz, t1, t2, t3, t4, t5, t6, t7, t8, absk, divn, sd }
avg fsd9 { nx, ny, nz, t1, t2, t3, t4, t5, t6, t7, t8, absk, divn, sd }
avg fsd { u, v, w, nx, ny, nz, t1, t2, t3, t4, t5, t6, t7, t8, absk, divn, sd }

View file

@ -239,14 +239,11 @@ contains
end function rxn_rate end function rxn_rate
real function threshold_min_max (c) real function threshold_min_max (c, minc, maxc)
real :: c real :: c
real :: minc, maxc real :: minc, maxc
minc = 0.1
maxc = 0.9
if ((c.lt.minc) .or. (c.gt.maxc)) then if ((c.lt.minc) .or. (c.gt.maxc)) then
threshold_min_max = 0. threshold_min_max = 0.
else else

File diff suppressed because it is too large Load diff