Fem: Load Elmer solver text output
(cherry picked from commit e116b5ae34)
This commit is contained in:
committed by
github-actions[bot]
parent
155e46a188
commit
0d202e5eb3
@@ -108,37 +108,94 @@ class ElmerTools(ObjectTools):
|
||||
return self.process
|
||||
|
||||
def update_properties(self):
|
||||
keep_result = self.fem_param.GetGroup("General").GetBool("KeepResultsOnReRun", False)
|
||||
if not self.obj.Results or keep_result:
|
||||
pipeline = self.obj.Document.addObject("Fem::FemPostPipeline", self.obj.Name + "Result")
|
||||
self.analysis.addObject(pipeline)
|
||||
temp_res = self.obj.Results
|
||||
temp_res.append(pipeline)
|
||||
self.obj.Results = temp_res
|
||||
self._load_results()
|
||||
# default display mode
|
||||
pipeline.ViewObject.DisplayMode = "Surface"
|
||||
pipeline.ViewObject.SelectionStyle = "BoundBox"
|
||||
else:
|
||||
self._load_results()
|
||||
self._load_vtk_results()
|
||||
self._load_dat_results()
|
||||
|
||||
def _clear_results(self):
|
||||
dir_content = os.listdir(self.obj.WorkingDirectory)
|
||||
for f in dir_content:
|
||||
path = os.path.join(self.obj.WorkingDirectory, f)
|
||||
base, ext = os.path.splitext(path)
|
||||
if ext in [".vtu", ".vtp", ".pvtu", ".pvd"]:
|
||||
if ext in [".vtu", ".vtp", ".pvtu", ".pvd", ".dat"]:
|
||||
os.remove(path)
|
||||
|
||||
def _load_results(self):
|
||||
def _load_vtk_results(self):
|
||||
# search current pipeline
|
||||
keep_result = self.fem_param.GetGroup("General").GetBool("KeepResultsOnReRun", False)
|
||||
pipeline = None
|
||||
create = False
|
||||
for res in self.obj.Results:
|
||||
if res.isDerivedFrom("Fem::FemPostPipeline"):
|
||||
pipeline = res
|
||||
|
||||
if not pipeline or keep_result:
|
||||
# create pipeline
|
||||
pipeline = self.obj.Document.addObject("Fem::FemPostPipeline", self.obj.Name + "Result")
|
||||
self.analysis.addObject(pipeline)
|
||||
tmp = self.obj.Results
|
||||
tmp.append(pipeline)
|
||||
self.obj.Results = tmp
|
||||
create = True
|
||||
|
||||
files = os.listdir(self.obj.WorkingDirectory)
|
||||
for f in files:
|
||||
base, ext = os.path.splitext(f)
|
||||
if ext == self._result_format:
|
||||
res = os.path.join(self.obj.WorkingDirectory, f)
|
||||
self.obj.Results[-1].read(res)
|
||||
pipeline.read(res)
|
||||
break
|
||||
|
||||
if create:
|
||||
# default display mode
|
||||
pipeline.ViewObject.DisplayMode = "Surface"
|
||||
pipeline.ViewObject.SelectionStyle = "BoundBox"
|
||||
fields = pipeline.ViewObject.getEnumerationsOfProperty("Field")
|
||||
for f in fields:
|
||||
# beware of possible suffix Im or Re
|
||||
if f.lower().startswith(self._get_default_field()):
|
||||
pipeline.ViewObject.Field = f
|
||||
break
|
||||
|
||||
def _load_dat_results(self):
|
||||
# search dat output
|
||||
keep_result = self.fem_param.GetGroup("General").GetBool("KeepResultsOnReRun", False)
|
||||
dat = None
|
||||
for res in self.obj.Results:
|
||||
if res.isDerivedFrom("App::TextDocument"):
|
||||
dat = res
|
||||
|
||||
if not dat or keep_result:
|
||||
# create dat output
|
||||
dat = self.obj.Document.addObject("App::TextDocument", self.obj.Name + "Output")
|
||||
self.analysis.addObject(dat)
|
||||
tmp = self.obj.Results
|
||||
tmp.append(dat)
|
||||
self.obj.Results = tmp
|
||||
|
||||
files = os.listdir(self.obj.WorkingDirectory)
|
||||
for f in files:
|
||||
if f.endswith(".dat"):
|
||||
dat_file = os.path.join(self.obj.WorkingDirectory, f)
|
||||
with open(dat_file, "r") as file:
|
||||
dat.Text = file.read()
|
||||
break
|
||||
|
||||
def _get_default_field(self):
|
||||
default = "None"
|
||||
for eq in self.obj.Group:
|
||||
match eq.Proxy.Type:
|
||||
case "Fem::EquationElmerHeat":
|
||||
default = "temperature"
|
||||
case "Fem::EquationElmerElasticity" | "Fem::EquationElmerDeformation":
|
||||
default = "displacement"
|
||||
case "Fem::EquationElmerElectrostatic" | "Fem::EquationElmerStaticCurrent":
|
||||
default = "potential"
|
||||
case "Fem::EquationElmerFlow":
|
||||
default = "pressure"
|
||||
case "Fem::EquationElmerMagnetodynamic" | "Fem::EquationElmerMagnetodynamic2D":
|
||||
default = "magnetic flux"
|
||||
return default
|
||||
|
||||
def version(self):
|
||||
p = QProcess()
|
||||
elmer_bin = settings.get_binary("ElmerSolver")
|
||||
|
||||
Reference in New Issue
Block a user