Форум программистов, компьютерный форум, киберфорум
С++ для начинающих
Войти
Регистрация
Восстановить пароль
Карта форума Темы раздела Блоги Сообщество Поиск Заказать работу  
 
Рейтинг 4.77/13: Рейтинг темы: голосов - 13, средняя оценка - 4.77
0 / 0 / 0
Регистрация: 11.11.2015
Сообщений: 17
1

Ansys и С++

26.10.2016, 14:41. Показов 2477. Ответов 4
Метки нет (Все метки)

Author24 — интернет-сервис помощи студентам
Доброго времени суток.
Преподаватель в универе да сей код
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
2.6.6.1. Description
 
You can use DEFINE_CONTACT to specify the response to a contact detection event in ANSYS Fluent. Note that UDFs that are defined using DEFINE_CONTACT can be executed only as compiled UDFs.
 
2.6.6.2. Usage
 
DEFINE_CONTACT (name, dt, contacts)
 
Argument Type
 
Description
 
symbol name
 
UDF name.
 
Dynamic_Thread *dt
 
Pointer to structure that stores the dynamic mesh attributes that you have specified (or that are calculated by ANSYS Fluent).
 
Objp *contacts
 
Pointer to a NULL-terminated linked list of elements involved in the contact detection event.
 
Function returns
 
void
 
There are three arguments to DEFINE_CONTACT: name, dt, and contacts. You supply name, the name of the UDF. The dt and contacts structure pointers are passed by the ANSYS Fluent solver to your UDF.
 
2.6.6.3. Example 1
 
/************************************************************\
 * 2-degree of freedom equation of motion compiled UDF      *
\************************************************************/
 
