Esempio n. 1
0
 static void DistributedLoad(int server, DistributedLoad dload)
 {
     using (var request = new DistributedLoadWriter(dload.serverID, dload.fromServerID, dload.num_elements, dload.cellid1, dload.cellid2, dload.weight, dload.single_element, false))
     {
         Global.CloudStorage.DistributedLoadMessageToBenchmarkServer(server, request);
     }
 }
Esempio n. 2
0
        public void SenderThread(object nthread)
        {
            int             senderThreadId = (int)nthread;
            Load            new_load;
            DistributedLoad distributedLoad = new DistributedLoad();

            distributedLoad.cellid1        = new long[4194304];
            distributedLoad.cellid2        = new long[4194304];
            distributedLoad.weight         = new float[4194304];
            distributedLoad.single_element = new bool[4194304];
            int index = 0;

            while (finished_readers < num_threads || load_sender_queue[senderThreadId].Count > 0)
            {
                try{
                    if (load_sender_queue[senderThreadId].TryDequeue(out new_load))
                    {
                        distributedLoad.cellid1[index]        = new_load.cellid1;
                        distributedLoad.cellid2[index]        = new_load.cellid2;
                        distributedLoad.weight[index]         = new_load.weight;
                        distributedLoad.single_element[index] = new_load.single_element;
                        Interlocked.Increment(ref all_threads_sent_edges);
                        index++;
                        if (index >= 4194000)
                        {
                            //Console.WriteLine("Send Load to Server " + senderThreadId);
                            using (var request = new DistributedLoadWriter(senderThreadId, this_server_id, index, distributedLoad.cellid1, distributedLoad.cellid2, distributedLoad.weight, distributedLoad.single_element, false))
                            {
                                Global.CloudStorage.DistributedLoadMessageToBenchmarkServer(senderThreadId, request);
                            }
                            distributedLoad                = new DistributedLoad();
                            distributedLoad.cellid1        = new long[4194304];
                            distributedLoad.cellid2        = new long[4194304];
                            distributedLoad.weight         = new float[4194304];
                            distributedLoad.single_element = new bool[4194304];
                            index = 0;
                        }
                    }
                    else
                    {
                        Thread.Sleep(50);
                    }
                } catch (Exception ex) {
                    Console.Error.WriteLine(ex.Message + " INDEX:" + index);
                    Console.Error.WriteLine(ex.StackTrace.ToString());
                }
            }
            try{
                // Last Send
                Console.WriteLine("Send LAST Load to Server " + senderThreadId + " " + index);
                using (var request = new DistributedLoadWriter(senderThreadId, this_server_id, index, distributedLoad.cellid1, distributedLoad.cellid2, distributedLoad.weight, distributedLoad.single_element, true))
                {
                    Global.CloudStorage.DistributedLoadMessageToBenchmarkServer(senderThreadId, request);
                }
            } catch (Exception ex) {
                Console.Error.WriteLine(ex.Message);
                Console.Error.WriteLine(ex.StackTrace.ToString());
            }
        }
Esempio n. 3
0
        private static Tuple <Model, IModelReader> CreateModel3(double C1, double C2, IDynamicMaterial commonDynamicMaterialProperties, double b, double[] l, double lambdag)
        {
            double poissonV    = 0.2;
            double muLame      = 2 * C1;
            double bulkModulus = 2 * muLame * (1 + poissonV) / (3 * (1 - 2 * poissonV));
            string filename    = Path.Combine(Directory.GetCurrentDirectory(), "InputFiles", "TumorGrowthModel", "9hexa.mphtxt");
            var    modelReader = new ComsolMeshReader1(filename, C1, C2, 1, commonDynamicMaterialProperties, lambdag);
            Model  model       = modelReader.CreateModelFromFile();
            //Boundary Conditions
            var lx = l[0];
            var ly = l[1];
            var lz = l[2];
            var distributedLoad = new DistributedLoad(lx, ly, lz);
            //var flux2 = new FluxLoad(f2);
            //var dir1 = new DirichletDistribution(list => {
            //    return Vector.CreateWithValue(list.Count, b1);
            //});
            //var dir2 = new DirichletDistribution(list => {
            //    return Vector.CreateWithValue(list.Count, b2);
            //});
            //var weakDirichlet1 = new WeakDirichlet(dir1, k);
            //var weakDirichlet2 = new WeakDirichlet(dir2, k);

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

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


            int[] boundaryIDs = new int[] { 0, 5 };
            foreach (int boundaryID in boundaryIDs)
            {
                foreach (IReadOnlyList <Node> nodes in modelReader.quadBoundaries[boundaryID])
                {
                    foreach (Node node in nodes)
                    {
                        node.Constraints.Add(new Constraint()
                        {
                            Amount = b,
                            DOF    = StructuralDof.TranslationX
                        });
                        node.Constraints.Add(new Constraint()
                        {
                            Amount = b,
                            DOF    = StructuralDof.TranslationY
                        });
                        node.Constraints.Add(new Constraint()
                        {
                            Amount = b,
                            DOF    = StructuralDof.TranslationZ
                        });
                    }
                }
            }
            return(new Tuple <Model, IModelReader>(model, modelReader));
        }
