# Garfield+Elmer Electric Field visualization

**URL:** <https://root-forum.cern.ch/t/garfield-elmer-electric-field-visualization/37270>\
**Category:** Garfield++\
**Created:** [December 19, 2019, 3:00pm UTC](https://root-forum.cern.ch/t/garfield-elmer-electric-field-visualization/37270 "2019-12-19T15:00:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sabrina\_M](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/5daacb/32.png) [@Sabrina\_M](https://root-forum.cern.ch/u/Sabrina_M)\
**Post date:** [December 19, 2019, 3:00pm UTC](https://root-forum.cern.ch/t/garfield-elmer-electric-field-visualization/37270/1 "2019-12-19T15:00:43Z")

</div>

Dear All,

I have used Elmer to solve the electrostatic’s field equations, and I have succesfully imported it on Garfield with the “ComponentElmer” class. I was also able to plot the equipotential surfaces with ViewField. However, what I really need to visualize is the electric field lines. Is this possible to do? This is the piece of code that I am using:

```auto
   const double ext_x = 19.0; // external box x-width
   const double ext_y = 1.0; // external box y-width
   const double ext_z = 25.0; // external box z-width

 TCanvas * c1 = new TCanvas();

ComponentElmer * elm = new ComponentElmer("Field_cage_2/mesh.header","Field_cage_2/mesh.elements","Field_cage_2/mesh.nodes","Field_cage_2/dielectrics.dat","Field_cage_2/field_cage_2.result","mm"); 
elm->SetMedium(0,gas);
 
 Sensor* sensor = new Sensor();
 sensor->AddComponent(elm);
 sensor->SetArea(-1*ext_x,-1*ext_y,-1*ext_z,ext_x,ext_y,ext_z);

 // Set up the object for field visualization.
   ViewField * vf = new ViewField();
   vf->SetSensor(sensor);
   vf->SetCanvas(c1);
   vf->SetArea(-1*ext_x,-1*ext_z,ext_x,ext_z);
   vf->SetNumberOfContours(50);
   vf->SetNumberOfSamples2d(50,50);
   vf->SetPlane(0,-1,0,0,0,0);

 ViewFEMesh * vFE = new ViewFEMesh();
  vFE->SetCanvas(cdrift);
   vFE->SetComponent(elm);
   vFE->SetPlane(0,-1,0,0,0,0);
   vFE->SetFillMesh(true);
   vFE->SetColor(1,kBlue);
  
   vFE->SetArea(-1*ext_x,-1*ext_z,-1*ext_z,ext_x,ext_z,ext_z);
   vf->PlotContour("v");
   vFE->Plot();
   app.Run(kTRUE);

     return 0;
 }

```

Thank you very much in advance!

Sabrina

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [December 20, 2019, 9:16am UTC](https://root-forum.cern.ch/t/garfield-elmer-electric-field-visualization/37270/2 "2019-12-20T09:16:16Z")

</div>

If you have your electric field lines as X and Y vectors you can draw them in the TCanvas you created using [TPolyLine](https://root.cern/doc/master/classTPolyLine.html).

---

<div class="post-metadata">

**Author:** ![Sabrina\_M](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/5daacb/32.png) [@Sabrina\_M](https://root-forum.cern.ch/u/Sabrina_M)\
**Post date:** [December 20, 2019, 9:58am UTC](https://root-forum.cern.ch/t/garfield-elmer-electric-field-visualization/37270/3 "2019-12-20T09:58:55Z")

</div>

Dear Couet,

Thank you very much for your reply. Unfortunately the problem is that the way Elmer stores the info about the potential (in the automatically generated ‘field\_cage\_2.result’ file) is not trivial (at least for me), so it is very convenient that garfield can understand it and plot it just by saying ‘view field’. I was wondering if there is a workaround or something I missed to view the actual field…

Cheers,

Sabrina

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [December 20, 2019, 10:08am UTC](https://root-forum.cern.ch/t/garfield-elmer-electric-field-visualization/37270/4 "2019-12-20T10:08:53Z")

</div>

> [@Sabrina\_M](#):
>
> so it is very convenient that garfield can understand it and plot it

In that case, I think it is more a question for the [Garfield people](http://garfieldpp.web.cern.ch/garfieldpp/support/).

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [January 3, 2020, 10:08am UTC](https://root-forum.cern.ch/t/garfield-elmer-electric-field-visualization/37270/5 "2020-01-03T10:08:58Z")

</div>

Closed on January 3, 2020, 10:08am UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