DEFINE_CONTACT(contact_props, dt, contacts)
{
  Objp *o;
  face_t face;
  Thread *thread;
  Domain *domain = NULL;
  Dynamic_Thread *ndt = NULL;
 
  int tid, nid, n_faces;
 
  real v0dotn1, v1dotn0;
  real nc_mag, norm0_mag, norm1_mag;
 
  real N3V_VEC (vel_rel);
  real N3V_VEC (nc), N3V_VEC (nctmp);
  real N3V_VEC (xc), N3V_VEC (xctmp);
  real N3V_VEC (vel0), N3V_VEC (omega0), N3V_VEC (theta0), N3V_VEC (norm0);
  real N3V_VEC (vel1), N3V_VEC (omega1), N3V_VEC (theta1), N3V_VEC (norm1);
 
  if (!Data_Valid_P())
    {
      return;
    }
 
  /* Define a common contact point / plane */
  N3V_S (nc, =, 0.0);
  N3V_S (xc, =, 0.0);
 
  /* Fetch current thread ID */
  tid = THREAD_ID (DT_THREAD (dt));
 
  nid = -1;
  n_faces = 0;
 
  loop (o, contacts)
    {
      face = O_F (o);
      thread = O_F_THREAD (o);
 
      /* Skip faces on current thread */
      if (THREAD_ID (thread) == tid)
        {
          continue;
        }
 
      /* Note ID for posterity */
      if (nid == -1)
        {
          nid = THREAD_ID (thread);
        }
 
      /* Initialize to zero */
      N3V_S (nctmp, =, 0.0);
      N3V_S (xctmp, =, 0.0);
 
      F_AREA (nctmp, face, thread);
      F_CENTROID (xctmp, face, thread);
 
#     if DEBUG
        {
          Message0
          (
            "\nFace:: %d (%d): Area: (%f %f %f) Centre: (%f %f %f)",
            face, THREAD_ID (thread),
            nctmp[0], nctmp[1], nctmp[2],
            xctmp[0], xctmp[1], xctmp[2]
          );
        }
#     endif
 
      /**
       * Negative sum because wall normals
       * point out of the fluid domain
       */
      N3V_V (nc, -=, nctmp);
      N3V_V (xc, +=, xctmp);
 
      n_faces++;
    }
 
# if RP_NODE
    {
      /* Reduce in parallel */
      nid = PRF_GIHIGH1 (nid);
      n_faces = PRF_GISUM1 (n_faces);
 
      PRF_GRSUM3 (nc[0], nc[1], nc[2]);
      PRF_GRSUM3 (xc[0], xc[1], xc[2]);
    }
# endif
 
  if (n_faces > 0)
    {
      nc_mag = N3V_MAG (nc) + REAL_MIN;
 
      N3V_S (nc, /=, nc_mag);
      N3V_S (xc, /=, n_faces);
    }
  else
    {
      return;
    }
 
  Message
  (
    "\nContact:: tid: %d nid: %d n_faces: %d "
    "Point: (%f %f %f) Normal: (%f %f %f)",
    tid, nid, n_faces,
    xc[0], xc[1], xc[2],
    nc[0], nc[1], nc[2]
  );
 
  /* Fetch thread for opposite body */
  domain = THREAD_DOMAIN (DT_THREAD (dt));
  thread = Lookup_Thread (domain, nid);
 
  if (NULLP (thread))
    {
      Message ("\nWarning: No thread for nid: %d ", nid);
 
      return;
    }
  else
    {
      ndt = THREAD_DT (thread);
    }
 
  /* Fetch body parameters */
  SDOF_Get_Motion (dt, vel0, omega0, theta0);
 
  /* Compute difference vectors and normalize */
  N3V_VV (norm0, =, xc, -, DT_CG (dt));
  norm0_mag = N3V_MAG (norm0) + REAL_MIN;
  N3V_S (norm0, /=, norm0_mag);
 
  if (NULLP (ndt))
    {
      /* Stationary body / wall. Use contact normal */
      N3V_V (norm1, =, nc);
 
      /* Compute relative velocity */
      N3V_S (vel1, =, 0.0);
      N3V_V (vel_rel, =, vel0);
    }
  else
    {
      /* Fetch body parameters */
      SDOF_Get_Motion (ndt, vel1, omega1, theta1);
 
      /* Compute relative velocity */
      N3V_VV (vel_rel, =, vel0, -, vel1);
 
      /* Compute difference vectors and normalize */
      N3V_VV (norm1, =, xc, -, DT_CG (ndt));
      norm1_mag = N3V_MAG (norm1) + REAL_MIN;
      N3V_S (norm1, /=, norm1_mag);
 
      /* Check if velocity needs to be reversed */
      if (N3V_DOT (vel_rel, nc) < 0.0)
        {
          /* Reflect velocity across the normal */
          v1dotn0 = 2.0 * N3V_DOT (vel1, norm0);
 
          N3V_S (norm0, *=, v1dotn0);
          N3V_V (vel1, -=, norm0);
 
          /* Override body velocity */
          SDOF_Overwrite_Motion (ndt, vel1, omega1, theta1);
        }
    }
 
  /* Check if velocity needs to be reversed */
  if (N3V_DOT (vel_rel, nc) < 0.0)
    {
      /* Reflect velocity across the normal */
      v0dotn1 = 2.0 * N3V_DOT (vel0, norm1);
 
      N3V_S (norm1, *=, v0dotn1);
      N3V_V (vel0, -=, norm1);
 
      /* Override body velocity */
      SDOF_Overwrite_Motion (dt, vel0, omega0, theta0);
    }
 
  Message
  (
    "\ncontact_props: Updated :: vel0 = (%f %f %f) vel1 = (%f %f %f)",
    vel0[0], vel0[1], vel0[2], vel1[0], vel1[1], vel1[2]
  );
}
2.6.6.4. Example 2
 
You can also use nodal contact information in a DEFINE_GRID_MOTION UDF that can be used to constrain grid motion in certain situations.
 
/*********************************************************************\
 * This UDF provides the moving-deforming mesh model with the        *
 * locations of the nodes on a deforming boundary. The UDF uses      *
 * nodal contact information to constrain motion.                    *
 * Compiled UDF, all metric units                                    *
\*********************************************************************/
 
#include "udf.h"
 
static real L = 2.5;
static real xoffset = 2.8;
static real amplitude = 1.0;
static real total_time = 15.0;
 
