#include #include #include static ofstream ofs("..\\three_d\\model.cpp", ios::out | ios::trunc); static ifstream ifs("solidex.NEU", ios::in); #define NODE 403 #define ELEMENT 404 #define CONSTRAINT 506 #define LOAD 507 #define BEGIN_AND_END -1 #define TRUE 1 #define FALSE 0 int begin() { // "begin" and "end" of the data blocks start at fourth column with "-1" char c; int negative_one; if(ifs.get(c) && c != ' ') { // 1st space while(ifs.get(c) && c != '\n'); return FALSE; } else { if(ifs.get(c) && c != ' ') { // 2nd space while(ifs.get(c) && c != '\n'); return FALSE; } else { if(ifs.get(c) && c != ' ') { // 3rd space while(ifs.get(c) && c != '\n'); return FALSE; } else { ifs >> negative_one; if(negative_one != BEGIN_AND_END) return FALSE; while(ifs.get(c) && c != '\n'); // skip the rest of the line } } } return TRUE; } int end() { return begin(); } // "end" and "begin" in FEMAP neutral file format share the same code int ID() { char c; int id; ifs >> id; // get ID while(ifs.get(c) && c != '\n'); // get char until return return id; } int match_block_ID(int id) { while(begin() != TRUE); if(ID() != id) { while(end() != TRUE); // skip remaining data util get to the end of the data block return match_block_ID(id); // recursive function call until match } return TRUE; } void define_node() { ofs << "Omega_h::Omega_h() {" << endl << endl << " // define nodes" << endl << " double x[3];" << " Node *node;" << endl; int node_no, integer; double x[3]; char c; while(ifs.get(c) && c != ' ') { ifs.putback(c); ifs >> node_no; ifs.get(c); for(int i = 0; i < 10; i++) { ifs >> integer; ifs.get(c); } // skip five integers for(i = 0; i < 3; i++) { ifs >> x[i]; ifs.get(c); } while(ifs.get(c) && c != '\n'); // get char until return // define nodes ofs << " x[0] = " << x[0] << "; x[1] = " << x[1] << "; x[2] = " << x[2] << ";" << endl << " node = new Node(" << node_no << ", 3, x);" << endl << " the_node_array.add(node);" << endl; } ifs.putback(c); while(end() == FALSE); // get to the end of the data block } void define_element() { int element_no, ena[4]; char c; ofs << endl << " // define elements" << endl << " int ena[4];" << " Omega_eh *elem;" << endl; while(ifs.get(c) && c != ' ') { ifs.putback(c); ifs >> element_no; while(ifs.get(c) && c != '\n'); // skip the remaining data on the first record for(int i = 0; i < 5; i++) { // for tetrahedral element 0, 1, 2, 4 are used in FEMAP neutral file format int j, integer; (i == 4) ? j = 3 : j = i; if(i == 3) { ifs >> integer; ifs.get(c); } else { ifs >> ena[j]; ifs.get(c); } } while(ifs.get(c) && c != '\n'); // skip the remaining data on the second record while(ifs.get(c) && c != '\n'); // skip the remaining data on the third record while(ifs.get(c) && c != '\n'); // skip the remaining data on the fourth record while(ifs.get(c) && c != '\n'); // skip the remaining data on the fifth record while(ifs.get(c) && c != '\n'); // skip the remaining data on the sixth record while(ifs.get(c) && c != '\n'); // skip the remaining data on the seventh record ofs << " ena[0] = " << ena[0] << "; ena[1] = " << ena[1] << "; ena[2] = " << ena[2] << "; ena[3] = " << ena[3] << ";" << endl << " elem = new Omega_eh(" << element_no << ", 0, 0, 4, ena);" << endl << " the_omega_eh_array.add(elem);" << endl; } ofs << "}" << endl; ifs.putback(c); while(end() == FALSE); // get to the end of the data block } void define_constraint_load() { double c[] = {249, 230, 231, 246, 223, 238, 251, 252, 253, 244, 237, 216, 241, 214, 217}, l[] = { 85, 162, 163, 4, 3, 166, 129, 8, 27, 26, 25, 24, 23, 22, 101, 32, 31, 30, 29, 28, 21, 100, 37, 36, 35, 34, 33, 132, 99, 42, 41, 40, 39, 38, 133, 49, 48, 14, 15, 45, 44, 134}; ofs << "gh_on_Gamma_h::gh_on_Gamma_h(int df, Omega_h& omega_h) {" << endl << " __initialization(df, omega_h);" << endl; // fixed boundary conditions ofs << " // fixed boundary conditions" << endl << " for(int i = 0; i < df; i++) {" << endl; for(int i = 0; i < 15; i++) ofs << " the_gh_array[node_order(" << c[i] << ")](i) = gh_on_Gamma_h::Dirichlet;" << endl; ofs << " }" << endl; // loadings ofs << endl << " // loadings" << endl; for(i = 0; i < 42; i++) ofs << " the_gh_array[node_order(" << l[i] << ")][2] = -500.0;" << endl; ofs << "}" << endl; } int main() { // read/output node match_block_ID(NODE); define_node(); // read/output element match_block_ID(ELEMENT); define_element(); define_constraint_load(); // read/output constraint //match_block_ID(CONSTRAINT); //define_constraint(); // read/output load //match_block_ID(LOAD); // define_load(); ofs.close(); ifs.close(); return 0; }