コード例 #1
0
        private static Model CreateModel()
        {
            IList <IList <Node> >    nodeBoundaries;
            IList <IList <Element> > elementBoundaries;
            double density = 1.0;
            double c       = 1.0;
            double k       = 1.0;

            double[] U = { 1.0, 1, 1 };
            double   h = .0;
            var      elementFactory3D  = new ConvectionDiffusionElement3DFactory(new ConvectionDiffusionMaterial(k, U, 0));
            var      boundaryFactory3D = new SurfaceBoundaryFactory3D(0, new ConvectionDiffusionMaterial(k, U, 0));
            var      model             = new Model();

            model.SubdomainsDictionary[0] = new Subdomain(0);
            elementBoundaries             = new List <IList <Element> >();
            nodeBoundaries = new List <IList <Node> >();
            for (int i = 0; i < 10; i++)
            {
                elementBoundaries.Add(new List <Element>());
                nodeBoundaries.Add(new List <Node>());
            }

            double[,] nodeData = new double[, ]
            {
                { 0, 0, 0 }, { 0, .1, 0 }, { 0, .1, .1 }, { 0, 0, .1 }, { .1, 0, 0 }, { .1, .1, 0 }, { .1, .1, .1 }, { .1, 0, .1 },
                { 0, 0.05, 0 }, { 0, 0, 0.05 }, { .05, 0, 0 }, { 0, .1, 0.05 }, { .05, .1, 0 }, { 0, 0.05, .1 }, { .05, .1, .1 },
                { .05, 0, .1 }, { .1, 0.05, 0 }, { .1, 0, 0.05 }, { .1, .1, 0.05 }, { .1, 0.05, .1 }, { 0, 0.05, 0.05 },
                { .05, 0.05, 0 }, { .05, 0, 0.05 }, { .05, .1, 0.05 }, { .05, 0.05, .1 }, { .1, 0.05, 0.05 },
                { .05, 0.05, 0.05 },
            };

            for (int nNode = 0; nNode < nodeData.GetLength(0); nNode++)
            {
                model.NodesDictionary.Add(nNode, new Node(id: nNode, x: nodeData[nNode, 0], y: nodeData[nNode, 1], z: nodeData[nNode, 2]));
            }
            IReadOnlyList <Node> nodes = new List <Node>
            {
                model.NodesDictionary[0], model.NodesDictionary[1], model.NodesDictionary[2],
                model.NodesDictionary[3], model.NodesDictionary[4], model.NodesDictionary[5],
                model.NodesDictionary[6], model.NodesDictionary[7], model.NodesDictionary[8],
                model.NodesDictionary[9], model.NodesDictionary[10], model.NodesDictionary[11],
                model.NodesDictionary[12], model.NodesDictionary[13], model.NodesDictionary[14],
                model.NodesDictionary[15], model.NodesDictionary[16], model.NodesDictionary[17],
                model.NodesDictionary[18], model.NodesDictionary[19], model.NodesDictionary[20],
                model.NodesDictionary[21], model.NodesDictionary[22], model.NodesDictionary[23],
                model.NodesDictionary[24], model.NodesDictionary[25], model.NodesDictionary[26],
            };
            IList <IReadOnlyList <Node> > face = new List <IReadOnlyList <Node> >();

            //face = new List<IReadOnlyList<Node>>();
            for (int i = 0; i < 6; i++)
            {
                face.Add(new List <Node>());
            }

            face[0] = new List <Node>
            {
                model.NodesDictionary[0],
                model.NodesDictionary[1],
                model.NodesDictionary[2],
                model.NodesDictionary[3],
                model.NodesDictionary[4],
                model.NodesDictionary[5],
                model.NodesDictionary[6],
                model.NodesDictionary[7],
                model.NodesDictionary[8],
            };
            face[1] = new List <Node>
            {
                model.NodesDictionary[0],
                model.NodesDictionary[1],
                model.NodesDictionary[2],
                model.NodesDictionary[9],
                model.NodesDictionary[10],
                model.NodesDictionary[11],
                model.NodesDictionary[18],
                model.NodesDictionary[19],
                model.NodesDictionary[20],
            };
            face[2] = new List <Node>
            {
                model.NodesDictionary[18],
                model.NodesDictionary[19],
                model.NodesDictionary[20],
                model.NodesDictionary[21],
                model.NodesDictionary[22],
                model.NodesDictionary[23],
                model.NodesDictionary[24],
                model.NodesDictionary[25],
                model.NodesDictionary[26],
            };
            face[3] = new List <Node>
            {
                model.NodesDictionary[6],
                model.NodesDictionary[7],
                model.NodesDictionary[8],
                model.NodesDictionary[15],
                model.NodesDictionary[16],
                model.NodesDictionary[17],
                model.NodesDictionary[24],
                model.NodesDictionary[25],
                model.NodesDictionary[26],
            };
            face[4] = new List <Node>
            {
                model.NodesDictionary[0],
                model.NodesDictionary[3],
                model.NodesDictionary[6],
                model.NodesDictionary[9],
                model.NodesDictionary[12],
                model.NodesDictionary[15],
                model.NodesDictionary[18],
                model.NodesDictionary[21],
                model.NodesDictionary[24],
            };
            face[5] = new List <Node>
            {
                model.NodesDictionary[2],
                model.NodesDictionary[5],
                model.NodesDictionary[8],
                model.NodesDictionary[11],
                model.NodesDictionary[14],
                model.NodesDictionary[17],
                model.NodesDictionary[20],
                model.NodesDictionary[23],
                model.NodesDictionary[26],
            };

            var Hexa27  = elementFactory3D.CreateElement(CellType.Hexa27, nodes);
            var element = new Element();

            element.ID          = 0;
            element.ElementType = Hexa27;
            foreach (Node node in nodes)
            {
                element.AddNode(node);
            }
            model.SubdomainsDictionary[0].Elements.Add(element);
            model.ElementsDictionary.Add(0, element);
            for (int i = 1; i < 7; i++)
            {
                var Quad        = boundaryFactory3D.CreateElement(CellType.Quad9, face[i - 1]);
                var faceElement = new Element();
                faceElement.ID          = i;
                faceElement.ElementType = Quad;
                foreach (Node node in face[i - 1])
                {
                    faceElement.AddNode(node);
                }
                model.SubdomainsDictionary[0].Elements.Add(faceElement);
                model.ElementsDictionary.Add(i, faceElement);
            }
            //constraints
            foreach (int i in new int[] { 2, 6, 7 })
            {
                model.NodesDictionary[i].Constraints.Add(new Constraint()
                {
                    Amount = 0,
                    DOF    = ThermalDof.Temperature
                });
            }

            // fortish korufhs
            Load load1;

            foreach (int i in new int[] { 0, 1, 3, 4, 5 })
            {
                load1 = new Load()
                {
                    Node   = model.NodesDictionary[i],
                    DOF    = ThermalDof.Temperature,
                    Amount = 100
                };
                model.Loads.Add(load1);
            }


            return(model);
        }
コード例 #2
0
        private static Tuple <Model, ComsolMeshReader2> CreateModel(double k, double[] U, double L)
        {
            string            filename    = Path.Combine(Directory.GetCurrentDirectory(), "InputFiles", "TumorGrowthModel", "mesh.mphtxt");
            ComsolMeshReader2 modelReader = new ComsolMeshReader2(filename, k, U, L);
            Model             model       = modelReader.CreateModelFromFile();
            //Boundary Conditions
            var flux1 = new FluxLoad(6.9e08);
            var flux2 = new FluxLoad(10);
            var dir1  = new DirichletDistribution(list => {
                return(Vector.CreateWithValue(list.Count, 1));
            });
            var dir2 = new DirichletDistribution(list => {
                return(Vector.CreateWithValue(list.Count, 0));
            });
            var weakDirichlet1 = new WeakDirichlet(dir1, k);
            var weakDirichlet2 = new WeakDirichlet(dir2, k);

            var dirichletFactory1 = new SurfaceLoadElementFactory(weakDirichlet1);
            var dirichletFactory2 = new SurfaceLoadElementFactory(weakDirichlet2);
            var fluxFactory1      = new SurfaceLoadElementFactory(flux1);
            var fluxFactory2      = new SurfaceLoadElementFactory(flux2);
            var boundaryFactory3D = new SurfaceBoundaryFactory3D(0,
                                                                 new ConvectionDiffusionMaterial(k, new double[] { 0, 0, 0 }, 0));


            int[] boundaryIDs = new int[] { 0, 1, 2 };
            //int numberOfQuadElements = 0;
            //for ( int i = 0; i<boundaryIDs.Length; i++)
            //{
            //    numberOfQuadElements += modelReader.quadBoundaries[boundaryIDs[i]].Count;
            //}
            int TriID = model.ElementsDictionary.Count + 1;

            foreach (int boundaryID in boundaryIDs)
            {
                foreach (IReadOnlyList <Node> nodes in modelReader.triBoundaries[boundaryID])
                {
                    //var fluxElement1 = fluxFactory1.CreateElement(CellType.Tri3, nodes);
                    //model.SurfaceLoads.Add(fluxElement1);
                    var dirichletElement1 = dirichletFactory1.CreateElement(CellType.Tri3, nodes);
                    model.SurfaceLoads.Add(dirichletElement1);
                    var SurfaceBoundaryElement = boundaryFactory3D.CreateElement(CellType.Tri3, nodes);
                    var element = new Element();
                    element.ID          = TriID;
                    element.ElementType = SurfaceBoundaryElement;
                    model.SubdomainsDictionary[0].Elements.Add(element);
                    model.ElementsDictionary.Add(TriID, element);
                    foreach (Node node in nodes)
                    {
                        element.AddNode(node);
                    }
                    TriID += 1;
                    // var surfaceElement = new SurfaceLoadElement();
                    //element.ID = TriID;
                    //surfaceElement.ElementType = DirichletElement1;
                    //model.SubdomainsDictionary[0].Elements.Add(dirichletElement1);
                    //model.ElementsDictionary.Add(TriID, surfaceElement);

                    //model.NodesDictionary[surfaceElement.ID].Constraints.Add(new Constraint() { DOF = ThermalDof.Temperature, Amount = 100 });
                }
            }
            boundaryIDs = new int[] { 5 };
            foreach (int boundaryID in boundaryIDs)
            {
                foreach (IReadOnlyList <Node> nodes in modelReader.quadBoundaries[boundaryID])
                {
                    //        //IReadOnlyList<Node> nodes = (IReadOnlyList<Node>)element.Nodes;
                    //        //var fluxElement1 = fluxFactory1.CreateElement(CellType.Quad4, nodes);
                    //        //model.SurfaceLoads.Add(fluxElement1);
                    var dirichletElement2 = dirichletFactory2.CreateElement(CellType.Quad4, nodes);
                    model.SurfaceLoads.Add(dirichletElement2);
                    var SurfaceBoundaryElement = boundaryFactory3D.CreateElement(CellType.Quad4, nodes);
                    var element = new Element();
                    element.ID          = TriID;
                    element.ElementType = SurfaceBoundaryElement;
                    model.SubdomainsDictionary[0].Elements.Add(element);
                    model.ElementsDictionary.Add(TriID, element);
                    foreach (Node node in nodes)
                    {
                        element.AddNode(node);
                    }
                    TriID += 1;
                    //        // var surfaceElement = new SurfaceLoadElement();
                    //        //element.ID = TriID;
                    //        //surfaceElement.ElementType = DirichletElement1;
                    //        //model.SubdomainsDictionary[0].Elements.Add(dirichletElement1);
                    //        //model.ElementsDictionary.Add(TriID, surfaceElement);

                    //        //model.NodesDictionary[surfaceElement.ID].Constraints.Add(new Constraint() { DOF = ThermalDof.Temperature, Amount = 100 });
                }
            }

            //boundaryIDs = new int[] { 1, 2, 3, 4 };
            //foreach (int boundaryID in boundaryIDs)
            //{
            //    foreach (Element element in modelReader.elementBoundaries[boundaryID])
            //    {
            //        IReadOnlyList<Node> nodes = (IReadOnlyList<Node>)element.Nodes;
            //        var fluxElement = fluxFactory.CreateElement(CellType.Quad4, nodes);
            //        model.SurfaceLoads.Add(fluxElement);
            //    }
            //}

            return(new Tuple <Model, ComsolMeshReader2>(model, modelReader));
        }
