Warp Factory
  • What is Warp Factory?
  • Overview
    • Installing Warp Factory
    • Workflow
    • Codebase Structure
    • Object Types
    • Frames
  • Examples
    • Metrics
      • M1 - First Metric
      • M2 - Default Metrics
      • M3 - Building a Metric
    • Energy Tensor
      • T1 - First Energy Tensor
      • T2 - Cartoon Methods
      • T3 - GPU Computation
      • T4 - Solver Order
      • T5 - Errors
    • Analysis
      • A1 - Energy Conditions
      • A2 - Metric Scalars
      • A3 - Eval Metric
      • A4 - Momentum Flow
    • Warp Shell
      • W1 Warp Shell Comoving
  • Modules
    • Metrics Module
      • Metric Library
        • metricGet_Minkowski
        • metricGet_Alcubierre
        • metricGet_Lentz
        • metricGet_VanDenBroeck
        • metricGet_WarpShellComoving
        • metricGet_ModifiedTime
        • metricGet_Schwarzschild
      • Metric Functions
        • setMinkowski
        • setMinkowskiThreePlusOne
        • threePlusOneBuilder
        • threePlusOneDecomposer
    • Analyzer Module
      • getMomentumFlowLines
      • doFrameTransfer
      • changeTensorIndex
      • getScalars
      • getEnergyConditions
      • evalMetric
    • Solver Module
      • getEnergyTensor
      • verifyTensor
    • Visualizer Module
      • plotThreePlusOne
      • plotTensor
      • Plot Functions
    • Units Module
  • General
    • Contributing
    • FAQ
    • Citing Warp Factory
Powered by GitBook
On this page
  • Building a Custom Metric
  • Needed properties
  • Step-by-Step
  • Create a new MATLAB function file
  • Replace the function definition with
  • Define needed properties besides tensor
  • Define metric tensor components
  • End the function
  • Calling Your Function
  • 3+1 Definition
  1. Examples
  2. Metrics

M3 - Building a Metric

Building a Custom Metric

Now that you understand the basics of metrics, let's provide the foundation for building a custom metric.

Needed properties

A custom metric will require all of the properties described in the first metric example. Namely:

.type

.index

.coords

.scaling

.tensor

Step-by-Step

You can use the code blocks below as a basis for creating a custom metric in Warp Factory.

Create a new MATLAB function file

Inside the 'Metrics' folder, right-click and select New -> Function

Name the file 'myCustomMetric.m'

Replace the function definition with

function [Metric] = myCustomMetric(gridSize,worldCenter,gridScaling,[args])

Where [args] are any needed parameters to create your metric.

Define needed properties besides tensor

Metric.type = "metric";
Metric.name = "My Custom Metric";
Metric.scaling = gridScaling;
Metric.coords = "cartesian";
Metric.index = "covariant";
Metric.date = date;

Define metric tensor components

The tensor object is a 4x4 cell array. Each cell contains an array of values for each point in spacetime.

T = 1:gridSize(1);
X = 1:gridSize(2);
Y = 1:gridSize(3);
Z = 1:gridSize(4);

% Set Minkowski terms
% This sets all 4x4 terms of the tensor to flat space
% This allows you to delete flat parts of the metric in the assignments
% below
Metric.tensor = setMinkowski(gridSize);

