Upload
dan-wolf
View
254
Download
7
Embed Size (px)
DESCRIPTION
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.
Citation preview
Chapter 70: User-defined Subroutines for Heat Transfer Coefficient
70 User-defined Subroutines for Heat Transfer Coefficient
Summary 1270
Introduction 1271
Modeling Details 1271
Results 1280
Modeling Tips 1280
Input File(s) 1281
MD Demonstration Problems
CHAPTER 701270
SummaryTitle Chapter 70: User-defined Subroutines
Features: User-defined Subroutines (Fortran, C, and Sinda SSK file)
Geometry & Boundary Conditions
Material properties
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
Tamb = 300 KConvection to ambient temperature
Heat Flux 1000 W/m2
Convection coefficient H = (T1 + 100)/RL computed in user subroutineWhere: T1 is the wall temperature on each node RL is the average distance to the leading edge to node
Dimension: 1m x 10m Unit Thickness Material: Iron
0 500 1000 1500 20000
200
400
600
800
1000 Conductivity (W/m/K)
Specific Heat = 477.3 W/Kg/K
Density = 7870 Kg/m3
Temperature (K)
Temperature result (User defined Fortran Subroutine)
Temperature result (User defined C Subroutine)
Temperature result (MSC Sinda Skeleton SSK file)
1271CHAPTER 70
User-defined Subroutines for Heat Transfer Coefficient
IntroductionThis 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
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 DetailsA 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.
Figure 70-1 Boundary Conditions
H Convection coefficient for each node.
T1 Temperature values on each node.
RL The average distance from the leading edge to node
Tamb = 300 KConvection to ambient temperature
Heat Flux 1000 W/m2
MD Demonstration Problems
CHAPTER 701272
Solution HighlightsMD 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,
In the Subroutine Variables1 block,
RCDATAMODULE
C GP Array, Conductor ID array, and Node ID array definition , (51,3)::GPDOUBLE PRECISION DIMENSION
, (51)::IDS_G,NODEIDSINTEGER(8) DIMENSION
VARIABLES1( iarray, ia_cnt, farray, fa_cnt )SUBROUTINE RCDATAUSE
IMPLICIT NONE(KIND=4), (*):: iarray(*)INTEGER DIMENSION
REAL(KIND=4), (*):: farray(*)DIMENSION ia_cnt, fa_cntINTEGER
::RL,AREADOUBLE PRECISION::HconvREAL(8)
::IRESISINTEGER(8)
ARRAYS64( tptr,cptr,qptr,gptr,aptr,kptr,xptr )CALL
400 IRESIS=1,51DORL = (GP(IRESIS,2)+GP(IRESIS,3))/2.0AREA = GP(IRESIS,1)Hconv = (T(NR(NODEIDS(IRESIS)))+100)/RLG(NGR(IDS_G(IRESIS))) = Hconv*AREA
END DO
END SUBROUTINE
1273CHAPTER 70
User-defined Subroutines for Heat Transfer Coefficient
In the Subroutine Execution block,
EXECUTION( iarray, ia_cnt, farray, fa_cnt )SUBROUTINE RCDATAUSE
IMPLICIT NONE(KIND=4), (*):: iarray(*)INTEGER DIMENSION
REAL(KIND=4), (*):: farray(*)DIMENSION ia_cnt, fa_cntINTEGER
::IRESISINTEGER(8)
C Get NODEIDS and GP(51,3) by reading "convec.dat"data
(11,FILE = 'convec.dat')OPEN
100 IRESIS=1,9DO(11,*)READ
100 END DO
200 IRESIS=1,51DO
(IRESIS==1 )IF THEN(11,800) NODEIDS(IRESIS)READ(11,1000) GP(IRESIS,1),GP(IRESIS,3),GP(IRESIS,3)READ
GP(IRESIS,2)=1.0(11,*)READ(11,*)READ(IRESIS==51)ELSE IF THEN(11,800) NODEIDS(IRESIS)READ(11,1000) GP(IRESIS,1),GP(IRESIS,2),GP(IRESIS,2)READ
GP(IRESIS,3)=11.0(11,*)READ(11,*)READ
ELSE(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,*)READ
GP(IRESIS,1) = GP(IRESIS,1) + GP(IRESIS+1,1)END IF
200 END DO(11)CLOSE
800 (7x,I3)FORMAT1000 (3(E20.11))FORMAT
C Get IDS_G(51) by reading conductors.txtdata
(11,FILE = 'conductors.txt')OPEN(11,*)READ300 IRESIS=1,51DO
(11,1010) IDS_G(IRESIS)READ300 END DO
(11)CLOSE1010 (12x,I4)FORMAT
END SUBROUTINE
MD Demonstration Problems
CHAPTER 701274
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];
1275CHAPTER 70
User-defined Subroutines for Heat Transfer Coefficient
In the RCEXec1 function
SCAResult DefEnt::RCExec1(const SCAInt32Sequence& IData, const SCAReal32Sequence& Rconst SCAStringSequence& CData)
{int i;char bin[256];
// get convection valuesifstream conv( "convec.dat" );char blank;for( i=0; i<9; i++ )
conv.getline( bin, 256 );
// first oneconv >> 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 firstconv >> 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 secondconv.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 oneconv >> 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 idsifstream cond( "conductors.txt" );cond.getline( bin, 256 );for( i=0; i<cnt; i++ ) {
cond >> ids_g[i]; cond.getline( bin, 256 );}return SCASuccess;
}
MD Demonstration Problems
CHAPTER 701276
In the RCEnt1 function
The following is the example SSK file in the working directory.
In the MODULE block
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 serviceDynReal64 T( NULL, 0, 0 ); DynReal64 C( NULL, 0, 0 ); DynReal64 Q( NULL, 0, 0DynReal64 G( NULL, 0, 0 );DynReal64 A( NULL, 0, 0 ); DynReal64 K( NULL, 0, 0 ); DynReal64 X( NULL, 0, 0Solv->Arrays64( T, C, Q, G, A, K, X );
// Adjust Conductorsfor( 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;
}
BCD 3MODULE DOUBLE PRECISION, DIMENSION(51,3)::GP INTEGER(8), DIMENSION(51)::IDS_G,NODEIDSEND
1277CHAPTER 70
User-defined Subroutines for Heat Transfer Coefficient
In the EXECUTION block
BCD 3EXECUTION
F INTEGER(8)::IRESISC 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 DOF DO 200 IRESIS=1,51F 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.0F READ(11,*)F READ(11,*)F ELSE IF(IRESIS==51) THENF READ(11,800) NODEIDS(IRESIS)F READ(11,1000) GP(IRESIS,1),GP(IRESIS,2),GP(IRESIS,2)F GP(IRESIS,3)=11.0F READ(11,*)F READ(11,*)F ELSEF 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 IFF 200 END DOF CLOSE(11)F 800 FORMAT(7x,I3)F1000 FORMAT(3(E20.11))
C Get IDS_G(51) data by reading conductors.txtF OPEN(11,FILE = 'conductors.txt')F READ(11,*)F DO 300 IRESIS=1,51F READ(11,1010) IDS_G(IRESIS)F300 END DOF CLOSE(11)F1010 FORMAT(12x,I4)
SNSOR END
MD Demonstration Problems
CHAPTER 701278
In the VARIABLE 1 block
BCD 3VARIABLES 1F DOUBLE PRECISION::RL,AREAF REAL(8)::HconvF INTEGER(8)::IRESIS
F DO 400 IRESIS=1,51F RL = (GP(IRESIS,2)+GP(IRESIS,3))/2.0F AREA = GP(IRESIS,1)F Hconv = (T(NR(NODEIDS(IRESIS)))+100)/RLF G(NGR(IDS_G(IRESIS))) = Hconv*AREAF400 END DO END
1279CHAPTER 70
User-defined Subroutines for Heat Transfer Coefficient
Calls user defined logic within a SCA service at the point specified within the solution sequence.
Format
Example
ENTUDS User-defined Logic at Entry Point
1 2 3 4 5 6 7 8 9 10ENTUDS 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
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 values for now: “RCENT1”, “RCENT2”, “ROCOUT1”, “RCEXEC1”.
C Required
GROUP The SCA group name used to identify the service C Required
“INT” Keyword indicating that the following data is integer. C
IDATAi Additional user supplied Integer data not already existing on the specified MAT entry.
I
“READ” Keyword indicating that the following is real. C
RDATAi Additional user supplied Read data not already existing on the specified MAT entry.
R
“CHAR” Keyword indicating that the following data is Character. C
CDATAi Additional user supplied Character data not already existing on the specified MAT entry.
C 2
MD Demonstration Problems
CHAPTER 701280
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
Results
Figure 70-2 Results
Modeling TipsIn 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.
a. RCENT1 Variable 1 block
b. RCENT2 Variable 2 block
c. RCOUT1 Output block
d. RCEXEC1 Execution block
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)
1281CHAPTER 70
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