在单元格/随机坐标中拆分矩形/在FORTRAN中存储在数组中 [英] split rectangle in cells / random coordinates / store in array in FORTRAN

查看:157
本文介绍了在单元格/随机坐标中拆分矩形/在FORTRAN中存储在数组中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在单元格中拆分一个矩形。在每个单元格中,它应该创建一个随机坐标(y,z)。不幸的是我无法附上照片。请在另一个论坛中查看图片和我的同一问题:

http://stackoverflow.com/questions/25103098/split-rectangle-in-cells-random-coordinates-store-in-array -in-fortran [ ^ ]





矩形的宽度和高度已知( initialW / initalH)。计算细胞的大小(dy / dz)。数字,即矩形的部分数量,是已知的。 (numberCellsY / numberCellsZ)



这里我在Fortran中的代码将单元格拆分为单元格:

I would like to split a rectangle in cells. In each cell it should be create a random coordinate (y, z). Unfortunately I can not attache pictures. Please see the pictures and my same question in another forum:
http://stackoverflow.com/questions/25103098/split-rectangle-in-cells-random-coordinates-store-in-array-in-fortran[^]


The wide and height of the rectangle are known (initialW / initalH). The size of the cells are calculated (dy / dz). The numbers, in how many cells the rectangle to be part, are known. (numberCellsY / numberCellsZ)

Here my Code in Fortran to split the rectangle in Cells:

yRVEMin = 0.0
yRVEMax = initialW
dy = ( yRVEMax - yRVEMin ) / numberCellsY         

zRVEMin = 0.0
zRVEMax = initialH
dz = ( zRVEMax - zRVEMin ) / numberCellsZ


do i = 1, numberCellsY 
   yMin(i) = (i-1)*dy
   yMax(i) = i*dy
end do

do j = 1, numberCellsZ 
    zMin(j) = (j-1)*dz
    zMax(j) = j*dz
end do





现在我想生成一个随机的每个细胞中的坐标。对我来说,问题是将coodinates存储在一个数组中。它不一定都存储在一个数组中,但最好尽可能存储。



要用坐标填充单元格,它应该从左下角的单元格开始,经过行(y方向),并在最后一个单元格(numberCellsY)之后跳过一个更高的列(z-dicrection)并再次由左侧新行的第一个单元格重新开始。应该这么长,直到达到规定的数量(nfibers)。



这是一个令人遗憾的尝试:



Now I would like to produce a random coordinate in each cell. The problem for me is, to store the coodinates in an array. It does not necessarily all be stored in one array, but as least as possible.

To fill the cells with coordinates it should start at the bottom left cell, go through the rows (y-direction), and after the last cell (numberCellsY) jump a column higher (z-dicrection) and start again by the first cell of the new row at left side. That should be made so long until a prescribed number (nfibers) is reached.

Here a deplorable try to do it:

call random_seed
  l = 0
    do k = 1 , nfibers
        if (l < numberCellsY) then
            l = l + 1
        else
            l = 1
        end if
        call random_number(y) 
        fiberCoordY(k) = yMin(l) + y * (yMax(l) - yMin(l))
    end do

n = 0
    do m = 1 , nfibers
        if (n < numberCellsZ) then
            n = n + 1
        else
           n = 1
        end if
        call random_number(z) 
       fiberCoordZ(m) = zMin(n) + z * (zMax(n) - zMin(n))
    end do





输出不是我想要的!只要达到numberCellsY步骤,fiberCoordZ应保持开启(zMin(1)/ zMax(1)。



以下设置的输出:



The output is not what I want! fiberCoordZ should be stay on (zMin(1) / zMax(1) as long as numberCellsY-steps are reached.

The output for following settings:

nfibers = 9 
numberCellsY = 3 
numberCellsZ = 3 
initialW = 9.0 
initialH = 9.0





我对fiberCoordY的随机输出是:



My random output for fiberCoordY is:

1.768946    3.362770     8.667685     1.898700    5.796713   8.770239       2.463412       3.546694    7.074708





和fiberCoordZ是:



and for fiberCoordZ is:

2.234807    5.213032     6.762228     2.948657    5.937295    8.649946      0.6795220     4.340364    8.352566





在这种情况下,前3个数量的fiberCoordz应该有一个介于0.0和3.0之间的值。比数字4 - 6之间的数值3.0和6.0。数字7 - 9的值在6.0 - 9.0之间。



如何解决这个问题?如果某人有更好的解决方案,请发布它!



谢谢



In this case the first 3 numbers of fiberCoordz should have a value between 0.0 and 3.0. Than number 4 - 6 a value between 3.0 and 6.0. And number 7 - 9 a value bewtween 6.0 - 9.0.

How can I solve this? If somebody has a solution with a better approach, please post it!

Thanks

推荐答案

这篇关于在单元格/随机坐标中拆分矩形/在FORTRAN中存储在数组中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