BasicVec<int> find_with_index(Sc2String name, BasicVec<Sc2String> list){ BasicVec<int> res; res.reserve(list.size()); for(unsigned i=0;i<list.size();i++){ if(name==list[i]){res.push_back(i);} } return res; }
void aaadd( BasicVec<String> var_templ, BasicVec<BasicVec<String,2> > rep ) { if ( var_templ.size() ) { BasicVec<String> t = tokenize( var_templ.back(), ' ' ); var_templ.pop_back(); for( int i = 1; i < t.size(); ++i ) { rep.push_back( t[ 0 ], t[ i ] ); aaadd( var_templ, rep ); rep.pop_back(); } } else res << rep; }
Ptr<CompilationTree> CompilationEnvironment::make_lnk_compilation_tree( const String &exe, const BasicVec<Ptr<CompilationTree> > &obj, bool lib, bool dyn ) { Ptr<CompilationTree> &res = deepest_child()->cor_files[ exe ]; if ( not res ) { res = NEW( CompilationTree, exe ); for( int i = 0; i < obj.size(); ++i ) res->add_child( obj[ i ] ); BasicVec<String> obj_str; for( int i = 0; i < obj.size(); ++i ) obj_str << obj[ i ]->dst; res->cmd = lnk_cmd( exe, obj_str, lib, dyn ); } return res; }
void write_groups_attributs_datasets(std::ofstream &f,Sc2String input_hdf5, Sc2String name_elements, Sc2String name_fields, BasicVec<Sc2String> attributs, int time) { Hdf hdf(input_hdf5); BasicVec<Sc2String> lists; lists=hdf.list_dir(name_elements); #if DIM==2 BasicVec<Sc2String> tensor_comp("xx","yy","xy"); BasicVec<Sc2String> vector_comp("x","y"); #else BasicVec<Sc2String> tensor_comp("xx","yy","zz","xy","xz","yz"); BasicVec<Sc2String> vector_comp("x","y","z"); #endif BasicVec<Sc2String> list_fields_tensor_time("sigma","epsilon","sigma_skin", "epsilon_skin"); BasicVec<Sc2String> list_fields_vector_time("F", "W", "Fchap", "Wchap"); BasicVec<Sc2String> list_fields_scalar_time("sigma_von_mises","sigma_von_mises_skin"); BasicVec<Sc2String> list_fields_global("num_proc","material","num_group", "number", "nature"); for (unsigned i=0; i< lists.size(); i++) { Sc2String name_list; name_list << name_elements <<"/"<< lists[i]; Sc2String name_list_c0=name_list+"/mesh_c0"; int nb_elems; hdf.read_size(name_list_c0,nb_elems); //Ecriture des attributs en fonction de leur nom for (unsigned attr=0;attr<attributs.size();attr++) { if (find(attributs[attr], list_fields_tensor_time) ) { for(unsigned d=0;d<tensor_comp.size();d++){ Sc2String name_field; name_field << name_fields << "/pt_"<<time<<"/"<<attributs[attr]<<"/"<<lists[i]<<"/"<<tensor_comp[d]; f <<" <DataItem Name=\"" << name_field <<"\" Format=\"HDF\" NumberType=\"Float\" Precision=\"8\" Dimensions=\" "<< nb_elems << " \">" << input_hdf5 <<":"<< name_field <<" </DataItem>" << endl; } } else if (find(attributs[attr], list_fields_vector_time) ) { for(unsigned d=0;d<DIM;d++){ Sc2String name_field; name_field << name_fields << "/pt_"<<time<<"/"<<attributs[attr]<<"/"<<lists[i]<<"/"<<vector_comp[d]; f <<" <DataItem Name=\"" << name_field <<"\" Format=\"HDF\" NumberType=\"Float\" Precision=\"8\" Dimensions=\" "<< nb_elems << " \">" << input_hdf5 <<":"<< name_field <<" </DataItem>" << endl; } } else if (find(attributs[attr], list_fields_scalar_time) ) { Sc2String name_field; name_field << name_fields << "/pt_"<<time<<"/"<<attributs[attr]<<"/"<<lists[i]; f <<" <DataItem Name=\"" << name_field <<"\" Format=\"HDF\" NumberType=\"Float\" Precision=\"8\" Dimensions=\" "<< nb_elems << " \">" << input_hdf5 <<":"<< name_field << " </DataItem>" << endl; } else if (find(attributs[attr], list_fields_global)) { Sc2String name_field; name_field << name_elements << "/"<<lists[i]<<"/"<<attributs[attr]; f <<" <DataItem Name=\"" << name_field <<"\" Format=\"HDF\" NumberType=\"Float\" Precision=\"8\" Dimensions=\" "<< nb_elems << " \">" << input_hdf5 <<":"<< name_field << " </DataItem>" << endl; } } } }
void write_groups_datasets_2(std::ofstream &f,Sc2String input_hdf5, Sc2String name_group_elements){ //lecture des noms des listes d'elements // int nb_elems_tot=0; // int nb_nodes_elem_glob=4; Hdf hdf(input_hdf5); BasicVec<Sc2String> lists; lists=hdf.list_dir(name_group_elements); for (unsigned i=0; i< lists.size(); i++) { Sc2String name_list; name_list << name_group_elements << "/"<<lists[i]; Sc2String name_list_c0=name_list+"/mesh_c0"; int nb_elems; hdf.read_size(name_list_c0,nb_elems); //lecture du nombre d'elements dans la liste //lecture du type d'elements int nb_nodes_elem; Metil::String base; hdf.read_tag(name_list,"base",base,1); if (base=="Bar") nb_nodes_elem=2; // Bar else if (base=="Bar_3") nb_nodes_elem=2; // Bar_3, on ne prend que les 2 premiers noeuds else if (base=="Triangle") nb_nodes_elem=3; // Triangle else if (base=="Triangle_6") nb_nodes_elem=3; // Triangle_6, on ne prend que les 3 premiers noeuds else if (base=="Quadrilateral") nb_nodes_elem=4; // quad else if (base=="Tetrahedron") nb_nodes_elem=4; // Tetra else if (base=="Tetrahedron_10") nb_nodes_elem=10; // Tetra_10, on ne prend que les 4 premiers noeuds else if (base=="Hexahedron") nb_nodes_elem=8; // quad else { std::cerr << "Type d'element non implementé - voir le tag \"base\" dans le fichier hdf5" ; assert(0);} for (unsigned j=0;j<nb_nodes_elem ; j++) { Sc2String data_item; data_item << name_list << "/mesh_c" <<j ; f <<" <DataItem Name=\"" << data_item << "\" Format=\"HDF\" NumberType=\"Int\" Dimensions=\" "<< nb_elems << " 1\">" << input_hdf5 <<":"<< data_item <<" </DataItem>" << endl; } } }
bool find(Sc2String name, BasicVec<Sc2String> list){ bool res=0; for(unsigned i=0;i<list.size();i++){ if(name==list[i]){res=1; break;} } return res; }
Ptr<CompilationTree> CompilationEnvironment::make_compilation_tree( const String &app, const String &cpp, bool lib, bool dyn, bool make_libs ) { BasicVec<Ptr<CompilationTree> > obj; parse_cpp( obj, cpp, dyn ); // sort by directory if ( make_libs ) { String base_dir = directory_of( cpp ); std::map<String,Lib> map_lib; for( int i = 0; i < obj.size(); ++i ) { String dir = directory_of( obj[ i ]->children[ 0 ]->dst ); if ( dir == base_dir ) continue; map_lib[ dir ].obj << obj[ i ]; obj.remove( i-- ); } // make dylibs int cpt = 0; for( std::map<String,Lib>::iterator iter = map_lib.begin(); iter != map_lib.end(); ++iter ) { String name; name << app << "_" << cpt++; obj << make_lnk_compilation_tree( lib_for( name, dyn ), iter->second.obj, true, dyn ); } } // return make_lnk_compilation_tree( app, obj, lib, dyn ); }
String CompilationEnvironment::find_src( const String &filename, const String ¤t_dir, const BasicVec<String> &add_paths, bool allow_cur_dir ) const { // absolute path ? if ( filename[ 0 ] == '/' or filename[ 0 ] == '\\' ) return ( file_exists( filename ) ? filename : String() ); // try with current_dir String trial = current_dir + filename; if ( allow_cur_dir and file_exists( trial ) ) return trial; // try with add_paths for( int i = 0; i < add_paths.size(); ++i ) { trial = add_paths[ i ] + filename; if ( file_exists( trial ) ) return trial; } // try with inc_paths for( int i = 0; i < inc_paths.size(); ++i ) { trial = inc_paths[ i ] + filename; if ( file_exists( trial ) ) return trial; } // try with inc_paths of child if ( child ) return child->find_src( filename, current_dir ); // not found :( return String(); }
void write_nodes_attributs_datasets(std::ofstream &f,Sc2String input_hdf5,int nb_nodes,Sc2String name_fields, BasicVec<Sc2String> attributs, int time, int i_proc) { //ecriture des attributs aux noeuds BasicVec<Sc2String> dimensions("x","y","z"); for (unsigned attr=0;attr<attributs.size();attr++) { if (attributs[attr]=="displacements" or attributs[attr]=="displacements_skin") for(unsigned d=0;d<DIM;d++){ Sc2String name_field; name_field << name_fields <<"/pt_"<<time<<"/"<<attributs[attr]<<"/"<<dimensions[d]; f <<" <DataItem Name=\""<<name_field<<"_proc_"<<i_proc<<"\" Format=\"HDF\" NumberType=\"Float\" Precision=\"8\" Dimensions=\" "<< nb_nodes << " 1 \">" << input_hdf5 <<":"<< name_field<< " </DataItem>" << endl; } } }
void CompilationEnvironment::load_env_var() { if ( String str = get_env( "METIL_INC_PATHS" ) ) { BasicVec<String> lst = tokenize( str, ';' ); for( int i = 0; i < lst.size(); ++i ) add_inc_path( lst[ i ] ); } if ( String str = get_env( "METIL_LIB_PATHS" ) ) { BasicVec<String> lst = tokenize( str, ';' ); for( int i = 0; i < lst.size(); ++i ) add_lib_path( lst[ i ] ); } if ( String str = get_env( "METIL_LIB_NAMES" ) ) { BasicVec<String> lst = tokenize( str, ';' ); for( int i = 0; i < lst.size(); ++i ) add_lib_name( lst[ i ] ); } if ( String str = get_env( "METIL_PARSED" ) ) { BasicVec<String> lst = tokenize( str, ';' ); for( int i = 0; i < lst.size(); ++i ) parsed << lst[ i ]; } if ( String str = get_env( "METIL_COMP_DIR" ) ) _comp_dir = str; if ( String str = get_env( "METIL_CXX" ) ) CXX = str; if ( String str = get_env( "METIL_LD" ) ) LD = str; if ( String str = get_env( "METIL_NVCC" ) ) NVCC = str; if ( String str = get_env( "METIL_CPPFLAGS" ) ) CPPFLAGS = str; if ( String str = get_env( "METIL_LDFLAGS" ) ) LDFLAGS = str; if ( String str = get_env( "METIL_DEV_EMU" ) ) device_emulation = Val( str ); if ( String str = get_env( "METIL_REG_CNT" ) ) maxrregcount = Val( str ); if ( String str = get_env( "METIL_DBG_LEVEL" ) ) dbg_level = Val( str ); if ( String str = get_env( "METIL_OPT_LEVEL" ) ) opt_level = Val( str ); if ( String str = get_env( "METIL_CXX_NAME" ) ) cxx_name = str; }
String CompilationEnvironment::lnk_cmd( const String &exe, const BasicVec<String> &obj, bool lib, bool dyn ) const { String cmd = get_LD(); // basic flags if ( lib ) cmd << ( dyn ? " -shared" : " -static" ); // input / output cmd << " -o '" << exe << "'"; for( int i = 0; i < obj.size(); ++i ) cmd << " '" << obj[ i ] << "'"; // -L... -l... extra_lnk_cmd( cmd, lib, dyn ); // dylibs for (int i = 0; i < dylibs.size(); ++i) cmd << " " << dylibs[ i ]; return cmd; }
void write_grids_2(std::ofstream &f,Sc2String name_hdf5, Sc2String name_elements, Sc2String name_nodes, Sc2String name_fields, Sc2String generic_grid_name, BasicVec<Sc2String> attributs, int time, int i_proc) { Sc2String input_hdf5; input_hdf5 << name_hdf5 <<"_"<<i_proc<<".h5"; Hdf hdf(input_hdf5); int nb_nodes; Sc2String data_node_x = (name_nodes + "/x"); hdf.read_size(data_node_x,nb_nodes); BasicVec<Sc2String> lists; lists=hdf.list_dir(name_elements); BasicVec<Sc2String> list_fields_tensor_time("sigma","epsilon","sigma_skin", "epsilon_skin"); BasicVec<Sc2String> list_fields_vector_time("F", "W", "Fchap", "Wchap"); BasicVec<Sc2String> list_fields_scalar_time("sigma_von_mises","sigma_von_mises_skin"); BasicVec<Sc2String> list_fields_global("num_proc","material","num_group", "number", "nature"); for (unsigned i=0; i< lists.size(); i++) { Sc2String name_list; name_list << name_elements << "/" <<lists[i]; Sc2String num_list = Metil::String(lists[i]).end_from(5); Sc2String name_list_c0=name_list +"/mesh_c0"; int nb_elems; hdf.read_size(name_list_c0,nb_elems); int nb_nodes_elem; Sc2String JOIN, name_element_xdmf; Metil::String base; hdf.read_tag(name_list,"base",base); if (base=="Bar" or base=="Bar_3") { nb_nodes_elem=2; JOIN="JOIN($0 , $1 )"; name_element_xdmf="Bar"; } else if (base=="Triangle" or base=="Triangle_6") { nb_nodes_elem=3; JOIN="JOIN($0 , $1 , $2 )"; name_element_xdmf="Triangle"; } else if (base=="Quadrilateral" ) { nb_nodes_elem=4; JOIN="JOIN($0 , $1 , $2, $3 )"; name_element_xdmf="Quadrilateral"; } else if (base=="Tetrahedron" or base=="Tetrahedron_10") { nb_nodes_elem=4; JOIN="JOIN($0 , $1 , $2 , $3)"; name_element_xdmf="Tetrahedron"; } else if (base=="Hexahedron" ) { nb_nodes_elem=8; JOIN="JOIN($0 , $1 , $2 , $3, $4 , $5 , $6 , $7 )"; name_element_xdmf="Hexahedron"; } else { std::cerr << "Type d'element non implementé - creation grids xdmf" ; assert(0); } f<<" <Grid Name=\""<< generic_grid_name << "_" << num_list <<"\">" << endl; //reference a la topology (connectivites) f<<" <Topology Type=\""<<name_element_xdmf<<"\" NumberOfElements=\" "<< nb_elems << " \" >" << endl; f<<" <DataItem Dimensions=\" "<< nb_elems << " " << nb_nodes_elem <<" \" ItemType=\"Function\" Function=\""<<JOIN<<"\"> " <<endl; for (unsigned j=0;j<nb_nodes_elem ; j++) { Sc2String data_item; data_item << name_list << "/mesh_c" <<j ; f<<" <DataItem Reference=\"XML\"> /Xdmf/Domain/DataItem[@Name=\""<< data_item <<"\"] </DataItem> " << endl; } f<<" </DataItem> " <<endl; f<<" </Topology>" <<endl; //reference aux noeuds #if DIM==2 f<<" <Geometry Type=\"XY_Z\">"<<endl; Sc2String JOIN_vector="JOIN($0 , $1 )"; #else f<<" <Geometry Type=\"X_Y_Z\">"<<endl; Sc2String JOIN_vector="JOIN($0 , $1 , $2)"; #endif BasicVec<Sc2String> dimensions("x","y","z"); for(unsigned d=0;d<DIM;d++){ Sc2String name_coor_node; name_coor_node << name_nodes << "/"<< dimensions[d]<<"_proc_"<<i_proc; f<<" <DataItem Reference=\"XML\"> /Xdmf/Domain/DataItem[@Name=\""<<name_coor_node<<"\"] </DataItem> " << endl; } f<<" </Geometry>" <<endl; //reference aux attributs for (unsigned attr=0;attr<attributs.size();attr++) { if (attributs[attr]=="displacements" or attributs[attr]=="displacements_skin") { f<<" <Attribute Name=\""<<attributs[attr]<<"\" AttributeType=\"Vector\" Center=\"Node\">" << endl; f<<" <DataItem Dimensions=\" "<< nb_nodes << " "<< DIM <<" \" ItemType=\"Function\" Function=\""<<JOIN_vector<<"\"> " <<endl; for(unsigned d=0;d<DIM;d++){ Sc2String name_field; name_field << name_fields <<"/pt_"<<time<<"/"<<attributs[attr]<<"/"<<dimensions[d]<<"_proc_"<<i_proc; f<<" <DataItem Reference=\"XML\"> /Xdmf/Domain/DataItem[@Name=\""<<name_field<<"\"] </DataItem> " << endl; } f<<" </DataItem> " <<endl; f<<" </Attribute>"<<endl; } else if (find(attributs[attr], list_fields_vector_time)) { f<<" <Attribute Name=\""<<attributs[attr]<<"\" AttributeType=\"Vector\" Center=\"Cell\">" << endl; f<<" <DataItem Dimensions=\" "<< nb_elems << " "<< DIM <<" \" ItemType=\"Function\" Function=\""<<JOIN_vector<<"\"> " <<endl; for(unsigned d=0;d<DIM;d++){ Sc2String name_field; name_field << name_fields <<"/pt_"<<time<<"/"<<attributs[attr]<<"/"<<lists[i]<<"/"<<dimensions[d]; f<<" <DataItem Reference=\"XML\"> /Xdmf/Domain/DataItem[@Name=\""<<name_field<<"\"] </DataItem> " << endl; } f<<" </DataItem> " <<endl; f<<" </Attribute>"<<endl; } else if(find(attributs[attr], list_fields_tensor_time)) { #if DIM==2 int nb_comp_tensor=3; Sc2String JOIN_tensor="JOIN($0 , $1 , $2 )"; BasicVec<Sc2String> tensor_comp=("xx","yy","xy"); #else int nb_comp_tensor=6; Sc2String JOIN_tensor="JOIN($0 , $1 , $2, $3 , $4 , $5 )"; BasicVec<Sc2String> tensor_comp("xx","yy","zz","xy","xz","yz"); #endif f<<" <Attribute AttributeType=\"Tensor6\" Name=\""<<attributs[attr] <<"\" Center=\"Cell\">" << endl; f<<" <DataItem Dimensions=\" "<< nb_elems << " " << tensor_comp.size() << " \" ItemType=\"Function\" Function=\""<<JOIN_tensor<<"\"> " <<endl; for(unsigned d=0;d<tensor_comp.size();d++){ Sc2String name_field; name_field << name_fields << "/pt_"<<time<<"/"<<attributs[attr]<<"/"<<lists[i]<<"/"<<tensor_comp[d]; f<<" <DataItem Reference=\"XML\"> /Xdmf/Domain/DataItem[@Name=\""<< name_field <<"\"] </DataItem> " << endl; } f<<" </DataItem> " <<endl; f<<" </Attribute>"<<endl; } else if(find(attributs[attr], list_fields_scalar_time)) { f<<" <Attribute AttributeType=\"Scalar\" Name=\""<<attributs[attr]<<"\" Center=\"Cell\">" << endl; Sc2String name_field; name_field << name_fields << "/pt_"<<time<<"/"<<attributs[attr]<<"/"<<lists[i]; std::cout << name_field << std::endl; f<<" <DataItem Dimensions=\" "<< nb_elems << " 1 \" Reference=\"XML\"> /Xdmf/Domain/DataItem[@Name=\""<< name_field <<"\"] </DataItem> " << endl; f<<" </Attribute>"<<endl; } else if(find(attributs[attr], list_fields_global)) { f<<" <Attribute AttributeType=\"Scalar\" Name=\""<<attributs[attr]<<"\" Center=\"Cell\">" << endl; Sc2String name_field; name_field << name_elements << "/"<<lists[i]<<"/"<<attributs[attr]; f<<" <DataItem Dimensions=\" "<< nb_elems << " 1 \" Reference=\"XML\"> /Xdmf/Domain/DataItem[@Name=\""<< name_field <<"\"] </DataItem> " << endl; f<<" </Attribute>"<<endl; } } f<<" </Grid>"<< endl; } }
void write_grids(std::ofstream &f,Sc2String input_hdf5, Sc2String name_group_elements, Sc2String name_nodes, BasicVec<int> list, int nb_nodes, Sc2String generic_grid_name, Sc2String name_fields, BasicVec<Sc2String> attributs, int nt, TYPE val_time, int type_element, int i_proc) { Hdf hdf(input_hdf5); for (unsigned i=0; i< list.size(); i++) { Sc2String name_list; name_list << name_group_elements << "/list_" << list[i]; Sc2String name_list_c0=name_list+"/mesh_c0"; int nb_elems; hdf.read_size(name_list_c0,nb_elems); int nb_nodes_elem; Sc2String JOIN, name_element_xdmf; if(type_element==0){ int pattern_id; hdf.read_tag(name_list,"pattern_id",pattern_id); if (pattern_id==0 or pattern_id==1) { nb_nodes_elem=3; JOIN="JOIN($0 , $1 , $2 )"; name_element_xdmf="Triangle"; } else if (pattern_id==2 or pattern_id==3) { nb_nodes_elem=4; JOIN="JOIN($0 , $1 , $2 , $3)"; name_element_xdmf="Tetrahedron"; } else { std::cerr << "Type d'element enfant non implementé" ; assert(0); } }else if(type_element==1){ int interface_id; hdf.read_tag(name_list,"interface_id",interface_id); if (interface_id==0 or interface_id==1) { nb_nodes_elem=2; JOIN="JOIN($0 , $1 )"; name_element_xdmf="Bar"; } else if (interface_id==2 or interface_id==3) { nb_nodes_elem=3; JOIN="JOIN($0 , $1 , $2 )"; name_element_xdmf="Triangle"; } else { std::cerr << "Type d'element enfant non implementé" ; assert(0); } } f<<" <Grid Name=\""<< generic_grid_name << "_" << i <<"\">" << endl; f<<" <Time Value=\""<<val_time<<"\" />" << endl; f<<" <Topology Type=\""<<name_element_xdmf<<"\" NumberOfElements=\" "<< nb_elems << " \" >" << endl; f<<" <DataItem Dimensions=\" "<< nb_elems << " " << nb_nodes_elem <<" \" ItemType=\"Function\" Function=\""<<JOIN<<"\"> " <<endl; for (unsigned j=0;j<nb_nodes_elem ; j++) { Sc2String data_item; data_item << name_list << "/mesh_c" <<j ; f<<" <DataItem Reference=\"XML\"> /Xdmf/Domain/DataItem[@Name=\""<< data_item <<"\"] </DataItem> " << endl; } f<<" </DataItem> " <<endl; f<<" </Topology>" <<endl; #if DIM==2 f<<" <Geometry Type=\"XY_Z\">"<<endl; #else f<<" <Geometry Type=\"X_Y_Z\">"<<endl; #endif BasicVec<Sc2String> dimensions("x","y","z"); for(unsigned d=0;d<DIM;d++){ Sc2String name_coor_node; name_coor_node << name_nodes << "/"<< dimensions[d]<<"_proc_"<<i_proc; f<<" <DataItem Reference=\"XML\"> /Xdmf/Domain/DataItem[@Name=\""<<name_coor_node<<"\"] </DataItem> " << endl; } f<<" </Geometry>" <<endl; for (unsigned attr=0;attr<attributs.size();attr++) { if (attributs[attr]=="displacements") { f<<" <Attribute Name=\"displacements\" AttributeType=\"Vector\" Center=\"Node\">" << endl; f<<" <DataItem Dimensions=\" "<< nb_nodes << " "<< DIM <<" \" ItemType=\"Function\" Function=\""<<JOIN<<"\"> " <<endl; f<<" <DataItem Reference=\"XML\"> /Xdmf/Domain/DataItem[@Name=\"dx_"<<nt<<"\"] </DataItem> " << endl; f<<" <DataItem Reference=\"XML\"> /Xdmf/Domain/DataItem[@Name=\"dy_"<<nt<<"\"] </DataItem> " << endl; #if DIM==3 f<<" <DataItem Reference=\"XML\"> /Xdmf/Domain/DataItem[@Name=\"dz_"<<nt<<"\"] </DataItem> " << endl; #endif f<<" </DataItem> " <<endl; f<<" </Attribute>"<<endl; } else if(attributs[attr]=="sigma") { #if DIM==2 int nb_comp_tensor=3; Sc2String JOIN_tensor="JOIN($0 , $1 , $2 )"; BasicVec<Sc2String> tensor_comp_sigma=BasicVec<Sc2String>("sxx","syy","sxy"); #else int nb_comp_tensor=6; Sc2String JOIN_tensor="JOIN($0 , $1 , $2, $3 , $4 , $5 )"; BasicVec<Sc2String> tensor_comp_sigma=BasicVec<Sc2String>("sxx","syy","szz","sxy","sxz","syz"); #endif f<<" <Attribute AttributeType=\"Tensor6\" Name=\"sigma\" Center=\"Cell\">" << endl; f<<" <DataItem Dimensions=\" "<< nb_elems << " " << nb_comp_tensor << " \" ItemType=\"Function\" Function=\""<<JOIN_tensor<<"\"> " <<endl; for(unsigned nc=0;nc<nb_comp_tensor;nc++) f<<" <DataItem Reference=\"XML\"> /Xdmf/Domain/DataItem[@Name=\""<< name_group_elements << "_"<<tensor_comp_sigma[nc]<<"_"<<nt<<"\"] </DataItem> " << endl; f<<" </DataItem> " <<endl; f<<" </Attribute>"<<endl; } else if(attributs[attr]=="epsilon") { #if DIM==2 int nb_comp_tensor=3; Sc2String JOIN_tensor="JOIN($0 , $1 , $2 )"; BasicVec<Sc2String> tensor_comp_sigma=BasicVec<Sc2String>("exx","eyy","exy"); #else int nb_comp_tensor=6; Sc2String JOIN_tensor="JOIN($0 , $1 , $2, $3 , $4 , $5 )"; BasicVec<Sc2String> tensor_comp_sigma=BasicVec<Sc2String>("exx","eyy","ezz","exy","exz","eyz"); #endif f<<" <Attribute AttributeType=\"Tensor6\" Name=\"epsilon\" Center=\"Cell\">" << endl; f<<" <DataItem Dimensions=\" "<< nb_elems << " " << nb_comp_tensor << " \" ItemType=\"Function\" Function=\""<<JOIN_tensor<<"\"> " <<endl; for(unsigned nc=0;nc<nb_comp_tensor;nc++) f<<" <DataItem Reference=\"XML\"> /Xdmf/Domain/DataItem[@Name=\""<< name_group_elements << "_"<<tensor_comp_sigma[nc]<<"_"<<nt<<"\"] </DataItem> " << endl; f<<" </DataItem> " <<endl; f<<" </Attribute>"<<endl; } else if(attributs[attr]=="sigma_von_mises") { f<<" <Attribute AttributeType=\"Scalar\" Name=\"sigma_von_mises\" Center=\"Cell\">" << endl; f<<" <DataItem Dimensions=\" "<< nb_elems << " 1 \" Reference=\"XML\"> /Xdmf/Domain/DataItem[@Name=\""<< name_group_elements << "_smises_"<< nt<<"\"] </DataItem> " << endl; f<<" </Attribute>"<<endl; } } f<<" </Grid>"<< endl; } }
static void save_dep_vec( String &fd, const BasicVec<String> &vec ) { for( int i = 0; i < vec.size(); ++i ) fd << vec[ i ].size() << vec[ i ]; fd << "0\n"; }
bool CompilationCppParser::init_using_dep( CompilationEnvironment &ce, const String &cpp_file, const String &dep_file ) { SI64 date_cpp = last_modification_time_or_zero_of_file_named( cpp_file ); SI64 date_dep = last_modification_time_or_zero_of_file_named( dep_file ); if ( date_cpp > date_dep ) return false; File fd( dep_file, "r" ); const char *c = fd.c_str(); // orig flags are conform ? BasicVec<String> loc_inc_paths; BasicVec<String> loc_def_procs; load_dep_vec( c, loc_inc_paths ); load_dep_vec( c, loc_def_procs ); if ( ce_inc_paths.size() != loc_inc_paths.size() or ce_def_procs.size() != loc_def_procs.size() ) return false; if ( any( ce_inc_paths != loc_inc_paths ) or any( ce_def_procs != loc_def_procs ) ) return false; // include file are older than dep file ? load_dep_vec( c, inc_files ); for( ST i = 0; i < inc_files.size(); ++i ) { if ( last_modification_time_or_zero_of_file_named( inc_files[ i ] ) > date_dep ) { inc_files.resize( 0 ); return false; } } // -> OK load_dep_vec( c, moc_files ); load_dep_vec( c, src_files ); load_dep_vec( c, lib_paths ); load_dep_vec( c, lib_names ); load_dep_vec( c, fra_names ); load_dep_vec( c, inc_paths ); load_dep_vec( c, cpp_flags ); load_dep_vec( c, lnk_flags ); load_dep_vec( c, gpu_flags ); load_dep_vec( c, var_templ ); load_dep_vec( c, cxx_name ); BasicVec<String> defs; load_dep_vec( c, defs ); for( int i = 0; i < defs.size(); ++i ) defines[ defs[ i ] ]; // .h.py ? for( int i = 0; i < inc_files.size(); ++i ) { String inc_file = inc_files[ i ]; if ( inc_file.ends_with( ".h" ) ) { String h_py = inc_file + ".py"; if ( file_exists( h_py ) ) { if ( last_modification_time_or_zero_of_file_named( h_py ) > last_modification_time_or_zero_of_file_named( inc_file ) ) make_h_py( h_py, inc_file ); } } } return true; }
void CompilationCppParser::parse_src_file_rec( CompilationEnvironment &ce, const String &filename ) { if ( is_a_directory( filename ) ) return; String current_dir = directory_of( filename ) + "/"; File file( filename, "r" ); for ( const char *c = file.c_str(); *c; ) { // string ? if ( c[ 0 ] == '"' ) { go_after_next_double_quote( ++c ); continue; } // comment ? if ( c[ 0 ] == '/' ) { if ( c[ 1 ] == '/' ) { go_to_next_line( c += 2 ); continue; } if ( c[ 1 ] == '*' ) { go_to_next_mul_slash( c += 2 ); continue; } } // QOBJECT ? if ( c[ 0 ] == 'Q' ) { if ( strncmp( c + 1, "_OBJECT", 7 ) == 0 ) { c += 8; if ( not filename.begins_by( "/usr/" ) ) // hum !! moc_files.push_back_unique( filename ); continue; } } // if ( c[ 0 ] == '#' ) { if ( c[ 1 ] == 'd' and c[ 2 ] == 'e' and c[ 3 ] == 'f' and c[ 4 ] == 'i' and c[ 5 ] == 'n' and c[ 6 ] == 'e' and c[ 7 ] == ' ' ) { defines[ get_next_word( c += 8 ) ]; continue; } if ( c[ 1 ] == 'i' ) { if ( c[ 2 ] == 'f' ) { if ( c[ 3 ] == 'd' and c[ 4 ] == 'e' and c[ 5 ] == 'f' and c[ 6 ] == ' ' ) { if ( not defines.count( get_next_word( c += 7 ) ) ) skip_lines_until_endif_or_else( c ); continue; } if ( c[ 3 ] == 'n' and c[ 4 ] == 'd' and c[ 5 ] == 'e' and c[ 6 ] == 'f' and c[ 7 ] == ' ' ) { if ( defines.count( get_next_word( c += 8 ) ) ) skip_lines_until_endif_or_else( c ); continue; } } if ( c[ 2 ] == 'n' and c[ 3 ] == 'c' and c[ 4 ] == 'l' and c[ 5 ] == 'u' and c[ 6 ] == 'd' and c[ 7 ] == 'e' and c[ 8 ] == ' ' ) { bool syst; String bas_name = get_include_filename( c += 9, syst ); String inc_file = ce.find_src( bas_name, current_dir, inc_paths, not syst ); if ( not inc_file ) inc_file = ce.find_src( bas_name, current_dir, ce_inc_paths, not syst ); // formulation. if ( not inc_file ) { int form_ind = bas_name.find( "formulation." ); if ( form_ind >= 0 and bas_name != "formulation.h" ) { String h_py = bas_name + ".py"; if ( not file_exists( h_py ) ) { int beg_form = form_ind + 12; int end_form = bas_name.find( ".", beg_form ); String form = bas_name.beg_upto( end_form ).end_from( beg_form ); int beg_elem = end_form + 1; int end_elem = bas_name.find( ".", beg_elem ); String elem = bas_name.beg_upto( end_elem ).end_from( beg_elem ); BasicVec<String> elem_list = tokenize( elem, ',' ); int beg_parm = end_elem + 1; int end_parm = bas_name.find( ".", beg_parm ); String parm = bas_name.beg_upto( end_parm ).end_from( beg_parm ); BasicVec<String> parm_list = tokenize( parm, ',' ); BasicVec<String> der_vars; BasicVec<String> dim; for( int np = 0; np < parm_list.size(); ++np ) { if ( parm_list[ np ].begins_by( "name_der_vars=" ) ) der_vars << parm_list[ np ].end_from( 14 ); else if ( parm_list[ np ].begins_by( "dim=" ) ) dim << parm_list[ np ].end_from( 4 ); } File f( h_py, "w" ); // f << "import sys, os\n"; // f << "sys.path.append( os.getcwd() + '/LMT' )\n"; // f << "sys.path.append( os.getcwd() + '/LMTpp' )\n"; f << "import formal_lf\n"; f << "formal_lf.write_pb(\n"; f << " name = '" << form << "',\n"; f << " formulations = ['" << form << "'],\n"; f << " elements = ["; for( int i = 0; i < elem_list.size(); ++i ) f << ( i ? ",'" : "'" ) << elem_list[ i ] << "'"; f << "],\n"; f << " incpaths = ['.'"; for( int i = 0; i < ce_inc_paths.size(); ++i ) if ( ce_inc_paths[ i ].find( "LMT" ) >= 0 ) f << ",'" << ce_inc_paths[ i ].beg_upto( ce_inc_paths[ i ].find( "/include" ) ) << "/formulations'"; f << "],\n"; f << " name_der_vars=["; for( int nd = 0; nd < der_vars.size(); ++nd ) f << ( nd ? "," : "" ) << '"' << der_vars[ nd ] << '"'; f << "],\n"; if ( dim.size() ) f << " dim='" << dim[ 0 ] << "',\n"; f << ")\n"; // f << " options = { 'behavior_simplification' : 'plane stress', 'behavior_law' : s }, // f << " # name_der_vars = [ "frac_E2", "frac_G12", "nu12" ] # } } } // .h.py ? if ( bas_name.ends_with( ".h" ) ) { if ( String h_py = ce.find_src( bas_name + ".py", current_dir ) ) { inc_file = h_py.beg_upto( h_py.size() - 3 ); if ( last_modification_time_or_zero_of_file_named( h_py ) > last_modification_time_or_zero_of_file_named( inc_file ) ) make_h_py( h_py, inc_file ); } } // parse rec if ( inc_file ) { inc_file = canonicalize_filename( inc_file ); inc_files << inc_file; // if ( not already_parsed.contains( inc_file ) ) { already_parsed << inc_file; parse_src_file_rec( ce, inc_file ); } } continue; } } if ( c[ 1 ] == 'p' and c[ 2 ] == 'r' and c[ 3 ] == 'a' and c[ 4 ] == 'g' and c[ 5 ] == 'm' and c[ 6 ] == 'a' and c[ 7 ] == ' ' ) { c += 8; if ( strncmp( c, "src_file ", 9 ) == 0 ) { String o = get_pragma_arg( c += 9 ); String s = ce.find_src( o, current_dir ); if ( s.size() ) src_files << s; else cerrn << "Impossible to find src '" << o << "'"; continue; } if ( strncmp( c, "lib_path ", 9 ) == 0 ) { lib_paths << ce.find_src( get_pragma_arg( c += 9 ), current_dir ); continue; } if ( strncmp( c, "lib_name ", 9 ) == 0 ) { lib_names << get_pragma_arg( c += 9 ); continue; } if ( strncmp( c, "fra_name ", 9 ) == 0 ) { fra_names << get_pragma_arg( c += 9 ); continue; } if ( strncmp( c, "inc_path ", 9 ) == 0 ) { String path = ce.find_src( get_pragma_arg( c += 9 ), current_dir ); if ( not ( path.ends_with( '/' ) or path.ends_with( '\\' ) ) ) path += '/'; inc_paths << path; continue; } if ( strncmp( c, "cpp_flag ", 9 ) == 0 ) { cpp_flags << get_pragma_arg( c += 9 ); continue; } if ( strncmp( c, "lnk_flag ", 9 ) == 0 ) { lnk_flags << get_pragma_arg( c += 9 ); continue; } if ( strncmp( c, "gpu_flag ", 9 ) == 0 ) { gpu_flags << get_pragma_arg( c += 9 ); continue; } if ( strncmp( c, "template ", 9 ) == 0 ) { var_templ << get_pragma_arg( c += 9 ); continue; } if ( strncmp( c, "cxx_name ", 9 ) == 0 ) { cxx_name << get_pragma_arg( c += 9 ); continue; } } } // ++c; } }