From 3b082dded2e42fe7b59db119a74268f20ae88f2b Mon Sep 17 00:00:00 2001 From: Yeongdo Park Date: Mon, 11 Mar 2019 00:25:58 +0900 Subject: [PATCH] CombustionModule base, copy of StandardVOFModule --- .../CombustionBoundaryConditionsView.java | 81 ++++++++ src/eu/engys/combustion/CombustionModule.java | 194 ++++++++++++++++++ .../combustion/CombustionPhasesView.java | 95 +++++++++ src/eu/engys/combustion/CombustionReader.java | 141 +++++++++++++ .../combustion/CombustionSolutionView.java | 74 +++++++ .../engys/combustion/CombustionTreeView.java | 51 +++++ src/eu/engys/combustion/CombustionWriter.java | 101 +++++++++ 7 files changed, 737 insertions(+) create mode 100644 src/eu/engys/combustion/CombustionBoundaryConditionsView.java create mode 100644 src/eu/engys/combustion/CombustionModule.java create mode 100644 src/eu/engys/combustion/CombustionPhasesView.java create mode 100644 src/eu/engys/combustion/CombustionReader.java create mode 100644 src/eu/engys/combustion/CombustionSolutionView.java create mode 100644 src/eu/engys/combustion/CombustionTreeView.java create mode 100644 src/eu/engys/combustion/CombustionWriter.java diff --git a/src/eu/engys/combustion/CombustionBoundaryConditionsView.java b/src/eu/engys/combustion/CombustionBoundaryConditionsView.java new file mode 100644 index 0000000..0d98f20 --- /dev/null +++ b/src/eu/engys/combustion/CombustionBoundaryConditionsView.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS is distributed in the hope that it will be useful, but WITHOUT | + * | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | + * | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.combustion; + +import eu.engys.core.modules.boundaryconditions.BoundaryConditionsView; +import eu.engys.core.modules.boundaryconditions.BoundaryTypePanel; +import eu.engys.core.modules.boundaryconditions.IBoundaryConditionsPanel; +import eu.engys.core.project.Model; +import eu.engys.core.project.zero.patches.BoundaryType; +import eu.engys.gui.casesetup.boundaryconditions.panels.patch.MomentumPatch; +import eu.engys.gui.casesetup.boundaryconditions.panels.wall.StandardMomentumWall; +import eu.engys.gui.casesetup.boundaryconditions.parameterspanel.MomentumParametersPanel; + +public class CombustionBoundaryConditionsView implements BoundaryConditionsView { + + public static final String MOMENTUM = " " + MomentumParametersPanel.MOMENTUM + " "; + private CombustionModule module; + + public CombustionBoundaryConditionsView(CombustionModule module) { + this.module = module; + } + + @Override + public void configure(BoundaryTypePanel panel) { + if (panel.getType() == BoundaryType.WALL) { + panel.addPanel(MOMENTUM, new VOFStandardMomentumWall(panel), 0); + } else if (panel.getType() == BoundaryType.PATCH) { + panel.addPanel(MOMENTUM, new VOFStandardMomentumPatch(panel), 0); + } + } + + class VOFStandardMomentumWall extends StandardMomentumWall { + public VOFStandardMomentumWall(BoundaryTypePanel parent) { + super(parent); + } + + @Override + public boolean isEnabled(Model model) { + return module.isVOF(); + } + } + + class VOFStandardMomentumPatch extends MomentumPatch { + + public VOFStandardMomentumPatch(BoundaryTypePanel parent) { + super(parent); + } + + @Override + public boolean isEnabled(Model model) { + return module.isVOF(); + } + } + + @Override + public void configure(IBoundaryConditionsPanel panel) { + } + +} diff --git a/src/eu/engys/combustion/CombustionModule.java b/src/eu/engys/combustion/CombustionModule.java new file mode 100644 index 0000000..04f2024 --- /dev/null +++ b/src/eu/engys/combustion/CombustionModule.java @@ -0,0 +1,194 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS is distributed in the hope that it will be useful, but WITHOUT | + * | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | + * | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.combustion; + +import java.util.HashSet; +import java.util.Set; + +import javax.inject.Inject; + +import eu.engys.core.dictionary.Dictionary; +import eu.engys.core.dictionary.FieldElement; +import eu.engys.core.modules.ApplicationModuleAdapter; +import eu.engys.core.modules.ModuleDefaults; +import eu.engys.core.modules.ModulePanel; +import eu.engys.core.modules.boundaryconditions.BoundaryConditionsView; +import eu.engys.core.modules.solutionmodelling.SolutionView; +import eu.engys.core.modules.tree.TreeView; +import eu.engys.core.project.Model; +import eu.engys.core.project.defaults.DefaultsProvider; +import eu.engys.core.project.state.MultiphaseModel; +import eu.engys.core.project.state.Solver; +import eu.engys.core.project.state.State; +import eu.engys.core.project.state.StateBuilder; +import eu.engys.core.project.zero.fields.Fields; +import eu.engys.core.project.zero.fields.FieldsDefaults; +import eu.engys.gui.casesetup.phases.PhasesPanel; + +public class CombustionModule extends ApplicationModuleAdapter { + + private static final String MODULE_NAME = "combustion"; + + public static final Solver REACTINGFOAM_FOAM = new Solver("reactingFoam"); + + public static final String VOF_LABEL = "VOF"; + public static final String VOF_KEY = "VOF"; + + public static final MultiphaseModel VOF_MODEL = new MultiphaseModel(VOF_LABEL, VOF_KEY, true, true); + + private CombustionSolutionView solutionView; + private CombustionBoundaryConditionsView boundaryConditionsView; + + private PhasesPanel phasesPanel; + private TreeView treeView; + + private double sigma; + + private Model model; + private DefaultsProvider defaults; + + private CombustionReader reader; + + @Inject + public CombustionModule(Model model) { + this.model = model; + this.solutionView = new CombustionSolutionView(this); + this.boundaryConditionsView = new CombustionBoundaryConditionsView(this); + + this.phasesPanel = new PhasesPanel(model, new CombustionPhasesView(this, model)); + this.treeView = new CombustionTreeView(this, phasesPanel); + + this.reader = new CombustionReader(model, this); + + this.defaults = new ModuleDefaults(this, model.getDefaults(), model.getDefaults().getDefaultStateData()) { + @Override + public Dictionary getDefaultsFieldMapsFor(State state, String region) { + Dictionary fieldMaps = super.getDefaultsFieldMapsFor(state, region); + fixAlphaFieldName(fieldMaps); + return fieldMaps; + } + }; + } + + private void fixAlphaFieldName(Dictionary fieldMaps) { + if (model.getState().getMultiphaseModel().isMultiphase() && model.getState().getPhases() > 1 && fieldMaps != null && fieldMaps.found(Fields.ALPHA)) { + String alpha = ((FieldElement) fieldMaps.remove(Fields.ALPHA)).getValue(); + fieldMaps.add(Fields.ALPHA + "." + model.getMaterials().getFirstMaterialName(), alpha); + } + } + + @Override + public String getName() { + return MODULE_NAME; + } + + @Override + public TreeView getTreeView() { + return treeView; + } + + @Override + public Set getCaseSetupPanels() { + Set panels = new HashSet<>(); + panels.add(phasesPanel); + return panels; + } + + @Override + public void updateSolver(State state) { + if (state.getMultiphaseModel().equals(VOF_MODEL)) { + if (state.isIncompressible()) { + if (state.isTransient()) { + if (state.isDynamic()) { + state.setSolver(INTER_DYM_FOAM); + } else { + state.setSolver(INTER_FOAM); + } + } + } + } + } + + @Override + public void loadState() { + reader.loadState(); + } + + @Override + public void loadMaterials() { + reader.loadMaterials(); + } + + @Override + public void save() { + new CombustionWriter(model, this).write(); + } + + @Override + public void saveDefaultsToProject() { + if (isVOF()) { + StateBuilder.saveDefaultsToProject(model, defaults); + } else { + } + } + + @Override + public Fields loadDefaultsFields(String region) { + if (isVOF()) { + return FieldsDefaults.loadFieldsFromDefaults(model.getProject().getBaseDir(), model.getState(), defaults, model.getPatches(), region); + } else { + return new Fields(); + } + } + + @Override + public SolutionView getSolutionView() { + return solutionView; + } + + @Override + public BoundaryConditionsView getBoundaryConditionsView() { + return boundaryConditionsView; + } + + public boolean isVOF() { + return model.getState().getMultiphaseModel().equals(VOF_MODEL); + } + + public void setSigma(double sigma) { + this.sigma = sigma; + } + + public double getSigma() { + return sigma; + } + + /* + * For test purposes only + */ + public PhasesPanel getPhasesPanel() { + return phasesPanel; + } +} diff --git a/src/eu/engys/combustion/CombustionPhasesView.java b/src/eu/engys/combustion/CombustionPhasesView.java new file mode 100644 index 0000000..7cda703 --- /dev/null +++ b/src/eu/engys/combustion/CombustionPhasesView.java @@ -0,0 +1,95 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS is distributed in the hope that it will be useful, but WITHOUT | + * | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | + * | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.combustion; + +import static eu.engys.core.project.constant.TransportProperties.SIGMA_KEY; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import eu.engys.core.dictionary.Dictionary; +import eu.engys.core.dictionary.DimensionedScalar; +import eu.engys.core.dictionary.model.DictionaryModel; +import eu.engys.core.project.Model; +import eu.engys.gui.casesetup.phases.PhasesView; +import eu.engys.util.DimensionalUnits; +import eu.engys.util.ui.builder.PanelBuilder; + +public class CombustionPhasesView implements PhasesView { + + public static final String SURFACE_TENSION_LABEL = "Surface Tension [N/m]"; + + private static final Logger logger = LoggerFactory.getLogger(CombustionPhasesView.class); + + private Model model; + private CombustionModule module; + private DictionaryModel sigmaModel = new DictionaryModel(new Dictionary("")); + + private PanelBuilder parametersBuilder; + + public CombustionPhasesView(CombustionModule module, Model model) { + this.module = module; + this.model = model; + } + + @Override + public void layoutComponents(PanelBuilder parametersBuilder) { + this.parametersBuilder = parametersBuilder; + } + + @Override + public void load(Model model) { + if (module.isVOF()) { + _layoutComponents(); + _load(model); + } + } + + private void _layoutComponents() { + parametersBuilder.clear(); + parametersBuilder.addComponent(SURFACE_TENSION_LABEL, sigmaModel.bindDimensionedDouble(SIGMA_KEY, DimensionalUnits.KG_S2, 0D, Double.MAX_VALUE)); + } + + private void _load(Model model) { + Dictionary dict = new Dictionary(""); + dict.add(new DimensionedScalar(SIGMA_KEY, String.valueOf(module.getSigma()), DimensionalUnits.KG_S2)); + sigmaModel.setDictionary(dict); + } + + @Override + public void save(Model model) { + if (module.isVOF()) { + _save(model); + } + } + + private void _save(Model model) { + Dictionary sigmaDict = sigmaModel.getDictionary(); + if (sigmaDict.found(SIGMA_KEY)) { + module.setSigma(sigmaDict.lookupScalar(SIGMA_KEY).doubleValue()); + } + } + +} diff --git a/src/eu/engys/combustion/CombustionReader.java b/src/eu/engys/combustion/CombustionReader.java new file mode 100644 index 0000000..f77e015 --- /dev/null +++ b/src/eu/engys/combustion/CombustionReader.java @@ -0,0 +1,141 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS is distributed in the hope that it will be useful, but WITHOUT | + * | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | + * | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.combustion; + +import static eu.engys.core.project.constant.ThermophysicalProperties.MATERIAL_NAME_KEY; +import static eu.engys.core.project.constant.TransportProperties.PHASES_KEY; +import static eu.engys.core.project.constant.TransportProperties.SIGMA_KEY; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import eu.engys.core.dictionary.Dictionary; +import eu.engys.core.project.Model; +import eu.engys.core.project.constant.ConstantFolder; +import eu.engys.core.project.constant.TransportProperties; +import eu.engys.core.project.materials.Material; +import eu.engys.core.project.materials.Materials; +import eu.engys.gui.casesetup.materials.StandardMaterialsReader; + +public class CombustionReader { + + private static final Logger logger = LoggerFactory.getLogger(CombustionReader.class); + + private Model model; + private CombustionModule module; + + private TransportProperties transportProperties; + + public CombustionReader(Model model, CombustionModule module) { + this.model = model; + this.module = module; + } + + public void loadState() { + if (isMultiphaseVOF()) { + model.getState().setMultiphaseModel(CombustionModule.VOF_MODEL); + model.getState().setPhases(2); + } + } + + public void loadMaterials() { + if (isMultiphaseVOF()) { + if (model.getState().isIncompressible()) { + readIncompressibleMaterials(); + } else { + readCompressibleMaterials(); + } + } + } + + private boolean isMultiphaseVOF() { + ConstantFolder constantFolder = model.getProject().getConstantFolder(); + TransportProperties transportProperties = constantFolder.getTransportProperties(); + if (transportProperties != null) { + if ((transportProperties.found(PHASES_KEY))) { + return true; + } else { + return false; + } + } else { + return false; + } + } + + private void readIncompressibleMaterials() { + Materials materials = model.getMaterials(); + ConstantFolder constantFolder = model.getProject().getConstantFolder(); + transportProperties = constantFolder.getTransportProperties(); + + if (transportProperties.found(PHASES_KEY)) { + model.getState().setPhases(2); + + String phases = transportProperties.lookup(PHASES_KEY).replaceAll("\\(", "").replaceAll("\\)", "").trim(); + + Dictionary dict1 = new Dictionary(transportProperties.subDict(phases.split(" ")[0])); + if (!dict1.isEmpty()) { + if (!dict1.found(MATERIAL_NAME_KEY)) { + dict1.add(MATERIAL_NAME_KEY, "material1"); + } + String name1 = dict1.lookup(MATERIAL_NAME_KEY); + dict1.setName(name1); + Material m1 = new StandardMaterialsReader().readIncompressibleMaterial(dict1); + materials.add(m1); + } + + Dictionary dict2 = new Dictionary(transportProperties.subDict(phases.split(" ")[1])); + if (!dict2.isEmpty()) { + if (!dict2.found(MATERIAL_NAME_KEY)) { + dict2.add(MATERIAL_NAME_KEY, "material2"); + } + String name2 = dict2.lookup(MATERIAL_NAME_KEY); + dict2.setName(name2); + Material m2 = new StandardMaterialsReader().readIncompressibleMaterial(dict2); + materials.add(m2); + } + + if (transportProperties.found(SIGMA_KEY)) { + double sigma = transportProperties.lookupScalar(SIGMA_KEY).doubleValue(); + module.setSigma(sigma); + } else if (dict1.found(SIGMA_KEY)) { + double sigma = dict1.lookupScalar(SIGMA_KEY).doubleValue(); + module.setSigma(sigma); + } else if (dict2.found(SIGMA_KEY)) { + double sigma = dict2.lookupScalar(SIGMA_KEY).doubleValue(); + module.setSigma(sigma); + } + + model.materialsChanged(); + + } else { + logger.warn("Multiphase case but no phases found in transportProperties"); + } + } + + public void readCompressibleMaterials() { + logger.error("Multiphase Compressible not supported"); + } + +} diff --git a/src/eu/engys/combustion/CombustionSolutionView.java b/src/eu/engys/combustion/CombustionSolutionView.java new file mode 100644 index 0000000..276e4d4 --- /dev/null +++ b/src/eu/engys/combustion/CombustionSolutionView.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS is distributed in the hope that it will be useful, but WITHOUT | + * | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | + * | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.combustion; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import eu.engys.core.modules.solutionmodelling.AbstractSolutionView; +import eu.engys.core.modules.solutionmodelling.MultiphaseBuilder; +import eu.engys.core.project.state.MultiphaseModel; +import eu.engys.core.project.state.SolutionState; +import eu.engys.util.ui.textfields.SpinnerField; + +public class CombustionSolutionView extends AbstractSolutionView { + + private static final Logger logger = LoggerFactory.getLogger(CombustionSolutionView.class); + + private CombustionModule module; + private MultiphaseBuilder builder; + + public CombustionSolutionView(CombustionModule module) { + this.module = module; + } + + @Override + public void buildMultiphase(MultiphaseBuilder builder) { + this.builder = builder; + builder.addMultiphaseChoice(CombustionModule.VOF_MODEL); + } + + @Override + public void fixSolutionState(SolutionState ss) { + if (ss.areSolverTypeAndTimeAndFlowAndTurbulenceChoosen()) { + boolean isVOFState = ss.isTransient() && ss.isIncompressible(); + if (isVOFState) { + builder.enableChoice(CombustionModule.VOF_MODEL); + } else { + builder.disableChoice(CombustionModule.VOF_MODEL); + } + } + } + + @Override + public void fixMultiphase(MultiphaseModel mm) { + SpinnerField phasesNumber = builder.getPhasesField(); + if (mm.equals(CombustionModule.VOF_MODEL)) { + phasesNumber.setIntValue(2); + phasesNumber.setEnabled(false); + } + } + +} diff --git a/src/eu/engys/combustion/CombustionTreeView.java b/src/eu/engys/combustion/CombustionTreeView.java new file mode 100644 index 0000000..79af8a6 --- /dev/null +++ b/src/eu/engys/combustion/CombustionTreeView.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS is distributed in the hope that it will be useful, but WITHOUT | + * | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | + * | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.combustion; + +import eu.engys.core.modules.ModulePanel; +import eu.engys.core.modules.tree.AbstractTreeViewAdapter; +import eu.engys.core.modules.tree.ModuleElementPanel; +import eu.engys.gui.casesetup.phases.PhasesPanel; + +public class CombustionTreeView extends AbstractTreeViewAdapter { + + private CombustionModule module; + private ModulePanel phasesPanel; + + public CombustionTreeView(CombustionModule module, PhasesPanel phasesPanel) { + this.module = module; + this.phasesPanel = phasesPanel; + } + + @Override + public void updateCaseSetupTree(ModuleElementPanel viewElementPanel) { + if (module.isVOF()) { + viewElementPanel.addPanel(phasesPanel); + } else { + viewElementPanel.removePanel(phasesPanel); + } + } + +} diff --git a/src/eu/engys/combustion/CombustionWriter.java b/src/eu/engys/combustion/CombustionWriter.java new file mode 100644 index 0000000..6fd26ab --- /dev/null +++ b/src/eu/engys/combustion/CombustionWriter.java @@ -0,0 +1,101 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS is distributed in the hope that it will be useful, but WITHOUT | + * | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | + * | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.combustion; + +import static eu.engys.core.project.constant.TransportProperties.PHASES_KEY; +import static eu.engys.core.project.constant.TransportProperties.SIGMA_KEY; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import eu.engys.core.dictionary.Dictionary; +import eu.engys.core.dictionary.DimensionedScalar; +import eu.engys.core.project.Model; +import eu.engys.core.project.constant.ConstantFolder; +import eu.engys.core.project.constant.TransportProperties; +import eu.engys.core.project.materials.Material; +import eu.engys.core.project.materials.Materials; +import eu.engys.gui.casesetup.materials.StandardMaterialsWriter; + +public class CombustionWriter { + + private static final Logger logger = LoggerFactory.getLogger(CombustionWriter.class); + + private Model model; + private CombustionModule module; + + public CombustionWriter(Model model, CombustionModule module) { + this.model = model; + this.module = module; + + } + + public void write() { + if (module.isVOF()) { + if (model.getState().isIncompressible()) { + writeIncompressibleMaterials(); + } else { + writeCompressibleMaterials(); + } + } + } + + private void writeCompressibleMaterials() { + logger.error("Multiphase Compressible not supported"); + } + + private void writeIncompressibleMaterials() { + Materials materials = model.getMaterials(); + ConstantFolder constantFolder = model.getProject().getConstantFolder(); + TransportProperties transportProperties = constantFolder.getTransportProperties(); + + if (materials.size() == 2) { + transportProperties.clear(); + + Material mat1 = materials.get(0); + String mat1Name = mat1.getName(); + Material mat2 = materials.get(1); + String mat2Name = mat2.getName(); + + transportProperties.add(PHASES_KEY, "(" + mat1Name + " " + mat2Name + ")"); + + Dictionary dict1 = new StandardMaterialsWriter(model).writeSingle_IncompressibleMaterial(mat1); + dict1.remove(SIGMA_KEY); + dict1.setName(mat1Name); + transportProperties.add(dict1); + + Dictionary dict2 = new StandardMaterialsWriter(model).writeSingle_IncompressibleMaterial(mat2); + dict2.remove(SIGMA_KEY); + dict2.setName(mat2Name); + transportProperties.add(dict2); + + double sigmaValue = module.getSigma(); + transportProperties.add(new DimensionedScalar(SIGMA_KEY, String.valueOf(sigmaValue), "[1 0 -2 0 0 0 0 ]")); + + } else { + logger.warn("Multiphase solution choosen but '{}' materials found", materials.size()); + } + } +}