static string[] BndFunctions(IGridData g) { int D = g.SpatialDimension; //return ArrayTools.Cat(VariableNames.VelocityVector(D), VariableNames.Temperature, "HeatFlux"); return(ArrayTools.Cat(VariableNames.HeatFluxVector(D), VariableNames.Temperature, VariableNames.VelocityVector(D))); }
public IDictionary <string, AppControl.BoundaryValueCollection> GetBoundaryConfig() { var config = new Dictionary <string, AppControl.BoundaryValueCollection>(); config.Add("wall_top", new AppControl.BoundaryValueCollection()); config.Add("wall_bottom", new AppControl.BoundaryValueCollection()); if (!periodic) { if (!this.ROT.ApproximateEquals(AffineTrafo.Some2DRotation(0.0))) { throw new NotSupportedException(); } double A_a0, A_a1, A_a2, B_a0, B_a1, B_a2; this.ParabolaCoeffs_A(out A_a2, out A_a1, out A_a0); this.ParabolaCoeffs_B(out B_a2, out B_a1, out B_a0); config.Add("velocity_inlet", new AppControl.BoundaryValueCollection()); config["velocity_inlet"].Evaluators.Add( VariableNames.Velocity_d(0) + "#A", (X, t) => A_a0 + A_a1 * X[1] + A_a2 * X[1] * X[1]); config["velocity_inlet"].Evaluators.Add( VariableNames.Velocity_d(0) + "#B", (X, t) => B_a0 + B_a1 * X[1] + B_a2 * X[1] * X[1]); config.Add("Pressure_Outlet", new AppControl.BoundaryValueCollection()); } return(config); }
public static string[] GetVariableNames(int numAgents, uint agentIdx) { var numOtherVars = VariableNames.Length; var variableNames = new string[numOtherVars + (numAgents * 8)]; //copies from above VariableNames.CopyTo(variableNames, 0); for (var i = 0u; i < numAgents; i++) { //ignores self agent if (i.Equals(agentIdx)) { continue; } var idxDiff = numOtherVars + (i * numOtherVars); variableNames[SOCIAL_ENCOUNTER_IDX + idxDiff] = string.Format("S{0}", i); variableNames[OTHER_EXTRINSIC_RWD_IDX + idxDiff] = string.Format("Re{0}", i); variableNames[OTHER_ST_ACT_CNT_IDX + idxDiff] = string.Format("Csa{0}", i); variableNames[OTHER_DIST_IDX + idxDiff] = string.Format("D{0}", i); variableNames[OTHER_ST_VAL_IDX + idxDiff] = string.Format("Vs{0}", i); variableNames[OTHER_ST_ACT_VAL_IDX + idxDiff] = string.Format("Qsa{0}", i); variableNames[OTHER_ST_ACT_PRED_ERR_IDX + idxDiff] = string.Format("Esa{0}", i); variableNames[OTHER_TRANS_PROB + idxDiff] = string.Format("Pssa{0}", i); } return(variableNames); }
public ViscosityInSpeciesBulk_GradUtranspTerm(double penalty, double sw, IncompressibleMultiphaseBoundaryCondMap bcMap, string spcName, SpeciesId spcId, int _d, int _D, double _muA, double _muB, double _betaS = 0.0) : base(penalty, _d, _D, bcMap, NSECommon.ViscosityOption.ConstantViscosity, constantViscosityValue: double.NegativeInfinity) { base.m_alpha = sw; this.m_bcMap = bcMap; m_spcId = spcId; switch (spcName) { case "A": currentMu = _muA; complementMu = _muB; break; case "B": currentMu = _muB; complementMu = _muA; break; default: throw new ArgumentException("Unknown species."); } double muFactor = Math.Max(currentMu, complementMu) / currentMu; base.m_penalty_base = penalty * muFactor; int D = base.m_D; base.velFunction = D.ForLoop(d => this.m_bcMap.bndFunction[VariableNames.Velocity_d(d) + "#" + spcName]); betaS = _betaS; }
public IDictionary <string, AppControl.BoundaryValueCollection> GetBoundaryConfig() { var config = new Dictionary <string, AppControl.BoundaryValueCollection>(); config.Add("wall_top", new AppControl.BoundaryValueCollection()); config.Add("wall_bottom", new AppControl.BoundaryValueCollection()); if (!periodic) { if (!this.ROT.ApproximateEquals(AffineTrafo.Some2DRotation(0.0))) { throw new NotSupportedException(); } config.Add("velocity_inlet", new AppControl.BoundaryValueCollection()); config["velocity_inlet"].Evaluators.Add( VariableNames.Velocity_d(0) + "#A", (X, t) => 1.0 - X[1] * X[1]); config["velocity_inlet"].Evaluators.Add( VariableNames.Velocity_d(0) + "#B", (X, t) => 1.0 - X[1] * X[1]); config.Add("Pressure_Outlet", new AppControl.BoundaryValueCollection()); } return(config); }
public ConductivityInSpeciesBulk(double penalty, double sw, ThermalMultiphaseBoundaryCondMap bcMap, int D, string spcName, SpeciesId spcId, double _kA, double _kB) : base(penalty, D, bcMap) { base.m_alpha = sw; this.m_bcMap = bcMap; this.m_spcId = spcId; ValidSpecies = spcName; switch (spcName) { case "A": currentk = _kA; complementk = _kB; break; case "B": currentk = _kB; complementk = _kA; break; default: throw new ArgumentException("Unknown species."); } double muFactor = Math.Max(currentk, complementk) / currentk; base.m_penalty_base = penalty * muFactor; base.tempFunction = this.m_bcMap.bndFunction[VariableNames.Temperature + "#" + spcName]; base.fluxFunction = D.ForLoop(d => bcMap.bndFunction[VariableNames.HeatFluxVectorComponent(d) + "#" + spcName]); }
public ConstitutiveEqns_CellWiseForm(int _ComponentRow, int _ComponentCol, BoundaryCondMap <IncompressibleBcType> _BcMap, double Weissenberg, double alpha = 1.0) { ComponentRow = _ComponentRow; ComponentCol = _ComponentCol; this.m_BcMap = _BcMap; this.m_Weissenberg = Weissenberg; this.m_alpha = alpha; StressFunction = new Func <double[], double, double> [GridCommons.FIRST_PERIODIC_BC_TAG, 2, 2]; var stressXXfuncS = m_BcMap.bndFunction[VariableNames.StressXX]; var stressXYfuncS = m_BcMap.bndFunction[VariableNames.StressXY]; var stressYYfuncS = m_BcMap.bndFunction[VariableNames.StressYY]; for (int et = 0; et < GridCommons.FIRST_PERIODIC_BC_TAG; et++) { StressFunction[et, 0, 0] = stressXXfuncS[et]; StressFunction[et, 1, 0] = stressXYfuncS[et]; StressFunction[et, 0, 1] = stressXYfuncS[et]; StressFunction[et, 1, 1] = stressYYfuncS[et]; } velFunction = new Func <double[], double, double> [GridCommons.FIRST_PERIODIC_BC_TAG, 2]; for (int d = 0; d < 2; d++) { velFunction.SetColumn(m_BcMap.bndFunction[VariableNames.Velocity_d(d)], d); } }
public ConvectionInSpeciesBulk_LLF(int SpatDim, IncompressibleMultiphaseBoundaryCondMap _bcmap, string spcName, SpeciesId spcId, int _component, double _rho, double _LFF, LevelSetTracker _lsTrk) : base(SpatDim, _bcmap, _component, false) { // rho = _rho; m_spcId = spcId; ValidSpecies = spcName; //varMode = _varMode; this.lsTrk = _lsTrk; this.LFF = _LFF; this.m_bcmap = _bcmap; int dir = base.m_component; base.velFunction = new Func <double[], double, double> [GridCommons.FIRST_PERIODIC_BC_TAG, SpatDim]; for (int d = 0; d < SpatDim; d++) { base.velFunction.SetColumn(m_bcmap.bndFunction[VariableNames.Velocity_d(d) + "#" + spcName], d); } //SubGrdMask = lsTrk.Regions.GetSpeciesSubGrid(spcId).VolumeMask.GetBitMaskWithExternal(); }
void SetBndfunction(string S) { int D = base.m_D; base.tempFunction = this.m_bcMap.bndFunction[VariableNames.Temperature + "#" + S]; base.fluxFunction = D.ForLoop(d => m_bcMap.bndFunction[VariableNames.HeatFluxVectorComponent(d) + "#" + S]); }
/// <summary> /// Generates the R script which performs the optimization. /// </summary> /// <param name="fileName">File path to which the R code will be saved.</param> /// <param name="outputPath">Directory/path to which output results will be saved. This is passed as a parameter to croptimizR.</param> /// <param name="apsimxFileName">Name of the .apsimx file to be run by the optimisation.</param> private void GenerateRScript(string fileName, string outputPath, string apsimxFileName) { // tbi: package installation. Need to test on a clean VM. StringBuilder contents = new StringBuilder(); contents.AppendLine($"variable_names <- c({string.Join(", ", VariableNames.Select(x => $"'{x.Trim()}'").ToArray())})"); // If we're reading from the PredictedObserved table, need to fix // Predicted./Observed. suffix for the observed variables. string[] sanitisedObservedVariables = GetObservedVariableName().Select(x => $"'{x.Trim()}'").ToArray(); string dateVariable = VariableNames.Any(v => v.StartsWith("Predicted.")) ? "Predicted.Clock.Today" : "Clock.Today"; contents.AppendLine($"observed_variable_names <- c({string.Join(", ", sanitisedObservedVariables)}, '{dateVariable}')"); contents.AppendLine($"apsimx_path <- '{typeof(IModel).Assembly.Location.Replace(@"\", @"\\")}'"); contents.AppendLine($"apsimx_file <- '{apsimxFileName.Replace(@"\", @"\\")}'"); contents.AppendLine($"simulation_names <- {GetSimulationNames()}"); contents.AppendLine($"predicted_table_name <- '{PredictedTableName}'"); contents.AppendLine($"observed_table_name <- '{ObservedTableName}'"); contents.AppendLine($"param_info <- {GetParamInfo()}"); contents.AppendLine(); contents.AppendLine(OptimizationMethod.GenerateOptimizationOptions("optim_options")); contents.AppendLine($"optim_options$path_results <- '{outputPath.Replace(@"\", @"\\")}'"); if (RandomSeed != null) { contents.AppendLine($"optim_options$ranseed <- {RandomSeed}"); } contents.AppendLine(); contents.AppendLine($"crit_function <- {OptimizationMethod.CritFunction}"); contents.AppendLine($"optim_method <- '{OptimizationMethod.ROptimizerName}'"); contents.AppendLine(); contents.Append(ReflectionUtilities.GetResourceAsString("Models.Resources.RScripts.OptimizR.r")); File.WriteAllText(fileName, contents.ToString()); }
/// <summary> /// Spatial Operators and Matrices /// </summary> /// with /// <param name="bcMap">Boundary Conditions</param> public SpatialOperator CreateAdvectionSpatialOperator(IncompressibleBoundaryCondMap bcMap) { Func <int[], int[], int[], int> QuadOrderFunction = QuadOrderFunc.SumOfMaxDegrees(); string[] parameterList; parameterList = ArrayTools.Cat(VariableNames.Velocity0Vector(D), VariableNames.Velocity0MeanVector(D)); if (!divUzero) { parameterList = ArrayTools.Cat(parameterList, "div(U)"); } SpatialOperator SO = new SpatialOperator(new string[] { "LevelSet" }, parameterList, new string[] { "Phi-Evo" }, QuadOrderFunc.NonLinear(2)); //div(u.phi) //SO.EquationComponents["Phi-Evo"].Add(new LevelSetUpwindFlux(GridDat, bcMap)); SO.EquationComponents["Phi-Evo"].Add(new LevelSetLLFFlux(GridDat, bcMap)); //bcMap.PhysMode = PhysicsMode.Multiphase; //SO.EquationComponents["Phi-Evo"].Add(new LinearizedScalarConvection(D, bcMap,null)); //SO.EquationComponents["Phi-Evo"].Add(new LevelSetAdvectionCentralFlux(D)); //-phi*div(u) if (!divUzero) { SO.EquationComponents["Phi-Evo"].Add(new FextSource()); } //penalization //Lsevo.EquationComponents["Phi-Evo"].Add(new JumpPenalization.GradientJumpForm2()); SO.Commit(); return(SO); }
private string[] GetObservedVariableName() { if (PredictedTableName == ObservedTableName) { return(VariableNames.Select(x => x.Replace("Predicted.", "Observed.")).ToArray()); } return(VariableNames); }
/// <summary> /// Based on the Ideas by /// C. Basting and D. Kuzmin, /// “A minimization-based finite element formulation for interface-preserving level set reinitialization”, /// Computing, vol. 95, no. 1, pp. 13–25, Dec. 2012. /// </summary> /// <param name="LSTrck"></param> /// <param name="bcmap">Boundary Conditions for the LevelSet Equations</param> /// <param name="Control">various parameters <paramref name="EllipticReinitControl"/></param> public Extender(SinglePhaseField Extension, LevelSetTracker LSTrck, ILevelSetComponent InterfaceFlux, List <DGField> InterfaceParams, VectorField <SinglePhaseField> LevelSetGradient, EllipticExtVelAlgoControl Control) { if (InterfaceFlux.ParameterOrdering.Count != InterfaceParams.Count) { throw new ArgumentException("Missmatch in Number of Parameters and expected amount in the given flux."); } this.InterfaceParams = InterfaceParams; this.Control = Control; int D = LSTrck.GridDat.SpatialDimension; //this.InterfaceValue = InterfaceValue; //InterfaceValue.Identification = "InterfaceValue"; this.Extension = Extension; this.LevelSetTracker = LSTrck; Phi = LevelSetTracker.LevelSets[0] as LevelSet; this.LevelSetGradient = LevelSetGradient; switch (Control.FluxVariant) { case FluxVariant.GradientBased: // Flux Direction based on Mean Level Set Gradient MeanLevelSetGradient = new VectorField <SinglePhaseField>( D.ForLoop( d => new SinglePhaseField( new Basis(LSTrck.GridDat, 0), VariableNames.MeanLevelSetGradientComponent(d) ) ) ); BulkParams = new List <DGField> { }; BulkParams = ArrayTools.Cat(BulkParams, LevelSetGradient.ToArray(), Phi, MeanLevelSetGradient.ToArray(), InterfaceParams.ToArray()); break; case FluxVariant.ValueBased: // Flux Direction Based on Cell-Averaged Level-Set Value MeanLevelSet = new SinglePhaseField(new Basis(LSTrck.GridDat, 0), "MeanLevelSet"); BulkParams = ArrayTools.Cat(LevelSetGradient.ToArray(), Phi, MeanLevelSet); break; case FluxVariant.SWIP: BulkParams = LevelSetGradient.ToArray(); break; default: throw new NotImplementedException(); } this.D = LevelSetTracker.GridDat.SpatialDimension; double PenaltyBase = Control.PenaltyMultiplierFlux * ((double)((Phi.Basis.Degree + 1) * (Phi.Basis.Degree + D))) / ((double)D); DefineBulkOperator(LSTrck, InterfaceFlux, D, PenaltyBase); Operator_interface = InterfaceFlux.XOperator(QuadOrderFunc.FixedOrder(2 * Extension.Basis.Degree + 2)); }
public swipConductivity(double _penaltyBase, int D, ThermalBoundaryCondMap bcmap) { this.m_penalty_base = _penaltyBase; this.m_D = D; tempFunction = bcmap.bndFunction[VariableNames.Temperature]; fluxFunction = D.ForLoop(d => bcmap.bndFunction[VariableNames.HeatFluxVectorComponent(d)]); EdgeTag2Type = bcmap.EdgeTag2Type; }
public override string ToCSharp(List <string> definedVariables, ConfigSettings settings) { using var writer = new StringWriter(); string scriptHash, scriptPath; var resultName = "tmp_" + VariableNames.RandomName(6); var engineName = "tmp_" + VariableNames.RandomName(6); var scopeName = "tmp_" + VariableNames.RandomName(6); switch (Interpreter) { case Interpreter.Jint: scriptHash = HexConverter.ToHexString(Crypto.MD5(Encoding.UTF8.GetBytes(Script))); scriptPath = $"Scripts/{scriptHash}.{GetScriptFileExtension(Interpreter)}"; if (!Directory.Exists("Scripts")) { Directory.CreateDirectory("Scripts"); } if (!File.Exists(scriptPath)) { File.WriteAllText(scriptPath, Script); } writer.WriteLine($"var {engineName} = new Engine();"); if (!string.IsNullOrWhiteSpace(InputVariables)) { foreach (var input in InputVariables.Split(',')) { writer.WriteLine($"{engineName}.SetValue(nameof({input}), {input});"); } } writer.WriteLine($"{engineName} = InvokeJint(data, {engineName}, \"{scriptPath}\");"); foreach (var output in OutputVariables) { if (!definedVariables.Contains(output.Name)) { writer.Write("var "); } writer.WriteLine($"{output.Name} = {engineName}.Global.GetProperty(\"{output.Name}\").Value.{GetJintMethod(output.Type)};"); } break; case Interpreter.NodeJS: var nodeScript = @$ "module.exports = (callback, {MakeInputs()}) => {{ {Script} var noderesult = {{ {MakeNodeObject()} }}; callback(null, noderesult); }}";
private void OnCommencing(object sender, EventArgs e) { dataToWriteToDb = null; // sanitise the variable names and remove duplicates List <string> variableNames = new List <string>(); variableNames.Add("Parent.Name as Zone"); variableNames.Add("[Clock].Today"); if (VariableNames != null && VariableNames.Count() > 0) { if (VariableNames.Count() > 1) { Summary.WriteWarning(this, String.Format("Multiple resource groups not permitted in ReportResourceLedger [{0}]\nAdditional entries have been ignored", this.Name)); } for (int i = 0; i < 1; i++) { // each variable name is now a ResourceGroup bool isDuplicate = StringUtilities.IndexOfCaseInsensitive(variableNames, this.VariableNames[i].Trim()) != -1; if (!isDuplicate && this.VariableNames[i] != string.Empty) { // check it is a ResourceGroup CLEMModel model = Resources.GetResourceGroupByName(this.VariableNames[i]) as CLEMModel; if (model == null) { Summary.WriteWarning(this, String.Format("Invalid resource group [{0}] in ReportResourceBalances [{1}]\nEntry has been ignored", this.VariableNames[i], this.Name)); } else { if (model.GetType() == typeof(Ruminant)) { variableNames.Add("[Resources]." + this.VariableNames[i] + ".LastTransaction.ExtraInformation.ID as uID"); variableNames.Add("[Resources]." + this.VariableNames[i] + ".LastTransaction.ExtraInformation.Breed as Breed"); variableNames.Add("[Resources]." + this.VariableNames[i] + ".LastTransaction.ExtraInformation.HerdName as Herd"); variableNames.Add("[Resources]." + this.VariableNames[i] + ".LastTransaction.ExtraInformation.GenderAsString as Sex"); variableNames.Add("[Resources]." + this.VariableNames[i] + ".LastTransaction.ExtraInformation.Age as Age"); variableNames.Add("[Resources]." + this.VariableNames[i] + ".LastTransaction.ExtraInformation.Weight as Weight"); variableNames.Add("[Resources]." + this.VariableNames[i] + ".LastTransaction.ExtraInformation.SaleFlagAsString as Reason"); variableNames.Add("[Resources]." + this.VariableNames[i] + ".LastTransaction.ExtraInformation.PopulationChangeDirection as Change"); } else { variableNames.Add("[Resources]." + this.VariableNames[i] + ".LastTransaction.Gain as Gain"); variableNames.Add("[Resources]." + this.VariableNames[i] + ".LastTransaction.Loss * -1.0 as Loss"); variableNames.Add("[Resources]." + this.VariableNames[i] + ".LastTransaction.ResourceType as Resource"); variableNames.Add("[Resources]." + this.VariableNames[i] + ".LastTransaction.Activity as Activity"); variableNames.Add("[Resources]." + this.VariableNames[i] + ".LastTransaction.ActivityType as ActivityType"); variableNames.Add("[Resources]." + this.VariableNames[i] + ".LastTransaction.Reason as Reason"); } } } } events.Subscribe("[Resources]." + this.VariableNames[0] + ".TransactionOccurred", DoOutputEvent); } base.VariableNames = variableNames.ToArray(); this.FindVariableMembers(); }
protected override SpatialOperator GetSpatialOperator(SolverConfiguration SolverConf, int SpatialComponent, int SpatialDirection) { SpatialOperator DivergenceOp = new SpatialOperator(new string[] { VariableNames.Velocity_d(SpatialComponent) }, new string[] { "div_d" }, QuadOrderFunc.Linear()); DivergenceOp.EquationComponents["div_d"].Add(new Divergence_DerivativeSource(SpatialComponent, SolverConf.SpatialDimension)); DivergenceOp.EquationComponents["div_d"].Add(new Divergence_DerivativeSource_Flux(SpatialComponent, SolverConf.BcMap)); DivergenceOp.Commit(); return(DivergenceOp); }
public AuxiliaryStabilizationForm(int _D, ThermalMultiphaseBoundaryCondMap bcMap, string spcName, SpeciesId spcId) { this.m_D = _D; EdgeTag2Type = bcMap.EdgeTag2Type; fluxFunction = m_D.ForLoop(d => bcMap.bndFunction[VariableNames.HeatFluxVectorComponent(d) + "#" + spcName]); this.m_spcId = spcId; //this.ksqrt = Math.Sqrt(_k); }
public override void VisitVariableDeclarationStatement(VariableDeclarationStatement variableDeclarationStatement) { foreach (var variable in variableDeclarationStatement.Variables) { VariableNames.Add(variable.Name); var lrr = (LocalResolveResult)Emitter.Resolver.ResolveNode(variable); Variables.Add(lrr.Variable); } base.VisitVariableDeclarationStatement(variableDeclarationStatement); }
public HeatFluxDivergenceInSpeciesBulk(int D, ThermalMultiphaseBoundaryCondMap bcMap, string spcName, SpeciesId spcId) { this.m_D = D; this.m_spcId = spcId; //this.ksqrt = Math.Sqrt(_k); fluxFunction = D.ForLoop(d => bcMap.bndFunction[VariableNames.HeatFluxVectorComponent(d) + "#" + spcName]); EdgeTag2Type = bcMap.EdgeTag2Type; }
public override void VisitCatchClause(CatchClause catchClause) { if (!ExcludeReadOnly && catchClause.VariableNameToken != null && !catchClause.VariableNameToken.IsNull) { VariableNames.Add(catchClause.VariableName); var lrr = (LocalResolveResult)Emitter.Resolver.ResolveNode(catchClause.VariableNameToken); Variables.Add(lrr.Variable); } base.VisitCatchClause(catchClause); }
public override void VisitForeachStatement(ForeachStatement foreachStatement) { if (foreachStatement.VariableNameToken != null && !foreachStatement.VariableNameToken.IsNull) { VariableNames.Add(foreachStatement.VariableName); var rr = (ForEachResolveResult)Emitter.Resolver.ResolveNode(foreachStatement); Variables.Add(rr.ElementVariable); } base.VisitForeachStatement(foreachStatement); }
/// <summary> /// Generates the R script which performs the optimization. /// </summary> /// <param name="fileName">File path to which the R code will be saved.</param> /// <param name="outputPath">Directory/path to which output results will be saved. This is passed as a parameter to croptimizR.</param> /// <param name="apsimxFileName">Name of the .apsimx file to be run by the optimisation.</param> private void GenerateRScript(string fileName, string outputPath, string apsimxFileName) { // tbi: package installation. Need to test on a clean VM. StringBuilder contents = new StringBuilder(); contents.AppendLine($"variable_names <- c({string.Join(", ", VariableNames.Select(x => $"'{x.Trim()}'").ToArray())})"); // In theory, it would be better to always use relative path to // the input file, by setting the working directory of the R // process appropriately. Unfortunately, this will require some // refactoring of the R wrapper which I don't really want to do // right now. So for now I'm going to just use relative path if // using docker. if (RDocker.UseDocker()) { apsimxFileName = Path.GetFileName(apsimxFileName); } // If we're reading from the PredictedObserved table, need to fix // Predicted./Observed. suffix for the observed variables. string escapedOutputPath = outputPath.Replace(@"\", "/"); string[] sanitisedObservedVariables = GetObservedVariableName().Select(x => $"'{x.Trim()}'").ToArray(); string dateVariable = VariableNames.Any(v => v.StartsWith("Predicted.")) ? "Predicted.Clock.Today" : "Clock.Today"; contents.AppendLine($"observed_variable_names <- c({string.Join(", ", sanitisedObservedVariables)}, '{dateVariable}')"); contents.AppendLine($"apsimx_path <- '{PathToModels().Replace(@"\", "/")}'"); contents.AppendLine($"apsimx_file <- '{apsimxFileName.Replace(@"\", "/")}'"); contents.AppendLine($"simulation_names <- {GetSimulationNames()}"); contents.AppendLine($"predicted_table_name <- '{PredictedTableName}'"); contents.AppendLine($"observed_table_name <- '{ObservedTableName}'"); contents.AppendLine($"param_info <- {GetParamInfo()}"); contents.AppendLine(); contents.AppendLine(OptimizationMethod.GenerateOptimizationOptions("optim_options")); contents.AppendLine($"optim_options$path_results <- '{escapedOutputPath}'"); if (RandomSeed != null) { contents.AppendLine($"optim_options$ranseed <- {RandomSeed}"); } contents.AppendLine(); contents.AppendLine($"crit_function <- {OptimizationMethod.CritFunction}"); contents.AppendLine($"optim_method <- '{OptimizationMethod.ROptimizerName}'"); contents.AppendLine(); contents.AppendLine(ReflectionUtilities.GetResourceAsString("Models.Resources.RScripts.OptimizR.r")); // Don't use Path.Combine() - as this may be running in a (linux) docker container. // R will work with forward slashes for path separators on win and linux, // but backslashes will not work on linux. string rDataExpectedPath = $"{escapedOutputPath}/optim_results.Rdata"; contents.AppendLine(CreateReadRDataScript(rDataExpectedPath)); File.WriteAllText(fileName, contents.ToString()); }
public IDictionary <string, AppControl.BoundaryValueCollection> GetBoundaryConfig() { var config = new Dictionary <string, AppControl.BoundaryValueCollection>(); config.Add("Velocity_Inlet_top", new AppControl.BoundaryValueCollection()); config["Velocity_Inlet_top"].Evaluators.Add( VariableNames.Velocity_d(1) + "#A", (X, t) => U2); config["Velocity_Inlet_top"].Evaluators.Add( VariableNames.Velocity_d(1) + "#B", (X, t) => U2); config.Add("Velocity_Inlet_bottom", new AppControl.BoundaryValueCollection()); config["Velocity_Inlet_bottom"].Evaluators.Add( VariableNames.Velocity_d(1) + "#A", (X, t) => U2); config["Velocity_Inlet_bottom"].Evaluators.Add( VariableNames.Velocity_d(1) + "#B", (X, t) => U2); //config.Add("wall_top", new AppControl.BoundaryValueCollection()); //config.Add("wall_bottom", new AppControl.BoundaryValueCollection()); if (!m_periodic) { Func <double[], double, double> u1Inlet; if (Math.Abs(U2) >= 1.0e-10) { u1Inlet = (X, t) => ((X[1] + 1) / U2 - (2.0 * (1.0 - Math.Exp(U2 * (X[1] + 1) * Rey))) / (U2 * (1 - Math.Exp(2.0 * U2 * Rey)))); } else { u1Inlet = (X, t) => (Rey * 0.5) * (1.0 - X[1] * X[1]); } config.Add("Velocity_Inlet_left", new AppControl.BoundaryValueCollection()); config["Velocity_Inlet_left"].Evaluators.Add( VariableNames.Velocity_d(0) + "#A", u1Inlet); config["Velocity_Inlet_left"].Evaluators.Add( VariableNames.Velocity_d(1) + "#A", (X, t) => U2); config["Velocity_Inlet_left"].Evaluators.Add( VariableNames.Velocity_d(0) + "#B", u1Inlet); config["Velocity_Inlet_left"].Evaluators.Add( VariableNames.Velocity_d(1) + "#B", (X, t) => U2); config.Add("Pressure_Outlet", new AppControl.BoundaryValueCollection()); } return(config); }
void SetBndfunc(string S) { int SpatDim = base.m_SpatialDimension; int dir = base.m_component; base.velFunction = new Func <double[], double, double> [GridCommons.FIRST_PERIODIC_BC_TAG, SpatDim]; for (int d = 0; d < SpatDim; d++) { base.velFunction.SetColumn(m_bcmap.bndFunction[VariableNames.Velocity_d(d) + "#" + S], d); } }
public LStateContext(Prototype pt, ControlFlowGraph cfg, DecompiledLua lua) { this.pt = pt; this.cfg = cfg; this.lua = lua; varNames = new VariableNames(pt.variableNames); upvalues = new BaseConstant[pt.upvalues.Count]; upvalueNames = new string[upvalues.Length]; slots = new BaseConstant[pt.frameSize]; InitUpvalues(); PrepareGlobals(); }
public VelocityGrad_SU(int Component, BoundaryCondMap <IncompressibleBcType> _BcMap) { this.Component = Component; this.m_BcMap = _BcMap; velFunction = new Func <double[], double, double> [GridCommons.FIRST_PERIODIC_BC_TAG, 2]; for (int d = 0; d < 2; d++) { velFunction.SetColumn(m_BcMap.bndFunction[VariableNames.Velocity_d(d)], d); } }
//protected Func<double[], double, double>[] ScalarFunction; public LinearizedConvection(int SpatDim, IncompressibleMultiphaseBoundaryCondMap _bcmap) { m_SpatialDimension = SpatDim; m_bcMap = _bcmap; VelFunction = new Func <double[], double, double> [GridCommons.FIRST_PERIODIC_BC_TAG, SpatDim]; for (int d = 0; d < m_SpatialDimension; d++) { VelFunction.SetColumn(m_bcMap.bndFunction[VariableNames.Velocity_d(d)], d); } //ScalarFunction = m_bcMap.bndFunction["KineticEnergy"]; }
public IncompressibleMultiphaseBoundaryCondMap(IGridData f, IDictionary <string, BoSSS.Solution.Control.AppControl.BoundaryValueCollection> b, string[] SpeciesNames) : base(f, b, PhysicsMode.Incompressible, BndFunctions(f, SpeciesNames)) // { string S0 = "#" + SpeciesNames[0]; int D = f.SpatialDimension; for (int d = 0; d < D; d++) { base.bndFunction.Add(VariableNames.Velocity_d(d), base.bndFunction[VariableNames.Velocity_d(d) + S0]); } base.bndFunction.Add(VariableNames.Pressure, base.bndFunction[VariableNames.Pressure + S0]); }
public LinearizedHeatConvection(int SpatDim, ThermalBoundaryCondMap _bcmap) { m_SpatialDimension = SpatDim; m_bcmap = _bcmap; VelFunction = new Func <double[], double, double> [GridCommons.FIRST_PERIODIC_BC_TAG, SpatDim]; for (int d = 0; d < m_SpatialDimension; d++) { VelFunction.SetColumn(m_bcmap.bndFunction[VariableNames.Velocity_d(d)], d); } TempFunction = m_bcmap.bndFunction[VariableNames.Temperature]; }