/// <summary> /// Test case using <see cref="StiffenedGas"/> in combination with the /// <see cref="RusanovFlux"/>. /// </summary> /// <returns></returns> public static VortexControl IsentropicVortexStiffenedGasRusanov() { VortexControl c = Template(1, 2); double referencePressure = 10.0; c.EquationOfState = new StiffenedGas(1.4, referencePressure); c.ConvectiveFluxType = ConvectiveFluxTypes.Rusanov; double gamma = c.EquationOfState.HeatCapacityRatio; Func <double[], double, double> x = (X, t) => X[0] - c.VortexSpeed * t; Func <double[], double, double> r = (X, t) => Math.Sqrt(x(X, t) * x(X, t) + X[1] * X[1]); Func <double[], double, double> phi = (X, t) => Math.Atan2(X[1], x(X, t)); Func <double[], double, double> rho = (X, t) => Math.Pow( 2.3535468936502524 - 0.5 * (gamma - 1.0) / gamma * Math.Exp(1.0 - r(X, t) * r(X, t)), 1.0 / (gamma - 1.0)); Func <double[], double, double> uAbs = (X, t) => r(X, t) * Math.Exp(0.5 * (1.0 - r(X, t) * r(X, t))); Func <double[], double, double> p = (X, t) => Math.Pow(rho(X, t), gamma) - referencePressure; c.InitialValues_Evaluators.Add(Variables.Density, X => rho(X, 0.0)); c.InitialValues_Evaluators.Add(Variables.Velocity.xComponent, X => c.VortexSpeed - Math.Sin(phi(X, 0.0)) * uAbs(X, 0.0)); c.InitialValues_Evaluators.Add(Variables.Velocity.yComponent, X => Math.Cos(phi(X, 0.0)) * uAbs(X, 0.0)); c.InitialValues_Evaluators.Add(Variables.Pressure, X => p(X, 0.0)); c.Queries.Add("L2ErrorDensity", QueryLibrary.L2Error(Variables.Density, rho)); c.Queries.Add("L2ErrorPressure", QueryLibrary.L2Error(Variables.Pressure, p)); c.Queries.Add("L2ErrorEntropy", QueryLibrary.L2Error(Variables.Entropy, (X, t) => 1.0)); return(c); }
public ActionResult Index( string flowName, string originalName, string connectionName, Dictionary <string, object> model) { var queryLibrary = new QueryLibrary(Request.PhysicalApplicationPath); var queries = queryLibrary.GetQueriesForFlowName(flowName); var query = queries .FirstOrDefault(q => q.OriginalName.Trim().ToLower() == originalName.Trim().ToLower()); if (query == null) { return(new HttpStatusCodeResult(400, "No such query")); } // Get params from model + query var parametersBuilder = new SqlParametersBuilder(); var sqlParameters = parametersBuilder.PopulateSqlParameters(query, model); // Build a DataLayer var connLibrary = new ConnectionLibrary(); if (!connLibrary.HasConnectionWithName(connectionName)) { return(new HttpStatusCodeResult(400, "No such connection")); } var dataLayer = new DataLayer(connectionName); var resultsTable = dataLayer.GetResults(query, sqlParameters); return(Json(resultsTable)); }
public static bool ShouldChargeToFormation(Agent agent) { return(agent.Formation != null && agent.Formation.MovementOrder.OrderType == OrderType.ChargeWithTarget && CommandSystemConfig.Get().AttackSpecificFormation&& (QueryLibrary.IsCavalry(agent) || QueryLibrary.IsRangedCavalry(agent) && agent.Formation.FiringOrder.OrderType == OrderType.HoldFire || CommandSystemSubModule.EnableChargeToFormationForInfantry && (QueryLibrary.IsInfantry(agent) || QueryLibrary.IsRanged(agent) && agent.Formation.FiringOrder.OrderType == OrderType.HoldFire))); }
/// <summary> /// Test cases using an <see cref="IdealGas"/> /// </summary> /// <returns></returns> public static RinglebControl RinglebIdealGasTest() { RinglebControl c = GetTemplate(2, new StiffenedGas(1.4, 0.0)); c.GridGuid = new Guid("499a52ea-9a36-48c4-9c3a-a13d1414b936"); c.ConvectiveFluxType = Convection.ConvectiveFluxTypes.Rusanov; c.Queries.Add("L2ErrorEntropy", QueryLibrary.L2Error(CNSVariables.Entropy, (X, t) => 0.7142857142857142)); return(c); }
public override void Execute(object parameter) { var repository = RepositoryManager.GetRepository(RepositoryManager.Folders); var folderRepository = repository.Entries.FirstOrDefault(); if (folderRepository == null) { return; } var databaseUri = DatabaseUri.Empty; var query = string.Empty; var name = "Folder"; do { var dialog = new QueryDialog(query, databaseUri, name); if (AppHost.Shell.ShowDialog(dialog) != true) { return; } name = dialog.QueryName; databaseUri = dialog.DatabaseUri ?? DatabaseUri.Empty; query = dialog.Query; if (LibraryManager.Libraries.Any(w => string.Compare(w.Name, name, StringComparison.InvariantCultureIgnoreCase) == 0)) { AppHost.MessageBox(string.Format("A folder with the name '{0}' already exists.\n\nPlease choose another name.", name), "Information", MessageBoxButton.OK, MessageBoxImage.Information); } else { break; } }while (true); var fileName = IO.File.GetSafeFileName(name + ".xml"); fileName = Path.Combine(folderRepository.Path, fileName); var folder = new QueryLibrary(fileName, name) { DatabaseUri = databaseUri, Query = query }; folder.Save(); folder.Initialize(); LibraryManager.Add(folder); folder.IsExpanded = true; folder.Refresh(); }
/// <summary> /// Test cases using a <see cref="StiffenedGas"/> /// </summary> /// <returns></returns> public static RinglebControl RinglebStiffenedGasTest() { RinglebControl c = GetTemplate(2, new StiffenedGas(7.0, 10.0)); c.GridGuid = new Guid("f5a0fea5-156d-42ce-abf2-a418469140bb"); c.ConvectiveFluxType = Convection.ConvectiveFluxTypes.Rusanov; c.RinglebReferenceSpeedOfSound = 5.0; c.RinglebReferenceTotalPressure = 30.0; c.Queries.Add("L2ErrorEntropy", QueryLibrary.L2Error(CNSVariables.Entropy, (X, t) => 1.80939686135e-6)); return(c); }
/// <summary> /// Common settings for all tests within this set of test cases /// </summary> /// <param name="dgDegree"></param> /// <param name="eos"></param> /// <returns></returns> private static RinglebControl GetTemplate(int dgDegree, StiffenedGas eos) { RinglebControl c = new RinglebControl(); c.DbPath = "../../Tests/Ringleb/ringlebTests.zip"; c.savetodb = false; c.ActiveOperators = Operators.Convection; c.EquationOfState = eos; c.ExplicitScheme = ExplicitSchemes.RungeKutta; c.ExplicitOrder = 4; c.MachNumber = 1 / Math.Sqrt(c.EquationOfState.HeatCapacityRatio); c.AddVariable(CompressibleVariables.Density, dgDegree); c.AddVariable(CompressibleVariables.Momentum.xComponent, dgDegree); c.AddVariable(CompressibleVariables.Momentum.yComponent, dgDegree); c.AddVariable(CompressibleVariables.Energy, dgDegree); c.AddVariable(CNSVariables.Pressure, dgDegree); c.AddVariable(CNSVariables.Entropy, dgDegree); Func <double[], RinglebExactSolution.FlowState> solution = X => RinglebExactSolution.GetFlowState( X[0], X[1], eos.HeatCapacityRatio, eos.ReferencePressure, c.RinglebReferenceSpeedOfSound, c.RinglebReferenceTotalPressure); c.InitialValues_Evaluators.Add(CompressibleVariables.Density, X => solution(X).Density); c.InitialValues_Evaluators.Add(CompressibleVariables.Momentum.xComponent, X => solution(X).Momentum[0]); c.InitialValues_Evaluators.Add(CompressibleVariables.Momentum.yComponent, X => solution(X).Momentum[1]); c.InitialValues_Evaluators.Add(CompressibleVariables.Energy, X => solution(X).Energy); c.AddBoundaryValue("ringleb"); c.Queries.Add("L2ErrorDensity", QueryLibrary.L2Error(CompressibleVariables.Density, (X, t) => solution(X).Density)); c.Queries.Add("L2ErrorPressure", QueryLibrary.L2Error(CNSVariables.Pressure, (X, t) => solution(X).Pressure)); c.dtMin = 0.0; c.dtMax = 1.0; c.CFLFraction = 0.5; c.Endtime = double.MaxValue; c.NoOfTimesteps = 50; return(c); }
public ActionResult Index() { // TODO Dependency Injection var queryLibrary = new QueryLibrary(Request.PhysicalApplicationPath); var flows = queryLibrary.GetQueryFlows(); var environmentLibrary = new ConnectionLibrary(); var envs = environmentLibrary.GetConnections(); var vm = new SherlockViewModel() { Environments = envs, Flows = flows }; return(Json(vm, JsonRequestBehavior.AllowGet)); }
private static VortexControl IdealGasTemplate(int divisions, int dgDegree) { VortexControl c = Template(divisions, dgDegree); c.EquationOfState = IdealGas.Air; IsentropicVortexExactSolution solution = new IsentropicVortexExactSolution(c, c.VortexSpeed); c.InitialValues_Evaluators.Add(Variables.Density, X => solution.rho()(X, 0.0)); c.InitialValues_Evaluators.Add(Variables.Velocity.xComponent, X => solution.u()(X, 0.0)); c.InitialValues_Evaluators.Add(Variables.Velocity.yComponent, X => solution.v()(X, 0.0)); c.InitialValues_Evaluators.Add(Variables.Pressure, X => solution.p()(X, 0.0)); c.Queries.Add("L2ErrorDensity", QueryLibrary.L2Error(Variables.Density, solution.rho())); c.Queries.Add("L2ErrorPressure", QueryLibrary.L2Error(Variables.Pressure, solution.p())); c.Queries.Add("L2ErrorEntropy", QueryLibrary.L2Error(Variables.Entropy, (X, t) => 1.0)); return(c); }
/// <summary> /// Test case using <see cref="CovolumeGas"/> in combination with the /// <see cref="RusanovFlux"/>. /// </summary> /// <returns></returns> public static VortexControl IsentropicVortexCovolumeGasRusanov() { VortexControl c = Template(1, 2); CovolumeGas eos = new CovolumeGas(1.4, 0.1); double integrationConstant = 3.6; c.EquationOfState = eos; c.ConvectiveFluxType = ConvectiveFluxTypes.Rusanov; Func <double[], double, StateVector> solution = (X, t) => CovolumeVortexExactSolution.GetSolution(X[0], X[1], c.VortexSpeed, t, c, integrationConstant); c.InitialValues_Evaluators.Add(Variables.Density, X => solution(X, 0.0).Density); c.InitialValues_Evaluators.Add(Variables.Velocity.xComponent, X => solution(X, 0.0).Velocity[0]); c.InitialValues_Evaluators.Add(Variables.Velocity.yComponent, X => solution(X, 0.0).Velocity[1]); c.InitialValues_Evaluators.Add(Variables.Pressure, X => solution(X, 0.0).Pressure); c.Queries.Add("L2ErrorDensity", QueryLibrary.L2Error(Variables.Density, (X, t) => solution(X, t).Density, 10)); c.Queries.Add("L2ErrorPressure", QueryLibrary.L2Error(Variables.Pressure, (X, t) => solution(X, t).Pressure, 10)); c.Queries.Add("L2ErrorEntropy", QueryLibrary.L2Error(Variables.Entropy, (X, t) => 1.0, 10)); return(c); }
public static IBMControl IBMAVTimeStepperTest_ShockTube(int explicitScheme, int explicitOrder) { IBMControl c = new IBMControl(); // ### Database ### //string dbPath = @"c:\bosss_db"; //c.DbPath = dbPath; //c.savetodb = dbPath != null; //c.saveperiod = 1; //c.PrintInterval = 1; //c.WriteLTSLog = false; //c.WriteLTSConsoleOutput = true; // ### Partitioning and load balancing ### int dgDegree = 2; int numOfCellsX = 75; int numOfCellsY = 55; double sensorLimit = 1e-3; double dtFixed = 0.0; double CFLFraction = 0.1; int numberOfSubGrids = 1; int reclusteringInterval = 1; int maxNumOfSubSteps = 10; double agg = 0.3; double smoothing = 4.0; // ### Partitioning and load balancing ### c.GridPartType = GridPartType.METIS; c.DynamicLoadBalancing_On = false; // ### Level-set ### c.DomainType = DomainTypes.StaticImmersedBoundary; double xMin = 0; double xMax = 1.5; double yMin = 0; double yMax = 1.1; double[] startOfRamp = new double[] { 0.2, 0.0 }; double[] startOfRamp2 = new double[] { 0.0, 0.2 }; Func <double, double, double> Ramp = delegate(double x, double ang) { return(Math.Tan(ang) * (x - startOfRamp[0]) + startOfRamp[1]); }; Func <double, double, double> Ramp2 = delegate(double x, double ang) { return(Math.Tan(ang) * (x - startOfRamp2[0]) + startOfRamp2[1]); }; double angle = Math.PI / 6; c.LevelSetFunction = (X, t) => - (X[1] - Ramp(X[0], angle)) * (X[1] - Ramp2(X[0], angle)); c.AddVariable(IBMVariables.LevelSet, 2); c.LevelSetBoundaryTag = "AdiabaticSlipWall"; c.CutCellQuadratureType = XQuadFactoryHelper.MomentFittingVariants.OneStepGaussAndStokes; c.LevelSetQuadratureOrder = 3 * dgDegree; c.AgglomerationThreshold = agg; //c.AddVariable(IBMVariables.FluidCells, 1); //c.AddVariable(IBMVariables.FluidCellsWithoutSourceCells, 1); //c.AddVariable(IBMVariables.CutCells, 1); //c.AddVariable(IBMVariables.CutCellsWithoutSourceCells, 1); //c.AddVariable(IBMVariables.SourceCells, 1); // ### Shock-Capturing ### bool AV = false; if (dgDegree >= 1) { AV = true; } if (AV) { c.ActiveOperators = Operators.Convection | Operators.ArtificialViscosity; } else { c.ActiveOperators = Operators.Convection; } c.ConvectiveFluxType = ConvectiveFluxTypes.OptimizedHLLC; double epsilon0 = 1.0; double kappa = 0.5; //double lambdaMax = 2.0; if (AV) { Variable sensorVariable = CompressibleVariables.Density; c.CNSShockSensor = new PerssonSensor(sensorVariable, sensorLimit); c.AddVariable(CNSVariables.ShockSensor, 0); //c.ArtificialViscosityLaw = new SmoothedHeavisideArtificialViscosityLaw(c.ShockSensor, dgDegree, sensorLimit, epsilon0, kappa, lambdaMax: lambdaMax); // fix lambdaMax c.ArtificialViscosityLaw = new SmoothedHeavisideArtificialViscosityLaw(c.CNSShockSensor, dgDegree, sensorLimit, epsilon0, kappa); // dynamic lambdaMax c.AddVariable(CNSVariables.ArtificialViscosity, 2); } // ### Time-Stepping ### c.ExplicitScheme = (ExplicitSchemes)explicitScheme; c.ExplicitOrder = explicitOrder; c.NumberOfSubGrids = numberOfSubGrids; c.ReclusteringInterval = reclusteringInterval; c.forceReclustering = true; c.maxNumOfSubSteps = maxNumOfSubSteps; c.FluxCorrection = false; // ### Physics ### c.EquationOfState = IdealGas.Air; c.MachNumber = 1.0 / Math.Sqrt(c.EquationOfState.HeatCapacityRatio); c.ReynoldsNumber = 1.0; c.PrandtlNumber = 0.71; // ### Output variables ### c.AddVariable(CompressibleVariables.Density, dgDegree); c.AddVariable(CompressibleVariables.Momentum.xComponent, dgDegree); c.AddVariable(CompressibleVariables.Momentum.yComponent, dgDegree); c.AddVariable(CompressibleVariables.Energy, dgDegree); //c.AddVariable(CNSVariables.Velocity.xComponent, dgDegree); //c.AddVariable(CNSVariables.Velocity.yComponent, dgDegree); //c.AddVariable(CNSVariables.Pressure, dgDegree); //c.AddVariable(CNSVariables.Entropy, dgDegree); //c.AddVariable(CNSVariables.LocalMachNumber, dgDegree); //c.AddVariable(CNSVariables.CFL, 0); //c.AddVariable(CNSVariables.CFLConvective, 0); //if (AV) { // c.AddVariable(CNSVariables.CFLArtificialViscosity, 0); //} //if (c.ExplicitScheme.Equals(ExplicitSchemes.LTS)) { // c.AddVariable(CNSVariables.LTSClusters, 0); //} //c.AddVariable(CNSVariables.Rank, 0); // ### Grid ### c.GridFunc = delegate { double[] xNodes = GenericBlas.Linspace(xMin, xMax, numOfCellsX + 1); double[] yNodes = GenericBlas.Linspace(yMin, yMax, numOfCellsY + 1); var grid = Grid2D.Cartesian2DGrid(xNodes, yNodes, periodicX: false, periodicY: false); grid.EdgeTagNames.Add(1, "AdiabaticSlipWall"); grid.DefineEdgeTags(X => 1); return(grid); }; // ### Boundary conditions ### c.AddBoundaryValue("AdiabaticSlipWall"); // ### Initial smoothing ### double shockAngle = angle + Math.PI / 2; double lengthMiddleLine = (xMax - xMin) / Math.Cos(angle); double shockPosX = 0.5 * lengthMiddleLine * Math.Cos(angle) + xMin; double cellSize = Math.Min((xMax - xMin) / numOfCellsX, (yMax - yMin) / numOfCellsY); double DistanceToInitialShock(double[] X, double t) { // direction vector Vector p1 = new Vector(shockPosX, Ramp(shockPosX, angle)); Vector p2 = new Vector(p1.x - 0.1, p1.y + 0.1 / Math.Tan(angle)); Vector p = p2 - p1; // normal vector Vector n = new Vector(p.y, -p.x); n.Normalize(); // Angle between line and x-axis double alpha = shockAngle; // distance of a point X to the origin (normal to the line) double nDotX = n.x * X[0] + n.y * X[1]; // distance to line double distance = nDotX - (0.5 * lengthMiddleLine + xMin / Math.Cos(angle)); return(distance); } // Function for smoothing the initial and top boundary conditions double SmoothJump(double distance) { // smoothing should be in the range of h/p double maxDistance = smoothing * cellSize / Math.Max(dgDegree, 1); return((Math.Tanh(distance / maxDistance) + 1.0) * 0.5); } // ### Initial conditions ### double densityLeft = 1.0; double densityRight = 0.125; double pressureLeft = 1.0; double pressureRight = 0.1; double velocityX = 0.0; double velocityY = 0.0; double discontinuityPosition = 0.5; Func <double, double> Jump = x => x <= discontinuityPosition ? 0 : 1; c.InitialValues_Evaluators.Add(CompressibleVariables.Density, X => densityLeft - SmoothJump(DistanceToInitialShock(X, t: 0.0)) * (densityLeft - densityRight)); c.InitialValues_Evaluators.Add(CNSVariables.Pressure, X => pressureLeft - SmoothJump(DistanceToInitialShock(X, t: 0.0)) * (pressureLeft - pressureRight)); c.InitialValues_Evaluators.Add(CNSVariables.Velocity.xComponent, X => velocityX); c.InitialValues_Evaluators.Add(CNSVariables.Velocity.yComponent, X => velocityY); // ### Time configuration ### c.dtMin = 0.0; c.dtMax = 1.0; if (dtFixed != 0.0) { c.dtFixed = dtFixed; } else { c.CFLFraction = CFLFraction; } c.Endtime = 0.25; c.NoOfTimesteps = 10; // ### Project and sessions name ### c.ProjectName = "IBM_AV_LTS_Test"; string tempSessionName; if (c.ExplicitScheme == ExplicitSchemes.LTS) { tempSessionName = String.Format("IBMST_p{0}_xCells{1}_yCells{2}_agg{3}_s0={4:0.0E-00}_CFLFrac{5}_ALTS{6}_{7}_re{8}_subs{9}_smooth{10}", dgDegree, numOfCellsX, numOfCellsY, c.AgglomerationThreshold, sensorLimit, c.CFLFraction, c.ExplicitOrder, c.NumberOfSubGrids, c.ReclusteringInterval, c.maxNumOfSubSteps, smoothing); } else if (c.ExplicitScheme == ExplicitSchemes.RungeKutta) { tempSessionName = String.Format("IBMST_p{0}_xCells{1}_yCells{2}_agg{3}_s0={4:0.0E-00}_CFLFrac{5}_RK{6}_smooth{7}", dgDegree, numOfCellsX, numOfCellsY, c.AgglomerationThreshold, sensorLimit, c.CFLFraction, c.ExplicitOrder, smoothing); } else if (c.ExplicitScheme == ExplicitSchemes.AdamsBashforth) { tempSessionName = String.Format("IBMST_p{0}_xCells{1}_yCells{2}_agg{3}_s0={4:0.0E-00}_CFLFrac{5}_AB{6}_smooth{7}", dgDegree, numOfCellsX, numOfCellsY, c.AgglomerationThreshold, sensorLimit, c.CFLFraction, c.ExplicitOrder, smoothing); } else { throw new NotImplementedException("Session name is not available for this type of time stepper"); } // Queries for comparison c.Queries.Add("L2NormDensity", QueryLibrary.L2Norm(CompressibleVariables.Density.Name)); return(c); }
static void Main(string[] args) { var getter = new InputGetter(); var queryLib = new QueryLibrary(); bool shopping = true; do { Console.WriteLine("What would you like to do?"); Console.WriteLine("1. Place an order (You need to provide Customer ID and Store ID)."); Console.WriteLine("2. Add a new customer."); Console.WriteLine("3. Search customers by name (first and last)."); Console.WriteLine("4. Display all order history items of a store location (By store ID)."); Console.WriteLine("5. Display all order history items of a customer (By customer ID)."); Console.WriteLine("6. Display all store locations."); Console.WriteLine("7. Display all customers."); Console.WriteLine("8. Display all order history items."); Console.WriteLine("9. Quit"); int action = getter.GetInputInt("Input a number: "); switch (action) { case 1: Customer customer = null; while (customer == null) { int cid = getter.GetInputInt("Input the customer's ID: "); customer = queryLib.GetCustomer(cid); } Console.WriteLine("Hello " + customer.FirstName + " " + customer.LastName); Store store = null; while (store == null) { int storeID = getter.GetInputInt("Input the store's ID: "); store = queryLib.GetStore(storeID); } Console.WriteLine("Welcome to " + store.Name); queryLib.PrintStoreProducts(store); var cart = queryLib.CreateShoppingCart(store); queryLib.PlaceOrder(store, customer, cart); break; case 2: string first = getter.GetInputString("Please enter the new customer's first name: "); string last = getter.GetInputString("Please enter the new customer's last name: "); int cnum = getter.GetInputInt("Please enter the new customer's card number: "); queryLib.AddCustomer(first, last, cnum); break; case 3: Customer cFind = null; while (cFind == null) { string fname = getter.GetInputString("Please enter the customer's first name: "); string lname = getter.GetInputString("Please enter the customer's last name: "); cFind = queryLib.GetCustomer(fname, lname); } Console.WriteLine("Here's your customer's information."); Console.WriteLine("ID: " + cFind.Id + ", Name: " + cFind.FirstName + " " + cFind.LastName + ", Card Number: " + cFind.CardNumber); break; case 4: Store location = null; while (location == null) { int sid = getter.GetInputInt("Please enter the store's ID: "); location = queryLib.GetStore(sid); } queryLib.StoreOrderHistory(location); break; case 5: Customer valuedCustomer = null; while (valuedCustomer == null) { int vid = getter.GetInputInt("Please enter the customer's ID: "); valuedCustomer = queryLib.GetCustomer(vid); } queryLib.CustomerOrderHistory(valuedCustomer); break; case 6: var storeLocs = queryLib.GetAllStoreLocations(); foreach (var sl in storeLocs) { Console.WriteLine(sl); } break; case 7: var customers = queryLib.GetAllCustomers(); foreach (var item in customers) { Console.WriteLine("Customer ID: " + item.Id + ", First Name: " + item.FirstName + ", Last Name: " + item.LastName + ", Card Number: " + item.CardNumber); } break; case 8: var orderHistoryItems = queryLib.GetAllOrderHistoryItems(); foreach (var item in orderHistoryItems) { Console.WriteLine("Order ID: " + item.Id + ", Store ID: " + item.StoreId + ", Customer ID: " + item.CustomerId + " Order Date: " + item.OrderDate + ", Total: $" + item.Total); } break; default: shopping = false; break; } Console.WriteLine(); }while (shopping); }
private static IBMControl CylinderControl(int dgDegree, double endTime) { string dbPath = @"..\..\Tests\IBMTests\IBMCylinderTests.zip"; double Mach = 0.2; double agglomerationThreshold = 0.3; int gridSize = 64; var restartData = new Dictionary <int, Tuple <Guid, Guid, Guid> >() { { 0, Tuple.Create(new Guid("ae64096b-bab4-4f63-a2cd-99f5920a11e3"), new Guid("486113d4-e700-4bdb-9f92-38a15bac5388"), new Guid("6adec616-275a-444d-86ad-1b2bc8b8cd65")) }, { 1, Tuple.Create(new Guid("083a99ee-af0b-4948-bd0f-1f972b551b99"), new Guid("4f4e6e60-953a-43c3-b062-c4750ab0ab71"), new Guid("d0615daf-6980-4ecf-af3f-e803877fc29b")) }, { 2, Tuple.Create(new Guid("d102c10a-0ef2-417e-af1b-4ffad5ea4fe3"), new Guid("f67d08be-3ede-4d74-9a40-829071b44e6b"), new Guid("dfe950aa-9a6b-43d4-b046-e5dd61cc67f3")) }, { 3, Tuple.Create(new Guid("f45e8802-4e78-45b5-9aac-c155c532b6a3"), new Guid("e670a74f-efb7-41d6-959c-28289e66904e"), new Guid("02e3f737-3f03-4b5a-9387-109dd0f4ec06")) } }; IBMControl c = new IBMControl(); c.DbPath = dbPath; c.savetodb = false; int levelSetQuadratureOrder = 2 * dgDegree + 2; // kind-of-fix c.ProjectName = String.Format("IBM cylinder: {0} cells, order {1}", gridSize, dgDegree); c.ProjectDescription = String.Format( "Flow around cylinder represented by a level set at Mach {0}" + " with cell agglomeration threshold {1} and {2}th order" + " HMF quadrature (classic variant)", Mach, agglomerationThreshold, levelSetQuadratureOrder); c.Tags.Add("Cylinder"); c.Tags.Add("IBM"); c.Tags.Add("Agglomeration"); c.DomainType = DomainTypes.StaticImmersedBoundary; c.ActiveOperators = Operators.Convection; c.ConvectiveFluxType = ConvectiveFluxTypes.OptimizedHLLC; c.ExplicitScheme = ExplicitSchemes.RungeKutta; c.ExplicitOrder = 1; c.EquationOfState = IdealGas.Air; c.MachNumber = 1.0 / Math.Sqrt(c.EquationOfState.HeatCapacityRatio); c.AddVariable(Variables.Density, dgDegree); c.AddVariable(Variables.Momentum.xComponent, dgDegree); c.AddVariable(Variables.Momentum.yComponent, dgDegree); c.AddVariable(Variables.Energy, dgDegree); c.AddVariable(IBMVariables.LevelSet, 2); var sessionAndGridGuid = restartData[dgDegree]; c.RestartInfo = new Tuple <Guid, TimestepNumber>(sessionAndGridGuid.Item1, -1); c.GridGuid = sessionAndGridGuid.Item2; c.GridPartType = GridPartType.METIS; c.GridPartOptions = "5"; double gamma = c.EquationOfState.HeatCapacityRatio; c.AddBoundaryValue("supersonicInlet", Variables.Density, (X, t) => 1.0); c.AddBoundaryValue("supersonicInlet", Variables.Velocity[0], (X, t) => Mach * Math.Sqrt(gamma)); c.AddBoundaryValue("supersonicInlet", Variables.Velocity[1], (X, t) => 0.0); c.AddBoundaryValue("supersonicInlet", Variables.Pressure, (X, t) => 1.0); c.AddBoundaryValue("adiabaticSlipWall"); c.LevelSetBoundaryTag = "adiabaticSlipWall"; c.Queries.Add("L2ErrorEntropy", IBMQueries.L2Error(state => state.Entropy, (X, t) => 1.0)); c.Queries.Add("L2ErrorDensity", QueryLibrary.L2Error(Variables.Density, sessionAndGridGuid.Item3)); c.Queries.Add("L2ErrorXMomentum", QueryLibrary.L2Error(Variables.Momentum[0], sessionAndGridGuid.Item3)); c.Queries.Add("L2ErrorYMomentum", QueryLibrary.L2Error(Variables.Momentum[1], sessionAndGridGuid.Item3)); c.Queries.Add("L2ErrorEnergy", QueryLibrary.L2Error(Variables.Energy, sessionAndGridGuid.Item3)); c.CutCellQuadratureType = XQuadFactoryHelper.MomentFittingVariants.OneStepGaussAndStokes; c.SurfaceHMF_ProjectNodesToLevelSet = false; c.SurfaceHMF_RestrictNodes = true; c.SurfaceHMF_UseGaussNodes = false; c.VolumeHMF_NodeCountSafetyFactor = 5.0; c.VolumeHMF_RestrictNodes = true; c.VolumeHMF_UseGaussNodes = false; c.LevelSetQuadratureOrder = levelSetQuadratureOrder; c.AgglomerationThreshold = agglomerationThreshold; c.dtMin = 0.0; c.dtMax = 1.0; c.CFLFraction = 0.3; c.Endtime = endTime; c.NoOfTimesteps = int.MaxValue; c.PrintInterval = 1; c.ResidualLoggerType = ResidualLoggerTypes.None; c.Paramstudy_CaseIdentification = new Tuple <string, object>[] { new Tuple <string, object>("dgDegree", dgDegree), }; return(c); }
/// <summary> /// 1D Manufactured solution for the Euler equations with variable Mach number /// </summary> /// <param name="dgDegree"></param> /// <param name="noOfCellsPerDirection"></param> /// <returns></returns> public static CNSControl Euler1D(int dgDegree, int noOfCellsPerDirection) { CNSControl c = new CNSControl(); c.PrintInterval = 1; c.ResidualInterval = 1; c.saveperiod = 1; c.DbPath = @""; c.savetodb = false; c.Tags.Add("MMS"); c.ActiveOperators = Operators.Convection | Operators.CustomSource; c.ConvectiveFluxType = ConvectiveFluxTypes.Rusanov; c.ExplicitScheme = ExplicitSchemes.RungeKutta; c.ExplicitOrder = 1; c.EquationOfState = IdealGas.Air; c.AddVariable(Variables.Density, dgDegree); c.AddVariable(Variables.Momentum.xComponent, dgDegree); c.AddVariable(Variables.Energy, dgDegree); c.AddVariable(Variables.Velocity.xComponent, dgDegree); c.AddVariable(Variables.Pressure, dgDegree); c.AddVariable(Variables.LocalMachNumber, dgDegree); c.GridFunc = delegate { double[] nodes = GenericBlas.Linspace(0.0, 1.0, noOfCellsPerDirection + 1); var grid = Grid1D.LineGrid(nodes); grid.EdgeTagNames.Add(1, "supersonicinlet"); grid.DefineEdgeTags(X => 1); return(grid); }; double gamma = c.EquationOfState.HeatCapacityRatio; c.MachNumber = 1 / Math.Sqrt(gamma); double a = 2.0 * Math.PI; double b = 0.25; double c1 = 2.0; double MachScaling = (gamma * c.MachNumber * c.MachNumber); Func <double[], double, double> rho = (X, t) => c1 + b * Math.Sin(a * X[0]); Func <double[], double, double> m0 = (X, t) => c1 + b * Math.Sin(a * X[0]); Func <double[], double, double> rhoE = (X, t) => (c1 + b * Math.Sin(a * X[0])) * (c1 + b * Math.Sin(a * X[0])); Func <double[], double, double> u0 = (X, t) => 1; Func <double[], double, double> p = (X, t) => (gamma - 1) * (rhoE(X, t) - 0.5 * MachScaling * rho(X, t) * u0(X, t) * u0(X, t)); c.InitialValues_Evaluators.Add(Variables.Density, X => rho(X, 0.0)); c.InitialValues_Evaluators.Add(Variables.Momentum.xComponent, X => m0(X, 0.0)); c.InitialValues_Evaluators.Add(Variables.Energy, X => rhoE(X, 0.0)); c.AddBoundaryCondition("supersonicInlet", Variables.Density, rho); c.AddBoundaryCondition("supersonicInlet", Variables.Velocity.xComponent, u0); c.AddBoundaryCondition("supersonicInlet", Variables.Pressure, p); // MMS Sources c.CustomContinuitySources.Add(map => new AdHocSourceTerm(map, (X, t, state) => - (a * b * Math.Cos(a * X[0])) )); c.CustomMomentumSources[0].Add(map => new AdHocSourceTerm(map, (X, t, state) => - ((a * b * Math.Cos(a * X[0])) * (1 + (gamma - 1) / MachScaling * (2 * rho(X, t) - 0.5 * MachScaling))) )); c.CustomEnergySources.Add(map => new AdHocSourceTerm(map, (X, t, state) => - ((a * b * Math.Cos(a * X[0])) * (2 * rho(X, t) + (gamma - 1) * (2 * rho(X, t) - 0.5 * MachScaling))) )); c.Queries.Add("L2ErrorDensity", QueryLibrary.L2Error(Variables.Density, rho)); c.Queries.Add("L2ErrorPressure", QueryLibrary.L2Error(Variables.Pressure, p)); c.Queries.Add("L2ErrorVelocity", QueryLibrary.L2Error(Variables.Velocity.xComponent, u0)); c.dtMin = 0.0; c.dtMax = 1.0; c.CFLFraction = 0.4; c.Endtime = 10000.0; c.NoOfTimesteps = int.MaxValue; c.ResidualLoggerType = ResidualLoggerTypes.ChangeRate | ResidualLoggerTypes.Query; c.ResidualBasedTerminationCriteria.Add("changeRate_abs_rhoE", 1E-14); c.ProjectName = "MMS_Euler1D_Flux=" + c.ConvectiveFluxType + "dg=" + dgDegree + "_cells=" + noOfCellsPerDirection; return(c); }
/// <summary> /// Template for all shock tube tests /// </summary> /// <param name="convectiveFlux"></param> /// <param name="densityLeft"></param> /// <param name="velocityLeft"></param> /// <param name="pressureLeft"></param> /// <param name="densityRight"></param> /// <param name="velocityRight"></param> /// <param name="pressureRight"></param> /// <param name="discontinuityPosition"></param> /// <returns></returns> private static CNSControl GetShockTubeControlTemplate(ConvectiveFluxTypes convectiveFlux, double densityLeft, double velocityLeft, double pressureLeft, double densityRight, double velocityRight, double pressureRight, double discontinuityPosition) { CNSControl c = new CNSControl(); c.DbPath = null; c.savetodb = false; c.ActiveOperators = Operators.Convection; c.ConvectiveFluxType = convectiveFlux; c.EquationOfState = IdealGas.Air; c.MachNumber = 1.0 / Math.Sqrt(c.EquationOfState.HeatCapacityRatio); c.ExplicitScheme = ExplicitSchemes.RungeKutta; c.ExplicitOrder = 1; int dgDegree = 0; c.AddVariable(Variables.Density, dgDegree); c.AddVariable(Variables.Momentum.xComponent, dgDegree); c.AddVariable(Variables.Energy, dgDegree); c.AddVariable(Variables.Pressure, dgDegree); c.AddVariable(Variables.Velocity.xComponent, dgDegree); c.GridFunc = delegate { double[] xNodes = GenericBlas.Linspace(0.0, 1.0, 201); var grid = Grid1D.LineGrid(xNodes, false); grid.EdgeTagNames.Add(1, "supersonicOutlet"); grid.DefineEdgeTags(X => 1); return(grid); }; // Take inner values everywhere c.AddBoundaryCondition("supersonicOutlet"); Material material = new Material(c); StateVector stateLeft = StateVector.FromPrimitiveQuantities( material, densityLeft, new Vector3D(velocityLeft, 0.0, 0.0), pressureLeft); StateVector stateRight = StateVector.FromPrimitiveQuantities( material, densityRight, new Vector3D(velocityRight, 0.0, 0.0), pressureRight); c.InitialValues_Evaluators.Add( Variables.Density, X => stateLeft.Density + (stateRight.Density - stateLeft.Density) * (X[0] - discontinuityPosition).Heaviside()); c.InitialValues_Evaluators.Add( Variables.Velocity.xComponent, X => stateLeft.Velocity.x + (stateRight.Velocity.x - stateLeft.Velocity.x) * (X[0] - discontinuityPosition).Heaviside()); c.InitialValues_Evaluators.Add( Variables.Pressure, X => stateLeft.Pressure + (stateRight.Pressure - stateLeft.Pressure) * (X[0] - discontinuityPosition).Heaviside()); var riemannSolver = new ExactRiemannSolver(stateLeft, stateRight, new Vector3D(1.0, 0.0, 0.0)); double pStar, uStar; riemannSolver.GetStarRegionValues(out pStar, out uStar); c.Queries.Add("L2ErrorDensity", QueryLibrary.L2Error( Variables.Density, (X, t) => riemannSolver.GetState(pStar, uStar, X[0] - discontinuityPosition, t).Density)); c.Queries.Add("L2ErrorVelocity", QueryLibrary.L2Error( Variables.Velocity.xComponent, (X, t) => riemannSolver.GetState(pStar, uStar, X[0] - discontinuityPosition, t).Velocity.x)); c.Queries.Add("L2ErrorPressure", QueryLibrary.L2Error( Variables.Pressure, (X, t) => riemannSolver.GetState(pStar, uStar, X[0] - discontinuityPosition, t).Pressure)); c.dtMin = 0.0; c.dtMax = 1.0; c.CFLFraction = 0.5; c.NoOfTimesteps = int.MaxValue; c.PrintInterval = 50; return(c); }
private static CNSControl[] GetTemplates() { int minDivisions = 0; int maxDivisions = 2; int minDegree = 0; int maxDegree = 3; List <CNSControl> result = new List <CNSControl>(); for (int dgDegree = minDegree; dgDegree <= maxDegree; dgDegree++) { for (int divisions = minDivisions; divisions <= maxDivisions; divisions++) { CNSControl c = new CNSControl(); //c.DbPath = @"c:\bosss_dbv2\exp"; c.savetodb = false; int noOfCells = (2 << divisions) * 8; c.PrintInterval = 1000; c.ResidualInterval = 100; c.saveperiod = 100000; c.ActiveOperators = Operators.Convection | Operators.CustomSource; c.ConvectiveFluxType = ConvectiveFluxTypes.OptimizedHLLC; c.ExplicitScheme = ExplicitSchemes.RungeKutta; c.ExplicitOrder = 1; c.EquationOfState = IdealGas.Air; double gamma = c.EquationOfState.HeatCapacityRatio; c.MachNumber = 1.0; double MaSquared = c.MachNumber * c.MachNumber; c.AddVariable(Variables.Density, dgDegree); c.AddVariable(Variables.Momentum.xComponent, dgDegree); c.AddVariable(Variables.Energy, dgDegree); c.AddVariable(Variables.Velocity.xComponent, dgDegree); c.AddVariable(Variables.Pressure, dgDegree); c.AddVariable(Variables.LocalMachNumber, dgDegree); Func <double[], double> exactDensity = X => (2.0 + Math.Cos(2 * X[0])) / 2.0; Func <double[], double> exactMomentum = X => (7.0 - Math.Cos(4.0 * X[0])) / 16.0; Func <double[], double> exactEnergy = X => (25.0 + 7.0 / 16.0 * MaSquared * (-2.0 + Math.Cos(2.0 * X[0])) * (-2.0 + Math.Cos(2.0 * X[0]))) * (2.0 + Math.Cos(2.0 * X[0])) / 20.0; // Add all types of boundary conditions for convenience Func <double[], double> exactVelocity = X => exactMomentum(X) / exactDensity(X); Func <double[], double> exactPressure = X => 1 + Math.Cos(2.0 * X[0]) / 2; c.InitialValues_Evaluators.Add(Variables.Density, exactDensity); c.InitialValues_Evaluators.Add(Variables.Velocity.xComponent, exactVelocity); c.InitialValues_Evaluators.Add(Variables.Pressure, exactPressure); c.AddBoundaryCondition("supersonicInlet", Variables.Density, exactDensity); c.AddBoundaryCondition("supersonicInlet", Variables.Velocity[0], exactVelocity); c.AddBoundaryCondition("supersonicInlet", Variables.Pressure, exactPressure); c.AddBoundaryCondition("subsonicInlet", Variables.Density, exactDensity); c.AddBoundaryCondition("subsonicInlet", Variables.Velocity[0], exactVelocity); c.AddBoundaryCondition("subsonicOutlet", Variables.Pressure, exactPressure); Func <double[], double> localMach = X => c.MachNumber * exactVelocity(X) / (Math.Sqrt(exactPressure(X) / exactDensity(X))); // Spurk: p305, eq(9.100) Func <double[], double> totalPressure = X => exactPressure(X) * Math.Pow((gamma - 1.0) / 2 * localMach(X) * localMach(X) + 1.0, gamma / (gamma - 1.0)); // Spurk: p305, eq(9.101) Func <double[], double> totalTemperature = X => exactPressure(X) / exactDensity(X) * ((gamma - 1.0) / 2 * localMach(X) * localMach(X) + 1.0); c.AddBoundaryCondition("subsonicPressureInlet", "p0", totalPressure); c.AddBoundaryCondition("subsonicPressureInlet", "T0", totalTemperature); c.CustomContinuitySources.Add(map => new AdHocSourceTerm(map, (x, t, state) => - Math.Sin(4.0 * x[0]) / 4.0)); c.CustomMomentumSources[0].Add(map => new AdHocSourceTerm(map, (x, t, state) => (160.0 - 35.0 * MaSquared - 56.0 * MaSquared * Math.Cos(2.0 * x[0]) + 21.0 * MaSquared * Math.Cos(4.0 * x[0])) * Math.Sin(2.0 * x[0]) / (224.0 * MaSquared))); c.CustomEnergySources.Add(map => new AdHocSourceTerm(map, (x, t, state) => - (7.0 / 640.0) * Math.Sin(2 * x[0]) * ((160.0 + 3.0 * MaSquared) * Math.Cos(2 * x[0]) + MaSquared * (10.0 - 6.0 * Math.Cos(4.0 * x[0]) + Math.Cos(6.0 * x[0]))))); c.Queries.Add("densityError", QueryLibrary.L2Error(Variables.Density, exactDensity, 10)); c.Queries.Add("momentumError", QueryLibrary.L2Error(Variables.Momentum[0], exactMomentum, 10)); c.Queries.Add("energyError", QueryLibrary.L2Error(Variables.Energy, exactEnergy, 10)); c.Paramstudy_CaseIdentification = new Tuple <string, object>[] { new Tuple <string, object>("divisions", divisions), new Tuple <string, object>("dgDegree", dgDegree) }; c.ResidualLoggerType = ResidualLoggerTypes.ChangeRate | ResidualLoggerTypes.Query; c.ResidualBasedTerminationCriteria.Add("changeRate_abs_rhoE", 1E-9); c.dtMin = 0.0; c.dtMax = 1.0; c.CFLFraction = 0.1; c.Endtime = 10000; c.NoOfTimesteps = 1000000; c.ProjectName = "MMS1D_Euler_Mach=" + c.MachNumber + "_dg=" + dgDegree + "_cells=" + noOfCells; result.Add(c); } } return(result.ToArray()); }
/// <summary> /// Template of the control file for all shock tube tests using artificial viscosity /// </summary> /// <param name="convectiveFlux"></param> /// <param name="densityLeft"></param> /// <param name="velocityLeft"></param> /// <param name="pressureLeft"></param> /// <param name="densityRight"></param> /// <param name="velocityRight"></param> /// <param name="pressureRight"></param> /// <param name="discontinuityPosition"></param> /// <param name="explicitScheme"></param> /// <param name="explicitOrder"></param> /// <param name="numOfClusters"></param> /// <returns></returns> private static CNSControl GetArtificialViscosityShockTubeControlTemplate(ConvectiveFluxTypes convectiveFlux, double densityLeft, double velocityLeft, double pressureLeft, double densityRight, double velocityRight, double pressureRight, double discontinuityPosition, ExplicitSchemes explicitScheme, int explicitOrder, int numOfClusters) { CNSControl c = new CNSControl(); c.DbPath = null; c.savetodb = false; //c.DbPath = @"c:\bosss_db\"; //c.savetodb = true; //c.saveperiod = 100; //c.PrintInterval = 100; c.ActiveOperators = Operators.Convection | Operators.ArtificialViscosity; c.ConvectiveFluxType = convectiveFlux; c.EquationOfState = IdealGas.Air; c.MachNumber = 1.0 / Math.Sqrt(c.EquationOfState.HeatCapacityRatio); c.ReynoldsNumber = 1.0; c.PrandtlNumber = 0.71; // Time stepping scheme c.ExplicitScheme = explicitScheme; c.ExplicitOrder = explicitOrder; if (explicitScheme == ExplicitSchemes.LTS) { c.NumberOfSubGrids = numOfClusters; c.ReclusteringInterval = 1; c.FluxCorrection = false; } int dgDegree = 3; int noOfCellsPerDirection = 50; double sensorLimit = 1e-4; double epsilon0 = 1.0; double kappa = 0.5; Variable sensorVariable = Variables.Density; c.ShockSensor = new PerssonSensor(sensorVariable, sensorLimit); c.ArtificialViscosityLaw = new SmoothedHeavisideArtificialViscosityLaw(c.ShockSensor, dgDegree, sensorLimit, epsilon0, kappa); c.AddVariable(Variables.Density, dgDegree); c.AddVariable(Variables.Momentum.xComponent, dgDegree); c.AddVariable(Variables.Energy, dgDegree); c.AddVariable(Variables.Velocity.xComponent, dgDegree); c.AddVariable(Variables.Pressure, dgDegree); c.AddVariable(Variables.Entropy, dgDegree); c.AddVariable(Variables.Viscosity, dgDegree); c.AddVariable(Variables.ArtificialViscosity, 1); //c.AddVariable(Variables.Sensor, dgDegree); c.AddVariable(Variables.LocalMachNumber, dgDegree); if (c.ExplicitScheme.Equals(ExplicitSchemes.LTS)) { c.AddVariable(Variables.LTSClusters, 0); } c.GridFunc = delegate { double[] xNodes = GenericBlas.Linspace(0.0, 1.0, noOfCellsPerDirection + 1); var grid = Grid1D.LineGrid(xNodes, periodic: false); // Boundary conditions grid.EdgeTagNames.Add(1, "AdiabaticSlipWall"); grid.DefineEdgeTags(delegate(double[] _X) { return(1); }); return(grid); }; c.AddBoundaryCondition("AdiabaticSlipWall"); Material material = new Material(c); StateVector stateLeft = StateVector.FromPrimitiveQuantities( material, densityLeft, new Vector3D(velocityLeft, 0.0, 0.0), pressureLeft); StateVector stateRight = StateVector.FromPrimitiveQuantities( material, densityRight, new Vector3D(velocityRight, 0.0, 0.0), pressureRight); c.InitialValues_Evaluators.Add( Variables.Density, X => stateLeft.Density + (stateRight.Density - stateLeft.Density) * (X[0] - discontinuityPosition).Heaviside()); c.InitialValues_Evaluators.Add( Variables.Velocity.xComponent, X => stateLeft.Velocity.x + (stateRight.Velocity.x - stateLeft.Velocity.x) * (X[0] - discontinuityPosition).Heaviside()); c.InitialValues_Evaluators.Add( Variables.Pressure, X => stateLeft.Pressure + (stateRight.Pressure - stateLeft.Pressure) * (X[0] - discontinuityPosition).Heaviside()); var riemannSolver = new ExactRiemannSolver(stateLeft, stateRight, new Vector3D(1.0, 0.0, 0.0)); double pStar, uStar; riemannSolver.GetStarRegionValues(out pStar, out uStar); c.Queries.Add("L2ErrorDensity", QueryLibrary.L2Error( Variables.Density, (X, t) => riemannSolver.GetState(pStar, uStar, X[0] - discontinuityPosition, t).Density)); c.Queries.Add("L2ErrorVelocity", QueryLibrary.L2Error( Variables.Velocity.xComponent, (X, t) => riemannSolver.GetState(pStar, uStar, X[0] - discontinuityPosition, t).Velocity.x)); c.Queries.Add("L2ErrorPressure", QueryLibrary.L2Error( Variables.Pressure, (X, t) => riemannSolver.GetState(pStar, uStar, X[0] - discontinuityPosition, t).Pressure)); c.dtMin = 0.0; c.dtMax = 1.0; c.dtFixed = 1.0e-6; c.Endtime = 5e-04; //c.NoOfTimesteps = 500; c.NoOfTimesteps = int.MaxValue; return(c); }
public static SIMPLEControl UnsteadyTaylorVortex() { SIMPLEControl c = new SIMPLEControl(); //c.DbPath = @"..\..\Base\06_ZipDatabases\NUnitTests.zip"; c.DbPath = @"NUnitTests.zip"; c.savetodb = false; c.GridGuid = new Guid("06e506b2-9cb7-48c5-ba5d-22fc57645aac"); c.GridPartType = GridPartType.METIS; c.ProjectName = "Unsteady_SIMPLE Taylor vortex"; c.ProjectDescription = "NUnitTest for Unsteady_SIMPLE"; // Required fields c.FieldOptions.Add( VariableNames.VelocityX, new FieldOpts() { Degree = 2, SaveToDB = FieldOpts.SaveToDBOpt.TRUE }); c.FieldOptions.Add( VariableNames.VelocityY, new FieldOpts() { Degree = 2, SaveToDB = FieldOpts.SaveToDBOpt.TRUE }); c.FieldOptions.Add( VariableNames.Pressure, new FieldOpts() { Degree = 1, SaveToDB = FieldOpts.SaveToDBOpt.TRUE }); // Auxiliary fields //c.FieldOptions.Add( // "VelocityX*", // new FieldOpts() { Degree = 2, SaveToDB = FieldOpts.SaveToDBOpt.FALSE }); //c.FieldOptions.Add( // "VelocityY*", // new FieldOpts() { Degree = 2, SaveToDB = FieldOpts.SaveToDBOpt.FALSE }); //c.FieldOptions.Add( // "VelocityX'", // new FieldOpts() { Degree = 2, SaveToDB = FieldOpts.SaveToDBOpt.FALSE }); //c.FieldOptions.Add( // "VelocityY'", // new FieldOpts() { Degree = 2, SaveToDB = FieldOpts.SaveToDBOpt.FALSE }); //c.FieldOptions.Add( // "VelocityXRes", // new FieldOpts() { Degree = 2, SaveToDB = FieldOpts.SaveToDBOpt.FALSE }); //c.FieldOptions.Add( // "VelocityYRes", // new FieldOpts() { Degree = 2, SaveToDB = FieldOpts.SaveToDBOpt.FALSE }); c.FieldOptions.Add( "Pressure'", new FieldOpts() { Degree = 1, SaveToDB = FieldOpts.SaveToDBOpt.FALSE }); c.FieldOptions.Add( "DivB4", new FieldOpts() { Degree = 1, SaveToDB = FieldOpts.SaveToDBOpt.FALSE }); c.FieldOptions.Add( "DivAfter", new FieldOpts() { Degree = 1, SaveToDB = FieldOpts.SaveToDBOpt.FALSE }); c.InitialValues_Evaluators.Add(VariableNames.VelocityX, X => - Cos(PI * X[0]) * Sin(PI * X[1])); c.InitialValues_Evaluators.Add(VariableNames.VelocityY, X => Sin(PI * X[0]) * Cos(PI * X[1])); c.InitialValues_Evaluators.Add(VariableNames.Pressure, X => - 0.25 * (Cos(2.0 * PI * X[0]) + Cos(2.0 * PI * X[1]))); c.Algorithm = SolutionAlgorithms.Unsteady_SIMPLE; c.TimeOrder = 4; c.NoOfTimesteps = 5; c.Endtime = 2.0; c.L2NormPressureCorrection = 1.0e-5; c.L2NormVelocityResidual = 1.0e-5; c.PredictorSolverFactory = () => new PARDISOSolver(); c.CorrectorSolverFactory = () => new PARDISOSolver(); c.PhysicsMode = PhysicsMode.Incompressible; c.Reynolds = 100.0; c.PredictorApproximation = PredictorApproximations.Identity; c.PressureStabilizationScaling = 0.0; c.PredictorApproximationUpdateCycle = 45; c.MaxNoSIMPLEsteps = 45; c.SavePeriodSIMPLE = 500; c.RelaxationFactorPressure = 1.0; c.RelexationFactorVelocity = 1.0; c.ViscousPenaltyScaling = 1.0; c.PrintLinerSolverResults = false; c.PressureReferencePoint = new double[] { 0.0, 0.0 }; c.PressureMeanValue = 0.0; c.AnalyticVelocityX = X => - Cos(PI * X[0]) * Sin(PI * X[1]) * Exp(-2.0 * PI * PI * 2.0 / 100.0); c.AnalyticVelocityY = X => Sin(PI * X[0]) * Cos(PI * X[1]) * Exp(-2.0 * PI * PI * 2.0 / 100.0); c.AnalyticPressure = X => - 0.25 * (Cos(2.0 * PI * X[0]) + Cos(2.0 * PI * X[1])) * Exp(-4.0 * PI * PI * 2.0 / 100.0); int queryQuadOrder = 10; c.Queries.Add( "SolL2err_u", QueryLibrary.L2Error(VariableNames.VelocityX, c.AnalyticVelocityX, queryQuadOrder)); c.Queries.Add( "SolL2err_v", QueryLibrary.L2Error(VariableNames.VelocityY, c.AnalyticVelocityY, queryQuadOrder)); c.Queries.Add( "SolL2err_p", QueryLibrary.L2Error(VariableNames.Pressure, c.AnalyticPressure, queryQuadOrder)); return(c); }
// Control templates private static CNSControl[] GetTemplates() { int minDivisions = 0; int maxDivisions = 2; int minDegree = 0; int maxDegree = 3; List <CNSControl> result = new List <CNSControl>(); for (int dgDegree = minDegree; dgDegree <= maxDegree; dgDegree++) { for (int divisions = minDivisions; divisions <= maxDivisions; divisions++) { CNSControl c = new CNSControl(); //c.DbPath = @"c:\bosss_dbv2\exp"; c.savetodb = false; int noOfCells = (2 << divisions) * 8; c.PrintInterval = 1000; c.ResidualInterval = 100; c.saveperiod = 100000; c.ActiveOperators = Operators.Convection | Operators.CustomSource; c.ConvectiveFluxType = ConvectiveFluxTypes.OptimizedHLLC; c.ExplicitScheme = ExplicitSchemes.RungeKutta; c.ExplicitOrder = 1; c.EquationOfState = IdealGas.Air; c.MachNumber = 1.0; c.AddVariable(CompressibleVariables.Density, dgDegree); c.AddVariable(CompressibleVariables.Momentum.xComponent, dgDegree); c.AddVariable(CompressibleVariables.Energy, dgDegree); c.AddVariable(CNSVariables.Velocity.xComponent, dgDegree); c.AddVariable(CNSVariables.Pressure, dgDegree); c.AddVariable(CNSVariables.LocalMachNumber, dgDegree); c.InitialValues_Evaluators.Add(CompressibleVariables.Density, exactDensity); c.InitialValues_Evaluators.Add(CNSVariables.Velocity.xComponent, exactVelocity); c.InitialValues_Evaluators.Add(CNSVariables.Pressure, exactPressure); c.CustomContinuitySources.Add(map => new AdHocSourceTerm(map, (x, t, state) => - Math.Sin(4.0 * x[0]) / 4.0)); c.CustomMomentumSources[0].Add(map => new AdHocSourceTerm(map, (x, t, state) => (160.0 - 35.0 * MaSquared - 56.0 * MaSquared * Math.Cos(2.0 * x[0]) + 21.0 * MaSquared * Math.Cos(4.0 * x[0])) * Math.Sin(2.0 * x[0]) / (224.0 * MaSquared))); c.CustomEnergySources.Add(map => new AdHocSourceTerm(map, (x, t, state) => - (7.0 / 640.0) * Math.Sin(2 * x[0]) * ((160.0 + 3.0 * MaSquared) * Math.Cos(2 * x[0]) + MaSquared * (10.0 - 6.0 * Math.Cos(4.0 * x[0]) + Math.Cos(6.0 * x[0]))))); c.Queries.Add("densityError", QueryLibrary.L2Error(CompressibleVariables.Density, exactDensity, 10)); c.Queries.Add("momentumError", QueryLibrary.L2Error(CompressibleVariables.Momentum[0], exactMomentum, 10)); c.Queries.Add("energyError", QueryLibrary.L2Error(CompressibleVariables.Energy, exactEnergy, 10)); c.Paramstudy_CaseIdentification = new Tuple <string, object>[] { new Tuple <string, object>("divisions", divisions), new Tuple <string, object>("dgDegree", dgDegree) }; c.ResidualLoggerType = ResidualLoggerTypes.ChangeRate | ResidualLoggerTypes.Query; c.ResidualBasedTerminationCriteria.Add("changeRate_abs_rhoE", 1E-9); c.dtMin = 0.0; c.dtMax = 1.0; c.CFLFraction = 0.1; c.Endtime = 10000; c.NoOfTimesteps = 1000000; c.ProjectName = "MMS1D_Euler_Mach=" + c.MachNumber + "_dg=" + dgDegree + "_cells=" + noOfCells; result.Add(c); } } return(result.ToArray()); }
public RTSCameraAgentComponent(Agent agent) : base(agent) { for (int i = 0; i < _colors.Length; ++i) { _colors[i] = new Contour(null, false); } CurrentTargetPosition = new QueryData <WorldPosition>(() => { try { var unit = Agent; var formation = unit.Formation; if (formation == null) { return(WorldPosition.Invalid); } var targetFormation = QueryDataStore.Get(formation.TargetFormation); if (QueryLibrary.IsRangedCavalry(unit)) { var targetAgent = unit.GetTargetAgent(); if (targetAgent == null || targetAgent.Formation != formation.TargetFormation) { Vec2 unitPosition = unit.Position.AsVec2; targetAgent = targetFormation.NearestAgent(unitPosition); } return(targetAgent?.GetWorldPosition() ?? new WorldPosition()); } if (QueryLibrary.IsCavalry(unit)) { var targetAgent = unit.GetTargetAgent(); if (targetAgent == null || targetAgent.Formation != formation.TargetFormation) { Vec2 unitPosition = formation.GetCurrentGlobalPositionOfUnit(unit, true) * 0.2f + unit.Position.AsVec2 * 0.8f; targetAgent = targetFormation.NearestOfAverageOfNearestPosition(unitPosition, 7); } if (targetAgent != null) { if (targetAgent.HasMount) { return(targetAgent.GetWorldPosition()); } var targetPosition = targetAgent.GetWorldPosition(); var targetDirection = targetPosition.AsVec2 - unit.Position.AsVec2; var distance = targetDirection.Normalize(); var result = targetPosition; // new if (distance > 20) { CurrentDirection = targetDirection; result.SetVec2(targetDirection * 10 + targetPosition.AsVec2); } else if (distance > 5 && targetDirection.DotProduct(CurrentDirection) < 0) { result.SetVec2( (CurrentDirection.DotProduct(targetDirection * distance) + 50) * CurrentDirection + unit.Position.AsVec2); } else { result.SetVec2(CurrentDirection * 10 + targetPosition.AsVec2); } // old //if (distance < 3) //{ // result = unit.GetWorldPosition(); // result.SetVec2(CurrentDirection * 20 + result.AsVec2); //} //else //{ // if (distance < 20 && targetDirection.DotProduct(CurrentDirection) < 0) // { // result.SetVec2(-targetDirection * 50 + result.AsVec2); // } // else // { // CurrentDirection = targetDirection; // result.SetVec2(targetDirection * 10 + result.AsVec2); // } //} return(result.GetNavMesh() == UIntPtr.Zero || !Mission.Current.IsPositionInsideBoundaries(result.AsVec2) ? targetPosition : result); } return(WorldPosition.Invalid); } else { var targetAgent = unit.GetTargetAgent(); if (targetAgent == null || targetAgent.Formation != formation.TargetFormation) { Vec2 unitPosition = formation.GetCurrentGlobalPositionOfUnit(unit, true) * 0.2f + unit.Position.AsVec2 * 0.8f; targetAgent = targetFormation.NearestAgent(unitPosition); } return(targetAgent?.GetWorldPosition() ?? new WorldPosition()); } } catch (Exception e) { Utility.DisplayMessage(e.ToString()); } return(WorldPosition.Invalid); }, 0.2f); }
private WorldPosition GetTargetPosition(Agent agent) { try { var unit = agent; if (!unit.IsActive()) { return(WorldPosition.Invalid); } var formation = unit.Formation; if (formation == null) { return(WorldPosition.Invalid); } var targetFormation = QueryDataStore.Get(formation.TargetFormation); Vec2 offset; if (QueryLibrary.IsCavalry(unit) || QueryLibrary.IsRangedCavalry(unit) && formation.FiringOrder.OrderType == OrderType.HoldFire) { var averageOfTargetAgents = QueryDataStore.Get(formation).AverageOfTargetAgents.Value; offset = averageOfTargetAgents.IsValid ? formation.TargetFormation.QuerySystem.AveragePosition * 0.2f + averageOfTargetAgents * 0.8f - formation.QuerySystem.AveragePosition : Vec2.Zero; } else if (QueryLibrary.IsInfantry(unit) || QueryLibrary.IsRanged(unit) && formation.FiringOrder.OrderType == OrderType.HoldFire) { var targetCenterAgent = targetFormation.NearestAgent(formation.CurrentPosition); if (targetCenterAgent == null) { return(WorldPosition.Invalid); } offset = targetCenterAgent.Position.AsVec2 - formation.CurrentPosition; } else { return(WorldPosition.Invalid); } Vec2 targetPosition = formation.GetCurrentGlobalPositionOfUnit(unit, true) + offset; var targetAgent = targetFormation.NearestAgent(targetPosition); var result = targetAgent?.GetWorldPosition() ?? WorldPosition.Invalid; PositionOfTargetAgent.SetValue(result.AsVec2, MBCommon.GetTime(MBCommon.TimeType.Mission)); if (targetAgent == null || !result.IsValid || result.GetNavMesh() == UIntPtr.Zero) { result = unit.GetWorldPosition(); result.SetVec2(result.AsVec2 + unit.GetMovementDirection().AsVec2 * 0.1f); return(result); } if (QueryLibrary.IsInfantry(unit) || QueryLibrary.IsRanged(unit) && formation.FiringOrder.OrderType == OrderType.HoldFire) { result.SetVec2((unit.Position.AsVec2 - result.AsVec2).Normalized() * 0.8f + result.AsVec2 + targetAgent.Velocity.AsVec2 * 1); } else if (QueryLibrary.IsCavalry(unit) || QueryLibrary.IsRangedCavalry(unit) && formation.FiringOrder.OrderType == OrderType.HoldFire) { result.SetVec2((result.AsVec2 - unit.Position.AsVec2).Normalized() * 3f + result.AsVec2 + targetAgent.Velocity.AsVec2 * 1 + unit.Velocity.AsVec2 * 1); } else { return(WorldPosition.Invalid); } return(result); } catch (Exception e) { Utility.DisplayMessage(e.ToString()); } return(WorldPosition.Invalid); }
public static SIMPLEControl PoiseuilleFlow() { SIMPLEControl c = new SIMPLEControl(); c.DbPath = @"NUnitTests.zip"; c.savetodb = false; c.GridGuid = new Guid("0062a338-a8a4-4d52-9b16-bc79379dd4d5"); c.GridPartType = GridPartType.METIS; c.ProjectName = "Steady_SIMPLE 2D Channel"; c.ProjectDescription = "NUnitTest for Steady_SIMPLE"; // Required fields c.FieldOptions.Add( VariableNames.VelocityX, new FieldOpts() { Degree = 2, SaveToDB = FieldOpts.SaveToDBOpt.TRUE }); c.FieldOptions.Add( VariableNames.VelocityY, new FieldOpts() { Degree = 2, SaveToDB = FieldOpts.SaveToDBOpt.TRUE }); c.FieldOptions.Add( VariableNames.Pressure, new FieldOpts() { Degree = 1, SaveToDB = FieldOpts.SaveToDBOpt.TRUE }); // Auxiliary fields //c.FieldOptions.Add( // "VelocityX*", // new FieldOpts() { Degree = 2, SaveToDB = FieldOpts.SaveToDBOpt.FALSE }); //c.FieldOptions.Add( // "VelocityY*", // new FieldOpts() { Degree = 2, SaveToDB = FieldOpts.SaveToDBOpt.FALSE }); //c.FieldOptions.Add( // "VelocityX'", // new FieldOpts() { Degree = 2, SaveToDB = FieldOpts.SaveToDBOpt.FALSE }); //c.FieldOptions.Add( // "VelocityY'", // new FieldOpts() { Degree = 2, SaveToDB = FieldOpts.SaveToDBOpt.FALSE }); //c.FieldOptions.Add( // "VelocityXRes", // new FieldOpts() { Degree = 2, SaveToDB = FieldOpts.SaveToDBOpt.FALSE }); //c.FieldOptions.Add( // "VelocityYRes", // new FieldOpts() { Degree = 2, SaveToDB = FieldOpts.SaveToDBOpt.FALSE }); c.FieldOptions.Add( "Pressure'", new FieldOpts() { Degree = 1, SaveToDB = FieldOpts.SaveToDBOpt.FALSE }); c.FieldOptions.Add( "DivB4", new FieldOpts() { Degree = 1, SaveToDB = FieldOpts.SaveToDBOpt.FALSE }); c.FieldOptions.Add( "DivAfter", new FieldOpts() { Degree = 1, SaveToDB = FieldOpts.SaveToDBOpt.FALSE }); c.InitialValues_Evaluators.Add(VariableNames.VelocityX, X => 0.0); c.InitialValues_Evaluators.Add(VariableNames.VelocityY, X => 0.0); c.InitialValues_Evaluators.Add(VariableNames.Pressure, X => 0.0); c.Algorithm = SolutionAlgorithms.Steady_SIMPLE; c.NoOfTimesteps = 1; c.L2NormPressureCorrection = 1.0e-6; c.L2NormVelocityResidual = 1.0e-6; c.PredictorSolverFactory = () => new PARDISOSolver(); c.CorrectorSolverFactory = () => new PARDISOSolver(); c.AddBoundaryValue("velocity_inlet", VariableNames.VelocityX, X => 1.0 - X[1] * X[1]); c.AddBoundaryValue("velocity_inlet", VariableNames.VelocityY, X => 0.0); c.AddBoundaryValue("pressure_outlet"); c.AddBoundaryValue("wall_lower"); c.AddBoundaryValue("wall_upper"); c.PhysicsMode = PhysicsMode.Incompressible; c.Reynolds = 100.0; c.PredictorApproximation = PredictorApproximations.Identity; c.PressureStabilizationScaling = 0.0; c.PredictorApproximationUpdateCycle = 500; c.MaxNoSIMPLEsteps = 500; c.SavePeriodSIMPLE = 500; c.RelaxationFactorPressure = 1.0; c.RelexationFactorVelocity = 0.2; c.ViscousPenaltyScaling = 1.0; c.PrintLinerSolverResults = false; c.AnalyticVelocityX = X => 1.0 - X[1] * X[1]; c.AnalyticVelocityY = X => 0.0; c.AnalyticPressure = X => - 2.0 / 100.0 * X[0] + 0.2; int queryQuadOrder = 10; c.Queries.Add( "SolL2err_u", QueryLibrary.L2Error(VariableNames.VelocityX, c.AnalyticVelocityX, queryQuadOrder)); c.Queries.Add( "SolL2err_v", QueryLibrary.L2Error(VariableNames.VelocityY, c.AnalyticVelocityY, queryQuadOrder)); c.Queries.Add( "SolL2err_p", QueryLibrary.L2Error(VariableNames.Pressure, c.AnalyticPressure, queryQuadOrder)); return(c); }
private static CNSControl ShockTubeToro1Template(int dgDegree, ExplicitSchemes explicitScheme, int explicitOrder, int noOfCells = 50, double gridStretching = 0.0, bool twoD = false) { double densityLeft = 1.0; double velocityLeft = 0.0; double pressureLeft = 1.0; double densityRight = 0.125; double velocityRight = 0.0; double pressureRight = 0.1; double discontinuityPosition = 0.5; CNSControl c = new CNSControl(); c.DbPath = null; //c.DbPath = @"c:\bosss_db\"; c.savetodb = false; c.ActiveOperators = Operators.Convection; c.ConvectiveFluxType = ConvectiveFluxTypes.OptimizedHLLC; c.EquationOfState = IdealGas.Air; c.MachNumber = 1.0 / Math.Sqrt(c.EquationOfState.HeatCapacityRatio); c.ReynoldsNumber = 1.0; c.PrandtlNumber = 0.71; c.ExplicitScheme = explicitScheme; c.ExplicitOrder = explicitOrder; c.AddVariable(CompressibleVariables.Density, dgDegree); c.AddVariable(CompressibleVariables.Momentum.xComponent, dgDegree); c.AddVariable(CompressibleVariables.Energy, dgDegree); c.AddVariable(CNSVariables.Velocity.xComponent, dgDegree); c.AddVariable(CNSVariables.Pressure, dgDegree); c.AddVariable(CNSVariables.Rank, 0); c.GridFunc = delegate { double xMin = 0.0; double xMax = 1.0; double yMin = 0.0; double yMax = 1.0; double[] xNodes; double[] yNodes; if (gridStretching > 0.0) { xNodes = Grid1D.TanhSpacing(xMin, xMax, noOfCells + 1, gridStretching, true); yNodes = Grid1D.TanhSpacing(yMin, yMax, 1 + 1, gridStretching, true); } else { xNodes = GenericBlas.Linspace(xMin, xMax, noOfCells + 1); yNodes = GenericBlas.Linspace(yMin, yMax, 1 + 1); } GridCommons grid; if (twoD) { grid = Grid2D.Cartesian2DGrid(xNodes, yNodes, periodicX: false, periodicY: false); } else { grid = Grid1D.LineGrid(xNodes, periodic: false); } // Boundary conditions grid.EdgeTagNames.Add(1, "AdiabaticSlipWall"); grid.DefineEdgeTags(delegate(double[] _X) { return(1); }); return(grid); }; c.AddBoundaryValue("AdiabaticSlipWall"); Material material = c.GetMaterial(); StateVector stateLeft = StateVector.FromPrimitiveQuantities( material, densityLeft, new Vector(velocityLeft, 0.0, 0.0), pressureLeft); StateVector stateRight = StateVector.FromPrimitiveQuantities( material, densityRight, new Vector(velocityRight, 0.0, 0.0), pressureRight); c.InitialValues_Evaluators.Add( CompressibleVariables.Density, X => stateLeft.Density + (stateRight.Density - stateLeft.Density) * (X[0] - discontinuityPosition).Heaviside()); c.InitialValues_Evaluators.Add( CNSVariables.Velocity.xComponent, X => stateLeft.Velocity.x + (stateRight.Velocity.x - stateLeft.Velocity.x) * (X[0] - discontinuityPosition).Heaviside()); c.InitialValues_Evaluators.Add( CNSVariables.Pressure, X => stateLeft.Pressure + (stateRight.Pressure - stateLeft.Pressure) * (X[0] - discontinuityPosition).Heaviside()); if (twoD) { c.InitialValues_Evaluators.Add(CNSVariables.Velocity.yComponent, X => 0); } if (!twoD) { var riemannSolver = new ExactRiemannSolver(stateLeft, stateRight, new Vector(1.0, 0.0, 0.0)); riemannSolver.GetStarRegionValues(out double pStar, out double uStar); c.Queries.Add("L2ErrorDensity", QueryLibrary.L2Error( CompressibleVariables.Density, (X, t) => riemannSolver.GetState(pStar, uStar, X[0] - discontinuityPosition, t).Density)); c.Queries.Add("L2ErrorVelocity", QueryLibrary.L2Error( CNSVariables.Velocity.xComponent, (X, t) => riemannSolver.GetState(pStar, uStar, X[0] - discontinuityPosition, t).Velocity.x)); c.Queries.Add("L2ErrorPressure", QueryLibrary.L2Error( CNSVariables.Pressure, (X, t) => riemannSolver.GetState(pStar, uStar, X[0] - discontinuityPosition, t).Pressure)); } c.dtMin = 0.0; c.dtMax = 1.0; //c.dtFixed = 1.0e-6; c.CFLFraction = 0.1; c.Endtime = 0.2; c.NoOfTimesteps = int.MaxValue; // Use METIS since ParMETIS is not installed on build server c.GridPartType = GridPartType.METIS; return(c); }
public static CNSControl Gassner3D_unsteady(int noOfCellsPerDirection, int dgDegree, string dbPath = @"/home/kraemer/CNS/dbe") { CNSControl c = new CNSControl(); // Session Settings c.DbPath = dbPath; c.savetodb = true; c.saveperiod = 10000; c.ProjectName = "MMS_Gassner3D_h=1/" + noOfCellsPerDirection + "_p=" + dgDegree; c.ProjectDescription = "Manufactured Solution by Gassner et al. (2008)"; c.Tags.Add("MMS"); c.Tags.Add("Diffusive Test"); c.GridPartType = GridPartType.ParMETIS; // Solver Type c.ActiveOperators = Operators.Convection | Operators.Diffusion | Operators.CustomSource; c.ConvectiveFluxType = ConvectiveFluxTypes.OptimizedHLLC; c.DiffusiveFluxType = DiffusiveFluxTypes.OptimizedSIPG; c.SIPGPenaltyScaling = 1.3; // Time-Stepping Settings c.ExplicitScheme = ExplicitSchemes.RungeKutta; c.ExplicitOrder = 4; //Material Settings c.EquationOfState = IdealGas.Air; c.ViscosityLaw = new ConstantViscosity(); c.PrandtlNumber = 0.72; c.ReynoldsNumber = 1000.0; c.MachNumber = 1 / Math.Sqrt(c.EquationOfState.HeatCapacityRatio); // Primary Variables c.AddVariable(Variables.Density, dgDegree); c.AddVariable(Variables.Momentum.xComponent, dgDegree); c.AddVariable(Variables.Momentum.yComponent, dgDegree); c.AddVariable(Variables.Momentum.zComponent, dgDegree); c.AddVariable(Variables.Energy, dgDegree); // Parameters c.AddVariable(Variables.Velocity.xComponent, dgDegree); c.AddVariable(Variables.Velocity.yComponent, dgDegree); c.AddVariable(Variables.Velocity.zComponent, dgDegree); c.AddVariable(Variables.Pressure, dgDegree); // Grid //c.GridFunc = delegate { // double[] nodes = GenericBlas.Linspace(0.0, 1.0, noOfCellsPerDirection + 1); // var grid = Grid3D.Cartesian3DGrid(nodes, nodes, nodes, periodicX: true, periodicY: true, periodicZ: true, _CellType: CellType.Cube_Linear); // return grid; //}; String grid = ""; switch (noOfCellsPerDirection) { case 16: grid = "06d43b3a-c630-445b-b17f-5c0a17d7e290"; break; case 32: grid = "c3276077-946a-4360-9917-eba9a87fcbfc"; break; case 64: grid = "c80eac65-6e56-420d-ae65-be8d75001539"; break; } Guid gridGuid; if (Guid.TryParse(grid, out gridGuid)) { c.GridGuid = gridGuid; } else { throw new Exception( "Could not find a grid at " + grid); } // Functions Func <double[], double, double> rho = (X, t) => 2.0 + 0.25 * Math.Sin(2 * Math.PI * (X[0] + X[1] + X[2]) - 0 * Math.PI * t); Func <double[], double, double> m = (X, t) => 2.0 + 0.25 * Math.Sin(2 * Math.PI * (X[0] + X[1] + X[2]) - 0 * Math.PI * t); Func <double[], double, double> rhoE = (X, t) => (2.0 + 0.25 * Math.Sin(2 * Math.PI * (X[0] + X[1] + X[2]) - 0 * Math.PI * t)) * (2.0 + 0.25 * Math.Sin(2 * Math.PI * (X[0] + X[1] + X[2]) - 0 * Math.PI * t)); Func <double[], double, double> u = (X, t) => 1.0; Func <double[], double, double> pressure = (X, t) => (1.4 - 1) * Math.Pow((2.0 + 0.25 * Math.Sin(2 * Math.PI * (X[0] + X[1] + X[2]) - 20 * Math.PI * t)), 2) - 3 / 2 * (2.0 + 0.25 * Math.Sin(2 * Math.PI * (X[0] + X[1] + X[2]) - 20 * Math.PI * t)); //Initial Values c.InitialValues_Evaluators.Add(Variables.Density, X => rho(X, 0.0)); c.InitialValues_Evaluators.Add(Variables.Momentum.xComponent, X => m(X, 0.0)); c.InitialValues_Evaluators.Add(Variables.Momentum.yComponent, X => m(X, 0.0)); c.InitialValues_Evaluators.Add(Variables.Momentum.zComponent, X => m(X, 0.0)); c.InitialValues_Evaluators.Add(Variables.Energy, X => rhoE(X, 0.0)); //c.InitialValues.Add(Variable.Velocity.xComponent, X => u0(X, 0.0)); //c.InitialValues.Add(Variable.Velocity.yComponent, X => u1(X, 0.0)); //c.InitialValues.Add(Variable.Velocity.zComponent, X => u2(X, 0.0)); //c.InitialValues.Add(Variable.Pressure, X => pressure(X, 0.0)); // Solver Settings c.dtMin = 0.0; c.dtMax = 1.0; c.Endtime = 0.1; c.CFLFraction = 0.1; c.NoOfTimesteps = 5000000; c.PrintInterval = 10; c.ResidualInterval = 100; c.ResidualLoggerType = ResidualLoggerTypes.ChangeRate | ResidualLoggerTypes.Query; //MMS Sources c.CustomContinuitySources.Add(map => new AdHocSourceTerm(map, (X, t, state) => 3.5 * Math.PI * Math.Cos(2 * Math.PI * (X[0] + X[1] + X[2]) - 20 * Math.PI * t))); c.CustomMomentumSources[0].Add(map => new AdHocSourceTerm(map, (X, t, state) => 3 * Math.PI * Math.Cos(2 * Math.PI * (X[0] + X[1] + X[2]) - 20 * Math.PI * t) - 0.05 * Math.PI * Math.Sin(4 * Math.PI * (X[0] + X[1] + X[2]) - 40 * Math.PI * t))); c.CustomMomentumSources[1].Add(map => new AdHocSourceTerm(map, (X, t, state) => 3 * Math.PI * Math.Cos(2 * Math.PI * (X[0] + X[1] + X[2]) - 20 * Math.PI * t) - 0.05 * Math.PI * Math.Sin(4 * Math.PI * (X[0] + X[1] + X[2]) - 40 * Math.PI * t))); c.CustomMomentumSources[2].Add(map => new AdHocSourceTerm(map, (X, t, state) => 3 * Math.PI * Math.Cos(2 * Math.PI * (X[0] + X[1] + X[2]) - 20 * Math.PI * t) - 0.05 * Math.PI * Math.Sin(4 * Math.PI * (X[0] + X[1] + X[2]) - 40 * Math.PI * t))); c.CustomEnergySources.Add(map => new AdHocSourceTerm(map, (X, t, state) => 12.5 * Math.PI * Math.Cos(2 * Math.PI * (X[0] + X[1] + X[2]) - 20 * Math.PI * t) + 0.725 * Math.PI * Math.Sin(4 * Math.PI * (X[0] + X[1] + X[2]) - 40 * Math.PI * t) - 0.005833333332 * Math.PI * Math.PI * Math.Sin(2 * Math.PI * (X[0] + X[1] + X[2]) - 20 * Math.PI * t))); //c.CustomEnergySources.Add(map => new AdHocSourceTerm(map, // (X, t, state) => -0.005833333332 * Math.PI * Math.PI * Math.Sin(2 * Math.PI * (X[0] + X[1] + X[2]) - 0 * Math.PI * t))); // Queries int QueryDegree = 10; c.Queries.Add("densityError", QueryLibrary.L2Error(Variables.Density, rho, QueryDegree)); c.Queries.Add("momentum0Error", QueryLibrary.L2Error(Variables.Momentum.xComponent, m, QueryDegree)); c.Queries.Add("energyError", QueryLibrary.L2Error(Variables.Energy, rhoE, QueryDegree)); c.Queries.Add("velocity0Error", QueryLibrary.L2Error(Variables.Velocity.xComponent, u, QueryDegree)); return(c); }
public static SIMPLEControl UnsteadyMultiphaseWave() { MultiphaseSIMPLEControl c = new MultiphaseSIMPLEControl(); //c.DbPath = @"..\..\Base\06_ZipDatabases\NUnitTests.zip"; c.DbPath = @"NUnitTests.zip"; c.savetodb = false; c.GridGuid = new Guid("a5135fbb-4243-4677-97f6-562860e4f95c"); c.GridPartType = GridPartType.METIS; c.ProjectName = "MultiphaseWave"; c.ProjectDescription = "Convected density wave"; // Required fields c.FieldOptions.Add( VariableNames.VelocityX, new FieldOpts() { Degree = 3, SaveToDB = FieldOpts.SaveToDBOpt.TRUE }); c.FieldOptions.Add( VariableNames.VelocityY, new FieldOpts() { Degree = 3, SaveToDB = FieldOpts.SaveToDBOpt.TRUE }); c.FieldOptions.Add( VariableNames.Pressure, new FieldOpts() { Degree = 2, SaveToDB = FieldOpts.SaveToDBOpt.TRUE }); c.FieldOptions.Add( "LevelSet", new FieldOpts() { Degree = 3, SaveToDB = FieldOpts.SaveToDBOpt.TRUE }); c.FieldOptions.Add( "Density", new FieldOpts() { Degree = 3, SaveToDB = FieldOpts.SaveToDBOpt.TRUE }); c.FieldOptions.Add( "Eta", new FieldOpts() { Degree = 3, SaveToDB = FieldOpts.SaveToDBOpt.TRUE }); // Auxiliary fields c.FieldOptions.Add( "DivB4", new FieldOpts() { Degree = 2, SaveToDB = FieldOpts.SaveToDBOpt.FALSE }); c.FieldOptions.Add( "DivAfter", new FieldOpts() { Degree = 2, SaveToDB = FieldOpts.SaveToDBOpt.FALSE }); c.FieldOptions.Add( "OperatorTest_x", new FieldOpts() { Degree = 3, SaveToDB = FieldOpts.SaveToDBOpt.FALSE }); c.FieldOptions.Add( "OperatorTest_y", new FieldOpts() { Degree = 3, SaveToDB = FieldOpts.SaveToDBOpt.FALSE }); c.FieldOptions.Add( "OperatorAna_x", new FieldOpts() { Degree = 3, SaveToDB = FieldOpts.SaveToDBOpt.FALSE }); c.FieldOptions.Add( "OperatorAna_y", new FieldOpts() { Degree = 3, SaveToDB = FieldOpts.SaveToDBOpt.FALSE }); c.InitialValues_Evaluators.Add(VariableNames.VelocityX, X => 1.0); c.InitialValues_Evaluators.Add(VariableNames.VelocityY, X => 0.0); c.InitialValues_Evaluators.Add(VariableNames.Pressure, X => 0.0); c.InitialValues_Evaluators.Add("LevelSet", X => 0.5 - 0.5 * Tanh(20.0 * X[0] - 12.0)); c.Algorithm = SolutionAlgorithms.Unsteady_SIMPLE; c.NoOfTimesteps = 2; c.Endtime = 0.02; c.TimeOrder = 1; c.L2NormPressureCorrection = 1.0e-8; c.L2NormVelocityResidual = 1.0e-8; c.L2NormLevelSetResidual = 1.0E-8; c.PredictorSolverFactory = () => new PARDISOSolver(); c.CorrectorSolverFactory = () => new PARDISOSolver(); c.LevelSetSolverFactory = () => new PARDISOSolver(); c.AddBoundaryValue("velocity_inlet", VariableNames.VelocityX, X => 1.0); c.AddBoundaryValue("velocity_inlet", VariableNames.VelocityY, X => 0.0); c.AddBoundaryValue("velocity_inlet", "LevelSet", X => 1.0); c.AddBoundaryValue("pressure_outlet"); c.PhysicsMode = PhysicsMode.Multiphase; c.Reynolds = 1.0; c.EoS = new MaterialLawMultiphase(rho1: 1000.0, rho2: 1.0, mu1: 1.0, mu2: 1.0); c.PredictorApproximation = PredictorApproximations.Diagonal; c.PressureStabilizationScaling = 0.0; c.PredictorApproximationUpdateCycle = 54; c.MaxNoSIMPLEsteps = 54; c.SavePeriodSIMPLE = 100; c.RelaxationFactorPressure = 0.3; c.RelexationFactorVelocity = 0.7; c.RelaxationFactorLevelSet = 1.0; c.LevelSetRelaxationType = RelaxationTypes.Implicit; c.ViscousPenaltyScaling = 1.0; c.PrintLinerSolverResults = false; c.AnalyticVelocityX = X => 1.0; c.AnalyticVelocityY = X => 0.0; c.AnalyticPressure = X => 0.0; c.AnalyticLevelSet = X => 0.5 - 0.5 * Tanh(20.0 * X[0] - 12.4); c.AnalyticDensity = X => 1000.0 * (0.5 - 0.5 * Tanh(20.0 * X[0] - 12.4)) + (1.0 - (0.5 - 0.5 * Tanh(20.0 * X[0] - 12.4))); int queryQuadOrder = 10; c.Queries.Add( "SolL2err_u", QueryLibrary.L2Error(VariableNames.VelocityX, c.AnalyticVelocityX, queryQuadOrder)); c.Queries.Add( "SolL2err_v", QueryLibrary.L2Error(VariableNames.VelocityY, c.AnalyticVelocityY, queryQuadOrder)); c.Queries.Add( "SolL2err_p", QueryLibrary.L2Error(VariableNames.Pressure, c.AnalyticPressure, queryQuadOrder)); c.Queries.Add( "SolL2err_phi", QueryLibrary.L2Error("LevelSet", c.AnalyticLevelSet, queryQuadOrder)); c.Queries.Add( "SolL2err_Rho", QueryLibrary.L2Error("Density", c.AnalyticDensity, queryQuadOrder)); return(c); }
public static IBMControl IBMAVTestContactDiscontinuity() { IBMControl c = new IBMControl(); //c.DbPath = @"c:\bosss_db"; c.DbPath = null; c.savetodb = false; c.saveperiod = 1; c.PrintInterval = 1; int dgDegree = 2; double xMin = 0.0; double xMax = 1.0; double yMin = 0.0; double yMax = 1.0; int numOfCellsX = 20; int numOfCellsY = 5; c.DomainType = DomainTypes.StaticImmersedBoundary; // Adjust height of cut cells such that we obtain AVCFL_cutcell = 0.5 * AVCFL // Here, this only depends on h_min double width = (xMax - xMin) / numOfCellsX; double height = (yMax - yMin) / numOfCellsY; double heightCutCell = (-2.0 * width * height) / (2.0 * height - 2.0 * Math.Sqrt(2) * width - 2.0 * Math.Sqrt(2) * height); double levelSetPosition = 2 * height + (height - heightCutCell); c.LevelSetFunction = delegate(double[] X, double t) { double y = X[1]; return(y - levelSetPosition); }; c.LevelSetBoundaryTag = "AdiabaticSlipWall"; c.CutCellQuadratureType = XQuadFactoryHelper.MomentFittingVariants.OneStepGaussAndStokes; c.LevelSetQuadratureOrder = 6; c.AgglomerationThreshold = 0.2; // Using this agglomeration threshold, no cells are agglomerated (all cells are true cut cells) c.AddVariable(IBMVariables.LevelSet, 1); bool AV = true; if (AV) { c.ActiveOperators = Operators.Convection | Operators.ArtificialViscosity; } else { c.ActiveOperators = Operators.Convection; } c.ConvectiveFluxType = ConvectiveFluxTypes.OptimizedHLLC; // Shock-capturing double sensorLimit = 1.0e-3; double epsilon0 = 1.0; double kappa = 0.5; Variable sensorVariable = Variables.Density; c.ShockSensor = new PerssonSensor(sensorVariable, sensorLimit); if (AV) { c.ArtificialViscosityLaw = new SmoothedHeavisideArtificialViscosityLaw(c.ShockSensor, dgDegree, sensorLimit, epsilon0, kappa); } // Runge-Kutta c.ExplicitScheme = ExplicitSchemes.RungeKutta; c.ExplicitOrder = 1; c.EquationOfState = IdealGas.Air; c.MachNumber = 1.0 / Math.Sqrt(c.EquationOfState.HeatCapacityRatio); c.ReynoldsNumber = 1.0; c.PrandtlNumber = 0.71; c.AddVariable(Variables.Density, dgDegree); c.AddVariable(Variables.Momentum.xComponent, dgDegree); c.AddVariable(Variables.Momentum.yComponent, dgDegree); c.AddVariable(Variables.Velocity.xComponent, dgDegree); c.AddVariable(Variables.Velocity.yComponent, dgDegree); c.AddVariable(Variables.Pressure, dgDegree); c.AddVariable(Variables.Energy, dgDegree); c.AddVariable(Variables.Entropy, dgDegree); c.AddVariable(Variables.LocalMachNumber, dgDegree); c.AddVariable(Variables.Rank, 0); c.AddVariable(Variables.ShockSensor, 0); if (AV) { c.AddVariable(Variables.ArtificialViscosity, 2); } c.AddVariable(Variables.CFL, 0); c.AddVariable(Variables.CFLConvective, 0); c.AddVariable(Variables.CFLArtificialViscosity, 0); if (c.ExplicitScheme.Equals(ExplicitSchemes.LTS)) { c.AddVariable(Variables.LTSClusters, 0); } c.GridFunc = delegate { double[] xNodes = GenericBlas.Linspace(xMin, xMax, numOfCellsX + 1); double[] yNodes = GenericBlas.Linspace(yMin, yMax, numOfCellsY + 1); var grid = Grid2D.Cartesian2DGrid(xNodes, yNodes, periodicX: false, periodicY: false); // Boundary conditions grid.EdgeTagNames.Add(1, "SubsonicInlet"); grid.EdgeTagNames.Add(2, "SubsonicOutlet"); grid.EdgeTagNames.Add(3, "AdiabaticSlipWall"); grid.DefineEdgeTags(delegate(double[] X) { if (Math.Abs(X[1]) < 1e-14) // bottom { return(3); } else if (Math.Abs(X[1] - (yMax - yMin)) < 1e-14) // top { return(3); } else if (Math.Abs(X[0]) < 1e-14) // left { return(1); } else if (Math.Abs(X[0] - (xMax - xMin)) < 1e-14) // right { return(2); } else { throw new System.Exception("Problem with definition of boundary conditions"); } }); return(grid); }; Func <double[], double, double> DistanceToLine = delegate(double[] X, double t) { // direction vector Vector2D p1 = new Vector2D(0.5, 0.0); Vector2D p2 = new Vector2D(0.5, 1.0); Vector2D p = p2 - p1; // normal vector Vector2D n = new Vector2D(p.y, -p.x); n.Normalize(); // angle between line and x-axis //double alpha = Math.Atan(Math.Abs((p2.y - p1.y)) / Math.Abs((p2.x - p1.x))); double alpha = Math.PI / 2; // distance of a point X to the origin (normal to the line) double nDotX = n.x * (X[0]) + n.y * (X[1]); // shock speed double vs = 1; // distance to line double distance = nDotX - (Math.Sin(alpha) * p1.x + vs * t); return(distance); }; double cellSize = Math.Min((xMax - xMin) / numOfCellsX, (yMax - yMin) / numOfCellsY); Func <double, double> SmoothJump = delegate(double distance) { // smoothing should be in the range of h/p double maxDistance = 2.0 * cellSize / Math.Max(dgDegree, 1); return((Math.Tanh(distance / maxDistance) + 1.0) * 0.5); }; double densityLeft = 100.0; double densityRight = 1.0; double pressure = 1.0; double velocityXLeft = 2.0; double velocityY = 0.0; c.AddBoundaryCondition("SubsonicInlet", Variables.Density, (X, t) => densityLeft); c.AddBoundaryCondition("SubsonicInlet", Variables.Velocity.xComponent, (X, t) => velocityXLeft); c.AddBoundaryCondition("SubsonicInlet", Variables.Velocity.yComponent, (X, t) => velocityY); c.AddBoundaryCondition("SubsonicOutlet", Variables.Pressure, (X, t) => pressure); c.AddBoundaryCondition("AdiabaticSlipWall"); // Initial conditions c.InitialValues_Evaluators.Add(Variables.Density, X => densityLeft - SmoothJump(DistanceToLine(X, 0)) * (densityLeft - densityRight)); c.InitialValues_Evaluators.Add(Variables.Pressure, X => pressure); c.InitialValues_Evaluators.Add(Variables.Velocity.xComponent, X => velocityXLeft); c.InitialValues_Evaluators.Add(Variables.Velocity.yComponent, X => velocityY); // Time config c.dtMin = 0.0; c.dtMax = 1.0; c.CFLFraction = 0.3; c.Endtime = 5e-3; c.NoOfTimesteps = int.MaxValue; // Queries for comparison c.Queries.Add("L2NormDensity", QueryLibrary.L2Norm(Variables.Density.Name)); c.Queries.Add("L2NormVelocityX", QueryLibrary.L2Norm(Variables.Velocity.xComponent.Name)); c.Queries.Add("L2NormPressure", QueryLibrary.L2Norm(Variables.Pressure)); return(c); }
/// <summary> /// 2D Manufactured Solution for the compressible Navier-Stokes equations with variable Mach number /// and constant viscosity. It is based on primitive variables. /// </summary> /// <param name="noOfCellsPerDirection"></param> /// <param name="dgDegree"></param> /// <param name="dbPath"></param> /// <returns></returns> public static CNSControl Gassner2D_primitive(int noOfCellsPerDirection, int dgDegree, string dbPath = @"c:\bosss_dbv2\exp") { CNSControl c = new CNSControl(); // Session Settings c.DbPath = dbPath; c.savetodb = true; c.saveperiod = 10000; c.ProjectDescription = "Manufactured Solution with primitive variables. Based on Gassner et al. (2008)"; c.Tags.Add("MMS"); c.Tags.Add("Diffusive Test"); // Solver Type c.ActiveOperators = Operators.Convection | Operators.Diffusion | Operators.CustomSource; c.ConvectiveFluxType = ConvectiveFluxTypes.OptimizedHLLC; c.DiffusiveFluxType = DiffusiveFluxTypes.OptimizedSIPG; c.SIPGPenaltyScaling = 1.3; // Solver Settings c.dtMin = 0.0; c.dtMax = 1.0; c.Endtime = 0.1; c.CFLFraction = 0.25; c.NoOfTimesteps = 2000; c.PrintInterval = 100; c.ResidualInterval = 1000; c.ResidualLoggerType = ResidualLoggerTypes.ChangeRate | ResidualLoggerTypes.Query; // Time-Stepping Settings c.ExplicitScheme = ExplicitSchemes.RungeKutta; c.ExplicitOrder = 4; //Material Settings c.EquationOfState = IdealGas.Air; c.ViscosityLaw = new ConstantViscosity(); c.PrandtlNumber = 0.72; c.ReynoldsNumber = 1.0e6; c.MachNumber = 1 / Math.Sqrt(1.4); // Primary Variables c.AddVariable(Variables.Density, dgDegree); c.AddVariable(Variables.Momentum.xComponent, dgDegree); c.AddVariable(Variables.Momentum.yComponent, dgDegree); c.AddVariable(Variables.Energy, dgDegree); // Parameters c.AddVariable(Variables.Velocity.xComponent, dgDegree); c.AddVariable(Variables.Velocity.yComponent, dgDegree); c.AddVariable(Variables.Pressure, dgDegree); c.AddVariable(Variables.LocalMachNumber, dgDegree); // Grid c.GridFunc = delegate { double[] nodes = GenericBlas.Linspace(0.0, 1.0, noOfCellsPerDirection + 1); var grid = Grid2D.Cartesian2DGrid(nodes, nodes, periodicX: true, periodicY: true); return(grid); }; // Functions double b = 0.25; double c1 = 2.0; double k = 2.0 * Math.PI; double omega = 20.0 * Math.PI; double gamma = c.EquationOfState.HeatCapacityRatio; double MachScaling = gamma * c.MachNumber * c.MachNumber; double PressureScale = 1.0; Func <double[], double, double> rho = (X, t) => c1 + b * Math.Sin(k * (X[0] + X[1]) - omega * t); Func <double[], double, double> u0 = (X, t) => 1.0; Func <double[], double, double> u1 = (X, t) => 1.0; Func <double[], double, double> pressure = (X, t) => rho(X, t) / PressureScale; Func <double[], double, double> m0 = (X, t) => u0(X, t) * rho(X, t); Func <double[], double, double> m1 = (X, t) => u1(X, t) * rho(X, t); Func <double[], double, double> rhoE = (X, t) => pressure(X, t) / (gamma - 1) + 0.5 * MachScaling * rho(X, t) * (u0(X, t) * u0(X, t) + u1(X, t) * u1(X, t)); //Initial Values //c.InitialValues.Add(Variables.Density, X => rho(X, 0.0)); //c.InitialValues.Add(Variables.Momentum.xComponent, X => m0(X, 0.0)); //c.InitialValues.Add(Variables.Momentum.yComponent, X => m1(X, 0.0)); //c.InitialValues.Add(Variables.Energy, X => rhoE(X, 0.0)); //c.InitialValues.Add(Variables.Velocity.xComponent, X => u0(X, 0.0)); //c.InitialValues.Add(Variables.Velocity.yComponent, X => u1(X, 0.0)); //c.InitialValues.Add(Variables.Pressure, X => pressure(X, 0.0)); //MMS Sources c.CustomContinuitySources.Add(map => new AdHocSourceTerm(map, (X, t, state) => - b * Math.Cos(k * (X[0] + X[1]) - omega * t) * (-omega + 2.0 * k))); c.CustomMomentumSources[0].Add(map => new AdHocSourceTerm(map, (X, t, state) => - b * Math.Cos(k * (X[0] + X[1]) - omega * t) * (-omega + 2.0 * k + k / (PressureScale * MachScaling)) )); c.CustomMomentumSources[1].Add(map => new AdHocSourceTerm(map, (X, t, state) => - b * Math.Cos(k * (X[0] + X[1]) - omega * t) * (-omega + 2.0 * k + k / (PressureScale * MachScaling)) )); c.CustomEnergySources.Add(map => new AdHocSourceTerm(map, (X, t, state) => - b * Math.Cos(k * (X[0] + X[1]) - omega * t) * (-omega / (PressureScale * (gamma - 1.0)) - MachScaling * omega + 2.0 * k / (PressureScale * (gamma - 1.0)) + 1.0 + MachScaling + 2.0 + k / PressureScale) )); // Queries int QueryDegree = 10; c.Queries.Add("densityError", QueryLibrary.L2Error(Variables.Density, rho, QueryDegree)); c.Queries.Add("momentum0Error", QueryLibrary.L2Error(Variables.Momentum.xComponent, m0, QueryDegree)); c.Queries.Add("energyError", QueryLibrary.L2Error(Variables.Energy, rhoE, QueryDegree)); c.Queries.Add("velocity0Error", QueryLibrary.L2Error(Variables.Velocity.xComponent, u0, QueryDegree)); c.ProjectName = "MMS-Gassner2D_Mach=" + c.MachNumber + "_Flux=" + c.DiffusiveFluxType + "_h=1/" + noOfCellsPerDirection + "_p=" + dgDegree; return(c); }
public static IBMControl IBMALTSTestContactDiscontinuity(double levelSetPosition, int explicitOrder, int numOfClusters) { IBMControl c = new IBMControl(); //c.DbPath = @"c:\bosss_db"; c.savetodb = false; c.saveperiod = 1; c.PrintInterval = 1; double xMin = 0; double xMax = 1; double yMin = 0; double yMax = 1; int numOfCellsX = 40; int numOfCellsY = 10; int dgDegree = 2; c.DomainType = DomainTypes.StaticImmersedBoundary; c.LevelSetFunction = delegate(double[] X, double t) { double y = X[1]; return(y - levelSetPosition); }; c.LevelSetBoundaryTag = "AdiabaticSlipWall"; //c.MomentFittingVariant = XQuadFactoryHelper.MomentFittingVariants.Classic; //c.SurfaceHMF_ProjectNodesToLevelSet = false; //c.SurfaceHMF_RestrictNodes = true; //c.SurfaceHMF_UseGaussNodes = false; //c.VolumeHMF_NodeCountSafetyFactor = 3.0; //c.VolumeHMF_RestrictNodes = true; //c.VolumeHMF_UseGaussNodes = false; //c.LevelSetQuadratureOrder = 6; c.CutCellQuadratureType = XQuadFactoryHelper.MomentFittingVariants.OneStepGaussAndStokes; c.LevelSetQuadratureOrder = 6; c.AgglomerationThreshold = 0.2; c.AddVariable(IBMVariables.LevelSet, 1); c.ActiveOperators = Operators.Convection; c.ConvectiveFluxType = ConvectiveFluxTypes.OptimizedHLLC; // (A)LTS c.ExplicitScheme = ExplicitSchemes.LTS; c.ExplicitOrder = explicitOrder; c.NumberOfSubGrids = numOfClusters; c.ReclusteringInterval = 1; c.FluxCorrection = false; c.EquationOfState = IdealGas.Air; c.MachNumber = 1.0 / Math.Sqrt(c.EquationOfState.HeatCapacityRatio); c.ReynoldsNumber = 1.0; c.PrandtlNumber = 0.71; c.AddVariable(Variables.Density, dgDegree); c.AddVariable(Variables.Momentum.xComponent, dgDegree); c.AddVariable(Variables.Momentum.yComponent, dgDegree); c.AddVariable(Variables.Velocity.xComponent, dgDegree); c.AddVariable(Variables.Velocity.yComponent, dgDegree); c.AddVariable(Variables.Pressure, dgDegree); c.AddVariable(Variables.Energy, dgDegree); c.AddVariable(Variables.Entropy, dgDegree); c.AddVariable(Variables.LocalMachNumber, dgDegree); c.AddVariable(Variables.Rank, 0); c.AddVariable(Variables.CFL, 0); if (c.ExplicitScheme.Equals(ExplicitSchemes.LTS)) { c.AddVariable(Variables.LTSClusters, 0); } c.GridFunc = delegate { double[] xNodes = GenericBlas.Linspace(xMin, xMax, numOfCellsX + 1); double[] yNodes = GenericBlas.Linspace(yMin, yMax, numOfCellsY + 1); var grid = Grid2D.Cartesian2DGrid(xNodes, yNodes, periodicX: false, periodicY: false); // Boundary conditions grid.EdgeTagNames.Add(1, "SubsonicInlet"); grid.EdgeTagNames.Add(2, "SubsonicOutlet"); grid.EdgeTagNames.Add(3, "AdiabaticSlipWall"); grid.DefineEdgeTags(delegate(double[] X) { if (Math.Abs(X[1]) < 1e-14) // bottom { return(3); } else if (Math.Abs(X[1] - (yMax - yMin)) < 1e-14) // top { return(3); } else if (Math.Abs(X[0]) < 1e-14) // left { return(1); } else if (Math.Abs(X[0] - (xMax - xMin)) < 1e-14) // right { return(2); } else { throw new System.Exception("Problem with definition of boundary conditions"); } }); return(grid); }; Func <double[], double, double> DistanceToLine = delegate(double[] X, double t) { // direction vector Vector2D p1 = new Vector2D(0.5, 0.0); Vector2D p2 = new Vector2D(0.5, 1.0); Vector2D p = p2 - p1; // normal vector Vector2D n = new Vector2D(p.y, -p.x); n.Normalize(); // angle between line and x-axis //double alpha = Math.Atan(Math.Abs((p2.y - p1.y)) / Math.Abs((p2.x - p1.x))); double alpha = Math.PI / 2; // distance of a point X to the origin (normal to the line) double nDotX = n.x * (X[0]) + n.y * (X[1]); // shock speed double vs = 1; // distance to line double distance = nDotX - (Math.Sin(alpha) * p1.x + vs * t); return(distance); }; double cellSize = Math.Min((xMax - xMin) / numOfCellsX, (yMax - yMin) / numOfCellsY); Func <double, double> SmoothJump = delegate(double distance) { // smoothing should be in the range of h/p double maxDistance = 4.0 * cellSize / Math.Max(dgDegree, 1); return((Math.Tanh(distance / maxDistance) + 1.0) * 0.5); }; double densityLeft = 100.0; double densityRight = 1.0; double pressure = 1.0; double velocityXLeft = 2.0; double velocityY = 0.0; c.AddBoundaryCondition("SubsonicInlet", Variables.Density, (X, t) => densityLeft); c.AddBoundaryCondition("SubsonicInlet", Variables.Velocity.xComponent, (X, t) => velocityXLeft); c.AddBoundaryCondition("SubsonicInlet", Variables.Velocity.yComponent, (X, t) => velocityY); c.AddBoundaryCondition("SubsonicOutlet", Variables.Pressure, (X, t) => pressure); c.AddBoundaryCondition("AdiabaticSlipWall"); // Initial conditions c.InitialValues_Evaluators.Add(Variables.Density, X => densityLeft - SmoothJump(DistanceToLine(X, 0)) * (densityLeft - densityRight)); c.InitialValues_Evaluators.Add(Variables.Pressure, X => pressure); c.InitialValues_Evaluators.Add(Variables.Velocity.xComponent, X => velocityXLeft); c.InitialValues_Evaluators.Add(Variables.Velocity.yComponent, X => velocityY); // Time config c.dtMin = 0.0; c.dtMax = 1.0; c.CFLFraction = 0.3; c.Endtime = 0.05; c.NoOfTimesteps = int.MaxValue; // Queries for comparison c.Queries.Add("L2NormDensity", QueryLibrary.L2Norm(Variables.Density.Name)); c.Queries.Add("L2NormVelocityX", QueryLibrary.L2Norm(Variables.Velocity.xComponent.Name)); c.Queries.Add("L2NormPressure", QueryLibrary.L2Norm(Variables.Pressure)); return(c); }
public static LowMachSIMPLEControl SteadyCouetteFlowWithTemperatureGradient() { LowMachSIMPLEControl c = new LowMachSIMPLEControl(); c.DbPath = @"..\..\Base\06_ZipDatabases\NUnitTests.zip"; c.savetodb = false; c.GridGuid = new Guid("b3eb0eac-d1a1-440c-9f08-5dae1284607d"); c.GridPartType = GridPartType.METIS; c.ProjectName = "Couette with temperature gradient"; c.ProjectDescription = "Steady Low Mach SIMPLE"; // Required fields c.FieldOptions.Add( VariableNames.VelocityX, new FieldOpts() { Degree = 2, SaveToDB = FieldOpts.SaveToDBOpt.TRUE }); c.FieldOptions.Add( VariableNames.VelocityY, new FieldOpts() { Degree = 2, SaveToDB = FieldOpts.SaveToDBOpt.TRUE }); c.FieldOptions.Add( VariableNames.Pressure, new FieldOpts() { Degree = 1, SaveToDB = FieldOpts.SaveToDBOpt.TRUE }); c.FieldOptions.Add( VariableNames.Temperature, new FieldOpts() { Degree = 2, SaveToDB = FieldOpts.SaveToDBOpt.TRUE }); c.FieldOptions.Add( VariableNames.ThermodynamicPressure, new FieldOpts() { Degree = 0, SaveToDB = FieldOpts.SaveToDBOpt.TRUE }); c.FieldOptions.Add( "Density", new FieldOpts() { Degree = 2, SaveToDB = FieldOpts.SaveToDBOpt.TRUE }); c.FieldOptions.Add( "Eta", new FieldOpts() { Degree = 2, SaveToDB = FieldOpts.SaveToDBOpt.TRUE }); // Auxiliary fields c.FieldOptions.Add( "DivB4", new FieldOpts() { Degree = 1, SaveToDB = FieldOpts.SaveToDBOpt.FALSE }); c.FieldOptions.Add( "DivAfter", new FieldOpts() { Degree = 1, SaveToDB = FieldOpts.SaveToDBOpt.FALSE }); c.FieldOptions.Add( "OperatorTest_x", new FieldOpts() { Degree = 2, SaveToDB = FieldOpts.SaveToDBOpt.FALSE }); c.FieldOptions.Add( "OperatorTest_y", new FieldOpts() { Degree = 2, SaveToDB = FieldOpts.SaveToDBOpt.FALSE }); c.FieldOptions.Add( "OperatorAna_x", new FieldOpts() { Degree = 2, SaveToDB = FieldOpts.SaveToDBOpt.FALSE }); c.FieldOptions.Add( "OperatorAna_y", new FieldOpts() { Degree = 2, SaveToDB = FieldOpts.SaveToDBOpt.FALSE }); c.InitialValues_Evaluators.Add(VariableNames.VelocityX, X => X[1]); c.InitialValues_Evaluators.Add(VariableNames.VelocityY, X => 0.0); c.InitialValues_Evaluators.Add(VariableNames.Pressure, X => - 0.97809076838538383654 * Log(1.2 * X[1] + 0.4) - 0.06641065188714375468); c.InitialValues_Evaluators.Add(VariableNames.Temperature, X => (1.6 - 0.4) * X[1] + 0.4); c.Algorithm = SolutionAlgorithms.Steady_SIMPLE; c.NoOfTimesteps = 1; c.L2NormPressureCorrection = 1.0e-6; c.L2NormVelocityResidual = 1.0e-6; c.L2NormTemperatureResidual = 1e-6; c.PredictorSolverFactory = () => new PARDISOSolver(); c.CorrectorSolverFactory = () => new PARDISOSolver(); c.TemperatureSolverFactory = () => new PARDISOSolver(); c.AnalyticVelocityX = X => - 0.33333333333333333332 + 1.2523108062960316903 * (X[1] + 0.11013981986815616002).Pow(3.0 / 5.0); c.AnalyticVelocityY = X => 0.0; c.AnalyticPressure = X => - 1.4882576522041879973 * (1.9716158024185796207 * X[1] + 0.21715340932759252572).Pow(2.0 / 5.0) + 1.5508248735452649660; c.AnalyticTemperature = X => (1.9716158024185796207 * X[1] + 0.21715340932759252572).Pow(3.0 / 5.0); c.AddBoundaryValue("velocity_inlet_top", VariableNames.VelocityX, X => 1.0); c.AddBoundaryValue("velocity_inlet_top", VariableNames.VelocityY, X => 0.0); c.AddBoundaryValue("velocity_inlet_top", VariableNames.Temperature, X => 1.6); c.AddBoundaryValue("velocity_inlet_left", VariableNames.VelocityX, c.AnalyticVelocityX); c.AddBoundaryValue("velocity_inlet_left", VariableNames.VelocityY, c.AnalyticVelocityY); c.AddBoundaryValue("velocity_inlet_left", VariableNames.Temperature, c.AnalyticTemperature); c.AddBoundaryValue("velocity_inlet_right", VariableNames.VelocityX, c.AnalyticVelocityX); c.AddBoundaryValue("velocity_inlet_right", VariableNames.VelocityY, c.AnalyticVelocityY); c.AddBoundaryValue("velocity_inlet_right", VariableNames.Temperature, c.AnalyticTemperature); c.AddBoundaryValue("wall_bottom", VariableNames.Temperature, X => 0.4); c.PhysicsMode = PhysicsMode.LowMach; c.ThermodynamicPressureMode = ThermodynamicPressureMode.Constant; c.Reynolds = 10.0; c.Prandtl = 0.71; c.Gamma = 1.4; c.EoS = new MaterialLawLowMach(600.0, MaterialParamsMode.PowerLaw, false); c.Froude = 0.92303846; c.GravityDirection = new double[] { 0.0, -1.0 }; c.PressureReferencePoint = new double[] { 0.0, 0.5 }; c.PressureMeanValue = 0.0; c.PredictorApproximation = PredictorApproximations.BlockDiagonal; c.PressureStabilizationScaling = 0.0; c.PredictorApproximationUpdateCycle = 1; c.MaxNoSIMPLEsteps = 1000; c.SavePeriodSIMPLE = 1000; c.RelaxationFactorPressure = 0.5; c.RelexationFactorVelocity = 0.8; c.RelexationFactorTemperature = 1.0; c.RelaxationModeTemperature = RelaxationTypes.Implicit; c.ViscousPenaltyScaling = 1.0; c.MaxFlowSolverIterations = 1; c.MaxTemperatureSolverIterations = 1; c.PrintLinerSolverResults = false; int queryQuadOrder = 15; c.Queries.Add( "SolL2err_u", QueryLibrary.L2Error(VariableNames.VelocityX, c.AnalyticVelocityX, queryQuadOrder)); c.Queries.Add( "SolL2err_v", QueryLibrary.L2Error(VariableNames.VelocityY, c.AnalyticVelocityY, queryQuadOrder)); c.Queries.Add( "SolL2err_p", QueryLibrary.L2Error(VariableNames.Pressure, c.AnalyticPressure, queryQuadOrder)); c.Queries.Add( "SolL2err_T", QueryLibrary.L2Error(VariableNames.Temperature, c.AnalyticTemperature, queryQuadOrder)); return(c); }
/// <summary> /// 2D manufactured solution for the Euler equations with variable Mach number /// </summary> /// <param name="dgDegree"></param> /// <param name="noOfCellsPerDirection"></param> /// <returns></returns> public static CNSControl Euler2D(int dgDegree, int noOfCellsPerDirection) { CNSControl c = new CNSControl(); c.PrintInterval = 100; c.ResidualInterval = 100; c.saveperiod = 100000; c.DbPath = @"\\fdyprime\scratch\kraemer-eis\bosss_dbv2"; c.savetodb = true; c.Tags.Add("MMS"); c.ActiveOperators = Operators.Convection | Operators.CustomSource; c.ConvectiveFluxType = ConvectiveFluxTypes.OptimizedHLLC; c.ExplicitScheme = ExplicitSchemes.RungeKutta; c.ExplicitOrder = 1; c.EquationOfState = IdealGas.Air; c.AddVariable(Variables.Density, dgDegree); c.AddVariable(Variables.Momentum.xComponent, dgDegree); c.AddVariable(Variables.Energy, dgDegree); c.AddVariable(Variables.Velocity.xComponent, dgDegree); c.AddVariable(Variables.Pressure, dgDegree); c.AddVariable(Variables.LocalMachNumber, dgDegree); c.GridFunc = delegate { double[] nodes = GenericBlas.Linspace(0.0, Math.PI / 2, noOfCellsPerDirection + 1); var grid = Grid2D.Cartesian2DGrid(nodes, nodes); grid.EdgeTagNames.Add(1, "supersonicinlet"); grid.DefineEdgeTags(X => 1); return(grid); }; double gamma = c.EquationOfState.HeatCapacityRatio; c.MachNumber = 1; double Mach = c.MachNumber; double MachSq = Mach * Mach; double MachScaling = (gamma * c.MachNumber * c.MachNumber); Func <double[], double, double> rho = (X, t) => 1.0 + 0.5 * Math.Cos(2.0 * (X[0] + X[1])); Func <double[], double, double> u0 = (X, t) => 1.0 - 0.25 * Math.Cos(2.0 * (X[0] + X[1])); Func <double[], double, double> u1 = (X, t) => 1.0 + 0.5 * Math.Cos(4.0 * (X[0] + X[1])); Func <double[], double, double> p = (X, t) => 1.0 + 0.5 * Math.Cos(2.0 * (X[0] + X[1])); Func <double[], double, double> rhoE = (X, t) => p(X, t) / (gamma - 1) + 0.5 * gamma * Mach * Mach * rho(X, t) * (u0(X, t) * u0(X, t) + u1(X, t) * u1(X, t)); Func <double[], double, double> m0 = (X, t) => rho(X, t) * u0(X, t); Func <double[], double, double> m1 = (X, t) => rho(X, t) * u1(X, t); c.InitialValues_Evaluators.Add(Variables.Density, X => rho(X, 0.0)); c.InitialValues_Evaluators.Add(Variables.Momentum.xComponent, X => m0(X, 0.0)); c.InitialValues_Evaluators.Add(Variables.Momentum.yComponent, X => m1(X, 0.0)); c.InitialValues_Evaluators.Add(Variables.Energy, X => rhoE(X, 0.0)); c.AddBoundaryCondition("supersonicInlet", Variables.Density, rho); c.AddBoundaryCondition("supersonicInlet", Variables.Velocity.xComponent, u0); c.AddBoundaryCondition("supersonicInlet", Variables.Velocity.yComponent, u1); c.AddBoundaryCondition("supersonicInlet", Variables.Pressure, p); // MMS Sources c.CustomContinuitySources.Add(map => new AdHocSourceTerm(map, (X, t, state) => (7.0 * Math.Sin(2.0 * (X[0] + X[1])) + 7.0 * Math.Sin(4.0 * (X[0] + X[1])) + 3.0 * Math.Sin(6.0 * (X[0] + X[1]))) / 4.0 )); c.CustomMomentumSources[0].Add(map => new AdHocSourceTerm(map, (X, t, state) => ((160.0 + 245.0 * MachSq + 504.0 * MachSq * Math.Cos(2.0 * (X[0] + X[1])) + 189.0 * MachSq * Math.Cos(4.0 * (X[0] + X[1])) - 56.0 * MachSq * Math.Cos(6.0 * (X[0] + X[1]))) * Math.Sin(2.0 * (X[0] + X[1]))) / (224.0 * MachSq) )); c.CustomMomentumSources[1].Add(map => new AdHocSourceTerm(map, (X, t, state) => ((40.0 + 259.0 * MachSq + 728.0 * MachSq * Math.Cos(2.0 * (X[0] + X[1])) + 266.0 * MachSq * Math.Cos(4.0 * (X[0] + X[1])) + 98.0 * MachSq * Math.Cos(6.0 * (X[0] + X[1])) + 35.0 * MachSq * Math.Cos(8.0 * (X[0] + X[1]))) * Math.Sin(2.0 * (X[0] + X[1]))) / (56.0 * MachSq) )); c.CustomEnergySources.Add(map => new AdHocSourceTerm(map, (X, t, state) => (7.0 * (1600.0 + 1019.0 * MachSq + (2240.0 + 3762.0 * MachSq) * Math.Cos(2.0 * (X[0] + X[1])) + 12.0 * (80.0 + 113.0 * MachSq) * Math.Cos(4.0 * (X[0] + X[1])) + 978.0 * MachSq * Math.Cos(6.0 * (X[0] + X[1])) + 333.0 * MachSq * Math.Cos(8.0 * (X[0] + X[1])) + 84.0 * MachSq * Math.Cos(10.0 * (X[0] + X[1])) + 28.0 * MachSq * Math.Cos(12.0 * (X[0] + X[1]))) * Math.Sin(2.0 * (X[0] + X[1]))) / 1280.0 )); c.Queries.Add("densityError", QueryLibrary.L2Error(Variables.Density, rho)); c.Queries.Add("momentum0Error", QueryLibrary.L2Error(Variables.Momentum.xComponent, m0)); c.Queries.Add("momentum1Error", QueryLibrary.L2Error(Variables.Momentum.xComponent, m1)); c.Queries.Add("energyError", QueryLibrary.L2Error(Variables.Energy, rhoE)); c.dtMin = 0.0; c.dtMax = 1.0; c.CFLFraction = 0.1; c.Endtime = 10000.0; c.NoOfTimesteps = int.MaxValue; c.ResidualLoggerType = ResidualLoggerTypes.ChangeRate | ResidualLoggerTypes.Query; c.ResidualBasedTerminationCriteria.Add("changeRate_abs_rhoE", 1E-12); c.ProjectName = "MMS2D_Euler_Flux=" + c.ConvectiveFluxType + "_Mach=" + Mach + "_dg=" + dgDegree + "_cells=" + noOfCellsPerDirection; return(c); }