-
Notifications
You must be signed in to change notification settings - Fork 4
Ms homo #72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jbrezmorf
wants to merge
8
commits into
JB_homo
Choose a base branch
from
MS_homo
base: JB_homo
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Ms homo #72
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3068e8c
mc homo
6485282
setup bgem.tests
97b7e1c
bgem mlmc dfm
46bb2cf
tests
123368c
Merge branch 'JB_homo' into MS_homo
165f37b
static transform mat fc
6edeb8b
Merge branch 'JB_homo' into MS_homo
jbrezmorf 78fe5eb
Merge branch 'JB_homo' into MS_homo
jbrezmorf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -992,8 +992,110 @@ def transform_mat(self): | |
| :return: Shape (N, 3, 3). | ||
| """ | ||
| trans_mat = (self.rotation_mat[:, :, :]).copy() | ||
| trans_mat[:, :, 0] *= (self.radius[:, 0])[:, None] | ||
| trans_mat[:, :, 1] *= (self.radius[:, 1])[:, None] | ||
| trans_mat[:, :, 0] *= (self.radius[:, 0])[:, None] | ||
| trans_mat[:, :, 1] *= (self.radius[:, 1])[:, None] | ||
| return trans_mat | ||
|
|
||
| @staticmethod | ||
| def get_rotation_mat(normal, shape_axis): | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it practical to create static methods. Could we simplify creation of FractureSet class so that one can use the class methods? At least deduplicate the code by calling static methods from cached_properties. Partialy done in JB_homo. |
||
| """ | ||
| Rotate and scale matrices for the fractures. The full transform involves 'self.center' as well: | ||
| ambient_space_points = self.center + self.transform_mat @ local_fr_points[:, None, :] | ||
|
|
||
| The Z- local axis is transformed to normal N (assumed unit). | ||
| The shape_axis S = [sx, sy, 0] must be rotated to SS by the rotation that rotates Z -> N. | ||
| Then SS is transformation of the local X axis. | ||
| The transformation of the Y axis is then computed by the corss product. | ||
|
|
||
| Let's compute S': | ||
| 1. Z -> N rotation unit axis K = [-Ny, Nx, 0] / Nxy | ||
| 2. K . S = Sx Ny - Sy Nx | ||
| 3. follow Rodriguez formula proof, split S into part parallel (p) with K and ortogonal (o) to K | ||
| Sp = (K.S) K | ||
| So = S - Sp | ||
| 4. In the plane perpendicular to K, | ||
| we have vertical component giving: cos(th) = Nz | ||
| and horizontal component giving sin(th) = Nxy = sqrt(Nx^2 + Ny^2) | ||
| 5. We rotate So by angle th: | ||
| SSo[z] = -|So| Nxy *sng(Nx) | ||
| SSo[x,y] = (So [x,y]) Nz | ||
| 6. SSp = Sp | ||
| 7. Sum: | ||
| SS = SSo + SSp : | ||
| SSx = Spx + (Nz)Sox | ||
| SSy = Spy + (Nz)Soy | ||
| SSz = -|So| Nxy *sng(Nx) | ||
| Finally, the third vector of the rotated bases is cross(N, S') | ||
| TODO: find a better vector representation of the rotations, allowing faster construction of the transfrom matrix | ||
| :return: Shape (N, 3, 3). | ||
| """ | ||
| N = normal | ||
| assert np.allclose(np.linalg.norm(N, axis=1), 1) | ||
| Nxy = np.stack([-N[:, 1], N[:, 0]], axis=1) | ||
| norm_Nxy = np.linalg.norm(Nxy, axis=1) | ||
| K = Nxy / norm_Nxy[:, None] | ||
| arg_small = np.argwhere(norm_Nxy < 1e-13)[:, 0] | ||
| K[arg_small, :] = np.array([1, 0], dtype=float) | ||
| K_dot_S = shape_axis[:, None, :] @ K[:, :, None] | ||
| S_p = K_dot_S[:, 0, :] * K | ||
| S_o = shape_axis - S_p | ||
| cos_th = N[:, 2:3] | ||
| SS_xy = S_p + cos_th * S_o | ||
| # ?? th is in (0, pi) -> sin(th) always positive | ||
| #pos_nx = np.logical_xor(N[:, 0] > 0, N[:, 2] < 0) | ||
| pos_nx = (N[:, None, 0:2] @ shape_axis[:, :, None])[:, 0, 0] > 0 | ||
| sin_th = norm_Nxy | ||
| sin_th[pos_nx] = - sin_th[pos_nx] | ||
| SS_z = np.linalg.norm(S_o, axis=1) * sin_th | ||
|
|
||
| # Construct the rotated X axis SS vector, shape (N, 3) | ||
| SS = np.concatenate([ | ||
| SS_xy, | ||
| SS_z[:, None] | ||
| ], axis=1) | ||
| scaled_trans_x = SS #* self.radius[:, 0:1] | ||
| scaled_trans_y = np.cross(N, SS, axis=1) #* self.radius[:, 1:2] | ||
| trans_z = N | ||
| rot_mat = np.stack([scaled_trans_x, scaled_trans_y, trans_z], axis=2) | ||
| return rot_mat | ||
|
|
||
| @staticmethod | ||
| def transform_mat_static(normal, shape_axis, radius): | ||
| """ | ||
| Rotate and scale matrices for the fractures. The full transform involves 'self.center' as well: | ||
| ambient_space_points = self.center + self.transform_mat @ local_fr_points[:, None, :] | ||
|
|
||
| The Z- local axis is transformed to normal N (assumed unit). | ||
| The shape_axis S = [sx, sy, 0] must be rotated to SS by the rotation that rotates Z -> N. | ||
| Then SS is transformation of the local X axis. | ||
| The transformation of the Y axis is then computed by the corss product. | ||
|
|
||
| Let's compute S': | ||
| 1. Z -> N rotation unit axis K = [-Ny, Nx, 0] / Nxy | ||
| 2. K . S = Sx Ny - Sy Nx | ||
| 3. follow Rodriguez formula proof, split S into part parallel (p) with K and ortogonal (o) to K | ||
| Sp = (K.S) K | ||
| So = S - Sp | ||
| 4. In the plane perpendicular to K, | ||
| we have vertical component giving: cos(th) = Nz | ||
| and horizontal component giving sin(th) = Nxy = sqrt(Nx^2 + Ny^2) | ||
| 5. We rotate So by angle th: | ||
| SSo[z] = -|So| Nxy *sng(Nx) | ||
| SSo[x,y] = (So [x,y]) Nz | ||
| 6. SSp = Sp | ||
| 7. Sum: | ||
| SS = SSo + SSp : | ||
| SSx = Spx + (Nz)Sox | ||
| SSy = Spy + (Nz)Soy | ||
| SSz = -|So| Nxy *sng(Nx) | ||
| Finally, the third vector of the rotated bases is cross(N, S') | ||
| TODO: find a better vector representation of the rotations, allowing faster construction of the transfrom matrix | ||
| :return: Shape (N, 3, 3). | ||
| """ | ||
| rotation_mat = FractureSet.get_rotation_mat(normal, shape_axis) | ||
| trans_mat = (rotation_mat[:, :, :]).copy() | ||
| trans_mat[:, :, 0] *= (radius[:, 0])[:, None] | ||
| trans_mat[:, :, 1] *= (radius[:, 1])[:, None] | ||
| return trans_mat | ||
|
|
||
| @fn.cached_property | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any problem with output_dir ?