{"action":"closed","issue":{"url":"https://api.github.com/repos/tbeu/Modelica/issues/1335","repository_url":"https://api.github.com/repos/tbeu/Modelica","labels_url":"https://api.github.com/repos/tbeu/Modelica/issues/1335/labels{/name}","comments_url":"https://api.github.com/repos/tbeu/Modelica/issues/1335/comments","events_url":"https://api.github.com/repos/tbeu/Modelica/issues/1335/events","html_url":"https://github.com/tbeu/Modelica/issues/1335","id":197586327,"number":1335,"title":"Problem with StepSmoother","user":{"login":"modelica-trac-importer","id":22202507,"avatar_url":"https://avatars.githubusercontent.com/u/22202507?v=3","gravatar_id":"","url":"https://api.github.com/users/modelica-trac-importer","html_url":"https://github.com/modelica-trac-importer","followers_url":"https://api.github.com/users/modelica-trac-importer/followers","following_url":"https://api.github.com/users/modelica-trac-importer/following{/other_user}","gists_url":"https://api.github.com/users/modelica-trac-importer/gists{/gist_id}","starred_url":"https://api.github.com/users/modelica-trac-importer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/modelica-trac-importer/subscriptions","organizations_url":"https://api.github.com/users/modelica-trac-importer/orgs","repos_url":"https://api.github.com/users/modelica-trac-importer/repos","events_url":"https://api.github.com/users/modelica-trac-importer/events{/privacy}","received_events_url":"https://api.github.com/users/modelica-trac-importer/received_events","type":"User","site_admin":false},"labels":[{"id":506762997,"url":"https://api.github.com/repos/tbeu/Modelica/labels/bug","name":"bug","color":"ee0701","default":true},{"id":506769262,"url":"https://api.github.com/repos/tbeu/Modelica/labels/L:Fluid.Dissipation","name":"L:Fluid.Dissipation","color":"0000aa","default":false}],"state":"closed","locked":false,"assignee":{"login":"beutlich","id":14896695,"avatar_url":"https://avatars.githubusercontent.com/u/14896695?v=3","gravatar_id":"","url":"https://api.github.com/users/beutlich","html_url":"https://github.com/beutlich","followers_url":"https://api.github.com/users/beutlich/followers","following_url":"https://api.github.com/users/beutlich/following{/other_user}","gists_url":"https://api.github.com/users/beutlich/gists{/gist_id}","starred_url":"https://api.github.com/users/beutlich/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/beutlich/subscriptions","organizations_url":"https://api.github.com/users/beutlich/orgs","repos_url":"https://api.github.com/users/beutlich/repos","events_url":"https://api.github.com/users/beutlich/events{/privacy}","received_events_url":"https://api.github.com/users/beutlich/received_events","type":"User","site_admin":false},"assignees":[{"login":"beutlich","id":14896695,"avatar_url":"https://avatars.githubusercontent.com/u/14896695?v=3","gravatar_id":"","url":"https://api.github.com/users/beutlich","html_url":"https://github.com/beutlich","followers_url":"https://api.github.com/users/beutlich/followers","following_url":"https://api.github.com/users/beutlich/following{/other_user}","gists_url":"https://api.github.com/users/beutlich/gists{/gist_id}","starred_url":"https://api.github.com/users/beutlich/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/beutlich/subscriptions","organizations_url":"https://api.github.com/users/beutlich/orgs","repos_url":"https://api.github.com/users/beutlich/repos","events_url":"https://api.github.com/users/beutlich/events{/privacy}","received_events_url":"https://api.github.com/users/beutlich/received_events","type":"User","site_admin":false}],"milestone":{"url":"https://api.github.com/repos/tbeu/Modelica/milestones/52","html_url":"https://github.com/tbeu/Modelica/milestone/52","labels_url":"https://api.github.com/repos/tbeu/Modelica/milestones/52/labels","id":2214855,"number":52,"title":"MSL3.2.1+build.3","description":"Plan as of 84th Modelica Design Meeting:\n 1. Freeze date for maintenance build: Dec 22, 2014\n 2. Leo will run regression testing an fill a ticket for all models with non-obvious differences by Jan 2, 2015 (check \n    wiki:HowTo/MAP-LIB/ModelicaStandardLibrary/RegressionTesting for instructions how to replicate regression tests)\n 3. All library officers should react within one week, until Jan 9, 2015 (either explain the difference or fix the bug)\n 4. A web meeting is scheduled shortly after Jan 9, 2015 for a quick review and then build `v3.2.1+build.3-beta.2`\n\n","creator":{"login":"modelica-trac-importer","id":22202507,"avatar_url":"https://avatars.githubusercontent.com/u/22202507?v=3","gravatar_id":"","url":"https://api.github.com/users/modelica-trac-importer","html_url":"https://github.com/modelica-trac-importer","followers_url":"https://api.github.com/users/modelica-trac-importer/followers","following_url":"https://api.github.com/users/modelica-trac-importer/following{/other_user}","gists_url":"https://api.github.com/users/modelica-trac-importer/gists{/gist_id}","starred_url":"https://api.github.com/users/modelica-trac-importer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/modelica-trac-importer/subscriptions","organizations_url":"https://api.github.com/users/modelica-trac-importer/orgs","repos_url":"https://api.github.com/users/modelica-trac-importer/repos","events_url":"https://api.github.com/users/modelica-trac-importer/events{/privacy}","received_events_url":"https://api.github.com/users/modelica-trac-importer/received_events","type":"User","site_admin":false},"open_issues":0,"closed_issues":22,"state":"closed","created_at":"2016-12-25T13:01:13Z","updated_at":"2016-12-26T13:09:16Z","due_on":"2014-03-15T07:00:00Z","closed_at":"2016-12-25T13:01:13Z"},"comments":6,"created_at":"2016-12-26T13:07:34Z","updated_at":"2016-12-26T13:09:16Z","closed_at":"2016-12-26T13:09:16Z","body":"**Modified by dietmarw on 25 Oct 2013 20:09 UTC**\nIn MSL 3.2.1 the Modelica.Fluid.Dissipation.Utilities.Functions.General.Stepsmoother function is written as follows:\n```mo\n        function Stepsmoother \"Continuous interpolation for x \"\n\n          extends Modelica.Icons.Function;\n          input Real func \"input value for that result = 100%\";\n          input Real nofunc \"input value for that result = 0%\";\n          input Real x \"input variable for continuous interpolation\";\n          output Real result \"output value\";\n\n        protected\n          Real m=Modelica.Constants.pi/(func - nofunc);\n          Real b=-Modelica.Constants.pi/2 - m*nofunc;\n          Real r_1=tan(m*x + b);\n\n        algorithm\n          result := if x >= 0.999999*(func - nofunc) + nofunc and func > nofunc or x\n             <= 0.999999*(func - nofunc) + nofunc and nofunc > func then 1 else if x\n             <= 0.000001*(func - nofunc) + nofunc and func > nofunc or x >= 0.000001*(\n            func - nofunc) + nofunc and nofunc > func then 0 else ((0.5*(exp(r_1) - exp(\n            -r_1))/(0.5*(exp(r_1) + exp(-r_1))) + 1)/2);\n          annotation (\n            derivative=Stepsmoother_der,\n            Documentation(info=\"<html> ... </html>\"),  smoothOrder=5);\n        end Stepsmoother;\n```\nThe problem is that the value of r_1 is computed unnecessarily, and in cases where it might introduce a NaN. In addition, the final clause of the if can be written much more efficiently.\n\nThese two problems can be easily corrected by re-writing the function as follows:\n```mo\n        function Stepsmoother \"Continuous interpolation for x \"\n\n          extends Modelica.Icons.Function;\n          input Real func \"input value for that result = 100%\";\n          input Real nofunc \"input value for that result = 0%\";\n          input Real x \"input variable for continuous interpolation\";\n          output Real result \"output value\";\n\n        protected\n          Real m=Modelica.Constants.pi/(func - nofunc);\n          Real b=-Modelica.Constants.pi/2 - m*nofunc;\n\n        algorithm\n          result := if x >= 0.999999*(func - nofunc) + nofunc and func > nofunc or x\n             <= 0.999999*(func - nofunc) + nofunc and nofunc > func then 1 else if x\n             <= 0.000001*(func - nofunc) + nofunc and func > nofunc or x >= 0.000001*(\n            func - nofunc) + nofunc and nofunc > func then 0 else\n            (1-Modelica.Math.tanh(Modelica.Math.tan(m*x + b)))/2);\n          annotation (\n            derivative=Stepsmoother_der,\n            Documentation(info=\"<html> ... </html>\"),  smoothOrder=5);\n        end Stepsmoother;\n```\nNote that this problem is not present in Stepsmoother_der, the derivative of this function. In that case the efficient form is already in use.\n\n----\n\n**Reported by awittkop on 25 Oct 2013 19:48 UTC**\nIn MSL 3.2.1 the Modelica.Fluid.Dissipation.Utilities.Functions.General.Stepsmoother function is written as follows:\n\n        function Stepsmoother \"Continuous interpolation for x \"\n\n          extends Modelica.Icons.Function;\n          input Real func \"input value for that result = 100%\";\n          input Real nofunc \"input value for that result = 0%\";\n          input Real x \"input variable for continuous interpolation\";\n          output Real result \"output value\";\n\n        protected\n          Real m=Modelica.Constants.pi/(func - nofunc);\n          Real b=-Modelica.Constants.pi/2 - m\\*nofunc;\n          Real r_1=tan(m\\*x + b);\n\n        algorithm\n          result := if x >= 0.999999\\*(func - nofunc) + nofunc and func > nofunc or x\n             <= 0.999999\\*(func - nofunc) + nofunc and nofunc > func then 1 else if x\n             <= 0.000001\\*(func - nofunc) + nofunc and func > nofunc or x >= 0.000001\\*(\n            func - nofunc) + nofunc and nofunc > func then 0 else ((0.5\\*(exp(r_1) - exp(\n            -r_1))/(0.5\\*(exp(r_1) + exp(-r_1))) + 1)/2);\n          annotation (\n            derivative=Stepsmoother_der,\n            Documentation(info=\"<html> ... </html>\"),  smoothOrder=5);\n        end Stepsmoother;\n\nThe problem is that the value of r_1 is computed unnecessarily, and in cases where it might introduce a NaN. In addition, the final clause of the if can be written much more efficiently.\n\nThese two problems can be easily corrected by re-writing the function as follows:\n\n        function Stepsmoother \"Continuous interpolation for x \"\n\n          extends Modelica.Icons.Function;\n          input Real func \"input value for that result = 100%\";\n          input Real nofunc \"input value for that result = 0%\";\n          input Real x \"input variable for continuous interpolation\";\n          output Real result \"output value\";\n\n        protected\n          Real m=Modelica.Constants.pi/(func - nofunc);\n          Real b=-Modelica.Constants.pi/2 - m\\*nofunc;\n\n        algorithm\n          result := if x >= 0.999999\\*(func - nofunc) + nofunc and func > nofunc or x\n             <= 0.999999\\*(func - nofunc) + nofunc and nofunc > func then 1 else if x\n             <= 0.000001\\*(func - nofunc) + nofunc and func > nofunc or x >= 0.000001\\*(\n            func - nofunc) + nofunc and nofunc > func then 0 else\n            (1-Modelica.Math.tanh(Modelica.Math.tan(m\\*x + b)))/2);\n          annotation (\n            derivative=Stepsmoother_der,\n            Documentation(info=\"<html> ... </html>\"),  smoothOrder=5);\n        end Stepsmoother;\n\nNote that this problem is not present in Stepsmoother_der, the derivative of this function. In that case the efficient form is already in use.\n\n----\n\nMigrated-From: https://trac.modelica.org/Modelica/ticket/1335"}}
{"actor":{"display_login":"modelica-trac-importer"}}