DEFINE_GRID_MOTION(wall_deform_top, domain, dt, time, dtime)
{
  int n;
  Node *node;
  face_t face;
 
  real A, factor, fraction;
 
  Thread *thread = DT_THREAD (dt);
 
  /**
   * Set/activate the deforming flag on adjacent cell zone, which
   * means that the cells adjacent to the deforming wall will also be
   * deformed, in order to avoid skewness.
   */
  SET_DEFORMING_THREAD_FLAG (THREAD_T0 (thread));
 
  /**
   * Loop over the deforming boundary zone faces;
   * inner loop loops over all nodes of a given face;
   * Thus, since one node can belong to several faces, one must guard
   * against operating on a given node more than once:
   */
  begin_f_loop (face, thread)
    {
      f_node_loop (face, thread, n)
        {
          node = F_NODE (face, thread, n);
 
          /* Compute the amplitude as a function of time */
          fraction = (time / total_time);
 
          factor = -1.0 * fabs (2.0 * (fraction - floor (fraction + 0.5)));
 
          A = factor * amplitude * sin (M_PI * (NODE_X (node) - xoffset) / L);
 
          /*
           * If node is in contact and motion is downward,
           * prevent further motion.
           */
          if (NODE_POS_CONTACT_P (node) && ((A + 1.0) < NODE_Y (node)))
            {
              NODE_POS_UPDATED (node);
              continue;
            }
 
          /*
           * Update the current node only if it has not been
           * previously visited:
           */
          if (NODE_POS_NEED_UPDATE (node))
            {
              /**
               * Set flag to indicate that the current node's
               * position has been updated, so that it will not be
               * updated during a future pass through the loop:
               */
              NODE_POS_UPDATED (node);
 
              NODE_Y (node) = A + 1.0;
            }
        }
    }
  end_f_loop (face, thread);
}
2.6.6.5. Hooking a DEFINE_CONTACT UDF to ANSYS Fluent
 
After the UDF that you have defined using DEFINE_CONTACT is compiled (Compiling UDFs), the name of the argument that you supplied as the first DEFINE macro argument will become visible in the UDF drop-down list in the Contact Detection tab of the Options dialog box in ANSYS Fluent. See Hooking DEFINE_CONTACT UDFs for details on how to hook your DEFINE_CONTACT UDF to ANSYS Fluent.
Говорит, разбери, напиши комментарии и т.д.
Покопался в интернете ничего понятно не нашел..
кто подскажет с какой стороны подойти,и вообще, с чего начать?
я запутался.
P/S если тема не в том разделе, прошу простить. Код крайне похож на синтаксис C++
0
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
26.10.2016, 14:41
Ответы с готовыми решениями:

C# + ANSYS
Кто нибудь пробовал интегрировать свою программу с расчетным ядром ANSYS? Возникала такая...

Ansys
Добрый день. Подскажите, есть ли русскоязычные версии Ansys? Интересует версия Ansys для...

Скачать ANSYS 10
Помогите с одной проблемкой кто нибудь!!!!!! Где Скачать прогу ANSYS 10 версии!!!!!! ПОмогит екто...

Substructuring в ANSYS
Здравствуйте, уважаемые форумчане, Есть модель шатуна ДВС с КЭ сеткой. Нужно получить из ANSYS...

4
Объявлятель переменных
1220 / 406 / 320
Регистрация: 24.09.2011
Сообщений: 1,265
26.10.2016, 15:04 2
1. Это не C++.
2. Код уже достаточно подробно прокомментирован. Вам только перевести осталось.
0
Любитель чаепитий
3742 / 1798 / 566
Регистрация: 24.08.2014
Сообщений: 6,016
Записей в блоге: 1
26.10.2016, 15:20 3
Цитата Сообщение от SpBerkut Посмотреть сообщение
1. Это не C++.
C чего Вы взяли?
Просто документацию вплели в реализацию.
Плюс куча дефайнов.
0
0 / 0 / 0
Регистрация: 11.11.2015
Сообщений: 17
26.10.2016, 16:40  [ТС] 4
Я пробовал, но я хочу вникнуть в сам синтаксис
литературу сколько искал, ничего не нашел
0
Объявлятель переменных
1220 / 406 / 320
Регистрация: 24.09.2011
Сообщений: 1,265
26.10.2016, 16:51 5
Цитата Сообщение от GbaLog- Посмотреть сообщение
C чего Вы взяли?
Виноват. C++ с Ansys'овскими библиотеками.
Цитата Сообщение от BigBro54 Посмотреть сообщение
я хочу вникнуть в сам синтаксис
Ищите учебники и пособия по Ansys Fluent. Тут, судя по поиску, им мало кто владеет.
0
26.10.2016, 16:51
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
26.10.2016, 16:51
Помогаю со студенческими работами здесь

Установка ANSYS 14.5.7
Добрый день! Прошу помочь с установкой ANSYS 14.5.7 на этапе установки лицензий. При установке...

Особености использование Ansys
Вот у меня в методичке для лабораторной указано что выбрать элемент 92 среди типов элементов. Но...

ANSYS Matlab Interface
Здравствуйте! На сегодняшний день, многие стремятся интегрировать среды моделирования и CAD...

Ошибка после установки ANSYS 14
здравствуйте ,произошла данная ошибка после установки ansys &quot;Can't read env(Ansys_appdata_dir) no...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
5
Ответ Создать тему
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2024, CyberForum.ru