Read in the temperature data: The temperature data needs to be provided as a binary file. For parallel runs, only rank 0 reads the file, and then distributes the data to the other processors.
This function needs to be better documented.
153 int *temperature_field_size = NULL;
154 double *time_level_data = NULL;
155 double *temperature_field_data = NULL;
156 double *time_buffer = NULL;
157 double *data_buffer = NULL;
159 int dim = boundary->
dim;
160 int face= boundary->
face;
165 printf(
"Reading boundary temperature data from %s.\n",filename);
172 for (d=0; d<ndims; d++) nproc *= mpi->
iproc[d]; nproc /= mpi->
iproc[dim];
174 in = fopen(filename,
"rb");
176 fprintf(stderr,
"Error in BCReadTemperatureData(): cannot open boundary temperature data file %s.\n",filename);
181 while ((!feof(in)) && (count < nproc)) {
183 int rank[ndims], size[ndims];
184 ferr = fread(rank,
sizeof(
int),ndims,in);
186 fprintf(stderr,
"Error in BCReadTemperatureData(): Error (1) in file reading, count %d.\n",count);
189 if (rank[dim] != (face > 0 ? 0 : mpi->
iproc[dim]-1) ) {
190 fprintf(stderr,
"Error in BCReadTemperatureData(): Error (2) in file reading, count %d.\n",count);
193 ferr = fread(size,
sizeof(
int),ndims,in);
195 fprintf(stderr,
"Error in BCReadTemperatureData(): Error (3) in file reading, count %d.\n",count);
199 int n_data = size[dim];
200 time_buffer = (
double*) calloc (n_data,
sizeof(
double));
201 ferr = fread(time_buffer,
sizeof(
double),n_data,in);
202 if (ferr != n_data) {
203 fprintf(stderr,
"Error in BCReadTemperatureData(): Error (5) in file reading, count %d.\n",count);
208 for (d=0; d<ndims; d++) data_size *= size[d];
209 data_buffer = (
double*) calloc (data_size,
sizeof(
double));
210 ferr = fread(data_buffer,
sizeof(
double),data_size,in);
211 if (ferr != data_size) {
212 fprintf(stderr,
"Error in BCReadTemperatureData(): Error (6) in file reading, count %d.\n",count);
222 temperature_field_size = (
int*) calloc (ndims,
sizeof(
int));
225 time_level_data = (
double*) calloc (size[dim],
sizeof(
double));
228 temperature_field_data = (
double*) calloc (data_size,
sizeof(
double));
229 ArrayCopynD(ndims,data_buffer,temperature_field_data,size,0,0,index,1);
234 MPI_Request req[3] = {MPI_REQUEST_NULL,MPI_REQUEST_NULL,MPI_REQUEST_NULL};
235 MPI_Isend(size,ndims,MPI_INT,rank1D,2152,mpi->
world,&req[0]);
236 MPI_Isend(time_buffer,size[dim],MPI_DOUBLE,rank1D,2154,mpi->
world,&req[2]);
237 MPI_Isend(data_buffer,data_size,MPI_DOUBLE,rank1D,2153,mpi->
world,&req[1]);
238 MPI_Status status_arr[3];
239 MPI_Waitall(3,&req[0],status_arr);
241 fprintf(stderr,
"Error in BCReadTemperatureData(): This is a serial run. Invalid (non-zero) rank read.\n");
252 fprintf(stderr,
"Error in BCReadTemperatureData(): missing data in unsteady boundary data file %s.\n",filename);
253 fprintf(stderr,
"Error in BCReadTemperatureData(): should contain data for %d processors, ", nproc);
254 fprintf(stderr,
"Error in BCReadTemperatureData(): but contains data for %d processors!\n", count);
263 if (mpi->
ip[dim] == (face > 0 ? 0 : mpi->
iproc[dim]-1) ) {
265 MPI_Request req = MPI_REQUEST_NULL;
267 temperature_field_size = (
int*) calloc (ndims,
sizeof(
int));
268 MPI_Irecv(temperature_field_size,ndims,MPI_INT,0,2152,mpi->
world,&req);
269 MPI_Wait(&req,MPI_STATUS_IGNORE);
272 for (d=0; d<ndims; d++)
if ((d != dim) && (temperature_field_size[d] != DomainSize[d])) flag = 0;
274 fprintf(stderr,
"Error in BCReadTemperatureData(): Error (4) (dimension mismatch) in file reading, rank %d.\n",mpi->
rank);
278 time_level_data = (
double*) calloc (temperature_field_size[dim],
sizeof(
double));
279 MPI_Irecv(time_level_data, temperature_field_size[dim], MPI_DOUBLE,0,2154,mpi->
world,&req);
280 MPI_Wait(&req,MPI_STATUS_IGNORE);
283 for (d=0; d<ndims; d++) data_size *= temperature_field_size[d];
284 temperature_field_data = (
double*) calloc (data_size,
sizeof(
double));
285 MPI_Irecv(temperature_field_data,data_size,MPI_DOUBLE,0,2153,mpi->
world,&req);
286 MPI_Wait(&req,MPI_STATUS_IGNORE);
290 fprintf(stderr,
"Error in BCReadTemperatureData(): Serial code should not be here!.\n");
int * UnsteadyTemperatureSize
char UnsteadyTemperatureFilename[_MAX_STRING_SIZE_]
Structure containing the variables and function pointers defining a boundary.
int MPIRank1D(int, int *, int *)
double * UnsteadyTimeLevels
INLINE int ArrayCopynD(int, const double *, double *, int *, int, int, int *, int)
Structure of MPI-related variables.
double * UnsteadyTemperatureData
#define _ArrayCopy1D_(x, y, size)