|
[Sponsors] |
Save & read a vector (array) in same or other macros for next time step or iteration |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
February 28, 2019, 13:43 |
Save & read a vector (array) in same or other macros for next time step or iteration
|
#1 |
Member
Peter Maroul
Join Date: May 2018
Posts: 52
Rep Power: 8 |
Hello all;
How can we save a written vector(array) (for example 2*30 ) and read (use) it for other or same UDF macros in the next time step or iterations? Thanks a lot for any advice. P.Maroul |
|
March 3, 2019, 18:55 |
|
#2 |
Member
Peter Maroul
Join Date: May 2018
Posts: 52
Rep Power: 8 |
Maybe I couldn't ask my question clearly, therefore I try to re-raise my question with a Pseudocode .
Code:
#include udf.h for(int i=0;i<n0;i++) for(int j=0;j<m0;j++) A(i,j)= A(i,j)+ /*some modifications or updates*/ DEFINE_ADJUST(my_adjust,d) { . . . /*some written text codes*/ . . } |
|
March 3, 2019, 21:38 |
|
#3 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
Code:
#include udf.h int n,m,i; real **A; A= (real**)malloc((m)*sizeof(real*)); for (i=0; i<m; i++) { A[i] = (real*)malloc(n*sizeof(real)); } best regards |
|
March 4, 2019, 06:15 |
|
#4 | |
Member
Peter Maroul
Join Date: May 2018
Posts: 52
Rep Power: 8 |
Quote:
How about two-dimensional arrays? Is the following Pseudocode right? Code:
#include udf.h int n,m,i; real **A; A= (real**)malloc((m)*sizeof(real*)); for (j=0; j<m; j++) { for (i=0; i<n; i++) { A[i][j] = (real*)malloc(n*sizeof(real)); }} |
||
March 4, 2019, 21:48 |
|
#6 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
I gave you code for memory allocation for 2D array (matrix)
than you may define value of each element in matrix using 2 loops for i and j you may do whatever you want. but reading/writing to file may take some time, depends on the size of your matrix. play with it. reading/writing to file functions are different for single core computation and parallel approach, take it into account best regards |
|
March 5, 2019, 16:27 |
|
#7 |
Member
Peter Maroul
Join Date: May 2018
Posts: 52
Rep Power: 8 |
Thanks Sirs very much !
If you're not in a hurry, can you send a Pseudocode executing the matrix's printing(A[i,j]) in a file, for example, in intervals of every ten time steps, and then from which part of the FLUENT options, the output of this matrix is visible? for example for a 2D array , how can I plot A[i][1] versus A[i][2] in each 10 deltaT in Fluent or other post processing tools? Thanks in advance for any help. |
|
March 21, 2019, 11:10 |
|
#8 | |
Member
Peter Maroul
Join Date: May 2018
Posts: 52
Rep Power: 8 |
Quote:
Are the n, m constant parameters dynamic allocated in udf's , too? |
||
March 22, 2019, 07:18 |
|
#9 | |
Member
Peter Maroul
Join Date: May 2018
Posts: 52
Rep Power: 8 |
Quote:
I compiled your suggested sub-code and encountered below error: error C2040: 'A' : 'int ' differs in levels of indirection from 'double ** ' for the command line 4:"A= (real**)malloc((m)*sizeof(real*));" How can I resolve this error? |
||
March 25, 2019, 01:27 |
|
#10 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
Code:
#include "udf.h" int n = 10,m =10; real **A; DEFINE_ON_DEMAND(Allocate_memory) { int i,j; A= (real**)malloc((m)*sizeof(real*)); for (i=0; i<m; i++) { A[i] = (real*)malloc(n*sizeof(real)); } } DEFINE_ON_DEMAND(Define_matrix) { int i,j; for (j=0; j<m; j++) { for (i=0; i<n; i++) { A[i][j] = i+j; } } } DEFINE_ON_DEMAND(Free_memory) { free(A); } |
|
March 30, 2019, 07:05 |
|
#11 |
Member
Peter Maroul
Join Date: May 2018
Posts: 52
Rep Power: 8 |
Dear Alexander.
Your answer was so helpful!!. Really I had to define that array in a define-on-demand and then to update in other macros. Good luck and best wish for you. |
|
Tags |
next time step, read array, save array |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
AMI speed performance | danny123 | OpenFOAM | 21 | October 24, 2020 05:13 |
Transient simulation not converging | skabilan | OpenFOAM Running, Solving & CFD | 14 | December 17, 2019 00:12 |
Kernel for new CPUs | Simbelmynė | Hardware | 22 | January 5, 2018 17:41 |
High Courant Number @ icoFoam | Artex85 | OpenFOAM Running, Solving & CFD | 11 | February 16, 2017 14:40 |
Floating point exception error | lpz_michele | OpenFOAM Running, Solving & CFD | 53 | October 19, 2015 03:50 |