Difference between revisions of "Programming"

From FEAP Wiki
Jump to navigation Jump to search
 
(40 intermediate revisions by 4 users not shown)
Line 1: Line 1:
FEAP is designed to allow users to modify the code for their owm purposes.  If at all possible, users should always use the user hooks provided in the user directory.  These allow users to make custom elements, material models, new FEAP commands, et cetera.  The [http://projects.ce.berkeley.edu/feap/pmanual85.pdf programmers manual] provides an introduction to programming in FEAP.
FEAP is designed to allow users to modify the code for their owm purposes.  If at all possible, users should always use the user hooks provided in the user directory.  These allow users to make custom elements, material models, new FEAP commands, et cetera.  The [http://projects.ce.berkeley.edu/feap/pmanual_86.pdf programmers manual] provides an introduction to programming in FEAP.
 
To use the user hooks, it is recommended to make a copy of the relevant stub file in a separate project directory.  Then add the full path name to this edited copy to main/makefile on the OBJECTS line so that it will be built into FEAP the next time you compile it.  If you are using windows, add the copy to your executable project.  Even though there is a version of the stub file in your FEAP archive file, the compiler should use your edited copy instead of the one in the archive.
 
It is also recommended that you obtain a good Fortran reference book, e.g. Modern Fortran Explained by Metcalf, Reid, and Cohen.


=== Programmers Manual ===
=== Programmers Manual ===
The [http://projects.ce.berkeley.edu/feap/pmanual85.pdf programmers manual] can be found on the FEAP project site [http://projects.ce.berkeley.edu/feap http://projects.ce.berkeley.edu/feap].
The programmers manual can be found on the FEAP project site [http://projects.ce.berkeley.edu/feap http://projects.ce.berkeley.edu/feap].


=== User Elements ===
=== User Elements ===
==== AceGen and Mathematica ====
A template has been developed for generating user elements in an automated manner using AceGen and Mathematica. The Mathematica files, the generated user elements, examples, and benchmark examples can be found on the [https://github.com/bhajay/FEAP-AceGen FEAP-AceGen] GitHub repository. Detailed documentation about the template can be found in the [http://faculty.ce.berkeley.edu/sanjay/ucb_semm_2021_01.pdf SEMM report (UCB/SEMM-20211/01)].
=== User Interface Elements ===
=== User Interface Elements ===
=== User Memory Allocation ===
=== User Memory Allocation ===
Line 10: Line 17:
=== User Body Forces ===
=== User Body Forces ===
=== User Materials ===
=== User Materials ===
The method to implement a user material model in FEAP has been described in Section 4.2 of FEAP Programmer Manual. Here we would like to clarify a few things in the user material model with history variables.
'''The  time-dependent history variables'''
The time-dependent variables are meant to be used for quantities that change in "TIME". That is if you have a solution that advances from time <math>t_n</math> to <math>t_{n+1}</math> the history variables for <math>t_n</math> are stored in <code>hr(nh1)</code>  and those for <math>t_{n+1}</math> are stored in <code>hr(nh2)</code>. These can be state variables in incremental stress-strain relations. In your solution algorithm, you must use the solution commands <code>TIME</code>  and <code>DT</code>. The structure of your user material model should look like this:
1. In your umati*.f routine, set <code>n1</code> equals the number of history variabales ''per Gauss point''.
2. In your umodelf.f or umatl*.f subroutine, read the history variables from the previous globally converged time step <math>t_n</math> from <code>hn(*)</code>
3. Compute new values of history variables
4. Write your newly computed history values to <code>h1(*)</code>  for next time step <math>t_{n+1}</math>. Do not write to <code>hn(*)</code>! 
After that, FEAP will carry out a global Newton iteration.  If the global Newton iteration is not converged, then the values you wrote to <code>h1(*)</code>  will be discarded and your routine will be called again. You will repeat again from step 2 until it is converged. Then, the values in <code>h1(*)</code>  will be copied over into <code>hn(*)</code> for use in the next time step when you execute the next <code>TIME</code> command. 
'''The  time-independent history variables'''
If the history variable does not depend in time then we consider them to be independent of "TIME", so you could use the time-independent history variables as it only stores one copy of each value instead of two in the previous case. This type of history variable is more like a status variable depending on deformation.  Here is the procedure to implement such kind of history variables,
1. In your umati*.f routine, set <code>n3</code> equals the number of history variables ''per element''.
2. In your umodelf.f or umatl*.f subroutine, read the history variables from the previous globally converged time step <math>t_n</math> from <code>hr(nh3+i)</code>  where <code>i</code> runs from 0 to the number of history variables (per gauss point) minus one and <code>nh3</code> points to the location of first history variable for the current Gauss point.
3. Compute new values of history variables.
4. Update history variables in <code>hr(*)</code> with the newly computed values if needed.
'''Initialization of history variables in element or materials routines'''
The history variables are initialized to zero by default. But if you want to initialize any of the history variables to non-zero values you can  do this when <code>ISW .eq. 14</code>. For example, if we have <code>m</code> history variables per gauss point, then you can initialize the time-dependent history variables to <code>1.0d0</code> in your umodelf.f or umatl*.f subroutine as follows,
<pre>
c... INITIALIZE HISTORY VARIABLES
        IF (ISW .EQ. 14) THEN
            do i = 1, m
                hn(i) = 1.0d0
                h1(i) = 1.0d0 
            end do
        END IF
</pre>
For time-independent history variables,
<pre>
c... INITIALIZE HISTORY VARIABLES
        IF (ISW .EQ. 14) THEN
            do i = 0, (m - 1)
                hr(nh3 + i ) = 1.0d0
            end do
        END IF
</pre>
This segment of code will be executed for each Gauss point of each element.
(Note that this page is  under development)
=== User Debugging File Outputs ===
=== User Debugging File Outputs ===
=== User Transient Algorithms ===
=== User Transient Algorithms ===
Line 15: Line 80:
=== Set User Data for Element Plotting ===
=== Set User Data for Element Plotting ===
=== Assembling User Contributions to the Tangent and RHS ===
=== Assembling User Contributions to the Tangent and RHS ===
=== Calling MATLAB functions from FEAP ===
FEAP can be coupled to [[MATLAB]] using the MATLAB Engine.  This permits the two way exchange of data between FEAP and routines written in MATLAB.  A big advantage of this is that one can leverage the vast array of MATLAB utilities (albeit while paying MATLAB's performance penalty).
=== User Functions ===
=== User Functions ===
=== Global User Parameters ===
=== Global User Parameters ===
Line 21: Line 89:
=== User Utility for Sparse Arrays ===
=== User Utility for Sparse Arrays ===
=== User Macro Commands ===
=== User Macro Commands ===
==== User Macro to reset material data ====
If one would like to change material properties in a computation from the command line, this is possible using a [[user macro customized to change material data]].
=== User Mesh Manipulation Commands ===
=== User Mesh Manipulation Commands ===
=== User Mesh Generation Commands ===
=== User Mesh Generation Commands ===
Line 26: Line 97:
=== User Mass Allocation ===
=== User Mass Allocation ===
=== User Problem Inputs ===
=== User Problem Inputs ===
When reading user inputs from the input file it is recommended that one use a [[Polling Input]] programing style.
=== Setting User Additions to the Profile ===
=== Setting User Additions to the Profile ===
=== User Proportional Load ===
=== User Proportional Load ===
Line 31: Line 104:
=== Custom User Banner Messages ===
=== Custom User Banner Messages ===
=== User Solvers ===
=== User Solvers ===
=== Memory ===
FEAP's [[memory]] management system is based on a fixed location in the user memory space and offsets from that location to memory blocks obtained from the operating system via calls to malloc.

Latest revision as of 12:07, 29 June 2023

FEAP is designed to allow users to modify the code for their owm purposes. If at all possible, users should always use the user hooks provided in the user directory. These allow users to make custom elements, material models, new FEAP commands, et cetera. The programmers manual provides an introduction to programming in FEAP.

To use the user hooks, it is recommended to make a copy of the relevant stub file in a separate project directory. Then add the full path name to this edited copy to main/makefile on the OBJECTS line so that it will be built into FEAP the next time you compile it. If you are using windows, add the copy to your executable project. Even though there is a version of the stub file in your FEAP archive file, the compiler should use your edited copy instead of the one in the archive.

It is also recommended that you obtain a good Fortran reference book, e.g. Modern Fortran Explained by Metcalf, Reid, and Cohen.

Programmers Manual

The programmers manual can be found on the FEAP project site http://projects.ce.berkeley.edu/feap.

User Elements

AceGen and Mathematica

A template has been developed for generating user elements in an automated manner using AceGen and Mathematica. The Mathematica files, the generated user elements, examples, and benchmark examples can be found on the FEAP-AceGen GitHub repository. Detailed documentation about the template can be found in the SEMM report (UCB/SEMM-20211/01).

User Interface Elements

User Memory Allocation

User Block Generation

User Body Forces

User Materials

The method to implement a user material model in FEAP has been described in Section 4.2 of FEAP Programmer Manual. Here we would like to clarify a few things in the user material model with history variables.

The time-dependent history variables

The time-dependent variables are meant to be used for quantities that change in "TIME". That is if you have a solution that advances from time to the history variables for are stored in hr(nh1) and those for are stored in hr(nh2). These can be state variables in incremental stress-strain relations. In your solution algorithm, you must use the solution commands TIME and DT. The structure of your user material model should look like this:

1. In your umati*.f routine, set n1 equals the number of history variabales per Gauss point.

2. In your umodelf.f or umatl*.f subroutine, read the history variables from the previous globally converged time step from hn(*)

3. Compute new values of history variables

4. Write your newly computed history values to h1(*) for next time step . Do not write to hn(*)!

After that, FEAP will carry out a global Newton iteration.  If the global Newton iteration is not converged, then the values you wrote to h1(*) will be discarded and your routine will be called again. You will repeat again from step 2 until it is converged. Then, the values in h1(*) will be copied over into hn(*) for use in the next time step when you execute the next TIME command.

The time-independent history variables

If the history variable does not depend in time then we consider them to be independent of "TIME", so you could use the time-independent history variables as it only stores one copy of each value instead of two in the previous case. This type of history variable is more like a status variable depending on deformation. Here is the procedure to implement such kind of history variables,

1. In your umati*.f routine, set n3 equals the number of history variables per element.

2. In your umodelf.f or umatl*.f subroutine, read the history variables from the previous globally converged time step from hr(nh3+i) where i runs from 0 to the number of history variables (per gauss point) minus one and nh3 points to the location of first history variable for the current Gauss point.

3. Compute new values of history variables.

4. Update history variables in hr(*) with the newly computed values if needed.

Initialization of history variables in element or materials routines

The history variables are initialized to zero by default. But if you want to initialize any of the history variables to non-zero values you can do this when ISW .eq. 14. For example, if we have m history variables per gauss point, then you can initialize the time-dependent history variables to 1.0d0 in your umodelf.f or umatl*.f subroutine as follows,

c... INITIALIZE HISTORY VARIABLES
        IF (ISW .EQ. 14) THEN
            do i = 1, m 
                hn(i) = 1.0d0
                h1(i) = 1.0d0  
            end do 
        END IF

For time-independent history variables,

c... INITIALIZE HISTORY VARIABLES
        IF (ISW .EQ. 14) THEN
            do i = 0, (m - 1)
                hr(nh3 + i ) = 1.0d0
            end do 
        END IF

This segment of code will be executed for each Gauss point of each element.

(Note that this page is under development)

User Debugging File Outputs

User Transient Algorithms

User Export of Tangent and Residual for Code Coupling

Set User Data for Element Plotting

Assembling User Contributions to the Tangent and RHS

Calling MATLAB functions from FEAP

FEAP can be coupled to MATLAB using the MATLAB Engine. This permits the two way exchange of data between FEAP and routines written in MATLAB. A big advantage of this is that one can leverage the vast array of MATLAB utilities (albeit while paying MATLAB's performance penalty).

User Functions

Global User Parameters

Set User Boundary Codes

User Displacement Imports

User Utility for Sparse Arrays

User Macro Commands

User Macro to reset material data

If one would like to change material properties in a computation from the command line, this is possible using a user macro customized to change material data.

User Mesh Manipulation Commands

User Mesh Generation Commands

User Plotting Commands

User Mass Allocation

User Problem Inputs

When reading user inputs from the input file it is recommended that one use a Polling Input programing style.

Setting User Additions to the Profile

User Proportional Load

User Rotational Updates

Custom User Banner Messages

User Solvers

Memory

FEAP's memory management system is based on a fixed location in the user memory space and offsets from that location to memory blocks obtained from the operating system via calls to malloc.