% Assign metric terms
for h = T
    for i = X
        for j = Y
            for k = Z
                % Define grid coordinates
                t = h*gridScaling(1)-wolrdCenter(1)
                x = i*gridScaling(2)-worldCenter(2);
                y = j*gridScaling(3)-worldCenter(3);
                z = k*gridScaling(4)-worldCenter(4);
                
                % Diagonal terms
                Metric.tensor{1,1}(h,i,j,k) = % Your equations as a function of t,x,y,z here
                Metric.tensor{2,2}(h,i,j,k) = % Your equations as a function of t,x,y,z here
                Metric.tensor{3,3}(h,i,j,k) = % Your equations as a function of t,x,y,z here
                Metric.tensor{4,4}(h,i,j,k) = % Your equations as a function of t,x,y,z here

                % Time cross terms
                Metric.tensor{1,2}(h,i,j,k) = % Your equations as a function of t,x,y,z here
                Metric.tensor{1,3}(h,i,j,k) = % Your equations as a function of t,x,y,z here
                Metric.tensor{1,4}(h,i,j,k) = % Your equations as a function of t,x,y,z here
                
                % Spatial cross terms
                Metric.tensor{2,3}(h,i,j,k) = % Your equations as a function of t,x,y,z here
                Metric.tensor{2,4}(h,i,j,k) = % Your equations as a function of t,x,y,z here
                Metric.tensor{3,4}(h,i,j,k) = % Your equations as a function of t,x,y,z here
                
                % Assign Symmetric Values
                Metric.tensor{2,1}(h,i,j,k) = Metric.tensor{1,2}(h,i,j,k);
                Metric.tensor{3,1}(h,i,j,k) = Metric.tensor{1,3}(h,i,j,k);
                Metric.tensor{4,1}(h,i,j,k) = Metric.tensor{1,4}(h,i,j,k);
                Metric.tensor{3,2}(h,i,j,k) = Metric.tensor{2,3}(h,i,j,k);
                Metric.tensor{4,2}(h,i,j,k) = Metric.tensor{2,4}(h,i,j,k);
                Metric.tensor{4,3}(h,i,j,k) = Metric.tensor{3,4}(h,i,j,k);
            end
        end
    end
end

End the function

end

Calling Your Function

In the Command Window or in custom script, your metric can be called via:

% Specify default args
gridSize = [1 20 20 20];
worldCenter = (gridSize+1)./2;
gridScaling = [1 1 1 1];

% Specify custom args here
args = 

Metric = myCustomMetric(gridSize,worldCenter,gridScaling,[args]);

3+1 Definition

Similar to building your metric directly via the metric tensor components, you can also build your metric via the 3+1 components.

The defining metric tensor components section gets changed to:

T = 1:gridSize(1);
X = 1:gridSize(2);
Y = 1:gridSize(3);
Z = 1:gridSize(4);

% Set Minkowski terms
% This sets all 4x4 3+1 components to that flat space
% This allows you to delete flat parts of the 3+1 in the assignments
% below
[alpha, beta, gamma] = setMinkowskiThreePlusOne(gridSize);

% Assign 3+1 terms
for h = T
    for i = X
        for j = Y
            for k = Z
                % Define grid coordinates
                t = h*gridScaling(1)-worldCenter(1)
                x = i*gridScaling(2)-worldCenter(2);
                y = j*gridScaling(3)-worldCenter(3);
                z = k*gridScaling(4)-worldCenter(4);
                
                % Alpha term
                alpha(h,i,j,k) = % Your equations as a function of t,x,y,z here

                % Beta terms
                beta{1}(h,i,j,k) = % Your equations as a function of t,x,y,z here
                beta{2}(h,i,j,k) = % Your equations as a function of t,x,y,z here
                beta{3}(h,i,j,k) = % Your equations as a function of t,x,y,z here
                
                % Gamma terms
                gamma{1,1}(h,i,j,k) = % Your equations as a function of t,x,y,z here
                gamma{2,2}(h,i,j,k) = % Your equations as a function of t,x,y,z here
                gamma{3,3}(h,i,j,k) = % Your equations as a function of t,x,y,z here
                gamma{1,2}(h,i,j,k) = % Your equations as a function of t,x,y,z here
                gamma{1,3}(h,i,j,k) = % Your equations as a function of t,x,y,z here
                gamma{2,3}(h,i,j,k) = % Your equations as a function of t,x,y,z here
                
                % Assign Symmetric Gamma Terms
                gamma{2,1}(h,i,j,k) = gamma{1,2}(h,i,j,k);
                gamma{3,1}(h,i,j,k) = gamma{1,3}(h,i,j,k);
                gamma{3,2}(h,i,j,k) = gamma{2,3}(h,i,j,k);
            end
        end
    end
end

% Convert 3+1 terms into the Metric
Metric.tensor = threePlusOneBuilder(alpha,beta,gamma);

PreviousM2 - Default MetricsNextEnergy Tensor

Last updated 1 year ago