Exemple #1
0
        private static Tuple <Model, ComsolMeshReader> CreateModel()
        {
            string           filename    = Path.Combine(Directory.GetCurrentDirectory(), "InputFiles", "TumorGrowthModel", "mesh1.mphtxt");
            ComsolMeshReader modelReader = new ComsolMeshReader(filename);
            Model            model       = modelReader.CreateModelFromFile();
            //Boundary Conditions
            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, 1));
            });
            var weakDirichlet1 = new WeakDirichlet(dir1, modelReader.diffusionCeoff);
            var weakDirichlet2 = new WeakDirichlet(dir2, modelReader.diffusionCeoff);

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

            int[] boundaryIDs = new int[] { 2, 7, 8, 9 };
            foreach (int boundaryID in boundaryIDs)
            {
                foreach (Element element in modelReader.elementBoundaries[boundaryID])
                {
                    IReadOnlyList <Node> nodes = (IReadOnlyList <Node>)element.Nodes;
                    var dirichletElement1      = dirichletFactory1.CreateElement(CellType.Tri3, nodes);
                    model.SurfaceLoads.Add(dirichletElement1);
                    //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[] { 0, 1, 3, 4, 6 };
            foreach (int boundaryID in boundaryIDs)
            {
                foreach (Element element in modelReader.elementBoundaries[boundaryID])
                {
                    IReadOnlyList <Node> nodes = (IReadOnlyList <Node>)element.Nodes;
                    var dirichletElement2      = dirichletFactory2.CreateElement(CellType.Tri3, nodes);
                    model.SurfaceLoads.Add(dirichletElement2);
                }
            }

            return(new Tuple <Model, ComsolMeshReader>(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));
        }
Exemple #3
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));
        }
Exemple #4
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 Model CreateModel()
        {
            IList <IList <Node> >    nodeBoundaries;
            IList <IList <Element> > elementBoundaries;
            double density = 1.0;

            double[] U = { 2, 2, 2 };
            double   k = 1.0;
            double   L = .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 },
                { 0, 1, 0 },
                { 0, 1, 1 },
                { 0, 0, 1 },
                { 1, 0, 0 },
                { 1, 1, 0 },
                { 1, 1, 1 },
                { 1, 0, 1 }
            };

            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],
            };
            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[4],
                model.NodesDictionary[5],
                model.NodesDictionary[6],
                model.NodesDictionary[7],
            };
            face[2] = new List <Node>
            {
                model.NodesDictionary[0],
                model.NodesDictionary[1],
                model.NodesDictionary[5],
                model.NodesDictionary[4],
            };
            face[3] = new List <Node>
            {
                model.NodesDictionary[1],
                model.NodesDictionary[2],
                model.NodesDictionary[6],
                model.NodesDictionary[5],
            };
            face[4] = new List <Node>
            {
                model.NodesDictionary[2],
                model.NodesDictionary[6],
                model.NodesDictionary[7],
                model.NodesDictionary[3],
            };
            face[5] = new List <Node>
            {
                model.NodesDictionary[0],
                model.NodesDictionary[4],
                model.NodesDictionary[7],
                model.NodesDictionary[3],
            };
            int[] elementData = new int[] { 0, 1, 2, 3, 4, 5, 6, 7 };// the last line will not be used. We assign only one element

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

            element.ID          = 0;
            element.ElementType = Hexa8;
            for (int j = 0; j < 8; j++)
            {
                element.NodesDictionary.Add(elementData[j], model.NodesDictionary[elementData[j]]);
            }
            model.SubdomainsDictionary[0].Elements.Add(element);
            model.ElementsDictionary.Add(0, element);

            var flux1 = new FluxLoad(1);
            var flux2 = 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 fluxFactory1      = new SurfaceLoadElementFactory(flux1);
            var fluxFactory2      = new SurfaceLoadElementFactory(flux2);

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

                //var dirichletElement = dirichletFactory2.CreateElement(CellType.Quad4, face[i]);
                //model.SurfaceLoads.Add(dirichletElement);

                var fluxElement = fluxFactory1.CreateElement(CellType.Quad4, face[i]);
                model.SurfaceLoads.Add(fluxElement);
            }

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

                //var dirichletElement = dirichletFactory2.CreateElement(CellType.Quad4, face[i]);
                //model.SurfaceLoads.Add(dirichletElement);

                var fluxElement = fluxFactory2.CreateElement(CellType.Quad4, face[i]);
                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 = ThermalDof.Temperature,
            //        Amount = 12.5
            //    };
            //    model.Loads.Add(load1);
            //}


            return(model);
        }
        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));
        }