1 /*****************************************************************************
2  * Copyright (c) 2019 FrontISTR Commons
3  * This software is released under the MIT License, see LICENSE.txt
4  *****************************************************************************/
5 /*
6   CHECDB_Section Ver.1.0
7 */
8 
9 #include "CHECDB.h"
10 #include "CHECData.h"
11 
12 using namespace std;
13 using namespace hecd_util;
14 
CHECDB_Section()15 CHECDB_Section::CHECDB_Section()
16     : CHECDataBlock(HECDB_SECTION),
17       type(TYPE_UNKNOWN),
18       n_comp(0),
19       secopt(0),
20       thickness(1.0),
21       integpoints(0),
22       gapcon(0),
23       gaprad1(0),
24       gaprad2(0) {
25   egrp[0]     = 0;
26   material[0] = 0;
27 }
28 
~CHECDB_Section()29 CHECDB_Section::~CHECDB_Section() {}
30 
Clear()31 void CHECDB_Section::Clear() {
32   type        = TYPE_UNKNOWN;
33   n_comp      = 0;
34   secopt      = 0;
35   thickness   = 1.0;
36   integpoints = 0;
37   gapcon      = 0;
38   gaprad1     = 0;
39   gaprad2     = 0;
40   egrp[0]     = 0;
41   material[0] = 0;
42 }
43 
Write(CHECData * hecd)44 void CHECDB_Section::Write(CHECData *hecd) {
45   switch (type) {
46     case TYPE_SOLID:
47       hecd->WriteHeader("!SECTION", "SSS", "TYPE", "SOLID", "EGRP", egrp,
48                         "MATERIAL", material);
49       hecd->WriteData("F", thickness);
50       break;
51 
52     case TYPE_SHELL:
53       hecd->WriteHeader("!SECTION", "SSS", "TYPE", "SHELL", "EGRP", egrp,
54                         "MATERIAL", material);
55       hecd->WriteData("FI", thickness, integpoints);
56       break;
57 
58     case TYPE_INTERFACE:
59       hecd->WriteHeader("!SECTION", "SSS", "INTERFACE", "SOLID", "EGRP", egrp,
60                         "MATERIAL", material);
61       hecd->WriteData("FFFF", thickness, gapcon, gaprad1, gaprad2);
62 
63     default:
64       assert(0);
65   }
66 }
67 
Read(class CHECData * hecd,char * header_line)68 bool CHECDB_Section::Read(class CHECData *hecd, char *header_line) {
69   int rcode[10];
70   char s[256], type_s[256];
71 
72   if (!hecd->ParseHeader(header_line, rcode, "SSS", "TYPE", s, "EGRP", egrp,
73                          "MATERIAL", material))
74     return false;
75 
76   cleanup_token(s, type_s);
77   toupper(type_s);
78 
79   if (strcmp(type_s, "SOLID") == 0) {
80     type = TYPE_SOLID;
81 
82     if (!hecd->ReadData(rcode, "F", &thickness)) return false;
83 
84   } else if (strcmp(type_s, "SHELL") == 0) {
85     type = TYPE_SHELL;
86 
87     if (!hecd->ReadData(rcode, "FI", &thickness, &integpoints)) return false;
88 
89   } else if (strcmp(type_s, "INTERFACE") == 0) {
90     type = TYPE_INTERFACE;
91 
92     if (!hecd->ReadData(rcode, "FFFF", &thickness, &gapcon, &gaprad1, &gaprad2))
93       return false;
94 
95   } else {
96     return false;
97   }
98 
99   return true;
100 }
101