|
[Sponsors] |
SEGMENTATION fault while using DEFINE_PROPERTY macro |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
January 24, 2018, 09:57 |
SEGMENTATION fault while using DEFINE_PROPERTY macro
|
#1 |
New Member
Leonard
Join Date: Dec 2017
Posts: 4
Rep Power: 8 |
Dear all,
I am relatively new to programming in c, and completely new in writing UDF's for Fluent. Now, I want to write an UDF that defines the thermal conductivity for the primary phase and the secondary phase. I am using the DEFINE_PROPERTY macro to do this. I have tried this in the following way: Code:
/********************************************************************* UDF that simulates the correlation for the conductivity proposed by Shen et al. **********************************************************************/ #include "udf.h" DEFINE_PROPERTY(cell_conductivity,cell,thread) { /* Variable fluid properties for water-vapor subcooling @353.15 K as defined by Mills */ real T_SAT = 373.15; real k_v = 24.8e-3; real k_l = 0.674; real ktc_; /* Enhancement factor n, as proposed by Shen. Enhances the energy transportation in the two-phase region. */ real n = 1.; Domain *subdomain_gas; Domain *subdomain_liq; int phase_domain_index_gas; int phase_domain_index_liq; Thread *gas; Thread *liq; real temp; subdomain_gas = Get_Domain(2); /* retrieve pointer to primary phase domain */ subdomain_liq = Get_Domain(3); /* retrieve pointer to secondary phase domain */ phase_domain_index_gas = PHASE_DOMAIN_INDEX(subdomain_gas); phase_domain_index_liq = PHASE_DOMAIN_INDEX(subdomain_liq); gas = THREAD_SUB_THREAD(thread, phase_domain_index_gas); liq = THREAD_SUB_THREAD(thread, phase_domain_index_liq); temp = C_T(cell,thread); if (temp >= T_SAT){ ktc_ = C_VOF(cell,liq) * k_l + C_VOF(cell,gas) * k_v; } else { ktc_ = C_VOF(cell,liq) * k_l + n * C_VOF(cell,gas) * k_v; } return ktc_; } I would be very happy if someone could help me. Also, feel free to give any tips on programming if you like. Cheers! |
|
January 25, 2018, 04:43 |
|
#2 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
This UDF needs some data to work, specifically the temperature and the VOF.
If you attach this UDF before initializing data, and Fluent wants to calculate the conductivity, Fluent will try to get the temperature/VOF, and fail, and give an error. The simplest solution: initialize your data first (with a constant conductivity), and attach the UDF after that. |
|
January 25, 2018, 04:59 |
|
#3 |
New Member
Leonard
Join Date: Dec 2017
Posts: 4
Rep Power: 8 |
I tried this, but this didn't work. I still receive the segmentation error. Any other suggestions?
|
|
January 25, 2018, 06:51 |
|
#4 |
New Member
Leonard
Join Date: Dec 2017
Posts: 4
Rep Power: 8 |
After doing some tests, I found out that C_VOF(c,t), returns the volume fraction of the secondary phase (seems counter-intuitive). Then I could fix the problem in the following way.
Code:
/********************************************************************* UDF that simulates the correlation for the conductivity proposed by Shen et al. **********************************************************************/ #include "udf.h" DEFINE_PROPERTY(cell_conductivity,cell,thread) { /* Variable fluid properties for water-vapor subcooling @353.15 K as defined by Mills */ real T_SAT = 373.15; real k_v = 0.0248; real k_l = 0.674; real ktc_; /* Enhancement factor n, as proposed by Shen. Enhances the energy transportation in the two-phase region. */ real n = 1.; real temp; temp = C_T(cell,thread); ktc_ = 0.; if (temp >= T_SAT) { ktc_ = C_VOF(cell,thread) * k_l + (1-C_VOF(cell,thread)) * k_v; } else { ktc_ = C_VOF(cell,thread) * k_l + n * (1-C_VOF(cell,thread)) * k_v; } return ktc_; } |
|
January 25, 2018, 06:58 |
|
#5 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
Eliminate the possible problems...
Does it work if you remove temperature? Code:
DEFINE_PROPERTY(cell_conductivity,cell,thread) { /* Variable fluid properties for water-vapor subcooling @353.15 K as defined by Mills */ real T_SAT = 373.15; real k_v = 24.8e-3; real k_l = 0.674; real ktc_; /* Enhancement factor n, as proposed by Shen. Enhances the energy transportation in the two-phase region. */ real n = 1.; Domain *subdomain_gas; Domain *subdomain_liq; int phase_domain_index_gas; int phase_domain_index_liq; Thread *gas; Thread *liq; real temp; subdomain_gas = Get_Domain(2); /* retrieve pointer to primary phase domain */ subdomain_liq = Get_Domain(3); /* retrieve pointer to secondary phase domain */ phase_domain_index_gas = PHASE_DOMAIN_INDEX(subdomain_gas); phase_domain_index_liq = PHASE_DOMAIN_INDEX(subdomain_liq); gas = THREAD_SUB_THREAD(thread, phase_domain_index_gas); liq = THREAD_SUB_THREAD(thread, phase_domain_index_liq); temp = 300.; /* <-- change is here! */ if (temp >= T_SAT){ ktc_ = C_VOF(cell,liq) * k_l + C_VOF(cell,gas) * k_v; } else { ktc_ = C_VOF(cell,liq) * k_l + n * C_VOF(cell,gas) * k_v; } return ktc_; } Knowing which part of the code is really given problems, makes it much easier to find the solution. |
|
January 26, 2018, 06:56 |
|
#6 |
New Member
Leonard
Join Date: Dec 2017
Posts: 4
Rep Power: 8 |
The problem lies in C_VOF(cell, liq) or C_VOF(cell, gas). Now I have tried to fix this the following way.
Code:
#include "udf.h" DEFINE_PROPERTY(cell_conductivity,c,thread) { /* Variable fluid properties for water-vapor subcooling @353.15 K as defined by Mills */ real T_SAT = 373.1; real k_v = 0.0248; real k_l = 0.674; real ktc_; /* Enhancement factor n, as proposed by Shen. Enhances the energy transportation in the two-phase region. */ real n = 1.; real temp = C_T(c,thread); Domain *mix_domain = Get_Domain(1); Thread *mix_thread; Thread **pt; mp_thread_loop_c(mix_thread, mix_domain, pt) { ktc_ = 0.; if (temp >= T_SAT) { ktc_ = C_VOF(c,pt[1]) * k_l + C_VOF(c,pt[0]) * k_v; } else { ktc_ = C_VOF(c,pt[1]) * k_l + n * C_VOF(c,pt[0]) * k_v; } Message(": %g\n", C_VOF(c,pt[0])); } return (ktc_); } After doing some other tests, I found out that C_VOF(c,pt[1])) always returns '1', and C_VOF(c,pt[0]) always returns '0'. But why? It should return the volume fraction right? Any other suggestions to obtain the volume fraction of a cell? |
|
Tags |
define_property, segmentaion fault, udf |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Segmentation fault when running dieselFoam or dieselEngineFoam in parallel | francesco | OpenFOAM Bugs | 4 | May 2, 2017 22:59 |
Segmentation fault in SU2 V5.0 | ygd | SU2 | 2 | March 1, 2017 05:38 |
Segmentation fault when running in parallel | Pj. | OpenFOAM Running, Solving & CFD | 3 | April 8, 2015 09:12 |
Segmentation Fault w/ compiled OF 2.2.0 - motorBike example | sudo | OpenFOAM Running, Solving & CFD | 3 | April 2, 2013 18:27 |
segmentation fault when installing OF-2.1.1 on a cluster | Rebecca513 | OpenFOAM Installation | 9 | July 31, 2012 16:06 |