#define USE_MY_OWN_FILE _NT #if USE_MY_OWN_FILE # define USE_FLUENT_IO_API 0 # define USE_UDF_PAR_IO 0 #endif #include "udf.h" /* Following definition divides by EPSILON to cancel * that from the definition of REAL_EQUAL_SCALED: */ #define REL_RESOL_IN_INJ_FILE 0.0001 /* If, for example, the file format is...: * (( 4.9821e+00 -1.0061e+00 4.2000e+00 -1.6938e-05 ... * then there are five significant digits * the "relative resolution" is 0.0001 = 1.e-4 */ #define MY_REAL_EQUAL(a, b) \ REAL_EQUAL_SCALED((a), (b), (REL_RESOL_IN_INJ_FILE / EPSILON)) DEFINE_DPM_INJECTION_INIT(injudf, I) { Particle *p; char rest[1024]; FILE *my_inj_file_ptr = I->inj_fil_ptr; if (dpm_par.n_user_reals < 1) { Message0("\nWARNING: UDF 'injudf' cannot operate, " "needs at least one DPM user-real!!\n"); return; } Message0("\nCONFIRMED: UDF 'injudf' can operate, " "DPM user-real number is '%i'\n", dpm_par.n_user_reals); #if USE_MY_OWN_FILE my_inj_file_ptr = fopen(I->injection_file, "r"); /* Cannot use the open file pointer provided * by the Fluent executable. */ #endif if (NULLP(my_inj_file_ptr)) { Message0("\n\nWARNING: UDF 'injudf' cannot operate, " "file '%s' is not open or could not be " "opened for reading!!\n\n", I->injection_file); return; } Message0("\nCONFIRMED: UDF 'injudf' can operate, File '%s' was opened for reading\n", I->injection_file); #if USE_MY_OWN_FILE /* "read away" the file header: */ fgets(rest, 1023, my_inj_file_ptr); fgets(rest, 1023, my_inj_file_ptr); #elif 00 rewind(my_inj_file_ptr); #endif loop(p, I->p_init) { while ( ! feof(my_inj_file_ptr)) { real file_x, file_y, file_z, file_u, file_v, file_w, file_d, file_T, file_M, file_m, file_n, file_t, file_f, file_vol, file_char = 0.; int nmatch = fscanf(my_inj_file_ptr, "((%lg %lg %lg %lg %lg %lg %lg %lg %lg %lg %lg %lg %lg %lg %lg", &file_x, &file_y, &file_z, &file_u, &file_v, &file_w, &file_d, &file_T, &file_M, &file_m, &file_n, &file_t, &file_f, &file_vol, &file_char); real DPM_VOLATILE_FRACTION = 0; real DPM_CHAR_FRACTION = 0; if (15 != nmatch) { CX_Message("\nnode-%d: WARNING: UDF 'injudf': Could not " "read from the file '%s' as expected -- bailing out because nmatch is %i!\n", myid, I->injection_file, nmatch); } /* Read additional numerical columns hereā€¦! */ /* Read the rest of the line into a string buffer: */ fgets(rest, 1023, my_inj_file_ptr); file_f -= I->start_flow_time_in_unst_file; if (0. < I->repeat_intrvl_from_unst_file) if (file_f > I->repeat_intrvl_from_unst_file) { rewind(my_inj_file_ptr); /* "read away" the file header: */ fgets(rest, 1023, my_inj_file_ptr); fgets(rest, 1023, my_inj_file_ptr); file_f = 0.; continue; } file_f += I->unsteady_start; if (0. < I->repeat_intrvl_from_unst_file) while (file_f < dpm_par.time) file_f += I->repeat_intrvl_from_unst_file; if ( MY_REAL_EQUAL(PP_POS(p)[0], file_x) && MY_REAL_EQUAL(PP_POS(p)[1], file_y) && MY_REAL_EQUAL(PP_POS(p)[2], file_z) && MY_REAL_EQUAL(PP_VEL(p)[0], file_u) && MY_REAL_EQUAL(PP_VEL(p)[1], file_v) && MY_REAL_EQUAL(PP_VEL(p)[2], file_w) && MY_REAL_EQUAL(PP_DIAM(p), file_d) && MY_REAL_EQUAL(PP_T(p), file_T) && MY_REAL_EQUAL(PP_FLOW_RATE(p), file_M) && /* The following PP_...(p) values aren't yet known in * parallel and will be calculated from P_FLOW_RATE(p) * later: * MY_REAL_EQUAL(PP_MASS(p) * PP_N(p), file_M) && * MY_REAL_EQUAL(PP_MASS(p), file_m) && * MY_REAL_EQUAL(PP_N(p), file_n) && */ MY_REAL_EQUAL(PP_INJ_DURATIME(p), file_t) && MY_REAL_EQUAL(PP_INJ_FLOWTIME(p), file_f)) { /* volatile fraction was read from inj-file, *and will now be assigned to PP_USER_REAL(p,0): */ PP_USER_REAL(p,0) = file_vol; /* char fraction was read from inj-file, *and will now be assigned to PP_USER_REAL(p,1): */ PP_USER_REAL(p,1) = file_char; /* volatile fraction was read from inj-file, *and will now be assigned to DPM_VOLATILE_FRACTION(p): */ DPM_VOLATILE_FRACTION(p) = file_vol; /* char fraction was read from inj-file, *and will now be assigned to DPM_CHAR_FRACTION(p): */ DPM_CHAR_FRACTION(p) = file_char; break; } } /* while(TRUE) */ /* End of file, but yet another particle to do? */ if (feof(my_inj_file_ptr) && ! NULLP(p->next)) { CX_Message("\n\n==========================================" "==============================================\n" "==== WARNING: injudf could not process all" " new particles on compute-node: %d..! ====\n" "============================================" "===========================================\n\n", myid); break; } } #if USE_MY_OWN_FILE fclose(my_inj_file_ptr); #endif }