Displaying values from a python code object on the geometry

Dan
Dan Member Posts: 1 **

I have a result I've calculated on a set of nodes in a python code object. I'm aware that there's a way to set the contour using dpf, but as I need individual node positions and a custom function to calculate my result, I'd rather use my existing values rather than figure out how to do it all again using dpf.

Is there a way to set the output contour without using dpf? Perhaps a half way house where I can compose a field to use in the dpf SetOutputContour function (I have node Ids and values per node), but how do I construct such a field?

Comments

  • Mike.Thompson
    Mike.Thompson Member, Employee Posts: 361
    25 Answers 100 Comments Second Anniversary 25 Likes
    ✭✭✭✭
    edited December 2023

    The answer is a bit nuanced, so lets start with some basic facts:

    1. You cannot plot with a python code object, you must use a python result object
    2. You can only plot DPF data in python result objects
    3. You can create DPF data from almost anything. You can read external files, or do non-DPF calculations and then simply put the data into a DPF Field/Fields Container. Although DPF calculations produce DPF data structures, it is NOT exclusive as you can create DPF data structures from scratch too.

    Check out this post that demonstrates how to read in data from a .csv file, then plot it in python result. A snippet of the code is below. This is where I read the data from l csv directly into a DPF field. DPF does not care if data comes from a results file, csv file, or is calculated in python directly. Once you have a Field, plot as you normally would.
    Obviously change as you see fit on the Field for things like location (nodal, elemental etc...), number of data points, units, scalar vs. vector vs tensor, etc....

    NdIds = []
    Vals = []
    with open(FilePath) as CsvFile:
        CsvReader = csv.reader(CsvFile, delimiter=',')
        Rows = list(CsvReader)
        for Row in Rows[1:]:
            NdIds.append(int(Row[NdIdsCol-1]))
            Vals.append(float(Row[ValsCol-1]))
    F = dpf.FieldsFactory.CreateScalarField(10, dpf.locations.nodal)
    F.Data=Vals
    F.Scoping.Ids=NdIds