Class JMadModelImpl

    • Field Detail

      • LOGGER

        protected static final org.slf4j.Logger LOGGER
        The logger for the class
      • dirtyModel

        protected boolean dirtyModel
        true, if some strengthes have been set since last recalc of optics
    • Constructor Detail

      • JMadModelImpl

        public JMadModelImpl()
    • Method Detail

      • readTable

        public void readTable​(java.io.File file,
                              java.lang.String tableName)
        instructs madx to read a table from a file.

        If a tableName is given, then the ReadMyTableCommand is used and the table is stored in the given table name. If the name is null, then the tablename must be given in the file.

        Parameters:
        file - the file from which to load the table
        tableName - the name of the table (lowercase!)
      • reset

        public void reset()
                   throws JMadModelException
        Description copied from interface: JMadModel
        resets the model. Preserves the elements-state: if they are initialized, they will be reinitialized, otherwise not.
        Specified by:
        reset in interface JMadModel
        Throws:
        JMadModelException - if the reset fails
      • isInitialized

        public boolean isInitialized()
        Specified by:
        isInitialized in interface JMadModel
        Returns:
        true if the model is initialized, false otherwise.
      • getKernel

        public JMadKernel getKernel()
        Description copied from interface: JMadModel
        This method retrieves the JMadKernel to which the model sends its commands. Use with care!
        Specified by:
        getKernel in interface JMadModel
        Returns:
        the kernel of the model.
      • getValues

        public java.util.List<java.lang.Double> getValues​(java.util.List<java.lang.String> valueNames)
                                                   throws JMadModelException
        Description copied from interface: JMadModel
        reads multiple values from the model which are given by their names
        Specified by:
        getValues in interface JMadModel
        Parameters:
        valueNames - the names of the values to read
        Returns:
        the values
        Throws:
        JMadModelException - if the retrieval of the values fails
      • getValueMap

        public java.util.Map<java.lang.String,​java.lang.Double> getValueMap​(java.util.Collection<java.lang.String> valueNames)
                                                                           throws JMadModelException
        Description copied from interface: JMadModel
        reads multiple values from the model given by their names to a map. The non-null map contains the mappings between valueName and read value, if the read operation was successful.
        Specified by:
        getValueMap in interface JMadModel
        Parameters:
        valueNames - the names of the values to read
        Returns:
        a guaranteed non-null map, containing the mappings of the read values
        Throws:
        JMadModelException
      • getValue

        public double getValue​(java.lang.String valueName)
                        throws JMadModelException
        Description copied from interface: JMadModel
        retrieves the value as defined by its name from madx.
        Specified by:
        getValue in interface JMadModel
        Parameters:
        valueName - the name of the value
        Returns:
        the actual value
        Throws:
        JMadModelException - if the retrieval of the values fails
      • setMisalignments

        protected void setMisalignments​(java.util.List<MisalignmentConfiguration> misalignmentConfigurations)
        sends the misalignment-commands to madx
        Parameters:
        misalignmentConfigurations - the misalignment-configurations from which to create the commands
      • twiss

        public TfsResult twiss​(TfsResultRequest resultRequest)
                        throws JMadModelException
        Description copied from interface: JMadModel
        runs the twiss with the given given ResultRequest and the initial conditions defined in the model.
        Specified by:
        twiss in interface JMadModel
        Parameters:
        resultRequest - the requested result
        Returns:
        the result of the twiss
        Throws:
        JMadModelException - if the twiss calculations fail
      • twissToFile

        public TfsResult twissToFile​(TfsResultRequest resultRequest,
                                     java.io.File tfsFile)
                              throws JMadModelException
        Description copied from interface: JMadModel
        run a twiss with the given given ResultRequest and the initial conditions defined in the model and write to file.
        Specified by:
        twissToFile in interface JMadModel
        Parameters:
        resultRequest - the requested result
        tfsFile - the file to write the twiss to
        Returns:
        The tfsresult from the twiss
        Throws:
        JMadModelException - if the twiss calculations fail
      • twissToFile

        public TfsResult twissToFile​(TfsResultRequest resultRequest,
                                     TwissInitialConditions customTwissInitialConditions,
                                     java.io.File tfsFile)
                              throws JMadModelException
        Description copied from interface: JMadModel
        run a twiss with the given initial conditions. And write to file. NOTE: This changes nothing in the state of the model
        Specified by:
        twissToFile in interface JMadModel
        Parameters:
        resultRequest - the requested result
        customTwissInitialConditions - the initial conditions to use
        tfsFile - the file to write the twiss to
        Returns:
        The tfs result, which is also written to the file
        Throws:
        JMadModelException - if the twiss calculations fail
      • twiss

        public TfsResult twiss​(TfsResultRequest resultRequest,
                               TwissInitialConditions customTwissInitialConditions)
                        throws JMadModelException
        Description copied from interface: JMadModel
        runs the twiss with the given initial conditions. NOTE: This changes nothing in the state of the model
        Specified by:
        twiss in interface JMadModel
        Parameters:
        resultRequest - the requested result
        customTwissInitialConditions - the initial conditions to use
        Returns:
        the result of the twiss
        Throws:
        JMadModelException - if the twiss calculations fail
      • setValue

        public void setValue​(java.lang.String name,
                             double value)
                      throws JMadModelException
        Description copied from interface: JMadModel
        sets a value as defined by its name directly in madx.
        Specified by:
        setValue in interface JMadModel
        Parameters:
        name - the name of the value to set
        value - the value to set
        Throws:
        JMadModelException - if setting the value to MadX fails
      • setValues

        public void setValues​(java.util.Map<java.lang.String,​java.lang.Double> valueNamePairs)
                       throws JMadModelException
        Description copied from interface: JMadModel
        sets a List of value - name pairs directly in madx
        Specified by:
        setValues in interface JMadModel
        Parameters:
        valueNamePairs - the Map containing madx parameter names and values to assign
        Throws:
        JMadModelException - if setting the values to MadX fails
      • finalize

        protected void finalize()
                         throws java.lang.Throwable
        Overrides:
        finalize in class java.lang.Object
        Throws:
        java.lang.Throwable
      • getKnobManager

        public KnobManager getKnobManager()
        Specified by:
        getKnobManager in interface JMadModel
        Returns:
        the manager, which contains all the model specific knobs.
      • getName

        public java.lang.String getName()
        Specified by:
        getName in interface JMadModel
        Returns:
        the name of the model containing
        • ModelDefinition Name
        • current Sequence Name
      • setActiveOpticsDefinition

        public void setActiveOpticsDefinition​(OpticsDefinition newActiveOpticsDefinition)
                                       throws JMadModelException
        Description copied from interface: JMadModel
        applies the values of the strengths given by the provided OpticsDefinition to the model. after loading of the optic it reloads the active RangeDefinition. This behavior is necessary, as some of the optics require re-matching of both beams combined. That can result in a different Range being active after the loading of the optics.
        Specified by:
        setActiveOpticsDefinition in interface JMadModel
        Parameters:
        newActiveOpticsDefinition - the optics definition to set as the active one
        Throws:
        JMadModelException - in case setting the active range fails
      • setTwissInitialConditions

        public void setTwissInitialConditions​(TwissInitialConditions twissInitialConditions)
      • addListener

        public void addListener​(JMadModelListener listener)
        Description copied from interface: JMadModel
        add a ModelListener
        Specified by:
        addListener in interface JMadModel
        Parameters:
        listener - the listener to add
      • execute

        public void execute​(java.lang.String cmd)
        Description copied from interface: JMadModel
        executes the given string directly in madx. (must also contain ";" at the end!) Use with care!
        Specified by:
        execute in interface JMadModel
        Parameters:
        cmd - the string to execute
      • call

        public void call​(java.io.File file)
        Description copied from interface: JMadModel
        calls a file from madx.
        Specified by:
        call in interface JMadModel
        Parameters:
        file - the file to call
      • fireBecameDirty

        protected void fireBecameDirty()
        notify all listeners, that some values changed, so that the actual data is no longer valid.
      • match

        public MatchResult match​(MatchResultRequest resultRequest)
                          throws JMadModelException
        Description copied from interface: JMadModel
        Run a MadX Matching Command on the JMad Model

        If no Sequence is specified in the MatchResultRequest the actual Sequence will be used for matching as enabled with the last setActiveRange command.

        After the Matching changes to the model are updated accordingly

        Specified by:
        match in interface JMadModel
        Parameters:
        resultRequest - the Matching Request containing relevant parameters
        Returns:
        the MatchResult as retrieved from MadX
        Throws:
        JMadModelException - if the matching fails
      • saveBeta

        public void saveBeta​(java.lang.String name,
                             java.lang.String location,
                             boolean runDummyTwiss)
                      throws JMadModelException
        Description copied from interface: JMadModel
        Execute the MadX SaveBeta Function, which saves the Optical Functions Values for a given location with the next twiss command inside MadX
        Specified by:
        saveBeta in interface JMadModel
        Parameters:
        name - the MadX internal Name for the SaveBeta
        location - the location in the sequence where to save the Optical Functions Values
        runDummyTwiss - if true a 'twiss;' command is send directly after the saveBeta
        Throws:
        JMadModelException
      • calcTwissSummary

        public TfsSummary calcTwissSummary()
                                    throws JMadModelException
        Description copied from interface: JMadModel
        Function issues a single twiss and returns only the summary of the resulting TfsResult. This is nothing else than a shortcut to

        twiss(TfsResultRequest.createSummaryOnlyRequest()).getSummary()

        Specified by:
        calcTwissSummary in interface JMadModel
        Returns:
        the summary part of the actually valid twiss result.
        Throws:
        JMadModelException - if the twiss fails.
      • loadAperture

        public void loadAperture()
        Description copied from interface: JMadModel
        loads all the aperture-files to the model aperture
        Specified by:
        loadAperture in interface JMadModel
      • setKernel

        public void setKernel​(JMadKernel kernel)
      • setModelFileFinderManager

        public void setModelFileFinderManager​(ModelFileFinderManager modelFileFinderManager)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • getDescription

        public java.lang.String getDescription()
        Specified by:
        getDescription in interface JMadModel
        Returns:
        the current description of the Model containing
        • ModelDefinition Name
        • current Sequence Name
        • current Range Name
        • current Optic Name
      • setMode

        public void setMode​(ModelMode modelMode)
        Specified by:
        setMode in interface JMadModel
        Parameters:
        modelMode - defines if normal madx or ptc is used
      • setTitle

        public void setTitle​(java.lang.String title)
        Specified by:
        setTitle in interface JMadModel
        Parameters:
        title - the title to set in MadX for the following twiss-commands
      • getMisalignments

        public java.util.List<MisalignmentConfiguration> getMisalignments()
        Description copied from interface: JMadModel
        NOTE: due to incubation form of this method ONLY QUADRUPOLE elements are extracted!
        Specified by:
        getMisalignments in interface JMadModel
        Returns:
        a complete list of an actual machine imperfections accordingly to the requested definition (see: Range addMisalignments(), addMisalignment())
      • getVariableValue

        protected java.lang.Double getVariableValue​(TfsResult misalignmentsRaw,
                                                    java.lang.Integer elementIndex,
                                                    EalignVariables variable)
        Parameters:
        misalignmentsRaw -
        elementIndex -
        variable -
        Returns:
      • setStrengthVarManager

        public void setStrengthVarManager​(StrengthVarManager strengthVarManager)