# A4 - Momentum Flow

## Computing Momentum Flow Lines

### Get Metric and Energy Tensor

{% code overflow="wrap" lineNumbers="true" %}

```matlab
%% Alcubierre
gridSize = [1 20 20 20];
worldCenter = (gridSize+1)./2;
velocity = 0.5;
R = 5;
sigma = 0.5;
Metric = metricGet_AlcubierreComoving(gridSize,worldCenter,velocity,R,sigma);

% Compute energy tensor
EnergyTensor = getEnergyTensor(Metric);
```

{% endcode %}

### Get Momentum Flow Lines

{% code overflow="wrap" lineNumbers="true" %}

```matlab
%% Get momentum flow lines

% Define the inputs
ngridsteps = 4;
stepSize = 0.75;
maxSteps = 10000;
scaleFactor = 1/max(abs(EnergyTensor.tensor{1,2}),[],'all');

% Build a grid of starting points using meshgrid
[X,Y,Z] = meshgrid(1:ngridsteps:gridSize(2),1:ngridsteps:gridSize(3),1:ngridsteps:gridSize(4));

% Assign the starting points into the cell format
startPoints = cell(1,3);
startPoints{1} = X;
startPoints{2} = Y;
startPoints{3} = Z;

% Find the flowline paths
[Paths] = getMomentumFlowLines(EnergyTensor, startPoints, stepSize, maxSteps, scaleFactor);
```

{% endcode %}

### Plot Momentum Flow Lines

```matlab
% Setup figure
figure()
hold on

% Define the segment of paths to plot
pathlength = 30; % length of index to plot the path
startIdx = 10; % start index

for i = 1:length(Paths)
    if size(Paths{i},1) > pathlength && length(Paths{i}) > startIdx+pathlength
        plot3(Paths{i}(startIdx:startIdx+pathlength,1), ...
            Paths{i}(startIdx:startIdx+pathlength,2), ...
            Paths{i}(startIdx:startIdx+pathlength,3),'k')
    end
end

% Set the camera view
view(45,45)
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://applied-physics.gitbook.io/warp-factory/examples/analysis/a4-momentum-flow.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
