3

I have different optical setups I would like to draw using pst-optexp, but not necessarily all in the same document. As an example I have the following code:

\documentclass[margin=5pt]{standalone}
\usepackage[dvipsnames,svgnames,pdf]{pstricks}
\usepackage{pdftricks}
\usepackage{auto-pst-pdf}
\usepackage{pst-optexp}
\usepackage{stackengine}
\begin{document}
    \begin{pspicture}(16,5)
        \psset[optexp]{fiber=none, usefiberstyle}
        \newpsstyle{Fiber}{linecolor=orange, linewidth=2\pslinewidth}
        %%Simple seed laser
        \pnodes(1, 1){DiodeIn} (2, 1){DiodeOut}
        \pnodes(3, 1) {FiberIn} (5, 1){FiberOut}
        \pnode(6, 1){SeedOutput}
        \pnodes(9, 4){TSFIn}(11, 4){TSFOut}
        \pnodes(13, 3){LoopIn}(13, 2){LoopOut}
        \pnodes(9, 1){OutputIsolatorIn}(11,1){OutputIsolatorOut}
        \pnodes(13, 2){OutputSplitter}(16, 3){LaserOutHigh}(16, 1){LaserOutLow}
        \optdiode[compname=SeedDiode, position=start](DiodeIn)(DiodeOut){\begin{tabular}{@{}c@{}}Laser\\diode\end{tabular}}
        \optfiber[compname=SeedFiber, addtoFiberOut={ncurv=1,angleB=0},addtoFiberIn={ncurv=1,angleA=0},compshift=-1,label=-1.5.l] (FiberIn)(FiberOut){\begin{tabular}
                {@{}c@{}}
                Active\\Fiber
            \end{tabular}}

        \nput{90}{SeedOutput}{Seed Output}
        
        \drawfiber{SeedDiode}{SeedFiber}
        \drawfiber[ArrowInside=->]{SeedFiber}(SeedOutput)
        
        %%Simple amplifier
        \pnodes(8, 1){AmpIn}
        \pnodes(11, 1){ActiveFiberIn}(13, 1){ActiveFiberOut}
        \pnodes(8, 4){PumpDiodeIn}(9, 4){PumpDiodeOut}
        \pnode(14, 2){AmpOut}
        \optdiode[compname=AmpDiode, position=start](PumpDiodeIn)(PumpDiodeOut){\begin{tabular}{@{}c@{}}Laser\\diode\end{tabular}}
        \wdmcoupler[compname=SignalPumpCombiner, coupleralign=bottom, couplersize=0.35](PumpDiodeOut)(AmpIn)(ActiveFiberIn){\begin{tabular}{@{}c@{}}
                Pump\\Combiner
        \end{tabular}}
        \optfiber[compname=PumpFiber, addtoFiberOut={ncurv=1,angleB=0},addtoFiberIn={ncurv=1,angleA=0},compshift=-1,label=-1.5.l] (ActiveFiberIn)(ActiveFiberOut){Active fiber}
        
        \nput{-90}{AmpIn}{Amp Input}
        \nput{90}{AmpOut}{Amp Output}
        
        \drawfiber{AmpDiode}{SignalPumpCombiner}
        \drawfiber[ArrowInside=->](AmpIn){SignalPumpCombiner}
        \drawfiber{SignalPumpCombiner}{PumpFiber}
        \drawfiber[ArrowInside=->, arrows=->]{PumpFiber}(AmpOut)
        
        %Connect both setups
        \drawfiber[linecolor=green](SeedOutput)(AmpIn)
    \end{pspicture}
\end{document}

which gives me enter image description here If I just want to show the part to the left of the green fiber, I would have to comment out the code responsible for the right hand side, and if I just would like to show the right side, I would have to comment out the code for the left side, and shift everything still remaining to the left (else I would have a lot of white space).

Therefore, to make everything simpler I was thinking of having each block in it's own file/"function", such that I can write code similar to

\documentclass[margin=5pt]{standalone}
\usepackage[dvipsnames,svgnames,pdf]{pstricks}
\usepackage{pdftricks}
\usepackage{auto-pst-pdf}
\usepackage{pst-optexp}
\usepackage{stackengine}
%%Somehow include seed/amp pst files here
\begin{document}
    \begin{pspicture}(16,5)
        \drawpart(%Coordinates here
        ){Seed}
        \drawpart(%Coordinates here
        ){Amp}
        
        %Connect both setups
        \drawfiber[linecolor=green](Seed)(Amp)
    \end{pspicture}
