FrontISTR  5.7.0
Large-scale structural analysis program with finit element method
conv_neu2fstr_static.cpp
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright (c) 2019 FrontISTR Commons
3  * This software is released under the MIT License, see LICENSE.txt
4  *****************************************************************************/
5 /*
6  conv_neu2fstr_static ver.1.01
7 */
8 
9 #include <vector>
10 #include <set>
11 #include <stdlib.h>
12 
13 #include "conv_neu2fstr_static.h"
14 #include "cconv_mat.h"
15 #include "conv_util.h"
16 
17 using namespace std;
18 using namespace n2h_util;
19 
20 static void ItoA(int i, char *s) { sprintf(s, "%d", i); }
21 
22 static int mesh_dof = 3;
23 
24 static bool check_mesh_for_fstr(CHECData &hec) {
25  bool fg_dof[4] = {false, false, false, false};
26  int dof_tbl[4] = {1, 2, 3, 6};
27  vector<CHECDataBlock *>::iterator iter;
28 
29  for (iter = hec.DB.begin(); iter != hec.DB.end(); iter++) {
30  if ((*iter)->data_type == HECDB_ELEMENT) {
31  CHECDB_Element *e = (CHECDB_Element *)*iter;
32 
33  switch (e->DOFNumber(e->type)) {
34  case 1:
35  fg_dof[0] = true;
36  break;
37 
38  case 2:
39  fg_dof[1] = true;
40  break;
41 
42  case 3:
43  fg_dof[2] = true;
44  break;
45 
46  case 6:
47  fg_dof[3] = true;
48  break;
49 
50  default:
51  assert(0);
52  }
53  }
54  }
55 
56  int c = 0;
57 
58  for (int i = 0; i < 4; i++) {
59  if (fg_dof[i]) {
60  c++;
61  mesh_dof = dof_tbl[i];
62  }
63  }
64 
65  if (c != 1) {
66  printf("### FrontSTR does not permit plural DOF\n");
67  fflush(stdout);
68  return false;
69  }
70 
71  return true;
72 }
73 
74 //-----------------------------------------------------------------------------
75 // BOUNDARY
76 //-----------------------------------------------------------------------------
77 
78 class cbitem {
79  public:
80  int nid; // node id
81  double value;
82  cbitem(int id = -1, double v = 0) : nid(id), value(v) {}
83  cbitem(const cbitem &i) : nid(i.nid), value(i.value) {}
84  cbitem &operator=(const cbitem &i) {
85  nid = i.nid;
86  value = i.value;
87  return *this;
88  }
89  void set_value(double v) { value = v; }
90 };
91 
92 inline bool operator==(const cbitem &a, const cbitem &b) {
93  return a.nid == b.nid;
94 }
95 inline bool operator<(const cbitem &a, const cbitem &b) {
96  return a.nid < b.nid;
97 }
98 inline bool operator>(const cbitem &a, const cbitem &b) {
99  return a.nid > b.nid;
100 }
101 
102 /*
103 static
104 CHECDB_NGroup* create_new_ngrp( CHECData& hec, const char* name )
105 {
106  CHECDB_NGroup* ngrp = new CHECDB_NGroup();
107  strcpy( ngrp->name, name );
108  return ngrp;
109 }
110 */
111 
112 static void set_boundary_node_by_506(set<cbitem> *bitem, int dof_n,
113  vector<CNFDB_506::cconst_item> &item,
114  CHECData &hec) {
115  vector<CNFDB_506::cconst_item>::iterator iter;
116 
117  for (iter = item.begin(); iter != item.end(); iter++) {
118  for (int i = 0; i < dof_n; i++) {
119  if (iter->DOF[i]) {
120  bitem[i].insert(cbitem(iter->ID));
121  }
122  }
123  }
124 }
125 
126 // execute after all executing set_boundary_node_by_506
127 
128 static void set_boundary_node_by_507(
129  set<cbitem> *bitem, vector<CNFDB_507::cstructural_load_rec> &item,
130  CHECData &hec) {
131  const int load_dof = 3;
132  const int FEA_load_nDisplacement = 3;
133  vector<cbitem> new_bitem[load_dof];
134  vector<CNFDB_507::cstructural_load_rec>::iterator iter;
135 
136  for (iter = item.begin(); iter != item.end(); iter++) {
137  if (iter->loadtype != FEA_load_nDisplacement) continue;
138 
139  set<cbitem>::iterator biter;
140 
141  for (int i = 0; i < load_dof; i++) { // not dof_n !!
142  // biter = find( bitem[i].begin(), bitem[i].end(), cbitem(
143  // iter->loadID ));
144  for (biter = bitem[i].begin(); biter != bitem[i].end(); biter++) {
145  if (biter->nid == iter->loadID) break;
146  }
147 
148  if (biter == bitem[i].end()) continue;
149 
150  bitem[i].erase(biter);
151  new_bitem[i].push_back(cbitem(iter->loadID, iter->value[i]));
152  }
153  }
154 
155  for (int i = 0; i < load_dof; i++) {
156  vector<cbitem>::iterator biter;
157 
158  for (biter = new_bitem[i].begin(); biter != new_bitem[i].end(); biter++) {
159  bitem[i].insert(*biter);
160  }
161  }
162 }
163 
164 // CAUTION) NOT SUPPORTED CURVE AND SURFACE NOW!!
165 static void SetBoundary(CNFData &neu, CHECData &hec) {
166  const int max_dof_n = 6;
167  set<cbitem> bitem[max_dof_n];
168  int dof_n = mesh_dof;
169  // search 506
170  {
171  vector<CNFDB_506 *>::iterator iter;
172 
173  for (iter = neu.DB_506.begin(); iter != neu.DB_506.end(); iter++) {
174  CNFDB_506 *p = *iter;
175  set_boundary_node_by_506(bitem, dof_n, p->const_nodes, hec);
176  }
177  }
178  // search 507
179  {
180  vector<CNFDB_507 *>::iterator iter;
181 
182  for (iter = neu.DB_507.begin(); iter != neu.DB_507.end(); iter++) {
183  CNFDB_507 *p = *iter;
184  set_boundary_node_by_507(bitem, p->structural_load_list, hec);
185  }
186  }
187  // registration
188  {
190 
191  for (int i = 0; i < dof_n; i++) {
192  set<cbitem>::iterator iter;
193 
194  for (iter = bitem[i].begin(); iter != bitem[i].end(); iter++) {
195  char name[256];
196  ItoA(iter->nid, name);
197  int dof = i + 1;
198  CFSTRDB_Boundary::CItem item(name, dof, dof, iter->value);
199  bc->ItemList.push_back(item);
200  }
201  }
202 
203  if (bc->ItemList.size() > 0) {
204  hec.DB.push_back(bc);
205 
206  } else {
207  delete bc;
208  }
209  }
210 }
211 
212 //-----------------------------------------------------------------------------
213 // CLOAD
214 //-----------------------------------------------------------------------------
215 
216 static void SetCLoad(CNFData &neu, CHECData &hec) {
217  const int load_dof = 3;
218  const int FEA_load_nForce = 1;
219 
220  if (neu.DB_507.size() == 0) return;
221 
222  CFSTRDB_CLoad *cload = new CFSTRDB_CLoad();
223  vector<CNFDB_507 *>::iterator iter;
224 
225  for (iter = neu.DB_507.begin(); iter != neu.DB_507.end(); iter++) {
226  CNFDB_507 *p = *iter;
227  vector<CNFDB_507::cstructural_load_rec>::iterator siter;
228 
229  for (siter = p->structural_load_list.begin();
230  siter != p->structural_load_list.end(); siter++) {
231  if (siter->loadtype != FEA_load_nForce) continue;
232 
233  for (int i = 0; i < load_dof; i++) {
234  if (siter->dof_face[i] == 0) continue;
235 
236  char name[256];
237  ItoA(siter->loadID, name);
238  int dof = i + 1;
239  CFSTRDB_CLoad::CItem item(name, dof, siter->value[i]);
240  cload->ItemList.push_back(item);
241  }
242  }
243  }
244 
245  if (cload->ItemList.size() > 0) {
246  hec.DB.push_back(cload);
247 
248  } else {
249  delete cload;
250  }
251 }
252 
253 //-----------------------------------------------------------------------------
254 // DLOAD
255 //-----------------------------------------------------------------------------
256 
257 static void set_dload_grav(CNFDB_507 *block, CFSTRDB_DLoad *dload) {
258  if (!block->grav_on) return;
259 
260  double dir[3];
261  double g;
262  dir[0] = block->grav[0];
263  dir[1] = block->grav[1];
264  dir[2] = block->grav[2];
265  g = dir[0] * dir[0] + dir[1] * dir[1] + dir[2] * dir[2];
266 
267  if (g == 0) return;
268 
269  g = sqrt(g);
270  dir[0] /= g;
271  dir[1] /= g;
272  dir[2] /= g;
274  item.param[0] = g;
275  item.param[1] = dir[0];
276  item.param[2] = dir[1];
277  item.param[3] = dir[2];
278  dload->ItemList.push_back(item);
279 }
280 
281 static void set_dload_cent(CNFDB_507 *block, CFSTRDB_DLoad *dload) {
282  if (!block->omega_on) return;
283 
284  double dir[3];
285  double omega;
286  dir[0] = block->omega[0];
287  dir[1] = block->omega[1];
288  dir[2] = block->omega[2];
289  omega = dir[0] * dir[0] + dir[1] * dir[1] + dir[2] * dir[2];
290 
291  if (omega == 0) return;
292 
293  omega = sqrt(omega);
294  dir[0] /= omega;
295  dir[1] /= omega;
296  dir[2] /= omega;
298  item.param[0] = omega;
299  item.param[1] = block->origin[0];
300  item.param[2] = block->origin[1];
301  item.param[3] = block->origin[2];
302  item.param[4] = dir[0];
303  item.param[5] = dir[1];
304  item.param[6] = dir[2];
305  dload->ItemList.push_back(item);
306 }
307 
308 static void SetDLoad(CNFData &neu, CHECData &hec) {
309  const int FEA_load_ePressure = 42;
310 
311  if (neu.DB_507.size() == 0) return;
312 
313  CFSTRDB_DLoad *dload = new CFSTRDB_DLoad();
314  vector<CNFDB_507 *>::iterator iter;
315 
316  for (iter = neu.DB_507.begin(); iter != neu.DB_507.end(); iter++) {
317  CNFDB_507 *p = *iter;
318  set_dload_grav(p, dload);
319  set_dload_cent(p, dload);
320  vector<CNFDB_507::cstructural_load_rec>::iterator siter;
321 
322  for (siter = p->structural_load_list.begin();
323  siter != p->structural_load_list.end(); siter++) {
324  if (siter->loadtype != FEA_load_ePressure) continue;
325 
326  int eid = siter->loadID;
327  int surf_no = siter->dof_face[0];
328  int hec_e_type = hec.GetElemType(eid);
329 
330  if (hec_e_type == 0) continue;
331 
332  int fg_front;
333  int load_type =
334  CFSTRDB_DLoad::TYPE_P0 + hec_face_no(hec_e_type, surf_no, fg_front);
335  double load = fg_front ? siter->value[0] : -siter->value[0];
336  char name[256];
337  ItoA(siter->loadID, name);
338  CFSTRDB_DLoad::CItem item(name, load_type);
339  item.param[0] = load;
340  dload->ItemList.push_back(item);
341  }
342  }
343 
344  if (dload->ItemList.size() > 0) {
345  hec.DB.push_back(dload);
346 
347  } else {
348  delete dload;
349  }
350 }
351 
352 //-----------------------------------------------------------------------------
353 // TEMPERATURE
354 //-----------------------------------------------------------------------------
355 
356 class cnode_temp {
357  public:
358  int nid;
359  double value;
360  cnode_temp(int id = -1, double v = 0) : nid(id), value(v) {}
361 };
362 
363 inline bool operator==(const cnode_temp &a, const cnode_temp &b) {
364  return a.nid == b.nid;
365 }
366 inline bool operator<(const cnode_temp &a, const cnode_temp &b) {
367  return a.nid < b.nid;
368 }
369 inline bool operator>(const cnode_temp &a, const cnode_temp &b) {
370  return a.nid > b.nid;
371 }
372 
373 static void set_temp_node(vector<CNFDB_507::ctemp_load_rec> &tload,
374  set<cnode_temp> &nt) {
375  vector<CNFDB_507::ctemp_load_rec>::iterator iter;
376 
377  for (iter = tload.begin(); iter != tload.end(); iter++) {
378  cnode_temp item(iter->ID, iter->temp);
379  nt.insert(item);
380  }
381 }
382 
383 static void set_temp_elem(CHECData &hec,
384  vector<CNFDB_507::ctemp_load_rec> &tload,
385  set<cnode_temp> &nt) {
386  vector<CNFDB_507::ctemp_load_rec>::iterator iter;
387 
388  for (iter = tload.begin(); iter != tload.end(); iter++) {
389  CHECDB_Element::CElemItem *elem = hec.GetElemItem(iter->ID);
390 
391  if (!elem) continue;
392 
393  for (int i = 0; i < elem->node_n; i++) {
394  cnode_temp item(elem->node[i], iter->temp);
395  nt.insert(item);
396  }
397  }
398 }
399 
400 static void SetTemperature(CNFData &neu, CHECData &hec) {
401  if (neu.DB_507.size() == 0) return;
402 
403  set<cnode_temp> nt;
404  vector<CNFDB_507 *>::iterator iter;
405 
406  for (iter = neu.DB_507.begin(); iter != neu.DB_507.end(); iter++) {
407  CNFDB_507 *p = *iter;
408  set_temp_node(p->ndtemp_load_list, nt);
409  set_temp_elem(hec, p->eltemp_load_list, nt);
410  }
411 
412  if (nt.size() > 0) {
414  hec.DB.push_back(temp);
415  }
416 }
417 
418 //-----------------------------------------------------------------------------
419 // REFTEMP
420 //-----------------------------------------------------------------------------
421 
422 static void SetReftemp(CNFData &neu, CHECData &hec) {
423  if (neu.DB_507.size() == 0) return;
424 
425  if (neu.version < 8.0) return;
426 
427  vector<CNFDB_507 *>::iterator iter;
428 
429  for (iter = neu.DB_507.begin(); iter != neu.DB_507.end(); iter++) {
430  CNFDB_507 *p = *iter;
431 
432  if (p->Ref_temp_on) {
433  CFSTRDB_Reftemp *reftemp = new CFSTRDB_Reftemp();
434  reftemp->value = p->Ref_temp;
435  hec.DB.push_back(reftemp);
436  }
437  }
438 }
439 
440 //=============================================================================
441 // conv_neu2fstr_static
442 //=============================================================================
443 
445  if (!check_mesh_for_fstr(hec)) throw;
446 
447  SetBoundary(neu, hec);
448  SetCLoad(neu, hec);
449  SetDLoad(neu, hec);
450  SetTemperature(neu, hec);
451  SetReftemp(neu, hec);
452 }
operator<
bool operator<(const cbitem &a, const cbitem &b)
Definition: conv_neu2fstr_static.cpp:95
cnode_temp
Definition: conv_neu2fstr_static.cpp:356
CFSTRDB_Boundary::ItemList
std::vector< CItem > ItemList
Definition: CFSTRDB.h:182
CFSTRDB_Boundary::CItem
Definition: CFSTRDB.h:163
n2h_util
Definition: conv_util.h:11
CHECDB_Element::CElemItem
Definition: CHECDB.h:76
CFSTRDB_Reftemp
Definition: CFSTRDB.h:301
CFSTRDB_DLoad::TYPE_CENT
@ TYPE_CENT
Definition: CFSTRDB.h:232
CHECData::GetElemItem
virtual class CHECDB_Element::CElemItem * GetElemItem(int id)
Definition: CHECData.cpp:682
CFSTRDB_DLoad::TYPE_P0
@ TYPE_P0
Definition: CFSTRDB.h:221
CFSTRDB_Temperature
Definition: CFSTRDB.h:279
n2h_util::hec_face_no
int hec_face_no(int hec_etype, int neu_face, int &fg_front)
Definition: conv_util.h:39
CNFDB_507::omega_on
nf_bool omega_on
Definition: CNFDB_507.h:134
cbitem
Definition: conv_neu2fstr_static.cpp:78
CNFData::version
double version
Definition: CNFData.h:48
CFSTRDB_DLoad::CItem
Definition: CFSTRDB.h:239
cnode_temp::nid
int nid
Definition: conv_neu2fstr_static.cpp:358
conv_util.h
CNFDB_507::eltemp_load_list
std::vector< ctemp_load_rec > eltemp_load_list
Definition: CNFDB_507.h:236
CNFDB_507::Ref_temp
nf_float Ref_temp
Definition: CNFDB_507.h:136
CFSTRDB_Reftemp::value
double value
Definition: CFSTRDB.h:305
CNFDB_507::origin
nf_float origin[3]
Definition: CNFDB_507.h:140
CNFDB_507::Ref_temp_on
nf_bool Ref_temp_on
Definition: CNFDB_507.h:135
cbitem::value
double value
Definition: conv_neu2fstr_static.cpp:81
CFSTRDB_Boundary
Definition: CFSTRDB.h:161
CNFDB_506
Definition: CNFDB_506.h:17
conv_neu2fstr_static
void conv_neu2fstr_static(CNFData &neu, CHECData &hec)
Definition: conv_neu2fstr_static.cpp:444
cbitem::cbitem
cbitem(int id=-1, double v=0)
Definition: conv_neu2fstr_static.cpp:82
cconv_mat.h
CNFDB_507
Definition: CNFDB_507.h:17
CHECDB_Element::CElemItem::node_n
int node_n
Definition: CHECDB.h:79
CNFData
Definition: CNFData.h:46
CHECData::DB
std::vector< CHECDataBlock * > DB
Definition: CHECData.h:30
CNFDB_507::grav
nf_float grav[6]
Definition: CNFDB_507.h:138
CHECData
Definition: CHECData.h:25
conv_neu2fstr_static.h
cbitem::cbitem
cbitem(const cbitem &i)
Definition: conv_neu2fstr_static.cpp:83
CFSTRDB_CLoad
Definition: CFSTRDB.h:191
CHECDB_Element::type
int type
Definition: CHECDB.h:71
CFSTRDB_CLoad::ItemList
std::vector< CItem > ItemList
Definition: CFSTRDB.h:209
CNFDB_507::structural_load_list
std::vector< cstructural_load_rec > structural_load_list
Definition: CNFDB_507.h:233
cbitem::operator=
cbitem & operator=(const cbitem &i)
Definition: conv_neu2fstr_static.cpp:84
CNFDB_507::ndtemp_load_list
std::vector< ctemp_load_rec > ndtemp_load_list
Definition: CNFDB_507.h:235
operator>
bool operator>(const cbitem &a, const cbitem &b)
Definition: conv_neu2fstr_static.cpp:98
cnode_temp::value
double value
Definition: conv_neu2fstr_static.cpp:359
CNFDB_507::grav_on
nf_bool grav_on
Definition: CNFDB_507.h:133
CNFDB_506::const_nodes
std::vector< cconst_item > const_nodes
Definition: CNFDB_506.h:78
cbitem::set_value
void set_value(double v)
Definition: conv_neu2fstr_static.cpp:89
cbitem::nid
int nid
Definition: conv_neu2fstr_static.cpp:80
cnode_temp::cnode_temp
cnode_temp(int id=-1, double v=0)
Definition: conv_neu2fstr_static.cpp:360
CFSTRDB_CLoad::CItem
Definition: CFSTRDB.h:193
operator==
bool operator==(const cbitem &a, const cbitem &b)
Definition: conv_neu2fstr_static.cpp:92
CHECDB_Element
Definition: CHECDB.h:62
CFSTRDB_DLoad
Definition: CFSTRDB.h:218
CHECData::GetElemType
virtual int GetElemType(int id)
Definition: CHECData.cpp:696
CHECDB_Element::CElemItem::node
int * node
Definition: CHECDB.h:78
CFSTRDB_DLoad::ItemList
std::vector< CItem > ItemList
Definition: CFSTRDB.h:270
CNFDB_507::omega
nf_float omega[3]
Definition: CNFDB_507.h:142
CHECDB_Element::DOFNumber
static int DOFNumber(int type)
Definition: CHECDB_Element.cpp:149
HECDB_ELEMENT
@ HECDB_ELEMENT
Definition: CHECDB.h:23
CFSTRDB_DLoad::TYPE_GRAV
@ TYPE_GRAV
Definition: CFSTRDB.h:231