Skip to content

Commit

Permalink
Get rid of the legacy conmech
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrbartman committed Sep 6, 2023
1 parent 56791af commit a62b72e
Show file tree
Hide file tree
Showing 34 changed files with 72 additions and 3,737 deletions.
92 changes: 0 additions & 92 deletions conmech/dynamics/dynamics.py
Original file line number Diff line number Diff line change
@@ -1,69 +1,23 @@
from dataclasses import dataclass
from typing import Optional

import numba
import numpy as np

from conmech.dynamics.factory.dynamics_factory_method import (
get_dynamics,
get_basic_matrices,
get_factory,
)
from conmech.helpers.schur_complement_functions import calculate_schur_complement_matrices
from conmech.properties.body_properties import (
TemperatureBodyProperties,
ElasticRelaxationProperties,
)
from conmech.scene.body_forces import BodyForces


@numba.njit
def get_edges_features_list_numba(edges_number, edges_features_matrix):
nodes_count = len(edges_features_matrix[0])
edges_features = np.zeros((edges_number + nodes_count, 8))
edge_id = 0
for i in range(nodes_count):
for j in range(nodes_count):
if np.any(edges_features_matrix[i, j]):
edges_features[edge_id] = edges_features_matrix[i, j]
edge_id += 1
return edges_features


# TODO: #75
@dataclass
class SolverMatrices:
def __init__(self):
self.lhs: np.ndarray
# TODO: #75 move to schur (careful - some properties are used by net)
self.lhs_boundary: np.ndarray
self.free_x_contact: np.ndarray
self.contact_x_free: np.ndarray
self.free_x_free_inverted: np.ndarray

self.lhs_temperature: np.ndarray
# TODO: #75 move to schur (careful - some properties are used by net)
self.temperature_boundary: np.ndarray
self.temperature_free_x_contact: np.ndarray
self.temperature_contact_x_free: np.ndarray
self.temperature_free_x_free_inv: np.ndarray


@dataclass
class DynamicsConfiguration:
normalize_by_rotation: bool = True
create_in_subprocess: bool = False
with_lhs: bool = True
with_schur: bool = True


