HyperMath

CAE Data Readers and Writers

CAE Data Readers and Writers

Previous topic Next topic Expand/collapse all hidden text  

CAE Data Readers and Writers

Previous topic Next topic JavaScript is required for expanding text JavaScript is required for the print function  

The various data types supported by Altair HyperGraph are also supported by HyperMath.  Data can be read one vector at a time or in multiples.  Data can also be queried for content information.

Reading Data

hmtoggle_plus1ReadVector

Reads a vector from the specified file.  The vector is specified by the (Type, Request, Component) format.  If the data is grouped in Subcases, the second form may be used.

The following consolidates the functions read and readsubcase, found in Templex™.

M = ReadVector(filename,type,request,component)

M = ReadVector(filename, subcase, type,request,component)

filename

Fully qualified filename to read. Use a forward slash, (/), or a double back slash, (\\), to separate folders.

subcase

A case sensitive string containing the name of the Subcase.

type

A case sensitive string containing the name of the Type to read or the explicit numerical index (1 based).

request (optional)

A case sensitive string containing the name of the data request to read or the explicit numerical index (1 based).  If a vector does not have Requests (like timestamp), this can be omitted.

component (optional)

A case sensitive string containing the name of the data component to read or the explicit numerical index (1 based). If a vector does not have Components (like timestamp), this can be omitted.

M

A vector of the read data. If data is empty, then so is the matrix and a warning is generated.

Example 1

Reads the component "Mag" of request "Node 1" of Type "X-disp" from the file data.dat.

V = ReadVector ("c:/data.dat", "X-disp", "Node 1", "Mag")

Example 2

If the above data were grouped in a Subcase named "Load 1", then the following would be used:

V = ReadVector ("c:/data.dat", "Load 1", "X-disp", "Node 1", "Mag")

See Also

ReadVectorBuilder

Multiple vectors can be read at once, but in two different ways, using the function ReadMultVectors.

The first method specifies multiple vectors by their (Type, Request, Component) set for a given Subcase. This is equivalent to using ReadVector multiple times. The arguments for (Type, Request, Component) set must be all of same data type, all strings, or all numerical indices.

hmtoggle_plus1ReadMultVectors

Reads multiple vectors of data for a particular Subcase.

M = ReadMultVectors(filename,t)

filename

Fully qualified filename to read. Use forward slash, (/), or double backslash, (\\), to separate folders.

t

An array of tables containing the (Subcase, Type, Request, Component) information of each vector. The structure of each table is shown below. The relevant information is set in the respective fields.

t

- SUBCASE (an optional field if the only Subcase is the implicit one)

- TYPE (the name or the numerical index of the Type)

- REQ (the name or the numerical index of the Request)

- COMP (the name or the numerical index of the Component)

M

An array of tables containing the read information. Each table has a hierarchical structure shown below, where the names of the fields for (Type, Request, Component) are set to the actual names or indices of those fields. This allows for easy access to the individual vectors. The data for each vector is stored in the field Data at the leaf node.

M

- SUBCASE (the name of the Subcase)

- type (the name or index of the Type as specified in the input)

- req (the name or index of the Request as specified in the input)

- comp (the name or index of the Component as specified in the input)

- Data (a vector containing the data)

Example 1

Reads two vectors from a file.

// Build the input table structure

t = {};

t.SUBCASE = "subcase 1" // specify the Subcase name

// the first vector specifications

t[1]={}

t[1].TYPE = "type1" // specify the Type name

t[1].REQ = "req1"        // specify the Request name

t[1].COMP = "comp1" // specify the Component name

// repeat for the second vector

t[2]={}

t[2].TYPE = "type1"

t[2].REQ = "req1"

t[2].COMP = "comp2"

// Now read the vectors

M = ReadMultVectors('c:/data.dat',t)

The results can be accessed as follows:

M["type1"]["req1"]["comp1"].Data

M["type1"]["req1"]["comp2"].Data

Example 2

This example is similar to Example 1 above, but uses numerical indices (shown for only the first vector).

// Build the input table structure

t = {};

t.SUBCASE = 1 // specify the Subcase index

// the first vector specifications

t[1]={}

t[1].TYPE = 1        // specify the Type index

t[1].REQ =  1        // specify the Request index

