-
Notifications
You must be signed in to change notification settings - Fork 137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mattdon/new melcor interface #2017
Open
mandd
wants to merge
37
commits into
devel
Choose a base branch
from
mattdon/New_MELCOR_Interface
base: devel
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
12d25ce
Update melcorCombinedInterface.py
mattdon e74717b
Delete MELCORdata.py
mattdon 0fa7df7
Delete melcorInterface.py
mattdon 33bc4ce
Delete melgenInterface.py
mattdon e0ead47
Update melcorCombinedInterface.py
mattdon 9e98ecb
Update melcorCombinedInterface.py
mattdon 446f280
Merge branch 'idaholab:devel' into New_MELCOR_Interface
mattdon 9f398e0
Update test_melcor_interface.xml
mattdon 49913b9
merge
mattdon 6deb3ab
merge
mattdon 216cb92
Merge branch 'devel' into mattdon/New_MELCOR_Interface
mandd 081f5f6
Revert "merge"
wangcj05 5b1c43a
first cleaning of PR
mandd 99e71a0
Merge branch 'devel' into mattdon/New_MELCOR_Interface
mandd 8bcc76f
edits
mandd 2c71868
Merge branch 'devel' into mattdon/New_MELCOR_Interface
mandd 508d1a0
Merge remote-tracking branch 'origin/mattdon/New_MELCOR_Interface' in…
mandd d0b5a91
edit test files
mandd a569931
edit combinedInterface file
mandd 4954399
added test files
mandd ad60e3a
missing test file
mandd 9fdb226
fix for diego
5f2c16c
small edits
mandd 879acc3
Merge remote-tracking branch 'origin/devel' into mattdon/New_MELCOR_I…
mandd 3eb7f67
added edits from rome
mandd ab83307
edit file
mandd b065ddb
final files
mandd d8c1ae7
removed last file
mandd 3108b58
Merge branch 'devel' into mattdon/New_MELCOR_Interface
aalfonsi e1ec0f5
removed whitespaces
aalfonsi 65d3231
Update ravenframework/Models/PostProcessors/SubdomainBasicStatistics.py
aalfonsi e81ace2
fixed dictionary format
aalfonsi 303b225
fixed dictionary format
aalfonsi d52231b
updated test
aalfonsi 851e8df
final edits
mandd a5c4085
addressing comments
mandd d0d345c
addressing comments
mandd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
edit test files
- Loading branch information
commit d0b5a91fc280d330c7ed2a894e7716fccc372e10
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,12 +16,12 @@ | |
@author: Matteo D'Onorio (Sapienza University of Rome) | ||
""" | ||
|
||
import sys | ||
import os | ||
from . import melcorTools | ||
from ravenframework.CodeInterfaceBaseClass import CodeInterfaceBase | ||
from ..Generic import GenericParser | ||
import pandas as pd | ||
import time | ||
|
||
|
||
class Melcor(CodeInterfaceBase): | ||
""" | ||
|
@@ -42,16 +42,19 @@ def _readMoreXML(self,xmlNode): | |
melNode = xmlNode.find('MelcorOutput') | ||
varNode = xmlNode.find('variables') | ||
plotNode = xmlNode.find('CodePlotFile') | ||
|
||
if varNode is None: | ||
raise IOError("Melcor variables not found, define variables to print") | ||
if plotNode is None: | ||
raise IOError("Please define the name of the MELCOR plot file in the CodePlotFile xml node") | ||
if melNode is None: | ||
raise IOError("Please enter MELCOR message file name") | ||
|
||
self.VarList = [var.strip() for var in varNode.text.split("$,")] | ||
self.MelcorPlotFile = [var.strip() for var in plotNode.text.split(",")][0] | ||
self.melcorOutFile = [var.strip() for var in melNode.text.split(",")][0] | ||
return self.VarList,self.MelcorPlotFile,self.melcorOutFile | ||
|
||
return self.VarList, self.MelcorPlotFile, self.melcorOutFile | ||
|
||
def findInps(self,currentInputFiles): | ||
""" | ||
|
@@ -141,15 +144,13 @@ def writeDict(self,filen,workDir): | |
@ In, workDir, str, current working directory | ||
@ Out, None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please update the Out, 'dictionary' will be returned. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added |
||
""" | ||
from melcorTools import MCRBin | ||
|
||
fileDir = os.path.join(workDir,self.MelcorPlotFile) | ||
Time,Data,VarUdm = MCRBin(fileDir,self.VarList) | ||
Time,Data,VarUdm = melcorTools.MCRBin(fileDir,self.VarList) | ||
dfTime = pd.DataFrame(Time, columns= ["Time"]) | ||
dfData = pd.DataFrame(Data, columns = self.VarList) | ||
df = pd.concat([dfTime, dfData], axis=1, join='inner') | ||
df.drop_duplicates(subset="Time",keep='first',inplace=True) | ||
dictionary=df.to_dict() | ||
dictionary = df.to_dict() | ||
return dictionary | ||
|
||
def finalizeCodeOutput(self,command,output,workingDir): | ||
|
116 changes: 116 additions & 0 deletions
116
ravenframework/CodeInterfaceClasses/MELCOR/melcorTools.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
""" | ||
MELCOR FORMAT SUPPORT MODULE | ||
Created on March 28, 2017 | ||
Last update on October 14, 2022 | ||
@authors: | ||
Matteo D'Onorio (University of Rome La Sapienza) | ||
Paolo Balestra (University of Rome La Sapienza) | ||
""" | ||
from struct import unpack | ||
import numpy as np | ||
from collections import Counter | ||
|
||
def MCRBin(fileDir, VarSrch): | ||
""" | ||
This method is called to collect the variables to be used in the postprocess | ||
@ In, fileDirectory, string, the file directory. This is the directory of the MELCOR plot file | ||
@ In, variableSearch, list, list of variables to be collected | ||
@ Out, Data, tuple (numpy.ndarray,numpy.ndarray,numpy.ndarray), this contains the extracted data for each declare variable | ||
""" | ||
HdrList = [] | ||
BlkLenBef = [] | ||
BlkLenAft = [] | ||
DataPos=[] | ||
cntr = 0 | ||
Var_dict = {} | ||
with open(fileDir, 'rb') as bf: | ||
while True: | ||
BlkLenBefSlave = bf.read(4) | ||
if not BlkLenBefSlave: | ||
break | ||
BlkLenBef.append(unpack('I', BlkLenBefSlave)[0]) | ||
if BlkLenBef[cntr] == 4: | ||
HdrList.append(str(unpack('4s', bf.read(4))[0], 'utf-8')) | ||
elif HdrList[cntr - 1] == 'TITL': | ||
probemTitle=str(unpack('%d' % BlkLenBef[cntr] + 's', bf.read(BlkLenBef[cntr]))[0], 'utf-8') | ||
HdrList.append([]) | ||
elif HdrList[cntr - 1] == 'KEY ': | ||
VarName=unpack('2I', bf.read(8)) | ||
HdrList.append([]) | ||
elif HdrList[cntr - 2] == 'KEY ': | ||
a = BlkLenBef[-1]/VarName[0] | ||
stringa=str(int(a))+"s" | ||
VarNam=[str(i, 'utf-8') for i in unpack(stringa * VarName[0], bf.read(BlkLenBef[cntr]))] | ||
HdrList.append([]) | ||
elif HdrList[cntr - 3] == 'KEY ': | ||
VarPos=unpack('%d' % VarName[0] + 'I', bf.read(BlkLenBef[cntr])) | ||
HdrList.append([]) | ||
elif HdrList[cntr - 4] == 'KEY ': | ||
VarUdm=[str(i, 'utf-8') for i in unpack('16s' * VarName[0], bf.read(BlkLenBef[cntr]))] | ||
HdrList.append([]) | ||
elif HdrList[cntr - 5] == 'KEY ': | ||
VarNum=unpack('%d' % VarName[1] + 'I', bf.read(BlkLenBef[cntr])) | ||
VarNameFull=[] | ||
VarUdmFull=[] | ||
NamCntr=0 | ||
VarPos = VarPos + (VarName[1]+1,) | ||
VarSrchPos=[0] | ||
itm_x_Var = [] | ||
for k in range(0,len(VarNam)): | ||
itm_x_Var.append(VarPos[k+1]-VarPos[k]) | ||
if len(itm_x_Var) != len(VarNam): | ||
print("Number of variables different from number of items of offset array") | ||
print(itm_x_Var) | ||
print(len(VarNam)) | ||
break | ||
Items_Tot = sum(itm_x_Var) | ||
if Items_Tot != len(VarNum): | ||
print("Somma degli item da associare ad ogni variabile è diversa dalla somma di tutti gli items id VarNum") | ||
VarNum_Cntr =0 | ||
Var_dict = {} | ||
for i,Var in enumerate(VarNam): | ||
NumOfItems = itm_x_Var[i] | ||
end = VarNum_Cntr + NumOfItems | ||
Var_dict[Var] = list(VarNum[VarNum_Cntr:end]) | ||
VarNum_Cntr = VarNum_Cntr+NumOfItems | ||
for key in Var_dict.keys(): | ||
for element in Var_dict[key]: | ||
if element == 0: | ||
VarNameFull.append(str(key).strip()) | ||
else: | ||
VarNameFull.append(key.strip()+'_%d' %element) | ||
for i,item in enumerate(itm_x_Var): | ||
for k in range(0,item): | ||
VarUdmFull.append(VarUdm[i].strip()) | ||
VarNameFull=['TIME','CPU','DT','UNKN03']+VarNameFull | ||
VarUdmFull=['sec','','','']+VarUdmFull | ||
for Nam in VarSrch: | ||
VarSrchPos.append(VarNameFull.index(Nam.strip())) | ||
VarUdmFull=[VarUdmFull[i] for i in VarSrchPos] | ||
SwapPosVarSrch=sorted(range(len(VarSrchPos)), key=lambda k: VarSrchPos[k]) | ||
SwapPosVarSrch=sorted(range(len(SwapPosVarSrch)), key=lambda k: SwapPosVarSrch[k]) | ||
VarSrchPos.sort() | ||
VarSrchPos.append(VarName[1]+4) | ||
HdrList.append([]) | ||
elif HdrList[cntr - 1] == '.TR/': | ||
DataPos.append(bf.tell()) | ||
bf.seek(BlkLenBef[cntr], 1) | ||
HdrList.append([]) | ||
else: | ||
HdrList.append([]) | ||
BlkLenAft.append(unpack('I', bf.read(4))[0]) | ||
|
||
cntr +=1 | ||
|
||
data=np.empty([len(DataPos), len(VarSrch)+1])*np.nan | ||
|
||
with open(fileDir, 'rb') as bf: | ||
for i,Pos in enumerate(DataPos): | ||
bf.seek(Pos, 0) | ||
for j in range(len(VarSrchPos)-1): | ||
data[i,j]=unpack('f', bf.read(4))[0] | ||
bf.seek((VarSrchPos[j+1]-VarSrchPos[j])*4-4, 1) | ||
|
||
data=data[:,SwapPosVarSrch] | ||
|
||
return data[:,0],data[:,1:],VarUdmFull[1:] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want to add your name and Andrea name here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added