You are on page 1of 13

Chapter 70: User-defined Subroutines for Heat Transfer Coefficient

User-defined Subroutines for


70 Heat Transfer Coefficient


Summary 1270

Introduction 1271

Modeling Details 1271

Results 1280

Modeling Tips 1280

Input File(s) 1281
1270 MD Demonstration Problems
CHAPTER 70

Summary
Title Chapter 70: User-defined Subroutines
Features: User-defined Subroutines (Fortran, C, and Sinda SSK file)
Geometry & Boundary Convection to ambient temperature Tamb = 300 K
Conditions

Heat Flux 1000 W/m2

Dimension: 1m x 10m Unit Thickness Material: Iron

Convection coefficient H = (T1 + 100)/RL computed in user subroutine


Where: T1 is the wall temperature on each node
RL is the average distance to the leading edge to node

Material properties 1000 Conductivity (W/m/K)

800 Specific Heat = 477.3 W/Kg/K


Density = 7870 Kg/m3
600

400

200
Temperature (K)

0
0 500 1000 1500 2000

Analysis characteristics Solution 400 / RC Network solver. Steady state analysis. User-defined Subroutines
(UDS) and SCA service.
Element type 4-node shell element CQUAD4
FE results Temperature result (User defined Fortran Subroutine)

Temperature result (User defined C Subroutine)

Temperature result (MSC Sinda Skeleton SSK file)


CHAPTER 70 1271
User-defined Subroutines for Heat Transfer Coefficient

Introduction
This example shows the basic steps to add user defined subroutines to MD Nastran solution 400/RC Network Solver.
The same model and convection correlation are used with P/Thermal's workshop 15, so that users can easily compare
the Fortran or C logics and temperature results. A Fortran or C user defined subroutine is used to calculated the
convection coefficients. We also show the MSC Sinda's SSK file to add the same Fortran logic to the sin file.
Convection coefficients are computed by the following formula
H = (T1 + 100)/RL
where

H Convection coefficient for each node.


T1 Temperature values on each node.
RL The average distance from the leading edge to node

In this problem, we are going to use a text file from P/Thermal to calculate the RL values. RL = (GP2+GP3)/2. Where:
GP2 and GP3 are the distance from each node control area's leading and trailing edges. GP2 and GP3 are added 1.0
according to the requirements of the specific convection correlation.
GP1 is the control area of the nodes. They can be found in the text file from P/Thermal. Users can create this text file
by themselves with any format they like. It contains the nodal control area GP1, and the two distances GP2 and GP3
of this control area.
We also need the conductor numbers in the sin file. You can get these conductor ids by running the model with a
constant dummy convection coefficient.

Modeling Details
A 1m x 10m unit thickness iron slab is meshed 5 x 50. The ambient temperature is set to be 300K, and a heat flux 1000
W/m² is applied to the bottom edge of the surface. A convection to ambient load is applied to the top edge of the plate.
A constant dummy convection coefficient is used for an initial run. We will need an initial run for the convection
conductor ids. Later, we will use a Fortran or C user defined subroutine to calculate the real h values, and replace the
convection conductors in the sin file.

Convection to ambient temperature Tamb = 300 K

Heat Flux 1000 W/m2


Figure 70-1 Boundary Conditions
1272 MD Demonstration Problems
CHAPTER 70

Solution Highlights
MD Nastran Solution 400/RC Network Solver supports user defined subroutines to modify any parameters in the
solver input (.sin) file. EntUDS is used to merge user's own subroutines into the 4 entry points of the solution sequence.
1. RCEnt1 ---- Beginning of nonlinear loop before temperature update
2. RCEnt2 ---- End of nonlinear loop after temperature update
3. RCOut1 ---- Beginning of output routine
4. RCExec1 - Beginning of Execution block
In this model, we will use RCEnet1 and RCExec1 entry points. We need to add three lines of command in the bdf file.
At the beginning of the bdf file:
CONNECT SERVICE MYGN1 'SCA.MDSolver.Obj.Uds.DefEnt'
At the end of the bdf file:
ENTUDS 1 RCENT1 MYGN1
ENTUDS 2 RCEXEC1 MYGN1
The following is the example Fortran code in the UDS.f file in the server's folder.
In the MODULE RCDATA block,

MODULE RCDATA

C GP Array, Conductor ID array, and Node ID array definition


