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

Diff of /trunk/paso/src/SolverFCT.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1370 by gross, Wed Jan 2 09:21:43 2008 UTC revision 1804 by gross, Wed Sep 24 07:52:19 2008 UTC
# Line 30  Line 30 
30  /**************************************************************/  /**************************************************************/
31    
32  /* free all memory used by                                */  /* free all memory used by                                */
33    
34  void Paso_FCTransportProblem_free(Paso_FCTransportProblem* in) {  void Paso_FCTransportProblem_free(Paso_FCTransportProblem* in) {
35       if (in!=NULL) {       if (in!=NULL) {
36          in->reference_counter--;          in->reference_counter--;
37          if (in->reference_counter<=0) {          if (in->reference_counter<=0) {
   
38             Paso_SystemMatrix_free(in->transport_matrix);             Paso_SystemMatrix_free(in->transport_matrix);
39             Paso_SystemMatrix_free(in->flux_matrix);             Paso_SystemMatrix_free(in->mass_matrix);
40               Paso_SystemMatrix_free(in->iteration_matrix);
41             Paso_MPIInfo_free(in->mpi_info);             Paso_MPIInfo_free(in->mpi_info);
42               Paso_Coupler_free(in->u_coupler);
43             MEMFREE(in->u);             MEMFREE(in->u);
            MEMFREE(in->lumped_mass_matrix);  
            MEMFREE(in->row_sum_flux_matrix);  
            MEMFREE(in->transport_matrix_diagonal);  
            MEMFREE(in->colorOf);  
44             MEMFREE(in->main_iptr);             MEMFREE(in->main_iptr);
45               MEMFREE(in->lumped_mass_matrix);
46               MEMFREE(in->main_diagonal_low_order_transport_matrix);
47             MEMFREE(in);             MEMFREE(in);
48          }          }
49      }      }
# Line 60  Paso_FCTransportProblem* Paso_FCTranspor Line 59  Paso_FCTransportProblem* Paso_FCTranspor
59  Paso_SystemMatrix* Paso_FCTransportProblem_borrowTransportMatrix(Paso_FCTransportProblem* in) {  Paso_SystemMatrix* Paso_FCTransportProblem_borrowTransportMatrix(Paso_FCTransportProblem* in) {
60     return in->transport_matrix;     return in->transport_matrix;
61  }  }
62    Paso_SystemMatrix* Paso_FCTransportProblem_borrowMassMatrix(Paso_FCTransportProblem* in) {
63  Paso_SystemMatrix* Paso_FCTransportProblem_borrowFluxMatrix(Paso_FCTransportProblem* in) {     return in->mass_matrix;
     return in->flux_matrix;  
64  }  }
65    
66  double* Paso_FCTransportProblem_borrowLumpedMassMatrix(Paso_FCTransportProblem* in) {  double* Paso_FCTransportProblem_borrowLumpedMassMatrix(Paso_FCTransportProblem* in) {
# Line 73  dim_t Paso_FCTransportProblem_getTotalNu Line 71  dim_t Paso_FCTransportProblem_getTotalNu
71      return Paso_SystemMatrix_getTotalNumRows(in->transport_matrix);      return Paso_SystemMatrix_getTotalNumRows(in->transport_matrix);
72  }  }
73    
74  Paso_FCTransportProblem* Paso_FCTransportProblem_alloc(double theta, double dt_max, Paso_SystemMatrixPattern *pattern, int block_size  Paso_FCTransportProblem* Paso_FCTransportProblem_alloc(double theta, Paso_SystemMatrixPattern *pattern, int block_size)
75    {
   
 ) {  
76       Paso_SystemMatrixType matrix_type=MATRIX_FORMAT_DEFAULT+MATRIX_FORMAT_BLK1;  /* at the moment only block size 1 is supported */       Paso_SystemMatrixType matrix_type=MATRIX_FORMAT_DEFAULT+MATRIX_FORMAT_BLK1;  /* at the moment only block size 1 is supported */
77       Paso_FCTransportProblem* out=NULL;       Paso_FCTransportProblem* out=NULL;
78       dim_t n,i;       dim_t n,i;
79       index_t iptr,iptr_main,k;       index_t iptr,iptr_main;
80    
81       if ((theta<0.) || (theta >1.)) {       if ((theta<0.) || (theta >1.)) {
82          Paso_setError(TYPE_ERROR,"Paso_FCTransportProblem_alloc: theta needs to be between 0. and. 1.");          Paso_setError(TYPE_ERROR,"Paso_FCTransportProblem_alloc: theta needs to be between 0. and. 1.");
# Line 89  Paso_FCTransportProblem* Paso_FCTranspor Line 85  Paso_FCTransportProblem* Paso_FCTranspor
85    
86       out=MEMALLOC(1,Paso_FCTransportProblem);       out=MEMALLOC(1,Paso_FCTransportProblem);
87       if (Paso_checkPtr(out)) return NULL;       if (Paso_checkPtr(out)) return NULL;
88         out->reference_counter=0;
89       out->theta=theta;       out->theta=theta;
90       out->dt_max=dt_max;       out->dt_max=LARGE_POSITIVE_FLOAT;
91       out->valid_matrices=FALSE;       out->valid_matrices=FALSE;
92       out->transport_matrix=Paso_SystemMatrix_alloc(matrix_type,pattern,block_size,block_size);       out->transport_matrix=Paso_SystemMatrix_alloc(matrix_type,pattern,block_size,block_size);
93       Paso_SystemMatrix_allocBuffer(out->transport_matrix);       out->mass_matrix=Paso_SystemMatrix_alloc(matrix_type,pattern,block_size,block_size);
94       out->flux_matrix=Paso_SystemMatrix_alloc(matrix_type,pattern,block_size,block_size);       out->iteration_matrix=NULL;
95         out->u=NULL;
96       out->mpi_info=Paso_MPIInfo_getReference(pattern->mpi_info);       out->mpi_info=Paso_MPIInfo_getReference(pattern->mpi_info);
   
      out->colorOf=NULL;  
97       out->main_iptr=NULL;       out->main_iptr=NULL;
98       out->lumped_mass_matrix=NULL;       out->lumped_mass_matrix=NULL;
99       out->row_sum_flux_matrix=NULL;       out->main_diagonal_low_order_transport_matrix=NULL;
      out->transport_matrix_diagonal=NULL;  
100    
101       if (Paso_noError()) {       if (Paso_noError()) {
102           n=Paso_SystemMatrix_getTotalNumRows(out->transport_matrix);           n=Paso_SystemMatrix_getTotalNumRows(out->transport_matrix);
103    
104           out->colorOf=MEMALLOC(n,index_t);           out->u=MEMALLOC(n,double);
105           out->main_iptr=MEMALLOC(n,index_t);           out->main_iptr=MEMALLOC(n,index_t);
106           out->lumped_mass_matrix=MEMALLOC(n,double);           out->lumped_mass_matrix=MEMALLOC(n,double);
107           out->row_sum_flux_matrix=MEMALLOC(n,double);           out->main_diagonal_low_order_transport_matrix=MEMALLOC(n,double);
108           out->transport_matrix_diagonal=MEMALLOC(n,double);           out->u_coupler=Paso_Coupler_alloc(Paso_FCTransportProblem_borrowConnector(out),block_size);
          out->u=MEMALLOC(n,double);  
109    
110           if ( ! (Paso_checkPtr(out->colorOf) || Paso_checkPtr(out->main_iptr) ||           if ( ! (Paso_checkPtr(out->u) || Paso_checkPtr(out->main_iptr) ||
111                   Paso_checkPtr(out->lumped_mass_matrix) || Paso_checkPtr(out->transport_matrix_diagonal) || Paso_checkPtr(out->row_sum_flux_matrix) || Paso_checkPtr(out->u)) ) {                   Paso_checkPtr(out->lumped_mass_matrix) || Paso_checkPtr(out->main_diagonal_low_order_transport_matrix)) && Paso_noError()  ) {
112                            
113               printf("Paso_SolverFCT_getFCTransportProblem: Revise coloring!!\n");               #pragma omp parallel
114               Paso_Pattern_color(pattern->mainPattern,&(out->num_colors),out->colorOf);               {
115                     #pragma omp for schedule(static) private(i)
116                                 for (i = 0; i < n; ++i) {
117               #pragma omp parallel for schedule(static) private(i)                      out->lumped_mass_matrix[i]=0.;
118               for (i = 0; i < n; ++i) {                      out->main_diagonal_low_order_transport_matrix[i]=0.;
119                  out->lumped_mass_matrix[i]=0.;                      out->u[i]=0.;
120                  out->row_sum_flux_matrix[i]=0.;                   }
121                  out->u[i]=0.;                   /* identify the main diagonals */
122               }                   #pragma omp for schedule(static) private(i,iptr,iptr_main)
123               /* identify the main diagonals */                   for (i = 0; i < n; ++i) {
124               #pragma omp parallel for schedule(static) private(i,iptr,iptr_main,k)                          iptr_main=pattern->mainPattern->ptr[0]-1;
125               for (i = 0; i < n; ++i) {                          for (iptr=pattern->mainPattern->ptr[i];iptr<pattern->mainPattern->ptr[i+1]; iptr++) {
126                      iptr_main=pattern->mainPattern->ptr[0]-1;                                if (pattern->mainPattern->index[iptr]==i) {
127                      for (iptr=pattern->mainPattern->ptr[i];iptr<pattern->mainPattern->ptr[i+1]; iptr++) {                                     iptr_main=iptr;
128                            if (pattern->mainPattern->index[iptr]==i) {                                     break;
129                                 iptr_main=iptr;                                }
130                                 break;                          }
131                            }                          out->main_iptr[i]=iptr_main;
132                      }                          if (iptr_main==pattern->mainPattern->ptr[0]-1)
133                      out->main_iptr[i]=iptr_main;                               Paso_setError(VALUE_ERROR, "Paso_FCTransportProblem_alloc: no main diagonal");
134                      if (iptr_main==pattern->mainPattern->ptr[0]-1)                   }
135                           Paso_setError(VALUE_ERROR, "Paso_FCTransportProblem_alloc: no main diagonal");      
136               }               }
   
137        }        }
138    
139    }    }
140    if (Paso_noError()) {    if (Paso_noError()) {
141         out->reference_counter=1;
142       return out;       return out;
143    } else {    } else {
144       Paso_FCTransportProblem_free(out);       Paso_FCTransportProblem_free(out);
# Line 155  Paso_FCTransportProblem* Paso_FCTranspor Line 148  Paso_FCTransportProblem* Paso_FCTranspor
148    
149  void Paso_FCTransportProblem_checkinSolution(Paso_FCTransportProblem* in, double* u) {  void Paso_FCTransportProblem_checkinSolution(Paso_FCTransportProblem* in, double* u) {
150      dim_t i, n;      dim_t i, n;
151          double local_u_min,u_min;
152      n=Paso_FCTransportProblem_getTotalNumRows(in);      n=Paso_SystemMatrix_getTotalNumRows(in->transport_matrix);
153      #pragma omp parallel for schedule(static) private(i)      u_min=LARGE_POSITIVE_FLOAT;
154      for (i = 0; i < n; ++i) {      #pragma omp parallel private(local_u_min)
155           in->u[i]=u[i];      {
156             local_u_min=0.;
157             #pragma omp for schedule(static) private(i)
158             for (i=0;i<n;++i) {
159                  in->u[i]=u[i];
160                  local_u_min=MIN(local_u_min,u[i]);
161             }
162             #pragma omp critical
163             {
164                u_min=MIN(u_min,local_u_min);
165             }
166        }
167        #ifdef PASO_MPI
168             local_u_min=u_min;
169             MPI_Allreduce(&local_u_min,&u_min, 1, MPI_DOUBLE, MPI_MIN, in->mpi_info->comm);
170        #endif
171        if (u_min<0) {
172           Paso_setError(VALUE_ERROR, "Paso_FCTransportProblem_checkinSolution: initial guess must be non-negative.");
173      }      }
174  }  }
175    dim_t Paso_FCTransportProblem_getBlockSize(const Paso_FCTransportProblem* in)
176    {
177       return in->transport_matrix->row_block_size;
178    }
179    
180    Paso_Connector* Paso_FCTransportProblem_borrowConnector(const Paso_FCTransportProblem* in)
181    {
182       return in->transport_matrix->pattern->col_connector;
183    }

Legend:
Removed from v.1370  
changed lines
  Added in v.1804

  ViewVC Help
Powered by ViewVC 1.1.26