Welcome to the TRNSYS Users Forum.

The forum is a place where people can interact and have discussions about different topics involving the use of the TRNSYS software package. Here you can post topics for discussion or questions on using TRNSYS and get advice from other users or TRNSYS experts. This forum is not intended for detailed technical support. Users should contact their distributor’s hotline for such assistance.

Some tips for success on using the forum:

  • Follow the Forum Rules posted in Forum Administration.
  • There are categories for different types of topics and questions. Post your topic or question into the proper category.
  • Before posting a topic or question search the existing topics  (and the TRNSYS Users listserv archive) to see if a similar topic or question has already been answered.
  • Use a descriptive topic name. Don’t use attention getting subjects, they don’t get attention and only annoy people.
  • State the version of TRNSYS and which add-ons your are using.
  • Include enough specific details for your topic of question to be answered. Just posting “Why am I getting an error?” without describing the specific error and what you are trying to do when you get the error will not receive a response that fixes your issue.
  • Remember when people help you, they are doing you a favor. Be patient, help people out by posting good descriptions of what you need help with, and be polite even if a response does not solve your issue.
  • Moderators may edit your post for clarity or move your topic to a more appropriate category.

Notifications
Clear all

[Solved] Is it possible to get an input of a TRNSYS type as an output for other calculations or display?

4 Posts
2 Users
0 Likes
421 Views
0
Topic starter

Good morning. Please, is it possible to get an input of a TRNSYS type as an output for other calculations or display?

1/ Is it possible to "collect" as an output the value of an input? For instance, the collector surface area that I enter in Type 1b should also be the collector area value that I would like to communicate as input to a component that I have created. To avoid writing it twice, I would like to link them. Actually, I have a lot of inputs...

2/ Is it possible to add an output to an existing type? For instance, has 3 outputs and I would like to add an outpout like "Incidence angle modifier - overall", which is probably an intermediate result in the calculation of the efficiency.

Thank you.

Topic Tags
1 Answer
0

@ken

1) It sounds like you want to create a variable in an equation block, which you can then use in multiple places in your project.

  • In Simulation Studio, go to Assembly -> Insert new equation. 
  • Open the equation block. On the 'Intermediates & Outputs' side, click the white paper icon ('Add a new output variable'), rename the new variable as you wish (say CollectorArea), and specify its value in the box to the right of the '=' sign. You can use ! to leave a comment after the value for your reference, such as the units or other description. Close the equation block window. 
  • Open the proforma for one of the Types in your simulation, and go to the parameter or input you want to specify. Click on the 'Unit' dropdown menu, and at the very bottom of the list, select 'variable name' for the units. Then type the name you specified in the equation block as the Value for that parameter/input. Repeat in as many places as you wish to use that variable. 

2) Adding an output can be done, but it does require some programming. It is a two-step process that involves editing both the proforma and the source code of the Type. 

Editing the proforma is pretty easy. Right-click on the proforma you want to edit, select 'Proforma', click on the 'Variables' tab, click on the 'Variables (Parameters, Inputs, Outputs, Derivatives)' button, click on the 'Outputs' tab, and click the 'Add' button on the right-hand side to add a new output variable. Specify its name, dimensions, and units. Make this a new Type by changing the Type number on the 'General' tab, say 9999 (any positive integer of five digits or less that isn't already used by a TRNSYS Type is okay). Save the changes to the proforma as 'Type9999' and close the proforma window. Then, to update the version of the proforma that's currently in your project, right-click on the proforma again, select 'Replace', navigate to the folder where you saved the Type9999 proforma (Trnsys18/Studio/Proforma/<directory structure is the same as the Direct Access Tree in the Studio>), and select the new proforma. If you stop here and try to run your simulation, you'll get an error that Type 9999 couldn't be found; you need to revise and recompile the source code next.

To revise the source code, open TypeStudio, go to Workspace -> Open Source File, and open the source code for the Type you wish to edit. The source code for all Types in the standard library can be found in the Trnsys18/Source Code/Types folder. Make the necessary revisions to change the Type number in the source code to 9999 (or whatever you chose) and add the output you want. There are notes in the Trnsys18/Documentation/Programmer's Guide.pdf that can help you if you're new to coding TRNSYS Types. When you're satisfied with the changes, go to Workspace -> Rename File, and name the file Type9999. Then, go to Build -> Compile Workspace to compile Type9999 as a new Type. You should now be able to run your project with Type 9999 and see the extended outputs. 

Note: if you follow the steps above for an existing Type in the standard library, and you do not change the Type number, you'll only create a duplicate Type, not replace the existing Type. TRNSYS will issue a warning that it found a duplicate for that Type number, but it will default to using the version compiled in TRNdll.dll, which won't have any of your changes and won't be compatible with the revised proforma. 

Ken Topic starter 19/05/2023 9:04 am

@a_weiss
Dear A_Weiss, thank you very much for your kind answers. I could only give feedback now because I wanted to succeed before coming back. In short:
1/ Your guess is perfect and I implemented your solution with the equation block: it works perfectly. Thank you.
2/ I was not successful why trying to add an output to an existing type. Indeed, when I come to the compilation stage in type studio, I obtain the following error "for Type 1b":
C:/TRNSYS18/sourceCode/Types/Type9999.f90:793: undefined reference to 'fprime_function_'
C:/TRNSYS18/sourceCode/Types/Type9999.f90:810: undefined reference to 'fprime_function_'
C:/TRNSYS18/sourceCode/Types/Type9999.f90:850: undefined reference to 'fprime_function_'
C:/TRNSYS18/sourceCode/Types/Type9999.f90:944: undefined reference to 'fprime_function_'
... more undefined reference to 'fprime_function_' follow.

I was trying to add an additional output to Type1b. As I obtained errors, I just try to do the same steps but without modifying anything in the Fortran code of Type1, except changing "Type1" to "Type9999". Even with that, I receive the same error.
Would you have some ideas?
Thank you.

A_Weiss A_Weiss 22/05/2023 4:59 pm

Fprime_function is the function Type 1 calls to calculate the collector efficiency factor from the given efficiency equation coefficients. The function itself lives in the SolarCalcs.lib library file, which doesn't make its source code accessible to users. There's an interface defined for Fprime_function in TRNSYSFunctions.f90, so I would've thought you could access Fprime_function from any Type that includes 'use TRNSYSFunctions', but, maybe not.

My guess is the source code has to be compiled with SolarCalcs.lib in the same .dll in order to work ... unfortunately I don't think it's possible within TypeStudio to compile multiple files that aren't all Fortran files, but I can ask around to confirm that.

The other option would be to use something like Microsoft Visual Studio with the Intel Fortran compiler to edit and compile Types. There's an introduction to compiling TRNSYS Types in Visual Studio in this video: https://www.youtube.com/watch?v=fZ5-zSC094Q. (The focus of the video is on debugging, but about 1 minute in there's a good demonstration of how to compile a user-written Type as part of the main TRNDll64.dll package, which is what you'll want to do). Instructions for downloading and installing Visual Studio and the Intel Fortran compiler are listed in the first comment on that video. If you take your same Type9999, add it to the TRNDll64.dll package, and compile it as part of the TRNDll64.dll package, it should already include the SolarCalcs.lib file and should recognize Fprime_function.

Ken Topic starter 23/05/2023 1:10 pm

@a_weiss
Dear A_Weiss, thank you very much for your explanations that make much sense and show me that Type 1 is not just a simple quadratic equation! Thank you for your suggestion.

Share: