Repository navigation
Use intermediate variables for Complex if-expressions in ComplexBlocks - #4847
Open
hubertus65 wants to merge 1 commit into
Open
hubertus65 wants to merge 1 commit into
hubertus65 wants to merge 1 commit into
Conversation
Feedback, Gain, Division and Add3 of ComplexBlocks.ComplexMath and Sources.ComplexStep wrote Complex if-expressions inline in the equation of their output connector, e.g. y = k*(if useConjugateInput then Modelica.ComplexMath.conj(u) else u); OCT (Modelon Impact) generates C code that does not compile for this: it contains the record constructor of the connector type Modelica.ComplexBlocks.Interfaces.ComplexOutput(...). As a result these five blocks cannot be used in Impact at all. Assign the if-expression to a protected Complex variable first, as Add and Product already do through the u1Internal/u2Internal variables of Interfaces.ComplexSI2SO (Division extends that base class too and now uses them). The public interface is unchanged. OpenModelica 1.27.1 gives bit-identical results before and after the change for the ComplexBlocks examples ShowTransferFunction and TestConversionBlock and for four ModelicaTest models using all five blocks. With the change, OCT compiles and simulates the blocks and matches the OpenModelica results. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UmNZkRw6HV9CeBvNk36AzT
This was referenced Oct 31, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Four blocks of
Modelica.ComplexBlocks.ComplexMath(Feedback,Gain,Division,Add3) andModelica.ComplexBlocks.Sources.ComplexStepwrite a Complex if-expression inline in the equation of their output connector:OCT, the compiler of Modelon Impact, generates C code for these equations that does not compile. The code contains the record constructor of the connector type,
Modelica.ComplexBlocks.Interfaces.ComplexOutput(...). As a result none of the five blocks can be used in Impact, with or without conjugated inputs.Other blocks of the same package are not affected.
AddandProductfirst assign the if-expression to a protected variable (u1Internal,u2InternalfromInterfaces.ComplexSI2SO, oruInternalfromInterfaces.ComplexSISO).This PR applies that existing pattern to the five blocks:
uInternal, theny = k*uInternalu1Internal,u2Internalu1Internal…u3InternalComplexSI2SO; now uses itsu1Internal/u2Internalinstead of repeating the if-expressionsstepValuePublic interfaces, parameters and documentation are unchanged.
Verification
ComplexBlocks.Examples.ShowTransferFunctionComplexBlocks.Examples.TestConversionBlockFeedback,Gain,Division,Add3, with and without conjugationComplexStepThe "after" column for OCT was produced with copies of the patched classes, since Impact ships its own MSL. The test models are part of the ModelicaTest coverage work on branch
coverage-improvement.🤖 Generated with Claude Code
https://claude.ai/code/session_01UmNZkRw6HV9CeBvNk36AzT