fix: reformat src with fantoms

This commit is contained in:
Jonas Juselius
2022-09-15 10:11:07 +02:00
parent b6cdd4f2f2
commit 7955a76178
5 changed files with 51 additions and 46 deletions

View File

@@ -54,7 +54,7 @@ let private cullCoords (p: BiPos) (idx: (int * int) []) =
let y' = idx |> Array.map (fun (i, j) -> y[i, j])
Array.zip x' y'
let private createTree (points: Leaf<float, int>[]) =
let private createTree (points: Leaf<float, int> []) =
let tree = KdTree<float, int>(2, KdTree.Math.DoubleMath())
points
|> Array.iter (fun a -> tree.Add([| a.Pos.X; a.Pos.Y |], a.Data) |> ignore)
@@ -114,7 +114,7 @@ let private genOobIdx (proj: IProj) (tree: KdTree<_, _>) (cullIdx: (int * int) [
fPos
|> Array.fold
(fun (n, a) (x, y as p0) ->
tree.GetNearestNeighbours([|x; y|], 1)
tree.GetNearestNeighbours([| x; y |], 1)
|> Array.head
|> fun p ->
let i0, i1 = cullIdx[p.Value]
@@ -149,7 +149,7 @@ let private mkFvcomAdjoint (proj: IProj) (fPos: PosVec) (bbox: BBox) ((rPos, wet
let nearest =
fPos
|> Array.map (fun (x, y) ->
tree.GetNearestNeighbours([|x; y|], 1)
tree.GetNearestNeighbours([| x; y |], 1)
|> Array.head
|> fun x -> x.Value)
{
@@ -169,7 +169,7 @@ let getNearestCell (proj: IProj) (fvcom: Grid) (roms: BiPos * Mask) =
let cells = Util.calcCentroids fvcom |> Array.map float2
mkFvcomAdjoint proj cells fvcom.BBox roms
let private createIdxTree (points: Leaf<float, int * int>[]) =
let private createIdxTree (points: Leaf<float, int * int> []) =
let tree = KdTree<float, int * int>(2, KdTree.Math.DoubleMath())
points
|> Array.iter (fun a -> tree.Add([| a.Pos.X; a.Pos.Y |], a.Data) |> ignore)
@@ -193,14 +193,10 @@ let makeNestTree ((lng, lat): float [,] * float [,]) =
// |> create2DTree treeLeafSize
|> createIdxTree
let getNearestUpperLeft'
(tree: KdTree<float, int * int>)
(((ew, ns), mask): BiPos * Mask)
((x, y): float * float)
=
let getNearestUpperLeft' (tree: KdTree<float, int * int>) (((ew, ns), mask): BiPos * Mask) ((x, y): float * float) =
let i, j =
// nearestNeighbor tree { X = x; Y = y }
tree.GetNearestNeighbours([|x; y|], 1)
tree.GetNearestNeighbours([| x; y |], 1)
|> fun x -> x[0].Value
let p1 =
[|
@@ -237,11 +233,13 @@ let getNearestUpperLeft'
[| i + 1, j; i + 1, j + 1; i, j + 1; i, j |]
elif inpolygon p3 (x, y) then
[| i, j - 1; i, j; i - 1, j; i - 1, j - 1 |]
elif inpolygon p4 (x,y) then
elif inpolygon p4 (x, y) then
[| i, j; i, j + 1; i - 1, j + 1; i - 1, j |]
else
[| 0,0; 0,0; 0,0; 0,0 |]
if (q |> Array.map (fun (q1, q2) -> q1 + q2) |> Array.sum) = 0 then
[| 0, 0; 0, 0; 0, 0; 0, 0 |]
if (q
|> Array.map (fun (q1, q2) -> q1 + q2)
|> Array.sum) = 0 then
failwith "Surrounding grid cell not found"
let m = q |> Array.map (fun (n, m) -> mask[n, m])
Array.zip q m
@@ -289,11 +287,13 @@ let getNearestUpperLeft
[| i + 1, j; i + 1, j + 1; i, j + 1; i, j |]
elif inpolygon p3 (x, y) then
[| i, j - 1; i, j; i - 1, j; i - 1, j - 1 |]
elif inpolygon p4 (x,y) then
elif inpolygon p4 (x, y) then
[| i, j; i, j + 1; i - 1, j + 1; i - 1, j |]
else
[| 0,0; 0,0; 0,0; 0,0 |]
if (q |> Array.map (fun (q1, q2) -> q1 + q2) |> Array.sum) = 0 then
[| 0, 0; 0, 0; 0, 0; 0, 0 |]
if (q
|> Array.map (fun (q1, q2) -> q1 + q2)
|> Array.sum) = 0 then
failwith "Surrounding grid cell not found"
let m = q |> Array.map (fun (n, m) -> mask[n, m])
Array.zip q m
@@ -318,4 +318,4 @@ let inline private cullBiMatrix (culler: (int * int) []) (m: 'a [,]) =
// adjoin fvcom and roms data based on nearest neighbours
let adjoinMatrix (adj: FvcomAdjoint) (m: 'a [,]) =
let x = cullBiMatrix adj.cullIdx m
adj.adjoinIdx |> Array.map (fun n -> x[n])
adj.adjoinIdx |> Array.map (fun n -> x[n])

View File

@@ -312,7 +312,8 @@ let getBBox (ds: DataSet) : BBox =
let maxX = Array.max x
let minY = Array.min y
let maxY = Array.max y
let center = float (minX + (maxX - minX)) / 2., float (minY + (maxY - minY))/ 2.
let center =
float (minX + (maxX - minX)) / 2., float (minY + (maxY - minY)) / 2.
{
minX = float minX
maxX = float maxX
@@ -327,10 +328,18 @@ let getBBox (ds: DataSet) : BBox =
let getGrid (ds: DataSet) : FvcomGrid =
try
let x = ds[ "x" ].GetData() :?> single [] |> Array.map float
let y = ds[ "y" ].GetData() :?> single [] |> Array.map float
let xc = ds[ "xc" ].GetData() :?> single [] |> Array.map float
let yc = ds[ "yc" ].GetData() :?> single [] |> Array.map float
let x =
ds[ "x" ].GetData() :?> single []
|> Array.map float
let y =
ds[ "y" ].GetData() :?> single []
|> Array.map float
let xc =
ds[ "xc" ].GetData() :?> single []
|> Array.map float
let yc =
ds[ "yc" ].GetData() :?> single []
|> Array.map float
let nv = ds[ "nv" ].GetData() :?> int [,]
let h = readBathymetry ds

View File

@@ -101,4 +101,4 @@ let calcVertexGradient (grid: ExtendedGrid) (field: float []) (thrs: float) (idx
let calcVertexGradients (grid: ExtendedGrid) (field: float []) (thrs: float) : Field =
let N = ((grid :> IGrid).getVertices ()).Length
[| 0 .. (N - 1) |]
|> Array.map (calcVertexGradient grid field thrs)
|> Array.map (calcVertexGradient grid field thrs)

View File

@@ -89,7 +89,7 @@ type private Ean = Map<NodeIdx, ElemIdx list>
// NOTE(SimenLK): The amount of items to be stored in the trees leafs
let treeLeafSize = LeafNodeSize 64
let private createTree (points: Leaf<double, int>[]) =
let private createTree (points: Leaf<double, int> []) =
let tree = KdTree<float, int>(2, KdTree.Math.DoubleMath())
points
|> Array.iter (fun a -> tree.Add([| a.Pos.X; a.Pos.Y |], a.Data) |> ignore)
@@ -438,9 +438,7 @@ module Util =
grid.getVertices ()
|> Array.mapi (fun i v ->
let x, y = v
{ Pos = { X = x; Y = y; }
Data = i }
)
{ Pos = { X = x; Y = y }; Data = i })
// |> create2DTree treeLeafSize
|> createTree
@@ -468,17 +466,15 @@ module Util =
// then Some leaf.Data
// else None)
let tryFindElement
(grid: IGrid)
(tree: KdTree<float, int>)
((p0, p1): float * float) =
tree.GetNearestNeighbours([|p0; p1|], 1)
let tryFindElement (grid: IGrid) (tree: KdTree<float, int>) ((p0, p1): float * float) =
tree.GetNearestNeighbours([| p0; p1 |], 1)
|> Array.tryHead
|> Option.bind (fun leaf ->
let vx = grid.getCellVertices leaf.Value
if isInsideTriangle vx (p0, p1)
then Some leaf.Value
else None)
if isInsideTriangle vx (p0, p1) then
Some leaf.Value
else
None)
// type private IdxTree = Tree<Leaf<single, ElemIdx> array, Node<single>>
// type private NodeIdxTree = Tree<Leaf<single, NodeIdx> array, Node<single>>
@@ -486,10 +482,10 @@ type private IdxTree = KdTree<float, int>
type private NodeIdxTree = KdTree<float, int>
type ExtendedGrid(grid: IGrid) =
let mutable nodeTree : NodeIdxTree option = None
let mutable elementTree : IdxTree option = None
let mutable neighborIndex : NeighborIndex option = None
let mutable centroids : Vertex [] option = None
let mutable nodeTree: NodeIdxTree option = None
let mutable elementTree: IdxTree option = None
let mutable neighborIndex: NeighborIndex option = None
let mutable centroids: Vertex [] option = None
let getNeighborIdx () =
match neighborIndex with
@@ -661,7 +657,7 @@ type ExtendedGrid(grid: IGrid) =
elementTree.Value)
let pickle = binarySerializer.Pickle tree
IO.File.WriteAllBytes (fname, pickle)
IO.File.WriteAllBytes(fname, pickle)
member x.loadElementTree(fname: string) =
let binarySerializer = FsPickler.CreateBinarySerializer()
@@ -670,4 +666,4 @@ type ExtendedGrid(grid: IGrid) =
elementTree <- binarySerializer.UnPickle<IdxTree> pickle |> Some
true
else
false
false

View File

@@ -88,7 +88,7 @@ let genBilinearInterpolationWgts
: BiWght option =
if mask0 && mask1 && mask2 && mask3 then
let AB = (x1 - x0) ** 2.0 + (y1 - y0) ** 2.0 |> sqrt
let BC = (x2 - x1)**2.0 + (y2 - y1)**2.0 |> sqrt
let BC = (x2 - x1) ** 2.0 + (y2 - y1) ** 2.0 |> sqrt
let CD = (x3 - x2) ** 2.0 + (y3 - y2) ** 2.0 |> sqrt
let DA = (x0 - x3) ** 2.0 + (y0 - y3) ** 2.0 |> sqrt
let h0 =
@@ -179,8 +179,8 @@ let interpolateProp
iprop
|> Array.mapi (fun id p ->
match p with
|Some _ -> -1
|None -> id)
| Some _ -> -1
| None -> id)
|> Array.filter (fun i -> i > 0)
|> Array.fold (fun a i -> a + "; " + string i) ""
failwith ($"FVCOM grid out of bounds. Oob indexes: {sidx}")
@@ -214,8 +214,8 @@ let interpProp (corneridx: (int * int) [] []) (wgths: BiWght option []) (prop: f
iprop
|> Array.mapi (fun i p ->
match p with
|Some _ -> -1
|None -> i)
| Some _ -> -1
| None -> i)
|> Array.filter (fun i -> i >= 0)
|> Array.fold (fun a i -> a + "; " + string i) ""
failwith ($"FVCOM grid out of bounds. Oob indexes: {sidx}")