Welcome, Guest
Username: Password: Remember me

TOPIC: Modify value of variable in 3D result file used as initial condition

Modify value of variable in 3D result file used as initial condition 7 years 3 weeks ago #28091

  • pma
  • pma's Avatar
Hello!

I am using a Telemac-3D result file as initial condition for a new simulation (computation continued = true). I would like to change the value of one the variables in this file. More specically what I want to do is to replace the values with a constant value in the entire domain.

Is there an easy way to do this?

Thanks in advance.
Kind regards,

Patricia
The administrator has disabled public write access.

Modify value of variable in 3D result file used as initial condition 7 years 3 weeks ago #28092

  • Phelype
  • Phelype's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 140
  • Thank you received: 64
Hello Patricia,

My suggestion (personal preference) would be the TelemacTools by Thomas Benson to read/write selafin files in Matlab.

If you don't use Matlab then there's the PPUtils or the PyTelTools developed for using with Python.

Also I think that in BlueKenue you can assign values to a variable. But I think it has a few restrictions on multi-frame files.

A quick question: if you want to assign a constant value throughout the domain, why use a continued computation? Why don't you do it using the steering?

Regards,

Phelype
The administrator has disabled public write access.
The following user(s) said Thank You: pma

Modify value of variable in 3D result file used as initial condition 7 years 3 weeks ago #28095

  • pma
  • pma's Avatar
Thanks you! I will look into the scripts you suggested.

The reason I am using continued computation is that I want to use all the variables from the old result file except for one which I want to set to a constant value. I read the result file in BlueKenue and tried to remove the variable that I wanted to set to a constant so that I could initialize it in the cas-file but I didn't get it to work.

Kind regards,

Patricia
The administrator has disabled public write access.

Modify value of variable in 3D result file used as initial condition 7 years 3 weeks ago #28101

  • c.coulet
  • c.coulet's Avatar
  • OFFLINE
  • Moderator
  • Posts: 3722
  • Thank you received: 1031
Hi
Instead of trying to modify the value in the result file, you could try to remove this variable from the result file and give the constant value in the steering file.
Hope this helps
Christophe
The administrator has disabled public write access.
The following user(s) said Thank You: pma

Modify value of variable in 3D result file used as initial condition 7 years 2 weeks ago #28140

  • pma
  • pma's Avatar
Hi!

Thanks for your suggestion!


I tried this approach by opening the 3D result file in Blue Kenue and removing one variable (right-clicked with the mouse on the variable and the marked "remove"). The variable disappeared but I was not able to save the file. "Load WorkSpace" savae dhte file in its original format with the variable and "Save" was greyed out. Would you do this in Blue Kenue or some other program? If in Blue Kenue, how can I save the modified file?

Kind regards,

Patricia
The administrator has disabled public write access.

Modify value of variable in 3D result file used as initial condition 7 years 2 weeks ago #28141

  • c.coulet
  • c.coulet's Avatar
  • OFFLINE
  • Moderator
  • Posts: 3722
  • Thank you received: 1031
Hi
You could normally save the file with "save as" as a "selafin file format"
Regards
Christophe
The administrator has disabled public write access.

Modify value of variable in 3D result file used as initial condition 7 years 2 weeks ago #28144

  • Lux
  • Lux's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 96
  • Thank you received: 39
Hi Patricia,

I do not know exactly what you want to modify, but there should be several ways (e.g. using a Fortran subroutine, a Python script or a software like BlueKenue).

If you want to use Python scripts, you can try PyTelTools.

To remove a variable, you can use the command line script cli/slf_base.py or simply use Extract Variables from the GUI (in the so-called classic interface).

After having installed PyTelTools, you can define also your own script and do some complex modification.
Here is an example in case you want to modify some variables for each frame (or time).
import numpy as np

from pyteltools.slf import Serafin


in_slf = 'r3d.slf'
out_slf = 'r3d_new.slf'
LANG = 'fr'  # Change to 'en' if variables are written in english

with Serafin.Read(in_slf, LANG) as resin:
    resin.read_header()
    print(resin.header.summary())
    resin.get_time()

    output_header = resin.header.copy()

    values = np.empty((output_header.nb_var, output_header.nb_nodes), dtype=output_header.np_float_type)

    with Serafin.Write(out_slf, LANG) as resout:
        resout.write_header(output_header)

        for time_index, time in enumerate(resin.time):
            print('Frame %i: time  %ds' % (time_index, time))
            for i, var_ID in enumerate(output_header.var_IDs):
                print('Variable: %s' % var_ID)
                values[i, :] = resin.read_var_in_frame(time_index, var_ID)

                # Do you modification by position
                if var_ID == 'W':  # Modify W velocity (beware that LANG variable is ok)
                    values[i, :] = values[i, :]/10

                if i == 1:  # Modify second variable (Python is using 0-indexed iterator)
                    values[i, :] = -2.0

            resout.write_entire_frame(output_header, time, values)

Hope it helps.

Regards,
Luc
The administrator has disabled public write access.

Modify value of variable in 3D result file used as initial condition 7 years 1 week ago #28155

  • riadh
  • riadh's Avatar
Hello

An easy way also is to use the following line in Telemac3d.F just before the time loop (and then put this subroutine in your fortran folder)

CALL OS( 'X=C ', X=Z, C=1.D0 )

you have to change Z and C by your variable.


with my kind regards

Riadh
The administrator has disabled public write access.
Moderators: pham

The open TELEMAC-MASCARET template for Joomla!2.5, the HTML 4 version.