Ejemplo n.º 1
0
        private static Tuple <Model, IModelReader> CreateModel3(double C1, double C2, IDynamicMaterial commonDynamicMaterialProperties, double b, double[] l, double lambdag)
        {
            double poissonV    = 0.2;
            double muLame      = 2 * C1;
            double bulkModulus = 2 * muLame * (1 + poissonV) / (3 * (1 - 2 * poissonV));
            string filename    = Path.Combine(Directory.GetCurrentDirectory(), "InputFiles", "TumorGrowthModel", "9hexa.mphtxt");
            var    modelReader = new ComsolMeshReader1(filename, C1, C2, 1, commonDynamicMaterialProperties, lambdag);
            Model  model       = modelReader.CreateModelFromFile();
            //Boundary Conditions
            var lx = l[0];
            var ly = l[1];
            var lz = l[2];
            var distributedLoad = new DistributedLoad(lx, ly, lz);
            //var flux2 = new FluxLoad(f2);
            //var dir1 = new DirichletDistribution(list => {
            //    return Vector.CreateWithValue(list.Count, b1);
            //});
            //var dir2 = new DirichletDistribution(list => {
            //    return Vector.CreateWithValue(list.Count, b2);
            //});
            //var weakDirichlet1 = new WeakDirichlet(dir1, k);
            //var weakDirichlet2 = new WeakDirichlet(dir2, k);

            //var dirichletFactory1 = new SurfaceLoadElementFactory(weakDirichlet1);
            //var dirichletFactory2 = new SurfaceLoadElementFactory(weakDirichlet2);
            var distributedLoadFactory = new SurfaceLoadElementFactory(distributedLoad);

            //var fluxFactory2 = new SurfaceLoadElementFactory(flux2);
            //var boundaryFactory3D = new SurfaceBoundaryFactory3D(0,
            //    new ConvectionDiffusionMaterial(k, new double[] { 0, 0, 0 }, 0));


            int[] boundaryIDs = new int[] { 0, 5 };
            foreach (int boundaryID in boundaryIDs)
            {
                foreach (IReadOnlyList <Node> nodes in modelReader.quadBoundaries[boundaryID])
                {
                    foreach (Node node in nodes)
                    {
                        node.Constraints.Add(new Constraint()
                        {
                            Amount = b,
                            DOF    = StructuralDof.TranslationX
                        });
                        node.Constraints.Add(new Constraint()
                        {
                            Amount = b,
                            DOF    = StructuralDof.TranslationY
                        });
                        node.Constraints.Add(new Constraint()
                        {
                            Amount = b,
                            DOF    = StructuralDof.TranslationZ
                        });
                    }
                }
            }
            return(new Tuple <Model, IModelReader>(model, modelReader));
        }
        private static Tuple <Model, IModelReader> CreateStructuralModel(double C1, double C2, IDynamicMaterial commonDynamicMaterialProperties, double b, double[] l, double lg)
        {
            string filename    = Path.Combine(Directory.GetCurrentDirectory(), "InputFiles", "TumorGrowthModel", "9hexa.mphtxt");
            double poisonRatio = .45;
            double bulkModulus = 4 * C1 * (1 + poisonRatio) / 3 / (1 - 2 * poisonRatio);
            var    modelReader = new ComsolMeshReader1(filename, C1, C2, bulkModulus, commonDynamicMaterialProperties, lg);
            Model  model       = modelReader.CreateModelFromFile();
            //Boundary Conditions
            var lx = l[0];
            var ly = l[1];
            var lz = l[2];
            var distributedLoad        = new DistributedLoad(lx, ly, lz);
            var distributedLoadFactory = new SurfaceLoadElementFactory(distributedLoad);


            int[] boundaryIDs = new int[] { 0 };
            foreach (int boundaryID in boundaryIDs)
            {
                foreach (IReadOnlyList <Node> nodes in modelReader.quadBoundaries[boundaryID])
                {
                    foreach (Node node in nodes)
                    {
                        node.Constraints.Add(new Constraint()
                        {
                            Amount = b,
                            DOF    = StructuralDof.TranslationX
                        });
                        //node.Constraints.Add(new Constraint()
                        //{
                        //    Amount = b,
                        //    DOF = StructuralDof.TranslationY
                        //});
                        //node.Constraints.Add(new Constraint()
                        //{
                        //    Amount = b,
                        //    DOF = StructuralDof.TranslationZ
                        //});
                    }
                }
            }
            boundaryIDs = new int[] { 1 };
            foreach (int boundaryID in boundaryIDs)
            {
                foreach (IReadOnlyList <Node> nodes in modelReader.quadBoundaries[boundaryID])
                {
                    foreach (Node node in nodes)
                    {
                        //node.Constraints.Add(new Constraint()
                        //{
                        //    Amount = b,
                        //    DOF = StructuralDof.TranslationX
                        //});
                        node.Constraints.Add(new Constraint()
                        {
                            Amount = b,
                            DOF    = StructuralDof.TranslationY
                        });
                        //node.Constraints.Add(new Constraint()
                        //{
                        //    Amount = b,
                        //    DOF = StructuralDof.TranslationZ
                        //});
                    }
                }
            }
            boundaryIDs = new int[] { 2 };
            foreach (int boundaryID in boundaryIDs)
            {
                foreach (IReadOnlyList <Node> nodes in modelReader.quadBoundaries[boundaryID])
                {
                    foreach (Node node in nodes)
                    {
                        //node.Constraints.Add(new Constraint()
                        //{
                        //    Amount = b,
                        //    DOF = StructuralDof.TranslationX
                        //});
                        //node.Constraints.Add(new Constraint()
                        //{
                        //    Amount = b,
                        //    DOF = StructuralDof.TranslationY
                        //});
                        node.Constraints.Add(new Constraint()
                        {
                            Amount = b,
                            DOF    = StructuralDof.TranslationZ
                        });
                    }
                }
            }
            boundaryIDs = new int[] { 5 };
            int QuadID = model.ElementsDictionary.Count + 1;

            foreach (int boundaryID in boundaryIDs)
            {
                foreach (IReadOnlyList <Node> nodes in modelReader.quadBoundaries[boundaryID])
                {
                    foreach (Node node in nodes)
                    {
                        model.Loads.Add(new Load()
                        {
                            Node = node, DOF = StructuralDof.TranslationX, Amount = +250.0
                        });
                    }

                    //var distributedLoadElement = distributedLoadFactory.CreateElement(CellType.Quad4, nodes);
                    //model.SurfaceLoads.Add(distributedLoadElement);
                }
            }
            return(new Tuple <Model, IModelReader>(model, modelReader));
        }