t[1].COMP = 1        // specify the Component index

The results can be accessed as follows:

M[1][1][1].Data

See Also

ReadVectorBuilder

The following form is the equivalent of resvector, found in Templex™.

hmtoggle_plus1ReadMultVectors

Reads vectors of data for a particular Type, at a particular timestep, across contiguous requests and components.

M = ReadMultVectors(filename,type, start_request, end_request, start_component, end_component, timestep)

filename

Fully qualified filename to read. Use forward slash, (/), or double-backslash, (\\),  to separate folders.

type

The Type of data to read, specified as the explicit numerical index (1 based).

start_request

The first data request to read, specified as the explicit numerical index (1 based).

end_request

The last data request to read, specified as the explicit numerical index (1 based).  Must be greater than or equal to start_request.

start_component

The first data component to read, specified as the explicit numerical index (1 based).

end_component

The last data component to read, specified as the explicit numerical index (1 based). Must be greater than or equal to start_component (1 based).

timestep

The timestep to read, specified as an index.

M

A matrix of size (end_request – start_request+1) rows and (end_component – start_component + 1) columns.  If start_component and end_component are equal, the result is a column vector.  If start_request and end_request are equal, the result is a row vector.

Rows represent requests and columns represent components.

All indices are one based.

Data with multiple Subcases are not supported.

Example

The following reads data from the file data.dat, for the first Type, the second and fourth requests, and the first to fifth components at the second time step.

M = ReadMultVectors ("c:/data.dat", 1, 2, 4, 1, 5, 2)

See Also

ReadVectorBuilder

Releasing Data

The data read via ReadVectors and ReadMultVectors are not necessarily automatically released from memory when the vectors they were assigned to are emptied. They can be released explicitly though as shown below. These mirror the ReadVectors and ReadMultVectors functions. On success, these return true.

ReleaseData(filename,type,request,component)

ReleaseData(filename,subcase,type,request,component)

The above two forms accept the same arguments as the two forms of ReadVectors, respectively.

ReleaseData(filename,t)

The above form accepts the same arguments as the first form of ReadMultVectors.

CAE Data Query

CAE data can also be queried for Subcase, Type, Request, and Component information.  When querying for this information, it is important to remember several points:

Data are grouped by Subcases.  Each file has at least one implicit Subcase, even though it may not be displayed as such in HyperGraph.
The first step in the query process is to get a handle to the Subcase. In the absence of Subcases, it will be the implicit Subcase (with index one).
Queries for Type, Request, and Component are done via this Subcase handle.
A default Type named "Index" is automatically appended to the list of Types for each Subcase.

The following functions are available for querying the data.

hmtoggle_plus1GetSubcase

Gets the handle to a Subcase.

s = GetSubcase(filename, i)

filename

Fully qualified filename to read.  Use forward slash, (/), or double backslashes, (\\), to separate folders.

i

The one-based index of the Subcase. There is always one implicit use case. In other words, "1" will always be available.

s

A handle to the Subcase.  It is used to query the data grouped beneath it for Type, Request, and Component information.

hmtoggle_plus1GetTotalSubcases

Returns the total number of Subcases.

n = GetTotalSubcases(filename)

filename

Fully qualified filename to read.  Use forward slash, (/) or double backslashes, (\\), to separate folders.

n

Total number of Subcases.  If only the implicit Subcase is present, a zero is returned.

hmtoggle_plus1GetSubcaseList

Returns the name of the Subcases.

t = GetSubcaseList (filename)

filename

Fully qualified filename to read. Use forward slash (/) or double backslashes, (\\), to separate folders.

t

A table containing the name of the Subcases as strings. Empty if no Subases are found.

hmtoggle_plus1GetSubcaseIndex

Returns the Subcase index.

i = s::GetSubcaseIndex()

s

The Subcase handle returned by GetSubcase.

i

The one based index of the Subcase

hmtoggle_plus1GetSubcaseName

Returns the name of the Subcase. It returns nil if no Subcase is present (only the implicit one).

name = s::GetSubcaseName()

s

The Subcase handle returned by GetSubcase.

name

The name of the Subcase.

hmtoggle_plus1GetNumTypes

Returns the total number of Types

n = s::GetNumTypes ()

s

The Subcase handle returned by GetSubcase.

n

