From b3c24e5eae1e887a546f74cdf2310ef361eef1b7 Mon Sep 17 00:00:00 2001 From: Ian Hinder Date: Fri, 13 Sep 2013 15:03:34 +0200 Subject: KrancThorn.m: Eliminate most temporary variables in CreateKrancThorn --- Tools/CodeGen/KrancThorn.m | 62 +++++++++++++++++----------------------------- 1 file changed, 23 insertions(+), 39 deletions(-) (limited to 'Tools/CodeGen') diff --git a/Tools/CodeGen/KrancThorn.m b/Tools/CodeGen/KrancThorn.m index eb0acbc..92a481c 100644 --- a/Tools/CodeGen/KrancThorn.m +++ b/Tools/CodeGen/KrancThorn.m @@ -62,18 +62,7 @@ DefFn[ Options[CreateKrancThorn] = ThornOptions; CreateKrancThorn[groupsOrig_, parentDirectory_, thornName_, opts:OptionsPattern[]] := - Module[{calcs, declaredGroups, odeGroups, implementation, - inheritedImplementations, includeFiles, - evolutionTimelevels, defaultEvolutionTimelevels, - parameters, - configuration, - partialDerivs, evolvedGroups, rhsGroups, nonevolvedGroups, - interface, evolvedGroupDefinitions, - evolvedODEGroups, nonevolvedODEGroups, - evolvedODEGroupDefinitions, rhsODEGroups, - cakernel, - sources = {}, - c}, + Module[{configuration, interface, schedule, param, make, cakernel, c}, InfoMessage[Terse, "Processing arguments to CreateKrancThorn"]; @@ -83,30 +72,23 @@ CreateKrancThorn[groupsOrig_, parentDirectory_, thornName_, opts:OptionsPattern[ cktCheckNamedArgs[{opts}]; - calcs = OptionValue[Calculations]; - declaredGroups = OptionValue[DeclaredGroups]; - odeGroups = OptionValue[ODEGroups]; - implementation = If[OptionValue[Implementation] =!= None, - OptionValue[Implementation], - thornName]; - inheritedImplementations = OptionValue[InheritedImplementations]; - includeFiles = OptionValue[IncludeFiles]; - evolutionTimelevels = OptionValue[EvolutionTimelevels]; (* Redundant *) - defaultEvolutionTimelevels = lookupDefault[{opts}, DefaultEvolutionTimelevels, evolutionTimelevels]; - partialDerivs = OptionValue[PartialDerivatives]; - - c = NewObject[Code, {"Name" -> thornName, - "Groups" -> groupsOrig, - "DeclaredGroups" -> declaredGroups, - "Calculations" -> calcs, - "ODEGroups" -> odeGroups, - "Implementation" -> implementation, - "InheritedImplementations" -> inheritedImplementations, - "IncludeFiles" -> includeFiles, - "EvolutionTimelevels" -> evolutionTimelevels, - "DefaultEvolutionTimelevels" -> defaultEvolutionTimelevels, - "PartialDerivatives" -> partialDerivs, - "Sources" -> {}}]; + c = NewObject[ + Code, + {"Name" -> thornName, + "Groups" -> groupsOrig, + "DeclaredGroups" -> OptionValue[DeclaredGroups], + "Calculations" -> OptionValue[Calculations], + "ODEGroups" -> OptionValue[ODEGroups], + "Implementation" -> If[OptionValue[Implementation] =!= None, + OptionValue[Implementation], + thornName], + "InheritedImplementations" -> OptionValue[InheritedImplementations], + "IncludeFiles" -> OptionValue[IncludeFiles], + "EvolutionTimelevels" -> OptionValue[EvolutionTimelevels], + "DefaultEvolutionTimelevels" -> lookupDefault[{opts}, DefaultEvolutionTimelevels, + OptionValue[EvolutionTimelevels]], + "PartialDerivatives" -> OptionValue[PartialDerivatives], + "Sources" -> {}}]; (* ------------------------------------------------------------------------ Add required include files @@ -135,8 +117,8 @@ CreateKrancThorn[groupsOrig_, parentDirectory_, thornName_, opts:OptionsPattern[ {calcs = GetObjectField[c, "Calculations"]}, calcs = Map[mapReplaceAdd[#, Shorthands, Join[lookup[#,Shorthands,{}],OptionValue[Shorthands]]] &, calcs]; - calcs = Map[Append[#, Implementation -> implementation] &, calcs]; - calcs = Map[Append[#, PartialDerivatives -> partialDerivs] &, calcs]; + calcs = Map[Append[#, Implementation -> GetObjectField[c, "Implementation"]] &, calcs]; + calcs = Map[Append[#, PartialDerivatives -> GetObjectField[c, "PartialDerivatives"]] &, calcs]; SetObjectField[c, "Calculations", calcs]]; (* ------------------------------------------------------------------------ @@ -323,7 +305,9 @@ CreateKrancThorn[groupsOrig_, parentDirectory_, thornName_, opts:OptionsPattern[ {Filename -> "RegisterMoL.cc", Contents -> CreateKrancMoLRegister[ evolvedGroups, nonevolvedGroups, evolvedODEGroups, - nonevolvedODEGroups, groups, implementation, thornName]}]]; + nonevolvedODEGroups, + Sequence@@(GetObjectField[c,#]& /@ + {"Groups", "Implementation", "Name"})]}]]; (* ------------------------------------------------------------------------ Add options to calculations -- cgit v1.2.3