Ejemplo n.º 3
0
        private static Tuple <Model, IModelReader> CreateStructuralModel(double[] C1, double[] C2, IDynamicMaterial[] commonDynamicMaterialProperties, double b, double[] l, double lambdag)
        {
            double[] poissonV       = new double[C1.Length];
            double[] muLame         = new double[C1.Length];
            double[] bulkModulusnew = new double[C1.Length];
            for (int i = 0; i < C1.Length; i++)
            {
                poissonV[i]       = 0.2;
                muLame[i]         = 2 * C1[i];
                bulkModulusnew[i] = 2 * muLame[i] * (1 + poissonV[i]) / (3 * (1 - 2 * poissonV[i]));
            }
            string filename    = Path.Combine(Directory.GetCurrentDirectory(), "InputFiles", "TumorGrowthModel", "125HexaHyperelasticCube.mphtxt");
            var    modelReader = new ComsolMeshReader1(filename, C1, C2, bulkModulusnew, commonDynamicMaterialProperties, new double[] { lambdag, 1 });
            Model  model       = modelReader.CreateModelFromFile();
            //Boundary Conditions
            var lx = l[0];
            var ly = l[1];
            var lz = l[2];
            var distributedLoad = new DistributedLoad(lx, ly, lz);
            //var flux2 = new FluxLoad(f2);
            //var dir1 = new DirichletDistribution(list => {
            //    return Vector.CreateWithValue(list.Count, b1);
            //});
            //var dir2 = new DirichletDistribution(list => {
            //    return Vector.CreateWithValue(list.Count, b2);
            //});
            //var weakDirichlet1 = new WeakDirichlet(dir1, k);
            //var weakDirichlet2 = new WeakDirichlet(dir2, k);

            //var dirichletFactory1 = new SurfaceLoadElementFactory(weakDirichlet1);
            //var dirichletFactory2 = new SurfaceLoadElementFactory(weakDirichlet2);
            var distributedLoadFactory = new SurfaceLoadElementFactory(distributedLoad);

            //var fluxFactory2 = new SurfaceLoadElementFactory(flux2);
            //var boundaryFactory3D = new SurfaceBoundaryFactory3D(0,
            //    new ConvectionDiffusionMaterial(k, new double[] { 0, 0, 0 }, 0));


            int[] boundaryIDs = new int[] { 0 };
            foreach (int boundaryID in boundaryIDs)
            {
                foreach (Node node in modelReader.nodeBoundaries[boundaryID])
                {
                    node.Constraints.Add(new Constraint()
                    {
                        Amount = b,
                        DOF    = StructuralDof.TranslationX
                    });
                    //node.Constraints.Add(new Constraint()
                    //{
                    //    Amount = b,
                    //    DOF = StructuralDof.TranslationY
                    //});
                    //node.Constraints.Add(new Constraint()
                    //{
                    //    Amount = b,
                    //    DOF = StructuralDof.TranslationZ
                    //});
                }
            }
            boundaryIDs = new int[] { 1 };
            foreach (int boundaryID in boundaryIDs)
            {
                foreach (Node node in modelReader.nodeBoundaries[boundaryID])
                {
                    //node.Constraints.Add(new Constraint()
                    //{
                    //    Amount = b,
                    //    DOF = StructuralDof.TranslationX
                    //});
                    node.Constraints.Add(new Constraint()
                    {
                        Amount = b,
                        DOF    = StructuralDof.TranslationY
                    });
                    //node.Constraints.Add(new Constraint()
                    //{
                    //    Amount = b,
                    //    DOF = StructuralDof.TranslationZ
                    //});
                }
            }
            boundaryIDs = new int[] { 2 };
            foreach (int boundaryID in boundaryIDs)
            {
                foreach (Node node in modelReader.nodeBoundaries[boundaryID])
                {
                    //node.Constraints.Add(new Constraint()
                    //{
                    //    Amount = b,
                    //    DOF = StructuralDof.TranslationX
                    //});
                    //node.Constraints.Add(new Constraint()
                    //{
                    //    Amount = b,
                    //    DOF = StructuralDof.TranslationY
                    //});
                    node.Constraints.Add(new Constraint()
                    {
                        Amount = b,
                        DOF    = StructuralDof.TranslationZ
                    });
                }
            }
            boundaryIDs = new int[] { 3 };
            int QuadID = model.ElementsDictionary.Count + 1;

            //foreach (int boundaryID in boundaryIDs)
            //{
            //    foreach (IReadOnlyList<Node> nodes in modelReader.quadBoundaries[boundaryID])
            //    {
            //        //var distributedLoadElement = distributedLoadFactory.CreateElement(CellType.Quad4, nodes);
            //        //model.SurfaceLoads.Add(distributedLoadElement);
            //        //var dirichletElement2 = dirichletFactory2.CreateElement(CellType.Quad4, nodes);
            //        //model.SurfaceLoads.Add(dirichletElement2);
            //        //var SurfaceBoundaryElement = boundaryFactory3D.CreateElement(CellType.Quad4, nodes);
            //        //var element = new Element();
            //        //element.ID = QuadID;
            //        //element.ElementType = SurfaceBoundaryElement;
            //        //model.SubdomainsDictionary[0].Elements.Add(element);
            //        //model.ElementsDictionary.Add(QuadID, element);
            //        //foreach (Node node in nodes)
            //        //{
            //        //    element.AddNode(node);
            //        //}
            //        //QuadID += 1;
            //        foreach (Node node in nodes)
            //        {
            //            model.Loads.Add(new Load() { Node = node, DOF = StructuralDof.TranslationZ, Amount = +100.0 });
            //        }
            //    }
            //}
            //int[] nodeIDs = new int[] { 1, 2, 3, 4 };
            int[] nodeIDs = new int[] { 0, 5, 10, 40 };
            foreach (int nodeID in nodeIDs)
            {
                model.Loads.Add(new Load()
                {
                    Node = model.NodesDictionary[nodeID], DOF = StructuralDof.TranslationZ, Amount = +lz
                });
            }
            return(new Tuple <Model, IModelReader>(model, modelReader));
        }
        private static Tuple <Model, IModelReader> CreateStructuralModel(double C1, double C2, IDynamicMaterial commonDynamicMaterialProperties, double b, double[] l)
        {
            string filename    = Path.Combine(Directory.GetCurrentDirectory(), "InputFiles", "TumorGrowthModel", "9hexa.mphtxt");
            var    modelReader = new ComsolMeshReader1(filename, C1, C2, 1, commonDynamicMaterialProperties);
            Model  model       = modelReader.CreateModelFromFile();
            //Boundary Conditions
            var lx = l[0];
            var ly = l[1];
            var lz = l[2];
            var distributedLoad = new DistributedLoad(lx, ly, lz);
            //var flux2 = new FluxLoad(f2);
            //var dir1 = new DirichletDistribution(list => {
            //    return Vector.CreateWithValue(list.Count, b1);
            //});
            //var dir2 = new DirichletDistribution(list => {
            //    return Vector.CreateWithValue(list.Count, b2);
            //});
            //var weakDirichlet1 = new WeakDirichlet(dir1, k);
            //var weakDirichlet2 = new WeakDirichlet(dir2, k);

            //var dirichletFactory1 = new SurfaceLoadElementFactory(weakDirichlet1);
            //var dirichletFactory2 = new SurfaceLoadElementFactory(weakDirichlet2);
            var distributedLoadFactory = new SurfaceLoadElementFactory(distributedLoad);

            //var fluxFactory2 = new SurfaceLoadElementFactory(flux2);
            //var boundaryFactory3D = new SurfaceBoundaryFactory3D(0,
            //    new ConvectionDiffusionMaterial(k, new double[] { 0, 0, 0 }, 0));


            int[] boundaryIDs = new int[] { 0, };
            foreach (int boundaryID in boundaryIDs)
            {
                foreach (IReadOnlyList <Node> nodes in modelReader.quadBoundaries[boundaryID])
                {
                    foreach (Node node in nodes)
                    {
                        node.Constraints.Add(new Constraint()
                        {
                            Amount = b,
                            DOF    = StructuralDof.TranslationX
                        });
                        node.Constraints.Add(new Constraint()
                        {
                            Amount = b,
                            DOF    = StructuralDof.TranslationY
                        });
                        node.Constraints.Add(new Constraint()
                        {
                            Amount = b,
                            DOF    = StructuralDof.TranslationZ
                        });
                    }
                }
            }
            boundaryIDs = new int[] { 5 };
            int QuadID = model.ElementsDictionary.Count + 1;

            foreach (int boundaryID in boundaryIDs)
            {
                foreach (IReadOnlyList <Node> nodes in modelReader.quadBoundaries[boundaryID])
                {
                    var distributedLoadElement = distributedLoadFactory.CreateElement(CellType.Quad4, nodes);
                    model.SurfaceLoads.Add(distributedLoadElement);
                    //var dirichletElement2 = dirichletFactory2.CreateElement(CellType.Quad4, nodes);
                    //model.SurfaceLoads.Add(dirichletElement2);
                    //var SurfaceBoundaryElement = boundaryFactory3D.CreateElement(CellType.Quad4, nodes);
                    //var element = new Element();
                    //element.ID = QuadID;
                    //element.ElementType = SurfaceBoundaryElement;
                    //model.SubdomainsDictionary[0].Elements.Add(element);
                    //model.ElementsDictionary.Add(QuadID, element);
                    //foreach (Node node in nodes)
                    //{
                    //    element.AddNode(node);
                    //}
                    //QuadID += 1;
                }
            }
            return(new Tuple <Model, IModelReader>(model, modelReader));
        }
        private static Tuple <Model, IModelReader> CreateStructuralModel(double[] MuLame, double[] PoissonV, IDynamicMaterial[] commonDynamicMaterialProperties,
                                                                         double b, double[] l, double[] lambdag)
        {
            double[] C1          = new double[MuLame.Length];
            double[] C2          = new double[MuLame.Length];
            double[] bulkModulus = new double[MuLame.Length];
            for (int i = 0; i < MuLame.Length; i++)
            {
                //poissonV[i] = 0.2;
                C1[i]          = MuLame[i] / 2;
                C2[i]          = 0;
                bulkModulus[i] = 2 * MuLame[i] * (1 + PoissonV[i]) / (3 * (1 - 2 * PoissonV[i]));
            }
            string            filename = Path.Combine(Directory.GetCurrentDirectory(), "InputFiles", "TumorGrowthModel", "mesh.mphtxt");
            ComsolMeshReader1 modelReader;

            if (lambdag == null)
            {
                modelReader = new ComsolMeshReader1(filename, C1, C2, bulkModulus, commonDynamicMaterialProperties);
            }
            else
            {
                modelReader = new ComsolMeshReader1(filename, C1, C2, bulkModulus, commonDynamicMaterialProperties, lambdag);
            }
            Model model = modelReader.CreateModelFromFile();
            //Boundary Conditions
            var lx = l[0];
            var ly = l[1];
            var lz = l[2];
            var distributedLoad = new DistributedLoad(lx, ly, lz);


            int[] boundaryIDs = new int[] { 0, 3 };
            foreach (int boundaryID in boundaryIDs)
            {
                foreach (Node node in modelReader.nodeBoundaries[boundaryID])
                {
                    node.Constraints.Add(new Constraint()
                    {
                        Amount = b,
                        DOF    = StructuralDof.TranslationX
                    });
                }
            }
            boundaryIDs = new int[] { 1, 4 };
            foreach (int boundaryID in boundaryIDs)
            {
                foreach (Node node in modelReader.nodeBoundaries[boundaryID])
                {
                    node.Constraints.Add(new Constraint()
                    {
                        Amount = b,
                        DOF    = StructuralDof.TranslationY
                    });
                }
            }
            boundaryIDs = new int[] { 3, 7 };
            foreach (int boundaryID in boundaryIDs)
            {
                foreach (Node node in modelReader.nodeBoundaries[boundaryID])
                {
                    node.Constraints.Add(new Constraint()
                    {
                        Amount = b,
                        DOF    = StructuralDof.TranslationZ
                    });
                }
            }
            boundaryIDs = new int[] { 6 };
            foreach (int boundaryID in boundaryIDs)
            {
                foreach (Node node in modelReader.nodeBoundaries[boundaryID])
                {
                    model.Loads.Add(new Load()
                    {
                        Node = node, DOF = StructuralDof.TranslationZ, Amount = .1
                    });
                }
            }
            return(new Tuple <Model, IModelReader>(model, modelReader));
        }