void CVODEModel::applyGradientDetector( const std::shared_ptr<PatchHierarchy>& hierarchy, const int level_number, const double time, const int tag_index, const bool initial_time, const bool uses_richardson_extrapolation_too) { NULL_USE(time); NULL_USE(initial_time); NULL_USE(uses_richardson_extrapolation_too); std::shared_ptr<PatchLevel> level( hierarchy->getPatchLevel(level_number)); for (PatchLevel::iterator p(level->begin()); p != level->end(); ++p) { const std::shared_ptr<Patch>& patch = *p; std::shared_ptr<CellData<int> > tag_data( SAMRAI_SHARED_PTR_CAST<CellData<int>, PatchData>( patch->getPatchData(tag_index))); TBOX_ASSERT(tag_data); // dumb implementation that tags all cells. tag_data->fillAll(TRUE); } }
void CESets::add_tag(iBase_TagHandle tag_handle, const char *value) { assert(tag_handle != NULL); char *tmp = NULL; if (value) { int err; int tag_size; iMesh_getTagSizeBytes(impl_, tag_handle, &tag_size, &err); check_error(impl_, err); tmp = static_cast<char*>(malloc(tag_size)); memcpy(tmp, value, tag_size); } tags_.push_back(tag_data(tag_handle, tmp)); }
static void display_latitude_or_longitude(struct writer *w, int option, u_int64_t value) { static char buf[70]; int negative; char * str; if ( option == 0 ) { tag_start(w, "lat", "Latitude"); } else { tag_start(w, "lon", "Longitude"); } negative = display_fixed_precision(value, 9, 25, 0, &str); if (option == 0) snprintf(buf, sizeof(buf), "%s %s", str, negative?" S":" N"); else snprintf(buf, sizeof(buf), "%s %s", str, negative?" W":" E"); tag_data(w, buf); tag_end(w); }
ErrorCode ReadGmsh::load_file(const char* filename, const EntityHandle*, const FileOptions&, const ReaderIface::SubsetList* subset_list, const Tag* file_id_tag) { int num_material_sets = 0; const int* material_set_list = 0; int zero = 0; if (subset_list) { if (subset_list->tag_list_length > 1 && !strcmp(subset_list->tag_list[0].tag_name, MATERIAL_SET_TAG_NAME)) { MB_SET_ERR(MB_UNSUPPORTED_OPERATION, "GMsh supports subset read only by material ID"); } material_set_list = subset_list->tag_list[0].tag_values; num_material_sets = subset_list->tag_list[0].num_tag_values; } geomSets.clear(); ErrorCode result = mdbImpl->tag_get_handle(GLOBAL_ID_TAG_NAME, 1, MB_TYPE_INTEGER, globalId, MB_TAG_DENSE | MB_TAG_CREAT, &zero); if (MB_SUCCESS != result) return result; // Create set for more convenient check for material set ids std::set<int> blocks; for (const int* mat_set_end = material_set_list + num_material_sets; material_set_list != mat_set_end; ++material_set_list) blocks.insert(*material_set_list); // Map of ID->handle for nodes std::map<long, EntityHandle> node_id_map; int data_size = 8; // Open file and hand off pointer to tokenizer FILE* file_ptr = fopen(filename, "r"); if (!file_ptr) { MB_SET_ERR(MB_FILE_DOES_NOT_EXIST, filename << ": " << strerror(errno)); } FileTokenizer tokens(file_ptr, readMeshIface); // Determine file format version const char* const start_tokens[] = {"$NOD", "$MeshFormat", 0}; int format_version = tokens.match_token(start_tokens); if (!format_version) return MB_FILE_DOES_NOT_EXIST; // If version 2.0, read additional header info if (2 == format_version) { double version; if (!tokens.get_doubles(1, &version)) return MB_FILE_WRITE_ERROR; if (version != 2.0 && version != 2.1 && version != 2.2) { MB_SET_ERR(MB_FILE_DOES_NOT_EXIST, filename << ": unknown format version: " << version); return MB_FILE_DOES_NOT_EXIST; } int file_format; if (!tokens.get_integers(1, &file_format) || !tokens.get_integers(1, &data_size) || !tokens.match_token("$EndMeshFormat")) return MB_FILE_WRITE_ERROR; // If physical entities in the gmsh file -> discard this const char* const phys_tokens[] = { "$Nodes", "$PhysicalNames", 0 }; int hasPhys = tokens.match_token(phys_tokens); if (hasPhys == 2) { long num_phys; if (!tokens.get_long_ints(1, &num_phys)) return MB_FILE_WRITE_ERROR; for (long loop_phys = 0; loop_phys < num_phys; loop_phys++) { long physDim; long physGroupNum; //char const * physName; if (!tokens.get_long_ints(1, &physDim)) return MB_FILE_WRITE_ERROR; if (!tokens.get_long_ints(1, &physGroupNum)) return MB_FILE_WRITE_ERROR; const char * ptc = tokens.get_string(); if (!ptc) return MB_FILE_WRITE_ERROR; // try to get to the end of the line, without reporting errors // really, we need to skip this while(!tokens.get_newline(false)) ptc = tokens.get_string(); } if (!tokens.match_token("$EndPhysicalNames") || !tokens.match_token( "$Nodes")) return MB_FILE_WRITE_ERROR; } } // Read number of nodes long num_nodes; if (!tokens.get_long_ints(1, &num_nodes)) return MB_FILE_WRITE_ERROR; // Allocate nodes std::vector<double*> coord_arrays; EntityHandle handle = 0; result = readMeshIface->get_node_coords(3, num_nodes, MB_START_ID, handle, coord_arrays); if (MB_SUCCESS != result) return result; // Read nodes double *x = coord_arrays[0], *y = coord_arrays[1], *z = coord_arrays[2]; for (long i = 0; i < num_nodes; ++i, ++handle) { long id; if (!tokens.get_long_ints(1, &id) || !tokens.get_doubles(1, x++) || !tokens.get_doubles(1, y++) || !tokens.get_doubles(1, z++)) return MB_FILE_WRITE_ERROR; if (!node_id_map.insert(std::pair<long, EntityHandle>(id, handle)).second) { MB_SET_ERR(MB_FILE_WRITE_ERROR, "Duplicate node ID at line " << tokens.line_number()); } } // Create reverse map from handle to id std::vector<int> ids(num_nodes); std::vector<int>::iterator id_iter = ids.begin(); std::vector<EntityHandle> handles(num_nodes); std::vector<EntityHandle>::iterator h_iter = handles.begin(); for (std::map<long, EntityHandle>::iterator i = node_id_map.begin(); i != node_id_map.end(); ++i, ++id_iter, ++h_iter) { *id_iter = i->first; * h_iter = i->second; } // Store IDs in tags result = mdbImpl->tag_set_data(globalId, &handles[0], num_nodes, &ids[0]); if (MB_SUCCESS != result) return result; if (file_id_tag) { result = mdbImpl->tag_set_data(*file_id_tag, &handles[0], num_nodes, &ids[0]); if (MB_SUCCESS != result) return result; } ids.clear(); handles.clear(); // Get tokens signifying end of node data and start of elements if (!tokens.match_token(format_version == 1 ? "$ENDNOD" : "$EndNodes") || !tokens.match_token(format_version == 1 ? "$ELM" : "$Elements")) return MB_FILE_WRITE_ERROR; // Get element count long num_elem; if (!tokens.get_long_ints(1, &num_elem)) return MB_FILE_WRITE_ERROR; // Lists of data accumulated for elements std::vector<EntityHandle> connectivity; std::vector<int> mat_set_list, geom_set_list, part_set_list, id_list; // Temporary, per-element data std::vector<int> int_data(5), tag_data(2); std::vector<long> tmp_conn; int curr_elem_type = -1; for (long i = 0; i < num_elem; ++i) { // Read element description // File format 1.0 if (1 == format_version) { if (!tokens.get_integers(5, &int_data[0])) return MB_FILE_WRITE_ERROR; tag_data[0] = int_data[2]; tag_data[1] = int_data[3]; if ((unsigned)tag_data[1] < GmshUtil::numGmshElemType && GmshUtil::gmshElemTypes[tag_data[1]].num_nodes != (unsigned)int_data[4]) { MB_SET_ERR(MB_FILE_WRITE_ERROR, "Invalid node count for element type at line " << tokens.line_number()); } } // File format 2.0 else { if (!tokens.get_integers(3, &int_data[0])) return MB_FILE_WRITE_ERROR; tag_data.resize(int_data[2]); if (!tokens.get_integers(tag_data.size(), &tag_data[0])) return MB_FILE_WRITE_ERROR; } // If a list of material sets was specified in the // argument list, skip any elements for which the // material set is not specified or is not in the // passed list. if (!blocks.empty() && (tag_data.empty() || blocks.find(tag_data[0]) != blocks.end())) continue; // If the next element is not the same type as the last one, // create a sequence for the block of elements we've read // to this point (all of the same type), and clear accumulated // data. if (int_data[1] != curr_elem_type) { if (!id_list.empty()) { // First iteration result = create_elements(GmshUtil::gmshElemTypes[curr_elem_type], id_list, mat_set_list, geom_set_list, part_set_list, connectivity, file_id_tag); if (MB_SUCCESS != result) return result; } id_list.clear(); mat_set_list.clear(); geom_set_list.clear(); part_set_list.clear(); connectivity.clear(); curr_elem_type = int_data[1]; if ((unsigned)curr_elem_type >= GmshUtil::numGmshElemType || GmshUtil::gmshElemTypes[curr_elem_type].mb_type == MBMAXTYPE) { MB_SET_ERR(MB_FILE_WRITE_ERROR, "Unsupported element type " << curr_elem_type << " at line " << tokens.line_number()); } tmp_conn.resize(GmshUtil::gmshElemTypes[curr_elem_type].num_nodes); } // Store data from element description id_list.push_back(int_data[0]); part_set_list.push_back(tag_data.size() > 2 ? tag_data[2] : 0); geom_set_list.push_back(tag_data.size() > 1 ? tag_data[1] : 0); mat_set_list.push_back(tag_data.size() > 0 ? tag_data[0] : 0); // Get element connectivity if (!tokens.get_long_ints(tmp_conn.size(), &tmp_conn[0])) return MB_FILE_WRITE_ERROR; // Convert connectivity from IDs to handles for (unsigned j = 0; j < tmp_conn.size(); ++j) { std::map<long, EntityHandle>::iterator k = node_id_map.find(tmp_conn[j]); if (k == node_id_map.end()) { MB_SET_ERR(MB_FILE_WRITE_ERROR, "Invalid node ID at line " << tokens.line_number()); } connectivity.push_back(k->second); } } // for (num_nodes) // Create entity sequence for last element(s). if (!id_list.empty()) { result = create_elements(GmshUtil::gmshElemTypes[curr_elem_type], id_list, mat_set_list, geom_set_list, part_set_list, connectivity, file_id_tag); if (MB_SUCCESS != result) return result; } // Construct parent-child relations for geometric sets. // Note: At the time this comment was written, the following // function was not implemented. result = create_geometric_topology(); geomSets.clear(); return result; }
static void display_med(struct writer *w, lldpctl_atom_t *port) { lldpctl_atom_t *medpolicies, *medpolicy; lldpctl_atom_t *medlocations, *medlocation; lldpctl_atom_t *caelements, *caelement; long int cap = lldpctl_atom_get_int(port, lldpctl_k_chassis_med_cap); const char *type; if (lldpctl_atom_get_int(port, lldpctl_k_chassis_med_type) <= 0) return; tag_start(w, "lldp-med", "LLDP-MED"); tag_datatag(w, "device-type", "Device Type", lldpctl_atom_get_str(port, lldpctl_k_chassis_med_type)); display_med_capability(w, cap, LLDP_MED_CAP_CAP, "Capabilities"); display_med_capability(w, cap, LLDP_MED_CAP_POLICY, "Policy"); display_med_capability(w, cap, LLDP_MED_CAP_LOCATION, "Location"); display_med_capability(w, cap, LLDP_MED_CAP_MDI_PSE, "MDI/PSE"); display_med_capability(w, cap, LLDP_MED_CAP_MDI_PD, "MDI/PD"); display_med_capability(w, cap, LLDP_MED_CAP_IV, "Inventory"); /* LLDP MED policies */ medpolicies = lldpctl_atom_get(port, lldpctl_k_port_med_policies); lldpctl_atom_foreach(medpolicies, medpolicy) { if (lldpctl_atom_get_int(medpolicy, lldpctl_k_med_policy_type) <= 0) continue; tag_start(w, "policy", "LLDP-MED Network Policy for"); tag_attr(w, "apptype", "", lldpctl_atom_get_str(medpolicy, lldpctl_k_med_policy_type)); tag_attr(w, "defined", "Defined", (lldpctl_atom_get_int(medpolicy, lldpctl_k_med_policy_unknown) > 0)?"no":"yes"); if (lldpctl_atom_get_int(medpolicy, lldpctl_k_med_policy_tagged) > 0) { int vid = lldpctl_atom_get_int(medpolicy, lldpctl_k_med_policy_vid); tag_start(w, "vlan", "VLAN"); if (vid == 0) { tag_attr(w, "vid", "", "priority"); } else if (vid == 4095) { tag_attr(w, "vid", "", "reserved"); } else { tag_attr(w, "vid", "", lldpctl_atom_get_str(medpolicy, lldpctl_k_med_policy_vid)); } tag_end(w); } tag_datatag(w, "priority", "Priority", lldpctl_atom_get_str(medpolicy, lldpctl_k_med_policy_priority)); tag_datatag(w, "dscp", "DSCP Value", lldpctl_atom_get_str(medpolicy, lldpctl_k_med_policy_dscp)); tag_end(w); } lldpctl_atom_dec_ref(medpolicies); /* LLDP MED locations */ medlocations = lldpctl_atom_get(port, lldpctl_k_port_med_locations); lldpctl_atom_foreach(medlocations, medlocation) { int format = lldpctl_atom_get_int(medlocation, lldpctl_k_med_location_format); if (format <= 0) continue; tag_start(w, "location", "LLDP-MED Location Identification"); tag_attr(w, "type", "Type", lldpctl_atom_get_str(medlocation, lldpctl_k_med_location_format)); switch (format) { case LLDP_MED_LOCFORMAT_COORD: tag_attr(w, "geoid", "Geoid", lldpctl_atom_get_str(medlocation, lldpctl_k_med_location_geoid)); tag_datatag(w, "lat", "Latitude", lldpctl_atom_get_str(medlocation, lldpctl_k_med_location_latitude)); tag_datatag(w, "lon", "Longitude", lldpctl_atom_get_str(medlocation, lldpctl_k_med_location_longitude)); tag_start(w, "altitude", "Altitude"); tag_attr(w, "unit", "", lldpctl_atom_get_str(medlocation, lldpctl_k_med_location_altitude_unit)); tag_data(w, lldpctl_atom_get_str(medlocation, lldpctl_k_med_location_altitude)); tag_end(w); break; case LLDP_MED_LOCFORMAT_CIVIC: tag_datatag(w, "country", "Country", lldpctl_atom_get_str(medlocation, lldpctl_k_med_location_country)); caelements = lldpctl_atom_get(medlocation, lldpctl_k_med_location_ca_elements); lldpctl_atom_foreach(caelements, caelement) { type = lldpctl_atom_get_str(caelement, lldpctl_k_med_civicaddress_type); tag_datatag(w, totag(type), type, lldpctl_atom_get_str(caelement, lldpctl_k_med_civicaddress_value)); } lldpctl_atom_dec_ref(caelements); break; case LLDP_MED_LOCFORMAT_ELIN: tag_datatag(w, "ecs", "ECS ELIN", lldpctl_atom_get_str(medlocation, lldpctl_k_med_location_elin)); break; }
static void display_med(struct writer *w, struct lldpd_chassis *chassis, struct lldpd_port *port) { int i; char *value; tag_start(w, "lldp-med", "LLDP-MED"); tag_datatag(w, "device-type", "Device Type", map_lookup(chassis_med_type_map, chassis->c_med_type)); display_med_capability(w, chassis, LLDPMED_CAP_CAP); display_med_capability(w, chassis, LLDPMED_CAP_POLICY); display_med_capability(w, chassis, LLDPMED_CAP_LOCATION); display_med_capability(w, chassis, LLDPMED_CAP_MDI_PSE); display_med_capability(w, chassis, LLDPMED_CAP_MDI_PD); display_med_capability(w, chassis, LLDPMED_CAP_IV); for (i = 0; i < LLDPMED_APPTYPE_LAST; i++) { if (i+1 == port->p_med_policy[i].type) { tag_start(w, "policy", "LLDP-MED Network Policy for"); tag_attr(w, "apptype", "AppType", u2str(port->p_med_policy[i].type)); tag_attr(w, "defined", "Defined", (port->p_med_policy[i].unknown)?"no":"yes"); tag_datatag(w, "descr", "", map_lookup(port_med_policy_map, port->p_med_policy[i].type)); if (port->p_med_policy[i].tagged) { tag_start(w, "vlan", "VLAN"); if (port->p_med_policy[i].vid == 0) { tag_attr(w, "vid", "", "priority"); } else if (port->p_med_policy[i].vid == 4095) { tag_attr(w, "vid", "", "reserved"); } else { tag_attr(w, "vid", "", u2str(port->p_med_policy[i].vid)); } tag_end(w); } tag_datatag(w, "priority", "Layer 2 Priority", u2str(port->p_med_policy[i].priority)); tag_datatag(w, "dscp", "DSCP Value", u2str(port->p_med_policy[i].dscp)); tag_end(w); } } for (i = 0; i < LLDPMED_LOCFORMAT_LAST; i++) { if (i+1 == port->p_med_location[i].format) { tag_start(w, "location", "LLDP-MED Location Identification"); switch(port->p_med_location[i].format) { case LLDPMED_LOCFORMAT_COORD: tag_attr(w, "type", "Type", "coordinates"); if (port->p_med_location[i].data_len != 16) { tag_datatag(w, "error", "Error", "bad data length"); } else { u_int64_t l; u_int8_t v; char * s; v = *(u_int8_t*)(port->p_med_location[i].data + 15); tag_attr(w, "geoid", "Geoid", map_lookup(port_med_geoid_map,v)); /* Latitude and longitude */ memcpy(&l, port->p_med_location[i].data, sizeof(u_int64_t)); l = (ntohll(l) & 0x03FFFFFFFF000000ULL) >> 24; display_latitude_or_longitude(w,0, l); memcpy(&l, port->p_med_location[i].data + 5, sizeof(u_int64_t)); l = (ntohll(l) & 0x03FFFFFFFF000000ULL) >> 24; display_latitude_or_longitude(w,1, l); /* Altitude */ memcpy(&l, port->p_med_location[i].data + 10, sizeof(u_int64_t)); l = (ntohll(l) & 0x3FFFFFFF000000ULL) >> 24; display_fixed_precision(l, 22, 8, 1, &s); tag_start(w, "altitude", "Altitude"); switch ((*(u_int8_t*)(port->p_med_location[i].data + 10)) & 0xf0) { case (1 << 4): tag_attr(w, "unit", "", "m"); break; case (2 << 4): tag_attr(w, "unit", "", "floor"); break; default: tag_attr(w, "unit", "", "unknown"); } tag_data(w,s); tag_end(w); } break; case LLDPMED_LOCFORMAT_CIVIC: tag_attr(w, "type", "Type", "address"); if ((port->p_med_location[i].data_len < 3) || (port->p_med_location[i].data_len - 1 != *(u_int8_t*)port->p_med_location[i].data)) { tag_datatag(w, "error", "Error", "bad data length"); } else { int l = 4, n, catype, calength; char country[3]; country[0] = ((char *)port->p_med_location[i].data)[2]; country[1] = ((char *)port->p_med_location[i].data)[3]; country[2] = 0; tag_datatag(w, "country", "Country", country); while ((n = (port-> p_med_location[i].data_len - l)) >= 2) { catype = *(u_int8_t*)(port-> p_med_location[i].data + l); calength = *(u_int8_t*)(port-> p_med_location[i].data + l + 1); if (n < 2 + calength) { tag_datatag(w, "error", "Error", "bad data length"); break; } if ((value = strndup((char *)(port-> p_med_location[i].data + l + 2), calength)) == NULL) { fatalx("not enough memory"); break; } tag_datatag(w, map_lookup(civic_address_type_tags,catype), map_lookup(civic_address_type_values,catype), value); free(value); l += 2 + calength; } } break; case LLDPMED_LOCFORMAT_ELIN: if ((value = strndup((char *)(port-> p_med_location[i].data), port->p_med_location[i].data_len)) == NULL) { fatalx( "not enough memory"); break; } tag_attr(w, "type", "Type", "elin"); tag_datatag(w, "ecs", "ECS ELIN", value); free(value); break; default: tag_attr(w, "type", "", "unknown"); tag_datatag(w, "unknown", "Data", dump(port->p_med_location[i].data, port->p_med_location[i].data_len, 20, ' ')); } tag_end(w); } }