class Dynamics:
# pylint: disable=too-many-instance-attributes
def __init__(
self,
body: "Body",
time_step,
dynamics_config: DynamicsConfiguration,
):
self.body = body
self.body.dynamics = self
Expand All @@ -72,10 +26,6 @@ def __init__(
self.temperature = BodyForces(
body,
)
self.time_step = time_step
self.with_lhs = dynamics_config.with_lhs
self.with_schur = dynamics_config.with_schur

self.factory = get_factory(body.mesh.mesh_prop.dimension)
self.element_initial_volume: np.ndarray
self.volume_at_nodes: np.ndarray
Expand All @@ -91,7 +41,6 @@ def __init__(
self.permittivity: np.ndarray
self.poisson_operator: np.ndarray

self.solver_cache = SolverMatrices()
self.reinitialize_matrices()

def reinitialize_matrices(self):
Expand Down Expand Up @@ -121,47 +70,6 @@ def reinitialize_matrices(self):
W=self._w_matrix,
)

if not self.with_lhs:
return

self.solver_cache.lhs = (
self.acceleration_operator
+ (self.viscosity + self.elasticity * self.time_step) * self.time_step
)
if self.with_schur:
(
self.solver_cache.lhs_boundary,
self.solver_cache.free_x_contact,
self.solver_cache.contact_x_free,
self.solver_cache.free_x_free_inverted,
) = calculate_schur_complement_matrices(
matrix=self.solver_cache.lhs,
dimension=self.body.mesh.dimension,
contact_indices=self.body.mesh.contact_indices,
free_indices=self.body.mesh.free_indices,
)

if self.with_temperature:
i = self.body.mesh.independent_indices
self.solver_cache.lhs_temperature = (
1 / self.time_step
) * self.acceleration_operator[i, i] + self.thermal_conductivity[i, i]
(
self.solver_cache.temperature_boundary,
self.solver_cache.temperature_free_x_contact,
self.solver_cache.temperature_contact_x_free,
self.solver_cache.temperature_free_x_free_inv,
) = calculate_schur_complement_matrices(
matrix=self.solver_cache.lhs_temperature,
dimension=1,
contact_indices=self.body.mesh.contact_indices,
free_indices=self.body.mesh.free_indices,
)

@property
def with_temperature(self):
return isinstance(self.body.properties, TemperatureBodyProperties)

def relaxation(self, time: float = 0):
# TODO handle others
if isinstance(self.body.properties, ElasticRelaxationProperties):
Expand Down
21 changes: 0 additions & 21 deletions conmech/helpers/cmh.py

This file was deleted.

27 changes: 0 additions & 27 deletions conmech/helpers/mph.py

This file was deleted.

49 changes: 0 additions & 49 deletions conmech/helpers/nph.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,26 +127,6 @@ def get_in_base(vectors: np.ndarray, base: np.ndarray) -> np.ndarray:
return vectors @ base.T


@numba.njit
def len_x_numba(corners):
return corners[2] - corners[0]


@numba.njit
def len_y_numba(corners):
return corners[3] - corners[1]


@numba.njit
def min_numba(corners):
return [corners[0], corners[1]]


@numba.njit
def max_numba(corners):
return [corners[2], corners[3]]


@numba.njit
def get_node_index_numba(node, nodes):
for i, n in enumerate(nodes):
Expand All @@ -159,35 +139,6 @@ def generate_normal(rows: int, columns: int, scale: float) -> np.ndarray:
return np.random.normal(loc=0.0, scale=scale * 0.5, size=[rows, columns])


def generate_uniform_circle(rows: int, columns: int, low: float, high: float) -> np.ndarray:
result = generate_normal(rows=rows, columns=columns, scale=1.0)
normalized_result = normalize_euclidean_numba(result)
radius = np.random.uniform(low=low, high=high, size=[rows, 1])
return radius * normalized_result


def append_euclidean_norm(data: np.ndarray) -> np.ndarray:
return np.hstack((data, euclidean_norm(data, keepdims=True)))


@numba.njit(inline="always")
def length(p_1, p_2):
return np.sqrt((p_1[0] - p_2[0]) ** 2 + (p_1[1] - p_2[1]) ** 2)


# @numba.njit
# def calculate_angle_numba(new_up_vector):
# old_up_vector = np.array([0., 1.])
# angle = (2 * (new_up_vector[0] >= 0) - 1) * np.arccos(np.dot(new_up_vector, old_up_vector))
# return angle
#
# @numba.njit
# def rotate_numba(vectors, angle):
# s = np.sin(angle)
# c = np.cos(angle)
#
# rotated_vectors = np.zeros_like(vectors)
# rotated_vectors[:, 0] = vectors[:, 0] * c - vectors[:, 1] * s
# rotated_vectors[:, 1] = vectors[:, 0] * s + vectors[:, 1] * c
#
# return rotated_vectors
45 changes: 0 additions & 45 deletions conmech/helpers/pkh.py

This file was deleted.

42 changes: 0 additions & 42 deletions conmech/helpers/schur_complement_functions.py

This file was deleted.

25 changes: 0 additions & 25 deletions conmech/mesh/interpolators.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,28 +74,3 @@ def get_nodes_interpolation(nodes: np.ndarray, base: np.ndarray, corner_vectors:
denormalized_nodes_interpolation # nph.get_in_base(denormalized_nodes_interpolation, base)
)
return nodes_interpolation


def interpolate_four(
nodes: np.ndarray,
mean_scale: float,
corners_scale_proportion: float,
base: np.ndarray,
interpolate_rotate: bool,
zero_out_proportion: float = 0,
):
if decide(zero_out_proportion):
return np.zeros_like(nodes)

dimension = nodes.shape[1]
corners_scale = mean_scale * corners_scale_proportion

mean = get_mean(dimension=dimension, scale=mean_scale)

get_corner_vectors = get_corner_vectors_rotate if interpolate_rotate else get_corner_vectors_all
corner_vectors = get_corner_vectors(dimension=dimension, scale=corners_scale)
nodes_interpolation = get_nodes_interpolation(
nodes=nodes, base=base, corner_vectors=corner_vectors
)

return mean + nodes_interpolation
12 changes: 3 additions & 9 deletions conmech/mesh/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ def __init__(
self,
mesh_prop: MeshProperties,
boundaries_description: BoundariesDescription,
create_in_subprocess: bool,
):
self.mesh_prop = mesh_prop

Expand All @@ -100,20 +99,15 @@ def __init__(
self.base_seed_indices: np.ndarray
self.closest_seed_index: int

self.reinitialize_data(mesh_prop, boundaries_description, create_in_subprocess)

def remesh(self, boundaries_description, create_in_subprocess):
self.reinitialize_data(self.mesh_prop, boundaries_description, create_in_subprocess)
self.reinitialize_data(mesh_prop, boundaries_description)

def reinitialize_data(
self,
mesh_prop: MeshProperties,
boundaries_description: BoundariesDescription,
create_in_subprocess,
boundaries_description: BoundariesDescription
):
input_nodes, input_elements = mesh_builders.build_mesh(
mesh_prop=mesh_prop,
create_in_subprocess=create_in_subprocess,
mesh_prop=mesh_prop
)
unordered_nodes, unordered_elements = remove_unconnected_nodes_numba(
input_nodes, input_elements
Expand Down
Loading

0 comments on commit a62b72e

Please sign in to comment.