\end{document}

Is that possible at all? Or are there other ways to achieve my goal (i.e. simplifying my code when reusing blocks) I could use?

1 Answer 1

2

You can define a simple command with \def, which takes as input parameters the component's coordinate and the name of the respective input/output node for connecting different components. The positioning is then done with PSTricks' \rput.

You can of course move the component definitions to an other file an include it with \input{mycomponents}

\documentclass[margin=5pt]{standalone}
\usepackage[dvipsnames,svgnames,pdf]{pstricks}
\usepackage{pdftricks}
\usepackage{auto-pst-pdf}
\usepackage{pst-optexp}
\usepackage{stackengine}
% Simple seed laser
%
% #1 is the coordinate where to position the component
% #2 is the name of the output node
\def\SimpleSeedLaser(#1)#2{%
  \rput(#1){%
    \def\SeedOutput{#2}%
    \pnodes(1, 1){DiodeIn}
    \pnode(6, 1){\SeedOutput}
    \optdiode[compname=SeedDiode, position=start](DiodeIn)(\SeedOutput){%
      \begin{tabular}{@{}c@{}}Laser\\diode\end{tabular}}
    \optfiber[compname=SeedFiber,compshift=-1,label=-1.5.l, addtoFiberOut={ArrowInside=->}](DiodeIn)(\SeedOutput){%
      \begin{tabular}{@{}c@{}}Active\\Fiber\end{tabular}}
    \nput{90}{\SeedOutput}{Seed Output}
  }%
}%
% Simple amplifier
% #1 is the coordinate where to position the component
% #2 is the name of the input node
\def\SimpleAmplifier(#1)#2{%
  \rput(#1){%
    \def\AmpIn{#2}%
    \pnodes(0, 1){\AmpIn}
    \pnodes(3, 1){ActiveFiberIn}(5, 1){ActiveFiberOut}
    \pnodes(0, 4){PumpDiodeIn}(1, 4){PumpDiodeOut}
    \pnode(6, 2){AmpOut}
    \optdiode[compname=AmpDiode, position=start](PumpDiodeIn)(PumpDiodeOut){%
      \begin{tabular}{@{}c@{}}Laser\\diode\end{tabular}}
    \wdmcoupler[compname=SignalPumpCombiner, coupleralign=bottom, couplersize=0.35, fiber=i](PumpDiodeIn)(\AmpIn)(ActiveFiberIn){%
      \begin{tabular}{@{}c@{}}Pump\\Combiner\end{tabular}}
    \optfiber[compname=PumpFiber, compshift=-1,label=-1.5.l, fiber=i](\oenodeOut{SignalPumpCombiner})(ActiveFiberOut){Active fiber}
        
    \nput{-90}{\AmpIn}{Amp Input}
    \nput{90}{AmpOut}{Amp Output}
        
    \drawfiber[ArrowInside=->, arrows=->]{PumpFiber}(AmpOut)
  }%
}%
\begin{document}
    \begin{pspicture}(16,5)
        \newpsstyle{Fiber}{linecolor=orange, linewidth=2\pslinewidth}
        \SimpleSeedLaser(0,0){SeedOutput}

        %\psset[optexp]{fiber=none}
        \SimpleAmplifier(8,0){AmpIn}
        
        %Connect both setups
        \drawfiber[linecolor=green](SeedOutput)(AmpIn)
    \end{pspicture}
\end{document}

enter image description here

Note, that I did some further optimizations of your code.

  • In general it is not necessary to remove all automatically drawn fibers with \psset{fiber=none}. The seed laser requires only two nodes at all, which can be used for all components. If you select the correct nodes, the automatically drawn fibers are fine.

  • You can also fine-tune which fibers are draw. For the coupler I used fibers=i, which draws both input fibers, but not the output fiber.

  • Use addtoFiber* only, if you draw fibers together with the components at all. Otherwise those settings have no effect.

  • You can use the various \oenode-commands to access component nodes, if they are needed e.g. for positioning of components. I used it to draw the active fiber with the automatic input fiber. SO only the output fiber must be drawn explicitely, because of the shift with respect to the rest of the components.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .