CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > Siemens > STAR-CCM+

Unicode and special characters issue in DesignManager

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 8, 2022, 01:29
Default Unicode and special characters issue in DesignManager
  #1
cwl
Senior Member
 
Chaotic Water
Join Date: Jul 2012
Location: Elgrin Fau
Posts: 436
Rep Power: 17
cwl is on a distinguished road
Hi everyone!

This time I've got the problem .. and the solution, - I hope it will help someone someday.


Software version:
  • Windows Server 2016
  • "Use Unicode UTF-8 for worldwide language support" is switched on in Region settings
  • STAR-CCM+ 2021.3


Problem description:
If there is a special symbol (like ³ or β) or a locale-specific symbols (Cyrillic for example) in the simulation (like Part name) or in path to the simulation or design manager project - design manager hangs up and Aborting it results in error like following:
Quote:
Error when deleting Task[9] : Unexpected result from Resource Manager command: tasks/9.
Called: tasks/9
Response Status Code: 500
Response reason: Internal Server Error
Response content: {"status": 500, "detail": "<UnicodeDecodeError> 'utf-8' codec can't decode byte 0xab in position 5307: invalid start byte"}

Reason:
When Star-CCM+ writes the .log-file ...\Design_Study\Design_1\Design_1.log encoded as 'cp1252', i.e. for example special character '«' (I had in Part's name Volume «Internal») is written down to file as 0xab (or \xab in Python notation).

In Python scripts that .log-file is open()'ed assuming the file is in unicode (utf-8), thus it expects that '«' to be written down as 0xc2 0xab (or [CODE]\xc2\xab[/I] in Python notation .. anyway it should be c2ab if you open the .log-file in hex editor. But it's not.


Solution:
The best solution would be to make STAR-CCM+ process just to write it's log encoded in utf-8.
STAR-CCM+ process is launched by Python script instance at line 603 of processmanagement.py as
Code:
  self._process = subprocess.Popen(command,
                                   stdout=self.outfile_w if self.outfile_w else None,
                                   stderr=subprocess.STDOUT,
                                   stdin=(subprocess.DEVNULL if self._use_shell else None),
                                   universal_newlines=True,
                                   startupinfo=None,
                                   cwd=self._cwd if self._cwd else None,
                                   shell=(self._use_shell if sys.platform == 'win32' else self._use_shell),
                                   creationflags=creationflags_value,
                                   start_new_session=(self._subprocess_in_new_session and sys.platform != 'win32'),
                                   env=child_env)
Honestly speaking yesterday was my first time with Python, so if I get things right - it should work after changing to:
Code:
  self._process = subprocess.Popen(command,
                                   stdout=self.outfile_w if self.outfile_w else None,
                                   stderr=subprocess.STDOUT,
                                   stdin=(subprocess.DEVNULL if self._use_shell else None),
                                   universal_newlines=True,
                                   startupinfo=None,
                                   cwd=self._cwd if self._cwd else None,
                                   shell=(self._use_shell if sys.platform == 'win32' else self._use_shell),
                                   creationflags=creationflags_value,
                                   start_new_session=(self._subprocess_in_new_session and sys.platform != 'win32'),
                                   env=child_env,
                                   encoding='utf-8')
But - no luck.


So, the workaround is - in Python-files
  • application.py in C:\Program Files\Siemens\16.06.008-R8\STAR-CCM+16.06.008-R8\star\lib\python\Lib\site-packages\resourcemanager\model\application.py
and
  • processmanagement.py in C:\Program Files\Siemens\16.06.008-R8\STAR-CCM+16.06.008-R8\star\lib\python\Lib\site-packages\starcommon\processmanagement.py

find every occurrence of call to 'open()' (like
Code:
with open(self.get_outpath(), 'at')
or
Code:
self._outfile_w = open(self.get_outpath(), 'w')
- and add
Quote:
, encoding='cp1252'
before the comma, so it would look like:
Code:
with open(self.get_outpath(), 'at', encoding='cp1252') as f:
Code:
self._outfile_w = open(self.get_outpath(), 'w', encoding='cp1252')

That solves the issue with the DesignManager and it runs ok.
At least - for me ...


Yet
Special characters like Cyrillic symbols (might affect special symbols in your language) in project path are written to .log-file as the same symbol '?' (0x3F):
Quote:
Starting local server: starccm+ -server ... -on ... -xdmprojectid ... -jobmanagerurl ... -taskid 3 -dmrunfile Design_1.mdxin -xencoded-session ...
...
Server::start -host ...
Loading: 01a - Project ??.sim
...
Project Name : ??100500
Study Name : Design Study
Design Name : Design 1
CWD : D:\Work\Project - ????\.mdxruntime\??100500_20220208082212\Design_St udy\Design_1
Output Dir : D:\Work\Project - ????\.mdxruntime\??100500_20220208082212\Design_St udy\Design_1\_out
...
Again - that does not break the DesignManager, but would be great to find a solution to that.


Any help/suggestions from anyone who has experience with Python more than I do are welcome.
cwl is offline   Reply With Quote

Reply


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



All times are GMT -4. The time now is 09:30.