CHLNDDEV / OceanMesh2D

A two-dimensional triangular mesh generator with pre- and post-processing utilities written in pure MATLAB (no toolboxes required) designed specifically to build models that solve shallow-water equations or wave equations in a coastal environment (ADCIRC, FVCOM, WaveWatch3, SWAN, SCHISM, Telemac, etc.).
https://github.com/sponsors/krober10nd
GNU General Public License v3.0
178 stars 64 forks source link

Spatially offset fine resolution #314

Open tc-ecoast opened 1 month ago

tc-ecoast commented 1 month ago

Hi all. I am generating a mesh for a region roughly 320 by 80 km, and am trying to resolve 60 small scale, circular, subaerial features (10 m diameter) that are located offshore in 60 m depth. I want to include them in the mesh and not make them boundaries.

The first two bboxs cover the coastal zone ranging from 1000 to 50 m resolution. The third bbox specified resolution ranges are depth dependent from a DEM, such that the subaerial features have a min and max resolution of 4 m. This generates higher resolution in the vicinity of the features, but not exactly located around each feature, with spatial offsets on the order of 10’s to 100’s of meters. I uploaded the matlab script for this as a txt file. bbox_dem gen_mesh_github.txt

When I generate a mesh with only the edgefx and geodata from bbox3, it generates high resolution in the correct places. bbox3_only

I have also tried to resolve the features by creating a bbox around each feature (with a 100 m diameter for example) with the resolution set at 2 m for each. The plot shows the bbox locations (magenta) which again results in spatially offset fine resolution in comparison to where I specified for it to occur. bbox_features_example

Any advice about how to fix this or if I’m doing anything wrong would be much appreciated. Thanks, Ted

krober10nd commented 1 month ago

Interesting application for offshore wind? I think this is happening because the vector inputs are by default smoothed via a moving window approach. You can deactivate this by passing "window",1 to your geodata class constructor.

tc-ecoast commented 1 month ago

Thanks, and that's correct regarding the application.

Using the "window",1 input to geodata did not change the result in either approach unfortunately.

I forgot to mention before, but when I interpolate the DEM with the features included, after the mesh generation, it interpolates it to the correct locations.

Would any spatial modifications occur during the call to meshgen?

Thanks

krober10nd commented 1 month ago

Could you post the vector inputs here so I can try at some point?

I wouldn't recommend using the feature size here. Instead use the distance mesh sizing function.

tc-ecoast commented 1 month ago

I'll try the distance sizing instead. Here is a compressed folder that contains everything to run my setup: https://www.dropbox.com/scl/fi/gvfuv45hdszfbxstyd2n4/upload.zip?rlkey=n7k69nya9wjcw8ogr0jgebkhq&dl=0

krober10nd commented 1 month ago

Hi Tom, I'm taking a look at your example. Can you add the offshore wind foundations to the shoreline inputs you pass to geodata_3 instead of modifying the DEM?

If you are using OceanMesh2D V6, set the high_fidelity option in the geodata_3 constructor to 1 and use a distance sizing heuristic instead of the feature size, you will be able to preserve the structure of the turbine foundations.

I am still investigating why the DEM is shifting in the mesh sizing function.

tc-ecoast commented 1 month ago

Thanks for looking into that. Including the feature locations to the shoreline input did allow for the features to be resolved at the correct locations which is great. We do want a mesh inside of the features as well though, but I'm looking into how to fill each mesh region after it is generated.

krober10nd commented 1 month ago

You can then use the meshgen class with the edgefx and geodata classes that have the osw foundations to just generate the pfix and egfix. Then you pass this to your meshgen. Don't use the geodata class with the osw in the vector inputs to build the final mesh though.

Check out how I did it in this example for constraining the shoreline but meshing upwards to a higher iso contour on the floodplain.

clearvars; clc; close all
%%
PREFIX = 'hamburg_overland';

%% Set mesh extents and set parameters for mesh.
min_el = 100*10;            % Minimum mesh resolution in meters.

max_el = 1e3*10;

grade = 0.05; 

fs = 3 ;                % Place 3 vertices per width of shoreline feature.

max_el_ns = 500*10; 

%%
coastline = 'GSHHS_f_L1';
floodline = 'floodline_contour_polygon_v1';
my_bbox   = 'bbox_v1';

tmp = m_shaperead(my_bbox); 
bbox2 = tmp.ncst{1}; 

gdatuw = geodata(...
    'shp',coastline,...
    'bbox',bbox2,...
    'h0',min_el,...
    'high_fidelity',1); % KJR: Set this for the constraints to be generated.

fh = edgefx(...
    'geodata',gdatuw,...
    'fs',fs,...
    'max_el_ns',max_el_ns,...
    'g',grade,...
    'max_el',max_el);
%%
mshopts = meshgen('ef',fh,'bou',gdatuw,'plot_on',1);

pfix  = mshopts.pfix; 
egfix = mshopts.egfix; 

gdat = geodata(...
    'shp',floodline,...
    'bbox',bbox2,...
    'h0',min_el);

mshopts = meshgen('ef',fh,'bou',gdat,...
    'pfix',pfix,'egfix',egfix);

mshopts = mshopts.build();

m = mshopts.grd;

%% 

plot(m,'type','tri','proj','none'); 
drawedge2(pfix,egfix,'k');
krober10nd commented 1 month ago

Have you been able to apply the above code to mesh the turbine foundations and preserve their locations?

tc-ecoast commented 1 month ago

That approach also did not work. I can give more detailed feedback soon.

I went back to the altered DEM approach and found that the spatial shifting occurs only when pfix points are input to meshgen (either at the model boundary or at the structure locations). So we found a working solution by using the altered DEM without any pfix points, which generated high resolution in the correct areas.

krober10nd commented 1 month ago

Thank you. I would l appreciate more details to resolve the original issue with the DEM shifting.

I also want to understand what went wrong with my last suggested approach using the high fidelity mode. Thanks again.