-
Couldn't load subscription status.
- Fork 140
Add Verification Manual VM8 #820
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
Merged
Merged
Changes from 42 commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
31e56be
VM8 almost finishe code, idea how to modify NDIST
RomanIlchenko1308 33aefbb
Merge branch 'main' into doc/vm8
RomanIlchenko1308 d824596
Merge branch 'main' into doc/vm8
RomanIlchenko1308 205d4bc
check kp distances and use updates of kdist
RomanIlchenko1308 fe3d08a
vm8 check
RomanIlchenko1308 70b259e
almost all code without comments
RomanIlchenko1308 62a3130
Merge branch 'main' into doc/vm8
RomanIlchenko1308 111be7d
deleted unnecessary files
RomanIlchenko1308 e073346
deleted old file without ndist and kdist functionality
RomanIlchenko1308 d4b8eba
removed old file and created new one to check kdist functionality
RomanIlchenko1308 a65b146
Full script without comments
RomanIlchenko1308 ed1e24f
extra modifications
RomanIlchenko1308 b02a745
check vm8
RomanIlchenko1308 8816dd3
updated and simplified pandas dataframe with output results
RomanIlchenko1308 a6855d7
Modified Output dataframe and added comments
RomanIlchenko1308 e9a440d
Modified LaTex style at the Check Output
RomanIlchenko1308 763a858
add numbers of the kps and nodes
RomanIlchenko1308 a1594a2
Added f-string properties to the print outputs
RomanIlchenko1308 7ab16d1
Added vtk and numbering to the kps and nodes plotting
RomanIlchenko1308 c1ad655
adding description
RomanIlchenko1308 36985e5
chaged a style inside of the keypoint and node topic
RomanIlchenko1308 c1c4ca5
fixed some mistakes of the description
RomanIlchenko1308 4f861a0
fixing style of script for pandas data frame settings
RomanIlchenko1308 60c6dd4
check unit testing
RomanIlchenko1308 ceaf516
added Analysis Assumptions description
RomanIlchenko1308 0fd4289
VM is ready to review
RomanIlchenko1308 ab7b7c7
VM is ready to review
RomanIlchenko1308 a9807cf
VM is ready to review1
RomanIlchenko1308 c1ddc15
VM8 is ready to review
RomanIlchenko1308 1838af2
VM8 changed name of the class block
RomanIlchenko1308 f76861e
Merge branch 'main' into doc/vm8
RomanIlchenko1308 795697b
Delete misc.xml
germa89 3c7425d
Delete pymapdl.iml
germa89 0597f27
removed idea files
RomanIlchenko1308 cdbc714
Merge branch 'main' into doc/vm8
RomanIlchenko1308 92abb06
Merge branch 'doc/vm8' of https://github.com/pyansys/pymapdl into doc…
RomanIlchenko1308 d688df7
changed names of the methods
RomanIlchenko1308 aa75db0
VM8 is ready to be merged, almost all suggestions were added
RomanIlchenko1308 ae776ba
VM8 is rebuilt with decorator property and ready to review
RomanIlchenko1308 a8842c6
Removed styling setting, left just format style for decimals
RomanIlchenko1308 dd79c00
Unit test check
RomanIlchenko1308 bd05834
Unit test check2
RomanIlchenko1308 7f03c65
VM8 Last update, ready to be merged
RomanIlchenko1308 78f8555
VM8 check
RomanIlchenko1308 50f0053
VM10 check test
RomanIlchenko1308 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
232 changes: 232 additions & 0 deletions
232
examples/06-verif-manual/vm-008-parametric_calculation.py
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 |
|---|---|---|
| @@ -0,0 +1,232 @@ | ||
| r""" | ||
| .. _ref_vm8_example: | ||
| Parametric Calculation | ||
| ---------------------- | ||
| Problem Description: | ||
| - Write a user file macro to calculate the distance ``d`` between either nodes | ||
| or keypoints in ``PREP7``. Define abbreviations for calling the macro and | ||
| verify the parametric expressions by using the macro to calculate | ||
| the distance between nodes :math:`N_1` and :math:`N_2` and | ||
| between keypoints :math:`K_3` and :math:`K_4`. | ||
| Reference: | ||
| - None. | ||
| Analysis Type(s): | ||
| - Parametric Arithmetic. | ||
| Element Type: | ||
| - None. | ||
| Geometric Properties(Coordinates): | ||
| - :math:`N_{\mathrm{1(x,y,z)}} = 1.5, 2.5, 3.5` | ||
| - :math:`N_{\mathrm{2(x,y,z)}} = -3.7, 4.6, -3` | ||
| - :math:`K_{\mathrm{3(x,y,z)}} = 100, 0, 30` | ||
| - :math:`K_{\mathrm{4(x,y,z)}} = -200,25,80` | ||
| .. image:: ../../_static/vm8_setup.png | ||
| :width: 300 | ||
| :alt: VM8 Problem Sketch | ||
| Analysis Assumptions and Modeling Notes: | ||
| - Instead of ``*CREATE``, ``*USE``, etc., we have created a class | ||
| ``Create`` with methods that correspond to each type of simulation. | ||
| This class gives a possibility to change coordinates and reuse it. | ||
| The simulation can be checked not just by target values, but also | ||
| with the simple distances' formula between keypoints as: | ||
| * Calculate distance between two keypoints in the Cartesian coordinate system: | ||
| :math:`D = \sqrt[2]{(x_2 - x_1)^2 + (y_2 - y_1)^2 + (z_2 - z_1)^2}` | ||
| * Python representation of the distance formula: | ||
| .. doctest:: | ||
| import math | ||
| # Define coordinates for keypoints K3 and K4. | ||
| x1, y1, z1 = 100, 0, 30 | ||
| x2, y2, z2 = -200, 25, 80 | ||
| dist_kp = math.sqrt((x2 - x1)**2 + (y2 - y1)**2 + (z2 - z1)**2) | ||
| print(dist_kp) | ||
RomanIlchenko1308 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| """ | ||
|
|
||
| ############################################################################### | ||
| # Start MAPDL | ||
| # ~~~~~~~~~~~ | ||
| # Start MAPDL and import Numpy and Pandas libraries. | ||
|
|
||
| # sphinx_gallery_thumbnail_path = '_static/vm8_setup.png' | ||
germa89 marked this conversation as resolved.
Show resolved
Hide resolved
RomanIlchenko1308 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| import numpy as np | ||
| import pandas as pd | ||
|
|
||
| from ansys.mapdl.core import launch_mapdl | ||
|
|
||
| # Start MAPDL. | ||
| mapdl = launch_mapdl() | ||
|
|
||
|
|
||
| ############################################################################### | ||
| # Pre-Processing | ||
| # ~~~~~~~~~~~~~~ | ||
| # Enter verification example mode and the pre-processing routine. | ||
|
|
||
| mapdl.clear() | ||
| mapdl.verify() | ||
| mapdl.prep7(mute=True) | ||
|
|
||
|
|
||
| ############################################################################### | ||
| # Define Class | ||
| # ~~~~~~~~~~~~ | ||
| # Identifying the class ``create`` with methods ``create_kp_method`` and | ||
| # ``create_node_method`` to calculate and plot the distances between keypoints | ||
| # and nodes. | ||
|
|
||
| class Create: | ||
| def __init__(self, p1, p2): | ||
| # Points Attributes. | ||
| self.p1 = p1 | ||
| self.p2 = p2 | ||
|
|
||
| def kp_distances(self): | ||
|
|
||
| # Define keypoints by coordinates. | ||
| kp1 = mapdl.k(npt=3, x=self.p1[0], y=self.p1[1], z=self.p1[2]) | ||
| kp2 = mapdl.k(npt=4, x=self.p2[0], y=self.p2[1], z=self.p2[2]) | ||
|
|
||
| # Get the distance between keypoints. | ||
| dist_kp, kx, ky, kz = mapdl.kdist(kp1, kp2) | ||
|
|
||
| # Plot keypoints. | ||
| mapdl.kplot(show_keypoint_numbering=True, | ||
| vtk=True, | ||
| background="grey", | ||
| show_bounds=True, | ||
| font_size=26) | ||
RomanIlchenko1308 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return dist_kp | ||
|
|
||
| def node_distances(self): | ||
|
|
||
| # Define nodes by coordinates. | ||
| node1 = mapdl.n(node=1, x=self.p1[0], y=self.p1[1], z=self.p1[2]) | ||
| node2 = mapdl.n(node=2, x=self.p2[0], y=self.p2[1], z=self.p2[2]) | ||
|
|
||
| # Get the distance between nodes. | ||
| dist_node, node_x, node_y, node_z = mapdl.ndist(node1, node2) | ||
|
|
||
| # Plot nodes. | ||
| mapdl.nplot(nnum=True, | ||
| vtk=True, | ||
| color="grey", | ||
| show_bounds=True, | ||
| font_size=26) | ||
RomanIlchenko1308 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return dist_node | ||
|
|
||
| @property | ||
| def p1(self): | ||
| # Getting value | ||
| return self._p1 | ||
|
|
||
| @p1.setter | ||
| def p1(self, new_value): | ||
| # Check the data type: | ||
| if not isinstance(new_value, list): | ||
| raise ValueError("The coordinates should be implemented by the list!") | ||
| # Check the quantity of items: | ||
| if len(new_value) != 3: | ||
| raise ValueError("The coordinates should have three items in the list as [X, Y, Z]") | ||
| self._p1 = new_value | ||
|
|
||
| @property | ||
| def p2(self): | ||
| return self._p2 | ||
|
|
||
| @p2.setter | ||
| def p2(self, new_value): | ||
| # Check the data type: | ||
| if not isinstance(new_value, list): | ||
| raise ValueError("The coordinates should be implemented by the list!") | ||
| # Check the quantity of items: | ||
| if len(new_value) != 3: | ||
| raise ValueError("The coordinates should have three items in the list as [X, Y, Z]") | ||
| self._p2 = new_value | ||
|
|
||
|
|
||
| ############################################################################### | ||
| # Distance between keypoints | ||
| # ~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| # Using already created method for keypoints to get the distance between them | ||
| # and print out an output. The keypoints have got next coordinates: | ||
| # | ||
| # * :math:`K_{\mathrm{3(x,y,z)}} = 100, 0, 30` | ||
| # * :math:`K_{\mathrm{4(x,y,z)}} = -200, 25,80` | ||
|
|
||
| kp1 = [100, 0, 30] | ||
| kp2 = [-200, 25, 80] | ||
| kp = Create(kp1, kp2) | ||
| kp_dist = kp.kp_distances() | ||
| print(f"Distance between keypoint is: {kp_dist:.2f}\n\n") | ||
|
|
||
| # Print the list of keypoints. | ||
| print(mapdl.klist()) | ||
|
|
||
|
|
||
| ############################################################################### | ||
| # Distance between nodes. | ||
| # ~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| # Using already created method for nodes to get the distance between them and | ||
| # print out an output. The nodes have got next coordinates: | ||
| # | ||
| # * :math:`N_{\mathrm{1(x,y,z)}} = 1.5, 2.5, 3.5` | ||
| # * :math:`N_{\mathrm{2(x,y,z)}} = -3.7, 4.6, -3` | ||
|
|
||
| node1 = [1.5, 2.5, 3.5] | ||
| node2 = [-3.7, 4.6, -3] | ||
| nodes = Create(node1, node2) | ||
| node_dist = nodes.node_distances() | ||
| print(f"Distance between nodes is: {node_dist:.2f}\n\n") | ||
|
|
||
| # Print the list of nodes. | ||
| print(mapdl.nlist()) | ||
|
|
||
|
|
||
| ############################################################################### | ||
| # Check Results | ||
| # ~~~~~~~~~~~~~ | ||
| # Finally we have the results of the distances for both simulations, | ||
| # which can be compared with expected target values: | ||
| # | ||
| # - 1st simulation to get the distance between keypoints :math:`K_3` and :math:`K_4`, where :math:`LEN_1 = 305.16\,(in)` | ||
| # - 2nd simulation to get the distance between nodes :math:`N_1` and :math:`N_2`, where :math:`LEN_2 = 8.58\,(in)` | ||
| # | ||
| # For better representation of the results we can use ``pandas`` dataframe | ||
| # with following settings below: | ||
|
|
||
| # Define the names of the rows. | ||
| row_names = ["N1 - N2 distance (LEN2)", | ||
| "K3 - K4 distance (LEN1)"] | ||
|
|
||
| # Define the names of the columns. | ||
| col_names = ['Target', | ||
| 'Mechanical APDL', | ||
| 'RATIO'] | ||
|
|
||
| # Define the values of the target results. | ||
| target_res = np.asarray([8.5849, 305.16]) | ||
|
|
||
| # Create an array with outputs of the simulations. | ||
| simulation_res = np.asarray([node_dist, kp_dist]) | ||
|
|
||
| # Identifying and filling corresponding columns. | ||
| main_columns = { | ||
| "Target": target_res, | ||
| "Mechanical APDL": simulation_res, | ||
| "Ratio": list(np.divide(simulation_res, target_res)) | ||
RomanIlchenko1308 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| # Create and fill the output dataframe with pandas. | ||
| df2 = pd.DataFrame(main_columns, index=row_names) | ||
|
|
||
| # Apply style settings for the dataframe. | ||
| df2.style.format("{:.2f}") | ||
RomanIlchenko1308 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.