demisjohn / pyFIMM

Python Interface to PhotonDesign's FimmWave/FimmProp software.
15 stars 4 forks source link

Waveguide.get_buildnode_str(): add arg for `add_nodes=True` #64

Closed demisjohn closed 8 years ago

demisjohn commented 8 years ago

optional argument add_nodes=True.

Put corresponding conditional on each line that actually adds a new node (as opposed to updating some value).

Eg. Orig:

fpString += self.nodestring + ".addSlice( %someparam )"

New:

if add_nodes: fpString += self.nodestring + ".addSlice( %someparam )"

But leave all lines that don't add a new node, such as

fpString += self.nodestring + ".n11 = %f" %(self.material.refractiveindex_or_whatever)
demisjohn commented 8 years ago

Eric (@estanton22), I see in _Waveguide.py, you have (line 423):

    if update_node:
        overwrite=True
        node_num = self.num
    else:
        N_nodes = fimm.Exec(nodestring + ".numsubnodes()")
        node_num = int(N_nodes+1)
        wgString = self.parent.nodestring + ".addsubnode(rwguideNode,"+str(self.name)+")"+"\n"  # make RWG node

    self._checkNodeName(nodestring, overwrite=overwrite, warn=warn)     # will alter the node name if needed
    self.num = node_num    

But if update_node=True you don't want _checkNodeName to delete the node.

Instead, move checkNodeName into the conditional, so it only runs if update_node=False, like so:

    if update_node:
        #- - removed overwrite
        node_num = self.num
    else:
        #- - added checknondename here
        self._checkNodeName(nodestring, overwrite=overwrite, warn=warn)     # will alter the node name if needed
        N_nodes = fimm.Exec(nodestring + ".numsubnodes()")
        node_num = int(N_nodes+1)
        wgString = self.parent.nodestring + ".addsubnode(rwguideNode,"+str(self.name)+")"+"\n"  # make RWG node

    self.num = node_num    

This is implemented in d0004d176bdcc0a73e1a6be6d61fe7c07ec953f3