Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

How use different classes as one property of a class

S__MPay
Beginner
251 Views

Short version:

We have class element with property of material

We have class steel and class concrete as materials.

I want that the element be able to receive either steel class or concrete class as element%material property.

What approach should I use to make this possible?

____________________________________________________________________________________

Detailed version:

Say we have a Hex element.

Elements can receive one material from various types as property say Concrete or Steel.

All materials have some common properties for example modulus of elasticity.

They also have some common methods but the way that the methods do a calculation is different for each material.

For example:

Concrete%Yield() will do calculations and return a value different from how Steel%Yield() would, but both materials have Yield() method which is accessed from element class.

Now I want my Hex element have a material property.

I created an abstract class material with property of material%Elastic_modulus and a differed method of material%Yield().

I want to create Hex class with abstract class of material as a property so I can use steel%material or concrete%material to assign my material to element. But I receive compiler error 8313:

The TYPE(derived-type-spec) shall not specify an abstract type.

So if this is not allowed how can I have a class element which can receive either concrete or steel class as material property?

____________________________________________________________________________________

I would appreciate your help.

0 Kudos
1 Solution
FortranFan
Honored Contributor II
251 Views

SPMay wrote:

.. I want to create Hex class with abstract class of material as a property so I can use steel%material or concrete%material to assign my material to element. But I receive compiler error 8313: ..

Use CLASS statement instead of TYPE but with a suitable attribute specifier, preferably ALLOCATABLE:

https://software.intel.com/en-us/fortran-compiler-18.0-developer-guide-and-reference-class

View solution in original post

0 Kudos
1 Reply
FortranFan
Honored Contributor II
252 Views

SPMay wrote:

.. I want to create Hex class with abstract class of material as a property so I can use steel%material or concrete%material to assign my material to element. But I receive compiler error 8313: ..

Use CLASS statement instead of TYPE but with a suitable attribute specifier, preferably ALLOCATABLE:

https://software.intel.com/en-us/fortran-compiler-18.0-developer-guide-and-reference-class

0 Kudos
Reply