Commit 792dba47 authored by Jonathan Lambrechts's avatar Jonathan Lambrechts
Browse files

rewrite readMsh and rename to readIdx

parent e2e4b25f
Pipeline #1172 passed with stage
in 27 minutes and 33 seconds
...@@ -66,7 +66,7 @@ groups.splitGroupsByPhysicalTag() ...@@ -66,7 +66,7 @@ groups.splitGroupsByPhysicalTag()
# Bathymetry # Bathymetry
bathDC = dgDofContainer(groups, 1) bathDC = dgDofContainer(groups, 1)
bathDC.readMsh("Bath/congoCoast-labels-clean_bath_smooth/congoCoast-labels-clean_bath_smooth.idx") bathDC.importIdx("Bath/congoCoast-labels-clean_bath_smooth/congoCoast-labels-clean_bath_smooth.idx")
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
#------- SET UP DIFFUSIVITY ---------------------------------------------------- #------- SET UP DIFFUSIVITY ----------------------------------------------------
...@@ -190,7 +190,7 @@ for n in range(1,LP_TotIter+1): ...@@ -190,7 +190,7 @@ for n in range(1,LP_TotIter+1):
print('Problem in loadedSolutions!') print('Problem in loadedSolutions!')
else: else:
print('-> simSolution not already loaded. Loading it from file. File is (gbr-%06d'%( iterNumberWanted )+').') print('-> simSolution not already loaded. Loading it from file. File is (gbr-%06d'%( iterNumberWanted )+').')
simSolution.readMsh('output/idx/idx-%06d'%( iterNumberWanted / simExportGap )+'.idx') simSolution.importIdx('output/idx/idx-%06d'%( iterNumberWanted / simExportGap )+'.idx')
loadedSolutions[0] = iterNumberWanted loadedSolutions[0] = iterNumberWanted
else: else:
...@@ -217,7 +217,7 @@ for n in range(1,LP_TotIter+1): ...@@ -217,7 +217,7 @@ for n in range(1,LP_TotIter+1):
else: else:
print('-> simSolutionUnder not already loaded. Loading it from file. l is:', l, '. File is (gbr-%06d'%( iterNumberWanted-l )+').') print('-> simSolutionUnder not already loaded. Loading it from file. l is:', l, '. File is (gbr-%06d'%( iterNumberWanted-l )+').')
t_solUnder = simStartTime + float(iterNumberWanted-l)*simDt t_solUnder = simStartTime + float(iterNumberWanted-l)*simDt
simSolutionUnder.readMsh('output/idx/idx-%06d'%( (iterNumberWanted-l) / simExportGap )+'.idx') simSolutionUnder.importIdx('output/idx/idx-%06d'%( (iterNumberWanted-l) / simExportGap )+'.idx')
loadedSolutions[2] = iterNumberWanted-l loadedSolutions[2] = iterNumberWanted-l
m=0 m=0
...@@ -242,7 +242,7 @@ for n in range(1,LP_TotIter+1): ...@@ -242,7 +242,7 @@ for n in range(1,LP_TotIter+1):
else: else:
print('-> simSolutionOver not already loaded. Loading it from file. m is:', m, '. File is (gbr-%06d'%( iterNumberWanted+m )+').') print('-> simSolutionOver not already loaded. Loading it from file. m is:', m, '. File is (gbr-%06d'%( iterNumberWanted+m )+').')
t_solOver = simStartTime + float(iterNumberWanted+m)*simDt t_solOver = simStartTime + float(iterNumberWanted+m)*simDt
simSolutionOver.readMsh('output/idx/idx-%06d'%( (iterNumberWanted+m) / simExportGap )+'.idx') simSolutionOver.importIdx('output/idx/idx-%06d'%( (iterNumberWanted+m) / simExportGap )+'.idx')
loadedSolutions[1] = iterNumberWanted+m loadedSolutions[1] = iterNumberWanted+m
scaleFactor = 1.0 - (t-t_solUnder)/(t_solOver-t_solUnder) scaleFactor = 1.0 - (t-t_solUnder)/(t_solOver-t_solUnder)
......
...@@ -136,7 +136,7 @@ def partitionMultirate(fileName, bathFileName, nMRGroups, mRAlgo, nPart, outputF ...@@ -136,7 +136,7 @@ def partitionMultirate(fileName, bathFileName, nMRGroups, mRAlgo, nPart, outputF
UTMtoLonLatDegrees = functionNumpy(3, UTMtoLonLatDegrees_func, [UTM]) UTMtoLonLatDegrees = functionNumpy(3, UTMtoLonLatDegrees_func, [UTM])
#lonLatDegrees = functionC("./lib_congo.so","UTMtoLonLatDegrees",3,[UTM]) #lonLatDegrees = functionC("./lib_congo.so","UTMtoLonLatDegrees",3,[UTM])
bath = dgDofContainer(groups, 1); bath = dgDofContainer(groups, 1);
bath.readMsh(bathFileName) bath.importIdx(bathFileName)
claw = dgConservationLawShallowWater2d() claw = dgConservationLawShallowWater2d()
solution = dgDofContainer(groups, claw.getNbFields()) solution = dgDofContainer(groups, claw.getNbFields())
Cd = functionNumpy(1, bottomDrag_const_n0235, [solution.getFunction(), bath.getFunction()]) Cd = functionNumpy(1, bottomDrag_const_n0235, [solution.getFunction(), bath.getFunction()])
...@@ -221,7 +221,7 @@ if Msg.GetCommRank() == 0 : ...@@ -221,7 +221,7 @@ if Msg.GetCommRank() == 0 :
groups = dgGroupCollection(model, 2, 1, True) groups = dgGroupCollection(model, 2, 1, True)
# Bathymetry of the model. # Bathymetry of the model.
bathDof = dgDofContainer(groups, 1) bathDof = dgDofContainer(groups, 1)
bathDof.readMsh("Bath/"+param.fileName+"_bath_smooth/"+param.fileName+"_bath_smooth.idx") bathDof.importIdx("Bath/"+param.fileName+"_bath_smooth/"+param.fileName+"_bath_smooth.idx")
# Associate bathymetry to every mesh node. # Associate bathymetry to every mesh node.
globNodeId2Bath = {} globNodeId2Bath = {}
......
...@@ -88,7 +88,7 @@ groups.splitGroupsByPhysicalTag() ...@@ -88,7 +88,7 @@ groups.splitGroupsByPhysicalTag()
# Grouped parameters. # Grouped parameters.
bath = dgDofContainer(groups, 1) bath = dgDofContainer(groups, 1)
bath.readMsh("Bath/"+param.fileName+"_bath_smooth/"+param.fileName+"_bath_smooth.idx") bath.importIdx("Bath/"+param.fileName+"_bath_smooth/"+param.fileName+"_bath_smooth.idx")
bath_PC = functionPrecomputed(groups, 3, 1) bath_PC = functionPrecomputed(groups, 3, 1)
bath_PC.compute(bath.getFunction()) bath_PC.compute(bath.getFunction())
bathGradient_PC = functionPrecomputed(groups, 3, 3) bathGradient_PC = functionPrecomputed(groups, 3, 3)
...@@ -104,7 +104,7 @@ solution = dgDofContainer(groups, 3) ...@@ -104,7 +104,7 @@ solution = dgDofContainer(groups, 3)
start = 0 start = 0
if (param.realTi != param.Ti): if (param.realTi != param.Ti):
start = int((t-param.realTi)/(dt*param.export)) start = int((t-param.realTi)/(dt*param.export))
solution.readMsh(param.outputDir+"/idx/idx-"+str(start).zfill(6)+".idx") solution.importIdx(param.outputDir+"/idx/idx-"+str(start).zfill(6)+".idx")
else: else:
solution.setAll(0.) solution.setAll(0.)
......
...@@ -18,7 +18,7 @@ bath = dgDofContainer(groups, 1); ...@@ -18,7 +18,7 @@ bath = dgDofContainer(groups, 1);
filename = "world" filename = "world"
outputDir = "bath" outputDir = "bath"
bathname= outputDir+"/"+filename+"_bath_smooth"+"/"+filename+"_bath_smooth.idx" bathname= outputDir+"/"+filename+"_bath_smooth"+"/"+filename+"_bath_smooth.idx"
bath.readMsh(bathname) bath.importIdx(bathname)
def getLayers (x, y, iGroup, iElement, iVertex) : def getLayers (x, y, iGroup, iElement, iVertex) :
h = bath.getGroupProxy(iGroup)(iVertex, iElement); h = bath.getGroupProxy(iGroup)(iVertex, iElement);
MinDiff = 1e10 MinDiff = 1e10
......
...@@ -142,7 +142,7 @@ gRef = GModel() ...@@ -142,7 +142,7 @@ gRef = GModel()
gRef.load("output/"+FileName+"-ref-%i.msh" % ref) gRef.load("output/"+FileName+"-ref-%i.msh" % ref)
groupsRef = dgGroupCollection(gRef, 2, 1) groupsRef = dgGroupCollection(gRef, 2, 1)
dofRef = dgDofContainer(groupsRef, 3) dofRef = dgDofContainer(groupsRef, 3)
dofRef.readMsh("output/dof-ref-%i-end/dof-ref-%i-end.idx" % (ref, ref)) dofRef.importIdx("output/dof-ref-%i-end/dof-ref-%i-end.idx" % (ref, ref))
XYZRef = groupsRef.getFunctionCoordinates() XYZRef = groupsRef.getFunctionCoordinates()
solRef = dofRef.getFunction() solRef = dofRef.getFunction()
...@@ -163,7 +163,7 @@ for i in range(0, nstage+1): ...@@ -163,7 +163,7 @@ for i in range(0, nstage+1):
g.load("output/"+FileName+"-%i.msh" % i) g.load("output/"+FileName+"-%i.msh" % i)
groups = dgGroupCollection(g, 2, 1) groups = dgGroupCollection(g, 2, 1)
dof = dgDofContainer(groups, 3) dof = dgDofContainer(groups, 3)
dof.readMsh("output/dof-%i-end/dof-%i-end.idx" % (i, i)) dof.importIdx("output/dof-%i-end/dof-%i-end.idx" % (i, i))
evaluator = dgFunctionEvaluator(groups, dof.getFunction()) evaluator = dgFunctionEvaluator(groups, dof.getFunction())
fsol = evaluator.newFunction(XYZRef) fsol = evaluator.newFunction(XYZRef)
......
...@@ -58,7 +58,7 @@ gRef = GModel() ...@@ -58,7 +58,7 @@ gRef = GModel()
gRef.load("output/square-%i.msh" % nstage) gRef.load("output/square-%i.msh" % nstage)
groupsRef = dgGroupCollection(gRef, 2, 1) groupsRef = dgGroupCollection(gRef, 2, 1)
dofRef = dgDofContainer(groupsRef, 3) dofRef = dgDofContainer(groupsRef, 3)
dofRef.readMsh("output/dof-%i-end/dof-%i-end.idx" % (nstage, nstage)) dofRef.importIdx("output/dof-%i-end/dof-%i-end.idx" % (nstage, nstage))
XYZRef = groupsRef.getFunctionCoordinates() XYZRef = groupsRef.getFunctionCoordinates()
solRef = dofRef.getFunction() solRef = dofRef.getFunction()
...@@ -75,7 +75,7 @@ for i in range(0, nstage): ...@@ -75,7 +75,7 @@ for i in range(0, nstage):
g.load("output/square-%i.msh" % i) g.load("output/square-%i.msh" % i)
groups = dgGroupCollection(g, 2, 1) groups = dgGroupCollection(g, 2, 1)
dof = dgDofContainer(groups, 3) dof = dgDofContainer(groups, 3)
dof.readMsh("output/dof-%i-end/dof-%i-end.idx" % (i, i)) dof.importIdx("output/dof-%i-end/dof-%i-end.idx" % (i, i))
evaluator = dgFunctionEvaluator(groups, dof.getFunction()) evaluator = dgFunctionEvaluator(groups, dof.getFunction())
fsol = evaluator.newFunction(XYZRef) fsol = evaluator.newFunction(XYZRef)
......
...@@ -92,7 +92,7 @@ def process(name) : ...@@ -92,7 +92,7 @@ def process(name) :
model.load(mesh1) model.load(mesh1)
groups = dgGroupCollection(model, 2, 1, True) groups = dgGroupCollection(model, 2, 1, True)
bathDof = dgDofContainer(groups, 1) bathDof = dgDofContainer(groups, 1)
bathDof.readMsh("./bathSmooth/bathSmooth.idx") bathDof.importIdx("./bathSmooth/bathSmooth.idx")
globNodeId2Bath = {} globNodeId2Bath = {}
dataProx = fullMatrixDouble() dataProx = fullMatrixDouble()
......
...@@ -132,13 +132,13 @@ for ifig,export_count in enumerate(export_counts) : ...@@ -132,13 +132,13 @@ for ifig,export_count in enumerate(export_counts) :
SFunc = SDof.getFunction() SFunc = SDof.getFunction()
uvFunc = uvDof.getFunction() uvFunc = uvDof.getFunction()
#etaDof.readMsh( idxDir + 'eta2d/'+ 'eta2d'+istr+'.idx') #etaDof.importIdx( idxDir + 'eta2d/'+ 'eta2d'+istr+'.idx')
#print 'Reading '+idxDir + 'uv/'+ 'uv'+istr+'.idx' #print 'Reading '+idxDir + 'uv/'+ 'uv'+istr+'.idx'
#SDof.readMsh( idxDir + 'S/'+ 'S'+istr+'.idx') #SDof.importIdx( idxDir + 'S/'+ 'S'+istr+'.idx')
#uvDof.readMsh( idxDir + 'uv/'+ 'uv'+istr+'.idx') #uvDof.importIdx( idxDir + 'uv/'+ 'uv'+istr+'.idx')
print 'Reading '+idxDir + 'uv'+istr+'.idx' print 'Reading '+idxDir + 'uv'+istr+'.idx'
SDof.readMsh( idxDir + 'S'+istr+'.idx') SDof.importIdx( idxDir + 'S'+istr+'.idx')
uvDof.readMsh( idxDir + 'uv'+istr+'.idx') uvDof.importIdx( idxDir + 'uv'+istr+'.idx')
dgDCMap = dataCacheMap(dataCacheMap.POINT_MODE, groups) dgDCMap = dataCacheMap(dataCacheMap.POINT_MODE, groups)
SCache = dgDCMap.get(SFunc) SCache = dgDCMap.get(SFunc)
......
...@@ -100,14 +100,14 @@ if generateData : ...@@ -100,14 +100,14 @@ if generateData :
for i,export_count in enumerate(export_counts) : for i,export_count in enumerate(export_counts) :
istr = "_{0:05}".format(export_count) istr = "_{0:05}".format(export_count)
print 'Reading '+idxDir + 'nn/'+ 'nn'+istr+'.idx' print 'Reading '+idxDir + 'nn/'+ 'nn'+istr+'.idx'
#etaDof.readMsh( idxDir + 'eta2d/'+ 'eta2d'+istr+'.idx') #etaDof.importIdx( idxDir + 'eta2d/'+ 'eta2d'+istr+'.idx')
#nnDof.readMsh( idxDir + 'S/'+ 'S'+istr+'.idx') #nnDof.importIdx( idxDir + 'S/'+ 'S'+istr+'.idx')
#uvDof.readMsh( idxDir + 'uv/'+ 'uv'+istr+'.idx') #uvDof.importIdx( idxDir + 'uv/'+ 'uv'+istr+'.idx')
[time, step] = etaDof.readMsh( idxDir + 'eta2d'+istr+'.idx') [time, step] = etaDof.importIdx( idxDir + 'eta2d'+istr+'.idx')
[time, step] = nnDof.readMsh( idxDir + 'nn'+istr+'.idx') [time, step] = nnDof.importIdx( idxDir + 'nn'+istr+'.idx')
[time, step] = ssDof.readMsh( idxDir + 'ss'+istr+'.idx') [time, step] = ssDof.importIdx( idxDir + 'ss'+istr+'.idx')
[time, step] = uvDof.readMsh( idxDir + 'uv'+istr+'.idx') [time, step] = uvDof.importIdx( idxDir + 'uv'+istr+'.idx')
[time, step] = SDof.readMsh( idxDir + 'S'+istr+'.idx') [time, step] = SDof.importIdx( idxDir + 'S'+istr+'.idx')
dgCG3d.apply(nnDof,nnDof) dgCG3d.apply(nnDof,nnDof)
dgCG3d.apply(ssDof,ssDof) dgCG3d.apply(ssDof,ssDof)
nnDof.exportMsh(dataDir+'/nnCG'+istr,time,export_count) nnDof.exportMsh(dataDir+'/nnCG'+istr,time,export_count)
......
...@@ -88,12 +88,12 @@ if generateData : ...@@ -88,12 +88,12 @@ if generateData :
for i,export_count in enumerate(export_counts) : for i,export_count in enumerate(export_counts) :
istr = "_{0:05}".format(export_count) istr = "_{0:05}".format(export_count)
print 'Reading '+idxDir + 'uv/'+ 'uv'+istr+'.idx' print 'Reading '+idxDir + 'uv/'+ 'uv'+istr+'.idx'
#etaDof.readMsh( idxDir + 'eta2d/'+ 'eta2d'+istr+'.idx') #etaDof.importIdx( idxDir + 'eta2d/'+ 'eta2d'+istr+'.idx')
#SDof.readMsh( idxDir + 'S/'+ 'S'+istr+'.idx') #SDof.importIdx( idxDir + 'S/'+ 'S'+istr+'.idx')
#uvDof.readMsh( idxDir + 'uv/'+ 'uv'+istr+'.idx') #uvDof.importIdx( idxDir + 'uv/'+ 'uv'+istr+'.idx')
etaDof.readMsh( idxDir + 'eta2d'+istr+'.idx') etaDof.importIdx( idxDir + 'eta2d'+istr+'.idx')
SDof.readMsh( idxDir + 'S'+istr+'.idx') SDof.importIdx( idxDir + 'S'+istr+'.idx')
uvDof.readMsh( idxDir + 'uv'+istr+'.idx') uvDof.importIdx( idxDir + 'uv'+istr+'.idx')
dgDCMap2d.setPoint(groups2d,x,y,0) dgDCMap2d.setPoint(groups2d,x,y,0)
eta = etaCache.get()(0,0) eta = etaCache.get()(0,0)
zs = linspace(zMin,eta,nZ) zs = linspace(zMin,eta,nZ)
......
...@@ -66,8 +66,8 @@ istr = "_{0:05}".format(export_count) ...@@ -66,8 +66,8 @@ istr = "_{0:05}".format(export_count)
#tkeDof.importMsh( odir + 'tke' + istr) #tkeDof.importMsh( odir + 'tke' + istr)
#epsDof.importMsh( odir + 'eps' + istr) #epsDof.importMsh( odir + 'eps' + istr)
#lDof.importMsh( odir + 'l' + istr) #lDof.importMsh( odir + 'l' + istr)
etaDof.readMsh( idxDir + 'eta2d'+istr+'.idx') etaDof.importIdx( idxDir + 'eta2d'+istr+'.idx')
SDof.readMsh( idxDir + 'S'+istr+'.idx') SDof.importIdx( idxDir + 'S'+istr+'.idx')
def bathFunc(x) : def bathFunc(x) :
return 10*(1.-x/50000.)/2.0 + 5*(1.+x/50000.)/2.0 return 10*(1.-x/50000.)/2.0 + 5*(1.+x/50000.)/2.0
......
...@@ -95,10 +95,10 @@ tkeCache = dgDCMap.get(tkeFunc) ...@@ -95,10 +95,10 @@ tkeCache = dgDCMap.get(tkeFunc)
for export_count in export_counts : for export_count in export_counts :
istr = "_{0:05}".format(export_count) istr = "_{0:05}".format(export_count)
etaDof.readMsh( idxDir + 'eta2d'+istr+'.idx') etaDof.importIdx( idxDir + 'eta2d'+istr+'.idx')
SDof.readMsh( idxDir + 'S'+istr+'.idx') SDof.importIdx( idxDir + 'S'+istr+'.idx')
#tkeDof.readMsh( idxDir + 'tke'+istr+'.idx') #tkeDof.importIdx( idxDir + 'tke'+istr+'.idx')
uvDof.readMsh( idxDir + 'uv'+istr+'.idx') uvDof.importIdx( idxDir + 'uv'+istr+'.idx')
# get eta value (depends onthe mesh!) # get eta value (depends onthe mesh!)
for i,x in enumerate(xs) : for i,x in enumerate(xs) :
......
...@@ -67,9 +67,9 @@ if continue_time: ...@@ -67,9 +67,9 @@ if continue_time:
#sol_old.setFieldName(0, 'eta_old') #sol_old.setFieldName(0, 'eta_old')
#sol_old.setFieldName(0, 'u_old') #sol_old.setFieldName(0, 'u_old')
#sol_old.setFieldName(0, 'v_old') #sol_old.setFieldName(0, 'v_old')
#sol_old.readMsh(path_output + "/idx/idx-" + t_start + "_COMP_0.idx",0,0) #sol_old.importIdx(path_output + "/idx/idx-" + t_start + "_COMP_0.idx",0,0)
#sol_old.readMsh(path_output + "/idx/idx-" + t_start + "_COMP_1.idx",1,1) #sol_old.importIdx(path_output + "/idx/idx-" + t_start + "_COMP_1.idx",1,1)
#sol_old.readMsh(path_output + "/idx/idx-" + t_start + "_COMP_2.idx",2,2) #sol_old.importIdx(path_output + "/idx/idx-" + t_start + "_COMP_2.idx",2,2)
else: else:
...@@ -89,7 +89,7 @@ else: ...@@ -89,7 +89,7 @@ else:
bath = dgDofContainer(groups, 1) bath = dgDofContainer(groups, 1)
bath.setFieldName(0, 'bath') bath.setFieldName(0, 'bath')
bath.readMsh(path_mesh + "B" + bathy_acc + "_bath_part/" + domain + mesh_acc + "B" + bathy_acc + "_bath_part.idx") bath.importIdx(path_mesh + "B" + bathy_acc + "_bath_part/" + domain + mesh_acc + "B" + bathy_acc + "_bath_part.idx")
bath_PC = functionPrecomputed(groups, 3, 1) bath_PC = functionPrecomputed(groups, 3, 1)
bath_PC.compute(bath.getFunction()) bath_PC.compute(bath.getFunction())
......
...@@ -73,7 +73,7 @@ solution.setFieldName(2, 'v') ...@@ -73,7 +73,7 @@ solution.setFieldName(2, 'v')
bath = dgDofContainer(groups, 1) bath = dgDofContainer(groups, 1)
bath.setFieldName(0, 'bath') bath.setFieldName(0, 'bath')
bath.readMsh(path_mesh + "B" + bathy_acc + "_bath_part/" + domain + mesh_acc + "B" + bathy_acc + "_bath_part.idx") bath.importIdx(path_mesh + "B" + bathy_acc + "_bath_part/" + domain + mesh_acc + "B" + bathy_acc + "_bath_part.idx")
bath_PC = functionPrecomputed(groups, 3, 1) bath_PC = functionPrecomputed(groups, 3, 1)
bath_PC.compute(bath.getFunction()) bath_PC.compute(bath.getFunction())
......
...@@ -1016,7 +1016,7 @@ class Loop: ...@@ -1016,7 +1016,7 @@ class Loop:
index = self._index_start+self._n_iter_offline%self._n_index_per_period index = self._index_start+self._n_iter_offline%self._n_index_per_period
else: else:
index = self._n_iter_offline index = self._n_iter_offline
i._hydro_sol_dof.readMsh(i._datafile+"-%06d_%06d.idx" %(index,j)) i._hydro_sol_dof.importIdx(i._datafile+"-%06d_%06d.idx" %(index,j))
i._hydro_sol_dof.scatter() i._hydro_sol_dof.scatter()
newton_converged = i._temporal_solver.subiterate(i._solution, self._dt, self._time) newton_converged = i._temporal_solver.subiterate(i._solution, self._dt, self._time)
if not newton_converged: if not newton_converged:
...@@ -1026,7 +1026,7 @@ class Loop: ...@@ -1026,7 +1026,7 @@ class Loop:
index = self._index_start+self._n_iter_offline%self._n_index_per_period index = self._index_start+self._n_iter_offline%self._n_index_per_period
else: else:
index = self._n_iter_offline index = self._n_iter_offline
i._hydro_sol_dof.readMsh(i._datafile+"-%06d_%06d.idx" %(index,j)) i._hydro_sol_dof.importIdx(i._datafile+"-%06d_%06d.idx" %(index,j))
i._hydro_sol_dof.scatter() i._hydro_sol_dof.scatter()
for e in self._export_dofs_full: for e in self._export_dofs_full:
e[0].exportIdxSubTimeStep(self._index_exporter_full, j, self._time - e[1]) e[0].exportIdxSubTimeStep(self._index_exporter_full, j, self._time - e[1])
......
...@@ -149,7 +149,7 @@ def _load(dof, data_file): ...@@ -149,7 +149,7 @@ def _load(dof, data_file):
elif (file_name[-4:] == ".msh"): elif (file_name[-4:] == ".msh"):
dof.importMsh(file_name) dof.importMsh(file_name)
elif (file_name[-4:] == ".idx"): elif (file_name[-4:] == ".idx"):
dof.readMsh(file_name) dof.importIdx(file_name)
else: else:
dgpy.Msg.Fatal(file_name + " must have one of the following extensions: '.idx', '.msh', '.nc'") dgpy.Msg.Fatal(file_name + " must have one of the following extensions: '.idx', '.msh', '.nc'")
dof.scatter(False) dof.scatter(False)
...@@ -176,7 +176,7 @@ def _load_function(data_file, groups): ...@@ -176,7 +176,7 @@ def _load_function(data_file, groups):
return f return f
elif (file_name[-4:] == ".idx"): elif (file_name[-4:] == ".idx"):
dof = dgpy.dgDofContainer(groups,1) dof = dgpy.dgDofContainer(groups,1)
dof.readMsh(file_name) dof.importIdx(file_name)
dof.scatter() dof.scatter()
f = dof.getFunction() f = dof.getFunction()
f.dof = dof f.dof = dof
......
...@@ -1627,6 +1627,121 @@ void dgDofContainer::exportFunctionSurf (functor * fun, const std::string name, ...@@ -1627,6 +1627,121 @@ void dgDofContainer::exportFunctionSurf (functor * fun, const std::string name,
} }
} }
void _readMsh(dgDofContainer &dof, std::string name, double &time, int &step, std::map<int, int> componentMap){
std::ifstream f (name.c_str());
if(!f.is_open()){
Msg::Fatal("Unable to open import file '%s'", name.c_str());
}
std::string word;
int ibuff;
double dbuff;
f >> word; if (word!="$MeshFormat") Msg::Fatal("bad file '%s'",name.c_str());
f >> dbuff; if (dbuff<2.0) Msg::Fatal("bad file '%s'",name.c_str());
f >> ibuff >> ibuff;
f >> word; if (word!="$EndMeshFormat") Msg::Fatal("bad file '%s'",name.c_str());
f >> word;
if (word =="$InterpolationScheme") {
while (word != "$EndInterpolationScheme" && !f.eof())
f >> word;
f >> word;
}
if (word!="$ElementNodeData") Msg::Fatal("bad file '%s'",name.c_str());
int nStrings;
f >> nStrings;
getline (f, word);
for (int i = 0; i < nStrings; i++)
getline (f, word);
int ndouble;
f >> ndouble >> time;
for (int i = 1; i < ndouble; ++i)
f >> dbuff;
int nint, ncomp, count;
f >> nint >> step >> ncomp >> count;
for (int i = 3; i < nint; ++i)
f >> ibuff;
fullMatrix<double> sol;
std::vector<int> ocomps(ncomp, -1);
for (auto it:componentMap) {
ocomps[it.second] = it.first;
}
if (componentMap.empty()) {
for (int i = 0; i < ncomp; ++i)
ocomps[i] = i;
}
for (int i = 0; i < count; i++) {
int elementNum, size;
f >> elementNum >> size;
int iGroup, iElem;
dof.getGroups()->find(elementNum, iGroup, iElem);
if (iGroup != -1){
dof.getGroupProxy(iGroup).getBlockProxy(iElem, sol);
if (size != sol.size1()) Msg::Fatal("bad size (%i) for element id (%i) in file '%s'",size, elementNum, name.c_str());
for (int k = 0; k < sol.size1(); ++k){
for (int icomp = 0; icomp < ncomp; ++icomp) {
int ocomp = ocomps[icomp];
if (ocomp == -1 || ocomp >= sol.size2()){
f >> dbuff;
}
else {
if(!(f >> sol(k, ocomp)))Msg::Fatal("bad file '%s'",name.c_str());
}
}
}
}
else{
getline(f, word);
}
}
f >> word; if (word!="$EndElementNodeData") Msg::Fatal("bad file '%s' (got '%s')", name.c_str(), word.c_str());
}
static double _importIdx(dgDofContainer &dof, std::string filename, std::map<int, int> componentMap, int next_field) {
std::ifstream f(filename);
std::string buf;
auto dirend = filename.find_last_of("/");
std::string dirname;
if (dirend != std::string::npos)
dirname = filename.substr(0,dirend+1);
double time = 0;
while(f >> buf) {
if (buf == "Merge"){
getline(f, buf);
auto p0 = buf.find('\"');
auto p1 = buf.find('\"',p0+1);
if (p0 == std::string::npos || p1 == std::string::npos)
Msg::Error("invalid file : %s", filename.c_str());
std::string sname = buf.substr(p0+1, p1-p0-1);
std::string ext = sname.substr(sname.find_last_of("."));
if (ext == ".idx")
_importIdx(dof, dirname+sname, componentMap, next_field);
else {
std::map<int, int> shiftedCMap;
for (auto it:componentMap)
shiftedCMap[it.first] = it.second - next_field;
double time;
int step;
_readMsh(dof, dirname + sname, time, step, shiftedCMap);
}
}
else if (buf == "//") {
f >> buf;
if (buf == "field") {
f >> next_field;
getline(f, buf);
}
}
else {
getline(f, buf);
}
}
return time;
}
double dgDofContainer::importIdx(const std::string filename, std::map<int, int> componentMap) {
return _importIdx(*this, filename, componentMap, 0);
}
static void writeMshInterpolationSchemes(FILE *f, const std::string &name, const dgGroupCollection &groups) static void writeMshInterpolationSchemes(FILE *f, const std::string &name, const dgGroupCollection &groups)
{ {
std::set<const nodalBasis*> allPb; std::set<const nodalBasis*> allPb;
...@@ -1806,129 +1921,6 @@ void dgDofContainer::importMshNodeData(const std::string name, bool multiFile) ...@@ -1806,129 +1921,6 @@ void dgDofContainer::importMshNodeData(const std::string name, bool multiFile)
} }
void dgDofContainer::_readMsh(std::string name, std::string name_dir, double &time, int &step, int nb_parts, int dofF){
size_t endp = name.size();
std::string f2name = std::string(name, 1, endp-3);
std::ifstream f ((name_dir+f2name).c_str());
if(!f.is_open()){
Msg::Fatal("Unable to open import file '%s'", (name_dir+f2name).c_str());
}
std::string word;
int ibuff;
double dbuff;
f >> word; if (word!="$MeshFormat") Msg::Fatal("bad file '%s'",(name_dir+f2name).c_str());
f >> dbuff; if (dbuff<2.0) Msg::Fatal("bad file '%s'",(name_dir+f2name).c_str());
f >> ibuff >> ibuff;
f >> word; if (word!="$EndMeshFormat") Msg::Fatal("bad file '%s'",(name_dir+f2name).c_str());
f >> word;
if (word =="$InterpolationScheme") {
while (word != "$EndInterpolationScheme" && !f.eof())
f >> word;
f >> word;
}
if (word!="$ElementNodeData") Msg::Fatal("bad file '%s'",(name_dir+f2name).c_str());
int nStrings;
f >> nStrings;
getline (f, word);
for (int i = 0; i < nStrings; i++)
getline (f, word);
f >> dbuff