3311x
001806
2023-07-19

Tutorial for WebService & API in C#

Our WebService offers users the opportunity to communicate with RFEM 6 and RSTAB 9 using various programming languages. Dlubal's high-level functions (HLFs) allow you to expand and simplify the WebService's functionality. In line with RFEM 6 and RSTAB 9, using our WebService makes an engineer's work easier and faster. Check it out now! This tutorial shows you how to use the C# library by means of a simple example.

The HLF library for C# provides numerous useful features for creating structures in RFEM and RSTAB, some of which will be used in the following example.

In order to implement the programmed code, a connection to the program is required first. One of the available ports must be specified as an address. The default address of RFEM/RSTAB is http://localhost:8081 . If necessary, it can be modified in the program options.

In the next step, various objects such as nodes, lines, and members can be created using the functions available in the C# library. The library includes classes for all available objects. The objects' properties can be defined and specified based on parameters. The number of parameters may vary depending on the use case.

The following shows how objects can be defined using the example of a node:

node newNode = new()
{
    no = nodeId,
    coordinates = new vector_3d() { x = xVector, y = 0.0, z = 0.0 },
    coordinate_system_type = node_coordinate_system_type.COORDINATE_SYSTEM_CARTESIAN,
    coordinate_system_typeSpecified = true,
    comment = "node for beam"
};

Lines, surfaces, and other objects are defined in the same way. Please note that a corresponding "Specified" attribute must be defined and set to "true" for certain attributes.

Practical Example

This example shows you how to create a continuous beam with a constant line load. The number of spans, the beam span, and the magnitude of the line load can be set variably via user input.

First, the required variables are user-defined in the console. The program checks whether the input of the user is compatible with the data type of the respective variable. If the entry is incorrect or empty, an error message appears in the console. During programming, care was taken to ensure that decimal places can be entered using both point and comma notation in order to minimize the susceptibility to errors during input.

Connection to RFEM/RSTAB

The following code tries to establish a connection with RFEM/RSTAB within a try-catch block:

var logger = LogManager.GetCurrentClassLogger();
string CurrentDirectory = Directory.GetCurrentDirectory();
try
{
    application_information ApplicationInfo;

    try
    {
        // connect to RFEM6 or RSTAB9 application
        application = new ApplicationClient(Binding, Address);
    }
    catch (Exception exception)
    {
        if (application != zero)
        {
            if (application.State != CommunicationState.Faulted)
            {
                application.Close();
                logger.Error(exception, "Something happened:" + exception.Message);
            }
            else
            {
                application.Abort();
                logger.Error(exception, "Communication with RFEM faulted:" + exception.Message);
            }
        }
        Console.WriteLine(exception.ToString());
    }
    finally
    {
        ApplicationInfo = application.get_information();
        logger.Info("Name: {0}, Version:{1}, Type: {2}, language: {3} ", ApplicationInfo.name, ApplicationInfo.version, ApplicationInfo.type, ApplicationInfo.language_name);
        Console.WriteLine("Name: {0}, Version:{1}, Type: {2}, language: {3} ", ApplicationInfo.name, ApplicationInfo.version, ApplicationInfo.type, ApplicationInfo.language_name);
    }
}

string modelName = "MyTestModel";
string modelUrl ="";
ModelClient model = new ModelClient(Binding, new EndpointAddress(modelUrl));

In order to set up a connection, the program must be open before running the code. After a successful connection, the program information is displayed in the console and a new model with a user-defined name is created in RFEM/RSTAB.

Definition of Basic Objects

In the next step, you can define the material and cross-section of the continuous beam. It is important that the description corresponds to the name stored in the RFEM material or cross-section library.

material materialConcrete = new material
{
    no = 1,
    name = "C20/25 | EN 1992-1-1:2004/A1:2014"
};

section sectionRectangle = new section
{
    no = 1,
    material = materialConcrete.no,
    materialSpecified = true,
    type = section_type.TYPE_PARAMETRIC_MASSIVE_I,
    typeSpecified = true,
    parametrization_type = section_parametrization_type.PARAMETRIC_MASSIVE_I__MASSIVE_RECTANGLE__R_M1,
    parametrization_typeSpecified = true,
    name = "R_M1 0.5/1.0"
};

With the help of loops, various objects (nodes, lines, members) are created and organized in lists. The nodes are defined depending on the user-defined number of spans and transferred to the "lineDefinitionNodes" list. The list will later be used to create lines based on their definition nodes. When creating an RSTAB model, the list is used to define the members based on their definition nodes. When using RFEM, the members are defined via lines.

SortedList<int, node> nodes = new SortedList<int, node>();
int[] lineDefinitionNodes = new int[spanNumber + 1];
int nodeId = 1;
double xVector = 0.0;

