Exemple #1
0
    def check_htc_file(self, f):

        with open(f) as fid:
            orglines = fid.read().strip().split("\n")

        htcfile = HTCFile(f, "../")
        newlines = str(htcfile).split("\n")
        htcfile.save(self.testfilepath + 'tmp.htc')
        # with open(self.testfilepath + 'tmp.htc') as fid:
        #    newlines = fid.readlines()

        for i, (org, new) in enumerate(zip(orglines, newlines), 1):

            def fmt(x):
                return x.strip().replace("\t", " ").replace("  ", " ").replace(
                    "  ", " ").replace("  ", " ").replace("  ", " ")

            if fmt(org) != fmt(new):
                print("----------%d-------------" % i)
                print(fmt(org))
                print(fmt(new))
                self.assertEqual(fmt(org), fmt(new))
                break
                print()
        assert len(orglines) == len(newlines)
Exemple #2
0
    def write(self, out_fn, **kwargs):
        ''' 
        Renders a single htc file for a given set of 'tagless' contents. 
        args: 
        out_fn (str or pathlib.Path): The output filename where to render
        the jinja template. 
        params (pd.DataFrame or pd.Series) : The input contents.
        '''
        # if isinstance(params, PandasObject):
        #     params = params.to_dict()

        htc = HTCFile(self.base_htc_file)
        for k, v in kwargs.items():
            k = k.replace('/', '.')
            if '.' in k:
                line = htc[k]
                v = str(v).strip().replace(",", " ")
                line.values = v.split()

            elif k in ['Name', 'Folder', 'DLC']:
                continue

            else:
                getattr(self, 'set_%s' % k)(htc, **kwargs)

            htc.save(out_fn)
Exemple #3
0
    def write(self, path, **kwargs):
        """Write a single htc file.

        Notes
        -----
        This function works both with the tagless and jinja file-writing systems. Any
        methods of the form `set_<tag>` are called during file writing.

        Parameters
        ----------
        path : str or pathlib.Path
            The path to save the htc file to.
        **kwargs : pd.DataFrame, pd.Series or dict
            Keyword arguments. The tags to update/replace in the file.
        """
        htc = HTCFile(self.base_htc_file, jinja_tags=kwargs)
        for k, v in kwargs.items():
            k = k.replace('/', '.')
            if '.' in k:  # directly replace tags like "wind.wsp"
                line = htc[k]
                v = str(v).strip().replace(",", " ")
                line.values = v.split()
            else:  # otherwise, use the "set_" attribute
                if hasattr(self, 'set_%s' % k):
                    getattr(self, 'set_%s' % k)(htc, **kwargs)
        htc.save(path)
Exemple #4
0
 def test_open_eq_save(self):
     HTCFile(self.testfilepath + "test3.htc",
             "../").save(self.testfilepath + "tmp.htc")
     htcfile = HTCFile(self.testfilepath + "tmp.htc", "../")
     htcfile.save(self.testfilepath + "tmp.htc")
     self.assertEqual(
         str(htcfile).count("\t"),
         str(HTCFile(self.testfilepath + "tmp.htc", "../")).count("\t"))
     self.assertEqual(str(htcfile),
                      str(HTCFile(self.testfilepath + "tmp.htc", "../")))
def main():
    if __name__ == '__main__':

        # ======================================================================
        # load existing htc file
        # ======================================================================
        path = os.path.dirname(test_files.__file__) + "/simulation_setup/DTU10MWRef6.0/"
        htc = HTCFile(path + "htc/DTU_10MW_RWT.htc")

        # ======================================================================
        # modify wind speed and turbulence intensity
        # ======================================================================

        htc.wind.wsp = 10

        # access wind section and change turbulence intensity
        wind = htc.wind
        wind.tint = .1

        #=======================================================================
        # print contents
        #=======================================================================
        print(htc)  # print htc file
        print(htc.keys())  # print htc sections
        print(wind)  # print wind section

        #=======================================================================
        # change tilt angle
        #=======================================================================
        orientation = htc.new_htc_structure.orientation

        # Two ways to access the relative orientation between towertop and shaft
        # 1) Knowning that it is the second relative section:
        rel_tt_shaft = orientation.relative__2
        # 2) Knowning that the section contains a field "body1" with value "topertop"
        rel_tt_shaft = orientation.get_subsection_by_name(name='towertop', field='body1')

        rel_tt_shaft.body2_eulerang__2 = 6, 0, 0
        print(rel_tt_shaft.body2_eulerang__2)

        # ======================================================================
        # set time, name and save
        # ======================================================================
        # set time of simulation, first output section and wind.scale_time_start
        htc.set_time(start=5, stop=10, step=0.1)

        # change name of logfile, animation, visualization and first output section
        htc.set_name("tmp_wsp10_tint0.1_tilt6")

        htc.save()  # Save htc modified htcfile as "tmp_wsp10_tint0.1_tilt6"
Exemple #6
0
    def write_input_files(self, Name, Folder='', **kwargs):
        htc = HTCFile(self.base_htc_file)
        for k, v in kwargs.items():
            k = k.replace('/', '.')
            if '.' in k:
                line = htc[k]
                v = str(v).strip().replace(",", " ")
                line.values = v.split()
            else:
                getattr(self, 'set_%s' % k)(htc, **kwargs)
        htc.set_name(Name, Folder)
        htc.save()
        args = {'Name': Name, 'Folder': Folder}
        args.update(kwargs)

        return pd.Series(args)
Exemple #7
0
 def test_tjul_example(self):
     htcfile = HTCFile(self.testfilepath + "./tjul.htc", ".")
     htcfile.save("./temp.htc")
Exemple #8
0
"""Use HAWC2S to calculate blade eigenanalysis
"""
import os
from wetb.hawc2.htc_file import HTCFile
from _inputs import hawc_dir, data_dir
from _utils import run_hawc2s


for h2_mod in ['FPM', 'NoFPM_notorsion']:

    # intermediate variables
    mod_dir = hawc_dir + h2_mod + '/'

    # create hawc2s file for blade eigenanalysis
    orig_htc = os.path.join(mod_dir, [f for f in os.listdir(mod_dir)
                                      if f.endswith('.htc')][0])
    new_htc = mod_dir + f'{h2_mod}_blade_eigenanalysis.htc'
    htc = HTCFile(orig_htc)
    htc.hawcstab2.add_line('compute_structural_modal_analysis', ['bladeonly', 20])
    htc.save(new_htc)

    # run hawc2s
    run_hawc2s(new_htc, mod_dir)
    cmb_path = new_htc.replace('.htc', '_Blade_struc.cmb')

    # move results to data directory
    os.replace(cmb_path, data_dir + f'eigenfreq_{h2_mod}_hawc2.txt')

    # delete hawc2s file
    os.remove(new_htc)