Update the mesh in PyAnsys

Samukham
Samukham Member Posts: 25
First Comment Name Dropper

Hello,

I would like to update one mesh with another mesh using a PyMAPDL command. Specifically, I have a .db file that I'll load using the PyMAPDL command mapdl.resume(). After loading it, I save the mesh as a new parameter, let's call it original_mesh. Next, I make some modifications to node locations using the mapdl.n() command. Then, I perform an analysis on the modified mesh. Once the analysis is complete, I need to replace the modified mesh with the original_mesh. One approach to achieve this is by restoring the modified node locations to their original values, But, for that I need to run a mapdl.n() commad in a loop, and it is time consuming as the no. of nodes are very large.

Is there a way to directly replace the modified mesh with the original_mesh without the need for any loops or node-by-node updates?

Example:
from ansys.mapdl.core import launch_mapdl
mapdl = launch_mapdl()
fname='modalat.db'
mapdl.resume(fname)
original_mesh = mapdl.mesh.grid.copy
mapdl.prep7()
mapdl.n(10,1,2,3)
mapdl.n(11,2,0,0)
mapdl.run('/SOLU')
mapdl.solve()
!Here I need to replace mapdl.mesh with original_mesh

Please suggest how to do the same.

Thanks,
Dr. Samukham

Comments

  • James Derrick
    James Derrick Administrator, Employee Posts: 242
    First Anniversary Solution Developer Community of Practice Member Ansys Employee 5 Up Votes
    admin

    @Rohith Patchigolla or @M do you have any ideas?

  • Mike.Thompson
    Mike.Thompson Member, Employee Posts: 240
    First Anniversary First Comment 5 Likes Ansys Employee

    @Samukham, what do you mean by replace the mesh? When you run an analysis the results file is written and the mesh data is included. There is no tool to rewrite that data with different node locations. We can however still use it in conjunction with that alternate node data via DPF and other means. For that I again need more info about what you mean by “replacing” the mesh and more importantly, the meaningful end goal.

  • Rohith Patchigolla
    Rohith Patchigolla Member, Moderator, Employee Posts: 86
    First Answer First Anniversary Name Dropper Solution Developer Community of Practice Member

    @Samukham, could you simply resume the db again to get the previous mesh. db file should still have the old mesh as you have not saved it.

    from ansys.mapdl.core import launch_mapdl
    mapdl = launch_mapdl()
    fname='modalat.db'
    mapdl.resume(fname)
    original_mesh = mapdl.mesh.grid.copy
    mapdl.prep7()
    mapdl.n(10,1,2,3)
    mapdl.n(11,2,0,0)
    mapdl.run('/SOLU')
    mapdl.solve()
    !Here I need to replace mapdl.mesh with original_mesh
    mapdl.resume(fname)
    original_mesh = mapdl.mesh.grid.copy

  • Samukham
    Samukham Member Posts: 25
    First Comment Name Dropper
    edited September 2023

    Hi @Mike.Thompson,
    By replacing mesh I mean, bringing back all the nodes to their original position. To be specific, first I resume a .db file, modify the few node positions, and then solve the modified model. Once the solution procedure is complete I need to bring back all the modified nodes to their original position. I have the original nodal positions in the .db file. I'm looking for a direct command that'll bring back all the modified nodes to their original positions all at once.

    Thanks,

  • German Martinez
    German Martinez Member, Employee Posts: 6
    First Anniversary Name Dropper First Comment Ansys Employee

    @Samukham If you don't mind to lose the results (because you have post processed everything), then just use mapdl.resume.

    If you want to keep the results, you can rename your job first, then do the changes, solve, save, resume to the original database, and repeat.
    Draft of code
    Not tested!

    # create base model
    mapdl.save("base_model.cdb")
    mapdl.jobname = "model_with_changes_1"
    
    # do changes to get model 1
    mapdl.n("...")
    mapdl.d("...")
    # etc...
    # Solve
    mapdl.solution()
    mapdl.solve()
    
    # post processing
    mapdl.post_processing.plot_nodal_displacements("X") 
    # etc
    
    # Resuming to base database
    mapdl.save()
    mapdl.resume("base_model.cdb")
    
    
  • Samukham
    Samukham Member Posts: 25
    First Comment Name Dropper

    Thank you @German Martinez, I'll try the recommended method.