Last active
April 26, 2018 12:24
-
-
Save miho/619fe912e63687c202e8a93a933f603e to your computer and use it in GitHub Desktop.
AdvectionDiffusion-UG4 component for VRL by A.Vogel and M.Hoffer
This file contains hidden or 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
| /** | |
| * Script to perform an Advection-Diffusion Problem | |
| * | |
| * Author: M. Hoffer, A. Vogel | |
| */ | |
| import edu.gcsc.vrl.ug.api.I_ApproximationSpace; | |
| import edu.gcsc.vrl.ug.api.I_UserNumber; | |
| import edu.gcsc.vrl.ug.api.I_UserVector; | |
| import edu.gcsc.vrl.ug.api.*; | |
| import edu.gcsc.vrl.userdata.*; | |
| import eu.mihosoft.vrl.annotation.ComponentInfo; | |
| import eu.mihosoft.vrl.annotation.MethodInfo; | |
| import eu.mihosoft.vrl.annotation.OutputInfo; | |
| import eu.mihosoft.vrl.annotation.ParamGroupInfo; | |
| import eu.mihosoft.vrl.annotation.ParamInfo; | |
| @ComponentInfo(name = "AdvectionDiffusion (custom version)", category = "Custom") | |
| public class AdvectionDiffusionCustom implements java.io.Serializable { | |
| private static final long serialVersionUID = 1L; | |
| @MethodInfo(valueStyle = "multi-out", interactive = true) | |
| @OutputInfo(style = "multi-out", | |
| elemNames = ["Problem-Setup", "Approximation-Space", "Output-Data", "StartValues"], | |
| elemTypes = [I_DomainDiscretization.class, I_ApproximationSpace.class, I_VTKOutput.class, I_UserNumber[].class]) | |
| public Object[] invoke( | |
| @ParamGroupInfo(group = "Domain") | |
| @ParamInfo(name = "Grid:", style = "ugx-load-dialog", options = "ugx_tag=\"TheFile\"") java.io.File file, | |
| @ParamGroupInfo(group = "Physical Parameter|true|Parameter") | |
| @ParamInfo(name = "Inner Parameters", style = "array", options = "ugx_tag=\"TheFile\"; minArraySize=1; type=\"s|mvnnn:Subset, Diffusion, Velocity, Source, Reaction Rate, Mass Scale\"") UserDataTuple[] convDiffData, | |
| @ParamGroupInfo(group = "Physical Parameter") | |
| @ParamInfo(name = "Dirichlet Boundary", style = "array", options = "ugx_tag=\"TheFile\"; minArraySize=0; type=\"s|n:Subset, Value\"") UserDataTuple[] dirichletBndValue, | |
| @ParamGroupInfo(group = "Physical Parameter") | |
| @ParamInfo(name = "Neumann Boundary ", style = "array", options = "ugx_tag=\"TheFile\"; minArraySize=0; type=\"s|n:Subset, Value\"") UserDataTuple[] neumannBndValue, | |
| @ParamGroupInfo(group = "Start Value|false|Start Values") | |
| @ParamInfo(name = "Start Value", style = "default", options = "ugx_tag=\"TheFile\"") I_UserNumber startValue, | |
| @ParamGroupInfo(group = "Discretization Setup|false|Discretization Parameters") | |
| @ParamInfo(name = "Discretization Type", style = "selection", options = "value=[\"Finite Element\", \"Finite Volume\"]") String discTypeName, | |
| @ParamGroupInfo(group = "Discretization Setup") | |
| @ParamInfo(name = "Upwind Type", style = "selection", options = "value=[\"Full\",\"Partial\", \"None\"]") String upwindTypeName | |
| ) { | |
| String fileName = file.getAbsolutePath(); | |
| int dim = convDiffData[0].getMatrixData(1).const__get_dim(); | |
| //-- Init UG for dimension and algebra | |
| F_InitUG.invoke(dim, new AlgebraType("CPU", 1)); | |
| //-------------------------------------------------------------------------------- | |
| //-- Domain Setup | |
| //-------------------------------------------------------------------------------- | |
| I_Domain dom = new Domain(); | |
| F_LoadDomain.invoke(dom, fileName); | |
| // -- Create, Load, Refine and Distribute Domain | |
| I_ApproximationSpace approxSpace = new ApproximationSpace(dom); | |
| String fctName = "c"; | |
| approxSpace.add_fct(fctName, "Lagrange", 1); | |
| //-------------------------------------------------------------------------------- | |
| //-- FV Disc setup | |
| //-------------------------------------------------------------------------------- | |
| I_DomainDiscretization domainDisc = new DomainDiscretization(approxSpace); | |
| I_MGSubsetHandler sh = dom.subset_handler(); | |
| String innerSubset = ""; | |
| for (int i = 0; i < convDiffData.length; i++) { | |
| String innerSS = convDiffData[i].getSubset(0); | |
| if (innerSubset == "") { | |
| innerSubset = innerSubset + innerSS; | |
| } else { | |
| innerSubset = innerSubset + "," + innerSS; | |
| } | |
| I_IConvectionShapes upwinding = null; | |
| if ("Full".equals(upwindTypeName)) { | |
| upwinding = new FullUpwind(); | |
| } else if ("Partial".equals(upwindTypeName)) { | |
| upwinding = new PartialUpwind(); | |
| } else if ("None".equals(upwindTypeName)) { | |
| upwinding = new NoUpwind(); | |
| } else { | |
| errorExit("Cannot find UpwindType which is equal to: " + upwindTypeName); | |
| } | |
| I_ConvectionDiffusionBase elemDisc = null; | |
| if ("Finite Element".equals(discTypeName)) { | |
| elemDisc = new ConvectionDiffusionFE(fctName, innerSS); | |
| } else if ("Finite Volume".equals(discTypeName)) { | |
| elemDisc = new ConvectionDiffusionFV1(fctName, innerSS); | |
| ((I_ConvectionDiffusionFV1) elemDisc).set_upwind(upwinding); | |
| } else { | |
| errorExit("Cannot find specified discretization type: " + discTypeName); | |
| } | |
| // try to read the value from the convDiffData array | |
| I_UserNumber massScale = null; | |
| try { | |
| massScale = convDiffData[i].getNumberData(5); | |
| } catch (Exception e) { | |
| System.err.println("massScale could not be get"); | |
| } | |
| I_UserNumber reactionRate = null; | |
| try { | |
| reactionRate = convDiffData[i].getNumberData(4); | |
| } catch (Exception e) { | |
| System.err.println("reactionRate could not be get"); | |
| } | |
| I_UserNumber source = null; | |
| try { | |
| source = convDiffData[i].getNumberData(3); | |
| } catch (Exception e) { | |
| System.err.println("source could not be get"); | |
| } | |
| I_UserVector velocity = null; | |
| try { | |
| velocity = convDiffData[i].getVectorData(2); | |
| } catch (Exception e) { | |
| System.err.println("velocity could not be get"); | |
| } | |
| I_UserMatrix diffusion = null; | |
| try { | |
| diffusion = convDiffData[i].getMatrixData(1); | |
| } catch (Exception e) { | |
| System.err.println("diffusion could not be get"); | |
| } | |
| // set the values if they could be read from convDiffData array | |
| if (diffusion != null) { | |
| elemDisc.set_diffusion((I_CplUserMatrix) diffusion); | |
| } | |
| if (velocity != null) { | |
| elemDisc.set_velocity((I_CplUserVector) velocity); | |
| } | |
| if (source != null) { | |
| elemDisc.set_source((I_CplUserNumber) source); | |
| } | |
| if (reactionRate != null) { | |
| elemDisc.set_reaction_rate((I_CplUserNumber) reactionRate); | |
| } | |
| if (massScale != null) { | |
| elemDisc.set_mass_scale((I_CplUserNumber) massScale); | |
| } | |
| domainDisc.add(elemDisc); | |
| } | |
| I_DirichletBoundary dirichletBND = new DirichletBoundary(); | |
| for (int i = 0; i < dirichletBndValue.length; i++) { | |
| String bndSS = dirichletBndValue[i].getSubset(0); | |
| dirichletBND.add(dirichletBndValue[i].getNumberData(1), fctName, bndSS); | |
| } | |
| domainDisc.add(dirichletBND); | |
| // I_NeumannBoundary neumannBND = new NeumannBoundary(innerSubset); | |
| // I_NeumannBoundaryBase neumannBND = new NeumannBoundaryBase(); // NOT instantiable !! | |
| I_NeumannBoundaryBase neumannBND = null; | |
| if ("Finite Element".equals(discTypeName)) { | |
| neumannBND = new NeumannBoundaryFE(); | |
| } else if ("Finite Volume".equals(discTypeName)) { | |
| neumannBND = new NeumannBoundaryFV(); | |
| } | |
| for (int i = 0; i < neumannBndValue.length; i++) { | |
| String bndSS = neumannBndValue[i].getSubset(0); | |
| neumannBND.add((I_CplUserNumber) neumannBndValue[i].getNumberData(1), fctName, bndSS); | |
| } | |
| if (neumannBndValue.length > 0) { | |
| domainDisc.add(neumannBND); | |
| } | |
| I_UserNumber[] startVal = new I_UserNumber[1]; | |
| startVal[0] = startValue; | |
| I_VTKOutput out = new VTKOutput(); | |
| out.select_nodal(fctName, fctName); | |
| return [domainDisc, approxSpace, out, startVal]; | |
| } | |
| private void errorExit(String s) { | |
| eu.mihosoft.vrl.system.VMessage.exception("Setup Error in AdvectionDiffusion: ", s); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment