CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > Siemens > STAR-CCM+

Create a user code

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 13, 2015, 03:36
Default Create a user code
  #1
New Member
 
Hoang Nhan Hien
Join Date: Jan 2014
Posts: 1
Rep Power: 0
HN_Hoang is on a distinguished road
Hi, I have tried to create a user code in star ccm+. I did a simple example given in the user guide of star ccm+ version 10.04.009 (window os), but it is not successful. I used visual studio 2013 as recommended in the user guide to compile source files (including uclib.h, uclib.c and zeroGradT.c).

First I compile uclib.c to create uclib.obj, then link this uclib.obj to UserFunctions.lib of star ccm+ to generate libuser.dll

There is no problem with the first step, but the second step is always wrong. The error is:
"ublib.obj : error LNK2019: unresolved external symbol zeroGradT referencetion uclib
libuser.dll : fatal error LNK1120: 1 unresolved externals"

I checked the define of zeroGradT function, but it seems to be okey. Could anyone help me find the solution for this problem? Thanks!

++++++++++++++++++++++++++

#ifndef UCLIB_H
#define UCLIB_H
#ifdef DOUBLE_PRECISION
typedef double Real;
#else
typedef float Real;
#endif
typedef double CoordReal;

#ifdef __cplusplus
extern "C" {
#endif
#if defined(WIN32) || defined(_WINDOWS) || defined(_WINNT)
# define USERFUNCTION_EXPORT __declspec(dllexport)
# define USERFUNCTION_IMPORT __declspec(dllimport)
#else
# define USERFUNCTION_EXPORT
# define USERFUNCTION_IMPORT
#endif

extern void USERFUNCTION_IMPORT ucarg(void *, char *, char *, int);
extern void USERFUNCTION_IMPORT ucfunc(void *, char *, char *);
extern void USERFUNCTION_IMPORT ucfunction(void *, char *, char *, int, ...);

void USERFUNCTION_EXPORT uclib();
#ifdef __cplusplus
}
#endif

#endif


+++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++

#include "uclib.h"

void zeroGradT(Real*, int, int*, Real*);

void USERFUNCTION_EXPORT uclib()
{
ucfunc(zeroGradT, "BoundaryProfile", "Zero Gradient Temperature");
ucarg (zeroGradT, "Face", "FaceCellIndex", sizeof(int[2]));
ucarg (zeroGradT, "Cell", "Temperature", sizeof(Real));
}

+++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++

#include "uclib.h"

void USERFUNCTION_EXPORT zeroGradT(Real *result, int size, int (*fc)[2], Real *T)
{
int i;
for (i = 0; i != size; ++i)
{
result[i] = T[fc[i][0]];
}
}

Last edited by HN_Hoang; November 16, 2015 at 04:29.
HN_Hoang is offline   Reply With Quote

Old   March 25, 2019, 21:38
Default
  #2
New Member
 
Subhadip Das
Join Date: Jan 2019
Location: Windsor, Canada
Posts: 4
Rep Power: 7
Subhadip is on a distinguished road
Hi..I am new to Star-ccm+ community. Can you please explain the procedure to use a user code? Do I need to compile the user code in C and attach to the sim file? How can I use this newly added user code with the simulation?? To my understanding, it is absolutely different from using a field function. Please help. Thanks.
Subhadip is offline   Reply With Quote

Old   December 21, 2020, 22:05
Default Difficulites to use user code on windows OS
  #3
New Member
 
HyeonsuNam
Join Date: Dec 2020
Posts: 2
Rep Power: 0
HyeonsuNam is on a distinguished road
From the installation and the user manual, visual studio 2013 and Intel 18.3 compiler is recommended on the new version 2020.3.

I tried to use visual studio 2019 to resister user code on UserFunctions.lib as addressed on the User Guide. But I failed to resolve the systematic problems mainly related on linking library, such as he mentioned above.

May it is convenient to use linux os to apply the user code. Now I'm trying it on the linux unbuntu 18.04. And the .so file has been compiled and then it could have been loaded on the user code tool. And I checked that it works properly.

The user code simple that I conceived, it showed almost same values with the embeded temperaure field function in Star ccm+.

https://o365uos-my.sharepoint.com/:i...miIOw?e=7u5Z0p

Quote:
#include "uclib.h"

void simple(Real* result, int size, Real* T) {
int i;

for (i = 0; i != size; ++i) {
result[i] = T[i];
}
}

void USERFUNCTION_EXPORT uclib() {
ucfunc(simple, "ScalarFieldFunction", "Temperature2");
ucarg(simple, "Cell", "Temperature", sizeof(Real));
}
Watch out that not all the linux platform are compatible for star ccm+, that on this ubuntu the cad scatch is not displayed propery. The proper linux platform is introduced on installation guide that consumers could download from siemens support center.

I hope that it might be help for someone considering user code.

Thank you.
HyeonsuNam is offline   Reply With Quote

Old   December 27, 2020, 04:15
Default
  #4
Senior Member
 
Ping
Join Date: Mar 2009
Posts: 556
Rep Power: 20
ping is on a distinguished road
i have done many ucode runs on windows and linux with no problems but you must follow the instructions very carefully and always use the tutorial supplied code first to get it all running.

however the reality is that ucode is actually very rarely needed in star due to the power of the field functions, java scripting and simulation operations - all many times easier to use - the user environment is much more friendly than what users of fluent and openfoam need to master
ping is offline   Reply With Quote

Reply

Tags
user code


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
User code in CCM+ ggulgulia STAR-CCM+ 2 May 28, 2015 02:23
Unable to create dll, lib files to run User Functions in CFX lucky_m_m CFX 0 July 19, 2013 03:23
How to create an user defined function? Cagdas FLUENT 1 September 5, 2007 21:02
user friendly cfd code waqar Main CFD Forum 19 August 18, 2000 17:31
Open source CFD code development, possible? Dr. Yazid Bindar Main CFD Forum 27 July 18, 2000 01:18


All times are GMT -4. The time now is 03:50.