stochasticHydroTools / SlenderBody

Slender-body hydrodynamics
11 stars 4 forks source link

Visualization issue #7

Closed Nasrollah closed 11 months ago

Nasrollah commented 1 year ago

To whom it may concern,

I have some data obtained from SlenderBody source code and need to visualize it. I know that a python package called "PlotOptix" is required for that. However, I do not know whether or not I should install it seperately and I need a license for that. Furthermore, I have seen a python script in "plots" directory which seems suitable to visualization. However, I do not know how to use that.

I would be wondering if you could kindly guide me on these issues related to visualization.

Yours sincerely, Nasrollah Hajaliakbari

omaxian commented 1 year ago

Nasrollah,

First of all, just so you know, I have finally finished the documentation for the software. You can find it here. This page in particular talks about what the outputs of your simulation mean.

For analyzing the output and visualization, there are a few options: 1) This Matlab file will read in the statistics from the simulation and plot the results. You can modify it to also plot the locations at each time step (the file Locs(FileString).txt has the locations of the Chebyshev points). 2) Another option is to use PlotOptix to make fancy visualizations. This requires a GPU, however. If you want to do that, I typically use this Matlab file to generate a set of .txt files for the locations at each time step. Then, as you mentioned, there is a file in the plots directory which takes those .txt files, as well as *.txt files with the cross link locations, as inputs and will plot the networks. 3) You can make your own plotting tools using Matplotlib in Python or whatever software you prefer.

I apologize as the tools we have for visualization are not as user friendly, so this will be a back and forth process. Let me know how I can be of help.

Thanks,

Ondrej Maxian

Nasrollah commented 1 year ago

Dear Dr. Ondrej Maxian

Thanks for your response and providing the documentation as a good tool for analyzing the inputs and outputs for this source code. Related to visualization, I want to use both matlab and plotOptix. At first, I tried to use matlab. To do that, I used your script file called “ProcessPythonNetwork.m “. However, I got this error in below and I have these questions related to that. “ Unrecognized function or variable 'chebpts'. “

1-Which version of Matlab you are using? 2-It seems that the function ” chebpts” is not existed in matlab in default. As a result, how should I provide and add that in matlab?

I would be wondering if you could kindly answer my questions.

Best regards, Nasrollah Hajaliakbari

omaxian commented 1 year ago

You need to install chebfun: https://www.chebfun.org/

Nasrollah commented 1 year ago

Dear Dr. Ondrej Maxian,

Thanks for your response and providing the link. Based on that, I have successfully read the data using some scripts in MATLAB to analyze the results (first option). There was only a small typo, like a bug in here:

https://github.com/stochasticHydroTools/SlenderBody/blob/master/Matlab/AnalyzePython/ProcessPythonNetwork.m#L51 “ Right now, I am working with plotoptix to do the visualization (second option). Based on your explanation, I have generated a set of .txt files for the locations at each time step from my results. However, I can see in the python script (BundledFibers.py) that there is still a file lacking, called “Colormap.txt”. I suppose it must be provided for the python script in order to be run. I would be wondering if you could kindly provide a template file for that until I can visualize the results.

Best regards, Nasrollah Hajaliakbari

omaxian commented 1 year ago

Nasrollah,

The colormap is up to you. You can generate it in Matlab via

cmap = colormap(winter)
writematrix(cmap,'Colormap.txt','delimiter',',')

for example (although "winter" is not a great map). See this page for a list of color maps.

OM

Nasrollah commented 11 months ago

Dear Dr. Ondrej Maxian,

Thanks for your response. After spending some time on visualization, I realized that I have some problems in using "plotoptix", since I want to create some contours which is not straightforward and also lack of handy GPUs here. As a result, I decided to use other software. I tried to write some codes for visualization and I could succeessfully visualize only the fibers but not the domain. To visualize the domain, I need to have a separate file in which the coordinates of eights domain’s corners have been dumped when the fibre locations are dumped. However, I do not know how to implement that (I do not know which of these files I must change: StrainDynamicNetwork.py, DomainC.cpp, Domain.py). I would be wondering if you could possibly provide some hints for me about that.

Best regards, Nasrollah Hajaliakbari

omaxian commented 11 months ago

Hi Nasrollah,

In the input file, you have the parameters gam0= $\gamma_0$ and omHz= $\omega$ (in Hz). Then $g=\gamma_0 \sin{(2 \pi \omega t)}$ is the strain in the domain at any given time. Then, when you render your periodic domain, you render it as normal, except any movement in the $y$ direction has to be accompanied by movement in the $gx$ direction. So if $L$ is the domain length, the 8 corners would be (0,0,0) (0,0,L) (L,0,0) (L,0,L) (gL,L,0) (gL,L,L) (gL+L,L,0) (gL+L,L,L)

I don't think you need to dump this information at run time. Rather, it can be a post-processing step in your visualization code. Does that make sense?

Thanks,

Ondrej Maxian

Nasrollah commented 11 months ago

Dear Dr. Ondrej Maxian,

Thanks for your respone and providing the info. I implemented that into my code. However, the domain does not quite fit into the fibers. I needed to double the size of the domain (from 2 to 4) (I am visualizing the results of the tutorial, I mean StrainDynamicNetwork.py), but there is a kind of offset here. I do not know what would be the coordinates of the domain center (relative to the fibers). I would be wondering if you could kindly guide me on this issue as well.

Best regards, Nasrollah Hajaliakbari

omaxian commented 11 months ago

The fiber locations won't ever be strictly inside the periodic box. The computations that involve periodicity do that, but they don't get saved in that way. If you want particles to be inside the box, I typically use this python code, where again $g$ is the strain, and xyz is the particle output from the code:

# Translate particles in z and y until they are on [0,L] in those directions
xyz[:,2]-=np.floor(xyz[:,2]/Lp)*Lp
yshift = np.floor(xyz[:,1]/Lp)*Lp
xyz[:,1]-=yshift;
xyz[:,0]-=g*yshift;
# Translate particles in x until they sit in parallelogram
xyz[:,0]-=np.floor(xyz[:,0]/Lp)*Lp # Now they are sitting on [0,L] in x 
if (g > 0): # Put them inside the slanted box
    inds = xyz[:,1] > 1/g*xyz[:,0]
    xyz[inds,:]+=[Lp,0,0]; 
elif (g < 0):
    inds = xyz[:,1] > 1/g*(xyz[:,0]-Lp)
    xyz[inds,:]-=[Lp,0,0]; 

By the way, the code will output the sparsely positioned Chebyshev tracking points. To render nice fibers, I typically resample the Chebyshev points on a uniform grid, then work with the uniformly-spaced particles using the code above. The code to do all this can be found here, although you will have to modify depending on the software you are using.

OM

Nasrollah commented 11 months ago

Dear Dr. Ondrej Maxian,

Thanks for your response and support.

Best regards, Nasrollah Hajaliakbari