DOUBLE PRECISION, DIMENSION(51,3)::GP
INTEGER(8), DIMENSION(51)::IDS_G,NODEIDS
In the Subroutine Variables1 block,

SUBROUTINE VARIABLES1( iarray, ia_cnt, farray, fa_cnt )


USE RCDATA
IMPLICIT NONE
INTEGER(KIND=4), DIMENSION(*):: iarray(*)
REAL(KIND=4), DIMENSION(*):: farray(*)
INTEGER ia_cnt, fa_cnt

DOUBLE PRECISION::RL,AREA
REAL(8)::Hconv
INTEGER(8)::IRESIS

CALL ARRAYS64( tptr,cptr,qptr,gptr,aptr,kptr,xptr )

DO 400 IRESIS=1,51
RL = (GP(IRESIS,2)+GP(IRESIS,3))/2.0
AREA = GP(IRESIS,1)
Hconv = (T(NR(NODEIDS(IRESIS)))+100)/RL
G(NGR(IDS_G(IRESIS))) = Hconv*AREA
END DO

END SUBROUTINE
CHAPTER 70 1273
User-defined Subroutines for Heat Transfer Coefficient

In the Subroutine Execution block,

SUBROUTINE EXECUTION( iarray, ia_cnt, farray, fa_cnt )


USE RCDATA
IMPLICIT NONE
INTEGER(KIND=4), DIMENSION(*):: iarray(*)
REAL(KIND=4), DIMENSION(*):: farray(*)
INTEGER ia_cnt, fa_cnt

INTEGER(8)::IRESIS

C Get NODEIDS and GP(51,3) data by reading "convec.dat"

OPEN(11,FILE = 'convec.dat')

DO 100 IRESIS=1,9
READ(11,*)
100 END DO

DO 200 IRESIS=1,51

IF(IRESIS==1 ) THEN
READ(11,800) NODEIDS(IRESIS)
READ(11,1000) GP(IRESIS,1),GP(IRESIS,3),GP(IRESIS,3)
GP(IRESIS,2)=1.0
READ(11,*)
READ(11,*)
ELSE IF(IRESIS==51) THEN
READ(11,800) NODEIDS(IRESIS)
READ(11,1000) GP(IRESIS,1),GP(IRESIS,2),GP(IRESIS,2)
GP(IRESIS,3)=11.0
READ(11,*)
READ(11,*)
ELSE
READ(11,800) NODEIDS(IRESIS)
READ(11,1000) GP(IRESIS,1),GP(IRESIS,2),GP(IRESIS,2)
READ(11,*)
READ(11,*)

READ(11,*)
READ(11,1000) GP(IRESIS+1,1),GP(IRESIS,3),GP(IRESIS,3)
READ(11,*)
READ(11,*)

GP(IRESIS,1) = GP(IRESIS,1) + GP(IRESIS+1,1)


END IF

200 END DO
CLOSE(11)
800 FORMAT(7x,I3)
1000 FORMAT(3(E20.11))

C Get IDS_G(51) data by reading conductors.txt

OPEN(11,FILE = 'conductors.txt')
READ(11,*)
DO 300 IRESIS=1,51
READ(11,1010) IDS_G(IRESIS)
300 END DO
CLOSE(11)
1010 FORMAT(12x,I4)

END SUBROUTINE
1274 MD Demonstration Problems
CHAPTER 70

The following is the example C code in the DefEnt.cpp file in the server's folder.
In the beginning of the DefEnt.cpp

#include "DefEnt.h"
#include "RCDefEnt.h"
#include <fstream>
#include <iostream>

