public Builder(IStructuralModel model, ISolver solver, INonLinearProvider provider, int numIncrements) : base(model, solver, provider, numIncrements) { MaxIterationsPerIncrement = 1000; NumIterationsForMatrixRebuild = 1; ResidualTolerance = 1E-3; }
private LoadControlAnalyzer(IStructuralModel model, ISolver solver, INonLinearProvider provider, IReadOnlyDictionary <int, INonLinearSubdomainUpdater> subdomainUpdaters, int numIncrements, int maxIterationsPerIncrement, int numIterationsForMatrixRebuild, double residualTolerance) : base(model, solver, provider, subdomainUpdaters, numIncrements, maxIterationsPerIncrement, numIterationsForMatrixRebuild, residualTolerance) { }
public FetiDPSubdomainGlobalMapping(IStructuralModel model, FetiDPDofSeparator dofSeparator, IStiffnessDistribution distribution) { this.model = model; this.dofSeparator = dofSeparator; this.distribution = distribution; }
public LinearAnalyzer(IStructuralModel model, ISolver solver, IAnalyzerProvider provider) { this.model = model; this.solver = solver; this.linearSystems = solver.LinearSystems; this.provider = provider; }
public override IFetiPreconditioner CreatePreconditioner(IStructuralModel model, IStiffnessDistribution stiffnessDistribution, IDofSeparator dofSeparator, ILagrangeMultipliersEnumerator lagrangeEnumerator, Dictionary <int, IFetiSubdomainMatrixManager> matrixManagers) { IReadOnlyList <ISubdomain> subdomains = model.Subdomains; int[] subdomainIDs = dofSeparator.BoundaryDofIndices.Keys.ToArray(); Dictionary <int, IMappingMatrix> boundaryBooleans = CalcBoundaryPreconditioningBooleanMatrices( stiffnessDistribution, dofSeparator, lagrangeEnumerator); foreach (int s in subdomainIDs) { if (!subdomains[s].StiffnessModified) { continue; } Debug.WriteLine($"{typeof(DiagonalDirichletPreconditioner).Name}.{this.GetType().Name}:" + $" Extracting boundary/internal submatrices of subdomain {s} for preconditioning"); IFetiSubdomainMatrixManager matrixManager = matrixManagers[s]; int[] boundaryDofs = dofSeparator.BoundaryDofIndices[s]; int[] internalDofs = dofSeparator.InternalDofIndices[s]; matrixManager.ExtractKbb(boundaryDofs); matrixManager.ExtractKbiKib(boundaryDofs, internalDofs); matrixManager.ExtractAndInvertKiiDiagonal(internalDofs); } return(new DiagonalDirichletPreconditioner(subdomainIDs, matrixManagers, boundaryBooleans)); }
private NewmarkDynamicAnalyzer(IStructuralModel model, ISolver solver, IImplicitIntegrationProvider provider, IChildAnalyzer childAnalyzer, double timeStep, double totalTime, double alpha, double delta) { this.model = model; this.linearSystems = solver.LinearSystems; this.solver = solver; this.provider = provider; this.ChildAnalyzer = childAnalyzer; this.beta = alpha; this.gamma = delta; this.timeStep = timeStep; this.totalTime = totalTime; this.ChildAnalyzer.ParentAnalyzer = this; // Initialize coefficients. It would make sense for them to be initialized in a different function, if they could // change during the analysis a0 = 1 / (alpha * timeStep * timeStep); a1 = delta / (alpha * timeStep); a2 = 1 / (alpha * timeStep); a3 = 1 / (2 * alpha) - 1; a4 = delta / alpha - 1; a5 = timeStep * 0.5 * (delta / alpha - 2); a6 = timeStep * (1 - delta); a7 = delta * timeStep; }
private PcgSolver(IStructuralModel model, PcgAlgorithm pcgAlgorithm, IPreconditionerFactory preconditionerFactory, IDofOrderer dofOrderer) : base(model, dofOrderer, new CsrAssembler(true), "PcgSolver") { this.pcgAlgorithm = pcgAlgorithm; this.preconditionerFactory = preconditionerFactory; }
public ProblemStructural(IStructuralModel model, ISolver solver) { this.model = model; this.linearSystems = solver.LinearSystems; this.solver = solver; this.DirichletLoadsAssembler = new DirichletEquivalentLoadsStructural(stiffnessProvider); }
public void PlotSubdomains(IStructuralModel model) { var writer = new MeshPartitionWriter(shuffleSubdomainColors); writer.WriteSubdomainElements($"{plotDirectoryPath}\\subdomains_{analysisStep}.vtk", model); writer.WriteBoundaryNodes($"{plotDirectoryPath}\\boundary_nodes_{analysisStep}.vtk", model); ++analysisStep; }
public void SolveTimestep(int i) { Debug.WriteLine("Newmark step: {0}", i); if (CreateNewModel != null) { CreateNewModel(uu, uc, v, modelsForReplacement, solversForReplacement, providersForReplacement, childAnalyzersForReplacement); model = modelsForReplacement[0]; solver = solversForReplacement[0]; linearSystems = solver.LinearSystems; provider = providersForReplacement[0]; ChildAnalyzer = childAnalyzersForReplacement[0]; ChildAnalyzer.ParentAnalyzer = this; InitializeInternal(true); } IDictionary <int, IVector> rhsVectors = provider.GetRhsFromHistoryLoad(i); foreach (var l in linearSystems.Values) { l.RhsVector = rhsVectors[l.Subdomain.ID]; } InitializeRhs(); CalculateRhsImplicit(); DateTime start = DateTime.Now; ChildAnalyzer.Solve(); DateTime end = DateTime.Now; UpdateVelocityAndAcceleration(i); UpdateResultStorages(start, end); // Print output results in *.txt file string path0 = Path.Combine(Directory.GetCurrentDirectory(), "MsolveOutput"); var path2 = Path.Combine(path0, $"MSolveHyperelasticDynamicsImplicitResults.txt"); using (var fileName = new StreamWriter(path2, true)) { double currentTime = ((i + 1) * timeStep); string strTimeStep = currentTime.ToString(); var totalSolution = ChildAnalyzer.Responses[0][1]; string strTotalSolution = totalSolution.ToString(); fileName.WriteLine(strTimeStep + ", " + strTotalSolution); } //if (CreateNewModel != null) //{ // CreateNewModel(uu, uc, v, modelsForReplacement, solversForReplacement, providersForReplacement, childAnalyzersForReplacement); // model = modelsForReplacement[0]; // solver = solversForReplacement[0]; // linearSystems = solver.LinearSystems; // provider = providersForReplacement[0]; // ChildAnalyzer = childAnalyzersForReplacement[0]; // ChildAnalyzer.ParentAnalyzer = this; // InitializeInternal(true); //} }
public HomogenizationAnalyzer(IStructuralModel model, ISolver solver, IStaticProvider provider, IReferenceVolumeElement rve) { this.model = model; this.linearSystems = solver.LinearSystems; this.solver = solver; this.provider = provider; this.rve = rve; }
public ISolver BuildSolver(IStructuralModel model) { if (!(model is IStructuralAsymmetricModel asymmetricModel)) { throw new ArgumentException("Gmres solver builder can be used only with asymmetric models."); } return(new GmresSolver(asymmetricModel, RowDofOrderer, ColumnDofOrderer)); }
public StaticAnalyzer(IStructuralModel model, ISolver solver, IStaticProvider provider, IChildAnalyzer childAnalyzer) { this.model = model; this.linearSystems = solver.LinearSystems; this.solver = solver; this.provider = provider; this.ChildAnalyzer = childAnalyzer; this.ChildAnalyzer.ParentAnalyzer = this; }
protected NonLinearAnalyzerBuilderBase(IStructuralModel model, ISolver solver, INonLinearProvider provider, int numIncrements) { //TODO: this should belong to all (child) analyzer builders this.model = model; this.solver = solver; this.provider = provider; this.numIncrements = numIncrements; SubdomainUpdaters = CreateDefaultSubdomainUpdaters(); }
private static void ReplaceLambdaGInModel(IStructuralModel model, double lg) { foreach (var e in model.Elements) { var et = (ContinuumElement3DNonLinearDefGrad)e.ElementType; var bindFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static; FieldInfo field = typeof(ContinuumElement3DNonLinearDefGrad).GetField("lambdag", bindFlags); field.SetValue(et, lg); } }
private double beta = 0.25, gamma = 0.5; // constant acceleration is the default public Builder(IStructuralModel model, ISolver solver, IImplicitIntegrationProvider provider, IChildAnalyzer childAnalyzer, double timeStep, double totalTime) { this.model = model; this.solver = solver; this.provider = provider; this.childAnalyzer = childAnalyzer; this.timeStep = timeStep; this.totalTime = totalTime; }
/// <summary> /// Creates both <see cref="BooleanMatrices"/> and <see cref="LagrangeMultipliers"/>. For use in heterogeneous problems. /// </summary> /// <param name="model"></param> public void DefineLagrangesAndBooleanMatrices(IStructuralModel model) { var numFreeDofs = new Dictionary <int, int>(); var freeDofOrderings = new Dictionary <int, DofTable>(); foreach (ISubdomain subdomain in model.Subdomains) { numFreeDofs[subdomain.ID] = subdomain.FreeDofOrdering.NumFreeDofs; freeDofOrderings[subdomain.ID] = subdomain.FreeDofOrdering.FreeDofs; } base.DefineLagrangesAndBooleanMatrices(model, numFreeDofs, freeDofOrderings); }
/// <summary> /// Creates both <see cref="BooleanMatrices"/> and <see cref="LagrangeMultipliers"/>. For use in heterogeneous problems. /// </summary> /// <param name="model"></param> public void DefineLagrangesAndBooleanMatrices(IStructuralModel model) { var numRemainderDofs = new Dictionary <int, int>(); var remainderDofOrderings = new Dictionary <int, DofTable>(); foreach (ISubdomain subdomain in model.Subdomains) { numRemainderDofs[subdomain.ID] = dofSeparator.RemainderDofIndices[subdomain.ID].Length; remainderDofOrderings[subdomain.ID] = dofSeparator.RemainderDofOrderings[subdomain.ID]; } base.DefineLagrangesAndBooleanMatrices(model, numRemainderDofs, remainderDofOrderings); }
public IGlobalFreeDofOrdering OrderFreeDofs(IStructuralModel model) { if (doOptimizationsIfSingleSubdomain && (model.Subdomains.Count == 1)) { ISubdomain subdomain = model.Subdomains.First(); // Order subdomain dofs (int numSubdomainFreeDofs, DofTable subdomainFreeDofs) = freeOrderingStrategy.OrderSubdomainDofs(subdomain); ISubdomainFreeDofOrdering subdomainOrdering; if (cacheElementToSubdomainDofMaps) { subdomainOrdering = new SubdomainFreeDofOrderingCaching(numSubdomainFreeDofs, subdomainFreeDofs); } else { subdomainOrdering = new SubdomainFreeDofOrderingGeneral(numSubdomainFreeDofs, subdomainFreeDofs); } // Reorder subdomain dofs reorderingStrategy.ReorderDofs(subdomain, subdomainOrdering); // Order global dofs return(new GlobalFreeDofOrderingSingle(subdomain, subdomainOrdering)); } else { // Order subdomain dofs var subdomainOrderings = new Dictionary <ISubdomain, ISubdomainFreeDofOrdering>(model.Subdomains.Count); foreach (ISubdomain subdomain in model.Subdomains) { (int numSubdomainFreeDofs, DofTable subdomainFreeDofs) = freeOrderingStrategy.OrderSubdomainDofs(subdomain); ISubdomainFreeDofOrdering subdomainOrdering; if (cacheElementToSubdomainDofMaps) { subdomainOrdering = new SubdomainFreeDofOrderingCaching( numSubdomainFreeDofs, subdomainFreeDofs); } else { subdomainOrdering = new SubdomainFreeDofOrderingGeneral(numSubdomainFreeDofs, subdomainFreeDofs); } subdomainOrderings.Add(subdomain, subdomainOrdering); // Reorder subdomain dofs reorderingStrategy.ReorderDofs(subdomain, subdomainOrdering); } // Order global dofs (int numGlobalFreeDofs, DofTable globalFreeDofs) = freeOrderingStrategy.OrderGlobalDofs(model); return(new GlobalFreeDofOrderingGeneral(numGlobalFreeDofs, globalFreeDofs, subdomainOrderings)); } }
internal NonLinearAnalyzerBase(IStructuralModel model, ISolver solver, INonLinearProvider provider, IReadOnlyDictionary <int, INonLinearSubdomainUpdater> subdomainUpdaters, int numIncrements, int maxIterationsPerIncrement, int numIterationsForMatrixRebuild, double residualTolerance) { this.model = model; this.solver = solver; this.provider = provider; this.subdomainUpdaters = subdomainUpdaters; this.linearSystems = solver.LinearSystems; this.numIncrements = numIncrements; this.maxIterationsPerIncrement = maxIterationsPerIncrement; this.numIterationsForMatrixRebuild = numIterationsForMatrixRebuild; this.residualTolerance = residualTolerance; }
public ConvectionDiffusionImplicitDynamicAnalyzer_Beta(IStructuralModel model, ISolver solver, IConvectionDiffusionIntegrationProvider provider, IChildAnalyzer childAnalyzer, double timeStep, double totalTime, IVector initialTemperature = null) { this.model = model; this.linearSystems = solver.LinearSystems; this.solver = solver; //solver.PreventFromOverwrittingSystemMatrices(); //TODO: If the scheme is purely implicit we can overwrite the matrix. this.provider = provider; this.ChildAnalyzer = childAnalyzer; this.timeStep = timeStep; this.totalTime = totalTime; this.ChildAnalyzer.ParentAnalyzer = this; this.initialTemperature = initialTemperature; }
public ODEDynamicAnalyzer(IStructuralModel model, ISolver solver, IImplicitIntegrationProvider provider, IChildAnalyzer childAnalyzer, double beta, double timeStep, double totalTime, IVector initialValue = null) { this.model = model; this.linearSystems = solver.LinearSystems; this.solver = solver; //solver.PreventFromOverwrittingSystemMatrices(); //TODO: If the scheme is purely implicit we can overwrite the matrix. this.provider = provider; this.ChildAnalyzer = childAnalyzer; this.beta = beta; this.timeStep = timeStep; this.totalTime = totalTime; this.ChildAnalyzer.ParentAnalyzer = this; }
public void PlotSubdomains(IStructuralModel model) { var writer = new MeshPartitionWriter(shuffleSubdomainColors); writer.WriteSubdomainElements($"{plotDirectoryPath}\\subdomains_{analysisStep}.vtk", model); writer.WriteBoundaryNodes($"{plotDirectoryPath}\\boundary_nodes_{analysisStep}.vtk", model); var allCornerNodes = new HashSet <INode>(); foreach (IEnumerable <INode> cornerNodes in solver.CornerNodesOfSubdomains.Values) { allCornerNodes.UnionWith(cornerNodes); } writer.WriteSpecialNodes($"{plotDirectoryPath}\\corner_nodes_{analysisStep}.vtk", "corner_nodes", allCornerNodes); ++analysisStep; }
/// <summary> /// Only <see cref="BooleanMatrices"/> will be explicitly created. <see cref="LagrangeMultipliers"/> will not. /// For use in homogeneous problems, where we do not need that much info about lagrange multipliers and boundary dofs. /// </summary> /// <param name="model"></param> protected void DefineBooleanMatrices(IStructuralModel model, Dictionary <int, int> numRemainderDofs, Dictionary <int, DofTable> remainderDofOrderings) //TODO: Rename the "remainder" { List <(INode node, IDofType[] dofs, ISubdomain[] subdomainsPlus, ISubdomain[] subdomainsMinus)> boundaryNodeData = DefineBoundaryDofConstraints(dofSeparator); // Create the signed boolean matrices. BooleanMatrices = new Dictionary <int, SignedBooleanMatrixColMajor>(); foreach (ISubdomain subdomain in model.Subdomains) { BooleanMatrices[subdomain.ID] = new SignedBooleanMatrixColMajor(NumLagrangeMultipliers, numRemainderDofs[subdomain.ID]); } // Fill the boolean matrices: node major, subdomain medium, dof minor. TODO: not sure about this order. int lag = 0; // Lagrange multiplier index foreach ((INode node, IDofType[] dofs, ISubdomain[] subdomainsPlus, ISubdomain[] subdomainsMinus)
protected SingleSubdomainSolverBase(IStructuralModel model, IDofOrderer dofOrderer, IGlobalMatrixAssembler <TMatrix> assembler, string name) { if (model.Subdomains.Count != 1) { throw new InvalidSolverException( $"{name} can be used if there is only 1 subdomain"); } this.model = model; subdomain = model.Subdomains[0]; linearSystem = new SingleSubdomainSystem <TMatrix>(subdomain); LinearSystems = new Dictionary <int, ILinearSystem>() { { subdomain.ID, linearSystem } }; linearSystem.MatrixObservers.Add(this); this.dofOrderer = dofOrderer; this.assembler = assembler; this.Logger = new SolverLogger(name); }
public MicrostructureBvpNRNLAnalyzer(IStructuralModel model, ISolver solver, Dictionary <int, NonLinearSubdomainUpdaterWithInitialConditions> subdomainUpdaters, INonLinearProvider provider, int increments, Dictionary <int, IVector> uInitialFreeDOFDisplacementsPerSubdomain, Dictionary <int, Node> boundaryNodes, Dictionary <int, Dictionary <IDofType, double> > initialConvergedBoundaryDisplacements, Dictionary <int, Dictionary <IDofType, double> > totalBoundaryDisplacements, Dictionary <int, EquivalentContributionsAssebler> equivalentContributionsAssemblers)//, ISubdomainGlobalMapping[] mappings) { this.model = model; this.solver = solver; this.subdomainUpdaters = subdomainUpdaters; //this.mappings = mappings; this.linearSystems = solver.LinearSystems; this.provider = provider; this.increments = increments; //this.globalRhs = Vector.CreateZero(model.GlobalDofOrdering.NumGlobalFreeDofs); this.u = uInitialFreeDOFDisplacementsPerSubdomain; //prosthiki MS, TODO:possibly check for compatibility elements format: u.Add(subdomain.ID, new Vector(subdomain.RHS.Length)); //this.uPlusdu = uInitialFreeDOFDisplacementsPerSubdomain; //prosthiki MS: commented out possible pass by reference this.boundaryNodes = boundaryNodes; this.initialConvergedBoundaryDisplacements = initialConvergedBoundaryDisplacements; this.totalBoundaryDisplacements = totalBoundaryDisplacements; this.equivalentContributionsAssemblers = equivalentContributionsAssemblers; //InitializeInternalVectors(); }
public void WriteBoundaryNodes(string path, IStructuralModel model) { using (var writer = new StreamWriter(path)) { // Header writer.Write("# vtk DataFile Version "); writer.WriteLine(vtkReaderVersion); writer.WriteLine(path); writer.Write("ASCII\n\n"); writer.WriteLine("DATASET UNSTRUCTURED_GRID"); // Write all nodes without repeating the boundary ones var boundaryNodes = new List <INode>(); foreach (INode node in model.Nodes) { if (node.SubdomainsDictionary.Count > 1) { boundaryNodes.Add(node); } } writer.WriteLine($"POINTS {boundaryNodes.Count} double"); foreach (INode node in boundaryNodes) { writer.WriteLine($"{node.X} {node.Y} {node.Z}"); } writer.WriteLine(); // Differentiate between crosspoint nodes (more than 2 subdomains) writer.WriteLine("POINT_DATA " + boundaryNodes.Count); writer.WriteLine($"SCALARS nodes_boundary_crosspoint double 1"); writer.WriteLine("LOOKUP_TABLE default"); foreach (INode node in boundaryNodes) { writer.WriteLine((node.SubdomainsDictionary.Count == 2) ? 0.0 : 1.0); } } }
/// <summary> /// </summary> /// <param name="model"></param> /// <param name="bottomLeftCoords"></param> /// <param name="topRightCoords"></param> /// <param name="thickness"></param> /// <param name="macroscopicTemperatureGradient"></param> /// <param name="meshTolerance">The default is 1E-10 * min(|xMax-xMin|, |yMax-yMin|)</param> public ThermalSquareRve(IStructuralModel model, Vector2 bottomLeftCoords, Vector2 topRightCoords, double thickness, Vector2 macroscopicTemperatureGradient, double meshTolerance) { this.model = model; this.xMin = bottomLeftCoords[0]; this.yMin = bottomLeftCoords[1]; this.xMax = topRightCoords[0]; this.yMax = topRightCoords[1]; this.thickness = thickness; this.macroscopicTemperatureGradient = macroscopicTemperatureGradient; // Find the nodes of each edge leftNodes = new HashSet <INode>(); rightNodes = new HashSet <INode>(); bottomNodes = new HashSet <INode>(); topNodes = new HashSet <INode>(); foreach (INode node in model.Nodes) { // Top and right edges are prioritized for corner nodes. //TODO: should the corner nodes be handled differently? if (Math.Abs(node.Y - yMax) <= meshTolerance) { topNodes.Add(node); } else if (Math.Abs(node.X - xMax) <= meshTolerance) { rightNodes.Add(node); } else if (Math.Abs(node.Y - yMin) <= meshTolerance) { bottomNodes.Add(node); } else if (Math.Abs(node.X - xMin) <= meshTolerance) { leftNodes.Add(node); } } }
public PcgSolver BuildSolver(IStructuralModel model) => new PcgSolver(model, PcgAlgorithm, PreconditionerFactory, DofOrderer);
ISolver ISolverBuilder.BuildSolver(IStructuralModel model) => BuildSolver(model);