# Implementing new Material

**URL:** <https://forum.compas-framework.org/t/implementing-new-material/164>\
**Category:** compas\_fea\
**Created:** [April 10, 2019, 7:57am UTC](https://forum.compas-framework.org/t/implementing-new-material/164 "2019-04-10T07:57:51Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![rviviane](https://avatars.discourse-cdn.com/v4/letter/r/7ea924/32.png) [@rviviane](https://forum.compas-framework.org/u/rviviane)\
**Post date:** [April 10, 2019, 7:57am UTC](https://forum.compas-framework.org/t/implementing-new-material/164/1 "2019-04-10T07:57:51Z")

</div>

Hi there,

I tried to implement a new material in the compas\_fea library.

I’ve used the following Example for execution:

- beam\_simple.3dm
- beam\_simple\_rhino.py

**Steps of implementation:**

**1. Implementing of SolidwoodC24** in the python file:(It is based on predefined orthotropic Material)  
_compas\compas\_fea\src\compas\_fea\fea\structure\material.py_

class SolidwoodC24(Material):

```
""" Elastic, orthotropic and homogeneous material.
    Parameters According to SIA 265 & SIA 265/1, page 25 (dimensioning Niveau)

Parameters
----------
name : str
    Material name.
Ex = Ey : float
    Young's modulus Ex, Ey in x & y direction [Pa].
    Perpendicular to fiber direction. 
    According to local axis of cross section.
Ez : float
    Young's modulus Ez in z direction [Pa]. 
    Parallel to fiber direction.
    According to local axis of cross section. 
v : float
    Poissons ratio --> unknown!
G : float
    Mean shear modulus [Pa].
p : float
    Density [kg/m3].
tension : bool
    Can take tension.
compression : bool
    Can take compression.
type: C16, C24, C30, D30 
    According to SIA 256 & SIA 265/1
    C24 as default value. --> not implemented yet!!
fu : float
    Ultimate stresses --> not yet defined!!

"""

def __init__ (self, name, Ex=300, Ey=300, Ez=11000, vxy=0.3, vyz=0.3, vzx=0.3, Gxy=500, Gyz=500, Gzx=500, p=380, tension=True, compression=True):
    Material. __init__ (self, name=name)

    Ex *= 10. **6; Ey *= 10.** 6; Ez *= 10. **6; Gxy *= 10.** 6; Gyz *= 10. **6; Gzx *= 10.** 6

    self. __name__ = 'SolidwoodC24'
    self.name = name
    self.E = {'Ex': Ex, 'Ey': Ey, 'Ez': Ez}
    self.v = {'vxy': vxy, 'vyz': vyz, 'vzx': vzx}
    self.G = {'Gxy': Gxy, 'Gyz': Gyz, 'Gzx': Gzx}
    self.p = p
    self.tension = tension
    self.compression = compression
    self.attr_list.extend(['E', 'v', 'G', 'p', 'tension', 'compression'])

```

.  
1.1 This command line works in the PythonRhinoScript:  
_from compas\_fea.structure import SolidwoodC24_  
.  
1.2 If I try to assemble the new material to the structure through the following command line  
(in PythonRhinoScript):  
_mdl.add(SolidwoodC24(name=‘mat\_elastic’))_

–\>Then I get an error message: ![image](https://us1.discourse-cdn.com/flex015/uploads/compas_framework1/original/1X/cc7de13e7becd45258b7a8ff7c035447fea9dd9a.png)

**2. In a second step** , I additional tried to implement the recently created material in the following python file:  
_compas\compas\_fea\src\compas\_fea\fea\materials.py_

2.1 By executing the example again, I got several new error messages:  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/compas_framework1/original/1X/69ea159764ad6bf899105fe10e4e121f6c7c1c65.png)

I’m not able to find the error… do I have to addapt another compas\_fea library file? Or how can I implement my own material in the material library of compas (local on my computer) ?

Thank you for your support,  
Viviane

---

<div class="post-metadata">

**Author:** ![andrewliew](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.compas-framework.org/andrewliew/32/88_2.png) [@andrewliew](https://forum.compas-framework.org/u/andrewliew)\
**Post date:** [April 11, 2019, 7:28am UTC](https://forum.compas-framework.org/t/implementing-new-material/164/3 "2019-04-11T07:28:05Z")

</div>

Hi there, you are on the right track, it seems like your new class is being imported fine, the only thing missing is you have to tell **compas\_fea** what to do with it, and this involves editing a file to tell it what to write when it sees this new model.

When the Python file runs, at some point (for example with tthe `.analyse_and_extract()` method, it will write the `.inp` file, if you open this up now you will find that the `*MATERIAL` part is likely empty, due to what I explained above, therefore the analysis will fail as it doesnt have material information.

The file you need to edit for recognising and writing materials is **compas\_fea.fea.materials**. In here is a method called `write_materials()`, which is where your `SolidwoodC24` material info would get written. Under the **Abaqus** heading (`elif self.software == 'abaqus'`) you will see checks for the material type `mtype`, where `mtype` is grabbed from the object’s ` __name__ `, that is your `SolidwoodC24. __name__ ` which you have already set from your code snippet.

It is then up to you to decide what to write, either you can use some of the `if` statements or code already in that **Abaqus** subsection (this is preferred), or you can (as an easy first step) branch off with your own if statement and write specifically your **SolidwoodC24** model. Once you have paired your model with the file writing, and it is in the correct Abaqus `.inp` format, there shouldn’t be any other further changes needed, and the code should work fine.

Keep me posted.

Andrew

---

<div class="post-metadata">

**Author:** ![rviviane](https://avatars.discourse-cdn.com/v4/letter/r/7ea924/32.png) [@rviviane](https://forum.compas-framework.org/u/rviviane)\
**Post date:** [April 12, 2019, 4:11pm UTC](https://forum.compas-framework.org/t/implementing-new-material/164/4 "2019-04-12T16:11:55Z")

</div>

Hi there, I’ve already edited the file you’ve refered to ( **compas\_fea.fea.materials** )

The concerning code lines are the ones below:  
File: compas\_fea.fea.materials (just a section of the entire file…)

```
        # Abaqus
        # ------------------------------------------------------------------------------------------------------

        elif self.software == 'abaqus':

            self.write_line('*MATERIAL, NAME={0}'.format(key))
            self.blank_line()

            # Elastic
            # -------

            if mtype in ['ElasticIsotropic', 'ElasticPlastic', 'Steel', 'Concrete', 'Stiff',
                         'ConcreteSmearedCrack', 'ConcreteDamagedPlasticity']:

                self.write_line('*ELASTIC')
                self.blank_line()
                self.write_line('{0}, {1}'.format(E['E'], v['v']))

                if not compression:
                    self.write_line('*NO COMPRESSION')

                if not tension:
                    self.write_line('*NO TENSION')

            # Orthotropic (Type: Engineering Constants in Abaqus)
            # -------
            if mtype in ['SolidwoodC24', 'ElasticOrthotropic']

                self.write_line('*ELASTIC, TYPE=ENGINEERING CONSTANTS')
                self.blank_line()
                self.write_line('{0}, {1}'.format(E['Ex','Ey','Ez'], v['vxy','vzx','vyz'], G['Gxy','Gzx'])) #only 8 field variables per line (According to the Abaqus Manual)
                self.blank_line()
                self.write_line('{0}, {1}'.format(G['Gxy']))

                if not compression:
                    self.write_line('*NO COMPRESSION')

                if not tension:
                    self.write_line('*NO TENSION')

            # Compression
            # -----------

```

I have tried to write the code according essential Abaqus Syntax for an orthotropic elastic material ([https://www.sharcnet.ca/Software/Abaqus610/Documentation/docs/v6.10/books/key/default.htm?startat=ch05abk03.html#usb-kws-melastic](https://www.sharcnet.ca/Software/Abaqus610/Documentation/docs/v6.10/books/key/default.htm?startat=ch05abk03.html#usb-kws-melastic)).

But I got a new error message in the RhinoPython Editor command line:

 ![32](https://us1.discourse-cdn.com/flex015/uploads/compas_framework1/original/1X/308c2babfe7631b472a58d4d99623bc7d938d058.png)

And I wonder what the meaning of this message could be… 🤔

Thank you for your support,  
Viviane

---

<div class="post-metadata">

**Author:** ![andrewliew](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.compas-framework.org/andrewliew/32/88_2.png) [@andrewliew](https://forum.compas-framework.org/u/andrewliew)\
**Post date:** [April 15, 2019, 7:35am UTC](https://forum.compas-framework.org/t/implementing-new-material/164/5 "2019-04-15T07:35:25Z")

</div>

This looks like an error in your use of `.format()`, check the Python docs and online on its use, because the following will not work:

```
'{0}, {1}'.format(E['Ex','Ey','Ez'], v['vxy','vzx','vyz'], G['Gxy','Gzx']

```

as `'{0}, {1}'` implies two entries, but you seem to want to use 8 (Abaqus does indeed limite to 8 per line I think), and `E['Ex','Ey','Ez']` looks like you are trying to access three entries in a dictionary at once, remember one key per one item (`E['Ex'], E['Ey'], E['Ez']`).

---

<div class="post-metadata">

**Author:** ![rviviane](https://avatars.discourse-cdn.com/v4/letter/r/7ea924/32.png) [@rviviane](https://forum.compas-framework.org/u/rviviane)\
**Post date:** [April 16, 2019, 8:28am UTC](https://forum.compas-framework.org/t/implementing-new-material/164/6 "2019-04-16T08:28:44Z")

</div>

Thank you for your response.  
I think my material works now, but the analyse has never completed successfully, when I let run the example (simple\_beam).

Below you can see an extract from the created simple\_beam.inp file… (Material Input):  
(looks good to me)

```
            **------------------------------------------------------------------
			** Materials
			**------------------------------------------------------------------
			**
			** solidwoodC24
			**------------
			**
			*MATERIAL, NAME=solidwoodC24
			**
			*ELASTIC, TYPE=ENGINEERING CONSTANTS
			**
			300000000.0,300000000.0,11000000000.0,0.3,0.3,0.3,500000000.0,500000000.0
			**
			500000000.0
			**
			*DENSITY
			**
			380
			**
			**
			**

```

Error Message in the Rhino Python Editor looks as follows:

 ![05](https://us1.discourse-cdn.com/flex015/uploads/compas_framework1/original/1X/9c660ea96618571d2288b4e57dc94d53bffe49b2.png)

And the Abaqus CAE error looks like this:

 ![46](https://us1.discourse-cdn.com/flex015/uploads/compas_framework1/original/1X/da63768aeb7615c772a7f3e4e1a48912b20d7883.png)

I think that there is a problem with the ‘step\_load’… It is a little confusing for me, because If I’m executing the same example with ElasticIsotropic Material (or any of the ones you and your team implemented), everything works fine.

Do you have an idea where the error comes from?

Thank you for your help 😃

---

<div class="post-metadata">

**Author:** ![andrewliew](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.compas-framework.org/andrewliew/32/88_2.png) [@andrewliew](https://forum.compas-framework.org/u/andrewliew)\
**Post date:** [April 19, 2019, 9:05am UTC](https://forum.compas-framework.org/t/implementing-new-material/164/7 "2019-04-19T09:05:41Z")

</div>

Because the Abaqus analysis did not complete, there is nothing for compas\_fea to plot, that is why the `plot_data` function cannot find the frame index.

To see what was wrong in the Abaqus analysis, run the .inp file in Abaqus CAE, turn the job monitor on, and it will tell you what went wrong (you are looking for the warnings, although any error information is also useful). It might be the new material, or might be something else.

Post what it says here and we can see.

---

<div class="post-metadata">

**Author:** ![rviviane](https://avatars.discourse-cdn.com/v4/letter/r/7ea924/32.png) [@rviviane](https://forum.compas-framework.org/u/rviviane)\
**Post date:** [April 25, 2019, 7:00am UTC](https://forum.compas-framework.org/t/implementing-new-material/164/8 "2019-04-25T07:00:23Z")

</div>

Analysis completed! 😃😃😃

Through the job monitor I was able to see, that my poisson ratios have been to hight.  
So I’ve changed the values from 0.3 to 0.1 for all of them and it’s working now.

---

<div class="post-metadata">

**Author:** ![andrewliew](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.compas-framework.org/andrewliew/32/88_2.png) [@andrewliew](https://forum.compas-framework.org/u/andrewliew)\
**Post date:** [April 26, 2019, 2:53pm UTC](https://forum.compas-framework.org/t/implementing-new-material/164/9 "2019-04-26T14:53:04Z")

</div>

Great, nice to hear you got it working.

If you think at a later time that your models are well developed enough for others to use, you can consider a pull request to get them merged into **compas\_fea**. You can find instructions on how to do pull requests on GitHub.

Have fun.
