/[escript]/trunk/paso/src/SolverFCT_FluxControl.c
ViewVC logotype

Annotation of /trunk/paso/src/SolverFCT_FluxControl.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1363 - (hide annotations)
Mon Dec 17 03:42:03 2007 UTC (12 years, 10 months ago) by gross
File MIME type: text/plain
File size: 8304 byte(s)
initialization for FCT solver added.
1 gross 1361 /* $Id:$ */
2    
3     /*******************************************************
4     *
5     * Copyright 2007 by University of Queensland
6     *
7     * http://esscc.uq.edu.au
8     * Primary Business: Queensland, Australia
9     * Licensed under the Open Software License version 3.0
10     * http://www.opensource.org/licenses/osl-3.0.php
11     *
12     *******************************************************/
13    
14     /**************************************************************/
15    
16     /* Paso: FluxControl */
17    
18     /**************************************************************/
19    
20     /* Author: l.gross@uq.edu.au */
21    
22     /**************************************************************/
23    
24    
25     #include "Paso.h"
26     #include "SolverFCT.h"
27     #include "PasoUtil.h"
28    
29     #define FLUX_S(a,b) ((SIGN(a)+SIGN(b))/2.)
30     #define MINMOD(a,b) (FLUX_S(a,b)*MIN(ABS(a),ABS(b)))
31     #define SUPERBEE(a,b) (FLUX_S(a,b)*MAX(MIN(2*ABS(a),ABS(b)),MIN(ABS(a),2*ABS(b))))
32    
33     #define FLUX_L(a,b) SUPERBEE(a,b) /* alter for other flux limiter */
34    
35     #define FLUX_LIMITER(a) FLUX_L(a,1)
36    
37     /**************************************************************/
38    
39     /* adds A plus stabelising diffusion into the matrix B */
40    
41     /* d_ij=alpha*max(0,-a[i,j],-a[j,i]) */
42     /* b[i,j]+=alpha*(a[i,j]+d_ij) */
43     /* b[j,i]+=alpha*(a[j,i]+d_ij) */
44     /* b[i,i]-=alpha*d_ij */
45     /* b[j,j]-=alpha*d_ij */
46    
47 gross 1363 void Paso_FCTransportProblem_addAdvectivePart(Paso_FCTransportProblem * fc, double alpha) {
48 gross 1361 dim_t n,i;
49     index_t color, iptr_ij,j,iptr_ji;
50     register double d_ij;
51    
52     if (fc==NULL) return;
53 gross 1362 n=Paso_SystemMatrix_getTotalNumRows(fc->flux_matrix);
54 gross 1361
55     #pragma omp parallel private(color)
56     {
57     /* process main block */
58     for (color=0;color<fc->num_colors;++color) {
59     #pragma omp for private(i,iptr_ij,j,iptr_ji,d_ij) schedule(static)
60     for (i = 0; i < n; ++i) {
61     if (fc->colorOf[i]==color) {
62 gross 1362 for (iptr_ij=fc->flux_matrix->mainBlock->pattern->ptr[i];iptr_ij<fc->flux_matrix->mainBlock->pattern->ptr[i+1]; ++iptr_ij) {
63     j=fc->flux_matrix->mainBlock->pattern->index[iptr_ij];
64 gross 1361 if (i<j) {
65     /* find entry a[j,i] */
66 gross 1362 for (iptr_ji=fc->flux_matrix->mainBlock->pattern->ptr[i];iptr_ji<fc->flux_matrix->mainBlock->pattern->ptr[j+1]-1; ++iptr_ji) {
67     if (fc->flux_matrix->mainBlock->pattern->index[iptr_ji]==i) {
68     d_ij=(-alpha)*MIN3(0.,fc->flux_matrix->mainBlock->val[iptr_ij],fc->flux_matrix->mainBlock->val[iptr_ji]);
69 gross 1363 fc->transport_matrix->mainBlock->val[iptr_ij]+=alpha*fc->flux_matrix->mainBlock->val[iptr_ij]+d_ij;
70     fc->transport_matrix->mainBlock->val[iptr_ji]+=alpha*fc->flux_matrix->mainBlock->val[iptr_ji]+d_ij;
71     fc->transport_matrix->mainBlock->val[fc->main_iptr[i]]-=d_ij;
72     fc->transport_matrix->mainBlock->val[fc->main_iptr[j]]-=d_ij;
73 gross 1361 break;
74     }
75     }
76     }
77    
78     }
79     /* TODO process couple block */
80     }
81     }
82     #pragma omp barrier
83     }
84     }
85    
86     }
87     /**************************************************************/
88    
89     /* adds antidiffusion to fa
90    
91     P_p[i] + = sum_j min(0,a[i,j]) min(0,u[j]-u[i])
92     P_n[i] + = sum_j min(0,a[i,j]) max(0,u[j]-u[i])
93     Q_p[i] + = sum_j max(0,a[i,j]) max(0,u[j]-u[i])
94     Q_n[i] + = sum_j max(0,a[i,j]) min(0,u[j]-u[i])
95     d_ij=max(0,-a[i,j],-a[j,i])
96     l_ji=max(0,a[j,i],a[j,i]-a[i,j])
97     if a[j,i] >= a[i,j] and 0>a[i,j] : (i.e d_ij>0 and l_ji>=l_ij)
98     r_ij = u[i]>u[j] ? Q_p[i]/P_p[i] : Q_n[i]/Q_n[i]
99     f_ij =min(FLUX_LIMITER(r_ij)*d_ij,l_ji) (u[i]-u[j])=min(FLUX_LIMITER(r_ij)*a[i,j],a[j,i]-a[i,j]) (u[i]-u[j])
100     fa[i]+=f_ij
101     fa[j]-=f_ij
102    
103     */
104    
105 gross 1362 void Paso_FCTransportProblem_setAntiDiffusiveFlux(Paso_FCTransportProblem * fc, double * u, double* fa) {
106 gross 1361
107     register double u_i,P_p,P_n,Q_p,Q_n,r_p,r_n, a_ij, d, u_j, r_ij, f_ij, a_ji;
108     double *u_remote=NULL;
109     index_t color, iptr_ij,j,iptr_ji, i;
110     dim_t n;
111    
112    
113     if (fc==NULL) return;
114 gross 1362 n=Paso_SystemMatrix_getTotalNumRows(fc->flux_matrix);
115 gross 1361 /* exchange */
116 gross 1362 Paso_SystemMatrix_allocBuffer(fc->flux_matrix);
117     Paso_SystemMatrix_startCollect(fc->flux_matrix,u);
118     u_remote=Paso_SystemMatrix_finishCollect(fc->flux_matrix);
119 gross 1361
120     #pragma omp parallel private(color)
121     {
122     for (color=0;color<fc->num_colors;++color) {
123     #pragma omp for schedule(static) private(i, u_i,P_p,P_n,Q_p,Q_n,r_p,r_n,iptr_ij,a_ij,d,j,iptr_ji, u_j, r_ij, f_ij, a_ji)
124     for (i = 0; i < n; ++i) {
125     if (fc->colorOf[i]==color) {
126     u_i=u[i];
127     /* gather the smoothness sensor */
128     P_p=0.;
129     P_n=0.;
130     Q_p=0.;
131     Q_n=0.;
132     #pragma ivdep
133 gross 1362 for (iptr_ij=(fc->flux_matrix->mainBlock->pattern->ptr[i]);iptr_ij<(fc->flux_matrix->mainBlock->pattern->ptr[i+1]); ++iptr_ij) {
134     a_ij=fc->flux_matrix->mainBlock->val[iptr_ij];
135     j=fc->flux_matrix->mainBlock->pattern->index[iptr_ij];
136 gross 1361 d=u[j]-u_i;
137     if (a_ij<0.) {
138     if (d<0.) {
139     P_p+=a_ij*d;
140     } else {
141     P_n+=a_ij*d;
142     }
143     } else {
144     if (d>0.) {
145     Q_p+=a_ij*d;
146     } else {
147     Q_n+=a_ij*d;
148     }
149     }
150     }
151     #pragma ivdep
152 gross 1362 for (iptr_ij=(fc->flux_matrix->coupleBlock->pattern->ptr[i]);iptr_ij<(fc->flux_matrix->coupleBlock->pattern->ptr[i+1]); ++iptr_ij) {
153     a_ij=fc->flux_matrix->coupleBlock->val[iptr_ij];
154     j=fc->flux_matrix->coupleBlock->pattern->index[iptr_ij];
155 gross 1361 d=u_remote[j]-u_i;
156     if (a_ij<0.) {
157     if (d<0.) {
158     P_p+=a_ij*d;
159     } else {
160     P_n+=a_ij*d;
161     }
162     } else {
163     if (d>0.) {
164     Q_p+=a_ij*d;
165     } else {
166     Q_n+=a_ij*d;
167     }
168     }
169     }
170     /* set the smoothness indicators */
171     r_p = (P_p > 0.) ? FLUX_LIMITER(Q_p/P_p) : 0.;
172     r_n = (P_n < 0 ) ? FLUX_LIMITER(Q_n/P_n) : 0.;
173     /* anti diffusive flux from main block */
174 gross 1362 for (iptr_ij=fc->flux_matrix->mainBlock->pattern->ptr[i];iptr_ij<fc->flux_matrix->mainBlock->pattern->ptr[i+1]; ++iptr_ij) {
175     a_ij=fc->flux_matrix->mainBlock->val[iptr_ij];
176     j=fc->flux_matrix->mainBlock->pattern->index[iptr_ij];
177 gross 1361 if (a_ij < 0 && i!=j) {
178     /* find entry a[j,i] */
179 gross 1362 for (iptr_ji=fc->flux_matrix->mainBlock->pattern->ptr[i];iptr_ji<fc->flux_matrix->mainBlock->pattern->ptr[j+1]-1; ++iptr_ji) {
180     if (fc->flux_matrix->mainBlock->pattern->index[iptr_ji]==i) {
181     a_ji=fc->flux_matrix->mainBlock->val[iptr_ji];
182 gross 1361 if (a_ji > a_ij || (a_ji == a_ij && j<i) ) {
183     u_j=u[j];
184     r_ij = u_i>u_j ? r_p : r_n;
185     f_ij =MIN(r_ij*a_ij,a_ji-a_ij)*(u_i-u_j);
186     fa[i]+=f_ij;
187     fa[j]-=f_ij;
188     break;
189     }
190     }
191     }
192     }
193     }
194     /* anti diffusive flux from couple block */
195    
196     /* TODO */
197     }
198     }
199     #pragma omp barrier
200     }
201     }
202     }

  ViewVC Help
Powered by ViewVC 1.1.26