Bug flix and correct import from xml

This commit is contained in:
Jonas Kellerer
2021-03-15 16:01:09 +01:00
parent 07c13466d6
commit dfda218f42
9 changed files with 14716 additions and 88 deletions
Binary file not shown.
+18
View File
@@ -0,0 +1,18 @@
<?xml version="1.0"?>
<Parameters>
<KatrinFields>
<MagneticField>
<Constant>2.5</Constant>
</MagneticField>
<ElectricField>
<Filename>/home/jonas/new_workspace/Coding/Output/KARL/ElectricField/E_field.h5</Filename>
<Radius>0.045</Radius>
<Height>13.</Height>
</ElectricField>
</KatrinFields>
</Parameters>
+3 -3
View File
@@ -1,8 +1,8 @@
#include "elecrticFieldFactory.h"
#include "HighFive/include/highfive/H5File.hpp"
#include "HighFive/include/highfive/H5DataSet.hpp"
#include "HighFive/include/highfive/H5DataSpace.hpp"
#include "highfive/H5File.hpp"
#include "highfive/H5DataSet.hpp"
#include "highfive/H5DataSpace.hpp"
#include <vector>
#include <array>
+77
View File
@@ -0,0 +1,77 @@
/**
* pugixml parser - version 1.11
* --------------------------------------------------------
* Copyright (C) 2006-2020, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com)
* Report bugs and download new versions at https://pugixml.org/
*
* This library is distributed under the MIT License. See notice at the end
* of this file.
*
* This work is based on the pugxml parser, which is:
* Copyright (C) 2003, by Kristen Wegner (kristen@tima.net)
*/
#ifndef HEADER_PUGICONFIG_HPP
#define HEADER_PUGICONFIG_HPP
// Uncomment this to enable wchar_t mode
// #define PUGIXML_WCHAR_MODE
// Uncomment this to enable compact mode
// #define PUGIXML_COMPACT
// Uncomment this to disable XPath
// #define PUGIXML_NO_XPATH
// Uncomment this to disable STL
// #define PUGIXML_NO_STL
// Uncomment this to disable exceptions
// #define PUGIXML_NO_EXCEPTIONS
// Set this to control attributes for public classes/functions, i.e.:
// #define PUGIXML_API __declspec(dllexport) // to export all public symbols from DLL
// #define PUGIXML_CLASS __declspec(dllimport) // to import all classes from DLL
// #define PUGIXML_FUNCTION __fastcall // to set calling conventions to all public functions to fastcall
// In absence of PUGIXML_CLASS/PUGIXML_FUNCTION definitions PUGIXML_API is used instead
// Tune these constants to adjust memory-related behavior
// #define PUGIXML_MEMORY_PAGE_SIZE 32768
// #define PUGIXML_MEMORY_OUTPUT_STACK 10240
// #define PUGIXML_MEMORY_XPATH_PAGE_SIZE 4096
// Tune this constant to adjust max nesting for XPath queries
// #define PUGIXML_XPATH_DEPTH_LIMIT 1024
// Uncomment this to switch to header-only version
#define PUGIXML_HEADER_ONLY
// Uncomment this to enable long long support
// #define PUGIXML_HAS_LONG_LONG
#endif
/**
* Copyright (c) 2006-2020 Arseny Kapoulkine
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
+13020
View File
File diff suppressed because it is too large Load Diff
+1499
View File
File diff suppressed because it is too large Load Diff
+43 -6
View File
@@ -4,23 +4,60 @@
#include "elecrticFieldFactory.h"
#include "CoordinateConversion.h"
#include "pugixml.hpp"
#include <stdexcept>
void initCoordinateConversion()
{
CoordinateConversion::setCylinderOrigin(
blitz::TinyVector<double,3>(0., 0., -3.));
}
void initKatrinFields() {
Katrin_Fields::wgtsMagField_T = load_parameter("BFIELD");
void initBField(const pugi::xml_node& B_params) {
const double B_value = atof(B_params.child_value("Constant"));
Katrin_Fields::wgtsMagField_T = B_value;
}
void initEField(const pugi::xml_node& E_params) {
std::string filename = std::string(E_params.child_value("Filename"));
double radius = atof(E_params.child_value("Radius"));
double height = atof(E_params.child_value("Height"));
Katrin_Fields::E_field_ptr = ElectricFieldFactory::build(
"/home/jonas/new_workspace/Coding/Output/KARL/ElectricField/E_field.h5",
0.045,
13.0);
filename,
radius,
height);
}
void initKatrinFields(const pugi::xml_node& field_params) {
if(field_params.empty()){
throw std::runtime_error("Can not build KatrinFields. No data given");
}
initBField(field_params.child("MagneticField"));
initEField(field_params.child("ElectricField"));
}
void Simulation::init()
{
pugi::xml_document parameter_file;
std::string filename_xml = get_enviroment_variable("PARAMETER_FILE");
pugi::xml_parse_result result = parameter_file.load_file(filename_xml.c_str());
if(result.status == pugi::xml_parse_status::status_ok){
std::cout << "Loaded paramters from: ";
std::cout << filename_xml << std::endl;
}
else{
std::cout << result.description() << std::endl;
throw std::runtime_error("Can not load params.xml.\n");
}
pugi::xml_node parameters = parameter_file.child("Parameters");
initCoordinateConversion();
initKatrinFields();
initKatrinFields(parameters.child("KatrinFields"));
}
@@ -5,24 +5,67 @@ from scipy.ndimage import gaussian_filter
from matplotlib import ticker, cm
import h5py as h5py
import import_dings as impding
from . import import_dings as impding
def createZeroFieldH5(filename_output):
zero = np.zeros((1,1))
saveToKarlH5File(filename_output, zero, zero)
def createFieldH5(filename_derived, filename_output, dx, timestep, cylinder_origin, radius, height, z_start, z_end):
L_wgts = 1300
num_cells = int((L_wgts - height*dx)/dx)
timestep = 761600
filename_derived = "/home/jonas/new_workspace/Coding/Output/LRZ/HugeClassChanges/triangleDensityLonger/reflecting/derived.h5"
filename_output = "/home/jonas/new_workspace/Coding/Output/LRZ/HugeClassChanges/triangleDensityLonger/reflecting/karl_input.h5"
data_Er = impding.getNumpyArray(filename_derived, timestep, "E_r")
data_Er_2d = radialAverage(data_Er[:,:,:-10], cylinder_origin, radius, height)
dx = 0.13801796042392211
L_wgts = 1300
data_Er_2d_ext = copyValues(data_Er_2d, z_start, z_end, num_cells)
cylinder_origin = [35,35,11]
radius = 32
height = 1434
data_Ez = impding.getNumpyArray(filename_derived, timestep, "E_z")
data_Ez_2d = radialAverage(data_Ez[:,:,:-10], cylinder_origin, radius, height)
z_start = 350
z_end = 1050
data_Ez_2d_ext = copyValues(data_Ez_2d, z_start, z_end, num_cells)
num_cells = int((L_wgts - height*dx)/dx)
saveToKarlH5File(filename_output, data_Er_2d_ext, data_Ez_2d_ext)
def plotFields(filename_derived, dx, timestep, cylinder_origin, radius, height, z_start, z_end):
L_wgts = 1300
num_cells = int((L_wgts - height*dx)/dx)
data_Er = impding.getNumpyArray(filename_derived, timestep, "E_r")
data_Er_2d = radialAverage(data_Er[:,:,:-10], cylinder_origin, radius, height)
data_Er_2d_ext = copyValues(data_Er_2d, z_start, z_end, num_cells)
data_Ez = impding.getNumpyArray(filename_derived, timestep, "E_z")
data_Ez_2d = radialAverage(data_Ez[:,:,:-10], cylinder_origin, radius, height)
data_Ez_2d_ext = copyValues(data_Ez_2d, z_start, z_end, num_cells)
fig, (ax0,ax1) = plt.subplots(2,1)
pos = ax0.contourf(data_Er_2d_ext, locator=ticker.LogLocator(), cmap=cm.Reds)
neg = ax0.contourf(data_Er_2d_ext*-1, locator=ticker.LogLocator(), cmap = cm.Purples)
pos = ax1.contourf(data_Er_2d, locator=ticker.LogLocator(), cmap=cm.Reds)
neg = ax1.contourf(data_Er_2d*-1, locator=ticker.LogLocator(), cmap = cm.Purples)
cbar_pos = fig.colorbar(pos)
cbar_neg = fig.colorbar(neg)
plt.show()
fig, (ax0,ax1) = plt.subplots(2,1)
pos = ax0.contourf(data_Ez_2d_ext, locator=ticker.LogLocator(), cmap=cm.Reds)
neg = ax0.contourf(data_Ez_2d_ext*-1, locator=ticker.LogLocator(), cmap = cm.Purples)
pos = ax1.contourf(data_Ez_2d, locator=ticker.LogLocator(), cmap=cm.Reds)
neg = ax1.contourf(data_Ez_2d*-1, locator=ticker.LogLocator(), cmap = cm.Purples)
cbar_pos = fig.colorbar(pos)
cbar_neg = fig.colorbar(neg)
plt.show()
def radialAverage(electricField, cylinder_origin, radius, height):
@@ -49,7 +92,7 @@ def radialAverage(electricField, cylinder_origin, radius, height):
return data_mean
# not used right now
def extendValues(data_2d, z_start, z_end, num_cells):
(size_x, size_y) = np.shape(data_2d)
data_ext = np.zeros((size_x, size_y+num_cells))
@@ -89,41 +132,7 @@ def copyValues(data_2d, z_start, z_end, num_cells):
return data_copy
data_Er = impding.getNumpyArray(filename_derived, timestep, "E_r")
data_Er_2d = radialAverage(data_Er[:,:,:-10], cylinder_origin, radius, height)
data_Er_2d_ext = copyValues(data_Er_2d, z_start, z_end, num_cells)
data_Ez = impding.getNumpyArray(filename_derived, timestep, "E_z")
data_Ez_2d = radialAverage(data_Ez[:,:,:-10], cylinder_origin, radius, height)
data_Ez_2d_ext = copyValues(data_Ez_2d, z_start, z_end, num_cells)
fig, (ax0,ax1) = plt.subplots(2,1)
pos = ax0.contourf(data_Er_2d_ext, locator=ticker.LogLocator(), cmap=cm.Reds)
neg = ax0.contourf(data_Er_2d_ext*-1, locator=ticker.LogLocator(), cmap = cm.Purples)
pos = ax1.contourf(data_Er_2d, locator=ticker.LogLocator(), cmap=cm.Reds)
neg = ax1.contourf(data_Er_2d*-1, locator=ticker.LogLocator(), cmap = cm.Purples)
cbar_pos = fig.colorbar(pos)
cbar_neg = fig.colorbar(neg)
plt.show()
fig, (ax0,ax1) = plt.subplots(2,1)
pos = ax0.contourf(data_Ez_2d_ext, locator=ticker.LogLocator(), cmap=cm.Reds)
neg = ax0.contourf(data_Ez_2d_ext*-1, locator=ticker.LogLocator(), cmap = cm.Purples)
pos = ax1.contourf(data_Ez_2d, locator=ticker.LogLocator(), cmap=cm.Reds)
neg = ax1.contourf(data_Ez_2d*-1, locator=ticker.LogLocator(), cmap = cm.Purples)
cbar_pos = fig.colorbar(pos)
cbar_neg = fig.colorbar(neg)
plt.show()
def saveToKarlH5File(filename, Er, Ez):
file = h5py.File(filename, 'w')
@@ -131,36 +140,4 @@ def saveToKarlH5File(filename, Er, Ez):
file.create_dataset('Ez', data=Ez)
file.close()
saveToKarlH5File(filename_output, data_Er_2d_ext, data_Ez_2d_ext)
"""
win = signal.windows.hann(150)
fildered =signal.convolve(data_Er_2d[0,:], win, mode='same')/sum(win)
plt.plot(data_Er_2d[0,:])
plt.plot(fildered)
plt.show()
plt.contourf(data_Er_2d)
plt.show()
filtered_2d = gaussian_filter(data_Er_2d,sigma=(2,10))
fig, ax = plt.subplots()
pos = plt.contourf(filtered_2d, locator=ticker.LogLocator(), cmap=cm.Reds)
neg = plt.contourf(filtered_2d*-1, locator=ticker.LogLocator(), cmap = cm.Purples)
cbar_pos = fig.colorbar(pos)
cbar_neg = fig.colorbar(neg)
plt.show()
plt.plot(filtered_2d[0,:],label="0")
plt.plot(filtered_2d[5,:],label="5")
plt.plot(filtered_2d[16,:],label="16")
plt.plot(filtered_2d[20,:],label="20")
plt.legend()
plt.show()
"""