1
$\begingroup$

How can we export the data in excel of the following streamlines and contour plots to plot in Tecplot?

StreamPlot[{-1 - x^2 + y, 1 + x - y^2}, {x, -3, 3}, {y, -3, 3},PlotLegends -> Automatic]

and isotherms, contourplot

ContourPlot[Cos[x]+Cos[y], {x, 0, 4 Pi}, {y, 0, 4Pi}]
$\endgroup$
5
  • 1
    $\begingroup$ Cases[yourStreamPlot, a_Arrow :> a[[1]], All] will return a list of the points describing each one of the arrows in that plot. You could export that to various formats using Export. It will then be up to you to adapt that so you can use Tecplot (with which I am not familiar). The ContourPlot is more complicated because color matters there, but if you just want the contour lines: Cases[Normal@yourContourPlot, l_Line :> l[[1]], All]. What do you need to do in Tecplot specifically? Maybe it could be accomplished in MMA without exporting. $\endgroup$ – MarcoB Mar 5 at 15:34
  • $\begingroup$ Does StreamPlot not just use the derivative in the x and y direction? Could you not just export the data that way? $\endgroup$ – Teabelly Mar 7 at 13:18
  • $\begingroup$ @Teabelly i Want to export the data results of fluid flow model. The code of that problem is too large that's why here I mention the simple example so I will get the idea of how to export the data? $\endgroup$ – Mathematicain Mar 7 at 16:28
  • $\begingroup$ Can you post the equation please? $\endgroup$ – Teabelly Mar 7 at 17:13
  • $\begingroup$ @Teabelly Please check this code i want to export data of streamlines and isotherms. drive.google.com/file/d/1WDH2PUMahuKMn1PtnaqYPSl1XCimgdXm/… $\endgroup$ – Mathematicain Mar 7 at 18:09
2
+50
$\begingroup$

StreamPlot - Using Excel

Preparing Data

Here is the procedure you should follow:

StreamPlot[{eq1[x,y], eq2[x,y]}, {x, ...}, {y, ...}]

should be written as:

