Path: blob/main/src/solvers/dgsem_unstructured/mappings_geometry_straight_2d.jl
5591 views
# By default, Julia/LLVM does not use fused multiply-add operations (FMAs).1# Since these FMAs can increase the performance of many numerical algorithms,2# we need to opt-in explicitly.3# See https://ranocha.de/blog/Optimizing_EC_Trixi for further details.4@muladd begin5#! format: noindent67# mapping formula from a point (xi, eta) in reference space [-1,1]^2 to a point (x,y)8# in physical coordinate space for a quadrilateral element with straight sides9# Alg. 95 from the blue book of Kopriva10function straight_side_quad_map(xi, eta, corner_points)11x = 0.25f0 * (corner_points[1, 1] * (1 - xi) * (1 - eta)12+ corner_points[2, 1] * (1 + xi) * (1 - eta)13+ corner_points[3, 1] * (1 + xi) * (1 + eta)14+ corner_points[4, 1] * (1 - xi) * (1 + eta))1516y = 0.25f0 * (corner_points[1, 2] * (1 - xi) * (1 - eta)17+ corner_points[2, 2] * (1 + xi) * (1 - eta)18+ corner_points[3, 2] * (1 + xi) * (1 + eta)19+ corner_points[4, 2] * (1 - xi) * (1 + eta))2021return x, y22end2324# Compute the metric terms for the straight sided quadrilateral mapping25# Alg. 100 from the blue book of Kopriva26function straight_side_quad_map_metrics(xi, eta, corner_points)27X_xi = 0.25f0 * ((1 - eta) * (corner_points[2, 1] - corner_points[1, 1]) +28(1 + eta) * (corner_points[3, 1] - corner_points[4, 1]))2930X_eta = 0.25f0 * ((1 - xi) * (corner_points[4, 1] - corner_points[1, 1]) +31(1 + xi) * (corner_points[3, 1] - corner_points[2, 1]))3233Y_xi = 0.25f0 * ((1 - eta) * (corner_points[2, 2] - corner_points[1, 2]) +34(1 + eta) * (corner_points[3, 2] - corner_points[4, 2]))3536Y_eta = 0.25f0 * ((1 - xi) * (corner_points[4, 2] - corner_points[1, 2]) +37(1 + xi) * (corner_points[3, 2] - corner_points[2, 2]))3839return X_xi, X_eta, Y_xi, Y_eta40end4142# construct the (x,y) node coordinates in the volume of a straight sided element43function calc_node_coordinates!(node_coordinates::AbstractArray{<:Any, 4}, element,44nodes, corners)45for j in eachindex(nodes), i in eachindex(nodes)46node_coordinates[:, i, j, element] .= straight_side_quad_map(nodes[i], nodes[j],47corners)48end4950return node_coordinates51end5253# construct the metric terms for a straight sided element54function calc_metric_terms!(jacobian_matrix, element, nodes, corners)5556# storage format:57# jacobian_matrix[1,1,:,:,:] <- X_xi58# jacobian_matrix[1,2,:,:,:] <- X_eta59# jacobian_matrix[2,1,:,:,:] <- Y_xi60# jacobian_matrix[2,2,:,:,:] <- Y_eta61for j in eachindex(nodes), i in eachindex(nodes)62(jacobian_matrix[1, 1, i, j, element],63jacobian_matrix[1, 2, i, j, element],64jacobian_matrix[2, 1, i, j, element],65jacobian_matrix[2, 2, i, j, element]) = straight_side_quad_map_metrics(nodes[i],66nodes[j],67corners)68end6970return jacobian_matrix71end7273# construct the normal direction vectors (but not actually normalized) for a straight sided element74# normalization occurs on the fly during the surface flux computation75function calc_normal_directions!(normal_directions, element, nodes, corners)7677# normal directions on the boundary for the left (local side 4) and right (local side 2)78for j in eachindex(nodes)79# side 280X_xi, X_eta, Y_xi, Y_eta = straight_side_quad_map_metrics(1, nodes[j],81corners)82Jtemp = X_xi * Y_eta - X_eta * Y_xi83normal_directions[1, j, 2, element] = sign(Jtemp) * (Y_eta)84normal_directions[2, j, 2, element] = sign(Jtemp) * (-X_eta)8586# side 487X_xi, X_eta, Y_xi, Y_eta = straight_side_quad_map_metrics(-1, nodes[j],88corners)89Jtemp = X_xi * Y_eta - X_eta * Y_xi90normal_directions[1, j, 4, element] = -sign(Jtemp) * (Y_eta)91normal_directions[2, j, 4, element] = -sign(Jtemp) * (-X_eta)92end9394# normal directions on the boundary for the top (local side 3) and bottom (local side 1)95for i in eachindex(nodes)96# side 197X_xi, X_eta, Y_xi, Y_eta = straight_side_quad_map_metrics(nodes[i], -1,98corners)99Jtemp = X_xi * Y_eta - X_eta * Y_xi100normal_directions[1, i, 1, element] = -sign(Jtemp) * (-Y_xi)101normal_directions[2, i, 1, element] = -sign(Jtemp) * (X_xi)102103# side 3104X_xi, X_eta, Y_xi, Y_eta = straight_side_quad_map_metrics(nodes[i], 1,105corners)106Jtemp = X_xi * Y_eta - X_eta * Y_xi107normal_directions[1, i, 3, element] = sign(Jtemp) * (-Y_xi)108normal_directions[2, i, 3, element] = sign(Jtemp) * (X_xi)109end110111return normal_directions112end113end # @muladd114115116