(* ::Package:: *) (* Copyright 2004-2010 Sascha Husa, Ian Hinder, Christiane Lechner, Barry Wardell This file is part of Kranc. Kranc is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. Kranc is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Kranc; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *) (****************************************************************************) (* Wrapper providing tensor support to Kranc (from TensorTools or xTensor) *) (****************************************************************************) If[!ValueQ[$KrancTensorPackage], $KrancTensorPackage = "TensorToolsKranc`"]; BeginPackage["KrancTensor`", {"Errors`", "KrancThorn`", "MapLookup`", "KrancGroups`", "Kranc`", $KrancTensorPackage}]; CreateKrancThornTT::usage = "Construct a Kranc thorn using tensor expressions."; (* FIXME: Move CreateGroupFromTensor here *) Begin["`Private`"]; (* -------------------------------------------------------------------------- Tensor Tools -------------------------------------------------------------------------- *) CreateKrancThornTT[groups_, parentDirectory_, thornName_, opts___] := Module[{calcs, expCalcs, expGroups, options, derivs, expDerivs, reflectionSymmetries, declaredGroups}, InfoMessage[Terse, "Processing tensorial arguments"]; calcs = lookup[{opts}, Calculations]; derivs = lookupDefault[{opts}, PartialDerivatives, {}]; Map[CheckCalculationTensors, calcs]; expCalcs = Map[makeCalculationExplicit, calcs]; InfoMessage[Info, "Group definitions:", groups]; VerifyGroups[groups]; expDerivs = Flatten[Map[ExpandComponents,derivs],1]; expGroups = Map[makeGroupExplicit, groups]; options = Join[DeleteCases[{opts}, Calculations -> _], {Calculations -> expCalcs}]; options = Join[DeleteCases[options, PartialDerivatives -> _], {PartialDerivatives -> expDerivs}]; declaredGroups = lookupDefault[{opts}, DeclaredGroups, {}]; evolutionTimelevels = lookupDefault[{opts}, EvolutionTimelevels, 3]; defaultEvolutionTimelevels = lookupDefault[{opts}, DefaultEvolutionTimelevels, evolutionTimelevels]; InfoMessage[Info, "Declared groups: " <> ToString[declaredGroups]]; InfoMessage[Terse, "Computing reflection symmetries"]; reflectionSymmetries = computeReflectionSymmetries[declaredGroups, groups]; InfoMessage[Info, "Reflection symmetries: ", reflectionSymmetries]; InfoMessage[Terse, "Creating (component-based) Kranc thorn"]; (* It is necessary to include the KrancThorn context here due to some annoying Needs[] dependency issue *) KrancThorn`CreateKrancThorn[expGroups, parentDirectory, thornName, Apply[Sequence, options], ReflectionSymmetries -> reflectionSymmetries]]; computeReflectionSymmetries[declaredGroups_, groups_] := Module[{variables, syms}, variables = variablesFromGroups[declaredGroups, groups]; syms = Flatten[Map[ReflectionSymmetries, variables], 1]; syms]; makeCalculationExplicit[calc_] := mapValueMapMultiple[calc, {Shorthands -> ExpandComponents, CollectList -> ExpandComponents, Equations -> ExpandComponents}]; makeGroupExplicit[g_] := Module[{variables, newVariables, newGroup}, variables = groupVariables[g]; newVariables = DeleteDuplicates[ExpandComponents[variables]]; newGroup = SetGroupVariables[g, newVariables]; newGroup]; End[]; EndPackage[];