CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > SU2

Segmentation Fault when Setting Custom Temperature on Nozzle Wall

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By bigfootedrockmidget

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 2, 2024, 06:56
Default Segmentation Fault when Setting Custom Temperature on Nozzle Wall
  #1
Member
 
Sean
Join Date: May 2023
Posts: 41
Rep Power: 2
bgulzar22 is on a distinguished road
Dear SU2 Community,

I am encountering an issue while trying to apply spatially varying temperatures on the wall of a nozzle in my SU2 simulation. To achieve this, I've developed a Python script to read temperature values from a file and apply them to the corresponding vertices on the nozzle wall.

However, when attempting to set the custom temperature using the SetMarkerCustomTemperature function, I encounter a segmentation fault error. This error occurs specifically when I uncomment the line SU2Driver.SetMarkerCustomTemperature(MarkerID, iVertex, temperature) in the script.

I've attached the relevant files for reference in the following link:
https://drive.google.com/drive/folde...usp=drive_link

Python script: [back_nozzle_2.py]
Configuration file: [Back_nozzle.cfg]
Mesh file: [PT.su2]
Temperature file: [temperature.txt]


I've ensured that all files are properly formatted and that the temperature file contains values matching the number of vertices on the wall. Despite this, I am still facing this segmentation fault.

Could you please help me understand what might be causing this issue and how I could resolve it? Any insights or suggestions would be greatly appreciated.

Thank you very much for your time and assistance.
bgulzar22 is offline   Reply With Quote

Old   April 3, 2024, 02:04
Default
  #2
Senior Member
 
bigfoot
Join Date: Dec 2011
Location: Netherlands
Posts: 504
Rep Power: 17
bigfootedrockmidget is on a distinguished road
You have to add this in your config file:

Code:
MARKER_PYTHON_CUSTOM = (WALL)
Compared to the unsteady CHT example in Testcases/py_wrapper, you have to modify this part:



Code:
    
      for iVertex in range(nVertex_CHTMarker):
       CoordX, CoordY = SU2Driver.MarkerCoordinates(CHTMarkerID).Get(iVertex)
      temperature = temperature_values[iVertex] if iVertex < len(temperature_values) else 0
      print("T(",CoordX,",",CoordY,") = ",temperature)
      SU2Driver.SetMarkerCustomTemperature(CHTMarkerID, iVertex, temperature)
complete code:





Code:
import sys
from optparse import OptionParser    # use a parser for configuration
import pysu2                        # imports the SU2 wrapped module
from math import *

# Read temperature values from a file (assuming one temperature value per line)
def read_temperature(file_path):
    try:
        with open(file_path, 'r') as temp_file:
            temperature_values = [float(line.strip()) for line in temp_file.readlines()]
        return temperature_values
    except FileNotFoundError:
        print(f"ERROR: File '{file_path}' not found.")
        sys.exit(1)
    except Exception as e:
        print("An error occurred while reading the temperature file:", e)
        sys.exit(1)

# -------------------------------------------------------------------
#  Main
# -------------------------------------------------------------------

def main():
  print("START PYTHON SCRIPT")
  # Command line options
  parser=OptionParser()
  parser.add_option("-f", "--file", dest="filename", help="Read config from FILE", metavar="FILE")
  parser.add_option("--parallel", action="store_true",
                    help="Specify if we need to initialize MPI", dest="with_MPI", default=False)

  (options, args) = parser.parse_args()
  options.nDim = int(2)
  options.nZone = int(1)

  # Import mpi4py for parallel run
  if options.with_MPI == True:
    from mpi4py import MPI
    comm = MPI.COMM_WORLD
    rank = comm.Get_rank()
  else:
    comm = 0
    rank = 0

  # Initialize the corresponding driver of SU2, this includes solver preprocessing
  try:
      SU2Driver = pysu2.CSinglezoneDriver(options.filename, options.nZone, comm);
  except TypeError as exception:
    print('A TypeError occured in pysu2.CDriver : ',exception)
    if options.with_MPI == True:
      print('ERROR : You are trying to initialize MPI with a serial build of the wrapper. Please, remove the --parallel option that is incompatible with a serial build.')
    else:
      print('ERROR : You are trying to launch a computation without initializing MPI but the wrapper has been built in parallel. Please add the --parallel option in order to initialize MPI for the wrapper.')
    return


  CHTMarkerID = None
  CHTMarker = 'WALL'       # Specified by the user

  temperature_file = 'temperature.txt'
  temperature_values = read_temperature(temperature_file)


  # Get all the tags with the CHT option
  CHTMarkerList =  SU2Driver.GetCHTMarkerTags()

  # Get all the markers defined on this rank and their associated indices.
  allMarkerIDs = SU2Driver.GetMarkerIndices()

  #Check if the specified marker has a CHT option and if it exists on this rank.
  if CHTMarker in CHTMarkerList and CHTMarker in allMarkerIDs.keys():
    CHTMarkerID = allMarkerIDs[CHTMarker]
    print("Marker ID = ",CHTMarkerID)

  # Number of vertices on the specified marker (per rank)
  nVertex_CHTMarker = 0         # total number of vertices (physical + halo)

  if CHTMarkerID != None:
    nVertex_CHTMarker = SU2Driver.GetNumberMarkerNodes(CHTMarkerID)
    print("nr vertices = ",nVertex_CHTMarker)

  # Retrieve some control parameters from the driver
  TimeIter = SU2Driver.GetTimeIter()
  nTimeIter = SU2Driver.GetNumberTimeIter()


  # Time loop is defined in Python so that we have acces to SU2 functionalities at each time step
  if rank == 0:
    sys.stdout.flush()
  if options.with_MPI == True:
    comm.Barrier()

  for TimeIter in range (nTimeIter):
    # Time iteration preprocessing
    SU2Driver.Preprocess(TimeIter)
    # Set this temperature to all the vertices on the specified CHT marker
    for iVertex in range(nVertex_CHTMarker):
      CoordX, CoordY = SU2Driver.MarkerCoordinates(CHTMarkerID).Get(iVertex)
      temperature = temperature_values[iVertex] if iVertex < len(temperature_values) else 0
      print("T(",CoordX,",",CoordY,") = ",temperature)
      SU2Driver.SetMarkerCustomTemperature(CHTMarkerID, iVertex, temperature)

    # Tell the SU2 drive to update the boundary conditions
    SU2Driver.BoundaryConditionsUpdate()
    # Run one time iteration (e.g. dual-time)
    SU2Driver.Run()
    # Postprocess the solver and exit cleanly
    SU2Driver.Postprocess()
    # Update the solver for the next time iteration
    SU2Driver.Update()
    # Monitor the solver and output solution to file if required
    stopCalc = SU2Driver.Monitor(TimeIter)
    SU2Driver.Output(TimeIter)
    if (stopCalc == True):
      break
    # Update control parameters
    TimeIter += 1
    time += deltaT


