Skip to content

Commit 7516d00

Browse files
authored
Merge pull request #8 from TimBellerby/pm0_4
Fixes to nhd statement
2 parents 04514da + b8a1500 commit 7516d00

File tree

8 files changed

+11886
-14
lines changed

8 files changed

+11886
-14
lines changed

examples/jacobi.pmm

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
An example of the use of the nhd statement to implement a stencil
3+
Solution of 2D heat equation by Jacobi iteration
4+
One boundary set to 1.0 - rest to 0.0
5+
*/
6+
tol=0.01
7+
for cell_pos in [1..10,1..10] {
8+
chan var cell=0.0
9+
over [0,]:cell=1.0
10+
print(cell_pos++cell)
11+
until invar err<tol {
12+
old_cell=cell
13+
nhd ortho[-1..1,-1..1] dcell of cell bounds EXCLUDED {
14+
cell=(dcell[-1,0]+dcell[1,0]+dcell[0,-1]+dcell[0,1])/4.0
15+
}
16+
chan cell_err=abs(cell-old_cell)
17+
err=reduce%($max,cell_err,0.0)
18+
if cell_pos==[1,1]:print("err="++err)
19+
}
20+
print(cell_pos++"="++cell)
21+
}

examples/jacobi_cyclic_bounds.pmm

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
An example of the use of the nhd statement to implement a stencil
3+
Solution of 2D heat equation by Jacobi iteration on a cylinder
4+
One boundary set to 1.0 with the opposite set to 0.0
5+
Boundaries along the other dimension are cyclic
6+
*/
7+
tol=0.01
8+
for cell_pos in [1..10,1..10] {
9+
chan var cell=0.0
10+
over [0,]:cell=1.0
11+
print(cell_pos++cell)
12+
until invar err<tol {
13+
old_cell=cell
14+
nhd ortho[-1..1,-1..1] dcell of cell bounds [EXCLUDED,CYCLE] {
15+
cell=(dcell[-1,0]+dcell[1,0]+dcell[0,-1]+dcell[0,1])/4.0
16+
}
17+
chan cell_err=abs(cell-old_cell)
18+
err=reduce%($max,cell_err,0.0)
19+
if cell_pos==[1,1]:print("err="++err)
20+
}
21+
print(cell_pos++"="++cell)
22+
}

src/cfortran.f90

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4977,9 +4977,18 @@ subroutine out_simple_scalar(g,str,l,n,x)
49774977
character(len=*),intent(in):: str
49784978
integer,intent(in):: l
49794979
integer,intent(in),optional:: n,x
4980-
integer:: arg1
4980+
integer:: arg1,ve
4981+
ve=g%codes(l+comp_op_arg0)
49814982
arg1=g%codes(l+comp_op_arg0+1)
4982-
if(.not.g_is_shared(g,arg1)) call gen_loop(g,l,.false.)
4983+
if(.not.g_is_shared(g,arg1)) then
4984+
call gen_loop(g,l,.false.)
4985+
else
4986+
! Close and re-open if statements
4987+
if(g%last_ve/=ve) then
4988+
call gen_if_nest(g,g%last_ve,ve)
4989+
g%last_ve=ve
4990+
endif
4991+
endif
49834992
if(g_kind(g,arg1)/=v_is_ctime_const) then
49844993
call out_simple(g,str,l,n,x)
49854994
endif

0 commit comments

Comments
 (0)