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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1859 - (show annotations)
Wed Oct 8 03:03:37 2008 UTC (11 years ago) by gross
File MIME type: text/plain
File size: 6898 byte(s)
first version of testing for transport solver.
1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2008 by University of Queensland
5 * Earth Systems Science Computational Center (ESSCC)
6 * http://www.uq.edu.au/esscc
7 *
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
17 /* Paso: FCTransportProblem */
18
19 /**************************************************************/
20
21 /* Author: l.gross@uq.edu.au */
22
23 /**************************************************************/
24
25
26 #include "Paso.h"
27 #include "SolverFCT.h"
28 #include "PasoUtil.h"
29
30
31 /**************************************************************/
32
33 /* free all memory used by */
34
35 void Paso_FCTransportProblem_free(Paso_FCTransportProblem* in) {
36 if (in!=NULL) {
37 in->reference_counter--;
38 if (in->reference_counter<=0) {
39 Paso_SystemMatrix_free(in->transport_matrix);
40 Paso_SystemMatrix_free(in->mass_matrix);
41 Paso_SystemMatrix_free(in->iteration_matrix);
42 Paso_MPIInfo_free(in->mpi_info);
43 Paso_Coupler_free(in->u_coupler);
44 MEMFREE(in->u);
45 MEMFREE(in->main_iptr);
46 MEMFREE(in->lumped_mass_matrix);
47 MEMFREE(in->main_diagonal_low_order_transport_matrix);
48 MEMFREE(in);
49 }
50 }
51 }
52
53 Paso_FCTransportProblem* Paso_FCTransportProblem_getReference(Paso_FCTransportProblem* in) {
54 if (in!=NULL) {
55 ++(in->reference_counter);
56 }
57 return in;
58 }
59
60 Paso_SystemMatrix* Paso_FCTransportProblem_borrowTransportMatrix(Paso_FCTransportProblem* in) {
61 return in->transport_matrix;
62 }
63 Paso_SystemMatrix* Paso_FCTransportProblem_borrowMassMatrix(Paso_FCTransportProblem* in) {
64 return in->mass_matrix;
65 }
66
67 double* Paso_FCTransportProblem_borrowLumpedMassMatrix(Paso_FCTransportProblem* in) {
68 return in->lumped_mass_matrix;
69 }
70
71 dim_t Paso_FCTransportProblem_getTotalNumRows(Paso_FCTransportProblem* in) {
72 return Paso_SystemMatrix_getTotalNumRows(in->transport_matrix);
73 }
74
75 Paso_FCTransportProblem* Paso_FCTransportProblem_alloc(double theta, Paso_SystemMatrixPattern *pattern, int block_size)
76 {
77 Paso_SystemMatrixType matrix_type=MATRIX_FORMAT_DEFAULT+MATRIX_FORMAT_BLK1; /* at the moment only block size 1 is supported */
78 Paso_FCTransportProblem* out=NULL;
79 Paso_SystemMatrixPattern *transport_pattern;
80 dim_t n,i;
81 index_t iptr,iptr_main;
82
83 if ((theta<0.) || (theta >1.)) {
84 Paso_setError(TYPE_ERROR,"Paso_FCTransportProblem_alloc: theta needs to be between 0. and. 1.");
85 return NULL;
86 }
87
88 out=MEMALLOC(1,Paso_FCTransportProblem);
89 if (Paso_checkPtr(out)) return NULL;
90 out->reference_counter=0;
91 out->theta=theta;
92 out->dt_max=LARGE_POSITIVE_FLOAT;
93 out->valid_matrices=FALSE;
94 out->transport_matrix=Paso_SystemMatrix_alloc(matrix_type,pattern,block_size,block_size);
95 out->mass_matrix=Paso_SystemMatrix_alloc(matrix_type,pattern,block_size,block_size);
96 out->iteration_matrix=NULL;
97 out->u=NULL;
98 out->mpi_info=Paso_MPIInfo_getReference(pattern->mpi_info);
99 out->main_iptr=NULL;
100 out->lumped_mass_matrix=NULL;
101 out->main_diagonal_low_order_transport_matrix=NULL;
102
103 if (Paso_noError()) {
104 n=Paso_SystemMatrix_getTotalNumRows(out->transport_matrix);
105 transport_pattern=out->transport_matrix->pattern;
106
107 out->u=MEMALLOC(n,double);
108 out->main_iptr=MEMALLOC(n,index_t);
109 out->lumped_mass_matrix=MEMALLOC(n,double);
110 out->main_diagonal_low_order_transport_matrix=MEMALLOC(n,double);
111 out->u_coupler=Paso_Coupler_alloc(Paso_FCTransportProblem_borrowConnector(out),block_size);
112
113 if ( ! (Paso_checkPtr(out->u) || Paso_checkPtr(out->main_iptr) ||
114 Paso_checkPtr(out->lumped_mass_matrix) || Paso_checkPtr(out->main_diagonal_low_order_transport_matrix)) && Paso_noError() ) {
115
116 #pragma omp parallel
117 {
118 #pragma omp for schedule(static) private(i)
119 for (i = 0; i < n; ++i) {
120 out->lumped_mass_matrix[i]=0.;
121 out->main_diagonal_low_order_transport_matrix[i]=0.;
122 out->u[i]=0.;
123 }
124 /* identify the main diagonals */
125 #pragma omp for schedule(static) private(i,iptr,iptr_main)
126 for (i = 0; i < n; ++i) {
127 iptr_main=transport_pattern->mainPattern->ptr[0]-1;
128 for (iptr=transport_pattern->mainPattern->ptr[i];iptr<transport_pattern->mainPattern->ptr[i+1]; iptr++) {
129 if (transport_pattern->mainPattern->index[iptr]==i) {
130 iptr_main=iptr;
131 break;
132 }
133 }
134 out->main_iptr[i]=iptr_main;
135 if (iptr_main==transport_pattern->mainPattern->ptr[0]-1)
136 Paso_setError(VALUE_ERROR, "Paso_FCTransportProblem_alloc: no main diagonal");
137 }
138
139 }
140 }
141
142 }
143 if (Paso_noError()) {
144 out->reference_counter=1;
145 return out;
146 } else {
147 Paso_FCTransportProblem_free(out);
148 return NULL;
149 }
150 }
151
152 void Paso_FCTransportProblem_checkinSolution(Paso_FCTransportProblem* in, double* u) {
153 dim_t i, n;
154 double local_u_min,u_min;
155 n=Paso_SystemMatrix_getTotalNumRows(in->transport_matrix);
156 u_min=LARGE_POSITIVE_FLOAT;
157 #pragma omp parallel private(local_u_min)
158 {
159 local_u_min=0.;
160 #pragma omp for schedule(static) private(i)
161 for (i=0;i<n;++i) {
162 in->u[i]=u[i];
163 local_u_min=MIN(local_u_min,u[i]);
164 }
165 #pragma omp critical
166 {
167 u_min=MIN(u_min,local_u_min);
168 }
169 }
170 #ifdef PASO_MPI
171 local_u_min=u_min;
172 MPI_Allreduce(&local_u_min,&u_min, 1, MPI_DOUBLE, MPI_MIN, in->mpi_info->comm);
173 #endif
174 if (u_min<0) {
175 Paso_setError(VALUE_ERROR, "Paso_FCTransportProblem_checkinSolution: initial guess must be non-negative.");
176 }
177 }
178 dim_t Paso_FCTransportProblem_getBlockSize(const Paso_FCTransportProblem* in)
179 {
180 return in->transport_matrix->row_block_size;
181 }
182
183 Paso_Connector* Paso_FCTransportProblem_borrowConnector(const Paso_FCTransportProblem* in)
184 {
185 return in->transport_matrix->pattern->col_connector;
186 }
187
188 index_t Paso_FCTransportProblem_getTypeId(const index_t solver,const index_t preconditioner, const index_t package,const bool_t symmetry)
189 {
190 return MATRIX_FORMAT_DEFAULT + MATRIX_FORMAT_BLK1;
191 }
192

  ViewVC Help
Powered by ViewVC 1.1.26