CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT

Having trouble with rand_gen( ) Function within Code

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 18, 2020, 17:51
Default Having trouble with rand_gen( ) Function within Code
  #1
New Member
 
David
Join Date: Aug 2020
Posts: 5
Rep Power: 5
David12 is on a distinguished road
Hey guys, I'm new to UDFs, and I've been having trouble with some code for the last couple of days and need some help. So essentially, what I've been doing is researching the acoustics of a propeller, and what I'm currently trying to do is create a UDF that makes a gaussian (normal) distribution of random values for the RPM and have the UDF select one at random. I've copied the code found on this website in order to do it, link: https://www.tutorialspoint.com/gener...in-c-cplusplus

When I run my code, I get a ton of errors. (posted below). I get this same error over and over, its so big that I just posted a snippet of it. I don't think it's a compiling error (but I could be wrong), because I've had compiling issues before and solved it and was able to compile other UDFs just fine. I'm thinking that maybe there's something wrong with my code? I'm not sure. Also, it might be a library issue with cstdlib and cmath, but I'm not sure because I have those two files in my Microsoft Visual file. Furthermore, the macro DEFINE_ZONE_MOTION is fine, because I've got it to work before this, its just the rand_gen( ) part that I'm having trouble with. I'm going to post my error, and then also my code

Errors:
Code:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cstdlib(19): error C2061: syntax error: identifier 'noexcept'
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cstdlib(19): error C2059: syntax error: ';'
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cstdlib(20): error C2449: found '{' at file scope (missing function header?)
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cstdlib(22): error C2059: syntax error: '}'
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cstdlib(29): error C2061: syntax error: identifier 'noexcept'
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cstdlib(29): error C2059: syntax error: ';'
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cstdlib(30): error C2449: found '{' at file scope (missing function header?)
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cstdlib(32): error C2059: syntax error: '}'
My Code:
Code:
#include "udf.h"
#include <stdlib.h>

#include <cstdlib>
#include <cmath>
#include <ctime>
#include <iostream>


FILE *fp;    

 
double rand_gen() 
{
 return ((double)(rand()) + 1.)/((double)(RAND_MAX) + 1.);                  
}
double normalRandom()
{ 
 double v1=rand_gen();
 double v2=rand_gen();
 return cos(2*3.14*v2)*sqrt(-2.*log(v1));
}



DEFINE_ZONE_MOTION(fmotion,omega,axis,origin,velocity,time,dtime)
{
    double sigma = 82.0;
    double Mi = 40.0;
    time = CURRENT_TIME;
    if (time < 0.1)
      {
        *omega = 2500.0 * time;
      }

    else
      {
        *omega = normalRandom()*sigma+Mi;
      }


    N3V_D (velocity,=,0.0,0.0,0.0);
    N3V_S(origin,=,0.0); 
    N3V_D(axis,=,0.0,1.0,0.0); 





    #if !RP_NODE 
    

    fp = fopen("data.txt","a+"); 
    fprintf(fp,"Random: %f Time: %f RPM: %f\n",r,time,*omega); 
    fclose(fp);    
    return;
    

    #endif  

}
David12 is offline   Reply With Quote

Reply


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
[snappyHexMesh] Invalid Normals for source face to target face while making AMI? Sorabh OpenFOAM Meshing & Mesh Conversion 1 August 3, 2021 06:35
[snappyHexMesh] How to define to right point for locationInMesh Mirage12 OpenFOAM Meshing & Mesh Conversion 7 March 13, 2016 14:07
Error with Wmake skabilan OpenFOAM Installation 3 July 28, 2009 00:35
DecomposePar links against liblamso0 with OpenMPI jens_klostermann OpenFOAM Bugs 11 June 28, 2007 17:51
Design Integration with CFD? John C. Chien Main CFD Forum 19 May 17, 2001 15:56


All times are GMT -4. The time now is 06:13.