Source code for Muscat.Containers.InriaMeshTools

# -*- coding: utf-8 -*-
#
# This file is subject to the terms and conditions defined in
# file 'LICENSE.txt', which is part of this source code package.
#
from numpy.typing import NDArray
import numpy as np

[docs]def fullMetric(metric: NDArray) -> NDArray: """Convert upper triangular coeff metric (mmg format) to complete SDP metric Parameters ---------- metric : NDArray a metric is a vector containing the dim2 = dim*(dim+1)/2 coefficients of the symmetric definite positive matrix Returns ------- metric : NDArray complete SDP metric """ dimF = metric.shape[0] if dimF == 3: met = np.array([[metric[0], metric[1]], [metric[1], metric[2]]]) elif dimF == 6: met = np.array([[metric[0], metric[1], metric[3]], [metric[1], metric[2], metric[4]], [metric[3], metric[4], metric[5]]]) elif dimF == 1: met = np.array([metric[0]]) return met
[docs]def flattenMetric(metric: NDArray) -> NDArray: """Convert complete SDP metric to upper triangular coeff metric (mmg format) Parameters ---------- metric : NDArray complete SDP metric Returns ------- metric : NDArray a metric is a vector containing the dim2 = dim*(dim+1)/2 coefficients of the symmetric definite positive matrix """ dim = metric.shape[0] if dim == 3: met = np.array([metric[0,0], metric[1,0], metric[1,1], metric[2,0], metric[2,1], metric[2,2]]) elif dim == 2: met = np.array([metric[0,0], metric[1,0], metric[1,1]]) elif dim == 1: met = np.array([metric[0,0]]) return met
[docs]def CheckIntegrity(GUI = False): fumet1 = np.array([[2, 1],[1, 3]]) met1 = flattenMetric(fumet1) fumet = fullMetric(met1) if (fumet1 != fumet).any(): raise ValueError("flattenMetric and fullMetric do not keep the metric") fumet2 = np.array([[2, 1, 4],[1, 3, 6],[4, 6, 1]]) met2 = flattenMetric(fumet2) fumet = fullMetric(met2) if (fumet2 != fumet).any(): raise ValueError("flattenMetric and fullMetric do not keep the metric") fumet3 = np.array([[2]]) met3 = flattenMetric(fumet3) fumet = fullMetric(met3) if (fumet3 != fumet).any(): raise ValueError("flattenMetric and fullMetric do not keep the metric") return "ok"
if __name__ == '__main__': print(CheckIntegrity())