<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[UDF求计算域中某网格到壁面的最近距离（C_WALL_DIST宏）]]></title><description><![CDATA[<p dir="auto">大家好我有一个小问题想请教各位大神。</p>
<p dir="auto"><strong>问题简单描述：</strong></p>
<p dir="auto">我想求计算域中每个网格的中心到最近壁面的距离。</p>
<p dir="auto"><strong>问题详细描述：</strong></p>
<p dir="auto">我使用的是C_WALL_DIST宏，但是发现在初始化的时候会报错。在二维的算例中能编译通过并进行计算，但是在三维的算例中可以编译通过但初始化错误（试过几台电脑，也试过串行并行）。<br />
错误提示为：f1 process could not be started fluent.</p>
<p dir="auto"><strong>我的问题</strong></p>
<p dir="auto">请问要求计算域中每个网格的中心到最近壁面的距离，有什么办法可以实现？这个C_WALL_DIST宏在帮助手册里没有说明，不知道可否满足我的需求。另外，我网上查找的时候，有人说（<a href="https://www.eureka.im/228.html" target="_blank" rel="noopener noreferrer nofollow ugc">链接地址</a>）可以先定义一个标量，把距离存在标量中，再拿到udf中计算用，他的代码完全看不懂啊（心累），请问这样可以吗？<br />
谢谢大家<img src="https://cfd-china.com/assets/plugins/nodebb-plugin-emoji/emoji/customizations/63b502d5-448e-4592-b11b-d08045e77f0a-f964f05bab046ee35faf5871640e593b.gif?v=eedi85amb0g" class="not-responsive emoji emoji-customizations emoji--xinxin2" style="height:23px;width:auto;vertical-align:middle" title=":xinxin2:" alt=":xinxin2:" /><br />
我的UDF代码如下：</p>
<pre><code>/*用于修改湍流模型中的湍流粘度*/
#include "udf.h"
DEFINE_TURBULENT_VISCOSITY(chen_mu_t,cell,thread)
{

    real chen_mu_t;
    real rho = C_R(cell,thread);
    real u,v,w;
	u=C_U(cell,thread);
	v=C_V(cell,thread);
	w=C_W(cell,thread);
    real local_velocity = sqrt(pow(u,2.0)+pow(v,2.0)+pow(w,2.0));
    real distance =C_WALL_DIST(cell,thread);
    chen_mu_t = 0.03874*rho*local_velocity*distance;

    return chen_mu_t;

}
</code></pre>
]]></description><link>https://cfd-china.com/topic/2776/udf求计算域中某网格到壁面的最近距离-c_wall_dist宏</link><generator>RSS for Node</generator><lastBuildDate>Sun, 16 Aug 2026 06:51:44 GMT</lastBuildDate><atom:link href="https://cfd-china.com/topic/2776.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 15 Jul 2019 06:43:33 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to UDF求计算域中某网格到壁面的最近距离（C_WALL_DIST宏） on Tue, 23 Apr 2024 03:12:43 GMT]]></title><description><![CDATA[<p dir="auto">我补充一句，最近也在写湍流模型UDF，需要用到壁面距离，发现C_WALL_DIST不能用之后不信邪，测试了很多（一个多小时测了十几二十个case），终于测试出来发现：<br />
C_WALL_DIST只有在选择了fluent已有湍流模型（我选了k-omega）的时候才能用，而当选择了laminar模式，用自己的湍流模型UDF的时候，如果涉及到C_WALL_DIST，就会报错。我的fluent版本为2022R2</p>
]]></description><link>https://cfd-china.com/post/37964</link><guid isPermaLink="true">https://cfd-china.com/post/37964</guid><dc:creator><![CDATA[evensun]]></dc:creator><pubDate>Tue, 23 Apr 2024 03:12:43 GMT</pubDate></item><item><title><![CDATA[Reply to UDF求计算域中某网格到壁面的最近距离（C_WALL_DIST宏） on Wed, 01 Mar 2023 15:03:18 GMT]]></title><description><![CDATA[<p dir="auto"><img src="/assets/uploads/files/1677682978962-062cb6a6-3028-4ae6-854e-2c36313d3288-image.png" alt="062cb6a6-3028-4ae6-854e-2c36313d3288-image.png" class=" img-fluid img-markdown" /><br />
<a href="https://www.cfd-online.com/Forums/fluent-udf/63211-calculate-distance-wall-neighbourig-cell-centroid-2.html" target="_blank" rel="noopener noreferrer nofollow ugc">https://www.cfd-online.com/Forums/fluent-udf/63211-calculate-distance-wall-neighbourig-cell-centroid-2.html</a></p>
]]></description><link>https://cfd-china.com/post/33649</link><guid isPermaLink="true">https://cfd-china.com/post/33649</guid><dc:creator><![CDATA[沉剑]]></dc:creator><pubDate>Wed, 01 Mar 2023 15:03:18 GMT</pubDate></item><item><title><![CDATA[Reply to UDF求计算域中某网格到壁面的最近距离（C_WALL_DIST宏） on Wed, 30 Jun 2021 08:59:22 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://cfd-china.com/uid/1129">@benqing</a>   感谢分享 厉害厉害！！</p>
]]></description><link>https://cfd-china.com/post/26329</link><guid isPermaLink="true">https://cfd-china.com/post/26329</guid><dc:creator><![CDATA[李东岳]]></dc:creator><pubDate>Wed, 30 Jun 2021 08:59:22 GMT</pubDate></item><item><title><![CDATA[Reply to UDF求计算域中某网格到壁面的最近距离（C_WALL_DIST宏） on Wed, 30 Jun 2021 08:37:20 GMT]]></title><description><![CDATA[<p dir="auto">这个问题我解决了，宏C_WALL_DIST在高版本里面确实不能用了，从<a href="https://www.cfd-online.com/Forums/fluent-udf/63211-calculate-distance-wall-neighbourig-cell-centroid-2.html" target="_blank" rel="noopener noreferrer nofollow ugc">CFDonline</a>上找到了一个可以用的代码，代码如下：</p>
<pre><code>#include "udf.h"
#include "prox.h"

