Skip to content

Node merge corrupts element-to-embedded-node maps #300

@rchristie

Description

@rchristie

Most Zinc code relies on the set_FE_nodal_element_xi_value() function to call FE_mesh_embedded_node_field::addNode/removeNode to manage the reverse map from elements to nodes.
However, Node::merge for a stored mesh location field does not do this; it calls free value storage code which is beneath this level.
Note that merging this type of field also clears the former value.
I expect merge/undefine this type of field will have a similar issue.
Following is a test showing the merge error:

// Test node merge maintains element-to-embedded node maps.
TEST(ZincNode, merge_embeddedLocation)
{
	ZincTestSetupCpp zinc;

	EXPECT_EQ(RESULT_OK, zinc.root_region.readFile(resourcePath("optimisation/fit_line_time.exf").c_str()));

	Mesh mesh1d = zinc.fm.findMeshByDimension(1);
	Element element1 = mesh1d.findElementByIdentifier(1);
	EXPECT_TRUE(element1.isValid());
	const double xi = 0.5;
	Nodeset datapoints = zinc.fm.findNodesetByFieldDomainType(Field::DOMAIN_TYPE_DATAPOINTS);
	Node datapoint2 = datapoints.findNodeByIdentifier(2);
	EXPECT_TRUE(datapoint2.isValid());
	FieldStoredMeshLocation hostLocation = zinc.fm.findFieldByName("host_location").castStoredMeshLocation();

	Nodetemplate nodetemplate = datapoints.createNodetemplate();
	EXPECT_EQ(RESULT_OK, nodetemplate.defineField(hostLocation));
	// before fix, the following orphans map from element back to node, so another can be added
	EXPECT_EQ(RESULT_OK, datapoint2.merge(nodetemplate));

	Fieldcache fieldcache = zinc.fm.createFieldcache();
	EXPECT_EQ(RESULT_OK, fieldcache.setNode(datapoint2));
	// before fix, the following adds a second map back from element to the same node 
	EXPECT_EQ(RESULT_OK, hostLocation.assignMeshLocation(fieldcache, element1, 1, &xi));

	// before fix the following would be an infinite loop
	EXPECT_EQ(RESULT_OK, mesh1d.destroyElement(element1));

	// also test merge with undefine
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions