> ## Documentation Index
> Fetch the complete documentation index at: https://developer.synopsys.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Extract Substructure

Extracting substructures in SoS.

* reduced the FEM mesh to a selected set of nodes and elements (all element nodes must belong to the selected nodes)
* extract sub sets of node and element data objects and scalars
* store it in a new database to be saved.

```lua theme={null}
-- 1st: based on selected nodes
-- get global node indices from a named selection
sel_nodes = sos.globalIndexFromNodeSet(sos.database(), "", "SOS_DATA_NODES") -- "" = part ident (or empty if no part-assembly structure), "SOS_DATA_NODES" = ident of named selection of type NODE
-- select adjacent elements
elements = sos.identifyElementsAdjacentToNodes(sos.database(), sel_nodes);
-- select all nodes belonging to the elements
adjacent_nodes = sos.identifyNodesOfElements(sos.database(), elements);
-- create the union of both nodes index sets (because there may be some nodes which do not have elements -> then the nodes belonging to the selected elements will not contain these)
nodes = sos.indexUnion(sel_nodes, adjacent_nodes)
-- extract data and structure for the selected nodes and elements
node_based_sdb = sos.extractSubstructure(sos.database(), nodes, elements);

-- 2nd: based on selected elements
-- get global element indices from a named selection
elements = sos.globalIndexFromElementSet(sos.database(), "", "SOS_DATA_ELEMENTS") -- "" = part ident (or empty if no part-assembly structure), "SOS_DATA_ELEMENTS" = ident of named selection of type ELEMENT
-- select contained nodes
nodes = sos.identifyNodesOfElements(sos.database(), elements);
-- extract data and structure for the selected nodes and elements
element_based_sdb = sos.extractSubstructure(sos.database(), nodes, elements);

--[[
Export one of the databases to file:

local settings = sos.SaveDataBaseSettings( path__out .. "/test_pi_extract_substructure__node_based.sdb" );
settings.replace_files = true
sos.saveDataBase(node_based_sdb, settings);
]]
```