static cxboolean wall_dist_set = FALSE;//cxboolean布尔运算，与或非，对错

DEFINE_ON_DEMAND(set_wall_dist_udm0)
{
	#if !RP_HOST//表示非host节点的话，执行后面的代码，fluent并行的话，会启动一个 host节点和指定个数的node节点，host节点主要处理GUI和结果收集之类的任务node节点负责分区计算任务

	Domain *domain;
	Thread *t;
	cell_t c;

	if (! wall_dist_set)
	{
		domain = Get_Domain(1);//ROOT_DOMAIN_ID?

		Alloc_Storage_Vars(domain, SV_RTMP_0, SV_NULL);//Alloc_Storage_Vars 用于更改分配

		Calc_Cell_Wall_Distance_New(domain, SV_RTMP_0);

		thread_loop_c(t,domain)
		{
		begin_c_loop(c,t)
			{
				C_UDMI(c,t,0) = C_TMP0(c,t);
			}
		end_c_loop(c,t)
		}
		wall_dist_set = TRUE;
	}
	#endif /* !RP_HOST */
}

DEFINE_ON_DEMAND(reset_udm0)
{
	#if !RP_HOST

	Domain *domain;
	Thread *t;
	cell_t c;

	domain = Get_Domain(1);

	thread_loop_c(t,domain)
	{
	begin_c_loop(c,t)
		{
			C_UDMI(c,t,0) = 0.0;
		}
	end_c_loop(c,t)
	}

	#endif /* !RP_HOST */

	wall_dist_set = FALSE;
}
</code></pre>
<p dir="auto">说实话这个代码我不能完全看懂，但是主要思想就是用DEFINE_ON_DEMAND定义两个命令reset_udm0和set_wall_dist_udm0，前者将壁面到最近壁面的距离reset为0，后者可以求出想要的结果，经过测试两个命令应该都是必须的，另外我放的代码和CFDonline上有一点不同，domain = Get_Domain(1);这一行在原代码里面是domain = Get_Domain(ROOT_DOMAIN_ID);注意修改，下图是我测试的一个水翼网格的结果，结果是对的，<br />
<img src="/assets/uploads/files/1625041832462-8d4c8b84-afb1-4937-ba4d-d10e1a38612d-image.png" alt="8d4c8b84-afb1-4937-ba4d-d10e1a38612d-image.png" class=" img-fluid img-markdown" /><br />
再啰嗦几句代码使用方法，这个代码直接复制到一个.c文件中，在fluent中添加memory的数量为2，编译.c文件并load，在calculate之前，点Execute on Demand，并先后运行reset_udm0和set_wall_dist_udm0，然后就可以calculate了<br />
<img src="/assets/uploads/files/1625042059075-993e14e8-bcd5-4fbf-a316-ac6b28281a67-image.png" alt="993e14e8-bcd5-4fbf-a316-ac6b28281a67-image.png" class=" img-fluid img-markdown" /><br />
<img src="/assets/uploads/files/1625042120330-690cec32-daaa-42de-a0c1-3075b41464e5-image.png" alt="690cec32-daaa-42de-a0c1-3075b41464e5-image.png" class=" img-fluid img-markdown" /></p>
]]></description><link>https://cfd-china.com/post/26328</link><guid isPermaLink="true">https://cfd-china.com/post/26328</guid><dc:creator><![CDATA[benqing]]></dc:creator><pubDate>Wed, 30 Jun 2021 08:37:20 GMT</pubDate></item><item><title><![CDATA[Reply to UDF求计算域中某网格到壁面的最近距离（C_WALL_DIST宏） on Wed, 23 Jun 2021 03:15:23 GMT]]></title><description><![CDATA[<p dir="auto">你们的问题解决了吗，我遇到了同样的问题<img src="https://cfd-china.com/assets/plugins/nodebb-plugin-emoji/emoji/customizations/55b82da1-1ba7-49f6-8e99-3c325e4e5bfc-1.gif?v=eedi85amb0g" class="not-responsive emoji emoji-customizations emoji--134" style="height:23px;width:auto;vertical-align:middle" title=":134:" alt=":134:" /></p>
]]></description><link>https://cfd-china.com/post/26239</link><guid isPermaLink="true">https://cfd-china.com/post/26239</guid><dc:creator><![CDATA[benqing]]></dc:creator><pubDate>Wed, 23 Jun 2021 03:15:23 GMT</pubDate></item><item><title><![CDATA[Reply to UDF求计算域中某网格到壁面的最近距离（C_WALL_DIST宏） on Wed, 31 Jul 2019 09:40:14 GMT]]></title><description><![CDATA[<p dir="auto">你的问题解决了吗？你是用什么方法求得壁面距离？</p>
]]></description><link>https://cfd-china.com/post/15075</link><guid isPermaLink="true">https://cfd-china.com/post/15075</guid><dc:creator><![CDATA[我是河滩]]></dc:creator><pubDate>Wed, 31 Jul 2019 09:40:14 GMT</pubDate></item><item><title><![CDATA[Reply to UDF求计算域中某网格到壁面的最近距离（C_WALL_DIST宏） on Sat, 20 Jul 2019 16:44:21 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://cfd-china.com/uid/2788">@深蓝</a> 你的链接发的并没有写关键代码 这只是部分的 这部分只是排错 计算距离代码并没列出 实际上这部分的实现如果你对UDF有一定的了解并不是很困难 关键是执行效率的问题 如果不是每步执行的 是一步执行的话 是比较简单的 你的方法就可以满足 如果是每步执行的 先排除哪个也就是哪个if写在头 是执行效率的关键 你需要把最大概率不满足的条件写在判断的最开始 其他的都是解析几何的问题 可以找node 也可以找F_centroid</p>
]]></description><link>https://cfd-china.com/post/14985</link><guid isPermaLink="true">https://cfd-china.com/post/14985</guid><dc:creator><![CDATA[l.j刘侃]]></dc:creator><pubDate>Sat, 20 Jul 2019 16:44:21 GMT</pubDate></item><item><title><![CDATA[Reply to UDF求计算域中某网格到壁面的最近距离（C_WALL_DIST宏） on Mon, 15 Jul 2019 13:47:50 GMT]]></title><description><![CDATA[<p dir="auto">谢谢李老师的回复。<br />
我想求的不是网格中心到网格边上的距离，是网格中心到最近的壁面边界的距离（比如说在一个房间内，房间内部的某个网格到最近墙壁的距离）。<br />
谢谢李老师的提醒，我突然想到一个办法，就是对每个网格中心点的x,y,z坐标进行大小判断，找出最小的那个，感觉可以，我先试试。<br />
<img src="https://cfd-china.com/assets/plugins/nodebb-plugin-emoji/emoji/customizations/fc646a58-09bb-4467-bc9a-c68f29698721-b40a64a6442420c68a3ef32e2fc175eb.jpg?v=eedi85amb0g" class="not-responsive emoji emoji-customizations emoji--xiabanle" style="height:23px;width:auto;vertical-align:middle" title=":xiabanle:" alt=":xiabanle:" /></p>
]]></description><link>https://cfd-china.com/post/14923</link><guid isPermaLink="true">https://cfd-china.com/post/14923</guid><dc:creator><![CDATA[深蓝]]></dc:creator><pubDate>Mon, 15 Jul 2019 13:47:50 GMT</pubDate></item><item><title><![CDATA[Reply to UDF求计算域中某网格到壁面的最近距离（C_WALL_DIST宏） on Mon, 15 Jul 2019 12:24:23 GMT]]></title><description><![CDATA[<p dir="auto">不太清楚Fluent那面，不过求网格的壁面距离从算法上比较麻烦，如果是规则网格还好，如果不规则网格，你想象一下，还是挺难弄的。一些边边角角很难确定到那一块是最近的距离。</p>
<p dir="auto"><img src="https://cfd-china.com/assets/plugins/nodebb-plugin-emoji/emoji/customizations/c6bae29e-9e80-4f89-9d32-329b995b3cba-3bbe3fe26d5f937fd0a4d7462a94e9b9.jpg?v=eedi85amb0g" class="not-responsive emoji emoji-customizations emoji--tishizi" style="height:23px;width:auto;vertical-align:middle" title=":tishizi:" alt=":tishizi:" /></p>
]]></description><link>https://cfd-china.com/post/14920</link><guid isPermaLink="true">https://cfd-china.com/post/14920</guid><dc:creator><![CDATA[李东岳]]></dc:creator><pubDate>Mon, 15 Jul 2019 12:24:23 GMT</pubDate></item></channel></rss>