PipeWithScalarField

model PipeWithScalarField "Visualizing a pipe with a scalar field"
    input Frames.Orientation R = Frames.nullRotation() "Orientation object to rotate the world frame into the surface frame"
        annotation (Dialog(group = "Surface frame"));
    input Modelica.SIunits.Position r_0[3] = {0, 0, 0} "Position vector from origin of world frame to origin of surface frame, resolved in world frame"
        annotation (Dialog(group = "Surface frame"));
    parameter Modelica.SIunits.Radius rOuter "Outer radius of pipe"
        annotation (Dialog(group = "Surface properties"));
    parameter Modelica.SIunits.Length length "Length of pipe"
        annotation (Dialog(group = "Surface properties"));
    parameter Integer n_rOuter = 30 "Number of points along outer radius"
        annotation (Dialog(group = "Surface properties"));
    parameter Integer n_length = 10 "Number of points along length"
        annotation (Dialog(group = "Surface properties"));
    parameter Types.SpecularCoefficient specularCoefficient = 0.7 "Reflection of ambient light (= 0: light is completely absorbed)"
        annotation (Dialog(group = "Surface properties"));
    parameter Real transparency = 0 "Transparency of shape: 0 (= opaque) ... 1 (= fully transparent)"
        annotation (Dialog(group = "Surface properties"));
    parameter Real xsi[:](each min = 0, each max = 1) = Modelica.Math.Vectors.relNodePositions(12) "[:] Relative position along the pipe with x[1] = 0, x[end] = 1"
        annotation (Dialog(group = "Color coding"));
    input Real T[size(xsi, 1)] "[:] Scalar values at position xsi*length (will be visualized by color)"
        annotation (Dialog(group = "Color coding"));
    parameter Real T_min "Minimum value of T that corresponds to colorMap[1,:]"
        annotation (Dialog(group = "Color coding"));
    parameter Real T_max "Maximum value of T that corresponds to colorMap[end,:]"
        annotation (Dialog(group = "Color coding"));
    parameter Integer n_colors = 64 "Number of colors in the colorMap"
        annotation (Dialog(group = "Color coding"));

    replaceable function colorMap = Modelica.Mechanics.MultiBody.Visualizers.Colors.ColorMaps.jet constrainedby Modelica.Mechanics.MultiBody.Interfaces.partialColorMap "Function defining the color map"
        annotation (
            choicesAllMatching = true,
            Dialog(group = "Color coding"),
            Documentation(info = "<html>\n<p>This replaceable function defines a particular color map.</p>\n<!--a placeholder to fulfill minimum documentation length-->\n</html>"));

protected
    parameter Real colorMapData[n_colors,3] = colorMap(n_colors) annotation (HideResult = true);
    Surface surface(R = R, r_0 = r_0, nu = n_length, nv = n_rOuter, wireframe = false, multiColoredSurface = true, specularCoefficient = specularCoefficient, transparency = transparency, redeclare function surfaceCharacteristic = Modelica.Mechanics.MultiBody.Visualizers.Advanced.SurfaceCharacteristics.pipeWithScalarField(rOuter = rOuter, length = length, xsi = xsi, T = T, T_min = T_min, T_max = T_max, colorMap = colorMapData)) annotation (Placement(transformation(extent = {
        {-20, 2}, 
        {0, 22}})));

    annotation (
        Icon(graphics = {
            Bitmap(
                extent = {
                    {-99, -60}, 
                    {99, 60}},
                fileName = "modelica://Modelica/Resources/Images/Mechanics/MultiBody/Visualizers/PipeWithScalarFieldIcon.png"), 
            Text(
                extent = {
                    {-150, 54}, 
                    {150, 94}},
                lineColor = {0, 0, 255},
                textString = "%name")}),
        Documentation(info = "<html>\n<p>\nModel <strong>PipeWithScalarField</strong> visualizes a pipe and a scalar\nfield along the pipe axis. The latter is shown by mapping scalar\nfield to color values with a color map and utilizing this color\nat the perimeter associated with the corresponding axis location.\nTypically the scalar field value is a temperature, but might\nbe also another quantity.\nPredefined color maps are available from\n<a href=\"modelica://Modelica.Mechanics.MultiBody.Visualizers.Colors.ColorMaps\">MultiBody.Visualizers.Colors.ColorMaps</a>\nand can be selected via parameter \"colorMap\".\nA color map with the corresponding scalar field values can be exported\nas vector-graphics in svg-format with function\n<a href=\"modelica://Modelica.Mechanics.MultiBody.Visualizers.Colors.colorMapToSvg\">MultiBody.Visualizers.Colors.colorMapToSvg</a>.\nThe position and orientation of the center of the\ncircle at the left end of the pipe is defined via parameters\n\"r_0\" and \"R\", respectively. The pipe axis is oriented along\nthe x-axis of the local coordinate system described by \"R\",\nsee figure below:\n</p>\n\n<blockquote>\n<img src=\"modelica://Modelica/Resources/Images/Mechanics/MultiBody/Visualizers/PipeWithScalarField.png\">\n</blockquote>\n\n<p>\nThe color coding is shown in the next figure. It was generated with\n<a href=\"modelica://Modelica.Mechanics.MultiBody.Visualizers.Colors.colorMapToSvg\">MultiBody.Visualizers.Colors.colorMapToSvg</a>\nusing the following call:\n</p>\n\n<blockquote>\n<pre>\ncolorMapToSvg(Modelica.Mechanics.MultiBody.Visualizers.Colors.ColorMaps.jet(),\n              height=50, nScalars=6, T_max=100, caption=\"Temperature in C\");\n</pre>\n</blockquote>\n\n<blockquote>\n<img src=\"modelica://Modelica/Resources/Images/Mechanics/MultiBody/Visualizers/PipeWithScalarField-ColorMap.png\">\n</blockquote>\n</html>"));
end PipeWithScalarField;