# -------------------------------------------------------------------
#  Run Main Program
# -------------------------------------------------------------------

# this is only accessed if running from command prompt
if __name__ == '__main__':
    main()


bgulzar22 likes this.
bigfootedrockmidget is offline   Reply With Quote

Old   April 4, 2024, 07:27
Default
  #3
Member
 
Sean
Join Date: May 2023
Posts: 41
Rep Power: 2
bgulzar22 is on a distinguished road
Dear Bigfoot,

Thank you for providing the updated code snippet and your guidance. I've implemented the changes in my script and observed improvements in addressing the segmentation fault issue.

However, I have a few queries regarding the updated code:

Time Loop in Steady Simulation: As my simulation is steady-state, I noticed the presence of a time loop in the script. Could you please clarify why the time loop is included? Shouldn't it be removed for steady simulations?

Incomplete Temperature Reading: Although the code has been updated, I noticed that not all temperature values are being read and assigned to the vertices correctly. Is there a specific reason why some temperature values are not being read?

Sequential Temperature Assignment: Currently, the temperature values are assigned to vertices in seemingly random assignments. Is there a way to modify the code so that temperature values are assigned sequentially from the start to the end of the WALL boundary? I want each temperature value to correspond to a specific vertex along the boundary.

I appreciate your assistance and look forward to your insights on these queries.

Best regards
bgulzar22 is offline   Reply With Quote

Old   April 4, 2024, 12:31
Default
  #4
Member
 
Sean
Join Date: May 2023
Posts: 41
Rep Power: 2
bgulzar22 is on a distinguished road
I noticed that when I attempted to print the CoordX and CoordY values of vertices on the WALL boundary, they appear to be generated randomly and not following a particular order. Could you please shed some light on why this is happening? I suspect that this randomness in vertex coordinates might be the reason why temperature values are not being assigned properly.

Any insights or suggestions on how to ensure that the vertex coordinates follow a specific order along the WALL boundary would be greatly appreciated.

Thank you for your time and assistance.
bgulzar22 is offline   Reply With Quote

Old   April 4, 2024, 15:20
Default
  #5
Senior Member
 
bigfoot
Join Date: Dec 2011
Location: Netherlands
Posts: 504
Rep Power: 17
bigfootedrockmidget is on a distinguished road
Quote:
Originally Posted by bgulzar22 View Post
I noticed that when I attempted to print the CoordX and CoordY values of vertices on the WALL boundary, they appear to be generated randomly and not following a particular order. Could you please shed some light on why this is happening? I suspect that this randomness in vertex coordinates might be the reason why temperature values are not being assigned properly.

Any insights or suggestions on how to ensure that the vertex coordinates follow a specific order along the WALL boundary would be greatly appreciated.

Thank you for your time and assistance.

It's just the order in which they are stored and read from the mesh file. For me it does not look random, though, it is almost exactly ordered according to the x-coordinate. In principle you should not expect any ordering, that is why you need to check the actual x,y coordinates of the vertices, and read the temperature values from file together with the spatial coordinates.
bigfootedrockmidget is offline   Reply With Quote

Reply

Tags
python code, python module, python script, python script error


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Ansys CFD-Post Application Error rushiCFD FLUENT 0 March 21, 2021 07:51
A question related to writing expression for (htc)Heat transfer coefficient Hamda CFX 11 April 17, 2020 00:57
Expert Parameters in CFX-pre ebrahem FLUENT 0 December 20, 2019 02:39
Problem in setting Boundary Condition Madhatter92 CFX 12 January 12, 2016 04:39
Question about bcdefw.f for wall temperature bc. Jimmy Siemens 10 March 18, 2008 15:28


All times are GMT -4. The time now is 13:11.