CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT > Fluent UDF and Scheme Programming

Fluent crashing with no error message when initialising simulation with new UDF's

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 26, 2021, 07:45
Default Fluent crashing with no error message when initialising simulation with new UDF's
  #1
New Member
 
Hamish
Join Date: Dec 2020
Location: Australia
Posts: 8
Rep Power: 5
ham551 is on a distinguished road
I wrote some new UDF's to give Fluent more accurate dynamical viscosity and thermal conductivity values for Hydrogen. Previously I had a more basic UDF just giving data for 1atm, now I am providing data for a large range of pressures and temperatures. However, when attempting to initialize the simulation with the new UDF's compiled, Fluent crashes almost instantly and doesn't give any message.

If I do a hybrid initialization first with the old UDF, then another with the new UDF's, it manages 6-7 iterations during initialization before crashing.

Seems likely it's the new UDF's causing the crash but I don't know why. Any ideas?

The UDF reads in data taken from a NASA CEA simulation using a .csv file. All the conductivity data is merged into a single column. So for each pressure, there exist 43 conductivity values for the 43 temperature intervals tested. The UDF checks the pressure from fluent, then fills a temporary array of the corresponding 43 conductivity values. Then the UDF checks the temperature from fluent and linearly interpolates the conductivity from that temporary array.

The code seems to work perfectly during testing, outputting the correct values and compiling in Fluent.

Code:
/******* UDF that simulates the thermal conductivity****************
***************of Hydrogen at pressures between 1Pa-6Bar and 300-4500K 
                               ************************/
#include <udf.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
DEFINE_PROPERTY(conductivity, c,t)
{
real conductivity = 0.3;
real T = C_T(c, t);
//Convert pressure[Pa] to [Bar].
real P = (C_P(c, t)*1E-05);
int pressureSize = 627;
int tempSize = 43;
int csvlength = 26961;
//Initialise arrays for temperatures, pressures and conductivities.
real temp[43] = {300,400 ... 4400,4500};
real pressure[627] = {1e-05 ... 0.0001 ... 0.01,0.02,0.03,0.04,0.05,0.06,0.07,0.08,0.09,0.1,0.11 ... 6};
real conductivities[26961];
char line[2048];
int i =0; 

//Open and read in .csv file of conductivities.
FILE *f = fopen("h2conductivity.csv", "r");
    if(f == NULL)
    {
        perror("Unable to open the file");
        exit(1);
    }
    while(fgets(line,sizeof(line),f))
    {
        char *token;
        token = strtok(line,",");
        conductivities[i] = atof(token);
        i=i+1;    
    }
    // Check for any 0 values and replace with set value.
    for(int i = 0; i < csvlength;i++)
    {
        if(conductivities[i] == 0){
        conductivities[i] = 3E-13;
        }
    }
    // Initialise an array for temporarily storing conductivity values
    //Check pressure from fluent against pressure values used to collect conductivity values and fill 
       temporary cond. array with corresponding conductivity values
    real tempConductivities[tempSize];
    for(int i = 0; i < pressureSize ; i++)
    {
        if(P>pressure[i] && P<((pressure[i]+pressure[i+1])/2))
        {
            int start = i*tempSize;
            int stop = start + tempSize;
            for(int j = start; j < stop; j++)
            {
            int q = j - start;
            tempConductivities[q] = conductivities[j];
            }
        }

        if(P>=(pressure[i]+pressure[i+1])/2)
        {
            int start = (i+1)*tempSize;
            int stop = start + tempSize;
            for(int j = start; j < stop; j++)
            {
            int q = j - start;
            tempConductivities[q] = conductivities[j];
            }
        }

        if(P == pressure[i])
        {
            int start = i*tempSize;
            int stop = start + tempSize;
            for(int j = start; j < stop; j++)
            {
            int q = j - start;
            tempConductivities[q] = conductivities[j];
            }
        }
    }
    //Compare temperature from fluent and linearly interpolate between conductivities in temp cond. array
    //Convert units to S.I by multiplying by 0.1 -> (mW/cmK) to (W/mK)
    for(int op=0;op<tempSize;op++)
    {
        if(T>temp[op] && T<temp[op+1])
        {
            conductivity = (tempConductivities[op] + ((tempConductivities[op+1]- 
             tempConductivities[op])/(temp[op+1]-temp[op]))*(T-temp[op]))*0.1;
        }
        if(T == temp[op])
        {
            conductivity = tempConductivities[op]*0.1;
        }
    }

    return conductivity;
}
ham551 is offline   Reply With Quote

Old   October 27, 2021, 13:54
Default
  #2
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
It crashes instantly because you use the temperature, which is not yet defined during initialization. If you initialize with another method, you avoid that problem.

And you open a file for every cell. That is very inefficient: the proper way is to read the file once (with a DEFINE_ON_DEMAND), store the info in a global array, and read from that global array.
But what is causing the crash is that you never close files. Soon you have millions of open files, and the system is not designed for that.
__________________
"The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform" is NOT the error after compiling. It is the error after loading. To see compiler errors, look at your screen after you click "build".
pakk is offline   Reply With Quote

Reply

Tags
fluent - udf, udf, udf crash


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to run fluent from matlab without using aas toolbox? artemis96 ANSYS 7 May 23, 2022 12:16
Transient Simulation - Fluent remove my case and data lape95 FLUENT 4 April 22, 2020 09:20
How to make UDFs for Nucleate Pool Boiling Simulation? SIKJAE Fluent UDF and Scheme Programming 1 August 4, 2018 07:07
Start new Ansys Fluent Simulation automatically Malue Fluent UDF and Scheme Programming 1 October 4, 2017 01:48
Simulation on fluent 14 NAD FLUENT 0 September 11, 2013 02:05


All times are GMT -4. The time now is 06:31.