Total number of Types belonging to the Subcase.  It will count the automatically appended type "Index".  Returns -1 if no Types are found.

hmtoggle_plus1GetTypeList

Returns the names of all Types.

t = s::GetTypeList ()

s

The Subcase handle returned by GetSubcase

t

A table containing the name of the Types as stings. Empty if no Types are found.

hmtoggle_plus1GetTypeName

Returns the name of the Type.

name = s::GetTypeName (i)

s

The Subcase handle returned by GetSubcase.

i

One-based index of the Type.

name

The name of the Type.

hmtoggle_plus1GetTypeIndex

Returns the index to the Type.

i = s::GetTypeIndex (name)

s

The Subcase handle returned by GetSubcase.

name

The name of the Type.

i

The one based index to the Type. Returns an error (invalid type) if not found.

hmtoggle_plus1GetNumReqs

Returns the total number of requests for a given Type.

n = s:: GetNumReqs(i)

s

The Subcase handle returned by GetSubcase.

i

The one-based index of the Type that the Request belongs to.

n

The number of requests for the Type.  Returns an error (invalid type) if no Requests are found.

hmtoggle_plus1GetReqList

Returns the names of all requests for a given Type.

t = s:: GetReqList (type)

s

The Subcase handle returned by GetSubcase

type

The name or one based index of the Type.

t

A table containing the name of the requests as stings. Empty if no requests are found.

hmtoggle_plus1GetReqName

Returns the name of the request for a given Type.

name = s::GetReqName (i, j)

s

The Subcase handle returned by GetSubcase.

i

The one-based index of the Type that the Request belongs to.

j

The one-based index of the Request.

name

The name of the Request.

hmtoggle_plus1GetReqIndex

Returns the index to a request for a given Type.

i = s::GetReqIndex (j, name)

s

The Subcase handle returned by GetSubcase.

j

The one-based index of the Type that the Request belongs to.

name

The name of the Request.

i

The one-based index of the Request.  Returns an error (invalid type) if not found.

hmtoggle_plus1GetNumComps

Returns the total number of components for a given Type.

n = s::GetNumComps(i)

s

The Subcase handle returned by GetSubcase.

i

The one-based index of the Type that the Request belongs to.

n

The number of components in the Type.  Returns -1 if no components are found.

hmtoggle_plus1GetCompList

Returns the names of the components for a given Type. Note, if the components are different for different requests then the list returned is the superset.

t = s:: GetCompList (type)

s

The Subcase handle returned by GetSubcase

type

The name or one-based index of the Type.

t

A table containing the name of the components as strings. Empty if no components are found.

hmtoggle_plus1GetFilteredCompList

Returns the names of the components for a given Type and Request. This is also needed when the component list varies with request.

t = s:: GetFilteredCompList(type, req)

s

The Subcase handle returned by GetSubcase.

type

The name or one-based index of the Type.

req

The name or one based index of the Request.

t

A table containing the name of the components as stings. Empty if no components are found.

hmtoggle_plus1GetCompName

Returns the name of the component for a given Type.

name = s::GetCompName (i, j)

s

The Subcase handle returned by GetSubcase.

i

The one-based index of the Type that the Request belongs to.

j

The one-based index of the component.

name

The name of the component.

hmtoggle_plus1GetCompIndex

Returns the index to a component for a given Type.

i = s::GetCompIndex (j, name)

s

The Subcase handle returned by GetSubcase.

j

The one-based index of the Type that the Request belongs to.

name

The name of the Component.

i

The one-based index of the Component.  Returns an error (invalid type) if not found.

hmtoggle_plus1Example

The following shows how to query data for number of Subcases, obtain the number of requests that belong to a specified Type in the last Subcase, and get the name of the last request in that Type.

n = GetTotalSubcases ("c:/test.dat");

if (n > 0) then

 obj = GetSubcase ("c:/test.dat", n); // gets handle of the last Subcase

 t = obj::GetTypeList(); // Gets the Type names in a table

     i = obj::GetTypeIndex("Time"); // index to Type named "Time"

 if (i>0) then

         n = obj::GetNumReqs(i); // number of requests for Type "Time"

         if (n > 0) then

                 name = obj::GetReqName(i,n); // the name of the last request

                 print(name)

         end

 end

end