Flatten[#, 1] &@ Table[{x, y, eq1[x,y], eq2[x,y]}, {x, ...}, {y, ...}]

Because writing on a single spreadsheet needs a 2-dimensional matrix, apply Flatten and export it as a .xlsx file (.csv also works):

data = Flatten[#, 1] &@
  Table[{x, y, -1 - x^2 + y, 1 + x - y^2}, {x, -3, 3}, {y, -3, 3}]


Export["D:\\data0.xlsx", data]

Open in Excel, select the data from the upper left-hand side to the other corner (direction of your selection is important for Tecplot add-in):

enter image description here

In Tecplot, change plot option from XY Line to 2D Cartesian, enable Vector:

enter image description here

A dialog will pop up, choose x3 for U and x4 for V:

enter image description here

Now you have your plot in Tecplot (because of the Table all the vectors sit on a grid):

enter image description here

If you want to have more vectors, increase Table step size for variables:

data = Flatten[#, 1] &@
  Table[{x, y, -1 - x^2 + y, 1 + x - y^2}, {x, -3, 3, .1}, {y, -3, 
    3, .1}]

enter image description here

If you want the same vectors you got in Mathematica:

eq[x_, y_] := {-1 - x^2 + y, 1 + x - y^2};
plt = StreamPlot[eq[x, y], {x, -3, 3}, {y, -3, 3}]

Output:

enter image description here

Extract vectors from plt and apply eq:

data = Join[#, eq @@ #] & /@ 
  Cases[plt, Arrow[{x_, __}] -> x, Infinity]

Result:

enter image description here

StreamPlot - Without Excel

You could export the data directly from Mathematica to a format which is known to Tecplot like .dat or .plt:

With .dat Format

Export data table to a .dat file:

Export["D:\\data1.dat", 
 Flatten[#, 1] &@
  Table[{x, y, -1 - x^2 + y, 1 + x - y^2}, {x, -3, 3}, {y, -3, 3}], "PLT"]

Open Teplot, go to File > Load Data..., choose D:\\data1.dat, in Choose Loader dialog, choose Tecplot Data Loader:

enter image description here

Change plot option from XY Line to 2D Cartesian, enable Vector. For the dialog, choose v3 variable for U and v4 for V:

With .plt Format

First, you need to define .plt export format for Mathematica:

ImportExport`RegisterExport["PLT", MyExportFormat`Exporter ]
MyExportFormat`Exporter[filename_, data_, opts___] :=
 Module[{edata, strm},
  edata = 
   "TITLE=\"Mathematica\"\nVARIABLES=" <> 
    StringReplace[
     ExportString[
      "v" <> ToString@# & /@ Range[1, #] &@Length@data[[1]], "TSV"], 
     "\n" -> " "] <>
    "\nZone T=\"M\"\n" <> ExportString[data, "TSV"];
  strm = OpenWrite[filename];
  WriteString[strm, edata];
  Close[strm]
  ]

Now we registered PLT export format.

Export your data with PLT format:

Export["D:\\data1.plt", 
 Flatten[#, 1] &@
  Table[{x, y, -1 - x^2 + y, 1 + x - y^2}, {x, -3, 3}, {y, -3, 3}], "PLT"]

Open the file in Teplot and follow the same procedure, you will get the same result like .dat format:

enter image description here

ContourPlot

We will populate points and calculate their values, export them to Excel, use Tecplot Add-in to import them to Tecplot:

ContourPlot[Cos[x] + Cos[y], {x, 0, 4 Pi}, {y, 0, 4 Pi}]

Output:

enter image description here

Use Table and add headings:

rg1 = Range[0, 4 Pi];
rg2 = Range[0, 4 Pi];

(* Data *)
Table[Cos[x] + Cos[y], {x, rg1}, {y, rg2}]

(* Data + headings *)
addHeadings = 
  MapThread[Prepend, {#, Prepend[rg1, ""]}] &@Prepend[#, rg2] &;

data4 = addHeadings@Table[Cos[x] + Cos[y], {x, rg1}, {y, rg2}];

Export the data:

Export["D:\\data4.xlsx", data4]

Open in Excel, select the data from the upper left-hand side to the other corner (direction of your selection is important for Tecplot add-in):

enter image description here

If you enable Tecplot add-in use Send to Tecplot under Add-ins Excel tab, when Tecplot opened, enable Contour:

enter image description here

Just like StreamPlot, increasing the Table variable step size, increase the quality of the result:

rg1 = Range[0, 4 Pi, .1];
rg2 = Range[0, 4 Pi, .1];

enter image description here

In the end, I should mention I'm not an expert in Tecplot and you might find better solutions, and if you do, don't remember to add it to this post so it becomes helpful for future viewers.

I used Mathematica 12.2 and Tecplot 360 EX 2017 R3.

$\endgroup$
4
  • $\begingroup$ @Bany Thank you so much for your help and for elaborating the problem in detail. It works. $\endgroup$ – Mathematicain Mar 12 at 13:49
  • $\begingroup$ how can export ( .dat) file of data $\endgroup$ – Mathematicain Mar 12 at 14:49
  • $\begingroup$ I edited the answer. $\endgroup$ – Ben Izd Mar 12 at 16:09
  • $\begingroup$ Thank you so much. $\endgroup$ – Mathematicain Mar 12 at 16:49
0
$\begingroup$

Not too sure what data you want, maybe this helps, it seems to give you the data for each vector field:

Table[{-1 - x^2 + y, 1 + x - y^2}, {x, -3, 3}, {y, -3, 3}]
Export["file.xls", %]
out[1]: {{{-13, -11}, {-12, -6}, {-11, -3},...}}

Can be used to produce the same graph... ish:

StreamPlot[{-1 - x^2 + y, 1 + x - y^2}, {x, -3, 3}, {y, -3, 3}, PlotLegends -> Automatic]

enter image description here

d0 = Table[{-1 - x^2 + y, 1 + x - y^2}, {x, -3, 3}, {y, -3, 3}]

Export["file.txt", d0, "Table"]

ListVectorPlot[d0, StreamPoints -> 100]

enter image description here

If you want the data from a graph with unknown equation / origin, maybe check this out:

How to Extract data points from plot in mathematica to redraw it with another program?

$\endgroup$
9
  • $\begingroup$ It's not working because when I export data the I can't plot it again in Mathematica or others like excel, Tecplot. $\endgroup$ – Mathematicain Mar 7 at 18:11
  • $\begingroup$ you can see the type of data that I export from comsol code. Please see this drive.google.com/file/d/1kHwbmb_E237BpN7xGuUpONnoJVWqGAFr/… $\endgroup$ – Mathematicain Mar 7 at 18:13
  • $\begingroup$ @Mathematicain I'm unfamilair with Tecplot, you want to export from mathematica in a similar format to the data in the link? Or you want to Import this data? $\endgroup$ – Teabelly Mar 7 at 18:33
  • $\begingroup$ The {x,y} are the first two columns of the main table (corresponding to d0), can you not just identify this in Tecplot? $\endgroup$ – Teabelly Mar 7 at 18:35
  • $\begingroup$ Yes I want to export data like the data I mention. in txt of xls format $\endgroup$ – Mathematicain Mar 7 at 18:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.