void Parse_WMS_1_3_0_Service_Node( Capabilities::ptr_t capabilities, pugi::xml_node& root_node, Status& status ) { // Log Entry BOOST_LOG_TRIVIAL(debug) << "Parsing WMS 1.3.0 Service XML Node."; // Iterate over child nodes std::string node_name; pugi::xml_node_iterator nit = root_node.begin(); for( ; nit != root_node.end(); nit++ ) { node_name = nit->name(); // Check if Name Node if( node_name == "Name" ){ capabilities->Set_Service_Name( nit->value() ); } // Otherwise, print warning else{ BOOST_LOG_TRIVIAL(warning) << "Found unknown node: " << nit->name(); } } // Return Success status = Status(StatusCode::SUCCESS); }
static void FromXml(const pugi::xml_node& xmlNode, DataSetElement& parent) { // ignore non-named XML nodes // // pugi::xml separates XML parts into more node types than we use // const string& label = xmlNode.name(); if (label.empty()) return; // label & text DataSetElement e(xmlNode.name(), FromInputXml()); e.Text(xmlNode.text().get()); // iterate attributes auto attrIter = xmlNode.attributes_begin(); auto attrEnd = xmlNode.attributes_end(); for ( ; attrIter != attrEnd; ++attrIter ) e.Attribute(attrIter->name(), attrIter->value()); // iterate children, recursively building up subtree auto childIter = xmlNode.begin(); auto childEnd = xmlNode.end(); for ( ; childIter != childEnd; ++childIter ) { pugi::xml_node childNode = *childIter; FromXml(childNode, e); } // add our element to its parent parent.AddChild(e); }
//----------------------------------------------------------------------------- void XMLMesh::read_array_uint(std::vector<std::size_t>& array, const pugi::xml_node xml_array) { // Check that we have an array const std::string name = xml_array.name(); if (name != "array") { dolfin_error("XMLMesh.cpp", "read mesh array data from XML file", "Expecting an XML array node"); } // Check type is unit const std::string type = xml_array.attribute("type").value(); if (type != "uint") { dolfin_error("XMLMesh.cpp", "read mesh array data from XML file", "Expecting an XML array node"); } // Get size and resize vector const std::size_t size = xml_array.attribute("size").as_uint(); array.resize(size); // Iterate over array entries for (pugi::xml_node_iterator it = xml_array.begin(); it !=xml_array.end(); ++it) { const std::size_t index = it->attribute("index").as_uint(); const double value = it->attribute("value").as_uint(); dolfin_assert(index < size); array[index] = value; } }
void mergeNodes(pugi::xml_node toNode, pugi::xml_node& fromNode) { // Base case = both nodes are text nodes pugi::xml_text fromNodeText = fromNode.text(); pugi::xml_text toNodeText = toNode.text(); if (fromNodeText && toNodeText) { SBLog::info() << "Overwriting template value of \"" << toNode.name() << "\" from \"" << toNodeText.get() << "\" to \"" << fromNodeText.get() << "\"." << std::endl; toNodeText.set(fromNodeText.get()); return; } // Calculate number of children in toNode unsigned maxDistance = std::distance(toNode.begin(), toNode.end()); // Merge children for (pugi::xml_node fromNodeChild = fromNode.first_child(); fromNodeChild; fromNodeChild = fromNodeChild.next_sibling()) { // Find appropriate merge point pugi::xml_node toNodeChild = findSimilarNode(fromNodeChild, toNode, maxDistance); if (toNodeChild) { mergeNodes(toNodeChild, fromNodeChild); } else { toNode.append_copy(fromNodeChild); } } // Erase fromNode removeNode(fromNode); }
bool Config::parseNode(const pugi::xml_node& node) { UnicodeString currentPath = StringConverter::fromUtf8(node.path('/')); currentPath.append("@"); pugi::xml_node::attribute_iterator attrIter = node.attributes_begin(); pugi::xml_node::attribute_iterator attrEnd = node.attributes_end(); for (; attrIter != attrEnd; ++attrIter) { UnicodeString configKey = currentPath; configKey.append(attrIter->name()); std::map<UnicodeString, Variable>::iterator itm = variablesMap_.find(configKey); if (itm != variablesMap_.end()) { if (!itm->second.parse(attrIter->value())) { return false; } } else { LOG_WARN << "Ignoring unknown config value " << configKey << std::endl; } } pugi::xml_node::iterator nodeIter = node.begin(); pugi::xml_node::iterator nodeEnd = node.end(); for (; nodeIter != nodeEnd; ++nodeIter) { if (nodeIter->type() == pugi::node_element) { if (!parseNode(*nodeIter)) { return false; } } } return true; }
void Parse_WMS_1_3_0_Capability_Node( Capabilities::ptr_t capabilities, pugi::xml_node& root_node, Status& status ) { // Log Entry BOOST_LOG_TRIVIAL(debug) << "Parsing WMS 1.3.0 Capability XML Node."; // Iterate over child nodes std::string node_name; pugi::xml_node_iterator nit = root_node.begin(); for( ; nit != root_node.end(); nit++ ) { node_name = nit->name(); // Check if Request Node if( node_name == "Request" ) { // Parse the Request Node Parse_WMS_1_3_0_Request_Node( capabilities, (*nit), status ); } // Check if Layer Node else if( node_name == "Layer" ) { // Parse the Layer Node Parse_WMS_1_3_0_Layer_Node( capabilities, (*nit), status ); } // Otherwise, print warning else{ BOOST_LOG_TRIVIAL(warning) << "Found unknown node: " << nit->name(); } } // Log Exit BOOST_LOG_TRIVIAL(debug) << "Finished Parsing WMS 1.3.0 Capability XML Node."; // Return Success status = Status(StatusCode::SUCCESS); }
void Parse_WMS_1_3_0_Layer_Node( Capabilities::ptr_t capabilities, OGC_Layer::ptr_t layer_node, pugi::xml_node& root_node, Status& status ) { // Log Entry BOOST_LOG_TRIVIAL(debug) << "Parsing WMS 1.3.0 Layer XML Node."; // Iterate over child nodes std::string node_name; pugi::xml_node_iterator nit = root_node.begin(); for( ; nit != root_node.end(); nit++ ) { node_name = nit->name(); // Check Name if( node_name == "Name" ) { layer_node->Set_Name( nit->text().as_string() ); } // Check Title else if( node_name == "Title" ) { layer_node->Set_Title( nit->text().as_string() ); } // Check CRS else if( node_name == "CRS" ) { layer_node->Add_CRS( nit->text().as_string() ); } // Check Bounding Box else if( node_name == "BoundingBox" ) { layer_node->Add_BBox( Parse_WMS_1_3_0_BoundingBox_Node((*nit), status)); } // Otherwise, print warning else{ BOOST_LOG_TRIVIAL(warning) << "Found unknown node: " << nit->name(); } } // Return Success status = Status(StatusCode::SUCCESS); }
void xmlManager::print_node(pugi::xml_node source_node, string prefix) { cout << prefix << source_node.name() << ": " << source_node.value() << endl; for (pugi::xml_attribute_iterator it = source_node.attributes_begin(); it != source_node.attributes_end(); it++) cout << prefix + "\t" << it->name() << " : " << it->value() << endl; for (pugi::xml_node_iterator it = source_node.begin(); it != source_node.end(); it++) print_node(*it, prefix + "\t"); }
void SettingsManager::mergeNodes(pugi::xml_node _nodeTarget, pugi::xml_node _nodeSource) { bool listElement = MyGUI::utility::endWith(_nodeTarget.name(), ".List"); // затираем текст у цели потому что любое значение текста источника является конечным pugi::xml_node targetTextNode = _nodeTarget.first_child(); if (!targetTextNode.empty() && targetTextNode.type() == pugi::node_pcdata) targetTextNode.set_value(""); pugi::xml_node sourceTextNode = _nodeSource.first_child(); if (!sourceTextNode.empty() && sourceTextNode.type() == pugi::node_pcdata) { targetTextNode = _nodeTarget.first_child(); if (targetTextNode.empty()) targetTextNode = _nodeTarget.append_child(pugi::node_pcdata); targetTextNode.set_value(sourceTextNode.value()); } for (pugi::xml_node::iterator child = _nodeSource.begin(); child != _nodeSource.end(); child ++) { if ((*child).type() != pugi::node_element) continue; pugi::xml_node targetChildNode; if (listElement) { targetChildNode = _nodeTarget.append_child((*child).name()); } else { targetChildNode = _nodeTarget.child((*child).name()); if (targetChildNode.empty()) targetChildNode = _nodeTarget.append_child((*child).name()); } mergeAttributes(targetChildNode, (*child)); mergeNodes(targetChildNode, (*child)); } }
void Parse_WMS_1_3_0_Request_Node( Capabilities::ptr_t capabilities, pugi::xml_node& root_node, Status& status ) { // Log Entry BOOST_LOG_TRIVIAL(debug) << "Parsing WMS 1.3.0 Request XML Node."; // Iterate over child nodes std::string node_name; pugi::xml_node_iterator nit = root_node.begin(); for( ; nit != root_node.end(); nit++ ) { node_name = nit->name(); // Otherwise, print warning //else{ // BOOST_LOG_TRIVIAL(warning) << "Found unknown node: " << nit->name(); //} } // Return Success status = Status(StatusCode::SUCCESS); }
void XMLFile::AddNode(const pugi::xml_node& patch, const pugi::xpath_node& original) const { // If pos is null, append or prepend add as a child, otherwise add before or after, the default is to append as a child pugi::xml_attribute pos = patch.attribute("pos"); if (!pos || strlen(pos.value()) <= 0 || strcmp(pos.value(), "append") == 0) { pugi::xml_node::iterator start = patch.begin(); pugi::xml_node::iterator end = patch.end(); // There can not be two consecutive text nodes, so check to see if they need to be combined // If they have been we can skip the first node of the nodes to add if (CombineText(patch.first_child(), original.node().last_child(), false)) start++; for (; start != end; start++) original.node().append_copy(*start); } else if (strcmp(pos.value(), "prepend") == 0) { pugi::xml_node::iterator start = patch.begin(); pugi::xml_node::iterator end = patch.end(); // There can not be two consecutive text nodes, so check to see if they need to be combined // If they have been we can skip the last node of the nodes to add if (CombineText(patch.last_child(), original.node().first_child(), true)) end--; pugi::xml_node pos = original.node().first_child(); for (; start != end; start++) original.node().insert_copy_before(*start, pos); } else if (strcmp(pos.value(), "before") == 0) { pugi::xml_node::iterator start = patch.begin(); pugi::xml_node::iterator end = patch.end(); // There can not be two consecutive text nodes, so check to see if they need to be combined // If they have been we can skip the first node of the nodes to add if (CombineText(patch.first_child(), original.node().previous_sibling(), false)) start++; // There can not be two consecutive text nodes, so check to see if they need to be combined // If they have been we can skip the last node of the nodes to add if (CombineText(patch.last_child(), original.node(), true)) end--; for (; start != end; start++) original.parent().insert_copy_before(*start, original.node()); } else if (strcmp(pos.value(), "after") == 0) { pugi::xml_node::iterator start = patch.begin(); pugi::xml_node::iterator end = patch.end(); // There can not be two consecutive text nodes, so check to see if they need to be combined // If they have been we can skip the first node of the nodes to add if (CombineText(patch.first_child(), original.node(), false)) start++; // There can not be two consecutive text nodes, so check to see if they need to be combined // If they have been we can skip the last node of the nodes to add if (CombineText(patch.last_child(), original.node().next_sibling(), true)) end--; pugi::xml_node pos = original.node(); for (; start != end; start++) pos = original.parent().insert_copy_after(*start, pos); } }
UniformBlock Visitor::synthesizeBlock(pugi::xml_node xml_data) { int binding_pt = xml_data.attribute("BindingPoint").as_int(); UniformBlock to_add = UniformBlock(xml_data.attribute("Name").as_string(), binding_pt); for (pugi::xml_node_iterator uniform = xml_data.begin(); uniform != xml_data.end(); ++uniform) { std::string uniform_name = uniform->attribute("Name").as_string(); //Keep track of the running total size in bytes of the uniform block int block_size = 0; std::string type = uniform->attribute("Type").as_string(); float* uniform_data; if (strcmp(type.c_str(), "float") == 0) { block_size = 1; float data_str = uniform->attribute("Data0").as_float(); uniform_data = new float[block_size]; uniform_data[0] = data_str; } else if (strcmp(type.c_str(), "vec2") == 0) { block_size = 2; float data_str = uniform->attribute("Data0").as_float(); float data_str1 = uniform->attribute("Data1").as_float(); uniform_data = new float[block_size]; uniform_data[0] = data_str; uniform_data[1] = data_str1; } else if (strcmp(type.c_str(), "vec3") == 0) { block_size = 3; float data_str0 = uniform->attribute("Data0").as_float(); float data_str1 = uniform->attribute("Data1").as_float(); float data_str2 = uniform->attribute("Data2").as_float(); uniform_data = new float[block_size]; uniform_data[0] = data_str0; uniform_data[1] = data_str1; uniform_data[2] = data_str2; } else if (strcmp(type.c_str(), "vec4") == 0) { block_size = 4; float data_str0 = uniform->attribute("Data0").as_float(); float data_str1 = uniform->attribute("Data1").as_float(); float data_str2 = uniform->attribute("Data2").as_float(); float data_str3 = uniform->attribute("Data3").as_float(); uniform_data = new float[block_size]; uniform_data[0] = data_str0; uniform_data[1] = data_str1; uniform_data[2] = data_str2; uniform_data[3] = data_str3; } //TODO: Check for other types ShaderParameter next_uniform = ShaderParameter(uniform_name, block_size * 4, block_size, uniform_data, true); to_add.addParameter(next_uniform); } return to_add; }
//Creates and initializes a texture object from xml Texture Visitor::loadTextureFromXml(pugi::xml_node& xml_text_data) { Texture to_return;// = nullptr; if (std::strcmp(xml_text_data.name(), "Texture") == 0) { pugi::xml_attribute tex_path = xml_text_data.attribute("TexturePath"); to_return = scene_objects.loadTexture(tex_path.as_string()); if (glGetError() != 0) std::cout << "Illegal arguments set for texture"; for (pugi::xml_node_iterator tex_parameter = xml_text_data.begin(); tex_parameter != xml_text_data.end(); ++tex_parameter) setGLCodeFromXml(*tex_parameter, to_return); } //TODO: Fix this, does not work because load3DTexture returns a pointer else if (std::strcmp(xml_text_data.name(), "Texture3D") == 0) { pugi::xml_attribute tex_path = xml_text_data.attribute("TexturePath"); //to_return = scene_objects.load3DTexture(tex_path.as_string()); for (pugi::xml_node_iterator tex_parameter = xml_text_data.begin(); tex_parameter != xml_text_data.end(); ++tex_parameter) setGLCodeFromXml(*tex_parameter, to_return); } else if (std::strcmp(xml_text_data.name(), "FrameBufferTexture") == 0) { int left = xml_text_data.attribute("left").as_int(); int bottom = xml_text_data.attribute("Bottom").as_int(); int width = xml_text_data.attribute("Width").as_int(); int height = xml_text_data.attribute("Height").as_int(); std::string name = xml_text_data.attribute("Name").as_string(); //to_return = scene_objects.loadFramebufferTexture(left, bottom, width, height, name); for (pugi::xml_node_iterator tex_parameter = xml_text_data.begin(); tex_parameter != xml_text_data.end(); ++tex_parameter) setGLCodeFromXml(*tex_parameter, to_return); for (pugi::xml_node_iterator tex_parameter = xml_text_data.begin(); tex_parameter != xml_text_data.end(); ++tex_parameter) { //if (strcmp(tex_parameter->name(), "TriangleMesh") == 0) // (static_cast<FrameBufferTexture*>(to_return))->addMesh(loadMeshFromXml(*tex_parameter)); } } else std::cout << "Undefined XML node type, check resource file for errors." << std::endl; return to_return; }
//Creates a TriangleMesh instance from provided xml data TriangleMesh Visitor::loadMeshFromXml(pugi::xml_node& resource, Node& container) { bool static_mesh = false; Shader mesh_shader; Texture mesh_texture; pugi::xml_node scenario_texture = resource.child("Texture"); if (resource.attribute("StaticObject")) { static_mesh = true; } if (resource.child("Texture") || resource.child("Texture3D") || resource.child("FrameBufferTexture")) for (pugi::xml_node_iterator textures = resource.begin(); textures != resource.end(); ++textures) { //mesh_texture = loadTextureFromXml(*textures); mesh_texture = loadTextureFromXml(resource.child("Texture")); //if (mesh_texture != nullptr) break; } else mesh_texture = scene_objects.getTextureByKey(resource.attribute("Texture").as_string()); std::string fs_path = resource.attribute("FSPath").as_string(); std::string vs_path = resource.attribute("VSPath").as_string(); mesh_shader = scene_objects.getShaderByKey(vs_path.append(fs_path)); std::string obj_path = resource.attribute("ObjFile").as_string(); //mesh_buffers = scene_objects.getBufferByKey(obj_path); pugi::xml_attribute instance = resource.attribute("InstanceCount"); vec3 position; vec3 velocity; //Now gather all information for uniforms to the shaders for (pugi::xml_node_iterator uniforms = resource.begin(); uniforms != resource.end(); ++uniforms) { if (std::strcmp(uniforms->name(), "UniformBlock") == 0) { UniformBlock to_add = synthesizeBlock(*uniforms); mesh_shader.addUniformBlock(to_add); } if (std::strcmp(uniforms->name(), "Uniform") == 0) { ShaderParameter uniform = parseUniform(*uniforms); if (strcmp(uniform.name.c_str(), "velocity") == 0) { velocity.x = uniform.client_data[0]; velocity.y = uniform.client_data[1]; velocity.z = uniform.client_data[2]; } else mesh_shader.addUniform(uniform); if (strcmp(uniform.name.c_str(), "translation") == 0) { position.x = uniform.client_data[0]; position.y = uniform.client_data[1]; position.z = uniform.client_data[2]; } } } //Now loop over all nodes to determine which blocks the shader should bind to for (pugi::xml_node_iterator uniforms = resource.begin(); uniforms != resource.end(); ++uniforms) { if (std::strcmp(uniforms->name(), "ShaderUniforms") == 0) { std::string block_name = uniforms->attribute("Name").as_string(); int block_index = uniforms->attribute("BindingPoint").as_int(); } } //Lava.png //dry_clay.jpg //Redbrick.jpg //rock04.jpg //Rosewood.jpg //Checkered Marble.png //Ocean Texture.png //Stonewall.jpg //Ambient Green.jpg //Red Pattern.jpg //Green Wall.jpg //Red Fuzzy Pattern.jpg //Brick Circle Pattern.jpg ObjFileReader* mesh_reader = scene_objects.getFileReader(obj_path); int num_buffers = mesh_reader->getNumSubMeshes(); Texture second = scene_objects.getTextureByKey("Lava.png"); Texture third = scene_objects.getTextureByKey("Redbrick.jpg"); Texture fourth = scene_objects.getTextureByKey("Rosewood.jpg"); Texture fifth = scene_objects.getTextureByKey("Checkered Marble.png"); Texture sixth = scene_objects.getTextureByKey("Lava.png"); Texture seventh = scene_objects.getTextureByKey("Ocean Texture.png"); Texture eighth= scene_objects.getTextureByKey("Stonewall.jpg"); Texture ninth = scene_objects.getTextureByKey("Ambient Green.jpg"); Texture tenth = scene_objects.getTextureByKey("Red Pattern.jpg"); Texture eleventh = scene_objects.getTextureByKey("Brick Circle Pattern.jpg"); Texture twelfth = scene_objects.getTextureByKey("Green Wall.jpg"); Texture thirteenth = scene_objects.getTextureByKey("Brick Circle Pattern.jpg"); for (int i = 0; i < num_buffers; i++) { BufferManager mesh_buffers; TriangleMesh to_return; mesh_buffers = mesh_reader->getPrimitive(i); //if (instance) // to_return = TriangleMesh(instance.as_int()); //else if (i % 13 == 0) to_return = TriangleMesh(mesh_shader, mesh_buffers, mesh_texture, static_mesh); else if (i % 13 == 1) to_return = TriangleMesh(mesh_shader, mesh_buffers, second, static_mesh); else if (i % 13 == 2) to_return = TriangleMesh(mesh_shader, mesh_buffers, third, static_mesh); else if (i % 13 == 3) to_return = TriangleMesh(mesh_shader, mesh_buffers, fourth, static_mesh); else if (i % 13 == 4) to_return = TriangleMesh(mesh_shader, mesh_buffers, fifth, static_mesh); else if (i % 13 == 5) to_return = TriangleMesh(mesh_shader, mesh_buffers, sixth, static_mesh); else if (i % 13 == 6) to_return = TriangleMesh(mesh_shader, mesh_buffers, seventh, static_mesh); else if (i % 13 == 7) to_return = TriangleMesh(mesh_shader, mesh_buffers, eighth, static_mesh); else if (i % 13 == 8) to_return = TriangleMesh(mesh_shader, mesh_buffers, ninth, static_mesh); else if (i % 13 == 9) to_return = TriangleMesh(mesh_shader, mesh_buffers, tenth, static_mesh); else if (i % 13 == 10) to_return = TriangleMesh(mesh_shader, mesh_buffers, eleventh, static_mesh); else if (i % 13 == 11) to_return = TriangleMesh(mesh_shader, mesh_buffers, twelfth, static_mesh); else if (i % 13 == 12) to_return = TriangleMesh(mesh_shader, mesh_buffers, thirteenth, static_mesh); //to_return.setPosition(position); to_return.setVelocity(velocity); container.meshes.push_back(to_return); } TriangleMesh dummy; return dummy; }
//----------------------------------------------------------------------------- void XMLMesh::read_data(MeshData& data, const Mesh& mesh, const pugi::xml_node mesh_node) { // Check if we have any mesh data const pugi::xml_node xml_data = mesh_node.child("data"); if (!xml_data) return; // Iterate over data for (pugi::xml_node_iterator it = xml_data.begin(); it != xml_data.end(); ++it) { // Get node name const std::string node_name = it->name(); // Read data stored as a MeshFunction (new style) if (node_name == "mesh_function") { // Create MeshFunction to read data into MeshFunction<std::size_t> mf(mesh); // Read MeshFunction //const std::string data_type = it->attribute("type").value(); XMLMeshFunction::read(mf, "uint", *it); // Create mesh domain array std::vector<std::size_t>& _data = data.create_array(mf.name(), mf.dim()); _data.resize(mf.size()); // Copy MeshFunction into MeshDomain array for (std::size_t i = 0; i < _data.size(); ++i) _data[i] = mf[i]; } else if (node_name != "data_entry") { dolfin_error("XMLMesh.cpp", "read mesh data from XML file", "Expecting XML node <data_entry> but got <%s>", node_name.c_str()); } else // Old-style storage { // Get name of data set const std::string data_set_name = it->attribute("name").value(); // Check that there is only one data set if (it->first_child().next_sibling()) { dolfin_error("XMLMesh.cpp", "read mesh data from XML file", "XML file contains too many data sets"); } // Get type of data set pugi::xml_node data_set = it->first_child(); const std::string data_set_type = data_set.name(); if (data_set_type == "array") { dolfin_error("XMLMesh.cpp", "read mesh data from XML file", "Only MeshFunction data can be read"); } else if (data_set_type == "mesh_function") { // Create MeshFunction to read data into MeshFunction<std::size_t> mf(mesh); // Read MeshFunction const std::string data_type = data_set.attribute("type").value(); XMLMeshFunction::read(mf, data_type, *it); // Create mesh domain array std::vector<std::size_t>& _data = data.create_array(data_set_name, mf.dim()); _data.resize(mf.size()); // Copy MeshFunction into MeshDomain array for (std::size_t i = 0; i < _data.size(); ++i) _data[i] = mf[i]; } else if (data_set_type == "meshfunction") { dolfin_error("XMLMesh.cpp", "read mesh data from XML file", "The XML tag <meshfunction> has been changed to <mesh_function>"); } else { dolfin_error("XMLMesh.cpp", "read mesh data from XML file", "Reading of MeshData \"%s\" is not yet supported", data_set_type.c_str()); } } } }
//----------------------------------------------------------------------------- void XMLFunctionData::read(Function& u, const pugi::xml_node xml_dolfin) { dolfin_assert(u.vector()); GenericVector& vector = *u.vector(); dolfin_assert(u.function_space()); const FunctionSpace& V = *u.function_space(); dolfin_assert(V.mesh()); const Mesh& mesh = *V.mesh(); std::vector<std::pair<la_index, la_index>> global_to_cell_dof; std::vector<double> x; std::vector<la_index> indices; const std::size_t num_dofs = V.dim(); if (MPI::rank(mesh.mpi_comm()) == 0) { // Check that we have a XML function data const pugi::xml_node xml_function_data_node = xml_dolfin.child("function_data"); if (!xml_function_data_node) { dolfin_error("XMLFunctionData.cpp", "read function from XML file", "Not a DOLFIN Function XML file"); } // Check size const std::size_t size = xml_function_data_node.attribute("size").as_uint(); if (size != num_dofs) { dolfin_error("XMLFunctionData.cpp", "read function from XML file", "The number of degrees of freedom (%d) does not match the " "dimension of the function space (%d)", size, num_dofs); } dolfin_assert(size == vector.size()); global_to_cell_dof.resize(num_dofs); x.resize(num_dofs); indices.resize(num_dofs); // Iterate over each cell entry for (pugi::xml_node_iterator it = xml_function_data_node.begin(); it != xml_function_data_node.end(); ++it) { const std::string name = it->name(); dolfin_assert(name == "dof"); const std::size_t global_index = it->attribute("index").as_uint(); const double value = it->attribute("value").as_double(); const std::size_t cell_index = it->attribute("cell_index").as_uint(); const std::size_t local_dof_index = it->attribute("cell_dof_index").as_uint(); global_to_cell_dof[global_index].first = cell_index; global_to_cell_dof[global_index].second = local_dof_index; x[global_index] = value; } } // Build current dof map based on function space V (empty on all but // process rank 0) std::vector<std::vector<dolfin::la_index>> dof_map; build_dof_map(dof_map, V); // Map old-to-current vector positions if (MPI::rank(mesh.mpi_comm()) == 0) { // Loop over dofs for (std::size_t i = 0; i < num_dofs; ++i) { // Get cell index and local (cell-wise) dof index (indices for // data from file) dolfin_assert(i < global_to_cell_dof.size()); const std::size_t global_cell_index = global_to_cell_dof[i].first; const std::size_t local_dof_index = global_to_cell_dof[i].second; // Local dof vector for cell in V const std::vector<la_index>& dofs = dof_map[global_cell_index]; dolfin_assert(local_dof_index < dofs.size()); // Get new dof index const dolfin::la_index new_index = dofs[local_dof_index]; // File to new indices[i] = new_index; } vector.set(x.data(), x.size(), indices.data()); } // Finalise vector vector.apply("insert"); }
//----------------------------------------------------------------------------- void XMLFunctionData::read(Function& u, const pugi::xml_node xml_dolfin) { dolfin_assert(u.vector()); GenericVector& vector = *u.vector(); dolfin_assert(u.function_space()); const FunctionSpace& V = *u.function_space(); std::vector<std::pair<uint, uint> > global_to_cell_dof; Array<double> x; Array<uint> indices; const uint num_dofs = V.dim(); if (MPI::process_number() == 0) { // Check that we have a XML function data const pugi::xml_node xml_function_data_node = xml_dolfin.child("function_data"); if (!xml_function_data_node) { dolfin_error("XMLFunctionData.cpp", "read function from XML file", "Not a DOLFIN Function XML file"); } const uint size = xml_function_data_node.attribute("size").as_uint(); dolfin_assert(vector.size() == size); dolfin_assert(vector.size() == num_dofs); global_to_cell_dof.resize(num_dofs); x.resize(num_dofs); indices.resize(num_dofs); // Iterate over each cell entry for (pugi::xml_node_iterator it = xml_function_data_node.begin(); it != xml_function_data_node.end(); ++it) { const std::string name = it->name(); dolfin_assert(name == "dof"); const uint global_index = it->attribute("index").as_uint(); const double value = it->attribute("value").as_double(); const uint cell_index = it->attribute("cell_index").as_uint(); const uint local_dof_index = it->attribute("cell_dof_index").as_uint(); global_to_cell_dof[global_index].first = cell_index; global_to_cell_dof[global_index].second = local_dof_index; x[global_index] = value; } } // Build current dof map based on function space V std::vector<std::vector<uint> > dof_map; build_dof_map(dof_map, V); // Map old-to-current vector positions if (MPI::process_number() == 0) { for (uint i = 0; i < num_dofs; ++i) { // Indices for data from file dolfin_assert(i < global_to_cell_dof.size()); const uint global_cell_index = global_to_cell_dof[i].first; const uint local_dof_index = global_to_cell_dof[i].second; // Local dof vector for V const std::vector<uint>& dofs = dof_map[global_cell_index]; dolfin_assert(local_dof_index < dofs.size()); const uint new_index = dofs[local_dof_index]; // File to new indices[i] = new_index; } vector.set(x.data().get(), x.size(), indices.data().get()); } // Finalise vector vector.apply("insert"); }
//----------------------------------------------------------------------------- void XMLMesh::read_domains(MeshDomains& domains, const Mesh& mesh, const pugi::xml_node mesh_node) { // Check if we have any domains const pugi::xml_node xml_domains = mesh_node.child("domains"); if (!xml_domains) return; // Iterate over data for (pugi::xml_node_iterator it = xml_domains.begin(); it != xml_domains.end(); ++it) { // Check that node is <mesh_value_collection> const std::string node_name = it->name(); if (node_name != "mesh_value_collection") { dolfin_error("XMLMesh.cpp", "read mesh domains from XML file", "Expecting XML node <mesh_value_collection> but got <%s>", node_name.c_str()); } // Get attributes const std::string type = it->attribute("type").value(); const std::size_t dim = it->attribute("dim").as_uint(); // Check that the type is uint if (type != "uint") { dolfin_error("XMLMesh.cpp", "read mesh domains from XML file", "Mesh domains must be marked as uint, not %s", type.c_str()); } // Initialise mesh entities mesh.init(dim); // Read data into a mesh value collection std::shared_ptr<const Mesh> _mesh = reference_to_no_delete_pointer(mesh); MeshValueCollection<std::size_t> mvc(_mesh); XMLMeshValueCollection::read(mvc, type, *it); // Get mesh value collection data const std::map<std::pair<std::size_t, std::size_t>, std::size_t>& values = mvc.values(); // Get mesh domain data and fill std::map<std::size_t, std::size_t>& markers = domains.markers(dim); std::map<std::pair<std::size_t, std::size_t>, std::size_t>::const_iterator entry; if (dim != mesh.topology().dim()) { for (entry = values.begin(); entry != values.end(); ++entry) { const Cell cell(mesh, entry->first.first); const std::size_t entity_index = cell.entities(dim)[entry->first.second]; markers[entity_index] = entry->second; } } else { // Special case for cells for (entry = values.begin(); entry != values.end(); ++entry) markers[entry->first.first] = entry->second; } } }