cee::ug::DataSourceMemory

class DataSourceMemory : public DataSource

A custom built data source for an unstructured grid model.

The data source contains a collection of all states for one analysis. Each state groups together geometries and results for one time step, load case, frequency etc. The memory data source class provides a way for the user to manually create the model “by hand”.

Each unstructured grid model owns one data source. A data source must have a minimum of one state. Each state must have at least one geometry and may contain a selection of results (scalars, vectors, displacements and/or transformations).

../_images/uml_memorydatasourc.png

When creating the memory data source, a unique id and a predefined number of geometries per state must be set in the constructor. The number of geometries per state cannot be changed after creation. Add states using addState() and query existing states with state() with the requested state index. All states can be removed with removeAllStates().

The data source directory describes the metadata for this data source and is accessed through directory(). All states, parts and results (scalars, vectors, displacements and transformations) added to the data source MUST have a corresponding info object in the directory.

Adding a data state and update the directory with the state metadata:

int stateId = 1;
cee::PtrRef<cee::ug::DataState> state = new cee::ug::DataState(stateId, 1);
dataSource->addState(state.get());
cee::ug::StateInfo stateInfo(stateId, "My state", 0.0);
dataSource->directory()->setStateInfo(stateInfo);

See DataSourceDirectory.

Note! Remember that since this object is reference counted it should never be created on the stack.

Example

Example on building your data source and geometry.

Create a model and a memory data source. The constructor of the data source takes a unique id and the number of geometries (here 1). Set the data source in the created model.

cee::PtrRef<cee::ug::UnstructGridModel> ugModel = new cee::ug::UnstructGridModel();
cee::PtrRef<cee::ug::DataSourceMemory> dataSource = new cee::ug::DataSourceMemory(1, 1);
ugModel->setDataSource(dataSource.get());

Create the state. Set number of geometries to 1 in the constructor.

int stateId = 1;
cee::PtrRef<cee::ug::DataState> state = new cee::ug::DataState(stateId, 1);
dataSource->addState(state.get());

Set the newly created state to current in the model specification.

ugModel->modelSpec().setStateId(stateId);

Create the geometry and add it to the state at index 0.

int geometryIndex = 0;
cee::PtrRef<cee::ug::DataGeometry> geo = new cee::ug::DataGeometry();
state->setGeometry(geometryIndex, geo.get());

Build a geometry containing the necessary parts, nodes and elements. Optionally, add results.

When finished, update the metadata in the data source directory with all new content.

// Set the part info
cee::ug::PartInfo partInfo(partId, "My part");
dataSource->directory()->setPartInfo(geometryIndex, partInfo);
// Set the state info
cee::ug::StateInfo stateInfo(stateId, "My state", 0.0);
dataSource->directory()->setStateInfo(stateInfo);

See the complete source code at: UnstructGrid: Simple Model with Two Triangles

Subclassed by DataSourcePhaseResponse

Public Functions

DataSourceMemory(int dataSourceId, size_t geometryCountPerState)

Constructs a memory data source.

Set a unique id and number of geometries per state upon construction. These values cannot be changed afterwards.

size_t geometryCountPerState() const

Returns number of geometries per state.

Number of geometries per state is set upon construction of the data source object and cannot be changed afterwards.

bool updateDerivedResult(ResultType resultType, int id)

Updates the derived result.

bool updateAllDerivedResults()

Updates all derived results.

void addState(DataState *state)

Adds a new state to the data source.

An added state MUST have the same number of geometries as the data source!

Warning

The added object is reference counted and should never be created on the stack or deleted!

void removeAllStates()

Removes all states in the data source.

void updateDirectoryFromStates()

Populates the directory with dummy data.

Provided for convenience. The directory should be populated manually to increase performance and providing more descriptive names and values.

Note that all existing items will be removed.