for (int i = 0; i < spanNumber + 1; i++)
{
    node newNode = new()
    {
        no = nodeId,
        coordinates = new vector_3d() { x = xVector, y = 0.0, z = 0.0 },
        coordinate_system_type = node_coordinate_system_type.COORDINATE_SYSTEM_CARTESIAN,
        coordinate_system_typeSpecified = true,
        comment = "concrete part"
    };
    nodes.Add(nodeId, newNode);
    lineDefinitionNodes[i] = nodeId;
    xVector = xVector + span;
    nodeId++;
}

// create lines
int lineId = 1;
SortedList<int, line> lines = new SortedList<int, line>();

for (int i = 0; i < spanNumber; i++)
{
    line newLine = new()
    {
        no = lineId,
        definition_nodes = new int[] { lineDefinitionNodes[i], lineDefinitionNodes[i + 1] },
        comment = "lines for beams",
        type = line_type.TYPE_POLYLINE,
        typeSpecified = true,
    };
    lines.Add(lineId, newLine);
    lineId++;
}

After all base objects have been created, two different nodal supports are defined. The nodal support on the first node should be fixed; the remaining supports should be designed as rollers in the X-direction. The definition nodes for the various support types are each summarized in a separate list.

nodal_support support1 = new()
{
    no = 1,
    nodes = supportedNodes1.ToArray(),
    spring = new vector_3d() { x = double.PositiveInfinity, y = double.PositiveInfinity, z = double.PositiveInfinity },
    rotational_restraint = new vector_3d() { x = double.PositiveInfinity, y = 0.0, z = double.PositiveInfinity }
};

nodal_support support2 = new()
{
    no = 2,
    nodes = supportedNodes2.ToArray(),
    spring = new vector_3d() { x = 0.0, y = double.PositiveInfinity, z = double.PositiveInfinity },
    rotational_restraint = new vector_3d() { x = 0.0, y = 0.0, z = double.PositiveInfinity }
};

nodalSupports.Add(support1);
nodalSupports.Add(support2);

Transfer of Objects to RFEM

In order to make the created objects available in RFEM/RSTAB, they must first be transferred to the program. This is done between the two functions "model.begin_modification" and "model.end_modification", using object-specific functions of the HLF library. All objects of one type are transferred to the program using foreach loops.

try
{
    model.begin_modification("Geometry");
    model.set_material(materialConcrete);
    model.set_section(sectionRectangle);

    foreach (KeyValuePair<int, node> nodeItem in nodes)
    {
        model.set_node(nodeItem.Value);
    }
    foreach (KeyValuePair<int, line> lineItem in lines)
    {
        model.set_line(lineItem.Value);
    }
    foreach (KeyValuePair<int, member> memberItem in members)
    {
       	model.set_member(memberItem.Value);
    }
    foreach (var nodalSupport in nodalSupports)
    {
        model.set_nodal_support(nodalSupport);
    }
}
catch (Exception exception)
{
    model.cancel_modification();
    logger.Error(exception, "Something happened while creation of geometry" + exception.Message);
    throw;
}
finally
{
    try
    {
       	model.finish_modification();
    }
    catch (Exception exception)
    {
        logger.Error(exception, "Something went wrong while finishing modification of geometry\n" + exception.Message + "\n");
         model.reset();
    }
}

Definition of Loads

Load cases, load combinations, and design situations are created in a similar way as basic objects and then transferred to the program.

Then, the member load, which was previously specified by the user, can be created:

SortedList<int, member_load> member_loads = new SortedList<int, member_load>();
int member_load_id = 1;

for (int i = 0; i < spanNumber; i++)
{
    member_load newMemberLoad = new()
    {
        no = i + 1,
        members_string = (i + 1).ToString(),
        members = new int[] { i + 1 },
        load_distribution = member_load_load_distribution.LOAD_DISTRIBUTION_UNIFORM,
        load_distributionSpecified = true,
        magnitude = memberLoad * 1000,
        magnitudeSpecified = true,
        load_is_over_total_length = true,
        load_is_over_total_lengthSpecified = true,
    };
    member_loads.Add(i + 1, newMemberLoad);
    member_load_id++;
}

In addition to uniformly distributed loads, trapezoidal and parabolic loads are also possible.

Calculation and Result Output

The model.calculate(all) function is used to perform all calculations in RFEM.

After a successful calculation, the results in this example are displayed in the console. The HLF library for C# also allows for the export of results in XML or CSV files.

Finally, the model.save() function can be used to save the model under the file path indicated in brackets:

//save the model before closing
model.save(CurrentDirectory + @"\testmodels\");
application.close_model(0, true);

Conclusion

In the example shown, the advantages and easy handling of the C# library are made clear. The structure can be quickly adapted by means of user-defined entries, which saves a lot of time when entering structural systems in RFEM 6 and RSTAB 9. The HLF library for C# also offers many other functions, enabling the creation of complex systems.


Author

Ms. Göbel provides technical support for Dlubal Software customers.

Links


;