Creating a temporary volScalarField in the calculation
I'm trying to create a new nonNewtonian model and in my .C file, I have a private member function to calculate nu:
Code:
Foam::tmp<Foam::volScalarField> Thanks, |
Dear Shuang,
I would not do it as you suggested because if you make a temporary volScalarField lead to memory allocation and deallocation in each time-step which is not a good way. It slows down your simulation and is waste of power. I think nowadays you should not have problems with memory space, so there is no need doing that. Back to your question. I think you know that your code cannot work because of not defined nu0 variable. However, please use code tags to visualize the c++ stuff. To implement a temporary volScalarField nu0 here you have to do it like that: Code:
|
Since you’re trying to create a new Non-Newtonian model your class should be inherited from viscosityModel class. So, have access to U_ field which can be used for creating your volScalarField in return of your method.
Code:
// Your If statement Cheers, |
Thank you Hasan. This is helpful
|
Hi Hasan,
I have another practical question, I hope you can help out. I create a temporary nu0 field using your approach and initialise the elements value to be 0. What I want to do right now is to update each element value based on the filter I applied. My code is below: Quote:
Quote:
1. why do I need to declare nu0 again given I just created? 2. how can I declare then? I hope you can help out. Thanks, |
Since you haven't defined any variable named nu0_, you're getting compile error. If you want to perform some operation on nu0_ you need to define it using its constructor.
Code:
volScalarField nu0_ |
Hi Hasan,
So I declared the nu0 in my .H file and my .C code is as below: Quote:
There is no compile error any more but when I run the model. It turns out the program did not go through the for loop, so at any time step, the nu is the constant initialised in nu0. Is there anything wrong in my logic? How could I modify it? Thanks |
Hi,
I did not check everything (reason below) but your function calcNu() will just return a volScalarField which is always zero. You should know that the return statement is the last execution in the function. What does that mean? It means that your forAll loop is senseless because you will never go to that point. Ergo, it will not work as you would like to have. By the way, I am sorry not to see that you want to build your own non-Newton model. Otherwise I would told you the same than Hasan (derive it from the non-Newtonian class) in order to have access to fields. However, I have the feeling that you are not aware with C++ and finally FOAM is nothing more than C++. To sum up: Code:
|
Quote:
Unless I have a very good mood, I have a tendency to skip those topics altogether. There is a post about using [CODE]-tags here, but I'm afraid that it being post #6 instead of #1, people simply do not see it. Nonetheless, it should be common forum sense... If you search before asking your question [which is mandatory], you'll also see others use it. Therefore, if someone does not use it, it is rather likely that that person did not search in the first place. |
Help on temporary volScalarField
Dear Foamers, I found this conversation suitable for a question regarding a volScalarField private member function.
I'm updating an OpenFOAM k-epsilon code from the 2.3.0 version to the 4.0. In doing so, when compiling my .C file, I get an error in correspondence of these lines: Code:
tmp<volScalarField> kEpsilon1::gCmuSmooth() Code:
{ tmp<volScalarField> gCmuSmooth() " This part of the code, written in the same way, was working perfectly on the 2.3.0 version of OpenFOAM. Should I change something in the way I declare or initialise gCmuSmooth() ? Any help or explanation would be extremely useful! |
Mr
Quote:
Hi, By Using this code i am trying to find min of volScalarField. volScalarField MINprincipalstress ( IOobject ( "MINprincipalstress", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE ), min(principalstress, MINprincipalstress) ); I have calculated the principal stress by using this code: volScalarField principalstress ( IOobject ( "principalstress", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE ), (0.5 * (sigmaxx + sigmayy) + 0.5 * sqrt( sqr(sigmaxx- sigmayy) + 4 * sqr(sigmaxy))) ); When i compile the code, it does not gives me any error. But when i run the simulation. after some iteration it gives me this error. I do not know, what should i do now. here is the error: GAMG: Solving for Dx, Initial residual = 9.14894e-07, Final residual = 9.14894e-07, No Iterations 0 GAMG: Solving for Dy, Initial residual = 9.97011e-07, Final residual = 9.97011e-07, No Iterations 0 ExecutionTime = 6.99 s ClockTime = 7 s Iteration: 9.994e-06 GAMG: Solving for Dx, Initial residual = 9.14894e-07, Final residual = 9.14894e-07, No Iterations 0 GAMG: Solving for Dy, Initial residual = 9.97011e-07, Final residual = 9.97011e-07, No Iterations 0 ExecutionTime = 6.99 s ClockTime = 7 s Iteration: 9.996e-06 GAMG: Solving for Dx, Initial residual = 9.14894e-07, Final residual = 9.14894e-07, No Iterations 0 GAMG: Solving for Dy, Initial residual = 9.97011e-07, Final residual = 9.97011e-07, No Iterations 0 ExecutionTime = 6.99 s ClockTime = 7 s Iteration: 9.998e-06 GAMG: Solving for Dx, Initial residual = 9.14894e-07, Final residual = 9.14894e-07, No Iterations 0 GAMG: Solving for Dy, Initial residual = 9.97011e-07, Final residual = 9.97011e-07, No Iterations 0 ExecutionTime = 6.99 s ClockTime = 7 s Iteration: 1e-05 GAMG: Solving for Dx, Initial residual = 9.14894e-07, Final residual = 9.14894e-07, No Iterations 0 GAMG: Solving for Dy, Initial residual = 9.97011e-07, Final residual = 9.97011e-07, No Iterations 0 Max sigmaEq = 1.89073e+09 Max sigmazz = 2.35054e+08 Principal Stress Maximum = 9.42315e+08 Principal Stress Minimum = -4.72528e+08 --> FOAM FATAL ERROR: (openfoam-2312) Different dimensions for 'min(a, b)' dimensions : [1 -1 -2 0 0 0 0] != [0 0 0 0 0 0 0] one more thing if i use std::min(principalstress, MINprincipalstress) it gives me an error this GAMG: Solving for Dx, Initial residual = 9.14894e-07, Final residual = 9.14894e-07, No Iterations 0 GAMG: Solving for Dy, Initial residual = 9.97011e-07, Final residual = 9.97011e-07, No Iterations 0 ExecutionTime = 7.44 s ClockTime = 8 s Iteration: 1e-05 GAMG: Solving for Dx, Initial residual = 9.14894e-07, Final residual = 9.14894e-07, No Iterations 0 GAMG: Solving for Dy, Initial residual = 9.97011e-07, Final residual = 9.97011e-07, No Iterations 0 Max sigmaEq = 1.89073e+09 Max sigmazz = 2.35054e+08 Principal Stress Maximum = 9.42315e+08 Principal Stress Minimum = -4.72528e+08 --> FOAM FATAL ERROR: (openfoam-2312) Cannot dereference nullptr at index 0 in range [0,5) can you let me know, what is issue here? |
All times are GMT -4. The time now is 12:49. |