コード例 #3
0
        private static Tuple <Model, ComsolMeshReader2> CreateModel(double k, double[] U, double L, double b1, double b2, double f1, double f2, double[] bl)
        {
            string            filename    = Path.Combine(Directory.GetCurrentDirectory(), "InputFiles", "TumorGrowthModel", "9hexa.mphtxt");
            ComsolMeshReader2 modelReader = new ComsolMeshReader2(filename, k, U, L);
            Model             model       = modelReader.CreateModelFromFile();
            //Boundary Conditions
            var flux1 = new FluxLoad(f1);
            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 fluxFactory1      = new SurfaceLoadElementFactory(flux1);
            var fluxFactory2      = new SurfaceLoadElementFactory(flux2);
            var boundaryFactory3D = new SurfaceBoundaryFactory3D(0,
                                                                 new ConvectionDiffusionMaterial(k, new double[] { 0, 0, 0 }, 0));

            foreach (Node node in model.Nodes)
            {
                model.Loads.Add(new Load()
                {
                    Amount = bl[node.ID], Node = node, DOF = ThermalDof.Temperature
                });
            }


            int[] boundaryIDs = new int[] { 0, };
            int   QuadID      = model.ElementsDictionary.Count + 1;

            foreach (int boundaryID in boundaryIDs)
            {
                foreach (IReadOnlyList <Node> nodes in modelReader.quadBoundaries[boundaryID])
                {
                    var fluxElement1 = fluxFactory1.CreateElement(CellType.Quad4, nodes);
                    model.SurfaceLoads.Add(fluxElement1);
                    var dirichletElement1 = dirichletFactory1.CreateElement(CellType.Quad4, nodes);
                    model.SurfaceLoads.Add(dirichletElement1);
                    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;
                }
            }
            boundaryIDs = new int[] { 5 };
            foreach (int boundaryID in boundaryIDs)
            {
                foreach (IReadOnlyList <Node> nodes in modelReader.quadBoundaries[boundaryID])
                {
                    var fluxElement1 = fluxFactory1.CreateElement(CellType.Quad4, nodes);
                    model.SurfaceLoads.Add(fluxElement1);
                    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, ComsolMeshReader2>(model, modelReader));
        }
        private static Tuple <Model, IModelReader> CreateConvectionDiffusionModel2(double k, double[] U, double L, double b, double f, double[] bl)
        {
            string filename    = Path.Combine(Directory.GetCurrentDirectory(), "InputFiles", "TumorGrowthModel", "9hexa.mphtxt");
            var    modelReader = new ComsolMeshReader2(filename, k, U, L);
            Model  model       = modelReader.CreateModelFromFile();
            var    material    = new ConvectionDiffusionMaterial(k, U, L);
            //Boundary Conditions
            var flux1 = new FluxLoad(f);
            var dir1  = new DirichletDistribution(list => {
                return(Vector.CreateWithValue(list.Count, b));
            });
            //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 fluxFactory1      = new SurfaceLoadElementFactory(flux1);
            var boundaryFactory3D = new SurfaceBoundaryFactory3D(0,
                                                                 new ConvectionDiffusionMaterial(k, new double[] { 0, 0, 0 }, 0));


            int[] domainIDs = new int[] { 0, };
            foreach (int domainID in domainIDs)
            {
                foreach (Element element in modelReader.elementDomains[domainID])
                {
                    ////IReadOnlyList<Node> nodes = (IReadOnlyList<Node>)element.Nodes;
                    //var fluxElement1 = fluxFactory1.CreateElement(CellType.Quad4, nodes);
                    //model.SurfaceLoads.Add(fluxElement1);
                    //var bodyLoadElementCellType = element.ElementType.CellType;
                    //var nodes = (IReadOnlyList<Node>)element.Nodes;
                    //var domainLoad = new ConvectionDiffusionDomainLoad(material, bl[], ThermalDof.Temperature);
                    //var bodyLoadElementFactory = new BodyLoadElementFactory(domainLoad, model);
                    //var bodyLoadElement = bodyLoadElementFactory.CreateElement(CellType.Hexa8, nodes);
                    //model.BodyLoads.Add(bodyLoadElement);
                    //var surfaceElement = new SurfaceLoadElement();
                    //element.ID = TriID;
                    //surfaceElement.ElementType = DirichletElement1;
                    //model.SubdomainsDictionary[0].Elements.Add(dirichletElement1);
                    //model.ElementsDictionary.Add(TriID, surfaceElement);

                    //model.NodesDictionary[surfaceElement.ID].Constraints.Add(new Constraint() { DOF = ThermalDof.Temperature, Amount = 100 });
                }
            }
            //foreach (Node node in model.Nodes)
            //{
            //    model.Loads.Add(new Load() { Amount = bl[node.ID], Node = node, DOF = ThermalDof.Temperature });
            //}

            int[] boundaryIDs = new int[] { 0, };
            int   QuadID      = model.ElementsDictionary.Count + 1;

            foreach (int boundaryID in boundaryIDs)
            {
                foreach (IReadOnlyList <Node> nodes in modelReader.quadBoundaries[boundaryID])
                {
                    //var fluxElement1 = fluxFactory1.CreateElement(CellType.Quad4, nodes);
                    //model.SurfaceLoads.Add(fluxElement1);
                    var dirichletElement1 = dirichletFactory1.CreateElement(CellType.Quad4, nodes);
                    model.SurfaceLoads.Add(dirichletElement1);
                    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;
                }
            }
            boundaryIDs = new int[] { 5 };
            foreach (int boundaryID in boundaryIDs)
            {
                foreach (IReadOnlyList <Node> nodes in modelReader.quadBoundaries[boundaryID])
                {
                    var fluxElement1 = fluxFactory1.CreateElement(CellType.Quad4, nodes);
                    model.SurfaceLoads.Add(fluxElement1);
                    //var bodyLoadElement = bodyLoadElementFactory.CreateElement(CellType.Quad4, nodes);
                    //model.SurfaceLoads.Add(bodyLoadElement);
                    //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));
        }
コード例 #5
0
        private static Tuple <Model, ComsolMeshReader2> CreateModel(double k, double[] U, double L)
        {
            string            filename    = Path.Combine(Directory.GetCurrentDirectory(), "InputFiles", "TumorGrowthModel", "fullModel.mphtxt");
            ComsolMeshReader2 modelReader = new ComsolMeshReader2(filename, new double[] { k }, new double[][] { U }, new double[] { L });
            Model             model       = modelReader.CreateModelFromFile();
            //Boundary Conditions
            var bodyLoad = new ConvectionDiffusionDomainLoad(new ConvectionDiffusionMaterial(k, U, L), 1, ThermalDof.Temperature);
            var flux1    = new FluxLoad(1);
            var flux2    = new FluxLoad(10);
            var dir1     = new DirichletDistribution(list => {
                return(Vector.CreateWithValue(list.Count, 1));
            });
            var dir2 = new DirichletDistribution(list => {
                return(Vector.CreateWithValue(list.Count, 0));
            });
            var weakDirichlet1 = new WeakDirichlet(dir1, k);
            var weakDirichlet2 = new WeakDirichlet(dir2, k);

            var bodyLoadElementFactory = new BodyLoadElementFactory(bodyLoad, model);
            var dirichletFactory1      = new SurfaceLoadElementFactory(weakDirichlet1);
            var dirichletFactory2      = new SurfaceLoadElementFactory(weakDirichlet2);
            var fluxFactory1           = new SurfaceLoadElementFactory(flux1);
            var fluxFactory2           = new SurfaceLoadElementFactory(flux2);
            var boundaryFactory3D      = new SurfaceBoundaryFactory3D(0,
                                                                      new ConvectionDiffusionMaterial(k, new double[] { 0, 0, 0 }, 0));

            int[] domainIDs = new int[] { 0, };
            foreach (int domainID in domainIDs)
            {
                foreach (Element element in modelReader.elementDomains[domainID])
                {
                    //IReadOnlyList<Node> nodes = (IReadOnlyList<Node>)element.Nodes;
                    //var fluxElement1 = fluxFactory1.CreateElement(CellType.Quad4, nodes);
                    //model.SurfaceLoads.Add(fluxElement1);
                    //var bodyLoadElementCellType = element.ElementType.CellType;
                    //var nodes = (IReadOnlyList<Node>)element.Nodes;
                    //var bodyLoadElement = bodyLoadElementFactory.CreateElement(CellType.Hexa8, nodes);
                    //model.BodyLoads.Add(bodyLoadElement);
                    // var surfaceElement = new SurfaceLoadElement();
                    //element.ID = TriID;
                    //surfaceElement.ElementType = DirichletElement1;
                    //model.SubdomainsDictionary[0].Elements.Add(dirichletElement1);
                    //model.ElementsDictionary.Add(TriID, surfaceElement);

                    //model.NodesDictionary[surfaceElement.ID].Constraints.Add(new Constraint() { DOF = ThermalDof.Temperature, Amount = 100 });
                }
            }

            //foreach (Node node in model.Nodes)
            //{
            //    model.Loads.Add(new Load() { Amount = .25, Node = node, DOF = ThermalDof.Temperature });
            //}

            int[] boundaryIDs = new int[] { 0, 1, 2, 3, 4, 7 };
            int   TriID       = model.ElementsDictionary.Count + 1;

            foreach (int boundaryID in boundaryIDs)
            {
                foreach (IReadOnlyList <Node> nodes in modelReader.triBoundaries[boundaryID])
                {
                    //IReadOnlyList<Node> nodes = (IReadOnlyList<Node>)element.Nodes;
                    //var fluxElement1 = fluxFactory1.CreateElement(CellType.Quad4, nodes);
                    //model.SurfaceLoads.Add(fluxElement1);
                    var dirichletElement1 = dirichletFactory1.CreateElement(CellType.Tri3, nodes);
                    model.SurfaceLoads.Add(dirichletElement1);
                    var surfaceBoundaryElement = boundaryFactory3D.CreateElement(CellType.Tri3, nodes);
                    var element = new Element();
                    element.ID          = TriID;
                    element.ElementType = surfaceBoundaryElement;
                    model.SubdomainsDictionary[0].Elements.Add(element);
                    model.ElementsDictionary.Add(TriID, element);
                    foreach (Node node in nodes)
                    {
                        element.AddNode(node);
                    }
                    TriID += 1;
                    // var surfaceElement = new SurfaceLoadElement();
                    //element.ID = TriID;
                    //surfaceElement.ElementType = DirichletElement1;
                    //model.SubdomainsDictionary[0].Elements.Add(dirichletElement1);
                    //model.ElementsDictionary.Add(TriID, surfaceElement);

                    //model.NodesDictionary[surfaceElement.ID].Constraints.Add(new Constraint() { DOF = ThermalDof.Temperature, Amount = 100 });
                }
            }
            boundaryIDs = new int[] { 6, 8, 9 };
            foreach (int boundaryID in boundaryIDs)
            {
                foreach (IReadOnlyList <Node> nodes in modelReader.triBoundaries[boundaryID])
                {
                    //IReadOnlyList<Node> nodes = (IReadOnlyList<Node>)element.Nodes;
                    //var fluxElement2 = fluxFactory2.CreateElement(CellType.Quad4, nodes);
                    //model.SurfaceLoads.Add(fluxElement2);
                    var dirichletElement2 = dirichletFactory2.CreateElement(CellType.Tri3, nodes);
                    model.SurfaceLoads.Add(dirichletElement2);
                    var surfaceBoundaryElement = boundaryFactory3D.CreateElement(CellType.Tri3, nodes);
                    var element = new Element();
                    element.ID          = TriID;
                    element.ElementType = surfaceBoundaryElement;
                    model.SubdomainsDictionary[0].Elements.Add(element);
                    model.ElementsDictionary.Add(TriID, element);
                    foreach (Node node in nodes)
                    {
                        element.AddNode(node);
                    }
                    TriID += 1;
                    // var surfaceElement = new SurfaceLoadElement();
                    //element.ID = TriID;
                    //surfaceElement.ElementType = DirichletElement1;
                    //model.SubdomainsDictionary[0].Elements.Add(dirichletElement1);
                    //model.ElementsDictionary.Add(TriID, surfaceElement);

                    //model.NodesDictionary[surfaceElement.ID].Constraints.Add(new Constraint() { DOF = ThermalDof.Temperature, Amount = 100 });
                }
            }

            //boundaryIDs = new int[] { 1, 2, 3, 4 };
            //foreach (int boundaryID in boundaryIDs)
            //{
            //    foreach (Element element in modelReader.elementBoundaries[boundaryID])
            //    {
            //        IReadOnlyList<Node> nodes = (IReadOnlyList<Node>)element.Nodes;
            //        var fluxElement = fluxFactory.CreateElement(CellType.Quad4, nodes);
            //        model.SurfaceLoads.Add(fluxElement);
            //    }
            //}

            return(new Tuple <Model, ComsolMeshReader2>(model, modelReader));
        }
コード例 #6
0
        public Model CreateModelFromFile()
        {
            double c = 1.0;

            double[] U = { 1.0, 1, 1 };
            double   k = 1.0;
            double   L = .0;

            diffusionCeoff = k;
            var elementFactory3D  = new ConvectionDiffusionElement3DFactory(new ConvectionDiffusionMaterial(c, k, U, L));
            var boundaryFactory3D = new SurfaceBoundaryFactory3D(0, new ConvectionDiffusionMaterial(c, k, U, L));
            var model             = new Model();

            model.SubdomainsDictionary[0] = new Subdomain(0);
            // Material

            char[]     delimeters = { ' ', '=', '\t' };
            Attributes?name       = null;

            String[] text = System.IO.File.ReadAllLines(Filename);
            elementBoundaries = new List <IList <Element> >();
            elementDomains    = new List <IList <Element> >();
            nodeBoundaries    = new List <IList <Node> >();
            for (int i = 0; i < 10; i++)
            {
                elementBoundaries.Add(new List <Element>());
                nodeBoundaries.Add(new List <Node>());
            }
            for (int i = 0; i < 2; i++)
            {
                elementDomains.Add(new List <Element>());
            }

            for (int i = 0; i < text.Length; i++)
            {
                String[]      line             = text[i].Split(delimeters, StringSplitOptions.RemoveEmptyEntries);
                StringBuilder comparisonString = new StringBuilder(null, 50);
                if (line.Length == 0)
                {
                    continue;
                }
                if (line[0] == "3" & line.Length > 1)
                {
                    try
                    {
                        name = (Attributes)Enum.Parse(typeof(Attributes), line[1]);
                    }
                    catch (Exception exception)
                    {
                        name = null;
                    }
                }
                else
                {
                    for (int linePosition = 0; linePosition < line.Length; linePosition++)
                    {
                        if (line[linePosition] == "#")
                        {
                            for (int ij = linePosition + 1; ij < line.Length; ij++)
                            {
                                comparisonString.Append(line[ij]);
                            }
                            try
                            {
                                name = (Attributes)Enum.Parse(typeof(Attributes), comparisonString.ToString());
                            }
                            catch (Exception exception)
                            {
                                name = null;
                            }
                        }
                    }
                }
                switch (name)
                {
                case Attributes.sdim:
                    int NumberOfDimensions = Int32.Parse(line[0]);
                    break;

                case Attributes.numberofmeshpoints:
                    NumberOfNodes = Int32.Parse(line[0]);
                    break;

                case Attributes.Meshpointcoordinates:
                    IList <Node> nodelist = new List <Node> {
                        null
                    };
                    for (int j = 0; j < NumberOfNodes; j++)
                    {
                        i++;
                        line = text[i].Split(delimeters);
                        int    nodeGlobalID = j;
                        double x            = Double.Parse(line[0], CultureInfo.InvariantCulture);
                        double y            = Double.Parse(line[1], CultureInfo.InvariantCulture);
                        double z            = Double.Parse(line[2], CultureInfo.InvariantCulture);
                        Node   node         = new Node(nodeGlobalID, x, y, z);
                        model.NodesDictionary.Add(nodeGlobalID, node);
                        nodelist.Add(node);
                    }

                    break;

                case Attributes.tri:
                    do
                    {
                        i++;
                        line = text[i].Split(delimeters);
                    } while (line[0] == "");
                    i++;
                    line = text[i].Split(delimeters);
                    NumberOfTriElements = Int32.Parse(line[0]);
                    i++;
                    IList <Node> nodesCollection = new List <Node>();
                    for (int TriID = 0; TriID < NumberOfTriElements; TriID++)
                    {
                        i++;
                        line = text[i].Split(delimeters);

                        for (int j = 0; j < (line.Length - 1); j++)
                        {
                            nodesCollection.Add(model.NodesDictionary[Int32.Parse(line[j])]);
                        }

                        IReadOnlyList <Node> nodes = new List <Node>
                        {
                            model.NodesDictionary[Int32.Parse(line[2])],
                            model.NodesDictionary[Int32.Parse(line[1])],
                            model.NodesDictionary[Int32.Parse(line[0])]
                        };

                        var Tri3    = boundaryFactory3D.CreateElement(CellType.Tri3, nodes);
                        var element = new Element();
                        element.ID          = TriID;
                        element.ElementType = Tri3;
                        model.SubdomainsDictionary[0].Elements.Add(element);
                        model.ElementsDictionary.Add(TriID, element);
                        double r3 = 0;
                        foreach (Node node in nodes)
                        {
                            element.AddNode(node);
                            r3 += Math.Sqrt(Math.Pow(node.X, 2) + Math.Pow(node.Y, 2) + Math.Pow(node.Z, 2));
                        }
                        if (element.Nodes[0].X == 0 && r3 < 3 * 5e-4)
                        {
                            elementBoundaries[0].Add(model.ElementsDictionary[TriID]);
                            //model.NodesDictionary[element.Nodes[0].ID].Constraints.Add(new Constraint() { DOF = ThermalDof.Temperature, Amount = 10 });
                        }
                        else if (element.Nodes[0].Y == 0 && r3 < 3 * 5e-4)
                        {
                            elementBoundaries[1].Add(model.ElementsDictionary[TriID]);
                        }
                        else if (element.Nodes[0].Z == 0 && r3 < 3 * 5e-4)
                        {
                            elementBoundaries[2].Add(model.ElementsDictionary[TriID]);
                        }
                        else if (element.Nodes[0].X == 0 && r3 > 3 * 5e-4)
                        {
                            elementBoundaries[3].Add(model.ElementsDictionary[TriID]);
                        }
                        else if (element.Nodes[0].Y == 0 && r3 > 3 * 5e-4)
                        {
                            elementBoundaries[4].Add(model.ElementsDictionary[TriID]);
                        }
                        else if (r3 == 3 * 5e-4)
                        {
                            elementBoundaries[5].Add(model.ElementsDictionary[TriID]);
                        }
                        else if (element.Nodes[0].Z == 0.1 && element.Nodes[1].Z == 0.1 && element.Nodes[2].Z == 0.1)
                        {
                            elementBoundaries[6].Add(model.ElementsDictionary[TriID]);
                        }
                        else if (element.Nodes[0].Z == 0 && r3 > 3 * 5e-4)
                        {
                            elementBoundaries[7].Add(model.ElementsDictionary[TriID]);
                        }
                        else if (element.Nodes[0].Y == 0.1 && element.Nodes[1].Y == 0.1 && element.Nodes[2].Y == 0.1)
                        {
                            elementBoundaries[8].Add(model.ElementsDictionary[TriID]);
                        }
                        else if (element.Nodes[0].X == 0.1 && element.Nodes[1].X == 0.1 && element.Nodes[2].X == 0.1)
                        {
                            elementBoundaries[9].Add(model.ElementsDictionary[TriID]);
                        }
                    }
                    nodesCollection = nodesCollection.Distinct().ToList();
                    foreach (Node node in nodesCollection)
                    {
                        double r = Math.Sqrt(Math.Pow(node.X, 2) + Math.Pow(node.Y, 2) + Math.Pow(node.Z, 2));
                        if (node.X == 0 && node.Y <= 5e-4 && node.Z <= 5e-4)
                        {
                            nodeBoundaries[0].Add(model.NodesDictionary[node.ID]);
                            //model.NodesDictionary[node.ID].Constraints.Add(new Constraint() { DOF = ThermalDof.Temperature, Amount = 10 });
                        }
                        else if (node.X <= 5e-4 && node.Y == 0 && node.Z <= 5e-4)
                        {
                            nodeBoundaries[1].Add(model.NodesDictionary[node.ID]);
                        }
                        else if (node.X <= 5e-4 && node.Y <= 5e-4 && node.Z == 0)
                        {
                            nodeBoundaries[2].Add(model.NodesDictionary[node.ID]);
                        }
                        else if (node.X == 0 && r > 5e-4)
                        {
                            nodeBoundaries[3].Add(model.NodesDictionary[node.ID]);
                        }
                        else if (node.Y == 0 && r > 5e-4)
                        {
                            nodeBoundaries[4].Add(model.NodesDictionary[node.ID]);
                        }
                        else if (r == 5e-4)
                        {
                            nodeBoundaries[5].Add(model.NodesDictionary[node.ID]);
                        }
                        else if (node.Z == 0.1)
                        {
                            nodeBoundaries[6].Add(model.NodesDictionary[node.ID]);
                        }
                        else if (node.Z == 0 && r > 5e-4)
                        {
                            nodeBoundaries[7].Add(model.NodesDictionary[node.ID]);
                        }
                        else if (node.Y == 0.1)
                        {
                            nodeBoundaries[8].Add(model.NodesDictionary[node.ID]);
                        }
                        else if (node.X == 0.1)
                        {
                            nodeBoundaries[9].Add(model.NodesDictionary[node.ID]);
                        }
                        //else
                        //{
                        //    model.Loads.Add(new Load() { Node = model.NodesDictionary[node.ID], DOF = ThermalDof.Temperature, Amount = 10 });
                        //}
                    }
                    break;

                case Attributes.quad:
                    do
                    {
                        i++;
                        line = text[i].Split(delimeters);
                    } while (line[0] == "");
                    i++;
                    line = text[i].Split(delimeters);
                    NumberOfTriElements = Int32.Parse(line[0]);
                    i++;
                    IList <Node> quadNodesCollection = new List <Node>();
                    for (int QuadID = 0; QuadID < NumberOfTriElements; QuadID++)
                    {
                        i++;
                        line = text[i].Split(delimeters);

                        for (int j = 0; j < (line.Length - 1); j++)
                        {
                            quadNodesCollection.Add(model.NodesDictionary[Int32.Parse(line[j])]);
                        }

                        IReadOnlyList <Node> nodes = new List <Node>
                        {
                            model.NodesDictionary[Int32.Parse(line[3])],
                            model.NodesDictionary[Int32.Parse(line[2])],
                            model.NodesDictionary[Int32.Parse(line[1])],
                            model.NodesDictionary[Int32.Parse(line[0])]
                        };

                        var Quad    = boundaryFactory3D.CreateElement(CellType.Quad4, nodes);
                        var element = new Element();
                        element.ID          = QuadID;
                        element.ElementType = Quad;
                        model.SubdomainsDictionary[0].Elements.Add(element);
                        model.ElementsDictionary.Add(QuadID, element);
                        //double r3 = 0;
                        //foreach (Node node in nodes)
                        //{
                        //    element.AddNode(node);
                        //    r3 += Math.Sqrt(Math.Pow(node.X, 2) + Math.Pow(node.Y, 2) + Math.Pow(node.Z, 2));
                        //}
                        //if (element.Nodes[0].X == 0 && r3 < 3 * 5e-4)
                        //{
                        //    elementBoundaries[0].Add(model.ElementsDictionary[QuadID]);
                        //    //model.NodesDictionary[element.Nodes[0].ID].Constraints.Add(new Constraint() { DOF = ThermalDof.Temperature, Amount = 10 });
                        //}
                        //else if (element.Nodes[0].Y == 0 && r3 < 3 * 5e-4)
                        //{
                        //    elementBoundaries[1].Add(model.ElementsDictionary[QuadID]);
                        //}
                        //else if (element.Nodes[0].Z == 0 && r3 < 3 * 5e-4)
                        //{
                        //    elementBoundaries[2].Add(model.ElementsDictionary[QuadID]);
                        //}
                        //else if (element.Nodes[0].X == 0 && r3 > 3 * 5e-4)
                        //{
                        //    elementBoundaries[3].Add(model.ElementsDictionary[QuadID]);
                        //}
                        //else if (element.Nodes[0].Y == 0 && r3 > 3 * 5e-4)
                        //{
                        //    elementBoundaries[4].Add(model.ElementsDictionary[QuadID]);
                        //}
                        //else if (r3 == 3 * 5e-4)
                        //{
                        //    elementBoundaries[5].Add(model.ElementsDictionary[QuadID]);
                        //}
                        //else if (element.Nodes[0].Z == 0.1 && element.Nodes[1].Z == 0.1 && element.Nodes[2].Z == 0.1)
                        //{
                        //    elementBoundaries[6].Add(model.ElementsDictionary[QuadID]);
                        //}
                        //else if (element.Nodes[0].Z == 0 && r3 > 3 * 5e-4)
                        //{
                        //    elementBoundaries[7].Add(model.ElementsDictionary[QuadID]);
                        //}
                        //else if (element.Nodes[0].Y == 0.1 && element.Nodes[1].Y == 0.1 && element.Nodes[2].Y == 0.1)
                        //{
                        //    elementBoundaries[8].Add(model.ElementsDictionary[QuadID]);
                        //}
                        //else if (element.Nodes[0].X == 0.1 && element.Nodes[1].X == 0.1 && element.Nodes[2].X == 0.1)
                        //{
                        //    elementBoundaries[9].Add(model.ElementsDictionary[QuadID]);
                        //}
                    }
                    quadNodesCollection = quadNodesCollection.Distinct().ToList();
                    foreach (Node node in quadNodesCollection)
                    {
                        double r = Math.Sqrt(Math.Pow(node.X, 2) + Math.Pow(node.Y, 2) + Math.Pow(node.Z, 2));
                        if (node.X == 0 && node.Y <= 5e-4 && node.Z <= 5e-4)
                        {
                            nodeBoundaries[0].Add(model.NodesDictionary[node.ID]);
                            //model.NodesDictionary[node.ID].Constraints.Add(new Constraint() { DOF = ThermalDof.Temperature, Amount = 10 });
                        }
                        else if (node.X <= 5e-4 && node.Y == 0 && node.Z <= 5e-4)
                        {
                            nodeBoundaries[1].Add(model.NodesDictionary[node.ID]);
                        }
                        else if (node.X <= 5e-4 && node.Y <= 5e-4 && node.Z == 0)
                        {
                            nodeBoundaries[2].Add(model.NodesDictionary[node.ID]);
                        }
                        else if (node.X == 0 && r > 5e-4)
                        {
                            nodeBoundaries[3].Add(model.NodesDictionary[node.ID]);
                        }
                        else if (node.Y == 0 && r > 5e-4)
                        {
                            nodeBoundaries[4].Add(model.NodesDictionary[node.ID]);
                        }
                        else if (r == 5e-4)
                        {
                            nodeBoundaries[5].Add(model.NodesDictionary[node.ID]);
                        }
                        else if (node.Z == 0.1)
                        {
                            nodeBoundaries[6].Add(model.NodesDictionary[node.ID]);
                        }
                        else if (node.Z == 0 && r > 5e-4)
                        {
                            nodeBoundaries[7].Add(model.NodesDictionary[node.ID]);
                        }
                        else if (node.Y == 0.1)
                        {
                            nodeBoundaries[8].Add(model.NodesDictionary[node.ID]);
                        }
                        else if (node.X == 0.1)
                        {
                            nodeBoundaries[9].Add(model.NodesDictionary[node.ID]);
                        }
                        //else
                        //{
                        //    model.Loads.Add(new Load() { Node = model.NodesDictionary[node.ID], DOF = ThermalDof.Temperature, Amount = 10 });
                        //}
                    }
                    break;

                case Attributes.tet:
                    do
                    {
                        i++;
                        line = text[i].Split(delimeters);
                    } while (line[0] == "");
                    i++;
                    line = text[i].Split(delimeters);
                    NumberOfTetElements = Int32.Parse(line[0]);
                    i++;
                    for (int TetID = NumberOfTriElements + 1; TetID < NumberOfTriElements + NumberOfTetElements; TetID++)
                    {
                        i++;
                        line = text[i].Split(delimeters);

                        IReadOnlyList <Node> nodes = new List <Node>
                        {
                            model.NodesDictionary[Int32.Parse(line[3])],
                            model.NodesDictionary[Int32.Parse(line[2])],
                            model.NodesDictionary[Int32.Parse(line[1])],
                            model.NodesDictionary[Int32.Parse(line[0])]
                        };
                        var Tet4    = elementFactory3D.CreateElement(CellType.Tet4, nodes);
                        var element = new Element();
                        element.ID          = TetID;
                        element.ElementType = Tet4;
                        double r4 = 0;
                        foreach (Node node in nodes)
                        {
                            element.AddNode(node);
                            r4 += Math.Sqrt(Math.Pow(node.X, 2) + Math.Pow(node.Y, 2) + Math.Pow(node.Z, 2));
                        }
                        model.SubdomainsDictionary[0].Elements.Add(element);
                        model.ElementsDictionary.Add(TetID, element);
                        if (r4 < 4 * 5e-4)
                        {
                            elementDomains[0].Add(element);
                        }
                        else
                        {
                            elementDomains[1].Add(element);
                        }
                    }
                    name = null;
                    break;
                }
            }
            return(model);
        }
コード例 #7
0
        private static Model CreateModel()
        {
            IList <IList <Node> >    nodeBoundaries;
            IList <IList <Element> > elementBoundaries;
            double k = 1.0;

            double[] U = { 1.0, 1, 1 };
            double   L = 0.0;
            double   h = 1.0;
            var      elementFactory3D  = new ConvectionDiffusionElement3DFactory(new ConvectionDiffusionMaterial(k, U, L));
            var      boundaryFactory3D = new SurfaceBoundaryFactory3D(0, new ConvectionDiffusionMaterial(k, U, L));
            var      model             = new Model();

            model.SubdomainsDictionary[0] = new Subdomain(0);
            elementBoundaries             = new List <IList <Element> >();
            nodeBoundaries = new List <IList <Node> >();
            for (int i = 0; i < 10; i++)
            {
                elementBoundaries.Add(new List <Element>());
                nodeBoundaries.Add(new List <Node>());
            }

            double[,] nodeData = new double[, ] {
                { 0, 0, 0 },
                { 1, 0, 0 },
                { 1, 1, 0 },
                { 0, 1, 0 },

                { 0, 0, 1 },
                { 1, 0, 1 },
                { 1, 1, 1 },
                { 0, 1, 1 },

                { 0, 0, 2 },
                { 1, 0, 2 },
                { 1, 1, 2 },
                { 0, 1, 2 }
            };

            for (int nNode = 0; nNode < nodeData.GetLength(0); nNode++)
            {
                model.NodesDictionary.Add(nNode, new Node(id: nNode, x: nodeData[nNode, 0], y: nodeData[nNode, 1], z: nodeData[nNode, 2]));
            }
            IReadOnlyList <Node> nodes1 = new List <Node>
            {
                model.NodesDictionary[0],
                model.NodesDictionary[1],
                model.NodesDictionary[2],
                model.NodesDictionary[3],
                model.NodesDictionary[4],
                model.NodesDictionary[5],
                model.NodesDictionary[6],
                model.NodesDictionary[7],
            };
            IReadOnlyList <Node> nodes2 = new List <Node>
            {
                model.NodesDictionary[4],
                model.NodesDictionary[5],
                model.NodesDictionary[6],
                model.NodesDictionary[7],
                model.NodesDictionary[8],
                model.NodesDictionary[9],
                model.NodesDictionary[10],
                model.NodesDictionary[11],
            };
            IList <IReadOnlyList <Node> > face = new List <IReadOnlyList <Node> >();

            //face = new List<IReadOnlyList<Node>>();
            for (int i = 0; i < 6; i++)
            {
                face.Add(new List <Node>());
            }

            face[0] = new List <Node>
            {
                model.NodesDictionary[0],
                model.NodesDictionary[1],
                model.NodesDictionary[2],
                model.NodesDictionary[3],
            };
            face[1] = new List <Node>
            {
                model.NodesDictionary[8],
                model.NodesDictionary[9],
                model.NodesDictionary[10],
                model.NodesDictionary[11],
            };
            face[2] = new List <Node>
            {
                model.NodesDictionary[0],
                model.NodesDictionary[1],
                model.NodesDictionary[9],
                model.NodesDictionary[8],
            };
            face[3] = new List <Node>
            {
                model.NodesDictionary[1],
                model.NodesDictionary[2],
                model.NodesDictionary[11],
                model.NodesDictionary[10],
            };
            face[4] = new List <Node>
            {
                model.NodesDictionary[2],
                model.NodesDictionary[3],
                model.NodesDictionary[11],
                model.NodesDictionary[10],
            };
            face[5] = new List <Node>
            {
                model.NodesDictionary[3],
                model.NodesDictionary[0],
                model.NodesDictionary[8],
                model.NodesDictionary[11],
            };
            //first hexa8
            int[] elementData_1 = new int[] { 0, 1, 2, 3, 4, 5, 6, 7 };// the last line will not be used. We assign only one element
            var   Hexa8_1       = elementFactory3D.CreateElement(CellType.Hexa8, nodes1);
            var   element_1     = new Element();

            element_1.ID          = 0;
            element_1.ElementType = Hexa8_1;
            for (int j = 0; nodes1.Count < 8; j++)
            {
                element_1.NodesDictionary.Add(nodes1[j].ID, model.NodesDictionary[elementData_1[j]]);
            }
            model.SubdomainsDictionary[0].Elements.Add(element_1);
            model.ElementsDictionary.Add(0, element_1);

            //second hexa8
            int[] elementData_2 = new int[] { 4, 5, 6, 7, 8, 9, 10, 11 };// the last line will not be used. We assign only one element
            var   Hexa8_2       = elementFactory3D.CreateElement(CellType.Hexa8, nodes2);
            var   element_2     = new Element();

            element_2.ID          = 0;
            element_2.ElementType = Hexa8_2;
            for (int j = 0; nodes1.Count < 8; j++)
            {
                element_2.NodesDictionary.Add(nodes2[j].ID, model.NodesDictionary[elementData_2[j]]);
            }
            model.SubdomainsDictionary[0].Elements.Add(element_2);
            model.ElementsDictionary.Add(1, element_2);

            //newmann and dirichlet load
            var flux = new FluxLoad(10);
            var dir1 = new DirichletDistribution(list => {
                return(Vector.CreateWithValue(list.Count, 0));
            });
            var dir2 = new DirichletDistribution(list => {
                return(Vector.CreateWithValue(list.Count, 10));
            });
            var weakDirichlet1 = new WeakDirichlet(dir1, k);
            var weakDirichlet2 = new WeakDirichlet(dir2, k);

            var dirichletFactory1 = new SurfaceLoadElementFactory(weakDirichlet1);
            var dirichletFactory2 = new SurfaceLoadElementFactory(weakDirichlet2);
            var fluxFactory       = new SurfaceLoadElementFactory(flux);

            foreach (int i in new int[] { 2 })
            {
                var Quad        = boundaryFactory3D.CreateElement(CellType.Quad4, face[i - 1]);
                var faceElement = new Element();
                faceElement.ID          = i;
                faceElement.ElementType = Quad;
                foreach (Node node in face[i - 1])
                {
                    faceElement.AddNode(node);
                }
                model.SubdomainsDictionary[0].Elements.Add(faceElement);
                model.ElementsDictionary.Add(i, faceElement);

                var dirichletElement = dirichletFactory1.CreateElement(CellType.Quad4, face[i - 1]);
                //var fluxElement = fluxFactory.CreateElement(CellType.Quad4, face[i - 1]);

                model.SurfaceLoads.Add(dirichletElement);
                //model.SurfaceLoads.Add(fluxElement);
            }

            foreach (int i in new int[] { 3 })
            {
                var Quad        = boundaryFactory3D.CreateElement(CellType.Quad4, face[i - 1]);
                var faceElement = new Element();
                faceElement.ID          = i;
                faceElement.ElementType = Quad;
                foreach (Node node in face[i - 1])
                {
                    faceElement.AddNode(node);
                }
                model.SubdomainsDictionary[0].Elements.Add(faceElement);
                model.ElementsDictionary.Add(i, faceElement);

                var dirichletElement = dirichletFactory2.CreateElement(CellType.Quad4, face[i - 1]);
                //var fluxElement = fluxFactory.CreateElement(CellType.Quad4, face[i - 1]);

                model.SurfaceLoads.Add(dirichletElement);
                //model.SurfaceLoads.Add(fluxElement);
            }

            //constraints
            //foreach (int i in new int[] { 4, 5, 6, 7 })
            //{
            //    model.NodesDictionary[i].Constraints.Add(new Constraint()
            //    {
            //        Amount = 0,
            //        DOF = ThermalDof.Temperature
            //    });
            //}

            //// loads
            //Load load1;
            //foreach (int i in new int[] {0, 1, 2, 3})
            //{
            //    load1 = new Load()
            //    {
            //        Node = model.NodesDictionary[i],
            //        DOF = ConvectionDiffusionDof.Temperature,
            //        Amount = 12.5
            //    };
            //    model.Loads.Add(load1);
            //}


            return(model);
        }