File tree Expand file tree Collapse file tree
incompressible_flow/Inc_Species_Transport/4__optimization Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # 06.12.2021 T. Kattmann
2+ #
3+ # Compute gradient norm for each design iteration and saves the gradient norm into a csv file.
4+
5+ import numpy as np
6+ import os
7+ import pandas as pd
8+
9+ if __name__ == '__main__' :
10+ # Create list with folder names
11+ baseFolder = "./"
12+ sub_folders = [name for name in os .listdir (baseFolder ) if os .path .isdir (os .path .join (baseFolder , name ))]
13+ DSN_folders = [folder for folder in sub_folders if 'DSN' in folder ]
14+
15+ # Initialize array of gradient Norms
16+ gradientNormVector = np .zeros (len (DSN_folders ))
17+
18+ # loop through all Design folder
19+ for i ,folder in enumerate (DSN_folders ):
20+ # check if gradient file exists
21+ gradFilename = baseFolder + folder + "/DOT/of_grad.csv"
22+ if os .path .exists (gradFilename ):
23+ # Read the gradient file and store gradient norm
24+ df = pd .read_csv (gradFilename )
25+ gradient = df .values
26+ gradientNormVector [i ] = np .linalg .norm (gradient )
27+ else :
28+ # Write a NaN as in Paraview these values are omitted
29+ gradientNormVector [i ] = np .nan
30+
31+ print (gradientNormVector )
32+ np .savetxt ("gradient_norm.csv" , gradientNormVector )
You can’t perform that action at this time.
0 commit comments