From 6899f68378b8ed9223c45785eb82dcbb72c8a167 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 19 Aug 2024 16:59:05 +0000 Subject: [PATCH] [bugfix] Add overloaded `Mdb.Model` method to copy existing model (backport #5708) (#5709) [bugfix] Add overloaded `Mdb.Model` method to copy existing model (#5708) (cherry picked from commit c744f24c5eabc0a37e36495a04b14300a030b950) Co-authored-by: Hailin Wang --- src/abaqus/Mdb/Mdb.py | 58 +++++++++++++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 13 deletions(-) diff --git a/src/abaqus/Mdb/Mdb.py b/src/abaqus/Mdb/Mdb.py index 317697b56e..2a5859921c 100644 --- a/src/abaqus/Mdb/Mdb.py +++ b/src/abaqus/Mdb/Mdb.py @@ -1,6 +1,8 @@ from __future__ import annotations -from typing_extensions import Literal +import copy + +from typing_extensions import Literal, overload from abqpy.decorators import abaqus_class_doc, abaqus_method_doc @@ -22,6 +24,7 @@ class Mdb(AcisMdb, JobMdb): mdb """ + @overload @abaqus_method_doc def Model( self, @@ -78,16 +81,45 @@ def Model( model: Model A Model object """ - self.models[name] = model = Model( - name, - description, - stefanBoltzmann, - absoluteZero, - waveFormulation, - modelType, - universalGas, - copyConstraints, - copyConnectors, - copyInteractions, - ) + + @overload + @abaqus_method_doc + def Model(self, name: str, objectToCopy: Model) -> Model: + """This method creates a Model object. + + .. note:: + This function can be accessed by:: + + mdb.Model + + Parameters + ---------- + name + A String specifying the repository key. + objectToCopy + A Model object to copy. + """ + + @abaqus_method_doc + def Model(self, name: str, *args, **kwargs) -> Model: + """This method creates a Model object. + + .. note:: + This function can be accessed by:: + + mdb.Model + + Parameters + ---------- + name + A String specifying the repository key. + args, kwargs + Positional and keyword arguments to be passed to the Model object. + """ + if len(args) == 1 and isinstance(args[0], Model): + self.models[name] = model = copy.deepcopy(args[0]) + elif "objectToCopy" in kwargs and isinstance(kwargs["objectToCopy"], Model): + self.models[name] = model = copy.deepcopy(kwargs["objectToCopy"]) + else: + self.models[name] = model = Model(name, *args, **kwargs) return model