Skip to content

Commit

Permalink
add expected output
Browse files Browse the repository at this point in the history
  • Loading branch information
sunethwarna committed Feb 2, 2024
1 parent b7de9eb commit 9a32385
Show file tree
Hide file tree
Showing 20 changed files with 530 additions and 13 deletions.
46 changes: 46 additions & 0 deletions docs/pages/Kratos/Expressions/General/Working_with_Numpy.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ numpy_nodal_expression = nodal_expression.Evaluate()
print("Shape of the numpy array = ", numpy_nodal_expression.shape)
```

Expected output:
```bash
Shape of the numpy array = (2, 3)
| / |
' / __| _` | __| _ \ __|
. \ | ( | | ( |\__ \
_|\_\_| \__,_|\__|\___/ ____/
Multi-Physics 9.4."3"-docs/expression_documentation-6de5f1a499-Release-x86_64
Compiled for GNU/Linux and Python3.11 with GCC-13.2
Compiled with threading and MPI support.
Maximum number of threads: 30.
Running without MPI.
```
## Reading from numpy arrays
First create the numpy array independent from Kratos if the number of local entities are known (i.e. number of nodes/conditions/elements in the local mesh). The following numpy data types are supported when reading numpy arrays:
1. ```numpy.int32```
Expand Down Expand Up @@ -76,6 +90,21 @@ for node in model_part.Nodes:
velocity = node.GetValue(Kratos.VELOCITY)
print(f"node id: {node.Id}, velocity: [{velocity[0]}, {velocity[1]}, {velocity[2]}]")
```
Expected output:
```bash
node id: 1, velocity: [1.0, 2.0, 3.0]
node id: 2, velocity: [3.0, 4.0, 5.0]
| / |
' / __| _` | __| _ \ __|
. \ | ( | | ( |\__ \
_|\_\_| \__,_|\__|\___/ ____/
Multi-Physics 9.4."3"-docs/expression_documentation-6de5f1a499-Release-x86_64
Compiled for GNU/Linux and Python3.11 with GCC-13.2
Compiled with threading and MPI support.
Maximum number of threads: 30.
Running without MPI.
```
## Moving from numpy arrays
This is similar to [reading from numpy arrays](#reading-from-numpy-arraystest) with the difference that this does not create a copy for the expression.
Expand Down Expand Up @@ -124,3 +153,20 @@ for node in model_part.Nodes:
velocity = node.GetValue(Kratos.VELOCITY)
print(f"node id: {node.Id}, velocity: [{velocity[0]}, {velocity[1]}, {velocity[2]}]")
```
Expected output:
```bash
node id: 1, velocity: [1.0, 2.0, 3.0]
node id: 2, velocity: [3.0, 4.0, 5.0]
node id: 1, velocity: [1.0, 2.0, 3.0]
node id: 2, velocity: [3.0, 10.0, 5.0]
| / |
' / __| _` | __| _ \ __|
. \ | ( | | ( |\__ \
_|\_\_| \__,_|\__|\___/ ____/
Multi-Physics 9.4."3"-docs/expression_documentation-6de5f1a499-Release-x86_64
Compiled for GNU/Linux and Python3.11 with GCC-13.2
Compiled with threading and MPI support.
Maximum number of threads: 30.
Running without MPI.
```
44 changes: 44 additions & 0 deletions docs/pages/Kratos/Expressions/IOs/C_Array_Expression_IO.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,21 @@ Kratos.Expression.CArrayExpressionIO.Write(nodal_expression, numpy_array)
print("numpy array = ", numpy_array)
```

Expected output:
```bash
numpy array = [[1. 2. 3.]
[3. 4. 5.]]
| / |
' / __| _` | __| _ \ __|
. \ | ( | | ( |\__ \
_|\_\_| \__,_|\__|\___/ ____/
Multi-Physics 9.4."3"-docs/expression_documentation-6de5f1a499-Release-x86_64
Compiled for GNU/Linux and Python3.11 with GCC-13.2
Compiled with threading and MPI support.
Maximum number of threads: 30.
Running without MPI.
```
## Reading and writing to `Kratos::Vector`
```CArrayExpressionIO``` also allows reading and writing from ```Kratos::Vector``` containers. In this case, the size of the ```Kratos::Vector``` should be the flattened size of the shape of interest which the user will be working on.
Expand Down Expand Up @@ -74,6 +89,21 @@ for node in model_part.Nodes:
print(f"node_id: {node.Id}, velocity: [{velocity[0]}, {velocity[1]}, {velocity[2]}]")
```
Expected output:
```bash
node_id: 1, velocity: [1.0, 2.0, 3.0]
node_id: 2, velocity: [4.0, 5.0, 6.0]
| / |
' / __| _` | __| _ \ __|
. \ | ( | | ( |\__ \
_|\_\_| \__,_|\__|\___/ ____/
Multi-Physics 9.4."3"-docs/expression_documentation-6de5f1a499-Release-x86_64
Compiled for GNU/Linux and Python3.11 with GCC-13.2
Compiled with threading and MPI support.
Maximum number of threads: 30.
Running without MPI.
```
Writing to a ```Kratos::Vector``` is illustarted by the following code snippet. If the passed vector (to where the expression values are written) is not with the correct size, it will be resized. This will also only write the data values of the local entities in the LocalMesh.
```python
import KratosMultiphysics as Kratos
Expand All @@ -96,3 +126,17 @@ Kratos.Expression.CArrayExpressionIO.Write(nodal_expression, vector)
print(vector)
```
Expected output:
```bash
[6](1,2,3,3,4,5)
| / |
' / __| _` | __| _ \ __|
. \ | ( | | ( |\__ \
_|\_\_| \__,_|\__|\___/ ____/
Multi-Physics 9.4."3"-docs/expression_documentation-6de5f1a499-Release-x86_64
Compiled for GNU/Linux and Python3.11 with GCC-13.2
Compiled with threading and MPI support.
Maximum number of threads: 30.
Running without MPI.
```
28 changes: 28 additions & 0 deletions docs/pages/Kratos/Expressions/IOs/Domain_Size_Expression_IO.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@ shape = element_expression.Evaluate().shape
print(shape)
```

Expected output:
```bash
(1,)
| / |
' / __| _` | __| _ \ __|
. \ | ( | | ( |\__ \
_|\_\_| \__,_|\__|\___/ ____/
Multi-Physics 9.4."3"-docs/expression_documentation-6de5f1a499-Release-x86_64
Compiled for GNU/Linux and Python3.11 with GCC-13.2
Compiled with threading and MPI support.
Maximum number of threads: 30.
Running without MPI.
```
## Using expressions without the model parts
The ```ConditionExpression``` and ```ElementExpression``` has an expression which can be directly used if required. The advantage of working
with the ```Expression``` directely is, then it is not bound to a model part of a ```DataValueContainer```. Hence, these expressions can be interchanged if required in
Expand All @@ -62,3 +76,17 @@ exp *= 2.0
print(exp)
```
Expected output:
```bash
(DoubleVec[]*2)
| / |
' / __| _` | __| _ \ __|
. \ | ( | | ( |\__ \
_|\_\_| \__,_|\__|\___/ ____/
Multi-Physics 9.4."3"-docs/expression_documentation-6de5f1a499-Release-x86_64
Compiled for GNU/Linux and Python3.11 with GCC-13.2
Compiled with threading and MPI support.
Maximum number of threads: 30.
Running without MPI.
```
65 changes: 64 additions & 1 deletion docs/pages/Kratos/Expressions/IOs/Literal_Expression_Input.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,21 @@ for node in model_part.Nodes:
print(f"node_id: {node.Id}, velocity = [{velocity[0]}, {velocity[1]}, {velocity[2]}]")
```

Expected output:
```bash
node_id: 1, velocity = [1.0, 2.0, 3.0]
node_id: 2, velocity = [1.0, 2.0, 3.0]
| / |
' / __| _` | __| _ \ __|
. \ | ( | | ( |\__ \
_|\_\_| \__,_|\__|\___/ ____/
Multi-Physics 9.4."3"-docs/expression_documentation-6de5f1a499-Release-x86_64
Compiled for GNU/Linux and Python3.11 with GCC-13.2
Compiled with threading and MPI support.
Maximum number of threads: 30.
Running without MPI.
```
## Setting literal expression to zero
The ```LiteralExpressionIO``` also can be used to set entity data to zero for a given variable. **In the case of dynamically sized types, it will create empty instances [Such as Vector with size 0, Matrix with shape (0,0)**. The passed variable is only used to determine the entity shape. Example:
Expand Down Expand Up @@ -77,6 +92,23 @@ for node in model_part.Nodes:
print(f"node_id: {node.Id}, pressure = {node.GetValue(Kratos.PRESSURE)}, temperature = {node.GetValue(Kratos.TEMPERATURE)}")
```
Expected output:
```bash
PRESSURE before resetting:
[10. 20.]
node_id: 1, pressure = 10.0, temperature = 0.0
node_id: 2, pressure = 20.0, temperature = 0.0
| / |
' / __| _` | __| _ \ __|
. \ | ( | | ( |\__ \
_|\_\_| \__,_|\__|\___/ ____/
Multi-Physics 9.4."3"-docs/expression_documentation-6de5f1a499-Release-x86_64
Compiled for GNU/Linux and Python3.11 with GCC-13.2
Compiled with threading and MPI support.
Maximum number of threads: 30.
Running without MPI.
```
## Use cases
Lets assume you want to get inverse of a scalar expressions such as PRESSURE. In that case you can easily use ```LiteralExpressionIO``` to compute it.
Expand Down Expand Up @@ -108,10 +140,26 @@ Kratos.Expression.VariableExpressionIO.Write(inverse_expression, Kratos.TEMPERAT
# now check
for node in model_part.Nodes:
velocity = node.GetValue(Kratos.VELOCITY)
print(f"node_id: {node.Id}, pressure = {node.GetValue(Kratos.PRESSURE)}, temperature = {node.GetValue(Kratos.TEMPERATURE)}")
```
Expected output:
```bash
PRESSURE before resetting:
[10. 20.]
node_id: 1, pressure = 10.0, temperature = 0.1
node_id: 2, pressure = 20.0, temperature = 0.05
| / |
' / __| _` | __| _ \ __|
. \ | ( | | ( |\__ \
_|\_\_| \__,_|\__|\___/ ____/
Multi-Physics 9.4."3"-docs/expression_documentation-6de5f1a499-Release-x86_64
Compiled for GNU/Linux and Python3.11 with GCC-13.2
Compiled with threading and MPI support.
Maximum number of threads: 30.
Running without MPI.
```
## Using expressions without the model parts
The ```NodalExpression```, ```ConditionExpression``` and ```ElementExpression``` has an expression which can be directly used if required. The advantage of working
with the ```Expression``` directely is, then it is not bound to a model part of a ```DataValueContainer```. Hence, these expressions can be interchanged if required in
Expand All @@ -137,3 +185,18 @@ for node in model_part.Nodes:
acceleration = node.GetValue(Kratos.ACCELERATION)
print(f"node_id: {node.Id}, acceleration: [{acceleration[0]},{acceleration[1]},{acceleration[2]}]")
```
Expected output:
```bash
node_id: 1, acceleration: [2.0,4.0,6.0]
node_id: 2, acceleration: [2.0,4.0,6.0]
| / |
' / __| _` | __| _ \ __|
. \ | ( | | ( |\__ \
_|\_\_| \__,_|\__|\___/ ____/
Multi-Physics 9.4."3"-docs/expression_documentation-6de5f1a499-Release-x86_64
Compiled for GNU/Linux and Python3.11 with GCC-13.2
Compiled with threading and MPI support.
Maximum number of threads: 30.
Running without MPI.
```
41 changes: 38 additions & 3 deletions docs/pages/Kratos/Expressions/IOs/Nodal_Position_Expression_IO.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Kratos.Expression.NodalPositionExpressionIO.Read(current_nodal_expression,Kratos
print("initial:\n", initial_nodal_expression.Evaluate())
print("current:\n", current_nodal_expression.Evaluate())

# now do some arithmatics with the exps
# now do some arithmetics with the exps
initial_nodal_expression *= 2
current_nodal_expression *= 2

Expand All @@ -52,9 +52,30 @@ for node in model_part.Nodes:
print(f"node_id: {node.Id}, initial: [{node.X0}, {node.Y0}, {node.Z0}], current: [{node.X}, {node.Y}, {node.Z}]")
```

Expected output:
```bash
initial:
[[0. 0. 0.]
[0. 1. 0.]]
current:
[[10. 10. 0.]
[ 0. 1. 0.]]
node_id: 1, initial: [0.0, 0.0, 0.0], current: [20.0, 20.0, 0.0]
node_id: 2, initial: [0.0, 2.0, 0.0], current: [0.0, 2.0, 0.0]
| / |
' / __| _` | __| _ \ __|
. \ | ( | | ( |\__ \
_|\_\_| \__,_|\__|\___/ ____/
Multi-Physics 9.4."3"-docs/expression_documentation-6de5f1a499-Release-x86_64
Compiled for GNU/Linux and Python3.11 with GCC-13.2
Compiled with threading and MPI support.
Maximum number of threads: 30.
Running without MPI.
```
## Using expressions without the model parts
The ```NodalExpression```, ```ConditionExpression``` and ```ElementExpression``` has an expression which can be directly used if required. The advantage of working
with the ```Expression``` directely is, then it is not bound to a model part of a ```DataValueContainer```. Hence, these expressions can be interchanged if required in
with the ```Expression``` directly is, then it is not bound to a model part of a ```DataValueContainer```. Hence, these expressions can be interchanged if required in
advanced use cases. Following code snippet shows how to use bare ```Expressions```.
```python
import KratosMultiphysics as Kratos
Expand All @@ -75,4 +96,18 @@ Kratos.Expression.NodalPositionExpressionIO.Output(model_part, Kratos.Configurat
# now read nodal positions
for node in model_part.Nodes:
print(f"node_id: {node.Id}, initial: [{node.X0}, {node.Y0}, {node.Z0}], current: [{node.X}, {node.Y}, {node.Z}]")
```
```
Expected output:
```bash
node_id: 1, initial: [0.0, 0.0, 0.0], current: [0.0, 0.0, 0.0]
node_id: 2, initial: [0.0, 1.0, 0.0], current: [0.0, 2.0, 0.0]
| / |
' / __| _` | __| _ \ __|
. \ | ( | | ( |\__ \
_|\_\_| \__,_|\__|\___/ ____/
Multi-Physics 9.4."3"-docs/expression_documentation-6de5f1a499-Release-x86_64
Compiled for GNU/Linux and Python3.11 with GCC-13.2
Compiled with threading and MPI support.
Maximum number of threads: 30.
Running without MPI.
```
Loading

0 comments on commit 9a32385

Please sign in to comment.