namespace SCA { namespace MDSolver { namespace Obj { namespace Uds { namespace Entry
{

using namespace std;

const int cnt = 51;


int nodes[cnt];
double gp[cnt][3];
int ids_g[cnt];
CHAPTER 70 1275
User-defined Subroutines for Heat Transfer Coefficient

In the RCEXec1 function

SCAResult DefEnt::RCExec1(const SCAInt32Sequence& IData, const SCAReal32Sequence& R


const SCAStringSequence& CData)
{
int i;
char bin[256];

// get convection values


ifstream conv( "convec.dat" );
char blank;
for( i=0; i<9; i++ )
conv.getline( bin, 256 );

// first one
conv >> blank >> nodes[0]; conv.getline( bin, 256 );
conv >> gp[0][0] >> gp[0][2] >> gp[0][2]; conv.getline( bin, 256 );
conv.getline( bin, 256 );
conv.getline( bin, 256 );
gp[0][1] = 1.0;
for( i=1; i<50; i++ )
{
// read first
conv >> blank >> nodes[i]; conv.getline( bin, 256 );
conv >> gp[i][0] >> gp[i][1] >> gp[i][1]; conv.getline( bin, 256 );
conv.getline( bin, 256 );
conv.getline( bin, 256 );
// read second
conv.getline( bin, 256 );
conv >> gp[i+1][0] >> gp[i+1][2] >> gp[i+1][2]; conv.getline( bin, 256 );
conv.getline( bin, 256 );
conv.getline( bin, 256 );
gp[i][0] += gp[i+1][0];
}
// last one
conv >> blank >> nodes[i]; conv.getline( bin, 256 );
conv >> gp[i][0] >> gp[i][1] >> gp[i][1]; conv.getline( bin, 256 );
conv.getline( bin, 256 );
conv.getline( bin, 256 );
gp[50][2] = 11.0;
// get conductor ids
ifstream cond( "conductors.txt" );
cond.getline( bin, 256 );
for( i=0; i<cnt; i++ ) {
cond >> ids_g[i]; cond.getline( bin, 256 );
}
return SCASuccess;
}
1276 MD Demonstration Problems
CHAPTER 70

In the RCEnt1 function

SCAResult DefEnt::RCEnt1(const SCAInt32Sequence& IData, const SCAReal32Sequence&


const SCAStringSequence& CData)
{
int i;
SCAReal64 rl, area, hconv;
SCAInt32 idr;

// Get the model data from the Solver service


DynReal64 T( NULL, 0, 0 ); DynReal64 C( NULL, 0, 0 ); DynReal64 Q( NULL, 0, 0
DynReal64 G( NULL, 0, 0 );
DynReal64 A( NULL, 0, 0 ); DynReal64 K( NULL, 0, 0 ); DynReal64 X( NULL, 0, 0
Solv->Arrays64( T, C, Q, G, A, K, X );

// Adjust Conductors
for( i=0; i<cnt; i++ ) {
rl = ( gp[i][1] + gp[i][2] ) * 0.5;
area = gp[i][0];
idr = Solv->ActRel( "NR", nodes[i] );
hconv = (T[idr]+100.0) / rl;
idr = Solv->ActRel( "NGR", ids_g[i] );
G[idr] = hconv*area;
}
return SCASuccess;
}
The following is the example SSK file in the working directory.
In the MODULE block

BCD 3MODULE
DOUBLE PRECISION, DIMENSION(51,3)::GP
INTEGER(8), DIMENSION(51)::IDS_G,NODEIDS
END
CHAPTER 70 1277
User-defined Subroutines for Heat Transfer Coefficient

In the EXECUTION block

BCD 3EXECUTION

F INTEGER(8)::IRESIS
C Get NODEIDS and GP(51,3) data by reading "convec.dat"
F OPEN(11,FILE = 'convec.dat')
F DO 100 IRESIS=1,9
F READ(11,*)
F100 END DO
F DO 200 IRESIS=1,51
F IF(IRESIS==1 ) THEN
F READ(11,800) NODEIDS(IRESIS)
F READ(11,1000) GP(IRESIS,1),GP(IRESIS,3),GP(IRESIS,3)
F GP(IRESIS,2)=1.0
F READ(11,*)
F READ(11,*)
F ELSE IF(IRESIS==51) THEN
F READ(11,800) NODEIDS(IRESIS)
F READ(11,1000) GP(IRESIS,1),GP(IRESIS,2),GP(IRESIS,2)
F GP(IRESIS,3)=11.0
F READ(11,*)
F READ(11,*)
F ELSE
F READ(11,800) NODEIDS(IRESIS)
F READ(11,1000) GP(IRESIS,1),GP(IRESIS,2),GP(IRESIS,2)
F READ(11,*)
F READ(11,*)
F READ(11,*)
F READ(11,1000) GP(IRESIS+1,1),GP(IRESIS,3),GP(IRESIS,3)
F READ(11,*)
F READ(11,*)
F GP(IRESIS,1) = GP(IRESIS,1) + GP(IRESIS+1,1)
F END IF
F 200 END DO
F CLOSE(11)
F 800 FORMAT(7x,I3)
F1000 FORMAT(3(E20.11))

C Get IDS_G(51) data by reading conductors.txt


F OPEN(11,FILE = 'conductors.txt')
F READ(11,*)
F DO 300 IRESIS=1,51
F READ(11,1010) IDS_G(IRESIS)
F300 END DO
F CLOSE(11)
F1010 FORMAT(12x,I4)

SNSOR
END
1278 MD Demonstration Problems
CHAPTER 70

In the VARIABLE 1 block

BCD 3VARIABLES 1
F DOUBLE PRECISION::RL,AREA
F REAL(8)::Hconv
F INTEGER(8)::IRESIS

F DO 400 IRESIS=1,51
F RL = (GP(IRESIS,2)+GP(IRESIS,3))/2.0
F AREA = GP(IRESIS,1)
F Hconv = (T(NR(NODEIDS(IRESIS)))+100)/RL
F G(NGR(IDS_G(IRESIS))) = Hconv*AREA
F400 END DO
END
CHAPTER 70 1279
User-defined Subroutines for Heat Transfer Coefficient

ENTUDS User-defined Logic at Entry Point

Calls user defined logic within a SCA service at the point specified within the solution sequence.

Format
1 2 3 4 5 6 7 8 9 10
ENTUDS ENTID ENTPNT GROUP +
+ “INT” IDATA1 IDATA2 IDATA3 IDATA4 IDATA5 IDATA6 IDATA7 +
+ IDATA8 IDATA9 ... ... IDATAn +
+ “real” RDATA1 RDATA2 RDATA3 RDATA4 RDATA5 RDATA6 RDATA7 +
+ RDATA8 RDATA9 ... ... RDATAn
+ “CHAR” CDATA1 CDATA2 ... ... CDATAn

Example
1 2 3 4 5 6 7 8 9 10
ENTUDS 1 RCENT1 MY_FUNC +
INT 2 17 +
REAL .5 .25

Field Contents Type Default


ENTID Entry point identification number. I0
ENTPNT The point of entry in the solution sequence. Acceptable C Require
values for now: “RCENT1”, “RCENT2”, “ROCOUT1”, d
“RCEXEC1”.
GROUP The SCA group name used to identify the service C Require
d
“INT” Keyword indicating that the following data is integer. C
IDATAi Additional user supplied Integer data not already I
existing on the specified MAT entry.
“READ” Keyword indicating that the following is real. C
RDATAi Additional user supplied Read data not already existing R
on the specified MAT entry.
“CHAR” Keyword indicating that the following data is Character. C
CDATAi Additional user supplied Character data not already C 2
existing on the specified MAT entry.
1280 MD Demonstration Problems
CHAPTER 70

Remarks
1. This entry is for RC Network solver only.
2. In SINDA input file, there are four entry points for users to input customized logics

a. RCENT1 Variable 1 block


b. RCENT2 Variable 2 block
c. RCOUT1 Output block
d. RCEXEC1 Execution block

Results
P/Thermal Temperature result: (303.4 K ~ 336.7 K)

MD Nastran / RC Network Solver: UDS.f temperature result: (303.3 K ~ 336.7 K)

MD Nastran / RC Network Solver: DefEnt.cpp temperature result: (303.3 K ~ 336.7 K)

MSC Sinda: SSK file temperature result: (303.3 K ~ 336.7 K)

Figure 70-2 Results

Modeling Tips
In UDS.f file, M type Fortran is not supported, and you do not need to mark F either. If you want to define a global
variable in the Module RCDATA, you need to insert a USE RCDATA command in the Entry blocks.
CHAPTER 70 1281
User-defined Subroutines for Heat Transfer Coefficient

In DefEnt.cpp file, you will need to use SCA*32 or 64 type variables if they are used by the Solver routines. If you
want to add the C logic in the original DefEnt.cpp file, you need to remove the Return Call command in each block.
They are used to call the UDS.f file.
In the UDS.f or DefEnt.cpp, if you want some output messages or variables, you will need to use call msg (bin) or msg
(bin) command which outputs to the f06 file. SCA service does not output messages to the console window.

Input File(s)
Files Description
exercise_15_sca_sca.bdf BDF file with SCA Entry interfaces
UDS.f Fortran logic for the SCA service
DefEnt.cpp C++ logic for the SCA service
exercise_15_sin.sin MSC Sinda input file
exercise_15_sin.SSK MSC Sinda's SSK (skeleton) file contains Fortran logic

You might also like