Skip to content
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
wants to merge 37 commits into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
12d25ce
Update melcorCombinedInterface.py
mattdon Oct 18, 2022
e74717b
Delete MELCORdata.py
mattdon Oct 18, 2022
0fa7df7
Delete melcorInterface.py
mattdon Oct 18, 2022
33bc4ce
Delete melgenInterface.py
mattdon Oct 18, 2022
e0ead47
Update melcorCombinedInterface.py
mattdon Oct 18, 2022
9e98ecb
Update melcorCombinedInterface.py
mattdon Oct 28, 2022
446f280
Merge branch 'idaholab:devel' into New_MELCOR_Interface
mattdon Oct 28, 2022
9f398e0
Update test_melcor_interface.xml
mattdon Nov 2, 2022
49913b9
merge
mattdon Nov 11, 2022
6deb3ab
merge
mattdon Nov 11, 2022
216cb92
Merge branch 'devel' into mattdon/New_MELCOR_Interface
mandd Nov 17, 2022
081f5f6
Revert "merge"
wangcj05 Nov 17, 2022
5b1c43a
first cleaning of PR
mandd Nov 18, 2022
99e71a0
Merge branch 'devel' into mattdon/New_MELCOR_Interface
mandd Dec 15, 2022
8bcc76f
edits
mandd Jan 12, 2023
2c71868
Merge branch 'devel' into mattdon/New_MELCOR_Interface
mandd Jan 12, 2023
508d1a0
Merge remote-tracking branch 'origin/mattdon/New_MELCOR_Interface' in…
mandd Jan 16, 2023
d0b5a91
edit test files
mandd Jan 17, 2023
a569931
edit combinedInterface file
mandd Jan 17, 2023
4954399
added test files
mandd Jan 17, 2023
ad60e3a
missing test file
mandd Jan 17, 2023
9fdb226
fix for diego
Jan 18, 2023
5f2c16c
small edits
mandd Feb 15, 2023
879acc3
Merge remote-tracking branch 'origin/devel' into mattdon/New_MELCOR_I…
mandd Feb 17, 2023
3eb7f67
added edits from rome
mandd Feb 22, 2023
ab83307
edit file
mandd Feb 24, 2023
b065ddb
final files
mandd May 26, 2023
d8c1ae7
removed last file
mandd May 26, 2023
3108b58
Merge branch 'devel' into mattdon/New_MELCOR_Interface
aalfonsi May 27, 2023
e1ec0f5
removed whitespaces
aalfonsi May 27, 2023
65d3231
Update ravenframework/Models/PostProcessors/SubdomainBasicStatistics.py
aalfonsi May 27, 2023
e81ace2
fixed dictionary format
aalfonsi Jun 1, 2023
303b225
fixed dictionary format
aalfonsi Jun 1, 2023
d52231b
updated test
aalfonsi Jun 1, 2023
851e8df
final edits
mandd Jun 2, 2023
a5c4085
addressing comments
mandd Jun 23, 2023
d0d345c
addressing comments
mandd Sep 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
edit test files
  • Loading branch information
mandd committed Jan 17, 2023
commit d0b5a91fc280d330c7ed2a894e7716fccc372e10
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
@author: Matteo D'Onorio (Sapienza University of Rome)
Copy link
Collaborator

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

"""

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):
"""
Expand All @@ -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):
"""
Expand Down Expand Up @@ -141,15 +144,13 @@ def writeDict(self,filen,workDir):
@ In, workDir, str, current working directory
@ Out, None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please update the Out, 'dictionary' will be returned.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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):
Expand Down
116 changes: 116 additions & 0 deletions ravenframework/CodeInterfaceClasses/MELCOR/melcorTools.py
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:]
5 changes: 2 additions & 3 deletions tests/framework/CodeInterfaceTests/test_melcor_interface.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
<RunInfo>
<WorkingDir>MelcorInterface</WorkingDir>
<Sequence>testMelcor,dumpResults</Sequence>
<batchSize>1</batchSize>
</RunInfo>

<Files>
Expand All @@ -29,8 +28,8 @@

<Models>
<Code name="MELGEN" subType="Melcor">
<executable>MELCOR_2.2/bin/melcor</executable>
<preexec>MELCOR_2.2/bin/melgen</preexec>
<executable></executable>
<!--preexec>MELCOR_2.2/bin/melgen</preexec-->
<clargs arg="" extension=".inp" type="input"/>
<CodePlotFile>MELPTF.PTF</CodePlotFile>
<variables>CVH-P_1</variables>
Expand Down
1 change: 1 addition & 0 deletions tests/framework/CodeInterfaceTests/tests
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
output = 'GenericInterface/samples.xml GenericInterface/sample/1/testSubDirectory/dummy_file_for_subdirectory.dummy GenericInterface/sample/testSubDirectory/dummy_file_for_subdirectory.dummy'
csv = 'GenericInterface/samples.csv'
[../]

[./genericInterfaceParallel]
type = 'RavenFramework'
input = 'generic_parallel.xml'
Expand Down