HCBBS Forum (English)
Submit Chemical Projects / Find Solutions
Amplify Your Requirements on a Broader Chemical Platform *Engineering · Technology · Equipment · Solutions*
Submit Request

How can Aspen interface with multiple Fortran subroutines simultaneously

2023-12-08View Original

Thread Content

Tutorials on using Aspen’s external Fortran subroutines can be found on the forum, but these tutorials all deal with connecting to just one Fortran program. Now I need to connect 3 different Fortran files to Aspen (to correct the mass transfer coefficients and interfacial area of Radfrac), but following the usual steps of \"Home Settings – Miscellaneous Files – Linker Options – Select opt file\", it seems that only one file can be selected. If another file is selected after choosing this file, the address of the previous file will be deleted, and an error indicating that a subroutine is missing will be displayed during execution. Do any of you have any methods or experiences? Can different Fortran programs have their addresses written in one opt file, and then only this opt file be selected during linking? Please advise
Reply #22023-12-08
Calling multiple Fortran subroutines from Aspen does indeed require some skill. Generally, if you want to link multiple Fortran subroutines, you need to compile all the Fortran source code into a single object file or library file, and then link this file in Aspen. Here are the steps that can be tried: 1. Compile the Fortran source code: Compile all of your Fortran subroutine source code files into object files. This usually requires using a Fortran compiler, such as gfortran or ifort. For example, if you have three Fortran source files: `sub1.f90`, `sub2.f90`, `sub3.f90`, you can use the following compilation commands to generate object files: gfortran -c sub1.f90 gfortran -c sub2.f90 gfortran -c sub3.f90. This will create three object files: `sub1.o`, `sub2.o`, `sub3.o`. 2. Create a static library file: Archive all object files into a single library file, such as `mylib.a`. You can use the `ar` command to do this. ar rcs mylib.a sub1.o sub2.o sub3.o This command creates a library file named `mylib.a`, which contains three object files. 3. Linking static libraries using linker options in Aspen: In Aspen, when you select your linker options in “Home Settings – Miscellaneous Files – Linker Options”, you only need to choose this generated static library file `mylib.a`. If Aspen requests a linker option file (a `.opt` file), you may need to specify the path and name of the library files in this file. For example, the content of your `.opt` file might look like this: mylib.a. Or if the library file is not in a path that Aspen can find directly, you need to specify the full path: /path/to/mylib.a. 4. Run the Aspen model: Once it has been linked correctly, you can run your Aspen model as usual. At this point, Aspen should be able to find and use your Fortran subroutine. If you are not familiar with how to compile and link Fortran programs, or if you encounter specific compilation or linking issues, you may need further guidance, such as by contacting your Fortran compiler provider or seeking help in relevant software development communities. Remember that during compilation and linking, it is necessary to ensure that the calling interface of the Fortran subroutine is compatible with the interface that allows Aspen to function properly. .

Submit a Project

**Looking for Chemical Technology, Equipment & Solutions?** No Registration Required Broader Platform Exposure | Global Chemical Service Provider Connections

Submit Request — Free Consultation

Disclaimer

This is an automated machine translation of the original thread. Some technical terms may have inaccuracies; the original text shall prevail. Click "View Original" at the top right to access the source page, which supports IP-based automatic real-time language translation. Please watch out for contact details and sales inducements to prevent fraud. All content and translations are for reference only, representing solely the poster's personal views. For enquiries, email service@hcbbs.com.