How to Automate Physics Choices and Studies Using Model Methods

June 28, 2017

You solved a model under certain assumptions. When you analyze the results, you find out that those assumptions do not hold. Now, you have to amend your analysis by incorporating new physics features or changing the study type. What if you could automate such processes? Today, we will discuss how to do so easily using the Model Method feature introduced in version 5.3 of the COMSOL Multiphysics® software.

Benefits of Customized Solution Procedures

We often make modeling decisions based on partial information. Does the flow stay laminar or does it become turbulent? Does a solid stay elastic or does it yield to become plastic under the specified loads and constraints? Are deformations large enough to require a geometrically nonlinear analysis or is small deformation theory good enough? Sometimes, a limit analysis can answer these questions. If we can answer such questions before solving the problem, we can pick the appropriate model. If not, it is economical to solve the simpler model and switch to the more complicated model only if the solution is not valid.

For example, we can do elastic analysis first and switch to elastoplastic analysis only if the maximum stress obtained by the first analysis is above the elastic limit. Similarly, we can solve assuming laminar flow and include turbulence in our model only if the Reynolds number obtained from the first analysis is high enough.

In these and other situations, where we may have to change our modeling approach based on preliminary results, it would save our efforts to automate the workflow. Information obtained from the first study can also be reused to make subsequent studies computationally efficient. Today, we will demonstrate how to do so by writing code to automate an elastoplastic analysis. The code runs an elastic analysis, checks if the maximum stress exceeds the yield stress of the material, and runs the model with plasticity if necessary.

Creating a Method in COMSOL Multiphysics®

Using the COMSOL Multiphysics® software on the Windows® operating system platform, you can build an app with a customized user interface and include methods for additional functionality. Apps built using the Application Builder in Windows® can then be run on any operating system. You can share the apps with colleagues, customers, students, and more.

In version 5.3 of the COMSOL® software, we introduced a new feature, called a method, that lets you extend the functionality of the software by writing code inside the COMSOL Multiphysics graphical user interface (GUI), even when you do not intend to make apps. The Record Code, Editor Tools, Language Elements, and Model Expression features of the Application Builder can be used to easily generate the Java® code needed to write a method.

A screenshot of the COMSOL Multiphysics GUI with the Model Method button highlighted.
To add a method, go to the Developer tab and click Model Method.

A screenshot of the COMSOL Multiphysics GUI showing how to run a method.
To run a method, go to the Developer tab, click Run Model Method, and choose a method.

In previous blog posts, we discussed how methods work and demonstrated how to use them to create randomized geometry. Today, we will extend that conversation to physics and study settings.

Automating an Elastoplastic Analysis with Model Methods

To demonstrate how to use methods in physics selection and study sequences, we will use a model based on an elastoplastic analysis of a holed plate from our Application Gallery. The Application Gallery example was set up with prior knowledge that the stress will exceed the elastic limit. As such, plasticity was added in the analysis. Today, we will have a method find that out and, if plasticity is necessary, incorporate that automatically.

The procedure we want to automate here contains the following steps:

  1. Run an elastic study without plasticity.
  2. Check if the maximum stress exceeds the initial yield stress of the material.
  3. If the maximum stress is less than the initial yield stress, stop. Otherwise, run the elastoplastic study.
  4. If plasticity is necessary, reuse information from the elastic study to avoid unnecessary nonlinear analysis in the elastic range.

We add two studies and disable plasticity in the first study. In the second study, we add an Auxiliary Sweep for load ramping in the elastoplastic analysis. In the first study, the full load is applied by setting para to 1 in Global Definitions. In the second study, we use the parameters p_low and p_next to make the study efficient. These parameters are going to be set based on the results of the first study.

A screenshot showing the settings for a stationary elastic study in COMSOL Multiphysics.

A screenshot showing the settings for a stationary elastoplastic study in COMSOL Multiphysics.
The second study will be computed only if the assumptions in the first study turn out to be incorrect.

In the Results section, we add a Derived Values node to evaluate the maximum stress from the first study. This could alternatively be done using the Maximum Component Coupling operator. This value, obtained in pascals (as shown in the Settings window for Surface Maximum 1) will be compared to the initial yield stress in pascals. To this end, we introduce the parameter SY_scaled.

A screenshot highlighting the Parameters settings in the COMSOL Multiphysics software.
SYield and SY_scaled are for the Materials node and the method, respectively.

A screenshot showing the Settings window for Surface Maximum in COMSOL Multiphysics.
A Maximum Component Coupling operator is another alternative for this operation.

Now that we have all of the ingredients we need, let’s write the method.

A screenshot of the Application Builder zoomed in on a method.
A method that is used to automate an efficient elastoplastic analysis.

Two of the above lines warrant some discussion:

  • Line 12:
    • The first study is done using a load parameter of 1. If StressRatio in line 9 is greater than 1, its reciprocal will tell us the load parameter at the elastic limit. Note that we could do so here, as plasticity is the only possible nonlinearity in our problem. The model has no geometric nonlinearity or contact.
  • Line 14:
    • If plasticity is needed, we want to do the auxiliary sweep in steps of 0.05. We use the ceil (ceiling) method from the Java® Math class to obtain the lowest value of the load parameter that is a multiple of 0.05 and is after the elastic limit.

With this information, the second study (if necessary) is solved only once in the elastic region: at the elastic limit. We can see what values of the load parameter are used in the Results section.

A screenshot of the 2D Plot Group settings with the parameter value options shown.
The lowest value of the load parameter, highlighted, is estimated using the elastic study.

If you go back to Global Definitions, you will see that the method has updated the parameters p_low and p_next from their original values of zero, shown earlier.

A screenshot of the COMSOL Multiphysics GUI showing a set of parameter values.
Parameter values changed by a method based on results from a preliminary study.

Closing Remarks

Today, we have demonstrated setting up efficient physics choices and study sequences using methods. Similar tasks can be accomplished by scripting. However, methods make it easy to grab the model objects and methods needed by using the same functionality employed in the Application Builder. When needed, these methods can be augmented by regular Java® classes, such as the Math class we used in the first example, or your own classes.

We have only shown one way of performing tasks to illustrate the use of methods in physics and solver settings, but there are alternatives and refinements. For example, in the elastoplasticity analysis, we added two studies in the Model Builder. Alternatively, you can use a single study where the plasticity and auxiliary sweep features can be enabled or disabled from a method.

In the examples above, there are logical decisions that have to be made between studies. When there are no such decisions and you just want to refer to one study from another (say, to use one study as a precomputing step for a subsequent study), you can use the Study Reference feature. See the section Study Reference in the COMSOL Multiphysics Reference Manual for details.

If you have any questions related to today’s discussion or using COMSOL Multiphysics, contact us via the button below.

Related Resources

Microsoft and Windows are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries. Oracle and Java are registered trademarks of Oracle and/or its affiliates.


Comments (0)

Leave a Comment
Log In | Registration
Loading...
EXPLORE COMSOL BLOG