From d6c3f16549b90bc5817d5ddcae82d69a9035a857 Mon Sep 17 00:00:00 2001 From: Pernelle Marone-Hitz Date: Thu, 3 Mar 2022 16:54:30 +0100 Subject: [PATCH 01/19] adding new example from manual --- ...hnology-showcase-dynamic-simulation-PCB.py | 234 ++++++++++++++++++ 1 file changed, 234 insertions(+) create mode 100644 examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py diff --git a/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py b/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py new file mode 100644 index 00000000000..5dd7b4babfb --- /dev/null +++ b/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py @@ -0,0 +1,234 @@ +""" +.. _ref_dynamic_simulation_printed_circuit_board: + +Dynamic simulation of a printed circuit board assembly +-------------------------------------------- + +This examples shows how to use PyMAPDL to import an existing FE model +and to run a modal and PSD analysis. PyDPF modules are also used for +post-processing. +This example is inspired from the model and analysis defined in +Chapter 20 of the Mechanical APDL Technology Showcase Manual. +""" + + +############################################################################### +# Starting MAPDL as a service and importing an external model +# ~~~~~~~~~~~~~ +# The original FE model is given in the Ansys Mechanical APDL Technology Showcase Manual. +# The .cdb contains a FE model of a single circuit board. The model is meshed +# with SOLID186, SHELL181 and BEAM188 elements. All components of the PCB +# model is assigned with linear elastic isotropic materials. Bonded and +# flexible surface-to-surface contact pairs are used to define the contact +# between the IC packages and the circuit board. + +# start MAPDL as a service +import os +from ansys.mapdl.core import launch_mapdl +mapdl = launch_mapdl(run_location=os.getcwd()) +print(mapdl) + +# read model of single circuit board +mapdl.prep7() +mapdl.cdread('COMB', 'Electronics_PCB', 'cdb') +mapdl.allsel() +mapdl.eplot() +mapdl.cmsel('all') + +############################################################################### +# Creating the complete layered model +# ~~~~~~~~~~~~~ +# The original model will be duplicated to create a layered PCB of three layers +# that are binded together + +# duplicate single PCB to get three layers +# get the maximum node number for the single layers PCB in the input file +max_nodenum = mapdl.get('max_nodenum','node',' ','num','max') +# generate additional PCBs offset by 20 mm in the -y direction +mapdl.egen('3',max_nodenum,'all',' ',' ',' ',' ',' ',' ',' ','0','-20','0') + + +# bind the three layers together +# select components of interest +mapdl.cmsel('s','N_JOINT_BOARD') +mapdl.cmsel('a','N_JOINT_LEGS') +mapdl.cmsel('a','N_BASE') +# get number of currently selected nodes +nb_selected_nodes = mapdl.mesh.n_node +current_node = 0 +queries = mapdl.queries +# also select similar nodes for copies of the single PCB +# and couple all dofs at the interface +for node_id in range(1,nb_selected_nodes+1): + current_node = queries.ndnext(current_node) + mapdl.nsel('a','node',' ', current_node + max_nodenum) + mapdl.nsel('a','node',' ', current_node + 2*max_nodenum) +mapdl.cpintf('all') + +# define fixed support boundary condition +# get max coupled set number +cp_max = mapdl.get('cp_max','cp','0','max') +# unselect nodes scoped in CP equations +mapdl.nsel('u','cp',' ','1','cp_max') +# create named selection for base excitation +mapdl.cm('n_base_excite','node') +# fix displacement for base excitation nodes +mapdl.d('all','all') + +# select all and plot model +mapdl.allsel('all') +mapdl.cmsel('all') +mapdl.graphics('power') +mapdl.rgb('index','100','100','100','0') +mapdl.rgb('index','80','80','80','13') +mapdl.rgb('index','60','60','60','14') +mapdl.rgb('index','0','0','0','15') +mapdl.triad('rbot') +mapdl.pnum('type','1') +mapdl.number('1') +mapdl.hbc('1','on') +mapdl.pbc('all',' ','1') +mapdl.view(1,1,1,1) +mapdl.eplot(vtk=False) +mapdl.eplot(vtk=True) + +############################################################################### +# Run a modal analysis +# ~~~~~~~~~~~~~ +# + +# enter solution processor and define analysis settings +mapdl.slashsolu() +mapdl.antype('modal') +# set number of modes to extract +nb_modes = 300 +# use Block Lanzos to extract specified number of modes +mapdl.modopt('lanb',nb_modes) +mapdl.mxpand(nb_modes) +output = mapdl.solve() +print(output) + + +############################################################################### +# Post-processing the modal results +# ~~~~~~~~~~~~~ +# This sections illustrates different methods to post-process the results of the +# modal analysis : PyMAPDL method, PyMAPDL result reader, PyDPF-Post +# and PyDPF-Core. All methods lead to the same result and are just given as an +# example of how each module can be used. + +# using MAPDL methods +mapdl.post1() +mapdl.set(1,1) +mapdl.plnsol('u','sum') + +# using PyMAPDL result reader +mapdl_result = mapdl.result +mapdl_result.plot_nodal_displacement(0) + +# using DPF-Post +from ansys.dpf import post +solution_path = os.path.join(os.getcwd(),'file.rst') +solution = post.load_solution(solution_path) +print(solution) +displacement = solution.displacement(time_scoping=1) +total_deformation = displacement.norm +total_deformation.plot_contour(show_edges=True) + +# using DPF-Core +from ansys.dpf import core +model = core.Model(solution_path) +results = model.results +print(results) +displacements = results.displacement() +total_def = core.operators.math.norm_fc(displacements) +total_def_container = total_def.outputs.fields_container() +mesh = model.metadata.meshed_region +mesh.plot(total_def_container.get_field_by_time_id(1)) + +############################################################################### +# PSD analysis +# ~~~~~~~~~~~~~ +# The response spectrum analysis is defined, solved and post-processed + +#define PSD analysis with input spectrum +mapdl.slashsolu() +mapdl.antype('spectr') +# power spectral density +mapdl.spopt('psd') +# use input table 1 with acceleration spectrum in terms of acceleration due to gravity +mapdl.psdunit(1,'accg',9.81*1000) +# define the frequency points in the input table 1 +mapdl.psdfrq(1,' ',1,40,50,70.71678,100,700,900) +# define the PSD values in the input table 1 +mapdl.psdval(1,.01,.01,0.1,1,10,10,1) +# set the damping ratio as 5% +mapdl.dmprat(0.05) +# apply base excitation on the set of nodes N_BASE_EXCITE in the y-direction from table 1 +mapdl.d('N_BASE_EXCITE','uy',1) +# calculate the participation factor for PSD with base excitation from input table 1 +mapdl.pfact(1,'base') +# write the displacent solution relative to the base excitation to the results file from the PSD analysis +mapdl.psdres('disp','rel') +# write the absolute velocity solution to the results file from the PSD analysis +mapdl.psdres('velo','abs') +# write the absolute acceleration solution to the results file from the PSD analysis +mapdl.psdres('acel','abs') +# combine only those modes whose significance level exceeds 0.0001 +mapdl.psdcom +mapdl.solve() + + +# post-process PSD analysis +# Using MAPDL methods in POST1 +mapdl.post1() +mapdl.set(1,1) +mapdl.plnsol('u','sum') +mapdl.set('last') +mapdl.plnsol('u','sum') + +# Using MAPDL methods in POST26 (time-history post-processing) +mapdl.post26() +# allow storage for 200 variables +mapdl.numvar(200) +mapdl.cmsel('s','MY_MONITOR') +monitored_node =mapdl.queries.ndnext(0) +mapdl.store('psd') +# store the psd analysis u_y data for the node MYMONITOR as the reference no 2 +mapdl.nsol(2,monitored_node,'u','y') +# compute the response power spectral density for displacement associated with variable 2 +mapdl.rpsd(3,2) +mapdl.show('png') +# plot the variable 3 +mapdl.plvar(3) +# print the variable 3 +mapdl.prvar(3) +# x-axis is set for Log X scale +mapdl.gropt('logx',1) +# y-axis is set for Log X scale +mapdl.gropt('logy',1) +# plot the variable 3 +mapdl.plvar(3) +mapdl.show('close') + +# Using python librairies to construct plots +# store MAPDL results to python variables +mapdl.dim('frequencies','array',4000,1) +mapdl.dim('response','array',4000,1) +mapdl.vget('frequencies(1)',1) +mapdl.vget('response(1)',3) +frequencies = mapdl.parameters['frequencies'] +response = mapdl.parameters['response'] + +# use Matplotlib to create graph +import matplotlib.pyplot as plt +fig = plt.figure() +ax = fig.add_subplot(111) +plt.xscale('log') +plt.yscale('log') +ax.plot(frequencies, response) +ax.set_xlabel("Frequencies") +ax.set_ylabel("Response power spectral density") + +# exit MAPDL +mapdl.exit() From 484fe28dd8a4742a7753c1f94f0c85f955aa406f Mon Sep 17 00:00:00 2001 From: Pernelle Marone-Hitz Date: Thu, 3 Mar 2022 17:38:38 +0100 Subject: [PATCH 02/19] Adapting to PEP8 and commenting use of DPF --- ...hnology-showcase-dynamic-simulation-PCB.py | 164 +++++++++--------- 1 file changed, 82 insertions(+), 82 deletions(-) diff --git a/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py b/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py index 5dd7b4babfb..e74b25f6be5 100644 --- a/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py +++ b/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py @@ -5,9 +5,9 @@ -------------------------------------------- This examples shows how to use PyMAPDL to import an existing FE model -and to run a modal and PSD analysis. PyDPF modules are also used for +and to run a modal and PSD analysis. PyDPF modules are also used for post-processing. -This example is inspired from the model and analysis defined in +This example is inspired from the model and analysis defined in Chapter 20 of the Mechanical APDL Technology Showcase Manual. """ @@ -17,10 +17,10 @@ # ~~~~~~~~~~~~~ # The original FE model is given in the Ansys Mechanical APDL Technology Showcase Manual. # The .cdb contains a FE model of a single circuit board. The model is meshed -# with SOLID186, SHELL181 and BEAM188 elements. All components of the PCB -# model is assigned with linear elastic isotropic materials. Bonded and -# flexible surface-to-surface contact pairs are used to define the contact -# between the IC packages and the circuit board. +# with SOLID186, SHELL181 and BEAM188 elements. All components of the PCB +# model is assigned with linear elastic isotropic materials. Bonded and +# flexible surface-to-surface contact pairs are used to define the contact +# between the IC packages and the circuit board. # start MAPDL as a service import os @@ -28,7 +28,7 @@ mapdl = launch_mapdl(run_location=os.getcwd()) print(mapdl) -# read model of single circuit board +# read model of single circuit board mapdl.prep7() mapdl.cdread('COMB', 'Electronics_PCB', 'cdb') mapdl.allsel() @@ -43,59 +43,59 @@ # duplicate single PCB to get three layers # get the maximum node number for the single layers PCB in the input file -max_nodenum = mapdl.get('max_nodenum','node',' ','num','max') +max_nodenum = mapdl.get('max_nodenum', 'node', ' ', 'num', 'max') # generate additional PCBs offset by 20 mm in the -y direction -mapdl.egen('3',max_nodenum,'all',' ',' ',' ',' ',' ',' ',' ','0','-20','0') +mapdl.egen('3', max_nodenum, 'all', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '0', '-20', '0') # bind the three layers together -# select components of interest -mapdl.cmsel('s','N_JOINT_BOARD') -mapdl.cmsel('a','N_JOINT_LEGS') -mapdl.cmsel('a','N_BASE') +# select components of interest +mapdl.cmsel('s', 'N_JOINT_BOARD') +mapdl.cmsel('a', 'N_JOINT_LEGS') +mapdl.cmsel('a', 'N_BASE') # get number of currently selected nodes -nb_selected_nodes = mapdl.mesh.n_node +nb_selected_nodes = mapdl.mesh.n_node current_node = 0 queries = mapdl.queries # also select similar nodes for copies of the single PCB # and couple all dofs at the interface -for node_id in range(1,nb_selected_nodes+1): +for node_id in range(1, nb_selected_nodes+1): current_node = queries.ndnext(current_node) - mapdl.nsel('a','node',' ', current_node + max_nodenum) - mapdl.nsel('a','node',' ', current_node + 2*max_nodenum) -mapdl.cpintf('all') + mapdl.nsel('a', 'node', ' ', current_node + max_nodenum) + mapdl.nsel('a', 'node', ' ', current_node + 2*max_nodenum) +mapdl.cpintf('all') # define fixed support boundary condition # get max coupled set number -cp_max = mapdl.get('cp_max','cp','0','max') -# unselect nodes scoped in CP equations -mapdl.nsel('u','cp',' ','1','cp_max') +cp_max = mapdl.get('cp_max', 'cp', '0', 'max') +# unselect nodes scoped in CP equations +mapdl.nsel('u', 'cp', ' ', '1', 'cp_max') # create named selection for base excitation -mapdl.cm('n_base_excite','node') +mapdl.cm('n_base_excite', 'node') # fix displacement for base excitation nodes -mapdl.d('all','all') +mapdl.d('all', 'all') # select all and plot model mapdl.allsel('all') mapdl.cmsel('all') mapdl.graphics('power') -mapdl.rgb('index','100','100','100','0') -mapdl.rgb('index','80','80','80','13') -mapdl.rgb('index','60','60','60','14') -mapdl.rgb('index','0','0','0','15') +mapdl.rgb('index', '100', '100', '100', '0') +mapdl.rgb('index', '80', '80', '80', '13') +mapdl.rgb('index', '60', '60', '60', '14') +mapdl.rgb('index', '0', '0', '0', '15') mapdl.triad('rbot') -mapdl.pnum('type','1') +mapdl.pnum('type', '1') mapdl.number('1') -mapdl.hbc('1','on') -mapdl.pbc('all',' ','1') -mapdl.view(1,1,1,1) +mapdl.hbc('1', 'on') +mapdl.pbc('all', ' ', '1') +mapdl.view(1, 1, 1, 1) mapdl.eplot(vtk=False) mapdl.eplot(vtk=True) ############################################################################### # Run a modal analysis # ~~~~~~~~~~~~~ -# +# # enter solution processor and define analysis settings mapdl.slashsolu() @@ -103,7 +103,7 @@ # set number of modes to extract nb_modes = 300 # use Block Lanzos to extract specified number of modes -mapdl.modopt('lanb',nb_modes) +mapdl.modopt('lanb', nb_modes) mapdl.mxpand(nb_modes) output = mapdl.solve() print(output) @@ -113,41 +113,41 @@ # Post-processing the modal results # ~~~~~~~~~~~~~ # This sections illustrates different methods to post-process the results of the -# modal analysis : PyMAPDL method, PyMAPDL result reader, PyDPF-Post +# modal analysis : PyMAPDL method, PyMAPDL result reader, PyDPF-Post # and PyDPF-Core. All methods lead to the same result and are just given as an # example of how each module can be used. # using MAPDL methods mapdl.post1() -mapdl.set(1,1) -mapdl.plnsol('u','sum') +mapdl.set(1, 1) +mapdl.plnsol('u', 'sum') # using PyMAPDL result reader mapdl_result = mapdl.result mapdl_result.plot_nodal_displacement(0) # using DPF-Post -from ansys.dpf import post -solution_path = os.path.join(os.getcwd(),'file.rst') -solution = post.load_solution(solution_path) -print(solution) -displacement = solution.displacement(time_scoping=1) -total_deformation = displacement.norm -total_deformation.plot_contour(show_edges=True) +# from ansys.dpf import post +# solution_path = os.path.join(os.getcwd(), 'file.rst') +# solution = post.load_solution(solution_path) +# print(solution) +# displacement = solution.displacement(time_scoping=1) +# total_deformation = displacement.norm +# total_deformation.plot_contour(show_edges=True) # using DPF-Core -from ansys.dpf import core -model = core.Model(solution_path) -results = model.results -print(results) -displacements = results.displacement() -total_def = core.operators.math.norm_fc(displacements) -total_def_container = total_def.outputs.fields_container() -mesh = model.metadata.meshed_region -mesh.plot(total_def_container.get_field_by_time_id(1)) +# from ansys.dpf import core +# model = core.Model(solution_path) +# results = model.results +# print(results) +# displacements = results.displacement() +# total_def = core.operators.math.norm_fc(displacements) +# total_def_container = total_def.outputs.fields_container() +# mesh = model.metadata.meshed_region +# mesh.plot(total_def_container.get_field_by_time_id(1)) ############################################################################### -# PSD analysis +# PSD analysis # ~~~~~~~~~~~~~ # The response spectrum analysis is defined, solved and post-processed @@ -155,68 +155,68 @@ mapdl.slashsolu() mapdl.antype('spectr') # power spectral density -mapdl.spopt('psd') +mapdl.spopt('psd') # use input table 1 with acceleration spectrum in terms of acceleration due to gravity -mapdl.psdunit(1,'accg',9.81*1000) +mapdl.psdunit(1, 'accg', 9.81*1000) # define the frequency points in the input table 1 -mapdl.psdfrq(1,' ',1,40,50,70.71678,100,700,900) +mapdl.psdfrq(1, ' ', 1, 40, 50, 70.71678, 100, 700, 900) # define the PSD values in the input table 1 -mapdl.psdval(1,.01,.01,0.1,1,10,10,1) +mapdl.psdval(1, .01, .01, 0.1, 1, 10, 10, 1) # set the damping ratio as 5% -mapdl.dmprat(0.05) +mapdl.dmprat(0.05) # apply base excitation on the set of nodes N_BASE_EXCITE in the y-direction from table 1 -mapdl.d('N_BASE_EXCITE','uy',1) +mapdl.d('N_BASE_EXCITE', 'uy', 1) # calculate the participation factor for PSD with base excitation from input table 1 -mapdl.pfact(1,'base') +mapdl.pfact(1, 'base') # write the displacent solution relative to the base excitation to the results file from the PSD analysis -mapdl.psdres('disp','rel') +mapdl.psdres('disp', 'rel') # write the absolute velocity solution to the results file from the PSD analysis -mapdl.psdres('velo','abs') +mapdl.psdres('velo', 'abs') # write the absolute acceleration solution to the results file from the PSD analysis -mapdl.psdres('acel','abs') +mapdl.psdres('acel', 'abs') # combine only those modes whose significance level exceeds 0.0001 -mapdl.psdcom +mapdl.psdcom mapdl.solve() # post-process PSD analysis # Using MAPDL methods in POST1 mapdl.post1() -mapdl.set(1,1) -mapdl.plnsol('u','sum') +mapdl.set(1, 1) +mapdl.plnsol('u', 'sum') mapdl.set('last') -mapdl.plnsol('u','sum') +mapdl.plnsol('u', 'sum') # Using MAPDL methods in POST26 (time-history post-processing) mapdl.post26() -# allow storage for 200 variables -mapdl.numvar(200) -mapdl.cmsel('s','MY_MONITOR') -monitored_node =mapdl.queries.ndnext(0) +# allow storage for 200 variables +mapdl.numvar(200) +mapdl.cmsel('s', 'MY_MONITOR') +monitored_node = mapdl.queries.ndnext(0) mapdl.store('psd') # store the psd analysis u_y data for the node MYMONITOR as the reference no 2 -mapdl.nsol(2,monitored_node,'u','y') +mapdl.nsol(2, monitored_node, 'u', 'y') # compute the response power spectral density for displacement associated with variable 2 -mapdl.rpsd(3,2) +mapdl.rpsd(3, 2) mapdl.show('png') # plot the variable 3 -mapdl.plvar(3) +mapdl.plvar(3) # print the variable 3 -mapdl.prvar(3) +mapdl.prvar(3) # x-axis is set for Log X scale -mapdl.gropt('logx',1) +mapdl.gropt('logx', 1) # y-axis is set for Log X scale -mapdl.gropt('logy',1) +mapdl.gropt('logy', 1) # plot the variable 3 -mapdl.plvar(3) +mapdl.plvar(3) mapdl.show('close') # Using python librairies to construct plots # store MAPDL results to python variables -mapdl.dim('frequencies','array',4000,1) -mapdl.dim('response','array',4000,1) -mapdl.vget('frequencies(1)',1) -mapdl.vget('response(1)',3) +mapdl.dim('frequencies', 'array', 4000, 1) +mapdl.dim('response', 'array', 4000, 1) +mapdl.vget('frequencies(1)', 1) +mapdl.vget('response(1)', 3) frequencies = mapdl.parameters['frequencies'] response = mapdl.parameters['response'] From 4045064acc6cec2034d0d21b4f19cf174c21ab5f Mon Sep 17 00:00:00 2001 From: Pernelle Marone-Hitz Date: Thu, 3 Mar 2022 17:41:36 +0100 Subject: [PATCH 03/19] Spell check --- .../20-example-technology-showcase-dynamic-simulation-PCB.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py b/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py index e74b25f6be5..5368ac350c6 100644 --- a/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py +++ b/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py @@ -211,7 +211,7 @@ mapdl.plvar(3) mapdl.show('close') -# Using python librairies to construct plots +# Using python libraries to construct plots # store MAPDL results to python variables mapdl.dim('frequencies', 'array', 4000, 1) mapdl.dim('response', 'array', 4000, 1) From cd78d58fe0e04ef5bd03e1780417b0d856552f82 Mon Sep 17 00:00:00 2001 From: Pernelle Marone-Hitz Date: Thu, 3 Mar 2022 17:55:44 +0100 Subject: [PATCH 04/19] Correcting formatting issues --- ...hnology-showcase-dynamic-simulation-PCB.py | 121 +++++++++--------- 1 file changed, 62 insertions(+), 59 deletions(-) diff --git a/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py b/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py index 5368ac350c6..232230635ad 100644 --- a/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py +++ b/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py @@ -24,16 +24,18 @@ # start MAPDL as a service import os + from ansys.mapdl.core import launch_mapdl + mapdl = launch_mapdl(run_location=os.getcwd()) print(mapdl) # read model of single circuit board mapdl.prep7() -mapdl.cdread('COMB', 'Electronics_PCB', 'cdb') +mapdl.cdread("COMB", "Electronics_PCB", "cdb") mapdl.allsel() mapdl.eplot() -mapdl.cmsel('all') +mapdl.cmsel("all") ############################################################################### # Creating the complete layered model @@ -43,51 +45,51 @@ # duplicate single PCB to get three layers # get the maximum node number for the single layers PCB in the input file -max_nodenum = mapdl.get('max_nodenum', 'node', ' ', 'num', 'max') +max_nodenum = mapdl.get("max_nodenum", "node", " ", "num", "max") # generate additional PCBs offset by 20 mm in the -y direction -mapdl.egen('3', max_nodenum, 'all', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '0', '-20', '0') +mapdl.egen("3", max_nodenum, "all", " ", " ", " ", " ", " ", " ", " ", "0", "-20", "0") # bind the three layers together # select components of interest -mapdl.cmsel('s', 'N_JOINT_BOARD') -mapdl.cmsel('a', 'N_JOINT_LEGS') -mapdl.cmsel('a', 'N_BASE') +mapdl.cmsel("s", "N_JOINT_BOARD") +mapdl.cmsel("a", "N_JOINT_LEGS") +mapdl.cmsel("a", "N_BASE") # get number of currently selected nodes nb_selected_nodes = mapdl.mesh.n_node current_node = 0 queries = mapdl.queries # also select similar nodes for copies of the single PCB # and couple all dofs at the interface -for node_id in range(1, nb_selected_nodes+1): +for node_id in range(1, nb_selected_nodes + 1): current_node = queries.ndnext(current_node) - mapdl.nsel('a', 'node', ' ', current_node + max_nodenum) - mapdl.nsel('a', 'node', ' ', current_node + 2*max_nodenum) -mapdl.cpintf('all') + mapdl.nsel("a", "node", " ", current_node + max_nodenum) + mapdl.nsel("a", "node", " ", current_node + 2 * max_nodenum) +mapdl.cpintf("all") # define fixed support boundary condition # get max coupled set number -cp_max = mapdl.get('cp_max', 'cp', '0', 'max') +cp_max = mapdl.get("cp_max", "cp", "0", "max") # unselect nodes scoped in CP equations -mapdl.nsel('u', 'cp', ' ', '1', 'cp_max') +mapdl.nsel("u", "cp", " ", "1", "cp_max") # create named selection for base excitation -mapdl.cm('n_base_excite', 'node') +mapdl.cm("n_base_excite", "node") # fix displacement for base excitation nodes -mapdl.d('all', 'all') +mapdl.d("all", "all") # select all and plot model -mapdl.allsel('all') -mapdl.cmsel('all') -mapdl.graphics('power') -mapdl.rgb('index', '100', '100', '100', '0') -mapdl.rgb('index', '80', '80', '80', '13') -mapdl.rgb('index', '60', '60', '60', '14') -mapdl.rgb('index', '0', '0', '0', '15') -mapdl.triad('rbot') -mapdl.pnum('type', '1') -mapdl.number('1') -mapdl.hbc('1', 'on') -mapdl.pbc('all', ' ', '1') +mapdl.allsel("all") +mapdl.cmsel("all") +mapdl.graphics("power") +mapdl.rgb("index", "100", "100", "100", "0") +mapdl.rgb("index", "80", "80", "80", "13") +mapdl.rgb("index", "60", "60", "60", "14") +mapdl.rgb("index", "0", "0", "0", "15") +mapdl.triad("rbot") +mapdl.pnum("type", "1") +mapdl.number("1") +mapdl.hbc("1", "on") +mapdl.pbc("all", " ", "1") mapdl.view(1, 1, 1, 1) mapdl.eplot(vtk=False) mapdl.eplot(vtk=True) @@ -99,11 +101,11 @@ # enter solution processor and define analysis settings mapdl.slashsolu() -mapdl.antype('modal') +mapdl.antype("modal") # set number of modes to extract nb_modes = 300 # use Block Lanzos to extract specified number of modes -mapdl.modopt('lanb', nb_modes) +mapdl.modopt("lanb", nb_modes) mapdl.mxpand(nb_modes) output = mapdl.solve() print(output) @@ -120,7 +122,7 @@ # using MAPDL methods mapdl.post1() mapdl.set(1, 1) -mapdl.plnsol('u', 'sum') +mapdl.plnsol("u", "sum") # using PyMAPDL result reader mapdl_result = mapdl.result @@ -151,29 +153,29 @@ # ~~~~~~~~~~~~~ # The response spectrum analysis is defined, solved and post-processed -#define PSD analysis with input spectrum +# define PSD analysis with input spectrum mapdl.slashsolu() -mapdl.antype('spectr') +mapdl.antype("spectr") # power spectral density -mapdl.spopt('psd') +mapdl.spopt("psd") # use input table 1 with acceleration spectrum in terms of acceleration due to gravity -mapdl.psdunit(1, 'accg', 9.81*1000) +mapdl.psdunit(1, "accg", 9.81 * 1000) # define the frequency points in the input table 1 -mapdl.psdfrq(1, ' ', 1, 40, 50, 70.71678, 100, 700, 900) +mapdl.psdfrq(1, " ", 1, 40, 50, 70.71678, 100, 700, 900) # define the PSD values in the input table 1 -mapdl.psdval(1, .01, .01, 0.1, 1, 10, 10, 1) +mapdl.psdval(1, 0.01, 0.01, 0.1, 1, 10, 10, 1) # set the damping ratio as 5% mapdl.dmprat(0.05) # apply base excitation on the set of nodes N_BASE_EXCITE in the y-direction from table 1 -mapdl.d('N_BASE_EXCITE', 'uy', 1) +mapdl.d("N_BASE_EXCITE", "uy", 1) # calculate the participation factor for PSD with base excitation from input table 1 -mapdl.pfact(1, 'base') +mapdl.pfact(1, "base") # write the displacent solution relative to the base excitation to the results file from the PSD analysis -mapdl.psdres('disp', 'rel') +mapdl.psdres("disp", "rel") # write the absolute velocity solution to the results file from the PSD analysis -mapdl.psdres('velo', 'abs') +mapdl.psdres("velo", "abs") # write the absolute acceleration solution to the results file from the PSD analysis -mapdl.psdres('acel', 'abs') +mapdl.psdres("acel", "abs") # combine only those modes whose significance level exceeds 0.0001 mapdl.psdcom mapdl.solve() @@ -183,49 +185,50 @@ # Using MAPDL methods in POST1 mapdl.post1() mapdl.set(1, 1) -mapdl.plnsol('u', 'sum') -mapdl.set('last') -mapdl.plnsol('u', 'sum') +mapdl.plnsol("u", "sum") +mapdl.set("last") +mapdl.plnsol("u", "sum") # Using MAPDL methods in POST26 (time-history post-processing) mapdl.post26() # allow storage for 200 variables mapdl.numvar(200) -mapdl.cmsel('s', 'MY_MONITOR') +mapdl.cmsel("s", "MY_MONITOR") monitored_node = mapdl.queries.ndnext(0) -mapdl.store('psd') +mapdl.store("psd") # store the psd analysis u_y data for the node MYMONITOR as the reference no 2 -mapdl.nsol(2, monitored_node, 'u', 'y') +mapdl.nsol(2, monitored_node, "u", "y") # compute the response power spectral density for displacement associated with variable 2 mapdl.rpsd(3, 2) -mapdl.show('png') +mapdl.show("png") # plot the variable 3 mapdl.plvar(3) # print the variable 3 mapdl.prvar(3) # x-axis is set for Log X scale -mapdl.gropt('logx', 1) +mapdl.gropt("logx", 1) # y-axis is set for Log X scale -mapdl.gropt('logy', 1) +mapdl.gropt("logy", 1) # plot the variable 3 mapdl.plvar(3) -mapdl.show('close') +mapdl.show("close") # Using python libraries to construct plots # store MAPDL results to python variables -mapdl.dim('frequencies', 'array', 4000, 1) -mapdl.dim('response', 'array', 4000, 1) -mapdl.vget('frequencies(1)', 1) -mapdl.vget('response(1)', 3) -frequencies = mapdl.parameters['frequencies'] -response = mapdl.parameters['response'] +mapdl.dim("frequencies", "array", 4000, 1) +mapdl.dim("response", "array", 4000, 1) +mapdl.vget("frequencies(1)", 1) +mapdl.vget("response(1)", 3) +frequencies = mapdl.parameters["frequencies"] +response = mapdl.parameters["response"] # use Matplotlib to create graph import matplotlib.pyplot as plt + fig = plt.figure() ax = fig.add_subplot(111) -plt.xscale('log') -plt.yscale('log') +plt.xscale("log") +plt.yscale("log") ax.plot(frequencies, response) ax.set_xlabel("Frequencies") ax.set_ylabel("Response power spectral density") From c98272280778ed8cc66cf6688b2e5b3161609ee0 Mon Sep 17 00:00:00 2001 From: Pernelle Marone-Hitz Date: Thu, 3 Mar 2022 18:03:27 +0100 Subject: [PATCH 05/19] Minor corrections --- .../20-example-technology-showcase-dynamic-simulation-PCB.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py b/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py index 232230635ad..9517e50fcc8 100644 --- a/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py +++ b/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py @@ -1,5 +1,4 @@ -""" -.. _ref_dynamic_simulation_printed_circuit_board: +""".. _ref_dynamic_simulation_printed_circuit_board: Dynamic simulation of a printed circuit board assembly -------------------------------------------- @@ -177,7 +176,7 @@ # write the absolute acceleration solution to the results file from the PSD analysis mapdl.psdres("acel", "abs") # combine only those modes whose significance level exceeds 0.0001 -mapdl.psdcom +mapdl.psdcom() mapdl.solve() From e48283103a855096d109a6cccbf4c7e55be2e778 Mon Sep 17 00:00:00 2001 From: Pernelle Marone-Hitz Date: Thu, 3 Mar 2022 18:11:52 +0100 Subject: [PATCH 06/19] Adding ReadMe --- examples/07-technology-showcase-examples/README.txt | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 examples/07-technology-showcase-examples/README.txt diff --git a/examples/07-technology-showcase-examples/README.txt b/examples/07-technology-showcase-examples/README.txt new file mode 100644 index 00000000000..38c890494ae --- /dev/null +++ b/examples/07-technology-showcase-examples/README.txt @@ -0,0 +1,7 @@ +Technology Showcase Manual Examples +==================================== +This section demonstrates the broad simulation capabilities +of Ansys Mechanical APDL. The problems demonstrate how +to use PyMAPDL to effectively and accurately +solve interdisciplinary problems +from a variety of industries and engineering fields. From 145060f9eee6bd80c00c06bb055d75cd31c3ed69 Mon Sep 17 00:00:00 2001 From: Pernelle Marone-Hitz Date: Fri, 4 Mar 2022 14:19:19 +0100 Subject: [PATCH 07/19] Changing file reference and Modification of description to indicate use of matplotlib --- ...e-technology-showcase-dynamic-simulation-PCB.py | 11 ++++++++--- examples/README.txt | 3 ++- src/ansys/mapdl/core/examples/downloads.py | 14 ++++++++++++++ 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py b/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py index 9517e50fcc8..fc8d35eed91 100644 --- a/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py +++ b/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py @@ -8,8 +8,12 @@ post-processing. This example is inspired from the model and analysis defined in Chapter 20 of the Mechanical APDL Technology Showcase Manual. -""" +Additional Packages Used +~~~~~~~~~~~~~~~~~~~~~~~~ +* `Matplotlib `_ is used for plotting purposes. + +""" ############################################################################### # Starting MAPDL as a service and importing an external model @@ -24,14 +28,15 @@ # start MAPDL as a service import os -from ansys.mapdl.core import launch_mapdl +from ansys.mapdl.core import examples, launch_mapdl mapdl = launch_mapdl(run_location=os.getcwd()) print(mapdl) # read model of single circuit board +pcb_mesh_file = examples.download_pcb_mesh_file() mapdl.prep7() -mapdl.cdread("COMB", "Electronics_PCB", "cdb") +mapdl.cdread("COMB", "pcb_mesh_file", "cdb") mapdl.allsel() mapdl.eplot() mapdl.cmsel("all") diff --git a/examples/README.txt b/examples/README.txt index 304ac20e155..19b04e10efc 100644 --- a/examples/README.txt +++ b/examples/README.txt @@ -17,4 +17,5 @@ Here are a series of examples using MAPDL with ``ansys-mapdl-core``. 01-apdlmath-examples\README.txt 02-geometry\README.txt 03-tips-n-tricks\README.txt - 05-Tech_demos\README.txt \ No newline at end of file + 05-Tech_demos\README.txt + 07-technology-showcase-examples\README.txt \ No newline at end of file diff --git a/src/ansys/mapdl/core/examples/downloads.py b/src/ansys/mapdl/core/examples/downloads.py index 5da3f86b733..c2dd7f4ba75 100644 --- a/src/ansys/mapdl/core/examples/downloads.py +++ b/src/ansys/mapdl/core/examples/downloads.py @@ -87,3 +87,17 @@ def download_vtk_rotor(): def _download_rotor_tech_demo_plot(): """Download rotor surface vtk file.""" return _download_file("rotor2.vtk", "geometry")[0] + + +def download_pcb_mesh_file(): + """Download a cdb file of a Printed Circuit Board. + + Examples + -------- + >>> from ansys.mapdl.core import examples + >>> filename = examples.download_pcb_mesh_file() + >>> filename + '/home/user/.local/share/ansys_mapdl_core/examples/pcb_mesh_file.cdb' + + """ + return _download_file("pcb_mesh_file.cdb", "mesh")[0] From e8c82fb4546a1fea481d9900078df3ffc4856654 Mon Sep 17 00:00:00 2001 From: Pernelle Marone-Hitz Date: Mon, 7 Mar 2022 14:43:35 +0100 Subject: [PATCH 08/19] Corrected path to download cdb --- src/ansys/mapdl/core/examples/downloads.py | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/ansys/mapdl/core/examples/downloads.py b/src/ansys/mapdl/core/examples/downloads.py index c2dd7f4ba75..5da3f86b733 100644 --- a/src/ansys/mapdl/core/examples/downloads.py +++ b/src/ansys/mapdl/core/examples/downloads.py @@ -87,17 +87,3 @@ def download_vtk_rotor(): def _download_rotor_tech_demo_plot(): """Download rotor surface vtk file.""" return _download_file("rotor2.vtk", "geometry")[0] - - -def download_pcb_mesh_file(): - """Download a cdb file of a Printed Circuit Board. - - Examples - -------- - >>> from ansys.mapdl.core import examples - >>> filename = examples.download_pcb_mesh_file() - >>> filename - '/home/user/.local/share/ansys_mapdl_core/examples/pcb_mesh_file.cdb' - - """ - return _download_file("pcb_mesh_file.cdb", "mesh")[0] From cd607b417f2e3ca43454547819ff28f83b2514e1 Mon Sep 17 00:00:00 2001 From: Pernelle Marone-Hitz Date: Mon, 7 Mar 2022 14:46:06 +0100 Subject: [PATCH 09/19] Correction for importing cdb file From 5b92ad8a0430a0ae99e4d16f9be1fba9f4597210 Mon Sep 17 00:00:00 2001 From: Pernelle Marone-Hitz Date: Mon, 7 Mar 2022 14:49:22 +0100 Subject: [PATCH 10/19] Correction for cdb path From f7009c335376abecedc7c534649f67b6135219c7 Mon Sep 17 00:00:00 2001 From: Pernelle Marone-Hitz Date: Mon, 7 Mar 2022 16:24:48 +0100 Subject: [PATCH 11/19] Correcting path for dowloading pcb --- ...20-example-technology-showcase-dynamic-simulation-PCB.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py b/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py index fc8d35eed91..da86104e05f 100644 --- a/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py +++ b/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py @@ -28,13 +28,15 @@ # start MAPDL as a service import os -from ansys.mapdl.core import examples, launch_mapdl +from ansys.mapdl.core import download_tech_demo_data, launch_mapdl mapdl = launch_mapdl(run_location=os.getcwd()) print(mapdl) # read model of single circuit board -pcb_mesh_file = examples.download_pcb_mesh_file() +# download the cdb file +pcb_mesh_file = download_tech_demo_data("td-20", "pcb_mesh_file") +# enter preprocessor and read in cdb mapdl.prep7() mapdl.cdread("COMB", "pcb_mesh_file", "cdb") mapdl.allsel() From f26ba9251440ca97fe562ef8529cb4cc21ff4a15 Mon Sep 17 00:00:00 2001 From: Pernelle Marone-Hitz Date: Mon, 7 Mar 2022 16:49:41 +0100 Subject: [PATCH 12/19] Correct modules to import --- .../20-example-technology-showcase-dynamic-simulation-PCB.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py b/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py index da86104e05f..e75fa305e5b 100644 --- a/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py +++ b/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py @@ -28,7 +28,8 @@ # start MAPDL as a service import os -from ansys.mapdl.core import download_tech_demo_data, launch_mapdl +from ansys.mapdl.core import launch_mapdl +from ansys.mapdl.core.examples import download_tech_demo_data mapdl = launch_mapdl(run_location=os.getcwd()) print(mapdl) From 094f15edc0928631358b5fb06680a139f3eca9ee Mon Sep 17 00:00:00 2001 From: Pernelle Marone-Hitz Date: Mon, 7 Mar 2022 17:27:30 +0100 Subject: [PATCH 13/19] Correction on upload file --- .../20-example-technology-showcase-dynamic-simulation-PCB.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py b/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py index e75fa305e5b..e6cc2e7453e 100644 --- a/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py +++ b/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py @@ -36,7 +36,7 @@ # read model of single circuit board # download the cdb file -pcb_mesh_file = download_tech_demo_data("td-20", "pcb_mesh_file") +pcb_mesh_file = download_tech_demo_data("td-20", "pcb_mesh_file.cdb") # enter preprocessor and read in cdb mapdl.prep7() mapdl.cdread("COMB", "pcb_mesh_file", "cdb") From 4b96077598b20957cac82fcc25707f4bdc32c3cf Mon Sep 17 00:00:00 2001 From: Pernelle Marone-Hitz Date: Mon, 7 Mar 2022 17:57:22 +0100 Subject: [PATCH 14/19] Modified path --- .../20-example-technology-showcase-dynamic-simulation-PCB.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py b/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py index e6cc2e7453e..552a634406f 100644 --- a/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py +++ b/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py @@ -39,7 +39,7 @@ pcb_mesh_file = download_tech_demo_data("td-20", "pcb_mesh_file.cdb") # enter preprocessor and read in cdb mapdl.prep7() -mapdl.cdread("COMB", "pcb_mesh_file", "cdb") +mapdl.cdread("COMB", "pcb_mesh_file") mapdl.allsel() mapdl.eplot() mapdl.cmsel("all") From 3011e98489ff90f8d9a3809dcc3ea828cf78bc11 Mon Sep 17 00:00:00 2001 From: Pernelle Marone-Hitz Date: Tue, 8 Mar 2022 10:18:13 +0100 Subject: [PATCH 15/19] Editing path to grab cdb file --- .../20-example-technology-showcase-dynamic-simulation-PCB.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py b/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py index 552a634406f..86cb81c40d3 100644 --- a/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py +++ b/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py @@ -39,7 +39,8 @@ pcb_mesh_file = download_tech_demo_data("td-20", "pcb_mesh_file.cdb") # enter preprocessor and read in cdb mapdl.prep7() -mapdl.cdread("COMB", "pcb_mesh_file") +file_path = os.path.join(mapdl.directory, "pcb_mesh_file.cdb") +mapdl.cdread("COMB", file_path) mapdl.allsel() mapdl.eplot() mapdl.cmsel("all") From f53f0605c4af98926f9661c831cd36e826efa5bd Mon Sep 17 00:00:00 2001 From: Pernelle Marone-Hitz Date: Tue, 8 Mar 2022 10:51:04 +0100 Subject: [PATCH 16/19] Correction to file path --- .../20-example-technology-showcase-dynamic-simulation-PCB.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py b/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py index 86cb81c40d3..1394d60488c 100644 --- a/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py +++ b/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py @@ -39,7 +39,7 @@ pcb_mesh_file = download_tech_demo_data("td-20", "pcb_mesh_file.cdb") # enter preprocessor and read in cdb mapdl.prep7() -file_path = os.path.join(mapdl.directory, "pcb_mesh_file.cdb") +file_path = os.path.join(os.getcwd(), "pcb_mesh_file.cdb") mapdl.cdread("COMB", file_path) mapdl.allsel() mapdl.eplot() From aa0df8acad7ab4f8ab788c64ddbfc55985da7ee9 Mon Sep 17 00:00:00 2001 From: Pernelle Marone-Hitz Date: Tue, 8 Mar 2022 11:14:21 +0100 Subject: [PATCH 17/19] Change running directory --- ...example-technology-showcase-dynamic-simulation-PCB.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py b/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py index 1394d60488c..c28af147dc6 100644 --- a/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py +++ b/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py @@ -26,21 +26,20 @@ # between the IC packages and the circuit board. # start MAPDL as a service -import os from ansys.mapdl.core import launch_mapdl from ansys.mapdl.core.examples import download_tech_demo_data -mapdl = launch_mapdl(run_location=os.getcwd()) +mapdl = launch_mapdl() print(mapdl) # read model of single circuit board # download the cdb file pcb_mesh_file = download_tech_demo_data("td-20", "pcb_mesh_file.cdb") + # enter preprocessor and read in cdb mapdl.prep7() -file_path = os.path.join(os.getcwd(), "pcb_mesh_file.cdb") -mapdl.cdread("COMB", file_path) +mapdl.cdread("COMB", pcb_mesh_file) mapdl.allsel() mapdl.eplot() mapdl.cmsel("all") @@ -138,7 +137,7 @@ # using DPF-Post # from ansys.dpf import post -# solution_path = os.path.join(os.getcwd(), 'file.rst') +# solution_path = 'file.rst' # solution = post.load_solution(solution_path) # print(solution) # displacement = solution.displacement(time_scoping=1) From ddd888177dfd23c0d9601d88c4f7abd586254afa Mon Sep 17 00:00:00 2001 From: Pernelle Marone-Hitz Date: Tue, 8 Mar 2022 13:47:10 +0100 Subject: [PATCH 18/19] Using a lower number of modes for CI/CD and using longer title underlines --- ...mple-technology-showcase-dynamic-simulation-PCB.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py b/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py index c28af147dc6..79881a0b59e 100644 --- a/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py +++ b/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py @@ -17,7 +17,7 @@ ############################################################################### # Starting MAPDL as a service and importing an external model -# ~~~~~~~~~~~~~ +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # The original FE model is given in the Ansys Mechanical APDL Technology Showcase Manual. # The .cdb contains a FE model of a single circuit board. The model is meshed # with SOLID186, SHELL181 and BEAM188 elements. All components of the PCB @@ -46,7 +46,7 @@ ############################################################################### # Creating the complete layered model -# ~~~~~~~~~~~~~ +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # The original model will be duplicated to create a layered PCB of three layers # that are binded together @@ -103,14 +103,15 @@ ############################################################################### # Run a modal analysis -# ~~~~~~~~~~~~~ +# ~~~~~~~~~~~~~~~~~~~~~~~ # # enter solution processor and define analysis settings mapdl.slashsolu() mapdl.antype("modal") # set number of modes to extract -nb_modes = 300 +# using a higher number of modes is recommended +nb_modes = 10 # use Block Lanzos to extract specified number of modes mapdl.modopt("lanb", nb_modes) mapdl.mxpand(nb_modes) @@ -120,7 +121,7 @@ ############################################################################### # Post-processing the modal results -# ~~~~~~~~~~~~~ +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # This sections illustrates different methods to post-process the results of the # modal analysis : PyMAPDL method, PyMAPDL result reader, PyDPF-Post # and PyDPF-Core. All methods lead to the same result and are just given as an From 0ec1211f665078810cb706bbeef879bc9e71cd6f Mon Sep 17 00:00:00 2001 From: Alex Kaszynski Date: Wed, 9 Mar 2022 18:22:55 +0100 Subject: [PATCH 19/19] cleanup example --- ...hnology-showcase-dynamic-simulation-PCB.py | 69 ++++++++++++++----- 1 file changed, 51 insertions(+), 18 deletions(-) diff --git a/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py b/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py index 79881a0b59e..8b13be9b4c0 100644 --- a/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py +++ b/examples/07-technology-showcase-examples/20-example-technology-showcase-dynamic-simulation-PCB.py @@ -1,13 +1,13 @@ """.. _ref_dynamic_simulation_printed_circuit_board: Dynamic simulation of a printed circuit board assembly --------------------------------------------- +------------------------------------------------------ -This examples shows how to use PyMAPDL to import an existing FE model -and to run a modal and PSD analysis. PyDPF modules are also used for -post-processing. -This example is inspired from the model and analysis defined in -Chapter 20 of the Mechanical APDL Technology Showcase Manual. +This examples shows how to use PyMAPDL to import an existing FE model and to +run a modal and PSD analysis. PyDPF modules are also used for post-processing. + +This example is inspired from the model and analysis defined in Chapter 20 of +the Mechanical APDL Technology Showcase Manual. Additional Packages Used ~~~~~~~~~~~~~~~~~~~~~~~~ @@ -25,11 +25,13 @@ # flexible surface-to-surface contact pairs are used to define the contact # between the IC packages and the circuit board. -# start MAPDL as a service + +import matplotlib.pyplot as plt from ansys.mapdl.core import launch_mapdl from ansys.mapdl.core.examples import download_tech_demo_data +# start MAPDL as a service mapdl = launch_mapdl() print(mapdl) @@ -41,7 +43,7 @@ mapdl.prep7() mapdl.cdread("COMB", pcb_mesh_file) mapdl.allsel() -mapdl.eplot() +mapdl.eplot(background="w") mapdl.cmsel("all") ############################################################################### @@ -53,8 +55,9 @@ # duplicate single PCB to get three layers # get the maximum node number for the single layers PCB in the input file max_nodenum = mapdl.get("max_nodenum", "node", " ", "num", "max") + # generate additional PCBs offset by 20 mm in the -y direction -mapdl.egen("3", max_nodenum, "all", " ", " ", " ", " ", " ", " ", " ", "0", "-20", "0") +mapdl.egen("3", max_nodenum, "all", dy="-20") # bind the three layers together @@ -62,10 +65,12 @@ mapdl.cmsel("s", "N_JOINT_BOARD") mapdl.cmsel("a", "N_JOINT_LEGS") mapdl.cmsel("a", "N_BASE") + # get number of currently selected nodes nb_selected_nodes = mapdl.mesh.n_node current_node = 0 queries = mapdl.queries + # also select similar nodes for copies of the single PCB # and couple all dofs at the interface for node_id in range(1, nb_selected_nodes + 1): @@ -77,14 +82,17 @@ # define fixed support boundary condition # get max coupled set number cp_max = mapdl.get("cp_max", "cp", "0", "max") + # unselect nodes scoped in CP equations mapdl.nsel("u", "cp", " ", "1", "cp_max") + # create named selection for base excitation mapdl.cm("n_base_excite", "node") + # fix displacement for base excitation nodes mapdl.d("all", "all") -# select all and plot model +# select all and plot the model using MAPDL's plotter and VTK's mapdl.allsel("all") mapdl.cmsel("all") mapdl.graphics("power") @@ -121,7 +129,7 @@ ############################################################################### # Post-processing the modal results -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # This sections illustrates different methods to post-process the results of the # modal analysis : PyMAPDL method, PyMAPDL result reader, PyDPF-Post # and PyDPF-Core. All methods lead to the same result and are just given as an @@ -136,7 +144,9 @@ mapdl_result = mapdl.result mapdl_result.plot_nodal_displacement(0) -# using DPF-Post +############################################################################### +# Using DPF-Post +# ~~~~~~~~~~~~~~ # from ansys.dpf import post # solution_path = 'file.rst' # solution = post.load_solution(solution_path) @@ -164,32 +174,45 @@ # define PSD analysis with input spectrum mapdl.slashsolu() mapdl.antype("spectr") + # power spectral density mapdl.spopt("psd") + # use input table 1 with acceleration spectrum in terms of acceleration due to gravity mapdl.psdunit(1, "accg", 9.81 * 1000) + # define the frequency points in the input table 1 mapdl.psdfrq(1, " ", 1, 40, 50, 70.71678, 100, 700, 900) + # define the PSD values in the input table 1 mapdl.psdval(1, 0.01, 0.01, 0.1, 1, 10, 10, 1) + # set the damping ratio as 5% mapdl.dmprat(0.05) + # apply base excitation on the set of nodes N_BASE_EXCITE in the y-direction from table 1 mapdl.d("N_BASE_EXCITE", "uy", 1) + # calculate the participation factor for PSD with base excitation from input table 1 mapdl.pfact(1, "base") + # write the displacent solution relative to the base excitation to the results file from the PSD analysis mapdl.psdres("disp", "rel") + # write the absolute velocity solution to the results file from the PSD analysis mapdl.psdres("velo", "abs") + # write the absolute acceleration solution to the results file from the PSD analysis mapdl.psdres("acel", "abs") + # combine only those modes whose significance level exceeds 0.0001 mapdl.psdcom() -mapdl.solve() - +output = mapdl.solve() +print(output) -# post-process PSD analysis +############################################################################### +# Post-process PSD analysis +# ~~~~~~~~~~~~~~~~~~~~~~~~~ # Using MAPDL methods in POST1 mapdl.post1() mapdl.set(1, 1) @@ -199,29 +222,39 @@ # Using MAPDL methods in POST26 (time-history post-processing) mapdl.post26() + # allow storage for 200 variables mapdl.numvar(200) mapdl.cmsel("s", "MY_MONITOR") monitored_node = mapdl.queries.ndnext(0) mapdl.store("psd") + # store the psd analysis u_y data for the node MYMONITOR as the reference no 2 mapdl.nsol(2, monitored_node, "u", "y") + # compute the response power spectral density for displacement associated with variable 2 mapdl.rpsd(3, 2) mapdl.show("png") + # plot the variable 3 mapdl.plvar(3) + # print the variable 3 mapdl.prvar(3) + # x-axis is set for Log X scale mapdl.gropt("logx", 1) + # y-axis is set for Log X scale mapdl.gropt("logy", 1) + # plot the variable 3 mapdl.plvar(3) mapdl.show("close") -# Using python libraries to construct plots +############################################################################### +# Plot using python libraries +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~ # store MAPDL results to python variables mapdl.dim("frequencies", "array", 4000, 1) mapdl.dim("response", "array", 4000, 1) @@ -231,7 +264,6 @@ response = mapdl.parameters["response"] # use Matplotlib to create graph -import matplotlib.pyplot as plt fig = plt.figure() ax = fig.add_subplot(111) @@ -241,5 +273,6 @@ ax.set_xlabel("Frequencies") ax.set_ylabel("Response power spectral density") -# exit MAPDL +############################################################################### +# Exit MAPDL mapdl.exit()