Professional Documents
Culture Documents
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
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)
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
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.
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
DOUBLE PRECISION::RL,AREA
REAL(8)::Hconv
INTEGER(8)::IRESIS
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
INTEGER(8)::IRESIS
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,*)
200 END DO
CLOSE(11)
800 FORMAT(7x,I3)
1000 FORMAT(3(E20.11))
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
{
// 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
// 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
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))
SNSOR
END
1278 MD Demonstration Problems
CHAPTER 70
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
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
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
P/Thermal Temperature result: (303.4 K ~ 336.7 K)
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