Coder Social home page Coder Social logo

Comments (9)

OndraMichal avatar OndraMichal commented on August 21, 2024

Hi @ZTThomasOberthanner,
thank you for thr question. To query the model you start with initializing the connection. This can be done via Model(False, "model_name"). Then use any getter you need to retrieve the data. Our unit tests (RFEM_Python_Client/UnitTests/) are good examples of setting values and getting them back for checking correctness. But in the tests we use currently available (active) model, that is why you see just Model() there.
If you want to see all available model functions and types (prefix ns0:), just initialize class Model and then print(Model.clientModel). This is the easiest way SUDS module shows everything it recognizes.
I'll add this process to our Wiki.

from rfem_python_client.

ZTThomasOberthanner avatar ZTThomasOberthanner commented on August 21, 2024

Thanks for the quick reply, i did had a look at test_Member_test.py but I could not find any tests for correctness there.
I am now able to get node/member information from the model. But I cannot figure out how to get the internal forces for a member for a certain loadcase/result combination. Would by happy for another hint.

from rfem_python_client.

DavidNaizheZhou avatar DavidNaizheZhou commented on August 21, 2024

is it possible to query a list/table of all nodes, members, ...?

suggestion:
get_node() - function with a default None

get_node(xs=None) -> provides the nodes table as (DataFrame or a Dict)
image

from rfem_python_client.

ZTThomasOberthanner avatar ZTThomasOberthanner commented on August 21, 2024

this is my implementation for fetching all nodes

    def get_nodes(self):
        numbers=self.service.get_all_object_numbers(type='E_OBJECT_TYPE_NODE')
        return [self.service.get_node(n) for n in numbers]

you cannot copy paste that, because this is part of my own python client, but i think you get the idea...

from rfem_python_client.

DavidNaizheZhou avatar DavidNaizheZhou commented on August 21, 2024

got it...thank you!!

here is my minimal working example:

from RFEM.initModel import Model, ConvertStrToListOfInt
from RFEM.BasicObjects.node import Node

Model(new_model=True, model_name="extract")

# model modification
Model.clientModel.service.begin_modification()
Node(1, 0.0, 0.0, 0.0)
Node(2, 1.0, 0.0, 0.0)
Node(3, 2.0, 0.0, 0.0)
Model.clientModel.service.finish_modification()

# extract all nodes
numbers = ConvertStrToListOfInt(
    Model.clientModel.service.get_all_object_numbers(type="E_OBJECT_TYPE_NODE")
)
node_list = [Model.clientModel.service.get_node(n) for n in numbers]

from rfem_python_client.

dogukankaratas avatar dogukankaratas commented on August 21, 2024

Hey, thanks for bringing this up and ideas. I would like to jump back the question and drop here a suggestion. Here is a function to create DataFrame tables for Node objects.

def getNodeTable():
        import pandas as pd
        nodeTable = pd.DataFrame(columns=["Node No.", "X", "Y", "Z"])
        modelStatus = GetModelInfo()
        for i in range(1, modelStatus[0] + 1):
            nodeTable.loc[i] = [i, Model.clientModel.service.get_node(i)['coordinate_1'],
                                   Model.clientModel.service.get_node(i)['coordinate_2'],
                                   Model.clientModel.service.get_node(i)['coordinate_3']]

        return nodeTable

The same logic will work for another objects (lines, members, surfaces etc.).

Maybe this functions can be added to our static methods. Please let me know about your thoughts ✌️

from rfem_python_client.

DavidNaizheZhou avatar DavidNaizheZhou commented on August 21, 2024

here is my suggestion for fetching tables into a pandas dataframe:

import pandas as pd
import numpy as np

from RFEM.initModel import Model, ConvertStrToListOfInt
from RFEM.BasicObjects.node import Node
from RFEM.BasicObjects.material import Material
from RFEM.BasicObjects.section import Section


def load_object(clientModel, type="NODE"):
    numbers = ConvertStrToListOfInt(
        clientModel.service.get_all_object_numbers(
            type="E_OBJECT_TYPE_{}".format(type.upper())
        )
    )
    if type.upper() == "NODE":
        return [Model.clientModel.service.get_node(int(n)) for n in numbers]
    else:
        # todo object types
        pass


def load_dataframe(clientModel, type="NODE"):
    nodes_list = load_object(clientModel, type)
    len_numbers = len(nodes_list)
    keys = dict(nodes_list[0]).keys()
    dataframe = pd.DataFrame(columns=keys, index=range(len_numbers), dtype=object)
    for i, node in enumerate(nodes_list):
        node_dict = dict(node)
        values = node_dict.values()
        dataframe.iloc[i] = np.array([value for value in values], dtype=object)
    return dataframe


Model(new_model=True, model_name="extract_dataframe")

# model modification
Model.clientModel.service.begin_modification()
Node(1, 0.0, 0.0, 0.0)
Node(2, 1.0, 0.0, 0.0)
Node(3, 2.0, 0.0, 0.0)
Model.clientModel.service.finish_modification()

# load dataframe
df = load_dataframe(Model.clientModel, type="NODE")
print(df)

from rfem_python_client.

ZTThomasOberthanner avatar ZTThomasOberthanner commented on August 21, 2024

just a reminder:
clientModel.service.get_all_object_numbers already returns a list of int - so no need for ConvertStrToListOfInt...

numbers = ConvertStrToListOfInt(
        clientModel.service.get_all_object_numbers(
            type="E_OBJECT_TYPE_{}".format(type.upper())
        )
    )

from rfem_python_client.

dogukankaratas avatar dogukankaratas commented on August 21, 2024

Since everyone has a solution, this issue will be closed 😃 Thanks for contribution.

from rfem_python_client.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.