Esempio n. 4
0
 public void addDistributedLoadToServer(DistributedLoad load)
 {
     try{
         Dictionary <long, int> position = new Dictionary <long, int>();
         SimpleGraphNode[]      thisLoadCompressedNodes = new SimpleGraphNode[load.num_elements];
         int reduction      = 0;
         int compress_index = 0;
         for (int i = 0; i < load.num_elements; i++)
         {
             Interlocked.Increment(ref all_threads_recieved_load_edges);
             if (position.ContainsKey(load.cellid1[i]))
             {
                 thisLoadCompressedNodes[position[load.cellid1[i]]].Outlinks.Add(load.cellid2[i]);
                 if (load.weight[i] != -1)
                 {
                     thisLoadCompressedNodes[position[load.cellid1[i]]].Weights.Add(load.weight[i]);
                 }
                 reduction++;
             }
             else
             {
                 position[load.cellid1[i]] = compress_index;
                 thisLoadCompressedNodes[compress_index]          = new SimpleGraphNode();
                 thisLoadCompressedNodes[compress_index].ID       = load.cellid1[i];
                 thisLoadCompressedNodes[compress_index].Outlinks = new List <long>();
                 thisLoadCompressedNodes[compress_index].Outlinks.Add(load.cellid2[i]);
                 if (load.weight[i] != -1)
                 {
                     thisLoadCompressedNodes[compress_index].Weights = new List <float>();
                     thisLoadCompressedNodes[compress_index].Weights.Add(load.weight[i]);
                 }
                 compress_index++;
             }
         }
         Console.WriteLine("Recieved Compressed Load (reduction)" + reduction + " compressed Nodes:" + compress_index);
         for (int i = 0; i < compress_index; i++)
         {
             //Console.WriteLine("RCV THREAD" + thisLoadCompressedNodes[i].ID);
             thread_cache[findThread(thisLoadCompressedNodes[i].ID)].Enqueue(thisLoadCompressedNodes[i]);
         }
         if (load.lastLoad)
         {
             Console.WriteLine("Last Load Arrived of Server:" + load.fromServerID);
             Interlocked.Increment(ref all_sends);
             //finished = true;
             Console.WriteLine("All Threads will be Finished!");
         }
     } catch (Exception ex) {
         Console.Error.WriteLine(ex.Message);
         Console.Error.WriteLine(ex.StackTrace.ToString());
     }
 }
        private static Tuple <Model, IModelReader> CreateStructuralModel(double C1, double C2, IDynamicMaterial commonDynamicMaterialProperties, double b, double[] l, double lg)
        {
            string filename    = Path.Combine(Directory.GetCurrentDirectory(), "InputFiles", "TumorGrowthModel", "9hexa.mphtxt");
            double poisonRatio = .45;
            double bulkModulus = 4 * C1 * (1 + poisonRatio) / 3 / (1 - 2 * poisonRatio);
            var    modelReader = new ComsolMeshReader1(filename, C1, C2, bulkModulus, commonDynamicMaterialProperties, lg);
            Model  model       = modelReader.CreateModelFromFile();
            //Boundary Conditions
            var lx = l[0];
            var ly = l[1];
            var lz = l[2];
            var distributedLoad        = new DistributedLoad(lx, ly, lz);
            var distributedLoadFactory = new SurfaceLoadElementFactory(distributedLoad);


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

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

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

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

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


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

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

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

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


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

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

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


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