Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1
  • 2

TOPIC: Compute or extract Strain Rate Tensor in Telemac 2D

Compute or extract Strain Rate Tensor in Telemac 2D 2 years 7 months ago #40185

Dear All,

I am trying to couple a behavioral model of fish migration with my 2D Simulation using TelAPy in python. One of my inputs for the behavioral model is the Strain Rate Tensor.

I have computed the SR extracting u,v,X,Y for each time-step. However, my script is extremelly expensive, computationally expensive.

Does anyone know how to extract or compute the Strain Rate Tensor each time step.

Thank you very much for the help,

Kind regards,

Marcelo
The administrator has disabled public write access.

Compute or extract Strain Rate Tensor in Telemac 2D 2 years 7 months ago #40197

  • pham
  • pham's Avatar
  • OFFLINE
  • Administrator
  • Posts: 1559
  • Thank you received: 602
Hello Marcelo,

I am not a TelApy specialist nor a Python expert, but your script may not be optimised. To get u, v, x and y for each time step, do you use e.g. a get_array method to manipulate a numpy array?

Python is optimised when scripts are well written (avoid loops as in Fortran). Maybe you should rewrite your script (please post in the script section in that case).

Hope this helps,

Chi-Tuan
The administrator has disabled public write access.

Compute or extract Strain Rate Tensor in Telemac 2D 2 years 7 months ago #40207

  • konsonaut
  • konsonaut's Avatar
  • OFFLINE
  • openTELEMAC Guru
  • Posts: 413
  • Thank you received: 144
Hi,

I am also not a TelApy specialist but maybe you could use a dedicated Fortran subroutine. Telemac in various subroutines computes the strain rate tensor e.g. for turbulence modelling, see for example in mixlength.f or smagor.f.
In calculating the strain rate tensor you should take care about the local areas.

BR,
Clemens
The administrator has disabled public write access.

Compute or extract Strain Rate Tensor in Telemac 2D 2 years 7 months ago #40232

Dear Clemens,

Thank you for the advice I will give it a look and probably contact you soon if possible for some additional support, if possible.

I am not an expert on Fortran coding. Have done a pretty simple codes. However I think it is the most suitable solution.

Thank you very much.

Kind regards,

Marcelo
The administrator has disabled public write access.

Compute or extract Strain Rate Tensor in Telemac 2D 2 years 7 months ago #40231

Dear Chi Tuan,

Yes indeed, I am using loops in python to compute the strain rate tensor norm. In addition I am using griddata interpolation to get it from numerical differentiation. It is a high computational effort. I don't think I will use it. However I have attached the file so you can give it a look

Kind regards,

Marcelo
Attachments:
The administrator has disabled public write access.

Compute or extract Strain Rate Tensor in Telemac 2D 2 years 7 months ago #40233

I made a mistake in the definition fo the matrix at the file strainRate_TelApy.py line 11 it is
dudx =np.zeros([ny,nx])
istead of
dudx =np.zeros(ny,nx)

greetings,

Marcelo
The administrator has disabled public write access.

Compute or extract Strain Rate Tensor in Telemac 2D 2 years 7 months ago #40235

  • pilou1253
  • pilou1253's Avatar
  • OFFLINE
  • openTELEMAC Guru
  • Posts: 584
  • Thank you received: 106
Hi,

Just a quick reply.

Firstly, I think the best is to compute the strain rate during the telemac run following methods used in the subroutines named by Clemens. You could save it in a PRIVE user variable and read it directly from TelApy at each time step.

Beware that in your method, you compute gradients from results interpolated on a regular mesh, which may introduce some errors.

Beware that you have an error in your python script at this line:
SR = np.sqrt(dudx**2 + dvdy**2 + (dudy+dvdy)**2/2)

it should be dvdx and not dvdy in the last term.

Good luck!

Best regards
PL
The administrator has disabled public write access.

Compute or extract Strain Rate Tensor in Telemac 2D 2 years 7 months ago #40236

Dear PL,

Thank you very much for pointing the error in the script out. As in for the other comments, I am aware about the errors the interpolation might have. As I stated I am new in Telemac usage and also a Fortran codign beginner. I am trying to figure out how to include the subroutine of the scripts Clemens mentioned without tocuhing the source code.

Should I specify it in the *.cas file as:
FORTRAN FILE: 'user_fortran/subroutine.f'

or include it in the source code? just to be sure the source of telemac2d is in 'opentelemac-mascaret/v#p#r#/sources/telemac2d/telemac2d.F', right?

Thank you again for the comments you all are really helping me out,

kind regards,

marcelo
The administrator has disabled public write access.

Compute or extract Strain Rate Tensor in Telemac 2D 2 years 7 months ago #40241

  • konsonaut
  • konsonaut's Avatar
  • OFFLINE
  • openTELEMAC Guru
  • Posts: 413
  • Thank you received: 144
Hi Marcelo,

as PL said, the most convenient way is to use a private variable PRIVE. You can find its usage in the Telemac manual and in a lot of forum posts also. It is well explained. You don't have to touch the source code or include something in the source folder.
If you specfiy FORTRAN FILE: 'user_fortran' Telemac will compile all user-defined subroutines in the folder 'user_fortran' which is very handy.
Regarding your Python script: I wouldn't go further with this script. If you want to stick to Python you should heaviliy modify it by using more pythonic-numpy functions. To start, for example for calculating the differences you could use numpy.diff. The construction of a regular grid is very inefficient, especially with such small deltas of 5 mm. Depending on your domain extension (shape), you have to calculate the variables in a lot of unnecessary points. Or your modelling domain is a square.

Personally, I'm dealing quite a lot with various habitat modelling techniques within Telemac and I'm interested also in fish migration models. Could you give me a reference for your case?

Another question: do you need to calculate the strain rate really at every time step?

Best regards,

Clemens
The administrator has disabled public write access.

Compute or extract Strain Rate Tensor in Telemac 2D 2 years 7 months ago #40242

  • pilou1253
  • pilou1253's Avatar
  • OFFLINE
  • openTELEMAC Guru
  • Posts: 584
  • Thank you received: 106
Dear Marcelo,

Fun to see that for a beginner in TELEMAC, you are already working with TelApy (I haven't tried even though I worked with the software for ca 10 years now!).

As Clemens wrote, I would recommend you to read the manual and especially the chapter dedicated to user subroutines.

What you need is to write your calculation of strain rate in a subroutine called at every time step, as user_preres_telemac2d.f

To store the strain rate in a user variable that you can find in the results file, please see that manual but you can also find examples in ./examples/telemac2d/pluie (look for PRIVE%ADR(1)... in the code).

This should set you in the right direction!

As for the strain rate calculation itself, it seems that there is a possibility to compute it directely with a CALL VECTOR and using formula 'PRODF' instead of 'GRADF X' and 'GRADF Y', see the developper guide chapter 4.3.2 (./documentation/Misc), but beware that you might need to divide by cell area**2 (=UNSV2D%R(I)**2), as done in subroutine mixlength.f that Clemens named.

Good luck!

Best regards
PL
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Moderators: pham

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